r243242 - [Sema] Refactor AddAlignedAttr to reduce indentation

David Majnemer david.majnemer at gmail.com
Sun Jul 26 02:02:21 PDT 2015


Author: majnemer
Date: Sun Jul 26 04:02:21 2015
New Revision: 243242

URL: http://llvm.org/viewvc/llvm-project?rev=243242&view=rev
Log:
[Sema] Refactor AddAlignedAttr to reduce indentation

No functionality change intended, just a tidy-up.

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=243242&r1=243241&r2=243242&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Jul 26 04:02:21 2015
@@ -2857,7 +2857,7 @@ void Sema::AddAlignValueAttr(SourceRange
   }
 
   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 At
   }
 
   // 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 At
   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);





More information about the cfe-commits mailing list