[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 6 09:34:24 PST 2023


================
@@ -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();
----------------
smanna12 wrote:

Thank you @AaronBallman for the suggestion. I have updated source code to pass the calculated alignment value https://github.com/llvm/llvm-project/pull/70762/commits/4c40ce27e81ae40f05aeabb513881032c04feb92


https://github.com/llvm/llvm-project/pull/70762


More information about the cfe-commits mailing list