clang 20.0.0git
Interp.cpp
Go to the documentation of this file.
1//===------- Interp.cpp - Interpreter 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 "Interp.h"
10#include "Function.h"
11#include "InterpFrame.h"
12#include "InterpShared.h"
13#include "InterpStack.h"
14#include "Opcode.h"
15#include "PrimType.h"
16#include "Program.h"
17#include "State.h"
21#include "clang/AST/DeclObjC.h"
22#include "clang/AST/Expr.h"
23#include "clang/AST/ExprCXX.h"
24#include "llvm/ADT/APSInt.h"
25#include "llvm/ADT/StringExtras.h"
26#include <limits>
27#include <vector>
28
29using namespace clang;
30using namespace clang::interp;
31
32static bool RetValue(InterpState &S, CodePtr &Pt, APValue &Result) {
33 llvm::report_fatal_error("Interpreter cannot return values");
34}
35
36//===----------------------------------------------------------------------===//
37// Jmp, Jt, Jf
38//===----------------------------------------------------------------------===//
39
40static bool Jmp(InterpState &S, CodePtr &PC, int32_t Offset) {
41 PC += Offset;
42 return true;
43}
44
45static bool Jt(InterpState &S, CodePtr &PC, int32_t Offset) {
46 if (S.Stk.pop<bool>()) {
47 PC += Offset;
48 }
49 return true;
50}
51
52static bool Jf(InterpState &S, CodePtr &PC, int32_t Offset) {
53 if (!S.Stk.pop<bool>()) {
54 PC += Offset;
55 }
56 return true;
57}
58
60 const ValueDecl *VD) {
61 const SourceInfo &E = S.Current->getSource(OpPC);
62 S.FFDiag(E, diag::note_constexpr_var_init_unknown, 1) << VD;
63 S.Note(VD->getLocation(), diag::note_declared_at) << VD->getSourceRange();
64}
65
67 const ValueDecl *VD);
69 const ValueDecl *D) {
70 const SourceInfo &E = S.Current->getSource(OpPC);
71
72 if (isa<ParmVarDecl>(D)) {
73 if (S.getLangOpts().CPlusPlus11) {
74 S.FFDiag(E, diag::note_constexpr_function_param_value_unknown) << D;
75 S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
76 } else {
77 S.FFDiag(E);
78 }
79 return false;
80 }
81
82 if (!D->getType().isConstQualified())
84 else if (const auto *VD = dyn_cast<VarDecl>(D);
85 VD && !VD->getAnyInitializer())
86 diagnoseMissingInitializer(S, OpPC, VD);
87
88 return false;
89}
90
92 const ValueDecl *VD) {
93 if (!S.getLangOpts().CPlusPlus)
94 return;
95
96 const SourceInfo &Loc = S.Current->getSource(OpPC);
97 if (const auto *VarD = dyn_cast<VarDecl>(VD);
98 VarD && VarD->getType().isConstQualified() &&
99 !VarD->getAnyInitializer()) {
100 diagnoseMissingInitializer(S, OpPC, VD);
101 return;
102 }
103
104 // Rather random, but this is to match the diagnostic output of the current
105 // interpreter.
106 if (isa<ObjCIvarDecl>(VD))
107 return;
108
110 S.FFDiag(Loc, diag::note_constexpr_ltor_non_const_int, 1) << VD;
111 S.Note(VD->getLocation(), diag::note_declared_at);
112 return;
113 }
114
115 S.FFDiag(Loc,
116 S.getLangOpts().CPlusPlus11 ? diag::note_constexpr_ltor_non_constexpr
117 : diag::note_constexpr_ltor_non_integral,
118 1)
119 << VD << VD->getType();
120 S.Note(VD->getLocation(), diag::note_declared_at);
121}
122
123static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
124 AccessKinds AK) {
125 if (Ptr.isActive())
126 return true;
127
128 assert(Ptr.inUnion());
129 assert(Ptr.isField() && Ptr.getField());
130
131 Pointer U = Ptr.getBase();
132 Pointer C = Ptr;
133 while (!U.isRoot() && U.inUnion() && !U.isActive()) {
134 if (U.getField())
135 C = U;
136 U = U.getBase();
137 }
138 assert(C.isField());
139
140 // Get the inactive field descriptor.
141 const FieldDecl *InactiveField = C.getField();
142 assert(InactiveField);
143
144 // Consider:
145 // union U {
146 // struct {
147 // int x;
148 // int y;
149 // } a;
150 // }
151 //
152 // When activating x, we will also activate a. If we now try to read
153 // from y, we will get to CheckActive, because y is not active. In that
154 // case, our U will be a (not a union). We return here and let later code
155 // handle this.
156 if (!U.getFieldDesc()->isUnion())
157 return true;
158
159 // Find the active field of the union.
160 const Record *R = U.getRecord();
161 assert(R && R->isUnion() && "Not a union");
162
163 const FieldDecl *ActiveField = nullptr;
164 for (const Record::Field &F : R->fields()) {
165 const Pointer &Field = U.atField(F.Offset);
166 if (Field.isActive()) {
167 ActiveField = Field.getField();
168 break;
169 }
170 }
171
172 const SourceInfo &Loc = S.Current->getSource(OpPC);
173 S.FFDiag(Loc, diag::note_constexpr_access_inactive_union_member)
174 << AK << InactiveField << !ActiveField << ActiveField;
175 return false;
176}
177
178static bool CheckTemporary(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
179 AccessKinds AK) {
180 if (auto ID = Ptr.getDeclID()) {
181 if (!Ptr.isStaticTemporary())
182 return true;
183
184 if (Ptr.getDeclDesc()->getType().isConstQualified())
185 return true;
186
187 if (S.P.getCurrentDecl() == ID)
188 return true;
189
190 const SourceInfo &E = S.Current->getSource(OpPC);
191 S.FFDiag(E, diag::note_constexpr_access_static_temporary, 1) << AK;
192 S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here);
193 return false;
194 }
195 return true;
196}
197
198static bool CheckGlobal(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
199 if (auto ID = Ptr.getDeclID()) {
200 if (!Ptr.isStatic())
201 return true;
202
203 if (S.P.getCurrentDecl() == ID)
204 return true;
205
206 S.FFDiag(S.Current->getLocation(OpPC), diag::note_constexpr_modify_global);
207 return false;
208 }
209 return true;
210}
211
212namespace clang {
213namespace interp {
214static void popArg(InterpState &S, const Expr *Arg) {
215 PrimType Ty = S.getContext().classify(Arg).value_or(PT_Ptr);
216 TYPE_SWITCH(Ty, S.Stk.discard<T>());
217}
218
220 assert(S.Current);
221 const Function *CurFunc = S.Current->getFunction();
222 assert(CurFunc);
223
224 if (CurFunc->isUnevaluatedBuiltin())
225 return;
226
227 // Some builtin functions require us to only look at the call site, since
228 // the classified parameter types do not match.
229 if (CurFunc->isBuiltin()) {
230 const auto *CE =
231 cast<CallExpr>(S.Current->Caller->getExpr(S.Current->getRetPC()));
232 for (int32_t I = CE->getNumArgs() - 1; I >= 0; --I) {
233 const Expr *A = CE->getArg(I);
234 popArg(S, A);
235 }
236 return;
237 }
238
239 if (S.Current->Caller && CurFunc->isVariadic()) {
240 // CallExpr we're look for is at the return PC of the current function, i.e.
241 // in the caller.
242 // This code path should be executed very rarely.
243 unsigned NumVarArgs;
244 const Expr *const *Args = nullptr;
245 unsigned NumArgs = 0;
246 const Expr *CallSite = S.Current->Caller->getExpr(S.Current->getRetPC());
247 if (const auto *CE = dyn_cast<CallExpr>(CallSite)) {
248 Args = CE->getArgs();
249 NumArgs = CE->getNumArgs();
250 } else if (const auto *CE = dyn_cast<CXXConstructExpr>(CallSite)) {
251 Args = CE->getArgs();
252 NumArgs = CE->getNumArgs();
253 } else
254 assert(false && "Can't get arguments from that expression type");
255
256 assert(NumArgs >= CurFunc->getNumWrittenParams());
257 NumVarArgs = NumArgs - (CurFunc->getNumWrittenParams() +
258 isa<CXXOperatorCallExpr>(CallSite));
259 for (unsigned I = 0; I != NumVarArgs; ++I) {
260 const Expr *A = Args[NumArgs - 1 - I];
261 popArg(S, A);
262 }
263 }
264
265 // And in any case, remove the fixed parameters (the non-variadic ones)
266 // at the end.
267 S.Current->popArgs();
268}
269
270bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
271 if (!Ptr.isExtern())
272 return true;
273
274 if (Ptr.isInitialized() ||
275 (Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl))
276 return true;
277
278 if (!S.checkingPotentialConstantExpression() && S.getLangOpts().CPlusPlus) {
279 const auto *VD = Ptr.getDeclDesc()->asValueDecl();
280 diagnoseNonConstVariable(S, OpPC, VD);
281 }
282 return false;
283}
284
285bool CheckArray(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
286 if (!Ptr.isUnknownSizeArray())
287 return true;
288 const SourceInfo &E = S.Current->getSource(OpPC);
289 S.FFDiag(E, diag::note_constexpr_unsized_array_indexed);
290 return false;
291}
292
293bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
294 AccessKinds AK) {
295 if (Ptr.isZero()) {
296 const auto &Src = S.Current->getSource(OpPC);
297
298 if (Ptr.isField())
299 S.FFDiag(Src, diag::note_constexpr_null_subobject) << CSK_Field;
300 else
301 S.FFDiag(Src, diag::note_constexpr_access_null) << AK;
302
303 return false;
304 }
305
306 if (!Ptr.isLive()) {
307 const auto &Src = S.Current->getSource(OpPC);
308 bool IsTemp = Ptr.isTemporary();
309
310 S.FFDiag(Src, diag::note_constexpr_lifetime_ended, 1) << AK << !IsTemp;
311
312 if (IsTemp)
313 S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here);
314 else
315 S.Note(Ptr.getDeclLoc(), diag::note_declared_at);
316
317 return false;
318 }
319
320 return true;
321}
322
323bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
324 assert(Desc);
325
326 auto IsConstType = [&S](const VarDecl *VD) -> bool {
327 QualType T = VD->getType();
328
329 if (T.isConstant(S.getCtx()))
330 return true;
331
332 if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11)
335 T.isConstQualified();
336
337 if (T.isConstQualified())
338 return true;
339
340 if (const auto *RT = T->getAs<ReferenceType>())
341 return RT->getPointeeType().isConstQualified();
342
343 if (const auto *PT = T->getAs<PointerType>())
344 return PT->getPointeeType().isConstQualified();
345
346 return false;
347 };
348
349 if (const auto *D = Desc->asVarDecl();
350 D && D->hasGlobalStorage() && D != S.EvaluatingDecl && !IsConstType(D)) {
351 diagnoseNonConstVariable(S, OpPC, D);
352 return false;
353 }
354
355 return true;
356}
357
358static bool CheckConstant(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
359 if (!Ptr.isBlockPointer())
360 return true;
361 return CheckConstant(S, OpPC, Ptr.getDeclDesc());
362}
363
364bool CheckNull(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
365 CheckSubobjectKind CSK) {
366 if (!Ptr.isZero())
367 return true;
368 const SourceInfo &Loc = S.Current->getSource(OpPC);
369 S.FFDiag(Loc, diag::note_constexpr_null_subobject)
370 << CSK << S.Current->getRange(OpPC);
371
372 return false;
373}
374
375bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
376 AccessKinds AK) {
377 if (!Ptr.isOnePastEnd())
378 return true;
379 const SourceInfo &Loc = S.Current->getSource(OpPC);
380 S.FFDiag(Loc, diag::note_constexpr_access_past_end)
381 << AK << S.Current->getRange(OpPC);
382 return false;
383}
384
385bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
386 CheckSubobjectKind CSK) {
387 if (!Ptr.isElementPastEnd())
388 return true;
389 const SourceInfo &Loc = S.Current->getSource(OpPC);
390 S.FFDiag(Loc, diag::note_constexpr_past_end_subobject)
391 << CSK << S.Current->getRange(OpPC);
392 return false;
393}
394
395bool CheckSubobject(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
396 CheckSubobjectKind CSK) {
397 if (!Ptr.isOnePastEnd())
398 return true;
399
400 const SourceInfo &Loc = S.Current->getSource(OpPC);
401 S.FFDiag(Loc, diag::note_constexpr_past_end_subobject)
402 << CSK << S.Current->getRange(OpPC);
403 return false;
404}
405
406bool CheckDowncast(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
407 uint32_t Offset) {
408 uint32_t MinOffset = Ptr.getDeclDesc()->getMetadataSize();
409 uint32_t PtrOffset = Ptr.getByteOffset();
410
411 // We subtract Offset from PtrOffset. The result must be at least
412 // MinOffset.
413 if (Offset < PtrOffset && (PtrOffset - Offset) >= MinOffset)
414 return true;
415
416 const auto *E = cast<CastExpr>(S.Current->getExpr(OpPC));
417 QualType TargetQT = E->getType()->getPointeeType();
418 QualType MostDerivedQT = Ptr.getDeclPtr().getType();
419
420 S.CCEDiag(E, diag::note_constexpr_invalid_downcast)
421 << MostDerivedQT << TargetQT;
422
423 return false;
424}
425
426bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
427 assert(Ptr.isLive() && "Pointer is not live");
428 if (!Ptr.isConst() || Ptr.isMutable())
429 return true;
430
431 // The This pointer is writable in constructors and destructors,
432 // even if isConst() returns true.
433 // TODO(perf): We could be hitting this code path quite a lot in complex
434 // constructors. Is there a better way to do this?
435 if (S.Current->getFunction()) {
436 for (const InterpFrame *Frame = S.Current; Frame; Frame = Frame->Caller) {
437 if (const Function *Func = Frame->getFunction();
438 Func && (Func->isConstructor() || Func->isDestructor()) &&
439 Ptr.block() == Frame->getThis().block()) {
440 return true;
441 }
442 }
443 }
444
445 if (!Ptr.isBlockPointer())
446 return false;
447
448 const QualType Ty = Ptr.getType();
449 const SourceInfo &Loc = S.Current->getSource(OpPC);
450 S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
451 return false;
452}
453
454bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
455 assert(Ptr.isLive() && "Pointer is not live");
456 if (!Ptr.isMutable())
457 return true;
458
459 // In C++14 onwards, it is permitted to read a mutable member whose
460 // lifetime began within the evaluation.
461 if (S.getLangOpts().CPlusPlus14 &&
462 Ptr.block()->getEvalID() == S.Ctx.getEvalID())
463 return true;
464
465 const SourceInfo &Loc = S.Current->getSource(OpPC);
466 const FieldDecl *Field = Ptr.getField();
467 S.FFDiag(Loc, diag::note_constexpr_access_mutable, 1) << AK_Read << Field;
468 S.Note(Field->getLocation(), diag::note_declared_at);
469 return false;
470}
471
472bool CheckVolatile(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
473 AccessKinds AK) {
474 assert(Ptr.isLive());
475
476 // FIXME: This check here might be kinda expensive. Maybe it would be better
477 // to have another field in InlineDescriptor for this?
478 if (!Ptr.isBlockPointer())
479 return true;
480
481 QualType PtrType = Ptr.getType();
482 if (!PtrType.isVolatileQualified())
483 return true;
484
485 const SourceInfo &Loc = S.Current->getSource(OpPC);
486 if (S.getLangOpts().CPlusPlus)
487 S.FFDiag(Loc, diag::note_constexpr_access_volatile_type) << AK << PtrType;
488 else
489 S.FFDiag(Loc);
490 return false;
491}
492
493bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
494 AccessKinds AK) {
495 assert(Ptr.isLive());
496
497 if (Ptr.isInitialized())
498 return true;
499
500 if (const auto *VD = Ptr.getDeclDesc()->asVarDecl();
501 VD && VD->hasGlobalStorage()) {
502 const SourceInfo &Loc = S.Current->getSource(OpPC);
503 if (VD->getAnyInitializer()) {
504 S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
505 S.Note(VD->getLocation(), diag::note_declared_at);
506 } else {
507 diagnoseMissingInitializer(S, OpPC, VD);
508 }
509 return false;
510 }
511
512 if (!S.checkingPotentialConstantExpression()) {
513 S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_uninit)
514 << AK << /*uninitialized=*/true << S.Current->getRange(OpPC);
515 }
516 return false;
517}
518
520 if (Ptr.isInitialized())
521 return true;
522
523 assert(S.getLangOpts().CPlusPlus);
524 const auto *VD = cast<VarDecl>(Ptr.getDeclDesc()->asValueDecl());
525 if ((!VD->hasConstantInitialization() &&
526 VD->mightBeUsableInConstantExpressions(S.getCtx())) ||
527 (S.getLangOpts().OpenCL && !S.getLangOpts().CPlusPlus11 &&
528 !VD->hasICEInitializer(S.getCtx()))) {
529 const SourceInfo &Loc = S.Current->getSource(OpPC);
530 S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
531 S.Note(VD->getLocation(), diag::note_declared_at);
532 }
533 return false;
534}
535
536bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
537 AccessKinds AK) {
538 if (!CheckLive(S, OpPC, Ptr, AK))
539 return false;
540 if (!CheckConstant(S, OpPC, Ptr))
541 return false;
542
543 if (!CheckDummy(S, OpPC, Ptr, AK))
544 return false;
545 if (!CheckExtern(S, OpPC, Ptr))
546 return false;
547 if (!CheckRange(S, OpPC, Ptr, AK))
548 return false;
549 if (!CheckActive(S, OpPC, Ptr, AK))
550 return false;
551 if (!CheckInitialized(S, OpPC, Ptr, AK))
552 return false;
553 if (!CheckTemporary(S, OpPC, Ptr, AK))
554 return false;
555 if (!CheckMutable(S, OpPC, Ptr))
556 return false;
557 if (!CheckVolatile(S, OpPC, Ptr, AK))
558 return false;
559 return true;
560}
561
562bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
563 if (!CheckLive(S, OpPC, Ptr, AK_Assign))
564 return false;
565 if (!CheckDummy(S, OpPC, Ptr, AK_Assign))
566 return false;
567 if (!CheckExtern(S, OpPC, Ptr))
568 return false;
569 if (!CheckRange(S, OpPC, Ptr, AK_Assign))
570 return false;
571 if (!CheckGlobal(S, OpPC, Ptr))
572 return false;
573 if (!CheckConst(S, OpPC, Ptr))
574 return false;
575 return true;
576}
577
578bool CheckInvoke(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
579 if (!CheckLive(S, OpPC, Ptr, AK_MemberCall))
580 return false;
581 if (!Ptr.isDummy()) {
582 if (!CheckExtern(S, OpPC, Ptr))
583 return false;
584 if (!CheckRange(S, OpPC, Ptr, AK_MemberCall))
585 return false;
586 }
587 return true;
588}
589
590bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
591 if (!CheckLive(S, OpPC, Ptr, AK_Assign))
592 return false;
593 if (!CheckRange(S, OpPC, Ptr, AK_Assign))
594 return false;
595 return true;
596}
597
598bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
599
600 if (F->isVirtual() && !S.getLangOpts().CPlusPlus20) {
601 const SourceLocation &Loc = S.Current->getLocation(OpPC);
602 S.CCEDiag(Loc, diag::note_constexpr_virtual_call);
603 return false;
604 }
605
606 if (F->isConstexpr() && F->hasBody() &&
607 (F->getDecl()->isConstexpr() || F->getDecl()->hasAttr<MSConstexprAttr>()))
608 return true;
609
610 // Implicitly constexpr.
611 if (F->isLambdaStaticInvoker())
612 return true;
613
614 const SourceLocation &Loc = S.Current->getLocation(OpPC);
615 if (S.getLangOpts().CPlusPlus11) {
616 const FunctionDecl *DiagDecl = F->getDecl();
617
618 // Invalid decls have been diagnosed before.
619 if (DiagDecl->isInvalidDecl())
620 return false;
621
622 // If this function is not constexpr because it is an inherited
623 // non-constexpr constructor, diagnose that directly.
624 const auto *CD = dyn_cast<CXXConstructorDecl>(DiagDecl);
625 if (CD && CD->isInheritingConstructor()) {
626 const auto *Inherited = CD->getInheritedConstructor().getConstructor();
627 if (!Inherited->isConstexpr())
628 DiagDecl = CD = Inherited;
629 }
630
631 // FIXME: If DiagDecl is an implicitly-declared special member function
632 // or an inheriting constructor, we should be much more explicit about why
633 // it's not constexpr.
634 if (CD && CD->isInheritingConstructor()) {
635 S.FFDiag(Loc, diag::note_constexpr_invalid_inhctor, 1)
636 << CD->getInheritedConstructor().getConstructor()->getParent();
637 S.Note(DiagDecl->getLocation(), diag::note_declared_at);
638 } else {
639 // Don't emit anything if the function isn't defined and we're checking
640 // for a constant expression. It might be defined at the point we're
641 // actually calling it.
642 bool IsExtern = DiagDecl->getStorageClass() == SC_Extern;
643 if (!DiagDecl->isDefined() && !IsExtern && DiagDecl->isConstexpr() &&
644 S.checkingPotentialConstantExpression())
645 return false;
646
647 // If the declaration is defined, declared 'constexpr' _and_ has a body,
648 // the below diagnostic doesn't add anything useful.
649 if (DiagDecl->isDefined() && DiagDecl->isConstexpr() &&
650 DiagDecl->hasBody())
651 return false;
652
653 S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
654 << DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
655
656 if (DiagDecl->getDefinition())
657 S.Note(DiagDecl->getDefinition()->getLocation(),
658 diag::note_declared_at);
659 else
660 S.Note(DiagDecl->getLocation(), diag::note_declared_at);
661 }
662 } else {
663 S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
664 }
665
666 return false;
667}
668
670 if ((S.Current->getDepth() + 1) > S.getLangOpts().ConstexprCallDepth) {
671 S.FFDiag(S.Current->getSource(OpPC),
672 diag::note_constexpr_depth_limit_exceeded)
673 << S.getLangOpts().ConstexprCallDepth;
674 return false;
675 }
676
677 return true;
678}
679
680bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This) {
681 if (!This.isZero())
682 return true;
683
684 const SourceInfo &Loc = S.Current->getSource(OpPC);
685
686 bool IsImplicit = false;
687 if (const auto *E = dyn_cast_if_present<CXXThisExpr>(Loc.asExpr()))
688 IsImplicit = E->isImplicit();
689
690 if (S.getLangOpts().CPlusPlus11)
691 S.FFDiag(Loc, diag::note_constexpr_this) << IsImplicit;
692 else
693 S.FFDiag(Loc);
694
695 return false;
696}
697
698bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD) {
699 if (!MD->isPureVirtual())
700 return true;
701 const SourceInfo &E = S.Current->getSource(OpPC);
702 S.FFDiag(E, diag::note_constexpr_pure_virtual_call, 1) << MD;
703 S.Note(MD->getLocation(), diag::note_declared_at);
704 return false;
705}
706
708 APFloat::opStatus Status) {
709 const SourceInfo &E = S.Current->getSource(OpPC);
710
711 // [expr.pre]p4:
712 // If during the evaluation of an expression, the result is not
713 // mathematically defined [...], the behavior is undefined.
714 // FIXME: C++ rules require us to not conform to IEEE 754 here.
715 if (Result.isNan()) {
716 S.CCEDiag(E, diag::note_constexpr_float_arithmetic)
717 << /*NaN=*/true << S.Current->getRange(OpPC);
718 return S.noteUndefinedBehavior();
719 }
720
721 // In a constant context, assume that any dynamic rounding mode or FP
722 // exception state matches the default floating-point environment.
723 if (S.inConstantContext())
724 return true;
725
726 FPOptions FPO = E.asExpr()->getFPFeaturesInEffect(S.Ctx.getLangOpts());
727
728 if ((Status & APFloat::opInexact) &&
729 FPO.getRoundingMode() == llvm::RoundingMode::Dynamic) {
730 // Inexact result means that it depends on rounding mode. If the requested
731 // mode is dynamic, the evaluation cannot be made in compile time.
732 S.FFDiag(E, diag::note_constexpr_dynamic_rounding);
733 return false;
734 }
735
736 if ((Status != APFloat::opOK) &&
737 (FPO.getRoundingMode() == llvm::RoundingMode::Dynamic ||
739 FPO.getAllowFEnvAccess())) {
740 S.FFDiag(E, diag::note_constexpr_float_arithmetic_strict);
741 return false;
742 }
743
744 if ((Status & APFloat::opStatus::opInvalidOp) &&
746 // There is no usefully definable result.
747 S.FFDiag(E);
748 return false;
749 }
750
751 return true;
752}
753
755 if (S.getLangOpts().CPlusPlus20)
756 return true;
757
758 const SourceInfo &E = S.Current->getSource(OpPC);
759 S.CCEDiag(E, diag::note_constexpr_new);
760 return true;
761}
762
763bool CheckNewDeleteForms(InterpState &S, CodePtr OpPC, bool NewWasArray,
764 bool DeleteIsArray, const Descriptor *D,
765 const Expr *NewExpr) {
766 if (NewWasArray == DeleteIsArray)
767 return true;
768
769 QualType TypeToDiagnose;
770 // We need to shuffle things around a bit here to get a better diagnostic,
771 // because the expression we allocated the block for was of type int*,
772 // but we want to get the array size right.
773 if (D->isArray()) {
774 QualType ElemQT = D->getType()->getPointeeType();
775 TypeToDiagnose = S.getCtx().getConstantArrayType(
776 ElemQT, APInt(64, static_cast<uint64_t>(D->getNumElems()), false),
777 nullptr, ArraySizeModifier::Normal, 0);
778 } else
779 TypeToDiagnose = D->getType()->getPointeeType();
780
781 const SourceInfo &E = S.Current->getSource(OpPC);
782 S.FFDiag(E, diag::note_constexpr_new_delete_mismatch)
783 << DeleteIsArray << 0 << TypeToDiagnose;
784 S.Note(NewExpr->getExprLoc(), diag::note_constexpr_dynamic_alloc_here)
785 << NewExpr->getSourceRange();
786 return false;
787}
788
789bool CheckDeleteSource(InterpState &S, CodePtr OpPC, const Expr *Source,
790 const Pointer &Ptr) {
791 if (Source && isa<CXXNewExpr>(Source))
792 return true;
793
794 // Whatever this is, we didn't heap allocate it.
795 const SourceInfo &Loc = S.Current->getSource(OpPC);
796 S.FFDiag(Loc, diag::note_constexpr_delete_not_heap_alloc)
797 << Ptr.toDiagnosticString(S.getCtx());
798
799 if (Ptr.isTemporary())
800 S.Note(Ptr.getDeclLoc(), diag::note_constexpr_temporary_here);
801 else
802 S.Note(Ptr.getDeclLoc(), diag::note_declared_at);
803 return false;
804}
805
806/// We aleady know the given DeclRefExpr is invalid for some reason,
807/// now figure out why and print appropriate diagnostics.
808bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR) {
809 const ValueDecl *D = DR->getDecl();
810 return diagnoseUnknownDecl(S, OpPC, D);
811}
812
813bool CheckDummy(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
814 AccessKinds AK) {
815 if (!Ptr.isDummy())
816 return true;
817
818 const Descriptor *Desc = Ptr.getDeclDesc();
819 const ValueDecl *D = Desc->asValueDecl();
820 if (!D)
821 return false;
822
823 if (AK == AK_Read || AK == AK_Increment || AK == AK_Decrement)
824 return diagnoseUnknownDecl(S, OpPC, D);
825
826 assert(AK == AK_Assign);
827 if (S.getLangOpts().CPlusPlus11) {
828 const SourceInfo &E = S.Current->getSource(OpPC);
829 S.FFDiag(E, diag::note_constexpr_modify_global);
830 }
831 return false;
832}
833
835 const CallExpr *CE, unsigned ArgSize) {
836 auto Args = llvm::ArrayRef(CE->getArgs(), CE->getNumArgs());
837 auto NonNullArgs = collectNonNullArgs(F->getDecl(), Args);
838 unsigned Offset = 0;
839 unsigned Index = 0;
840 for (const Expr *Arg : Args) {
841 if (NonNullArgs[Index] && Arg->getType()->isPointerType()) {
842 const Pointer &ArgPtr = S.Stk.peek<Pointer>(ArgSize - Offset);
843 if (ArgPtr.isZero()) {
844 const SourceLocation &Loc = S.Current->getLocation(OpPC);
845 S.CCEDiag(Loc, diag::note_non_null_attribute_failed);
846 return false;
847 }
848 }
849
850 Offset += align(primSize(S.Ctx.classify(Arg).value_or(PT_Ptr)));
851 ++Index;
852 }
853 return true;
854}
855
856// FIXME: This is similar to code we already have in Compiler.cpp.
857// I think it makes sense to instead add the field and base destruction stuff
858// to the destructor Function itself. Then destroying a record would really
859// _just_ be calling its destructor. That would also help with the diagnostic
860// difference when the destructor or a field/base fails.
862 const Pointer &BasePtr,
863 const Descriptor *Desc) {
864 assert(Desc->isRecord());
865 const Record *R = Desc->ElemRecord;
866 assert(R);
867
868 if (Pointer::pointToSameBlock(BasePtr, S.Current->getThis())) {
869 const SourceInfo &Loc = S.Current->getSource(OpPC);
870 S.FFDiag(Loc, diag::note_constexpr_double_destroy);
871 return false;
872 }
873
874 // Destructor of this record.
875 if (const CXXDestructorDecl *Dtor = R->getDestructor();
876 Dtor && !Dtor->isTrivial()) {
877 const Function *DtorFunc = S.getContext().getOrCreateFunction(Dtor);
878 if (!DtorFunc)
879 return false;
880
881 S.Stk.push<Pointer>(BasePtr);
882 if (!Call(S, OpPC, DtorFunc, 0))
883 return false;
884 }
885 return true;
886}
887
888bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
889 assert(B);
890 const Descriptor *Desc = B->getDescriptor();
891
892 if (Desc->isPrimitive() || Desc->isPrimitiveArray())
893 return true;
894
895 assert(Desc->isRecord() || Desc->isCompositeArray());
896
897 if (Desc->isCompositeArray()) {
898 const Descriptor *ElemDesc = Desc->ElemDesc;
899 assert(ElemDesc->isRecord());
900
901 Pointer RP(const_cast<Block *>(B));
902 for (unsigned I = 0; I != Desc->getNumElems(); ++I) {
903 if (!runRecordDestructor(S, OpPC, RP.atIndex(I).narrow(), ElemDesc))
904 return false;
905 }
906 return true;
907 }
908
909 assert(Desc->isRecord());
910 return runRecordDestructor(S, OpPC, Pointer(const_cast<Block *>(B)), Desc);
911}
912
914 const APSInt &Value) {
915 llvm::APInt Min;
916 llvm::APInt Max;
917
918 if (S.EvaluatingDecl && !S.EvaluatingDecl->isConstexpr())
919 return;
920
921 ED->getValueRange(Max, Min);
922 --Max;
923
924 if (ED->getNumNegativeBits() &&
925 (Max.slt(Value.getSExtValue()) || Min.sgt(Value.getSExtValue()))) {
926 const SourceLocation &Loc = S.Current->getLocation(OpPC);
927 S.CCEDiag(Loc, diag::note_constexpr_unscoped_enum_out_of_range)
928 << llvm::toString(Value, 10) << Min.getSExtValue() << Max.getSExtValue()
929 << ED;
930 } else if (!ED->getNumNegativeBits() && Max.ult(Value.getZExtValue())) {
931 const SourceLocation &Loc = S.Current->getLocation(OpPC);
932 S.CCEDiag(Loc, diag::note_constexpr_unscoped_enum_out_of_range)
933 << llvm::toString(Value, 10) << Min.getZExtValue() << Max.getZExtValue()
934 << ED;
935 }
936}
937
939 // The current stack frame when we started Interpret().
940 // This is being used by the ops to determine wheter
941 // to return from this function and thus terminate
942 // interpretation.
943 const InterpFrame *StartFrame = S.Current;
944 assert(!S.Current->isRoot());
945 CodePtr PC = S.Current->getPC();
946
947 // Empty program.
948 if (!PC)
949 return true;
950
951 for (;;) {
952 auto Op = PC.read<Opcode>();
953 CodePtr OpPC = PC;
954
955 switch (Op) {
956#define GET_INTERP
957#include "Opcodes.inc"
958#undef GET_INTERP
959 }
960 }
961}
962
963} // namespace interp
964} // namespace clang
Defines the clang::ASTContext interface.
const Decl * D
Expr * E
Defines the clang::Expr interface and subclasses for C++ expressions.
static bool Jmp(InterpState &S, CodePtr &PC, int32_t Offset)
Definition: Interp.cpp:40
static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Definition: Interp.cpp:123
static bool CheckGlobal(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Definition: Interp.cpp:198
static bool CheckTemporary(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Definition: Interp.cpp:178
static bool Jt(InterpState &S, CodePtr &PC, int32_t Offset)
Definition: Interp.cpp:45
static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC, const ValueDecl *VD)
Definition: Interp.cpp:91
static bool RetValue(InterpState &S, CodePtr &Pt, APValue &Result)
Definition: Interp.cpp:32
static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC, const ValueDecl *D)
Definition: Interp.cpp:68
static bool Jf(InterpState &S, CodePtr &PC, int32_t Offset)
Definition: Interp.cpp:52
static void diagnoseMissingInitializer(InterpState &S, CodePtr OpPC, const ValueDecl *VD)
Definition: Interp.cpp:59
#define TYPE_SWITCH(Expr, B)
Definition: PrimType.h:148
SourceLocation Loc
Definition: SemaObjC.cpp:758
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2803
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2064
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2830
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:3008
Expr ** getArgs()
Retrieve the call arguments.
Definition: Expr.h:3011
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1265
ValueDecl * getDecl()
Definition: Expr.h:1333
bool isInvalidDecl() const
Definition: DeclBase.h:595
SourceLocation getLocation() const
Definition: DeclBase.h:446
bool hasAttr() const
Definition: DeclBase.h:584
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:434
Represents an enum.
Definition: Decl.h:3844
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4041
void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const
Calculates the [Min,Max) values the enum can store based on the NumPositiveBits and NumNegativeBits.
Definition: Decl.cpp:4972
This represents one expression.
Definition: Expr.h:110
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Returns the set of floating point options that apply to this expression.
Definition: Expr.cpp:3864
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
QualType getType() const
Definition: Expr.h:142
LangOptions::FPExceptionModeKind getExceptionMode() const
Definition: LangOptions.h:865
RoundingMode getRoundingMode() const
Definition: LangOptions.h:853
Represents a member of a struct/union/class.
Definition: Decl.h:3030
Represents a function declaration or definition.
Definition: Decl.h:1932
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2302
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2760
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:2395
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2285
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition: Decl.h:2214
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3144
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
Definition: Decl.cpp:3191
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Definition: LangOptions.h:278
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3187
A (possibly-)qualified type.
Definition: Type.h:941
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:7834
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:7823
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3428
const LangOptions & getLangOpts() const
Definition: Sema.h:595
Encodes a location in the source.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
Definition: Type.cpp:2167
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
Definition: Type.cpp:2217
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:8434
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8540
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:667
QualType getType() const
Definition: Decl.h:678
Represents a variable declaration or definition.
Definition: Decl.h:879
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition: Decl.h:1174
A memory block, either on the stack or in the heap.
Definition: InterpBlock.h:49
const Descriptor * getDescriptor() const
Returns the block's descriptor.
Definition: InterpBlock.h:67
unsigned getEvalID() const
The Evaluation ID this block was created in.
Definition: InterpBlock.h:85
Pointer into the code segment.
Definition: Source.h:30
std::enable_if_t<!std::is_pointer< T >::value, T > read()
Reads data and advances the pointer.
Definition: Source.h:60
Base class for stack frames, shared between VM and walker.
Definition: Frame.h:25
Bytecode function.
Definition: Function.h:77
bool isBuiltin() const
Definition: Function.h:180
const FunctionDecl * getDecl() const
Returns the original FunctionDecl.
Definition: Function.h:92
bool hasBody() const
Checks if the function already has a body attached.
Definition: Function.h:171
bool isVirtual() const
Checks if the function is virtual.
Definition: Function.cpp:47
bool isUnevaluatedBuiltin() const
Definition: Function.h:182
bool isConstexpr() const
Checks if the function is valid to call in constexpr.
Definition: Function.h:132
unsigned getNumWrittenParams() const
Returns the number of parameter this function takes when it's called, i.e excluding the instance poin...
Definition: Function.h:188
bool isLambdaStaticInvoker() const
Returns whether this function is a lambda static invoker, which we generate custom byte code for.
Definition: Function.h:151
bool isVariadic() const
Definition: Function.h:176
Frame storing local variables.
Definition: InterpFrame.h:26
Interpreter context.
Definition: InterpState.h:36
A pointer to a memory block, live or dead.
Definition: Pointer.h:82
Pointer narrow() const
Restricts the scope of an array element pointer.
Definition: Pointer.h:183
bool isInitialized() const
Checks if an object was initialized.
Definition: Pointer.cpp:304
bool isStatic() const
Checks if the storage is static.
Definition: Pointer.h:480
bool inUnion() const
Definition: Pointer.h:403
Pointer atIndex(uint64_t Idx) const
Offsets a pointer inside an array.
Definition: Pointer.h:149
bool isDummy() const
Checks if the pointer points to a dummy value.
Definition: Pointer.h:527
bool isExtern() const
Checks if the storage is extern.
Definition: Pointer.h:474
bool isActive() const
Checks if the object is active.
Definition: Pointer.h:516
bool isConst() const
Checks if an object or a subfield is mutable.
Definition: Pointer.h:538
bool isMutable() const
Checks if the field is mutable.
Definition: Pointer.h:498
bool isUnknownSizeArray() const
Checks if the structure is an array of unknown size.
Definition: Pointer.h:416
QualType getType() const
Returns the type of the innermost field.
Definition: Pointer.h:338
bool isLive() const
Checks if the pointer is live.
Definition: Pointer.h:269
bool isStaticTemporary() const
Checks if the storage is a static temporary.
Definition: Pointer.h:495
Pointer getBase() const
Returns a pointer to the object of which this pointer is a field.
Definition: Pointer.h:308
std::string toDiagnosticString(const ASTContext &Ctx) const
Converts the pointer to a string usable in diagnostics.
Definition: Pointer.cpp:294
bool isZero() const
Checks if the pointer is null.
Definition: Pointer.h:260
const Descriptor * getDeclDesc() const
Accessor for information about the declaration site.
Definition: Pointer.h:283
static bool pointToSameBlock(const Pointer &A, const Pointer &B)
Checks if both given pointers point to the same block.
Definition: Pointer.cpp:447
bool isOnePastEnd() const
Checks if the index is one past end.
Definition: Pointer.h:590
const FieldDecl * getField() const
Returns the field information.
Definition: Pointer.h:468
bool isElementPastEnd() const
Checks if the pointer is an out-of-bounds element pointer.
Definition: Pointer.h:613
bool isBlockPointer() const
Definition: Pointer.h:456
bool isTemporary() const
Checks if the storage is temporary.
Definition: Pointer.h:487
SourceLocation getDeclLoc() const
Definition: Pointer.h:293
const Block * block() const
Definition: Pointer.h:569
Pointer getDeclPtr() const
Definition: Pointer.h:352
std::optional< unsigned > getDeclID() const
Returns the declaration ID.
Definition: Pointer.h:545
bool isField() const
Checks if the item is a field in an object.
Definition: Pointer.h:275
unsigned getByteOffset() const
Returns the byte offset from the start.
Definition: Pointer.h:554
Structure/Class descriptor.
Definition: Record.h:25
bool isUnion() const
Checks if the record is a union.
Definition: Record.h:56
const CXXDestructorDecl * getDestructor() const
Returns the destructor of the record, if any.
Definition: Record.h:70
llvm::iterator_range< const_field_iter > fields() const
Definition: Record.h:77
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:77
bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a value can be initialized.
Definition: Interp.cpp:590
bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B)
Definition: Interp.cpp:888
llvm::APInt APInt
Definition: Integral.h:29
bool Interpret(InterpState &S, APValue &Result)
Interpreter entry point.
Definition: Interp.cpp:938
static bool runRecordDestructor(InterpState &S, CodePtr OpPC, const Pointer &BasePtr, const Descriptor *Desc)
Definition: Interp.cpp:861
bool CheckDowncast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, uint32_t Offset)
Checks if the dowcast using the given offset is possible with the given pointer.
Definition: Interp.cpp:406
bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR)
We aleady know the given DeclRefExpr is invalid for some reason, now figure out why and print appropr...
Definition: Interp.cpp:808
bool CheckCallDepth(InterpState &S, CodePtr OpPC)
Checks if calling the currently active function would exceed the allowed call depth.
Definition: Interp.cpp:669
bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This)
Checks the 'this' pointer.
Definition: Interp.cpp:680
bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
Checks if the Descriptor is of a constexpr or const global variable.
Definition: Interp.cpp:323
bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a pointer points to a mutable field.
Definition: Interp.cpp:454
bool CheckSubobject(InterpState &S, CodePtr OpPC, const Pointer &Ptr, CheckSubobjectKind CSK)
Checks if Ptr is a one-past-the-end pointer.
Definition: Interp.cpp:395
bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a value can be loaded from a block.
Definition: Interp.cpp:536
bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Definition: Interp.cpp:493
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
Definition: PrimType.h:126
bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is in range.
Definition: Interp.cpp:375
bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD)
Checks if a method is pure virtual.
Definition: Interp.cpp:698
bool This(InterpState &S, CodePtr OpPC)
Definition: Interp.h:2263
bool CheckDynamicMemoryAllocation(InterpState &S, CodePtr OpPC)
Checks if dynamic memory allocation is available in the current language mode.
Definition: Interp.cpp:754
bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is live and accessible.
Definition: Interp.cpp:293
static void popArg(InterpState &S, const Expr *Arg)
Definition: Interp.cpp:214
void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED, const APSInt &Value)
Definition: Interp.cpp:913
PrimType
Enumeration of the primitive types of the VM.
Definition: PrimType.h:33
bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a value can be stored in a block.
Definition: Interp.cpp:562
bool CheckNull(InterpState &S, CodePtr OpPC, const Pointer &Ptr, CheckSubobjectKind CSK)
Checks if a pointer is null.
Definition: Interp.cpp:364
bool CheckDeleteSource(InterpState &S, CodePtr OpPC, const Expr *Source, const Pointer &Ptr)
Check the source of the pointer passed to delete/delete[] has actually been heap allocated by us.
Definition: Interp.cpp:789
bool CheckArray(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if the array is offsetable.
Definition: Interp.cpp:285
bool CheckGlobalInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Check if a global variable is initialized.
Definition: Interp.cpp:519
bool CheckNonNullArgs(InterpState &S, CodePtr OpPC, const Function *F, const CallExpr *CE, unsigned ArgSize)
Checks if all the arguments annotated as 'nonnull' are in fact not null.
Definition: Interp.cpp:834
bool CheckDummy(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is a dummy pointer.
Definition: Interp.cpp:813
void cleanupAfterFunctionCall(InterpState &S, CodePtr OpPC)
Definition: Interp.cpp:219
bool CheckVolatile(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Definition: Interp.cpp:472
llvm::BitVector collectNonNullArgs(const FunctionDecl *F, const llvm::ArrayRef< const Expr * > &Args)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
Definition: PrimType.cpp:23
llvm::APSInt APSInt
Definition: Floating.h:24
bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if the variable has externally defined storage.
Definition: Interp.cpp:270
bool CheckNewDeleteForms(InterpState &S, CodePtr OpPC, bool NewWasArray, bool DeleteIsArray, const Descriptor *D, const Expr *NewExpr)
Diagnose mismatched new[]/delete or new/delete[] pairs.
Definition: Interp.cpp:763
bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F)
Checks if a method can be called.
Definition: Interp.cpp:598
bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a pointer points to const storage.
Definition: Interp.cpp:426
bool CheckInvoke(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a method can be invoked on an object.
Definition: Interp.cpp:578
bool CheckFloatResult(InterpState &S, CodePtr OpPC, const Floating &Result, APFloat::opStatus Status)
Checks if the result of a floating-point operation is valid in the current context.
Definition: Interp.cpp:707
The JSON file list parser is used to communicate input to InstallAPI.
@ SC_Extern
Definition: Specifiers.h:251
CheckSubobjectKind
The order of this enum is important for diagnostics.
Definition: State.h:40
@ CSK_Field
Definition: State.h:43
@ Result
The result type of a method or function.
AccessKinds
Kinds of access we can perform on an object, for diagnostics.
Definition: State.h:26
@ AK_Increment
Definition: State.h:30
@ AK_Read
Definition: State.h:27
@ AK_Assign
Definition: State.h:29
@ AK_MemberCall
Definition: State.h:32
@ AK_Decrement
Definition: State.h:31
const FunctionProtoType * T
#define bool
Definition: stdbool.h:24
Describes a memory block created by an allocation site.
Definition: Descriptor.h:111
unsigned getNumElems() const
Returns the number of elements stored in the block.
Definition: Descriptor.h:237
bool isPrimitive() const
Checks if the descriptor is of a primitive.
Definition: Descriptor.h:251
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
Definition: Descriptor.h:244
const ValueDecl * asValueDecl() const
Definition: Descriptor.h:202
QualType getType() const
Definition: Descriptor.cpp:394
const Descriptor *const ElemDesc
Descriptor of the array element.
Definition: Descriptor.h:143
unsigned getMetadataSize() const
Returns the size of the metadata.
Definition: Descriptor.h:234
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
Definition: Descriptor.h:242
const VarDecl * asVarDecl() const
Definition: Descriptor.h:206
bool isRecord() const
Checks if the descriptor is of a record.
Definition: Descriptor.h:256
const Record *const ElemRecord
Pointer to the record, if block contains records.
Definition: Descriptor.h:141