[Sema] Introduce MaximumAlignment value, to be used instead of magical constants
There is llvm::Value::MaximumAlignment, which is numerically
equivalent to these constants, but we can't use it directly
because we can't include llvm IR headers in clang Sema.
So instead, copy-paste the constant, and fixup the places to use it.
This was initially reviewed in https://reviews.llvm.org/D72998
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 8ad981f..e097ec0 100644
--- 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) {
@@ -3816,13 +3814,12 @@
}
}
- // Alignment calculations can wrap around if it's greater than 2**28.
- unsigned MaxValidAlignment =
- Context.getTargetInfo().getTriple().isOSBinFormatCOFF() ? 8192
- : 268435456;
- if (AlignVal > MaxValidAlignment) {
+ unsigned MaximumAlignment = Sema::MaximumAlignment;
+ if (Context.getTargetInfo().getTriple().isOSBinFormatCOFF())
+ MaximumAlignment = std::min(MaximumAlignment, 8192u);
+ if (AlignVal > MaximumAlignment) {
Diag(AttrLoc, diag::err_attribute_aligned_too_great)
- << MaxValidAlignment << E->getSourceRange();
+ << MaximumAlignment << E->getSourceRange();
return;
}