[cfe-commits] r126059 - in /cfe/trunk: lib/AST/ASTContext.cpp test/Sema/struct-packed-align.c

Chris Lattner sabre at nondot.org
Sat Feb 19 14:55:41 PST 2011


Author: lattner
Date: Sat Feb 19 16:55:41 2011
New Revision: 126059

URL: http://llvm.org/viewvc/llvm-project?rev=126059&view=rev
Log:
Fix PR9253, allowing attribute(aligned) to reduce the alignment of
a typedef.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/Sema/struct-packed-align.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=126059&r1=126058&r2=126059&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat Feb 19 16:55:41 2011
@@ -882,7 +882,13 @@
     const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl();
     std::pair<uint64_t, unsigned> Info
       = getTypeInfo(Typedef->getUnderlyingType().getTypePtr());
-    Align = std::max(Typedef->getMaxAlignment(), Info.second);
+    // If the typedef has an aligned attribute on it, it overrides any computed
+    // alignment we have.  This violates the GCC documentation (which says that
+    // attribute(aligned) can only round up) but matches its implementation.
+    if (unsigned AttrAlign = Typedef->getMaxAlignment())
+      Align = AttrAlign;
+    else
+      Align = Info.second;
     Width = Info.first;
     break;
   }

Modified: cfe/trunk/test/Sema/struct-packed-align.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/struct-packed-align.c?rev=126059&r1=126058&r2=126059&view=diff
==============================================================================
--- cfe/trunk/test/Sema/struct-packed-align.c (original)
+++ cfe/trunk/test/Sema/struct-packed-align.c Sat Feb 19 16:55:41 2011
@@ -117,3 +117,18 @@
 
 extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1];
 extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1];
+
+// Attribute aligned can round down typedefs.  PR9253
+typedef long long  __attribute__((aligned(1))) nt;
+
+struct nS {
+  char buf_nr;
+  nt start_lba;
+};
+
+extern int n1[sizeof(struct nS) == 9 ? 1 : -1];
+extern int n2[__alignof(struct nS) == 1 ? 1 : -1];
+
+
+
+





More information about the cfe-commits mailing list