Skip to content

Commit 920eb8d

Browse files
committed
[clang] Remove an incorrect assertion in ConstantFoldAttrs
Evaluating the attribute expression can be successful without resulting in a value. Namely, when the expression is of type void.
1 parent bc860b4 commit 920eb8d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang/lib/Sema/SemaAttr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ bool Sema::ConstantFoldAttrArgs(const AttributeCommonInfo &CI,
439439
Diag(Note.first, Note.second);
440440
return false;
441441
}
442-
assert(Eval.Val.hasValue());
443-
E = ConstantExpr::Create(Context, E, Eval.Val);
442+
if (Eval.Val.hasValue())
443+
E = ConstantExpr::Create(Context, E, Eval.Val);
444444
}
445445

446446
return true;

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)