This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 23b2f96c9d043806a30df86258238ae001241057
Author: p-szafonimateusz <p-szafonimate...@xiaomi.com>
AuthorDate: Fri May 24 09:17:08 2024 +0200

    libm/libm: disable optimization for sincos
    
    Disable sincos optimization for all functions in this file,
    otherwise gcc would generate infinite calls.
    Refer to gcc bug 46926.
    -fno-builtin-sin or -fno-builtin-cos can disable sincos optimization,
    but these two options do not work inside optimize pragma in-file.
    Thus we just enforce -O0 when compiling this file.
    
    Signed-off-by: p-szafonimateusz <p-szafonimate...@xiaomi.com>
---
 libs/libm/libm/lib_sincos.c  | 9 +++++++++
 libs/libm/libm/lib_sincosf.c | 9 +++++++++
 libs/libm/libm/lib_sincosl.c | 9 +++++++++
 3 files changed, 27 insertions(+)

diff --git a/libs/libm/libm/lib_sincos.c b/libs/libm/libm/lib_sincos.c
index fd00547edd..a3c3fc82ae 100644
--- a/libs/libm/libm/lib_sincos.c
+++ b/libs/libm/libm/lib_sincos.c
@@ -27,12 +27,21 @@
 
 #include <math.h>
 
+/* Disable sincos optimization for all functions in this file,
+ * otherwise gcc would generate infinite calls.
+ * Refer to gcc PR46926.
+ * -fno-builtin-sin or -fno-builtin-cos can disable sincos optimization,
+ * but these two options do not work inside optimize pragma in-file.
+ * Thus we just enforce -O0 when compiling this file.
+ */
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 #ifdef CONFIG_HAVE_DOUBLE
 
+nooptimiziation_function
 void sincos(double x, double *s, double *c)
 {
   *s = sin(x);
diff --git a/libs/libm/libm/lib_sincosf.c b/libs/libm/libm/lib_sincosf.c
index 311c36f6fb..064cb0e757 100644
--- a/libs/libm/libm/lib_sincosf.c
+++ b/libs/libm/libm/lib_sincosf.c
@@ -27,10 +27,19 @@
 
 #include <math.h>
 
+/* Disable sincos optimization for all functions in this file,
+ * otherwise gcc would generate infinite calls.
+ * Refer to gcc PR46926.
+ * -fno-builtin-sin or -fno-builtin-cos can disable sincos optimization,
+ * but these two options do not work inside optimize pragma in-file.
+ * Thus we just enforce -O0 when compiling this file.
+ */
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
+nooptimiziation_function
 void sincosf(float x, float *s, float *c)
 {
   *s = sinf(x);
diff --git a/libs/libm/libm/lib_sincosl.c b/libs/libm/libm/lib_sincosl.c
index 864e1fd67b..1512765c70 100644
--- a/libs/libm/libm/lib_sincosl.c
+++ b/libs/libm/libm/lib_sincosl.c
@@ -27,12 +27,21 @@
 
 #include <math.h>
 
+/* Disable sincos optimization for all functions in this file,
+ * otherwise gcc would generate infinite calls.
+ * Refer to gcc PR46926.
+ * -fno-builtin-sin or -fno-builtin-cos can disable sincos optimization,
+ * but these two options do not work inside optimize pragma in-file.
+ * Thus we just enforce -O0 when compiling this file.
+ */
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 #ifdef CONFIG_HAVE_LONG_DOUBLE
 
+nooptimiziation_function
 void sincosl(long double x, long double *s, long double *c)
 {
   *s = sinl(x);

Reply via email to