This is an archive of the discontinued LLVM Phabricator instance.

[test-suite] Fix FreeBSD and OpenBSD builds
ClosedPublic

Authored by dim on Mar 16 2023, 11:40 AM.

Details

Summary

With clang 16, SingleSource/Benchmarks/Misc/mandel.c fails to compile on
FreeBSD, complaining that hypot() is not declared:

SingleSource/Benchmarks/Misc/mandel.c:38:13: error: call to undeclared library function 'hypot' with type 'double (double, double)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        if (hypot(__real__ z, __imag__ z) >= ESCAPE)
            ^

The hypot() function is declared in <math.h>, not <complex.h>, so
use the former. This also applies to at least OpenBSD.

Diff Detail

Repository
rT test-suite

Event Timeline

dim created this revision.Mar 16 2023, 11:40 AM
dim requested review of this revision.Mar 16 2023, 11:40 AM
brad added a comment.Mar 17 2023, 12:08 AM

Looks like all three OS's have tgmath.h as well. Why not just make this

#if defined(__MINGW32__)
#include <complex.h>
#elif defined(__APPLE__)
#include <math.h>
#else
#include <tgmath.h>
#endif

For now, unless you can also build test on macOS?

dim added a comment.Mar 18 2023, 4:46 PM

Looks like all three OS's have tgmath.h as well. Why not just make this

#if defined(__MINGW32__)
#include <complex.h>
#elif defined(__APPLE__)
#include <math.h>
#else
#include <tgmath.h>
#endif

For now, unless you can also build test on macOS?

Yes, <tgmath.h> is also available on macOS, but it is unnecessary, even on Linux. Using just <math.h> should be sufficient, because the only math function used is hypot(3) which works on doubles by default. There is really no need to pull in the tricky macro machinery from tgmath here.

brad added a comment.Mar 18 2023, 4:49 PM

Yes, <tgmath.h> is also available on macOS, but it is unnecessary, even on Linux. Using just <math.h> should be sufficient, because the only math function used is hypot(3) which works on doubles by default. There is really no need to pull in the tricky macro machinery from tgmath here.

I was thinking about just using math.h as well but wasn't sure what OS's might be intended to be supported. I started looking through commit history and wasn't sure why tgmath.h was used in the first place.

dim updated this revision to Diff 506337.Mar 18 2023, 4:52 PM

Simplify.

dim updated this revision to Diff 506338.Mar 18 2023, 4:54 PM

Uploaded wrong commit.

brad accepted this revision.Mar 18 2023, 4:58 PM
This revision is now accepted and ready to land.Mar 18 2023, 4:58 PM
emaste accepted this revision.Mar 18 2023, 5:48 PM
This revision was automatically updated to reflect the committed changes.