Stage two of getting CFE top correct.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39734 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Lexer/badstring_in_if0.c b/test/Lexer/badstring_in_if0.c
new file mode 100644
index 0000000..714f89b
--- /dev/null
+++ b/test/Lexer/badstring_in_if0.c
@@ -0,0 +1,8 @@
+// RUN: clang -E %s 2>&1 | not grep error
+#if 0
+
+  "
+
+  '
+
+#endif
diff --git a/test/Lexer/block_cmt_end.c b/test/Lexer/block_cmt_end.c
new file mode 100644
index 0000000..b111b2a
--- /dev/null
+++ b/test/Lexer/block_cmt_end.c
@@ -0,0 +1,27 @@
+/*
+  RUN: clang -E %s | grep bar &&
+  RUN: clang -E %s | grep foo &&
+  RUN: clang -E %s | not grep abc &&
+  RUN: clang -E %s | not grep xyz &&
+  RUN: clang -parse-ast-check %s
+ */
+
+/* abc
+
+next comment ends with normal escaped newline:
+*/
+
+/* expected-warning {{escaped newline}} expected-warning {{backslash and newline}}  *\  
+/
+
+bar
+
+/* xyz
+
+next comment ends with a trigraph escaped newline: */
+
+/* expected-warning {{escaped newline between}}   expected-warning {{backslash and newline separated by space}}    expected-warning {{trigraph ends block comment}}   *??/    
+/
+
+foo /* expected-error {{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}} */
+
diff --git a/test/Lexer/escape_newline.c b/test/Lexer/escape_newline.c
new file mode 100644
index 0000000..235ee51
--- /dev/null
+++ b/test/Lexer/escape_newline.c
@@ -0,0 +1,7 @@
+// RUN: clang -E %s | grep -- ' ->' &&
+// RUN: clang -E %s 2>&1 | grep 'backslash and newline separated by space' &&
+// RUN: clang -E %s 2>&1 | grep 'trigraph converted'
+
+// This is an ugly way to spell a -> token.
+ -??/      
+>
diff --git a/test/Lexer/number.c b/test/Lexer/number.c
new file mode 100644
index 0000000..4e12cc7
--- /dev/null
+++ b/test/Lexer/number.c
@@ -0,0 +1,4 @@
+// RUN: clang %s -fsyntax-only
+
+float X = 1.17549435e-38F;
+
diff --git a/test/Lexer/unknown-char.c b/test/Lexer/unknown-char.c
new file mode 100644
index 0000000..8bdfe60
--- /dev/null
+++ b/test/Lexer/unknown-char.c
@@ -0,0 +1,2 @@
+// RUN: clang -E %s 2>&1 | not grep error
+ ` ` ` `
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..2c35b44
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,3 @@
+
+all:
+	find Lexer Preprocessor Parser -name '*.c*' -print -exec ./TestRunner.sh {} \;
diff --git a/test/Parser/CompoundStmtScope.c b/test/Parser/CompoundStmtScope.c
new file mode 100644
index 0000000..d6a4730
--- /dev/null
+++ b/test/Parser/CompoundStmtScope.c
@@ -0,0 +1,8 @@
+// RUN: clang -parse-ast-check %s
+
+int foo() {
+  {
+    typedef float X;
+  }
+  X Y;  // expected-error {{use of undeclared identifier}}
+}
diff --git a/test/Parser/argument_qualified.c b/test/Parser/argument_qualified.c
new file mode 100644
index 0000000..cd92c32
--- /dev/null
+++ b/test/Parser/argument_qualified.c
@@ -0,0 +1,5 @@
+// RUN: clang %s
+int abc (const float x) {
+  return 1;
+}
+
diff --git a/test/Parser/argument_redef.c b/test/Parser/argument_redef.c
new file mode 100644
index 0000000..c3dae51
--- /dev/null
+++ b/test/Parser/argument_redef.c
@@ -0,0 +1,6 @@
+/* RUN: clang -parse-ast-check %s
+*/
+
+int foo(int A) { /* expected-error {{previous definition is here}} */
+  int A; /* expected-error {{redefinition of 'A'}} */
+}
diff --git a/test/Parser/argument_scope.c b/test/Parser/argument_scope.c
new file mode 100644
index 0000000..8b9f065
--- /dev/null
+++ b/test/Parser/argument_scope.c
@@ -0,0 +1,6 @@
+// RUN: clang -fsyntax-only %s
+typedef struct foo foo;
+
+void blah(int foo) {
+  foo = 1;
+}
diff --git a/test/Parser/attributes.c b/test/Parser/attributes.c
new file mode 100644
index 0000000..29e8c81
--- /dev/null
+++ b/test/Parser/attributes.c
@@ -0,0 +1,6 @@
+// RUN: clang -parse-ast-check %s
+
+static __inline void __attribute__((__always_inline__, __nodebug__)) // expected-warning {{extension used}}
+foo (void)
+{
+}
diff --git a/test/Parser/bad-control.c b/test/Parser/bad-control.c
new file mode 100644
index 0000000..9143934
--- /dev/null
+++ b/test/Parser/bad-control.c
@@ -0,0 +1,9 @@
+/* RUN: clang -parse-ast-check %s
+*/
+int foo() { 
+  break; /* expected-error {{'break' statement not in loop or switch statement}} */
+}
+
+int foo2() { 
+  continue; /* expected-error {{'continue' statement not in loop statement}} */
+}
diff --git a/test/Parser/c-namespace.c b/test/Parser/c-namespace.c
new file mode 100644
index 0000000..2b38050
--- /dev/null
+++ b/test/Parser/c-namespace.c
@@ -0,0 +1,6 @@
+// RUN: clang -fsyntax-only %s 
+void bla1() {
+  struct XXX;
+  int XXX;
+}
+
diff --git a/test/Parser/cxx-bool.cpp b/test/Parser/cxx-bool.cpp
new file mode 100644
index 0000000..623dcb2
--- /dev/null
+++ b/test/Parser/cxx-bool.cpp
@@ -0,0 +1,4 @@
+// RUN: clang -fsyntax-only %s
+
+bool a = true;
+bool b = false;
diff --git a/test/Parser/cxx-casting.cpp b/test/Parser/cxx-casting.cpp
new file mode 100644
index 0000000..638985f
--- /dev/null
+++ b/test/Parser/cxx-casting.cpp
@@ -0,0 +1,32 @@
+// RUN: clang -fsyntax-only %s
+// XFAIL: *
+
+char *const_cast_test(const char *var)
+{
+  return const_cast<char*>(var);
+}
+
+#if 0
+// FIXME: Uncomment when C++ is supported more.
+struct A {
+  virtual ~A() {}
+};
+
+struct B : public A {
+};
+
+struct B *dynamic_cast_test(struct A *a)
+{
+  return dynamic_cast<struct B*>(a);
+}
+#endif
+
+char *reinterpret_cast_test()
+{
+  return reinterpret_cast<char*>(0xdeadbeef);
+}
+
+double static_cast_test(int i)
+{
+  return static_cast<double>(i);
+}
diff --git a/test/Parser/cxx-reference.cpp b/test/Parser/cxx-reference.cpp
new file mode 100644
index 0000000..44a2a03
--- /dev/null
+++ b/test/Parser/cxx-reference.cpp
@@ -0,0 +1,17 @@
+// RUN: clang -parse-ast-check %s
+
+extern char *bork;
+char *& bar = bork;
+
+void foo(int &a) {
+}
+
+typedef int & A;
+
+void g(const A aref) {
+}
+
+int & const X; // expected-error {{'const' qualifier may not be applied to a reference}}
+int & volatile Y; // expected-error {{'volatile' qualifier may not be applied to a reference}}
+int & const volatile Z; /* expected-error {{'const' qualifier may not be applied}} \
+                           expected-error {{'volatile' qualifier may not be applied}} */
diff --git a/test/Parser/declarators.c b/test/Parser/declarators.c
new file mode 100644
index 0000000..af599f8
--- /dev/null
+++ b/test/Parser/declarators.c
@@ -0,0 +1,28 @@
+// RUN: clang %s -fsyntax-only
+
+extern int a1[];
+
+void f0();
+void f1(int [*]);
+void f2(int [const *]);
+void f3(int [volatile const*]);
+int f4(*XX)(void);
+
+char ((((*X))));
+
+void (*signal(int, void (*)(int)))(int);
+
+int a, ***C, * const D, b(int);
+
+int *A;
+
+struct str;
+
+int test2(int *P, int A) {
+  struct str;
+
+  // Hard case for array decl, not Array[*].
+  int Array[*(int*)P+A];
+}
+
+
diff --git a/test/Parser/expressions.c b/test/Parser/expressions.c
new file mode 100644
index 0000000..77201a8
--- /dev/null
+++ b/test/Parser/expressions.c
@@ -0,0 +1,30 @@
+// RUN: clang -fsyntax-only %s
+
+void test1() {
+  if (sizeof (int){ 1});   // sizeof compound literal
+  if (sizeof (int));       // sizeof type
+
+  (int)4;   // cast.
+  (int){4}; // compound literal.
+
+  // FIXME: change this to the struct version when we can.
+  //int A = (struct{ int a;}){ 1}.a;
+  int A = (int){ 1}.a;
+}
+
+int test2(int a, int b) {
+  return a ? a,b : a;
+}
+
+int test3(int a, int b, int c) {
+  return a = b = c;
+}
+
+int test4() {
+  test4();
+}
+
+int test_offsetof() {
+  // FIXME: change into something that is semantically correct.
+  __builtin_offsetof(int, a.b.c[4][5]);
+}
diff --git a/test/Parser/function-decls.c b/test/Parser/function-decls.c
new file mode 100644
index 0000000..ef93756
--- /dev/null
+++ b/test/Parser/function-decls.c
@@ -0,0 +1,10 @@
+/* RUN: clang %s -parse-ast-print
+ */
+
+void foo() {
+  int X;
+  X = sizeof(void (*(*)())());
+  X = sizeof(int(*)(int, float, ...));
+  X = sizeof(void (*(int arga, void (*argb)(double Y)))(void* Z));
+}
+
diff --git a/test/Parser/portability.c b/test/Parser/portability.c
new file mode 100644
index 0000000..a96aee5
--- /dev/null
+++ b/test/Parser/portability.c
@@ -0,0 +1,5 @@
+// RUN: clang -arch ppc -arch linux -fsyntax-only %s 2>&1 | grep note | wc -l | grep 1
+
+// wchar_t varies across targets.
+void *X = L"foo";
+
diff --git a/test/Parser/recovery-1.c b/test/Parser/recovery-1.c
new file mode 100644
index 0000000..4dd1af1
--- /dev/null
+++ b/test/Parser/recovery-1.c
@@ -0,0 +1,7 @@
+// RUN: clang -fsyntax-only -fno-caret-diagnostics -pedantic %s 2>&1 | grep warning | wc -l | grep 1
+// RUN: clang -parse-ast-check %s
+
+char ((((                       /* expected-error {{to match this '('}} */
+*X x ] ))));                    /* expected-error {{expected ')'}} */
+
+;   // expected-warning {{ISO C does not allow an extra ';' outside of a function}}
diff --git a/test/Parser/statements.c b/test/Parser/statements.c
new file mode 100644
index 0000000..b3f043e
--- /dev/null
+++ b/test/Parser/statements.c
@@ -0,0 +1,49 @@
+// RUN: clang -fsyntax-only %s
+
+int test1() {
+  { ; {  ;;}} ;;
+}
+
+int test2() {
+  if (0) { if (1) {} } else { }
+
+  do { } while (0); 
+  
+  while (0) while(0) do ; while(0);
+
+  for (0;0;0)
+    for (;;)
+      for (9;0;2)
+        ;
+  for (int X = 0; 0; 0);
+}
+
+int test3() {
+    switch (0) {
+    
+    case 4:
+      if (0) {
+    case 6: ;
+      }
+    default:
+      ;     
+  }
+}
+
+int test4() {
+  if (0);
+  
+  int X;  // declaration in a block.
+  
+foo:  if (0);
+}
+
+typedef int t;
+void test5() {
+  if (0);
+
+  //t x = 0;      // FIXME: Enable when handling of typedef names is impl.
+
+  if (0);
+}
+
diff --git a/test/Parser/struct-recursion.c b/test/Parser/struct-recursion.c
new file mode 100644
index 0000000..c16f9fc
--- /dev/null
+++ b/test/Parser/struct-recursion.c
@@ -0,0 +1,11 @@
+// RUN: clang %s -fsyntax-only
+
+// C99 6.7.2.3p11
+
+// mutually recursive structs
+struct s1 { struct s2 *A; };
+struct s2 { struct s1 *B; };
+
+// both types are complete now.
+struct s1 a;
+struct s2 b;
diff --git a/test/Parser/types.c b/test/Parser/types.c
new file mode 100644
index 0000000..f1ffb94
--- /dev/null
+++ b/test/Parser/types.c
@@ -0,0 +1,6 @@
+// RUN: clang %s -fsyntax-only
+
+// Test the X can be overloaded inside the struct.
+typedef int X; 
+struct Y { short X; };
+
diff --git a/test/Preprocessor/_Pragma-dependency.c b/test/Preprocessor/_Pragma-dependency.c
new file mode 100644
index 0000000..f7d7efe
--- /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 0000000..152e71a
--- /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 0000000..b8f5499
--- /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 0000000..82a7fbe
--- /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 0000000..4d2d29e
--- /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 0000000..190e5a7
--- /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 0000000..c9ce558
--- /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 0000000..13d5661
--- /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 0000000..fa5f735
--- /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 0000000..ce7990a
--- /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 0000000..88957df
--- /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 0000000..08b4637
--- /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 0000000..1a3bd96
--- /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 0000000..ce7b4c4
--- /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 0000000..635a6fd
--- /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 0000000..b6bd00e
--- /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 0000000..ecc52e8
--- /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 0000000..36c4452
--- /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 0000000..12e589f
--- /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 0000000..2587b0a
--- /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 0000000..b0be7b3
--- /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 0000000..66586e7
--- /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 0000000..fc8bc70
--- /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, 
+// except for its spelling"
+//
+// This should be spelled as 'and', not '&&'
+a: X(and)
+
diff --git a/test/Preprocessor/cxx_or.cpp b/test/Preprocessor/cxx_or.cpp
new file mode 100644
index 0000000..ce3fed1
--- /dev/null
+++ b/test/Preprocessor/cxx_or.cpp
@@ -0,0 +1,17 @@
+// RUN: clang -DA -DB -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DB -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if defined(A) or 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_true.cpp b/test/Preprocessor/cxx_true.cpp
new file mode 100644
index 0000000..5ebdaf8
--- /dev/null
+++ b/test/Preprocessor/cxx_true.cpp
@@ -0,0 +1,13 @@
+/* RUN: clang -E %s -x=c++ | grep block_1 &&
+   RUN: clang -E %s -x=c++ | not grep block_2 &&
+   RUN: clang -E %s -x=c | not grep block
+*/
+
+#if true
+block_1
+#endif
+
+#if false
+block_2
+#endif
+
diff --git a/test/Preprocessor/cxx_xor.cpp b/test/Preprocessor/cxx_xor.cpp
new file mode 100644
index 0000000..7a4c882
--- /dev/null
+++ b/test/Preprocessor/cxx_xor.cpp
@@ -0,0 +1,18 @@
+// RUN: clang -DA=1 -DB=1 -E %s | grep 'int a = 927 == 927' &&
+// 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 xor 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/define_other_target.c b/test/Preprocessor/define_other_target.c
new file mode 100644
index 0000000..367e164
--- /dev/null
+++ b/test/Preprocessor/define_other_target.c
@@ -0,0 +1,27 @@
+// Note that the run lines are at the bottom of this file.
+
+#define_other_target TEST1
+TEST1   // diagnose
+
+#define_other_target TEST2
+#undef TEST2
+TEST2   // no diagnose
+
+#define_other_target TEST3
+#define TEST3
+TEST3   // no diagnose
+
+#define TEST4
+#define_other_target TEST4
+TEST4   // diagnose
+
+
+// check success:
+// RUN: clang -Eonly %s &&
+
+// Check proper # of notes is emitted.
+// RUN: clang -Eonly %s 2>&1 | grep note | wc -l | grep 2 &&
+
+// Check that the diagnostics are the right ones.
+// RUN: clang %s -Eonly -fno-caret-diagnostics 2>&1 | grep ':4:1: note' &&
+// RUN: clang %s -Eonly -fno-caret-diagnostics 2>&1 | grep ':16:1: note'
diff --git a/test/Preprocessor/define_target.c b/test/Preprocessor/define_target.c
new file mode 100644
index 0000000..85a132f
--- /dev/null
+++ b/test/Preprocessor/define_target.c
@@ -0,0 +1,27 @@
+// Note that the run lines are at the bottom of this file.
+
+#define_target TEST1
+TEST1   // diagnose
+
+#define_target TEST2
+#undef TEST2
+TEST2   // no diagnose
+
+#define_target TEST3
+#define TEST3
+TEST3   // no diagnose
+
+#define TEST4
+#define_target TEST4
+TEST4   // diagnose
+
+
+// check success:
+// RUN: clang -Eonly %s &&
+
+// Check proper # of notes is emitted.
+// RUN: clang -Eonly %s 2>&1 | grep note | wc -l | grep 2 &&
+
+// Check that the diagnostics are the right ones.
+// RUN: clang %s -Eonly -fno-caret-diagnostics 2>&1 | grep ':4:1: note' &&
+// RUN: clang %s -Eonly -fno-caret-diagnostics 2>&1 | grep ':16:1: note'
diff --git a/test/Preprocessor/disabled-cond-diags.c b/test/Preprocessor/disabled-cond-diags.c
new file mode 100644
index 0000000..df9dc89
--- /dev/null
+++ b/test/Preprocessor/disabled-cond-diags.c
@@ -0,0 +1,10 @@
+// RUN: clang -E %s 2>&1 | not grep "warning\|error"
+
+#if 0
+
+// Shouldn't get warnings here.
+??( ??)
+
+// Should not get an error here.
+` ` ` `
+#endif
diff --git a/test/Preprocessor/expr_liveness.c b/test/Preprocessor/expr_liveness.c
new file mode 100644
index 0000000..f14ac0a
--- /dev/null
+++ b/test/Preprocessor/expr_liveness.c
@@ -0,0 +1,32 @@
+/* RUN: clang -E %s -DNO_ERRORS &&
+   RUN: not clang -E %s
+ */
+
+#ifdef NO_ERRORS
+/* None of these divisions by zero are in live parts of the expression, do not
+   emit any diagnostics. */
+
+#define MACRO_0 0
+#define MACRO_1 1
+
+#if MACRO_0 && 10 / MACRO_0
+foo
+#endif
+
+#if MACRO_1 || 10 / MACRO_0
+bar
+#endif
+
+#if 0 ? 124/0 : 42
+#endif
+
+#else
+
+
+/* The 1/0 is live, it should error out. */
+#if 0 && 1 ? 4 : 1 / 0
+baz
+#endif
+
+
+#endif
diff --git a/test/Preprocessor/expr_usual_conversions.c b/test/Preprocessor/expr_usual_conversions.c
new file mode 100644
index 0000000..b2ccc40
--- /dev/null
+++ b/test/Preprocessor/expr_usual_conversions.c
@@ -0,0 +1,8 @@
+// RUN: clang %s -E  2>&1 | grep warning | wc -l | grep 2
+
+#define INTMAX_MIN (-9223372036854775807LL -1)
+
+#if (-42 + 0U) / -2
+foo
+#endif
+
diff --git a/test/Preprocessor/file_to_include.h b/test/Preprocessor/file_to_include.h
new file mode 100644
index 0000000..97728ab
--- /dev/null
+++ b/test/Preprocessor/file_to_include.h
@@ -0,0 +1,3 @@
+
+#warning file successfully included
+
diff --git a/test/Preprocessor/hash_line.c b/test/Preprocessor/hash_line.c
new file mode 100644
index 0000000..788440b
--- /dev/null
+++ b/test/Preprocessor/hash_line.c
@@ -0,0 +1,8 @@
+// The 1 and # should not go on the same line.
+// RUN: clang %s -E | not grep "1 #" &&
+// RUN: clang %s -E | grep '^1$' &&
+// RUN: clang %s -E | grep '^      #$'
+1
+#define EMPTY
+EMPTY #
+
diff --git a/test/Preprocessor/hash_space.c b/test/Preprocessor/hash_space.c
new file mode 100644
index 0000000..77f5cfc
--- /dev/null
+++ b/test/Preprocessor/hash_space.c
@@ -0,0 +1,6 @@
+// RUN: clang %s -E | grep " #"
+
+// Should put a space before the # so that -fpreprocessed mode doesn't
+// macro expand this again.
+#define HASH #
+HASH define foo bar
diff --git a/test/Preprocessor/includeexpand.c b/test/Preprocessor/includeexpand.c
new file mode 100644
index 0000000..3363795
--- /dev/null
+++ b/test/Preprocessor/includeexpand.c
@@ -0,0 +1,12 @@
+// RUN: clang %s -fno-caret-diagnostics 2>&1 | grep 'file successfully included' | wc -l | grep 3
+
+// XX expands to nothing.
+#define XX
+
+#define FILE "file_to_include.h"
+#include XX FILE
+
+#include FILE
+
+
+#include "file_to_include.h"
diff --git a/test/Preprocessor/indent_macro.c b/test/Preprocessor/indent_macro.c
new file mode 100644
index 0000000..0dcaa7b
--- /dev/null
+++ b/test/Preprocessor/indent_macro.c
@@ -0,0 +1,6 @@
+// RUN: clang -E %s | grep '^   zzap$'
+
+// zzap is on a new line, should be indented.
+#define BLAH  zzap
+   BLAH
+
diff --git a/test/Preprocessor/macro_arg_keyword.c b/test/Preprocessor/macro_arg_keyword.c
new file mode 100644
index 0000000..1f9d7e7
--- /dev/null
+++ b/test/Preprocessor/macro_arg_keyword.c
@@ -0,0 +1,6 @@
+// RUN: clang -E %s | grep xxx-xxx
+
+#define foo(return) return-return
+
+foo(xxx)
+
diff --git a/test/Preprocessor/macro_defined.c b/test/Preprocessor/macro_defined.c
new file mode 100644
index 0000000..f120197
--- /dev/null
+++ b/test/Preprocessor/macro_defined.c
@@ -0,0 +1,6 @@
+// RUN: clang %s -E 2>&1 | not grep error
+
+// This should not be rejected.
+#ifdef defined
+#endif
+
diff --git a/test/Preprocessor/macro_disable.c b/test/Preprocessor/macro_disable.c
new file mode 100644
index 0000000..33b856d
--- /dev/null
+++ b/test/Preprocessor/macro_disable.c
@@ -0,0 +1,13 @@
+// RUN: clang -E %s | grep 'a: 2 + M_0(3)(4)(5);' &&
+// RUN: clang -E %s | grep 'b: 4 + 4 + 3 + 2 + 1 + M_0(3)(2)(1);'
+
+#define M_0(x) M_ ## x 
+#define M_1(x) x + M_0(0) 
+#define M_2(x) x + M_1(1) 
+#define M_3(x) x + M_2(2) 
+#define M_4(x) x + M_3(3) 
+#define M_5(x) x + M_4(4) 
+
+a: M_0(1)(2)(3)(4)(5);
+b: M_0(5)(4)(3)(2)(1);
+
diff --git a/test/Preprocessor/macro_disable2.c b/test/Preprocessor/macro_disable2.c
new file mode 100644
index 0000000..6e1f804
--- /dev/null
+++ b/test/Preprocessor/macro_disable2.c
@@ -0,0 +1,8 @@
+// RUN: clang -E %s | grep 'A B C A B A C A B C A'
+
+#define A A B C 
+#define B B C A 
+#define C C A B 
+ 
+A 
+
diff --git a/test/Preprocessor/macro_disable3.c b/test/Preprocessor/macro_disable3.c
new file mode 100644
index 0000000..b358a55
--- /dev/null
+++ b/test/Preprocessor/macro_disable3.c
@@ -0,0 +1,8 @@
+// RUN: clang %s -E | grep -F 'f(2 * (f(2 * (z[0]))));'
+// Check for C99 6.10.3.4p2.
+
+#define f(a) f(x * (a)) 
+#define x 2 
+#define z z[0] 
+f(f(z)); 
+
diff --git a/test/Preprocessor/macro_expand.c b/test/Preprocessor/macro_expand.c
new file mode 100644
index 0000000..69a4835
--- /dev/null
+++ b/test/Preprocessor/macro_expand.c
@@ -0,0 +1,7 @@
+// RUN: clang -E %s | grep '^Y$'
+
+#define X() Y
+#define Y() X
+
+X()()()
+
diff --git a/test/Preprocessor/macro_expandloc.c b/test/Preprocessor/macro_expandloc.c
new file mode 100644
index 0000000..00bba6f
--- /dev/null
+++ b/test/Preprocessor/macro_expandloc.c
@@ -0,0 +1,6 @@
+// RUN: clang %s -E 2>&1 | grep '#include'
+#define FOO 1
+
+// The error message should be on the #include line, not the 1.
+#include FOO
+
diff --git a/test/Preprocessor/macro_expandloc2.c b/test/Preprocessor/macro_expandloc2.c
new file mode 100644
index 0000000..3a83329
--- /dev/null
+++ b/test/Preprocessor/macro_expandloc2.c
@@ -0,0 +1,6 @@
+// RUN: clang %s -E 2>&1 | grep '#include'
+#define FOO BAR
+
+// The error message should be on the #include line, not the 1.
+#include FOO
+
diff --git a/test/Preprocessor/macro_fn_comma_swallow.c b/test/Preprocessor/macro_fn_comma_swallow.c
new file mode 100644
index 0000000..d4f3bb9
--- /dev/null
+++ b/test/Preprocessor/macro_fn_comma_swallow.c
@@ -0,0 +1,16 @@
+// Test the GNU comma swallowing extension.
+// RUN: clang %s -E | grep 'foo{A, }' && 
+// RUN: clang %s -E | grep 'fo2{A,}' && 
+// RUN: clang %s -E | grep '{foo}'
+
+#define X(Y) foo{A, Y}
+X()
+
+#define X2(Y) fo2{A,##Y}
+X2()
+
+// should eat the comma.
+#define X3(b, ...) {b, ## __VA_ARGS__}
+X3(foo)
+
+
diff --git a/test/Preprocessor/macro_fn_disable_expand.c b/test/Preprocessor/macro_fn_disable_expand.c
new file mode 100644
index 0000000..a9e1d46
--- /dev/null
+++ b/test/Preprocessor/macro_fn_disable_expand.c
@@ -0,0 +1,11 @@
+// RUN: clang %s -E | grep 'bar foo (2)' &&
+// RUN: clang %s -E | grep 'm(ABCD)'
+
+#define foo(x) bar x
+foo(foo) (2)
+
+
+#define m(a) a(w)
+#define w ABCD
+m(m)   // m(ABCD)
+
diff --git a/test/Preprocessor/macro_fn_lparen_scan.c b/test/Preprocessor/macro_fn_lparen_scan.c
new file mode 100644
index 0000000..497ef23
--- /dev/null
+++ b/test/Preprocessor/macro_fn_lparen_scan.c
@@ -0,0 +1,27 @@
+// RUN: clang -E %s | grep 'noexp: foo y' &&
+// RUN: clang -E %s | grep 'expand: abc' &&
+// RUN: clang -E %s | grep 'noexp2: foo nonexp' &&
+// RUN: clang -E %s | grep 'expand2: abc'
+
+#define A foo
+#define foo() abc
+#define X A y
+
+// This should not expand to abc, because the foo macro isn't followed by (.
+noexp: X
+
+
+// This should expand to abc.
+#undef X
+#define X A ()
+expand: X
+
+
+// This should be 'foo nonexp'
+noexp2: A nonexp
+
+// This should expand
+expand2: A (
+)
+
+
diff --git a/test/Preprocessor/macro_fn_lparen_scan2.c b/test/Preprocessor/macro_fn_lparen_scan2.c
new file mode 100644
index 0000000..fa4d504
--- /dev/null
+++ b/test/Preprocessor/macro_fn_lparen_scan2.c
@@ -0,0 +1,7 @@
+// RUN: clang -E %s | grep 'FUNC (3 +1);'
+
+#define F(a) a 
+#define FUNC(a) (a+1) 
+
+F(FUNC) FUNC (3); /* final token sequence is FUNC(3+1) */ 
+
diff --git a/test/Preprocessor/macro_fn_placemarker.c b/test/Preprocessor/macro_fn_placemarker.c
new file mode 100644
index 0000000..30c0bcf
--- /dev/null
+++ b/test/Preprocessor/macro_fn_placemarker.c
@@ -0,0 +1,5 @@
+// RUN: clang %s -E | grep 'foo(A, )'
+
+#define X(Y) foo(A, Y)
+X()
+
diff --git a/test/Preprocessor/macro_fn_preexpand.c b/test/Preprocessor/macro_fn_preexpand.c
new file mode 100644
index 0000000..81a7c41
--- /dev/null
+++ b/test/Preprocessor/macro_fn_preexpand.c
@@ -0,0 +1,12 @@
+// RUN: clang %s -E | grep 'pre: 1 1 X' &&
+// RUN: clang %s -E | grep 'nopre: 1A(X)'
+
+/* Preexpansion of argument. */
+#define A(X) 1 X
+pre: A(A(X))
+
+/* The ## operator disables preexpansion. */
+#undef A
+#define A(X) 1 ## X
+nopre: A(A(X))
+
diff --git a/test/Preprocessor/macro_fn_varargs_iso.c b/test/Preprocessor/macro_fn_varargs_iso.c
new file mode 100644
index 0000000..716e920
--- /dev/null
+++ b/test/Preprocessor/macro_fn_varargs_iso.c
@@ -0,0 +1,11 @@
+
+// RUN: clang -E %s | grep 'foo{a, b, c, d, e}' &&
+// RUN: clang -E %s | grep 'foo2{d, C, B}' &&
+// RUN: clang -E %s | grep 'foo2{d,e, C, B}'
+
+#define va1(...) foo{a, __VA_ARGS__, e}
+va1(b, c, d)
+#define va2(a, b, ...) foo2{__VA_ARGS__, b, a}
+va2(B, C, d)
+va2(B, C, d,e)
+
diff --git a/test/Preprocessor/macro_fn_varargs_named.c b/test/Preprocessor/macro_fn_varargs_named.c
new file mode 100644
index 0000000..75ee961
--- /dev/null
+++ b/test/Preprocessor/macro_fn_varargs_named.c
@@ -0,0 +1,7 @@
+// RUN: clang -E %s | grep '^a: x$' &&
+// RUN: clang -E %s | grep '^b: x y, z,h$'
+
+#define A(b, c...) b c
+a: A(x)
+b: A(x, y, z,h)
+
diff --git a/test/Preprocessor/macro_not_define.c b/test/Preprocessor/macro_not_define.c
new file mode 100644
index 0000000..388481a
--- /dev/null
+++ b/test/Preprocessor/macro_not_define.c
@@ -0,0 +1,9 @@
+// RUN: clang -E %s | grep '^ # define X 3$'
+
+#define H # 
+ #define D define 
+ 
+ #define DEFINE(a, b) H D a b 
+ 
+ DEFINE(X, 3) 
+
diff --git a/test/Preprocessor/macro_paste_bad.c b/test/Preprocessor/macro_paste_bad.c
new file mode 100644
index 0000000..60caa42
--- /dev/null
+++ b/test/Preprocessor/macro_paste_bad.c
@@ -0,0 +1,5 @@
+// RUN: clang -Eonly %s 2>&1 | grep error
+// pasting ""x"" and ""+"" does not give a valid preprocessing token
+#define XYZ  x ## +
+XYZ
+
diff --git a/test/Preprocessor/macro_paste_bcpl_comment.c b/test/Preprocessor/macro_paste_bcpl_comment.c
new file mode 100644
index 0000000..9a864d5
--- /dev/null
+++ b/test/Preprocessor/macro_paste_bcpl_comment.c
@@ -0,0 +1,5 @@
+// RUN: clang %s -Eonly 2>&1 | grep error
+
+#define COMM1 / ## /
+COMM1
+
diff --git a/test/Preprocessor/macro_paste_c_block_comment.c b/test/Preprocessor/macro_paste_c_block_comment.c
new file mode 100644
index 0000000..9299514
--- /dev/null
+++ b/test/Preprocessor/macro_paste_c_block_comment.c
@@ -0,0 +1,7 @@
+// RUN: clang %s -Eonly 2>&1 | grep error &&
+// RUN: clang %s -Eonly 2>&1 | not grep unterminated &&
+// RUN: clang %s -Eonly 2>&1 | not grep scratch
+
+#define COMM / ## *
+COMM
+
diff --git a/test/Preprocessor/macro_paste_empty.c b/test/Preprocessor/macro_paste_empty.c
new file mode 100644
index 0000000..8b78ecd
--- /dev/null
+++ b/test/Preprocessor/macro_paste_empty.c
@@ -0,0 +1,13 @@
+// RUN: clang -E %s | grep 'a:Y' &&
+// RUN: clang -E %s | grep 'b:Y' &&
+// RUN: clang -E %s | grep 'c:YY'
+
+#define FOO(X) X ## Y
+a:FOO()
+
+#define FOO2(X) Y ## X
+b:FOO2()
+
+#define FOO3(X) X ## Y ## X ## Y ## X ## X
+c:FOO3()
+
diff --git a/test/Preprocessor/macro_paste_hard.c b/test/Preprocessor/macro_paste_hard.c
new file mode 100644
index 0000000..be46745
--- /dev/null
+++ b/test/Preprocessor/macro_paste_hard.c
@@ -0,0 +1,17 @@
+// RUN: clang -E %s | grep '1: aaab 2' &&
+// RUN: clang -E %s | grep '2: 2 baaa' &&
+// RUN: clang -E %s | grep '3: 2 xx'
+
+#define a(n) aaa ## n
+#define b 2
+1: a(b b)   // aaab 2    2 gets expanded, not b.
+
+#undef a
+#undef b
+#define a(n) n ## aaa
+#define b 2
+2: a(b b)   // 2 baaa    2 gets expanded, not b.
+
+#define baaa xx
+3: a(b b)   // 2 xx
+
diff --git a/test/Preprocessor/macro_paste_hashhash.c b/test/Preprocessor/macro_paste_hashhash.c
new file mode 100644
index 0000000..4ebf55e
--- /dev/null
+++ b/test/Preprocessor/macro_paste_hashhash.c
@@ -0,0 +1,7 @@
+// RUN: clang -E %s | grep '^"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) 
+join(x, y);
+
diff --git a/test/Preprocessor/macro_paste_none.c b/test/Preprocessor/macro_paste_none.c
new file mode 100644
index 0000000..2ba2820
--- /dev/null
+++ b/test/Preprocessor/macro_paste_none.c
@@ -0,0 +1,6 @@
+// RUN: clang -E %s | grep '!!'
+
+#define A(B,C) B ## C
+
+!A(,)!
+
diff --git a/test/Preprocessor/macro_paste_simple.c b/test/Preprocessor/macro_paste_simple.c
new file mode 100644
index 0000000..e8dc1e8
--- /dev/null
+++ b/test/Preprocessor/macro_paste_simple.c
@@ -0,0 +1,3 @@
+// clang %s -E | grep "barbaz123"
+
+#define FOO bar ## baz ## 123
diff --git a/test/Preprocessor/macro_paste_spacing.c b/test/Preprocessor/macro_paste_spacing.c
new file mode 100644
index 0000000..471ebcc
--- /dev/null
+++ b/test/Preprocessor/macro_paste_spacing.c
@@ -0,0 +1,7 @@
+// RUN: clang %s -E | grep "^xy$"
+
+#define A  x ## y
+blah
+
+A
+
diff --git a/test/Preprocessor/macro_rescan.c b/test/Preprocessor/macro_rescan.c
new file mode 100644
index 0000000..2ceb292
--- /dev/null
+++ b/test/Preprocessor/macro_rescan.c
@@ -0,0 +1,9 @@
+// RUN: clang -E %s | grep 'ei_1 = (17 +1);' &&
+// RUN: clang -E %s | grep 'ei_2 = (M1)(17);'
+
+#define M1(a) (a+1) 
+#define M2(b) b 
+
+int ei_1 = M2(M1)(17); /* becomes int ei_1 = (17+1); */ 
+int ei_2 = (M2(M1))(17); /* becomes int ei_2 = (M1)(17); */ 
+
diff --git a/test/Preprocessor/macro_rescan2.c b/test/Preprocessor/macro_rescan2.c
new file mode 100644
index 0000000..4fae444
--- /dev/null
+++ b/test/Preprocessor/macro_rescan2.c
@@ -0,0 +1,15 @@
+// RUN: clang %s -E | grep 'a: 2\*f(9)' &&
+// RUN: clang %s -E | grep 'b: 2\*9\*g'
+
+#define f(a) a*g 
+#define g f 
+a: f(2)(9) 
+
+#undef f
+#undef g
+
+#define f(a) a*g 
+#define g(a) f(a) 
+
+b: f(2)(9)
+
diff --git a/test/Preprocessor/macro_rescan_varargs.c b/test/Preprocessor/macro_rescan_varargs.c
new file mode 100644
index 0000000..3c79d0e
--- /dev/null
+++ b/test/Preprocessor/macro_rescan_varargs.c
@@ -0,0 +1,10 @@
+// RUN: clang -E %s | grep -F "1: F, (, 'a', 'b', );" &&
+// RUN: clang -E %s | grep -F "2: 'a' + 'b';"
+#define LPAREN ( 
+#define RPAREN ) 
+#define F(x, y) x + y 
+#define ELLIP_FUNC(...) __VA_ARGS__ 
+
+1: ELLIP_FUNC(F, LPAREN, 'a', 'b', RPAREN); /* 1st invocation */ 
+2: ELLIP_FUNC(F LPAREN 'a', 'b' RPAREN); /* 2nd invocation */ 
+
diff --git a/test/Preprocessor/macro_rparen_scan.c b/test/Preprocessor/macro_rparen_scan.c
new file mode 100644
index 0000000..d4e6283
--- /dev/null
+++ b/test/Preprocessor/macro_rparen_scan.c
@@ -0,0 +1,8 @@
+// RUN: clang -E %s | grep '^3 ;$'
+
+/* Right paren scanning, hard case.  Should expand to 3. */
+#define i(x) 3 
+#define a i(yz 
+#define b ) 
+a b ) ; 
+
diff --git a/test/Preprocessor/macro_rparen_scan2.c b/test/Preprocessor/macro_rparen_scan2.c
new file mode 100644
index 0000000..99545e7
--- /dev/null
+++ b/test/Preprocessor/macro_rparen_scan2.c
@@ -0,0 +1,8 @@
+// clang -E %s | grep -F 'static int glob = (1 + 1 );'
+
+#define R_PAREN ) 
+
+#define FUNC(a) a 
+
+static int glob = (1 + FUNC(1 R_PAREN ); 
+
diff --git a/test/Preprocessor/macro_space.c b/test/Preprocessor/macro_space.c
new file mode 100644
index 0000000..553fddb
--- /dev/null
+++ b/test/Preprocessor/macro_space.c
@@ -0,0 +1,5 @@
+// RUN: clang %s -E | grep '! ,'
+
+#define XX
+! XX,
+
diff --git a/test/Preprocessor/output_paste_avoid.c b/test/Preprocessor/output_paste_avoid.c
new file mode 100644
index 0000000..842063a
--- /dev/null
+++ b/test/Preprocessor/output_paste_avoid.c
@@ -0,0 +1,12 @@
+// RUN: clang -E %s | grep '+ + - - + + = = =' &&
+// RUN: clang -E %s | not grep -F '...'
+
+// This should print as ".. ." to avoid turning into ...
+#define y(a) ..a
+y(.)
+
+#define PLUS +
+#define EMPTY
+#define f(x) =x=
++PLUS -EMPTY- PLUS+ f(=)
+
diff --git a/test/Preprocessor/paste_bad.c b/test/Preprocessor/paste_bad.c
new file mode 100644
index 0000000..89e8799
--- /dev/null
+++ b/test/Preprocessor/paste_bad.c
@@ -0,0 +1,17 @@
+// GCC PR 20077
+// RUN: not clang -E %s &&
+// RUN: not clang -E %s 2>&1 | grep error: | wc -l | grep 10
+
+#define a   a ## ## /* { dg-error "end of a macro expansion" } */
+#define b() b ## ## /* { dg-error "end of a macro expansion" } */
+#define c   c ##    /* { dg-error "end of a macro expansion" } */
+#define d() d ##    /* { dg-error "end of a macro expansion" } */
+
+
+#define e   ## ## e /* { dg-error "end of a macro expansion" } */
+#define f() ## ## f /* { dg-error "end of a macro expansion" } */
+#define g   ## g    /* { dg-error "end of a macro expansion" } */
+#define h() ## h    /* { dg-error "end of a macro expansion" } */
+#define i   ##      /* { dg-error "end of a macro expansion" } */
+#define j() ##      /* { dg-error "end of a macro expansion" } */
+
diff --git a/test/Preprocessor/poison.c b/test/Preprocessor/poison.c
new file mode 100644
index 0000000..5df4b47
--- /dev/null
+++ b/test/Preprocessor/poison.c
@@ -0,0 +1,4 @@
+// RUN: clang %s -E 2>&1 | grep error
+
+#pragma GCC poison rindex
+rindex(some_string, 'h');
diff --git a/test/Preprocessor/poison_expansion.c b/test/Preprocessor/poison_expansion.c
new file mode 100644
index 0000000..3444bac
--- /dev/null
+++ b/test/Preprocessor/poison_expansion.c
@@ -0,0 +1,9 @@
+// RUN: clang %s -E 2>&1 | not grep error
+
+#define strrchr rindex
+#pragma GCC poison rindex
+
+// Can poison multiple times.
+#pragma GCC poison rindex
+
+strrchr(some_string, 'h');
diff --git a/test/Preprocessor/pragma_unknown.c b/test/Preprocessor/pragma_unknown.c
new file mode 100644
index 0000000..ca2bea1
--- /dev/null
+++ b/test/Preprocessor/pragma_unknown.c
@@ -0,0 +1,6 @@
+// RUN: clang -E %s | grep '#pragma foo bar'
+
+// GCC doesn't expand macro args for unrecognized pragmas.
+#define bar xX
+#pragma foo bar
+
diff --git a/test/Preprocessor/stringize_misc.c b/test/Preprocessor/stringize_misc.c
new file mode 100644
index 0000000..b8e4480
--- /dev/null
+++ b/test/Preprocessor/stringize_misc.c
@@ -0,0 +1,26 @@
+// RUN: clang -E %s | grep -F '"f(1, 2)" "g((x=y++, y))"' &&
+// RUN: clang -E %s | grep -F '"{a=1" "b=2;}"' &&
+// RUN: clang -E %s | grep -F '"<" "["' &&
+// RUN: clang -E %s | grep -F '"(,)" "(...)"' &&
+// RUN: clang -E %s | grep -F '{a=1 c=3; b=2;}' &&
+// RUN: clang -E %s | grep -F '"a COMMA b" "(a, b)"'
+
+#define M(x, y) #x #y
+
+M( f(1, 2), g((x=y++, y))) 
+M( {a=1 , b=2;} ) /* A semicolon is not a comma */ 
+M( <, [ ) /* Passes the arguments < and [ */ 
+M( (,), (...) ) /* Passes the arguments (,) and (...) */ 
+
+#define START_END(start, end) start c=3; end 
+
+START_END( {a=1 , b=2;} ) /* braces are not parentheses */ 
+
+/* 
+ * To pass a comma token as an argument it is 
+ * necessary to write: 
+ */ 
+#define COMMA , 
+ 
+M(a COMMA b, (a, b)) 
+
diff --git a/test/Preprocessor/stringize_space.c b/test/Preprocessor/stringize_space.c
new file mode 100644
index 0000000..8c83677
--- /dev/null
+++ b/test/Preprocessor/stringize_space.c
@@ -0,0 +1,4 @@
+// RUN: clang -E %s | grep -- '-"" , - "" , -"" , - ""'
+
+#define A(b) -#b  ,  - #b  ,  -# b  ,  - # b
+A()
diff --git a/test/Sema/i-c-e1.c b/test/Sema/i-c-e1.c
new file mode 100644
index 0000000..cb4a9a3
--- /dev/null
+++ b/test/Sema/i-c-e1.c
@@ -0,0 +1,5 @@
+// RUN: clang %s -fsyntax-only
+
+void test1(int n, int* p) { *(n ? p : (void *)(7-7)) = 1; }
+void test2(int n, int* p) { *(n ? p : (void *)0) = 1; }
+
diff --git a/test/Sema/implicit-def.c b/test/Sema/implicit-def.c
new file mode 100644
index 0000000..942f091
--- /dev/null
+++ b/test/Sema/implicit-def.c
@@ -0,0 +1,8 @@
+/* RUN: clang -parse-ast %s -std=c89 &&
+ * RUN: not clang -parse-ast %s -std=c99 -pedantic-errors
+ */
+
+int A() {
+  return X();
+}
+
diff --git a/test/Sema/unused-expr.c b/test/Sema/unused-expr.c
new file mode 100644
index 0000000..667f286
--- /dev/null
+++ b/test/Sema/unused-expr.c
@@ -0,0 +1,26 @@
+// RUN: clang -parse-ast-check %s
+
+int foo(int X, int Y);
+
+void bar(volatile int *VP, int *P, int A,
+         _Complex double C, volatile _Complex double VC) {
+  
+  VP == P;             // expected-warning {{expression result unused}}
+  (void)A;             // expected-warning {{expression result unused}}
+  (void)foo(1,2);      // no warning.
+  
+  A == foo(1, 2);      // expected-warning {{expression result unused}}
+
+  foo(1,2)+foo(4,3);   // expected-warning {{expression result unused}}
+
+
+  *P;                  // expected-warning {{expression result unused}}
+  *VP;                 // no warning.
+  P[4];                // expected-warning {{expression result unused}}
+  VP[4];               // no warning.
+
+  // FIXME: SEMA explodes on these.
+  //__real__ C;
+  //__real__ VC;
+}
+
diff --git a/test/Sema/void_arg.c b/test/Sema/void_arg.c
new file mode 100644
index 0000000..b390f59
--- /dev/null
+++ b/test/Sema/void_arg.c
@@ -0,0 +1,21 @@
+/* RUN: clang -parse-ast %s 2>&1 | grep '6 diagnostics'
+ */
+
+typedef void Void;
+
+void foo() {
+  int X;
+  
+  X = sizeof(int (void a));
+  X = sizeof(int (int, void));
+  X = sizeof(int (void, ...));
+
+  X = sizeof(int (Void a));
+  X = sizeof(int (int, Void));
+  X = sizeof(int (Void, ...));
+
+  // Accept these.
+  X = sizeof(int (void));
+  X = sizeof(int (Void));
+}
+
diff --git a/test/TestRunner.sh b/test/TestRunner.sh
new file mode 100755
index 0000000..2c96fd5
--- /dev/null
+++ b/test/TestRunner.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+#  TestRunner.sh - This script is used to run arbitrary unit tests.  Unit
+#  tests must contain the command used to run them in the input file, starting
+#  immediately after a "RUN:" string.
+#
+#  This runner recognizes and replaces the following strings in the command:
+#
+#     %s - Replaced with the input name of the program, or the program to
+#          execute, as appropriate.
+#     %llvmgcc - llvm-gcc command
+#     %llvmgxx - llvm-g++ command
+#     %prcontext - prcontext.tcl script
+#
+
+FILENAME=$1
+TESTNAME=$1
+SUBST=$1
+FILENAME_ONLY=`basename $1`
+OUTPUT=Output/$FILENAME_ONLY.out
+
+# create the output directory if it does not already exist
+mkdir Output > /dev/null 2>&1
+
+if test $# != 1; then
+  # If more than one parameter is passed in, there must be three parameters:
+  # The filename to read from (already processed), the command used to execute,
+  # and the file to output to.
+  SUBST=$2
+  OUTPUT=$3
+  TESTNAME=$3
+fi
+
+ulimit -t 40
+
+SCRIPT=$OUTPUT.script
+grep 'RUN:' $FILENAME | sed "s|^.*RUN:\(.*\)$|\1|g;s|%s|$SUBST|g;s|%llvmgcc|llvm-gcc -emit-llvm|g;s|%llvmgxx|llvm-g++ -emit-llvm|g;s|%prcontext|prcontext.tcl|g" > $SCRIPT
+
+grep -q XFAIL $FILENAME && (printf "XFAILED '$TESTNAME': "; grep XFAIL $FILENAME)
+
+/bin/sh $SCRIPT > $OUTPUT 2>&1 || (
+  echo "******************** TEST '$TESTNAME' FAILED! ********************"
+  echo "Command: "
+  cat $SCRIPT
+  echo "Output:"
+  cat $OUTPUT
+  rm $OUTPUT
+  echo "******************** TEST '$TESTNAME' FAILED! ********************"
+)
+