r214698 - AST: Propagate 'AlignIsRequired' though many levels of typedefs

David Majnemer david.majnemer at gmail.com
Sun Aug 3 22:11:02 PDT 2014


Author: majnemer
Date: Mon Aug  4 00:11:01 2014
New Revision: 214698

URL: http://llvm.org/viewvc/llvm-project?rev=214698&view=rev
Log:
AST: Propagate 'AlignIsRequired' though many levels of typedefs

A typedef of a typedef should have AlignIsRequired if *either* typedef
has an AlignAttr attached to it.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=214698&r1=214697&r2=214698&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Aug  4 00:11:01 2014
@@ -1707,8 +1707,10 @@ TypeInfo ASTContext::getTypeInfoImpl(con
     if (unsigned AttrAlign = Typedef->getMaxAlignment()) {
       Align = AttrAlign;
       AlignIsRequired = true;
-    } else
+    } else {
       Align = Info.Align;
+      AlignIsRequired = Info.AlignIsRequired;
+    }
     Width = Info.Width;
     break;
   }

Modified: cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp?rev=214698&r1=214697&r2=214698&view=diff
==============================================================================
--- cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp (original)
+++ cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp Mon Aug  4 00:11:01 2014
@@ -684,6 +684,34 @@ struct PC {
 // CHECK-X64-NEXT:      | [sizeof=16, align=8
 // CHECK-X64-NEXT:      |  nvsize=12, nvalign=8]
 
+typedef PB PD;
+
+#pragma pack(push, 1)
+struct PE {
+  char a;
+  PD x;
+};
+#pragma pack(pop)
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK:         0 | struct PE
+// CHECK-NEXT:    0 |   char a
+// CHECK-NEXT:    8 |   struct PA x
+// CHECK-NEXT:    8 |     int c
+// CHECK-NEXT:      |   [sizeof=4, align=4
+// CHECK-NEXT:      |    nvsize=4, nvalign=4]
+// CHECK-NEXT:      | [sizeof=16, align=8
+// CHECK-NEXT:      |  nvsize=12, nvalign=8]
+// CHECK-X64: *** Dumping AST Record Layout
+// CHECK-X64:         0 | struct PE
+// CHECK-X64-NEXT:    0 |   char a
+// CHECK-X64-NEXT:    8 |   struct PA x
+// CHECK-X64-NEXT:    8 |     int c
+// CHECK-X64-NEXT:      |   [sizeof=4, align=4
+// CHECK-X64-NEXT:      |    nvsize=4, nvalign=4]
+// CHECK-X64-NEXT:      | [sizeof=16, align=8
+// CHECK-X64-NEXT:      |  nvsize=12, nvalign=8]
+
 typedef int __declspec(align(2)) QA;
 #pragma pack(push, 1)
 struct QB {
@@ -768,6 +796,7 @@ sizeof(RE)+
 sizeof(ND)+
 sizeof(OD)+
 sizeof(PC)+
+sizeof(PE)+
 sizeof(QB)+
 sizeof(QC)+
 sizeof(QD)+





More information about the cfe-commits mailing list