]> granicus.if.org Git - clang/commitdiff
[Sema] Refactor AddAlignedAttr to reduce indentation
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 26 Jul 2015 09:02:21 +0000 (09:02 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 26 Jul 2015 09:02:21 +0000 (09:02 +0000)
No functionality change intended, just a tidy-up.

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

lib/Sema/SemaDeclAttr.cpp

index 4f8d7e8e4af5f09e02c05fcb711c1d0179de83c3..31ddd503af9fdd3e4c7eeb3cc14850bf231e1bcb 100644 (file)
@@ -2857,7 +2857,7 @@ void Sema::AddAlignValueAttr(SourceRange AttrRange, Decl *D, Expr *E,
   }
 
   if (!E->isValueDependent()) {
-    llvm::APSInt Alignment(32);
+    llvm::APSInt Alignment;
     ExprResult ICE
       = VerifyIntegerConstantExpression(E, &Alignment,
           diag::err_align_value_attribute_argument_not_int,
@@ -2971,7 +2971,7 @@ void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
   }
 
   // FIXME: Cache the number on the Attr object?
-  llvm::APSInt Alignment(32);
+  llvm::APSInt Alignment;
   ExprResult ICE
     = VerifyIntegerConstantExpression(E, &Alignment,
         diag::err_aligned_attribute_argument_not_int,
@@ -2979,44 +2979,44 @@ void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
   if (ICE.isInvalid())
     return;
 
+  uint64_t AlignVal = Alignment.getZExtValue();
+
   // C++11 [dcl.align]p2:
   //   -- if the constant expression evaluates to zero, the alignment
   //      specifier shall have no effect
   // 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(AlignVal)) {
       Diag(AttrLoc, diag::err_alignment_not_power_of_two)
         << E->getSourceRange();
       return;
     }
-    if (Context.getTargetInfo().isTLSSupported()) {
-      if (unsigned MaxAlign = Context.getTargetInfo().getMaxTLSAlign()) {
-        if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
-          if (VD->getTLSKind()) {
-            CharUnits MaxAlignChars = Context.toCharUnitsFromBits(MaxAlign);
-            if (Alignment.getSExtValue() > MaxAlignChars.getQuantity()) {
-              Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
-                << (unsigned)Alignment.getZExtValue() << VD
-                << (unsigned)MaxAlignChars.getQuantity();
-              return;
-            }
-          }
-        }
-      }
-    }
   }
 
   // Alignment calculations can wrap around if it's greater than 2**28.
   unsigned MaxValidAlignment =
       Context.getTargetInfo().getTriple().isOSBinFormatCOFF() ? 8192
                                                               : 268435456;
-  if (Alignment.getZExtValue() > MaxValidAlignment) {
+  if (AlignVal > MaxValidAlignment) {
     Diag(AttrLoc, diag::err_attribute_aligned_too_great) << MaxValidAlignment
                                                          << E->getSourceRange();
     return;
   }
 
+  if (Context.getTargetInfo().isTLSSupported()) {
+    unsigned MaxTLSAlign =
+        Context.toCharUnitsFromBits(Context.getTargetInfo().getMaxTLSAlign())
+            .getQuantity();
+    auto *VD = dyn_cast<VarDecl>(D);
+    if (MaxTLSAlign && AlignVal > MaxTLSAlign && VD &&
+        VD->getTLSKind() != VarDecl::TLS_None) {
+      Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
+          << (unsigned)AlignVal << VD << MaxTLSAlign;
+      return;
+    }
+  }
+
   AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context, true,
                                                 ICE.get(), SpellingListIndex);
   AA->setPackExpansion(IsPackExpansion);