From 155dcce40110fbe8a29a5b00a3078e3333d10f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 2 May 2024 14:04:38 +0200 Subject: [PATCH] Reapply "[clang][Interp][NFC] Save source location of evaluating expression" This reverts commit ebcb04ae8825b15fd6aa249a8da0617b877b4705. --- clang/lib/AST/Interp/EvalEmitter.cpp | 1 + clang/lib/AST/Interp/InterpFrame.cpp | 7 +++++-- clang/lib/AST/Interp/InterpState.h | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index d764b4b6f6d1..388c3612f292 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -34,6 +34,7 @@ EvalEmitter::~EvalEmitter() { EvaluationResult EvalEmitter::interpretExpr(const Expr *E, bool ConvertResultToRValue) { + S.setEvalLocation(E->getExprLoc()); this->ConvertResultToRValue = ConvertResultToRValue; EvalResult.setSource(E); diff --git a/clang/lib/AST/Interp/InterpFrame.cpp b/clang/lib/AST/Interp/InterpFrame.cpp index 515b1f5fde1a..51b0bd5c1551 100644 --- a/clang/lib/AST/Interp/InterpFrame.cpp +++ b/clang/lib/AST/Interp/InterpFrame.cpp @@ -191,8 +191,11 @@ Frame *InterpFrame::getCaller() const { } SourceRange InterpFrame::getCallRange() const { - if (!Caller->Func) - return S.getRange(nullptr, {}); + if (!Caller->Func) { + if (SourceRange NullRange = S.getRange(nullptr, {}); NullRange.isValid()) + return NullRange; + return S.EvalLocation; + } return S.getRange(Caller->Func, RetPC - sizeof(uintptr_t)); } diff --git a/clang/lib/AST/Interp/InterpState.h b/clang/lib/AST/Interp/InterpState.h index c17cfad11b1e..d483c60c58e2 100644 --- a/clang/lib/AST/Interp/InterpState.h +++ b/clang/lib/AST/Interp/InterpState.h @@ -98,6 +98,8 @@ public: Context &getContext() const { return Ctx; } + void setEvalLocation(SourceLocation SL) { this->EvalLocation = SL; } + private: /// AST Walker state. State &Parent; @@ -115,6 +117,8 @@ public: Context &Ctx; /// The current frame. InterpFrame *Current = nullptr; + /// Source location of the evaluating expression + SourceLocation EvalLocation; }; } // namespace interp