Skip to content

Commit 318bff6

Browse files
authored
[clang][CUDA] Disable float128 diagnostics for device compilation (#83918)
1 parent 0497c77 commit 318bff6

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4877,7 +4877,9 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo &CI,
48774877
NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType);
48784878

48794879
if (NewElemTy.isNull()) {
4880-
Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
4880+
// Only emit diagnostic on host for 128-bit mode attribute
4881+
if (!(DestWidth == 128 && getLangOpts().CUDAIsDevice))
4882+
Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
48814883
return;
48824884
}
48834885

clang/lib/Sema/SemaType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
15611561
break;
15621562
case DeclSpec::TST_float128:
15631563
if (!S.Context.getTargetInfo().hasFloat128Type() &&
1564-
!S.getLangOpts().SYCLIsDevice &&
1564+
!S.getLangOpts().SYCLIsDevice && !S.getLangOpts().CUDAIsDevice &&
15651565
!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice))
15661566
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
15671567
<< "__float128";

clang/test/SemaCUDA/float128.cu

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// CPU-side compilation on x86 (no errors expected).
2+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 -x cuda -fsyntax-only -verify=cpu %s
3+
4+
// GPU-side compilation on x86 (no errors expected)
5+
// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -x cuda -fsyntax-only -verify=gpu %s
6+
7+
// cpu-no-diagnostics
8+
typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
9+
typedef __float128 _Float128;
10+
11+
// gpu-note@+1 {{'a' defined here}}
12+
__attribute__((device)) __float128 f(__float128 a, float b) {
13+
// gpu-note@+1 {{'c' defined here}}
14+
__float128 c = b + 1.0;
15+
// gpu-error@+2 {{'a' requires 128 bit size '__float128' type support, but target 'nvptx64' does not support it}}
16+
// gpu-error@+1 {{'c' requires 128 bit size '__float128' type support, but target 'nvptx64' does not support it}}
17+
return a + c;
18+
}

0 commit comments

Comments
 (0)