[clang] [clang][CUDA] Disable float128 diagnostics for device compilation (PR #83918)
Pranav Kant via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 4 14:27:23 PST 2024
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 <prka at google.com>
Date: Mon, 4 Mar 2024 22:19:04 +0000
Subject: [PATCH] [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;
More information about the cfe-commits
mailing list