Skip to content

Commit de04e6c

Browse files
committed
[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.
1 parent 3d8a44d commit de04e6c

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

clang/lib/AST/Interp/EvalEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ EvalEmitter::~EvalEmitter() {
3434

3535
EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
3636
bool ConvertResultToRValue) {
37+
S.setEvalLocation(E->getExprLoc());
3738
this->ConvertResultToRValue = ConvertResultToRValue;
3839
EvalResult.setSource(E);
3940

clang/lib/AST/Interp/InterpFrame.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,11 @@ Frame *InterpFrame::getCaller() const {
191191
}
192192

193193
SourceRange InterpFrame::getCallRange() const {
194-
if (!Caller->Func)
194+
if (!Caller->Func) {
195+
if (S.EvalLocation.isValid())
196+
return S.EvalLocation;
195197
return S.getRange(nullptr, {});
198+
}
196199
return S.getRange(Caller->Func, RetPC - sizeof(uintptr_t));
197200
}
198201

clang/lib/AST/Interp/InterpState.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class InterpState final : public State, public SourceMapper {
9898

9999
Context &getContext() const { return Ctx; }
100100

101+
void setEvalLocation(SourceLocation SL) { this->EvalLocation = SL; }
102+
101103
private:
102104
/// AST Walker state.
103105
State &Parent;
@@ -115,6 +117,8 @@ class InterpState final : public State, public SourceMapper {
115117
Context &Ctx;
116118
/// The current frame.
117119
InterpFrame *Current = nullptr;
120+
/// Source location of the evaluating expression
121+
SourceLocation EvalLocation;
118122
};
119123

120124
} // namespace interp

0 commit comments

Comments
 (0)