Skip to content

Commit

Permalink
[CUDA] Allow external variables in separate compilation
Browse files Browse the repository at this point in the history
According to the CUDA Programming Guide this is prohibited in
whole program compilation mode. This makes sense because external
references cannot be satisfied in that mode anyway. However,
such variables are allowed in separate compilation mode which
is a valid use case.

Differential Revision: https://reviews.llvm.org/D42923

llvm-svn: 325136
  • Loading branch information
hahnjo committed Feb 14, 2018
1 parent 7e5d525 commit ee47d8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDeclAttr.cpp
Expand Up @@ -4112,7 +4112,8 @@ static void handleSharedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
auto *VD = cast<VarDecl>(D);
// extern __shared__ is only allowed on arrays with no length (e.g.
// "int x[]").
if (VD->hasExternalStorage() && !isa<IncompleteArrayType>(VD->getType())) {
if (!S.getLangOpts().CUDARelocatableDeviceCode && VD->hasExternalStorage() &&
!isa<IncompleteArrayType>(VD->getType())) {
S.Diag(Attr.getLoc(), diag::err_cuda_extern_shared) << VD;
return;
}
Expand Down
5 changes: 5 additions & 0 deletions clang/test/SemaCUDA/extern-shared.cu
@@ -1,6 +1,11 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s

// RUN: %clang_cc1 -fsyntax-only -fcuda-rdc -verify=rdc %s
// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -fcuda-rdc -verify=rdc %s
// These declarations are fine in separate compilation mode:
// rdc-no-diagnostics

#include "Inputs/cuda.h"

__device__ void foo() {
Expand Down

0 comments on commit ee47d8c

Please sign in to comment.