clang 24.0.0git
EvaluationResult.cpp
Go to the documentation of this file.
1//===----- EvaluationResult.cpp - Result class 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 "EvaluationResult.h"
10#include "../ExprConstShared.h"
11#include "InterpState.h"
12#include "Pointer.h"
13#include "Record.h"
15#include "clang/AST/Expr.h"
16#include "clang/AST/ExprCXX.h"
17#include "clang/AST/ExprObjC.h"
18#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/SmallPtrSet.h"
20#include <iterator>
21
22namespace clang {
23namespace interp {
24
25QualType EvaluationResult::getStorageType() const {
26 if (const auto *E = Source.asExpr()) {
27 if (E->isPRValue())
28 return E->getType();
29
30 return Ctx.getASTContext().getLValueReferenceType(E->getType());
31 }
32
33 if (const auto *D = Source.asValueDecl())
34 return D->getType();
35 return QualType();
36}
37
39 const FieldDecl *SubObjDecl) {
40 assert(SubObjDecl && "Subobject declaration does not exist");
41 S.FFDiag(Loc, diag::note_constexpr_uninitialized)
42 << /*(name)*/ 1 << SubObjDecl;
43 S.Note(SubObjDecl->getLocation(),
44 diag::note_constexpr_subobject_declared_here);
45}
46
47static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc,
48 PtrView BasePtr, const Record *R,
49 bool IsCompleteClass = true);
50
52 PtrView BasePtr) {
53 const Descriptor *BaseDesc = BasePtr.getFieldDesc();
54 assert(BaseDesc->isArray());
55
56 size_t NumElems = BaseDesc->getNumElems();
57 if (NumElems == 0)
58 return true;
59
60 bool Result = true;
61
62 if (BaseDesc->isPrimitiveArray()) {
63 if (BasePtr.allElementsInitialized())
64 return true;
65 if (const FieldDecl *F = BasePtr.getField())
67 return false;
68 }
69 const Descriptor *ElemDesc = BaseDesc->ElemDesc;
70
71 if (ElemDesc->isRecord()) {
72 const Record *R = ElemDesc->ElemRecord;
73 for (size_t I = 0; I != NumElems; ++I) {
74 PtrView ElemPtr = BasePtr.atIndex(I).narrow();
75 Result &= CheckFieldsInitialized(S, Loc, ElemPtr, R);
76 }
77 } else if (ElemDesc->isArray()) {
78 for (size_t I = 0; I != NumElems; ++I) {
79 PtrView ElemPtr = BasePtr.atIndex(I).narrow();
80 Result &= CheckArrayInitialized(S, Loc, ElemPtr);
81 }
82 }
83
84 return Result;
85}
86
88 PtrView BasePtr, const Record *R,
89 bool IsCompleteClass) {
90 assert(R);
91 bool Result = true;
92 // Check all fields of this record are initialized.
93 for (const Record::Field &F : R->fields()) {
94 PtrView FieldPtr = BasePtr.atField(F.Offset);
95
96 // Don't check inactive union members.
97 if (R->isUnion() && !FieldPtr.isActive())
98 continue;
99
100 QualType FieldType = F.Decl->getType();
101 const Descriptor *FieldDesc = FieldPtr.getFieldDesc();
102
103 if (FieldDesc->isRecord()) {
104 Result &= CheckFieldsInitialized(S, Loc, FieldPtr, FieldPtr.getRecord());
105 } else if (FieldType->isIncompleteArrayType()) {
106 // Nothing to do here.
107 } else if (F.Decl->isUnnamedBitField()) {
108 // Nothing do do here.
109 } else if (FieldDesc->isArray()) {
110 Result &= CheckArrayInitialized(S, Loc, FieldPtr);
111 } else if (!FieldPtr.isInitialized()) {
112 DiagnoseUninitializedSubobject(S, Loc, F.Decl);
113 Result = false;
114 }
115 }
116
117 auto diagnoseBase = [&](const Record::Base &B, unsigned Index) -> bool {
118 const Descriptor *Desc = BasePtr.getDeclDesc();
119 if (const auto *CD = dyn_cast_if_present<CXXRecordDecl>(R->getDecl())) {
120 const auto &BS = *std::next(CD->bases_begin(), Index);
121 SourceLocation TypeBeginLoc = BS.getBaseTypeLoc();
122 S.FFDiag(TypeBeginLoc, diag::note_constexpr_uninitialized_base)
123 << B.Desc->getType() << SourceRange(TypeBeginLoc, BS.getEndLoc());
124 } else {
125 S.FFDiag(Desc->getLocation(), diag::note_constexpr_uninitialized_base)
126 << B.Desc->getType();
127 }
128 return false;
129 };
130
131 // Check Fields in all bases.
132 for (auto [I, B] : llvm::enumerate(R->bases())) {
133 PtrView P = BasePtr.atField(B.Offset);
134 if (!P.isInitialized())
135 return diagnoseBase(B, I);
136 Result &= CheckFieldsInitialized(S, Loc, P, B.R, /*IsCompleteClass=*/false);
137 }
138
139 // And virtual bases.
140 if (IsCompleteClass) {
141 for (auto [I, B] : llvm::enumerate(R->virtual_bases())) {
142 PtrView P = BasePtr.atField(B.Offset);
143 if (!P.isInitialized())
144 return diagnoseBase(B, I);
145 Result &=
146 CheckFieldsInitialized(S, Loc, P, B.R, /*IsCompleteClass=*/false);
147 }
148 }
149
150 return Result;
151}
152
154 const Pointer &Ptr) const {
155 assert(Source);
156 assert(empty());
157
158 if (Ptr.isZero())
159 return true;
160 if (!Ptr.isBlockPointer())
161 return true;
162
163 // We can't inspect dead pointers at all. Return true here so we can
164 // diagnose them later.
165 if (!Ptr.isLive())
166 return true;
167
168 SourceLocation InitLoc;
169 if (const auto *D = Source.asDecl())
170 InitLoc = cast<VarDecl>(D)->getAnyInitializer()->getExprLoc();
171 else if (const auto *E = Source.asExpr())
172 InitLoc = E->getExprLoc();
173
174 if (const Record *R = Ptr.getRecord())
175 return CheckFieldsInitialized(S, InitLoc, Ptr.view(), R);
176
177 if (isa_and_nonnull<ConstantArrayType>(Ptr.getType()->getAsArrayTypeUnsafe()))
178 return CheckArrayInitialized(S, InitLoc, Ptr.view());
179
180 return true;
181}
182
183static bool isOrHasPtr(const Descriptor *D) {
184 if ((D->isPrimitive() || D->isPrimitiveArray()) && D->getPrimType() == PT_Ptr)
185 return true;
186
187 if (D->ElemRecord)
188 return D->ElemRecord->hasPtrField();
189 return false;
190}
191
192static void collectBlocks(PtrView Ptr,
194 bool IsCompleteClass = true) {
195 auto isUsefulPtr = [](const Pointer &P) -> bool {
196 return P.isLive() && P.isBlockPointer() && !P.isZero() && !P.isDummy() &&
197 P.isDereferencable() && !P.isUnknownSizeArray() && !P.isOnePastEnd();
198 };
199
200 if (!Ptr.isLive() || Ptr.isZero() || Ptr.isUnknownSizeArray() ||
201 Ptr.isOnePastEnd())
202 return;
203
204 Blocks.insert(Ptr.Pointee);
205
206 const Descriptor *Desc = Ptr.getFieldDesc();
207 if (!Desc)
208 return;
209
210 if (const Record *R = Desc->ElemRecord) {
211 if (!R->hasPtrField())
212 return;
213
214 for (const Record::Base &B : R->bases()) {
215 if (!B.R->hasPtrField())
216 continue;
217 PtrView BasePtr = Ptr.atField(B.Offset);
218 collectBlocks(BasePtr, Blocks, /*IsCompleteClass=*/false);
219 }
220
221 for (const Record::Field &F : R->fields()) {
222 if (!isOrHasPtr(F.Desc))
223 continue;
224 PtrView FieldPtr = Ptr.atField(F.Offset);
225 collectBlocks(FieldPtr, Blocks);
226 }
227
228 if (IsCompleteClass) {
229 for (const Record::Base &B : R->virtual_bases()) {
230 if (!B.R->hasPtrField())
231 continue;
232 PtrView BasePtr = Ptr.atField(B.Offset);
233 collectBlocks(BasePtr, Blocks, /*IsCompleteClass=*/false);
234 }
235 }
236
237 return;
238 }
239
240 if (Desc->isPrimitive() && Desc->getPrimType() == PT_Ptr) {
241 Pointer Pointee = Ptr.deref<Pointer>();
242 if (isUsefulPtr(Pointee) && !Blocks.contains(Pointee.block()))
243 collectBlocks(Pointee.view(), Blocks);
244
245 return;
246 }
247
248 if (Desc->isPrimitiveArray() && Desc->getPrimType() == PT_Ptr) {
249 for (unsigned I = 0; I != Desc->getNumElems(); ++I) {
250 Pointer ElemPointee = Ptr.elem<Pointer>(I);
251 if (isUsefulPtr(ElemPointee) && !Blocks.contains(ElemPointee.block()))
252 collectBlocks(ElemPointee.view(), Blocks);
253 }
254 return;
255 }
256
257 if (Desc->isCompositeArray() && isOrHasPtr(Desc->ElemDesc)) {
258 for (unsigned I = 0; I != Desc->getNumElems(); ++I) {
259 PtrView ElemPtr = Ptr.atIndex(I).narrow();
260 collectBlocks(ElemPtr, Blocks);
261 }
262 }
263}
264
266 const Pointer &Ptr,
267 SourceInfo Info) const {
268 if (!Ptr.isBlockPointer())
269 return true;
270
271 // Collect all blocks that this pointer (transitively) points to and
272 // return false if any of them is a dynamic block.
274
275 collectBlocks(Ptr.view(), Blocks);
276
277 for (const Block *B : Blocks) {
278 if (B->isDynamic()) {
279 assert(B->getDescriptor());
280 assert(B->getDescriptor()->asExpr());
281
282 bool IsSubobj = !Ptr.isRoot() || Ptr.isArrayElement();
283 S.FFDiag(Info, diag::note_constexpr_dynamic_alloc)
284 << Ptr.getType()->isReferenceType() << IsSubobj;
285 S.Note(B->getDescriptor()->asExpr()->getExprLoc(),
286 diag::note_constexpr_dynamic_alloc_here);
287 return false;
288 }
289 }
290
291 return true;
292}
293
294static bool isGlobalLValue(const Pointer &Ptr) {
295 if (Ptr.isDynamic())
296 return true;
297 if (Ptr.isTypeidPointer())
298 return true;
299
300 return ::isGlobalLValue(Ptr.getRootValueDecl(), Ptr.getRootExpr());
301}
302
303/// Check if the given function pointer can be returned from an evaluation.
304static bool checkFunctionPtr(InterpState &S, const Pointer &Ptr,
305 QualType PtrType, SourceInfo Info,
306 ConstantExprKind ConstexprKind) {
307 assert(Ptr.isFunctionPointer());
308 const FunctionPointer &FuncPtr = Ptr.asFunctionPointer();
309
310 if (!FuncPtr.Func)
311 return true;
312
313 const FunctionDecl *FD = FuncPtr.Func->getDecl();
314 // E.g. ObjC block pointers.
315 if (!FD)
316 return true;
317 if (FD->isImmediateFunction()) {
318 S.FFDiag(Info, diag::note_consteval_address_accessible)
319 << !PtrType->isAnyPointerType();
320 S.Note(FD->getLocation(), diag::note_declared_at);
321 return false;
322 }
323
324 // __declspec(dllimport) must be handled very carefully:
325 // We must never initialize an expression with the thunk in C++.
326 // Doing otherwise would allow the same id-expression to yield
327 // different addresses for the same function in different translation
328 // units. However, this means that we must dynamically initialize the
329 // expression with the contents of the import address table at runtime.
330 //
331 // The C language has no notion of ODR; furthermore, it has no notion of
332 // dynamic initialization. This means that we are permitted to
333 // perform initialization with the address of the thunk.
334 if (S.getLangOpts().CPlusPlus && !isForManglingOnly(ConstexprKind) &&
335 FD->hasAttr<DLLImportAttr>())
336 // FIXME: Diagnostic!
337 return false;
338 return true;
339}
340
341static bool lvalFields(InterpState &S, const ASTContext &Ctx, PtrView Ptr,
342 QualType PtrType, SourceInfo Info,
343 ConstantExprKind ConstexprKind,
345static bool lval(InterpState &S, const ASTContext &Ctx, const Pointer &Ptr,
346 QualType PtrType, SourceInfo Info,
347 ConstantExprKind ConstexprKind,
349 if (Ptr.isFunctionPointer())
350 return checkFunctionPtr(S, Ptr, PtrType, Info, ConstexprKind);
351
352 if (!Ptr.isBlockPointer() && !Ptr.isOpaquePointer())
353 return true;
354
355 const Expr *BaseE = Ptr.getRootExpr();
356 const ValueDecl *BaseVD = Ptr.getRootValueDecl();
357 assert(BaseE || BaseVD);
358 bool IsReferenceType = PtrType->isReferenceType();
359 bool IsSubObj = !Ptr.isRoot() || (Ptr.inArray() && !Ptr.isArrayRoot());
360
361 if (!isGlobalLValue(Ptr)) {
362 if (S.getLangOpts().CPlusPlus11) {
363 S.FFDiag(Info, diag::note_constexpr_non_global, 1)
364 << IsReferenceType << IsSubObj << !!BaseVD << BaseVD;
365 const VarDecl *VarD = dyn_cast_if_present<VarDecl>(BaseVD);
366 if (VarD && VarD->isConstexpr()) {
367 // Non-static local constexpr variables have unintuitive semantics:
368 // constexpr int a = 1;
369 // constexpr const int *p = &a;
370 // ... is invalid because the address of 'a' is not constant. Suggest
371 // adding a 'static' in this case.
372 S.Note(VarD->getLocation(), diag::note_constexpr_not_static)
373 << VarD
374 << FixItHint::CreateInsertion(VarD->getBeginLoc(), "static ");
375 } else {
376 if (BaseVD)
377 S.Note(BaseVD->getLocation(), diag::note_declared_at);
378 else if (BaseE)
379 S.Note(BaseE->getExprLoc(), diag::note_constexpr_temporary_here);
380 }
381 } else {
382 S.FFDiag(Info);
383 }
384 return false;
385 }
386
387 if (const auto *VD = dyn_cast_if_present<VarDecl>(BaseVD)) {
388 // We might allow creating pointers into invalid records, but do not allow
389 // returning them from an evaluation.
390 if (const RecordDecl *TypeRD = VD->getType()->getAsRecordDecl();
391 TypeRD && TypeRD->isInvalidDecl())
392 return false;
393 // Check if this is a thread-local variable.
394 if (VD->getTLSKind()) {
395 // FIXME: Diagnostic!
396 return false;
397 }
398
399 // A dllimport variable never acts like a constant, unless we're
400 // evaluating a value for use only in name mangling, and unless it's a
401 // static local. For the latter case, we'd still need to evaluate the
402 // constant expression in case we're inside a (inlined) function.
403 if (!isForManglingOnly(ConstexprKind) && VD->hasAttr<DLLImportAttr>() &&
404 !VD->isStaticLocal())
405 return false;
406
407 // Address of a managed variable is never a constant expression.
408 if (S.getLangOpts().CUDA && VD->hasAttr<HIPManagedAttr>())
409 return false;
410
411 // In CUDA/HIP device compilation, only device side variables have
412 // constant addresses.
413 if (S.getLangOpts().CUDA && S.getLangOpts().CUDAIsDevice &&
415 if ((!VD->hasAttr<CUDADeviceAttr>() && !VD->hasAttr<CUDAConstantAttr>() &&
416 !VD->getType()->isCUDADeviceBuiltinSurfaceType() &&
417 !VD->getType()->isCUDADeviceBuiltinTextureType()))
418 return false;
419 }
420
421 return true;
422 }
423
424 if (const auto *MTE = dyn_cast_if_present<MaterializeTemporaryExpr>(BaseE)) {
425 QualType TempType = Ptr.getType();
426
427 if (TempType.isDestructedType()) {
428 S.FFDiag(MTE->getExprLoc(),
429 diag::note_constexpr_unsupported_temporary_nontrivial_dtor)
430 << TempType;
431 return false;
432 }
433
434 if (Ptr.getFieldDesc()->isPrimitive() &&
435 Ptr.getFieldDesc()->getPrimType() == PT_Ptr) {
436 // Recurse!
437 Pointer Pointee = Ptr.deref<Pointer>();
438 if (!Pointee.isBlockPointer() ||
439 CheckedBlocks.insert(Pointee.block()).second) {
440 if (!lval(S, Ctx, Pointee, Pointee.getType(),
441 Ptr.getDeclDesc()->getLoc(), ConstexprKind, CheckedBlocks))
442 return false;
443 }
444 } else {
445 if (!lvalFields(S, Ctx, Ptr.view(), TempType, Info, ConstexprKind,
446 CheckedBlocks))
447 return false;
448 }
449 }
450
451 return true;
452}
453
454static bool lvalFields(InterpState &S, const ASTContext &Ctx, PtrView Ptr,
455 QualType PtrType, SourceInfo Info,
456 ConstantExprKind ConstexprKind,
458 assert(Ptr.isLive());
459 const Descriptor *FieldDesc = Ptr.getFieldDesc();
460 if (const Record *R = Ptr.getRecord()) {
461 if (!R->hasPtrField())
462 return true;
463
464 for (const Record::Base &B : R->bases()) {
465 if (!B.R->hasPtrField())
466 continue;
467
468 PtrView BasePtr = Ptr.atField(B.Offset);
469 if (!lvalFields(S, Ctx, BasePtr, B.Desc->getType(), Info, ConstexprKind,
470 CheckedBlocks))
471 return false;
472 }
473
474 for (const Record::Field &F : R->fields()) {
475 PtrView FieldPtr = Ptr.atField(F.Offset);
476 if (!isOrHasPtr(F.Desc))
477 continue;
478
479 if (F.Desc->isPrimitive() && F.Desc->getPrimType() == PT_Ptr) {
480 Pointer Pointee = FieldPtr.deref<Pointer>();
481 if (!Pointee.isBlockPointer() ||
482 CheckedBlocks.insert(Pointee.block()).second) {
483 QualType FieldType = F.Decl->getType();
484 if (!lval(S, Ctx, Pointee, FieldType, Info, ConstexprKind,
485 CheckedBlocks))
486 return false;
487 }
488 } else {
489 if (!lvalFields(S, Ctx, FieldPtr, F.Decl->getType(), Info,
490 ConstexprKind, CheckedBlocks))
491 return false;
492 }
493 }
494
495 for (const Record::Base &B : R->virtual_bases()) {
496 if (!B.R->hasPtrField())
497 continue;
498 PtrView BasePtr = Ptr.atField(B.Offset);
499 if (!lvalFields(S, Ctx, BasePtr, B.Desc->getType(), Info, ConstexprKind,
500 CheckedBlocks))
501 return false;
502 }
503 return true;
504 }
505
506 if (FieldDesc->isPrimitiveArray() && FieldDesc->getPrimType() == PT_Ptr) {
507 for (unsigned I = 0; I != FieldDesc->getNumElems(); ++I) {
508 Pointer Pointee = Ptr.elem<Pointer>(I);
509
510 if (!Pointee.isBlockPointer() ||
511 CheckedBlocks.insert(Pointee.block()).second) {
512 if (!lval(S, Ctx, Pointee, FieldDesc->getElemQualType(), Info,
513 ConstexprKind, CheckedBlocks))
514 return false;
515 }
516 }
517 return true;
518 }
519
520 if (FieldDesc->isCompositeArray()) {
521 if (FieldDesc->ElemRecord && !FieldDesc->ElemRecord->hasPtrField())
522 return true;
523
524 for (unsigned I = 0; I != FieldDesc->getNumElems(); ++I) {
525 PtrView Elem = Ptr.atIndex(I).narrow();
526 if (!lvalFields(S, Ctx, Elem, FieldDesc->getElemQualType(), Info,
527 ConstexprKind, CheckedBlocks))
528 return false;
529 }
530 return true;
531 }
532 if (FieldDesc->isPrimitive() && FieldDesc->getPrimType() == PT_MemberPtr) {
533 MemberPointer MP = Ptr.deref<MemberPointer>();
534 if (!EvaluationResult::checkMemberPointer(S, MP, Info, ConstexprKind))
535 return false;
536 }
537
538 return true;
539}
540
541/// Toplevel accessor to check all lvalue fields.
543 SourceInfo Info,
544 ConstantExprKind ConstexprKind) const {
545 if (!Ptr.isBlockPointer())
546 return true;
547
548 QualType SourceType = getStorageType();
550
551 return lvalFields(S, Ctx.getASTContext(), Ptr.view(), SourceType, Info,
552 ConstexprKind, CheckedBlocks);
553}
554
556 SourceInfo Info,
557 ConstantExprKind ConstexprKind) const {
558 QualType SourceType = getStorageType();
559 if (Ptr.isFunctionPointer())
560 return checkFunctionPtr(S, Ptr, SourceType, Info, ConstexprKind);
561
562 if (Ptr.isZero())
563 return true;
564
565 bool IsReferenceType = SourceType->isReferenceType();
566 if (Ptr.isTypeidPointer()) {
567 if (isTemplateArgument(ConstexprKind)) {
568 S.FFDiag(Info, diag::note_constexpr_invalid_template_arg)
569 << IsReferenceType << /*IsSubObj=*/false << /*InvalidBaseKind=*/0;
570 return false;
571 }
572 return true;
573 }
574
575 if (Ptr.isStringPointer()) {
576 // Additional restrictions apply in a template argument. We only enforce the
577 // C++20 restrictions here; additional syntactic and semantic restrictions
578 // are applied elsewhere.
579 if (isTemplateArgument(ConstexprKind)) {
580 bool IsSubObj = Ptr.asStringPointer().Decayed || Ptr.getIndex() != 0;
581 int InvalidBaseKind = -1;
582 StringRef Ident;
583 const Expr *BaseE = Ptr.asStringPointer().Base;
584 if (isa_and_nonnull<StringLiteral>(BaseE))
585 InvalidBaseKind = 1;
586 else if (const auto *PE = dyn_cast_if_present<PredefinedExpr>(BaseE)) {
587 InvalidBaseKind = 3;
588 Ident = PE->getIdentKindName();
589 }
590
591 if (InvalidBaseKind != -1) {
592 S.FFDiag(Info, diag::note_constexpr_invalid_template_arg)
593 << IsReferenceType << IsSubObj << InvalidBaseKind << Ident;
594 return false;
595 }
596 }
597 return true;
598 }
599
600 if (!Ptr.isBlockPointer() && !Ptr.isOpaquePointer())
601 return true;
602
603 // Additional restrictions apply in a template argument. We only enforce the
604 // C++20 restrictions here; additional syntactic and semantic restrictions
605 // are applied elsewhere.
606 if (isTemplateArgument(ConstexprKind)) {
607 const Expr *BaseE = Ptr.getRootExpr();
608 const ValueDecl *BaseVD = Ptr.getRootValueDecl();
609 assert(BaseE || BaseVD);
610 if (isa_and_nonnull<MaterializeTemporaryExpr>(BaseE) ||
611 isa_and_nonnull<LifetimeExtendedTemporaryDecl>(BaseVD)) {
612 bool IsSubObj = !Ptr.isRoot() || (Ptr.inArray() && !Ptr.isArrayRoot());
613 S.FFDiag(Info, diag::note_constexpr_invalid_template_arg)
614 << IsReferenceType << IsSubObj << 2;
615 return false;
616 }
617 }
618
620 if (!lval(S, Ctx.getASTContext(), Ptr, SourceType, Info, ConstexprKind,
621 CheckedBlocks)) {
622 return false;
623 }
624
625 return true;
626}
627
629 const MemberPointer &MemberPtr,
630 SourceInfo Info,
631 ConstantExprKind ConstexprKind) {
632 const CXXMethodDecl *MD = MemberPtr.getMemberFunction();
633 if (!MD)
634 return true;
635
636 if (MD->isImmediateFunction()) {
637 S.FFDiag(Info, diag::note_consteval_address_accessible)
638 << /*pointer=*/false;
639 S.Note(MD->getLocation(), diag::note_declared_at);
640 return false;
641 }
642
643 if (isForManglingOnly(ConstexprKind) || MD->isVirtual() ||
644 !MD->hasAttr<DLLImportAttr>()) {
645 return true;
646 }
647 return false;
648}
649
651 InterpState &S, const Pointer &Ptr, SourceInfo Info,
652 ConstantExprKind ConstexprKind) const {
653 return checkFunctionPtr(S, Ptr, getStorageType(), Info, ConstexprKind);
654}
655
656} // namespace interp
657} // namespace clang
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isTemplateArgument(ConstantExprKind Kind)
bool isForManglingOnly(ConstantExprKind Kind)
Determines whether the given kind of constant expression is only ever used for name mangling.
llvm::MachO::Record Record
Definition MachO.h:31
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
struct clang::ASTContext::CUDAConstantEvalContext CUDAConstantEvalCtx
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2153
bool isVirtual() const
Definition DeclCXX.h:2208
bool isInvalidDecl() const
Definition DeclBase.h:597
SourceLocation getLocation() const
Definition DeclBase.h:448
bool hasAttr() const
Definition DeclBase.h:586
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:833
This represents one expression.
Definition Expr.h:114
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
Represents a member of a struct/union/class.
Definition Decl.h:3341
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition Diagnostic.h:103
Represents a function declaration or definition.
Definition Decl.h:2082
bool isImmediateFunction() const
Definition Decl.cpp:3414
A (possibly-)qualified type.
Definition TypeBase.h:938
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition TypeBase.h:1561
Represents a struct/union/class.
Definition Decl.h:4508
Encodes a location in the source.
A trivial tuple used to represent a source range.
bool isIncompleteArrayType() const
Definition TypeBase.h:8922
bool isReferenceType() const
Definition TypeBase.h:8839
bool isAnyPointerType() const
Definition TypeBase.h:8823
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:714
Represents a variable declaration or definition.
Definition Decl.h:934
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1606
A memory block, either on the stack or in the heap.
Definition Block.h:68
static bool checkMemberPointer(InterpState &S, const MemberPointer &MemberPtr, SourceInfo Info, ConstantExprKind ConstexprKind)
Check if the given member pointer can be returned from an evaluation.
bool checkFunctionPointer(InterpState &S, const Pointer &Ptr, SourceInfo Info, ConstantExprKind ConstexprKind) const
Check if the given function pointer can be returned from an evaluation.
bool checkLValue(InterpState &S, const Pointer &Ptr, SourceInfo Info, ConstantExprKind ConstexprKind) const
Check the given pointer as an lvalue, i.e.
bool checkDynamicAllocations(InterpState &S, const Pointer &Ptr, SourceInfo Info) const
Check that none of the blocks the given pointer (transitively) points to are dynamically allocated.
bool checkFullyInitialized(InterpState &S, const Pointer &Ptr) const
Check that all subobjects of the given pointer have been initialized.
bool checkLValueFields(InterpState &S, const Pointer &Ptr, SourceInfo Info, ConstantExprKind ConstexprKind) const
Check all fields of the given pointer.
const FunctionDecl * getDecl() const
Returns the original FunctionDecl.
Definition Function.h:133
Interpreter context.
Definition InterpState.h:47
A pointer to a memory block, live or dead.
Definition Pointer.h:544
QualType getType() const
Returns the type of the innermost field.
Definition Pointer.h:724
bool isBlockPointer() const
Definition Pointer.h:870
const Block * block() const
Definition Pointer.h:1010
PtrView view() const
Definition Pointer.h:603
Structure/Class descriptor.
Definition Record.h:27
bool hasPtrField() const
If this record (or any of its bases) contains a field of type PT_Ptr.
Definition Record.h:85
Describes the statement/declaration an opcode was generated from.
Definition Source.h:77
OptionalDiagnostic Note(SourceLocation Loc, diag::kind DiagId)
Add a note to a prior diagnostic.
Definition State.cpp:86
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:37
ASTContext & getASTContext() const
Definition State.h:92
const LangOptions & getLangOpts() const
Definition State.h:94
static bool lvalFields(InterpState &S, const ASTContext &Ctx, PtrView Ptr, QualType PtrType, SourceInfo Info, ConstantExprKind ConstexprKind, llvm::SmallPtrSet< const Block *, 4 > &CheckedBlocks)
static bool CheckArrayInitialized(InterpState &S, SourceLocation Loc, PtrView BasePtr)
static bool isOrHasPtr(const Descriptor *D)
static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc, PtrView BasePtr, const Record *R, bool IsCompleteClass=true)
static bool isGlobalLValue(const Pointer &Ptr)
static void DiagnoseUninitializedSubobject(InterpState &S, SourceLocation Loc, const FieldDecl *SubObjDecl)
static bool lval(InterpState &S, const ASTContext &Ctx, const Pointer &Ptr, QualType PtrType, SourceInfo Info, ConstantExprKind ConstexprKind, llvm::SmallPtrSet< const Block *, 4 > &CheckedBlocks)
static bool checkFunctionPtr(InterpState &S, const Pointer &Ptr, QualType PtrType, SourceInfo Info, ConstantExprKind ConstexprKind)
Check if the given function pointer can be returned from an evaluation.
static void collectBlocks(PtrView Ptr, llvm::SmallPtrSet< const Block *, 4 > &Blocks, bool IsCompleteClass=true)
Top level wrappers for InstallAPI frontend operations.
Expr::ConstantExprKind ConstantExprKind
Definition Expr.h:1087
@ Result
The result type of a method or function.
Definition TypeBase.h:906
U cast(CodeGen::Address addr)
Definition Address.h:327
bool NoWrongSidedVars
Do not allow wrong-sided variables in constant expressions.
Definition ASTContext.h:865
Describes a memory block created by an allocation site.
Definition Descriptor.h:126
unsigned getNumElems() const
Returns the number of elements stored in the block.
Definition Descriptor.h:249
SourceLocation getLocation() const
Definition Descriptor.h:201
bool isPrimitive() const
Checks if the descriptor is of a primitive.
Definition Descriptor.h:263
QualType getElemQualType() const
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
Definition Descriptor.h:256
const Descriptor *const ElemDesc
Descriptor of the array element.
Definition Descriptor.h:152
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
Definition Descriptor.h:254
PrimType getPrimType() const
Definition Descriptor.h:234
bool isRecord() const
Checks if the descriptor is of a record.
Definition Descriptor.h:268
const Record *const ElemRecord
Pointer to the record, if block contains records.
Definition Descriptor.h:150
bool isArray() const
Checks if the descriptor is of an array.
Definition Descriptor.h:266
const Descriptor * getDeclDesc() const
Definition Pointer.h:88
bool allElementsInitialized() const
Definition Pointer.cpp:868
PtrView atField(unsigned Offset) const
Definition Pointer.h:271
const Record * getRecord() const
Definition Pointer.h:155
const Descriptor * getFieldDesc() const
Definition Pointer.h:82
const FieldDecl * getField() const
Definition Pointer.h:160
PtrView atIndex(unsigned Idx) const
Definition Pointer.h:211
PtrView narrow() const
Definition Pointer.h:92
bool isInitialized() const
Definition Pointer.h:299
QualType getType() const
Definition Pointer.h:276
bool isActive() const
Definition Pointer.h:45
T & deref() const
Definition Pointer.h:246