Skip to content

[clang][bytecode] Fix void unary * operators #105640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions clang/test/AST/ByteCode/invalid.cpp
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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 *'}}
}
}
Loading