[clang] 733a92d - [clang][bytecode] Print Pointers via APValue (#107056)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 3 02:07:22 PDT 2024
Author: Timm Baeder
Date: 2024-09-03T11:07:19+02:00
New Revision: 733a92d7bced7119986a93a1b4e1c760f92b9583
URL: https://github.com/llvm/llvm-project/commit/733a92d7bced7119986a93a1b4e1c760f92b9583
DIFF: https://github.com/llvm/llvm-project/commit/733a92d7bced7119986a93a1b4e1c760f92b9583.diff
LOG: [clang][bytecode] Print Pointers via APValue (#107056)
Instead of doing this ourselves, just rely on printing the APValue.
Added:
Modified:
clang/lib/AST/ByteCode/InterpFrame.cpp
clang/test/AST/ByteCode/constexpr-frame-describe.cpp
Removed:
################################################################################
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)'}}
More information about the cfe-commits
mailing list