@@ -715,23 +715,6 @@ static bool CheckLifetime(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
715715 return false ;
716716}
717717
718- bool CheckGlobalInitialized (InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
719- if (Ptr.isInitialized ())
720- return true ;
721-
722- assert (S.getLangOpts ().CPlusPlus );
723- const auto *VD = cast<VarDecl>(Ptr.getDeclDesc ()->asValueDecl ());
724- if ((!VD->hasConstantInitialization () &&
725- VD->mightBeUsableInConstantExpressions (S.getASTContext ())) ||
726- (S.getLangOpts ().OpenCL && !S.getLangOpts ().CPlusPlus11 &&
727- !VD->hasICEInitializer (S.getASTContext ()))) {
728- const SourceInfo &Loc = S.Current ->getSource (OpPC);
729- S.FFDiag (Loc, diag::note_constexpr_var_init_non_constant, 1 ) << VD;
730- S.Note (VD->getLocation (), diag::note_declared_at);
731- }
732- return false ;
733- }
734-
735718static bool CheckWeak (InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
736719 if (!Ptr.isWeak ())
737720 return true ;
@@ -745,6 +728,37 @@ static bool CheckWeak(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
745728 return false ;
746729}
747730
731+ // The list of checks here is just the one from CheckLoad, but with the
732+ // ones removed that are impossible on primitive global values.
733+ // For example, since those can't be members of structs, they also can't
734+ // be mutable.
735+ bool CheckGlobalLoad (InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
736+ if (!CheckExtern (S, OpPC, Ptr))
737+ return false ;
738+ if (!CheckConstant (S, OpPC, Ptr))
739+ return false ;
740+ if (!CheckDummy (S, OpPC, Ptr, AK_Read))
741+ return false ;
742+ if (!CheckInitialized (S, OpPC, Ptr, AK_Read))
743+ return false ;
744+ if (!CheckTemporary (S, OpPC, Ptr, AK_Read))
745+ return false ;
746+ if (!CheckWeak (S, OpPC, Ptr))
747+ return false ;
748+ if (!CheckVolatile (S, OpPC, Ptr, AK_Read))
749+ return false ;
750+ return true ;
751+ }
752+
753+ // Similarly, for local loads.
754+ bool CheckLocalLoad (InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
755+ if (!CheckInitialized (S, OpPC, Ptr, AK_Read))
756+ return false ;
757+ if (!CheckVolatile (S, OpPC, Ptr, AK_Read))
758+ return false ;
759+ return true ;
760+ }
761+
748762bool CheckLoad (InterpState &S, CodePtr OpPC, const Pointer &Ptr,
749763 AccessKinds AK) {
750764 if (!CheckLive (S, OpPC, Ptr, AK))
0 commit comments