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

via flang-commits flang-commits at lists.llvm.org
Wed Nov 15 12:39:11 PST 2023


================
@@ -322,6 +322,90 @@ 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.
+    // Check if an expression resulting in a negative/positive cases that take
+    // more than 64 bits.
+    // Print the actual alignment value passing to the attribute if it is less
+    // than 64 bits otherwise print the expression.
+    if (ArgVal < CodeAlignAttr::MinimumAlignment ||
+        (ArgVal < CodeAlignAttr::MaximumAlignment && !ArgVal.isPowerOf2())) {
+      if (!ArgVal.trySExtValue()) {
----------------
smanna12 wrote:

@erichkeane, I tried your suggested change. But it is casing the assertion. Am i missing something? 
```
if (ArgVal < CodeAlignAttr::MinimumAlignment ||
        (ArgVal < CodeAlignAttr::MaximumAlignment && !ArgVal.isPowerOf2())) {
      if (std::optional<int64_t> Value = ArgVal.trySExtValue())
        Diag(CI.getLoc(), diag::err_attribute_power_of_two_in_range)
            << CI << CodeAlignAttr::MinimumAlignment
            << CodeAlignAttr::MaximumAlignment << E;
      else
        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 (std::optional<int64_t> Value = ArgVal.trySExtValue())
        Diag(CI.getLoc(), diag::err_attribute_power_of_two_in_range)
            << CI << CodeAlignAttr::MinimumAlignment
            << CodeAlignAttr::MaximumAlignment << E;
      else
        Diag(CI.getLoc(), diag::err_attribute_power_of_two_in_range)
            << CI << CodeAlignAttr::MinimumAlignment
            << CodeAlignAttr::MaximumAlignment << ArgVal.getZExtValue();
      return nullptr;
    }
```

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


More information about the flang-commits mailing list