From c73745c944318e711f751fdd0d85e9d1efe740c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Wed, 30 Apr 2025 16:00:54 +0200 Subject: [PATCH] [clang][bytecode] Only print ptr/reference types via toAPValue() Otherwise, convert them to an RValue to print them. This fixes the printing of e.g. complex values. --- clang/lib/AST/ByteCode/InterpFrame.cpp | 13 ++++++++++++- .../test/AST/ByteCode/constexpr-frame-describe.cpp | 3 +-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 1a6e271c78d6f..e4bd4a6ba7656 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -107,7 +107,18 @@ void InterpFrame::destroy(unsigned Idx) { template static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx, QualType Ty) { - V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty); + if constexpr (std::is_same_v) { + if (Ty->isPointerOrReferenceType()) + V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty); + else { + if (std::optional RValue = V.toRValue(ASTCtx, Ty)) + RValue->printPretty(OS, ASTCtx, Ty); + else + OS << "..."; + } + } else { + V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty); + } } static bool shouldSkipInBacktrace(const Function *F) { diff --git a/clang/test/AST/ByteCode/constexpr-frame-describe.cpp b/clang/test/AST/ByteCode/constexpr-frame-describe.cpp index d875d8730b7d6..1b19a7af0663b 100644 --- a/clang/test/AST/ByteCode/constexpr-frame-describe.cpp +++ b/clang/test/AST/ByteCode/constexpr-frame-describe.cpp @@ -79,8 +79,7 @@ static_assert(bar.fail1()); // both-error {{constant expression}} \ static_assert(bar.fail2()); // both-error {{constant expression}} \ // both-note {{in call to 'bar.fail2()'}} static_assert(bar.fail3(3, 4UL, bar, &bar)); // both-error {{constant expression}} \ - // expected-note {{in call to 'bar.fail3, const Bar *>(3, 4, &bar, &bar)'}} \ - // ref-note {{in call to 'bar.fail3, const Bar *>(3, 4, {}, &bar)'}} + // both-note {{in call to 'bar.fail3, const Bar *>(3, 4, {}, &bar)'}}