blob: bc4f10d3082c0d1906fa168d6c2582e585e15bf8 [file] [log] [blame]
Justin Lebar5489f852018-05-17 16:15:07 +00001// RUN: %clang_cc1 -fsyntax-only -Wundefined-internal -verify %s
2// RUN: %clang_cc1 -fsyntax-only -Wundefined-internal -fcuda-is-device -verify %s
Justin Lebar10411012016-09-30 23:57:30 +00003
Yaxun Liu97670892018-10-02 17:48:54 +00004// RUN: %clang_cc1 -fsyntax-only -Wundefined-internal -fgpu-rdc -verify=rdc %s
5// RUN: %clang_cc1 -fsyntax-only -Wundefined-internal -fcuda-is-device -fgpu-rdc -verify=rdc %s
Justin Lebar5489f852018-05-17 16:15:07 +00006
7// Most of these declarations are fine in separate compilation mode.
Jonas Hahnfeldee47d8c2018-02-14 16:04:03 +00008
Justin Lebar10411012016-09-30 23:57:30 +00009#include "Inputs/cuda.h"
10
11__device__ void foo() {
12 extern __shared__ int x; // expected-error {{__shared__ variable 'x' cannot be 'extern'}}
Justin Lebar281ce2a2016-10-02 15:24:50 +000013 extern __shared__ int arr[]; // ok
14 extern __shared__ int arr0[0]; // expected-error {{__shared__ variable 'arr0' cannot be 'extern'}}
15 extern __shared__ int arr1[1]; // expected-error {{__shared__ variable 'arr1' cannot be 'extern'}}
16 extern __shared__ int* ptr ; // expected-error {{__shared__ variable 'ptr' cannot be 'extern'}}
Justin Lebar10411012016-09-30 23:57:30 +000017}
18
19__host__ __device__ void bar() {
Justin Lebar281ce2a2016-10-02 15:24:50 +000020 extern __shared__ int arr[]; // ok
21 extern __shared__ int arr0[0]; // expected-error {{__shared__ variable 'arr0' cannot be 'extern'}}
22 extern __shared__ int arr1[1]; // expected-error {{__shared__ variable 'arr1' cannot be 'extern'}}
23 extern __shared__ int* ptr ; // expected-error {{__shared__ variable 'ptr' cannot be 'extern'}}
Justin Lebar10411012016-09-30 23:57:30 +000024}
25
26extern __shared__ int global; // expected-error {{__shared__ variable 'global' cannot be 'extern'}}
Justin Lebar281ce2a2016-10-02 15:24:50 +000027extern __shared__ int global_arr[]; // ok
28extern __shared__ int global_arr1[1]; // expected-error {{__shared__ variable 'global_arr1' cannot be 'extern'}}
Justin Lebar5489f852018-05-17 16:15:07 +000029
30// Check that, iff we're not in rdc mode, extern __shared__ can appear in an
31// anonymous namespace / in a static function without generating a warning
32// about a variable with internal linkage but no definition
33// (-Wundefined-internal).
34namespace {
35extern __shared__ int global_arr[]; // rdc-warning {{has internal linkage but is not defined}}
36__global__ void in_anon_ns() {
37 extern __shared__ int local_arr[]; // rdc-warning {{has internal linkage but is not defined}}
38
39 // Touch arrays to generate the warning.
40 local_arr[0] = 0; // rdc-note {{used here}}
41 global_arr[0] = 0; // rdc-note {{used here}}
42}
43} // namespace