From ae1249e4f2103b958ad8e4c278ca8b8df2710e86 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Thu, 16 Mar 2017 23:19:00 +0000 Subject: [PATCH] [Headers] Reapply: Add #include_next for tgmath.h on Darwin Reapply r289181 but rename the include guard to avoid conflict with the one from Darwin. Allow darwin to provide additional definitions and implementation specifc values for tgmath.h on Apple platforms. rdar://problem/19019845 llvm-svn: 298013 --- clang/lib/Headers/tgmath.h | 16 +++++++++++++--- clang/test/Headers/Inputs/usr/include/math.h | 1 + clang/test/Headers/Inputs/usr/include/tgmath.h | 4 ++++ clang/test/Headers/tgmath-darwin.c | 12 ++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 clang/test/Headers/Inputs/usr/include/math.h create mode 100644 clang/test/Headers/Inputs/usr/include/tgmath.h create mode 100644 clang/test/Headers/tgmath-darwin.c diff --git a/clang/lib/Headers/tgmath.h b/clang/lib/Headers/tgmath.h index 318e1185feee..34e26dcc05ec 100644 --- a/clang/lib/Headers/tgmath.h +++ b/clang/lib/Headers/tgmath.h @@ -22,12 +22,21 @@ * \*===----------------------------------------------------------------------===*/ -#ifndef __TGMATH_H -#define __TGMATH_H +#ifndef __CLANG_TGMATH_H +#define __CLANG_TGMATH_H /* C99 7.22 Type-generic math . */ #include +/* + * Allow additional definitions and implementation-defined values on Apple + * platforms. This is done after #include to avoid depcycle conflicts + * between libcxx and darwin in C++ modules builds. + */ +#if defined(__APPLE__) && __STDC_HOSTED__ && __has_include_next() +# include_next +#else + /* C++ handles type genericity with overloading in math.h. */ #ifndef __cplusplus #include @@ -1371,4 +1380,5 @@ static long double #undef _TG_ATTRS #endif /* __cplusplus */ -#endif /* __TGMATH_H */ +#endif /* __has_include_next */ +#endif /* __CLANG_TGMATH_H */ diff --git a/clang/test/Headers/Inputs/usr/include/math.h b/clang/test/Headers/Inputs/usr/include/math.h new file mode 100644 index 000000000000..4171d4febc63 --- /dev/null +++ b/clang/test/Headers/Inputs/usr/include/math.h @@ -0,0 +1 @@ +// math.h diff --git a/clang/test/Headers/Inputs/usr/include/tgmath.h b/clang/test/Headers/Inputs/usr/include/tgmath.h new file mode 100644 index 000000000000..897962d9e16e --- /dev/null +++ b/clang/test/Headers/Inputs/usr/include/tgmath.h @@ -0,0 +1,4 @@ +#ifndef SYS_TGMATH_H +#define SYS_TGMATH_H + +#endif /* SYS_TGMATH_H */ diff --git a/clang/test/Headers/tgmath-darwin.c b/clang/test/Headers/tgmath-darwin.c new file mode 100644 index 000000000000..916605a718ab --- /dev/null +++ b/clang/test/Headers/tgmath-darwin.c @@ -0,0 +1,12 @@ +// REQUIRES: system-darwin +// RUN: %clang -target x86_64-apple-darwin10 -fsyntax-only -std=c11 -isysroot %S/Inputs %s +#include + +// Test the #include_next of tgmath.h works on Darwin. +#ifndef SYS_TGMATH_H + #error "SYS_TGMATH_H not defined" +#endif + +#ifndef __CLANG_TGMATH_H + #error "__CLANG_TGMATH_H not defined" +#endif