diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-04-10 06:40:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-10 06:40:54 +0200 |
commit | 02f923f8e4329995f2f0c512fa53f5e37e631933 (patch) | |
tree | 699c00d26fc51705bb81d2060de152510c19424a /clang/lib/AST/ByteCode/Pointer.cpp | |
parent | 5587932e20ff90ba8a28f3c9089e8b12e42b09b5 (diff) | |
download | llvm-02f923f8e4329995f2f0c512fa53f5e37e631933.zip llvm-02f923f8e4329995f2f0c512fa53f5e37e631933.tar.gz llvm-02f923f8e4329995f2f0c512fa53f5e37e631933.tar.bz2 |
[clang][bytecode] Classify function pointers as PT_Ptr (#135026)
The Pointer class already has the capability to be a function pointer,
but we still classifed function pointers as PT_FnPtr/FunctionPointer.
This means when converting from a Pointer to a FunctionPointer, we lost
the information of what the original Pointer pointed to.
Diffstat (limited to 'clang/lib/AST/ByteCode/Pointer.cpp')
-rw-r--r-- | clang/lib/AST/ByteCode/Pointer.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 5b52261..918a434 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -152,8 +152,15 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const { CharUnits::fromQuantity(asIntPointer().Value + this->Offset), Path, /*IsOnePastEnd=*/false, /*IsNullPtr=*/false); - if (isFunctionPointer()) - return asFunctionPointer().toAPValue(ASTCtx); + if (isFunctionPointer()) { + const FunctionPointer &FP = asFunctionPointer(); + if (const FunctionDecl *FD = FP.getFunction()->getDecl()) + return APValue(FD, CharUnits::fromQuantity(FP.getOffset() + Offset), {}, + /*OnePastTheEnd=*/false, /*IsNull=*/false); + return APValue(FP.getFunction()->getExpr(), + CharUnits::fromQuantity(FP.getOffset() + Offset), {}, + /*OnePastTheEnd=*/false, /*IsNull=*/false); + } if (isTypeidPointer()) { TypeInfoLValue TypeInfo(PointeeStorage.Typeid.TypePtr); @@ -379,6 +386,9 @@ std::string Pointer::toDiagnosticString(const ASTContext &Ctx) const { if (isIntegralPointer()) return (Twine("&(") + Twine(asIntPointer().Value + Offset) + ")").str(); + if (isFunctionPointer()) + return asFunctionPointer().toDiagnosticString(Ctx); + return toAPValue(Ctx).getAsString(Ctx, getType()); } |