Author: Yaxun (Sam) Liu Date: 2021-05-12T22:32:10-04:00 New Revision: ce6cc87ce9e96eaa5e5ef0c1f5dc07b41381996d
URL: https://github.com/llvm/llvm-project/commit/ce6cc87ce9e96eaa5e5ef0c1f5dc07b41381996d DIFF: https://github.com/llvm/llvm-project/commit/ce6cc87ce9e96eaa5e5ef0c1f5dc07b41381996d.diff LOG: [clang] Minor fix for MarkVarDeclODRUsed Merge two if as follow up of https://reviews.llvm.org/D102270 Added: Modified: clang/lib/Sema/SemaExpr.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index b8be6732b758..6e20eb5b99dd 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -17126,7 +17126,7 @@ MarkVarDeclODRUsed(VarDecl *Var, SourceLocation Loc, Sema &SemaRef, CaptureType, DeclRefType, FunctionScopeIndexToStopAt); - if (SemaRef.LangOpts.CUDA) { + if (SemaRef.LangOpts.CUDA && Var && Var->hasGlobalStorage()) { auto *FD = dyn_cast_or_null<FunctionDecl>(SemaRef.CurContext); auto Target = SemaRef.IdentifyCUDATarget(FD); auto IsEmittedOnDeviceSide = [](VarDecl *Var) { @@ -17142,28 +17142,26 @@ MarkVarDeclODRUsed(VarDecl *Var, SourceLocation Loc, Sema &SemaRef, } return false; }; - if (Var && Var->hasGlobalStorage()) { - if (!IsEmittedOnDeviceSide(Var)) { - // Diagnose ODR-use of host global variables in device functions. - // Reference of device global variables in host functions is allowed - // through shadow variables therefore it is not diagnosed. - if (SemaRef.LangOpts.CUDAIsDevice) - SemaRef.targetDiag(Loc, diag::err_ref_bad_target) - << /*host*/ 2 << /*variable*/ 1 << Var << Target; - } else if ((Target == Sema::CFT_Host || Target == Sema::CFT_HostDevice) && - !Var->hasExternalStorage()) { - // Record a CUDA/HIP device side variable if it is ODR-used - // by host code. This is done conservatively, when the variable is - // referenced in any of the following contexts: - // - a non-function context - // - a host function - // - a host device function - // This makes the ODR-use of the device side variable by host code to - // be visible in the device compilation for the compiler to be able to - // emit template variables instantiated by host code only and to - // externalize the static device side variable ODR-used by host code. - SemaRef.getASTContext().CUDADeviceVarODRUsedByHost.insert(Var); - } + if (!IsEmittedOnDeviceSide(Var)) { + // Diagnose ODR-use of host global variables in device functions. + // Reference of device global variables in host functions is allowed + // through shadow variables therefore it is not diagnosed. + if (SemaRef.LangOpts.CUDAIsDevice) + SemaRef.targetDiag(Loc, diag::err_ref_bad_target) + << /*host*/ 2 << /*variable*/ 1 << Var << Target; + } else if ((Target == Sema::CFT_Host || Target == Sema::CFT_HostDevice) && + !Var->hasExternalStorage()) { + // Record a CUDA/HIP device side variable if it is ODR-used + // by host code. This is done conservatively, when the variable is + // referenced in any of the following contexts: + // - a non-function context + // - a host function + // - a host device function + // This makes the ODR-use of the device side variable by host code to + // be visible in the device compilation for the compiler to be able to + // emit template variables instantiated by host code only and to + // externalize the static device side variable ODR-used by host code. + SemaRef.getASTContext().CUDADeviceVarODRUsedByHost.insert(Var); } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits