[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-14 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).

AaronBallman wrote:

Yeah, that's why I'm trying to push/nerd snipe for offloading to tackle this 
problem at some point sooner rather than later. The debugging experience for 
offload is already hard enough but in this particular case, good luck even 
noticing our bug (unless you're testing excess precision really well, you won't 
notice you got 32-bits instead of 128-bits for the computations, so this kind 
of bug can remain in a codebase for a *long* time I'd expect).

https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-14 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).

jhuber6 wrote:

Offloading languages are basically woefully optimistic about types. They 
declare all the types to match, which can result in things that are mutually 
incompatible (i.e. long double giving you fp80 on a GPU which cannot codegen 
it). There's tons of hacks around stuff like this.

https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-14 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

Despite the miscompile, this LGTM and I filed 
https://github.com/llvm/llvm-project/issues/216334 for addressing the 
underlying issue.

Note, this is a bit odd to accept in a known-bad state, but because our 
behavior in OpenMP (and other offloading languages) is to reject code compiling 
against a newer glibc (2.41 or later) even if the type is not used in the 
program, we'll hold our nose. But the issue should be addressed ASAP. CC 
@sarnex @jdoerfert @jhuber6 for awareness

https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-13 Thread Alex Duran via cfe-commits


@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).

adurang wrote:

I expanded the test forcing the type to be consumed by the backend. OpenMP 
currently seems to just downgrade the type to 64-bits with not error message.

I added different FIXME messages pointing the different things that are wrong 
today.

https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-13 Thread Alex Duran via cfe-commits

https://github.com/adurang updated 
https://github.com/llvm/llvm-project/pull/214497

>From 4dd92c173b766a6f0f2c8caff108608d00b778fc Mon Sep 17 00:00:00 2001
From: "Duran, Alex" 
Date: Thu, 6 Aug 2026 06:45:42 -0700
Subject: [PATCH 1/4] [clang][sema] Suppress unsupported 128-bit mode attribute
 diagnostic for OpenMP device compilation

On system with newer glibc (2.41) the device compilation side fails with:

/usr/include/x86_64-linux-gnu/bits/floatn.h:83:52: error: unsupported machine 
mode '__TC__'
   83 | typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
  |^

Sema::AddModeAttr already avoids diagnosing a 128-bit `mode` attribute
(e.g. __TC__, as used by glibc's __cfloat128) that the target can't
represent, but only for CUDA and SYCL device compilation. OpenMP
target-device compilation for targets also lacks a 128-bit float/complex
representation so we extend the check to cover OpenMPIsTargetDevice as
well to avoid the fail.
---
 clang/lib/Sema/SemaDeclAttr.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 492b125587344..813b7de3e86e6 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5226,7 +5226,8 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
   if (NewElemTy.isNull()) {
 // Only emit diagnostic on host for 128-bit mode attribute
 if (!(DestWidth == 128 &&
-  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice)))
+  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice ||
+   getLangOpts().OpenMPIsTargetDevice)))
   Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
 return;
   }

>From 2d6fc7a8a90c970f47c312a83cb5628be08be5fa Mon Sep 17 00:00:00 2001
From: "Duran, Alex" 
Date: Thu, 6 Aug 2026 07:05:24 -0700
Subject: [PATCH 2/4] Add regression test

---
 clang/test/OpenMP/target_device_float128_mode_attr.c | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 clang/test/OpenMP/target_device_float128_mode_attr.c

diff --git a/clang/test/OpenMP/target_device_float128_mode_attr.c 
b/clang/test/OpenMP/target_device_float128_mode_attr.c
new file mode 100644
index 0..19bff61bfb0ed
--- /dev/null
+++ b/clang/test/OpenMP/target_device_float128_mode_attr.c
@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).
+// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-is-target-device -x c -fsyntax-only -verify=device %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-unknown-linux-gnu -fopenmp -fopenmp-is-target-device -x c -fsyntax-only 
-verify=device %s
+// RUN: %clang_cc1 -triple spirv64 -aux-triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-is-target-device -x c -fsyntax-only -verify=device %s
+
+// host-no-diagnostics
+// device-no-diagnostics
+typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));

>From b00a3a42b2192413a3ec77c5332d83dde017d18f Mon Sep 17 00:00:00 2001
From: "Duran, Alex" 
Date: Thu, 6 Aug 2026 08:01:04 -0700
Subject: [PATCH 3/4] simplify condition

---
 clang/lib/Sema/SemaDeclAttr.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 813b7de3e86e6..79e9824bd5728 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5225,9 +5225,7 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
 
   if (NewElemTy.isNull()) {
 // Only emit diagnostic on host for 128-bit mode attribute
-if (!(DestWidth == 128 &&
-  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice ||
-   getLangOpts().OpenMPIsTargetDevice)))
+if (!(DestWidth == 128 && getLangOpts().isTargetDevice()))
   Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
 return;
   }

>From 9439db8a16b2c5addf0a01f82e6e7020eb955cfa Mon Sep 17 00:00:00 2001
From: "Duran, Alex" 
Date: Thu, 13 Aug 2026 05:38:11 -0700
Subject: [PATCH 4/4] Add FIXME notes and check for current OpenMP codegen

---
 clang/lib/Sema/SemaDeclAttr.cpp |  2 ++
 .../OpenMP/target_device_float128_mode_attr.c   | 17 ++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 79e9824bd5728..f7b0bc8c440db 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5224,6 +5224,8 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
 NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType);
 
   if 

[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-07 Thread Tom Honermann via cfe-commits


@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).

tahonermann wrote:

I think @Fznamznon's example should produce a (possibly deferred) diagnostic as 
should this example: https://godbolt.org/z/h354W9T7d.

At a minimum, the test(s) should exercise use in a device function with a FIXME 
stating that a diagnostic should be issued for such usage.


https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-07 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).

AaronBallman wrote:

Looking at some of the comments in `checkTypeSupport` leaves me a bit 
terrified: 
https://github.com/llvm/llvm-project/blob/9ff674efdb2be183f8a873f70726107b1399d708/clang/lib/Sema/Sema.cpp#L2272
 Unused declaration... during codegen... turning into a bucket of bytes with 
some hope sprinkled in. :-D

tl;dr specific to this PR: if the type is not supported on the device, we need 
test coverage demonstrating that problematic uses of the type are diagnosed 
correctly for device compilations. Can someone point me to that existing 
coverage? (And do we have coverage for Cuda, SYCL, OpenMP, and others? Or only 
one offloading language?) The changes in this PR are just adding one more case 
to an existing pattern, so that seems fine, but I want to make sure this isn't 
cargo culting around a bigger problem.

https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-07 Thread Mariya Podchishchaeva via cfe-commits


@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).

Fznamznon wrote:

That highly depends on the CodeGen as well as further lowering and the type 
itself. The type this PR is poking at doesn't seem to be problematic 
https://godbolt.org/z/h7515Y3Go though a warning saying please don't do this 
would probably make sense. 
I remember some types crashed translation from LLVM IR to SPIR-V via the 
translator tool used in SYCL's downstream so for that purpose 
`Sema::checkTypeSupport` was invented.

https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-07 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).

AaronBallman wrote:

What happens if it is used from device code entry points or something called by 
them?

https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-07 Thread Mariya Podchishchaeva via cfe-commits


@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).

Fznamznon wrote:

At least for SYCL, the type won't make it to the codegen if not used from the 
device code, i.e. not used from within device code entry points or anything 
called by them. I suppose OMP/CUDA work in a similar way. If we want to 
diagnose the problematic type , see `Sema::checkTypeSupport`  and 
`Sema::targetDiag`.

https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-06 Thread Alex Duran via cfe-commits


@@ -5226,7 +5226,8 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
   if (NewElemTy.isNull()) {
 // Only emit diagnostic on host for 128-bit mode attribute
 if (!(DestWidth == 128 &&
-  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice)))
+  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice ||

adurang wrote:

seems much better, yes. Should have been like that from the beginning!

https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-06 Thread Alex Duran via cfe-commits

https://github.com/adurang updated 
https://github.com/llvm/llvm-project/pull/214497

>From 4dd92c173b766a6f0f2c8caff108608d00b778fc Mon Sep 17 00:00:00 2001
From: "Duran, Alex" 
Date: Thu, 6 Aug 2026 06:45:42 -0700
Subject: [PATCH 1/3] [clang][sema] Suppress unsupported 128-bit mode attribute
 diagnostic for OpenMP device compilation

On system with newer glibc (2.41) the device compilation side fails with:

/usr/include/x86_64-linux-gnu/bits/floatn.h:83:52: error: unsupported machine 
mode '__TC__'
   83 | typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
  |^

Sema::AddModeAttr already avoids diagnosing a 128-bit `mode` attribute
(e.g. __TC__, as used by glibc's __cfloat128) that the target can't
represent, but only for CUDA and SYCL device compilation. OpenMP
target-device compilation for targets also lacks a 128-bit float/complex
representation so we extend the check to cover OpenMPIsTargetDevice as
well to avoid the fail.
---
 clang/lib/Sema/SemaDeclAttr.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 492b125587344..813b7de3e86e6 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5226,7 +5226,8 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
   if (NewElemTy.isNull()) {
 // Only emit diagnostic on host for 128-bit mode attribute
 if (!(DestWidth == 128 &&
-  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice)))
+  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice ||
+   getLangOpts().OpenMPIsTargetDevice)))
   Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
 return;
   }

>From 2d6fc7a8a90c970f47c312a83cb5628be08be5fa Mon Sep 17 00:00:00 2001
From: "Duran, Alex" 
Date: Thu, 6 Aug 2026 07:05:24 -0700
Subject: [PATCH 2/3] Add regression test

---
 clang/test/OpenMP/target_device_float128_mode_attr.c | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 clang/test/OpenMP/target_device_float128_mode_attr.c

diff --git a/clang/test/OpenMP/target_device_float128_mode_attr.c 
b/clang/test/OpenMP/target_device_float128_mode_attr.c
new file mode 100644
index 0..19bff61bfb0ed
--- /dev/null
+++ b/clang/test/OpenMP/target_device_float128_mode_attr.c
@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).
+// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-is-target-device -x c -fsyntax-only -verify=device %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-unknown-linux-gnu -fopenmp -fopenmp-is-target-device -x c -fsyntax-only 
-verify=device %s
+// RUN: %clang_cc1 -triple spirv64 -aux-triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-is-target-device -x c -fsyntax-only -verify=device %s
+
+// host-no-diagnostics
+// device-no-diagnostics
+typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));

>From b00a3a42b2192413a3ec77c5332d83dde017d18f Mon Sep 17 00:00:00 2001
From: "Duran, Alex" 
Date: Thu, 6 Aug 2026 08:01:04 -0700
Subject: [PATCH 3/3] simplify condition

---
 clang/lib/Sema/SemaDeclAttr.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 813b7de3e86e6..79e9824bd5728 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5225,9 +5225,7 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
 
   if (NewElemTy.isNull()) {
 // Only emit diagnostic on host for 128-bit mode attribute
-if (!(DestWidth == 128 &&
-  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice ||
-   getLangOpts().OpenMPIsTargetDevice)))
+if (!(DestWidth == 128 && getLangOpts().isTargetDevice()))
   Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
 return;
   }

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-06 Thread Nick Sarnie via cfe-commits


@@ -5226,7 +5226,8 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
   if (NewElemTy.isNull()) {
 // Only emit diagnostic on host for 128-bit mode attribute
 if (!(DestWidth == 128 &&
-  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice)))
+  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice ||

sarnex wrote:

can we instead use `getLangOpts().isTargetDevice()`? it does exactly this 
already:


https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-06 Thread Nick Sarnie via cfe-commits

https://github.com/sarnex edited 
https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-06 Thread Nick Sarnie via cfe-commits

https://github.com/sarnex edited 
https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-06 Thread Nick Sarnie via cfe-commits

https://github.com/sarnex approved this pull request.

lgtm with a nit, but lets wait for another review also

https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-06 Thread via cfe-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-clang

Author: Alex Duran (adurang)


Changes

 On systems with newer glibc (2.41) when compiling with -fopenmp-targets the 
device compilation side fails with:

> /usr/include/x86_64-linux-gnu/bits/floatn.h:83:52: error: unsupported 
machine mode '__TC__'
>83 | typedef _Complex float __cfloat128 __attribute__ ((__mode__ 
(__TC__)));
>   |^
 
 Sema::AddModeAttr already avoids diagnosing a 128-bit `mode` attribute  (e.g. 
__TC__, as used by glibc's __cfloat128) that the target can't represent, but 
only for CUDA and SYCL device compilation. OpenMP target-device compilation for 
targets also lacks a 128-bit float/complex representation so we extend the 
check to cover OpenMPIsTargetDevice as well to avoid the fail.

Assisted by Claude.

---
Full diff: https://github.com/llvm/llvm-project/pull/214497.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+2-1) 
- (added) clang/test/OpenMP/target_device_float128_mode_attr.c (+11) 


``diff
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 492b125587344..813b7de3e86e6 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5226,7 +5226,8 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
   if (NewElemTy.isNull()) {
 // Only emit diagnostic on host for 128-bit mode attribute
 if (!(DestWidth == 128 &&
-  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice)))
+  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice ||
+   getLangOpts().OpenMPIsTargetDevice)))
   Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
 return;
   }
diff --git a/clang/test/OpenMP/target_device_float128_mode_attr.c 
b/clang/test/OpenMP/target_device_float128_mode_attr.c
new file mode 100644
index 0..19bff61bfb0ed
--- /dev/null
+++ b/clang/test/OpenMP/target_device_float128_mode_attr.c
@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).
+// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-is-target-device -x c -fsyntax-only -verify=device %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-unknown-linux-gnu -fopenmp -fopenmp-is-target-device -x c -fsyntax-only 
-verify=device %s
+// RUN: %clang_cc1 -triple spirv64 -aux-triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-is-target-device -x c -fsyntax-only -verify=device %s
+
+// host-no-diagnostics
+// device-no-diagnostics
+typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));

``




https://github.com/llvm/llvm-project/pull/214497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Suppress unsupported 128-bit mode attribute diagnostic for OpenMP device compilation (PR #214497)

2026-08-06 Thread Alex Duran via cfe-commits

https://github.com/adurang created 
https://github.com/llvm/llvm-project/pull/214497

 On systems with newer glibc (2.41) when compiling with -fopenmp-targets the 
device compilation side fails with:

> /usr/include/x86_64-linux-gnu/bits/floatn.h:83:52: error: unsupported 
> machine mode '__TC__'
>83 | typedef _Complex float __cfloat128 __attribute__ ((__mode__ 
> (__TC__)));
>   |^
 
 Sema::AddModeAttr already avoids diagnosing a 128-bit `mode` attribute  (e.g. 
__TC__, as used by glibc's __cfloat128) that the target can't represent, but 
only for CUDA and SYCL device compilation. OpenMP target-device compilation for 
targets also lacks a 128-bit float/complex representation so we extend the 
check to cover OpenMPIsTargetDevice as well to avoid the fail.

Assisted by Claude.

>From 4dd92c173b766a6f0f2c8caff108608d00b778fc Mon Sep 17 00:00:00 2001
From: "Duran, Alex" 
Date: Thu, 6 Aug 2026 06:45:42 -0700
Subject: [PATCH 1/2] [clang][sema] Suppress unsupported 128-bit mode attribute
 diagnostic for OpenMP device compilation

On system with newer glibc (2.41) the device compilation side fails with:

/usr/include/x86_64-linux-gnu/bits/floatn.h:83:52: error: unsupported machine 
mode '__TC__'
   83 | typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
  |^

Sema::AddModeAttr already avoids diagnosing a 128-bit `mode` attribute
(e.g. __TC__, as used by glibc's __cfloat128) that the target can't
represent, but only for CUDA and SYCL device compilation. OpenMP
target-device compilation for targets also lacks a 128-bit float/complex
representation so we extend the check to cover OpenMPIsTargetDevice as
well to avoid the fail.
---
 clang/lib/Sema/SemaDeclAttr.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 492b125587344..813b7de3e86e6 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5226,7 +5226,8 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo 
&CI,
   if (NewElemTy.isNull()) {
 // Only emit diagnostic on host for 128-bit mode attribute
 if (!(DestWidth == 128 &&
-  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice)))
+  (getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice ||
+   getLangOpts().OpenMPIsTargetDevice)))
   Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
 return;
   }

>From 2d6fc7a8a90c970f47c312a83cb5628be08be5fa Mon Sep 17 00:00:00 2001
From: "Duran, Alex" 
Date: Thu, 6 Aug 2026 07:05:24 -0700
Subject: [PATCH 2/2] Add regression test

---
 clang/test/OpenMP/target_device_float128_mode_attr.c | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 clang/test/OpenMP/target_device_float128_mode_attr.c

diff --git a/clang/test/OpenMP/target_device_float128_mode_attr.c 
b/clang/test/OpenMP/target_device_float128_mode_attr.c
new file mode 100644
index 0..19bff61bfb0ed
--- /dev/null
+++ b/clang/test/OpenMP/target_device_float128_mode_attr.c
@@ -0,0 +1,11 @@
+// Host-side compilation on x86 (no errors expected).
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64 
-fopenmp -x c -fsyntax-only -verify=host %s
+
+// Device-side compilation for targets without 128-bit float/complex support 
(no errors expected).
+// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-is-target-device -x c -fsyntax-only -verify=device %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple 
x86_64-unknown-linux-gnu -fopenmp -fopenmp-is-target-device -x c -fsyntax-only 
-verify=device %s
+// RUN: %clang_cc1 -triple spirv64 -aux-triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-is-target-device -x c -fsyntax-only -verify=device %s
+
+// host-no-diagnostics
+// device-no-diagnostics
+typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits