llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> For void-types InitListExprs, we need to diagnose them as invalid. But only if we are _not_ discarding. --- Full diff: https://github.com/llvm/llvm-project/pull/105625.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+9-14) - (modified) clang/test/AST/ByteCode/literals.cpp (+1) ``````````diff diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 6d05f75131640a..10f3222726fd43 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -1318,15 +1318,6 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { template <class Emitter> bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits, const Expr *ArrayFiller, const Expr *E) { - - QualType QT = E->getType(); - - if (const auto *AT = QT->getAs<AtomicType>()) - QT = AT->getValueType(); - - if (QT->isVoidType()) - return this->emitInvalid(E); - // Handle discarding first. if (DiscardResult) { for (const Expr *Init : Inits) { @@ -1336,6 +1327,13 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits, return true; } + QualType QT = E->getType(); + if (const auto *AT = QT->getAs<AtomicType>()) + QT = AT->getValueType(); + + if (QT->isVoidType()) + return this->emitInvalid(E); + // Primitive values. if (std::optional<PrimType> T = classify(QT)) { assert(!DiscardResult); @@ -3251,12 +3249,9 @@ template <class Emitter> bool Compiler<Emitter>::visit(const Expr *E) { if (E->getType().isNull()) return false; - if (E->getType()->isVoidType()) - return this->discard(E); - // Create local variable to hold the return value. - if (!E->isGLValue() && !E->getType()->isAnyComplexType() && - !classify(E->getType())) { + if (!E->getType()->isVoidType() && !E->isGLValue() && + !E->getType()->isAnyComplexType() && !classify(E->getType())) { std::optional<unsigned> LocalIndex = allocateLocal(E); if (!LocalIndex) return false; diff --git a/clang/test/AST/ByteCode/literals.cpp b/clang/test/AST/ByteCode/literals.cpp index a46f6ed747ec2f..2329d4d973f01d 100644 --- a/clang/test/AST/ByteCode/literals.cpp +++ b/clang/test/AST/ByteCode/literals.cpp @@ -46,6 +46,7 @@ static_assert(Failed2 == 0, ""); // both-error {{not an integral constant expres // both-note {{initializer of 'Failed2' is not a constant expression}} const int x = *(volatile int*)0x1234; +static_assert((void{}, true), ""); namespace ScalarTypes { constexpr int ScalarInitInt = int(); `````````` </details> https://github.com/llvm/llvm-project/pull/105625 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits