llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Brad Smith (brad0)

<details>
<summary>Changes</summary>

For a real argument, the type-generic conj() returned the argument
converted to complex, giving x + 0i. C11 7.25p5 requires the complex
function to be called, so the result should be conj(x + 0i), which
is x - 0i. Call conjf/conj/conjl for the real overloads, the same as
cproj() already does.

Fixes #<!-- -->244639

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


2 Files Affected:

- (modified) clang/lib/Headers/tgmath.h (+3-3) 
- (added) clang/test/Headers/tgmath-conj.c (+20) 


``````````diff
diff --git a/clang/lib/Headers/tgmath.h b/clang/lib/Headers/tgmath.h
index 7acf18b9dd357..866dcca683410 100644
--- a/clang/lib/Headers/tgmath.h
+++ b/clang/lib/Headers/tgmath.h
@@ -1277,15 +1277,15 @@ static long double
 
 static float _Complex
     _TG_ATTRS
-    __tg_conj(float __x) {return __x;}
+    __tg_conj(float __x) {return conjf(__x);}
 
 static double _Complex
     _TG_ATTRS
-    __tg_conj(double __x) {return __x;}
+    __tg_conj(double __x) {return conj(__x);}
 
 static long double _Complex
     _TG_ATTRS
-    __tg_conj(long double __x) {return __x;}
+    __tg_conj(long double __x) {return conjl(__x);}
 
 static float _Complex
     _TG_ATTRS
diff --git a/clang/test/Headers/tgmath-conj.c b/clang/test/Headers/tgmath-conj.c
new file mode 100644
index 0000000000000..9e3573b1c9dc1
--- /dev/null
+++ b/clang/test/Headers/tgmath-conj.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -isystem %S/Inputs/include 
\
+// RUN:   -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+
+#include <tgmath.h>
+
+// C11 7.25p5: conj() of a real argument calls the complex function, so the
+// result is x - 0i, not x + 0i.
+
+float complex test_conj_float(float x) { return conj(x); }
+double complex test_conj_double(double x) { return conj(x); }
+long double complex test_conj_long_double(long double x) { return conj(x); }
+
+// CHECK-LABEL: define internal <2 x float> @_ZL9__tg_conjf(
+// CHECK:         store float -0.000000e+00, ptr {{%.*}}
+
+// CHECK-LABEL: define internal { double, double } @_ZL9__tg_conjd(
+// CHECK:         store double -0.000000e+00, ptr {{%.*}}
+
+// CHECK-LABEL: define internal { x86_fp80, x86_fp80 } @_ZL9__tg_conje(
+// CHECK:         store x86_fp80 -0.000000e+00, ptr {{%.*}}

``````````

</details>


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

Reply via email to