@@ -2371,9 +2371,9 @@ bool Compiler<Emitter>::VisitStringLiteral(const StringLiteral *E) {
2371
2371
2372
2372
template <class Emitter >
2373
2373
bool Compiler<Emitter>::VisitObjCStringLiteral(const ObjCStringLiteral *E) {
2374
- if (std::optional< unsigned > I = P. getOrCreateDummy (E) )
2375
- return this -> emitGetPtrGlobal (*I, E) ;
2376
- return false ;
2374
+ if (DiscardResult )
2375
+ return true ;
2376
+ return this -> emitDummyPtr (E, E) ;
2377
2377
}
2378
2378
2379
2379
template <class Emitter >
@@ -3445,11 +3445,8 @@ bool Compiler<Emitter>::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
3445
3445
assert (RD);
3446
3446
// If the definiton of the result type is incomplete, just return a dummy.
3447
3447
// If (and when) that is read from, we will fail, but not now.
3448
- if (!RD->isCompleteDefinition ()) {
3449
- if (std::optional<unsigned > I = P.getOrCreateDummy (GuidDecl))
3450
- return this ->emitGetPtrGlobal (*I, E);
3451
- return false ;
3452
- }
3448
+ if (!RD->isCompleteDefinition ())
3449
+ return this ->emitDummyPtr (GuidDecl, E);
3453
3450
3454
3451
std::optional<unsigned > GlobalIndex = P.getOrCreateGlobal (GuidDecl);
3455
3452
if (!GlobalIndex)
@@ -3687,11 +3684,11 @@ bool Compiler<Emitter>::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
3687
3684
if (!E->isExpressibleAsConstantInitializer ())
3688
3685
return this ->discard (SubExpr) && this ->emitInvalid (E);
3689
3686
3690
- assert (classifyPrim (E) == PT_Ptr);
3691
- if (std::optional<unsigned > I = P.getOrCreateDummy (E))
3692
- return this ->emitGetPtrGlobal (*I, E);
3687
+ if (DiscardResult)
3688
+ return true ;
3693
3689
3694
- return false ;
3690
+ assert (classifyPrim (E) == PT_Ptr);
3691
+ return this ->emitDummyPtr (E, E);
3695
3692
}
3696
3693
3697
3694
template <class Emitter >
@@ -4483,15 +4480,9 @@ bool Compiler<Emitter>::VisitBuiltinCallExpr(const CallExpr *E,
4483
4480
BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
4484
4481
BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
4485
4482
BuiltinID == Builtin::BI__builtin_function_start) {
4486
- if (std::optional<unsigned > GlobalOffset = P.getOrCreateDummy (E)) {
4487
- if (!this ->emitGetPtrGlobal (*GlobalOffset, E))
4488
- return false ;
4489
-
4490
- if (PrimType PT = classifyPrim (E); PT != PT_Ptr && isPtrType (PT))
4491
- return this ->emitDecayPtr (PT_Ptr, PT, E);
4483
+ if (DiscardResult)
4492
4484
return true ;
4493
- }
4494
- return false ;
4485
+ return this ->emitDummyPtr (E, E);
4495
4486
}
4496
4487
4497
4488
QualType ReturnType = E->getType ();
@@ -6097,6 +6088,10 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
6097
6088
6098
6089
if (VD->evaluateValue ())
6099
6090
return revisit (VD);
6091
+
6092
+ if (!D->getType ()->isReferenceType ())
6093
+ return this ->emitDummyPtr (D, E);
6094
+
6100
6095
return this ->emitInvalidDeclRef (cast<DeclRefExpr>(E),
6101
6096
/* InitializerFailed=*/ true , E);
6102
6097
}
@@ -6109,23 +6104,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
6109
6104
}
6110
6105
}
6111
6106
6112
- if (std::optional<unsigned > I = P.getOrCreateDummy (D)) {
6113
- if (!this ->emitGetPtrGlobal (*I, E))
6114
- return false ;
6115
- if (E->getType ()->isVoidType ())
6116
- return true ;
6117
- // Convert the dummy pointer to another pointer type if we have to.
6118
- if (PrimType PT = classifyPrim (E); PT != PT_Ptr) {
6119
- if (isPtrType (PT))
6120
- return this ->emitDecayPtr (PT_Ptr, PT, E);
6121
- return false ;
6122
- }
6123
- return true ;
6124
- }
6125
-
6126
- if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
6127
- return this ->emitInvalidDeclRef (DRE, /* InitializerFailed=*/ false , E);
6128
- return false ;
6107
+ return this ->emitDummyPtr (D, E);
6129
6108
}
6130
6109
6131
6110
template <class Emitter >
@@ -6428,6 +6407,29 @@ bool Compiler<Emitter>::emitDestruction(const Descriptor *Desc,
6428
6407
return this ->emitRecordDestruction (Desc->ElemRecord , Loc);
6429
6408
}
6430
6409
6410
+ // / Create a dummy pointer for the given decl (or expr) and
6411
+ // / push a pointer to it on the stack.
6412
+ template <class Emitter >
6413
+ bool Compiler<Emitter>::emitDummyPtr(const DeclTy &D, const Expr *E) {
6414
+ assert (!DiscardResult && " Should've been checked before" );
6415
+
6416
+ unsigned DummyID = P.getOrCreateDummy (D);
6417
+
6418
+ if (!this ->emitGetPtrGlobal (DummyID, E))
6419
+ return false ;
6420
+ if (E->getType ()->isVoidType ())
6421
+ return true ;
6422
+
6423
+ // Convert the dummy pointer to another pointer type if we have to.
6424
+ if (PrimType PT = classifyPrim (E); PT != PT_Ptr) {
6425
+ if (isPtrType (PT))
6426
+ return this ->emitDecayPtr (PT_Ptr, PT, E);
6427
+ return false ;
6428
+ }
6429
+
6430
+ return true ;
6431
+ }
6432
+
6431
6433
namespace clang {
6432
6434
namespace interp {
6433
6435
0 commit comments