[clang] e8fb478 - [clang][Interp] Don't call getSource() on functions without a body

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Fri May 5 03:02:20 PDT 2023


Author: Timm Bäder
Date: 2023-05-05T11:59:42+02:00
New Revision: e8fb478f2df863c744b4eed5a5aa07a36fba737d

URL: https://github.com/llvm/llvm-project/commit/e8fb478f2df863c744b4eed5a5aa07a36fba737d
DIFF: https://github.com/llvm/llvm-project/commit/e8fb478f2df863c744b4eed5a5aa07a36fba737d.diff

LOG: [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

Added: 
    

Modified: 
    clang/lib/AST/Interp/EvalEmitter.h
    clang/lib/AST/Interp/Function.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/EvalEmitter.h b/clang/lib/AST/Interp/EvalEmitter.h
index 22d7b7c68d104..99933900f2921 100644
--- a/clang/lib/AST/Interp/EvalEmitter.h
+++ b/clang/lib/AST/Interp/EvalEmitter.h
@@ -71,7 +71,7 @@ class EvalEmitter : public SourceMapper {
 
   /// 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.

diff  --git a/clang/lib/AST/Interp/Function.cpp b/clang/lib/AST/Interp/Function.cpp
index 40001faad4116..4e6d175c41b26 100644
--- a/clang/lib/AST/Interp/Function.cpp
+++ b/clang/lib/AST/Interp/Function.cpp
@@ -32,6 +32,7 @@ Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
 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() && "Function has no body");
   unsigned Offset = PC - getCodeBegin();
   using Elem = std::pair<unsigned, SourceInfo>;
   auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());


        


More information about the cfe-commits mailing list