Skip to content

Commit 9ad54be

Browse files
committed
[clang][bytecode] Narrow pointer in UO_Deref unary operators
Otherwise we treat this like an array element even though we should treat it as a single object.
1 parent 490b7d1 commit 9ad54be

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5738,9 +5738,17 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
57385738
// We should already have a pointer when we get here.
57395739
return this->delegate(SubExpr);
57405740
case UO_Deref: // *x
5741-
if (DiscardResult)
5741+
if (DiscardResult) {
5742+
// assert(false);
57425743
return this->discard(SubExpr);
5743-
return this->visit(SubExpr);
5744+
}
5745+
5746+
if (!this->visit(SubExpr))
5747+
return false;
5748+
if (classifyPrim(SubExpr) == PT_Ptr)
5749+
return this->emitNarrowPtr(E);
5750+
return true;
5751+
57445752
case UO_Not: // ~x
57455753
if (!T)
57465754
return this->emitError(E);

clang/test/AST/ByteCode/cxx98.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ _Static_assert(a == 0, ""); // both-error {{static assertion expression is not a
5454
struct SelfReference { SelfReference &r; };
5555
extern SelfReference self_reference_1;
5656
SelfReference self_reference_2 = {self_reference_1};
57+
58+
struct PR65784s{
59+
int *ptr;
60+
} const PR65784[] = {(int *)""};
61+
PR65784s PR65784f() { return *PR65784; }

0 commit comments

Comments
 (0)