summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorKristina Brooks <notstina@gmail.com>2019-05-16 00:52:41 +0000
committerKristina Brooks <notstina@gmail.com>2019-05-16 00:52:41 +0000
commit3acc1d1be329d9f6e363c34c455fec86e0c4935c (patch)
tree69a501f5b6ce0545070ad7128315093288a6b158 /clang/test
parente7ab59eda98094183cd4d75f5edde9e07e27072b (diff)
downloadbcm5719-llvm-3acc1d1be329d9f6e363c34c455fec86e0c4935c.tar.gz
bcm5719-llvm-3acc1d1be329d9f6e363c34c455fec86e0c4935c.zip
[Clang][PP] Add the __FILE_NAME__ builtin macro.
This patch adds the `__FILE_NAME__` macro that expands to the last component of the path, similar to `__FILE__` except with a guarantee that only the last path component (without the separator) will be rendered. I intend to follow through with discussion of this with WG14 as a potential inclusion in the C standard or failing that, try to discuss this with GCC developers since this extension is desired by GCC and Clang users/developers alike. Differential Revision: https://reviews.llvm.org/D61756 llvm-svn: 360833
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h6
-rw-r--r--clang/test/Preprocessor/Inputs/include-subdir/h1
-rw-r--r--clang/test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h1
-rw-r--r--clang/test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h1
-rw-r--r--clang/test/Preprocessor/file_name_macro.c44
5 files changed, 53 insertions, 0 deletions
diff --git a/clang/test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h b/clang/test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
new file mode 100644
index 00000000000..e974799b1f6
--- /dev/null
+++ b/clang/test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
@@ -0,0 +1,6 @@
+3: __FILE_NAME__
+4: "file_name_macro_include.h"
+#ifdef MS
+// Should be the same even when included with backslash.
+5: __FILE_NAME__
+#endif
diff --git a/clang/test/Preprocessor/Inputs/include-subdir/h b/clang/test/Preprocessor/Inputs/include-subdir/h
new file mode 100644
index 00000000000..b9839684e89
--- /dev/null
+++ b/clang/test/Preprocessor/Inputs/include-subdir/h
@@ -0,0 +1 @@
+6: __FILE_NAME__
diff --git a/clang/test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h b/clang/test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
new file mode 100644
index 00000000000..f793be596c7
--- /dev/null
+++ b/clang/test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
@@ -0,0 +1 @@
+7: __FILE_NAME__
diff --git a/clang/test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h b/clang/test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
new file mode 100644
index 00000000000..66860acc64d
--- /dev/null
+++ b/clang/test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
@@ -0,0 +1 @@
+8: __FILE_NAME__
diff --git a/clang/test/Preprocessor/file_name_macro.c b/clang/test/Preprocessor/file_name_macro.c
new file mode 100644
index 00000000000..9dc9dc5684c
--- /dev/null
+++ b/clang/test/Preprocessor/file_name_macro.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -E %s -I%S/Inputs | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -fms-compatibility -DMS -E %s -I%S/Inputs | FileCheck -check-prefix=CHECK-MS -strict-whitespace %s
+// RUN: %clang_cc1 -E %s -I%S/Inputs -DBADINC -verify
+
+#ifdef BADINC
+
+// Paranoia.
+
+__FILE_NAME__
+#include <include-subdir/> // expected-error {{file not found}}
+__FILE_NAME__
+
+#else
+
+// Reference.
+1: "file_name_macro.c"
+
+// Ensure it expands correctly for this file.
+2: __FILE_NAME__
+
+// CHECK: {{^}}1: "file_name_macro.c"
+// CHECK: {{^}}2: "file_name_macro.c"
+
+// Test if inclusion works right.
+#ifdef MS
+#include <include-subdir\file_name_macro_include.h>
+// MS compatibility allows for mixed separators in paths.
+#include <include-subdir/subdir1\hdr1.h>
+#include <include-subdir\subdir1/hdr2.h>
+#else
+#include <include-subdir/file_name_macro_include.h>
+#endif
+
+#include <include-subdir/h>
+
+// CHECK: {{^}}3: "file_name_macro_include.h"
+// CHECK: {{^}}4: "file_name_macro_include.h"
+// CHECK-NOT: {{^}}5: "file_name_macro_include.h"
+// CHECK-MS: {{^}}5: "file_name_macro_include.h"
+// CHECK: {{^}}6: "h"
+// CHECK-MS: {{^}}7: "hdr1.h"
+// CHECK-MS: {{^}}8: "hdr2.h"
+
+#endif
OpenPOWER on IntegriCloud