https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/200394

None

>From 7dea41b2eab29b6a6fb0a421dd3724db5046a99a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Fri, 29 May 2026 15:15:10 +0200
Subject: [PATCH] [clang][bytecode] Reject invalid UnaryOperators

---
 clang/lib/AST/ByteCode/Compiler.cpp |  3 +++
 clang/test/AST/ByteCode/invalid.cpp | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index f339d9a41ac2e..082345f1f1e16 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -7109,6 +7109,9 @@ static uint32_t getBitWidth(const Expr *E) {
 
 template <class Emitter>
 bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
+  if (E->containsErrors())
+    return false;
+
   const Expr *SubExpr = E->getSubExpr();
   if (SubExpr->getType()->isAnyComplexType())
     return this->VisitComplexUnaryOperator(E);
diff --git a/clang/test/AST/ByteCode/invalid.cpp 
b/clang/test/AST/ByteCode/invalid.cpp
index 9f157db889a22..9513645a74794 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -188,3 +188,13 @@ namespace InvalidCallExpr {
     return true;
   }
 }
+
+namespace InvalidUnaryOperator {
+  typedef struct {} S;
+  void foo() {
+    S *s = (S *)malloc(sizeof(*s)); // both-error {{use of undeclared 
identifier 'malloc'}}
+    S *&sref = s;
+    for (int i = 0; i < 2; sref++)
+      ;
+  }
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to