Skip to contentSkip to conversation

add __builtin functions for isinf_sign, isfinite and isnan

PATCH Superseded Logan Gunthorpe 2 participants 2 messages Nov 16, 2017 Sparse checker

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add __builtin functions for isinf_sign, isfinite and isnan

These bultins are defined by in gcc since 4.4. They are also now used by the isinf, isfinite and isnan macros. So using them with a newer gcc causes 'undefined identifier' errors.

Add the builtin definitions and some validation checks for these functions.

---
 lib.c                    | 3 +++
 validation/builtin_inf.c | 8 ++++++++
 2 files changed, 11 insertions(+)
lib.c +3 -0
index 4602cf8..cc740e9 100644
@@ -1105,6 +1105,9 @@ void declare_builtin_functions(void)
 	add_pre_buffer("extern double __builtin_nan(const char *);\n");
 	add_pre_buffer("extern float __builtin_nanf(const char *);\n");
 	add_pre_buffer("extern long double __builtin_nanl(const char *);\n");
+	add_pre_buffer("extern int __builtin_isinf_sign(float);\n");
+	add_pre_buffer("extern int __builtin_isfinite(float);\n");
+	add_pre_buffer("extern int __builtin_isnan(float);\n");
 
 	/* And some __FORTIFY_SOURCE ones.. */
 	add_pre_buffer ("extern __SIZE_TYPE__ __builtin_object_size(const void *, int);\n");
validation/builtin_inf.c +8 -0
index 48546e4..0855ab0 100644
@@ -7,6 +7,14 @@ static long double li = __builtin_infl();
 static double dn = __builtin_nan("");
 static float fn = __builtin_nanf("");
 static long double ln = __builtin_nanl("");
+static int inf = __builtin_isinf_sign(0.0);
+static int fin = __builtin_isfinite(0.0);
+static int nan = __builtin_isnan(0.0);
+
+#include <math.h>
+static int inf2 = isinf(0.0);
+static int fin2 = isfinite(0.0);
+static int nan2 = isnan(0.0);
 
 /*
  * check-name: __builtin INFINITY / nan()
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 6 lines · Logan Gunthorpe

These bultins are defined by in gcc since 4.4. They are also now used by the isinf, isfinite and isnan macros. So using them with a newer gcc causes 'undefined identifier' errors.

Add the builtin definitions and some validation checks for these functions.

Thanks for the patch.

validation/builtin_inf.c static long double li = __builtin_infl(); · line 14

Quoted 13 lines
validation/builtin_inf.c +5 -0
index 48546e4..0855ab0 100644
@@ -7,6 +7,14 @@ static long double li = __builtin_infl();
 static double dn = __builtin_nan("");
 static float fn = __builtin_nanf("");
 static long double ln = __builtin_nanl("");
+static int inf = __builtin_isinf_sign(0.0);
+static int fin = __builtin_isfinite(0.0);
+static int nan = __builtin_isnan(0.0);
+
+#include <math.h>

Can you remove the <math.h>?

For the validation test, it would be best to not depend on system header file. You can use sparse -E to dig out the related function call after the pre-process.

Other than that, it looks good.

I want to apply with the math.h removed.

Chris