summaryrefslogtreecommitdiffstats
path: root/test/PCH
diff options
context:
space:
mode:
Diffstat (limited to 'test/PCH')
-rw-r--r--test/PCH/asm.c11
-rw-r--r--test/PCH/asm.h14
-rw-r--r--test/PCH/attrs.c8
-rw-r--r--test/PCH/attrs.h7
-rw-r--r--test/PCH/blocks.c12
-rw-r--r--test/PCH/blocks.h14
-rw-r--r--test/PCH/builtins.c10
-rw-r--r--test/PCH/builtins.h2
-rw-r--r--test/PCH/enum.c15
-rw-r--r--test/PCH/enum.h16
-rw-r--r--test/PCH/exprs.c89
-rw-r--r--test/PCH/exprs.h86
-rw-r--r--test/PCH/ext_vector.c10
-rw-r--r--test/PCH/ext_vector.h4
-rw-r--r--test/PCH/external-defs.c19
-rw-r--r--test/PCH/external-defs.h13
-rw-r--r--test/PCH/functions.c20
-rw-r--r--test/PCH/functions.h6
-rw-r--r--test/PCH/fuzzy-pch.c19
-rw-r--r--test/PCH/fuzzy-pch.h2
-rw-r--r--test/PCH/line-directive.c25
-rw-r--r--test/PCH/line-directive.h2
-rw-r--r--test/PCH/method_pool.h37
-rw-r--r--test/PCH/method_pool.m21
-rw-r--r--test/PCH/multiple_decls.c17
-rw-r--r--test/PCH/multiple_decls.h7
-rw-r--r--test/PCH/nonvisible-external-defs.c10
-rw-r--r--test/PCH/nonvisible-external-defs.h11
-rw-r--r--test/PCH/objc_exprs.h18
-rw-r--r--test/PCH/objc_exprs.m28
-rw-r--r--test/PCH/objc_import.h7
-rw-r--r--test/PCH/objc_import.m15
-rw-r--r--test/PCH/objc_methods.h11
-rw-r--r--test/PCH/objc_methods.m16
-rw-r--r--test/PCH/objc_property.h12
-rw-r--r--test/PCH/objc_property.m11
-rw-r--r--test/PCH/preprocess.c5
-rw-r--r--test/PCH/preprocess.h7
-rw-r--r--test/PCH/stmts.c14
-rw-r--r--test/PCH/stmts.h96
-rw-r--r--test/PCH/struct.c28
-rw-r--r--test/PCH/struct.h29
-rw-r--r--test/PCH/tentative-defs.c9
-rw-r--r--test/PCH/tentative-defs.h9
-rw-r--r--test/PCH/types.c72
-rw-r--r--test/PCH/types.h44
-rw-r--r--test/PCH/va_arg.c12
-rw-r--r--test/PCH/va_arg.h8
-rw-r--r--test/PCH/variables.c23
-rw-r--r--test/PCH/variables.h26
50 files changed, 1007 insertions, 0 deletions
diff --git a/test/PCH/asm.c b/test/PCH/asm.c
new file mode 100644
index 0000000..bff271de
--- /dev/null
+++ b/test/PCH/asm.c
@@ -0,0 +1,11 @@
+// Test this without pch.
+// RUN: clang-cc -triple i386-unknown-unknown -include %S/asm.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -triple i386-unknown-unknown -emit-pch -o %t %S/asm.h &&
+// RUN: clang-cc -triple i386-unknown-unknown -include-pch %t -fsyntax-only -verify %s
+
+
+void call_f(void) { f(); }
+
+void call_clobbers(void) { clobbers(); }
diff --git a/test/PCH/asm.h b/test/PCH/asm.h
new file mode 100644
index 0000000..a568058
--- /dev/null
+++ b/test/PCH/asm.h
@@ -0,0 +1,14 @@
+// Header for the PCH test asm.c
+
+void f() {
+ int i;
+
+ asm ("foo\n" : : "a" (i + 2));
+ asm ("foo\n" : [symbolic_name] "=a" (i) : "[symbolic_name]" (i));
+}
+
+void clobbers() {
+ asm ("nop" : : : "ax", "#ax", "%ax");
+ asm ("nop" : : : "eax", "rax", "ah", "al");
+ asm ("nop" : : : "0", "%0", "#0");
+}
diff --git a/test/PCH/attrs.c b/test/PCH/attrs.c
new file mode 100644
index 0000000..1ffb467
--- /dev/null
+++ b/test/PCH/attrs.c
@@ -0,0 +1,8 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/attrs.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/attrs.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+// expected-note{{previous overload}}
+double f(double); // expected-error{{overloadable}}
diff --git a/test/PCH/attrs.h b/test/PCH/attrs.h
new file mode 100644
index 0000000..0d01565
--- /dev/null
+++ b/test/PCH/attrs.h
@@ -0,0 +1,7 @@
+// Header for PCH test exprs.c
+
+
+
+
+
+int f(int) __attribute__((overloadable));
diff --git a/test/PCH/blocks.c b/test/PCH/blocks.c
new file mode 100644
index 0000000..f3efc8a
--- /dev/null
+++ b/test/PCH/blocks.c
@@ -0,0 +1,12 @@
+// Test this without pch.
+// RUN: clang-cc -fblocks -include %S/blocks.h -fsyntax-only -emit-llvm -o - %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -fblocks -o %t %S/blocks.h &&
+// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -emit-llvm -o - %s
+
+int do_add(int x, int y) { return add(x, y); }
+
+int do_scaled_add(int a, int b, int s) {
+ return scaled_add(a, b, s);
+}
diff --git a/test/PCH/blocks.h b/test/PCH/blocks.h
new file mode 100644
index 0000000..af7bb6f
--- /dev/null
+++ b/test/PCH/blocks.h
@@ -0,0 +1,14 @@
+// Header for PCH test blocks.c
+
+int call_block(int (^bl)(int x, int y), int a, int b) {
+ return bl(a, b);
+}
+
+int add(int a, int b) {
+ return call_block(^(int x, int y) { return x + y; }, a, b);
+}
+
+int scaled_add(int a, int b, int s) {
+ __block int scale = s;
+ return call_block(^(int x, int y) { return x*scale + y; }, a, b);
+}
diff --git a/test/PCH/builtins.c b/test/PCH/builtins.c
new file mode 100644
index 0000000..3d1786b
--- /dev/null
+++ b/test/PCH/builtins.c
@@ -0,0 +1,10 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/builtins.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/builtins.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+void hello() {
+ printf("Hello, World!");
+}
diff --git a/test/PCH/builtins.h b/test/PCH/builtins.h
new file mode 100644
index 0000000..56e4a53
--- /dev/null
+++ b/test/PCH/builtins.h
@@ -0,0 +1,2 @@
+// Header for PCH test builtins.c
+int printf(char const *, ...);
diff --git a/test/PCH/enum.c b/test/PCH/enum.c
new file mode 100644
index 0000000..45b0491
--- /dev/null
+++ b/test/PCH/enum.c
@@ -0,0 +1,15 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/enum.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/enum.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+int i = Red;
+
+int return_enum_constant() {
+ int result = aRoundShape;
+ return result;
+}
+
+enum Shape s = Triangle;
diff --git a/test/PCH/enum.h b/test/PCH/enum.h
new file mode 100644
index 0000000..7dc4e63
--- /dev/null
+++ b/test/PCH/enum.h
@@ -0,0 +1,16 @@
+/* Used in enum.c test */
+
+enum Color {
+ Red,
+ Green,
+ Blue
+};
+
+enum Shape {
+ Square,
+ Triangle = 17,
+ Rhombus,
+ Circle
+};
+
+enum Shape aRoundShape = Circle;
diff --git a/test/PCH/exprs.c b/test/PCH/exprs.c
new file mode 100644
index 0000000..c8e6d1d
--- /dev/null
+++ b/test/PCH/exprs.c
@@ -0,0 +1,89 @@
+// Test this without pch.
+// RUN: clang-cc -fblocks -include %S/exprs.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -fblocks -o %t %S/exprs.h &&
+// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -verify %s
+
+int integer;
+long long_integer;
+double floating;
+_Complex double floating_complex;
+
+// DeclRefExpr
+int_decl_ref *int_ptr1 = &integer;
+enum_decl_ref *enum_ptr1 = &integer;
+
+// IntegerLiteral
+integer_literal *int_ptr2 = &integer;
+long_literal *long_ptr1 = &long_integer;
+
+// FloatingLiteral + ParenExpr
+floating_literal *double_ptr = &floating;
+
+// ImaginaryLiteral
+imaginary_literal *cdouble_ptr = &floating_complex;
+
+// StringLiteral
+const char* printHello() {
+ return hello;
+}
+
+// CharacterLiteral
+char_literal *int_ptr3 = &integer;
+
+// UnaryOperator
+negate_enum *int_ptr4 = &integer;
+
+// SizeOfAlignOfExpr
+typeof(sizeof(float)) size_t_value;
+typeof_sizeof *size_t_ptr = &size_t_value;
+typeof_sizeof2 *size_t_ptr2 = &size_t_value;
+
+// ArraySubscriptExpr
+array_subscript *double_ptr1_5 = &floating;
+
+// CallExpr
+call_returning_double *double_ptr2 = &floating;
+
+// MemberExpr
+member_ref_double *double_ptr3 = &floating;
+
+// BinaryOperator
+add_result *int_ptr5 = &integer;
+
+// CompoundAssignOperator
+addeq_result *int_ptr6 = &integer;
+
+// ConditionalOperator
+conditional_operator *double_ptr4 = &floating;
+
+// CStyleCastExpr
+void_ptr vp1 = &integer;
+
+// CompoundLiteral
+struct S s;
+compound_literal *sptr = &s;
+
+// ExtVectorElementExpr
+ext_vector_element *double_ptr5 = &floating;
+
+// InitListExpr
+double get_from_double_array(unsigned Idx) { return double_array[Idx]; }
+
+/// DesignatedInitExpr
+float get_from_designated(unsigned Idx) {
+ return designated_inits[2].y;
+}
+
+// TypesCompatibleExpr
+types_compatible *int_ptr7 = &integer;
+
+// ChooseExpr
+choose_expr *int_ptr8 = &integer;
+
+// GNUNullExpr FIXME: needs C++
+//null_type null = __null;
+
+// ShuffleVectorExpr
+shuffle_expr *vec_ptr = &vec2;
diff --git a/test/PCH/exprs.h b/test/PCH/exprs.h
new file mode 100644
index 0000000..7012422
--- /dev/null
+++ b/test/PCH/exprs.h
@@ -0,0 +1,86 @@
+// Header for PCH test exprs.c
+
+// DeclRefExpr
+int i = 17;
+enum Enum { Enumerator = 18 };
+typedef typeof(i) int_decl_ref;
+typedef typeof(Enumerator) enum_decl_ref;
+
+// IntegerLiteral
+typedef typeof(17) integer_literal;
+typedef typeof(17l) long_literal;
+
+// FloatingLiteral and ParenExpr
+typedef typeof((42.5)) floating_literal;
+
+// ImaginaryLiteral
+typedef typeof(17.0i) imaginary_literal;
+
+// StringLiteral
+const char *hello = "Hello" "PCH" "World";
+
+// CharacterLiteral
+typedef typeof('a') char_literal;
+
+// UnaryOperator
+typedef typeof(-Enumerator) negate_enum;
+
+// SizeOfAlignOfExpr
+typedef typeof(sizeof(int)) typeof_sizeof;
+typedef typeof(sizeof(Enumerator)) typeof_sizeof2;
+
+// ArraySubscriptExpr
+extern double values[];
+typedef typeof(values[2]) array_subscript;
+
+// CallExpr
+double dplus(double x, double y);
+double d0, d1;
+typedef typeof((&dplus)(d0, d1)) call_returning_double;
+
+// MemberExpr
+struct S {
+ double x;
+};
+typedef typeof(((struct S*)0)->x) member_ref_double;
+
+// BinaryOperator
+typedef typeof(i + Enumerator) add_result;
+
+// CompoundAssignOperator
+typedef typeof(i += Enumerator) addeq_result;
+
+// ConditionalOperator
+typedef typeof(i? : d0) conditional_operator;
+
+// CStyleCastExpr
+typedef typeof((void *)0) void_ptr;
+
+// CompoundLiteral
+typedef typeof((struct S){.x = 3.5}) compound_literal;
+
+// ExtVectorElementExpr
+typedef __attribute__(( ext_vector_type(2) )) double double2;
+extern double2 vec2, vec2b;
+typedef typeof(vec2.x) ext_vector_element;
+
+// InitListExpr
+double double_array[3] = { 1.0, 2.0 };
+
+// DesignatedInitExpr
+struct {
+ int x;
+ float y;
+} designated_inits[3] = { [0].y = 17, [2].x = 12.3, 3.5 };
+
+// TypesCompatibleExpr
+typedef typeof(__builtin_types_compatible_p(float, double)) types_compatible;
+
+// ChooseExpr
+typedef typeof(__builtin_choose_expr(17 > 19, d0, 1)) choose_expr;
+
+// GNUNullExpr FIXME: needs C++
+// typedef typeof(__null) null_type;
+
+// ShuffleVectorExpr
+typedef typeof(__builtin_shufflevector(vec2, vec2b, 2, 1)) shuffle_expr;
diff --git a/test/PCH/ext_vector.c b/test/PCH/ext_vector.c
new file mode 100644
index 0000000..4b5c259
--- /dev/null
+++ b/test/PCH/ext_vector.c
@@ -0,0 +1,10 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/ext_vector.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/ext_vector.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+int test(float4 f4) {
+ return f4.xy; // expected-error{{float2}}
+}
diff --git a/test/PCH/ext_vector.h b/test/PCH/ext_vector.h
new file mode 100644
index 0000000..39ab923
--- /dev/null
+++ b/test/PCH/ext_vector.h
@@ -0,0 +1,4 @@
+// Header file for ext_vector.c PCH test
+
+typedef __attribute__((ext_vector_type(2))) float float2;
+typedef __attribute__((ext_vector_type(4))) float float4;
diff --git a/test/PCH/external-defs.c b/test/PCH/external-defs.c
new file mode 100644
index 0000000..b7eb700
--- /dev/null
+++ b/test/PCH/external-defs.c
@@ -0,0 +1,19 @@
+// Test with pch.
+// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/external-defs.h &&
+// RUN: clang-cc -triple x86_64-apple-darwin9 -include-pch %t.pch -emit-llvm -o %t %s &&
+
+// RUN: grep "@x = common global i32 0" %t | count 1 &&
+// RUN: grep "@z" %t | count 0 &&
+
+// RUN: grep "@x2 = global i32 19" %t | count 1 &&
+int x2 = 19;
+
+// RUN: grep "@incomplete_array = common global .*1 x i32" %t | count 1 &&
+// RUN: grep "@incomplete_array2 = common global .*17 x i32" %t | count 1 &&
+int incomplete_array2[17];
+// RUN: grep "@incomplete_array3 = common global .*1 x i32" %t | count 1
+int incomplete_array3[];
+
+struct S {
+ int x, y;
+};
diff --git a/test/PCH/external-defs.h b/test/PCH/external-defs.h
new file mode 100644
index 0000000..657b47b
--- /dev/null
+++ b/test/PCH/external-defs.h
@@ -0,0 +1,13 @@
+// Helper for external-defs.c test
+
+// Tentative definitions
+int x;
+int x2;
+
+// Should not show up
+static int z;
+
+int incomplete_array[];
+int incomplete_array2[];
+
+struct S s;
diff --git a/test/PCH/functions.c b/test/PCH/functions.c
new file mode 100644
index 0000000..6d3c5a0
--- /dev/null
+++ b/test/PCH/functions.c
@@ -0,0 +1,20 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/functions.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/functions.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+int f0(int x0, int y0, ...) { return x0 + y0; }
+
+float *test_f1(int val, double x, double y) {
+ if (val > 5)
+ return f1(x, y);
+ else
+ return f1(x); // expected-error{{too few arguments to function call}}
+}
+
+void test_g0(int *x, float * y) {
+ g0(y); // expected-warning{{incompatible pointer types passing 'float *', expected 'int *'}}
+ g0(x);
+}
diff --git a/test/PCH/functions.h b/test/PCH/functions.h
new file mode 100644
index 0000000..bc28ad7
--- /dev/null
+++ b/test/PCH/functions.h
@@ -0,0 +1,6 @@
+/* For use with the functions.c test */
+
+int f0(int x, int y, ...);
+float *f1(float x, float y);
+
+void g0(int *);
diff --git a/test/PCH/fuzzy-pch.c b/test/PCH/fuzzy-pch.c
new file mode 100644
index 0000000..2ddcb8b
--- /dev/null
+++ b/test/PCH/fuzzy-pch.c
@@ -0,0 +1,19 @@
+// Test with pch.
+// RUN: clang-cc -emit-pch -DFOO -o %t %S/variables.h &&
+// RUN: clang-cc -DBAR=int -include-pch %t -fsyntax-only -pedantic %s &&
+// RUN: clang-cc -DFOO -DBAR=int -include-pch %t -Werror %s &&
+// RUN: not clang-cc -DFOO -DBAR=int -DX=5 -include-pch %t -Werror %s
+
+BAR bar = 17;
+
+#ifndef FOO
+# error FOO was not defined
+#endif
+
+#if FOO != 1
+# error FOO has the wrong definition
+#endif
+
+#ifndef BAR
+# error BAR was not defined
+#endif
diff --git a/test/PCH/fuzzy-pch.h b/test/PCH/fuzzy-pch.h
new file mode 100644
index 0000000..9eb1005
--- /dev/null
+++ b/test/PCH/fuzzy-pch.h
@@ -0,0 +1,2 @@
+// Header for PCH test fuzzy-pch.c
+void f(int X);
diff --git a/test/PCH/line-directive.c b/test/PCH/line-directive.c
new file mode 100644
index 0000000..53edb3c
--- /dev/null
+++ b/test/PCH/line-directive.c
@@ -0,0 +1,25 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/line-directive.h -fsyntax-only %s 2>&1|grep "25:5" &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/line-directive.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only %s 2>&1|grep "25:5"
+
+double x; // expected-error{{redefinition of 'x' with a different type}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// expected-note{{previous definition is here}}
diff --git a/test/PCH/line-directive.h b/test/PCH/line-directive.h
new file mode 100644
index 0000000..c5594b4
--- /dev/null
+++ b/test/PCH/line-directive.h
@@ -0,0 +1,2 @@
+#line 25 "line-directive.c"
+int x;
diff --git a/test/PCH/method_pool.h b/test/PCH/method_pool.h
new file mode 100644
index 0000000..f7af904
--- /dev/null
+++ b/test/PCH/method_pool.h
@@ -0,0 +1,37 @@
+/* For use with the method_pool.m test */
+
+/* Whitespace below is significant */
+
+
+
+
+
+
+
+
+
+
+
+@interface TestMethodPool1
++ alloc;
+- (double)instMethod:(int)foo;
+@end
+
+@interface TestMethodPool2
+- (char)instMethod:(int)foo;
+@end
+
+@implementation TestMethodPool1
++ alloc {
+}
+
+- (double)instMethod:(int)foo {
+ return foo;
+}
+@end
+
+@implementation TestMethodPool2
+- (char)instMethod:(int)foo {
+ return foo;
+}
+@end
diff --git a/test/PCH/method_pool.m b/test/PCH/method_pool.m
new file mode 100644
index 0000000..8dd7834
--- /dev/null
+++ b/test/PCH/method_pool.m
@@ -0,0 +1,21 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/method_pool.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -x=objective-c -emit-pch -o %t %S/method_pool.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+int message_id(id x) {
+ return [x instMethod:17]; // expected-warning{{multiple methods}}
+}
+
+
+
+
+
+/* Whitespace below is significant */
+/* expected-note{{using}} */
+
+
+
+/* expected-note{{also}} */
diff --git a/test/PCH/multiple_decls.c b/test/PCH/multiple_decls.c
new file mode 100644
index 0000000..4b2fc62
--- /dev/null
+++ b/test/PCH/multiple_decls.c
@@ -0,0 +1,17 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/multiple_decls.h -fsyntax-only -ast-print -o - %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/multiple_decls.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -ast-print -o - %s
+
+void f0(char c) {
+ wide(c);
+}
+
+struct wide w;
+struct narrow n;
+
+void f1(int i) {
+ narrow(i);
+}
diff --git a/test/PCH/multiple_decls.h b/test/PCH/multiple_decls.h
new file mode 100644
index 0000000..23696b0
--- /dev/null
+++ b/test/PCH/multiple_decls.h
@@ -0,0 +1,7 @@
+// Header for PCH test multiple_decls.c
+
+struct wide { int value; };
+int wide(char);
+
+struct narrow { char narrow; };
+char narrow(int);
diff --git a/test/PCH/nonvisible-external-defs.c b/test/PCH/nonvisible-external-defs.c
new file mode 100644
index 0000000..bfe5cca
--- /dev/null
+++ b/test/PCH/nonvisible-external-defs.c
@@ -0,0 +1,10 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/nonvisible-external-defs.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/nonvisible-external-defs.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+int g(int, float); // expected-error{{conflicting types}}
+
+// expected-note{{previous declaration}}
diff --git a/test/PCH/nonvisible-external-defs.h b/test/PCH/nonvisible-external-defs.h
new file mode 100644
index 0000000..a36fc2e
--- /dev/null
+++ b/test/PCH/nonvisible-external-defs.h
@@ -0,0 +1,11 @@
+// Helper for PCH test nonvisible-external-defs.h
+
+
+
+
+
+
+
+void f() {
+ extern int g(int, int);
+}
diff --git a/test/PCH/objc_exprs.h b/test/PCH/objc_exprs.h
new file mode 100644
index 0000000..b811430
--- /dev/null
+++ b/test/PCH/objc_exprs.h
@@ -0,0 +1,18 @@
+
+@protocol foo;
+@class itf;
+
+// Expressions
+typedef typeof(@"foo" "bar") objc_string;
+typedef typeof(@encode(int)) objc_encode;
+typedef typeof(@protocol(foo)) objc_protocol;
+typedef typeof(@selector(noArgs)) objc_selector_noArgs;
+typedef typeof(@selector(oneArg:)) objc_selector_oneArg;
+typedef typeof(@selector(foo:bar:)) objc_selector_twoArg;
+
+
+// Types.
+typedef typeof(id<foo>) objc_id_protocol_ty;
+
+typedef typeof(itf*) objc_interface_ty;
+typedef typeof(itf<foo>*) objc_qual_interface_ty;
diff --git a/test/PCH/objc_exprs.m b/test/PCH/objc_exprs.m
new file mode 100644
index 0000000..eb1ae43
--- /dev/null
+++ b/test/PCH/objc_exprs.m
@@ -0,0 +1,28 @@
+// Test this without pch.
+// RUN: clang-cc -fblocks -include %S/objc_exprs.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -x objective-c-header -emit-pch -fblocks -o %t %S/objc_exprs.h &&
+// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -verify %s
+
+// Expressions
+int *A1 = (objc_string)0; // expected-warning {{'struct objc_object *'}}
+
+char A2 = (objc_encode){}; // expected-error {{not a compile-time constant}} \
+ expected-warning {{char [2]}}
+
+int *A3 = (objc_protocol)0; // expected-warning {{aka 'Protocol *'}}
+
+
+// Types.
+int *T0 = (objc_id_protocol_ty)0; // expected-error {{not a compile-time constant}} \
+ expected-warning {{aka 'id<foo>'}}
+
+int *T1 = (objc_interface_ty)0; // expected-warning {{aka 'itf *'}}
+int *T2 = (objc_qual_interface_ty)0; // expected-warning {{aka 'itf<foo> *'}}
+
+objc_selector_noArgs s1;
+objc_selector_oneArg s2;
+objc_selector_twoArg s3;
+
+
diff --git a/test/PCH/objc_import.h b/test/PCH/objc_import.h
new file mode 100644
index 0000000..8af87ab
--- /dev/null
+++ b/test/PCH/objc_import.h
@@ -0,0 +1,7 @@
+/* For use with the objc_import.m test */
+
+@interface TestPCH
++ alloc;
+- (void)instMethod;
+@end
+
diff --git a/test/PCH/objc_import.m b/test/PCH/objc_import.m
new file mode 100644
index 0000000..86c1c25
--- /dev/null
+++ b/test/PCH/objc_import.m
@@ -0,0 +1,15 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/objc_import.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -x=objective-c -emit-pch -o %t %S/objc_import.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+#import "objc_import.h"
+
+void func() {
+ TestPCH *xx;
+
+ xx = [TestPCH alloc];
+ [xx instMethod];
+}
diff --git a/test/PCH/objc_methods.h b/test/PCH/objc_methods.h
new file mode 100644
index 0000000..4c6b1e1
--- /dev/null
+++ b/test/PCH/objc_methods.h
@@ -0,0 +1,11 @@
+/* For use with the methods.m test */
+
+@interface TestPCH
++ alloc;
+- (void)instMethod;
+@end
+
+@class TestForwardClassDecl;
+
+// FIXME: @compatibility_alias AliasForTestPCH TestPCH;
+
diff --git a/test/PCH/objc_methods.m b/test/PCH/objc_methods.m
new file mode 100644
index 0000000..1a198b1
--- /dev/null
+++ b/test/PCH/objc_methods.m
@@ -0,0 +1,16 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/objc_methods.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -x=objective-c -emit-pch -o %t %S/objc_methods.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+void func() {
+ TestPCH *xx;
+ TestForwardClassDecl *yy;
+// FIXME:
+// AliasForTestPCH *zz;
+
+ xx = [TestPCH alloc];
+ [xx instMethod];
+}
diff --git a/test/PCH/objc_property.h b/test/PCH/objc_property.h
new file mode 100644
index 0000000..2432370
--- /dev/null
+++ b/test/PCH/objc_property.h
@@ -0,0 +1,12 @@
+/* For use with the objc_property.m PCH test */
+@interface TestProperties
+{
+ int value;
+ float percentage;
+}
+
++ alloc;
+
+@property int value;
+@property float percentage;
+@end
diff --git a/test/PCH/objc_property.m b/test/PCH/objc_property.m
new file mode 100644
index 0000000..5cf6de7
--- /dev/null
+++ b/test/PCH/objc_property.m
@@ -0,0 +1,11 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/objc_property.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -x=objective-c -emit-pch -o %t %S/objc_property.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+void func() {
+ TestProperties *xx = [TestProperties alloc];
+ xx.value = 5;
+}
diff --git a/test/PCH/preprocess.c b/test/PCH/preprocess.c
new file mode 100644
index 0000000..128cc0a
--- /dev/null
+++ b/test/PCH/preprocess.c
@@ -0,0 +1,5 @@
+// RUN: clang-cc -emit-pch -o %t %S/preprocess.h &&
+// RUN: clang-cc -include-pch %t -E -o - %s | grep -c "a_typedef" | count 1
+#include "preprocess.h"
+
+int a_value;
diff --git a/test/PCH/preprocess.h b/test/PCH/preprocess.h
new file mode 100644
index 0000000..39fa006
--- /dev/null
+++ b/test/PCH/preprocess.h
@@ -0,0 +1,7 @@
+// Helper header for preprocess.c PCH test
+#ifndef PREPROCESS_H
+#define PREPROCESS_H
+
+typedef int a_typedef;
+
+#endif // PREPROCESS_H
diff --git a/test/PCH/stmts.c b/test/PCH/stmts.c
new file mode 100644
index 0000000..0d906f2
--- /dev/null
+++ b/test/PCH/stmts.c
@@ -0,0 +1,14 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/stmts.h -fsyntax-only -emit-llvm -o - %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/stmts.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -emit-llvm -o - %s
+
+void g0(void) { f0(5); }
+int g1(int x) { return f1(x); }
+const char* query_name(void) { return what_is_my_name(); }
+
+int use_computed_goto(int x) { return computed_goto(x); }
+
+int get_weird_max(int x, int y) { return weird_max(x, y); }
diff --git a/test/PCH/stmts.h b/test/PCH/stmts.h
new file mode 100644
index 0000000..4267e2c
--- /dev/null
+++ b/test/PCH/stmts.h
@@ -0,0 +1,96 @@
+// Header for PCH test stmts.c
+
+void f0(int x) {
+ // NullStmt
+ ;
+ // IfStmt
+ if (x) {
+ } else if (x + 1) {
+ }
+
+ switch (x) {
+ case 0:
+ x = 17;
+ break;
+
+ case 1:
+ break;
+
+ default:
+ switch (x >> 1) {
+ case 7:
+ // fall through
+ case 9:
+ break;
+ }
+ x += 2;
+ break;
+ }
+
+ while (x > 20) {
+ if (x > 30) {
+ --x;
+ continue;
+ } else if (x < 5)
+ break;
+ else
+ goto done;
+ }
+
+ do {
+ x++;
+ } while (x < 10);
+
+ almost_done:
+ for (int y = x; y < 20; ++y) {
+ if (x + y == 12)
+ return;
+ else if (x - y == 7)
+ goto almost_done;
+ }
+
+ done:
+ x = x + 2;
+
+ int z = x, *y, j = 5;
+}
+
+int f1(int x) {
+ switch (x) {
+ case 17:
+ return 12;
+
+ default:
+ break;
+ }
+
+ // variable-length array
+ int array[x * 17 + 3];
+
+ return x*2;
+}
+
+const char* what_is_my_name(void) { return __func__; }
+
+int computed_goto(int x) {
+ start:
+ x = x << 1;
+ void *location = &&start;
+
+ if (x > 17)
+ location = &&done;
+
+ while (x > 12) {
+ --x;
+ if (x == 15)
+ goto *location;
+ }
+
+ done:
+ return 5;
+}
+
+#define maxint(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
+int weird_max(int x, int y) {
+ return maxint(++x, --y);
+}
diff --git a/test/PCH/struct.c b/test/PCH/struct.c
new file mode 100644
index 0000000..f1e2811
--- /dev/null
+++ b/test/PCH/struct.c
@@ -0,0 +1,28 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/struct.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/struct.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+struct Point *p1;
+
+float getX(struct Point *p1) {
+ return p1->x;
+}
+
+void *get_fun_ptr() {
+ return fun->is_ptr? fun->ptr : 0;
+}
+
+struct Fun2 {
+ int very_fun;
+};
+
+int get_very_fun() {
+ return fun2->very_fun;
+}
+
+int *int_ptr_fail = &fun->is_ptr; // expected-error{{address of bit-field requested}}
+
+struct Nested nested = { 1, 2 };
diff --git a/test/PCH/struct.h b/test/PCH/struct.h
new file mode 100644
index 0000000..2ffdd4a
--- /dev/null
+++ b/test/PCH/struct.h
@@ -0,0 +1,29 @@
+// Used with the struct.c test
+
+struct Point {
+ float x, y, z;
+};
+
+struct Point2 {
+ float xValue, yValue, zValue;
+};
+
+struct Fun;
+
+struct Fun *fun;
+
+struct Fun {
+ int is_ptr : 1;
+
+ union {
+ void *ptr;
+ int *integer;
+ };
+};
+
+struct Fun2;
+struct Fun2 *fun2;
+
+struct S {
+ struct Nested { int x, y; } nest;
+};
diff --git a/test/PCH/tentative-defs.c b/test/PCH/tentative-defs.c
new file mode 100644
index 0000000..980cfab
--- /dev/null
+++ b/test/PCH/tentative-defs.c
@@ -0,0 +1,9 @@
+// Test with pch.
+// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/tentative-defs.h &&
+// RUN: clang-cc -triple x86_64-apple-darwin9 -include-pch %t.pch -verify -emit-llvm -o %t %s &&
+
+// RUN: grep "@variable = common global i32 0" %t | count 1 &&
+// RUN: grep "@incomplete_array = common global .*1 x i32" %t | count 1
+
+
+// FIXME: tentative-defs.h expected-warning{{tentative}}
diff --git a/test/PCH/tentative-defs.h b/test/PCH/tentative-defs.h
new file mode 100644
index 0000000..4675d9a
--- /dev/null
+++ b/test/PCH/tentative-defs.h
@@ -0,0 +1,9 @@
+// Header for PCH test tentative-defs.c
+int variable;
+
+
+
+
+
+
+int incomplete_array[];
diff --git a/test/PCH/types.c b/test/PCH/types.c
new file mode 100644
index 0000000..c111c9e
--- /dev/null
+++ b/test/PCH/types.c
@@ -0,0 +1,72 @@
+// Test this without pch.
+// RUN: clang-cc -fblocks -include %S/types.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -fblocks -o %t %S/types.h &&
+// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -verify %s
+
+typedef int INT;
+INT int_value;
+
+__attribute__((address_space(1))) int int_as_one;
+
+// TYPE_EXT_QUAL
+ASInt *as_int_ptr1 = &int_value; // expected-error{{different address spaces}} \
+ // FIXME: expected-warning{{discards qualifiers}}
+ASInt *as_int_ptr2 = &int_as_one;
+
+// FIXME: TYPE_FIXED_WIDTH_INT
+
+// TYPE_COMPLEX
+_Complex float Cfloat_val;
+Cfloat *Cfloat_ptr = &Cfloat_val;
+
+// TYPE_POINTER
+int_ptr int_value_ptr = &int_value;
+
+// TYPE_BLOCK_POINTER
+void test_block_ptr(Block *bl) {
+ *bl = ^(int x, float f) { return x; };
+}
+
+// TYPE_CONSTANT_ARRAY
+five_ints fvi = { 1, 2, 3, 4, 5 };
+
+// TYPE_INCOMPLETE_ARRAY
+float_array fa1 = { 1, 2, 3 };
+float_array fa2 = { 1, 2, 3, 4, 5, 6, 7, 8 };
+
+// TYPE_VARIABLE_ARRAY in stmts.[ch]
+
+// TYPE_VECTOR
+float4 f4 = { 1.0, 2.0, 3.0, 4.0 };
+
+// TYPE_EXT_VECTOR
+ext_float4 ef4 = { 1.0, 2.0, 3.0, 4.0 };
+
+// TYPE_FUNCTION_NO_PROTO
+noproto np1;
+int np1(x, y)
+ int x;
+ float y;
+{
+ return x;
+}
+
+// TYPE_FUNCTION_PROTO
+proto p1;
+float p1(float x, float y, ...) {
+ return x + y;
+}
+proto *p2 = p1;
+
+// TYPE_TYPEDEF
+int_ptr_ptr ipp = &int_value_ptr;
+
+// TYPE_TYPEOF_EXPR
+typeof_17 *t17 = &int_value;
+struct S { int x, y; };
+typeof_17 t17_2 = (struct S){1, 2}; // expected-error{{incompatible type initializing}}
+
+// TYPE_TYPEOF
+int_ptr_ptr2 ipp2 = &int_value_ptr;
diff --git a/test/PCH/types.h b/test/PCH/types.h
new file mode 100644
index 0000000..df9f5c8
--- /dev/null
+++ b/test/PCH/types.h
@@ -0,0 +1,44 @@
+/* Used with the types.c test */
+
+// TYPE_EXT_QUAL
+typedef __attribute__((address_space(1))) int ASInt;
+
+// FIXME: TYPE_FIXED_WIDTH_INT
+
+// TYPE_COMPLEX
+typedef _Complex float Cfloat;
+
+// TYPE_POINTER
+typedef int * int_ptr;
+
+// TYPE_BLOCK_POINTER
+typedef int (^Block)(int, float);
+
+// TYPE_CONSTANT_ARRAY
+typedef int five_ints[5];
+
+// TYPE_INCOMPLETE_ARRAY
+typedef float float_array[];
+
+// TYPE_VARIABLE_ARRAY in stmts.[ch]
+
+// TYPE_VECTOR
+typedef float float4 __attribute__((vector_size(16)));
+
+// TYPE_EXT_VECTOR
+typedef float ext_float4 __attribute__((ext_vector_type(4)));
+
+// TYPE_FUNCTION_NO_PROTO
+typedef int noproto();
+
+// TYPE_FUNCTION_PROTO
+typedef float proto(float, float, ...);
+
+// TYPE_TYPEDEF
+typedef int_ptr * int_ptr_ptr;
+
+// TYPE_TYPEOF_EXPR
+typedef typeof(17) typeof_17;
+
+// TYPE_TYPEOF
+typedef typeof(int_ptr *) int_ptr_ptr2;
diff --git a/test/PCH/va_arg.c b/test/PCH/va_arg.c
new file mode 100644
index 0000000..75cee06
--- /dev/null
+++ b/test/PCH/va_arg.c
@@ -0,0 +1,12 @@
+// Test this without pch.
+// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -include %S/va_arg.h %s -emit-llvm -o - &&
+
+// Test with pch.
+// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -emit-pch -o %t %S/va_arg.h &&
+// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -include-pch %t %s -emit-llvm -o -
+
+char *g0(char** argv, int argc) { return argv[argc]; }
+
+char *g(char **argv) {
+ f(g0, argv, 1, 2, 3);
+}
diff --git a/test/PCH/va_arg.h b/test/PCH/va_arg.h
new file mode 100644
index 0000000..4a8e510
--- /dev/null
+++ b/test/PCH/va_arg.h
@@ -0,0 +1,8 @@
+// Header for PCH test va_arg.c
+
+typedef __builtin_va_list va_list;
+char *f (char * (*g) (char **, int), char **p, ...) {
+ char *s;
+ va_list v;
+ s = g (p, __builtin_va_arg(v, int));
+}
diff --git a/test/PCH/variables.c b/test/PCH/variables.c
new file mode 100644
index 0000000..c988a59
--- /dev/null
+++ b/test/PCH/variables.c
@@ -0,0 +1,23 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/variables.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/variables.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+int *ip2 = &x;
+float *fp = &ip; // expected-warning{{incompatible pointer types}}
+// FIXME:variables.h expected-note{{previous}}
+double z; // expected-error{{redefinition}}
+// FIXME:variables.h expected-note{{previous}}
+int z2 = 18; // expected-error{{redefinition}}
+double VeryHappy; // expected-error{{redefinition}}
+// FIXME:variables.h expected-note{{previous definition is here}}
+
+int Q = A_MACRO_IN_THE_PCH;
+
+int R = FUNCLIKE_MACRO(A_MACRO_, IN_THE_PCH);
+
+
+int UNIQUE(a); // a2
+int *Arr[] = { &a0, &a1, &a2 };
diff --git a/test/PCH/variables.h b/test/PCH/variables.h
new file mode 100644
index 0000000..70aec65
--- /dev/null
+++ b/test/PCH/variables.h
@@ -0,0 +1,26 @@
+// RUN: clang-cc -emit-pch -o variables.h.pch variables.h
+// Do not mess with the whitespace in this file. It's important.
+
+
+
+
+extern float y;
+extern int *ip, x;
+
+float z;
+
+int z2 = 17;
+
+#define MAKE_HAPPY(X) X##Happy
+int MAKE_HAPPY(Very);
+
+#define A_MACRO_IN_THE_PCH 492
+#define FUNCLIKE_MACRO(X, Y) X ## Y
+
+#define PASTE2(x,y) x##y
+#define PASTE1(x,y) PASTE2(x,y)
+#define UNIQUE(x) PASTE1(x,__COUNTER__)
+
+int UNIQUE(a); // a0
+int UNIQUE(a); // a1
+
OpenPOWER on IntegriCloud