clang 20.0.0git
Function.cpp
Go to the documentation of this file.
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 "Program.h"
11#include "clang/AST/Decl.h"
12#include "clang/AST/DeclCXX.h"
14
15using namespace clang;
16using namespace clang::interp;
17
18Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
20 llvm::DenseMap<unsigned, ParamDescriptor> &&Params,
22 bool HasThisPointer, bool HasRVO, unsigned BuiltinID)
23 : P(P), Source(Source), ArgSize(ArgSize), ParamTypes(std::move(ParamTypes)),
24 Params(std::move(Params)), ParamOffsets(std::move(ParamOffsets)),
25 HasThisPointer(HasThisPointer), HasRVO(HasRVO), BuiltinID(BuiltinID) {
26 if (const auto *F = Source.dyn_cast<const FunctionDecl *>())
27 Variadic = F->isVariadic();
28}
29
30Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
31 auto It = Params.find(Offset);
32 assert(It != Params.end() && "Invalid parameter offset");
33 return It->second;
34}
35
36SourceInfo Function::getSource(CodePtr PC) const {
37 assert(PC >= getCodeBegin() && "PC does not belong to this function");
38 assert(PC <= getCodeEnd() && "PC Does not belong to this function");
39 assert(hasBody() && "Function has no body");
40 unsigned Offset = PC - getCodeBegin();
41 using Elem = std::pair<unsigned, SourceInfo>;
42 auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());
43 if (It == SrcMap.end())
44 return SrcMap.back().second;
45 return It->second;
46}
47
48bool Function::isVirtual() const {
49 if (const auto *M = dyn_cast_if_present<CXXMethodDecl>(
50 Source.dyn_cast<const FunctionDecl *>()))
51 return M->isVirtual();
52 return false;
53}
54
55/// Unevaluated builtins don't get their arguments put on the stack
56/// automatically. They instead operate on the AST of their Call
57/// Expression.
58/// Similar information is available via ASTContext::BuiltinInfo,
59/// but that is not correct for our use cases.
60static bool isUnevaluatedBuiltin(unsigned BuiltinID) {
61 return BuiltinID == Builtin::BI__builtin_classify_type ||
62 BuiltinID == Builtin::BI__builtin_os_log_format_buffer_size ||
63 BuiltinID == Builtin::BI__builtin_constant_p ||
64 BuiltinID == Builtin::BI__noop;
65}
66
67bool Function::isUnevaluatedBuiltin() const {
68 return ::isUnevaluatedBuiltin(BuiltinID);
69}
StringRef P
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static bool isUnevaluatedBuiltin(unsigned BuiltinID)
Unevaluated builtins don't get their arguments put on the stack automatically.
Definition: Function.cpp:60
Represents a function declaration or definition.
Definition: Decl.h:1935
Pointer into the code segment.
Definition: Source.h:30
std::pair< PrimType, Descriptor * > ParamDescriptor
Definition: Function.h:83
The program contains and links the bytecode for all functions.
Definition: Program.h:39
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:77
llvm::PointerUnion< const FunctionDecl *, const BlockExpr * > FunctionDeclTy
Definition: Function.h:60
The JSON file list parser is used to communicate input to InstallAPI.