[clang] 125aa10 - [clang][bytecode] Fix void unary * operators (#105640)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 22 05:05:22 PDT 2024
Author: Timm Baeder
Date: 2024-08-22T14:05:17+02:00
New Revision: 125aa10b3d645bd26523a1bc321bb2e6b1cf04e1
URL: https://github.com/llvm/llvm-project/commit/125aa10b3d645bd26523a1bc321bb2e6b1cf04e1
DIFF: https://github.com/llvm/llvm-project/commit/125aa10b3d645bd26523a1bc321bb2e6b1cf04e1.diff
LOG: [clang][bytecode] Fix void unary * operators (#105640)
Discard the subexpr.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/invalid.cpp
Removed:
################################################################################
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 *'}}
+ }
}
More information about the cfe-commits
mailing list