[cfe-commits] r162074 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/SemaCXX/pragma-pack.cpp unittests/Tooling/RecursiveASTVisitorTest.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Thu Aug 16 20:20:55 PDT 2012
Author: rsmith
Date: Thu Aug 16 22:20:55 2012
New Revision: 162074
URL: http://llvm.org/viewvc/llvm-project?rev=162074&view=rev
Log:
Don't forget to apply #pragma pack to partial and explicit specializations of
class templates. This fixes misalignment issues in llvm/Support/Endian.h when
built by Clang.
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaCXX/pragma-pack.cpp
cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=162074&r1=162073&r2=162074&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Aug 16 22:20:55 2012
@@ -5518,6 +5518,13 @@
if (Attr)
ProcessDeclAttributeList(S, Specialization, Attr);
+ // Add alignment attributes if necessary; these attributes are checked when
+ // the ASTContext lays out the structure.
+ if (TUK == TUK_Definition) {
+ AddAlignmentAttributesForRecord(Specialization);
+ AddMsStructLayoutForRecord(Specialization);
+ }
+
if (ModulePrivateLoc.isValid())
Diag(Specialization->getLocation(), diag::err_module_private_specialization)
<< (isPartialSpecialization? 1 : 0)
Modified: cfe/trunk/test/SemaCXX/pragma-pack.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/pragma-pack.cpp?rev=162074&r1=162073&r2=162074&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/pragma-pack.cpp (original)
+++ cfe/trunk/test/SemaCXX/pragma-pack.cpp Thu Aug 16 22:20:55 2012
@@ -32,3 +32,26 @@
int check[sizeof(Sub) == 13 ? 1 : -1];
}
+
+namespace llvm_support_endian {
+
+template<typename, bool> struct X;
+
+#pragma pack(push)
+#pragma pack(1)
+template<typename T> struct X<T, true> {
+ T t;
+};
+#pragma pack(pop)
+
+#pragma pack(push)
+#pragma pack(2)
+template<> struct X<long double, true> {
+ long double c;
+};
+#pragma pack(pop)
+
+int check1[__alignof(X<int, true>) == 1 ? 1 : -1];
+int check2[__alignof(X<long double, true>) == 2 ? 1 : -1];
+
+}
Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp?rev=162074&r1=162073&r2=162074&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp Thu Aug 16 22:20:55 2012
@@ -385,4 +385,11 @@
"int main() { Simple s; Simple t(s); }\n"));
}
+TEST(RecursiveASTVisitor, VisitsExtension) {
+ DeclRefExprVisitor Visitor;
+ Visitor.ExpectMatch("s", 1, 24);
+ EXPECT_TRUE(Visitor.runOver(
+ "int s = __extension__ (s);\n"));
+}
+
} // end namespace clang
More information about the cfe-commits
mailing list