================ @@ -322,6 +322,50 @@ 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(); + + int align_value = ArgVal.getSExtValue(); + if (align_value < CodeAlignAttr::getMinValue() || + align_value > CodeAlignAttr::getMaxValue() || !ArgVal.isPowerOf2()) { + Diag(CI.getLoc(), diag::err_attribute_power_of_two_in_range) + << CI << CodeAlignAttr::getMinValue() << CodeAlignAttr::getMaxValue(); ---------------- AaronBallman wrote:
```suggestion int AlignValue = ArgVal.getSExtValue(); if (AlignValue < CodeAlignAttr::getMinValue() || AlignValue > CodeAlignAttr::getMaxValue() || !ArgVal.isPowerOf2()) { Diag(CI.getLoc(), diag::err_attribute_power_of_two_in_range) << CI << CodeAlignAttr::getMinValue() << CodeAlignAttr::getMaxValue(); ``` It would be good to also pass in the alignment value we calculated as part of the diagnostic (because it can be a constant expression, the actual value may not be obvious from the code snippet). 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