Skip to content

[clang][bytecode][NFC] Implement MemberPointer::toDiagnosticString() #106825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2024

Conversation

tbaederr
Copy link
Contributor

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Aug 31, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 31, 2024

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/106825.diff

3 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Interp.h (+2-2)
  • (modified) clang/lib/AST/ByteCode/MemberPointer.h (+6-6)
  • (modified) clang/lib/AST/ByteCode/Opcodes.td (+2-2)
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index aa790a71a6b476..13884ad6f64b63 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1045,7 +1045,7 @@ inline bool CmpHelperEQ<MemberPointer>(InterpState &S, CodePtr OpPC,
     if (MP.isWeak()) {
       const SourceInfo &Loc = S.Current->getSource(OpPC);
       S.FFDiag(Loc, diag::note_constexpr_mem_pointer_weak_comparison)
-          << MP.getMemberFunction();
+          << MP.toDiagnosticString(S.getASTContext());
       return false;
     }
   }
@@ -2828,7 +2828,7 @@ inline bool GetIntPtr(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
   return true;
 }
 
-inline bool GetMemberPtr(InterpState &S, CodePtr OpPC, const Decl *D) {
+inline bool GetMemberPtr(InterpState &S, CodePtr OpPC, const ValueDecl *D) {
   S.Stk.push<MemberPointer>(D);
   return true;
 }
diff --git a/clang/lib/AST/ByteCode/MemberPointer.h b/clang/lib/AST/ByteCode/MemberPointer.h
index de135a40a3c77b..b17ce256e75e29 100644
--- a/clang/lib/AST/ByteCode/MemberPointer.h
+++ b/clang/lib/AST/ByteCode/MemberPointer.h
@@ -22,21 +22,21 @@ class FunctionPointer;
 class MemberPointer final {
 private:
   Pointer Base;
-  const Decl *Dcl = nullptr;
+  const ValueDecl *Dcl = nullptr;
   int32_t PtrOffset = 0;
 
-  MemberPointer(Pointer Base, const Decl *Dcl, int32_t PtrOffset)
+  MemberPointer(Pointer Base, const ValueDecl *Dcl, int32_t PtrOffset)
       : Base(Base), Dcl(Dcl), PtrOffset(PtrOffset) {}
 
 public:
   MemberPointer() = default;
-  MemberPointer(Pointer Base, const Decl *Dcl) : Base(Base), Dcl(Dcl) {}
+  MemberPointer(Pointer Base, const ValueDecl *Dcl) : Base(Base), Dcl(Dcl) {}
   MemberPointer(uint32_t Address, const Descriptor *D) {
     // We only reach this for Address == 0, when creating a null member pointer.
     assert(Address == 0);
   }
 
-  MemberPointer(const Decl *D) : Dcl(D) {
+  MemberPointer(const ValueDecl *D) : Dcl(D) {
     assert((isa<FieldDecl, IndirectFieldDecl, CXXMethodDecl>(D)));
   }
 
@@ -67,7 +67,7 @@ class MemberPointer final {
   }
 
   bool hasDecl() const { return Dcl; }
-  const Decl *getDecl() const { return Dcl; }
+  const ValueDecl *getDecl() const { return Dcl; }
 
   MemberPointer atInstanceBase(unsigned Offset) const {
     if (Base.isZero())
@@ -96,7 +96,7 @@ class MemberPointer final {
   }
 
   std::string toDiagnosticString(const ASTContext &Ctx) const {
-    return "FIXME";
+    return toAPValue(Ctx).getAsString(Ctx, Dcl->getType());
   }
 
   ComparisonCategoryResult compare(const MemberPointer &RHS) const {
diff --git a/clang/lib/AST/ByteCode/Opcodes.td b/clang/lib/AST/ByteCode/Opcodes.td
index f286c71a129d1d..46247688d4ef85 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -62,7 +62,7 @@ def ArgExpr : ArgType { let Name = "const Expr *"; }
 def ArgOffsetOfExpr : ArgType { let Name = "const OffsetOfExpr *"; }
 def ArgDeclRef : ArgType { let Name = "const DeclRefExpr *"; }
 def ArgCCI : ArgType { let Name = "const ComparisonCategoryInfo *"; }
-def ArgDecl : ArgType { let Name = "const Decl*"; }
+def ArgValueDecl : ArgType { let Name = "const ValueDecl*"; }
 def ArgVarDecl : ArgType { let Name = "const VarDecl*"; }
 def ArgDesc : ArgType { let Name = "const Descriptor *"; }
 def ArgPrimType : ArgType { let Name = "PrimType"; }
@@ -756,7 +756,7 @@ def Memcpy : Opcode;
 def ToMemberPtr : Opcode;
 def CastMemberPtrPtr : Opcode;
 def GetMemberPtr : Opcode {
-  let Args = [ArgDecl];
+  let Args = [ArgValueDecl];
 }
 def GetMemberPtrBase : Opcode;
 def GetMemberPtrDecl : Opcode;

@tbaederr tbaederr merged commit 6f81c87 into llvm:main Aug 31, 2024
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants