Skip to content

Commit

Permalink
castxml: Fix __float128 simulation with -std=gnu++{11,14} again
Browse files Browse the repository at this point in the history
The approach used in commit 1414278 (castxml: Fix `__float128`
simulation with `-std=gnu++{11,14}`, 2016-01-25) allowed Clang to use
its own builtin `__float128` type when it is available.  However, Clang
does not really implement this builtin and issues diagnostics when it is
used in some contexts (e.g. as a data member).

Instead we need to provide our own approximation of the builtin in all
cases.  Avoid a conflict with the Clang builtin by using the
preprocessor to rename the type to `__castxml__float128`.  Then replace
this name with `__float128` during output.

GitHub-Issue: #59
  • Loading branch information
bradking committed May 10, 2016
1 parent 9aa7a28 commit 9a83414
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
13 changes: 3 additions & 10 deletions src/Output.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,8 @@ void ASTVisitor::PrintIdAttribute(DumpNode const* dn)
//----------------------------------------------------------------------------
void ASTVisitor::PrintNameAttribute(std::string const& name)
{
this->OS << " name=\"" << encodeXML(name) << "\"";
std::string n = stringReplace(name, "__castxml__float128_s", "__float128");
this->OS << " name=\"" << encodeXML(n) << "\"";
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -1619,14 +1620,6 @@ void ASTVisitor::OutputNamespaceDecl(
void ASTVisitor::OutputRecordDecl(clang::RecordDecl const* d,
DumpNode const* dn)
{
// As a special case, replace the Clang fake builtin for __float128
// with a FundamentalType so we generate the same thing gccxml did.
if (this->CI.getLangOpts().CPlusPlus &&
d == this->CI.getASTContext().getFloat128StubType()) {
this->PrintFloat128Type(dn);
return;
}

const char* tag;
switch (d->getTagKind()) {
case clang::TTK_Class: tag = "Class"; break;
Expand Down Expand Up @@ -1725,7 +1718,7 @@ void ASTVisitor::OutputTypedefDecl(clang::TypedefDecl const* d,
{
// As a special case, replace our compatibility Typedef for __float128
// with a FundamentalType so we generate the same thing gccxml did.
if (d->getName() == "__float128" &&
if (d->getName() == "__castxml__float128" &&
clang::isa<clang::TranslationUnitDecl>(d->getDeclContext())) {
clang::SourceLocation sl = d->getLocation();
if (sl.isValid()) {
Expand Down
19 changes: 9 additions & 10 deletions src/RunClang.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,15 @@ class CastXMLPredefines: public T

// Provide __float128 if simulating the actual GNU compiler.
if (this->NeedFloat128(this->Opts.Predefines)) {
// Clang provides its own (fake) builtin in gnu++11 mode.
// Otherwise we need to provide our own.
if (!(CI.getLangOpts().CPlusPlus11 &&
CI.getLangOpts().GNUMode)) {
builtins += "\n"
"typedef struct __castxml__float128 { "
" char x[16] __attribute__((aligned(16))); "
"} __float128;\n"
;
}
// Clang provides its own (fake) builtin in gnu++11 mode but issues
// diagnostics when it is used in some contexts. Provide our own
// approximation of the builtin instead.
builtins += "\n"
"typedef struct __castxml__float128_s { "
" char x[16] __attribute__((aligned(16))); "
"} __castxml__float128;\n"
"#define __float128 __castxml__float128\n"
;
}

// Provide __is_assignable builtin if simulating MSVC.
Expand Down
1 change: 1 addition & 0 deletions test/expect/cmd.cc-gnu-c-tgt-i386-opt-E.stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
#define __castxml_clang_major__ [0-9]+
#define __castxml_clang_minor__ [0-9]+
#define __castxml_clang_patchlevel__ [0-9]+
#define __float128 __castxml__float128
#define __i386__ 1$
1 change: 1 addition & 0 deletions test/expect/cmd.cc-gnu-tgt-i386-opt-E.stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
#define __castxml_clang_minor__ [0-9]+
#define __castxml_clang_patchlevel__ [0-9]+
#define __cplusplus 199711L
#define __float128 __castxml__float128
#define __i386__ 1$
13 changes: 9 additions & 4 deletions test/expect/gccxml.any.GNU-float128.xml.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
^<\?xml version="1.0"\?>
<GCC_XML[^>]*>
<Function id="_1" name="start" returns="_2" context="_3" location="f1:1" file="f1" line="1" mangled="">
<Argument type="_2" location="f1:1" file="f1" line="1"/>
<Namespace id="_1" name="start" context="_2" members="_3 _4 _5"/>
<Function id="_3" name="f" returns="_6" context="_1" location="f1:3" file="f1" line="3" mangled="">
<Argument type="_6" location="f1:3" file="f1" line="3"/>
</Function>
<FundamentalType id="_2" name="__float128" size="128" align="128"/>
<Namespace id="_3" name="::"/>
<Variable id="_4" name="v" type="_6" init="" context="_1" location="f1:4" file="f1" line="4" mangled="[^"]*"/>
<Variable id="_5" name="pa" type="_7" context="_1" location="f1:5" file="f1" line="5" mangled="[^"]*"/>
<FundamentalType id="_6" name="__float128" size="128" align="128"/>
<PointerType id="_7" type="_8"/>
<Namespace id="_2" name="::"/>
<Struct id="_8" name="A&lt;__float128&gt;" context="_2" location="f1:1" file="f1" line="1" incomplete="1"/>
<File id="f1" name=".*/test/input/GNU-float128.cxx"/>
</GCC_XML>$
1 change: 1 addition & 0 deletions test/input/GNU-float128.c
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__float128 start(__float128);
__float128 v;
7 changes: 6 additions & 1 deletion test/input/GNU-float128.cxx
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
__float128 start(__float128);
template <typename T> struct A;
namespace start {
__float128 f(__float128);
__float128 v;
A<__float128>* pa;
}

0 comments on commit 9a83414

Please sign in to comment.