OSDN Git Service

Partially revert "[IR] Attribute/AttrBuilder: use Value::MaximumAlignment magic constant"
authorRoman Lebedev <lebedev.ri@gmail.com>
Thu, 23 Jan 2020 20:30:09 +0000 (23:30 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Thu, 23 Jan 2020 20:30:42 +0000 (23:30 +0300)
Apparently makes bots angry.

This reverts commit d096f8d306b2b16a25f65ffb70849ca7963a0dac.

clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclAttr.cpp

index 92d964d..fae1ade 100644 (file)
@@ -372,15 +372,6 @@ class Sema final {
                                       QualType ResultTy,
                                       ArrayRef<QualType> 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<DeclGroupRef> DeclGroupPtrTy;
   typedef OpaquePtr<TemplateName> TemplateTy;
index 1539f33..1f36156 100644 (file)
@@ -5373,9 +5373,11 @@ bool Sema::SemaBuiltinAssumeAligned(CallExpr *TheCall) {
       return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two)
              << Arg->getSourceRange();
 
-    if (Result > Sema::MaximumAlignment)
+    // Alignment calculations can wrap around if it's greater than 2**29.
+    unsigned MaximumAlignment = 536870912;
+    if (Result > MaximumAlignment)
       Diag(TheCall->getBeginLoc(), diag::warn_assume_aligned_too_great)
-          << Arg->getSourceRange() << Sema::MaximumAlignment;
+          << Arg->getSourceRange() << MaximumAlignment;
   }
 
   if (NumArgs > 2) {
index b404b45..8aff975 100644 (file)
@@ -3810,9 +3810,13 @@ void Sema::AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
     }
   }
 
-  if (AlignVal > Sema::MaximumAlignment) {
+  // 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)
-        << Sema::MaximumAlignment << E->getSourceRange();
+        << MaxValidAlignment << E->getSourceRange();
     return;
   }