https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/180710
>From 123d06900b7d6dbba7074c7b72eaf0cd4fa9f4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Tue, 10 Feb 2026 10:53:09 +0100 Subject: [PATCH] [clang][bytecode] Improve rejecting UnaryExprOrTypeTraitExprs Some of them work just fine, even if the expression contains errors. --- clang/lib/AST/ByteCode/Compiler.cpp | 9 ++++++--- clang/test/AST/ByteCode/invalid.cpp | 6 ++++++ clang/test/SemaCXX/alignof-sizeof-reference.cpp | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 526e1aee9ce3d..7aa7a8d75c8e1 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -2256,9 +2256,6 @@ template <class Emitter> bool Compiler<Emitter>::VisitUnaryExprOrTypeTraitExpr( const UnaryExprOrTypeTraitExpr *E) { - if (E->containsErrors()) - return false; - UnaryExprOrTypeTrait Kind = E->getKind(); const ASTContext &ASTCtx = Ctx.getASTContext(); @@ -2333,6 +2330,9 @@ bool Compiler<Emitter>::VisitUnaryExprOrTypeTraitExpr( // Argument is an expression, not a type. const Expr *Arg = E->getArgumentExpr()->IgnoreParens(); + if (Arg->getType()->isDependentType()) + return false; + // The kinds of expressions that we have special-case logic here for // should be kept up to date with the special checks for those // expressions in Sema. @@ -2356,6 +2356,9 @@ bool Compiler<Emitter>::VisitUnaryExprOrTypeTraitExpr( } if (Kind == UETT_VectorElements) { + if (E->containsErrors()) + return false; + if (const auto *VT = E->getTypeOfArgument()->getAs<VectorType>()) return this->emitConst(VT->getNumElements(), E); assert(E->getTypeOfArgument()->isSizelessVectorType()); diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp index 4979e52e0d666..497f193c5dd82 100644 --- a/clang/test/AST/ByteCode/invalid.cpp +++ b/clang/test/AST/ByteCode/invalid.cpp @@ -171,5 +171,11 @@ constexpr int invalidUnaryOrTypeTrait() { static_assert(invalidUnaryOrTypeTrait() == 11, ""); // both-error {{not an integral constant expression}} +constexpr int invalidUnaryOrTypeTrait2() { + return alignof * 10; // both-error {{indirection requires pointer operand}} \ + // both-warning {{'alignof' applied to an expression is a GNU extension}} +} + /// Pointer::toRValue() of a function type. void foo() { *(void (*)()) ""; } // both-warning {{expression result unused}} + diff --git a/clang/test/SemaCXX/alignof-sizeof-reference.cpp b/clang/test/SemaCXX/alignof-sizeof-reference.cpp index 3e37d615bbcf5..c5de165d38c77 100644 --- a/clang/test/SemaCXX/alignof-sizeof-reference.cpp +++ b/clang/test/SemaCXX/alignof-sizeof-reference.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter struct s0; // expected-note {{forward declaration}} char ar[sizeof(s0&)]; // expected-error {{invalid application of 'sizeof' to an incomplete type}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
