Skip to content

Commit df8b785

Browse files
authored
[clang][bytecode] Narrow pointer in UO_Deref unary operators (#113089)
Otherwise we treat this like an array element even though we should treat it as a single object.
1 parent d80b9cf commit df8b785

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
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/lib/AST/ByteCode/Pointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx,
635635

636636
// Return the composite type.
637637
APValue Result;
638-
if (!Composite(getType(), *this, Result))
638+
if (!Composite(ResultType, *this, Result))
639639
return std::nullopt;
640640
return Result;
641641
}

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)