This is an archive of the discontinued LLVM Phabricator instance.

Fix <cmath> compilation on FreeBSD
AbandonedPublic

Authored by dim on Mar 27 2016, 1:36 PM.

Details

Summary

On FreeBSD, a number of math.h functions are actually defined as macros,
such as signbit(), fpclassify() and others. Since libc++'s <cmath>
attempts to do using ::signbit;, using ::fpclassify;, and so on,
this results in compile errors:

libcxx/include/cmath:309:9: error: '::signbit' has not been declared
 using ::signbit;
         ^
libcxx/include/cmath:310:9: error: '::fpclassify' has not been declared
 using ::fpclassify;
         ^

Here is a patch to exclude signbit through isunordered, and also
abs, which we don't have in math.h.

(Actually, I'm not sure that ::abs should even be in here, since it is
a stdlib.h function? We don't have it in math.h, in any case.)

Diff Detail

Event Timeline

dim updated this revision to Diff 51747.Mar 27 2016, 1:36 PM
dim retitled this revision from to Fix <cmath> compilation on FreeBSD.
dim updated this object.
dim added reviewers: mclow.lists, EricWF, emaste.
dim added subscribers: cfe-commits, bdrewery.
dim added a comment.Mar 27 2016, 1:38 PM

Note that these compilation errors came up specifically because @bdrewery is doing cross-compilation of FreeBSD with recent versions of gcc. Apparently clang does not give the same errors on these undefined identifiers, but I'm not entirely sure why not...

EricWF edited edge metadata.Mar 30 2016, 3:00 PM
In D18501#384285, @dim wrote:

Note that these compilation errors came up specifically because @bdrewery is doing cross-compilation of FreeBSD with recent versions of gcc. Apparently clang does not give the same errors on these undefined identifiers, but I'm not entirely sure why not...

Can we find out why?

rsmith added a subscriber: rsmith.Mar 30 2016, 3:05 PM

libc++'s <math.h> converts the signbit macro into a function. If you're not seeing a function here, that suggests your include paths are messed up and the C library <math.h> is being found before libc++'s <math.h>.

dim abandoned this revision.Apr 2 2016, 6:39 AM

Yes, this was indeed the wrong include order. During the latter stages of FreeBSD's buildworld, the compiler is invoked with -nostdinc++, but /usr/include was put before the libc++ include directory, /usr/include/c++/v1. So as @rsmith remarked, the system's math.h was found before the one from libc++, causing the complaints about missing declarations.