[clang] 227b32f - [clang] Remove an incorrect assertion in ConstantFoldAttrs (#105789)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 4 03:58:49 PST 2025
Author: Timm Baeder
Date: 2025-02-04T12:58:44+01:00
New Revision: 227b32f6a1329c449f1222a42471190eededa433
URL: https://github.com/llvm/llvm-project/commit/227b32f6a1329c449f1222a42471190eededa433
DIFF: https://github.com/llvm/llvm-project/commit/227b32f6a1329c449f1222a42471190eededa433.diff
LOG: [clang] Remove an incorrect assertion in ConstantFoldAttrs (#105789)
Evaluating the attribute expression can be successful without resulting
in a value. Namely, when the expression is of type void.
Fixes https://github.com/llvm/llvm-project/issues/119125
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaAttr.cpp
clang/test/CodeGenCXX/attr-annotate2.cpp
clang/test/SemaCXX/attr-annotate.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 33a37bdf3f328a..90ba5e61d03fec 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -136,6 +136,7 @@ Bug Fixes to Compiler Builtins
Bug Fixes to Attribute Support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ - Fixed crash when a parameter to the ``clang::annotate`` attribute evaluates to ``void``. See #GH119125
Bug Fixes to C++ Support
^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 6907fa91e28c20..defdda17c32ded 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -537,7 +537,6 @@ bool Sema::ConstantFoldAttrArgs(const AttributeCommonInfo &CI,
Diag(Note.first, Note.second);
return false;
}
- assert(Eval.Val.hasValue());
E = ConstantExpr::Create(Context, E, Eval.Val);
}
diff --git a/clang/test/CodeGenCXX/attr-annotate2.cpp b/clang/test/CodeGenCXX/attr-annotate2.cpp
index 1c9c39c9efb83b..0b57af1b42a05a 100644
--- a/clang/test/CodeGenCXX/attr-annotate2.cpp
+++ b/clang/test/CodeGenCXX/attr-annotate2.cpp
@@ -4,18 +4,28 @@
// CHECK: @[[STR:.*]] = private unnamed_addr constant [45 x i8] c"_Generic selection expression should be fine\00", section "llvm.metadata"
// CHECK-NEXT: @[[FILENAME:.*]] = private unnamed_addr constant {{.*}}, section "llvm.metadata"
// CHECK-NEXT: @[[ARGS:.*]] = private unnamed_addr constant { i32 } zeroinitializer, section "llvm.metadata"
+// CHECK-NEXT: @[[STR2:.*]] = private unnamed_addr constant [14 x i8] c"void is undef\00", section "llvm.metadata"
+// CHECK-NEXT: @[[ARGS3:.*]] = private unnamed_addr constant { i8, i8, i32 } { i8 undef, i8 undef, i32 7 }, section "llvm.metadata"
+
+
// CHECK-LABEL: @_Z1fv(
// CHECK-NEXT: entry:
// CHECK-NEXT: [[N:%.*]] = alloca i32, align 4
// CHECK-NEXT: [[J:%.*]] = alloca i32, align 4
+// CHECK-NEXT: [[K:%.*]] = alloca i32, align 4
// CHECK-NEXT: store i32 10, ptr [[N]], align 4
// CHECK-NEXT: call void @llvm.var.annotation.p0.p0(ptr [[J]], ptr @[[STR]], ptr @[[FILENAME]], i32 {{.*}}, ptr @[[ARGS]])
// CHECK-NEXT: store i32 0, ptr [[J]], align 4
+// CHECK-NEXT: call void @llvm.var.annotation.p0.p0(ptr [[K]], ptr @[[STR2]], ptr @[[FILENAME]], i32 {{.*}}, ptr @[[ARGS3]])
+// CHECK-NEXT: store i32 0, ptr [[K]], align 4
// CHECK-NEXT: ret void
//
void f() {
int n = 10;
[[clang::annotate("_Generic selection expression should be fine", _Generic(n, int : 0, default : 1))]]
int j = 0; // second arg should resolve to 0 fine
+
+ [[clang::annotate("void is undef", (void)2, (void)4, 7)]]
+ int k = 0;
}
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)]] ();
+}
More information about the cfe-commits
mailing list