Bug: bindgen - clang error undeclared identifier '__builtin_isnanf(l)' when building with gcc
Status: RESOLVED
Priority: --
Resolution: INVALID
Created: 2020-01-23 18:02:12+00:00
Resolved: 2020-01-24 13:48:55+00:00

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0

Steps to reproduce:

I see this on Solaris with gcc build (clang doesn't work for me) after integration of:
Bug 1560664 - default to C++17 with optional gnu extensions; r=rstewart

```
22:15.00 error: failed to run custom build command for `style v0.0.1 (/scratch/FIREFOX/servo/components/style)`
22:15.00 Caused by:
22:15.00   process didn't exit successfully: `/scratch/FIREFOX/obj-x86_64-pc-solaris2.11/debug/build/style-b3369fd9f69dd0ab/build-script-build` (exit code: 101)
22:15.00 --- stdout
22:15.00 cargo:rerun-if-changed=build.rs
..
22:15.06 --- stderr
..
22:15.09 /usr/gcc/9/lib/gcc/x86_64-pc-solaris2.11/9.2.0/../../../../include/c++/9.2.0/tr1/special_function_util.h:126:14: error: use of undeclared identifier '__builtin_isnanf'
22:15.09 /usr/gcc/9/lib/gcc/x86_64-pc-solaris2.11/9.2.0/../../../../include/c++/9.2.0/tr1/special_function_util.h:130:14: error: use of undeclared identifier '__builtin_isnanl'
```

Problem seems to be that clang doesn't have ```__builtin_isnanf``` and ```__builtin_isnanl``` where gcc does. Seems that gcc internal headers gets into clang.

Clang seems to be called like this:

```
/usr/bin/clang -x c++ - -v -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla-config.h -DDEBUG=1 -DJS_DEBUG=1 -x c++ -fno-sized-deallocation -fno-aligned-new -DTRACING=1 -DIMPL_LIBXUL -DMOZILLA_INTERNAL_API -DRUST_BINDGEN -DOS_POSIX=1 -DOS_SOLARIS=1 -std=gnu++17 -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/nsStyleStruct.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/StyleAnimationValue.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/gfxFontConstants.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/gfxFontFeatures.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/nsStyleConsts.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/css/Loader.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/css/SheetLoadData.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/DeclarationBlock.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/dom/AnimationEffectBinding.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/dom/HTMLSlotElement.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/dom/KeyframeEffectBinding.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/dom/MediaList.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/dom/ShadowRoot.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/AnimationPropertySegment.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/ComputedTiming.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/ComputedTimingFunction.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/CORSMode.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/Keyframe.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/ServoElementSnapshot.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/ServoElementSnapshotTable.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/dom/Element.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/dom/ChildIterator.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/dom/NameSpaceConstants.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/LookAndFeel.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/GeckoBindings.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/ServoBindings.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/ComputedStyle.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/ServoTraversalStatistics.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/SizeOfState.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/nsCSSProps.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/nsContentUtils.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/nsNameSpaceManager.h -include /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/nsMediaFeatures.h -I/scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include
```

And the error is:
```
In file included from <built-in>:2:
In file included from /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/nsStyleStruct.h:18:
In file included from /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/StyleColorInlines.h:12:
In file included from /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/nsColor.h:13:
In file included from /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/nsCoord.h:10:
In file included from /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/FloatingPoint.h:15:
In file included from /scratch/FIREFOX/obj-x86_64-pc-solaris2.11/dist/include/mozilla/MathAlgorithms.h:15:
In file included from /usr/gcc/9/lib/gcc/x86_64-pc-solaris2.11/9.2.0/../../../../include/c++/9.2.0/cmath:1927:
In file included from /usr/gcc/9/lib/gcc/x86_64-pc-solaris2.11/9.2.0/../../../../include/c++/9.2.0/bits/specfun.h:49:
In file included from /usr/gcc/9/lib/gcc/x86_64-pc-solaris2.11/9.2.0/../../../../include/c++/9.2.0/tr1/gamma.tcc:49:
/usr/gcc/9/lib/gcc/x86_64-pc-solaris2.11/9.2.0/../../../../include/c++/9.2.0/tr1/special_function_util.h:126:14: error: use of undeclared identifier '__builtin_isnanf'; did you mean '__builtin_nanf'?
    { return __builtin_isnanf(__x); }
             ^
```

The only workaround I was able to find out was to modify gcc header like this:

```
--- /usr/gcc/9/include/c++/9.2.0/tr1/special_function_util.h
+++ /usr/gcc/9/include/c++/9.2.0/tr1/special_function_util.h
@@ -121,6 +121,7 @@
     inline bool __isnan(const _Tp __x)
     { return __builtin_isnan(__x); }

+#if !defined(__clang__)
     template<>
     inline bool __isnan<float>(float __x)
     { return __builtin_isnanf(__x); }
@@ -128,6 +129,7 @@
     template<>
     inline bool __isnan<long double>(long double __x)
     { return __builtin_isnanl(__x); }
+#endif

 #endif
   } // namespace __detail
```