diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -372,6 +372,15 @@ QualType ResultTy, ArrayRef Args); + /// The maximum alignment, same as in llvm::Value. We duplicate them here + /// because that allows us not to duplicate the constants in clang code, + /// which we must to since we can't directly use the llvm constants. + /// + /// This is the greatest alignment value supported by load, store, and alloca + /// instructions, and global values. + static const unsigned MaxAlignmentExponent = 29; + static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent; + public: typedef OpaquePtr DeclGroupPtrTy; typedef OpaquePtr TemplateTy; diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3665,11 +3665,9 @@ return; } - // Alignment calculations can wrap around if it's greater than 2**29. - unsigned MaximumAlignment = 536870912; - if (I > MaximumAlignment) + if (I > Sema::MaximumAlignment) Diag(Arg->getExprLoc(), diag::warn_assume_aligned_too_great) - << Arg->getSourceRange() << MaximumAlignment; + << Arg->getSourceRange() << Sema::MaximumAlignment; } } } @@ -5394,11 +5392,9 @@ return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two) << Arg->getSourceRange(); - // Alignment calculations can wrap around if it's greater than 2**29. - unsigned MaximumAlignment = 536870912; - if (Result > MaximumAlignment) + if (Result > Sema::MaximumAlignment) Diag(TheCall->getBeginLoc(), diag::warn_assume_aligned_too_great) - << Arg->getSourceRange() << MaximumAlignment; + << Arg->getSourceRange() << Sema::MaximumAlignment; } if (NumArgs > 2) { diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1626,11 +1626,9 @@ return; } - // Alignment calculations can wrap around if it's greater than 2**29. - unsigned MaximumAlignment = 536870912; - if (I > MaximumAlignment) + if (I > Sema::MaximumAlignment) Diag(CI.getLoc(), diag::warn_assume_aligned_too_great) - << CI.getRange() << MaximumAlignment; + << CI.getRange() << Sema::MaximumAlignment; } if (OE) { @@ -3815,13 +3813,9 @@ } } - // Alignment calculations can wrap around if it's greater than 2**28. - unsigned MaxValidAlignment = - Context.getTargetInfo().getTriple().isOSBinFormatCOFF() ? 8192 - : 268435456; - if (AlignVal > MaxValidAlignment) { - Diag(AttrLoc, diag::err_attribute_aligned_too_great) << MaxValidAlignment - << E->getSourceRange(); + if (AlignVal > Sema::MaximumAlignment) { + Diag(AttrLoc, diag::err_attribute_aligned_too_great) + << Sema::MaximumAlignment << E->getSourceRange(); return; } diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -143,7 +143,7 @@ } Attribute Attribute::getWithAlignment(LLVMContext &Context, Align A) { - assert(A <= 0x40000000 && "Alignment too large."); + assert(A <= llvm::Value::MaximumAlignment && "Alignment too large."); return get(Context, Alignment, A.value()); } @@ -1525,7 +1525,7 @@ if (!Align) return *this; - assert(*Align <= 0x40000000 && "Alignment too large."); + assert(*Align <= llvm::Value::MaximumAlignment && "Alignment too large."); Attrs[Attribute::Alignment] = true; Alignment = Align;