Author: Timm Baeder
Date: 2026-02-10T11:44:26+01:00
New Revision: af74bc96c2d0ed892062d54f05ee6699bcecc72e

URL: 
https://github.com/llvm/llvm-project/commit/af74bc96c2d0ed892062d54f05ee6699bcecc72e
DIFF: 
https://github.com/llvm/llvm-project/commit/af74bc96c2d0ed892062d54f05ee6699bcecc72e.diff

LOG: [clang][bytecode] Improve rejecting UnaryExprOrTypeTraitExprs (#180710)

Some of them work just fine, even if the expression contains errors.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/test/AST/ByteCode/invalid.cpp
    clang/test/SemaCXX/alignof-sizeof-reference.cpp

Removed: 
    


################################################################################
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

Reply via email to