Skip to content

Commit 4258998

Browse files
authored
[clang][bytecode] Only print ptr/reference types via toAPValue() (#137965)
Otherwise, convert them to an RValue to print them. This fixes the printing of e.g. complex values.
1 parent c2c0ef5 commit 4258998

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

clang/lib/AST/ByteCode/InterpFrame.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,18 @@ void InterpFrame::destroy(unsigned Idx) {
107107
template <typename T>
108108
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx,
109109
QualType Ty) {
110-
V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty);
110+
if constexpr (std::is_same_v<Pointer, T>) {
111+
if (Ty->isPointerOrReferenceType())
112+
V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty);
113+
else {
114+
if (std::optional<APValue> RValue = V.toRValue(ASTCtx, Ty))
115+
RValue->printPretty(OS, ASTCtx, Ty);
116+
else
117+
OS << "...";
118+
}
119+
} else {
120+
V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty);
121+
}
111122
}
112123

113124
static bool shouldSkipInBacktrace(const Function *F) {

clang/test/AST/ByteCode/constexpr-frame-describe.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ static_assert(bar.fail1<int>()); // both-error {{constant expression}} \
7979
static_assert(bar.fail2<int*, 42>()); // both-error {{constant expression}} \
8080
// both-note {{in call to 'bar.fail2<int *, 42>()'}}
8181
static_assert(bar.fail3(3, 4UL, bar, &bar)); // both-error {{constant expression}} \
82-
// expected-note {{in call to 'bar.fail3<int, unsigned long, Bar<int>, const Bar<int> *>(3, 4, &bar, &bar)'}} \
83-
// ref-note {{in call to 'bar.fail3<int, unsigned long, Bar<int>, const Bar<int> *>(3, 4, {}, &bar)'}}
82+
// both-note {{in call to 'bar.fail3<int, unsigned long, Bar<int>, const Bar<int> *>(3, 4, {}, &bar)'}}
8483

8584

8685

0 commit comments

Comments
 (0)