Skip to content

Commit e8fb478

Browse files
committed
[clang][Interp] Don't call getSource() on functions without a body
For builtin functions, we create a Function instance without a body or code. When emitting diagnostics from them, we need a proper SourceInfo to point to, but the only thing we can use is the call site of the builtin function. Differential Revision: https://reviews.llvm.org/D149824
1 parent 1d424ee commit e8fb478

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

clang/lib/AST/Interp/EvalEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class EvalEmitter : public SourceMapper {
7171

7272
/// Returns the source location of the current opcode.
7373
SourceInfo getSource(const Function *F, CodePtr PC) const override {
74-
return F ? F->getSource(PC) : CurrentSource;
74+
return (F && F->hasBody()) ? F->getSource(PC) : CurrentSource;
7575
}
7676

7777
/// Parameter indices.

clang/lib/AST/Interp/Function.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
3232
SourceInfo Function::getSource(CodePtr PC) const {
3333
assert(PC >= getCodeBegin() && "PC does not belong to this function");
3434
assert(PC <= getCodeEnd() && "PC Does not belong to this function");
35+
assert(hasBody() && "Function has no body");
3536
unsigned Offset = PC - getCodeBegin();
3637
using Elem = std::pair<unsigned, SourceInfo>;
3738
auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());

0 commit comments

Comments
 (0)