https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/107056
Instead of doing this ourselves, just rely on printing the APValue. >From 05f15c5c7c867cdb37f45c51e7d33fdcc527463e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Tue, 3 Sep 2024 09:58:06 +0200 Subject: [PATCH] [clang][bytecode] Print Pointers via APValue Instead of doing this ourselves, just rely on printing the APValue. --- clang/lib/AST/ByteCode/InterpFrame.cpp | 54 ------------------- .../AST/ByteCode/constexpr-frame-describe.cpp | 4 +- 2 files changed, 1 insertion(+), 57 deletions(-) diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 5e98444ef05a59..c75386eaeb4c7e 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -107,60 +107,6 @@ static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx, V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty); } -template <> -void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, - QualType Ty) { - if (P.isZero()) { - OS << "nullptr"; - return; - } - - auto printDesc = [&OS, &Ctx](const Descriptor *Desc) { - if (const auto *D = Desc->asDecl()) { - // Subfields or named values. - if (const auto *VD = dyn_cast<ValueDecl>(D)) { - OS << *VD; - return; - } - // Base classes. - if (isa<RecordDecl>(D)) - return; - } - // Temporary expression. - if (const auto *E = Desc->asExpr()) { - E->printPretty(OS, nullptr, Ctx.getPrintingPolicy()); - return; - } - llvm_unreachable("Invalid descriptor type"); - }; - - if (!Ty->isReferenceType()) - OS << "&"; - llvm::SmallVector<Pointer, 2> Levels; - for (Pointer F = P; !F.isRoot();) { - Levels.push_back(F); - F = F.isArrayElement() ? F.getArray().expand() : F.getBase(); - } - - // Drop the first pointer since we print it unconditionally anyway. - if (!Levels.empty()) - Levels.erase(Levels.begin()); - - printDesc(P.getDeclDesc()); - for (const auto &It : Levels) { - if (It.inArray()) { - OS << "[" << It.expand().getIndex() << "]"; - continue; - } - if (auto Index = It.getIndex()) { - OS << " + " << Index; - continue; - } - OS << "."; - printDesc(It.getFieldDesc()); - } -} - void InterpFrame::describe(llvm::raw_ostream &OS) const { // We create frames for builtin functions as well, but we can't reliably // diagnose them. The 'in call to' diagnostics for them add no value to the diff --git a/clang/test/AST/ByteCode/constexpr-frame-describe.cpp b/clang/test/AST/ByteCode/constexpr-frame-describe.cpp index a0ae046fc01786..d875d8730b7d6d 100644 --- a/clang/test/AST/ByteCode/constexpr-frame-describe.cpp +++ b/clang/test/AST/ByteCode/constexpr-frame-describe.cpp @@ -84,7 +84,6 @@ static_assert(bar.fail3(3, 4UL, bar, &bar)); // both-error {{constant expression -/// FIXME: Bound member pointer printing doesn't work right, see the last parameter to MemPtr(). struct MemPtrTest { int n; void f(); @@ -94,5 +93,4 @@ constexpr int MemPtr(int (MemPtrTest::*a), void (MemPtrTest::*b)(), int &c) { return c; // both-note {{read of non-constexpr variable 'mpt'}} } static_assert(MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.*&MemPtrTest::n), ""); // both-error {{constant expression}} \ - // expected-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt)'}} \ - // ref-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.n)'}} + // both-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.n)'}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits