aboutsummaryrefslogtreecommitdiff
path: root/test/Preprocessor
diff options
context:
space:
mode:
Diffstat (limited to 'test/Preprocessor')
-rw-r--r--test/Preprocessor/_Pragma-dependency.c7
-rw-r--r--test/Preprocessor/_Pragma-location.c4
-rw-r--r--test/Preprocessor/_Pragma-physloc.c6
-rw-r--r--test/Preprocessor/_Pragma-poison.c8
-rw-r--r--test/Preprocessor/_Pragma-syshdr.c4
-rw-r--r--test/Preprocessor/_Pragma-syshdr2.c5
-rw-r--r--test/Preprocessor/builtin_line.c4
-rw-r--r--test/Preprocessor/c99-6_10_3_3_p4.c6
-rw-r--r--test/Preprocessor/c99-6_10_3_4_p5.c29
-rw-r--r--test/Preprocessor/c99-6_10_3_4_p6.c24
-rw-r--r--test/Preprocessor/c99-6_10_3_4_p7.c9
-rw-r--r--test/Preprocessor/c99-6_10_3_4_p9.c16
-rw-r--r--test/Preprocessor/comment_save.c7
-rw-r--r--test/Preprocessor/comment_save_if.c6
-rw-r--r--test/Preprocessor/comment_save_macro.c8
-rw-r--r--test/Preprocessor/cxx_and.cpp17
-rw-r--r--test/Preprocessor/cxx_bitand.cpp16
-rw-r--r--test/Preprocessor/cxx_bitor.cpp18
-rw-r--r--test/Preprocessor/cxx_compl.cpp16
-rw-r--r--test/Preprocessor/cxx_not.cpp15
-rw-r--r--test/Preprocessor/cxx_not_eq.cpp16
-rw-r--r--test/Preprocessor/cxx_oper_keyword.cpp7
-rw-r--r--test/Preprocessor/cxx_oper_spelling.cpp11
-rw-r--r--test/Preprocessor/cxx_or.cpp17
-rw-r--r--test/Preprocessor/cxx_true.cpp13
-rw-r--r--test/Preprocessor/cxx_xor.cpp18
-rw-r--r--test/Preprocessor/define_other_target.c27
-rw-r--r--test/Preprocessor/define_target.c27
-rw-r--r--test/Preprocessor/disabled-cond-diags.c10
-rw-r--r--test/Preprocessor/expr_liveness.c32
-rw-r--r--test/Preprocessor/expr_usual_conversions.c8
-rw-r--r--test/Preprocessor/file_to_include.h3
-rw-r--r--test/Preprocessor/hash_line.c8
-rw-r--r--test/Preprocessor/hash_space.c6
-rw-r--r--test/Preprocessor/includeexpand.c12
-rw-r--r--test/Preprocessor/indent_macro.c6
-rw-r--r--test/Preprocessor/macro_arg_keyword.c6
-rw-r--r--test/Preprocessor/macro_defined.c6
-rw-r--r--test/Preprocessor/macro_disable.c13
-rw-r--r--test/Preprocessor/macro_disable2.c8
-rw-r--r--test/Preprocessor/macro_disable3.c8
-rw-r--r--test/Preprocessor/macro_expand.c7
-rw-r--r--test/Preprocessor/macro_expandloc.c6
-rw-r--r--test/Preprocessor/macro_expandloc2.c6
-rw-r--r--test/Preprocessor/macro_fn_comma_swallow.c16
-rw-r--r--test/Preprocessor/macro_fn_disable_expand.c11
-rw-r--r--test/Preprocessor/macro_fn_lparen_scan.c27
-rw-r--r--test/Preprocessor/macro_fn_lparen_scan2.c7
-rw-r--r--test/Preprocessor/macro_fn_placemarker.c5
-rw-r--r--test/Preprocessor/macro_fn_preexpand.c12
-rw-r--r--test/Preprocessor/macro_fn_varargs_iso.c11
-rw-r--r--test/Preprocessor/macro_fn_varargs_named.c7
-rw-r--r--test/Preprocessor/macro_not_define.c9
-rw-r--r--test/Preprocessor/macro_paste_bad.c5
-rw-r--r--test/Preprocessor/macro_paste_bcpl_comment.c5
-rw-r--r--test/Preprocessor/macro_paste_c_block_comment.c7
-rw-r--r--test/Preprocessor/macro_paste_empty.c13
-rw-r--r--test/Preprocessor/macro_paste_hard.c17
-rw-r--r--test/Preprocessor/macro_paste_hashhash.c7
-rw-r--r--test/Preprocessor/macro_paste_none.c6
-rw-r--r--test/Preprocessor/macro_paste_simple.c3
-rw-r--r--test/Preprocessor/macro_paste_spacing.c7
-rw-r--r--test/Preprocessor/macro_rescan.c9
-rw-r--r--test/Preprocessor/macro_rescan2.c15
-rw-r--r--test/Preprocessor/macro_rescan_varargs.c10
-rw-r--r--test/Preprocessor/macro_rparen_scan.c8
-rw-r--r--test/Preprocessor/macro_rparen_scan2.c8
-rw-r--r--test/Preprocessor/macro_space.c5
-rw-r--r--test/Preprocessor/output_paste_avoid.c12
-rw-r--r--test/Preprocessor/paste_bad.c17
-rw-r--r--test/Preprocessor/poison.c4
-rw-r--r--test/Preprocessor/poison_expansion.c9
-rw-r--r--test/Preprocessor/pragma_unknown.c6
-rw-r--r--test/Preprocessor/stringize_misc.c26
-rw-r--r--test/Preprocessor/stringize_space.c4
75 files changed, 814 insertions, 0 deletions
diff --git a/test/Preprocessor/_Pragma-dependency.c b/test/Preprocessor/_Pragma-dependency.c
new file mode 100644
index 0000000000..f7d7efe41b
--- /dev/null
+++ b/test/Preprocessor/_Pragma-dependency.c
@@ -0,0 +1,7 @@
+// RUN: clang %s -E 2>&1 | grep 'DO_PRAGMA (STR' &&
+// RUN: clang %s -E 2>&1 | grep '7:12'
+
+#define DO_PRAGMA _Pragma
+#define STR "GCC dependency \"parse.y\"")
+// Test that this line is printed by caret diagnostics.
+DO_PRAGMA (STR
diff --git a/test/Preprocessor/_Pragma-location.c b/test/Preprocessor/_Pragma-location.c
new file mode 100644
index 0000000000..152e71ac13
--- /dev/null
+++ b/test/Preprocessor/_Pragma-location.c
@@ -0,0 +1,4 @@
+// RUN: clang %s -E | not grep 'scratch space'
+
+#define push _Pragma ("pack(push)")
+push
diff --git a/test/Preprocessor/_Pragma-physloc.c b/test/Preprocessor/_Pragma-physloc.c
new file mode 100644
index 0000000000..b8f5499c7a
--- /dev/null
+++ b/test/Preprocessor/_Pragma-physloc.c
@@ -0,0 +1,6 @@
+// RUN: clang %s -E | grep '#pragma x y z' &&
+// RUN: clang %s -E | grep '#pragma a b c'
+
+_Pragma("x y z")
+_Pragma("a b c")
+
diff --git a/test/Preprocessor/_Pragma-poison.c b/test/Preprocessor/_Pragma-poison.c
new file mode 100644
index 0000000000..82a7fbecc2
--- /dev/null
+++ b/test/Preprocessor/_Pragma-poison.c
@@ -0,0 +1,8 @@
+// RUN: clang -Eonly %s 2>&1 | grep error | wc -l | grep 1 &&
+// RUN: clang -Eonly %s 2>&1 | grep 7:4 | wc -l | grep 1
+
+#define BAR _Pragma ("GCC poison XYZW") XYZW /*NO ERROR*/
+XYZW // NO ERROR
+BAR
+ XYZW // ERROR
+
diff --git a/test/Preprocessor/_Pragma-syshdr.c b/test/Preprocessor/_Pragma-syshdr.c
new file mode 100644
index 0000000000..4d2d29e023
--- /dev/null
+++ b/test/Preprocessor/_Pragma-syshdr.c
@@ -0,0 +1,4 @@
+// RUN: clang %s -E 2>&1 | grep 'system_header ignored in main file'
+
+_Pragma ("GCC system_header")
+
diff --git a/test/Preprocessor/_Pragma-syshdr2.c b/test/Preprocessor/_Pragma-syshdr2.c
new file mode 100644
index 0000000000..190e5a7a30
--- /dev/null
+++ b/test/Preprocessor/_Pragma-syshdr2.c
@@ -0,0 +1,5 @@
+// RUN: clang -E %s 2>&1 | grep 'file not found'
+
+#define DO_PRAGMA _Pragma
+DO_PRAGMA ("GCC dependency \"blahblabh\"")
+
diff --git a/test/Preprocessor/builtin_line.c b/test/Preprocessor/builtin_line.c
new file mode 100644
index 0000000000..c9ce558c1a
--- /dev/null
+++ b/test/Preprocessor/builtin_line.c
@@ -0,0 +1,4 @@
+// RUN: clang %s -E | grep "^ 4"
+#define FOO __LINE__
+
+ FOO
diff --git a/test/Preprocessor/c99-6_10_3_3_p4.c b/test/Preprocessor/c99-6_10_3_3_p4.c
new file mode 100644
index 0000000000..13d5661e36
--- /dev/null
+++ b/test/Preprocessor/c99-6_10_3_3_p4.c
@@ -0,0 +1,6 @@
+// RUN: clang -E %s | grep -F 'char p[] = "x ## y";'
+#define hash_hash # ## #
+#define mkstr(a) # a
+#define in_between(a) mkstr(a)
+#define join(c, d) in_between(c hash_hash d)
+char p[] = join(x, y);
diff --git a/test/Preprocessor/c99-6_10_3_4_p5.c b/test/Preprocessor/c99-6_10_3_4_p5.c
new file mode 100644
index 0000000000..fa5f7358b9
--- /dev/null
+++ b/test/Preprocessor/c99-6_10_3_4_p5.c
@@ -0,0 +1,29 @@
+// Example from C99 6.10.3.4p5
+
+// RUN: clang -E %s | grep -F 'f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);' &&
+// RUN: clang -E %s | grep -F 'f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);' &&
+// RUN: clang -E %s | grep -F 'int i[] = { 1, 23, 4, 5, };' &&
+// RUN: clang -E %s | grep -F 'char c[2][6] = { "hello", "" };'
+
+
+#define x 3
+#define f(a) f(x * (a))
+#undef x
+#define x 2
+#define g f
+#define z z[0]
+#define h g(~
+#define m(a) a(w)
+#define w 0,1
+#define t(a) a
+#define p() int
+#define q(x) x
+#define r(x,y) x ## y
+#define str(x) # x
+ f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
+ g(x+(3,4)-w) | h 5) & m
+(f)^m(m);
+p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
+char c[2][6] = { str(hello), str() };
+
+
diff --git a/test/Preprocessor/c99-6_10_3_4_p6.c b/test/Preprocessor/c99-6_10_3_4_p6.c
new file mode 100644
index 0000000000..ce7990a4cf
--- /dev/null
+++ b/test/Preprocessor/c99-6_10_3_4_p6.c
@@ -0,0 +1,24 @@
+// Example from C99 6.10.3.4p6
+
+// RUN: clang -E %s | grep -F 'printf("x" "1" "= %d, x" "2" "= s" x1, x2);' &&
+// RUN: clang -E %s | grep 'fputs("strncmp(\\"abc\\\\0d\\" \\"abc\\", .\\\\4.) == 0" ": @\\n", s);' &&
+// RUN: clang -E %s | grep -F 'include "vers2.h"' &&
+// RUN: clang -E %s | grep -F '"hello";' &&
+// RUN: clang -E %s | grep -F '"hello" ", world"'
+
+#define str(s) # s
+#define xstr(s) str(s)
+#define debug(s, t) printf("x" # s "= %d, x" # t "= s" \
+ x ## s, x ## t)
+#define INCFILE(n) vers ## n
+#define glue(a, b) a ## b
+#define xglue(a, b) glue(a, b)
+#define HIGHLOW "hello"
+#define LOW LOW ", world"
+debug(1, 2);
+fputs(str(strncmp("abc\0d" "abc", '\4') // this goes away
+ == 0) str(: @\n), s);
+include xstr(INCFILE(2).h)
+glue(HIGH, LOW);
+xglue(HIGH, LOW)
+
diff --git a/test/Preprocessor/c99-6_10_3_4_p7.c b/test/Preprocessor/c99-6_10_3_4_p7.c
new file mode 100644
index 0000000000..88957dfb67
--- /dev/null
+++ b/test/Preprocessor/c99-6_10_3_4_p7.c
@@ -0,0 +1,9 @@
+// Example from C99 6.10.3.4p7
+
+// RUN: clang -E %s | grep -F 'int j[] = { 123, 45, 67, 89,' &&
+// RUN: clang -E %s | grep -F '10, 11, 12, };'
+
+#define t(x,y,z) x ## y ## z
+int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
+t(10,,), t(,11,), t(,,12), t(,,) };
+
diff --git a/test/Preprocessor/c99-6_10_3_4_p9.c b/test/Preprocessor/c99-6_10_3_4_p9.c
new file mode 100644
index 0000000000..08b4637e0e
--- /dev/null
+++ b/test/Preprocessor/c99-6_10_3_4_p9.c
@@ -0,0 +1,16 @@
+// Example from C99 6.10.3.4p9
+
+// RUN: clang -E %s | grep -F 'fprintf(stderr, "Flag");' &&
+// RUN: clang -E %s | grep -F 'fprintf(stderr, "X = %d\n", x);' &&
+// RUN: clang -E %s | grep -F 'puts("The first, second, and third items.");' &&
+// RUN: clang -E %s | grep -F '((x>y)?puts("x>y"): printf("x is %d but y is %d", x, y));'
+
+#define debug(...) fprintf(stderr, __VA_ARGS__)
+#define showlist(...) puts(#__VA_ARGS__)
+#define report(test, ...) ((test)?puts(#test):\
+ printf(__VA_ARGS__))
+debug("Flag");
+debug("X = %d\n", x);
+showlist(The first, second, and third items.);
+report(x>y, "x is %d but y is %d", x, y);
+
diff --git a/test/Preprocessor/comment_save.c b/test/Preprocessor/comment_save.c
new file mode 100644
index 0000000000..1a3bd96efb
--- /dev/null
+++ b/test/Preprocessor/comment_save.c
@@ -0,0 +1,7 @@
+// RUN: clang -E -C %s | grep '^// foo$' &&
+// RUN: clang -E -C %s | grep -F '^/* bar */$'
+
+// foo
+/* bar */
+
+
diff --git a/test/Preprocessor/comment_save_if.c b/test/Preprocessor/comment_save_if.c
new file mode 100644
index 0000000000..ce7b4c45b1
--- /dev/null
+++ b/test/Preprocessor/comment_save_if.c
@@ -0,0 +1,6 @@
+// RUN: clang %s -E -CC -pedantic 2>&1 | grep -v '^/' | not grep warning
+
+#if 1 /*bar */
+
+#endif /*foo*/
+
diff --git a/test/Preprocessor/comment_save_macro.c b/test/Preprocessor/comment_save_macro.c
new file mode 100644
index 0000000000..635a6fd406
--- /dev/null
+++ b/test/Preprocessor/comment_save_macro.c
@@ -0,0 +1,8 @@
+// RUN: clang -E -C %s | grep '^boo bork bar // zot$' &&
+// RUN: clang -E -CC %s | grep -F '^boo bork /* blah*/ bar // zot$' &&
+// RUN: clang -E %s | grep '^boo bork bar$'
+
+
+#define FOO bork // blah
+boo FOO bar // zot
+
diff --git a/test/Preprocessor/cxx_and.cpp b/test/Preprocessor/cxx_and.cpp
new file mode 100644
index 0000000000..b6bd00e529
--- /dev/null
+++ b/test/Preprocessor/cxx_and.cpp
@@ -0,0 +1,17 @@
+// RUN: clang -DA -DB -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -DB -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if defined(A) and defined(B)
+#define X 37
+#else
+#define X 927
+#endif
+
+#if defined(A) && defined(B)
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
diff --git a/test/Preprocessor/cxx_bitand.cpp b/test/Preprocessor/cxx_bitand.cpp
new file mode 100644
index 0000000000..ecc52e89ab
--- /dev/null
+++ b/test/Preprocessor/cxx_bitand.cpp
@@ -0,0 +1,16 @@
+// RUN: clang -DA=1 -DB=2 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -DA=1 -DB=1 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if A bitand B
+#define X 37
+#else
+#define X 927
+#endif
+
+#if A & B
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
diff --git a/test/Preprocessor/cxx_bitor.cpp b/test/Preprocessor/cxx_bitor.cpp
new file mode 100644
index 0000000000..36c44523df
--- /dev/null
+++ b/test/Preprocessor/cxx_bitor.cpp
@@ -0,0 +1,18 @@
+// RUN: clang -DA=1 -DB=1 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA=0 -DB=1 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA=1 -DB=0 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA=0 -DB=0 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if A bitor B
+#define X 37
+#else
+#define X 927
+#endif
+
+#if A | B
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
diff --git a/test/Preprocessor/cxx_compl.cpp b/test/Preprocessor/cxx_compl.cpp
new file mode 100644
index 0000000000..12e589ffa1
--- /dev/null
+++ b/test/Preprocessor/cxx_compl.cpp
@@ -0,0 +1,16 @@
+// RUN: clang -DA=1 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA=0 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if compl 0 bitand A
+#define X 37
+#else
+#define X 927
+#endif
+
+#if ~0 & A
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
diff --git a/test/Preprocessor/cxx_not.cpp b/test/Preprocessor/cxx_not.cpp
new file mode 100644
index 0000000000..2587b0ab99
--- /dev/null
+++ b/test/Preprocessor/cxx_not.cpp
@@ -0,0 +1,15 @@
+// RUN: clang -DA=1 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 37 == 37'
+#if not defined(A)
+#define X 37
+#else
+#define X 927
+#endif
+
+#if ! defined(A)
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
diff --git a/test/Preprocessor/cxx_not_eq.cpp b/test/Preprocessor/cxx_not_eq.cpp
new file mode 100644
index 0000000000..b0be7b3917
--- /dev/null
+++ b/test/Preprocessor/cxx_not_eq.cpp
@@ -0,0 +1,16 @@
+// RUN: clang -DA=1 -DB=1 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -DA=1 -DB=2 -E %s | grep 'int a = 37 == 37'
+#if A not_eq B
+#define X 37
+#else
+#define X 927
+#endif
+
+#if A != B
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
diff --git a/test/Preprocessor/cxx_oper_keyword.cpp b/test/Preprocessor/cxx_oper_keyword.cpp
new file mode 100644
index 0000000000..66586e7b36
--- /dev/null
+++ b/test/Preprocessor/cxx_oper_keyword.cpp
@@ -0,0 +1,7 @@
+// RUN: not clang %s -E &&
+// RUN: clang %s -E -fno-operator-names
+
+// Not valid in C++ unless -fno-operator-names is passed.
+#define and foo
+
+
diff --git a/test/Preprocessor/cxx_oper_spelling.cpp b/test/Preprocessor/cxx_oper_spelling.cpp
new file mode 100644
index 0000000000..fc8bc70e51
--- /dev/null
+++ b/test/Preprocessor/cxx_oper_spelling.cpp
@@ -0,0 +1,11 @@
+// RUN: clang -E %s | grep 'a: "and"'
+
+#define X(A) #A
+
+// C++'03 2.5p2: "In all respects of the language, each alternative
+// token behaves the same, respectively, as its primary token,