/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/Interp/Function.cpp
Line | Count | Source |
1 | | //===--- Function.h - Bytecode function for the VM --------------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #include "Function.h" |
10 | | #include "Opcode.h" |
11 | | #include "Program.h" |
12 | | #include "clang/AST/Decl.h" |
13 | | #include "clang/AST/DeclCXX.h" |
14 | | #include "clang/Basic/Builtins.h" |
15 | | |
16 | | using namespace clang; |
17 | | using namespace clang::interp; |
18 | | |
19 | | Function::Function(Program &P, const FunctionDecl *F, unsigned ArgSize, |
20 | | llvm::SmallVectorImpl<PrimType> &&ParamTypes, |
21 | | llvm::DenseMap<unsigned, ParamDescriptor> &&Params, |
22 | | llvm::SmallVectorImpl<unsigned> &&ParamOffsets, |
23 | | bool HasThisPointer, bool HasRVO) |
24 | 1.69k | : P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize), |
25 | 1.69k | ParamTypes(std::move(ParamTypes)), Params(std::move(Params)), |
26 | 1.69k | ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer), |
27 | 1.69k | HasRVO(HasRVO), Variadic(F->isVariadic()) {} |
28 | | |
29 | 673 | Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const { |
30 | 673 | auto It = Params.find(Offset); |
31 | 673 | assert(It != Params.end() && "Invalid parameter offset"); |
32 | 673 | return It->second; |
33 | 673 | } |
34 | | |
35 | 742 | SourceInfo Function::getSource(CodePtr PC) const { |
36 | 742 | assert(PC >= getCodeBegin() && "PC does not belong to this function"); |
37 | 742 | assert(PC <= getCodeEnd() && "PC Does not belong to this function"); |
38 | 742 | assert(hasBody() && "Function has no body"); |
39 | 742 | unsigned Offset = PC - getCodeBegin(); |
40 | 742 | using Elem = std::pair<unsigned, SourceInfo>; |
41 | 742 | auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first()); |
42 | 742 | assert(It != SrcMap.end()); |
43 | 742 | return It->second; |
44 | 742 | } |
45 | | |
46 | 8.20k | bool Function::isVirtual() const { |
47 | 8.20k | if (const auto *M = dyn_cast<CXXMethodDecl>(F)) |
48 | 4.62k | return M->isVirtual(); |
49 | 3.58k | return false; |
50 | 8.20k | } |
51 | | |
52 | 8.78k | bool Function::needsRuntimeArgPop(const ASTContext &Ctx) const { |
53 | 8.78k | if (!isBuiltin()) |
54 | 7.49k | return false; |
55 | 1.28k | return Ctx.BuiltinInfo.hasCustomTypechecking(getBuiltinID()); |
56 | 8.78k | } |