Issue 23867 - ImportC: undefined identifier `__builtin_isnan`
Summary: ImportC: undefined identifier `__builtin_isnan`
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: ImportC, pull
Depends on:
Blocks:
 
Reported: 2023-04-29 14:17 UTC by Lance Bachmeier
Modified: 2023-04-30 23:00 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lance Bachmeier 2023-04-29 14:17:00 UTC
The failing C code is

if (ISNAN(df) || df <= 0.0)	ML_WARN_return_NAN;

The ISNAN macro is defined with these lines

/* If isnan is a macro, as C99 specifies, the C++
   math header will undefine it. This happens on macOS */
# ifdef __cplusplus
  int R_isnancpp(double); /* in mlutils.c */
#  define ISNAN(x)     R_isnancpp(x)
# else
#  define ISNAN(x)     (isnan(x)!=0)
# endif

Looking at the gcc preprocessor output, this

if (ISNAN(df) || df <= 0.0)

expands to

if ((__builtin_isnan (Rf_df)!=0) || Rf_df <= 0.0)
Comment 1 Lance Bachmeier 2023-04-29 21:01:00 UTC
Adding #define __builtin_isnan isnan to the .c file fixes this.
Comment 2 Walter Bright 2023-04-30 05:20:20 UTC
https://github.com/dlang/dmd/pull/15147
Comment 3 Dlang Bot 2023-04-30 21:15:13 UTC
@bachmeil updated dlang/dmd pull request #15147 "Fix 23867 and 23869" fixing this issue:

- Fix issues 23867 and 23869 - define __builtin_isfinite and __builtin_isnan
  
  These GNU C builtins are referenced by macros such as:
  * ISNAN
  * R_FINITE

https://github.com/dlang/dmd/pull/15147
Comment 4 Dlang Bot 2023-04-30 23:00:07 UTC
dlang/dmd pull request #15147 "Fix 23867 and 23869" was merged into master:

- 812fd8a5fa5fb04c5d48e10a57905d5a39f39f13 by Lance Bachmeier:
  Fix issues 23867 and 23869 - define __builtin_isfinite and __builtin_isnan
  
  These GNU C builtins are referenced by macros such as:
  * ISNAN
  * R_FINITE

https://github.com/dlang/dmd/pull/15147