[clang] [clang] Remove an incorrect assertion in ConstantFoldAttrs (PR #105789)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 23 00:00:13 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Evaluating the attribute expression can be successful without resulting in a value. Namely, when the expression is of type void.
---
Full diff: https://github.com/llvm/llvm-project/pull/105789.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaAttr.cpp (+2-2)
- (modified) clang/test/SemaCXX/attr-annotate.cpp (+4)
``````````diff
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index a1724820472b59..51354963c0831e 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -439,8 +439,8 @@ bool Sema::ConstantFoldAttrArgs(const AttributeCommonInfo &CI,
Diag(Note.first, Note.second);
return false;
}
- assert(Eval.Val.hasValue());
- E = ConstantExpr::Create(Context, E, Eval.Val);
+ if (Eval.Val.hasValue())
+ E = ConstantExpr::Create(Context, E, Eval.Val);
}
return true;
diff --git a/clang/test/SemaCXX/attr-annotate.cpp b/clang/test/SemaCXX/attr-annotate.cpp
index 846ef4119f1d7c..ff538fee9cb3c7 100644
--- a/clang/test/SemaCXX/attr-annotate.cpp
+++ b/clang/test/SemaCXX/attr-annotate.cpp
@@ -134,3 +134,7 @@ constexpr int foldable_but_invalid() {
template <typename T> [[clang::annotate()]] void f2() {}
// expected-error at -1 {{'annotate' attribute takes at least 1 argument}}
}
+
+namespace test5 {
+ void bir [[clang::annotate("B", (void)1)]] ();
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/105789
More information about the cfe-commits
mailing list