@@ -321,7 +321,7 @@ void SemaCUDA::EraseUnwantedMatches(
321321 if (Matches.size () <= 1 )
322322 return ;
323323
324- using Pair = std::pair<DeclAccessPair, FunctionDecl*>;
324+ using Pair = std::pair<DeclAccessPair, FunctionDecl *>;
325325
326326 // Gets the CUDA function preference for a call from Caller to Match.
327327 auto GetCFP = [&](const Pair &Match) {
@@ -504,7 +504,6 @@ bool SemaCUDA::inferTargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
504504 }
505505 }
506506
507-
508507 // If no target was inferred, mark this member as __host__ __device__;
509508 // it's the least restrictive option that can be invoked from any target.
510509 bool NeedsH = true , NeedsD = true ;
@@ -679,16 +678,22 @@ void SemaCUDA::checkAllowedInitializer(VarDecl *VD) {
679678 FD && FD->isDependentContext ())
680679 return ;
681680
681+ bool IsSharedVar = VD->hasAttr <CUDASharedAttr>();
682+ bool IsDeviceOrConstantVar =
683+ !IsSharedVar &&
684+ (VD->hasAttr <CUDADeviceAttr>() || VD->hasAttr <CUDAConstantAttr>());
685+ if ((IsSharedVar || IsDeviceOrConstantVar) &&
686+ VD->getType ().getQualifiers ().getAddressSpace () != LangAS::Default) {
687+ Diag (VD->getLocation (), diag::err_cuda_address_space_gpuvar);
688+ VD->setInvalidDecl ();
689+ return ;
690+ }
682691 // Do not check dependent variables since the ctor/dtor/initializer are not
683692 // determined. Do it after instantiation.
684693 if (VD->isInvalidDecl () || !VD->hasInit () || !VD->hasGlobalStorage () ||
685694 IsDependentVar (VD))
686695 return ;
687696 const Expr *Init = VD->getInit ();
688- bool IsSharedVar = VD->hasAttr <CUDASharedAttr>();
689- bool IsDeviceOrConstantVar =
690- !IsSharedVar &&
691- (VD->hasAttr <CUDADeviceAttr>() || VD->hasAttr <CUDAConstantAttr>());
692697 if (IsDeviceOrConstantVar || IsSharedVar) {
693698 if (HasAllowedCUDADeviceStaticInitializer (
694699 *this , VD, IsSharedVar ? CICK_Shared : CICK_DeviceOrConstant))
0 commit comments