Skip to content

Conversation

c8ef
Copy link
Contributor

@c8ef c8ef commented Sep 5, 2025

@llvmbot llvmbot added the libc label Sep 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2025

@llvm/pr-subscribers-libc

Author: Connector Switch (c8ef)

Changes

Fixes #156344 (comment)


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

1 Files Affected:

  • (modified) libc/include/llvm-libc-macros/complex-macros.h (+12-7)
diff --git a/libc/include/llvm-libc-macros/complex-macros.h b/libc/include/llvm-libc-macros/complex-macros.h
index d98c6fdb306c8..5ea272a2e7482 100644
--- a/libc/include/llvm-libc-macros/complex-macros.h
+++ b/libc/include/llvm-libc-macros/complex-macros.h
@@ -22,21 +22,26 @@
 
 // TODO: Add imaginary macros once GCC or Clang support _Imaginary builtin-type.
 
-#define CMPLX(x, y) __builtin_complex((double)(x), (double)(y))
-#define CMPLXF(x, y) __builtin_complex((float)(x), (float)(y))
-#define CMPLXL(x, y) __builtin_complex((long double)(x), (long double)(y))
+#if !defined(__clang__) || (__clang_major__ >= 12)
+#define __CMPLX(r, i, t) (__builtin_complex((t)(r), (t)(i)))
+#else
+#define __CMPLX(r, i, t) ((_Complex t){(t)(r), (t)(i)})
+#endif
+
+#define CMPLX(r, i) __CMPLX(r, i, double)
+#define CMPLXF(r, i) __CMPLX(r, i, float)
+#define CMPLXL(r, i) __CMPLX(r, i, long double)
 
 #ifdef LIBC_TYPES_HAS_CFLOAT16
 #if !defined(__clang__) || (__clang_major__ >= 22 && __clang_minor__ > 0)
-#define CMPLXF16(x, y) __builtin_complex((_Float16)(x), (_Float16)(y))
+#define CMPLXF16(r, i) __CMPLX(r, i, _Float16)
 #else
-#define CMPLXF16(x, y)                                                         \
-  ((complex _Float16)(__builtin_complex((float)(x), (float)(y))))
+#define CMPLXF16(r, i) ((complex _Float16)(__CMPLX(r, i, float)))
 #endif
 #endif // LIBC_TYPES_HAS_CFLOAT16
 
 #ifdef LIBC_TYPES_HAS_CFLOAT128
-#define CMPLXF128(x, y) __builtin_complex((float128)(x), (float128)(y))
+#define CMPLXF128(r, i) __CMPLX(r, i, float128)
 #endif // LIBC_TYPES_HAS_CFLOAT128
 
 #endif // __STDC_NO_COMPLEX__

@c8ef c8ef requested review from jhuber6 and lntue September 5, 2025 12:53
@lntue lntue merged commit caf5fb1 into llvm:main Sep 5, 2025
23 of 24 checks passed
@c8ef c8ef deleted the clang11 branch September 5, 2025 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants