diff options
Diffstat (limited to 'test/PCH')
61 files changed, 360 insertions, 38 deletions
diff --git a/test/PCH/badpch-dir.h.gch/.keep b/test/PCH/Inputs/badpch-dir.h.gch/.keep index e69de29bb2d1d..e69de29bb2d1d 100644 --- a/test/PCH/badpch-dir.h.gch/.keep +++ b/test/PCH/Inputs/badpch-dir.h.gch/.keep diff --git a/test/PCH/badpch-empty.h.gch b/test/PCH/Inputs/badpch-empty.h.gch index e69de29bb2d1d..e69de29bb2d1d 100644 --- a/test/PCH/badpch-empty.h.gch +++ b/test/PCH/Inputs/badpch-empty.h.gch diff --git a/test/PCH/Inputs/case-insensitive-include.h b/test/PCH/Inputs/case-insensitive-include.h new file mode 100644 index 0000000000000..60bdf36dbb7f4 --- /dev/null +++ b/test/PCH/Inputs/case-insensitive-include.h @@ -0,0 +1,5 @@ +#pragma once + +struct S { + int x; +}; diff --git a/test/PCH/Inputs/chain-macro-override1.h b/test/PCH/Inputs/chain-macro-override1.h index d956396f9160f..7532d7ef58d64 100644 --- a/test/PCH/Inputs/chain-macro-override1.h +++ b/test/PCH/Inputs/chain-macro-override1.h @@ -3,3 +3,7 @@ void g(); #define g() f() #define h() f() #define x x +#define h2() f() + +#define h3() +#undef h3 diff --git a/test/PCH/Inputs/chain-macro-override2.h b/test/PCH/Inputs/chain-macro-override2.h index e4bff77294fd9..1e0e3b9671567 100644 --- a/test/PCH/Inputs/chain-macro-override2.h +++ b/test/PCH/Inputs/chain-macro-override2.h @@ -3,3 +3,6 @@ #undef h #define h() g() int x; +#undef h2 + +int h3(); diff --git a/test/PCH/Inputs/cxx11-statement-attributes.h b/test/PCH/Inputs/cxx11-statement-attributes.h new file mode 100644 index 0000000000000..f4d0619a3f98a --- /dev/null +++ b/test/PCH/Inputs/cxx11-statement-attributes.h @@ -0,0 +1,14 @@ +// To be used with cxx11-statement-attributes.cpp. +template<const int N> +int f(int n) { + switch (n * N) { + case 0: + n += 15; + [[clang::fallthrough]]; // This shouldn't generate a warning. + case 1: + n += 20; + [[clang::fallthrough]]; // This should generate a warning: "fallthrough annotation does not directly precede switch label". + break; + } + return n; +} diff --git a/test/PCH/__va_list_tag.c b/test/PCH/__va_list_tag.c index 23c54ea8fb8ee..efe5c1b36630a 100644 --- a/test/PCH/__va_list_tag.c +++ b/test/PCH/__va_list_tag.c @@ -7,6 +7,8 @@ // RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -emit-pch -x c-header -o %t %S/Inputs/__va_list_tag.h // RUN: %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -include-pch %t %s -verify +// expected-no-diagnostics + int myvprintf(const char *fmt, va_list args) { return myvfprintf(fmt, args); } diff --git a/test/PCH/asm.c b/test/PCH/asm.c index 99bc14dc2fb44..160829b7a6e71 100644 --- a/test/PCH/asm.c +++ b/test/PCH/asm.c @@ -5,6 +5,7 @@ // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-pch -o %t %S/asm.h // RUN: %clang_cc1 -triple i386-unknown-unknown -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics void call_f(void) { f(); } diff --git a/test/PCH/badpch.c b/test/PCH/badpch.c index e687ef3246821..f34e3d6a158bc 100644 --- a/test/PCH/badpch.c +++ b/test/PCH/badpch.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -include-pch %S/badpch-empty.h.gch %s 2>&1 | FileCheck -check-prefix=CHECK-EMPTY %s -// RUN: %clang_cc1 -fsyntax-only -include-pch %S/badpch-dir.h.gch %s 2>&1 | FileCheck -check-prefix=CHECK-DIR %s +// RUN: %clang_cc1 -fsyntax-only -include-pch %S/Inputs/badpch-empty.h.gch %s 2>&1 | FileCheck -check-prefix=CHECK-EMPTY %s +// RUN: %clang_cc1 -fsyntax-only -include-pch %S/Inputs/badpch-dir.h.gch %s 2>&1 | FileCheck -check-prefix=CHECK-DIR %s // The purpose of this test is to verify that various invalid PCH files are // reported as such. @@ -10,4 +10,4 @@ // submitted on 2012-02-06 introduced a segfault in the case where the PCH is // an empty file and clang was built with assertions. // CHECK-EMPTY: error: input is not a PCH file: '{{.*[/\\]}}badpch-empty.h.gch' -// CHECK-DIR: error: unable to read PCH file {{.*[/\\]}}badpch-dir.h.gch: +// CHECK-DIR:error: no suitable precompiled header file found in directory '{{.*[/\\]}}badpch-dir.h.gch diff --git a/test/PCH/builtins.c b/test/PCH/builtins.c index eed2224d415fe..da9eef7496cd8 100644 --- a/test/PCH/builtins.c +++ b/test/PCH/builtins.c @@ -5,6 +5,8 @@ // RUN: %clang_cc1 -emit-pch -o %t %S/builtins.h // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + void hello() { printf("Hello, World!"); } diff --git a/test/PCH/case-insensitive-include.c b/test/PCH/case-insensitive-include.c new file mode 100644 index 0000000000000..707de702f15dc --- /dev/null +++ b/test/PCH/case-insensitive-include.c @@ -0,0 +1,29 @@ +// REQUIRES: case-insensitive-filesystem + +// Test this without pch. +// RUN: cp %S/Inputs/case-insensitive-include.h %T +// RUN: %clang_cc1 -fsyntax-only %s -include %s -I %T -verify + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t.pch %s -I %T + +// Modify inode of the header. +// RUN: cp %T/case-insensitive-include.h %t.copy +// RUN: touch -r %T/case-insensitive-include.h %t.copy +// RUN: mv %t.copy %T/case-insensitive-include.h + +// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t.pch -I %T -verify + +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER + +#include "case-insensitive-include.h" +#include "Case-Insensitive-Include.h" + +#else + +#include "Case-Insensitive-Include.h" + +#endif diff --git a/test/PCH/chain-categories.m b/test/PCH/chain-categories.m index 1b91c732b4d0e..7836e09d88fe3 100644 --- a/test/PCH/chain-categories.m +++ b/test/PCH/chain-categories.m @@ -4,6 +4,8 @@ // With PCH // RUN: %clang_cc1 -fsyntax-only -verify %s -chain-include %s -chain-include %s +// expected-no-diagnostics + #ifndef HEADER1 #define HEADER1 //===----------------------------------------------------------------------===// diff --git a/test/PCH/chain-class-extension.m b/test/PCH/chain-class-extension.m index c99d6d43ae5e2..03fdee70b850f 100644 --- a/test/PCH/chain-class-extension.m +++ b/test/PCH/chain-class-extension.m @@ -4,6 +4,8 @@ // With PCH // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin10 -fobjc-arc %s -chain-include %s -chain-include %s +// expected-no-diagnostics + #ifndef HEADER1 #define HEADER1 //===----------------------------------------------------------------------===// diff --git a/test/PCH/chain-cxx.cpp b/test/PCH/chain-cxx.cpp index 0d50e61c5a956..4b64f51143df6 100644 --- a/test/PCH/chain-cxx.cpp +++ b/test/PCH/chain-cxx.cpp @@ -6,6 +6,8 @@ // With PCH // RUN: %clang_cc1 -fsyntax-only -verify %s -chain-include %s -chain-include %s +// expected-no-diagnostics + #ifndef HEADER1 #define HEADER1 //===----------------------------------------------------------------------===// diff --git a/test/PCH/chain-decls.c b/test/PCH/chain-decls.c index f5724c4c13437..bffa09228f90c 100644 --- a/test/PCH/chain-decls.c +++ b/test/PCH/chain-decls.c @@ -7,6 +7,8 @@ // RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s // RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s +// expected-no-diagnostics + // CHECK: void f(); // CHECK: void g(); diff --git a/test/PCH/chain-macro-override.c b/test/PCH/chain-macro-override.c index 2713e7084a9d2..24a7b3edf640d 100644 --- a/test/PCH/chain-macro-override.c +++ b/test/PCH/chain-macro-override.c @@ -10,5 +10,7 @@ int foo() { f(); g(); h(); + h2(); // expected-warning{{implicit declaration of function 'h2' is invalid in C99}} + h3(); return x; } diff --git a/test/PCH/chain-macro.c b/test/PCH/chain-macro.c index 18356f75a0e2b..b0fd63de46d5a 100644 --- a/test/PCH/chain-macro.c +++ b/test/PCH/chain-macro.c @@ -2,6 +2,7 @@ // RUN: %clang_cc1 -emit-pch -o %t2 -detailed-preprocessing-record %S/Inputs/chain-macro2.h -include-pch %t1 // RUN: %clang_cc1 -fsyntax-only -verify -include-pch %t2 %s // RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s +// expected-no-diagnostics // CHECK: void f(); FOOBAR diff --git a/test/PCH/chain-remap-types.m b/test/PCH/chain-remap-types.m index 585da44865026..13f2e39b148d6 100644 --- a/test/PCH/chain-remap-types.m +++ b/test/PCH/chain-remap-types.m @@ -2,6 +2,7 @@ // RUN: %clang_cc1 -emit-pch -x objective-c-header -o %t2 %S/Inputs/chain-remap-types2.h -include-pch %t1 // RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s // RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s +// expected-no-diagnostics // CHECK: @class X; // CHECK: struct Y diff --git a/test/PCH/cmdline-include.c b/test/PCH/cmdline-include.c index ad4519279ae36..556c28ea0f5af 100644 --- a/test/PCH/cmdline-include.c +++ b/test/PCH/cmdline-include.c @@ -2,5 +2,6 @@ // 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 +// expected-no-diagnostics int g = x1 + x2; diff --git a/test/PCH/cxx-exprs.cpp b/test/PCH/cxx-exprs.cpp index 9cd31941e3562..b7707e0b9347f 100644 --- a/test/PCH/cxx-exprs.cpp +++ b/test/PCH/cxx-exprs.cpp @@ -5,6 +5,8 @@ // RUN: %clang_cc1 -std=c++11 -emit-pch -o %t %s // RUN: %clang_cc1 -include-pch %t -verify -std=c++11 %s +// expected-no-diagnostics + #ifndef HEADER #define HEADER diff --git a/test/PCH/cxx-for-range.h b/test/PCH/cxx-for-range.h index f15c7e73df398..8f50f2f269284 100644 --- a/test/PCH/cxx-for-range.h +++ b/test/PCH/cxx-for-range.h @@ -9,11 +9,12 @@ struct T { }; char *begin(T); char *end(T); -struct U { }; -namespace std { +namespace NS { + struct U { }; char *begin(U); char *end(U); } +using NS::U; void f() { char a[3] = { 0, 1, 2 }; diff --git a/test/PCH/cxx-friends.cpp b/test/PCH/cxx-friends.cpp index bdba42bbcb51f..f7d45cea8df4a 100644 --- a/test/PCH/cxx-friends.cpp +++ b/test/PCH/cxx-friends.cpp @@ -5,6 +5,8 @@ // RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-friends.h // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + class F { void m() { A* a; diff --git a/test/PCH/cxx-functions.cpp b/test/PCH/cxx-functions.cpp index 74df01a094b36..3b4fe77c044a2 100644 --- a/test/PCH/cxx-functions.cpp +++ b/test/PCH/cxx-functions.cpp @@ -4,6 +4,8 @@ // RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-functions.h // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + void test_foo() { foo(); diff --git a/test/PCH/cxx-implicit-moves.cpp b/test/PCH/cxx-implicit-moves.cpp index ccdc874cb1fa8..ff6322d49d689 100644 --- a/test/PCH/cxx-implicit-moves.cpp +++ b/test/PCH/cxx-implicit-moves.cpp @@ -1,6 +1,7 @@ // Test with PCH // RUN: %clang_cc1 -std=c++11 -x c++-header -emit-pch -o %t %s // RUN: %clang_cc1 -std=c++11 -include-pch %t -verify %s +// expected-no-diagnostics // PR10847 #ifndef HEADER diff --git a/test/PCH/cxx-method.cpp b/test/PCH/cxx-method.cpp index 6ec65b2486181..40490ea681faf 100644 --- a/test/PCH/cxx-method.cpp +++ b/test/PCH/cxx-method.cpp @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -x c++ -emit-pch %S/Inputs/cxx-method.h -o %t // RUN: %clang_cc1 -include-pch %t -verify %s +// expected-no-diagnostics void S::m(int x) { } diff --git a/test/PCH/cxx-ms-function-specialization-class-scope.cpp b/test/PCH/cxx-ms-function-specialization-class-scope.cpp index 1803a11b96b85..afbb80b7376e3 100644 --- a/test/PCH/cxx-ms-function-specialization-class-scope.cpp +++ b/test/PCH/cxx-ms-function-specialization-class-scope.cpp @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -fms-extensions -triple i386-unknown-unknown -x c++-header -emit-pch -o %t %S/cxx-ms-function-specialization-class-scope.h // RUN: %clang_cc1 -fms-extensions -triple i386-unknown-unknown -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics void test2() diff --git a/test/PCH/cxx-namespaces.cpp b/test/PCH/cxx-namespaces.cpp index 0fd3de7f6c884..e0ff27c020c45 100644 --- a/test/PCH/cxx-namespaces.cpp +++ b/test/PCH/cxx-namespaces.cpp @@ -5,6 +5,8 @@ // RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-namespaces.h // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + void m() { N::x = 0; } diff --git a/test/PCH/cxx-templates.cpp b/test/PCH/cxx-templates.cpp index 7ce247721f8f0..d27e9ca93c43f 100644 --- a/test/PCH/cxx-templates.cpp +++ b/test/PCH/cxx-templates.cpp @@ -1,11 +1,13 @@ // Test this without pch. -// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s -ast-dump -o - -// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s -ast-dump -o - +// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h %s -emit-llvm -o - | FileCheck %s // Test with pch. -// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h -// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump -o - -// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h +// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump -o - +// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - | FileCheck %s + +// expected-no-diagnostics // CHECK: define weak_odr void @_ZN2S4IiE1mEv // CHECK: define linkonce_odr void @_ZN2S3IiE1mEv @@ -68,3 +70,12 @@ Foo< D >& Foo< D >::operator=( const Foo& other ) { return *this; } + +namespace TestNestedExpansion { + struct Int { + Int(int); + friend Int operator+(Int, Int); + }; + Int &g(Int, int, double); + Int &test = NestedExpansion<char, char, char>().f(0, 1, 2, Int(3), 4, 5.0); +} diff --git a/test/PCH/cxx-templates.h b/test/PCH/cxx-templates.h index 152e8cef54647..756f208b76fd3 100644 --- a/test/PCH/cxx-templates.h +++ b/test/PCH/cxx-templates.h @@ -215,3 +215,8 @@ class Foo : protected T public: Foo& operator=( const Foo& other ); }; + +template<typename...A> struct NestedExpansion { + template<typename...B> auto f(A...a, B...b) -> decltype(g(a + b...)); +}; +template struct NestedExpansion<char, char, char>; diff --git a/test/PCH/cxx-traits.cpp b/test/PCH/cxx-traits.cpp index 3df34794f2e23..938f36f2c2791 100644 --- a/test/PCH/cxx-traits.cpp +++ b/test/PCH/cxx-traits.cpp @@ -4,6 +4,8 @@ // RUN: %clang_cc1 -x c++-header -std=c++11 -emit-pch -o %t %S/cxx-traits.h // RUN: %clang_cc1 -std=c++11 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + bool _Is_pod_comparator = __is_pod<int>::__value; bool _Is_empty_check = __is_empty<int>::__value; diff --git a/test/PCH/cxx-typeid.cpp b/test/PCH/cxx-typeid.cpp index 41dd544807ea0..d1e0f9ded751e 100644 --- a/test/PCH/cxx-typeid.cpp +++ b/test/PCH/cxx-typeid.cpp @@ -4,6 +4,8 @@ // RUN: %clang -ccc-pch-is-pch -x c++-header -o %t.gch %S/cxx-typeid.h // RUN: %clang -ccc-pch-is-pch -include %t -fsyntax-only -Xclang -verify %s +// expected-no-diagnostics + void f() { (void)typeid(int); } diff --git a/test/PCH/cxx-variadic-templates.cpp b/test/PCH/cxx-variadic-templates.cpp index 5b586931d541e..dc00758aa5201 100644 --- a/test/PCH/cxx-variadic-templates.cpp +++ b/test/PCH/cxx-variadic-templates.cpp @@ -7,5 +7,11 @@ // RUN: %clang_cc1 -std=c++11 -include-pch %t -verify %s -ast-dump -o - // RUN: %clang_cc1 -std=c++11 -include-pch %t %s -emit-llvm -o - | FileCheck %s +// expected-no-diagnostics + // CHECK: allocate_shared shared_ptr<int> spi = shared_ptr<int>::allocate_shared(1, 2); + +template<int> struct A {}; +template<int> struct B {}; +outer<int, int>::inner<1, 2, A, B> i(A<1>{}, B<2>{}); diff --git a/test/PCH/cxx-variadic-templates.h b/test/PCH/cxx-variadic-templates.h index f6ee7876c2c2d..50596cdf5dbf9 100644 --- a/test/PCH/cxx-variadic-templates.h +++ b/test/PCH/cxx-variadic-templates.h @@ -16,3 +16,10 @@ shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) shared_ptr<_Tp> __r; return __r; } + +template<typename...Ts> struct outer { + template<Ts...Vs, template<Ts> class ...Cs> struct inner { + inner(Cs<Vs>...); + }; +}; +template struct outer<int, int>; diff --git a/test/PCH/cxx11-constexpr.cpp b/test/PCH/cxx11-constexpr.cpp index ce43206d3960a..8b722ce980951 100644 --- a/test/PCH/cxx11-constexpr.cpp +++ b/test/PCH/cxx11-constexpr.cpp @@ -20,6 +20,13 @@ struct D : B { int k; }; +constexpr int value = 7; + +template<typename T> +constexpr T plus_seven(T other) { + return value + other; +} + #else static_assert(D(4).k == 9, ""); @@ -28,4 +35,6 @@ constexpr int f(C c) { return 0; } // expected-error {{not a literal type}} constexpr B b; // expected-error {{constant expression}} expected-note {{non-constexpr}} // expected-note@9 {{here}} +static_assert(plus_seven(3) == 10, ""); + #endif diff --git a/test/PCH/cxx11-exception-spec.cpp b/test/PCH/cxx11-exception-spec.cpp index 3fca4e48acf8f..446619ed1c943 100644 --- a/test/PCH/cxx11-exception-spec.cpp +++ b/test/PCH/cxx11-exception-spec.cpp @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t // RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t -verify %s +// expected-no-diagnostics #ifndef HEADER_INCLUDED diff --git a/test/PCH/cxx11-statement-attributes.cpp b/test/PCH/cxx11-statement-attributes.cpp new file mode 100644 index 0000000000000..3bb7b40aa96a2 --- /dev/null +++ b/test/PCH/cxx11-statement-attributes.cpp @@ -0,0 +1,12 @@ +// Sanity check. +// RUN: %clang_cc1 -include %S/Inputs/cxx11-statement-attributes.h -std=c++11 -Wimplicit-fallthrough -fsyntax-only %s -o - -verify +// Run the same tests, this time with the attributes loaded from the PCH file. +// RUN: %clang_cc1 -x c++-header -emit-pch -std=c++11 -o %t %S/Inputs/cxx11-statement-attributes.h +// RUN: %clang_cc1 -include-pch %t -std=c++11 -Wimplicit-fallthrough -fsyntax-only %s -o - -verify + +// Warning from Inputs/cxx11-statement-attributes.h: +// expected-warning@10 {{fallthrough annotation does not directly precede switch label}} + +void g(int n) { + f<1>(n); // expected-note {{in instantiation of function template specialization 'f<1>' requested here}} +} diff --git a/test/PCH/cxx_exprs.cpp b/test/PCH/cxx_exprs.cpp index 4cd9bae1fa4c1..0fb7590c68b57 100644 --- a/test/PCH/cxx_exprs.cpp +++ b/test/PCH/cxx_exprs.cpp @@ -5,6 +5,8 @@ // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -x c++-header -std=c++11 -emit-pch -o %t %S/cxx_exprs.h // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-dump +// expected-no-diagnostics + int integer; double floating; char character; @@ -37,3 +39,9 @@ cxx_null_ptr_result null_ptr = nullptr; // CXXTypeidExpr typeid_result1 typeid_1 = 0; typeid_result2 typeid_2 = 0; + +// CharacterLiteral variants +static_assert(char_value == 97, "char_value is correct"); +static_assert(wchar_t_value == 305, "wchar_t_value is correct"); +static_assert(char16_t_value == 231, "char16_t_value is correct"); +static_assert(char32_t_value == 8706, "char32_t_value is correct"); diff --git a/test/PCH/cxx_exprs.h b/test/PCH/cxx_exprs.h index 67ab4a6d34db9..35db82efaeecd 100644 --- a/test/PCH/cxx_exprs.h +++ b/test/PCH/cxx_exprs.h @@ -81,3 +81,8 @@ CtorStruct create_CtorStruct() { return CtorStruct(1, 3.14f); // CXXTemporaryObjectExpr }; +// CharacterLiteral variants +const char char_value = 'a'; +const wchar_t wchar_t_value = L'ı'; +const char16_t char16_t_value = u'ç'; +const char32_t char32_t_value = U'∂'; diff --git a/test/PCH/empty-with-headers.c b/test/PCH/empty-with-headers.c index 751be1c9eb39c..b51f0ce258487 100644 --- a/test/PCH/empty-with-headers.c +++ b/test/PCH/empty-with-headers.c @@ -24,4 +24,4 @@ typedef int my_int; // This should only fire if the header is not included, // either explicitly or as a prefix header. -// expected-error{{ISO C requires a translation unit to contain at least one declaration.}} +// expected-error{{ISO C requires a translation unit to contain at least one declaration}} diff --git a/test/PCH/enum.c b/test/PCH/enum.c index 10ceb7c60b0a8..81dbd907ac786 100644 --- a/test/PCH/enum.c +++ b/test/PCH/enum.c @@ -5,6 +5,8 @@ // RUN: %clang_cc1 -emit-pch -o %t %S/enum.h // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + int i = Red; int return_enum_constant() { diff --git a/test/PCH/exprs.c b/test/PCH/exprs.c index 5928abda58f35..c0b279f88a381 100644 --- a/test/PCH/exprs.c +++ b/test/PCH/exprs.c @@ -3,7 +3,11 @@ // Test with pch. // RUN: %clang_cc1 -emit-pch -fblocks -o %t %S/exprs.h -// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -verify %s +// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -verify %s -DWITH_PCH + +#ifdef WITH_PCH +// expected-no-diagnostics +#endif __SIZE_TYPE__ size_type_value; int integer; diff --git a/test/PCH/field-designator.c b/test/PCH/field-designator.c new file mode 100644 index 0000000000000..763cfdab28da2 --- /dev/null +++ b/test/PCH/field-designator.c @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -cc1 %s -include %s +// RUN: %clang_cc1 -cc1 %s -emit-pch -o %t.pch +// RUN: %clang_cc1 -cc1 %s -include-pch %t.pch + +// rdar://12239321 Make sure we don't emit a bogus +// error: field designator 'e' does not refer to a non-static data member + +#ifndef HEADER +#define HEADER +//===----------------------------------------------------------------------===// + +struct U { + union { + struct { + int e; + int f; + }; + + int a; + }; +}; + +//===----------------------------------------------------------------------===// +#else +#if !defined(HEADER) +# error Header inclusion order messed up +#endif +//===----------------------------------------------------------------------===// + +void bar() { + static const struct U plan = { .e = 1 }; +} + +//===----------------------------------------------------------------------===// +#endif diff --git a/test/PCH/friend-template.cpp b/test/PCH/friend-template.cpp new file mode 100644 index 0000000000000..989819b64fbe3 --- /dev/null +++ b/test/PCH/friend-template.cpp @@ -0,0 +1,46 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %s -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER + +// rdar://12627738 +namespace rdar12627738 { + +class RecyclerTag { + template <typename T> friend class Recycler; +}; + +} + +#else + +namespace rdar12627738 { + +template<typename TTag> +class CRN { + template <typename T> friend class Recycler; +}; + + +template<typename T> +class Recycler { +public: + Recycler (); +}; + + +template<typename T> +Recycler<T>::Recycler () +{ +} + +} + +#endif diff --git a/test/PCH/fuzzy-pch.c b/test/PCH/fuzzy-pch.c index 567575346ce17..7296d1dc893b3 100644 --- a/test/PCH/fuzzy-pch.c +++ b/test/PCH/fuzzy-pch.c @@ -1,8 +1,14 @@ // Test with pch. // RUN: %clang_cc1 -emit-pch -DFOO -o %t %S/variables.h // RUN: %clang_cc1 -DBAR=int -include-pch %t -fsyntax-only -pedantic %s -// RUN: %clang_cc1 -DFOO -DBAR=int -include-pch %t -Werror %s -// RUN: not %clang_cc1 -DFOO -DBAR=int -DX=5 -include-pch %t -Werror %s +// RUN: %clang_cc1 -DFOO -DBAR=int -include-pch %t %s +// RUN: not %clang_cc1 -DFOO=blah -DBAR=int -include-pch %t %s 2> %t.err +// RUN: FileCheck -check-prefix=CHECK-FOO %s < %t.err +// RUN: not %clang_cc1 -UFOO -include-pch %t %s 2> %t.err +// RUN: FileCheck -check-prefix=CHECK-NOFOO %s < %t.err + +// RUN: not %clang_cc1 -DFOO -undef -include-pch %t %s 2> %t.err +// RUN: FileCheck -check-prefix=CHECK-UNDEF %s < %t.err BAR bar = 17; @@ -17,3 +23,9 @@ BAR bar = 17; #ifndef BAR # error BAR was not defined #endif + +// CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah') +// CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line + +// CHECK-UNDEF: command line contains '-undef' but precompiled header was not built with it + diff --git a/test/PCH/missing-file.cpp b/test/PCH/missing-file.cpp index 7d5cd111101c7..7dd11d4561a8e 100644 --- a/test/PCH/missing-file.cpp +++ b/test/PCH/missing-file.cpp @@ -4,19 +4,14 @@ // 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 +// %t.h might be touched by scanners as a hot file on Windows, +// to fail to remove %.h with single run. +// RUN: rm %t.h || rm %t.h || rm %t.h -// 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 +// Check diagnostic with location in original source: +// RUN: not %clang_cc1 -include-pch %t.h.pch -emit-obj -o %t.o %s 2> %t.stderr +// RUN: grep 'could not find file' %t.stderr void qq(S*) {} diff --git a/test/PCH/objc_container.m b/test/PCH/objc_container.m index 1e59054a2e542..07371caeaf717 100644 --- a/test/PCH/objc_container.m +++ b/test/PCH/objc_container.m @@ -4,8 +4,10 @@ // Test with pch. // RUN: %clang_cc1 -x objective-c -emit-pch -o %t %S/objc_container.h // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s -// RUN: %clang -cc1 -include-pch %t -ast-print %s | FileCheck -check-prefix=PRINT %s -// RUN: %clang -cc1 -include-pch %t -emit-llvm -o - %s | FileCheck -check-prefix=IR %s +// RUN: %clang_cc1 -include-pch %t -ast-print %s | FileCheck -check-prefix=PRINT %s +// RUN: %clang_cc1 -include-pch %t -emit-llvm -o - %s | FileCheck -check-prefix=IR %s + +// expected-no-diagnostics // CHECK-PRINT: id oldObject = array[10]; // CHECK-PRINT: array[10] = oldObject; diff --git a/test/PCH/objc_import.m b/test/PCH/objc_import.m index 277c6dd6c2f0a..c7dd805b3e470 100644 --- a/test/PCH/objc_import.m +++ b/test/PCH/objc_import.m @@ -5,6 +5,8 @@ // RUN: %clang_cc1 -x objective-c -emit-pch -o %t %S/objc_import.h // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + #import "objc_import.h" void func() { diff --git a/test/PCH/objc_literals.m b/test/PCH/objc_literals.m index cce3173bba027..b73c3bebb8c41 100644 --- a/test/PCH/objc_literals.m +++ b/test/PCH/objc_literals.m @@ -1,7 +1,9 @@ -// RUN: %clang -cc1 -emit-pch -o %t %s -// RUN: %clang -cc1 -include-pch %t -verify %s -// RUN: %clang -cc1 -include-pch %t -ast-print %s | FileCheck -check-prefix=PRINT %s -// RUN: %clang -cc1 -include-pch %t -emit-llvm -o - %s | FileCheck -check-prefix=IR %s +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -verify %s +// RUN: %clang_cc1 -include-pch %t -ast-print %s | FileCheck -check-prefix=PRINT %s +// RUN: %clang_cc1 -include-pch %t -emit-llvm -o - %s | FileCheck -check-prefix=IR %s + +// expected-no-diagnostics #ifndef HEADER #define HEADER diff --git a/test/PCH/objc_literals.mm b/test/PCH/objc_literals.mm index 8ef335115030b..ef95294d7aa79 100644 --- a/test/PCH/objc_literals.mm +++ b/test/PCH/objc_literals.mm @@ -1,7 +1,9 @@ -// RUN: %clang -cc1 -emit-pch -x objective-c++ -std=c++0x -o %t %s -// RUN: %clang -cc1 -include-pch %t -x objective-c++ -std=c++0x -verify %s -// RUN: %clang -cc1 -include-pch %t -x objective-c++ -std=c++0x -ast-print %s | FileCheck -check-prefix=PRINT %s -// RUN: %clang -cc1 -include-pch %t -x objective-c++ -std=c++0x -emit-llvm -o - %s | FileCheck -check-prefix=IR %s +// RUN: %clang_cc1 -emit-pch -x objective-c++ -std=c++0x -o %t %s +// RUN: %clang_cc1 -include-pch %t -x objective-c++ -std=c++0x -verify %s +// RUN: %clang_cc1 -include-pch %t -x objective-c++ -std=c++0x -ast-print %s | FileCheck -check-prefix=PRINT %s +// RUN: %clang_cc1 -include-pch %t -x objective-c++ -std=c++0x -emit-llvm -o - %s | FileCheck -check-prefix=IR %s + +// expected-no-diagnostics #ifndef HEADER #define HEADER diff --git a/test/PCH/objc_methods.m b/test/PCH/objc_methods.m index e8aab843dc515..ea40460fb8df1 100644 --- a/test/PCH/objc_methods.m +++ b/test/PCH/objc_methods.m @@ -5,6 +5,8 @@ // RUN: %clang_cc1 -x objective-c -emit-pch -o %t %S/objc_methods.h // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + void func() { TestPCH *xx; TestForwardClassDecl *yy; diff --git a/test/PCH/objc_property.m b/test/PCH/objc_property.m index b51cd90927ae5..88a091928050f 100644 --- a/test/PCH/objc_property.m +++ b/test/PCH/objc_property.m @@ -5,6 +5,8 @@ // RUN: %clang_cc1 -x objective-c -emit-pch -o %t %S/objc_property.h // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + void func() { TestProperties *xx = [TestProperties alloc]; xx.value = 5; diff --git a/test/PCH/pch-dir.c b/test/PCH/pch-dir.c new file mode 100644 index 0000000000000..ae841ce0a7a4d --- /dev/null +++ b/test/PCH/pch-dir.c @@ -0,0 +1,28 @@ +// RUN: mkdir -p %t.h.gch +// RUN: %clang -x c-header %S/pch-dir.h -DFOO=foo -o %t.h.gch/c.gch +// RUN: %clang -x c-header %S/pch-dir.h -DFOO=bar -o %t.h.gch/cbar.gch +// RUN: %clang -x c++-header -std=c++98 %S/pch-dir.h -o %t.h.gch/cpp.gch +// RUN: %clang -include %t.h -DFOO=foo -fsyntax-only %s -Xclang -print-stats 2> %t.clog +// RUN: FileCheck -check-prefix=C %s < %t.clog +// RUN: %clang -include %t.h -DFOO=bar -DBAR=bar -fsyntax-only %s -Xclang -ast-print > %t.cbarlog +// RUN: FileCheck -check-prefix=CBAR %s < %t.cbarlog +// RUN: %clang -x c++ -include %t.h -std=c++98 -fsyntax-only %s -Xclang -print-stats 2> %t.cpplog +// RUN: FileCheck -check-prefix=CPP %s < %t.cpplog + +// RUN: not %clang -x c++ -std=c++11 -include %t.h -fsyntax-only %s 2> %t.cpp11log +// RUN: FileCheck -check-prefix=CPP11 %s < %t.cpp11log + +// CHECK-CBAR: int bar +int FOO; + +int get() { +#ifdef __cplusplus + // CHECK-CPP: .h.gch{{[/\\]}}cpp.gch + return i; +#else + // CHECK-C: .h.gch{{[/\\]}}c.gch + return j; +#endif +} + +// CHECK-CPP11: no suitable precompiled header file found in directory diff --git a/test/PCH/pch-dir.h b/test/PCH/pch-dir.h new file mode 100644 index 0000000000000..e94a8c7ad90a8 --- /dev/null +++ b/test/PCH/pch-dir.h @@ -0,0 +1,5 @@ +#ifdef __cplusplus +extern int i; +#else +extern int j; +#endif diff --git a/test/PCH/pending-ids.m b/test/PCH/pending-ids.m index b612d89e94524..2ca0e6e93568c 100644 --- a/test/PCH/pending-ids.m +++ b/test/PCH/pending-ids.m @@ -7,6 +7,8 @@ // RUN: %clang_cc1 %s -emit-pch -o %t // RUN: %clang_cc1 -emit-llvm-only -verify %s -include-pch %t -g +// expected-no-diagnostics + #ifndef HEADER #define HEADER //===----------------------------------------------------------------------===// diff --git a/test/PCH/pragma-diag-section.cpp b/test/PCH/pragma-diag-section.cpp index 5b996bb2f0d16..627156f153986 100644 --- a/test/PCH/pragma-diag-section.cpp +++ b/test/PCH/pragma-diag-section.cpp @@ -11,7 +11,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wtautological-compare" template <typename T> -struct TS { +struct TS1 { void m() { T a = 0; T b = a==a; @@ -21,9 +21,22 @@ struct TS { #else + +template <typename T> +struct TS2 { + void m() { + T a = 0; + T b = a==a; // expected-warning {{self-comparison always evaluates to true}} expected-note@39 {{in instantiation of member function}} + } +}; + void f() { - TS<int> ts; - ts.m(); + TS1<int> ts1; + ts1.m(); + + + TS2<int> ts2; + ts2.m(); } #endif diff --git a/test/PCH/pragma-diag.c b/test/PCH/pragma-diag.c index b304c4bf8c35f..601c940cee9b3 100644 --- a/test/PCH/pragma-diag.c +++ b/test/PCH/pragma-diag.c @@ -5,6 +5,8 @@ // RUN: %clang_cc1 %s -emit-pch -o %t // RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only +// expected-no-diagnostics + #ifndef HEADER #define HEADER diff --git a/test/PCH/rdar8852495.c b/test/PCH/rdar8852495.c index fb465a37ce38d..7639f1f0db659 100644 --- a/test/PCH/rdar8852495.c +++ b/test/PCH/rdar8852495.c @@ -5,6 +5,8 @@ // 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 +// expected-no-diagnostics + // This tests that diagnostic mappings from PCH are propagated for #pragma // diagnostics but not for command-line flags. diff --git a/test/PCH/reinclude.cpp b/test/PCH/reinclude.cpp index 97e22cf9d6f14..4bec0508b1490 100644 --- a/test/PCH/reinclude.cpp +++ b/test/PCH/reinclude.cpp @@ -7,4 +7,6 @@ // 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 +// expected-no-diagnostics + int q2 = A::y; diff --git a/test/PCH/single-token-macro.c b/test/PCH/single-token-macro.c index 29edb753e41a4..52873bfc24419 100644 --- a/test/PCH/single-token-macro.c +++ b/test/PCH/single-token-macro.c @@ -7,6 +7,8 @@ // RUN: %clang_cc1 %s -emit-pch -o %t // RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only +// expected-no-diagnostics + #ifndef HEADER #define HEADER diff --git a/test/PCH/target-options.c b/test/PCH/target-options.c new file mode 100644 index 0000000000000..2b85efe07abfa --- /dev/null +++ b/test/PCH/target-options.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -triple=x86_64-apple-darwin9 -emit-pch -o %t.pch %S/target-options.h +// RUN: not %clang_cc1 -triple=x86_64-unknown-freebsd7.0 -include-pch %t.pch %s -emit-llvm -o - > %t.err 2>&1 +// RUN: FileCheck %s < %t.err + +// CHECK: for the target diff --git a/test/PCH/target-options.h b/test/PCH/target-options.h new file mode 100644 index 0000000000000..2c3edf6aa2e74 --- /dev/null +++ b/test/PCH/target-options.h @@ -0,0 +1,2 @@ +enum { apple_cc = __APPLE_CC__ }; + |