diff options
Diffstat (limited to 'test')
45 files changed, 796 insertions, 84 deletions
diff --git a/test/Analysis/dead-stores.c b/test/Analysis/dead-stores.c index 9a266c9..209ca65 100644 --- a/test/Analysis/dead-stores.c +++ b/test/Analysis/dead-stores.c @@ -1,18 +1,18 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s void f1() { - int k, y; + int k, y; // expected-warning{{unused variable 'k'}} expected-warning{{unused variable 'y'}} int abc=1; - long idx=abc+3*5; // expected-warning {{never read}} + long idx=abc+3*5; // expected-warning {{never read}} expected-warning{{unused variable 'idx'}} } void f2(void *b) { char *c = (char*)b; // no-warning - char *d = b+1; // expected-warning {{never read}} + char *d = b+1; // expected-warning {{never read}} expected-warning{{unused variable 'd'}} printf("%s", c); // expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \ // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}} } @@ -40,7 +40,7 @@ void f4(int k) { void f5() { int x = 4; // no-warning - int *p = &x; // expected-warning{{never read}} + int *p = &x; // expected-warning{{never read}} expected-warning{{unused variable 'p'}} } @@ -105,13 +105,20 @@ int f11b() { } int f12a(int y) { - int x = y; // expected-warning{{never read}} + int x = y; // expected-warning{{unused variable 'x'}} return 1; } int f12b(int y) { int x __attribute__((unused)) = y; // no-warning return 1; } +int f12c(int y) { + // Allow initialiation of scalar variables by parameters as a form of + // defensive programming. + int x = y; // no-warning + x = 1; + return x; +} // Filed with PR 2630. This code should produce no warnings. int f13(void) @@ -138,7 +145,7 @@ int f14(int count) { // Test case for <rdar://problem/6248086> void f15(unsigned x, unsigned y) { int count = x * y; // no-warning - int z[count]; + int z[count]; // expected-warning{{unused variable 'z'}} } int f16(int x) { @@ -367,7 +374,7 @@ void f23(int argc, char **argv) { } void f23_pos(int argc, char **argv) { - int shouldLog = (argc > 1); // expected-warning{{Value stored to 'shouldLog' during its initialization is never read}} + int shouldLog = (argc > 1); // expected-warning{{Value stored to 'shouldLog' during its initialization is never read}} expected-warning{{unused variable 'shouldLog'}} ^{ f23_aux("I did too use it!\n"); }(); @@ -377,7 +384,7 @@ void f24_A(int y) { // FIXME: One day this should be reported as dead since 'z = x + y' is dead. int x = (y > 2); // no-warning ^ { - int z = x + y; // expected-warning{{Value stored to 'z' during its initialization is never read}} + int z = x + y; // expected-warning{{Value stored to 'z' during its initialization is never read}} expected-warning{{unused variable 'z'}} }(); } diff --git a/test/Analysis/misc-ps-region-store.m b/test/Analysis/misc-ps-region-store.m index 21a54c3..898a33e 100644 --- a/test/Analysis/misc-ps-region-store.m +++ b/test/Analysis/misc-ps-region-store.m @@ -888,3 +888,25 @@ char *rdar_7242010(int count, char **y) { return y[0]; // no-warning } +//===----------------------------------------------------------------------===// +// <rdar://problem/7770737> +//===----------------------------------------------------------------------===// + +struct rdar_7770737_s { intptr_t p; }; +void rdar_7770737_aux(struct rdar_7770737_s *p); +int rdar_7770737(void) +{ + int x; + + // Previously 'f' was not properly invalidated, causing the use of + // an uninitailized value below. + struct rdar_7770737_s f = { .p = (intptr_t)&x }; + rdar_7770737_aux(&f); + return x; // no-warning +} +int rdar_7770737_pos(void) +{ + int x; + struct rdar_7770737_s f = { .p = (intptr_t)&x }; + return x; // expected-warning{{Undefined or garbage value returned to caller}} +} diff --git a/test/Analysis/uninit-vals-ps-region.c b/test/Analysis/uninit-vals-ps-region.m index 44f506e..7e2fff9 100644 --- a/test/Analysis/uninit-vals-ps-region.c +++ b/test/Analysis/uninit-vals-ps-region.m @@ -45,3 +45,18 @@ void test_uninit_neg() { test_unit_aux2(v2.x + v1.y); // no-warning } +extern void test_uninit_struct_arg_aux(struct TestUninit arg); +void test_uninit_struct_arg() { + struct TestUninit x; + test_uninit_struct_arg_aux(x); // expected-warning{{Passed-by-value struct argument contains uninitialized data (e.g., field: 'x')}} +} + +@interface Foo +- (void) passVal:(struct TestUninit)arg; +@end +void testFoo(Foo *o) { + struct TestUninit x; + [o passVal:x]; // expected-warning{{Passed-by-value struct argument contains uninitialized data (e.g., field: 'x')}} +} + + diff --git a/test/CXX/class.access/class.access.nest/p1.cpp b/test/CXX/class.access/class.access.nest/p1.cpp new file mode 100644 index 0000000..d2644c6 --- /dev/null +++ b/test/CXX/class.access/class.access.nest/p1.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -fsyntax-only -faccess-control -verify %s + +// Derived from GNU's std::string +namespace test0 { + class A { + struct B { + unsigned long length; + }; + struct C : B { + static const unsigned long max_length; + }; + }; + + const unsigned long A::C::max_length = sizeof(B); +} + +// Example from the standard. +namespace test1 { + class E { + int x; + class B {}; + + class I { + B b; + int y; // expected-note {{declared private here}} + void f(E* p, int i) { + p->x = i; + } + }; + + int g(I* p) { return p->y; } // expected-error {{'y' is a private member of 'test1::E::I'}} + }; +} diff --git a/test/CXX/class.access/class.friend/p1.cpp b/test/CXX/class.access/class.friend/p1.cpp index 83b4227..851cd3d 100644 --- a/test/CXX/class.access/class.friend/p1.cpp +++ b/test/CXX/class.access/class.friend/p1.cpp @@ -115,3 +115,37 @@ namespace test0 { } }; } + +// Make sure that friends have access to inherited protected members. +namespace test2 { + struct X; + + class ilist_half_node { + friend struct ilist_walker_bad; + X *Prev; + protected: + X *getPrev() { return Prev; } + }; + + class ilist_node : private ilist_half_node { // expected-note {{declared private here}} expected-note {{constrained by private inheritance here}} + friend struct ilist_walker; + X *Next; + X *getNext() { return Next; } // expected-note {{declared private here}} + }; + + struct X : ilist_node {}; + + struct ilist_walker { + static X *getPrev(X *N) { return N->getPrev(); } + static X *getNext(X *N) { return N->getNext(); } + }; + + struct ilist_walker_bad { + static X *getPrev(X *N) { return N->getPrev(); } // \ + // expected-error {{'getPrev' is a private member of 'test2::ilist_half_node'}} \ + // expected-error {{cannot cast 'test2::X' to its private base class 'test2::ilist_half_node'}} + + static X *getNext(X *N) { return N->getNext(); } // \ + // expected-error {{'getNext' is a private member of 'test2::ilist_node'}} + }; +} diff --git a/test/CXX/class.access/p4.cpp b/test/CXX/class.access/p4.cpp index 15b336a..bc69bee 100644 --- a/test/CXX/class.access/p4.cpp +++ b/test/CXX/class.access/p4.cpp @@ -112,9 +112,10 @@ namespace test3 { A local; // expected-error {{variable of type 'test3::A' has private destructor}} } - template <unsigned N> class Base { ~Base(); }; // expected-note 8 {{declared private here}} - class Base2 : virtual Base<2> { ~Base2(); }; // expected-note 2 {{declared private here}} - class Base3 : virtual Base<3> { public: ~Base3(); }; + template <unsigned N> class Base { ~Base(); }; // expected-note 14 {{declared private here}} + class Base2 : virtual Base<2> { ~Base2(); }; // expected-note 3 {{declared private here}} \ + // expected-error {{base class 'Base<2>' has private destructor}} + class Base3 : virtual Base<3> { public: ~Base3(); }; // expected-error {{base class 'Base<3>' has private destructor}} // These don't cause diagnostics because we don't need the destructor. class Derived0 : Base<0> { ~Derived0(); }; @@ -130,11 +131,11 @@ namespace test3 { ~Derived2() {} }; - class Derived3 : // expected-error {{inherited virtual base class 'Base<2>' has private destructor}} \ - // expected-error {{inherited virtual base class 'Base<3>' has private destructor}} - Base<0>, // expected-error {{base class 'Base<0>' has private destructor}} - virtual Base<1>, // expected-error {{base class 'Base<1>' has private destructor}} - Base2, // expected-error {{base class 'test3::Base2' has private destructor}} + class Derived3 : // expected-error 2 {{inherited virtual base class 'Base<2>' has private destructor}} \ + // expected-error 2 {{inherited virtual base class 'Base<3>' has private destructor}} + Base<0>, // expected-error 2 {{base class 'Base<0>' has private destructor}} + virtual Base<1>, // expected-error 2 {{base class 'Base<1>' has private destructor}} + Base2, // expected-error 2 {{base class 'test3::Base2' has private destructor}} virtual Base3 {}; Derived3 d3; @@ -220,3 +221,44 @@ namespace test6 { Test2 a = t; } } + +// Redeclaration lookups are not accesses. +namespace test7 { + class A { + int private_member; + }; + class B : A { + int foo(int private_member) { + return 0; + } + }; +} + +// Ignored operator new and delete overloads are not +namespace test8 { + typedef __typeof__(sizeof(int)) size_t; + + class A { + void *operator new(size_t s); + void operator delete(void *p); + public: + void *operator new(size_t s, int n); + void operator delete(void *p, int n); + }; + + void test() { + new (2) A(); + } +} + +// Don't silently upgrade forbidden-access paths to private. +namespace test9 { + class A { + public: static int x; + }; + class B : private A { // expected-note {{constrained by private inheritance here}} + }; + class C : public B { + static int getX() { return x; } // expected-error {{'x' is a private member of 'test9::A'}} + }; +} diff --git a/test/CXX/class/class.union/p1.cpp b/test/CXX/class/class.union/p1.cpp index f53783e..e974d82 100644 --- a/test/CXX/class/class.union/p1.cpp +++ b/test/CXX/class/class.union/p1.cpp @@ -46,25 +46,25 @@ union U1 { union U2 { struct { - Virtual v; // expected-note {{because type 'U2::<anonymous>' has a member with a non-trivial copy constructor}} + Virtual v; // expected-note {{because type 'U2::<anonymous struct}} } m1; // expected-error {{union member 'm1' has a non-trivial copy constructor}} struct { - VirtualBase vbase; // expected-note {{because type 'U2::<anonymous>' has a member with a non-trivial copy constructor}} + VirtualBase vbase; // expected-note {{because type 'U2::<anonymous struct}} } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}} struct { - Ctor ctor; // expected-note {{because type 'U2::<anonymous>' has a member with a non-trivial constructor}} + Ctor ctor; // expected-note {{because type 'U2::<anonymous struct}} } m3; // expected-error {{union member 'm3' has a non-trivial constructor}} struct { - Ctor2 ctor2; // expected-note {{because type 'U2::<anonymous>' has a member with a non-trivial constructor}} + Ctor2 ctor2; // expected-note {{because type 'U2::<anonymous struct}} } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}} struct { - CopyCtor copyctor; // expected-note {{because type 'U2::<anonymous>' has a member with a non-trivial copy constructor}} + CopyCtor copyctor; // expected-note {{because type 'U2::<anonymous struct}} } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}} struct { - CopyAssign copyassign; // expected-note {{because type 'U2::<anonymous>' has a member with a non-trivial copy assignment operator}} + CopyAssign copyassign; // expected-note {{because type 'U2::<anonymous struct}} } m5; // expected-error {{union member 'm5' has a non-trivial copy assignment operator}} struct { - Dtor dtor; // expected-note {{because type 'U2::<anonymous>' has a member with a non-trivial destructor}} + Dtor dtor; // expected-note {{because type 'U2::<anonymous struct}} } m6; // expected-error {{union member 'm6' has a non-trivial destructor}} struct { Okay okay; diff --git a/test/CXX/temp/temp.decls/temp.friend/p1.cpp b/test/CXX/temp/temp.decls/temp.friend/p1.cpp index 7a28e70..f1b3c81 100644 --- a/test/CXX/temp/temp.decls/temp.friend/p1.cpp +++ b/test/CXX/temp/temp.decls/temp.friend/p1.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm-only %s +// RUN: %clang_cc1 -faccess-control -verify -emit-llvm-only %s template <typename T> struct Num { T value_; @@ -54,3 +54,34 @@ int calc2() { Num<int> result = x * n; return result.get(); } + +// Reduced from GNU <locale> +namespace test1 { + class A { + bool b; // expected-note {{declared private here}} + template <typename T> friend bool has(const A&); + }; + template <typename T> bool has(const A &x) { + return x.b; + } + template <typename T> bool hasnot(const A &x) { + return x.b; // expected-error {{'b' is a private member of 'test1::A'}} + } +} + +namespace test2 { + class A { + bool b; // expected-note {{declared private here}} + template <typename T> friend class HasChecker; + }; + template <typename T> class HasChecker { + bool check(A *a) { + return a->b; + } + }; + template <typename T> class HasNotChecker { + bool check(A *a) { + return a->b; // expected-error {{'b' is a private member of 'test2::A'}} + } + }; +} diff --git a/test/CodeGen/atomic.c b/test/CodeGen/atomic.c index ff304f5..c201a1a 100644 --- a/test/CodeGen/atomic.c +++ b/test/CodeGen/atomic.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 > %t1 +// RUN: grep @llvm.memory.barrier %t1 | count 42 // RUN: grep @llvm.atomic.load.add.i32 %t1 | count 3 // RUN: grep @llvm.atomic.load.sub.i8 %t1 | count 2 // RUN: grep @llvm.atomic.load.min.i32 %t1 diff --git a/test/CodeGen/const-arithmetic.c b/test/CodeGen/const-arithmetic.c new file mode 100644 index 0000000..e12b4f6 --- /dev/null +++ b/test/CodeGen/const-arithmetic.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s + +// CHECK: @g1 = global [2 x i8*] [i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -2), i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -46)], align 8 ; <[2 x i8*]*> [#uses=0] +// CHECK: @g2 = global [2 x i8*] [i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -2), i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -46)], align 8 ; <[2 x i8*]*> [#uses=0] + +extern struct { unsigned char a, b; } g0[]; +void *g1[] = {g0 + -1, g0 + -23 }; +void *g2[] = {g0 - 1, g0 - 23 }; diff --git a/test/CodeGenCXX/attr.cpp b/test/CodeGenCXX/attr.cpp index 4c781c6..d689a4f 100644 --- a/test/CodeGenCXX/attr.cpp +++ b/test/CodeGenCXX/attr.cpp @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s +// CHECK: @test2 = alias i32 ()* @_Z5test1v + // CHECK: define i32 @_Z3foov() nounwind align 1024 int foo() __attribute__((aligned(1024))); int foo() { } @@ -18,3 +20,9 @@ void C::bar2() { } // CHECK: define void @_ZN1C4bar3Ev(%class.C* %this) nounwind align 1024 void C::bar3() { } + +// PR6635 +// CHECK: define i32 @_Z5test1v() +int test1() { return 10; } +// CHECK at top of file +extern "C" int test2() __attribute__((alias("_Z5test1v"))); diff --git a/test/CodeGenCXX/cxx-apple-kext.cpp b/test/CodeGenCXX/cxx-apple-kext.cpp new file mode 100644 index 0000000..8d67b53 --- /dev/null +++ b/test/CodeGenCXX/cxx-apple-kext.cpp @@ -0,0 +1,36 @@ +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 %s -flto -S -o - |\ +// RUN: FileCheck --check-prefix=CHECK-NO-KEXT %s +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 %s -fapple-kext -flto -S -o - |\ +// RUN: FileCheck --check-prefix=CHECK-KEXT %s + +// CHECK-NO-KEXT: @_ZTI3foo = {{.*}} @_ZTVN10__cxxabiv117 +// CHECK-NO-KEXT-NOT: _GLOBAL__D_a +// CHECK-NO-KEXT: @is_hosted = global +// CHECK-NO-KEXT: call i32 @__cxa_atexit({{.*}} @_ZN3fooD1Ev +// CHECK-NO-KEXT: declare i32 @__cxa_atexit + +// CHECK-KEXT: @_ZTV3foo = +// CHECK-KEXT-NOT: @_ZTVN10__cxxabiv117 +// CHECK-KEXT-NOT: call i32 @__cxa_atexit({{.*}} @_ZN3fooD1Ev +// CHECK-KEXT-NOT: declare i32 @__cxa_atexit +// CHECK-KEXT: @is_freestanding = global +// CHECK-KEXT: _GLOBAL__D_a +// CHECK-KEXT: call void @_ZN3fooD1Ev(%class.foo* @a) + +class foo { +public: + foo(); + virtual ~foo(); +}; + +foo a; +foo::~foo() {} + +#if !(__STDC_HOSTED__ == 1) +int is_freestanding = 1; +#else +int is_hosted = 1; +#endif + +extern "C" void f1() { +} diff --git a/test/CodeGenCXX/deferred-global-init.cpp b/test/CodeGenCXX/deferred-global-init.cpp index 802042d..24c8c67 100644 --- a/test/CodeGenCXX/deferred-global-init.cpp +++ b/test/CodeGenCXX/deferred-global-init.cpp @@ -11,6 +11,6 @@ void* bar() { return a; } // CHECK: load i8** @foo // CHECK: ret void -// CHECK: define internal void @__cxx_global_initialization +// CHECK: define internal void @_GLOBAL__I_a // CHECK: call void @__cxx_global_var_init() // CHECK: ret void diff --git a/test/CodeGenCXX/global-dtor-no-atexit.cpp b/test/CodeGenCXX/global-dtor-no-atexit.cpp new file mode 100644 index 0000000..81e2199 --- /dev/null +++ b/test/CodeGenCXX/global-dtor-no-atexit.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple x86_64 %s -fno-use-cxa-atexit -emit-llvm -o - | FileCheck %s + +// CHECK: define internal void @_GLOBAL__D_a() +// CHECK: call void @_ZN1AD1Ev(%class.A* @b) +// CHECK: call void @_ZN1AD1Ev(%class.A* @a) +// CHECK: } + +class A { +public: + A(); + ~A(); +}; + +A a, b; diff --git a/test/CodeGenCXX/global-init.cpp b/test/CodeGenCXX/global-init.cpp index b60e056..7cbd559 100644 --- a/test/CodeGenCXX/global-init.cpp +++ b/test/CodeGenCXX/global-init.cpp @@ -28,4 +28,4 @@ C c; // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1DD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @d, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) D d; -// CHECK: define internal void @__cxx_global_initialization() { +// CHECK: define internal void @_GLOBAL__I_a() { diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp index 8dee41b..ec9c08c 100644 --- a/test/CodeGenCXX/mangle.cpp +++ b/test/CodeGenCXX/mangle.cpp @@ -453,3 +453,18 @@ namespace test8 { class B { static int value; }; template class A<B::value>; } +// CHECK: declare void @_ZN5test91fIiNS_3barEEEvRKNT0_3baz1XE +namespace test9 { + template<class T> + struct foo { + typedef T X; + }; + struct bar { + typedef foo<int> baz; + }; + template <class zaz, class zed> + void f(const typename zed::baz::X&); + void g() { + f<int, bar>( 0); + } +} diff --git a/test/CodeGenCXX/vtable-layout.cpp b/test/CodeGenCXX/vtable-layout.cpp index f11ae34..bc3d54b 100644 --- a/test/CodeGenCXX/vtable-layout.cpp +++ b/test/CodeGenCXX/vtable-layout.cpp @@ -887,8 +887,8 @@ class E : virtual C { }; // CHECK-NEXT: -- (Test21::E, 8) vtable address -- // CHECK-NEXT: 15 | [unused] void Test21::F::f() // -// CHECK: Virtual base offset offsets for 'Test21::F'. -// CHECK-NEXT: Test21::A | -32 +// CHECK: Virtual base offset offsets for 'Test21::F' (5 entries). +// CHECK-NEXT: Test21::A | -32 // CHECK-NEXT: Test21::B | -40 // CHECK-NEXT: Test21::C | -48 // CHECK-NEXT: Test21::D | -56 diff --git a/test/Driver/cc-print-options.c b/test/Driver/cc-print-options.c new file mode 100644 index 0000000..7b798cb --- /dev/null +++ b/test/Driver/cc-print-options.c @@ -0,0 +1,7 @@ +// RUN: env CC_PRINT_OPTIONS=1 \ +// RUN: CC_PRINT_OPTIONS_FILE=%t.log \ +// RUN: %clang -S -o %t.s %s +// RUN: FileCheck %s < %t.log + +// CHECK: [Logging clang options]{{.*}}clang{{.*}}"-S" + diff --git a/test/Driver/darwin-ld.c b/test/Driver/darwin-ld.c index d34d566..9ae81f1 100644 --- a/test/Driver/darwin-ld.c +++ b/test/Driver/darwin-ld.c @@ -32,8 +32,8 @@ // // Note that at conception, this exactly matches gcc. -// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -A ARG0 -F ARG1 -L ARG2 -Mach -T ARG4 -X -Z -all_load -allowable_client ARG8 -bind_at_load -compatibility_version ARG11 -current_version ARG12 -d -dead_strip -dylib_file ARG14 -dylinker -dylinker_install_name ARG16 -dynamic -dynamiclib -e ARG19 -exported_symbols_list ARG20 -fexceptions -flat_namespace -fnested-functions -fopenmp -force_cpusubtype_ALL -fpie -fprofile-arcs -headerpad_max_install_names -image_base ARG29 -init ARG30 -install_name ARG31 -m ARG33 -miphoneos-version-min=2.0 -mmacosx-version-min=10.3.2 -multi_module -multiply_defined ARG37 -multiply_defined_unused ARG38 -no_dead_strip_inits_and_terms -nodefaultlibs -nofixprebinding -nomultidefs -noprebind -noseglinkedit -nostartfiles -nostdlib -pagezero_size ARG54 -pg -prebind -prebind_all_twolevel_modules -preload -r -read_only_relocs ARG55 -s -sectalign ARG57_0 ARG57_1 ARG57_2 -sectcreate ARG58_0 ARG58_1 ARG58_2 -sectobjectsymbols ARG59_0 ARG59_1 -sectorder ARG60_0 ARG60_1 ARG60_2 -seg1addr ARG61 -seg_addr_table ARG62 -seg_addr_table_filename ARG63 -segaddr ARG64_0 ARG64_1 -segcreate ARG65_0 ARG65_1 ARG65_2 -seglinkedit -segprot ARG67_0 ARG67_1 ARG67_2 -segs_read_FOO -segs_read_only_addr ARG69 -segs_read_write_addr ARG70 -shared-libgcc -single_module -static -static-libgcc -sub_library ARG77 -sub_umbrella ARG78 -t -twolevel_namespace -twolevel_namespace_hints -u ARG82 -umbrella ARG83 -undefined ARG84 -unexported_symbols_list ARG85 -w -weak_reference_mismatches ARG87 -whatsloaded -whyload -y -filelist FOO 2> %t.log -// RUN: grep '".*ld.*" "-static" "-dylib" "-dylib_compatibility_version" "ARG11" "-dylib_current_version" "ARG12" "-arch" "i386" "-dylib_install_name" "ARG31" "-all_load" "-allowable_client" "ARG8" "-bind_at_load" "-dead_strip" "-no_dead_strip_inits_and_terms" "-dylib_file" "ARG14" "-dynamic" "-exported_symbols_list" "ARG20" "-flat_namespace" "-headerpad_max_install_names" "-image_base" "ARG29" "-init" "ARG30" "-macosx_version_min" "10.3.2" "-iphoneos_version_min" "2.0" "-nomultidefs" "-multi_module" "-single_module" "-multiply_defined" "ARG37" "-multiply_defined_unused" "ARG38" "-pie" "-prebind" "-noprebind" "-nofixprebinding" "-prebind_all_twolevel_modules" "-read_only_relocs" "ARG55" "-sectcreate" "ARG58_0" "ARG58_1" "ARG58_2" "-sectorder" "ARG60_0" "ARG60_1" "ARG60_2" "-seg1addr" "ARG61" "-segprot" "ARG67_0" "ARG67_1" "ARG67_2" "-segaddr" "ARG64_0" "ARG64_1" "-segs_read_only_addr" "ARG69" "-segs_read_write_addr" "ARG70" "-seg_addr_table" "ARG62" "-seg_addr_table_filename" "ARG63" "-sub_library" "ARG77" "-sub_umbrella" "ARG78" "-twolevel_namespace" "-twolevel_namespace_hints" "-umbrella" "ARG83" "-undefined" "ARG84" "-unexported_symbols_list" "ARG85" "-weak_reference_mismatches" "ARG87" "-X" "-y" "-w" "-pagezero_size" "ARG54" "-segs_read_FOO" "-seglinkedit" "-noseglinkedit" "-sectalign" "ARG57_0" "ARG57_1" "ARG57_2" "-sectobjectsymbols" "ARG59_0" "ARG59_1" "-segcreate" "ARG65_0" "ARG65_1" "ARG65_2" "-whyload" "-whatsloaded" "-dylinker_install_name" "ARG16" "-dylinker" "-Mach" "-d" "-s" "-t" "-Z" "-u" "ARG82" "-undefined" "ARG84" "-A" "ARG0" "-e" "ARG19" "-m" "ARG33" "-r" "-o" "a.out" "-L" "ARG2" "-lgomp" "-L/usr/lib/i686-apple-darwin.*/4.2.1" "-L/usr/lib/gcc/i686-apple-darwin.*/4.2.1" "-L/usr/lib/gcc/i686-apple-darwin.*/4.2.1" "-L/usr/lib/gcc/i686-apple-darwin.*/4.2.1/../../../i686-apple-darwin.*/4.2.1" "-L/usr/lib/gcc/i686-apple-darwin.*/4.2.1/../../.." "-filelist" "FOO" "-lgcov" "-allow_stack_execute" "-T" "ARG4" "-F" "ARG1"' %t.log +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -A ARG0 -F ARG1 -L ARG2 -Mach -T ARG4 -X -Z -all_load -allowable_client ARG8 -bind_at_load -compatibility_version ARG11 -current_version ARG12 -d -dead_strip -dylib_file ARG14 -dylinker -dylinker_install_name ARG16 -dynamic -dynamiclib -e ARG19 -exported_symbols_list ARG20 -fexceptions -flat_namespace -fnested-functions -fopenmp -force_cpusubtype_ALL -fpie -fprofile-arcs -headerpad_max_install_names -image_base ARG29 -init ARG30 -install_name ARG31 -m ARG33 -miphoneos-version-min=2.0 -mmacosx-version-min=10.3.2 -multi_module -multiply_defined ARG37 -multiply_defined_unused ARG38 -no_dead_strip_inits_and_terms -nodefaultlibs -nofixprebinding -nomultidefs -noprebind -noseglinkedit -nostartfiles -nostdlib -pagezero_size ARG54 -pg -prebind -prebind_all_twolevel_modules -preload -r -read_only_relocs ARG55 -s -sectalign ARG57_0 ARG57_1 ARG57_2 -sectcreate ARG58_0 ARG58_1 ARG58_2 -sectobjectsymbols ARG59_0 ARG59_1 -sectorder ARG60_0 ARG60_1 ARG60_2 -seg1addr ARG61 -seg_addr_table ARG62 -seg_addr_table_filename ARG63 -segaddr ARG64_0 ARG64_1 -segcreate ARG65_0 ARG65_1 ARG65_2 -seglinkedit -segprot ARG67_0 ARG67_1 ARG67_2 -segs_read_FOO -segs_read_only_addr ARG69 -segs_read_write_addr ARG70 -shared-libgcc -single_module -static -static-libgcc -sub_library ARG77 -sub_umbrella ARG78 -t -twolevel_namespace -twolevel_namespace_hints -u ARG82 -umbrella ARG83 -undefined ARG84 -unexported_symbols_list ARG85 -w -weak_reference_mismatches ARG87 -whatsloaded -whyload -y -filelist FOO -l FOO 2> %t.log +// RUN: grep '".*ld.*" "-static" "-dylib" "-dylib_compatibility_version" "ARG11" "-dylib_current_version" "ARG12" "-arch" "i386" "-dylib_install_name" "ARG31" "-all_load" "-allowable_client" "ARG8" "-bind_at_load" "-dead_strip" "-no_dead_strip_inits_and_terms" "-dylib_file" "ARG14" "-dynamic" "-exported_symbols_list" "ARG20" "-flat_namespace" "-headerpad_max_install_names" "-image_base" "ARG29" "-init" "ARG30" "-macosx_version_min" "10.3.2" "-iphoneos_version_min" "2.0" "-nomultidefs" "-multi_module" "-single_module" "-multiply_defined" "ARG37" "-multiply_defined_unused" "ARG38" "-pie" "-prebind" "-noprebind" "-nofixprebinding" "-prebind_all_twolevel_modules" "-read_only_relocs" "ARG55" "-sectcreate" "ARG58_0" "ARG58_1" "ARG58_2" "-sectorder" "ARG60_0" "ARG60_1" "ARG60_2" "-seg1addr" "ARG61" "-segprot" "ARG67_0" "ARG67_1" "ARG67_2" "-segaddr" "ARG64_0" "ARG64_1" "-segs_read_only_addr" "ARG69" "-segs_read_write_addr" "ARG70" "-seg_addr_table" "ARG62" "-seg_addr_table_filename" "ARG63" "-sub_library" "ARG77" "-sub_umbrella" "ARG78" "-twolevel_namespace" "-twolevel_namespace_hints" "-umbrella" "ARG83" "-undefined" "ARG84" "-unexported_symbols_list" "ARG85" "-weak_reference_mismatches" "ARG87" "-X" "-y" "-w" "-pagezero_size" "ARG54" "-segs_read_FOO" "-seglinkedit" "-noseglinkedit" "-sectalign" "ARG57_0" "ARG57_1" "ARG57_2" "-sectobjectsymbols" "ARG59_0" "ARG59_1" "-segcreate" "ARG65_0" "ARG65_1" "ARG65_2" "-whyload" "-whatsloaded" "-dylinker_install_name" "ARG16" "-dylinker" "-Mach" "-d" "-s" "-t" "-Z" "-u" "ARG82" "-undefined" "ARG84" "-A" "ARG0" "-e" "ARG19" "-m" "ARG33" "-r" "-o" "a.out" "-L" "ARG2" "-lgomp" "-L/usr/lib/i686-apple-darwin.*/4.2.1" "-L/usr/lib/gcc/i686-apple-darwin.*/4.2.1" "-L/usr/lib/gcc/i686-apple-darwin.*/4.2.1" "-L/usr/lib/gcc/i686-apple-darwin.*/4.2.1/../../../i686-apple-darwin.*/4.2.1" "-L/usr/lib/gcc/i686-apple-darwin.*/4.2.1/../../.." "-filelist" "FOO" "-lFOO" "-lgcov" "-allow_stack_execute" "-T" "ARG4" "-F" "ARG1"' %t.log // Don't run dsymutil on a fat build of an executable. // RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -arch i386 -arch x86_64 -g %s 2> %t.log diff --git a/test/Index/annotate-tokens-pp.c b/test/Index/annotate-tokens-pp.c new file mode 100644 index 0000000..485786e --- /dev/null +++ b/test/Index/annotate-tokens-pp.c @@ -0,0 +1,58 @@ +#define NOTHING(X,Y) +#define STILL_NOTHING NOTHING(honk,warble) +#define BAR baz +#define WIBBLE(X, Y) X##Y +NOTHING(more,junk) float WIBBLE(int, float); +int BAR STILL_NOTHING; +#include "foo.h" +#undef BAR + +// RUN: c-index-test -test-annotate-tokens=%s:2:1:9:1 -I%S/Inputs %s | FileCheck %s +// CHECK: Punctuation: "#" [2:1 - 2:2] preprocessing directive= +// CHECK: Identifier: "define" [2:2 - 2:8] preprocessing directive= +// CHECK: Identifier: "STILL_NOTHING" [2:9 - 2:22] macro definition=STILL_NOTHING +// CHECK: Identifier: "NOTHING" [2:23 - 2:30] preprocessing directive= +// CHECK: Punctuation: "(" [2:30 - 2:31] preprocessing directive= +// CHECK: Identifier: "honk" [2:31 - 2:35] preprocessing directive= +// CHECK: Punctuation: "," [2:35 - 2:36] preprocessing directive= +// CHECK: Identifier: "warble" [2:36 - 2:42] preprocessing directive= +// CHECK: Punctuation: ")" [2:42 - 2:43] preprocessing directive= +// CHECK: Punctuation: "#" [3:1 - 3:2] preprocessing directive= +// CHECK: Identifier: "define" [3:2 - 3:8] preprocessing directive= +// CHECK: Identifier: "BAR" [3:9 - 3:12] macro definition=BAR +// CHECK: Identifier: "baz" [3:13 - 3:16] preprocessing directive= +// CHECK: Punctuation: "#" [4:1 - 4:2] preprocessing directive= +// CHECK: Identifier: "define" [4:2 - 4:8] preprocessing directive= +// CHECK: Identifier: "WIBBLE" [4:9 - 4:15] macro definition=WIBBLE +// CHECK: Punctuation: "(" [4:15 - 4:16] preprocessing directive= +// CHECK: Identifier: "X" [4:16 - 4:17] preprocessing directive= +// CHECK: Punctuation: "," [4:17 - 4:18] preprocessing directive= +// CHECK: Identifier: "Y" [4:19 - 4:20] preprocessing directive= +// CHECK: Punctuation: ")" [4:20 - 4:21] preprocessing directive= +// CHECK: Identifier: "X" [4:22 - 4:23] preprocessing directive= +// CHECK: Punctuation: "##" [4:23 - 4:25] preprocessing directive= +// CHECK: Identifier: "Y" [4:25 - 4:26] preprocessing directive= +// CHECK: Identifier: "NOTHING" [5:1 - 5:8] macro instantiation=NOTHING:1:9 +// CHECK: Punctuation: "(" [5:8 - 5:9] +// CHECK: Identifier: "more" [5:9 - 5:13] +// CHECK: Punctuation: "," [5:13 - 5:14] +// CHECK: Identifier: "junk" [5:14 - 5:18] +// CHECK: Punctuation: ")" [5:18 - 5:19] +// CHECK: Keyword: "float" [5:20 - 5:25] +// CHECK: Identifier: "WIBBLE" [5:26 - 5:32] macro instantiation=WIBBLE:4:9 +// CHECK: Punctuation: "(" [5:32 - 5:33] +// CHECK: Keyword: "int" [5:33 - 5:36] +// CHECK: Punctuation: "," [5:36 - 5:37] +// CHECK: Keyword: "float" [5:38 - 5:43] +// CHECK: Punctuation: ")" [5:43 - 5:44] +// CHECK: Punctuation: ";" [5:44 - 5:45] +// CHECK: Keyword: "int" [6:1 - 6:4] +// CHECK: Identifier: "BAR" [6:5 - 6:8] macro instantiation=BAR:3:9 +// CHECK: Identifier: "STILL_NOTHING" [6:9 - 6:22] macro instantiation=STILL_NOTHING:2:9 +// CHECK: Punctuation: ";" [6:22 - 6:23] +// CHECK: Punctuation: "#" [7:1 - 7:2] preprocessing directive= +// CHECK: Identifier: "include" [7:2 - 7:9] preprocessing directive= +// CHECK: Literal: ""foo.h"" [7:10 - 7:17] preprocessing directive= +// CHECK: Punctuation: "#" [8:1 - 8:2] preprocessing directive= +// CHECK: Identifier: "undef" [8:2 - 8:7] preprocessing directive= +// CHECK: Identifier: "BAR" [8:8 - 8:11] preprocessing directive= diff --git a/test/Index/c-index-getCursor-pp.c b/test/Index/c-index-getCursor-pp.c new file mode 100644 index 0000000..67fcfef --- /dev/null +++ b/test/Index/c-index-getCursor-pp.c @@ -0,0 +1,18 @@ +#define OBSCURE(X) X +#define DECORATION + +typedef int T; +void OBSCURE(func)(int x) { + OBSCURE(T) DECORATION value; +} + +// RUN: c-index-test -cursor-at=%s:1:11 %s | FileCheck -check-prefix=CHECK-1 %s +// CHECK-1: macro definition=OBSCURE +// RUN: c-index-test -cursor-at=%s:2:14 %s | FileCheck -check-prefix=CHECK-2 %s +// CHECK-2: macro definition=DECORATION +// RUN: c-index-test -cursor-at=%s:5:7 %s | FileCheck -check-prefix=CHECK-3 %s +// CHECK-3: macro instantiation=OBSCURE:1:9 +// RUN: c-index-test -cursor-at=%s:6:6 %s | FileCheck -check-prefix=CHECK-4 %s +// CHECK-4: macro instantiation=OBSCURE:1:9 +// RUN: c-index-test -cursor-at=%s:6:19 %s | FileCheck -check-prefix=CHECK-5 %s +// CHECK-5: macro instantiation=DECORATION:2:9 diff --git a/test/Index/c-index-getCursor-test.m b/test/Index/c-index-getCursor-test.m index 8341b80..3cf1b6d 100644 --- a/test/Index/c-index-getCursor-test.m +++ b/test/Index/c-index-getCursor-test.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fblocks -emit-pch -x objective-c %s -o %t.ast +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fblocks -emit-pch -x objective-c %s -detailed-preprocessing-record -o %t.ast // RUN: c-index-test -test-file-scan %t.ast %s | FileCheck %s @interface Foo { @@ -52,6 +52,13 @@ int main (int argc, const char * argv[]) { main(someEnum, (const char **)bee); } +#define CONCAT(X, Y) X##Y + +void f() { + int CONCAT(my,_var); +} +#undef CONCAT + // CHECK: [1:1 - 3:1] Invalid Cursor => NoDeclFound // CHECK: [3:1 - 7:1] ObjCInterfaceDecl=Foo:3:12 // CHECK: [7:1 - 7:7] ObjCInstanceMethodDecl=foo:7:1 @@ -155,3 +162,7 @@ int main (int argc, const char * argv[]) { // CHECK: [52:33 - 52:36] DeclRefExpr=bee:45:8 // CHECK: [52:36 - 52:37] CallExpr=main:44:5 // CHECK: [52:37 - 53:2] UnexposedStmt= +// CHECK: [55:9 - 55:26] macro definition=CONCAT +// CHECK: [57:6 - 57:10] FunctionDecl=f:57:6 (Definition) +// CHECK: [58:4 - 58:8] VarDecl=my_var:58:8 (Definition) +// CHECK: [58:8 - 58:14] macro instantiation=CONCAT:55:9 diff --git a/test/PCH/changed-files.c b/test/PCH/changed-files.c index 36453c4..dd08bdd 100644 --- a/test/PCH/changed-files.c +++ b/test/PCH/changed-files.c @@ -1,11 +1,26 @@ const char *s0 = m0; +int s1 = m1; +const char *s2 = m0; -// RUN: echo '#define m0 ""' > %t.h -// RUN: %clang_cc1 -emit-pch -o %t.h.pch %t.h -// RUN: echo '' > %t.h -// RUN: not %clang_cc1 -include-pch %t.h.pch %s 2>&1 | grep "size of file" +// FIXME: This test fails inexplicably on Windows in a manner that makes it +// look like standard error isn't getting flushed properly. -// RUN: echo '#define m0 000' > %t.h -// RUN: %clang_cc1 -emit-pch -o %t.h.pch %t.h -// RUN: echo '' > %t.h -// RUN: not %clang_cc1 -include-pch %t.h.pch %s 2>&1 | grep "size of file" +// RUN: true +// RUNx: echo '#define m0 ""' > %t.h +// RUNx: %clang_cc1 -emit-pch -o %t.h.pch %t.h +// RUNx: echo '' > %t.h +// RUNx: not %clang_cc1 -include-pch %t.h.pch %s 2> %t.stderr +// RUNx: grep "modified" %t.stderr + +// RUNx: echo '#define m0 000' > %t.h +// RUNx: %clang_cc1 -emit-pch -o %t.h.pch %t.h +// RUNx: echo '' > %t.h +// RUNx: not %clang_cc1 -include-pch %t.h.pch %s 2> %t.stderr +// RUNx: grep "modified" %t.stderr + +// RUNx: echo '#define m0 000' > %t.h +// RUNx: echo "#define m1 'abcd'" >> %t.h +// RUNx: %clang_cc1 -emit-pch -o %t.h.pch %t.h +// RUNx: echo '' > %t.h +// RUNx: not %clang_cc1 -include-pch %t.h.pch %s 2> %t.stderr +// RUNx: grep "modified" %t.stderr diff --git a/test/PCH/headermap.h b/test/PCH/headermap.h new file mode 100644 index 0000000..efab2d8 --- /dev/null +++ b/test/PCH/headermap.h @@ -0,0 +1,3 @@ +/* Helper for the headermap.m test */ +int x = 17; + diff --git a/test/PCH/headermap.m b/test/PCH/headermap.m new file mode 100644 index 0000000..6ba83d7 --- /dev/null +++ b/test/PCH/headermap.m @@ -0,0 +1,15 @@ +// RUN: touch %t.hmap + +// RUN: %clang_cc1 -x objective-c -emit-pch -o %t.h.pch %S/headermap.h +// RUN: %clang_cc1 -include-pch %t.h.pch %s + +// RUN: %clang_cc1 -x objective-c -emit-pch -o %t.h.pch %S/headermap.h +// RUN: %clang_cc1 -include-pch %t.h.pch -I%t.hmap %s + +// RUN: %clang_cc1 -x objective-c -I%t.hmap -emit-pch -o %t.h.pch %S/headermap.h +// RUN: %clang_cc1 -include-pch %t.h.pch %s + +// RUN: %clang_cc1 -x objective-c -I%t.hmap -emit-pch -o %t.h.pch %S/headermap.h +// RUN: %clang_cc1 -include-pch %t.h.pch -I%t.hmap %s +#import "headermap.h" + diff --git a/test/Sema/block-byref-args.c b/test/Sema/block-byref-args.c deleted file mode 100644 index 255c97b..0000000 --- a/test/Sema/block-byref-args.c +++ /dev/null @@ -1,22 +0,0 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks - -int printf(const char *, ...); - -int main(int argc, char **argv) { - __block void(*bobTheFunction)(void); - __block void(^bobTheBlock)(void); - - bobTheBlock = ^{;}; - - __block int JJJJ; - __attribute__((__blocks__(byref))) int III; - - int (^XXX)(void) = ^{ return III+JJJJ; }; - - // rdar 7671883 - __block char array[10] = {'a', 'b', 'c', 'd'}; - char (^ch)() = ^{ array[1] = 'X'; return array[5]; }; - ch(); - - return 0; -} diff --git a/test/Sema/block-misc.c b/test/Sema/block-misc.c index 1109be6..ca71ab1 100644 --- a/test/Sema/block-misc.c +++ b/test/Sema/block-misc.c @@ -214,8 +214,10 @@ void test20() { // radr://7438948 void test21() { int a[7]; // expected-note {{declared at}} + __block int b[10]; // expected-note {{declared at}} a[1] = 1; ^{ (void)a[1]; // expected-error {{cannot refer to declaration with an array type inside block}} + (void)b[1]; // expected-error {{cannot refer to declaration with an array type inside block}} }(); } diff --git a/test/Sema/invalid-init-diag.c b/test/Sema/invalid-init-diag.c index a215fa7..dec7d6c 100644 --- a/test/Sema/invalid-init-diag.c +++ b/test/Sema/invalid-init-diag.c @@ -1,4 +1,4 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only int a; -struct {int x;} x = a; // expected-error {{incompatible type initializing 'int', expected 'struct <anonymous>'}} +struct {int x;} x = a; // expected-error {{incompatible type initializing 'int', expected 'struct <anonymous}} diff --git a/test/Sema/warn-shadow.c b/test/Sema/warn-shadow.c new file mode 100644 index 0000000..c9a783b --- /dev/null +++ b/test/Sema/warn-shadow.c @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s + +int i; // expected-note 3 {{previous declaration is here}} + +void foo() { + int pass1; + int i; // expected-warning {{declaration shadows a variable in the global scope}} \ + // expected-note {{previous declaration is here}} + { + int pass2; + int i; // expected-warning {{declaration shadows a local variable}} \ + // expected-note {{previous declaration is here}} + { + int pass3; + int i; // expected-warning {{declaration shadows a local variable}} + } + } + + int sin; // okay; 'sin' has not been declared, even though it's a builtin. +} + +// <rdar://problem/7677531> +void (^test1)(int) = ^(int i) { // expected-warning {{declaration shadows a variable in the global scope}} \ + // expected-note{{previous declaration is here}} + { + int i; // expected-warning {{declaration shadows a local variable}} \ + // expected-note{{previous declaration is here}} + + (^(int i) { return i; })(i); //expected-warning {{declaration shadows a local variable}} + } +}; + + +struct test2 { + int i; +}; + +void test3(void) { + struct test4 { + int i; + }; +} + +void test4(int i) { // expected-warning {{declaration shadows a variable in the global scope}} +} diff --git a/test/Sema/x86-intrinsics-headers.c b/test/Sema/x86-intrinsics-headers.c index 006716e..24c2d92 100644 --- a/test/Sema/x86-intrinsics-headers.c +++ b/test/Sema/x86-intrinsics-headers.c @@ -21,4 +21,12 @@ #include <tmmintrin.h> # endif +# if defined(__SSE4_1__) +#include <smmintrin.h> +# endif + +# if defined(__SSE4_2__) +#include <nmmintrin.h> +# endif + #endif diff --git a/test/SemaCXX/access-base-class.cpp b/test/SemaCXX/access-base-class.cpp index eeb5f1c..25fd9e5 100644 --- a/test/SemaCXX/access-base-class.cpp +++ b/test/SemaCXX/access-base-class.cpp @@ -63,13 +63,14 @@ namespace T6 { class A {}; - class B : private A { // expected-note {{declared private here}} + class B : private A { // expected-note {{declared private here}} expected-note {{constrained by private inheritance here}} void f(C* c); }; class C : public B { void f(C *c) { - A* a = c; // expected-error {{cannot cast 'T6::C' to its private base class 'T6::A'}} + A* a = c; // expected-error {{cannot cast 'T6::C' to its private base class 'T6::A'}} \ + // expected-error {{'A' is a private member of 'T6::A'}} } }; diff --git a/test/SemaCXX/class.cpp b/test/SemaCXX/class.cpp index 743983c..508ca4d 100644 --- a/test/SemaCXX/class.cpp +++ b/test/SemaCXX/class.cpp @@ -118,3 +118,21 @@ struct S void S::f() {} // expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}} void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}} }; + +// Don't crash on this bogus code. +namespace pr6629 { + // TODO: most of these errors are spurious + template<class T1, class T2> struct foo : + bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}} \ + // BOGUS expected-error {{expected '{' after base class list}} \ + // BOGUS expected-error {{expected ';' after struct}} \ + // BOGUS expected-error {{expected unqualified-id}} \ + { }; + + template<> struct foo<unknown,unknown> { // why isn't there an error here? + template <typename U1, typename U2> struct bar { + typedef bar type; + static const int value = 0; + }; + }; +} diff --git a/test/SemaCXX/condition.cpp b/test/SemaCXX/condition.cpp index b3e862d..daa86f6 100644 --- a/test/SemaCXX/condition.cpp +++ b/test/SemaCXX/condition.cpp @@ -17,7 +17,7 @@ void test() { switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}} while (struct S {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} expected-note{{candidate constructor (the implicit copy constructor)}} - while (struct {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct <anonymous>' is not contextually convertible to 'bool'}} expected-note{{candidate constructor (the implicit copy constructor)}} + while (struct {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{not contextually convertible to 'bool'}} expected-note{{candidate constructor (the implicit copy constructor)}} switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}} \ // expected-warning{{enumeration value 'E' not handled in switch}} diff --git a/test/SemaCXX/conditional-expr.cpp b/test/SemaCXX/conditional-expr.cpp index 4fcb0bb..accc8db 100644 --- a/test/SemaCXX/conditional-expr.cpp +++ b/test/SemaCXX/conditional-expr.cpp @@ -154,8 +154,8 @@ void test() i1 = i1 ? i1 : ir1; int *pi1 = i1 ? &i1 : 0; pi1 = i1 ? 0 : &i1; - i1 = i1 ? i1 : EVal; // expected-warning {{operands of ? are integers of different signs}} ?? - i1 = i1 ? EVal : i1; // expected-warning {{operands of ? are integers of different signs}} ?? + i1 = i1 ? i1 : EVal; + i1 = i1 ? EVal : i1; d1 = i1 ? 'c' : 4.0; d1 = i1 ? 4.0 : 'c'; Base *pb = i1 ? (Base*)0 : (Derived*)0; @@ -191,7 +191,7 @@ void test() test0 = test0 ? (short) 10 : test0; test0 = test0 ? EVal : test0; - test0 = test0 ? EVal : (int) test0; // expected-warning {{operands of ? are integers of different signs}} + test0 = test0 ? EVal : (int) test0; // Note the thing that this does not test: since DR446, various situations // *must* create a separate temporary copy of class objects. This can only diff --git a/test/SemaCXX/warn-shadow.cpp b/test/SemaCXX/warn-shadow.cpp new file mode 100644 index 0000000..509c344 --- /dev/null +++ b/test/SemaCXX/warn-shadow.cpp @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -Wshadow %s + +namespace { + int i; // expected-note {{previous declaration is here}} +} + +namespace one { +namespace two { + int j; // expected-note {{previous declaration is here}} +} +} + +namespace xx { + int m; +} +namespace yy { + int m; +} + +using namespace one::two; +using namespace xx; +using namespace yy; + +void foo() { + int i; // expected-warning {{declaration shadows a variable in namespace '<anonymous>'}} + int j; // expected-warning {{declaration shadows a variable in namespace 'one::two'}} + int m; +} + +class A { + static int data; // expected-note {{previous declaration}} + int field; // expected-note {{previous declaration}} + + void test() { + char *field; // expected-warning {{declaration shadows a field of 'A'}} + char *data; // expected-warning {{declaration shadows a static data member of 'A'}} + } +}; + +// TODO: this should warn, <rdar://problem/5018057> +class B : A { + int data; + static int field; +}; diff --git a/test/SemaCXX/warn-sign-compare.cpp b/test/SemaCXX/warn-sign-compare.cpp new file mode 100644 index 0000000..3042bfd --- /dev/null +++ b/test/SemaCXX/warn-sign-compare.cpp @@ -0,0 +1,72 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -Wsign-compare %s + +// NOTE: When a 'enumeral mismatch' warning is implemented then expect several +// of the following cases to be impacted. + +// namespace for anonymous enums tests +namespace test1 { + enum { A }; + enum { B = -1 }; + + template <typename T> struct Foo { + enum { C }; + enum { D = ~0U }; + }; + + enum { E = ~0U }; + + void doit_anonymous( int i ) { + int a1 = 1 ? i : A; + int a2 = 1 ? A : i; + + int b1 = 1 ? i : B; + int b2 = 1 ? B : i; + + int c1 = 1 ? i : Foo<bool>::C; + int c2 = 1 ? Foo<bool>::C : i; + + int d1 = 1 ? i : Foo<bool>::D; // expected-warning {{operands of ? are integers of different signs}} + int d2 = 1 ? Foo<bool>::D : i; // expected-warning {{operands of ? are integers of different signs}} + int d3 = 1 ? B : Foo<bool>::D; // expected-warning {{operands of ? are integers of different signs}} + int d4 = 1 ? Foo<bool>::D : B; // expected-warning {{operands of ? are integers of different signs}} + + int e1 = 1 ? i : E; // expected-warning {{operands of ? are integers of different signs}} + int e2 = 1 ? E : i; // expected-warning {{operands of ? are integers of different signs}} + int e3 = 1 ? E : B; // expected-warning {{operands of ? are integers of different signs}} + int e4 = 1 ? B : E; // expected-warning {{operands of ? are integers of different signs}} + } +} + +// namespace for named enums tests +namespace test2 { + enum Named1 { A }; + enum Named2 { B = -1 }; + + template <typename T> struct Foo { + enum Named3 { C }; + enum Named4 { D = ~0U }; + }; + + enum Named5 { E = ~0U }; + + void doit_anonymous( int i ) { + int a1 = 1 ? i : A; + int a2 = 1 ? A : i; + + int b1 = 1 ? i : B; + int b2 = 1 ? B : i; + + int c1 = 1 ? i : Foo<bool>::C; + int c2 = 1 ? Foo<bool>::C : i; + + int d1 = 1 ? i : Foo<bool>::D; // expected-warning {{operands of ? are integers of different signs}} + int d2 = 1 ? Foo<bool>::D : i; // expected-warning {{operands of ? are integers of different signs}} + int d3 = 1 ? B : Foo<bool>::D; // expected-warning {{operands of ? are integers of different signs}} + int d4 = 1 ? Foo<bool>::D : B; // expected-warning {{operands of ? are integers of different signs}} + + int e1 = 1 ? i : E; // expected-warning {{operands of ? are integers of different signs}} + int e2 = 1 ? E : i; // expected-warning {{operands of ? are integers of different signs}} + int e3 = 1 ? E : B; // expected-warning {{operands of ? are integers of different signs}} + int e4 = 1 ? B : E; // expected-warning {{operands of ? are integers of different signs}} + } +} diff --git a/test/SemaObjC/block-type-safety.m b/test/SemaObjC/block-type-safety.m new file mode 100644 index 0000000..dab0af4 --- /dev/null +++ b/test/SemaObjC/block-type-safety.m @@ -0,0 +1,96 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks +// test for block type safety. + +@interface Super @end +@interface Sub : Super @end + +void f2(void(^f)(Super *)) { + Super *o; + f(o); +} + +void f3(void(^f)(Sub *)) { + Sub *o; + f(o); +} + +void r0(Super* (^f)()) { + Super *o = f(); +} + +void r1(Sub* (^f)()) { + Sub *o = f(); +} + +@protocol NSObject; + +void r2 (id<NSObject> (^f) (void)) { + id o = f(); +} + +void test1() { + f2(^(Sub *o) { }); // expected-error {{incompatible block pointer types passing 'void (^)(Sub *)', expected 'void (^)(Super *)'}} + f3(^(Super *o) { }); // OK, block taking Super* may be called with a Sub* + + r0(^Super* () { return 0; }); // OK + r0(^Sub* () { return 0; }); // OK, variable of type Super* gets return value of type Sub* + r0(^id () { return 0; }); // expected-error {{incompatible block pointer types passing 'id (^)(void)', expected 'Super *(^)()'}} + + r1(^Super* () { return 0; }); // expected-error {{incompatible block pointer types passing 'Super *(^)(void)', expected 'Sub *(^)()'}} + r1(^Sub* () { return 0; }); // OK + r1(^id () { return 0; }); // expected-error {{incompatible block pointer types passing 'id (^)(void)', expected 'Sub *(^)()'}} + + r2(^id<NSObject>() { return 0; }); +} + + +@interface A @end +@interface B @end + +void f0(void (^f)(A* x)) { + A* a; + f(a); +} + +void f1(void (^f)(id x)) { + B *b; + f(b); +} + +void test2(void) +{ + f0(^(id a) { }); // OK + f1(^(A* a) { }); // expected-error {{incompatible block pointer types passing 'void (^)(A *)', expected 'void (^)(id)'}} + f1(^(id<NSObject> a) { }); // OK +} + +@interface NSArray + // Calls block() with every object in the array + -enumerateObjectsWithBlock:(void (^)(id obj))block; +@end + +@interface MyThing +-(void) printThing; +@end + +@implementation MyThing + static NSArray* myThings; // array of MyThing* + + -(void) printThing { } + +// programmer wants to write this: + -printMyThings1 { + [myThings enumerateObjectsWithBlock: ^(MyThing *obj) { // expected-error {{incompatible block pointer types sending 'void (^)(MyThing *)', expected 'void (^)(id)'}} + [obj printThing]; + }]; + } + +// strict type safety requires this: + -printMyThings { + [myThings enumerateObjectsWithBlock: ^(id obj) { + MyThing *obj2 = (MyThing *)obj; + [obj2 printThing]; + }]; + } +@end + diff --git a/test/SemaObjC/class-method-self.m b/test/SemaObjC/class-method-self.m index 71509ba..6f7d1fd 100644 --- a/test/SemaObjC/class-method-self.m +++ b/test/SemaObjC/class-method-self.m @@ -18,9 +18,9 @@ typedef struct objc_class *Class; static XX *obj; + (void)classMethod { - [obj addObserver:self]; + [obj addObserver:self]; // expected-warning {{incompatible pointer types sending 'Class', expected 'XX *'}} Class whatever; - [obj addObserver:whatever]; // GCC warns about this. + [obj addObserver:whatever]; // expected-warning {{incompatible pointer types sending 'Class', expected 'XX *'}} } @end diff --git a/test/SemaObjC/comptypes-1.m b/test/SemaObjC/comptypes-1.m index 24f7041..5b1891d 100644 --- a/test/SemaObjC/comptypes-1.m +++ b/test/SemaObjC/comptypes-1.m @@ -35,7 +35,7 @@ int main() warning, unless done from an 'id'. */ obj_c = obj; /* Ok */ obj_c = obj_cp; // // expected-warning {{incompatible pointer types assigning 'MyOtherClass *', expected 'MyClass *'}} - obj_c = obj_C; + obj_c = obj_C; // expected-warning {{incompatible pointer types assigning 'Class', expected 'MyClass *'}} /* Assigning to an 'id<MyProtocol>' variable should generate a warning if done from a 'MyClass *' (which doesn't implement @@ -44,7 +44,7 @@ int main() obj_p = obj; /* Ok */ obj_p = obj_c; // expected-warning {{incompatible type assigning 'MyClass *', expected 'id<MyProtocol>'}} obj_p = obj_cp; /* Ok */ - obj_p = obj_C; // Ok + obj_p = obj_C; // expected-warning {{incompatible pointer types assigning 'Class', expected 'id<MyProtocol>'}} /* Assigning to a 'MyOtherClass *' variable should always generate a warning, unless done from an 'id' or an 'id<MyProtocol>' (since @@ -52,7 +52,7 @@ int main() obj_cp = obj; /* Ok */ obj_cp = obj_c; // expected-warning {{incompatible pointer types assigning 'MyClass *', expected 'MyOtherClass *'}} obj_cp = obj_p; /* Ok */ - obj_cp = obj_C; + obj_cp = obj_C; // expected-warning {{incompatible pointer types assigning 'Class', expected 'MyOtherClass *'}} /* Any comparison involving an 'id' must be without warnings. */ if (obj == obj_p) foo() ; /* Ok */ /*Bogus warning here in 2.95.4*/ diff --git a/test/SemaObjC/id.m b/test/SemaObjC/id.m index 98904fe..206127a 100644 --- a/test/SemaObjC/id.m +++ b/test/SemaObjC/id.m @@ -9,7 +9,8 @@ void foo() { // Test assignment compatibility of Class and id. No warning should be // produced. // rdar://6770142 - Class and id<foo> are compatible. - S = T; T = S; + S = T; // expected-warning {{incompatible pointer types assigning 'Class', expected 'id<Foo>'}} + T = S; // expected-warning {{incompatible pointer types assigning 'id<Foo>', expected 'Class'}} R = T; T = R; R = S; S = R; } diff --git a/test/SemaObjC/invalid-code.m b/test/SemaObjC/invalid-code.m index 9913a3a..2f297cf 100644 --- a/test/SemaObjC/invalid-code.m +++ b/test/SemaObjC/invalid-code.m @@ -5,3 +5,10 @@ void test1() { void *p = @1; // expected-error {{unexpected '@' in program}} } +// <rdar://problem/7495713> +// This previously triggered a crash because the class has not been defined. +@implementation RDar7495713 (rdar_7495713_cat) // expected-error{{cannot find interface declaration for 'RDar7495713'}} +- (id) rdar_7495713 { + __PRETTY_FUNCTION__; // expected-warning{{expression result unused}} +} +@end diff --git a/test/SemaObjC/ivar-in-class-extension.m b/test/SemaObjC/ivar-in-class-extension.m index 683a78f..e1a649c 100644 --- a/test/SemaObjC/ivar-in-class-extension.m +++ b/test/SemaObjC/ivar-in-class-extension.m @@ -31,12 +31,12 @@ int fn3(SomeClass *obj) { @end @interface SomeClass (Category) - { // expected-error {{ivar may be placed in a class extension}} + { // expected-error {{ivars may not be placed in categories}} int categoryIvar; } @end @interface SomeClass (Category1) - { // expected-error {{ivar may be placed in a class extension}} + { // expected-error {{ivars may not be placed in categories}} } @end diff --git a/test/SemaObjC/property-not-lvalue.m b/test/SemaObjC/property-not-lvalue.m index 473ef86..55eec3e 100644 --- a/test/SemaObjC/property-not-lvalue.m +++ b/test/SemaObjC/property-not-lvalue.m @@ -15,8 +15,8 @@ typedef struct NSSize { void foo() { Foo *f; - f.size.width = 2.2; // expected-error {{cannot assign to a sub-structure of an ivar using property assignment syntax}} - f.size.inner.dim = 200; // expected-error {{cannot assign to a sub-structure of an ivar using property assignment syntax}} + f.size.width = 2.2; // expected-error {{expression is not assignable using property assignment syntax}} + f.size.inner.dim = 200; // expected-error {{expression is not assignable using property assignment syntax}} } // radar 7628953 @@ -28,7 +28,7 @@ void foo() { @implementation Gorf - (void)MyView_sharedInit { - self.size.width = 2.2; // expected-error {{cannot assign to a sub-structure returned via a getter using property assignment syntax}} + self.size.width = 2.2; // expected-error {{expression is not assignable using property assignment syntax}} } - (NSSize)size {} @end diff --git a/test/SemaObjC/warn-incompatible-builtin-types.m b/test/SemaObjC/warn-incompatible-builtin-types.m new file mode 100644 index 0000000..2a5005a --- /dev/null +++ b/test/SemaObjC/warn-incompatible-builtin-types.m @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar 7634850 + +@interface Foo +- (void)foo:(Class)class; +@end + +void FUNC() { + Class c, c1; + SEL s1, s2; + id i, i1; + Foo *f; + [f foo:f]; // expected-warning {{incompatible pointer types sending 'Foo *', expected 'Class'}} + c = f; // expected-warning {{incompatible pointer types assigning 'Foo *', expected 'Class'}} + + c = i; + + i = c; + + c = c1; + + i = i1; + + s1 = i; // expected-warning {{incompatible pointer types assigning 'id', expected 'SEL'}} + i = s1; // expected-warning {{incompatible pointer types assigning 'SEL', expected 'id'}} + + s1 = s2; + + s1 = c; // expected-warning {{incompatible pointer types assigning 'Class', expected 'SEL'}} + + c = s1; // expected-warning {{incompatible pointer types assigning 'SEL', expected 'Class'}} + + f = i; + + f = c; // expected-warning {{incompatible pointer types assigning 'Class', expected 'Foo *'}} + + f = s1; // expected-warning {{incompatible pointer types assigning 'SEL', expected 'Foo *'}} + + i = f; + + s1 = f; // expected-warning {{incompatible pointer types assigning 'Foo *', expected 'SEL'}} +} diff --git a/test/lit.cfg b/test/lit.cfg index beb8ae0..b306331 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -119,6 +119,11 @@ def inferClang(PATH): return clang +# When running under valgrind, we mangle '-vg' onto the end of the triple so we +# can check it with XFAIL and XTARGET. +if lit.useValgrind: + config.target_triple += '-vg' + config.clang = inferClang(config.environment['PATH']) if not lit.quiet: lit.note('using clang: %r' % config.clang) |