[clang] de04e6c - [clang][Interp][NFC] Save source location of evaluating expression
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu May 2 04:49:48 PDT 2024
Author: Timm Bäder
Date: 2024-05-02T13:43:07+02:00
New Revision: de04e6cd90b891215f1dfc83ec886d037a7c2ed0
URL: https://github.com/llvm/llvm-project/commit/de04e6cd90b891215f1dfc83ec886d037a7c2ed0
DIFF: https://github.com/llvm/llvm-project/commit/de04e6cd90b891215f1dfc83ec886d037a7c2ed0.diff
LOG: [clang][Interp][NFC] Save source location of evaluating expression
We don't have a source location to point to when the evaluation
of a destructor of a temporary created via an expression fails.
Added:
Modified:
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/InterpState.h
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp
index d764b4b6f6d17b..388c3612f292b0 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 515b1f5fde1aa7..cf296b4e64f928 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)
+ if (!Caller->Func) {
+ if (S.EvalLocation.isValid())
+ return S.EvalLocation;
return S.getRange(nullptr, {});
+ }
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 c17cfad11b1e2b..d483c60c58e248 100644
--- a/clang/lib/AST/Interp/InterpState.h
+++ b/clang/lib/AST/Interp/InterpState.h
@@ -98,6 +98,8 @@ class InterpState final : public State, public SourceMapper {
Context &getContext() const { return Ctx; }
+ void setEvalLocation(SourceLocation SL) { this->EvalLocation = SL; }
+
private:
/// AST Walker state.
State &Parent;
@@ -115,6 +117,8 @@ class InterpState final : public State, public SourceMapper {
Context &Ctx;
/// The current frame.
InterpFrame *Current = nullptr;
+ /// Source location of the evaluating expression
+ SourceLocation EvalLocation;
};
} // namespace interp
More information about the cfe-commits
mailing list