clang: lib/AST/ByteCode/Context.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
20
21using namespace clang;
23
25
27
29 assert(Stk.empty());
31 if ( ||
->hasBody())
33
35 return false;
36
38 return false;
39
40 return Func->isConstexpr();
41}
42
44 ++EvalID;
45 bool Recursing = !Stk.empty();
46 size_t StackSizeBefore = Stk.size();
48
49 auto Res = C.interpretExpr(E, E->isGLValue());
50
51 if (Res.isInvalid()) {
52 C.cleanup();
53 Stk.clearTo(StackSizeBefore);
54 return false;
55 }
56
57 if (!Recursing) {
58 assert(Stk.empty());
59 C.cleanup();
60#ifndef NDEBUG
61
62
63 Stk.clearTo(StackSizeBefore);
64#endif
65 }
66
67 Result = Res.toAPValue();
68
69 return true;
70}
71
74 ++EvalID;
75 bool Recursing = !Stk.empty();
76 size_t StackSizeBefore = Stk.size();
78
79 auto Res = C.interpretExpr(E, false,
80 true);
81 if (Res.isInvalid()) {
82 C.cleanup();
83 Stk.clearTo(StackSizeBefore);
84 return false;
85 }
86
87 if (!Recursing) {
88 assert(Stk.empty());
89 C.cleanup();
90#ifndef NDEBUG
91
92
93 Stk.clearTo(StackSizeBefore);
94#endif
95 }
96
97 Result = Res.toAPValue();
98 return true;
99}
100
103 ++EvalID;
104 bool Recursing = !Stk.empty();
105 size_t StackSizeBefore = Stk.size();
107
112 if (Res.isInvalid()) {
113 C.cleanup();
114 Stk.clearTo(StackSizeBefore);
115
116 return false;
117 }
118
119 if (!Recursing) {
120 assert(Stk.empty());
121 C.cleanup();
122#ifndef NDEBUG
123
124
125 Stk.clearTo(StackSizeBefore);
126#endif
127 }
128
129 Result = Res.toAPValue();
130 return true;
131}
132
134
138
139
141 return std::nullopt;
142
145 case 64:
147 case 32:
149 case 16:
151 case 8:
153 default:
155 }
156 }
157
160 case 64:
162 case 32:
164 case 16:
166 case 8:
168 case 1:
169
171 default:
173 }
174 }
175
178
181
185
189
192
194 return classify(AT->getValueType());
195
196 if (const auto *DT = dyn_cast(T))
197 return classify(DT->getUnderlyingType());
198
201
202 return std::nullopt;
203}
204
207}
208
209
210
213}
214
216
217 {
220 Func->getArgSize());
222 assert(Stk.empty());
223 return true;
224 }
225
226
227
228 }
229
231 return false;
232}
233
234
239 assert(DynamicDecl);
240 assert(StaticDecl);
241 assert(InitialFunction);
242
244 const CXXMethodDecl *FoundFunction = InitialFunction;
245 for (;;) {
248 if (Overrider)
249 return Overrider;
250
251
254 continue;
255 }
256
257
259 const CXXRecordDecl *Base = Spec.getType()->getAsCXXRecordDecl();
260 if (Base == StaticDecl || Base->isDerivedFrom(StaticDecl)) {
261 CurRecord = Base;
262 break;
263 }
264 }
265 }
266
267 llvm_unreachable(
268 "Couldn't find an overriding function in the class hierarchy?");
269 return nullptr;
270}
271
273 assert(FD);
275 bool IsBeingCompiled = Func && Func->isDefined() && ->isFullyCompiled();
276 bool WasNotDefined = Func && ->isConstexpr() &&
->isDefined();
277
278 if (IsBeingCompiled)
280
281 if ( || WasNotDefined) {
284 }
285
287}
288
290 const RecordDecl *DerivedDecl) const {
291 assert(BaseDecl);
292 assert(DerivedDecl);
293 const auto *FinalDecl = cast(BaseDecl);
294 const RecordDecl *CurDecl = DerivedDecl;
295 const Record *CurRecord = P->getOrCreateRecord(CurDecl);
296 assert(CurDecl && FinalDecl);
297
298 unsigned OffsetSum = 0;
299 for (;;) {
301
302 for (const Record::Base &B : CurRecord->bases()) {
303 const auto *BaseDecl = cast(B.Decl);
304
305 if (BaseDecl == FinalDecl || BaseDecl->isDerivedFrom(FinalDecl)) {
306 OffsetSum += B.Offset;
307 CurRecord = B.R;
308 CurDecl = BaseDecl;
309 break;
310 }
311 }
312 if (CurDecl == FinalDecl)
313 break;
314 }
315
316 assert(OffsetSum > 0);
317 return OffsetSum;
318}
319
321 return P->getOrCreateRecord(D);
322}
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
unsigned getIntWidth(QualType T) const
const llvm::fltSemantics & getFloatTypeSemantics(QualType T) const
Return the APFloat 'semantics' for the specified scalar floating point type.
const LangOptions & getLangOpts() const
const TargetInfo & getTargetInfo() const
Represents a base class of a C++ class.
QualType getType() const
Retrieves the type of the base class.
Represents a static or instance method of a struct/union/class.
CXXMethodDecl * getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, bool MayBeBase=false)
Find if RD declares a function that overrides this function, and if so, return it.
Represents a C++ struct/union/class.
unsigned getNumBases() const
Retrieves the number of base classes of this class.
base_class_iterator bases_begin()
This represents one expression.
Represents a function declaration or definition.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A (possibly-)qualified type.
Represents a struct/union/class.
unsigned getCharWidth() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isBlockPointerType() const
bool isBooleanType() const
bool isFunctionReferenceType() const
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
bool isFunctionPointerType() const
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isAnyComplexType() const
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
bool isMemberPointerType() const
bool isPointerOrReferenceType() const
bool isFunctionType() const
bool isObjCObjectPointerType() const
bool isVectorType() const
bool isFloatingType() const
const T * getAs() const
Member-template getAs'.
bool isNullPtrType() const
bool isRecordType() const
Represents a variable declaration or definition.
Pointer into the code segment.
Compilation context for expressions.
const LangOptions & getLangOpts() const
Returns the language options.
~Context()
Cleans up the constexpr VM.
Context(ASTContext &Ctx)
Initialises the constexpr VM.
unsigned getCharBit() const
Returns CHAR_BIT.
bool evaluateAsInitializer(State &Parent, const VarDecl *VD, APValue &Result)
Evaluates a toplevel initializer.
const llvm::fltSemantics & getFloatSemantics(QualType T) const
Return the floating-point semantics for T.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
unsigned collectBaseOffset(const RecordDecl *BaseDecl, const RecordDecl *DerivedDecl) const
const Record * getRecord(const RecordDecl *D) const
bool isPotentialConstantExpr(State &Parent, const FunctionDecl *FnDecl)
Checks if a function is a potential constant expression.
bool evaluateAsRValue(State &Parent, const Expr *E, APValue &Result)
Evaluates a toplevel expression as an rvalue.
const CXXMethodDecl * getOverridingFunction(const CXXRecordDecl *DynamicDecl, const CXXRecordDecl *StaticDecl, const CXXMethodDecl *InitialFunction) const
bool evaluate(State &Parent, const Expr *E, APValue &Result, ConstantExprKind Kind)
Like evaluateAsRvalue(), but does no implicit lvalue-to-rvalue conversion.
std::optional< PrimType > classify(QualType T) const
Classifies a type.
const Function * getOrCreateFunction(const FunctionDecl *FD)
Frame storing local variables.
void clearTo(size_t NewSize)
void clear()
Clears the stack without calling any destructors.
size_t size() const
Returns the size of the stack in bytes.
bool empty() const
Returns whether the stack is empty.
The program contains and links the bytecode for all functions.
Structure/Class descriptor.
unsigned getNumBases() const
llvm::iterator_range< const_base_iter > bases() const
Interface for the VM to interact with the AST walker's context.
Defines the clang::TargetInfo interface.
bool CheckGlobalInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Check if a global variable is initialized.
bool Interpret(InterpState &S)
Interpreter entry point.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T