aboutsummaryrefslogtreecommitdiff
path: root/test/Frontend
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-04-16 19:08:41 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-04-16 19:08:41 +0000
commit596eea7cc26979c952a0b177d024787a99b299df (patch)
tree109fdb515aefd3f15bceb876d7d51e12fee4a940 /test/Frontend
parent051303ce09291dfbed537fa33b0d8a4d92c82b75 (diff)
rewrite-includes: Rewrite __has_include(_next) to get rid of a host dependency.
This broke e.g. compiling a crash report from a glibc system on Darwin. Sadly, the implementation had to game the lexer a lot as we're not using a real preprocessor here. It also doesn't handle special cases like arbitrary macros in __has_include, but since this macro isn't common outside of clang's headers we can get away with that. Fixes PR14422. Differential Revision: http://llvm-reviews.chandlerc.com/D594 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179616 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Frontend')
-rw-r--r--test/Frontend/Inputs/rewrite-includes8.h5
-rw-r--r--test/Frontend/rewrite-includes-invalid-hasinclude.c17
-rw-r--r--test/Frontend/rewrite-includes.c19
3 files changed, 41 insertions, 0 deletions
diff --git a/test/Frontend/Inputs/rewrite-includes8.h b/test/Frontend/Inputs/rewrite-includes8.h
new file mode 100644
index 0000000000..e827ad99cf
--- /dev/null
+++ b/test/Frontend/Inputs/rewrite-includes8.h
@@ -0,0 +1,5 @@
+#if __has_include_next(<rewrite-includes8.h>)
+#elif __has_include(<rewrite-includes8.hfail>)
+#endif
+#if !__has_include("rewrite-includes8.h")
+#endif
diff --git a/test/Frontend/rewrite-includes-invalid-hasinclude.c b/test/Frontend/rewrite-includes-invalid-hasinclude.c
new file mode 100644
index 0000000000..e32d6ad8a3
--- /dev/null
+++ b/test/Frontend/rewrite-includes-invalid-hasinclude.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -E -frewrite-includes -DFIRST -I %S/Inputs %s -o - | FileCheck -strict-whitespace %s
+
+#if __has_include bar.h
+#endif
+
+#if __has_include(bar.h)
+#endif
+
+#if __has_include(<bar.h)
+#endif
+
+// CHECK: #if __has_include bar.h
+// CHECK: #endif
+// CHECK: #if __has_include(bar.h)
+// CHECK: #endif
+// CHECK: #if __has_include(<bar.h)
+// CHECK: #endif
diff --git a/test/Frontend/rewrite-includes.c b/test/Frontend/rewrite-includes.c
index 546a2c44af..bf330a60a3 100644
--- a/test/Frontend/rewrite-includes.c
+++ b/test/Frontend/rewrite-includes.c
@@ -18,6 +18,7 @@ A(1,2)
continues */
#include "rewrite-includes7.h"
#include "rewrite-includes7.h"
+#include "rewrite-includes8.h"
// ENDCOMPARE
// CHECK: {{^}}// STARTCOMPARE{{$}}
// CHECK-NEXT: {{^}}#define A(a,b) a ## b{{$}}
@@ -88,6 +89,16 @@ A(1,2)
// CHECK-NEXT: {{^}}#include "rewrite-includes7.h"{{$}}
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
// CHECK-NEXT: {{^}}# 21 "{{.*}}rewrite-includes.c"{{$}}
+// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}#include "rewrite-includes8.h"{{$}}
+// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}# 1 "{{.*[/\\]Inputs[/\\]}}rewrite-includes8.h" 1{{$}}
+// CHECK-NEXT: {{^}}#if (1)/*__has_include_next(<rewrite-includes8.h>)*/{{$}}
+// CHECK-NEXT: {{^}}#elif (0)/*__has_include(<rewrite-includes8.hfail>)*/{{$}}
+// CHECK-NEXT: {{^}}#endif{{$}}
+// CHECK-NEXT: {{^}}#if !(1)/*__has_include("rewrite-includes8.h")*/{{$}}
+// CHECK-NEXT: {{^}}#endif{{$}}
+// CHECK-NEXT: {{^}}# 22 "{{.*}}rewrite-includes.c" 2{{$}}
// CHECK-NEXT: {{^}}// ENDCOMPARE{{$}}
// CHECKNL: {{^}}// STARTCOMPARE{{$}}
@@ -142,4 +153,12 @@ A(1,2)
// CHECKNL-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
// CHECKNL-NEXT: {{^}}#include "rewrite-includes7.h"{{$}}
// CHECKNL-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
+// CHECKNL-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
+// CHECKNL-NEXT: {{^}}#include "rewrite-includes8.h"{{$}}
+// CHECKNL-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
+// CHECKNL-NEXT: {{^}}#if (1)/*__has_include_next(<rewrite-includes8.h>)*/{{$}}
+// CHECKNL-NEXT: {{^}}#elif (0)/*__has_include(<rewrite-includes8.hfail>)*/{{$}}
+// CHECKNL-NEXT: {{^}}#endif{{$}}
+// CHECKNL-NEXT: {{^}}#if !(1)/*__has_include("rewrite-includes8.h")*/{{$}}
+// CHECKNL-NEXT: {{^}}#endif{{$}}
// CHECKNL-NEXT: {{^}}// ENDCOMPARE{{$}}