Thanks to visit codestin.com
Credit goes to clang.llvm.org

clang 22.0.0git
Context.cpp
Go to the documentation of this file.
1//===--- Context.cpp - Context for the constexpr 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 "Context.h"
10#include "ByteCodeEmitter.h"
11#include "Compiler.h"
12#include "EvalEmitter.h"
13#include "Interp.h"
14#include "InterpFrame.h"
15#include "InterpStack.h"
16#include "PrimType.h"
17#include "Program.h"
18#include "clang/AST/ASTLambda.h"
19#include "clang/AST/Expr.h"
21#include "llvm/Support/SystemZ/zOSSupport.h"
22
23using namespace clang;
24using namespace clang::interp;
25
26Context::Context(ASTContext &Ctx) : Ctx(Ctx), P(new Program(*this)) {
27 this->ShortWidth = Ctx.getTargetInfo().getShortWidth();
28 this->IntWidth = Ctx.getTargetInfo().getIntWidth();
29 this->LongWidth = Ctx.getTargetInfo().getLongWidth();
30 this->LongLongWidth = Ctx.getTargetInfo().getLongLongWidth();
31 assert(Ctx.getTargetInfo().getCharWidth() == 8 &&
32 "We're assuming 8 bit chars");
33}
34
36
38 assert(Stk.empty());
39
40 // Get a function handle.
42 if (!Func)
43 return false;
44
45 // Compile the function.
46 Compiler<ByteCodeEmitter>(*this, *P).compileFunc(
47 FD, const_cast<Function *>(Func));
48
49 if (!Func->isValid())
50 return false;
51
52 ++EvalID;
53 // And run it.
54 return Run(Parent, Func);
55}
56
58 const FunctionDecl *FD) {
59 assert(Stk.empty());
60 ++EvalID;
61 size_t StackSizeBefore = Stk.size();
62 Compiler<EvalEmitter> C(*this, *P, Parent, Stk);
63
64 if (!C.interpretCall(FD, E)) {
65 C.cleanup();
66 Stk.clearTo(StackSizeBefore);
67 }
68}
69
71 ++EvalID;
72 bool Recursing = !Stk.empty();
73 size_t StackSizeBefore = Stk.size();
74 Compiler<EvalEmitter> C(*this, *P, Parent, Stk);
75
76 auto Res = C.interpretExpr(E, /*ConvertResultToRValue=*/E->isGLValue());
77
78 if (Res.isInvalid()) {
79 C.cleanup();
80 Stk.clearTo(StackSizeBefore);
81 return false;
82 }
83
84 if (!Recursing) {
85 // We *can* actually get here with a non-empty stack, since
86 // things like InterpState::noteSideEffect() exist.
87 C.cleanup();
88#ifndef NDEBUG
89 // Make sure we don't rely on some value being still alive in
90 // InterpStack memory.
91 Stk.clearTo(StackSizeBefore);
92#endif
93 }
94
95 Result = Res.stealAPValue();
96
97 return true;
98}
99
100bool Context::evaluate(State &Parent, const Expr *E, APValue &Result,
101 ConstantExprKind Kind) {
102 ++EvalID;
103 bool Recursing = !Stk.empty();
104 size_t StackSizeBefore = Stk.size();
105 Compiler<EvalEmitter> C(*this, *P, Parent, Stk);
106
107 auto Res = C.interpretExpr(E, /*ConvertResultToRValue=*/false,
108 /*DestroyToplevelScope=*/true);
109 if (Res.isInvalid()) {
110 C.cleanup();
111 Stk.clearTo(StackSizeBefore);
112 return false;
113 }
114
115 if (!Recursing) {
116 assert(Stk.empty());
117 C.cleanup();
118#ifndef NDEBUG
119 // Make sure we don't rely on some value being still alive in
120 // InterpStack memory.
121 Stk.clearTo(StackSizeBefore);
122#endif
123 }
124
125 Result = Res.stealAPValue();
126 return true;
127}
128
130 const Expr *Init, APValue &Result) {
131 ++EvalID;
132 bool Recursing = !Stk.empty();
133 size_t StackSizeBefore = Stk.size();
134 Compiler<EvalEmitter> C(*this, *P, Parent, Stk);
135
136 bool CheckGlobalInitialized =
138 (VD->getType()->isRecordType() || VD->getType()->isArrayType());
139 auto Res = C.interpretDecl(VD, Init, CheckGlobalInitialized);
140 if (Res.isInvalid()) {
141 C.cleanup();
142 Stk.clearTo(StackSizeBefore);
143
144 return false;
145 }
146
147 if (!Recursing) {
148 assert(Stk.empty());
149 C.cleanup();
150#ifndef NDEBUG
151 // Make sure we don't rely on some value being still alive in
152 // InterpStack memory.
153 Stk.clearTo(StackSizeBefore);
154#endif
155 }
156
157 Result = Res.stealAPValue();
158 return true;
159}
160
161template <typename ResultT>
162bool Context::evaluateStringRepr(State &Parent, const Expr *SizeExpr,
163 const Expr *PtrExpr, ResultT &Result) {
164 assert(Stk.empty());
165 Compiler<EvalEmitter> C(*this, *P, Parent, Stk);
166
167 // Evaluate size value.
168 APValue SizeValue;
169 if (!evaluateAsRValue(Parent, SizeExpr, SizeValue))
170 return false;
171
172 if (!SizeValue.isInt())
173 return false;
174 uint64_t Size = SizeValue.getInt().getZExtValue();
175
176 auto PtrRes = C.interpretAsPointer(PtrExpr, [&](const Pointer &Ptr) {
177 if (Size == 0) {
178 if constexpr (std::is_same_v<ResultT, APValue>)
180 return true;
181 }
182
183 if (!Ptr.isLive() || !Ptr.getFieldDesc()->isPrimitiveArray())
184 return false;
185
186 // Must be char.
187 if (Ptr.getFieldDesc()->getElemSize() != 1 /*bytes*/)
188 return false;
189
190 if (Size > Ptr.getNumElems()) {
191 Parent.FFDiag(SizeExpr, diag::note_constexpr_access_past_end) << AK_Read;
192 Size = Ptr.getNumElems();
193 }
194
195 if constexpr (std::is_same_v<ResultT, APValue>) {
196 QualType CharTy = PtrExpr->getType()->getPointeeType();
197 Result = APValue(APValue::UninitArray{}, Size, Size);
198 for (uint64_t I = 0; I != Size; ++I) {
199 if (std::optional<APValue> ElemVal =
200 Ptr.atIndex(I).toRValue(*this, CharTy))
201 Result.getArrayInitializedElt(I) = *ElemVal;
202 else
203 return false;
204 }
205 } else {
206 assert((std::is_same_v<ResultT, std::string>));
207 if (Size < Result.max_size())
208 Result.resize(Size);
209 Result.assign(reinterpret_cast<const char *>(Ptr.getRawAddress()), Size);
210 }
211
212 return true;
213 });
214
215 if (PtrRes.isInvalid()) {
216 C.cleanup();
217 Stk.clear();
218 return false;
219 }
220
221 return true;
222}
223
224bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
225 const Expr *PtrExpr, APValue &Result) {
226 assert(SizeExpr);
227 assert(PtrExpr);
228
229 return evaluateStringRepr(Parent, SizeExpr, PtrExpr, Result);
230}
231
232bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
233 const Expr *PtrExpr, std::string &Result) {
234 assert(SizeExpr);
235 assert(PtrExpr);
236
237 return evaluateStringRepr(Parent, SizeExpr, PtrExpr, Result);
238}
239
240bool Context::evaluateStrlen(State &Parent, const Expr *E, uint64_t &Result) {
241 assert(Stk.empty());
242 Compiler<EvalEmitter> C(*this, *P, Parent, Stk);
243
244 auto PtrRes = C.interpretAsPointer(E, [&](const Pointer &Ptr) {
245 const Descriptor *FieldDesc = Ptr.getFieldDesc();
246 if (!FieldDesc->isPrimitiveArray())
247 return false;
248
249 if (Ptr.isDummy() || Ptr.isUnknownSizeArray())
250 return false;
251
252 unsigned N = Ptr.getNumElems();
253 if (Ptr.elemSize() == 1) {
254 Result = strnlen(reinterpret_cast<const char *>(Ptr.getRawAddress()), N);
255 return Result != N;
256 }
257
258 PrimType ElemT = FieldDesc->getPrimType();
259 Result = 0;
260 for (unsigned I = Ptr.getIndex(); I != N; ++I) {
261 INT_TYPE_SWITCH(ElemT, {
262 auto Elem = Ptr.elem<T>(I);
263 if (Elem.isZero())
264 return true;
265 ++Result;
266 });
267 }
268 // We didn't find a 0 byte.
269 return false;
270 });
271
272 if (PtrRes.isInvalid()) {
273 C.cleanup();
274 Stk.clear();
275 return false;
276 }
277 return true;
278}
279
280const LangOptions &Context::getLangOpts() const { return Ctx.getLangOpts(); }
281
282static PrimType integralTypeToPrimTypeS(unsigned BitWidth) {
283 switch (BitWidth) {
284 case 64:
285 return PT_Sint64;
286 case 32:
287 return PT_Sint32;
288 case 16:
289 return PT_Sint16;
290 case 8:
291 return PT_Sint8;
292 default:
293 return PT_IntAPS;
294 }
295 llvm_unreachable("Unhandled BitWidth");
296}
297
298static PrimType integralTypeToPrimTypeU(unsigned BitWidth) {
299 switch (BitWidth) {
300 case 64:
301 return PT_Uint64;
302 case 32:
303 return PT_Uint32;
304 case 16:
305 return PT_Uint16;
306 case 8:
307 return PT_Uint8;
308 default:
309 return PT_IntAP;
310 }
311 llvm_unreachable("Unhandled BitWidth");
312}
313
315
316 if (const auto *BT = dyn_cast<BuiltinType>(T.getCanonicalType())) {
317 auto Kind = BT->getKind();
318 if (Kind == BuiltinType::Bool)
319 return PT_Bool;
320 if (Kind == BuiltinType::NullPtr)
321 return PT_Ptr;
322 if (Kind == BuiltinType::BoundMember)
323 return PT_MemberPtr;
324
325 // Just trying to avoid the ASTContext::getIntWidth call below.
326 if (Kind == BuiltinType::Short)
327 return integralTypeToPrimTypeS(this->ShortWidth);
328 if (Kind == BuiltinType::UShort)
329 return integralTypeToPrimTypeU(this->ShortWidth);
330
331 if (Kind == BuiltinType::Int)
332 return integralTypeToPrimTypeS(this->IntWidth);
333 if (Kind == BuiltinType::UInt)
334 return integralTypeToPrimTypeU(this->IntWidth);
335 if (Kind == BuiltinType::Long)
336 return integralTypeToPrimTypeS(this->LongWidth);
337 if (Kind == BuiltinType::ULong)
338 return integralTypeToPrimTypeU(this->LongWidth);
339 if (Kind == BuiltinType::LongLong)
340 return integralTypeToPrimTypeS(this->LongLongWidth);
341 if (Kind == BuiltinType::ULongLong)
342 return integralTypeToPrimTypeU(this->LongLongWidth);
343
344 if (Kind == BuiltinType::SChar || Kind == BuiltinType::Char_S)
345 return integralTypeToPrimTypeS(8);
346 if (Kind == BuiltinType::UChar || Kind == BuiltinType::Char_U ||
347 Kind == BuiltinType::Char8)
348 return integralTypeToPrimTypeU(8);
349
350 if (BT->isSignedInteger())
351 return integralTypeToPrimTypeS(Ctx.getIntWidth(T));
352 if (BT->isUnsignedInteger())
353 return integralTypeToPrimTypeU(Ctx.getIntWidth(T));
354
355 if (BT->isFloatingPoint())
356 return PT_Float;
357 }
358
359 if (T->isPointerOrReferenceType())
360 return PT_Ptr;
361
362 if (T->isMemberPointerType())
363 return PT_MemberPtr;
364
365 if (const auto *BT = T->getAs<BitIntType>()) {
366 if (BT->isSigned())
367 return integralTypeToPrimTypeS(BT->getNumBits());
368 return integralTypeToPrimTypeU(BT->getNumBits());
369 }
370
371 if (const auto *D = T->getAsEnumDecl()) {
372 if (!D->isComplete())
373 return std::nullopt;
374 return classify(D->getIntegerType());
375 }
376
377 if (const auto *AT = T->getAs<AtomicType>())
378 return classify(AT->getValueType());
379
380 if (const auto *DT = dyn_cast<DecltypeType>(T))
381 return classify(DT->getUnderlyingType());
382
383 if (T->isObjCObjectPointerType() || T->isBlockPointerType())
384 return PT_Ptr;
385
386 if (T->isFixedPointType())
387 return PT_FixedPoint;
388
389 // Vector and complex types get here.
390 return std::nullopt;
391}
392
393unsigned Context::getCharBit() const {
394 return Ctx.getTargetInfo().getCharWidth();
395}
396
397/// Simple wrapper around getFloatTypeSemantics() to make code a
398/// little shorter.
399const llvm::fltSemantics &Context::getFloatSemantics(QualType T) const {
400 return Ctx.getFloatTypeSemantics(T);
401}
402
403bool Context::Run(State &Parent, const Function *Func) {
404 InterpState State(Parent, *P, Stk, *this, Func);
405 if (Interpret(State)) {
406 assert(Stk.empty());
407 return true;
408 }
409 Stk.clear();
410 return false;
411}
412
413// TODO: Virtual bases?
414const CXXMethodDecl *
416 const CXXRecordDecl *StaticDecl,
417 const CXXMethodDecl *InitialFunction) const {
418 assert(DynamicDecl);
419 assert(StaticDecl);
420 assert(InitialFunction);
421
422 const CXXRecordDecl *CurRecord = DynamicDecl;
423 const CXXMethodDecl *FoundFunction = InitialFunction;
424 for (;;) {
425 const CXXMethodDecl *Overrider =
426 FoundFunction->getCorrespondingMethodDeclaredInClass(CurRecord, false);
427 if (Overrider)
428 return Overrider;
429
430 // Common case of only one base class.
431 if (CurRecord->getNumBases() == 1) {
432 CurRecord = CurRecord->bases_begin()->getType()->getAsCXXRecordDecl();
433 continue;
434 }
435
436 // Otherwise, go to the base class that will lead to the StaticDecl.
437 for (const CXXBaseSpecifier &Spec : CurRecord->bases()) {
438 const CXXRecordDecl *Base = Spec.getType()->getAsCXXRecordDecl();
439 if (Base == StaticDecl || Base->isDerivedFrom(StaticDecl)) {
440 CurRecord = Base;
441 break;
442 }
443 }
444 }
445
446 llvm_unreachable(
447 "Couldn't find an overriding function in the class hierarchy?");
448 return nullptr;
449}
450
452 assert(FuncDecl);
453 if (const Function *Func = P->getFunction(FuncDecl))
454 return Func;
455
456 // Manually created functions that haven't been assigned proper
457 // parameters yet.
458 if (!FuncDecl->param_empty() && !FuncDecl->param_begin())
459 return nullptr;
460
461 bool IsLambdaStaticInvoker = false;
462 if (const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl);
463 MD && MD->isLambdaStaticInvoker()) {
464 // For a lambda static invoker, we might have to pick a specialized
465 // version if the lambda is generic. In that case, the picked function
466 // will *NOT* be a static invoker anymore. However, it will still
467 // be a non-static member function, this (usually) requiring an
468 // instance pointer. We suppress that later in this function.
469 IsLambdaStaticInvoker = true;
470 }
471 // Set up argument indices.
472 unsigned ParamOffset = 0;
473 SmallVector<PrimType, 8> ParamTypes;
474 SmallVector<unsigned, 8> ParamOffsets;
475 llvm::DenseMap<unsigned, Function::ParamDescriptor> ParamDescriptors;
476
477 // If the return is not a primitive, a pointer to the storage where the
478 // value is initialized in is passed as the first argument. See 'RVO'
479 // elsewhere in the code.
480 QualType Ty = FuncDecl->getReturnType();
481 bool HasRVO = false;
482 if (!Ty->isVoidType() && !canClassify(Ty)) {
483 HasRVO = true;
484 ParamTypes.push_back(PT_Ptr);
485 ParamOffsets.push_back(ParamOffset);
487 }
488
489 // If the function decl is a member decl, the next parameter is
490 // the 'this' pointer. This parameter is pop()ed from the
491 // InterpStack when calling the function.
492 bool HasThisPointer = false;
493 if (const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl)) {
494 if (!IsLambdaStaticInvoker) {
495 HasThisPointer = MD->isInstance();
496 if (MD->isImplicitObjectMemberFunction()) {
497 ParamTypes.push_back(PT_Ptr);
498 ParamOffsets.push_back(ParamOffset);
500 }
501 }
502
503 if (isLambdaCallOperator(MD)) {
504 // The parent record needs to be complete, we need to know about all
505 // the lambda captures.
506 if (!MD->getParent()->isCompleteDefinition())
507 return nullptr;
508 llvm::DenseMap<const ValueDecl *, FieldDecl *> LC;
509 FieldDecl *LTC;
510
511 MD->getParent()->getCaptureFields(LC, LTC);
512
513 if (MD->isStatic() && !LC.empty()) {
514 // Static lambdas cannot have any captures. If this one does,
515 // it has already been diagnosed and we can only ignore it.
516 return nullptr;
517 }
518 }
519 }
520
521 // Assign descriptors to all parameters.
522 // Composite objects are lowered to pointers.
523 for (const ParmVarDecl *PD : FuncDecl->parameters()) {
524 OptPrimType T = classify(PD->getType());
525 PrimType PT = T.value_or(PT_Ptr);
526 Descriptor *Desc = P->createDescriptor(PD, PT);
527 ParamDescriptors.insert({ParamOffset, {PT, Desc}});
528 ParamOffsets.push_back(ParamOffset);
529 ParamOffset += align(primSize(PT));
530 ParamTypes.push_back(PT);
531 }
532
533 // Create a handle over the emitted code.
534 assert(!P->getFunction(FuncDecl));
535 const Function *Func = P->createFunction(
536 FuncDecl, ParamOffset, std::move(ParamTypes), std::move(ParamDescriptors),
537 std::move(ParamOffsets), HasThisPointer, HasRVO, IsLambdaStaticInvoker);
538 return Func;
539}
540
542 const BlockDecl *BD = E->getBlockDecl();
543 // Set up argument indices.
544 unsigned ParamOffset = 0;
545 SmallVector<PrimType, 8> ParamTypes;
546 SmallVector<unsigned, 8> ParamOffsets;
547 llvm::DenseMap<unsigned, Function::ParamDescriptor> ParamDescriptors;
548
549 // Assign descriptors to all parameters.
550 // Composite objects are lowered to pointers.
551 for (const ParmVarDecl *PD : BD->parameters()) {
552 OptPrimType T = classify(PD->getType());
553 PrimType PT = T.value_or(PT_Ptr);
554 Descriptor *Desc = P->createDescriptor(PD, PT);
555 ParamDescriptors.insert({ParamOffset, {PT, Desc}});
556 ParamOffsets.push_back(ParamOffset);
557 ParamOffset += align(primSize(PT));
558 ParamTypes.push_back(PT);
559 }
560
561 if (BD->hasCaptures())
562 return nullptr;
563
564 // Create a handle over the emitted code.
565 Function *Func =
566 P->createFunction(E, ParamOffset, std::move(ParamTypes),
567 std::move(ParamDescriptors), std::move(ParamOffsets),
568 /*HasThisPointer=*/false, /*HasRVO=*/false,
569 /*IsLambdaStaticInvoker=*/false);
570
571 assert(Func);
572 Func->setDefined(true);
573 // We don't compile the BlockDecl code at all right now.
574 Func->setIsFullyCompiled(true);
575 return Func;
576}
577
578unsigned Context::collectBaseOffset(const RecordDecl *BaseDecl,
579 const RecordDecl *DerivedDecl) const {
580 assert(BaseDecl);
581 assert(DerivedDecl);
582 const auto *FinalDecl = cast<CXXRecordDecl>(BaseDecl);
583 const RecordDecl *CurDecl = DerivedDecl;
584 const Record *CurRecord = P->getOrCreateRecord(CurDecl);
585 assert(CurDecl && FinalDecl);
586
587 unsigned OffsetSum = 0;
588 for (;;) {
589 assert(CurRecord->getNumBases() > 0);
590 // One level up
591 for (const Record::Base &B : CurRecord->bases()) {
592 const auto *BaseDecl = cast<CXXRecordDecl>(B.Decl);
593
594 if (BaseDecl == FinalDecl || BaseDecl->isDerivedFrom(FinalDecl)) {
595 OffsetSum += B.Offset;
596 CurRecord = B.R;
597 CurDecl = BaseDecl;
598 break;
599 }
600 }
601 if (CurDecl == FinalDecl)
602 break;
603 }
604
605 assert(OffsetSum > 0);
606 return OffsetSum;
607}
608
609const Record *Context::getRecord(const RecordDecl *D) const {
610 return P->getOrCreateRecord(D);
611}
612
614 return ID == Builtin::BI__builtin_classify_type ||
615 ID == Builtin::BI__builtin_os_log_format_buffer_size ||
616 ID == Builtin::BI__builtin_constant_p || ID == Builtin::BI__noop;
617}
This file provides some common utility functions for processing Lambda related AST Constructs.
static PrimType integralTypeToPrimTypeS(unsigned BitWidth)
Definition Context.cpp:282
static PrimType integralTypeToPrimTypeU(unsigned BitWidth)
Definition Context.cpp:298
#define INT_TYPE_SWITCH(Expr, B)
Definition PrimType.h:228
static bool isRecordType(QualType T)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
APSInt & getInt()
Definition APValue.h:489
bool isInt() const
Definition APValue.h:467
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:188
A fixed int type of a specified bitwidth.
Definition TypeBase.h:8137
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4651
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
Definition Decl.h:4770
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:4737
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6558
const BlockDecl * getBlockDecl() const
Definition Expr.h:6570
Represents a base class of a C++ class.
Definition DeclCXX.h:146
QualType getType() const
Retrieves the type of the base class.
Definition DeclCXX.h:249
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2129
CXXMethodDecl * getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, bool MayBeBase=false)
Find if RD declares a function that overrides this function, and if so, return it.
Definition DeclCXX.cpp:2423
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
base_class_range bases()
Definition DeclCXX.h:608
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition DeclCXX.h:602
base_class_iterator bases_begin()
Definition DeclCXX.h:615
This represents one expression.
Definition Expr.h:112
bool isGLValue() const
Definition Expr.h:287
QualType getType() const
Definition Expr.h:144
Represents a member of a struct/union/class.
Definition Decl.h:3157
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3393
Represents a function declaration or definition.
Definition Decl.h:1999
QualType getReturnType() const
Definition Decl.h:2842
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2771
param_iterator param_begin()
Definition Decl.h:2783
bool param_empty() const
Definition Decl.h:2782
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents a parameter to a function.
Definition Decl.h:1789
A (possibly-)qualified type.
Definition TypeBase.h:937
Represents a struct/union/class.
Definition Decl.h:4309
bool isVoidType() const
Definition TypeBase.h:8878
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
bool isArrayType() const
Definition TypeBase.h:8621
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:752
QualType getType() const
Definition Decl.h:722
Represents a variable declaration or definition.
Definition Decl.h:925
Compilation context for expressions.
Definition Compiler.h:110
const LangOptions & getLangOpts() const
Returns the language options.
Definition Context.cpp:280
const Function * getOrCreateObjCBlock(const BlockExpr *E)
Definition Context.cpp:541
~Context()
Cleans up the constexpr VM.
Definition Context.cpp:35
Context(ASTContext &Ctx)
Initialises the constexpr VM.
Definition Context.cpp:26
bool evaluateCharRange(State &Parent, const Expr *SizeExpr, const Expr *PtrExpr, APValue &Result)
Definition Context.cpp:224
bool canClassify(QualType T)
Definition Context.h:97
static bool isUnevaluatedBuiltin(unsigned ID)
Unevaluated builtins don't get their arguments put on the stack automatically.
Definition Context.cpp:613
unsigned getCharBit() const
Returns CHAR_BIT.
Definition Context.cpp:393
bool evaluateStrlen(State &Parent, const Expr *E, uint64_t &Result)
Evalute.
Definition Context.cpp:240
const llvm::fltSemantics & getFloatSemantics(QualType T) const
Return the floating-point semantics for T.
Definition Context.cpp:399
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Definition Context.h:126
void isPotentialConstantExprUnevaluated(State &Parent, const Expr *E, const FunctionDecl *FD)
Definition Context.cpp:57
unsigned collectBaseOffset(const RecordDecl *BaseDecl, const RecordDecl *DerivedDecl) const
Definition Context.cpp:578
const Record * getRecord(const RecordDecl *D) const
Definition Context.cpp:609
bool isPotentialConstantExpr(State &Parent, const FunctionDecl *FD)
Checks if a function is a potential constant expression.
Definition Context.cpp:37
const Function * getOrCreateFunction(const FunctionDecl *FuncDecl)
Definition Context.cpp:451
OptPrimType classify(QualType T) const
Classifies a type.
Definition Context.cpp:314
bool evaluateAsRValue(State &Parent, const Expr *E, APValue &Result)
Evaluates a toplevel expression as an rvalue.
Definition Context.cpp:70
const CXXMethodDecl * getOverridingFunction(const CXXRecordDecl *DynamicDecl, const CXXRecordDecl *StaticDecl, const CXXMethodDecl *InitialFunction) const
Definition Context.cpp:415
bool evaluate(State &Parent, const Expr *E, APValue &Result, ConstantExprKind Kind)
Like evaluateAsRvalue(), but does no implicit lvalue-to-rvalue conversion.
Definition Context.cpp:100
bool evaluateAsInitializer(State &Parent, const VarDecl *VD, const Expr *Init, APValue &Result)
Evaluates a toplevel initializer.
Definition Context.cpp:129
Bytecode function.
Definition Function.h:86
void clear()
Clears the stack.
bool empty() const
Returns whether the stack is empty.
Definition InterpStack.h:84
Interpreter context.
Definition InterpState.h:43
A pointer to a memory block, live or dead.
Definition Pointer.h:91
Pointer atIndex(uint64_t Idx) const
Offsets a pointer inside an array.
Definition Pointer.h:156
bool isDummy() const
Checks if the pointer points to a dummy value.
Definition Pointer.h:544
int64_t getIndex() const
Returns the index into an array.
Definition Pointer.h:609
unsigned getNumElems() const
Returns the number of elements.
Definition Pointer.h:593
bool isUnknownSizeArray() const
Checks if the structure is an array of unknown size.
Definition Pointer.h:412
bool isLive() const
Checks if the pointer is live.
Definition Pointer.h:265
T & elem(unsigned I) const
Dereferences the element at index I.
Definition Pointer.h:676
std::optional< APValue > toRValue(const Context &Ctx, QualType ResultType) const
Converts the pointer to an APValue that is an rvalue.
Definition Pointer.cpp:719
const Descriptor * getFieldDesc() const
Accessors for information about the innermost field.
Definition Pointer.h:323
size_t elemSize() const
Returns the element size of the innermost field.
Definition Pointer.h:355
const std::byte * getRawAddress() const
If backed by actual data (i.e.
Definition Pointer.h:603
The program contains and links the bytecode for all functions.
Definition Program.h:36
Structure/Class descriptor.
Definition Record.h:25
unsigned getNumBases() const
Definition Record.h:96
llvm::iterator_range< const_base_iter > bases() const
Definition Record.h:92
Interface for the VM to interact with the AST walker's context.
Definition State.h:79
OptionalDiagnostic FFDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
Diagnose that the evaluation could not be folded (FF => FoldFailure)
Definition State.cpp:21
Defines the clang::TargetInfo interface.
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
Definition PrimType.h:185
PrimType
Enumeration of the primitive types of the VM.
Definition PrimType.h:34
bool Init(InterpState &S, CodePtr OpPC)
Definition Interp.h:2100
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
Definition PrimType.cpp:23
bool Interpret(InterpState &S)
Interpreter entry point.
Definition Interp.cpp:2271
The JSON file list parser is used to communicate input to InstallAPI.
Expr::ConstantExprKind ConstantExprKind
Definition Expr.h:1042
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition ASTLambda.h:28
@ Result
The result type of a method or function.
Definition TypeBase.h:905
@ AK_Read
Definition State.h:27
const FunctionProtoType * T
U cast(CodeGen::Address addr)
Definition Address.h:327
Describes a memory block created by an allocation site.
Definition Descriptor.h:122
unsigned getElemSize() const
returns the size of an element when the structure is viewed as an array.
Definition Descriptor.h:244
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
Definition Descriptor.h:254
PrimType getPrimType() const
Definition Descriptor.h:236