@@ -2371,9 +2371,9 @@ bool Compiler<Emitter>::VisitStringLiteral(const StringLiteral *E) {
23712371
23722372template <class Emitter >
23732373bool 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) ;
23772377}
23782378
23792379template <class Emitter >
@@ -3445,11 +3445,8 @@ bool Compiler<Emitter>::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
34453445 assert (RD);
34463446 // If the definiton of the result type is incomplete, just return a dummy.
34473447 // 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);
34533450
34543451 std::optional<unsigned > GlobalIndex = P.getOrCreateGlobal (GuidDecl);
34553452 if (!GlobalIndex)
@@ -3687,11 +3684,11 @@ bool Compiler<Emitter>::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
36873684 if (!E->isExpressibleAsConstantInitializer ())
36883685 return this ->discard (SubExpr) && this ->emitInvalid (E);
36893686
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 ;
36933689
3694- return false ;
3690+ assert (classifyPrim (E) == PT_Ptr);
3691+ return this ->emitDummyPtr (E, E);
36953692}
36963693
36973694template <class Emitter >
@@ -4483,15 +4480,9 @@ bool Compiler<Emitter>::VisitBuiltinCallExpr(const CallExpr *E,
44834480 BuiltinID == Builtin::BI__builtin___NSStringMakeConstantString ||
44844481 BuiltinID == Builtin::BI__builtin_ptrauth_sign_constant ||
44854482 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)
44924484 return true ;
4493- }
4494- return false ;
4485+ return this ->emitDummyPtr (E, E);
44954486 }
44964487
44974488 QualType ReturnType = E->getType ();
@@ -6097,6 +6088,10 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
60976088
60986089 if (VD->evaluateValue ())
60996090 return revisit (VD);
6091+
6092+ if (!D->getType ()->isReferenceType ())
6093+ return this ->emitDummyPtr (D, E);
6094+
61006095 return this ->emitInvalidDeclRef (cast<DeclRefExpr>(E),
61016096 /* InitializerFailed=*/ true , E);
61026097 }
@@ -6109,23 +6104,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
61096104 }
61106105 }
61116106
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);
61296108}
61306109
61316110template <class Emitter >
@@ -6428,6 +6407,29 @@ bool Compiler<Emitter>::emitDestruction(const Descriptor *Desc,
64286407 return this ->emitRecordDestruction (Desc->ElemRecord , Loc);
64296408}
64306409
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+
64316433namespace clang {
64326434namespace interp {
64336435
0 commit comments