]> granicus.if.org Git - clang/commitdiff
[Sema] The alignment of an object has an upper bound from the object file format
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 26 Jul 2015 01:48:59 +0000 (01:48 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 26 Jul 2015 01:48:59 +0000 (01:48 +0000)
Don't use the spelling of the alignment attribute to determine whether
or not an alignment amount makes sense.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243233 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/Sema/MicrosoftCompatibility.c

index 64e61b5c388e7ee1e9d5b048ad084d6fdbf67cc1..4f8d7e8e4af5f09e02c05fcb711c1d0179de83c3 100644 (file)
@@ -2985,7 +2985,7 @@ void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
   // C11 6.7.5p6:
   //   An alignment specification of zero has no effect.
   if (!(TmpAttr.isAlignas() && !Alignment)) {
-    if(!llvm::isPowerOf2_64(Alignment.getZExtValue())) {
+    if (!llvm::isPowerOf2_64(Alignment.getZExtValue())) {
       Diag(AttrLoc, diag::err_alignment_not_power_of_two)
         << E->getSourceRange();
       return;
@@ -3008,7 +3008,9 @@ void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
   }
 
   // Alignment calculations can wrap around if it's greater than 2**28.
-  unsigned MaxValidAlignment = TmpAttr.isDeclspec() ? 8192 : 268435456;
+  unsigned MaxValidAlignment =
+      Context.getTargetInfo().getTriple().isOSBinFormatCOFF() ? 8192
+                                                              : 268435456;
   if (Alignment.getZExtValue() > MaxValidAlignment) {
     Diag(AttrLoc, diag::err_attribute_aligned_too_great) << MaxValidAlignment
                                                          << E->getSourceRange();
index 010033bba00c622d99d6780a14f60759bcb90fe3..697d3f216637f625b0dad02c381bf0600477e5d5 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-compatibility
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-compatibility -triple i686-pc-win32
 
 enum ENUM1; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
 enum ENUM1 var1 = 3;