diff options
Diffstat (limited to 'test/PCH')
42 files changed, 540 insertions, 82 deletions
diff --git a/test/PCH/Inputs/chain-cxx1.h b/test/PCH/Inputs/chain-cxx1.h deleted file mode 100644 index 7ea3ffb..0000000 --- a/test/PCH/Inputs/chain-cxx1.h +++ /dev/null @@ -1,19 +0,0 @@ -// Primary header for C++ chained PCH test - -void f(); - -// Name not appearing in dependent -void pf(); - -namespace ns { - void g(); - - void pg(); -} - -template <typename T> -struct S { typedef int G; }; - -// Partially specialize -template <typename T> -struct S<T *> { typedef int H; }; diff --git a/test/PCH/Inputs/chain-cxx2.h b/test/PCH/Inputs/chain-cxx2.h deleted file mode 100644 index adc10fd..0000000 --- a/test/PCH/Inputs/chain-cxx2.h +++ /dev/null @@ -1,32 +0,0 @@ -// Dependent header for C++ chained PCH test - -// Overload function from primary -void f(int); - -// Add function with different name -void f2(); - -// Reopen namespace -namespace ns { - // Overload function from primary - void g(int); - - // Add different name - void g2(); -} - -// Specialize template from primary -template <> -struct S<int> { typedef int I; }; - -// Partially specialize -template <typename T> -struct S<T &> { typedef int J; }; - -// Specialize previous partial specialization -template <> -struct S<int *> { typedef int K; }; - -// Specialize the partial specialization from this file -template <> -struct S<int &> { typedef int L; }; diff --git a/test/PCH/Inputs/chain-macro-override1.h b/test/PCH/Inputs/chain-macro-override1.h index 4f9321d..d956396 100644 --- a/test/PCH/Inputs/chain-macro-override1.h +++ b/test/PCH/Inputs/chain-macro-override1.h @@ -2,3 +2,4 @@ void f() __attribute__((unavailable)); void g(); #define g() f() #define h() f() +#define x x diff --git a/test/PCH/Inputs/chain-macro-override2.h b/test/PCH/Inputs/chain-macro-override2.h index f279e2a..e4bff77 100644 --- a/test/PCH/Inputs/chain-macro-override2.h +++ b/test/PCH/Inputs/chain-macro-override2.h @@ -2,3 +2,4 @@ #undef g #undef h #define h() g() +int x; diff --git a/test/PCH/Inputs/chain-remap-types1.h b/test/PCH/Inputs/chain-remap-types1.h new file mode 100644 index 0000000..d105489 --- /dev/null +++ b/test/PCH/Inputs/chain-remap-types1.h @@ -0,0 +1,10 @@ +@class X; + +struct Y { + X *my_X; +}; + +@interface X { +} +@property X *prop; +@end diff --git a/test/PCH/Inputs/chain-remap-types2.h b/test/PCH/Inputs/chain-remap-types2.h new file mode 100644 index 0000000..55ca8a9 --- /dev/null +++ b/test/PCH/Inputs/chain-remap-types2.h @@ -0,0 +1,8 @@ +void h(X*); + +@interface X (Blah) { +} +@end + +void g(X*); + diff --git a/test/PCH/Inputs/chain-selectors1.h b/test/PCH/Inputs/chain-selectors1.h index 37c1c00..b0b68f8 100644 --- a/test/PCH/Inputs/chain-selectors1.h +++ b/test/PCH/Inputs/chain-selectors1.h @@ -10,3 +10,7 @@ void foo1() { //(void)@selector(x); (void)@selector(f); } + +@interface X (Blah) +- (void)blah_method; +@end diff --git a/test/PCH/Inputs/chain-selectors2.h b/test/PCH/Inputs/chain-selectors2.h index 4d6b556..973fc10 100644 --- a/test/PCH/Inputs/chain-selectors2.h +++ b/test/PCH/Inputs/chain-selectors2.h @@ -9,3 +9,7 @@ void foo2() { //(void)@selector(y); //(void)@selector(e); } + +@interface X (Blarg) +- (void)blarg_method; +@end diff --git a/test/PCH/Inputs/namespaces.h b/test/PCH/Inputs/namespaces.h index 553aadd..bd2c3ee 100644 --- a/test/PCH/Inputs/namespaces.h +++ b/test/PCH/Inputs/namespaces.h @@ -38,3 +38,7 @@ using namespace N2::Inner; extern "C" { void ext(); } + +inline namespace N4 { + struct MemberOfN4; +} diff --git a/test/PCH/Inputs/typo.h b/test/PCH/Inputs/typo.h new file mode 100644 index 0000000..63b553b --- /dev/null +++ b/test/PCH/Inputs/typo.h @@ -0,0 +1,6 @@ + + +@interface NSString ++ (id)alloc; +@end + diff --git a/test/PCH/Inputs/va_arg.h b/test/PCH/Inputs/va_arg.h new file mode 100644 index 0000000..1244e9f --- /dev/null +++ b/test/PCH/Inputs/va_arg.h @@ -0,0 +1,2 @@ +#include <stdarg.h> + diff --git a/test/PCH/attrs-PR8406.c b/test/PCH/attrs-PR8406.c new file mode 100644 index 0000000..85225f5 --- /dev/null +++ b/test/PCH/attrs-PR8406.c @@ -0,0 +1,23 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %s -emit-llvm -o - %s | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -emit-llvm -o - %s | FileCheck %s + +#ifndef HEADER +#define HEADER + +struct Bar +{ + // CHECK: align 512 + int buffer[123] __attribute__((__aligned__(512))); +}; + +#else + +void foo() { + struct Bar bar; +} + +#endif diff --git a/test/PCH/attrs.c b/test/PCH/attrs.c index c971193..2f868ac 100644 --- a/test/PCH/attrs.c +++ b/test/PCH/attrs.c @@ -1,8 +1,17 @@ // Test this without pch. -// RUN: %clang_cc1 -include %S/attrs.h -fsyntax-only -verify %s +// RUN: %clang_cc1 -include %s -fsyntax-only -verify %s // Test with pch. -// RUN: %clang_cc1 -emit-pch -o %t %S/attrs.h +// RUN: %clang_cc1 -emit-pch -o %t %s // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s -// expected-note{{previous overload}} + +#ifndef HEADER +#define HEADER + +int f(int) __attribute__((visibility("default"), overloadable)); // expected-note{{previous overload}} + +#else + double f(double); // expected-error{{overloadable}} + +#endif diff --git a/test/PCH/attrs.h b/test/PCH/attrs.h deleted file mode 100644 index 58f0589..0000000 --- a/test/PCH/attrs.h +++ /dev/null @@ -1,7 +0,0 @@ -// Header for PCH test exprs.c - - - - - -int f(int) __attribute__((visibility("default"), overloadable)); diff --git a/test/PCH/chain-cxx.cpp b/test/PCH/chain-cxx.cpp index 3e46214..d269de5 100644 --- a/test/PCH/chain-cxx.cpp +++ b/test/PCH/chain-cxx.cpp @@ -1,13 +1,82 @@ // Test C++ chained PCH functionality // Without PCH -// RUN: %clang_cc1 -fsyntax-only -verify -include %S/Inputs/chain-cxx1.h -include %S/Inputs/chain-cxx2.h %s +// RUN: %clang_cc1 -fsyntax-only -verify -include %s -include %s %s // With PCH -// RUN: %clang_cc1 -x c++ -emit-pch -o %t1 %S/Inputs/chain-cxx1.h -// RUN: %clang_cc1 -x c++ -emit-pch -o %t2 %S/Inputs/chain-cxx2.h -include-pch %t1 -chained-pch +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t1 %s +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t2 %s -include-pch %t1 -chained-pch // RUN: %clang_cc1 -fsyntax-only -verify -include-pch %t2 %s +#ifndef HEADER1 +#define HEADER1 +//===----------------------------------------------------------------------===// +// Primary header for C++ chained PCH test + +void f(); + +// Name not appearing in dependent +void pf(); + +namespace ns { + void g(); + + void pg(); +} + +template <typename T> +struct S { typedef int G; }; + +// Partially specialize +template <typename T> +struct S<T *> { typedef int H; }; + +template <typename T> struct TS2; +typedef TS2<int> TS2int; + +//===----------------------------------------------------------------------===// +#elif not defined(HEADER2) +#define HEADER2 +//===----------------------------------------------------------------------===// +// Dependent header for C++ chained PCH test + +// Overload function from primary +void f(int); + +// Add function with different name +void f2(); + +// Reopen namespace +namespace ns { + // Overload function from primary + void g(int); + + // Add different name + void g2(); +} + +// Specialize template from primary +template <> +struct S<int> { typedef int I; }; + +// Partially specialize +template <typename T> +struct S<T &> { typedef int J; }; + +// Specialize previous partial specialization +template <> +struct S<int *> { typedef int K; }; + +// Specialize the partial specialization from this file +template <> +struct S<int &> { typedef int L; }; + +template <typename T> struct TS2 { }; + +//===----------------------------------------------------------------------===// +#else +//===----------------------------------------------------------------------===// + void test() { f(); f(1); @@ -25,4 +94,9 @@ void test() { typedef S<double &>::J T4; typedef S<int *>::K T5; typedef S<int &>::L T6; + + TS2int ts2; } + +//===----------------------------------------------------------------------===// +#endif diff --git a/test/PCH/chain-macro-override.c b/test/PCH/chain-macro-override.c index 14478af..8e20881 100644 --- a/test/PCH/chain-macro-override.c +++ b/test/PCH/chain-macro-override.c @@ -1,13 +1,14 @@ // Test this without pch. -// RUN: %clang_cc1 -include %S/Inputs/chain-macro-override1.h -include %S/Inputs/chain-macro-override2.h -fsyntax-only -verify %s +// RUN: %clang_cc1 -include %S/Inputs/chain-macro-override1.h -include %S/Inputs/chain-macro-override2.h -fsyntax-only -verify -detailed-preprocessing-record %s // Test with pch. -// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-macro-override1.h -// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-macro-override2.h -include-pch %t1 -chained-pch +// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-macro-override1.h -detailed-preprocessing-record +// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-macro-override2.h -include-pch %t1 -chained-pch -detailed-preprocessing-record // RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s -void foo() { +int foo() { f(); g(); h(); + return x; } diff --git a/test/PCH/chain-macro.c b/test/PCH/chain-macro.c index b4dcdfe..68b18de 100644 --- a/test/PCH/chain-macro.c +++ b/test/PCH/chain-macro.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-macro1.h -// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-macro2.h -include-pch %t1 -chained-pch +// RUN: %clang_cc1 -emit-pch -o %t1 -detailed-preprocessing-record %S/Inputs/chain-macro1.h +// RUN: %clang_cc1 -emit-pch -o %t2 -detailed-preprocessing-record %S/Inputs/chain-macro2.h -include-pch %t1 -chained-pch // RUN: %clang_cc1 -fsyntax-only -verify -include-pch %t2 %s // RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s diff --git a/test/PCH/chain-remap-types.m b/test/PCH/chain-remap-types.m new file mode 100644 index 0000000..a45a79d --- /dev/null +++ b/test/PCH/chain-remap-types.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-pch -x objective-c-header -o %t1 %S/Inputs/chain-remap-types1.h +// RUN: %clang_cc1 -emit-pch -x objective-c-header -o %t2 %S/Inputs/chain-remap-types2.h -include-pch %t1 -chained-pch +// RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s +// RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s + +// CHECK: @class X; +// CHECK: struct Y +// CHECK: @property ( assign,readwrite ) X * prop +// CHECK: void h(X *); +// CHECK: @interface X(Blah) +// CHECK: void g(X *); + diff --git a/test/PCH/chain-selectors.m b/test/PCH/chain-selectors.m index 60db3f9..3b19172 100644 --- a/test/PCH/chain-selectors.m +++ b/test/PCH/chain-selectors.m @@ -22,3 +22,19 @@ void bar() { (void)@selector(y); // expected-warning {{unimplemented selector}} (void)@selector(e); // expected-warning {{unimplemented selector}} } + +@implementation X (Blah) +- (void)test_Blah { + [self blah_method]; +} + +- (void)blah_method { } +@end + +@implementation X (Blarg) +- (void)test_Blarg { + [self blarg_method]; +} + +- (void)blarg_method { } +@end diff --git a/test/PCH/check-deserializations.cpp b/test/PCH/check-deserializations.cpp new file mode 100644 index 0000000..9f73c95 --- /dev/null +++ b/test/PCH/check-deserializations.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -error-on-deserialized-decl S1_method -include-pch %t -emit-llvm-only %s + +#ifndef HEADER +#define HEADER +// Header. + +struct S1 { + void S1_method(); // This should not be deserialized. + virtual void S1_keyfunc(); +}; + + +#else +// Using the header. + +void test(S1*) { +} + +#endif diff --git a/test/PCH/cmdline-include.c b/test/PCH/cmdline-include.c new file mode 100644 index 0000000..ad45192 --- /dev/null +++ b/test/PCH/cmdline-include.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -include %S/cmdline-include1.h -x c-header %S/cmdline-include2.h -emit-pch -o %t +// RUN: %clang_cc1 %s -include-pch %t -fsyntax-only -verify +// RUN: %clang_cc1 -x c-header %S/cmdline-include1.h -emit-pch -o %t +// RUN: %clang_cc1 %s -include-pch %t -include %S/cmdline-include2.h -fsyntax-only -verify + +int g = x1 + x2; diff --git a/test/PCH/cmdline-include1.h b/test/PCH/cmdline-include1.h new file mode 100644 index 0000000..4f7c661 --- /dev/null +++ b/test/PCH/cmdline-include1.h @@ -0,0 +1 @@ +enum { x1 }; diff --git a/test/PCH/cmdline-include2.h b/test/PCH/cmdline-include2.h new file mode 100644 index 0000000..cf8e37b --- /dev/null +++ b/test/PCH/cmdline-include2.h @@ -0,0 +1 @@ +enum { x2 }; diff --git a/test/PCH/cuda-kernel-call.cu b/test/PCH/cuda-kernel-call.cu new file mode 100644 index 0000000..ef12c59 --- /dev/null +++ b/test/PCH/cuda-kernel-call.cu @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -fsyntax-only %s + +#ifndef HEADER +#define HEADER +// Header. + +#include "../SemaCUDA/cuda.h" + +void kcall(void (*kp)()) { + kp<<<1, 1>>>(); +} + +__global__ void kern() { +} + +#else +// Using the header. + +void test() { + kcall(kern); + kern<<<1, 1>>>(); +} + +#endif diff --git a/test/PCH/cxx-templates.cpp b/test/PCH/cxx-templates.cpp index a862ea5..05dd6ed 100644 --- a/test/PCH/cxx-templates.cpp +++ b/test/PCH/cxx-templates.cpp @@ -1,11 +1,11 @@ // Test this without pch. -// RUN: %clang_cc1 -include %S/cxx-templates.h -verify %s -ast-dump -o - -// RUN: %clang_cc1 -include %S/cxx-templates.h %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -fexceptions -include %S/cxx-templates.h -verify %s -ast-dump -o - +// RUN: %clang_cc1 -fexceptions -include %S/cxx-templates.h %s -emit-llvm -o - | FileCheck %s // Test with pch. -// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-templates.h -// RUN: %clang_cc1 -include-pch %t -verify %s -ast-dump -o - -// RUN: %clang_cc1 -include-pch %t %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h +// RUN: %clang_cc1 -fexceptions -include-pch %t -verify %s -ast-dump -o - +// RUN: %clang_cc1 -fexceptions -include-pch %t %s -emit-llvm -o - | FileCheck %s // CHECK: define weak_odr void @_ZN2S4IiE1mEv // CHECK: define linkonce_odr void @_ZN2S3IiE1mEv @@ -17,7 +17,7 @@ struct A { static T my_templf(T x) { return x; } }; -void test() { +void test(const int (&a6)[17]) { int x = templ_f<int, 5>(3); S<char, float>::templ(); @@ -30,6 +30,16 @@ void test() { S3<int> s3; s3.m(); + + TS5 ts(0); + + S6<const int[17]>::t2 b6 = a6; } template struct S4<int>; + +S7<int[5]> s7_5; + +namespace ZeroLengthExplicitTemplateArgs { + template void f<X>(X*); +} diff --git a/test/PCH/cxx-templates.h b/test/PCH/cxx-templates.h index 978d768..d2c820f 100644 --- a/test/PCH/cxx-templates.h +++ b/test/PCH/cxx-templates.h @@ -135,3 +135,61 @@ void S4ImplicitInst() { S4<int> s; s.m(); } + +struct S5 { + S5(int x); +}; + +struct TS5 { + S5 s; + template <typename T> + TS5(T y) : s(y) {} +}; + +// PR 8134 +template<class T> void f_PR8134(T); +template<class T> void f_PR8134(T); +void g_PR8134() { f_PR8134(0); f_PR8134('x'); } + +// rdar8580149 +template <typename T> +struct S6; + +template <typename T, unsigned N> +struct S6<const T [N]> +{ +private: + typedef const T t1[N]; +public: + typedef t1& t2; +}; + +template<typename T> + struct S7; + +template<unsigned N> +struct S7<int[N]> : S6<const int[N]> { }; + +// Zero-length template argument lists +namespace ZeroLengthExplicitTemplateArgs { + template<typename T> void h(); + + struct Y { + template<typename T> void f(); + }; + + template<typename T> + void f(T *ptr) { + T::template g<>(17); + ptr->template g2<>(17); + h<T>(); + h<int>(); + Y y; + y.f<int>(); + } + + struct X { + template<typename T> static void g(T); + template<typename T> void g2(T); + }; +} diff --git a/test/PCH/cxx-variadic-templates.cpp b/test/PCH/cxx-variadic-templates.cpp new file mode 100644 index 0000000..9b1df9a --- /dev/null +++ b/test/PCH/cxx-variadic-templates.cpp @@ -0,0 +1,11 @@ +// Test this without pch. +// RUN: %clang_cc1 -std=c++0x -include %S/cxx-variadic-templates.h -verify %s -ast-dump -o - +// RUN: %clang_cc1 -std=c++0x -include %S/cxx-variadic-templates.h %s -emit-llvm -o - | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -std=c++0x -x c++-header -emit-pch -o %t %S/cxx-variadic-templates.h +// RUN: %clang_cc1 -std=c++0x -include-pch %t -verify %s -ast-dump -o - +// RUN: %clang_cc1 -std=c++0x -include-pch %t %s -emit-llvm -o - | FileCheck %s + +// CHECK: allocate_shared +shared_ptr<int> spi = shared_ptr<int>::allocate_shared(1, 2); diff --git a/test/PCH/cxx-variadic-templates.h b/test/PCH/cxx-variadic-templates.h new file mode 100644 index 0000000..f6ee787 --- /dev/null +++ b/test/PCH/cxx-variadic-templates.h @@ -0,0 +1,18 @@ +// PR9073 +template<typename _Tp> +class shared_ptr{ +public: + template<class _Alloc, class ..._Args> + static + shared_ptr<_Tp> + allocate_shared(const _Alloc& __a, _Args&& ...__args); +}; + +template<class _Tp> +template<class _Alloc, class ..._Args> +shared_ptr<_Tp> +shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) +{ + shared_ptr<_Tp> __r; + return __r; +} diff --git a/test/PCH/cxx_exprs.cpp b/test/PCH/cxx_exprs.cpp index 2b9a5ab..cf7ae33 100644 --- a/test/PCH/cxx_exprs.cpp +++ b/test/PCH/cxx_exprs.cpp @@ -1,9 +1,9 @@ // Test this without pch. -// RUN: %clang_cc1 -include %S/cxx_exprs.h -std=c++0x -fsyntax-only -verify %s -ast-dump +// RUN: %clang_cc1 -fexceptions -include %S/cxx_exprs.h -std=c++0x -fsyntax-only -verify %s -ast-dump // Test with pch. Use '-ast-dump' to force deserialization of function bodies. -// RUN: %clang_cc1 -x c++-header -std=c++0x -emit-pch -o %t %S/cxx_exprs.h -// RUN: %clang_cc1 -std=c++0x -include-pch %t -fsyntax-only -verify %s -ast-dump +// RUN: %clang_cc1 -fexceptions -x c++-header -std=c++0x -emit-pch -o %t %S/cxx_exprs.h +// RUN: %clang_cc1 -fexceptions -std=c++0x -include-pch %t -fsyntax-only -verify %s -ast-dump int integer; double floating; diff --git a/test/PCH/headersearch.cpp b/test/PCH/headersearch.cpp new file mode 100644 index 0000000..151756c --- /dev/null +++ b/test/PCH/headersearch.cpp @@ -0,0 +1,44 @@ +// Test reading of PCH with changed location of original input files, +// i.e. invoking header search. +// XFAIL: win32 + +// Generate the original files: +// RUN: mkdir -p %t_orig/sub %t_orig/sub2 +// RUN: echo 'struct orig_sub{char c; int i; };' > %t_orig/sub/orig_sub.h +// RUN: echo 'void orig_sub2_1();' > %t_orig/sub2/orig_sub2_1.h +// RUN: echo '#include "orig_sub2_1.h"' > %t_orig/sub2/orig_sub2.h +// RUN: echo 'template <typename T> void tf() { orig_sub2_1(); T::foo(); }' >> %t_orig/sub2/orig_sub2.h +// RUN: echo 'void foo() {}' > %t_orig/tmp2.h +// RUN: echo '#include "tmp2.h"' > %t_orig/all.h +// RUN: echo '#include "sub/orig_sub.h"' >> %t_orig/all.h +// RUN: echo '#include "orig_sub2.h"' >> %t_orig/all.h +// RUN: echo 'int all();' >> %t_orig/all.h + +// Generate the PCH: +// RUN: cd %t_orig && %clang_cc1 -x c++ -emit-pch -o all.h.pch -Isub2 all.h +// RUN: rm -rf %t_moved +// RUN: mv %t_orig %t_moved + +// Check diagnostic with location in original source: +// RUN: %clang_cc1 -include-pch all.h.pch -I%t_moved -I%t_moved/sub2 -Wpadded -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'struct orig_sub' %t.stderr + +// Check diagnostic with 2nd location in original source: +// RUN: not %clang_cc1 -DREDECL -include-pch all.h.pch -I%t_moved -I%t_moved/sub2 -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'void foo' %t.stderr + +// Check diagnostic with instantiation location in original source: +// RUN: not %clang_cc1 -DINSTANTIATION -include-pch all.h.pch -I%t_moved -I%t_moved/sub2 -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'orig_sub2_1' %t.stderr + +void qq(orig_sub*) {all();} + +#ifdef REDECL +float foo() {return 0;} +#endif + +#ifdef INSTANTIATION +void f() { + tf<int>(); +} +#endif diff --git a/test/PCH/missing-file.cpp b/test/PCH/missing-file.cpp new file mode 100644 index 0000000..7d5cd11 --- /dev/null +++ b/test/PCH/missing-file.cpp @@ -0,0 +1,31 @@ +// Test reading of PCH without original input files. + +// Generate the PCH, removing the original file: +// RUN: echo 'struct S{char c; int i; }; void foo() {}' > %t.h +// RUN: echo 'template <typename T> void tf() { T::foo(); }' >> %t.h +// RUN: %clang_cc1 -x c++ -emit-pch -o %t.h.pch %t.h +// RUN: rm %t.h + +// Check diagnostic with location in original source: +// RUN: %clang_cc1 -include-pch %t.h.pch -Wpadded -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'bytes to align' %t.stderr + +// Check diagnostic with 2nd location in original source: +// RUN: not %clang_cc1 -DREDECL -include-pch %t.h.pch -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'previous definition is here' %t.stderr + +// Check diagnostic with instantiation location in original source: +// RUN: not %clang_cc1 -DINSTANTIATION -include-pch %t.h.pch -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'cannot be used prior to' %t.stderr + +void qq(S*) {} + +#ifdef REDECL +float foo() {return 0f;} +#endif + +#ifdef INSTANTIATION +void f() { + tf<int>(); +} +#endif diff --git a/test/PCH/namespaces.cpp b/test/PCH/namespaces.cpp index b8a22e5..6dd4473 100644 --- a/test/PCH/namespaces.cpp +++ b/test/PCH/namespaces.cpp @@ -40,3 +40,6 @@ void (*pused)() = used_func; using N1::used_cls; used_cls s1; used_cls* ps1 = &s1; + +inline namespace N4 { } +struct MemberOfN4 *mn4; diff --git a/test/PCH/opencl-extensions.cl b/test/PCH/opencl-extensions.cl new file mode 100644 index 0000000..a22b007 --- /dev/null +++ b/test/PCH/opencl-extensions.cl @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -fsyntax-only %s + +#ifndef HEADER +#define HEADER +// Header. + +#pragma OPENCL EXTENSION cl_khr_fp64 : enable + +#else +// Using the header. + +void test(void) { + double d; +} + +#endif diff --git a/test/PCH/pragma-diag-section.cpp b/test/PCH/pragma-diag-section.cpp new file mode 100644 index 0000000..312f720 --- /dev/null +++ b/test/PCH/pragma-diag-section.cpp @@ -0,0 +1,26 @@ +// Test this without pch. +// RUN: %clang_cc1 %s -include %s -verify -fsyntax-only + +// Test with pch. +// RUN: %clang_cc1 %s -emit-pch -o %t +// RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only + +#ifndef HEADER +#define HEADER + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wtautological-compare" +template <typename T> +struct TS { + void m() { T b = b==b; } +}; +#pragma clang diagnostic pop + +#else + +void f() { + TS<int> ts; + ts.m(); +} + +#endif diff --git a/test/PCH/pragma-diag.c b/test/PCH/pragma-diag.c new file mode 100644 index 0000000..c517103 --- /dev/null +++ b/test/PCH/pragma-diag.c @@ -0,0 +1,19 @@ +// Test this without pch. +// RUN: %clang_cc1 %s -include %s -verify -fsyntax-only + +// Test with pch. +// RUN: %clang_cc1 %s -emit-pch -o %t +// RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only + +#ifndef HEADER +#define HEADER + +#pragma clang diagnostic ignored "-Wtautological-compare" + +#else + +void f() { + int b = b==b; +} + +#endif diff --git a/test/PCH/rdar8852495.c b/test/PCH/rdar8852495.c new file mode 100644 index 0000000..2d49e00 --- /dev/null +++ b/test/PCH/rdar8852495.c @@ -0,0 +1,25 @@ +// Test this without pch. +// RUN: %clang_cc1 %s -include %s -verify -fsyntax-only -Wno-sign-compare -Wtautological-compare + +// Test with pch. +// RUN: %clang_cc1 %s -emit-pch -o %t -Wsign-compare -Wtautological-compare +// RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only -Wno-sign-compare -Wtautological-compare + +// This tests that diagnostic mappings from PCH are propagated for #pragma +// diagnostics but not for command-line flags. + +#ifndef HEADER +#define HEADER + +#pragma clang diagnostic ignored "-Wtautological-compare" + +#else + +int f() { + int b = b==b; + unsigned x; + signed y; + return x == y; +} + +#endif diff --git a/test/PCH/reinclude.cpp b/test/PCH/reinclude.cpp index 6ab1002..71f9028 100644 --- a/test/PCH/reinclude.cpp +++ b/test/PCH/reinclude.cpp @@ -4,5 +4,7 @@ // RUN: %clang_cc1 -x c++-header %S/reinclude1.h -emit-pch -o %t1 // RUN: %clang_cc1 -x c++-header %S/reinclude2.h -include-pch %t1 -emit-pch -o %t2 // RUN: %clang_cc1 %s -include-pch %t2 -fsyntax-only -verify +// RUN: %clang_cc1 -x c++-header %S/reinclude2.h -include-pch %t1 -emit-pch -o %t2 -chained-pch +// RUN: %clang_cc1 %s -include-pch %t2 -fsyntax-only -verify int q2 = A::y; diff --git a/test/PCH/reinclude1.h b/test/PCH/reinclude1.h index 4c8ccae..baeb677 100644 --- a/test/PCH/reinclude1.h +++ b/test/PCH/reinclude1.h @@ -2,3 +2,6 @@ namespace A { int x; int y; } + +int foo; +#define foo foo diff --git a/test/PCH/reloc.c b/test/PCH/reloc.c index fd78feb..51a7c4c 100644 --- a/test/PCH/reloc.c +++ b/test/PCH/reloc.c @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -emit-pch -o %t -relocatable-pch -isysroot %S/libroot %S/libroot/usr/include/reloc.h // RUN: %clang_cc1 -include-pch %t -isysroot %S/libroot %s -verify // RUN: not %clang_cc1 -include-pch %t %s - +// XFAIL: win32 #include <reloc.h> int x = 2; // expected-error{{redefinition}} diff --git a/test/PCH/types.c b/test/PCH/types.c index 73a2205..ba00dc6 100644 --- a/test/PCH/types.c +++ b/test/PCH/types.c @@ -11,8 +11,7 @@ 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_ptr1 = &int_value; // expected-error{{changes address space of pointer}} ASInt *as_int_ptr2 = &int_as_one; // FIXME: TYPE_FIXED_WIDTH_INT diff --git a/test/PCH/typo.m b/test/PCH/typo.m new file mode 100644 index 0000000..c6f0275 --- /dev/null +++ b/test/PCH/typo.m @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -x objective-c-header -emit-pch -o %t %S/Inputs/typo.h +// RUN: %clang_cc1 -include-pch %t -verify %s +// In header: expected-note{{declared here}} +void f() { + [NSstring alloc]; // expected-error{{unknown receiver 'NSstring'; did you mean 'NSString'?}} +} diff --git a/test/PCH/va_arg.cpp b/test/PCH/va_arg.cpp new file mode 100644 index 0000000..7c8dc6b --- /dev/null +++ b/test/PCH/va_arg.cpp @@ -0,0 +1,16 @@ +// Test this without pch. +// RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -include %S/Inputs/va_arg.h %s -emit-llvm -o - + +// Test with pch. +// RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -emit-pch -x c++-header -o %t %S/Inputs/va_arg.h +// RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -include-pch %t %s -emit-llvm -o - + +typedef __SIZE_TYPE__ size_t; + +extern "C" { +int vsnprintf(char * , size_t, const char * , va_list) ; +} + +void f(char *buffer, unsigned count, const char* format, va_list argptr) { + vsnprintf(buffer, count, format, argptr); +} |