[clang] bb770de - [clang][Interp] Reject void-typed InitListExprs
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 29 07:30:31 PDT 2024
Author: Timm Bäder
Date: 2024-04-29T16:30:12+02:00
New Revision: bb770deb9acf554a17ad49c0b3af9b8cf83ec221
URL: https://github.com/llvm/llvm-project/commit/bb770deb9acf554a17ad49c0b3af9b8cf83ec221
DIFF: https://github.com/llvm/llvm-project/commit/bb770deb9acf554a17ad49c0b3af9b8cf83ec221.diff
LOG: [clang][Interp] Reject void-typed InitListExprs
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 568a929c6a1693..0a93a6a198a9de 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1114,6 +1114,9 @@ bool ByteCodeExprGen<Emitter>::visitArrayElemInit(unsigned ElemIndex,
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
+ if (E->getType()->isVoidType())
+ return this->emitInvalid(E);
+
// Handle discarding first.
if (DiscardResult) {
for (const Expr *Init : E->inits()) {
diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp
index a4ae73e423e74c..a5bb9f1a19aaa7 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -611,3 +611,9 @@ namespace {
static_assert((g<int>(), true), "");
}
+
+namespace {
+ /// The InitListExpr here is of void type.
+ void bir [[clang::annotate("B", {1, 2, 3, 4})]] (); // both-error {{'annotate' attribute requires parameter 1 to be a constant expression}} \
+ // both-note {{subexpression not valid in a constant expression}}
+}
More information about the cfe-commits
mailing list