[clang] [CUDA][HIP] warn incompatible redeclare (PR #77359)

Artem Belevich via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 16 11:33:24 PST 2024


================
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:   -isystem %S/Inputs -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only \
+// RUN:   -isystem %S/Inputs -fcuda-is-device -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:   -isystem %S/Inputs -verify=redecl -Woffload-incompatible-redeclare %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only \
+// RUN:   -isystem %S/Inputs -fcuda-is-device -Woffload-incompatible-redeclare -verify=redecl %s
+
+// expected-no-diagnostics
+#include "cuda.h"
+
+__device__ void f(); // redecl-note {{previous declaration is here}}
+
+void f() {} // redecl-warning {{incompatible host/device attribute with redeclaration: new declaration is __host__ function, old declaration is __device__ function. It will cause warning with nvcc}}
----------------
Artem-B wrote:

I'm not convinced that it's something we need to fix. As far as CUDA is concerned those are two different function overloads and it's business as usual with no warning required.

nvcc does not have a concept of attribute-based overloads, so for them a function with different attributes is a sign of a potential issue, but it's not the case for clang, IMO.

https://github.com/llvm/llvm-project/pull/77359


More information about the cfe-commits mailing list