[PATCH] D149824: [clang][Interp] Don't call getSource() on functions without a body
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 4 01:26:44 PDT 2023
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149824
Files:
clang/lib/AST/Interp/EvalEmitter.h
clang/lib/AST/Interp/Function.cpp
Index: clang/lib/AST/Interp/Function.cpp
===================================================================
--- clang/lib/AST/Interp/Function.cpp
+++ clang/lib/AST/Interp/Function.cpp
@@ -32,6 +32,7 @@
SourceInfo Function::getSource(CodePtr PC) const {
assert(PC >= getCodeBegin() && "PC does not belong to this function");
assert(PC <= getCodeEnd() && "PC Does not belong to this function");
+ assert(hasBody());
unsigned Offset = PC - getCodeBegin();
using Elem = std::pair<unsigned, SourceInfo>;
auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());
Index: clang/lib/AST/Interp/EvalEmitter.h
===================================================================
--- clang/lib/AST/Interp/EvalEmitter.h
+++ clang/lib/AST/Interp/EvalEmitter.h
@@ -71,7 +71,7 @@
/// Returns the source location of the current opcode.
SourceInfo getSource(const Function *F, CodePtr PC) const override {
- return F ? F->getSource(PC) : CurrentSource;
+ return (F && F->hasBody()) ? F->getSource(PC) : CurrentSource;
}
/// Parameter indices.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149824.519380.patch
Type: text/x-patch
Size: 1081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230504/b1671b66/attachment.bin>
More information about the cfe-commits
mailing list