[flang-commits] [llvm] [flang] [clang-tools-extra] [clang] [compiler-rt] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

via flang-commits flang-commits at lists.llvm.org
Mon Nov 13 13:03:26 PST 2023


================
@@ -322,6 +322,66 @@ 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.
+    int AlignValue = ArgVal.getSExtValue();
----------------
smanna12 wrote:

with SExt, we can see this:
``
test/Sema/code_align.c:69:5: error: 'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive; got -9223372036854775808
    [[clang::code_align(9223372036854775808)]]
       ^
``
With ZExt, we can see correct value:
```
uint64_t AlignValue = ArgVal.getZExtValue();
test/Sema/code_align.c:69:5: error: 'code_align' attribute requires an integer argument which is a constant power of two between 1 and 4096 inclusive; got 9223372036854775808
     [[clang::code_align(9223372036854775808)]]
````

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


More information about the flang-commits mailing list