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

Discard the subexpr.

>From 811ce07c27a92a55642088f26560b4698e5bfc7f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com>
Date: Thu, 22 Aug 2024 12:54:27 +0200
Subject: [PATCH] [clang][Bytecode] Fix void unary * operators

Discard the subexpr.
---
 clang/lib/AST/ByteCode/Compiler.cpp | 2 +-
 clang/test/AST/ByteCode/invalid.cpp | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 10f3222726fd43..9d376641f9c5a3 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5145,7 +5145,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const 
UnaryOperator *E) {
     // We should already have a pointer when we get here.
     return this->delegate(SubExpr);
   case UO_Deref: // *x
-    if (DiscardResult)
+    if (DiscardResult || E->getType()->isVoidType())
       return this->discard(SubExpr);
     return this->visit(SubExpr);
   case UO_Not: // ~x
diff --git a/clang/test/AST/ByteCode/invalid.cpp 
b/clang/test/AST/ByteCode/invalid.cpp
index 522ad02f71ce07..3c142481f78119 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 
-fexperimental-new-constant-interpreter -verify %s
-// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -verify=ref %s
+// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 
-fexperimental-new-constant-interpreter -verify=expected,both %s
+// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -verify=ref,both %s
 
 namespace Throw {
 
@@ -65,4 +65,9 @@ namespace Casts {
                                                // ref-error {{must be 
initialized by a constant expression}} \
                                                // ref-note {{reinterpret_cast 
is not allowed}}
 
+  void func() {
+    struct B {};
+    B b;
+    (void)*reinterpret_cast<void*>(&b); // both-error {{indirection not 
permitted on operand of type 'void *'}}
+  }
 }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to