diff options
author | Brad King <brad.king@kitware.com> | 2015-06-23 20:54:11 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-06-24 17:46:59 (GMT) |
commit | adcf6a0b51032e4486e1ba0bac3f646166b09653 (patch) | |
tree | e5bdc1c4a5e8ea4588180274400c0f0832637edb | |
parent | e519695620c0f5ebf1011e8946f1878b67f2fb08 (diff) | |
download | CastXML-adcf6a0b51032e4486e1ba0bac3f646166b09653.zip CastXML-adcf6a0b51032e4486e1ba0bac3f646166b09653.tar.gz CastXML-adcf6a0b51032e4486e1ba0bac3f646166b09653.tar.bz2 |
Output: Further hide our __float128 struct from generated xml
Give the our __float128 struct an internal '__castxml' name so that it
can be identified during traversal of member lists. Do not report the
struct as a member of the translation unit since the typedef will be
generated as a FundamentalType directly. Also generate empty mangled=""
attributes for mangled names involving our __float128 struct since the
mangled names will not use the "g" that GCC would for the builtin type.
Add test cases that do not use --castxml-start. Verify that no test
case produces '__castxml' in its output to ensure we always hide such
internal details from the generated output.
GitHub-Issue: 18
-rw-r--r-- | src/Detect.cxx | 2 | ||||
-rw-r--r-- | src/Output.cxx | 17 | ||||
-rw-r--r-- | test/CMakeLists.txt | 10 | ||||
-rw-r--r-- | test/expect/gccxml.any.GNU-float128-nostart.xml.txt | 5 | ||||
-rw-r--r-- | test/expect/gccxml.any.GNU-float128.xml.txt | 2 | ||||
-rw-r--r-- | test/expect/gccxml.c89.GNU-float128-nostart.xml.txt | 5 | ||||
-rw-r--r-- | test/expect/gccxml.c89.GNU-float128.xml.txt | 2 | ||||
-rw-r--r-- | test/run.cmake | 4 |
8 files changed, 44 insertions, 3 deletions
diff --git a/src/Detect.cxx b/src/Detect.cxx index d3f6d23..c7a7bae 100644 --- a/src/Detect.cxx +++ b/src/Detect.cxx @@ -81,7 +81,7 @@ static void fixPredefines(Options& opts) pd.find("#define __x86_64__ ") != pd.npos || pd.find("#define __ia64__ ") != pd.npos)) { pd += "\n" - "typedef struct { " + "typedef struct __castxml_float128 { " " char x[16] __attribute__((aligned(16))); " "} __float128;\n" ; diff --git a/src/Output.cxx b/src/Output.cxx index 73f0978..affb4fb 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -750,6 +750,8 @@ void ASTVisitor::AddFunctionTemplateDecl(clang::FunctionTemplateDecl const* d, void ASTVisitor::AddDeclContextMembers(clang::DeclContext const* dc, std::set<DumpId>& emitted) { + bool const isTranslationUnit = clang::isa<clang::TranslationUnitDecl>(dc); + for(clang::DeclContext::decl_iterator i = dc->decls_begin(), e = dc->decls_end(); i != e; ++i) { clang::Decl const* d = *i; @@ -767,6 +769,9 @@ void ASTVisitor::AddDeclContextMembers(clang::DeclContext const* dc, if (rd->isInjectedClassName()) { continue; } + if (isTranslationUnit && rd->getName() == "__castxml_float128") { + continue; + } } break; case clang::Decl::AccessSpec: { continue; @@ -803,6 +808,12 @@ void ASTVisitor::AddDeclContextMembers(clang::DeclContext const* dc, continue; } } break; + case clang::Decl::Record: { + clang::RecordDecl const* rd = static_cast<clang::RecordDecl const*>(d); + if (isTranslationUnit && rd->getName() == "__castxml_float128") { + continue; + } + } break; case clang::Decl::Using: { continue; } break; @@ -1030,6 +1041,12 @@ void ASTVisitor::PrintMangledAttribute(clang::NamedDecl const* d) this->MangleContext->mangleName(d, rso); } + // We cannot mangle __float128 correctly because Clang does not have + // it as an internal type, so skip mangled attributes involving it. + if (s.find("18__castxml_float128") != s.npos) { + s = ""; + } + // Strip a leading 1 byte in MS mangling. if (!s.empty() && s[0] == '\1') { s = s.substr(1); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3244f41..653f5a2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -301,11 +301,21 @@ endforeach() if(TEST_GNU_C) set(castxml_test_gccxml_extra_arguments --castxml-cc-gnu ${TEST_GNU_C}) castxml_test_gccxml_c(GNU-float128) + set(castxml_test_gccxml_custom_input GNU-float128) + set(castxml_test_gccxml_custom_start "") + castxml_test_gccxml_c(GNU-float128-nostart) + unset(castxml_test_gccxml_custom_start) + unset(castxml_test_gccxml_custom_input) unset(castxml_test_gccxml_extra_arguments) endif() if(TEST_GNU_CXX) set(castxml_test_gccxml_extra_arguments --castxml-cc-gnu ${TEST_GNU_CXX}) castxml_test_gccxml(GNU-float128) + set(castxml_test_gccxml_custom_input GNU-float128) + set(castxml_test_gccxml_custom_start "") + castxml_test_gccxml(GNU-float128-nostart) + unset(castxml_test_gccxml_custom_start) + unset(castxml_test_gccxml_custom_input) unset(castxml_test_gccxml_extra_arguments) endif() diff --git a/test/expect/gccxml.any.GNU-float128-nostart.xml.txt b/test/expect/gccxml.any.GNU-float128-nostart.xml.txt new file mode 100644 index 0000000..826d133 --- /dev/null +++ b/test/expect/gccxml.any.GNU-float128-nostart.xml.txt @@ -0,0 +1,5 @@ +^<\?xml version="1.0"\?> +<GCC_XML[^>]*> +.*<FundamentalType id="_[0-9]+" name="__float128" size="128" align="128"/>.* + <File id="f1" name=".*/test/input/GNU-float128.cxx"/> +</GCC_XML>$ diff --git a/test/expect/gccxml.any.GNU-float128.xml.txt b/test/expect/gccxml.any.GNU-float128.xml.txt index 2797894..c09de58 100644 --- a/test/expect/gccxml.any.GNU-float128.xml.txt +++ b/test/expect/gccxml.any.GNU-float128.xml.txt @@ -1,6 +1,6 @@ ^<\?xml version="1.0"\?> <GCC_XML[^>]*> - <Function id="_1" name="start" returns="_2" context="_3" location="f1:1" file="f1" line="1" mangled="[^"]+"> + <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"/> </Function> <FundamentalType id="_2" name="__float128" size="128" align="128"/> diff --git a/test/expect/gccxml.c89.GNU-float128-nostart.xml.txt b/test/expect/gccxml.c89.GNU-float128-nostart.xml.txt new file mode 100644 index 0000000..58d80c4 --- /dev/null +++ b/test/expect/gccxml.c89.GNU-float128-nostart.xml.txt @@ -0,0 +1,5 @@ +^<\?xml version="1.0"\?> +<GCC_XML[^>]*> +.*<FundamentalType id="_[0-9]+" name="__float128" size="128" align="128"/>.* + <File id="f1" name=".*/test/input/GNU-float128.c"/> +</GCC_XML>$ diff --git a/test/expect/gccxml.c89.GNU-float128.xml.txt b/test/expect/gccxml.c89.GNU-float128.xml.txt index 9263155..3e0272d 100644 --- a/test/expect/gccxml.c89.GNU-float128.xml.txt +++ b/test/expect/gccxml.c89.GNU-float128.xml.txt @@ -1,6 +1,6 @@ ^<\?xml version="1.0"\?> <GCC_XML[^>]*> - <Function id="_1" name="start" returns="_2" context="_3" location="f1:1" file="f1" line="1" mangled="[^"]+"> + <Function id="_1" name="start" returns="_2" context="_3" location="f1:1" file="f1" line="1" mangled="_Z5start"> <Argument type="_2" location="f1:1" file="f1" line="1"/> </Function> <FundamentalType id="_2" name="__float128" size="128" align="128"/> diff --git a/test/run.cmake b/test/run.cmake index 14f5f51..1b973b3 100644 --- a/test/run.cmake +++ b/test/run.cmake @@ -75,6 +75,10 @@ foreach(o result stdout stderr ${maybe_xml}) endif() endforeach() +if(maybe_xml AND actual_xml MATCHES "__castxml") + set(msg "xml contains disallowed text '__castxml'\n") +endif() + if(msg) if("$ENV{TEST_UPDATE}" AND expect_xml_file AND EXISTS "${xml}") set(update_xml "${actual_xml}") |