[clang] f7e87dd - [CUDA][HIP] Change default lang std to c++14

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 1 18:09:40 PDT 2021


Author: Yaxun (Sam) Liu
Date: 2021-06-01T20:45:10-04:00
New Revision: f7e87dd6ff0c1c4a41a6b654d2460557ae97ab8d

URL: https://github.com/llvm/llvm-project/commit/f7e87dd6ff0c1c4a41a6b654d2460557ae97ab8d
DIFF: https://github.com/llvm/llvm-project/commit/f7e87dd6ff0c1c4a41a6b654d2460557ae97ab8d.diff

LOG: [CUDA][HIP] Change default lang std to c++14

Currently clang and nvcc use c++14 as default std for C++.
gcc 11 even uses c++17 as default std for C++. However,
clang uses c++98 as default std for CUDA/HIP.

As c++14 has been well adopted and became default for
clang, it seems reasonable to use c++14 as default std
for CUDA/HIP.

Reviewed by: Artem Belevich

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

Added: 
    clang/test/Preprocessor/lang-std.cu

Modified: 
    clang/include/clang/Basic/LangStandards.def
    clang/test/Parser/cuda-kernel-call.cu
    clang/test/SemaCUDA/asm_delayed_diags.cu
    clang/test/SemaCUDA/cuda-builtin-vars.cu
    clang/test/SemaCUDA/function-target.cu
    clang/test/SemaCUDA/implicit-member-target-collision.cu

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/LangStandards.def b/clang/include/clang/Basic/LangStandards.def
index f086d8a43ccb5..2cfeb68e56d62 100644
--- a/clang/include/clang/Basic/LangStandards.def
+++ b/clang/include/clang/Basic/LangStandards.def
@@ -194,11 +194,11 @@ LANGSTANDARD_ALIAS_DEPR(openclcpp, "CLC++")
 
 // CUDA
 LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA CUDA(tm)",
-             LineComment | CPlusPlus | Digraphs)
+             LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
 
 // HIP
 LANGSTANDARD(hip, "hip", HIP, "HIP",
-             LineComment | CPlusPlus | Digraphs)
+             LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
 
 #undef LANGSTANDARD
 #undef LANGSTANDARD_ALIAS

diff  --git a/clang/test/Parser/cuda-kernel-call.cu b/clang/test/Parser/cuda-kernel-call.cu
index 2a409aa3777ea..ef708e3a4b96d 100644
--- a/clang/test/Parser/cuda-kernel-call.cu
+++ b/clang/test/Parser/cuda-kernel-call.cu
@@ -12,8 +12,8 @@ void foo(void) {
 
   // The following two are parse errors because -std=c++11 is not enabled.
 
-  S<S<S<int>>> s; // expected-error 2{{use '> >'}}
-  S<S<S<>>> s1; // expected-error 2{{use '> >'}}
-  (void)(&f<S<S<int>>>==0); // expected-error 2{{use '> >'}}
-  (void)(&f<S<S<>>>==0); // expected-error 2{{use '> >'}}
+  S<S<S<int>>> s;
+  S<S<S<>>> s1;
+  (void)(&f<S<S<int>>>==0);
+  (void)(&f<S<S<>>>==0);
 }

diff  --git a/clang/test/Preprocessor/lang-std.cu b/clang/test/Preprocessor/lang-std.cu
new file mode 100644
index 0000000000000..4f35af01aaf5f
--- /dev/null
+++ b/clang/test/Preprocessor/lang-std.cu
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -dM -E -x hip %s | FileCheck -check-prefix=CXX14 %s
+// RUN: %clang_cc1 -dM -E %s | FileCheck -check-prefix=CXX14 %s
+// RUN: %clang_cc1 -dM -E -std=c++98 -x hip %s | FileCheck -check-prefix=CXX98 %s
+// RUN: %clang_cc1 -dM -E -std=c++98 %s | FileCheck -check-prefix=CXX98 %s
+
+// CXX98: #define __cplusplus 199711L
+// CXX14: #define __cplusplus 201402L

diff  --git a/clang/test/SemaCUDA/asm_delayed_diags.cu b/clang/test/SemaCUDA/asm_delayed_diags.cu
index 457054f608fab..55d063ed9fa1f 100644
--- a/clang/test/SemaCUDA/asm_delayed_diags.cu
+++ b/clang/test/SemaCUDA/asm_delayed_diags.cu
@@ -28,7 +28,7 @@ static __device__ __host__ unsigned t2(signed char input) {
 }
 
 static __device__ __host__ double t3(double x) {
-  register long double result;
+  long double result;
   __asm __volatile("frndint"
                    : "=t"(result)
                    : "0"(x));

diff  --git a/clang/test/SemaCUDA/cuda-builtin-vars.cu b/clang/test/SemaCUDA/cuda-builtin-vars.cu
index 27a9c5abd700b..f9c05e94f4a6e 100644
--- a/clang/test/SemaCUDA/cuda-builtin-vars.cu
+++ b/clang/test/SemaCUDA/cuda-builtin-vars.cu
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 "-triple" "nvptx-nvidia-cuda" -fcuda-is-device -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "nvptx-nvidia-cuda" -fcuda-is-device -fsyntax-only -verify \
+// RUN:   -verify-ignore-unexpected=note %s
 
 #include "__clang_cuda_builtin_vars.h"
 __attribute__((global))
@@ -37,17 +38,13 @@ void kernel(int *out) {
   // expected-note at __clang_cuda_builtin_vars.h:* {{variable 'warpSize' declared const here}}
 
   // Make sure we can't construct or assign to the special variables.
-  __cuda_builtin_threadIdx_t x; // expected-error {{calling a private constructor of class '__cuda_builtin_threadIdx_t'}}
-  // expected-note at __clang_cuda_builtin_vars.h:* {{declared private here}}
+  __cuda_builtin_threadIdx_t x; // expected-error {{call to deleted constructor of '__cuda_builtin_threadIdx_t'}}
 
-  __cuda_builtin_threadIdx_t y = threadIdx; // expected-error {{calling a private constructor of class '__cuda_builtin_threadIdx_t'}}
-  // expected-note at __clang_cuda_builtin_vars.h:* {{declared private here}}
+  __cuda_builtin_threadIdx_t y = threadIdx; // expected-error {{call to deleted constructor of '__cuda_builtin_threadIdx_t'}}
 
-  threadIdx = threadIdx; // expected-error {{'operator=' is a private member of '__cuda_builtin_threadIdx_t'}}
-  // expected-note at __clang_cuda_builtin_vars.h:* {{declared private here}}
+  threadIdx = threadIdx; // expected-error {{overload resolution selected deleted operator '='}}
 
-  void *ptr = &threadIdx; // expected-error {{'operator&' is a private member of '__cuda_builtin_threadIdx_t'}}
-  // expected-note at __clang_cuda_builtin_vars.h:* {{declared private here}}
+  void *ptr = &threadIdx; // expected-error {{overload resolution selected deleted operator '&'}}
 
   // Following line should've caused an error as one is not allowed to
   // take address of a built-in variable in CUDA. Alas there's no way

diff  --git a/clang/test/SemaCUDA/function-target.cu b/clang/test/SemaCUDA/function-target.cu
index 48f7229df21f2..64444b6676248 100644
--- a/clang/test/SemaCUDA/function-target.cu
+++ b/clang/test/SemaCUDA/function-target.cu
@@ -9,6 +9,7 @@ __host__ __device__ void h1hd(void);
 __global__ void h1g(void);
 
 struct h1ds { // expected-note {{requires 1 argument}}
+	      // expected-note at -1 {{candidate constructor (the implicit move constructor) not viable}}
   __device__ h1ds(); // expected-note {{candidate constructor not viable: call to __device__ function from __host__ function}}
 };
 

diff  --git a/clang/test/SemaCUDA/implicit-member-target-collision.cu b/clang/test/SemaCUDA/implicit-member-target-collision.cu
index 25cdccbfd35d0..a50fddaa4615b 100644
--- a/clang/test/SemaCUDA/implicit-member-target-collision.cu
+++ b/clang/test/SemaCUDA/implicit-member-target-collision.cu
@@ -19,6 +19,7 @@ struct C1_with_collision : A1_with_host_ctor, B1_with_device_ctor {
 // expected-note at -3 {{candidate constructor (the implicit default constructor}} not viable
 // expected-note at -4 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
 // expected-note at -5 {{candidate constructor (the implicit copy constructor}} not viable
+// expected-note at -6 {{candidate constructor (the implicit move constructor) not viable}}
 
 void hostfoo1() {
   C1_with_collision c; // expected-error {{no matching constructor}}
@@ -35,6 +36,7 @@ struct C2_with_collision {
 // expected-note at -5 {{candidate constructor (the implicit default constructor}} not viable
 // expected-note at -6 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
 // expected-note at -7 {{candidate constructor (the implicit copy constructor}} not viable
+// expected-note at -8 {{candidate constructor (the implicit move constructor) not viable}}
 
 void hostfoo2() {
   C2_with_collision c; // expected-error {{no matching constructor}}
@@ -51,6 +53,7 @@ struct C3_with_collision : A1_with_host_ctor {
 // expected-note at -4 {{candidate constructor (the implicit default constructor}} not viable
 // expected-note at -5 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
 // expected-note at -6 {{candidate constructor (the implicit copy constructor}} not viable
+// expected-note at -7 {{candidate constructor (the implicit move constructor) not viable}}
 
 void hostfoo3() {
   C3_with_collision c; // expected-error {{no matching constructor}}


        


More information about the cfe-commits mailing list