https://github.com/pranavk updated https://github.com/llvm/llvm-project/pull/83918
>From c28121199d5e16efb908a3058a52c6b5b2016848 Mon Sep 17 00:00:00 2001 From: Pranav Kant <p...@google.com> Date: Mon, 4 Mar 2024 22:19:04 +0000 Subject: [PATCH 1/3] [clang][CUDA] Disable float128 diagnostics for device compilation --- clang/lib/Sema/SemaDeclAttr.cpp | 4 +++- clang/lib/Sema/SemaType.cpp | 1 + clang/test/SemaCUDA/float128.cu | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCUDA/float128.cu diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 397b5db0dc0669..e6943efb345ce0 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -4877,7 +4877,9 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo &CI, NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType); if (NewElemTy.isNull()) { - Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name; + // Only emit diagnostic on host for 128-bit mode attribute + if (!(DestWidth == 128 && getLangOpts().CUDAIsDevice)) + Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name; return; } diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 1e43e36016a66f..4a4e6f80d0d049 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1562,6 +1562,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { case DeclSpec::TST_float128: if (!S.Context.getTargetInfo().hasFloat128Type() && !S.getLangOpts().SYCLIsDevice && + !S.getLangOpts().CUDAIsDevice && !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice)) S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__float128"; diff --git a/clang/test/SemaCUDA/float128.cu b/clang/test/SemaCUDA/float128.cu new file mode 100644 index 00000000000000..a59e1b2f8a741a --- /dev/null +++ b/clang/test/SemaCUDA/float128.cu @@ -0,0 +1,9 @@ +// CPU-side compilation on x86 (no errors expected). +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 -x cuda -fsyntax-only -verify %s + +// GPU-side compilation on x86 (no errors expected) +// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -x cuda -fsyntax-only -verify %s + +// expected-no-diagnostics +typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__))); +typedef __float128 _Float128; >From bcc8d6ea5e7922712017ecb1941a53cf769577b3 Mon Sep 17 00:00:00 2001 From: Pranav Kant <p...@google.com> Date: Mon, 4 Mar 2024 22:31:24 +0000 Subject: [PATCH 2/3] formatting --- clang/lib/Sema/SemaType.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 4a4e6f80d0d049..3148299f6467af 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1561,8 +1561,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { break; case DeclSpec::TST_float128: if (!S.Context.getTargetInfo().hasFloat128Type() && - !S.getLangOpts().SYCLIsDevice && - !S.getLangOpts().CUDAIsDevice && + !S.getLangOpts().SYCLIsDevice && !S.getLangOpts().CUDAIsDevice && !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice)) S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__float128"; >From 422af59d7aa7c0095606e0a9bf6ce091ea84b925 Mon Sep 17 00:00:00 2001 From: Pranav Kant <p...@google.com> Date: Wed, 6 Mar 2024 22:33:33 +0000 Subject: [PATCH 3/3] extend test to compile a device function --- clang/test/SemaCUDA/float128.cu | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/clang/test/SemaCUDA/float128.cu b/clang/test/SemaCUDA/float128.cu index a59e1b2f8a741a..f8f20cb1588d76 100644 --- a/clang/test/SemaCUDA/float128.cu +++ b/clang/test/SemaCUDA/float128.cu @@ -1,9 +1,18 @@ // CPU-side compilation on x86 (no errors expected). -// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 -x cuda -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 -x cuda -fsyntax-only -verify=cpu %s // GPU-side compilation on x86 (no errors expected) -// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -x cuda -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -x cuda -fsyntax-only -verify=gpu %s -// expected-no-diagnostics +// cpu-no-diagnostics typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__))); typedef __float128 _Float128; + +// gpu-note@+1 {{'a' defined here}} +__attribute__((device)) __float128 f(__float128 a, float b) { + // gpu-note@+1 {{'c' defined here}} + __float128 c = b + 1.0; + // gpu-error@+2 {{'a' requires 128 bit size '__float128' type support, but target 'nvptx64' does not support it}} + // gpu-error@+1 {{'c' requires 128 bit size '__float128' type support, but target 'nvptx64' does not support it}} + return a + c; +} \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits