================
@@ -322,6 +322,81 @@ static Attr *handleUnlikely(Sema &S, Stmt *St, const 
ParsedAttr &A,
   return ::new (S.Context) UnlikelyAttr(S.Context, A);
 }
 
+CodeAlignAttr *Sema::BuildCodeAlignAttr(const AttributeCommonInfo &CI,
+                                        Expr *E) {
+  if (!E->isValueDependent()) {
+    llvm::APSInt ArgVal;
+    ExprResult Res = VerifyIntegerConstantExpression(E, &ArgVal);
+    if (Res.isInvalid())
+      return nullptr;
+    E = Res.get();
+
+    // This attribute requires an integer argument which is a constant power of
+    // two between 1 and 4096 inclusive.
+    if (ArgVal < CodeAlignAttr::MinimumAlignment ||
+        (ArgVal < CodeAlignAttr::MaximumAlignment && !ArgVal.isPowerOf2())) {
+      Diag(CI.getLoc(), diag::err_attribute_power_of_two_in_range)
+          << CI << CodeAlignAttr::MinimumAlignment
+          << CodeAlignAttr::MaximumAlignment << ArgVal.getSExtValue();
+      return nullptr;
+    }
+
+    if (ArgVal > CodeAlignAttr::MaximumAlignment) {
+      if (ArgVal > std::numeric_limits<int32_t>::max() &&
----------------
erichkeane wrote:

This isn't a great solution either.  This results in us lying to users.  
Additionally, we have no problem with less than 64 bits.

Also note, you have the same problem with something sufficiently negative as 
well.  Part of the problem is we only have diagnostic overloads for `<<` up to 
'long long'.  I might suggest printing the expression instead if 
`tryGetSExtValue` fails.

https://github.com/llvm/llvm-project/pull/70762
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to