]> granicus.if.org Git - clang/commitdiff
[Headers] Reapply: Add #include_next for tgmath.h on Darwin
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Thu, 16 Mar 2017 23:19:00 +0000 (23:19 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Thu, 16 Mar 2017 23:19:00 +0000 (23:19 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298013 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Headers/tgmath.h
test/Headers/Inputs/usr/include/math.h [new file with mode: 0644]
test/Headers/Inputs/usr/include/tgmath.h [new file with mode: 0644]
test/Headers/tgmath-darwin.c [new file with mode: 0644]

index 318e1185feee72db8a5bfa3eca64ef41b3ea06ce..34e26dcc05ec34a82541140027798efdddad321a 100644 (file)
  *
 \*===----------------------------------------------------------------------===*/
 
-#ifndef __TGMATH_H
-#define __TGMATH_H
+#ifndef __CLANG_TGMATH_H
+#define __CLANG_TGMATH_H
 
 /* C99 7.22 Type-generic math <tgmath.h>. */
 #include <math.h>
 
+/*
+ * Allow additional definitions and implementation-defined values on Apple
+ * platforms. This is done after #include <math.h> to avoid depcycle conflicts
+ * between libcxx and darwin in C++ modules builds.
+ */
+#if defined(__APPLE__) && __STDC_HOSTED__ && __has_include_next(<tgmath.h>)
+#  include_next <tgmath.h>
+#else
+
 /* C++ handles type genericity with overloading in math.h. */
 #ifndef __cplusplus
 #include <complex.h>
@@ -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/test/Headers/Inputs/usr/include/math.h b/test/Headers/Inputs/usr/include/math.h
new file mode 100644 (file)
index 0000000..4171d4f
--- /dev/null
@@ -0,0 +1 @@
+// math.h
diff --git a/test/Headers/Inputs/usr/include/tgmath.h b/test/Headers/Inputs/usr/include/tgmath.h
new file mode 100644 (file)
index 0000000..897962d
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef SYS_TGMATH_H
+#define SYS_TGMATH_H
+
+#endif /* SYS_TGMATH_H */
diff --git a/test/Headers/tgmath-darwin.c b/test/Headers/tgmath-darwin.c
new file mode 100644 (file)
index 0000000..916605a
--- /dev/null
@@ -0,0 +1,12 @@
+// REQUIRES: system-darwin
+// RUN: %clang -target x86_64-apple-darwin10 -fsyntax-only -std=c11 -isysroot %S/Inputs %s
+#include <tgmath.h>
+
+// 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