Skip to content

Commit 227b32f

Browse files
authored
[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 #119125
1 parent 64927af commit 227b32f

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ Bug Fixes to Compiler Builtins
136136

137137
Bug Fixes to Attribute Support
138138
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139+
- Fixed crash when a parameter to the ``clang::annotate`` attribute evaluates to ``void``. See #GH119125
139140

140141
Bug Fixes to C++ Support
141142
^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaAttr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,6 @@ bool Sema::ConstantFoldAttrArgs(const AttributeCommonInfo &CI,
537537
Diag(Note.first, Note.second);
538538
return false;
539539
}
540-
assert(Eval.Val.hasValue());
541540
E = ConstantExpr::Create(Context, E, Eval.Val);
542541
}
543542

clang/test/CodeGenCXX/attr-annotate2.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,28 @@
44
// CHECK: @[[STR:.*]] = private unnamed_addr constant [45 x i8] c"_Generic selection expression should be fine\00", section "llvm.metadata"
55
// CHECK-NEXT: @[[FILENAME:.*]] = private unnamed_addr constant {{.*}}, section "llvm.metadata"
66
// CHECK-NEXT: @[[ARGS:.*]] = private unnamed_addr constant { i32 } zeroinitializer, section "llvm.metadata"
7+
// CHECK-NEXT: @[[STR2:.*]] = private unnamed_addr constant [14 x i8] c"void is undef\00", section "llvm.metadata"
8+
// CHECK-NEXT: @[[ARGS3:.*]] = private unnamed_addr constant { i8, i8, i32 } { i8 undef, i8 undef, i32 7 }, section "llvm.metadata"
9+
10+
711

812
// CHECK-LABEL: @_Z1fv(
913
// CHECK-NEXT: entry:
1014
// CHECK-NEXT: [[N:%.*]] = alloca i32, align 4
1115
// CHECK-NEXT: [[J:%.*]] = alloca i32, align 4
16+
// CHECK-NEXT: [[K:%.*]] = alloca i32, align 4
1217
// CHECK-NEXT: store i32 10, ptr [[N]], align 4
1318
// CHECK-NEXT: call void @llvm.var.annotation.p0.p0(ptr [[J]], ptr @[[STR]], ptr @[[FILENAME]], i32 {{.*}}, ptr @[[ARGS]])
1419
// CHECK-NEXT: store i32 0, ptr [[J]], align 4
20+
// CHECK-NEXT: call void @llvm.var.annotation.p0.p0(ptr [[K]], ptr @[[STR2]], ptr @[[FILENAME]], i32 {{.*}}, ptr @[[ARGS3]])
21+
// CHECK-NEXT: store i32 0, ptr [[K]], align 4
1522
// CHECK-NEXT: ret void
1623
//
1724
void f() {
1825
int n = 10;
1926
[[clang::annotate("_Generic selection expression should be fine", _Generic(n, int : 0, default : 1))]]
2027
int j = 0; // second arg should resolve to 0 fine
28+
29+
[[clang::annotate("void is undef", (void)2, (void)4, 7)]]
30+
int k = 0;
2131
}

clang/test/SemaCXX/attr-annotate.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,7 @@ constexpr int foldable_but_invalid() {
134134
template <typename T> [[clang::annotate()]] void f2() {}
135135
// expected-error@-1 {{'annotate' attribute takes at least 1 argument}}
136136
}
137+
138+
namespace test5 {
139+
void bir [[clang::annotate("B", (void)1)]] ();
140+
}

0 commit comments

Comments
 (0)