[clang] [Clang][Interp] Fix display of syntactically-invalid note for member function calls (PR #102170)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 8 09:43:25 PDT 2024
================
@@ -198,11 +198,11 @@ def NoRet : Opcode {}
def Call : Opcode {
- let Args = [ArgFunction, ArgUint32];
+ let Args = [ArgFunction, ArgUint32, ArgExpr];
----------------
tbaederr wrote:
You forgot the `This && IsMemberCall` check from the current interpreter.
Consider these diffs:
```diff
+
+ const Expr *MyCE = Caller->getExpr(getRetPC());
+ assert(MyCE == CallExpr);
+
const FunctionDecl *F = getCallee();
- if (const auto *M = dyn_cast<CXXMethodDecl>(F);
- M && M->isInstance() && !isa<CXXConstructorDecl>(F)) {
- print(OS, This, S.getCtx(), S.getCtx().getRecordType(M->getParent()));
- OS << "->";
+ assert(F);
+
+ bool IsMemberCall =
+ isa<CXXMethodDecl>(F) && !isa<CXXConstructorDecl>(F) &&
+ cast<CXXMethodDecl>(F)->isImplicitObjectMemberFunction();
+
+ assert(Caller);
+
+ if (Func->hasThisPointer() && IsMemberCall) {
+ if (const auto *MCE = dyn_cast_if_present<CXXMemberCallExpr>(MyCE)) {
+ const Expr *Object = MCE->getImplicitObjectArgument();
+ Object->printPretty(OS, /*Helper=*/nullptr, S.getCtx().getPrintingPolicy(),
+ /*Indentation=*/0);
+ if (Object->getType()->isPointerType())
+ OS << "->";
+ else
+ OS << ".";
+ } else if (const auto *OCE =
+ dyn_cast_if_present<CXXOperatorCallExpr>(MyCE)) {
+ OCE->getArg(0)->printPretty(OS, /*Helper=*/nullptr,
+ S.getCtx().getPrintingPolicy(),
+ /*Indentation=*/0);
+ OS << ".";
+ }
```
```diff
diff --git a/clang/lib/AST/Interp/Source.cpp b/clang/lib/AST/Interp/Source.cpp
index 45cd0ad4fd42..77796b00ca52 100644
--- a/clang/lib/AST/Interp/Source.cpp
+++ b/clang/lib/AST/Interp/Source.cpp
@@ -41,7 +41,7 @@ const Expr *SourceInfo::asExpr() const {
const Expr *SourceMapper::getExpr(const Function *F, CodePtr PC) const {
if (const Expr *E = getSource(F, PC).asExpr())
return E;
- llvm::report_fatal_error("missing source expression");
+ return nullptr;
}
```
I'll have to rebuild llvm locally now because I figured out the `llvm::report_fatal_error` above just trips my build up.
https://github.com/llvm/llvm-project/pull/102170
More information about the cfe-commits
mailing list