From: David Majnemer Date: Sun, 26 Jul 2015 09:02:21 +0000 (+0000) Subject: [Sema] Refactor AddAlignedAttr to reduce indentation X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a15ae4a506cfaaa75e342ba347d98bbb1675a765;p=clang [Sema] Refactor AddAlignedAttr to reduce indentation 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 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 4f8d7e8e4a..31ddd503af 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -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(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(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);