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

via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 6 07:08:49 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Alex Duran (adurang)

<details>
<summary>Changes</summary>

 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 0000000000000..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__)));

``````````

</details>


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


More information about the cfe-commits mailing list