diff options
Diffstat (limited to 'test')
331 files changed, 5373 insertions, 847 deletions
diff --git a/test/ASTMerge/Inputs/enum1.c b/test/ASTMerge/Inputs/enum1.c new file mode 100644 index 0000000..f2b9c5c --- /dev/null +++ b/test/ASTMerge/Inputs/enum1.c @@ -0,0 +1,42 @@ +// Matching +enum E1 { + E1Enumerator1, + E1Enumerator2 = 3, + E1Enumerator3 +} x1; + +// Value mismatch +enum E2 { + E2Enumerator1, + E2Enumerator2 = 3, + E2Enumerator3 +} x2; + +// Name mismatch +enum E3 { + E3Enumerator1, + E3Enumerator2 = 3, + E3Enumerator3 +} x3; + +// Missing enumerator +enum E4 { + E4Enumerator1, + E4Enumerator2, + E4Enumerator3 +} x4; + +// Extra enumerator +enum E5 { + E5Enumerator1, + E5Enumerator2, + E5Enumerator3 +} x5; + +// Matching, with typedef +typedef enum { + E6Enumerator1, + E6Enumerator2 +} E6; + +E6 x6; diff --git a/test/ASTMerge/Inputs/enum2.c b/test/ASTMerge/Inputs/enum2.c new file mode 100644 index 0000000..315b4dc --- /dev/null +++ b/test/ASTMerge/Inputs/enum2.c @@ -0,0 +1,42 @@ +// Matching +enum E1 { + E1Enumerator1, + E1Enumerator2 = 3, + E1Enumerator3 +} x1; + +// Value mismatch +enum E2 { + E2Enumerator1, + E2Enumerator2 = 4, + E2Enumerator3 +} x2; + +// Name mismatch +enum E3 { + E3Enumerator1, + E3Enumerator = 3, + E3Enumerator3 +} x3; + +// Missing enumerator +enum E4 { + E4Enumerator1, + E4Enumerator2 +} x4; + +// Extra enumerator +enum E5 { + E5Enumerator1, + E5Enumerator2, + E5Enumerator3, + E5Enumerator4 +} x5; + +// Matching, with typedef +typedef enum { + E6Enumerator1, + E6Enumerator2 +} E6; + +E6 x6; diff --git a/test/ASTMerge/Inputs/function1.c b/test/ASTMerge/Inputs/function1.c new file mode 100644 index 0000000..4523bd3 --- /dev/null +++ b/test/ASTMerge/Inputs/function1.c @@ -0,0 +1,6 @@ +void f0(int); +void f1(int, float); +void f2(); +void f3(void); +void f4(int, int); +int f5(int) __attribute__((const)); diff --git a/test/ASTMerge/Inputs/function2.c b/test/ASTMerge/Inputs/function2.c new file mode 100644 index 0000000..6ca810a --- /dev/null +++ b/test/ASTMerge/Inputs/function2.c @@ -0,0 +1,7 @@ +typedef int Int; +void f0(Int); +void f1(Int, double); +void f2(int, int); +void f3(int); +static void f4(float, float); +int f5(int) __attribute__((const)); diff --git a/test/ASTMerge/Inputs/interface1.m b/test/ASTMerge/Inputs/interface1.m new file mode 100644 index 0000000..1aa1c3b --- /dev/null +++ b/test/ASTMerge/Inputs/interface1.m @@ -0,0 +1,7 @@ +// Matches +@interface I1 +@end + +// Matches +@interface I2 : I1 +@end diff --git a/test/ASTMerge/Inputs/interface2.m b/test/ASTMerge/Inputs/interface2.m new file mode 100644 index 0000000..1aa1c3b --- /dev/null +++ b/test/ASTMerge/Inputs/interface2.m @@ -0,0 +1,7 @@ +// Matches +@interface I1 +@end + +// Matches +@interface I2 : I1 +@end diff --git a/test/ASTMerge/Inputs/lit.local.cfg b/test/ASTMerge/Inputs/lit.local.cfg new file mode 100644 index 0000000..e6f55ee --- /dev/null +++ b/test/ASTMerge/Inputs/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes = [] diff --git a/test/ASTMerge/Inputs/struct1.c b/test/ASTMerge/Inputs/struct1.c new file mode 100644 index 0000000..af2af8a --- /dev/null +++ b/test/ASTMerge/Inputs/struct1.c @@ -0,0 +1,63 @@ +typedef int Int; +typedef float Float; + +// Matches +struct S0 { + Int field1; + Float field2; +}; + +struct S0 x0; + +// Mismatch in field type +struct S1 { + Int field1; + int field2; +}; + +struct S1 x1; + +// Mismatch in tag kind. +struct S2 { int i; float f; } x2; + +// Missing fields +struct S3 { int i; float f; double d; } x3; + +// Extra fields +struct S4 { int i; } x4; + +// Bit-field matches +struct S5 { int i : 8; unsigned j : 8; } x5; + +// Bit-field mismatch +struct S6 { int i : 8; unsigned j : 8; } x6; + +// Bit-field mismatch +struct S7 { int i : 8; unsigned j : 8; } x7; + +// Incomplete type +struct S8 *x8; + +// Incomplete type +struct S9 { int i; float f; } *x9; + +// Incomplete type +struct S10 *x10; + +// Matches +struct ListNode { + int value; + struct ListNode *Next; +} xList; + +// Mismatch due to struct used internally +struct DeepError { + int value; + struct DeeperError { int i; int f; } *Deeper; +} xDeep; + +// Matches +struct { + Int i; + float f; +} x11; diff --git a/test/ASTMerge/Inputs/struct2.c b/test/ASTMerge/Inputs/struct2.c new file mode 100644 index 0000000..4b43df7 --- /dev/null +++ b/test/ASTMerge/Inputs/struct2.c @@ -0,0 +1,60 @@ +// Matches +struct S0 { + int field1; + float field2; +}; + +struct S0 x0; + +// Mismatch in field type +struct S1 { + int field1; + float field2; +}; + +struct S1 x1; + +// Mismatch in tag kind. +union S2 { int i; float f; } x2; + +// Missing fields +struct S3 { int i; float f; } x3; + +// Extra fields +struct S4 { int i; float f; } x4; + +// Bit-field matches +struct S5 { int i : 8; unsigned j : 8; } x5; + +// Bit-field mismatch +struct S6 { int i : 8; unsigned j; } x6; + +// Bit-field mismatch +struct S7 { int i : 8; unsigned j : 16; } x7; + +// Incomplete type +struct S8 { int i; float f; } *x8; + +// Incomplete type +struct S9 *x9; + +// Incomplete type +struct S10 *x10; + +// Matches +struct ListNode { + int value; + struct ListNode *Next; +} xList; + +// Mismatch due to struct used internally +struct DeepError { + int value; + struct DeeperError { int i; float f; } *Deeper; +} xDeep; + +// Matches +struct { + int i; + float f; +} x11; diff --git a/test/ASTMerge/Inputs/typedef1.c b/test/ASTMerge/Inputs/typedef1.c new file mode 100644 index 0000000..5657675 --- /dev/null +++ b/test/ASTMerge/Inputs/typedef1.c @@ -0,0 +1,4 @@ +typedef int Typedef1; +typedef int Typedef2; +Typedef1 x1; +Typedef2 x2; diff --git a/test/ASTMerge/Inputs/typedef2.c b/test/ASTMerge/Inputs/typedef2.c new file mode 100644 index 0000000..129d710 --- /dev/null +++ b/test/ASTMerge/Inputs/typedef2.c @@ -0,0 +1,4 @@ +typedef int Typedef1; +typedef double Typedef2; +Typedef1 x1; +Typedef2 x2; diff --git a/test/ASTMerge/Inputs/var1.c b/test/ASTMerge/Inputs/var1.c new file mode 100644 index 0000000..4f5cbe1 --- /dev/null +++ b/test/ASTMerge/Inputs/var1.c @@ -0,0 +1,7 @@ +int *x0; +float **x1; +#include "var1.h" +int xarray0[17]; +int xarray1[]; +int xarray2[18]; +int xarray3[18]; diff --git a/test/ASTMerge/Inputs/var1.h b/test/ASTMerge/Inputs/var1.h new file mode 100644 index 0000000..1518e17 --- /dev/null +++ b/test/ASTMerge/Inputs/var1.h @@ -0,0 +1 @@ +double x2; diff --git a/test/ASTMerge/Inputs/var2.c b/test/ASTMerge/Inputs/var2.c new file mode 100644 index 0000000..01986e4 --- /dev/null +++ b/test/ASTMerge/Inputs/var2.c @@ -0,0 +1,7 @@ +int *x0; +double *x1; +int x2; +int xarray0[17]; +int xarray1[17]; +int xarray2[]; +int xarray3[17]; diff --git a/test/ASTMerge/enum.c b/test/ASTMerge/enum.c new file mode 100644 index 0000000..9b78fd1 --- /dev/null +++ b/test/ASTMerge/enum.c @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/enum1.c +// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/enum2.c +// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +// CHECK: enum1.c:9:6: warning: type 'enum E2' has incompatible definitions in different translation units +// CHECK: enum1.c:11:3: note: enumerator 'E2Enumerator2' with value 3 here +// CHECK: enum2.c:11:3: note: enumerator 'E2Enumerator2' with value 4 here +// CHECK: enum2.c:13:3: error: external variable 'x2' declared with incompatible types in different translation units ('enum E2' vs. 'enum E2') +// CHECK: enum1.c:13:3: note: declared here with type 'enum E2' +// CHECK: enum1.c:16:6: warning: type 'enum E3' has incompatible definitions in different translation units +// CHECK: enum1.c:18:3: note: enumerator 'E3Enumerator2' with value 3 here +// CHECK: enum2.c:18:3: note: enumerator 'E3Enumerator' with value 3 here +// CHECK: enum2.c:20:3: error: external variable 'x3' declared with incompatible types in different translation units ('enum E3' vs. 'enum E3') +// CHECK: enum1.c:20:3: note: declared here with type 'enum E3' +// CHECK: enum1.c:23:6: warning: type 'enum E4' has incompatible definitions in different translation units +// CHECK: enum1.c:26:3: note: enumerator 'E4Enumerator3' with value 2 here +// CHECK: enum2.c:23:6: note: no corresponding enumerator here +// CHECK: enum2.c:26:3: error: external variable 'x4' declared with incompatible types in different translation units ('enum E4' vs. 'enum E4') +// CHECK: enum1.c:27:3: note: declared here with type 'enum E4' +// CHECK: enum1.c:30:6: warning: type 'enum E5' has incompatible definitions in different translation units +// CHECK: enum2.c:33:3: note: enumerator 'E5Enumerator4' with value 3 here +// CHECK: enum1.c:30:6: note: no corresponding enumerator here +// CHECK: enum2.c:34:3: error: external variable 'x5' declared with incompatible types in different translation units ('enum E5' vs. 'enum E5') +// CHECK: enum1.c:34:3: note: declared here with type 'enum E5' +// CHECK: 20 diagnostics generated diff --git a/test/ASTMerge/function.c b/test/ASTMerge/function.c new file mode 100644 index 0000000..581b6ec --- /dev/null +++ b/test/ASTMerge/function.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/function1.c +// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/function2.c +// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +// CHECK: function2.c:3:6: error: external function 'f1' declared with incompatible types in different translation units ('void (Int, double)' vs. 'void (int, float)') +// CHECK: function1.c:2:6: note: declared here with type 'void (int, float)' +// CHECK: function2.c:5:6: error: external function 'f3' declared with incompatible types in different translation units ('void (int)' vs. 'void (void)') +// CHECK: function1.c:4:6: note: declared here with type 'void (void)' +// CHECK: 4 diagnostics generated diff --git a/test/ASTMerge/interface.m b/test/ASTMerge/interface.m new file mode 100644 index 0000000..d6af2f4 --- /dev/null +++ b/test/ASTMerge/interface.m @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/interface1.m +// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/interface2.m +// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 + +// FIXME: FileCheck! + diff --git a/test/ASTMerge/struct.c b/test/ASTMerge/struct.c new file mode 100644 index 0000000..e72b93b --- /dev/null +++ b/test/ASTMerge/struct.c @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/struct1.c +// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/struct2.c +// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +// CHECK: struct1.c:13:8: warning: type 'struct S1' has incompatible definitions in different translation units +// CHECK: struct1.c:15:7: note: field 'field2' has type 'int' here +// CHECK: struct2.c:12:9: note: field 'field2' has type 'float' here +// CHECK: struct2.c:15:11: error: external variable 'x1' declared with incompatible types in different translation units ('struct S1' vs. 'struct S1') +// CHECK: struct1.c:18:11: note: declared here with type 'struct S1' +// CHECK: struct1.c:21:8: warning: type 'struct S2' has incompatible definitions in different translation units +// CHECK: struct2.c:18:7: note: 'S2' is a union here +// CHECK: struct2.c:18:30: error: external variable 'x2' declared with incompatible types in different translation units ('union S2' vs. 'struct S2') +// CHECK: struct1.c:21:31: note: declared here with type 'struct S2' +// CHECK: struct1.c:24:8: warning: type 'struct S3' has incompatible definitions in different translation units +// CHECK: struct1.c:24:36: note: field 'd' has type 'double' here +// CHECK: struct2.c:21:8: note: no corresponding field here +// CHECK: struct2.c:21:31: error: external variable 'x3' declared with incompatible types in different translation units ('struct S3' vs. 'struct S3') +// CHECK: struct1.c:24:41: note: declared here with type 'struct S3' +// CHECK: struct1.c:27:8: warning: type 'struct S4' has incompatible definitions in different translation units +// CHECK: struct2.c:24:26: note: field 'f' has type 'float' here +// CHECK: struct1.c:27:8: note: no corresponding field here +// CHECK: struct2.c:24:31: error: external variable 'x4' declared with incompatible types in different translation units ('struct S4' vs. 'struct S4') +// CHECK: struct1.c:27:22: note: declared here with type 'struct S4' +// CHECK: struct1.c:33:8: warning: type 'struct S6' has incompatible definitions in different translation units +// CHECK: struct1.c:33:33: note: bit-field 'j' with type 'unsigned int' and length 8 here +// CHECK: struct2.c:30:33: note: field 'j' is not a bit-field +// CHECK: struct2.c:30:38: error: external variable 'x6' declared with incompatible types in different translation units ('struct S6' vs. 'struct S6') +// CHECK: struct1.c:33:42: note: declared here with type 'struct S6' +// CHECK: struct1.c:36:8: warning: type 'struct S7' has incompatible definitions in different translation units +// CHECK: struct1.c:36:33: note: bit-field 'j' with type 'unsigned int' and length 8 here +// CHECK: struct2.c:33:33: note: bit-field 'j' with type 'unsigned int' and length 16 here +// CHECK: struct2.c:33:43: error: external variable 'x7' declared with incompatible types in different translation units ('struct S7' vs. 'struct S7') +// CHECK: struct1.c:36:42: note: declared here with type 'struct S7' +// CHECK: struct1.c:56:10: warning: type 'struct DeeperError' has incompatible definitions in different translation units +// CHECK: struct1.c:56:35: note: field 'f' has type 'int' here +// CHECK: struct2.c:53:37: note: field 'f' has type 'float' here +// CHECK: struct1.c:54:8: warning: type 'struct DeepError' has incompatible definitions in different translation units +// CHECK: struct1.c:56:41: note: field 'Deeper' has type 'struct DeeperError *' here +// CHECK: struct2.c:53:43: note: field 'Deeper' has type 'struct DeeperError *' here +// CHECK: struct2.c:54:3: error: external variable 'xDeep' declared with incompatible types in different translation units ('struct DeepError' vs. 'struct DeepError') +// CHECK: struct1.c:57:3: note: declared here with type 'struct DeepError' +// CHECK: 37 diagnostics diff --git a/test/ASTMerge/typedef.c b/test/ASTMerge/typedef.c new file mode 100644 index 0000000..4498864 --- /dev/null +++ b/test/ASTMerge/typedef.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/typedef1.c +// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/typedef2.c +// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +// CHECK: typedef2.c:4:10: error: external variable 'x2' declared with incompatible types in different translation units ('Typedef2' (aka 'double') vs. 'Typedef2' (aka 'int')) +// CHECK: typedef1.c:4:10: note: declared here with type 'Typedef2' (aka 'int') +// CHECK: 2 diagnostics diff --git a/test/ASTMerge/var.c b/test/ASTMerge/var.c new file mode 100644 index 0000000..fd30794 --- /dev/null +++ b/test/ASTMerge/var.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/var1.c +// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/var2.c +// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +// CHECK: var2.c:2:9: error: external variable 'x1' declared with incompatible types in different translation units ('double *' vs. 'float **') +// CHECK: var1.c:2:9: note: declared here with type 'float **' +// CHECK: var2.c:3:5: error: external variable 'x2' declared with incompatible types in different translation units ('int' vs. 'double') +// CHECK: In file included from{{.*}}var1.c:3: +// CHECK: var1.h:1:8: note: declared here with type 'double' +// CHECK: error: external variable 'xarray3' declared with incompatible types in different translation units ('int [17]' vs. 'int [18]') +// CHECK: var1.c:7:5: note: declared here with type 'int [18]' +// CHECK: 6 diagnostics diff --git a/test/Analysis/CFDateGC.m b/test/Analysis/CFDateGC.m index 34bc3c0..abcefde 100644 --- a/test/Analysis/CFDateGC.m +++ b/test/Analysis/CFDateGC.m @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify -fobjc-gc -analyzer-constraints=basic %s -Wno-implicit-function-declaration -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify -fobjc-gc -analyzer-constraints=range %s -Wno-implicit-function-declaration -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify -fobjc-gc -disable-free %s -Wno-implicit-function-declaration -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify -fobjc-gc %s -Wno-implicit-function-declaration -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify -fobjc-gc %s -Wno-implicit-function-declaration +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify -fobjc-gc -analyzer-constraints=basic %s -Wno-implicit-function-declaration +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify -fobjc-gc -analyzer-constraints=range %s -Wno-implicit-function-declaration +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify -fobjc-gc -disable-free %s -Wno-implicit-function-declaration +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -fobjc-gc %s -Wno-implicit-function-declaration +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fobjc-gc %s -Wno-implicit-function-declaration //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from diff --git a/test/Analysis/CFNumber.c b/test/Analysis/CFNumber.c index 9e6f093..544644a 100644 --- a/test/Analysis/CFNumber.c +++ b/test/Analysis/CFNumber.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s typedef signed long CFIndex; typedef const struct __CFAllocator * CFAllocatorRef; diff --git a/test/Analysis/CFRetainRelease_NSAssertionHandler.m b/test/Analysis/CFRetainRelease_NSAssertionHandler.m index e2d1c88..ce9e6ff 100644 --- a/test/Analysis/CFRetainRelease_NSAssertionHandler.m +++ b/test/Analysis/CFRetainRelease_NSAssertionHandler.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -verify %s -analyzer-constraints=basic -analyzer-store=basic -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -verify %s -analyzer-constraints=range -analyzer-store=basic -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -verify %s -analyzer-constraints=basic -analyzer-store=region -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -verify %s -analyzer-constraints=range -analyzer-store=region +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -verify %s -analyzer-constraints=basic -analyzer-store=basic +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -verify %s -analyzer-constraints=range -analyzer-store=basic +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -verify %s -analyzer-constraints=basic -analyzer-store=region +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -verify %s -analyzer-constraints=range -analyzer-store=region typedef struct objc_selector *SEL; typedef signed char BOOL; diff --git a/test/Analysis/CGColorSpace.c b/test/Analysis/CGColorSpace.c index 7390b5a..737f1a3 100644 --- a/test/Analysis/CGColorSpace.c +++ b/test/Analysis/CGColorSpace.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s typedef struct CGColorSpace *CGColorSpaceRef; extern CGColorSpaceRef CGColorSpaceCreateDeviceRGB(void); diff --git a/test/Analysis/CheckNSError.m b/test/Analysis/CheckNSError.m index e3b1be0..6bf299d 100644 --- a/test/Analysis/CheckNSError.m +++ b/test/Analysis/CheckNSError.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s typedef signed char BOOL; diff --git a/test/Analysis/MissingDealloc.m b/test/Analysis/MissingDealloc.m index daa6460..bfd968a 100644 --- a/test/Analysis/MissingDealloc.m +++ b/test/Analysis/MissingDealloc.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -warn-objc-missing-dealloc '-DIBOutlet=__attribute__((iboutlet))' %s -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-missing-dealloc '-DIBOutlet=__attribute__((iboutlet))' %s -verify typedef signed char BOOL; @protocol NSObject - (BOOL)isEqual:(id)object; diff --git a/test/Analysis/NSPanel.m b/test/Analysis/NSPanel.m index b2863e0..7ebe18f 100644 --- a/test/Analysis/NSPanel.m +++ b/test/Analysis/NSPanel.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s // BEGIN delta-debugging reduced header stuff diff --git a/test/Analysis/NSString.m b/test/Analysis/NSString.m index 515b9f7..fa81b3d 100644 --- a/test/Analysis/NSString.m +++ b/test/Analysis/NSString.m @@ -1,13 +1,13 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s // ==-- FIXME: -analyzer-store=basic fails on this file (false negatives). --== -// NOTWORK: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s && -// NOTWORK: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s && -// NOTWORK: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s && -// NOTWORK: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s +// NOTWORK: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s && +// NOTWORK: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s && +// NOTWORK: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s && +// NOTWORK: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from diff --git a/test/Analysis/NSWindow.m b/test/Analysis/NSWindow.m index acd3278..34e6c68 100644 --- a/test/Analysis/NSWindow.m +++ b/test/Analysis/NSWindow.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -warn-dead-stores -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -warn-dead-stores -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -warn-dead-stores -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -warn-dead-stores -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -analyzer-store=basic -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -analyzer-store=basic -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -analyzer-store=region -analyzer-constraints=range -verify %s // These declarations were reduced using Delta-Debugging from Foundation.h // on Mac OS X. The test cases are below. diff --git a/test/Analysis/NoReturn.m b/test/Analysis/NoReturn.m index 9d3de0f..a02c93c 100644 --- a/test/Analysis/NoReturn.m +++ b/test/Analysis/NoReturn.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s #include <stdarg.h> diff --git a/test/Analysis/ObjCProperties.m b/test/Analysis/ObjCProperties.m index 1749d71..72f3d38 100644 --- a/test/Analysis/ObjCProperties.m +++ b/test/Analysis/ObjCProperties.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic %s -verify -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range %s -verify -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic %s -verify -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range %s -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic %s -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range %s -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic %s -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range %s -verify // The point of this test cases is to exercise properties in the static // analyzer diff --git a/test/Analysis/ObjCRetSigs.m b/test/Analysis/ObjCRetSigs.m index cdc8199..a76d7b9 100644 --- a/test/Analysis/ObjCRetSigs.m +++ b/test/Analysis/ObjCRetSigs.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -warn-objc-methodsigs -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-methodsigs -verify %s int printf(const char *, ...); diff --git a/test/Analysis/PR2599.m b/test/Analysis/PR2599.m index d260961..68c8c06 100644 --- a/test/Analysis/PR2599.m +++ b/test/Analysis/PR2599.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-constraints=basic -analyzer-store=basic -checker-cfref -fobjc-gc -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-constraints=range -analyzer-store=basic -checker-cfref -fobjc-gc -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-constraints=basic -analyzer-store=basic -checker-cfref -fobjc-gc -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-constraints=range -analyzer-store=region -checker-cfref -fobjc-gc -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-constraints=basic -analyzer-store=basic -analyzer-check-objc-mem -fobjc-gc -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-constraints=range -analyzer-store=basic -analyzer-check-objc-mem -fobjc-gc -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-constraints=basic -analyzer-store=basic -analyzer-check-objc-mem -fobjc-gc -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-constraints=range -analyzer-store=region -analyzer-check-objc-mem -fobjc-gc -verify %s typedef const void * CFTypeRef; typedef const struct __CFString * CFStringRef; diff --git a/test/Analysis/PR2978.m b/test/Analysis/PR2978.m index a70e34a..1ed138e 100644 --- a/test/Analysis/PR2978.m +++ b/test/Analysis/PR2978.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -warn-objc-missing-dealloc %s -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-missing-dealloc %s -verify // Tests for the checker which checks missing/extra ivar 'release' calls // in dealloc. diff --git a/test/Analysis/PR3991.m b/test/Analysis/PR3991.m index 38566d5..3fed57e 100644 --- a/test/Analysis/PR3991.m +++ b/test/Analysis/PR3991.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s //===----------------------------------------------------------------------===// // Delta-debugging produced forward declarations. diff --git a/test/Analysis/array-struct.c b/test/Analysis/array-struct.c index 0354c06..3e46a0a 100644 --- a/test/Analysis/array-struct.c +++ b/test/Analysis/array-struct.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s struct s { int data; diff --git a/test/Analysis/blocks.m b/test/Analysis/blocks.m index ef43751..e8e96a2 100644 --- a/test/Analysis/blocks.m +++ b/test/Analysis/blocks.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -checker-cfref -analyzer-store=region -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem -analyzer-store=region -fblocks -verify %s //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from Mac OS X headers: @@ -67,3 +67,19 @@ void test1(NSString *format, ...) { __builtin_va_end(args); } + +// test2 - Test that captured variables that are uninitialized are flagged +// as such. +void test2() { + static int y = 0; + int x; + ^{ y = x + 1; }(); // expected-warning{{Variable 'x' is captured by block with a garbage value}} +} + +void test2_b() { + static int y = 0; + __block int x; + // This is also a bug, but should be found not by checking the value + // 'x' is bound at block creation. + ^{ y = x + 1; }(); // no-warning +} diff --git a/test/Analysis/casts.c b/test/Analysis/casts.c index ef398bb..1cb88e6 100644 --- a/test/Analysis/casts.c +++ b/test/Analysis/casts.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s -// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s // Test if the 'storage' region gets properly initialized after it is cast to // 'struct sockaddr *'. diff --git a/test/Analysis/casts.m b/test/Analysis/casts.m index 790f63f..c99b4d6 100644 --- a/test/Analysis/casts.m +++ b/test/Analysis/casts.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s // Test function pointer casts. Currently we track function addresses using // loc::FunctionVal. Because casts can be arbitrary, do we need to model diff --git a/test/Analysis/cfref_PR2519.c b/test/Analysis/cfref_PR2519.c index c673736..ebf3544 100644 --- a/test/Analysis/cfref_PR2519.c +++ b/test/Analysis/cfref_PR2519.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s typedef unsigned char Boolean; typedef signed long CFIndex; diff --git a/test/Analysis/cfref_rdar6080742.c b/test/Analysis/cfref_rdar6080742.c index f302733..12b0819 100644 --- a/test/Analysis/cfref_rdar6080742.c +++ b/test/Analysis/cfref_rdar6080742.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s // This test case was reported in <rdar:problem/6080742>. // It tests path-sensitivity with respect to '!(cfstring != 0)' (negation of inequality). diff --git a/test/Analysis/complex.c b/test/Analysis/complex.c index 2b4f2c4..bb2b2fe 100644 --- a/test/Analysis/complex.c +++ b/test/Analysis/complex.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -Wno-unreachable-code %s #include <stdint.h> diff --git a/test/Analysis/concrete-address.c b/test/Analysis/concrete-address.c index 443e364..07ca713 100644 --- a/test/Analysis/concrete-address.c +++ b/test/Analysis/concrete-address.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s void foo() { int *p = (int*) 0x10000; // Should not crash here. diff --git a/test/Analysis/conditional-op-missing-lhs.c b/test/Analysis/conditional-op-missing-lhs.c index 7db9284..86882a5 100644 --- a/test/Analysis/conditional-op-missing-lhs.c +++ b/test/Analysis/conditional-op-missing-lhs.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -warn-dead-stores -warn-uninit-values -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -warn-uninit-values -verify %s void f1() { diff --git a/test/Analysis/dead-stores.c b/test/Analysis/dead-stores.c index 91f2b2a..a002174 100644 --- a/test/Analysis/dead-stores.c +++ b/test/Analysis/dead-stores.c @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -warn-dead-stores -fblocks -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -warn-dead-stores -fblocks -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -warn-dead-stores -fblocks -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -warn-dead-stores -fblocks -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -warn-dead-stores -fblocks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code %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 %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 %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 %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 %s void f1() { int k, y; diff --git a/test/Analysis/dead-stores.cpp b/test/Analysis/dead-stores.cpp index 9778a11..22d446e 100644 --- a/test/Analysis/dead-stores.cpp +++ b/test/Analysis/dead-stores.cpp @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -warn-dead-stores -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -warn-dead-stores -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -warn-dead-stores -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -warn-dead-stores -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -warn-dead-stores -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -analyzer-check-dead-stores -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -analyzer-check-dead-stores -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -analyzer-check-dead-stores -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-check-dead-stores -verify -Wno-unreachable-code %s //===----------------------------------------------------------------------===// // Basic dead store checking (but in C++ mode). diff --git a/test/Analysis/dead-stores.m b/test/Analysis/dead-stores.m index d4a20a8..765a24a 100644 --- a/test/Analysis/dead-stores.m +++ b/test/Analysis/dead-stores.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -warn-dead-stores -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -verify %s typedef signed char BOOL; typedef unsigned int NSUInteger; diff --git a/test/Analysis/delegates.m b/test/Analysis/delegates.m index 876e3a0..18b4241 100644 --- a/test/Analysis/delegates.m +++ b/test/Analysis/delegates.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s //===----------------------------------------------------------------------===// diff --git a/test/Analysis/elementtype.c b/test/Analysis/elementtype.c index 4f79a31..08ffe32 100644 --- a/test/Analysis/elementtype.c +++ b/test/Analysis/elementtype.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region %s typedef struct added_obj_st { int type; diff --git a/test/Analysis/exercise-ps.c b/test/Analysis/exercise-ps.c index 27094c8..0a95b70 100644 --- a/test/Analysis/exercise-ps.c +++ b/test/Analysis/exercise-ps.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s // // Just exercise the analyzer on code that has at one point caused issues // (i.e., no assertions or crashes). diff --git a/test/Analysis/fields.c b/test/Analysis/fields.c index 2a71114..c97d4f8 100644 --- a/test/Analysis/fields.c +++ b/test/Analysis/fields.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref %s -analyzer-store=basic -verify -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref %s -analyzer-store=region -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem %s -analyzer-store=basic -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem %s -analyzer-store=region -verify unsigned foo(); typedef struct bf { unsigned x:2; } bf; diff --git a/test/Analysis/func.c b/test/Analysis/func.c index 8a951f8..53c873d 100644 --- a/test/Analysis/func.c +++ b/test/Analysis/func.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s void f(void) { void (*p)(void); diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index 7d2b718..3cce1b0 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-experimental-checks -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-experimental-checks -analyzer-store=region -verify %s typedef __typeof(sizeof(int)) size_t; void *malloc(size_t); void free(void *); @@ -57,3 +57,7 @@ void pr6069() { char *buf = doit2(); free(buf); } + +void pr6293() { + free(0); +} diff --git a/test/Analysis/misc-ps-64.m b/test/Analysis/misc-ps-64.m index 3f8836b..0dbd6cb 100644 --- a/test/Analysis/misc-ps-64.m +++ b/test/Analysis/misc-ps-64.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify -fblocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify -fblocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify -fblocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify -fblocks %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -fblocks %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -fblocks %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s // <rdar://problem/6440393> - A bunch of misc. failures involving evaluating // these expressions and building CFGs. These tests are here to prevent diff --git a/test/Analysis/misc-ps-basic-store.m b/test/Analysis/misc-ps-basic-store.m index 2ae09ad..4f8e4f6 100644 --- a/test/Analysis/misc-ps-basic-store.m +++ b/test/Analysis/misc-ps-basic-store.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify -fblocks %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify -fblocks %s //--------------------------------------------------------------------------- // Test case 'checkaccess_union' differs for region store and basic store. diff --git a/test/Analysis/misc-ps-eager-assume.m b/test/Analysis/misc-ps-eager-assume.m index c23efab..a986b8e 100644 --- a/test/Analysis/misc-ps-eager-assume.m +++ b/test/Analysis/misc-ps-eager-assume.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s -analyzer-eagerly-assume +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s -analyzer-eagerly-assume // Delta-reduced header stuff (needed for test cases). typedef signed char BOOL; diff --git a/test/Analysis/misc-ps-flat-store.c b/test/Analysis/misc-ps-flat-store.c new file mode 100644 index 0000000..8cbcecf --- /dev/null +++ b/test/Analysis/misc-ps-flat-store.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=flat -verify %s + +void f1() { + int x; + int *p; + x = 1; + p = 0; + if (x != 1) + *p = 1; // no-warning +} diff --git a/test/Analysis/misc-ps-ranges.m b/test/Analysis/misc-ps-ranges.m index df7e97c..b1afc3d 100644 --- a/test/Analysis/misc-ps-ranges.m +++ b/test/Analysis/misc-ps-ranges.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify -fblocks %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -fblocks %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s // <rdar://problem/6776949> // main's 'argc' argument is always > 0 diff --git a/test/Analysis/misc-ps-region-store-i386.m b/test/Analysis/misc-ps-region-store-i386.m index bb98668..026d4f5 100644 --- a/test/Analysis/misc-ps-region-store-i386.m +++ b/test/Analysis/misc-ps-region-store-i386.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks %s // Here is a case where a pointer is treated as integer, invalidated as an // integer, and then used again as a pointer. This test just makes sure diff --git a/test/Analysis/misc-ps-region-store-x86_64.m b/test/Analysis/misc-ps-region-store-x86_64.m index 3f30327..e3c6d47 100644 --- a/test/Analysis/misc-ps-region-store-x86_64.m +++ b/test/Analysis/misc-ps-region-store-x86_64.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks %s // Here is a case where a pointer is treated as integer, invalidated as an // integer, and then used again as a pointer. This test just makes sure diff --git a/test/Analysis/misc-ps-region-store.cpp b/test/Analysis/misc-ps-region-store.cpp index 8b58131..6794d48 100644 --- a/test/Analysis/misc-ps-region-store.cpp +++ b/test/Analysis/misc-ps-region-store.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s // Test basic handling of references. char &test1_aux(); diff --git a/test/Analysis/misc-ps-region-store.m b/test/Analysis/misc-ps-region-store.m index a88c26c..201cbc9 100644 --- a/test/Analysis/misc-ps-region-store.m +++ b/test/Analysis/misc-ps-region-store.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -DTEST_64 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -DTEST_64 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s typedef struct objc_selector *SEL; typedef signed char BOOL; @@ -590,6 +590,55 @@ int blocks_2(int *p, int z) { return z; } +// Test that the value of 'x' is considered invalidated after the block +// is passed as an argument to the message expression. +typedef void (^RDar7582031CB)(void); +@interface RDar7582031 +- rdar7582031:RDar7582031CB; +- rdar7582031_b:RDar7582031CB; +@end + +// Test with one block. +unsigned rdar7582031(RDar7582031 *o) { + __block unsigned x; + [o rdar7582031:^{ x = 1; }]; + return x; // no-warning +} + +// Test with two blocks. +unsigned long rdar7582031_b(RDar7582031 *o) { + __block unsigned y; + __block unsigned long x; + [o rdar7582031:^{ y = 1; }]; + [o rdar7582031_b:^{ x = 1LL; }]; + return x + (unsigned long) y; // no-warning +} + +// Show we get an error when 'o' is null because the message +// expression has no effect. +unsigned long rdar7582031_b2(RDar7582031 *o) { + __block unsigned y; + __block unsigned long x; + if (o) + return 1; + [o rdar7582031:^{ y = 1; }]; + [o rdar7582031_b:^{ x = 1LL; }]; + return x + (unsigned long) y; // expected-warning{{The left operand of '+' is a garbage value}} +} + +// Show that we handle static variables also getting invalidated. +void rdar7582031_aux(void (^)(void)); +RDar7582031 *rdar7582031_aux_2(); + +unsigned rdar7582031_static() { + static RDar7582031 *o = 0; + rdar7582031_aux(^{ o = rdar7582031_aux_2(); }); + + __block unsigned x; + [o rdar7582031:^{ x = 1; }]; + return x; // no-warning +} + //===----------------------------------------------------------------------===// // <rdar://problem/7462324> - Test that variables passed using __blocks // are not treated as being uninitialized. @@ -730,3 +779,91 @@ void rdar_7527292() { } } +//===----------------------------------------------------------------------===// +// <rdar://problem/7515938> - Handle initialization of incomplete arrays +// in structures using a compound value. Previously this crashed. +//===----------------------------------------------------------------------===// + +struct rdar_7515938 { + int x; + int y[]; +}; + +const struct rdar_7515938 *rdar_7515938() { + static const struct rdar_7515938 z = { 0, { 1, 2 } }; + if (z.y[0] != 1) { + int *p = 0; + *p = 0xDEADBEEF; // no-warning + } + return &z; +} + +struct rdar_7515938_str { + int x; + char y[]; +}; + +const struct rdar_7515938_str *rdar_7515938_str() { + static const struct rdar_7515938_str z = { 0, "hello" }; + return &z; +} + +//===----------------------------------------------------------------------===// +// Assorted test cases from PR 4172. +//===----------------------------------------------------------------------===// + +struct PR4172A_s { int *a; }; + +void PR4172A_f2(struct PR4172A_s *p); + +int PR4172A_f1(void) { + struct PR4172A_s m; + int b[4]; + m.a = b; + PR4172A_f2(&m); + return b[3]; // no-warning +} + +struct PR4172B_s { int *a; }; + +void PR4172B_f2(struct PR4172B_s *p); + +int PR4172B_f1(void) { + struct PR4172B_s m; + int x; + m.a = &x; + PR4172B_f2(&m); + return x; // no-warning +} + +//===----------------------------------------------------------------------===// +// Test invalidation of values in struct literals. +//===----------------------------------------------------------------------===// + +struct s_rev96062 { int *x; int *y; }; +struct s_rev96062_nested { struct s_rev96062 z; }; + +void test_a_rev96062_aux(struct s_rev96062 *s); +void test_a_rev96062_aux2(struct s_rev96062_nested *s); + +int test_a_rev96062() { + int a, b; + struct s_rev96062 x = { &a, &b }; + test_a_rev96062_aux(&x); + return a + b; // no-warning +} +int test_b_rev96062() { + int a, b; + struct s_rev96062 x = { &a, &b }; + struct s_rev96062 z = x; + test_a_rev96062_aux(&z); + return a + b; // no-warning +} +int test_c_rev96062() { + int a, b; + struct s_rev96062 x = { &a, &b }; + struct s_rev96062_nested w = { x }; + struct s_rev96062_nested z = w; + test_a_rev96062_aux2(&z); + return a + b; // no-warning +} diff --git a/test/Analysis/misc-ps-region-store.mm b/test/Analysis/misc-ps-region-store.mm index fd92759..92addd1 100644 --- a/test/Analysis/misc-ps-region-store.mm +++ b/test/Analysis/misc-ps-region-store.mm @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s //===------------------------------------------------------------------------------------------===// // This files tests our path-sensitive handling of Objective-c++ files. diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m index ae42dca..fa05f6f 100644 --- a/test/Analysis/misc-ps.m +++ b/test/Analysis/misc-ps.m @@ -1,12 +1,12 @@ // NOTE: Use '-fobjc-gc' to test the analysis being run twice, and multiple reports are not issued. -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -fobjc-gc -analyzer-constraints=basic -verify -fblocks %s -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify -fblocks %s -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify -fblocks %s -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -fobjc-gc -analyzer-constraints=basic -verify -fblocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify -fblocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify -fblocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -fobjc-gc -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -fobjc-gc -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s typedef struct objc_ivar *Ivar; typedef struct objc_selector *SEL; @@ -837,3 +837,99 @@ void f(kwset_t *kws, char const *p, char const *q) { d = delta[c = (end+=d)[-1]]; // no-warning trie = next[c]; } + +//===----------------------------------------------------------------------===// +// <rdar://problem/7593875> When handling sizeof(VLA) it leads to a hole in +// the ExplodedGraph (causing a false positive) +//===----------------------------------------------------------------------===// + +int rdar_7593875_aux(int x); +int rdar_7593875(int n) { + int z[n > 10 ? 10 : n]; // VLA. + int v; + v = rdar_7593875_aux(sizeof(z)); + // Previously we got a false positive about 'v' being uninitialized. + return v; // no-warning +} + +//===----------------------------------------------------------------------===// +// Handle casts from symbolic regions (packaged as integers) to doubles. +// Previously this caused an assertion failure. +//===----------------------------------------------------------------------===// + +void *foo_rev95119(); +void baz_rev95119(double x); +void bar_rev95119() { + // foo_rev95119() returns a symbolic pointer. It is then + // cast to an int which is then cast to a double. + int value = (int) foo_rev95119(); + baz_rev95119((double)value); +} + +//===----------------------------------------------------------------------===// +// Handle loading a symbolic pointer from a symbolic region that was +// invalidated by a call to an unknown function. +//===----------------------------------------------------------------------===// + +void bar_rev95192(int **x); +void foo_rev95192(int **x) { + *x = 0; + bar_rev95192(x); + // Not a null dereference. + **x = 1; // no-warning +} + +//===----------------------------------------------------------------------===// +// Handle casts of a function to a function pointer with a different return +// value. We don't yet emit an error for such cases, but we now we at least +// don't crash when the return value gets interpreted in a way that +// violates our invariants. +//===----------------------------------------------------------------------===// + +void *foo_rev95267(); +int bar_rev95267() { + char (*Callback_rev95267)(void) = (char (*)(void)) foo_rev95267; + if ((*Callback_rev95267)() == (char) 0) + return 1; + return 0; +} + +// Same as previous case, but handle casts to 'void'. +int bar_rev95274() { + void (*Callback_rev95274)(void) = (void (*)(void)) foo_rev95267; + (*Callback_rev95274)(); + return 0; +} + +void rdar7582031_test_static_init_zero() { + static unsigned x; + if (x == 0) + return; + int *p = 0; + *p = 0xDEADBEEF; +} +void rdar7582031_test_static_init_zero_b() { + static void* x; + if (x == 0) + return; + int *p = 0; + *p = 0xDEADBEEF; +} + +//===----------------------------------------------------------------------===// +// Test handling of parameters that are structs that contain floats and // +// nested fields. // +//===----------------------------------------------------------------------===// + +struct s_rev95547_nested { float x, y; }; +struct s_rev95547 { + struct s_rev95547_nested z1; + struct s_rev95547_nested z2; +}; +float foo_rev95547(struct s_rev95547 w) { + return w.z1.x + 20.0; // no-warning +} +void foo_rev95547_b(struct s_rev95547 w) { + struct s_rev95547 w2 = w; + w2.z1.x += 20.0; // no-warning +} diff --git a/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m b/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m index f4f4e5c..5722a04 100644 --- a/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m +++ b/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin8 %s -// RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin8 %s -// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin9 %s -// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin9 %s +// RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin8 %s +// RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin8 %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin9 %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin9 %s @interface MyClass {} - (void *)voidPtrM; diff --git a/test/Analysis/no-exit-cfg.c b/test/Analysis/no-exit-cfg.c index d7800f8..659f675 100644 --- a/test/Analysis/no-exit-cfg.c +++ b/test/Analysis/no-exit-cfg.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s // This is a test case for the issue reported in PR 2819: // http://llvm.org/bugs/show_bug.cgi?id=2819 diff --git a/test/Analysis/no-outofbounds.c b/test/Analysis/no-outofbounds.c index dc553cc..f9ac589 100644 --- a/test/Analysis/no-outofbounds.c +++ b/test/Analysis/no-outofbounds.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -checker-cfref -analyze -analyzer-experimental-internal-checks -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -checker-cfref -analyze -analyzer-experimental-internal-checks -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyzer-check-objc-mem -analyze -analyzer-experimental-internal-checks -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyzer-check-objc-mem -analyze -analyzer-experimental-internal-checks -analyzer-store=region -verify %s // XFAIL: * //===----------------------------------------------------------------------===// diff --git a/test/Analysis/null-deref-ps-region.c b/test/Analysis/null-deref-ps-region.c index dfd76e9..0199d20f 100644 --- a/test/Analysis/null-deref-ps-region.c +++ b/test/Analysis/null-deref-ps-region.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -std=gnu99 -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -analyzer-store=region -verify %s // The store for 'a[1]' should not be removed mistakenly. SymbolicRegions may diff --git a/test/Analysis/null-deref-ps.c b/test/Analysis/null-deref-ps.c index 6dd50a3..704ad33 100644 --- a/test/Analysis/null-deref-ps.c +++ b/test/Analysis/null-deref-ps.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -checker-cfref -verify %s -analyzer-constraints=basic -analyzer-store=basic -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -checker-cfref -verify %s -analyzer-constraints=range -analyzer-store=basic -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -checker-cfref -analyzer-store=region -analyzer-constraints=range -analyzer-no-purge-dead -verify %s -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -verify %s -analyzer-constraints=basic -analyzer-store=basic +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -verify %s -analyzer-constraints=range -analyzer-store=basic +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-no-purge-dead -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s typedef unsigned uintptr_t; diff --git a/test/Analysis/outofbound.c b/test/Analysis/outofbound.c index 68e77ca..45325e9 100644 --- a/test/Analysis/outofbound.c +++ b/test/Analysis/outofbound.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-experimental-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-experimental-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s typedef __typeof(sizeof(int)) size_t; void *malloc(size_t); diff --git a/test/Analysis/override-werror.c b/test/Analysis/override-werror.c index a2a8ec6..522b9dc 100644 --- a/test/Analysis/override-werror.c +++ b/test/Analysis/override-werror.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -Werror %s -analyzer-store=basic -verify -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -Werror %s -analyzer-store=region -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -Werror %s -analyzer-store=basic -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -Werror %s -analyzer-store=region -verify // This test case illustrates that using '-analyze' overrides the effect of // -Werror. This allows basic warnings not to interfere with producing diff --git a/test/Analysis/plist-output.m b/test/Analysis/plist-output.m index a584de8..f49fef5 100644 --- a/test/Analysis/plist-output.m +++ b/test/Analysis/plist-output.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-output=plist -o - %s | FileCheck %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-output=plist -o - %s | FileCheck %s void test_null_init(void) { int *p = 0; diff --git a/test/Analysis/pr4209.m b/test/Analysis/pr4209.m index da288e9..eb01015 100644 --- a/test/Analysis/pr4209.m +++ b/test/Analysis/pr4209.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s // This test case was crashing due to how CFRefCount.cpp resolved the // ObjCInterfaceDecl* and ClassName in EvalObjCMessageExpr. diff --git a/test/Analysis/pr_2542_rdar_6793404.m b/test/Analysis/pr_2542_rdar_6793404.m index 890fa04..feafe2a 100644 --- a/test/Analysis/pr_2542_rdar_6793404.m +++ b/test/Analysis/pr_2542_rdar_6793404.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -pedantic -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -pedantic -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -pedantic -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -pedantic -analyzer-store=region -verify %s // BEGIN delta-debugging reduced header stuff diff --git a/test/Analysis/pr_4164.c b/test/Analysis/pr_4164.c index b21b1dc..e8a410f 100644 --- a/test/Analysis/pr_4164.c +++ b/test/Analysis/pr_4164.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s // PR 4164: http://llvm.org/bugs/show_bug.cgi?id=4164 // diff --git a/test/Analysis/ptr-arith.c b/test/Analysis/ptr-arith.c index be50486..f6bd61c 100644 --- a/test/Analysis/ptr-arith.c +++ b/test/Analysis/ptr-arith.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify -triple i686-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -triple i686-apple-darwin9 %s void f1() { int a[10]; diff --git a/test/Analysis/rdar-6442306-1.m b/test/Analysis/rdar-6442306-1.m index b3558a6..a2af946 100644 --- a/test/Analysis/rdar-6442306-1.m +++ b/test/Analysis/rdar-6442306-1.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref %s -analyzer-store=basic -verify -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref %s -analyzer-store=region -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem %s -analyzer-store=basic -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem %s -analyzer-store=region -verify typedef int bar_return_t; typedef struct { diff --git a/test/Analysis/rdar-6540084.m b/test/Analysis/rdar-6540084.m index d4c67a1..dd01810 100644 --- a/test/Analysis/rdar-6540084.m +++ b/test/Analysis/rdar-6540084.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -warn-dead-stores -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -verify %s // // This test exercises the live variables analysis (LiveVariables.cpp). // The case originally identified a non-termination bug. diff --git a/test/Analysis/rdar-6541136-region.c b/test/Analysis/rdar-6541136-region.c index 9afffcb..82232c6 100644 --- a/test/Analysis/rdar-6541136-region.c +++ b/test/Analysis/rdar-6541136-region.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region %s +// RUN: %clang_cc1 -verify -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region %s struct tea_cheese { unsigned magic; }; typedef struct tea_cheese kernel_tea_cheese_t; diff --git a/test/Analysis/rdar-6541136.c b/test/Analysis/rdar-6541136.c index 423fe4b..844a936 100644 --- a/test/Analysis/rdar-6541136.c +++ b/test/Analysis/rdar-6541136.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic %s +// RUN: %clang_cc1 -verify -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic %s struct tea_cheese { unsigned magic; }; typedef struct tea_cheese kernel_tea_cheese_t; diff --git a/test/Analysis/rdar-6562655.m b/test/Analysis/rdar-6562655.m index 185649f..2aa2229 100644 --- a/test/Analysis/rdar-6562655.m +++ b/test/Analysis/rdar-6562655.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=region -verify %s // // This test case mainly checks that the retain/release checker doesn't crash // on this file. diff --git a/test/Analysis/rdar-6582778-basic-store.c b/test/Analysis/rdar-6582778-basic-store.c index a4229f7..ff32372 100644 --- a/test/Analysis/rdar-6582778-basic-store.c +++ b/test/Analysis/rdar-6582778-basic-store.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s typedef const void * CFTypeRef; typedef double CFTimeInterval; diff --git a/test/Analysis/rdar-6600344-nil-receiver-undefined-struct-ret.m b/test/Analysis/rdar-6600344-nil-receiver-undefined-struct-ret.m index 225074b..838a98b 100644 --- a/test/Analysis/rdar-6600344-nil-receiver-undefined-struct-ret.m +++ b/test/Analysis/rdar-6600344-nil-receiver-undefined-struct-ret.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s -verify -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=region %s -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=basic %s -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=region %s -verify typedef struct Foo { int x; } Bar; diff --git a/test/Analysis/rdar-7168531.m b/test/Analysis/rdar-7168531.m index 8a84b4b..bb34713 100644 --- a/test/Analysis/rdar-7168531.m +++ b/test/Analysis/rdar-7168531.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -triple i386-apple-darwin10 -analyzer-store=region -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -triple i386-apple-darwin10 -analyzer-store=basic +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -triple i386-apple-darwin10 -analyzer-store=region +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -triple i386-apple-darwin10 -analyzer-store=basic // Note that the target triple is important for this test case. It specifies that we use the // fragile Objective-C ABI. diff --git a/test/Analysis/refcnt_naming.m b/test/Analysis/refcnt_naming.m index 66210c3..9defce2 100644 --- a/test/Analysis/refcnt_naming.m +++ b/test/Analysis/refcnt_naming.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s typedef const struct __CFString * CFStringRef; typedef const struct __CFAllocator * CFAllocatorRef; diff --git a/test/Analysis/reference.cpp b/test/Analysis/reference.cpp index a641b8e..54d7cf5 100644 --- a/test/Analysis/reference.cpp +++ b/test/Analysis/reference.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s void f1() { int const &i = 3; diff --git a/test/Analysis/region-1.m b/test/Analysis/region-1.m index 1b95ac4..9274cfc 100644 --- a/test/Analysis/region-1.m +++ b/test/Analysis/region-1.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s // // This test case simply should not crash. It evaluates the logic of not // using MemRegion::getRValueType in incorrect places. diff --git a/test/Analysis/retain-release-basic-store.m b/test/Analysis/retain-release-basic-store.m index 2ef061a..751dca0 100644 --- a/test/Analysis/retain-release-basic-store.m +++ b/test/Analysis/retain-release-basic-store.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -verify %s //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from diff --git a/test/Analysis/retain-release-gc-only.m b/test/Analysis/retain-release-gc-only.m index fcec46e..8995d5f 100644 --- a/test/Analysis/retain-release-gc-only.m +++ b/test/Analysis/retain-release-gc-only.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=basic -verify -fobjc-gc-only -fblocks %s -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=region -fobjc-gc-only -fblocks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -verify -fobjc-gc-only -fblocks %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -fobjc-gc-only -fblocks -verify %s //===----------------------------------------------------------------------===// // Header stuff. diff --git a/test/Analysis/retain-release-region-store.m b/test/Analysis/retain-release-region-store.m index 3a0142b..111d4b9 100644 --- a/test/Analysis/retain-release-region-store.m +++ b/test/Analysis/retain-release-region-store.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index 691e2a2..1c41d85 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -checker-cfref -analyzer-store=basic -fblocks -verify %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -checker-cfref -analyzer-store=region -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem -analyzer-store=basic -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem -analyzer-store=region -fblocks -verify %s #if __has_feature(attribute_ns_returns_retained) #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained)) diff --git a/test/Analysis/security-syntax-checks-no-emit.c b/test/Analysis/security-syntax-checks-no-emit.c index fbfeb1a..7a71235 100644 --- a/test/Analysis/security-syntax-checks-no-emit.c +++ b/test/Analysis/security-syntax-checks-no-emit.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i686-pc-linux-gnu -analyze -warn-security-syntactic %s -verify +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -analyze -analyzer-check-security-syntactic %s -verify // This file complements 'security-syntax-checks.m', but tests that we omit // specific checks on platforms where they don't make sense. diff --git a/test/Analysis/security-syntax-checks.m b/test/Analysis/security-syntax-checks.m index cfdb030..8dd859a 100644 --- a/test/Analysis/security-syntax-checks.m +++ b/test/Analysis/security-syntax-checks.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -warn-security-syntactic %s -verify +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-check-security-syntactic %s -verify // <rdar://problem/6336718> rule request: floating point used as loop // condition (FLP30-C, FLP-30-CPP) diff --git a/test/Analysis/stack-addr-ps.c b/test/Analysis/stack-addr-ps.c index 315b900..f8cadbe 100644 --- a/test/Analysis/stack-addr-ps.c +++ b/test/Analysis/stack-addr-ps.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=basic -fblocks -verify %s -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=region -fblocks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -fblocks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -fblocks -verify %s int* f1() { int x = 0; diff --git a/test/Analysis/uninit-msg-expr.m b/test/Analysis/uninit-msg-expr.m index c8a9e3c..4061150 100644 --- a/test/Analysis/uninit-msg-expr.m +++ b/test/Analysis/uninit-msg-expr.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from diff --git a/test/Analysis/uninit-ps-rdar6145427.m b/test/Analysis/uninit-ps-rdar6145427.m index d4e3b31..1409dbd 100644 --- a/test/Analysis/uninit-ps-rdar6145427.m +++ b/test/Analysis/uninit-ps-rdar6145427.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -verify -analyzer-store=basic -checker-cfref %s -// RUN: %clang_cc1 -analyze -verify -analyzer-store=region -checker-cfref %s +// RUN: %clang_cc1 -analyze -verify -analyzer-store=basic -analyzer-check-objc-mem %s +// RUN: %clang_cc1 -analyze -verify -analyzer-store=region -analyzer-check-objc-mem %s // Delta-Debugging reduced preamble. typedef signed char BOOL; diff --git a/test/Analysis/uninit-vals-ps-region.c b/test/Analysis/uninit-vals-ps-region.c index 216856e..44f506e 100644 --- a/test/Analysis/uninit-vals-ps-region.c +++ b/test/Analysis/uninit-vals-ps-region.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s struct s { int data; diff --git a/test/Analysis/uninit-vals-ps.c b/test/Analysis/uninit-vals-ps.c index 12287a2..4abd413 100644 --- a/test/Analysis/uninit-vals-ps.c +++ b/test/Analysis/uninit-vals-ps.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s struct FPRec { void (*my_func)(int * x); diff --git a/test/Analysis/uninit-vals.m b/test/Analysis/uninit-vals.m index 037e227..2f7f29c 100644 --- a/test/Analysis/uninit-vals.m +++ b/test/Analysis/uninit-vals.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=basic -verify %s -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s typedef unsigned int NSUInteger; diff --git a/test/Analysis/unions-region.m b/test/Analysis/unions-region.m index 7fd1b44..180faf8 100644 --- a/test/Analysis/unions-region.m +++ b/test/Analysis/unions-region.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -checker-cfref -analyzer-store=region -analyzer-constraints=range %s -verify +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range %s -verify //===-- unions-region.m ---------------------------------------------------===// // diff --git a/test/Analysis/unused-ivars.m b/test/Analysis/unused-ivars.m index 2ad886f..600f0e2 100644 --- a/test/Analysis/unused-ivars.m +++ b/test/Analysis/unused-ivars.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fblocks -analyze -warn-objc-unused-ivars %s -verify +// RUN: %clang_cc1 -fblocks -analyze -analyzer-check-objc-unused-ivars %s -verify //===--- BEGIN: Delta-debugging reduced headers. --------------------------===// diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6796bbf..245fe1f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -53,7 +53,7 @@ if(PYTHONINTERP_FOUND) --param build_config=${CMAKE_CFG_INTDIR} -sv ${CLANG_TEST_EXTRA_ARGS} ${CMAKE_CURRENT_BINARY_DIR}/${testdir} - DEPENDS clang index-test c-index-test + DEPENDS clang c-index-test COMMENT "Running Clang regression tests in ${testdir}") endforeach() @@ -64,7 +64,7 @@ if(PYTHONINTERP_FOUND) --param build_config=${CMAKE_CFG_INTDIR} -sv ${CLANG_TEST_EXTRA_ARGS} ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS clang index-test c-index-test + DEPENDS clang c-index-test COMMENT "Running Clang regression tests") add_custom_target(clang-c++tests @@ -74,6 +74,6 @@ if(PYTHONINTERP_FOUND) --param build_config=${CMAKE_CFG_INTDIR} -sv ${CLANG_TEST_EXTRA_ARGS} ${CMAKE_CURRENT_SOURCE_DIR}/../utils/C++Tests - DEPENDS clang index-test c-index-test + DEPENDS clang c-index-test COMMENT "Running Clang regression tests") endif() diff --git a/test/CXX/basic/basic.def.odr/p1-var.cpp b/test/CXX/basic/basic.def.odr/p1-var.cpp new file mode 100644 index 0000000..892f546 --- /dev/null +++ b/test/CXX/basic/basic.def.odr/p1-var.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// C++ [basic.def.odr]p1: +// No translation unit shall contain more than one definition of any +// variable, [...]. + +// Bad: in C++, these are both definitions. None of that C99 tentative stuff. +int i; // expected-note {{previous}} +int i; // expected-error {{redefinition}} + +// OK: decl + def +extern int j; +int j; + +// OK: def + decl +int k; +extern int k; + +// Bad. The important thing here is that we don't emit the diagnostic twice. +int l = 1; // expected-note {{previous}} +int l = 2; // expected-error {{redefinition}} diff --git a/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp b/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp index 76b6e2b..8126d28 100644 --- a/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp +++ b/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp @@ -15,4 +15,4 @@ namespace A { } class Ident<int> GlobalIdent; -union Ident<int> GlobalIdent; // expected-error {{ tag type that does not match }} +union Ident<int> GlobalIdent2; // expected-error {{ tag type that does not match }} diff --git a/test/CXX/class.access/class.access.base/p1.cpp b/test/CXX/class.access/class.access.base/p1.cpp index fd0d9f6..1bbcedb 100644 --- a/test/CXX/class.access/class.access.base/p1.cpp +++ b/test/CXX/class.access/class.access.base/p1.cpp @@ -54,13 +54,13 @@ namespace test0 { // of the base class are accessible as protected members of the // derived class. namespace test1 { - class Base { // expected-note 6 {{constrained by protected inheritance}} - public: int pub; static int spub; // expected-note 2 {{constrained by protected inheritance}} + class Base { + public: int pub; static int spub; protected: int prot; static int sprot; // expected-note 4 {{declared protected here}} private: int priv; static int spriv; // expected-note 8 {{declared private here}} }; - class Test : protected Base { + class Test : protected Base { // expected-note 6 {{declared protected here}} expected-note 8 {{constrained by protected inheritance here}} void test() { pub++; spub++; @@ -79,19 +79,19 @@ namespace test1 { }; void test(Test *t) { - t->pub++; // expected-error {{protected member}} + t->pub++; // expected-error {{protected member}} expected-error {{protected base class}} t->spub++; // expected-error {{protected member}} - t->prot++; // expected-error {{protected member}} + t->prot++; // expected-error {{protected member}} expected-error {{protected base class}} t->sprot++; // expected-error {{protected member}} - t->priv++; // expected-error {{private member}} + t->priv++; // expected-error {{private member}} expected-error {{protected base class}} t->spriv++; // expected-error {{private member}} // Two possible errors here: one for Base, one for the member - t->Base::pub++; // expected-error {{protected member}} + t->Base::pub++; // expected-error {{protected member}} expected-error {{protected base class}} t->Base::spub++; // expected-error {{protected member}} - t->Base::prot++; // expected-error 2 {{protected member}} + t->Base::prot++; // expected-error 2 {{protected member}} expected-error {{protected base class}} t->Base::sprot++; // expected-error 2 {{protected member}} - t->Base::priv++; // expected-error {{protected member}} expected-error {{private member}} + t->Base::priv++; // expected-error {{protected member}} expected-error {{private member}} expected-error {{protected base class}} t->Base::spriv++; // expected-error {{protected member}} expected-error {{private member}} } } @@ -102,21 +102,20 @@ namespace test1 { // the base class are accessible as private members of the derived // class. namespace test2 { - class Base { //expected-note 6 {{constrained by private inheritance}} + class Base { public: - int pub; // expected-note {{constrained by private inheritance}} - static int spub; // expected-note {{constrained by private inheritance}} + int pub; + static int spub; protected: - int prot; // expected-note {{constrained by private inheritance}} \ - // expected-note {{declared protected here}} - static int sprot; // expected-note {{constrained by private inheritance}} \ - // expected-note {{declared protected here}} + int prot; // expected-note {{declared protected here}} + static int sprot; // expected-note {{declared protected here}} private: int priv; // expected-note 4 {{declared private here}} static int spriv; // expected-note 4 {{declared private here}} }; - class Test : private Base { // expected-note 6 {{'private' inheritance specifier here}} + class Test : private Base { // expected-note 6 {{declared private here}} \ + // expected-note 10 {{constrained by private inheritance here}} void test() { pub++; spub++; @@ -135,18 +134,18 @@ namespace test2 { }; void test(Test *t) { - t->pub++; // expected-error {{private member}} expected-error {{inaccessible base class}} + t->pub++; // expected-error {{private member}} expected-error {{private base class}} t->spub++; // expected-error {{private member}} - t->prot++; // expected-error {{private member}} expected-error {{inaccessible base class}} + t->prot++; // expected-error {{private member}} expected-error {{private base class}} t->sprot++; // expected-error {{private member}} - t->priv++; // expected-error {{private member}} expected-error {{inaccessible base class}} + t->priv++; // expected-error {{private member}} expected-error {{private base class}} t->spriv++; // expected-error {{private member}} - t->Base::pub++; // expected-error {{private member}} expected-error {{inaccessible base class}} + t->Base::pub++; // expected-error {{private member}} expected-error {{private base class}} t->Base::spub++; // expected-error {{private member}} - t->Base::prot++; // expected-error {{protected member}} expected-error {{private member}} expected-error {{inaccessible base class}} + t->Base::prot++; // expected-error {{protected member}} expected-error {{private member}} expected-error {{private base class}} t->Base::sprot++; // expected-error {{protected member}} expected-error {{private member}} - t->Base::priv++; // expected-error 2 {{private member}} expected-error {{inaccessible base class}} + t->Base::priv++; // expected-error 2 {{private member}} expected-error {{private base class}} t->Base::spriv++; // expected-error 2 {{private member}} } } diff --git a/test/CXX/class.access/p4.cpp b/test/CXX/class.access/p4.cpp new file mode 100644 index 0000000..7aa614c --- /dev/null +++ b/test/CXX/class.access/p4.cpp @@ -0,0 +1,114 @@ +// RUN: %clang_cc1 -fsyntax-only -faccess-control -verify %s + +// C++0x [class.access]p4: + +// Access control is applied uniformly to all names, whether the +// names are referred to from declarations or expressions. In the +// case of overloaded function names, access control is applied to +// the function selected by overload resolution. + +class Public {} PublicInst; +class Protected {} ProtectedInst; +class Private {} PrivateInst; + +namespace test0 { + class A { + public: + void foo(Public&); + protected: + void foo(Protected&); // expected-note 2 {{declared protected here}} + private: + void foo(Private&); // expected-note 2 {{declared private here}} + }; + + void test(A *op) { + op->foo(PublicInst); + op->foo(ProtectedInst); // expected-error {{'foo' is a protected member}} + op->foo(PrivateInst); // expected-error {{'foo' is a private member}} + + void (A::*a)(Public&) = &A::foo; + void (A::*b)(Protected&) = &A::foo; // expected-error {{'foo' is a protected member}} + void (A::*c)(Private&) = &A::foo; // expected-error {{'foo' is a private member}} + } +} + +// Member operators. +namespace test1 { + class A { + public: + void operator+(Public&); + void operator[](Public&); + void operator()(Public&); + typedef void (*PublicSurrogate)(Public&); + operator PublicSurrogate() const; + protected: + void operator+(Protected&); // expected-note {{declared protected here}} + void operator[](Protected&); // expected-note {{declared protected here}} + void operator()(Protected&); // expected-note {{declared protected here}} + typedef void (*ProtectedSurrogate)(Protected&); + operator ProtectedSurrogate() const; // expected-note {{declared protected here}} + private: + void operator+(Private&); // expected-note {{declared private here}} + void operator[](Private&); // expected-note {{declared private here}} + void operator()(Private&); // expected-note {{declared private here}} + void operator-(); // expected-note {{declared private here}} + typedef void (*PrivateSurrogate)(Private&); + operator PrivateSurrogate() const; // expected-note {{declared private here}} + }; + void operator+(const A &, Public&); + void operator+(const A &, Protected&); + void operator+(const A &, Private&); + void operator-(const A &); + + void test(A &a, Public &pub, Protected &prot, Private &priv) { + a + pub; + a + prot; // expected-error {{'operator+' is a protected member}} + a + priv; // expected-error {{'operator+' is a private member}} + a[pub]; + a[prot]; // expected-error {{'operator[]' is a protected member}} + a[priv]; // expected-error {{'operator[]' is a private member}} + a(pub); + a(prot); // expected-error {{'operator()' is a protected member}} + a(priv); // expected-error {{'operator()' is a private member}} + -a; // expected-error {{'operator-' is a private member}} + + const A &ca = a; + ca + pub; + ca + prot; + ca + priv; + -ca; + // These are all surrogate calls + ca(pub); + ca(prot); // expected-error {{'operator void (*)(class Protected &)' is a protected member}} + ca(priv); // expected-error {{'operator void (*)(class Private &)' is a private member}} + } +} + +// Implicit constructor calls. +namespace test2 { + class A { + private: + A(); // expected-note {{declared private here}} + + static A foo; + }; + + A a; // expected-error {{calling a private constructor}} + A A::foo; // okay +} + +// Implicit destructor calls. +namespace test3 { + class A{ + private: + ~A(); // expected-note 3 {{declared private here}} + static A foo; + }; + + A a; // expected-error {{'~A' is a private member}} + A A::foo; + + void foo(A param) { // expected-error {{'~A' is a private member}} + A local; // expected-error {{'~A' is a private member}} + } +} diff --git a/test/CXX/class.access/p6.cpp b/test/CXX/class.access/p6.cpp new file mode 100644 index 0000000..aaf510a --- /dev/null +++ b/test/CXX/class.access/p6.cpp @@ -0,0 +1,54 @@ +// RUN: %clang_cc1 -fsyntax-only -faccess-control -verify %s + +// C++0x [class.access]p6: +// All access controls in [class.access] affect the ability to +// access a class member name from a particular scope. For purposes +// of access control, the base-specifiers of a class and the +// definitions of class members that appear outside of the class +// definition are considered to be within the scope of that +// class. In particular, access controls apply as usual to member +// names accessed as part of a function return type, even though it +// is not possible to determine the access privileges of that use +// without first parsing the rest of the function +// declarator. Similarly, access control for implicit calls to the +// constructors, the conversion functions, or the destructor called +// to create and destroy a static data member is performed as if +// these calls appeared in the scope of the member's class. + +struct Public {}; struct Protected {}; struct Private {}; + +namespace test0 { + class A { + typedef int type; // expected-note {{declared private here}} + type foo(); + }; + + A::type foo() { } // expected-error {{'type' is a private member}} + A::type A::foo() { } +} + +// conversion decls +namespace test1 { + class A { + public: + A(); + operator Public (); + A(Public); + protected: + operator Protected (); // expected-note {{declared protected here}} + A(Protected); // expected-note {{declared protected here}} + private: + operator Private (); // expected-note {{declared private here}} + A(Private); // expected-note {{declared private here}} + }; + + void test() { + A a; + Public pub = a; + Protected prot = a; // expected-error {{'operator Protected' is a protected member}} + Private priv = a; // expected-error {{'operator Private' is a private member}} + A apub = pub; + A aprot = prot; // expected-error {{protected constructor}} + A apriv = priv; // expected-error {{private constructor}} + } +} diff --git a/test/CXX/class/class.local/p2.cpp b/test/CXX/class/class.local/p2.cpp index 56ff1e5..8d281a5 100644 --- a/test/CXX/class/class.local/p2.cpp +++ b/test/CXX/class/class.local/p2.cpp @@ -3,9 +3,9 @@ struct A { }; void f() { - struct B : private A {}; // expected-note{{'private' inheritance specifier here}} + struct B : private A {}; // expected-note{{declared private here}} B b; - A *a = &b; // expected-error{{conversion from 'struct B' to inaccessible base class 'struct A'}} + A *a = &b; // expected-error{{cannot cast 'struct B' to its private base class 'struct A'}} } diff --git a/test/CXX/conv/conv.mem/p4.cpp b/test/CXX/conv/conv.mem/p4.cpp new file mode 100644 index 0000000..1ecbc47 --- /dev/null +++ b/test/CXX/conv/conv.mem/p4.cpp @@ -0,0 +1,65 @@ +// RUN: %clang_cc1 -fsyntax-only -faccess-control -verify %s + +struct Base { + int data; + int method(); +}; +int (Base::*data_ptr) = &Base::data; +int (Base::*method_ptr)() = &Base::method; + +namespace test0 { + struct Derived : Base {}; + void test() { + int (Derived::*d) = data_ptr; + int (Derived::*m)() = method_ptr; + } +} + +// Can't be inaccessible. +namespace test1 { + struct Derived : private Base {}; // expected-note 2 {{declared private here}} + void test() { + int (Derived::*d) = data_ptr; // expected-error {{cannot cast private base class 'struct Base' to 'struct test1::Derived'}} + int (Derived::*m)() = method_ptr; // expected-error {{cannot cast private base class 'struct Base' to 'struct test1::Derived'}} + } +}; + +// Can't be ambiguous. +namespace test2 { + struct A : Base {}; + struct B : Base {}; + struct Derived : A, B {}; + void test() { + int (Derived::*d) = data_ptr; // expected-error {{ambiguous conversion from pointer to member of base class 'struct Base' to pointer to member of derived class 'struct test2::Derived'}} + int (Derived::*m)() = method_ptr; // expected-error {{ambiguous conversion from pointer to member of base class 'struct Base' to pointer to member of derived class 'struct test2::Derived'}} + } +} + +// Can't be virtual. +namespace test3 { + struct Derived : virtual Base {}; + void test() { + int (Derived::*d) = data_ptr; // expected-error {{conversion from pointer to member of class 'struct Base' to pointer to member of class 'struct test3::Derived' via virtual base 'struct Base' is not allowed}} + int (Derived::*m)() = method_ptr; // expected-error {{conversion from pointer to member of class 'struct Base' to pointer to member of class 'struct test3::Derived' via virtual base 'struct Base' is not allowed}} + } +} + +// Can't be virtual even if there's a non-virtual path. +namespace test4 { + struct A : Base {}; + struct Derived : Base, virtual A {}; + void test() { + int (Derived::*d) = data_ptr; // expected-error {{ambiguous conversion from pointer to member of base class 'struct Base' to pointer to member of derived class 'struct test4::Derived'}} + int (Derived::*m)() = method_ptr; // expected-error {{ambiguous conversion from pointer to member of base class 'struct Base' to pointer to member of derived class 'struct test4::Derived'}} + } +} + +// PR6254: don't get thrown off by a virtual base. +namespace test5 { + struct A {}; + struct Derived : Base, virtual A {}; + void test() { + int (Derived::*d) = data_ptr; + int (Derived::*m)() = method_ptr; + } +} diff --git a/test/CXX/conv/conv.qual/pr6089.cpp b/test/CXX/conv/conv.qual/pr6089.cpp new file mode 100644 index 0000000..ae75ec4 --- /dev/null +++ b/test/CXX/conv/conv.qual/pr6089.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +bool is_char_ptr( const char* ); + +template< class T > + long is_char_ptr( T /* r */ ); + +// Note: the const here does not lead to a qualification conversion +template< class T > + void make_range( T* const r, bool ); + +template< class T > + void make_range( T& r, long ); + +void first_finder( const char*& Search ) +{ + make_range( Search, is_char_ptr(Search) ); +} diff --git a/test/CXX/dcl.dcl/dcl.enum/p5.cpp b/test/CXX/dcl.dcl/dcl.enum/p5.cpp new file mode 100644 index 0000000..f260624 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.enum/p5.cpp @@ -0,0 +1,56 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s +template<typename T> int force_same(T, T); + +// C++ [dcl.enum]p5: +// [...] If the underlying type is not fixed, the type of each enumerator is +// the type of its initializing value: +// - If an initializer is specified for an enumerator, the initializing +// value has the same type as the expression. +enum Bullet1 { + Bullet1Val1 = 'a', + Bullet1Val2 = 10u, + Bullet1Val1IsChar = sizeof(force_same(Bullet1Val1, char(0))), + Bullet1Val2IsUnsigned = sizeof(force_same(Bullet1Val2, unsigned(0))) +}; + +// - If no initializer is specified for the first enumerator, the +// initializing value has an unspecified integral type. +enum Bullet2 { + Bullet2Val, + Bullet2ValIsInt = sizeof(force_same(Bullet2Val, int(0))) +}; + +// - Otherwise the type of the initializing value is the same as the type +// of the initializing value of the preceding enumerator unless the +// incremented value is not representable in that type, in which case the +// type is an unspecified integral type sufficient to contain the +// incremented value. If no such type exists, the program is ill-formed. +enum Bullet3a { + Bullet3aVal1 = 17, + Bullet3aVal2, + Bullet3aVal2IsInt = sizeof(force_same(Bullet3aVal2, int(0))), + Bullet3aVal3 = 2147483647, + Bullet3aVal3IsInt = sizeof(force_same(Bullet3aVal3, int(0))), + Bullet3aVal4, + Bullet3aVal4IsUnsigned = sizeof(force_same(Bullet3aVal4, 0ul)) +}; + +enum Bullet3b { + Bullet3bVal1 = 17u, + Bullet3bVal2, + Bullet3bVal2IsInt = sizeof(force_same(Bullet3bVal2, 0u)), + Bullet3bVal3 = 2147483647u, + Bullet3bVal3IsInt = sizeof(force_same(Bullet3bVal3, 0u)), + Bullet3bVal4, + Bullet3bVal4IsUnsigned = sizeof(force_same(Bullet3bVal4, 0ul)) +}; + +enum Bullet3c { + Bullet3cVal1 = 0xFFFFFFFFFFFFFFFEull, + Bullet3cVal2, + Bullet3cVal3 // expected-warning{{not representable}} +}; + +// Following the closing brace of an enum-specifier, each enumerator has the +// type of its enumeration. +int array0[sizeof(force_same(Bullet3bVal3, Bullet3b(0)))? 1 : -1]; diff --git a/test/CXX/dcl.dcl/dcl.link/p7.cpp b/test/CXX/dcl.dcl/dcl.link/p7.cpp new file mode 100644 index 0000000..bd9ff3c --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.link/p7.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +struct X { }; + +// CHECK: @x1 = global %struct.X zeroinitializer +// CHECK: @x4 = global %struct.X zeroinitializer +// CHECK: @x2 = external global %struct.X +// CHECK: @x3 = external global %struct.X +extern "C" { + + + X x1; +} + +extern "C" X x2; + +extern X x3; + +X x4; + +X& get(int i) { + if (i == 1) + return x1; + else if (i == 2) + return x2; + else if (i == 3) + return x3; + else + return x4; +} diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p6.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p6.cpp index 16a09d8..fcc1334 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p6.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p6.cpp @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -verify %s -// XFAIL: * class A { public: @@ -7,7 +6,11 @@ public: explicit operator int(); // expected-warning {{explicit conversion functions are a C++0x extension}} - explicit void f0(); // expected-error {{'explicit' cannot only be applied to constructor or conversion function}} + explicit void f0(); // expected-error {{'explicit' can only be applied to a constructor or conversion function}} + + operator bool(); }; -explicit A::A() { } // expected-error {{'explicit' cannot be specified outside class definition}} +explicit A::A() { } // expected-error {{'explicit' can only be specified inside the class definition}} +explicit A::operator bool() { return false; } // expected-warning {{explicit conversion functions are a C++0x extension}}\ + // expected-error {{'explicit' can only be specified inside the class definition}} diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp index cf3db51..d9c5d01 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp @@ -68,17 +68,23 @@ void bind_lvalue_quals(volatile Base b, volatile Derived d, volatile Base &bvr4 = dvc; // expected-error{{binding of reference to type 'struct Base volatile' to a value of type 'struct Derived const volatile' drops qualifiers}} volatile int &ir = ivc; // expected-error{{binding of reference to type 'int volatile' to a value of type 'int const volatile' drops qualifiers}} + + const volatile Base &bcvr1 = b; + const volatile Base &bcvr2 = d; } void bind_lvalue_to_rvalue() { Base &br1 = Base(); // expected-error{{non-const lvalue reference to type 'struct Base' cannot bind to a temporary of type 'struct Base'}} Base &br2 = Derived(); // expected-error{{non-const lvalue reference to type 'struct Base' cannot bind to a temporary of type 'struct Derived'}} + const volatile Base &br3 = Base(); // expected-error{{volatile lvalue reference to type 'struct Base const volatile' cannot bind to a temporary of type 'struct Base'}} + const volatile Base &br4 = Derived(); // expected-error{{volatile lvalue reference to type 'struct Base const volatile' cannot bind to a temporary of type 'struct Derived'}} int &ir = 17; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}} } void bind_lvalue_to_unrelated(Unrelated ur) { Base &br1 = ur; // expected-error{{non-const lvalue reference to type 'struct Base' cannot bind to a value of unrelated type 'struct Unrelated'}} + const volatile Base &br2 = ur; // expected-error{{volatile lvalue reference to type 'struct Base const volatile' cannot bind to a value of unrelated type 'struct Unrelated'}} } void bind_lvalue_to_conv_lvalue() { diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp new file mode 100644 index 0000000..cf52909 --- /dev/null +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +namespace PR5909 { + struct Foo { + int x : 20; + }; + + bool Test(const int& foo); + + const Foo f = { 0 }; // It compiles without the 'const'. + bool z = Test(f.x); +} diff --git a/test/CXX/dcl.decl/dcl.init/p6.cpp b/test/CXX/dcl.decl/dcl.init/p6.cpp new file mode 100644 index 0000000..f627a19 --- /dev/null +++ b/test/CXX/dcl.decl/dcl.init/p6.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// FIXME: Very incomplete! + +// If a program calls for the default initialization of an object of a +// const-qualified type T, T shall be a class type with a +// user-provided default constructor. +struct NoUserDefault { }; +struct HasUserDefault { HasUserDefault(); }; + +void test_const_default_init() { + const NoUserDefault x1; // expected-error{{default initialization of an object of const type 'struct NoUserDefault const' requires a user-provided default constructor}} + const HasUserDefault x2; + const int x3; // expected-error{{default initialization of an object of const type 'int const'}} +} diff --git a/test/CXX/dcl.decl/dcl.name/p1.cpp b/test/CXX/dcl.decl/dcl.name/p1.cpp new file mode 100644 index 0000000..7586007 --- /dev/null +++ b/test/CXX/dcl.decl/dcl.name/p1.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +namespace pr6200 { + struct v {}; + struct s { + int i; + operator struct v() { return v(); }; + }; + + void f() + { + // Neither of these is a declaration. + (void)new struct s; + (void)&s::operator struct v; + } +} diff --git a/test/CXX/expr/p8.cpp b/test/CXX/expr/p8.cpp index cc834d9..2f6c094 100644 --- a/test/CXX/expr/p8.cpp +++ b/test/CXX/expr/p8.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s int a0; -const volatile int a1; +const volatile int a1 = 2; int a2[16]; int a3(); diff --git a/test/CXX/lex/lex.literal/lex.ccon/p1.cpp b/test/CXX/lex/lex.literal/lex.ccon/p1.cpp new file mode 100644 index 0000000..7b65f7e --- /dev/null +++ b/test/CXX/lex/lex.literal/lex.ccon/p1.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Check types of char literals +extern char a; +extern __typeof('a') a; +extern int b; +extern __typeof('asdf') b; +extern wchar_t c; +extern __typeof(L'a') c; diff --git a/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp b/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp new file mode 100644 index 0000000..83365a2 --- /dev/null +++ b/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp @@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// C++0x [temp.arg.nontype]p1: +// +// A template-argument for a non-type, non-template template-parameter shall +// be one of: +// -- an integral constant expression; or +// -- the name of a non-type template-parameter ; or +namespace non_type_tmpl_param { + template <int N> struct X0 { X0(); }; + template <int N> X0<N>::X0() { } + template <int* N> struct X1 { X1(); }; + template <int* N> X1<N>::X1() { } + template <int& N> struct X3 { X3(); }; + template <int& N> X3<N>::X3() { } + template <int (*F)(int)> struct X4 { X4(); }; + template <int (*F)(int)> X4<F>::X4() { } + template <typename T, int (T::* M)(int)> struct X5 { X5(); }; + template <typename T, int (T::* M)(int)> X5<T, M>::X5() { } +} + +// -- the address of an object or function with external linkage, including +// function templates and function template-ids but excluding non-static +// class members, expressed as & id-expression where the & is optional if +// the name refers to a function or array, or if the corresponding +// template-parameter is a reference; or +namespace addr_of_obj_or_func { + template <int* p> struct X0 { }; + template <int (*fp)(int)> struct X1 { }; + // FIXME: Add reference template parameter tests. + + int i = 42; + int iarr[10]; + int f(int i); + template <typename T> T f_tmpl(T t); + void test() { + X0<&i> x0a; + X0<iarr> x0b; + X1<&f> x1a; + X1<f> x1b; + X1<f_tmpl> x1c; + X1<f_tmpl<int> > x1d; + } +} + +// -- a constant expression that evaluates to a null pointer value (4.10); or +// -- a constant expression that evaluates to a null member pointer value +// (4.11); or +// -- a pointer to member expressed as described in 5.3.1. + +namespace bad_args { + template <int* N> struct X0 { }; + int i = 42; + X0<&i + 2> x0a; // expected-error{{non-type template argument does not refer to any declaration}} + int* iptr = &i; + X0<iptr> x0b; // FIXME: This should not be accepted. +} diff --git a/test/CXX/temp/temp.arg/temp.arg.nontype/p5.cpp b/test/CXX/temp/temp.arg/temp.arg.nontype/p5.cpp new file mode 100644 index 0000000..458aff2 --- /dev/null +++ b/test/CXX/temp/temp.arg/temp.arg.nontype/p5.cpp @@ -0,0 +1,129 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// C++0x [temp.arg.nontype] p5: +// The following conversions are performed on each expression used as +// a non-type template-argument. If a non-type template-argument cannot be +// converted to the type of the corresponding template-parameter then the +// program is ill-formed. +// -- for a non-type template-parameter of integral or enumeration type, +// integral promotions (4.5) and integral conversions (4.7) are applied. +// -- for a non-type template-parameter of type pointer to object, +// qualification conversions (4.4) and the array-to-pointer conversion +// (4.2) are applied; if the template-argument is of type +// std::nullptr_t, the null pointer conversion (4.10) is applied. +namespace pointer_to_object_parameters { + // PR6226 + struct Str { + Str(const char *); + }; + + template<const char *s> + struct A { + Str get() { return s; } + }; + + char hello[6] = "Hello"; + extern const char world[6]; + const char world[6] = "world"; + void test() { + (void)A<hello>().get(); + (void)A<world>().get(); + } + + class X { + public: + X(); + X(int, int); + operator int() const; + }; + + template<X const *Ptr> struct A2; + + X *X_ptr; + X an_X; + X array_of_Xs[10]; + A2<X_ptr> *a12; + A2<array_of_Xs> *a13; + A2<&an_X> *a13_2; + A2<(&an_X)> *a13_3; // expected-error{{non-type template argument cannot be surrounded by parentheses}} + + // PR6244 + struct X1 {} X1v; + template <X1*> struct X2 { }; + template <X1* Value> struct X3 : X2<Value> { }; + struct X4 : X3<&X1v> { }; +} + +// -- For a non-type template-parameter of type reference to object, no +// conversions apply. The type referred to by the reference may be more +// cv-qualified than the (otherwise identical) type of the +// template-argument. The template-parameter is bound directly to the +// template-argument, which shall be an lvalue. +namespace reference_parameters { + template <int& N> struct S0 { }; // expected-note 3 {{template parameter is declared here}} + template <const int& N> struct S1 { }; // expected-note 2 {{template parameter is declared here}} + template <volatile int& N> struct S2 { }; // expected-note 2 {{template parameter is declared here}} + template <const volatile int& N> struct S3 { }; + int i; + extern const int ci; + volatile int vi; + extern const volatile int cvi; + void test() { + S0<i> s0; + S0<ci> s0c; // expected-error{{reference binding of non-type template parameter of type 'int &' to template argument of type 'int const' ignores qualifiers}} + S0<vi> s0v; // expected-error{{reference binding of non-type template parameter of type 'int &' to template argument of type 'int volatile' ignores qualifiers}} + S0<cvi> s0cv; // expected-error{{reference binding of non-type template parameter of type 'int &' to template argument of type 'int const volatile' ignores qualifiers}} + + S1<i> s1; + S1<ci> s1c; + S1<vi> s1v; // expected-error{{reference binding of non-type template parameter of type 'int const &' to template argument of type 'int volatile' ignores qualifiers}} + S1<cvi> s1cv; // expected-error{{reference binding of non-type template parameter of type 'int const &' to template argument of type 'int const volatile' ignores qualifiers}} + + S2<i> s2; + S2<ci> s2c; // expected-error{{reference binding of non-type template parameter of type 'int volatile &' to template argument of type 'int const' ignores qualifiers}} + S2<vi> s2v; + S2<cvi> s2cv; // expected-error{{reference binding of non-type template parameter of type 'int volatile &' to template argument of type 'int const volatile' ignores qualifiers}} + + S3<i> s3; + S3<ci> s3c; + S3<vi> s3v; + S3<cvi> s3cv; + } + + namespace PR6250 { + template <typename T, const T &ref> void inc() { + ref++; // expected-error{{read-only variable is not assignable}} + } + + template<typename T, const T &ref> void bind() { + T &ref2 = ref; // expected-error{{drops qualifiers}} + } + + int counter; + void test() { + inc<int, counter>(); // expected-note{{instantiation of}} + bind<int, counter>(); // expected-note{{instantiation of}} + } + } +} + +// -- For a non-type template-parameter of type pointer to function, the +// function-to-pointer conversion (4.3) is applied; if the +// template-argument is of type std::nullptr_t, the null pointer +// conversion (4.10) is applied. If the template-argument represents +// a set of overloaded functions (or a pointer to such), the matching +// function is selected from the set (13.4). +// -- For a non-type template-parameter of type reference to function, no +// conversions apply. If the template-argument represents a set of +// overloaded functions, the matching function is selected from the set +// (13.4). +// -- For a non-type template-parameter of type pointer to member function, +// if the template-argument is of type std::nullptr_t, the null member +// pointer conversion (4.11) is applied; otherwise, no conversions +// apply. If the template-argument represents a set of overloaded member +// functions, the matching member function is selected from the set +// (13.4). +// -- For a non-type template-parameter of type pointer to data member, +// qualification conversions (4.4) are applied; if the template-argument +// is of type std::nullptr_t, the null member pointer conversion (4.11) +// is applied. diff --git a/test/CXX/temp/temp.decls/temp.mem/p5.cpp b/test/CXX/temp/temp.decls/temp.mem/p5.cpp index 098ffa4..b0078d4 100644 --- a/test/CXX/temp/temp.decls/temp.mem/p5.cpp +++ b/test/CXX/temp/temp.decls/temp.mem/p5.cpp @@ -55,7 +55,7 @@ template double Foo::As2(); // Partial ordering with conversion function templates. struct X0 { template<typename T> operator T*() { - T x; + T x = 1; x = 17; // expected-error{{read-only variable is not assignable}} } diff --git a/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3.cpp b/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3.cpp index 8fb736c..95f9640 100644 --- a/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3.cpp +++ b/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -template<class X, class Y, class Z> X f(Y,Z); // expected-note {{candidate function}} +template<class X, class Y, class Z> X f(Y,Z); // expected-note {{candidate template ignored: couldn't infer template argument 'X'}} void g() { f<int,char*,double>("aa",3.0); diff --git a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp index bcfb71c..1b7310f 100644 --- a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp +++ b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/basic.cpp @@ -15,7 +15,8 @@ void test_f1(int *ip, float fv) { f1(ip, fv); } -template<typename T> void f2(T*, T*); // expected-note 2 {{candidate function}} +// TODO: this diagnostic can and should improve +template<typename T> void f2(T*, T*); // expected-note 2 {{candidate template ignored: failed template argument deduction}} struct ConvToIntPtr { operator int*() const; diff --git a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p6.cpp b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p6.cpp new file mode 100644 index 0000000..6edf079 --- /dev/null +++ b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p6.cpp @@ -0,0 +1,95 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +namespace test0 { + template<class T> void apply(T x, void (*f)(T)) { f(x); } // expected-note 2 {{failed template argument deduction}}\ + // expected-note {{no overload of 'temp2' matching 'void (*)(int)'}} + + template<class A> void temp(A); + void test0() { + // okay: deduce T=int from first argument, A=int during overload + apply(0, &temp); + apply(0, &temp<>); + + // okay: deduce T=int from first and second arguments + apply(0, &temp<int>); + + // deduction failure: T=int from first, T=long from second + apply(0, &temp<long>); // expected-error {{no matching function for call to 'apply'}} + } + + void over(int); + int over(long); + + void test1() { + // okay: deductions match + apply(0, &over); + + // deduction failure: deduced T=long from first argument, T=int from second + apply(0L, &over); // expected-error {{no matching function for call to 'apply'}} + } + + void over(short); + + void test2() { + // deduce T=int from first arg, second arg is undeduced context, + // pick correct overload of 'over' during overload resolution for 'apply' + apply(0, &over); + } + + template<class A, class B> B temp2(A); + void test3() { + // deduce T=int from first arg, A=int B=void during overload resolution + apply(0, &temp2); + apply(0, &temp2<>); + apply(0, &temp2<int>); + + // overload failure + apply(0, &temp2<long>); // expected-error {{no matching function for call to 'apply'}} + } +} + +namespace test1 { + template<class T> void invoke(void (*f)(T)) { f(T()); } // expected-note 6 {{couldn't infer template argument}} \ + // expected-note {{failed template argument deduction}} + + template<class T> void temp(T); + void test0() { + // deduction failure: overload has template => undeduced context + invoke(&temp); // expected-error {{no matching function for call to 'invoke'}} + invoke(&temp<>); // expected-error {{no matching function for call to 'invoke'}} + + // okay: full template-id + invoke(&temp<int>); + } + + void over(int); + int over(long); + + void test1() { + // okay: only one overload matches + invoke(&over); + } + + void over(short); + + void test2() { + // deduction failure: overload has multiple matches => undeduced context + invoke(&over); // expected-error {{no matching function for call to 'invoke'}} + } + + template<class A, class B> B temp2(A); + void test3() { + // deduction failure: overload has template => undeduced context + // (even though partial application temp2<int> could in theory + // let us infer T=int) + invoke(&temp2); // expected-error {{no matching function for call to 'invoke'}} + invoke(&temp2<>); // expected-error {{no matching function for call to 'invoke'}} + invoke(&temp2<int>); // expected-error {{no matching function for call to 'invoke'}} + + // okay: full template-id + invoke(&temp2<int, void>); + + // overload failure + invoke(&temp2<int, int>); // expected-error {{no matching function for call to 'invoke'}} + } +} diff --git a/test/CXX/temp/temp.names/p4.cpp b/test/CXX/temp/temp.names/p4.cpp new file mode 100644 index 0000000..103a1bd --- /dev/null +++ b/test/CXX/temp/temp.names/p4.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct meta { + template<typename U> + struct apply { + typedef U* type; + }; +}; + +template<typename T, typename U> +void f(typename T::template apply<U>::type); + +void test_f(int *ip) { + f<meta, int>(ip); +} diff --git a/test/CXX/temp/temp.res/temp.local/p1.cpp b/test/CXX/temp/temp.res/temp.local/p1.cpp new file mode 100644 index 0000000..ed534a4 --- /dev/null +++ b/test/CXX/temp/temp.res/temp.local/p1.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// C++0x [temp.local]p1: +// Like normal (non-template) classes, class templates have an +// injected-class-name (Clause 9). The injected-class-name can be used with +// or without a template-argument-list. When it is used without +// a template-argument-list, it is equivalent to the injected-class-name +// followed by the template-parameters of the class template enclosed in <>. + +template <typename T> struct X0 { + X0(); + ~X0(); + X0 f(const X0&); +}; + +// Test non-type template parameters. +template <int N1, const int& N2, const int* N3> struct X1 { + X1(); + ~X1(); + X1 f(const X1& x1a) { X1 x1b(x1a); return x1b; } +}; + +// When it is used with a template-argument-list, it refers to the specified +// class template specialization, which could be the current specialization +// or another specialization. +// FIXME: Test this clause. + +int i = 42; +int* iptr = &i; +void test() { + X0<int> x0; (void)x0; + X1<42, i, iptr> x1; (void)x1; +} diff --git a/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp b/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp index 3b5b5af..88cfc5d 100644 --- a/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp +++ b/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp @@ -18,7 +18,18 @@ namespace test1 { }; typedef A<int> AA; - template <> int AA::foo = 0; // expected-error {{cannot use typedef}} - int AA::bar = 1; // expected-error {{cannot use typedef}} expected-error {{template specialization requires 'template<>'}} + template <> int AA::foo = 0; + int AA::bar = 1; // expected-error {{template specialization requires 'template<>'}} int A<float>::bar = 2; // expected-error {{template specialization requires 'template<>'}} + + template <> class A<double> { + public: + static int foo; // expected-note{{attempt to specialize}} + static int bar; + }; + + typedef A<double> AB; + template <> int AB::foo = 0; // expected-error{{extraneous 'template<>'}} \ + // expected-error{{does not specialize}} + int AB::bar = 1; } diff --git a/test/CodeGen/2010-02-09-DbgSelf.m b/test/CodeGen/2010-02-09-DbgSelf.m new file mode 100644 index 0000000..e09adac --- /dev/null +++ b/test/CodeGen/2010-02-09-DbgSelf.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -x objective-c -emit-llvm -g < %s | grep "\"self\", metadata" +// Test to check that "self" argument is assigned a location. + +@interface Foo +-(void) Bar: (int)x ; +@end + + +@implementation Foo +-(void) Bar: (int)x +{ +} +@end + diff --git a/test/CodeGen/2010-02-15-Dbg-MethodStart.m b/test/CodeGen/2010-02-15-Dbg-MethodStart.m new file mode 100644 index 0000000..5186b20 --- /dev/null +++ b/test/CodeGen/2010-02-15-Dbg-MethodStart.m @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -x objective-c -emit-llvm -g < %s | grep subprogram | grep "i32 9" +// Test to check that subprogram start location. + +@interface Foo +-(int) barMethod; +@end + +@implementation Foo +-(int) barMethod { + int i = 0; + int j = 1; + int k = 1; + return i + j + k; +} +@end diff --git a/test/CodeGen/address-space-field1.c b/test/CodeGen/address-space-field1.c index 61d88f9..a81e08e 100644 --- a/test/CodeGen/address-space-field1.c +++ b/test/CodeGen/address-space-field1.c @@ -1,8 +1,8 @@ // RUN: %clang_cc1 -emit-llvm < %s -o - | FileCheck %s // CHECK:%struct.S = type { i32, i32 } // CHECK:define void @test_addrspace(%struct.S addrspace(1)* %p1, %struct.S addrspace(2)* %p2) nounwind -// CHECK: [[p1addr:%.*]] = alloca %struct.S addrspace(1)* ; <%struct.S addrspace(1)**> [#uses=3] -// CHECK: [[p2addr:%.*]] = alloca %struct.S addrspace(2)* ; <%struct.S addrspace(2)**> [#uses=3] +// CHECK: [[p1addr:%.*]] = alloca %struct.S addrspace(1)* +// CHECK: [[p2addr:%.*]] = alloca %struct.S addrspace(2)* // CHECK: store %struct.S addrspace(1)* %p1, %struct.S addrspace(1)** [[p1addr]] // CHECK: store %struct.S addrspace(2)* %p2, %struct.S addrspace(2)** [[p2addr]] // CHECK: [[t0:%.*]] = load %struct.S addrspace(2)** [[p2addr]] ; <%struct.S addrspace(2)*> [#uses=1] diff --git a/test/CodeGen/arm-arguments.c b/test/CodeGen/arm-arguments.c index fb61b0f..d313a9b 100644 --- a/test/CodeGen/arm-arguments.c +++ b/test/CodeGen/arm-arguments.c @@ -92,3 +92,64 @@ void f15(struct s7 a0) {} // APCS-GNU: define arm_apcscc void @f16() // AAPCS: define arm_aapcscc void @f16() void f16(struct s8 a0) {} + +// APCS-GNU: define arm_apcscc i32 @f17() +// AAPCS: define arm_aapcscc i32 @f17() +struct s17 { short f0 : 13; char f1 : 4; }; +struct s17 f17(void) {} + +// APCS-GNU: define arm_apcscc i32 @f18() +// AAPCS: define arm_aapcscc i32 @f18() +struct s18 { short f0; char f1 : 4; }; +struct s18 f18(void) {} + +// APCS-GNU: define arm_apcscc void @f19( +// APCS-GNU: struct.s19* noalias sret +// AAPCS: define arm_aapcscc i32 @f19() +struct s19 { int f0; struct s8 f1; }; +struct s19 f19(void) {} + +// APCS-GNU: define arm_apcscc void @f20( +// APCS-GNU: struct.s20* noalias sret +// AAPCS: define arm_aapcscc i32 @f20() +struct s20 { struct s8 f1; int f0; }; +struct s20 f20(void) {} + +// APCS-GNU: define arm_apcscc i32 @f21() +// AAPCS: define arm_aapcscc i32 @f21() +struct s21 { struct {} f1; int f0 : 4; }; +struct s21 f21(void) {} + +// APCS-GNU: define arm_apcscc i16 @f22() +// APCS-GNU: define arm_apcscc i32 @f23() +// APCS-GNU: define arm_apcscc i64 @f24() +// APCS-GNU: define arm_apcscc i128 @f25() +// APCS-GNU: define arm_apcscc i64 @f26() +// APCS-GNU: define arm_apcscc i128 @f27() +// AAPCS: define arm_aapcscc i16 @f22() +// AAPCS: define arm_aapcscc i32 @f23() +// AAPCS: define arm_aapcscc void @f24({{.*}} noalias sret +// AAPCS: define arm_aapcscc void @f25({{.*}} noalias sret +// AAPCS: define arm_aapcscc void @f26({{.*}} noalias sret +// AAPCS: define arm_aapcscc void @f27({{.*}} noalias sret +_Complex char f22(void) {} +_Complex short f23(void) {} +_Complex int f24(void) {} +_Complex long long f25(void) {} +_Complex float f26(void) {} +_Complex double f27(void) {} + +// APCS-GNU: define arm_apcscc i16 @f28() +// AAPCS: define arm_aapcscc i16 @f28() +struct s28 { _Complex char f0; }; +struct s28 f28() {} + +// APCS-GNU: define arm_apcscc i32 @f29() +// AAPCS: define arm_aapcscc i32 @f29() +struct s29 { _Complex short f0; }; +struct s29 f29() {} + +// APCS-GNU: define arm_apcscc void @f30({{.*}} noalias sret +// AAPCS: define arm_aapcscc void @f30({{.*}} noalias sret +struct s30 { _Complex int f0; }; +struct s30 f30() {} diff --git a/test/CodeGen/attributes.c b/test/CodeGen/attributes.c index 68bc73d..770ce76 100644 --- a/test/CodeGen/attributes.c +++ b/test/CodeGen/attributes.c @@ -74,3 +74,10 @@ int t19(void) { void t20(void) { __builtin_abort(); } + +void (__attribute__((fastcall)) *fptr)(int); +void t21(void) { + fptr(10); +} +// CHECK: [[FPTRVAR:%[a-z0-9]+]] = load void (i32)** @fptr +// CHECK-NEXT: call x86_fastcallcc void [[FPTRVAR]](i32 10) diff --git a/test/CodeGen/darwin-string-literals.c b/test/CodeGen/darwin-string-literals.c index b665321..8734295 100644 --- a/test/CodeGen/darwin-string-literals.c +++ b/test/CodeGen/darwin-string-literals.c @@ -2,13 +2,13 @@ // CHECK-LSB: @.str = private constant [8 x i8] c"string0\00" // CHECK-LSB: @.str1 = private constant [8 x i8] c"string1\00" -// CHECK-LSB: @.str2 = internal constant [36 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00\00", section "__TEXT,__ustring", align 2 +// CHECK-LSB: @.str2 = internal constant [36 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00\00", align 2 // RUN: %clang_cc1 -triple powerpc-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix MSB %s // CHECK-MSB: @.str = private constant [8 x i8] c"string0\00" // CHECK-MSB: @.str1 = private constant [8 x i8] c"string1\00" -// CHECK-MSB: @.str2 = internal constant [36 x i8] c"\00h\00e\00l\00l\00o\00 !\92\00 &\03\00 !\90\00 \00w\00o\00r\00l\00d\00\00", section "__TEXT,__ustring", align 2 +// CHECK-MSB: @.str2 = internal constant [36 x i8] c"\00h\00e\00l\00l\00o\00 !\92\00 &\03\00 !\90\00 \00w\00o\00r\00l\00d\00\00", align 2 const char *g0 = "string0"; const void *g1 = __builtin___CFStringMakeConstantString("string1"); diff --git a/test/CodeGen/debug-info-crash.c b/test/CodeGen/debug-info-crash.c new file mode 100644 index 0000000..e0c9dd4 --- /dev/null +++ b/test/CodeGen/debug-info-crash.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple i386-apple-darwin10 -fblocks -g -S %s -o - + +// rdar://7590323 +typedef struct dispatch_queue_s *dispatch_queue_t; +__attribute__((visibility("default"))) +extern struct dispatch_queue_s _dispatch_main_q; +typedef struct dispatch_item_s *dispatch_item_t; +typedef void (^dispatch_legacy_block_t)(dispatch_item_t); +dispatch_item_t LEGACY_dispatch_call(dispatch_queue_t dq, + dispatch_legacy_block_t dispatch_block, + dispatch_legacy_block_t callback_block) { + dispatch_queue_t lq = _dispatch_queue_get_current() ?: (&_dispatch_main_q); + dispatch_async(dq, ^{ + if (callback_block) { + dispatch_async(lq, ^{ + } + ); + } + } + ); +} diff --git a/test/CodeGen/enum.c b/test/CodeGen/enum.c index 771fc6b..eab32c1 100644 --- a/test/CodeGen/enum.c +++ b/test/CodeGen/enum.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm-bc -o - | opt -std-compile-opts | llvm-dis | grep 'ret i32 6' +// RUN: %clang_cc1 -triple i386-unknown-unknown -x c++ %s -emit-llvm-bc -o - | opt -std-compile-opts | llvm-dis | grep 'ret i32 7' static enum { foo, bar = 1U } z; diff --git a/test/CodeGen/function-attributes.c b/test/CodeGen/function-attributes.c index 8ddaa28..3a1030a 100644 --- a/test/CodeGen/function-attributes.c +++ b/test/CodeGen/function-attributes.c @@ -81,3 +81,11 @@ void f14(int a) { // CHECK: { void f15(void) { } + +// PR5254 +// CHECK: define void @f16 +// CHECK: alignstack(16) +// CHECK: { +void __attribute__((force_align_arg_pointer)) f16(void) { +} + diff --git a/test/CodeGen/stdcall-fastcall.c b/test/CodeGen/stdcall-fastcall.c index 838ccfb..bea6df3 100644 --- a/test/CodeGen/stdcall-fastcall.c +++ b/test/CodeGen/stdcall-fastcall.c @@ -1,17 +1,33 @@ -// RUN: %clang_cc1 -emit-llvm < %s | grep 'fastcallcc' | count 4 -// RUN: %clang_cc1 -emit-llvm < %s | grep 'stdcallcc' | count 4 +// RUN: %clang_cc1 -emit-llvm < %s | FileCheck %s void __attribute__((fastcall)) f1(void); void __attribute__((stdcall)) f2(void); void __attribute__((fastcall)) f3(void) { +// CHECK: define x86_fastcallcc void @f3() f1(); +// CHECK: call x86_fastcallcc void @f1() } void __attribute__((stdcall)) f4(void) { +// CHECK: define x86_stdcallcc void @f4() f2(); +// CHECK: call x86_stdcallcc void @f2() } +// PR5280 +void (__attribute__((fastcall)) *pf1)(void) = f1; +void (__attribute__((stdcall)) *pf2)(void) = f2; +void (__attribute__((fastcall)) *pf3)(void) = f3; +void (__attribute__((stdcall)) *pf4)(void) = f4; + int main(void) { f3(); f4(); + // CHECK: call x86_fastcallcc void @f3() + // CHECK: call x86_stdcallcc void @f4() + pf1(); pf2(); pf3(); pf4(); + // CHECK: call x86_fastcallcc void %{{.*}}() + // CHECK: call x86_stdcallcc void %{{.*}}() + // CHECK: call x86_fastcallcc void %{{.*}}() + // CHECK: call x86_stdcallcc void %{{.*}}() return 0; } diff --git a/test/CodeGen/union.c b/test/CodeGen/union.c index b40a405..1883ca6 100644 --- a/test/CodeGen/union.c +++ b/test/CodeGen/union.c @@ -39,3 +39,6 @@ int qfunc() {q buf; unsigned char* x = buf.x;} union RR {_Bool a : 1;} RRU; int RRF(void) {return RRU.a;} +// PR6164 +typedef union T0 { unsigned int : 0; } T0; +T0 t0; diff --git a/test/CodeGenCXX/PR4890-debug-info-dtor.cpp b/test/CodeGenCXX/PR4890-debug-info-dtor.cpp deleted file mode 100644 index bcaf1b9..0000000 --- a/test/CodeGenCXX/PR4890-debug-info-dtor.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: %clang_cc1 -emit-llvm-only -g %s -struct X { - ~X(); -}; - -X::~X() { } diff --git a/test/CodeGenCXX/alloca-align.cpp b/test/CodeGenCXX/alloca-align.cpp new file mode 100644 index 0000000..de6b34d --- /dev/null +++ b/test/CodeGenCXX/alloca-align.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s +// +// CHECK: alloca %struct.MemsetRange, align 16 + +struct MemsetRange { + int Start, End; + unsigned Alignment; + int TheStores __attribute__((aligned(16))); +}; +void foobar() { + (void) MemsetRange(); +} diff --git a/test/CodeGenCXX/anonymous-namespaces.cpp b/test/CodeGenCXX/anonymous-namespaces.cpp index 7689c94..695f8f5 100644 --- a/test/CodeGenCXX/anonymous-namespaces.cpp +++ b/test/CodeGenCXX/anonymous-namespaces.cpp @@ -1,9 +1,25 @@ // RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s + +int f(); + namespace { + // CHECK: @_ZN12_GLOBAL__N_11bE = internal global i32 0 + // CHECK: @_ZN12_GLOBAL__N_1L1cE = internal global i32 0 + // CHECK: @_ZN12_GLOBAL__N_11D1dE = internal global i32 0 // CHECK: @_ZN12_GLOBAL__N_11aE = internal global i32 0 int a = 0; + int b = f(); + + static int c = f(); + + class D { + static int d; + }; + + int D::d = f(); + // CHECK: define internal i32 @_ZN12_GLOBAL__N_13fooEv() int foo() { return 32; diff --git a/test/CodeGenCXX/attr.cpp b/test/CodeGenCXX/attr.cpp index 1b214b7..4c781c6 100644 --- a/test/CodeGenCXX/attr.cpp +++ b/test/CodeGenCXX/attr.cpp @@ -1,39 +1,20 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin -O0 -S %s -o %t.s -// RUN: FileCheck --input-file=%t.s %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s +// CHECK: define i32 @_Z3foov() nounwind align 1024 int foo() __attribute__((aligned(1024))); int foo() { } -// CHECK:.align 10, 0x90 -// CHECK:.globl __Z3foov -// CHECK:__Z3foov: - - class C { virtual void bar1() __attribute__((aligned(1))); virtual void bar2() __attribute__((aligned(2))); virtual void bar3() __attribute__((aligned(1024))); } c; -// CHECK:.align 1, 0x90 -// CHECK-NEXT:.globl __ZN1CC1Ev - +// CHECK: define void @_ZN1C4bar1Ev(%class.C* %this) nounwind align 2 void C::bar1() { } -// CHECK:.align 1, 0x90 -// CHECK-NEXT:.globl __ZN1C4bar1Ev -// CHECK-NEXT:__ZN1C4bar1Ev: - - +// CHECK: define void @_ZN1C4bar2Ev(%class.C* %this) nounwind align 2 void C::bar2() { } -// CHECK:.align 1, 0x90 -// CHECK-NEXT:.globl __ZN1C4bar2Ev -// CHECK-NEXT:__ZN1C4bar2Ev: - - +// CHECK: define void @_ZN1C4bar3Ev(%class.C* %this) nounwind align 1024 void C::bar3() { } - -// CHECK:.align 10, 0x90 -// CHECK-NEXT:.globl __ZN1C4bar3Ev -// CHECK-NEXT:__ZN1C4bar3Ev: diff --git a/test/CodeGenCXX/condition.cpp b/test/CodeGenCXX/condition.cpp index a1b7a09..e435408 100644 --- a/test/CodeGenCXX/condition.cpp +++ b/test/CodeGenCXX/condition.cpp @@ -64,7 +64,7 @@ void switch_destruct(int z) { z = 19; break; } - // CHECK: {{sw.epilog:|:4}} + // CHECK: {{sw.epilog:|:5}} // CHECK: call void @_ZN16ConvertibleToIntD1Ev // CHECK: store i32 20 z = 20; @@ -74,18 +74,18 @@ int foo(); void while_destruct(int z) { // CHECK: define void @_Z14while_destructi - // CHECK: {{while.cond:|:1}} + // CHECK: {{while.cond:|:2}} while (X x = X()) { // CHECK: call void @_ZN1XC1Ev - // CHECK: {{while.body:|:3}} + // CHECK: {{while.body:|:4}} // CHECK: store i32 21 z = 21; - // CHECK: {{while.cleanup:|:4}} + // CHECK: {{while.cleanup:|:5}} // CHECK: call void @_ZN1XD1Ev } - // CHECK: {{while.end|:6}} + // CHECK: {{while.end|:7}} // CHECK: store i32 22 z = 22; } @@ -94,16 +94,16 @@ void for_destruct(int z) { // CHECK: define void @_Z12for_destruct // CHECK: call void @_ZN1YC1Ev for(Y y = Y(); X x = X(); ++z) - // CHECK: {{for.cond:|:1}} + // CHECK: {{for.cond:|:2}} // CHECK: call void @_ZN1XC1Ev - // CHECK: {{for.body:|:3}} + // CHECK: {{for.body:|:4}} // CHECK: store i32 23 z = 23; - // CHECK: {{for.inc:|:4}} - // CHECK: br label %{{for.cond.cleanup|7}} - // CHECK: {{for.cond.cleanup:|:7}} + // CHECK: {{for.inc:|:5}} + // CHECK: br label %{{for.cond.cleanup|8}} + // CHECK: {{for.cond.cleanup:|:8}} // CHECK: call void @_ZN1XD1Ev - // CHECK: {{for.end:|:9}} + // CHECK: {{for.end:|:10}} // CHECK: call void @_ZN1YD1Ev // CHECK: store i32 24 z = 24; diff --git a/test/CodeGenCXX/conditional-temporaries.cpp b/test/CodeGenCXX/conditional-temporaries.cpp index 0eac10b..d538287 100644 --- a/test/CodeGenCXX/conditional-temporaries.cpp +++ b/test/CodeGenCXX/conditional-temporaries.cpp @@ -1,28 +1,55 @@ -// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O3 | FileCheck %s -struct I { +namespace { + +static int ctorcalls; +static int dtorcalls; + +struct A { + A() : i(0) { ctorcalls++; } + ~A() { dtorcalls++; } int i; - I(); - ~I(); + + friend const A& operator<<(const A& a, int n) { + return a; + } }; -void g(int); +void g(int) { } +void g(const A&) { } -volatile int i; +void f1(bool b) { + g(b ? A().i : 0); + g(b || A().i); + g(b && A().i); + g(b ? A() << 1 : A() << 2); +} -void f1() { - // CHECK: call void @_ZN1IC1Ev - g(i ? I().i : 0); - // CHECK: call void @_Z1gi - // CHECK: call void @_ZN1ID1Ev +struct Checker { + Checker() { + f1(true); + f1(false); + } +}; - // CHECK: call void @_ZN1IC1Ev - g(i || I().i); - // CHECK: call void @_Z1gi - // CHECK: call void @_ZN1ID1Ev +Checker c; + +} + +// CHECK: define i32 @_Z12getCtorCallsv() +int getCtorCalls() { + // CHECK: ret i32 5 + return ctorcalls; +} + +// CHECK: define i32 @_Z12getDtorCallsv() +int getDtorCalls() { + // CHECK: ret i32 5 + return dtorcalls; +} - // CHECK: call void @_ZN1IC1Ev - g(i && I().i); - // CHECK: call void @_Z1gi - // CHECK: call void @_ZN1ID1Ev +// CHECK: define zeroext i1 @_Z7successv() +bool success() { + // CHECK: ret i1 true + return ctorcalls == dtorcalls; } diff --git a/test/CodeGenCXX/const-global-linkage.cpp b/test/CodeGenCXX/const-global-linkage.cpp index f88bc80..d0a055b 100644 --- a/test/CodeGenCXX/const-global-linkage.cpp +++ b/test/CodeGenCXX/const-global-linkage.cpp @@ -3,11 +3,11 @@ const int x = 10; const int y = 20; // CHECK-NOT: @x -// CHECK: @y = internal constant i32 20 +// CHECK: @_ZL1y = internal constant i32 20 const int& b() { return y; } const char z1[] = "asdf"; const char z2[] = "zxcv"; // CHECK-NOT: @z1 -// CHECK: @z2 = internal constant +// CHECK: @_ZL2z2 = internal constant const char* b2() { return z2; } diff --git a/test/CodeGenCXX/const-init.cpp b/test/CodeGenCXX/const-init.cpp index 874b5f64..9cfce7a 100644 --- a/test/CodeGenCXX/const-init.cpp +++ b/test/CodeGenCXX/const-init.cpp @@ -2,11 +2,11 @@ // CHECK: @a = global i32 10 int a = 10; -// CHECK: @ar = global i32* @a +// CHECK: @ar = constant i32* @a int &ar = a; void f(); -// CHECK: @fr = global void ()* @_Z1fv +// CHECK: @fr = constant void ()* @_Z1fv void (&fr)() = f; struct S { int& a; }; diff --git a/test/CodeGenCXX/conversion-function.cpp b/test/CodeGenCXX/conversion-function.cpp index fccb6f0..e2f8f7e 100644 --- a/test/CodeGenCXX/conversion-function.cpp +++ b/test/CodeGenCXX/conversion-function.cpp @@ -2,7 +2,7 @@ // RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s // RUN: %clang_cc1 -triple i386-apple-darwin -std=c++0x -S %s -o %t-32.s // RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s - +// XFAIL: * extern "C" int printf(...); struct S { operator int(); diff --git a/test/CodeGenCXX/debug-info.cpp b/test/CodeGenCXX/debug-info.cpp index cb6e830..6bb9533 100644 --- a/test/CodeGenCXX/debug-info.cpp +++ b/test/CodeGenCXX/debug-info.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm-only -g +// RUN: %clang_cc1 -emit-llvm-only -g %s template<typename T> struct Identity { typedef T Type; }; @@ -24,3 +24,29 @@ namespace EmptyNameCrash { typedef struct { A x; } B; B x; } + +// PR4890 +namespace PR4890 { + struct X { + ~X(); + }; + + X::~X() { } +} + +namespace VirtualDtor { + struct Y { + virtual ~Y(); + }; + + Y::~Y() { } +} + +namespace VirtualBase { + struct A { }; + struct B : virtual A { }; + + void f() { + B b; + } +} diff --git a/test/CodeGenCXX/default-destructor-synthesis.cpp b/test/CodeGenCXX/default-destructor-synthesis.cpp index 71167a2..fac5cc0 100644 --- a/test/CodeGenCXX/default-destructor-synthesis.cpp +++ b/test/CodeGenCXX/default-destructor-synthesis.cpp @@ -1,58 +1,36 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++0x -O0 -S %s -o %t-64.s -// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s -// RUN: %clang_cc1 -triple i386-apple-darwin -std=c++0x -O0 -S %s -o %t-32.s -// RUN: FileCheck -check-prefix LP32 -input-file=%t-32.s %s - -extern "C" int printf(...); - -int count = 1; +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O2 -o - | FileCheck %s +static int count = 0; struct S { - S() : iS(count++), fS(1.23) {}; - ~S(){printf("S::~S(%d, %f)\n", iS, fS); }; - int iS; - float fS; + S() { count++; } + ~S() { count--; } }; -struct Q { - Q() : iQ(count++), dQ(2.34) {}; - ~Q(){printf("Q::~Q(%d, %f)\n", iQ, dQ); }; - int iQ; - double dQ; +struct P { + P() { count++; } + ~P() { count--; } }; -struct P { - P() : fP(3.45) , iP(count++) {}; - ~P(){printf("P::~P(%d, %f)\n", iP, fP); }; - float fP; - int iP; +struct Q { + Q() { count++; } + ~Q() { count--; } }; -struct M : Q, P { +struct M : Q, P { S s; - Q q; - - P p; - - P p_arr[3]; - - Q q_arr[2][3]; - + P p; + P p_arr[3]; + Q q_arr[2][3]; }; - -M gm; - -int main() {M m1;} - -// CHECK-LP64: .globl __ZN1MD1Ev -// CHECK-LP64-NEXT: .weak_definition __ZN1MD1Ev -// CHECK-LP64-NEXT: __ZN1MD1Ev: -// CHECK-LP64: callq __ZN1MC1Ev -// CHECK-LP64: callq __ZN1MD1Ev - -// CHECK-LP32: .globl __ZN1MD1Ev -// CHECK-LP32-NEXT: .weak_definition __ZN1MD1Ev -// CHECK-LP32-NEXT:__ZN1MD1Ev: -// CHECK-LP32: call L__ZN1MC1Ev -// CHECK-LP32: call L__ZN1MD1Ev + +// CHECK: define i32 @_Z1fv() nounwind +int f() { + { + count = 1; + M a; + } + + // CHECK: ret i32 1 + return count; +} diff --git a/test/CodeGenCXX/deferred-global-init.cpp b/test/CodeGenCXX/deferred-global-init.cpp index 5701479..802042d 100644 --- a/test/CodeGenCXX/deferred-global-init.cpp +++ b/test/CodeGenCXX/deferred-global-init.cpp @@ -5,7 +5,7 @@ extern void* foo; static void* const a = foo; void* bar() { return a; } -// CHECK: @a = internal global i8* null +// CHECK: @_ZL1a = internal global i8* null // CHECK: define internal void @__cxx_global_var_init // CHECK: load i8** @foo diff --git a/test/CodeGenCXX/derived-to-base.cpp b/test/CodeGenCXX/derived-to-base.cpp index 45728b7..e44fdc5 100644 --- a/test/CodeGenCXX/derived-to-base.cpp +++ b/test/CodeGenCXX/derived-to-base.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm %s -o - +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s struct A { void f(); @@ -14,3 +14,23 @@ void f() { b.f(); } + +// CHECK: define %struct.B* @_Z1fP1A(%struct.A* %a) nounwind +B *f(A *a) { + // CHECK-NOT: br label + // CHECK: ret %struct.B* + return static_cast<B*>(a); +} + +// PR5965 +namespace PR5965 { + +// CHECK: define %struct.A* @_ZN6PR59651fEP1B(%struct.B* %b) nounwind +A *f(B* b) { + // CHECK-NOT: br label + // CHECK: ret %struct.A* + return b; +} + +} + diff --git a/test/CodeGenCXX/dyncast.cpp b/test/CodeGenCXX/dyncast.cpp index 054b972..127cdd8 100644 --- a/test/CodeGenCXX/dyncast.cpp +++ b/test/CodeGenCXX/dyncast.cpp @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -I%S -triple x86_64-apple-darwin -std=c++0x -emit-llvm %s -o %t.ll // RUN: FileCheck -check-prefix LL --input-file=%t.ll %s +// XFAIL: win32 #include <typeinfo> @@ -69,14 +70,7 @@ void test1() { // CHECK-LL-NEXT: [[ep:%.*]] = alloca %class.test1_E*, align 8 // CHECK-LL-NEXT: [[vp:%.*]] = alloca i8*, align 8 // CHECK-LL-NEXT: [[cvp:%.*]] = alloca i8*, align 8 -// CHECK-LL-NEXT: br i1 false, label %[[castnull:.*]], label %[[castnotnull:.*]] -// CHECK-LL: [[castnotnull]] -// CHECK-LL-NEXT: br label %[[castend:.*]] -// CHECK-LL: [[castnull]] -// CHECK-LL-NEXT: br label %[[castend]] -// CHECK-LL: [[castend]] -// CHECK-LL-NEXT: [[v0:%.*]] = phi %class.test1_A* [ bitcast (%class.test1_D* @test1_d to %class.test1_A*), %[[castnotnull]] ], [ null, %[[castnull]] ] -// CHECK-LL-NEXT: store %class.test1_A* [[v0]], %class.test1_A** [[bp]] +// CHECK-LL-NEXT: store %class.test1_A* bitcast (%class.test1_D* @test1_d to %class.test1_A*), %class.test1_A** [[bp]] // CHECK-LL-NEXT: br i1 false, label %[[castnull2:.*]], label %[[castnotnull1:.*]] // CHECK-LL: [[castnotnull1]] // CHECK-LL-NEXT: [[vtable:%.*]] = load i8** bitcast (%class.test1_D* @test1_d to i8**) @@ -333,23 +327,10 @@ void test1() { // CHECK-LL-NEXT: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([10 x i8]* @.str1, i32 0, i32 0), i32 12) // CHECK-LL-NEXT: br label %[[ifend113]] // CHECK-LL: [[ifend113]] -// CHECK-LL-NEXT: br i1 false, label %[[castnull116:.*]], label %[[castnotnull115:.*]] -// CHECK-LL: [[castnotnull115]] -// CHECK-LL-NEXT: br label %[[castend117:.*]] -// CHECK-LL: [[castnull116]] -// CHECK-LL-NEXT: br label %[[castend117]] -// CHECK-LL: [[castend117]] -// CHECK-LL-NEXT: [[v62:%.*]] = phi %class.test1_E* [ bitcast (%class.test1_F* @test1_f to %class.test1_E*), %[[castnotnull115]] ], [ null, %[[castnull116]] ] -// CHECK-LL-NEXT: store %class.test1_E* [[v62]], %class.test1_E** [[ep]] +// CHECK-LL-NEXT: store %class.test1_E* bitcast (%class.test1_F* @test1_f to %class.test1_E*), %class.test1_E** [[ep]] // CHECK-LL-NEXT: [[tmp118:%.*]] = load %class.test1_E** [[ep]] -// CHECK-LL-NEXT: br i1 false, label %[[castnull120:.*]], label %[[castnotnull119:.*]] -// CHECK-LL: [[castnotnull119]] -// CHECK-LL-NEXT: br label %[[castend121:.*]] -// CHECK-LL: [[castnull120]] -// CHECK-LL-NEXT: br label %[[castend121]] -// CHECK-LL: [[castend121]] -// CHECK-LL-NEXT: [[v63:%.*]] = phi %class.test1_E* [ bitcast (%class.test1_F* @test1_f to %class.test1_E*), %[[castnotnull119]] ], [ null, %[[castnull120]] ] -// CHECK-LL-NEXT: [[cmp122:%.*]] = icmp eq %class.test1_E* [[tmp118]], [[v63]] +// CHECK-LL-NEXT: [[cmp122:%.*]] = icmp eq %class.test1_E* [[tmp118]], bitcast (%class.test1_F* @test1_f to %class.test1_E*) ; <i1> [#uses=1] + // CHECK-LL-NEXT: br i1 [[cmp122]], label %[[ifthen123:.*]], label %[[ifelse125:.*]] // CHECK-LL: [[ifthen123]] // CHECK-LL-NEXT: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([10 x i8]* @.str, i32 0, i32 0), i32 13) diff --git a/test/CodeGenCXX/extern-c.cpp b/test/CodeGenCXX/extern-c.cpp index 427a45a..ca5cd73 100644 --- a/test/CodeGenCXX/extern-c.cpp +++ b/test/CodeGenCXX/extern-c.cpp @@ -10,4 +10,7 @@ extern int b; // RUN: grep "@_ZN3foo1cE = global i32" %t | count 1 int c = 5; +// RUN: not grep "@_ZN3foo1dE" %t +extern "C" struct d; + } diff --git a/test/CodeGenCXX/global-init.cpp b/test/CodeGenCXX/global-init.cpp index b375aef..b60e056 100644 --- a/test/CodeGenCXX/global-init.cpp +++ b/test/CodeGenCXX/global-init.cpp @@ -7,6 +7,12 @@ struct A { struct B { B(); ~B(); }; +struct C { void *field; }; + +struct D { ~D(); }; + +// CHECK: @c = global %struct.C zeroinitializer, align 8 + // CHECK: call void @_ZN1AC1Ev(%struct.A* @a) // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @a, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) A a; @@ -14,3 +20,12 @@ A a; // CHECK: call void @_ZN1BC1Ev(%struct.A* @b) // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1BD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @b, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) B b; + +// PR6205: this should not require a global initializer +// CHECK-NOT: call void @_ZN1CC1Ev(%struct.C* @c) +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() { diff --git a/test/CodeGenCXX/global-llvm-constant.cpp b/test/CodeGenCXX/global-llvm-constant.cpp index e799231..ef1dcf0 100644 --- a/test/CodeGenCXX/global-llvm-constant.cpp +++ b/test/CodeGenCXX/global-llvm-constant.cpp @@ -7,4 +7,4 @@ struct A { const A x; -// CHECK: @x = internal global +// CHECK: @_ZL1x = internal global diff --git a/test/CodeGenCXX/internal-linkage.cpp b/test/CodeGenCXX/internal-linkage.cpp new file mode 100644 index 0000000..1ae0f08 --- /dev/null +++ b/test/CodeGenCXX/internal-linkage.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +struct Global { }; +template<typename T> struct X { }; + + +namespace { + struct Anon { }; + + // CHECK: @_ZN12_GLOBAL__N_15anon0E = internal global + Global anon0; +} + +// CHECK: @anon1 = internal global +Anon anon1; + +// CHECK: @anon2 = internal global +X<Anon> anon2; + diff --git a/test/CodeGenCXX/mangle-exprs.cpp b/test/CodeGenCXX/mangle-exprs.cpp new file mode 100644 index 0000000..cdad398 --- /dev/null +++ b/test/CodeGenCXX/mangle-exprs.cpp @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s + +template < bool condition, typename T = void > +struct enable_if { typedef T type; }; + +template< typename T > +struct enable_if< false, T > {}; + +// PR5876 +namespace Casts { + template< unsigned O > + void implicit(typename enable_if< O <= 4 >::type* = 0) { + } + + template< unsigned O > + void cstyle(typename enable_if< O <= (unsigned)4 >::type* = 0) { + } + + template< unsigned O > + void functional(typename enable_if< O <= unsigned(4) >::type* = 0) { + } + + template< unsigned O > + void static_(typename enable_if< O <= static_cast<unsigned>(4) >::type* = 0) { + } + + // FIXME: Test const_cast, reinterpret_cast, dynamic_cast, which are + // a bit harder to use in template arguments. + template <unsigned N> struct T {}; + + template <int N> T<N> f() { return T<N>(); } + + // CHECK: define void @_ZN5Casts8implicitILj4EEEvPN9enable_ifIXleT_Li4EEvE4typeE + template void implicit<4>(void*); + // CHECK: define void @_ZN5Casts6cstyleILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE + template void cstyle<4>(void*); + // CHECK: define void @_ZN5Casts10functionalILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE + template void functional<4>(void*); + // CHECK: define void @_ZN5Casts7static_ILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE + template void static_<4>(void*); + + // CHECK: define i64 @_ZN5Casts1fILi6EEENS_1TIXT_EEEv + template T<6> f<6>(); +} diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp index 5947587..0718378 100644 --- a/test/CodeGenCXX/mangle.cpp +++ b/test/CodeGenCXX/mangle.cpp @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fblocks | FileCheck %s - struct X { }; struct Y { }; @@ -9,6 +8,9 @@ struct Y { }; // CHECK: @_ZZN1N1gEvE1a = internal global // CHECK: @_ZGVZN1N1gEvE1a = internal global +//CHECK: @pr5966_i = external global +//CHECK: @_ZL8pr5966_i = internal global + // CHECK: define zeroext i1 @_ZplRK1YRA100_P1X bool operator+(const Y&, X* (&xs)[100]) { return false; } @@ -310,7 +312,67 @@ template class Alloc<char>; // CHECK: define void @_Z1fU13block_pointerFiiiE void f(int (^)(int, int)) { } -// PR5869 -// CHECK: define internal void @_ZL2f2v -static void f2() {} -void f3() { f2(); } +void pr5966_foo() { + extern int pr5966_i; + pr5966_i = 0; +} + +static int pr5966_i; + +void pr5966_bar() { + pr5966_i = 0; +} + +namespace test0 { + int ovl(int x); + char ovl(double x); + + template <class T> void f(T, char (&buffer)[sizeof(ovl(T()))]) {} + + void test0() { + char buffer[1]; + f(0.0, buffer); + } + // CHECK: define void @_ZN5test05test0Ev() + // CHECK: define linkonce_odr void @_ZN5test01fIdEEvT_RAszcl3ovlcvS1__EE_c( + + void test1() { + char buffer[sizeof(int)]; + f(1, buffer); + } + // CHECK: define void @_ZN5test05test1Ev() + // CHECK: define linkonce_odr void @_ZN5test01fIiEEvT_RAszcl3ovlcvS1__EE_c( + + template <class T> void g(char (&buffer)[sizeof(T() + 5.0f)]) {} + void test2() { + char buffer[sizeof(float)]; + g<float>(buffer); + } + // CHECK: define linkonce_odr void @_ZN5test01gIfEEvRAszplcvT__ELf40A00000E_c( + + template <class T> void h(char (&buffer)[sizeof(T() + 5.0)]) {} + void test3() { + char buffer[sizeof(double)]; + h<float>(buffer); + } + // CHECK: define linkonce_odr void @_ZN5test01hIfEEvRAszplcvT__ELd4014000000000000E_c( + + template <class T> void j(char (&buffer)[sizeof(T().buffer)]) {} + struct A { double buffer[128]; }; + void test4() { + char buffer[1024]; + j<A>(buffer); + } + // CHECK: define linkonce_odr void @_ZN5test01jINS_1AEEEvRAszmecvT__E6buffer_c( +} + +namespace test1 { + template<typename T> struct X { }; + template<template<class> class Y, typename T> void f(Y<T>) { } + // CHECK: define void @_ZN5test11fINS_1XEiEEvT_IT0_E + template void f(X<int>); +} + +// CHECK: define internal void @_Z27functionWithInternalLinkagev() +static void functionWithInternalLinkage() { } +void g() { functionWithInternalLinkage(); } diff --git a/test/CodeGenCXX/member-function-pointer-calls.cpp b/test/CodeGenCXX/member-function-pointer-calls.cpp new file mode 100644 index 0000000..e1f2eb7 --- /dev/null +++ b/test/CodeGenCXX/member-function-pointer-calls.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s +struct A { + virtual int vf1() { return 1; } + virtual int vf2() { return 2; } +}; + +int f(A* a, int (A::*fp)()) { + return (a->*fp)(); +} + +// CHECK: define i32 @_Z2g1v() +int g1() { + A a; + + // CHECK: call i32 @_ZN1A3vf1Ev + // CHECK-NEXT: ret i32 + return f(&a, &A::vf1); +} + +int g2() { + A a; + + // CHECK: call i32 @_ZN1A3vf2Ev + // CHECK-NEXT: ret i32 + return f(&a, &A::vf2); +} diff --git a/test/CodeGenCXX/member-function-pointers.cpp b/test/CodeGenCXX/member-function-pointers.cpp index e1353a7..f7c445b 100644 --- a/test/CodeGenCXX/member-function-pointers.cpp +++ b/test/CodeGenCXX/member-function-pointers.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin9 | FileCheck %s -struct A { int a; void f(); virtual void vf(); }; +struct A { int a; void f(); virtual void vf1(); virtual void vf2(); }; struct B { int b; virtual void g(); }; struct C : B, A { }; @@ -9,17 +9,20 @@ void (A::*volatile vpa)(); void (B::*pb)(); void (C::*pc)(); -// CHECK: @pa2 = global %0 { i64 ptrtoint (void ()* @_ZN1A1fEv to i64), i64 0 }, align 8 +// CHECK: @pa2 = global %0 { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 0 }, align 8 void (A::*pa2)() = &A::f; // CHECK: @pa3 = global %0 { i64 1, i64 0 }, align 8 -void (A::*pa3)() = &A::vf; +void (A::*pa3)() = &A::vf1; -// CHECK: @pc2 = global %0 { i64 ptrtoint (void ()* @_ZN1A1fEv to i64), i64 16 }, align 8 +// CHECK: @pa4 = global %0 { i64 9, i64 0 }, align 8 +void (A::*pa4)() = &A::vf2; + +// CHECK: @pc2 = global %0 { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 16 }, align 8 void (C::*pc2)() = &C::f; // CHECK: @pc3 = global %0 { i64 1, i64 0 }, align 8 -void (A::*pc3)() = &A::vf; +void (A::*pc3)() = &A::vf1; void f() { // CHECK: store i64 0, i64* getelementptr inbounds (%0* @pa, i32 0, i32 0) @@ -43,7 +46,7 @@ void f() { void f2() { // CHECK: [[pa2ptr:%[a-zA-Z0-9\.]+]] = getelementptr inbounds %0* %pa2, i32 0, i32 0 - // CHECK: store i64 ptrtoint (void ()* @_ZN1A1fEv to i64), i64* [[pa2ptr]] + // CHECK: store i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64* [[pa2ptr]] // CHECK: [[pa2adj:%[a-zA-Z0-9\.]+]] = getelementptr inbounds %0* %pa2, i32 0, i32 1 // CHECK: store i64 0, i64* [[pa2adj]] void (A::*pa2)() = &A::f; @@ -52,7 +55,13 @@ void f2() { // CHECK: store i64 1, i64* [[pa3ptr]] // CHECK: [[pa3adj:%[a-zA-Z0-9\.]+]] = getelementptr inbounds %0* %pa3, i32 0, i32 1 // CHECK: store i64 0, i64* [[pa3adj]] - void (A::*pa3)() = &A::vf; + void (A::*pa3)() = &A::vf1; + + // CHECK: [[pa4ptr:%[a-zA-Z0-9\.]+]] = getelementptr inbounds %0* %pa4, i32 0, i32 0 + // CHECK: store i64 9, i64* [[pa4ptr]] + // CHECK: [[pa4adj:%[a-zA-Z0-9\.]+]] = getelementptr inbounds %0* %pa4, i32 0, i32 1 + // CHECK: store i64 0, i64* [[pa4adj]] + void (A::*pa4)() = &A::vf2; } void f3(A *a, A &ar) { @@ -150,3 +159,17 @@ namespace MemberPointerImpCast { (obj->*method)(); } } + +// PR6258 +namespace PR6258 { + + struct A { + void f(bool); + }; + + void (A::*pf)(bool) = &A::f; + + void f() { + void (A::*pf)(bool) = &A::f; + } +} diff --git a/test/CodeGenCXX/member-initializers.cpp b/test/CodeGenCXX/member-initializers.cpp new file mode 100644 index 0000000..81dcee7 --- /dev/null +++ b/test/CodeGenCXX/member-initializers.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 -O3 | FileCheck %s + +struct A { + virtual int f() { return 1; } +}; + +struct B : A { + B() : i(f()) { } + + virtual int f() { return 2; } + + int i; +}; + +// CHECK: define i32 @_Z1fv() nounwind +int f() { + B b; + + // CHECK: call i32 @_ZN1B1fEv + return b.i; +} + +// Test that we don't try to fold the default value of j when initializing i. +// CHECK: define i32 @_Z9test_foldv() nounwind +int test_fold() { + struct A { + A(const int j = 1) : i(j) { } + int i; + }; + + // CHECK: ret i32 2 + return A(2).i; +} + diff --git a/test/CodeGenCXX/member-pointer-cast.cpp b/test/CodeGenCXX/member-pointer-cast.cpp deleted file mode 100644 index 4937b03..0000000 --- a/test/CodeGenCXX/member-pointer-cast.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin9 | FileCheck %s - -struct A { int a; }; -struct B { int b; }; -struct C : B, A { }; - -int A::*pa; -int C::*pc; - -void f() { - // CHECK: store i64 -1, i64* @pa - pa = 0; - - // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = add i64 {{.*}}, 4 - // CHECK: store i64 [[ADJ]], i64* @pc - pc = pa; - - // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = sub i64 {{.*}}, 4 - // CHECK: store i64 [[ADJ]], i64* @pa - pa = static_cast<int A::*>(pc); -} diff --git a/test/CodeGenCXX/member-pointers-zero-init.cpp b/test/CodeGenCXX/member-pointers-zero-init.cpp deleted file mode 100644 index 18a2ead..0000000 --- a/test/CodeGenCXX/member-pointers-zero-init.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// RUN: %clang_cc1 -emit-llvm %s -o %t -triple=x86_64-apple-darwin9 - -struct A { - int i; -}; - -// RUN: grep "@a = global i64 -1" %t -int A::* a; - -// RUN: grep "@aa = global \[2 x i64\] \[i64 -1, i64 -1\]" %t -int A::* aa[2]; - -// RUN: grep "@aaa = global \[2 x \[2 x i64\]\] \[\[2 x i64\] \[i64 -1, i64 -1\], \[2 x i64\] \[i64 -1, i64 -1\]\]" %t -int A::* aaa[2][2]; - -// RUN: grep "@b = global i64 -1" %t -int A::* b = 0; - -void f() { - // RUN: grep "%.* = icmp ne i64 %.*, -1" %t | count 2 - if (a) { } - if (a != 0) { } - - // RUN: grep "%.* = icmp ne i64 -1, %.*" %t | count 1 - if (0 != a) { } - - // RUN: grep "%.* = icmp eq i64 %.*, -1" %t | count 1 - if (a == 0) { } - - // RUN: grep "%.* = icmp eq i64 -1, %.*" %t | count 1 - if (0 == a) { } - -} - diff --git a/test/CodeGenCXX/no-exceptions.cpp b/test/CodeGenCXX/no-exceptions.cpp new file mode 100644 index 0000000..da672c4 --- /dev/null +++ b/test/CodeGenCXX/no-exceptions.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s + +void g(); + +// CHECK: define void @_Z1fv() nounwind +void f() throw (int) { + + // CHECK-NOT: invoke void @_Z1gv + g(); + // CHECK: call void @_Z1gv() + // CHECK: ret void +} diff --git a/test/CodeGenCXX/pointers-to-data-members.cpp b/test/CodeGenCXX/pointers-to-data-members.cpp new file mode 100644 index 0000000..d96eb03 --- /dev/null +++ b/test/CodeGenCXX/pointers-to-data-members.cpp @@ -0,0 +1,87 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin10 | FileCheck %s + +struct A { int a; int b; }; +struct B { int b; }; +struct C : B, A { }; + +// Zero init. +namespace ZeroInit { + // CHECK: @_ZN8ZeroInit1aE = global i64 -1 + int A::* a; + + // CHECK: @_ZN8ZeroInit2aaE = global [2 x i64] [i64 -1, i64 -1] + int A::* aa[2]; + + // CHECK: @_ZN8ZeroInit3aaaE = global [2 x [2 x i64]] {{\[}}[2 x i64] [i64 -1, i64 -1], [2 x i64] [i64 -1, i64 -1]] + int A::* aaa[2][2]; + + // CHECK: @_ZN8ZeroInit1bE = global i64 -1, + int A::* b = 0; + + // CHECK: @_ZN8ZeroInit2saE = global %struct.anon { i64 -1 } + struct { + int A::*a; + } sa; + + // CHECK: @_ZN8ZeroInit3ssaE = + // CHECK: [2 x i64] [i64 -1, i64 -1] + struct { + int A::*aa[2]; + } ssa[2]; + + // CHECK: @_ZN8ZeroInit2ssE = global %1 { %struct.anon { i64 -1 } } + struct { + struct { + int A::*pa; + } s; + } ss; +} + +// PR5674 +namespace PR5674 { + // CHECK: @_ZN6PR56742pbE = global i64 4 + int A::*pb = &A::b; +} + +// Casts. +namespace Casts { + +int A::*pa; +int C::*pc; + +void f() { + // CHECK: store i64 -1, i64* @_ZN5Casts2paE + pa = 0; + + // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = add i64 {{.*}}, 4 + // CHECK: store i64 [[ADJ]], i64* @_ZN5Casts2pcE + pc = pa; + + // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = sub i64 {{.*}}, 4 + // CHECK: store i64 [[ADJ]], i64* @_ZN5Casts2paE + pa = static_cast<int A::*>(pc); +} + +} + +// Comparisons +namespace Comparisons { + void f() { + int A::*a; + + // CHECK: icmp ne i64 {{.*}}, -1 + if (a) { } + + // CHECK: icmp ne i64 {{.*}}, -1 + if (a != 0) { } + + // CHECK: icmp ne i64 -1, {{.*}} + if (0 != a) { } + + // CHECK: icmp eq i64 {{.*}}, -1 + if (a == 0) { } + + // CHECK: icmp eq i64 -1, {{.*}} + if (0 == a) { } + } +} diff --git a/test/CodeGenCXX/reference-init.cpp b/test/CodeGenCXX/reference-init.cpp index 6c2c6a3..9469c84 100644 --- a/test/CodeGenCXX/reference-init.cpp +++ b/test/CodeGenCXX/reference-init.cpp @@ -14,3 +14,11 @@ namespace PR5911 { int iarr[] = { 1 }; int test() { return f(iarr); } } + +// radar 7574896 +struct Foo { int foo; }; +Foo& ignoreSetMutex = *(new Foo); + +// Binding to a bit-field that requires a temporary. +struct { int bitfield : 3; } s = { 3 }; +const int &s2 = s.bitfield; diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp index 6bec8bd..39b5909 100644 --- a/test/CodeGenCXX/references.cpp +++ b/test/CodeGenCXX/references.cpp @@ -38,6 +38,8 @@ void test_bool() { bool_reference_return() = true; a = bool_reference_return(); + + struct { const bool& b; } b = { true }; } void test_scalar() { @@ -54,6 +56,8 @@ void test_scalar() { int_reference_return() = 10; a = int_reference_return(); + + struct { const int& a; } agg = { 10 }; } void test_complex() { @@ -64,6 +68,8 @@ void test_complex() { complex_int_reference_return() = 10i; a = complex_int_reference_return(); + + struct { const _Complex int &a; } agg = { 10i }; } void test_aggregate() { @@ -74,6 +80,8 @@ void test_aggregate() { aggregate_reference_return().a = 10; c = aggregate_reference_return(); + + struct { const C& a; } agg = { C() }; } int& reference_return() { diff --git a/test/CodeGenCXX/static-data-member.cpp b/test/CodeGenCXX/static-data-member.cpp index 53a1d5e..b3a2af2 100644 --- a/test/CodeGenCXX/static-data-member.cpp +++ b/test/CodeGenCXX/static-data-member.cpp @@ -1,4 +1,14 @@ // RUN: %clang_cc1 -emit-llvm -o - %s + +// CHECK: @_ZN1A1aE = constant i32 10 + +// PR5564. +struct A { + static const int a = 10; +}; + +const int A::a; + struct S { static int i; }; diff --git a/test/CodeGenCXX/static-init.cpp b/test/CodeGenCXX/static-init.cpp index cbd90e7..a67d137 100644 --- a/test/CodeGenCXX/static-init.cpp +++ b/test/CodeGenCXX/static-init.cpp @@ -1,4 +1,10 @@ // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s + +// CHECK: @_ZZ1hvE1i = internal global i32 0, align 4 + +// CHECK: @_ZZ2h2vE1i = weak global i32 0 +// CHECK: @_ZGVZ2h2vE1i = weak global i64 0 + struct A { A(); ~A(); @@ -15,3 +21,16 @@ void g() { // CHECK: call void @_ZN1AC1Ev( static A& a = *new A; } + +int a(); +void h() { + static const int i = a(); +} + +inline void h2() { + static int i = a(); +} + +void h3() { + h2(); +} diff --git a/test/CodeGenCXX/temp-order.cpp b/test/CodeGenCXX/temp-order.cpp index 05a9aed..341cd0c 100644 --- a/test/CodeGenCXX/temp-order.cpp +++ b/test/CodeGenCXX/temp-order.cpp @@ -129,10 +129,30 @@ static unsigned f6() { return tt.Product; } +// 5, 2 +static unsigned f7() { + TempTracker tt; + { + (void)((A(tt, 2, false) && A(tt, 3, false)) || A(tt, 5, false)); + } + return tt.Product; +} + +// 5, 2 +static unsigned f8() { + TempTracker tt; + + { + (void)((A(tt, 2) || A(tt, 3)) && A(tt, 5)); + } + return tt.Product; +} + extern "C" void error(); extern "C" void print(const char *Name, unsigned N); -#define ORDER3(a, b, c) (pow(a, 1) * pow(b, 2) * pow(c, 3)) +#define ORDER2(a, b) (pow(a, 1) * pow(b, 2)) +#define ORDER3(a, b, c) (ORDER2(a, b) * pow(c, 3)) #define ORDER4(a, b, c, d) (ORDER3(a, b, c) * pow(d, 4)) #define ORDER5(a, b, c, d, e) (ORDER4(a, b, c, d) * pow(e, 5)) #define ORDER6(a, b, c, d, e, f) (ORDER5(a, b, c, d, e) * pow(f, 6)) @@ -171,6 +191,16 @@ void test() { print("f6", f6()); if (f6() != ORDER6(3, 7, 11, 5, 13, 2)) error(); + +// CHECK: call void @print(i8* {{.*}}, i32 20) + print("f7", f7()); + if (f7() != ORDER2(5, 2)) + error(); + +// CHECK: call void @print(i8* {{.*}}, i32 20) + print("f8", f8()); + if (f8() != ORDER2(5, 2)) + error(); } diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp index 6117818..3b624af 100644 --- a/test/CodeGenCXX/temporaries.cpp +++ b/test/CodeGenCXX/temporaries.cpp @@ -249,3 +249,42 @@ namespace PR5867 { g2(17); } } + +// PR6199 +namespace PR6199 { + struct A { ~A(); }; + + struct B { operator A(); }; + + // CHECK: define void @_ZN6PR61992f2IiEENS_1AET_ + template<typename T> A f2(T) { + B b; + // CHECK: call void @_ZN6PR61991BcvNS_1AEEv + // CHECK-NEXT: ret void + return b; + } + + template A f2<int>(int); + +} + +namespace T12 { + +struct A { + A(); + ~A(); + int f(); +}; + +int& f(int); + +// CHECK: define void @_ZN3T121gEv +void g() { + // CHECK: call void @_ZN3T121AC1Ev + // CHECK-NEXT: call i32 @_ZN3T121A1fEv( + // CHECK-NEXT: call i32* @_ZN3T121fEi( + // CHECK-NEXT: call void @_ZN3T121AD1Ev( + int& i = f(A().f()); +} + +} diff --git a/test/CodeGenCXX/threadsafe-statics.cpp b/test/CodeGenCXX/threadsafe-statics.cpp new file mode 100644 index 0000000..65ebc43 --- /dev/null +++ b/test/CodeGenCXX/threadsafe-statics.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck -check-prefix=WITH-TSS %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fno-threadsafe-statics | FileCheck -check-prefix=NO-TSS %s + +int f(); + +// WITH-TSS: define void @_Z1gv() nounwind +// WITH-TSS: call i32 @__cxa_guard_acquire +// WITH-TSS: call void @__cxa_guard_release +// WITH-TSS: ret void +void g() { + static int a = f(); +} + +// NO-TSS: define void @_Z1gv() nounwind +// NO-TSS-NOT: call i32 @__cxa_guard_acquire +// NO-TSS-NOT: call void @__cxa_guard_release +// NO-TSS: ret void diff --git a/test/CodeGenCXX/throw-expressions.cpp b/test/CodeGenCXX/throw-expressions.cpp index 9449618..1670e44 100644 --- a/test/CodeGenCXX/throw-expressions.cpp +++ b/test/CodeGenCXX/throw-expressions.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm-only -verify %s +// RUN: %clang_cc1 -emit-llvm-only -verify %s -Wno-unreachable-code int val = 42; int& test1() { diff --git a/test/CodeGenCXX/virt.cpp b/test/CodeGenCXX/virt.cpp index 22e11fd..9d671c4 100644 --- a/test/CodeGenCXX/virt.cpp +++ b/test/CodeGenCXX/virt.cpp @@ -384,11 +384,11 @@ struct test16_D : test16_NV1, virtual test16_B2 { // CHECK-LP64-NEXT: .quad __ZTcv0_n48_v0_n24_N8test16_D4foo1Ev // CHECK-LP64-NEXT: .quad __ZN9test16_B24foo2Ev // CHECK-LP64-NEXT: .quad __ZN9test16_B26foo_B2Ev -// CHECK-LP64-NEXT .quad 16 -// CHECK-LP64-NEXT .quad 16 +// CHECK-LP64-NEXT: .quad 16 +// CHECK-LP64-NEXT: .quad 16 // CHECK-LP64-NEXT: .quad 0 // CHECK-LP64-NEXT: .quad 0 -// CHECK-LP64: .quad -16 +// CHECK-LP64-NEXT: .quad -16 // CHECK-LP64-NEXT: .quad -32 // CHECK-LP64-NEXT: .quad 0 // CHECK-LP64-NEXT: .quad 0 @@ -402,8 +402,8 @@ struct test16_D : test16_NV1, virtual test16_B2 { // CHECK-LP64-NEXT: .quad __ZN8test16_B5foo_BEv // CHECK-LP64-NEXT: .quad -48 // CHECK-LP64-NEXT: .quad __ZTI8test16_D -// CHECK-LP64-NEXT .quad __ZTcvn16_n40_v16_n32_N8test16_D4foo1Ev -// CHECK-LP64: .quad __ZN10test16_NV27foo_NV2Ev +// CHECK-LP64-NEXT: .quad __ZTcvn16_n40_v16_n32_N8test16_D4foo1Ev +// CHECK-LP64-NEXT: .quad __ZN10test16_NV27foo_NV2Ev // CHECK-LP64-NEXT: .quad __ZN10test16_NV28foo_NV2bEv @@ -696,32 +696,32 @@ void test12_foo() { // FIXME: This is the wrong thunk, but until these issues are fixed, better // than nothing. -// CHECK-LPLL64:define weak %class.test8_D* @_ZTcvn16_n72_v16_n32_N8test16_D4foo1Ev(%class.test8_D*) -// CHECK-LPLL64: %{{retval|2}} = alloca %class.test8_D* -// CHECK-LPLL64: %.addr = alloca %class.test8_D* -// CHECK-LPLL64: store %class.test8_D* %0, %class.test8_D** %.addr -// CHECK-LPLL64: %{{this|3}} = load %class.test8_D** %.addr -// CHECK-LPLL64: %{{1|4}} = bitcast %class.test8_D* %{{this|3}} to i8* -// CHECK-LPLL64: %{{2|5}} = getelementptr inbounds i8* %{{1|4}}, i64 -16 -// CHECK-LPLL64: %{{3|6}} = bitcast i8* %{{2|5}} to %class.test8_D* -// CHECK-LPLL64: %{{4|7}} = bitcast %class.test8_D* %{{3|6}} to i8* -// CHECK-LPLL64: %{{5|8}} = bitcast %class.test8_D* %3 to i64** -// CHECK-LPLL64: %{{vtable|9}} = load i64** %{{5|8}} -// CHECK-LPLL64: %{{6|10}} = getelementptr inbounds i64* %{{vtable|9}}, i64 -9 -// CHECK-LPLL64: %{{7|11}} = load i64* %{{6|10}} -// CHECK-LPLL64: %{{8|12}} = getelementptr i8* %{{4|7}}, i64 %{{7|11}} -// CHECK-LPLL64: %{{9|13}} = bitcast i8* %{{8|12}} to %class.test8_D* -// CHECK-LPLL64: %{{call|14}} = call %class.test8_D* @_ZTch0_v16_n32_N8test16_D4foo1Ev(%class.test8_D* %{{9|13}}) -// CHECK-LPLL64: store %class.test8_D* %{{call|14}}, %class.test8_D** %{{retval|2}} -// CHECK-LPLL64: %{{10|15}} = load %class.test8_D** %{{retval|2}} -// CHECK-LPLL64: ret %class.test8_D* %{{10|15}} -// CHECK-LPLL64:} +// CHECK-LPLL64define weak %class.test8_D* @_ZTcvn16_n72_v16_n32_N8test16_D4foo1Ev(%class.test8_D*) +// CHECK-LPLL64 %{{retval|2}} = alloca %class.test8_D* +// CHECK-LPLL64 %.addr = alloca %class.test8_D* +// CHECK-LPLL64 store %class.test8_D* %0, %class.test8_D** %.addr +// CHECK-LPLL64 %{{this|3}} = load %class.test8_D** %.addr +// CHECK-LPLL64 %{{1|4}} = bitcast %class.test8_D* %{{this|3}} to i8* +// CHECK-LPLL64 %{{2|5}} = getelementptr inbounds i8* %{{1|4}}, i64 -16 +// CHECK-LPLL64 %{{3|6}} = bitcast i8* %{{2|5}} to %class.test8_D* +// CHECK-LPLL64 %{{4|7}} = bitcast %class.test8_D* %{{3|6}} to i8* +// CHECK-LPLL64 %{{5|8}} = bitcast %class.test8_D* %3 to i64** +// CHECK-LPLL64 %{{vtable|9}} = load i64** %{{5|8}} +// CHECK-LPLL64 %{{6|10}} = getelementptr inbounds i64* %{{vtable|9}}, i64 -9 +// CHECK-LPLL64 %{{7|11}} = load i64* %{{6|10}} +// CHECK-LPLL64 %{{8|12}} = getelementptr i8* %{{4|7}}, i64 %{{7|11}} +// CHECK-LPLL64 %{{9|13}} = bitcast i8* %{{8|12}} to %class.test8_D* +// CHECK-LPLL64 %{{call|14}} = call %class.test8_D* @_ZTch0_v16_n32_N8test16_D4foo1Ev(%class.test8_D* %{{9|13}}) +// CHECK-LPLL64 store %class.test8_D* %{{call|14}}, %class.test8_D** %{{retval|2}} +// CHECK-LPLL64 %{{10|15}} = load %class.test8_D** %{{retval|2}} +// CHECK-LPLL64 ret %class.test8_D* %{{10|15}} +// CHECK-LPLL64} // CHECK-LPLL64:define weak %class.test8_D* @_ZTch0_v16_n32_N8test16_D4foo1Ev(%{{class.test8_D|.*}}*) -// CHECK-LPLL64: %{{retval|2}} = alloca %class.test8_D* -// CHECK-LPLL64: %.addr = alloca %class.test8_D* -// CHECK-LPLL64: store %class.test8_D* %0, %class.test8_D** %.addr -// CHECK-LPLL64: %{{this|3}} = load %class.test8_D** %.addr +// CHECK-LPLL64: %{{retval|1}} = alloca %class.test8_D* +// CHECK-LPLL64: %{{.addr|2}} = alloca %class.test8_D* +// CHECK-LPLL64: store %class.test8_D* %0, %class.test8_D** %{{.addr|2}} +// CHECK-LPLL64: %{{this|3}} = load %class.test8_D** %{{.addr|2}} // CHECK-LPLL64: %{{call|4}} = call %class.test8_D* @_ZN8test16_D4foo1Ev(%class.test8_D* %{{this|3}}) // CHECK-LPLL64: %{{1|5}} = icmp ne %class.test8_D* %{{call|4}}, null // CHECK-LPLL64: br i1 %{{1|5}}, label %{{2|6}}, label %{{12|17}} diff --git a/test/CodeGenCXX/virtual-bases.cpp b/test/CodeGenCXX/virtual-bases.cpp index 1eaef3f..200f21a 100644 --- a/test/CodeGenCXX/virtual-bases.cpp +++ b/test/CodeGenCXX/virtual-bases.cpp @@ -15,3 +15,11 @@ struct B : virtual A { // CHECK: define void @_ZN1BC1Ev(%struct.B* %this) // CHECK: define void @_ZN1BC2Ev(%struct.B* %this, i8** %vtt) B::B() { } + +struct C : virtual A { + C(bool); +}; + +// CHECK: define void @_ZN1CC1Eb(%struct.B* %this, i1 zeroext) +// CHECK: define void @_ZN1CC2Eb(%struct.B* %this, i8** %vtt, i1 zeroext) +C::C(bool) { } diff --git a/test/CodeGenCXX/virtual-function-calls.cpp b/test/CodeGenCXX/virtual-function-calls.cpp index 0b3a684..46e7b2d 100644 --- a/test/CodeGenCXX/virtual-function-calls.cpp +++ b/test/CodeGenCXX/virtual-function-calls.cpp @@ -1,6 +1,8 @@ // RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s // PR5021 +namespace PR5021 { + struct A { virtual void f(char); }; @@ -16,4 +18,21 @@ struct B : virtual A { void f(B * b) { b->f(); -}
\ No newline at end of file +} + +} + +namespace Test1 { + struct A { + virtual ~A(); + }; + + struct B : A { + virtual ~B(); + virtual void f(); + }; + + void f(B *b) { + b->f(); + } +} diff --git a/test/CodeGenCXX/visibility.cpp b/test/CodeGenCXX/visibility.cpp new file mode 100644 index 0000000..5edd27b --- /dev/null +++ b/test/CodeGenCXX/visibility.cpp @@ -0,0 +1,66 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s + +#define HIDDEN __attribute__((visibility("hidden"))) +#define PROTECTED __attribute__((visibility("protected"))) +#define DEFAULT __attribute__((visibility("default"))) + +// CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10 + +namespace Test1 { + // CHECK: define hidden void @_ZN5Test11fEv + void HIDDEN f() { } + +} + +namespace Test2 { + struct HIDDEN A { + void f(); + }; + + // A::f is a member function of a hidden class. + // CHECK: define hidden void @_ZN5Test21A1fEv + void A::f() { } +} + +namespace Test3 { + struct HIDDEN A { + struct B { + void f(); + }; + }; + + // B is a nested class where its parent class is hidden. + // CHECK: define hidden void @_ZN5Test31A1B1fEv + void A::B::f() { } +} + +namespace Test4 HIDDEN { + int VariableInHiddenNamespace = 10; + + // Test4::g is in a hidden namespace. + // CHECK: define hidden void @_ZN5Test41gEv + void g() { } + + struct DEFAULT A { + void f(); + }; + + // A has default visibility. + // CHECK: define void @_ZN5Test41A1fEv + void A::f() { } +} + +namespace Test5 { + + namespace NS HIDDEN { + // f is in NS which is hidden. + // CHECK: define hidden void @_ZN5Test52NS1fEv() + void f() { } + } + + namespace NS { + // g is in NS, but this NS decl is not hidden. + // CHECK: define void @_ZN5Test52NS1gEv + void g() { } + } +} diff --git a/test/CodeGenCXX/vtable-layout.cpp b/test/CodeGenCXX/vtable-layout.cpp new file mode 100644 index 0000000..8fbe486 --- /dev/null +++ b/test/CodeGenCXX/vtable-layout.cpp @@ -0,0 +1,367 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm-only -fdump-vtable-layouts 2>&1 | FileCheck %s + +// For now, just verify this doesn't crash. +namespace test0 { + struct Obj {}; + + struct Base { virtual const Obj *foo() = 0; }; + struct Derived : Base { virtual Obj *foo() { return new Obj(); } }; + + void test(Derived *D) { D->foo(); } +} + +namespace Test1 { +// CHECK: Vtable for 'Test1::A' (3 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test1::A RTTI +// CHECK-NEXT: -- (Test1::A, 0) vtable address -- +// CHECK-NEXT: 2 | void Test1::A::f() +struct A { + virtual void f(); +}; +void A::f() { } + +} + +namespace Test2 { + +// This is a smoke test of the vtable dumper. +// CHECK: Vtable for 'Test2::A' (9 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test2::A RTTI +// CHECK-NEXT: -- (Test2::A, 0) vtable address -- +// CHECK-NEXT: 2 | void Test2::A::f() +// CHECK-NEXT: 3 | void Test2::A::f() const +// CHECK-NEXT: 4 | Test2::A *Test2::A::g(int) +// CHECK-NEXT: 5 | Test2::A::~A() [complete] +// CHECK-NEXT: 6 | Test2::A::~A() [deleting] +// CHECK-NEXT: 7 | void Test2::A::h() +// CHECK-NEXT: 8 | Test2::A &Test2::A::operator=(Test2::A const &) +struct A { + virtual void f(); + virtual void f() const; + + virtual A* g(int a); + virtual ~A(); + virtual void h(); + virtual A& operator=(const A&); +}; +void A::f() { } + +// Another simple vtable dumper test. + +// CHECK: Vtable for 'Test2::B' (6 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test2::B RTTI +// CHECK-NEXT: -- (Test2::B, 0) vtable address -- +// CHECK-NEXT: 2 | void Test2::B::f() +// CHECK-NEXT: 3 | void Test2::B::g() [pure] +// CHECK-NEXT: 4 | Test2::B::~B() [complete] [pure] +// CHECK-NEXT: 5 | Test2::B::~B() [deleting] [pure] +struct B { + virtual void f(); + virtual void g() = 0; + virtual ~B() = 0; +}; +void B::f() { } + +} + +namespace Test3 { + +// If a function in a derived class overrides a function in a primary base, +// then the function should not have an entry in the derived class (unless the return +// value requires adjusting). + +// CHECK: Vtable for 'Test3::A' (3 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test3::A RTTI +// CHECK-NEXT: -- (Test3::A, 0) vtable address -- +// CHECK-NEXT: 2 | void Test3::A::f() +struct A { + virtual void f(); +}; +void A::f() { } + +// CHECK: Vtable for 'Test3::B' (4 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test3::B RTTI +// CHECK-NEXT: -- (Test3::A, 0) vtable address -- +// CHECK-NEXT: -- (Test3::B, 0) vtable address -- +// CHECK-NEXT: 2 | void Test3::B::f() +// CHECK-NEXT: 3 | void Test3::B::g() +struct B : A { + virtual void f(); + virtual void g(); +}; +void B::f() { } + +// CHECK: Vtable for 'Test3::C' (5 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test3::C RTTI +// CHECK-NEXT: -- (Test3::A, 0) vtable address -- +// CHECK-NEXT: -- (Test3::C, 0) vtable address -- +// CHECK-NEXT: 2 | void Test3::A::f() +// CHECK-NEXT: 3 | void Test3::C::g() +// CHECK-NEXT: 4 | void Test3::C::h() +struct C : A { + virtual void g(); + virtual void h(); +}; +void C::g() { } + +// CHECK: Vtable for 'Test3::D' (5 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test3::D RTTI +// CHECK-NEXT: -- (Test3::A, 0) vtable address -- +// CHECK-NEXT: -- (Test3::B, 0) vtable address -- +// CHECK-NEXT: -- (Test3::D, 0) vtable address -- +// CHECK-NEXT: 2 | void Test3::D::f() +// CHECK-NEXT: 3 | void Test3::D::g() +// CHECK-NEXT: 4 | void Test3::D::h() +struct D : B { + virtual void f(); + virtual void g(); + virtual void h(); +}; + +void D::f() { } +} + +namespace Test4 { + +// Test non-virtual result adjustments. + +struct R1 { int r1; }; +struct R2 { int r2; }; +struct R3 : R1, R2 { int r3; }; + +struct A { + virtual R2 *f(); +}; + +// CHECK: Vtable for 'Test4::B' (4 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test4::B RTTI +// CHECK-NEXT: -- (Test4::A, 0) vtable address -- +// CHECK-NEXT: -- (Test4::B, 0) vtable address -- +// CHECK-NEXT: 2 | Test4::R3 *Test4::B::f() +// CHECK-NEXT: [return adjustment: 4 non-virtual] +// CHECK-NEXT: 3 | Test4::R3 *Test4::B::f() + +struct B : A { + virtual R3 *f(); +}; +R3 *B::f() { return 0; } + +// Test virtual result adjustments. +struct V1 { int v1; }; +struct V2 : virtual V1 { int v1; }; + +struct C { + virtual V1 *f(); +}; + +// CHECK: Vtable for 'Test4::D' (4 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test4::D RTTI +// CHECK-NEXT: -- (Test4::C, 0) vtable address -- +// CHECK-NEXT: -- (Test4::D, 0) vtable address -- +// CHECK-NEXT: 2 | Test4::V2 *Test4::D::f() +// CHECK-NEXT: [return adjustment: 0 non-virtual, -24 vbase offset offset] +// CHECK-NEXT: 3 | Test4::V2 *Test4::D::f() +struct D : C { + virtual V2 *f(); +}; +V2 *D::f() { return 0; }; + +// Virtual result adjustments with an additional non-virtual adjustment. +struct V3 : virtual R3 { int r3; }; + +// CHECK: Vtable for 'Test4::E' (4 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test4::E RTTI +// CHECK-NEXT: -- (Test4::A, 0) vtable address -- +// CHECK-NEXT: -- (Test4::E, 0) vtable address -- +// CHECK-NEXT: 2 | Test4::V3 *Test4::E::f() +// CHECK-NEXT: [return adjustment: 4 non-virtual, -24 vbase offset offset] +// CHECK-NEXT: 3 | Test4::V3 *Test4::E::f() + +struct E : A { + virtual V3 *f(); +}; +V3 *E::f() { return 0;} + +// Test that a pure virtual member doesn't get a thunk. + +// CHECK: Vtable for 'Test4::F' (5 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test4::F RTTI +// CHECK-NEXT: -- (Test4::A, 0) vtable address -- +// CHECK-NEXT: -- (Test4::F, 0) vtable address -- +// CHECK-NEXT: 2 | Test4::R3 *Test4::F::f() [pure] +// CHECK-NEXT: 3 | void Test4::F::g() +// CHECK-NEXT: 4 | Test4::R3 *Test4::F::f() [pure] +struct F : A { + virtual void g(); + virtual R3 *f() = 0; +}; +void F::g() { } + +} + +namespace Test5 { + +// Simple secondary vtables without 'this' pointer adjustments. +struct A { + virtual void f(); + virtual void g(); + int a; +}; + +struct B1 : A { + virtual void f(); + int b1; +}; + +struct B2 : A { + virtual void g(); + int b2; +}; + +// CHECK: Vtable for 'Test5::C' (9 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test5::C RTTI +// CHECK-NEXT: -- (Test5::A, 0) vtable address -- +// CHECK-NEXT: -- (Test5::B1, 0) vtable address -- +// CHECK-NEXT: -- (Test5::C, 0) vtable address -- +// CHECK-NEXT: 2 | void Test5::B1::f() +// CHECK-NEXT: 3 | void Test5::A::g() +// CHECK-NEXT: 4 | void Test5::C::h() +// CHECK-NEXT: 5 | offset_to_top (-16) +// CHECK-NEXT: 6 | Test5::C RTTI +// CHECK-NEXT: -- (Test5::A, 16) vtable address -- +// CHECK-NEXT: -- (Test5::B2, 16) vtable address -- +// CHECK-NEXT: 7 | void Test5::A::f() +// CHECK-NEXT: 8 | void Test5::B2::g() +struct C : B1, B2 { + virtual void h(); +}; +void C::h() { } +} + +namespace Test6 { + +// Simple non-virtual 'this' pointer adjustments. +struct A1 { + virtual void f(); + int a; +}; + +struct A2 { + virtual void f(); + int a; +}; + +// CHECK: Vtable for 'Test6::C' (6 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test6::C RTTI +// CHECK-NEXT: -- (Test6::A1, 0) vtable address -- +// CHECK-NEXT: -- (Test6::C, 0) vtable address -- +// CHECK-NEXT: 2 | void Test6::C::f() +// CHECK-NEXT: 3 | offset_to_top (-16) +// CHECK-NEXT: 4 | Test6::C RTTI +// CHECK-NEXT: -- (Test6::A2, 16) vtable address -- +// CHECK-NEXT: 5 | void Test6::C::f() +// CHECK-NEXT: [this adjustment: -16 non-virtual] +struct C : A1, A2 { + virtual void f(); +}; +void C::f() { } + +} + +namespace Test7 { + +// Test that the D::f overrider for A::f have different 'this' pointer +// adjustments in the two A base subobjects. + +struct A { + virtual void f(); + int a; +}; + +struct B1 : A { }; +struct B2 : A { }; + +struct C { virtual void c(); }; + +// CHECK: Vtable for 'Test7::D' (10 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test7::D RTTI +// CHECK-NEXT: -- (Test7::C, 0) vtable address -- +// CHECK-NEXT: -- (Test7::D, 0) vtable address -- +// CHECK-NEXT: 2 | void Test7::C::c() +// CHECK-NEXT: 3 | void Test7::D::f() +// CHECK-NEXT: 4 | offset_to_top (-8) +// CHECK-NEXT: 5 | Test7::D RTTI +// CHECK-NEXT: -- (Test7::A, 8) vtable address -- +// CHECK-NEXT: -- (Test7::B1, 8) vtable address -- +// CHECK-NEXT: 6 | void Test7::D::f() +// CHECK-NEXT: [this adjustment: -8 non-virtual] +// CHECK-NEXT: 7 | offset_to_top (-24) +// CHECK-NEXT: 8 | Test7::D RTTI +// CHECK-NEXT: -- (Test7::A, 24) vtable address -- +// CHECK-NEXT: -- (Test7::B2, 24) vtable address -- +// CHECK-NEXT: 9 | void Test7::D::f() +// CHECK-NEXT: [this adjustment: -24 non-virtual] +struct D : C, B1, B2 { + virtual void f(); +}; +void D::f() { } + +} + +namespace Test8 { + +// Test that we don't try to layout vtables for classes that don't have +// virtual bases or virtual member functions. + +struct A { }; + +// CHECK: Vtable for 'Test8::B' (3 entries). +// CHECK-NEXT: 0 | offset_to_top (0) +// CHECK-NEXT: 1 | Test8::B RTTI +// CHECK-NEXT: -- (Test8::B, 0) vtable address -- +// CHECK-NEXT: 2 | void Test8::B::f() +struct B : A { + virtual void f(); +}; +void B::f() { } + +} + +namespace Test9 { + +// Simple test of vbase offsets. + +struct A1 { int a1; }; +struct A2 { int a2; }; + +// CHECK: Vtable for 'Test9::B' (5 entries). +// CHECK-NEXT: 0 | vbase_offset (16) +// CHECK-NEXT: 1 | vbase_offset (12) +// CHECK-NEXT: 2 | offset_to_top (0) +// CHECK-NEXT: 3 | Test9::B RTTI +// CHECK-NEXT: -- (Test9::B, 0) vtable address -- +// CHECK-NEXT: 4 | void Test9::B::f() +struct B : virtual A1, virtual A2 { + int b; + + virtual void f(); +}; + + +void B::f() { } + +} diff --git a/test/CodeGenCXX/vtable-pointer-initialization.cpp b/test/CodeGenCXX/vtable-pointer-initialization.cpp new file mode 100644 index 0000000..92e0117 --- /dev/null +++ b/test/CodeGenCXX/vtable-pointer-initialization.cpp @@ -0,0 +1,54 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s + +struct Field { + Field(); + ~Field(); +}; + +struct Base { + Base(); + ~Base(); +}; + +struct A : Base { + A(); + ~A(); + + virtual void f(); + + Field field; +}; + +// CHECK: define void @_ZN1AC1Ev( +// CHECK: call void @_ZN4BaseC2Ev( +// CHECK: store i8** getelementptr inbounds ([3 x i8*]* @_ZTV1A, i64 0, i64 2) +// CHECK: call void @_ZN5FieldC1Ev( +// CHECK: ret void +A::A() { } + +// CHECK: define void @_ZN1AD1Ev( +// CHECK: store i8** getelementptr inbounds ([3 x i8*]* @_ZTV1A, i64 0, i64 2) +// CHECK: call void @_ZN5FieldD1Ev( +// CHECK: call void @_ZN4BaseD2Ev( +// CHECK: ret void +A::~A() { } + +struct B : Base { + virtual void f(); + + Field field; +}; + +void f() { B b; } + +// CHECK: define linkonce_odr void @_ZN1BC1Ev( +// CHECK: call void @_ZN4BaseC2Ev( +// CHECK: store i8** getelementptr inbounds ([3 x i8*]* @_ZTV1B, i64 0, i64 2) +// CHECK: call void @_ZN5FieldC1Ev +// CHECK: ret void + +// CHECK: define linkonce_odr void @_ZN1BD1Ev( +// CHECK: store i8** getelementptr inbounds ([3 x i8*]* @_ZTV1B, i64 0, i64 2) +// CHECK: call void @_ZN5FieldD1Ev( +// CHECK: call void @_ZN4BaseD2Ev( +// CHECK: ret void diff --git a/test/CodeGenCXX/x86_32-arguments.cpp b/test/CodeGenCXX/x86_32-arguments.cpp new file mode 100644 index 0000000..d13c0e4 --- /dev/null +++ b/test/CodeGenCXX/x86_32-arguments.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s + +// Non-trivial dtors, should both be passed indirectly. +struct S { + ~S(); + int s; +}; + +// CHECK: define void @_Z1fv(%struct.S* noalias sret % +S f() { return S(); } +// CHECK: define void @_Z1f1S(%struct.S*) +void f(S) { } + +// Non-trivial dtors, should both be passed indirectly. +class C { + ~C(); + double c; +}; + +// CHECK: define void @_Z1gv(%class.C* noalias sret % +C g() { return C(); } + +// CHECK: define void @_Z1f1C(%class.C*) +void f(C) { } diff --git a/test/CodeGenObjC/PR4894-recursive-debug-crash.m b/test/CodeGenObjC/PR4894-recursive-debug-crash.m deleted file mode 100644 index 5d2327a..0000000 --- a/test/CodeGenObjC/PR4894-recursive-debug-crash.m +++ /dev/null @@ -1,40 +0,0 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -g -emit-llvm %s -o - | FileCheck %s -// PR4894 -// -// This test is actually just making sure we can generate the debug info for the -// return type from im0 without crashing. -// XFAIL: * - -@interface I0 { - I0 *_iv0; -} -@end -@protocol P0 @end - -@interface I1 @end -@implementation I1 -- (I0<P0> *) im0 { -// CHECK: @"\01-[I1 im0]" -// CHECK: llvm.dbg.func.start - return 0; -} -@end - -// FIXME: This was another PR4894 test case, which is crashing somewhere -// else. PR5025. -#if 0 -typedef const struct objc_selector { - void *sel_id; - const char *sel_types; -} *SEL; - -@interface I2 -+(id) dictionary; -@end - -@implementation I3; -+(void) initialize { - I2 *a0 = [I2 dictionary]; -} -@end -#endif diff --git a/test/CodeGenObjC/blocks-4.m b/test/CodeGenObjC/blocks-4.m new file mode 100644 index 0000000..d945ed4 --- /dev/null +++ b/test/CodeGenObjC/blocks-4.m @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm -fblocks -o %t %s +// rdar://7590273 + +void EXIT(id e); + +@interface NSBlockOperation { +} ++(id)blockOperationWithBlock:(void (^)(void))block ; +@end + +void FUNC() { + [NSBlockOperation blockOperationWithBlock:^{ + @try { + + } + @catch (id exception) { + EXIT(exception); + } + }]; + +} diff --git a/test/CodeGenObjC/PR4541.m b/test/CodeGenObjC/debug-info-crash.m index 84218a9..92f9c0e 100644 --- a/test/CodeGenObjC/PR4541.m +++ b/test/CodeGenObjC/debug-info-crash.m @@ -1,6 +1,29 @@ -// RUN: %clang_cc1 -o %t -w -g %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -fblocks -g -S %s -o - +// rdar://7556129 +@implementation test +- (void)wait { + ^{}; +} +@end + +// PR4894 +@interface I0 { + I0 *_iv0; +} +@end +@protocol P0 @end +@interface I1 @end +@implementation I1 +- (I0<P0> *) im0 { + // CHECK: @"\01-[I1 im0]" + // CHECK: llvm.dbg.func.start + return 0; +} +@end + +// PR4541 @class NSString; @interface NSAttributedString - (NSString *)string; @@ -15,5 +38,3 @@ NSMutableAttributedString *attrStr; } @end - - diff --git a/test/CodeGenObjC/id-isa-codegen.m b/test/CodeGenObjC/id-isa-codegen.m index 89e9922..3179e11 100644 --- a/test/CodeGenObjC/id-isa-codegen.m +++ b/test/CodeGenObjC/id-isa-codegen.m @@ -34,3 +34,17 @@ Class Test(const void *inObject1) { return ((id)inObject1)->isa; return (id)0; } + +// rdar 7609722 +@interface Foo { +@public + id isa; +} ++(id)method; +@end + +id Test2() { + if([Foo method]->isa) + return (*[Foo method]).isa; + return [Foo method]->isa; +} diff --git a/test/CodeGenObjC/image-info.m b/test/CodeGenObjC/image-info.m index 17f7531..8916d00 100644 --- a/test/CodeGenObjC/image-info.m +++ b/test/CodeGenObjC/image-info.m @@ -1,2 +1,2 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin-10 -emit-llvm -o %t %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o %t %s // RUN: grep -F '@"\01L_OBJC_IMAGE_INFO" = internal constant [2 x i32] [i32 0, i32 16], section "__OBJC, __image_info,regular"' %t diff --git a/test/CodeGenObjC/objc2-legacy-dispatch.m b/test/CodeGenObjC/objc2-legacy-dispatch.m new file mode 100644 index 0000000..4c37573 --- /dev/null +++ b/test/CodeGenObjC/objc2-legacy-dispatch.m @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck -check-prefix=CHECK_NEW_DISPATCH %s +// +// CHECK_NEW_DISPATCH: define void @f0 +// CHECK_NEW_DISPATCH: bitcast {{.*}}objc_msgSend_fixup_alloc +// CHECK_NEW_DISPATCH: define void @f1 +// CHECK_NEW_DISPATCH: load {{.*}}OBJC_SELECTOR_REFERENCES +// +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-legacy-dispatch -emit-llvm -o - %s | FileCheck -check-prefix=CHECK_OLD_DISPATCH %s +// +// CHECK_OLD_DISPATCH: define void @f0 +// CHECK_OLD_DISPATCH: load {{.*}}OBJC_SELECTOR_REFERENCES +// CHECK_OLD_DISPATCH: define void @f1 +// CHECK_OLD_DISPATCH: load {{.*}}OBJC_SELECTOR_REFERENCES + +@interface A ++(id) alloc; +-(int) im0; +@end + +void f0(void) { + [A alloc]; +} + +void f1(A *a) { + [a im0]; +} diff --git a/test/CodeGenObjC/objc2-weak-block-call.m b/test/CodeGenObjC/objc2-weak-block-call.m new file mode 100644 index 0000000..a3514b0 --- /dev/null +++ b/test/CodeGenObjC/objc2-weak-block-call.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -fblocks -fobjc-gc -triple x86_64-apple-darwin -S %s -o %t-64.s +// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s +// RUN: %clang_cc1 -fblocks -fobjc-gc -triple i386-apple-darwin -S %s -o %t-32.s +// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s + +@interface MyView +- (void)MyView_sharedInit; +@end + +void foo(MyView *(^obj)(void)) ; + +@implementation MyView +- (void)MyView_sharedInit { + + __block __weak MyView *weakSelf = self; + foo( + ^{ + return weakSelf; + }); + +} +@end + +// CHECK-LP64: callq _objc_read_weak +// CHECK-LP64: callq _objc_read_weak + +// CHECK-LP32: call L_objc_read_weak +// CHECK-LP32: call L_objc_read_weak + diff --git a/test/CodeGenObjC/unwind-fn.m b/test/CodeGenObjC/unwind-fn.m new file mode 100644 index 0000000..0aa8cde --- /dev/null +++ b/test/CodeGenObjC/unwind-fn.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck --check-prefix=DEFAULT_EH %s +// RUN: %clang_cc1 -fsjlj-exceptions -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck --check-prefix=SJLJ_EH %s + +// DEFAULT_EH: declare void @_Unwind_Resume_or_Rethrow(i8*) +// SJLJ_EH: declare void @_Unwind_SjLj_Resume(i8*) + +void f1(), f2(); +void f0() { + @try { + f1(); + } @catch (...) { + f2(); + } +} diff --git a/test/Coverage/html-diagnostics.c b/test/Coverage/html-diagnostics.c index 6971f58..81b2cfa 100644 --- a/test/Coverage/html-diagnostics.c +++ b/test/Coverage/html-diagnostics.c @@ -1,5 +1,5 @@ // RUN: rm -rf %t -// RUN: %clang_cc1 -analyze -analyzer-output=html -checker-cfref -o %t %s +// RUN: %clang_cc1 -analyze -analyzer-output=html -analyzer-check-objc-mem -o %t %s // RUN: cat %t/*.html | FileCheck %s // CHECK: <h3>Annotated Source Code</h3> diff --git a/test/Driver/darwin-iphone-defaults.m b/test/Driver/darwin-iphone-defaults.m new file mode 100644 index 0000000..97ac4a4 --- /dev/null +++ b/test/Driver/darwin-iphone-defaults.m @@ -0,0 +1,30 @@ +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -arch armv7 -flto -S -o - %s | FileCheck %s + +// CHECK: @f0 +// CHECK-NOT: ssp +// CHECK: ) { +// CHECK: @__f0_block_invoke +// CHECK: void @f1 +// CHECK-NOT: msgSend_fixup_alloc +// CHECK: OBJC_SELECTOR_REFERENCES + +int f0() { + return ^(){ return 0; }(); +} + +@interface I0 +@property (assign) int p0; +@end + +@implementation I0 +@synthesize p0 = __sythesized_p0; +@end + +@interface I1 ++(id) alloc; +@end + +void f1() { + [I1 alloc]; +} + diff --git a/test/Driver/darwin-ld.c b/test/Driver/darwin-ld.c index de751a6..d34d566 100644 --- a/test/Driver/darwin-ld.c +++ b/test/Driver/darwin-ld.c @@ -39,5 +39,38 @@ // RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -arch i386 -arch x86_64 -g %s 2> %t.log // RUN: grep dsymutil %t.log | count 0 +// Check linker changes that came with new linkedit format. +// RUN: touch %t.o +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -arch armv6 -miphoneos-version-min=3.0 %t.o 2> %t.log +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -arch armv6 -miphoneos-version-min=3.0 -dynamiclib %t.o 2>> %t.log +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -arch armv6 -miphoneos-version-min=3.0 -bundle %t.o 2>> %t.log +// RUN: FileCheck -check-prefix=LINK_IPHONE_3_0 %s < %t.log +// LINK_IPHONE_3_0: ld" +// LINK_IPHONE_3_0-NOT: -lcrt1.3.1.o +// LINK_IPHONE_3_0: -lcrt1.o +// LINK_IPHONE_3_0: -lSystem +// LINK_IPHONE_3_0: ld" +// LINK_IPHONE_3_0: -dylib +// LINK_IPHONE_3_0: -ldylib1.o +// LINK_IPHONE_3_0: -lSystem +// LINK_IPHONE_3_0: ld" +// LINK_IPHONE_3_0: -lbundle1.o +// LINK_IPHONE_3_0: -lSystem +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -arch armv7 -miphoneos-version-min=3.1 %t.o 2> %t.log +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -arch armv7 -miphoneos-version-min=3.1 -dynamiclib %t.o 2>> %t.log +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -arch armv7 -miphoneos-version-min=3.1 -bundle %t.o 2>> %t.log +// RUN: FileCheck -check-prefix=LINK_IPHONE_3_1 %s < %t.log + +// LINK_IPHONE_3_1: ld" +// LINK_IPHONE_3_1-NOT: -lcrt1.o +// LINK_IPHONE_3_1: -lcrt1.3.1.o +// LINK_IPHONE_3_1: -lSystem +// LINK_IPHONE_3_1: ld" +// LINK_IPHONE_3_1: -dylib +// LINK_IPHONE_3_1-NOT: -ldylib1.o +// LINK_IPHONE_3_1: -lSystem +// LINK_IPHONE_3_1: ld" +// LINK_IPHONE_3_1-NOT: -lbundle1.o +// LINK_IPHONE_3_1: -lSystem diff --git a/test/Driver/darwin-version.c b/test/Driver/darwin-version.c index e69a844..84533a6 100644 --- a/test/Driver/darwin-version.c +++ b/test/Driver/darwin-version.c @@ -1,6 +1,23 @@ -// RUN: env MACOSX_DEPLOYMENT_TARGET=10.1 %clang -ccc-host-triple i386-apple-darwin9 -E %s - +// RUN: env MACOSX_DEPLOYMENT_TARGET=10.1 \ +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -DTEST0 -E %s +#ifdef TEST0 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1010 #error Invalid version #endif +#endif +// RUN: env IPHONEOS_DEPLOYMENT_TARGET=2.0 \ +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -DTEST1 -E %s +#ifdef TEST1 +#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ != 20000 +#error Invalid version +#endif +#endif + +// RUN: env IPHONEOS_DEPLOYMENT_TARGET=2.3.1 \ +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -DTEST2 -E %s +#ifdef TEST2 +#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ != 20301 +#error Invalid version +#endif +#endif diff --git a/test/Driver/rewrite-objc.m b/test/Driver/rewrite-objc.m new file mode 100644 index 0000000..38993fc --- /dev/null +++ b/test/Driver/rewrite-objc.m @@ -0,0 +1,11 @@ +// RUN: %clang -ccc-host-triple unknown -rewrite-objc %s -o - -### 2>&1 | \ +// RUN: FileCheck -check-prefix=TEST0 %s +// TEST0: clang{{.*}}" "-rewrite-objc" + +// RUN: not %clang -ccc-no-clang -ccc-host-triple unknown -rewrite-objc %s -o - -### 2>&1 | \ +// RUN: FileCheck -check-prefix=TEST1 %s +// TEST1: invalid output type 'rewritten-objc' for use with gcc + +// RUN: not %clang -ccc-no-clang -ccc-host-triple i386-apple-darwin10 -rewrite-objc %s -o - -### 2>&1 | \ +// RUN: FileCheck -check-prefix=TEST2 %s +// TEST2: invalid output type 'rewritten-objc' for use with gcc diff --git a/test/FixIt/fixit.cpp b/test/FixIt/fixit.cpp index 04b99c9..ee93755 100644 --- a/test/FixIt/fixit.cpp +++ b/test/FixIt/fixit.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -pedantic -fixit %s -o - | %clang_cc1 -fsyntax-only -pedantic -Werror -x c++ - +// RUN: %clang_cc1 -pedantic -Wall -fixit %s -o - | %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -x c++ - /* This is a test of the various code modification hints that are provided as part of warning or extension diagnostics. All of the @@ -28,11 +28,12 @@ struct CT<0> { }; // expected-error{{'template<>'}} template<> class CT<1> { }; // expected-error{{tag type}} -// PR5444 -namespace PR5444 { - void foo(int x, int y = 0); - void foo(int x, int y = 0) { } +// Access declarations +class A { +protected: + int foo(); +}; - void foo(int = 0); - void foo(int = 0) { } -} +class B : public A { + A::foo; // expected-warning{{access declarations are deprecated}} +}; diff --git a/test/FixIt/typo-crash.m b/test/FixIt/typo-crash.m new file mode 100644 index 0000000..f10fe61 --- /dev/null +++ b/test/FixIt/typo-crash.m @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// <rdar://problem/7605289> +@implementation Unknown (Blarg) // expected-error{{cannot find interface declaration for 'Unknown'}} +- (int)method { return ivar; } // expected-error{{use of undeclared identifier 'ivar'}} +@end diff --git a/test/FixIt/typo.m b/test/FixIt/typo.m index c2069dd..86dd383 100644 --- a/test/FixIt/typo.m +++ b/test/FixIt/typo.m @@ -86,5 +86,5 @@ void test2(Collide *a) { - (int)send:(void*)buffer bytes:(int)bytes; @end -@interface IPv8 <Network_Socket> // expected-error{{cannot find protocol declaration for 'Network_Socket'; did you mean 'NetworkSocket'?}} +@interface IPv6 <Network_Socket> // expected-error{{cannot find protocol declaration for 'Network_Socket'; did you mean 'NetworkSocket'?}} @end diff --git a/test/Index/TestClassDecl.m b/test/Index/TestClassDecl.m index f962712..b55c862 100644 --- a/test/Index/TestClassDecl.m +++ b/test/Index/TestClassDecl.m @@ -15,19 +15,19 @@ void function(Foo * arg) // nothing here. } -// CHECK-scan: {start_line=1 start_col=1 end_line=7 end_col=1} Invalid Cursor => NoDeclFound -// CHECK-scan: {start_line=8 start_col=1 end_line=8 end_col=7} UnexposedDecl=:8:1 -// CHECK-scan: {start_line=8 start_col=8 end_line=8 end_col=10} ObjCClassRef=Foo:10:12 -// CHECK-scan: {start_line=8 start_col=11 end_line=9 end_col=1} Invalid Cursor => NoDeclFound -// CHECK-scan: {start_line=10 start_col=1 end_line=11 end_col=4} ObjCInterfaceDecl=Foo:10:12 -// CHECK-scan: {start_line=11 start_col=5 end_line=13 end_col=5} Invalid Cursor => NoDeclFound -// CHECK-scan: {start_line=13 start_col=6 end_line=13 end_col=14} FunctionDecl=function:13:6 (Definition) -// CHECK-scan: {start_line=13 start_col=15 end_line=13 end_col=17} ObjCClassRef=Foo:10:12 -// CHECK-scan: {start_line=13 start_col=18 end_line=13 end_col=23} ParmDecl=arg:13:21 (Definition) -// CHECK-scan: {start_line=13 start_col=24 end_line=13 end_col=25} FunctionDecl=function:13:6 (Definition) -// CHECK-scan: {start_line=14 start_col=1 end_line=16 end_col=1} UnexposedStmt=function +// CHECK-scan: [1:1 - 8:1] Invalid Cursor => NoDeclFound +// CHECK-scan: [8:1 - 8:8] UnexposedDecl=:8:1 +// CHECK-scan: [8:8 - 8:11] ObjCClassRef=Foo:10:12 +// CHECK-scan: [8:11 - 10:1] Invalid Cursor => NoDeclFound +// CHECK-scan: [10:1 - 11:5] ObjCInterfaceDecl=Foo:10:12 +// CHECK-scan: [11:5 - 13:6] Invalid Cursor => NoDeclFound +// CHECK-scan: [13:6 - 13:15] FunctionDecl=function:13:6 (Definition) +// CHECK-scan: [13:15 - 13:18] ObjCClassRef=Foo:10:12 +// CHECK-scan: [13:18 - 13:24] ParmDecl=arg:13:21 (Definition) +// CHECK-scan: [13:24 - 14:1] FunctionDecl=function:13:6 (Definition) +// CHECK-scan: [14:1 - 16:2] UnexposedStmt= -// CHECK-load: TestClassDecl.m:10:12: ObjCInterfaceDecl=Foo:10:12 [Extent=10:1:11:4] -// CHECK-load: TestClassDecl.m:13:6: FunctionDecl=function:13:6 (Definition) [Extent=13:6:16:1] -// CHECK-load: TestClassDecl.m:13:21: ParmDecl=arg:13:21 (Definition) [Extent=13:15:13:23] +// CHECK-load: TestClassDecl.m:10:12: ObjCInterfaceDecl=Foo:10:12 Extent=[10:1 - 11:5] +// CHECK-load: TestClassDecl.m:13:6: FunctionDecl=function:13:6 (Definition) Extent=[13:6 - 16:2] +// CHECK-load: TestClassDecl.m:13:21: ParmDecl=arg:13:21 (Definition) Extent=[13:15 - 13:24] diff --git a/test/Index/TestClassForwardDecl.m b/test/Index/TestClassForwardDecl.m index c53453b..325a423 100644 --- a/test/Index/TestClassForwardDecl.m +++ b/test/Index/TestClassForwardDecl.m @@ -12,15 +12,15 @@ void function(Foo * arg) // nothing here. } -// CHECK-scan: {start_line=1 start_col=1 end_line=7 end_col=1} Invalid Cursor => NoDeclFound -// CHECK-scan: {start_line=8 start_col=1 end_line=8 end_col=7} UnexposedDecl=:8:1 -// CHECK-scan: {start_line=8 start_col=8 end_line=8 end_col=10} ObjCClassRef=Foo:8:8 -// CHECK-scan: {start_line=8 start_col=11 end_line=10 end_col=5} Invalid Cursor => NoDeclFound -// CHECK-scan: {start_line=10 start_col=6 end_line=10 end_col=14} FunctionDecl=function:10:6 (Definition) -// CHECK-scan: {start_line=10 start_col=15 end_line=10 end_col=17} ObjCClassRef=Foo:8:8 -// CHECK-scan: {start_line=10 start_col=18 end_line=10 end_col=23} ParmDecl=arg:10:21 (Definition) -// CHECK-scan: {start_line=10 start_col=24 end_line=10 end_col=25} FunctionDecl=function:10:6 (Definition) -// CHECK-scan: {start_line=11 start_col=1 end_line=13 end_col=1} UnexposedStmt=function +// CHECK-scan: [1:1 - 8:1] Invalid Cursor => NoDeclFound +// CHECK-scan: [8:1 - 8:8] UnexposedDecl=:8:1 +// CHECK-scan: [8:8 - 8:11] ObjCClassRef=Foo:8:8 +// CHECK-scan: [8:11 - 10:6] Invalid Cursor => NoDeclFound +// CHECK-scan: [10:6 - 10:15] FunctionDecl=function:10:6 (Definition) +// CHECK-scan: [10:15 - 10:18] ObjCClassRef=Foo:8:8 +// CHECK-scan: [10:18 - 10:24] ParmDecl=arg:10:21 (Definition) +// CHECK-scan: [10:24 - 11:1] FunctionDecl=function:10:6 (Definition) +// CHECK-scan: [11:1 - 13:2] UnexposedStmt= diff --git a/test/Index/annotate-tokens.c b/test/Index/annotate-tokens.c new file mode 100644 index 0000000..ef0069c --- /dev/null +++ b/test/Index/annotate-tokens.c @@ -0,0 +1,64 @@ +typedef int T; +struct X { int a, b; }; +void f(void *ptr) { + T* t_ptr = (T *)ptr; + (void)sizeof(T); + /* A comment */ + struct X x = (struct X){1, 2}; + void *xx = ptr ? : &x; + const char * hello = "Hello"; +} + +// RUN: c-index-test -test-annotate-tokens=%s:4:1:9:32 %s | FileCheck %s +// CHECK: Identifier: "T" [4:3 - 4:4] TypeRef=T:1:13 +// CHECK: Punctuation: "*" [4:4 - 4:5] +// CHECK: Identifier: "t_ptr" [4:6 - 4:11] VarDecl=t_ptr:4:6 (Definition) +// CHECK: Punctuation: "=" [4:12 - 4:13] +// CHECK: Punctuation: "(" [4:14 - 4:15] +// CHECK: Identifier: "T" [4:15 - 4:16] TypeRef=T:1:13 +// CHECK: Punctuation: "*" [4:17 - 4:18] +// CHECK: Punctuation: ")" [4:18 - 4:19] +// CHECK: Identifier: "ptr" [4:19 - 4:22] DeclRefExpr=ptr:3:14 +// CHECK: Punctuation: ";" [4:22 - 4:23] +// CHECK: Punctuation: "(" [5:3 - 5:4] +// CHECK: Keyword: "void" [5:4 - 5:8] +// CHECK: Punctuation: ")" [5:8 - 5:9] +// CHECK: Keyword: "sizeof" [5:9 - 5:15] +// CHECK: Punctuation: "(" [5:15 - 5:16] +// CHECK: Identifier: "T" [5:16 - 5:17] TypeRef=T:1:13 +// CHECK: Punctuation: ")" [5:17 - 5:18] +// CHECK: Punctuation: ";" [5:18 - 5:19] +// CHECK: Comment: "/* A comment */" [6:3 - 6:18] +// CHECK: Keyword: "struct" [7:3 - 7:9] +// CHECK: Identifier: "X" [7:10 - 7:11] TypeRef=struct X:2:8 +// CHECK: Identifier: "x" [7:12 - 7:13] VarDecl=x:7:12 (Definition) +// CHECK: Punctuation: "=" [7:14 - 7:15] +// CHECK: Punctuation: "(" [7:16 - 7:17] +// CHECK: Keyword: "struct" [7:17 - 7:23] +// CHECK: Identifier: "X" [7:24 - 7:25] TypeRef=struct X:2:8 +// CHECK: Punctuation: ")" [7:25 - 7:26] +// CHECK: Punctuation: "{" [7:26 - 7:27] +// CHECK: Literal: "1" [7:27 - 7:28] +// CHECK: Punctuation: "," [7:28 - 7:29] +// CHECK: Literal: "2" [7:30 - 7:31] +// CHECK: Punctuation: "}" [7:31 - 7:32] +// CHECK: Punctuation: ";" [7:32 - 7:33] +// CHECK: Keyword: "void" [8:3 - 8:7] +// CHECK: Punctuation: "*" [8:8 - 8:9] +// CHECK: Identifier: "xx" [8:9 - 8:11] VarDecl=xx:8:9 (Definition) +// CHECK: Punctuation: "=" [8:12 - 8:13] +// CHECK: Identifier: "ptr" [8:14 - 8:17] DeclRefExpr=ptr:3:14 +// CHECK: Punctuation: "?" [8:18 - 8:19] +// CHECK: Punctuation: ":" [8:20 - 8:21] +// CHECK: Punctuation: "&" [8:22 - 8:23] +// CHECK: Identifier: "x" [8:23 - 8:24] DeclRefExpr=x:7:12 +// CHECK: Punctuation: ";" [8:24 - 8:25] +// CHECK: Keyword: "const" [9:3 - 9:8] +// CHECK: Keyword: "char" [9:9 - 9:13] +// CHECK: Punctuation: "*" [9:14 - 9:15] +// CHECK: Identifier: "hello" [9:16 - 9:21] VarDecl=hello:9:16 (Definition) +// CHECK: Punctuation: "=" [9:22 - 9:23] +// CHECK: Literal: ""Hello"" [9:24 - 9:31] +// CHECK: Punctuation: ";" [9:31 - 9:32] +// CHECK: Punctuation: "}" [10:1 - 10:2] + diff --git a/test/Index/c-index-api-loadTU-test.m b/test/Index/c-index-api-loadTU-test.m index cf0dbff..cd0c868 100644 --- a/test/Index/c-index-api-loadTU-test.m +++ b/test/Index/c-index-api-loadTU-test.m @@ -65,67 +65,67 @@ int main (int argc, const char * argv[]) { // CHECK: <invalid loc>:87:81: FieldDecl=overflow_arg_area:87:81 (Definition) // CHECK: <invalid loc>:87:107: FieldDecl=reg_save_area:87:107 (Definition) // CHECK: <invalid loc>:87:123: TypedefDecl=__va_list_tag:87:123 (Definition) -// CHECK: <invalid loc>:87:9: TypeRef=struct __va_list_tag:87:16 +// CHECK: <invalid loc>:87:16: TypeRef=struct __va_list_tag:87:16 // CHECK: <invalid loc>:87:159: TypedefDecl=__builtin_va_list:87:159 (Definition) // CHECK: <invalid loc>:87:145: TypeRef=__va_list_tag:87:123 // CHECK: <invalid loc>:87:177: UnexposedExpr= -// CHECK: c-index-api-loadTU-test.m:4:12: ObjCInterfaceDecl=Foo:4:12 [Extent=4:1:11:4] -// CHECK: c-index-api-loadTU-test.m:8:1: ObjCInstanceMethodDecl=foo:8:1 [Extent=8:1:8:6] -// CHECK: c-index-api-loadTU-test.m:9:1: ObjCClassMethodDecl=fooC:9:1 [Extent=9:1:9:7] -// CHECK: c-index-api-loadTU-test.m:13:12: ObjCInterfaceDecl=Bar:13:12 [Extent=13:1:17:4] -// CHECK: c-index-api-loadTU-test.m:13:18: ObjCSuperClassRef=Foo:4:12 [Extent=13:18:13:20] -// CHECK: c-index-api-loadTU-test.m:19:12: ObjCCategoryDecl=FooCat:19:12 [Extent=19:1:22:4] -// CHECK: c-index-api-loadTU-test.m:19:12: ObjCClassRef=Foo:4:12 [Extent=19:12:19:14] -// CHECK: c-index-api-loadTU-test.m:20:1: ObjCInstanceMethodDecl=catMethodWithFloat::20:1 [Extent=20:1:20:40] -// CHECK: c-index-api-loadTU-test.m:20:36: ParmDecl=fArg:20:36 (Definition) [Extent=20:29:20:39] -// CHECK: c-index-api-loadTU-test.m:21:1: ObjCInstanceMethodDecl=floatMethod:21:1 [Extent=21:1:21:22] -// CHECK: c-index-api-loadTU-test.m:24:1: ObjCProtocolDecl=Proto:24:1 (Definition) [Extent=24:1:26:4] -// CHECK: c-index-api-loadTU-test.m:25:1: ObjCInstanceMethodDecl=pMethod:25:1 [Extent=25:1:25:10] -// CHECK: c-index-api-loadTU-test.m:28:1: ObjCProtocolDecl=SubP:28:1 (Definition) [Extent=28:1:30:4] -// CHECK: c-index-api-loadTU-test.m:28:17: ObjCProtocolRef=Proto:24:1 [Extent=28:17:28:21] -// CHECK: c-index-api-loadTU-test.m:29:1: ObjCInstanceMethodDecl=spMethod:29:1 [Extent=29:1:29:11] -// CHECK: c-index-api-loadTU-test.m:32:12: ObjCInterfaceDecl=Baz:32:12 [Extent=32:1:39:4] -// CHECK: c-index-api-loadTU-test.m:32:18: ObjCSuperClassRef=Bar:13:12 [Extent=32:18:32:20] -// CHECK: c-index-api-loadTU-test.m:32:23: ObjCProtocolRef=SubP:28:1 [Extent=32:23:32:26] -// CHECK: c-index-api-loadTU-test.m:34:9: ObjCIvarDecl=_anIVar:34:9 (Definition) [Extent=34:9:34:15] -// CHECK: c-index-api-loadTU-test.m:37:1: ObjCInstanceMethodDecl=bazMethod:37:1 [Extent=37:1:37:20] -// CHECK: c-index-api-loadTU-test.m:41:1: EnumDecl=:41:1 (Definition) [Extent=41:1:43:1] -// CHECK: c-index-api-loadTU-test.m:42:3: EnumConstantDecl=someEnum:42:3 (Definition) [Extent=42:3:42:10] -// CHECK: c-index-api-loadTU-test.m:45:5: FunctionDecl=main:45:5 (Definition) [Extent=45:5:54:1] -// CHECK: c-index-api-loadTU-test.m:45:15: ParmDecl=argc:45:15 (Definition) [Extent=45:11:45:18] -// CHECK: c-index-api-loadTU-test.m:45:34: ParmDecl=argv:45:34 (Definition) [Extent=45:27:45:37] -// CHECK: c-index-api-loadTU-test.m:45:5: UnexposedStmt=main [Extent=45:42:54:1] -// CHECK: c-index-api-loadTU-test.m:45:5: UnexposedStmt=main [Extent=46:2:46:11] -// CHECK: c-index-api-loadTU-test.m:46:8: VarDecl=bee:46:8 (Definition) [Extent=46:2:46:10] -// CHECK: c-index-api-loadTU-test.m:46:2: ObjCClassRef=Baz:32:12 [Extent=46:2:46:4] -// CHECK: c-index-api-loadTU-test.m:46:8: UnexposedStmt=bee [Extent=47:2:47:18] -// CHECK: c-index-api-loadTU-test.m:47:5: VarDecl=a:47:5 (Definition) [Extent=47:2:47:17] -// CHECK: c-index-api-loadTU-test.m:47:2: TypeRef=id:0:0 [Extent=47:2:47:3] -// CHECK: c-index-api-loadTU-test.m:47:9: ObjCMessageExpr=foo:8:1 [Extent=47:9:47:17] -// CHECK: c-index-api-loadTU-test.m:47:10: DeclRefExpr=bee:46:8 [Extent=47:10:47:12] -// CHECK: c-index-api-loadTU-test.m:47:5: UnexposedStmt=a [Extent=48:2:48:26] -// CHECK: c-index-api-loadTU-test.m:48:12: VarDecl=c:48:12 (Definition) [Extent=48:2:48:25] -// CHECK: c-index-api-loadTU-test.m:48:2: TypeRef=id:0:0 [Extent=48:2:48:3] -// CHECK: c-index-api-loadTU-test.m:48:6: ObjCProtocolRef=SubP:28:1 [Extent=48:6:48:9] -// CHECK: c-index-api-loadTU-test.m:48:16: UnexposedExpr=fooC:9:1 [Extent=48:16:48:25] -// CHECK: c-index-api-loadTU-test.m:48:16: ObjCMessageExpr=fooC:9:1 [Extent=48:16:48:25] -// CHECK: c-index-api-loadTU-test.m:48:12: UnexposedStmt=c [Extent=49:2:49:14] -// CHECK: c-index-api-loadTU-test.m:49:13: VarDecl=d:49:13 (Definition) [Extent=49:2:49:13] -// CHECK: c-index-api-loadTU-test.m:49:2: TypeRef=id:0:0 [Extent=49:2:49:3] -// CHECK: c-index-api-loadTU-test.m:49:6: ObjCProtocolRef=Proto:24:1 [Extent=49:6:49:10] -// CHECK: c-index-api-loadTU-test.m:50:2: UnexposedExpr= [Extent=50:2:50:6] -// CHECK: c-index-api-loadTU-test.m:50:2: DeclRefExpr=d:49:13 [Extent=50:2:50:2] -// CHECK: c-index-api-loadTU-test.m:50:6: UnexposedExpr=c:48:12 [Extent=50:6:50:6] -// CHECK: c-index-api-loadTU-test.m:50:6: DeclRefExpr=c:48:12 [Extent=50:6:50:6] -// CHECK: c-index-api-loadTU-test.m:51:2: ObjCMessageExpr=pMethod:25:1 [Extent=51:2:51:12] -// CHECK: c-index-api-loadTU-test.m:51:3: DeclRefExpr=d:49:13 [Extent=51:3:51:3] -// CHECK: c-index-api-loadTU-test.m:52:2: ObjCMessageExpr=catMethodWithFloat::20:1 [Extent=52:2:52:43] -// CHECK: c-index-api-loadTU-test.m:52:3: DeclRefExpr=bee:46:8 [Extent=52:3:52:5] -// CHECK: c-index-api-loadTU-test.m:52:26: ObjCMessageExpr=floatMethod:21:1 [Extent=52:26:52:42] -// CHECK: c-index-api-loadTU-test.m:52:27: DeclRefExpr=bee:46:8 [Extent=52:27:52:29] -// CHECK: c-index-api-loadTU-test.m:53:3: CallExpr=main:45:5 [Extent=53:3:53:36] -// CHECK: c-index-api-loadTU-test.m:53:3: UnexposedExpr=main:45:5 [Extent=53:3:53:6] -// CHECK: c-index-api-loadTU-test.m:53:3: DeclRefExpr=main:45:5 [Extent=53:3:53:6] -// CHECK: c-index-api-loadTU-test.m:53:8: DeclRefExpr=someEnum:42:3 [Extent=53:8:53:15] -// CHECK: c-index-api-loadTU-test.m:53:18: UnexposedExpr=bee:46:8 [Extent=53:18:53:35] -// CHECK: c-index-api-loadTU-test.m:53:33: DeclRefExpr=bee:46:8 [Extent=53:33:53:35] +// CHECK: c-index-api-loadTU-test.m:4:12: ObjCInterfaceDecl=Foo:4:12 Extent=[4:1 - 11:5] +// CHECK: c-index-api-loadTU-test.m:8:1: ObjCInstanceMethodDecl=foo:8:1 Extent=[8:1 - 8:7] +// CHECK: c-index-api-loadTU-test.m:9:1: ObjCClassMethodDecl=fooC:9:1 Extent=[9:1 - 9:8] +// CHECK: c-index-api-loadTU-test.m:13:12: ObjCInterfaceDecl=Bar:13:12 Extent=[13:1 - 17:5] +// CHECK: c-index-api-loadTU-test.m:13:18: ObjCSuperClassRef=Foo:4:12 Extent=[13:18 - 13:21] +// CHECK: c-index-api-loadTU-test.m:19:12: ObjCCategoryDecl=FooCat:19:12 Extent=[19:1 - 22:5] +// CHECK: c-index-api-loadTU-test.m:19:12: ObjCClassRef=Foo:4:12 Extent=[19:12 - 19:15] +// CHECK: c-index-api-loadTU-test.m:20:1: ObjCInstanceMethodDecl=catMethodWithFloat::20:1 Extent=[20:1 - 20:41] +// CHECK: c-index-api-loadTU-test.m:20:36: ParmDecl=fArg:20:36 (Definition) Extent=[20:29 - 20:40] +// CHECK: c-index-api-loadTU-test.m:21:1: ObjCInstanceMethodDecl=floatMethod:21:1 Extent=[21:1 - 21:23] +// CHECK: c-index-api-loadTU-test.m:24:1: ObjCProtocolDecl=Proto:24:1 (Definition) Extent=[24:1 - 26:5] +// CHECK: c-index-api-loadTU-test.m:25:1: ObjCInstanceMethodDecl=pMethod:25:1 Extent=[25:1 - 25:11] +// CHECK: c-index-api-loadTU-test.m:28:1: ObjCProtocolDecl=SubP:28:1 (Definition) Extent=[28:1 - 30:5] +// CHECK: c-index-api-loadTU-test.m:28:17: ObjCProtocolRef=Proto:24:1 Extent=[28:17 - 28:22] +// CHECK: c-index-api-loadTU-test.m:29:1: ObjCInstanceMethodDecl=spMethod:29:1 Extent=[29:1 - 29:12] +// CHECK: c-index-api-loadTU-test.m:32:12: ObjCInterfaceDecl=Baz:32:12 Extent=[32:1 - 39:5] +// CHECK: c-index-api-loadTU-test.m:32:18: ObjCSuperClassRef=Bar:13:12 Extent=[32:18 - 32:21] +// CHECK: c-index-api-loadTU-test.m:32:23: ObjCProtocolRef=SubP:28:1 Extent=[32:23 - 32:27] +// CHECK: c-index-api-loadTU-test.m:34:9: ObjCIvarDecl=_anIVar:34:9 (Definition) Extent=[34:9 - 34:16] +// CHECK: c-index-api-loadTU-test.m:37:1: ObjCInstanceMethodDecl=bazMethod:37:1 Extent=[37:1 - 37:21] +// CHECK: c-index-api-loadTU-test.m:41:1: EnumDecl=:41:1 (Definition) Extent=[41:1 - 43:2] +// CHECK: c-index-api-loadTU-test.m:42:3: EnumConstantDecl=someEnum:42:3 (Definition) Extent=[42:3 - 42:11] +// CHECK: c-index-api-loadTU-test.m:45:5: FunctionDecl=main:45:5 (Definition) Extent=[45:5 - 54:2] +// CHECK: c-index-api-loadTU-test.m:45:15: ParmDecl=argc:45:15 (Definition) Extent=[45:11 - 45:19] +// CHECK: c-index-api-loadTU-test.m:45:34: ParmDecl=argv:45:34 (Definition) Extent=[45:27 - 45:38] +// CHECK: c-index-api-loadTU-test.m:45:5: UnexposedStmt= Extent=[45:42 - 54:2] +// CHECK: c-index-api-loadTU-test.m:45:5: UnexposedStmt= Extent=[46:2 - 46:12] +// CHECK: c-index-api-loadTU-test.m:46:8: VarDecl=bee:46:8 (Definition) Extent=[46:2 - 46:11] +// CHECK: c-index-api-loadTU-test.m:46:2: ObjCClassRef=Baz:32:12 Extent=[46:2 - 46:5] +// CHECK: c-index-api-loadTU-test.m:46:8: UnexposedStmt= Extent=[47:2 - 47:19] +// CHECK: c-index-api-loadTU-test.m:47:5: VarDecl=a:47:5 (Definition) Extent=[47:2 - 47:18] +// CHECK: c-index-api-loadTU-test.m:47:2: TypeRef=id:0:0 Extent=[47:2 - 47:4] +// CHECK: c-index-api-loadTU-test.m:47:9: ObjCMessageExpr=foo:8:1 Extent=[47:9 - 47:18] +// CHECK: c-index-api-loadTU-test.m:47:10: DeclRefExpr=bee:46:8 Extent=[47:10 - 47:13] +// CHECK: c-index-api-loadTU-test.m:47:5: UnexposedStmt= Extent=[48:2 - 48:27] +// CHECK: c-index-api-loadTU-test.m:48:12: VarDecl=c:48:12 (Definition) Extent=[48:2 - 48:26] +// CHECK: c-index-api-loadTU-test.m:48:2: TypeRef=id:0:0 Extent=[48:2 - 48:4] +// CHECK: c-index-api-loadTU-test.m:48:6: ObjCProtocolRef=SubP:28:1 Extent=[48:6 - 48:10] +// CHECK: c-index-api-loadTU-test.m:48:16: UnexposedExpr=fooC:9:1 Extent=[48:16 - 48:26] +// CHECK: c-index-api-loadTU-test.m:48:16: ObjCMessageExpr=fooC:9:1 Extent=[48:16 - 48:26] +// CHECK: c-index-api-loadTU-test.m:48:12: UnexposedStmt= Extent=[49:2 - 49:15] +// CHECK: c-index-api-loadTU-test.m:49:13: VarDecl=d:49:13 (Definition) Extent=[49:2 - 49:14] +// CHECK: c-index-api-loadTU-test.m:49:2: TypeRef=id:0:0 Extent=[49:2 - 49:4] +// CHECK: c-index-api-loadTU-test.m:49:6: ObjCProtocolRef=Proto:24:1 Extent=[49:6 - 49:11] +// CHECK: c-index-api-loadTU-test.m:50:2: UnexposedExpr= Extent=[50:2 - 50:7] +// CHECK: c-index-api-loadTU-test.m:50:2: DeclRefExpr=d:49:13 Extent=[50:2 - 50:3] +// CHECK: c-index-api-loadTU-test.m:50:6: UnexposedExpr=c:48:12 Extent=[50:6 - 50:7] +// CHECK: c-index-api-loadTU-test.m:50:6: DeclRefExpr=c:48:12 Extent=[50:6 - 50:7] +// CHECK: c-index-api-loadTU-test.m:51:2: ObjCMessageExpr=pMethod:25:1 Extent=[51:2 - 51:13] +// CHECK: c-index-api-loadTU-test.m:51:3: DeclRefExpr=d:49:13 Extent=[51:3 - 51:4] +// CHECK: c-index-api-loadTU-test.m:52:2: ObjCMessageExpr=catMethodWithFloat::20:1 Extent=[52:2 - 52:44] +// CHECK: c-index-api-loadTU-test.m:52:3: DeclRefExpr=bee:46:8 Extent=[52:3 - 52:6] +// CHECK: c-index-api-loadTU-test.m:52:26: ObjCMessageExpr=floatMethod:21:1 Extent=[52:26 - 52:43] +// CHECK: c-index-api-loadTU-test.m:52:27: DeclRefExpr=bee:46:8 Extent=[52:27 - 52:30] +// CHECK: c-index-api-loadTU-test.m:53:3: CallExpr=main:45:5 Extent=[53:3 - 53:37] +// CHECK: c-index-api-loadTU-test.m:53:3: UnexposedExpr=main:45:5 Extent=[53:3 - 53:7] +// CHECK: c-index-api-loadTU-test.m:53:3: DeclRefExpr=main:45:5 Extent=[53:3 - 53:7] +// CHECK: c-index-api-loadTU-test.m:53:8: DeclRefExpr=someEnum:42:3 Extent=[53:8 - 53:16] +// CHECK: c-index-api-loadTU-test.m:53:18: UnexposedExpr=bee:46:8 Extent=[53:18 - 53:36] +// CHECK: c-index-api-loadTU-test.m:53:33: DeclRefExpr=bee:46:8 Extent=[53:33 - 53:36] diff --git a/test/Index/c-index-getCursor-test.m b/test/Index/c-index-getCursor-test.m index 8fb7ffc..6a17e1c 100644 --- a/test/Index/c-index-getCursor-test.m +++ b/test/Index/c-index-getCursor-test.m @@ -52,102 +52,102 @@ int main (int argc, const char * argv[]) { main(someEnum, (const char **)bee); } -// CHECK: {start_line=1 start_col=1 end_line=2 end_col=62} Invalid Cursor => NoDeclFound -// CHECK: {start_line=3 start_col=1 end_line=6 end_col=1} ObjCInterfaceDecl=Foo:3:12 -// CHECK: {start_line=7 start_col=1 end_line=7 end_col=6} ObjCInstanceMethodDecl=foo:7:1 -// CHECK: {start_line=7 start_col=7 end_line=7 end_col=7} ObjCInterfaceDecl=Foo:3:12 -// CHECK: {start_line=8 start_col=1 end_line=8 end_col=7} ObjCClassMethodDecl=fooC:8:1 -// CHECK: {start_line=8 start_col=8 end_line=10 end_col=4} ObjCInterfaceDecl=Foo:3:12 -// CHECK: {start_line=10 start_col=5 end_line=11 end_col=1} Invalid Cursor => NoDeclFound -// CHECK: {start_line=12 start_col=1 end_line=12 end_col=17} ObjCInterfaceDecl=Bar:12:12 -// CHECK: {start_line=12 start_col=18 end_line=12 end_col=20} ObjCSuperClassRef=Foo:3:12 -// CHECK: {start_line=12 start_col=21 end_line=16 end_col=4} ObjCInterfaceDecl=Bar:12:12 -// CHECK: {start_line=16 start_col=5 end_line=17 end_col=1} Invalid Cursor => NoDeclFound -// CHECK: {start_line=18 start_col=1 end_line=18 end_col=11} ObjCCategoryDecl=FooCat:18:12 -// CHECK: {start_line=18 start_col=12 end_line=18 end_col=14} ObjCClassRef=Foo:3:12 -// CHECK: {start_line=18 start_col=15 end_line=18 end_col=24} ObjCCategoryDecl=FooCat:18:12 -// CHECK: {start_line=19 start_col=1 end_line=19 end_col=28} ObjCInstanceMethodDecl=catMethodWithFloat::19:1 -// CHECK: {start_line=19 start_col=29 end_line=19 end_col=39} ParmDecl=fArg:19:36 (Definition) -// CHECK: {start_line=19 start_col=40 end_line=19 end_col=40} ObjCInstanceMethodDecl=catMethodWithFloat::19:1 -// CHECK: {start_line=19 start_col=41 end_line=19 end_col=41} ObjCCategoryDecl=FooCat:18:12 -// CHECK: {start_line=20 start_col=1 end_line=20 end_col=22} ObjCInstanceMethodDecl=floatMethod:20:1 -// CHECK: {start_line=20 start_col=23 end_line=21 end_col=4} ObjCCategoryDecl=FooCat:18:12 -// CHECK: {start_line=21 start_col=5 end_line=22 end_col=1} Invalid Cursor => NoDeclFound -// CHECK: {start_line=23 start_col=1 end_line=23 end_col=16} ObjCProtocolDecl=Proto:23:1 (Definition) -// CHECK: {start_line=24 start_col=1 end_line=24 end_col=10} ObjCInstanceMethodDecl=pMethod:24:1 -// CHECK: {start_line=24 start_col=11 end_line=25 end_col=4} ObjCProtocolDecl=Proto:23:1 (Definition) -// CHECK: {start_line=25 start_col=5 end_line=26 end_col=1} Invalid Cursor => NoDeclFound -// CHECK: {start_line=27 start_col=1 end_line=27 end_col=16} ObjCProtocolDecl=SubP:27:1 (Definition) -// CHECK: {start_line=27 start_col=17 end_line=27 end_col=21} ObjCProtocolRef=Proto:23:1 -// CHECK: {start_line=27 start_col=22 end_line=27 end_col=23} ObjCProtocolDecl=SubP:27:1 (Definition) -// CHECK: {start_line=28 start_col=1 end_line=28 end_col=11} ObjCInstanceMethodDecl=spMethod:28:1 -// CHECK: {start_line=28 start_col=12 end_line=29 end_col=4} ObjCProtocolDecl=SubP:27:1 (Definition) -// CHECK: {start_line=29 start_col=5 end_line=30 end_col=1} Invalid Cursor => NoDeclFound -// CHECK: {start_line=31 start_col=1 end_line=31 end_col=17} ObjCInterfaceDecl=Baz:31:12 -// CHECK: {start_line=31 start_col=18 end_line=31 end_col=20} ObjCSuperClassRef=Bar:12:12 -// CHECK: {start_line=31 start_col=21 end_line=31 end_col=22} ObjCInterfaceDecl=Baz:31:12 -// CHECK: {start_line=31 start_col=23 end_line=31 end_col=26} ObjCProtocolRef=SubP:27:1 -// CHECK: {start_line=31 start_col=27 end_line=33 end_col=8} ObjCInterfaceDecl=Baz:31:12 -// CHECK: {start_line=33 start_col=9 end_line=33 end_col=15} ObjCIvarDecl=_anIVar:33:9 (Definition) -// CHECK: {start_line=33 start_col=16 end_line=35 end_col=1} ObjCInterfaceDecl=Baz:31:12 -// CHECK: {start_line=36 start_col=1 end_line=36 end_col=20} ObjCInstanceMethodDecl=bazMethod:36:1 -// CHECK: {start_line=36 start_col=21 end_line=38 end_col=4} ObjCInterfaceDecl=Baz:31:12 -// CHECK: {start_line=38 start_col=5 end_line=39 end_col=1} Invalid Cursor => NoDeclFound -// CHECK: {start_line=40 start_col=1 end_line=41 end_col=2} EnumDecl=:40:1 (Definition) -// CHECK: {start_line=41 start_col=3 end_line=41 end_col=10} EnumConstantDecl=someEnum:41:3 (Definition) -// CHECK: {start_line=41 start_col=11 end_line=42 end_col=1} EnumDecl=:40:1 (Definition) -// CHECK: {start_line=42 start_col=2 end_line=44 end_col=4} Invalid Cursor => NoDeclFound -// CHECK: {start_line=44 start_col=5 end_line=44 end_col=10} FunctionDecl=main:44:5 (Definition) -// CHECK: {start_line=44 start_col=11 end_line=44 end_col=18} ParmDecl=argc:44:15 (Definition) -// CHECK: {start_line=44 start_col=19 end_line=44 end_col=26} FunctionDecl=main:44:5 (Definition) -// CHECK: {start_line=44 start_col=27 end_line=44 end_col=37} ParmDecl=argv:44:34 (Definition) -// CHECK: {start_line=44 start_col=38 end_line=44 end_col=41} FunctionDecl=main:44:5 (Definition) -// CHECK: {start_line=44 start_col=42 end_line=45 end_col=1} UnexposedStmt=main -// CHECK: {start_line=45 start_col=2 end_line=45 end_col=4} ObjCClassRef=Baz:31:12 -// CHECK: {start_line=45 start_col=5 end_line=45 end_col=10} VarDecl=bee:45:8 (Definition) -// CHECK: {start_line=45 start_col=11 end_line=45 end_col=11} UnexposedStmt=main -// CHECK: {start_line=45 start_col=12 end_line=46 end_col=1} UnexposedStmt=main -// CHECK: {start_line=46 start_col=2 end_line=46 end_col=3} TypeRef=id:0:0 -// CHECK: {start_line=46 start_col=4 end_line=46 end_col=8} VarDecl=a:46:5 (Definition) -// CHECK: {start_line=46 start_col=9 end_line=46 end_col=9} ObjCMessageExpr=foo:7:1 -// CHECK: {start_line=46 start_col=10 end_line=46 end_col=12} DeclRefExpr=bee:45:8 -// CHECK: {start_line=46 start_col=13 end_line=46 end_col=17} ObjCMessageExpr=foo:7:1 -// CHECK: {start_line=46 start_col=18 end_line=46 end_col=18} UnexposedStmt=main -// CHECK: {start_line=46 start_col=19 end_line=47 end_col=1} UnexposedStmt=main -// CHECK: {start_line=47 start_col=2 end_line=47 end_col=3} TypeRef=id:0:0 -// CHECK: {start_line=47 start_col=4 end_line=47 end_col=5} VarDecl=c:47:12 (Definition) -// CHECK: {start_line=47 start_col=6 end_line=47 end_col=9} ObjCProtocolRef=SubP:27:1 -// CHECK: {start_line=47 start_col=10 end_line=47 end_col=15} VarDecl=c:47:12 (Definition) -// CHECK: {start_line=47 start_col=16 end_line=47 end_col=25} ObjCMessageExpr=fooC:8:1 -// CHECK: {start_line=47 start_col=26 end_line=47 end_col=26} UnexposedStmt=main -// CHECK: {start_line=47 start_col=27 end_line=48 end_col=1} UnexposedStmt=main -// CHECK: {start_line=48 start_col=2 end_line=48 end_col=3} TypeRef=id:0:0 -// CHECK: {start_line=48 start_col=4 end_line=48 end_col=5} VarDecl=d:48:13 (Definition) -// CHECK: {start_line=48 start_col=6 end_line=48 end_col=10} ObjCProtocolRef=Proto:23:1 -// CHECK: {start_line=48 start_col=11 end_line=48 end_col=13} VarDecl=d:48:13 (Definition) -// CHECK: {start_line=48 start_col=14 end_line=48 end_col=14} UnexposedStmt=main -// CHECK: {start_line=48 start_col=15 end_line=49 end_col=1} UnexposedStmt=main -// CHECK: {start_line=49 start_col=2 end_line=49 end_col=2} DeclRefExpr=d:48:13 -// CHECK: {start_line=49 start_col=3 end_line=49 end_col=5} UnexposedExpr= -// CHECK: {start_line=49 start_col=6 end_line=49 end_col=6} DeclRefExpr=c:47:12 -// CHECK: {start_line=49 start_col=7 end_line=50 end_col=1} UnexposedStmt=main -// CHECK: {start_line=50 start_col=2 end_line=50 end_col=2} ObjCMessageExpr=pMethod:24:1 -// CHECK: {start_line=50 start_col=3 end_line=50 end_col=3} DeclRefExpr=d:48:13 -// CHECK: {start_line=50 start_col=4 end_line=50 end_col=12} ObjCMessageExpr=pMethod:24:1 -// CHECK: {start_line=50 start_col=13 end_line=51 end_col=1} UnexposedStmt=main -// CHECK: {start_line=51 start_col=2 end_line=51 end_col=2} ObjCMessageExpr=catMethodWithFloat::19:1 -// CHECK: {start_line=51 start_col=3 end_line=51 end_col=5} DeclRefExpr=bee:45:8 -// CHECK: {start_line=51 start_col=6 end_line=51 end_col=25} ObjCMessageExpr=catMethodWithFloat::19:1 -// CHECK: {start_line=51 start_col=26 end_line=51 end_col=26} ObjCMessageExpr=floatMethod:20:1 -// CHECK: {start_line=51 start_col=27 end_line=51 end_col=29} DeclRefExpr=bee:45:8 -// CHECK: {start_line=51 start_col=30 end_line=51 end_col=42} ObjCMessageExpr=floatMethod:20:1 -// CHECK: {start_line=51 start_col=43 end_line=51 end_col=43} ObjCMessageExpr=catMethodWithFloat::19:1 -// CHECK: {start_line=51 start_col=44 end_line=52 end_col=2} UnexposedStmt=main -// CHECK: {start_line=52 start_col=3 end_line=52 end_col=6} DeclRefExpr=main:44:5 -// CHECK: {start_line=52 start_col=7 end_line=52 end_col=7} CallExpr=main:44:5 -// CHECK: {start_line=52 start_col=8 end_line=52 end_col=15} DeclRefExpr=someEnum:41:3 -// CHECK: {start_line=52 start_col=16 end_line=52 end_col=17} CallExpr=main:44:5 -// CHECK: {start_line=52 start_col=18 end_line=52 end_col=32} UnexposedExpr=bee:45:8 -// CHECK: {start_line=52 start_col=33 end_line=52 end_col=35} DeclRefExpr=bee:45:8 -// CHECK: {start_line=52 start_col=36 end_line=52 end_col=36} CallExpr=main:44:5 -// CHECK: {start_line=52 start_col=37 end_line=53 end_col=1} UnexposedStmt=main +// 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 +// CHECK: [7:7 - 8:1] ObjCInterfaceDecl=Foo:3:12 +// CHECK: [8:1 - 8:8] ObjCClassMethodDecl=fooC:8:1 +// CHECK: [8:8 - 10:5] ObjCInterfaceDecl=Foo:3:12 +// CHECK: [10:5 - 12:1] Invalid Cursor => NoDeclFound +// CHECK: [12:1 - 12:18] ObjCInterfaceDecl=Bar:12:12 +// CHECK: [12:18 - 12:21] ObjCSuperClassRef=Foo:3:12 +// CHECK: [12:21 - 16:5] ObjCInterfaceDecl=Bar:12:12 +// CHECK: [16:5 - 18:1] Invalid Cursor => NoDeclFound +// CHECK: [18:1 - 18:12] ObjCCategoryDecl=FooCat:18:12 +// CHECK: [18:12 - 18:15] ObjCClassRef=Foo:3:12 +// CHECK: [18:15 - 19:1] ObjCCategoryDecl=FooCat:18:12 +// CHECK: [19:1 - 19:29] ObjCInstanceMethodDecl=catMethodWithFloat::19:1 +// CHECK: [19:29 - 19:40] ParmDecl=fArg:19:36 (Definition) +// CHECK: [19:40 - 19:41] ObjCInstanceMethodDecl=catMethodWithFloat::19:1 +// CHECK: [19:41 - 20:1] ObjCCategoryDecl=FooCat:18:12 +// CHECK: [20:1 - 20:23] ObjCInstanceMethodDecl=floatMethod:20:1 +// CHECK: [20:23 - 21:5] ObjCCategoryDecl=FooCat:18:12 +// CHECK: [21:5 - 23:1] Invalid Cursor => NoDeclFound +// CHECK: [23:1 - 24:1] ObjCProtocolDecl=Proto:23:1 (Definition) +// CHECK: [24:1 - 24:11] ObjCInstanceMethodDecl=pMethod:24:1 +// CHECK: [24:11 - 25:5] ObjCProtocolDecl=Proto:23:1 (Definition) +// CHECK: [25:5 - 27:1] Invalid Cursor => NoDeclFound +// CHECK: [27:1 - 27:17] ObjCProtocolDecl=SubP:27:1 (Definition) +// CHECK: [27:17 - 27:22] ObjCProtocolRef=Proto:23:1 +// CHECK: [27:22 - 28:1] ObjCProtocolDecl=SubP:27:1 (Definition) +// CHECK: [28:1 - 28:12] ObjCInstanceMethodDecl=spMethod:28:1 +// CHECK: [28:12 - 29:5] ObjCProtocolDecl=SubP:27:1 (Definition) +// CHECK: [29:5 - 31:1] Invalid Cursor => NoDeclFound +// CHECK: [31:1 - 31:18] ObjCInterfaceDecl=Baz:31:12 +// CHECK: [31:18 - 31:21] ObjCSuperClassRef=Bar:12:12 +// CHECK: [31:21 - 31:23] ObjCInterfaceDecl=Baz:31:12 +// CHECK: [31:23 - 31:27] ObjCProtocolRef=SubP:27:1 +// CHECK: [31:27 - 33:9] ObjCInterfaceDecl=Baz:31:12 +// CHECK: [33:9 - 33:16] ObjCIvarDecl=_anIVar:33:9 (Definition) +// CHECK: [33:16 - 36:1] ObjCInterfaceDecl=Baz:31:12 +// CHECK: [36:1 - 36:21] ObjCInstanceMethodDecl=bazMethod:36:1 +// CHECK: [36:21 - 38:5] ObjCInterfaceDecl=Baz:31:12 +// CHECK: [38:5 - 40:1] Invalid Cursor => NoDeclFound +// CHECK: [40:1 - 41:3] EnumDecl=:40:1 (Definition) +// CHECK: [41:3 - 41:11] EnumConstantDecl=someEnum:41:3 (Definition) +// CHECK: [41:11 - 42:2] EnumDecl=:40:1 (Definition) +// CHECK: [42:2 - 44:5] Invalid Cursor => NoDeclFound +// CHECK: [44:5 - 44:11] FunctionDecl=main:44:5 (Definition) +// CHECK: [44:11 - 44:19] ParmDecl=argc:44:15 (Definition) +// CHECK: [44:19 - 44:27] FunctionDecl=main:44:5 (Definition) +// CHECK: [44:27 - 44:38] ParmDecl=argv:44:34 (Definition) +// CHECK: [44:38 - 44:42] FunctionDecl=main:44:5 (Definition) +// CHECK: [44:42 - 45:2] UnexposedStmt= +// CHECK: [45:2 - 45:5] ObjCClassRef=Baz:31:12 +// CHECK: [45:5 - 45:11] VarDecl=bee:45:8 (Definition) +// CHECK: [45:11 - 45:12] UnexposedStmt= +// CHECK: [45:12 - 46:2] UnexposedStmt= +// CHECK: [46:2 - 46:4] TypeRef=id:0:0 +// CHECK: [46:4 - 46:9] VarDecl=a:46:5 (Definition) +// CHECK: [46:9 - 46:10] ObjCMessageExpr=foo:7:1 +// CHECK: [46:10 - 46:13] DeclRefExpr=bee:45:8 +// CHECK: [46:13 - 46:18] ObjCMessageExpr=foo:7:1 +// CHECK: [46:18 - 46:19] UnexposedStmt= +// CHECK: [46:19 - 47:2] UnexposedStmt= +// CHECK: [47:2 - 47:4] TypeRef=id:0:0 +// CHECK: [47:4 - 47:6] VarDecl=c:47:12 (Definition) +// CHECK: [47:6 - 47:10] ObjCProtocolRef=SubP:27:1 +// CHECK: [47:10 - 47:16] VarDecl=c:47:12 (Definition) +// CHECK: [47:16 - 47:26] ObjCMessageExpr=fooC:8:1 +// CHECK: [47:26 - 47:27] UnexposedStmt= +// CHECK: [47:27 - 48:2] UnexposedStmt= +// CHECK: [48:2 - 48:4] TypeRef=id:0:0 +// CHECK: [48:4 - 48:6] VarDecl=d:48:13 (Definition) +// CHECK: [48:6 - 48:11] ObjCProtocolRef=Proto:23:1 +// CHECK: [48:11 - 48:14] VarDecl=d:48:13 (Definition) +// CHECK: [48:14 - 48:15] UnexposedStmt= +// CHECK: [48:15 - 49:2] UnexposedStmt= +// CHECK: [49:2 - 49:3] DeclRefExpr=d:48:13 +// CHECK: [49:3 - 49:6] UnexposedExpr= +// CHECK: [49:6 - 49:7] DeclRefExpr=c:47:12 +// CHECK: [49:7 - 50:2] UnexposedStmt= +// CHECK: [50:2 - 50:3] ObjCMessageExpr=pMethod:24:1 +// CHECK: [50:3 - 50:4] DeclRefExpr=d:48:13 +// CHECK: [50:4 - 50:13] ObjCMessageExpr=pMethod:24:1 +// CHECK: [50:13 - 51:2] UnexposedStmt= +// CHECK: [51:2 - 51:3] ObjCMessageExpr=catMethodWithFloat::19:1 +// CHECK: [51:3 - 51:6] DeclRefExpr=bee:45:8 +// CHECK: [51:6 - 51:26] ObjCMessageExpr=catMethodWithFloat::19:1 +// CHECK: [51:26 - 51:27] ObjCMessageExpr=floatMethod:20:1 +// CHECK: [51:27 - 51:30] DeclRefExpr=bee:45:8 +// CHECK: [51:30 - 51:43] ObjCMessageExpr=floatMethod:20:1 +// CHECK: [51:43 - 51:44] ObjCMessageExpr=catMethodWithFloat::19:1 +// CHECK: [51:44 - 52:3] UnexposedStmt= +// CHECK: [52:3 - 52:7] DeclRefExpr=main:44:5 +// CHECK: [52:7 - 52:8] CallExpr=main:44:5 +// CHECK: [52:8 - 52:16] DeclRefExpr=someEnum:41:3 +// CHECK: [52:16 - 52:18] CallExpr=main:44:5 +// CHECK: [52:18 - 52:33] UnexposedExpr=bee:45:8 +// CHECK: [52:33 - 52:36] DeclRefExpr=bee:45:8 +// CHECK: [52:36 - 52:37] CallExpr=main:44:5 +// CHECK: [52:37 - 53:2] UnexposedStmt= diff --git a/test/Index/cindex-from-source.m b/test/Index/cindex-from-source.m index 8f79304..6c5d936 100644 --- a/test/Index/cindex-from-source.m +++ b/test/Index/cindex-from-source.m @@ -4,6 +4,6 @@ // RUN: FileCheck %s < %t // CHECK: cindex-from-source.m:{{.*}}:{{.*}}: StructDecl=s0:{{.*}}:{{.*}} // CHECK: cindex-from-source.m:{{.*}}:{{.*}}: VarDecl=g0:{{.*}}:{{.*}} -// CHECK: cindex-from-source.m:9:1: TypeRef=t0:1:13 [Extent=9:1:9:2] +// CHECK: cindex-from-source.m:9:1: TypeRef=t0:1:13 Extent=[9:1 - 9:3] struct s0 {}; t0 g0; diff --git a/test/Index/cindex-test-inclusions.c b/test/Index/cindex-test-inclusions.c new file mode 100644 index 0000000..9c7de2e --- /dev/null +++ b/test/Index/cindex-test-inclusions.c @@ -0,0 +1,13 @@ +// RUN: c-index-test -test-inclusion-stack-source %s 2>&1 | FileCheck %s + +#include "include_test.h" + +// CHECK: cindex-test-inclusions.c +// CHECK: included by: +// CHECK: include_test.h +// CHECK: included by: +// CHECK: cindex-test-inclusions.c:3:10 +// CHECK: include_test_2.h +// CHECK: included by: +// CHECK: include_test.h:1:10 +// CHECK: cindex-test-inclusions.c:3:10 diff --git a/test/Index/code-complete-errors.c b/test/Index/code-complete-errors.c new file mode 100644 index 0000000..520a8c8 --- /dev/null +++ b/test/Index/code-complete-errors.c @@ -0,0 +1,16 @@ +_Complex cd; // CHECK: code-complete-errors.c:1:1: warning: plain '_Complex' requires a type specifier; assuming '_Complex double' +// CHECK: FIX-IT: Insert " double" at 1:9 +struct s { + int x, y;; // CHECK: code-complete-errors.c:4:12: warning: extra ';' inside a struct or union +}; // CHECK: FIX-IT: Remove [4:12 - 4:13] + +struct s s0 = { y: 5 }; // CHECK: code-complete-errors.c:7:20: warning: use of GNU old-style field designator extension +// CHECK: FIX-IT: Replace [7:17 - 7:19] with ".y = " +int f(int *ptr1, float *ptr2) { + return ptr1 != ptr2; // CHECK: code-complete-errors.c:10:15:[10:10 - 10:14][10:18 - 10:22]: warning: comparison of distinct pointer types ('int *' and 'float *') +} + +void g() { } + +// RUN: c-index-test -code-completion-at=%s:13:12 -pedantic %s 2> %t +// RUN: FileCheck -check-prefix=CHECK %s < %t diff --git a/test/Index/include_test.h b/test/Index/include_test.h new file mode 100644 index 0000000..3c40c8d --- /dev/null +++ b/test/Index/include_test.h @@ -0,0 +1 @@ +#include "include_test_2.h" diff --git a/test/Index/include_test_2.h b/test/Index/include_test_2.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/Index/include_test_2.h diff --git a/test/Index/load-exprs.c b/test/Index/load-exprs.c index a360efd..f72f104 100644 --- a/test/Index/load-exprs.c +++ b/test/Index/load-exprs.c @@ -4,10 +4,15 @@ void f(void *ptr) { T* t_ptr = (T *)ptr; (void)sizeof(T); struct X x = (struct X){1, 2}; + void *xx = ptr ? : &x; } // RUN: c-index-test -test-load-source all %s | FileCheck %s -// CHECK: load-exprs.c:4:15: TypeRef=T:1:13 [Extent=4:15:4:15] -// CHECK: load-exprs.c:5:16: TypeRef=T:1:13 [Extent=5:16:5:16] -// FIXME: the source location for "struct X" points at "struct", not "X" +// CHECK: load-exprs.c:4:15: TypeRef=T:1:13 Extent=[4:15 - 4:16] +// CHECK: load-exprs.c:5:16: TypeRef=T:1:13 Extent=[5:16 - 5:17] +// CHECK: load-exprs.c:6:10: TypeRef=struct X:2:8 Extent=[6:10 - 6:11] +// CHECK: load-exprs.c:6:24: TypeRef=struct X:2:8 Extent=[6:24 - 6:25] +// CHECK: load-exprs.c:7:9: VarDecl=xx:7:9 (Definition) Extent=[7:3 - 7:24] +// CHECK: load-exprs.c:7:14: DeclRefExpr=ptr:3:14 Extent=[7:14 - 7:17] +// CHECK: load-exprs.c:7:23: DeclRefExpr=x:6:12 Extent=[7:23 - 7:24] diff --git a/test/Index/load-stmts.cpp b/test/Index/load-stmts.cpp new file mode 100644 index 0000000..fdfedfb --- /dev/null +++ b/test/Index/load-stmts.cpp @@ -0,0 +1,51 @@ +typedef int T; +struct X { int a, b; }; +void f(int x) { + for (T y = x; T z = x; ++x) { + } + if (T *z2 = &x) { } + while (T *z3 = &x) { } + switch (T z4 = x) { + case 17: break; + } +} + +// RUN: c-index-test -test-load-source all %s | FileCheck %s +// CHECK: load-stmts.cpp:3:6: UnexposedStmt= Extent=[4:3 - 5:4] +// CHECK: load-stmts.cpp:3:6: UnexposedStmt= Extent=[4:8 - 4:16] +// CHECK: load-stmts.cpp:4:10: VarDecl=y:4:10 (Definition) Extent=[4:8 - 4:15] +// CHECK: load-stmts.cpp:4:8: TypeRef=T:1:13 Extent=[4:8 - 4:9] +// CHECK: load-stmts.cpp:4:14: DeclRefExpr=x:3:12 Extent=[4:14 - 4:15] +// CHECK: load-stmts.cpp:4:19: VarDecl=z:4:19 (Definition) Extent=[4:17 - 4:24] +// CHECK: load-stmts.cpp:4:17: TypeRef=T:1:13 Extent=[4:17 - 4:18] +// CHECK: load-stmts.cpp:4:23: DeclRefExpr=x:3:12 Extent=[4:23 - 4:24] +// CHECK: load-stmts.cpp:4:19: UnexposedExpr=z:4:19 Extent=[4:19 - 4:20] +// CHECK: load-stmts.cpp:4:19: DeclRefExpr=z:4:19 Extent=[4:19 - 4:20] +// CHECK: load-stmts.cpp:4:26: UnexposedExpr= Extent=[4:26 - 4:29] +// CHECK: load-stmts.cpp:4:28: DeclRefExpr=x:3:12 Extent=[4:28 - 4:29] +// CHECK: load-stmts.cpp:4:19: UnexposedStmt= Extent=[4:31 - 5:4] +// CHECK: load-stmts.cpp:4:19: UnexposedStmt= Extent=[6:3 - 6:22] +// CHECK: load-stmts.cpp:6:10: VarDecl=z2:6:10 (Definition) Extent=[6:7 - 6:17] +// CHECK: load-stmts.cpp:6:7: TypeRef=T:1:13 Extent=[6:7 - 6:8] +// CHECK: load-stmts.cpp:6:15: UnexposedExpr= Extent=[6:15 - 6:17] +// CHECK: load-stmts.cpp:6:16: DeclRefExpr=x:3:12 Extent=[6:16 - 6:17] +// CHECK: load-stmts.cpp:6:10: UnexposedExpr=z2:6:10 Extent=[6:10 - 6:12] +// CHECK: load-stmts.cpp:6:10: DeclRefExpr=z2:6:10 Extent=[6:10 - 6:12] +// CHECK: load-stmts.cpp:6:10: UnexposedStmt= Extent=[6:19 - 6:22] +// CHECK: load-stmts.cpp:6:10: UnexposedStmt= Extent=[7:3 - 7:25] +// CHECK: load-stmts.cpp:7:13: VarDecl=z3:7:13 (Definition) Extent=[7:10 - 7:20] +// CHECK: load-stmts.cpp:7:10: TypeRef=T:1:13 Extent=[7:10 - 7:11] +// CHECK: load-stmts.cpp:7:18: UnexposedExpr= Extent=[7:18 - 7:20] +// CHECK: load-stmts.cpp:7:19: DeclRefExpr=x:3:12 Extent=[7:19 - 7:20] +// CHECK: load-stmts.cpp:7:13: UnexposedExpr=z3:7:13 Extent=[7:13 - 7:15] +// CHECK: load-stmts.cpp:7:13: DeclRefExpr=z3:7:13 Extent=[7:13 - 7:15] +// CHECK: load-stmts.cpp:7:13: UnexposedStmt= Extent=[7:22 - 7:25] +// CHECK: load-stmts.cpp:7:13: UnexposedStmt= Extent=[8:3 - 10:4] +// CHECK: load-stmts.cpp:8:13: VarDecl=z4:8:13 (Definition) Extent=[8:11 - 8:19] +// CHECK: load-stmts.cpp:8:11: TypeRef=T:1:13 Extent=[8:11 - 8:12] +// CHECK: load-stmts.cpp:8:18: DeclRefExpr=x:3:12 Extent=[8:18 - 8:19] +// CHECK: load-stmts.cpp:8:13: DeclRefExpr=z4:8:13 Extent=[8:13 - 8:15] +// CHECK: load-stmts.cpp:8:13: UnexposedStmt= Extent=[8:21 - 10:4] +// CHECK: load-stmts.cpp:8:13: UnexposedStmt= Extent=[9:3 - 9:17] +// CHECK: load-stmts.cpp:8:13: UnexposedStmt= Extent=[9:12 - 9:17] +// CHECK: load-stmts.cpp:9:8: UnexposedExpr= Extent=[9:8 - 9:10] diff --git a/test/Index/remap-cursor-at.c b/test/Index/remap-cursor-at.c index f7bcf79..fb97d5d 100644 --- a/test/Index/remap-cursor-at.c +++ b/test/Index/remap-cursor-at.c @@ -1,5 +1,5 @@ // RUN: c-index-test -cursor-at=%s:1:15 -cursor-at=%s:2:21 -remap-file="%s;%S/Inputs/remap-load-to.c" %s | FileCheck %s -// RUN: CINDEXTEST_USE_EXTERNAL_AST_GENERATION=1 c-index-test -cursor-at=%s:1:15 -cursor-at=%s:2:21 -remap-file="%s;%S/Inputs/remap-load-to.c" %s | FileCheck %s +// RUN: env CINDEXTEST_USE_EXTERNAL_AST_GENERATION=1 c-index-test -cursor-at=%s:1:15 -cursor-at=%s:2:21 -remap-file="%s;%S/Inputs/remap-load-to.c" %s | FileCheck %s // CHECK: ParmDecl=parm1:1:13 (Definition) // CHECK: DeclRefExpr=parm2:1:26 diff --git a/test/Index/remap-load.c b/test/Index/remap-load.c index 84e45bc..b8415e6 100644 --- a/test/Index/remap-load.c +++ b/test/Index/remap-load.c @@ -1,13 +1,14 @@ // RUN: c-index-test -test-load-source all -remap-file="%s;%S/Inputs/remap-load-to.c" %s | FileCheck -check-prefix=CHECK %s -// RUN: CINDEXTEST_USE_EXTERNAL_AST_GENERATION=1 c-index-test -test-load-source all -remap-file="%s;%S/Inputs/remap-load-to.c" %s | FileCheck -check-prefix=CHECK %s +// RUN: env CINDEXTEST_USE_EXTERNAL_AST_GENERATION=1 c-index-test -test-load-source all -remap-file="%s;%S/Inputs/remap-load-to.c" %s | FileCheck -check-prefix=CHECK %s +// XFAIL: win32 -// CHECK: remap-load.c:1:5: FunctionDecl=foo:1:5 (Definition) [Extent=1:5:3:1] -// CHECK: remap-load.c:1:13: ParmDecl=parm1:1:13 (Definition) [Extent=1:9:1:17] -// CHECK: remap-load.c:1:26: ParmDecl=parm2:1:26 (Definition) [Extent=1:20:1:30] -// CHECK: remap-load.c:1:5: UnexposedStmt=foo [Extent=1:33:3:1] -// CHECK: remap-load.c:1:5: UnexposedStmt=foo [Extent=2:3:2:22] -// CHECK: remap-load.c:2:10: UnexposedExpr= [Extent=2:10:2:22] -// CHECK: remap-load.c:2:10: UnexposedExpr= [Extent=2:10:2:22] -// CHECK: remap-load.c:2:10: UnexposedExpr=parm1:1:13 [Extent=2:10:2:14] -// CHECK: remap-load.c:2:10: DeclRefExpr=parm1:1:13 [Extent=2:10:2:14] -// CHECK: remap-load.c:2:18: DeclRefExpr=parm2:1:26 [Extent=2:18:2:22] +// CHECK: remap-load.c:1:5: FunctionDecl=foo:1:5 (Definition) Extent=[1:5 - 3:2] +// CHECK: remap-load.c:1:13: ParmDecl=parm1:1:13 (Definition) Extent=[1:9 - 1:18] +// CHECK: remap-load.c:1:26: ParmDecl=parm2:1:26 (Definition) Extent=[1:20 - 1:31] +// CHECK: remap-load.c:1:5: UnexposedStmt= Extent=[1:33 - 3:2] +// CHECK: remap-load.c:1:5: UnexposedStmt= Extent=[2:3 - 2:23] +// CHECK: remap-load.c:2:10: UnexposedExpr= Extent=[2:10 - 2:23] +// CHECK: remap-load.c:2:10: UnexposedExpr= Extent=[2:10 - 2:23] +// CHECK: remap-load.c:2:10: UnexposedExpr=parm1:1:13 Extent=[2:10 - 2:15] +// CHECK: remap-load.c:2:10: DeclRefExpr=parm1:1:13 Extent=[2:10 - 2:15] +// CHECK: remap-load.c:2:18: DeclRefExpr=parm2:1:26 Extent=[2:18 - 2:23] diff --git a/test/Misc/caret-diags-macros.c b/test/Misc/caret-diags-macros.c index 80371a9..e138f59 100644 --- a/test/Misc/caret-diags-macros.c +++ b/test/Misc/caret-diags-macros.c @@ -24,3 +24,12 @@ void bar() { C; } + +// rdar://7597492 +#define sprintf(str, A, B) \ +__builtin___sprintf_chk (str, 0, 42, A, B) + +void baz(char *Msg) { + sprintf(Msg, " sizeof FoooLib : =%3u\n", 12LL); +} + diff --git a/test/PCH/cxx_exprs.cpp b/test/PCH/cxx_exprs.cpp index 51269d5..0f0fe88 100644 --- a/test/PCH/cxx_exprs.cpp +++ b/test/PCH/cxx_exprs.cpp @@ -1,13 +1,14 @@ // Test this without pch. -// RUN: %clang_cc1 -include %S/cxx_exprs.h -fsyntax-only -verify %s +// RUN: %clang_cc1 -include %S/cxx_exprs.h -std=c++0x -fsyntax-only -verify %s // Test with pch. -// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx_exprs.h -// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// 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 int integer; double floating; char character; +bool boolean; // CXXStaticCastExpr static_cast_result void_ptr = &integer; @@ -24,3 +25,11 @@ const_cast_result char_ptr = &character; // CXXFunctionalCastExpr functional_cast_result *double_ptr = &floating; + +// CXXBoolLiteralExpr +bool_literal_result *bool_ptr = &boolean; +static_assert(true_value, "true_value is true"); +static_assert(!false_value, "false_value is false"); + +// CXXNullPtrLiteralExpr +cxx_null_ptr_result null_ptr = nullptr; diff --git a/test/PCH/cxx_exprs.h b/test/PCH/cxx_exprs.h index b649428..a871aa2 100644 --- a/test/PCH/cxx_exprs.h +++ b/test/PCH/cxx_exprs.h @@ -1,21 +1,29 @@ // Header for PCH test cxx_exprs.cpp // CXXStaticCastExpr -typedef typeof(static_cast<void *>(0)) static_cast_result; +typedef __typeof__(static_cast<void *>(0)) static_cast_result; // CXXDynamicCastExpr struct Base { virtual void f(); }; struct Derived : Base { }; Base *base_ptr; -typedef typeof(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result; +typedef __typeof__(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result; // CXXReinterpretCastExpr -typedef typeof(reinterpret_cast<void *>(0)) reinterpret_cast_result; +typedef __typeof__(reinterpret_cast<void *>(0)) reinterpret_cast_result; // CXXConstCastExpr const char *const_char_ptr_value; -typedef typeof(const_cast<char *>(const_char_ptr_value)) const_cast_result; +typedef __typeof__(const_cast<char *>(const_char_ptr_value)) const_cast_result; // CXXFunctionalCastExpr int int_value; -typedef typeof(double(int_value)) functional_cast_result; +typedef __typeof__(double(int_value)) functional_cast_result; + +// CXXBoolLiteralExpr +typedef __typeof__(true) bool_literal_result; +const bool true_value = true; +const bool false_value = false; + +// CXXNullPtrLiteralExpr +typedef __typeof__(nullptr) cxx_null_ptr_result; diff --git a/test/Parser/altivec.c b/test/Parser/altivec.c new file mode 100644 index 0000000..99544ea --- /dev/null +++ b/test/Parser/altivec.c @@ -0,0 +1,91 @@ +// RUN: %clang_cc1 -faltivec -fsyntax-only -verify %s + +__vector char vv_c; +__vector signed char vv_sc; +__vector unsigned char vv_uc; +__vector short vv_s; +__vector signed short vv_ss; +__vector unsigned short vv_us; +__vector short int vv_si; +__vector signed short int vv_ssi; +__vector unsigned short int vv_usi; +__vector int vv_i; +__vector signed int vv_sint; +__vector unsigned int vv_ui; +__vector float vv_f; +__vector bool vv_b; +__vector __pixel vv_p; +__vector pixel vv__p; +__vector int vf__r(); +void vf__a(__vector int a); +void vf__a2(int b, __vector int a); + +vector char v_c; +vector signed char v_sc; +vector unsigned char v_uc; +vector short v_s; +vector signed short v_ss; +vector unsigned short v_us; +vector short int v_si; +vector signed short int v_ssi; +vector unsigned short int v_usi; +vector int v_i; +vector signed int v_sint; +vector unsigned int v_ui; +vector float v_f; +vector bool v_b; +vector __pixel v_p; +vector pixel v__p; +vector int f__r(); +void f_a(vector int a); +void f_a2(int b, vector int a); + +// These should have warnings. +__vector long vv_l; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector signed long vv_sl; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector unsigned long vv_ul; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector long int vv_li; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector signed long int vv_sli; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector unsigned long int vv_uli; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector long v_l; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector signed long v_sl; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector unsigned long v_ul; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector long int v_li; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector signed long int v_sli; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector unsigned long int v_uli; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector long double vv_ld; // expected-warning {{Use of "long" with "__vector" is deprecated}} expected-error {{cannot use "double" with "__vector"}} +vector long double v_ld; // expected-warning {{Use of "long" with "__vector" is deprecated}} expected-error {{cannot use "double" with "__vector"}} + +// These should have errors. +__vector double vv_d; // expected-error {{cannot use "double" with "__vector"}} +__vector double vv_d; // expected-error {{cannot use "double" with "__vector"}} +vector double v_d; // expected-error {{cannot use "double" with "__vector"}} +vector double v_d; // expected-error {{cannot use "double" with "__vector"}} +__vector long double vv_ld; // expected-warning {{Use of "long" with "__vector" is deprecated}} expected-error {{cannot use "double" with "__vector"}} +vector long double v_ld; // expected-warning {{Use of "long" with "__vector" is deprecated}} expected-error {{cannot use "double" with "__vector"}} + +void f() { + __vector unsigned int v = {0,0,0,0}; + __vector int v__cast = (__vector int)v; + __vector int v_cast = (vector int)v; + __vector char vb_cast = (vector char)v; + + // Check some casting between gcc and altivec vectors. + #define gccvector __attribute__((vector_size(16))) + gccvector unsigned int gccv = {0,0,0,0}; + gccvector unsigned int gccv1 = gccv; + gccvector int gccv2 = (gccvector int)gccv; + gccvector unsigned int gccv3 = v; + __vector unsigned int av = gccv; + __vector int avi = (__vector int)gccv; + gccvector unsigned int gv = v; + gccvector int gvi = (gccvector int)v; + __attribute__((vector_size(8))) unsigned int gv8; + gv8 = gccv; // expected-error {{incompatible type assigning '__attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int', expected '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int'}} + av = gv8; // expected-error {{incompatible type assigning '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int', expected '__vector unsigned int'}} + + v = gccv; + __vector unsigned int tv = gccv; + gccv = v; + gccvector unsigned int tgv = v; +} diff --git a/test/Parser/cxx-altivec.cpp b/test/Parser/cxx-altivec.cpp new file mode 100644 index 0000000..a26eee4 --- /dev/null +++ b/test/Parser/cxx-altivec.cpp @@ -0,0 +1,108 @@ +// RUN: %clang_cc1 -faltivec -fsyntax-only -verify %s + +// This is the same as the C version: + +__vector char vv_c; +__vector signed char vv_sc; +__vector unsigned char vv_uc; +__vector short vv_s; +__vector signed short vv_ss; +__vector unsigned short vv_us; +__vector short int vv_si; +__vector signed short int vv_ssi; +__vector unsigned short int vv_usi; +__vector int vv_i; +__vector signed int vv_sint; +__vector unsigned int vv_ui; +__vector float vv_f; +__vector bool vv_b; +__vector __pixel vv_p; +__vector pixel vv__p; +__vector int vf__r(); +void vf__a(__vector int a); +void vf__a2(int b, __vector int a); + +vector char v_c; +vector signed char v_sc; +vector unsigned char v_uc; +vector short v_s; +vector signed short v_ss; +vector unsigned short v_us; +vector short int v_si; +vector signed short int v_ssi; +vector unsigned short int v_usi; +vector int v_i; +vector signed int v_sint; +vector unsigned int v_ui; +vector float v_f; +vector bool v_b; +vector __pixel v_p; +vector pixel v__p; +vector int f__r(); +void f_a(vector int a); +void f_a2(int b, vector int a); + +// These should have warnings. +__vector long vv_l; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector signed long vv_sl; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector unsigned long vv_ul; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector long int vv_li; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector signed long int vv_sli; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector unsigned long int vv_uli; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector long v_l; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector signed long v_sl; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector unsigned long v_ul; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector long int v_li; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector signed long int v_sli; // expected-warning {{Use of "long" with "__vector" is deprecated}} +vector unsigned long int v_uli; // expected-warning {{Use of "long" with "__vector" is deprecated}} +__vector long double vv_ld; // expected-warning {{Use of "long" with "__vector" is deprecated}} expected-error {{cannot use "double" with "__vector"}} +vector long double v_ld; // expected-warning {{Use of "long" with "__vector" is deprecated}} expected-error {{cannot use "double" with "__vector"}} + +// These should have errors. +__vector double vv_d1; // expected-error {{cannot use "double" with "__vector"}} +vector double v_d2; // expected-error {{cannot use "double" with "__vector"}} +__vector long double vv_ld3; // expected-warning {{Use of "long" with "__vector" is deprecated}} expected-error {{cannot use "double" with "__vector"}} +vector long double v_ld4; // expected-warning {{Use of "long" with "__vector" is deprecated}} expected-error {{cannot use "double" with "__vector"}} + +void f() { + __vector unsigned int v = {0,0,0,0}; + __vector int v__cast = (__vector int)v; + __vector int v_cast = (vector int)v; + __vector char vb_cast = (vector char)v; + + // Check some casting between gcc and altivec vectors. + #define gccvector __attribute__((vector_size(16))) + gccvector unsigned int gccv = {0,0,0,0}; + gccvector unsigned int gccv1 = gccv; + gccvector int gccv2 = (gccvector int)gccv; + gccvector unsigned int gccv3 = v; + __vector unsigned int av = gccv; + __vector int avi = (__vector int)gccv; + gccvector unsigned int gv = v; + gccvector int gvi = (gccvector int)v; + __attribute__((vector_size(8))) unsigned int gv8; + gv8 = gccv; // expected-error {{incompatible type assigning '__attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int', expected '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int'}} + av = gv8; // expected-error {{incompatible type assigning '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int', expected '__vector unsigned int'}} + + v = gccv; + __vector unsigned int tv = gccv; + gccv = v; + gccvector unsigned int tgv = v; +} + +// Now for the C++ version: + +class vc__v { + __vector int v; + __vector int f__r(); + void f__a(__vector int a); + void f__a2(int b, __vector int a); +}; + +class c_v { + vector int v; + vector int f__r(); + void f__a(vector int a); + void f__a2(int b, vector int a); +}; + diff --git a/test/Parser/cxx-decl.cpp b/test/Parser/cxx-decl.cpp index 3c88b7a..f37604c 100644 --- a/test/Parser/cxx-decl.cpp +++ b/test/Parser/cxx-decl.cpp @@ -52,3 +52,9 @@ void test(struct Type *P) { (y:b) // expected-error {{unexpected ':' in nested name specifier}} 4) : 5; } + +struct test4 { + int x // expected-error {{expected ';' at end of declaration list}} + int y; + int z // expected-error {{expected ';' at end of declaration list}} +}; diff --git a/test/Parser/cxx-template-decl.cpp b/test/Parser/cxx-template-decl.cpp index 5cb84a6..3f8f1ec 100644 --- a/test/Parser/cxx-template-decl.cpp +++ b/test/Parser/cxx-template-decl.cpp @@ -96,3 +96,13 @@ void f2() { // PR3844 template <> struct S<int> { }; // expected-error{{explicit specialization of non-template struct 'S'}} + +namespace PR6184 { + namespace N { + template <typename T> + void bar(typename T::x); + } + + template <typename T> + void N::bar(typename T::x) { } +} diff --git a/test/Parser/declarators.c b/test/Parser/declarators.c index 3831199..91803c1 100644 --- a/test/Parser/declarators.c +++ b/test/Parser/declarators.c @@ -47,8 +47,8 @@ int test6() { return a; } // a should be declared. // Use of tagged type without tag. rdar://6783347 struct xyz { int y; }; enum myenum { ASDFAS }; -xyz b; // expected-error {{use of tagged type 'xyz' without 'struct' tag}} -myenum c; // expected-error {{use of tagged type 'myenum' without 'enum' tag}} +xyz b; // expected-error {{must use 'struct' tag to refer to type 'xyz'}} +myenum c; // expected-error {{must use 'enum' tag to refer to type 'myenum'}} float *test7() { // We should recover 'b' by parsing it with a valid type of "struct xyz", which @@ -64,3 +64,22 @@ static f; // expected-warning {{type specifier missing, defaults to 'int'}} static g = 4; // expected-warning {{type specifier missing, defaults to 'int'}} static h // expected-warning {{type specifier missing, defaults to 'int'}} __asm__("foo"); + + +struct test9 { + int x // expected-error {{expected ';' at end of declaration list}} + int y; + int z // expected-warning {{expected ';' at end of declaration list}} +}; + +// PR6208 +struct test10 { int a; } static test10x; +struct test11 { int a; } const test11x; + +// PR6216 +void test12() { + (void)__builtin_offsetof(struct { char c; int i; }, i); +} + +// rdar://7608537 +struct test13 { int a; } (test13x); diff --git a/test/Parser/objc-property-syntax.m b/test/Parser/objc-property-syntax.m index b5f57f3..064a209 100644 --- a/test/Parser/objc-property-syntax.m +++ b/test/Parser/objc-property-syntax.m @@ -5,8 +5,10 @@ }; @property unsigned char bufferedUTF8Bytes[4]; // expected-error {{property cannot have array or function type}} @property unsigned char bufferedUTFBytes:1; // expected-error {{property name cannot be a bitfield}} +@property(nonatomic, retain, setter=ab_setDefaultToolbarItems) MyClass *ab_defaultToolbarItems; // expected-error {{method name referenced in property setter attribute must end with ':'}} @end @implementation MyClass +@dynamic ab_defaultToolbarItems; @end diff --git a/test/Parser/statements.c b/test/Parser/statements.c index 8fec0f1..a662c9b 100644 --- a/test/Parser/statements.c +++ b/test/Parser/statements.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code void test1() { { ; { ;;}} ;; diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c index a1485b6..cccee76 100644 --- a/test/Preprocessor/init.c +++ b/test/Preprocessor/init.c @@ -443,7 +443,6 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=pic16-none-none < /dev/null | FileCheck -check-prefix PIC16 %s // -// PIC16:#define _CONFIG(conf) asm("CONFIG "#conf) // PIC16:#define __CHAR_BIT__ 8 // PIC16:#define __DBL_DENORM_MIN__ 1.40129846e-45F // PIC16:#define __DBL_DIG__ 6 @@ -500,6 +499,7 @@ // PIC16:#define __LONG_LONG_MAX__ 2147483647LL // PIC16:#define __LONG_MAX__ 2147483647L // PIC16:#define __NO_INLINE__ 1 +// PIC16:#define __PIC16 1 // PIC16:#define __POINTER_WIDTH__ 16 // PIC16:#define __PTRDIFF_TYPE__ int // PIC16:#define __PTRDIFF_WIDTH__ 16 @@ -515,12 +515,15 @@ // PIC16:#define __WCHAR_WIDTH__ 16 // PIC16:#define __WINT_TYPE__ int // PIC16:#define __WINT_WIDTH__ 16 +// PIC16:#define __address(Addr) __attribute__((section("Address="#Addr))) // PIC16:#define __clang__ 1 +// PIC16:#define __config(conf) asm("CONFIG "#conf) +// PIC16:#define __idlocs(value) asm("__IDLOCS "#value) // PIC16:#define __llvm__ 1 // PIC16:#define __pic16 1 -// PIC16:#define _address(Addr) __attribute__((section("Address="#Addr))) -// PIC16:#define _interrupt __attribute__((section("interrupt=0x4"))) __attribute__((used)) -// PIC16:#define _section(SectName) __attribute__((section(SectName))) +// PIC16:#define __section(SectName) __attribute__((section(SectName))) +// PIC16:#define interrupt __attribute__((section("interrupt=0x4"))) __attribute__((used)) +// PIC16:#define near __attribute__((section("Address=NEAR"))) // PIC16:#define ram __attribute__((address_space(0))) // PIC16:#define rom __attribute__((address_space(1))) // diff --git a/test/Preprocessor/mi_opt2.c b/test/Preprocessor/mi_opt2.c new file mode 100644 index 0000000..198d19f --- /dev/null +++ b/test/Preprocessor/mi_opt2.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -E %s | FileCheck %s +// PR6282 +// This test should not trigger the include guard optimization since +// the guard macro is defined on the first include. + +#define ITERATING 1 +#define X 1 +#include "mi_opt2.h" +#undef X +#define X 2 +#include "mi_opt2.h" + +// CHECK: b: 1 +// CHECK: b: 2 + diff --git a/test/Preprocessor/mi_opt2.h b/test/Preprocessor/mi_opt2.h new file mode 100644 index 0000000..df37eba --- /dev/null +++ b/test/Preprocessor/mi_opt2.h @@ -0,0 +1,5 @@ +#ifndef ITERATING +a: X +#else +b: X +#endif diff --git a/test/Rewriter/blockcast3.mm b/test/Rewriter/blockcast3.mm new file mode 100644 index 0000000..97f417c --- /dev/null +++ b/test/Rewriter/blockcast3.mm @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7607781 + +typedef struct { + int a; + int b; +} mystruct; + +void g(int (^block)(mystruct s)) { + mystruct x; + int v = block(x); +} + +void f(const void **arg) { + __block const void **q = arg; + g(^(mystruct s){ + *q++ = (void*)s.a; + return 314; + }); +} + +// CHECK-LP: (struct __Block_byref_q_0 *)&q diff --git a/test/Rewriter/rewrite-block-pointer.mm b/test/Rewriter/rewrite-block-pointer.mm new file mode 100644 index 0000000..b03b7a9 --- /dev/null +++ b/test/Rewriter/rewrite-block-pointer.mm @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7638400 + +@interface X +@end + +void foo(void (^block)(int)); + +@implementation X +static void enumerateIt(void (^block)(id, id, char *)) { + foo(^(int idx) { }); +} +@end + +// CHECK-LP: static void enumerateIt(void (*)(id, id, char *)); diff --git a/test/Rewriter/rewrite-byref-vars.mm b/test/Rewriter/rewrite-byref-vars.mm index 1489c59..58b925a 100644 --- a/test/Rewriter/rewrite-byref-vars.mm +++ b/test/Rewriter/rewrite-byref-vars.mm @@ -36,9 +36,19 @@ __declspec(dllexport) extern "C" __declspec(dllexport) void XXXXBreakTheRewriter id list; } - (void) Meth; +// radar 7589385 use before definition +- (void) allObjects; @end @implementation I +// radar 7589385 use before definition +- (void) allObjects { + __attribute__((__blocks__(byref))) id *listp; + + ^(void) { + *listp++ = 0; + }; +} - (void) Meth { __attribute__((__blocks__(byref))) void ** listp = (void **)list; } @end diff --git a/test/Rewriter/rewrite-cast-ivar-access.mm b/test/Rewriter/rewrite-cast-ivar-access.mm new file mode 100644 index 0000000..c04cbab --- /dev/null +++ b/test/Rewriter/rewrite-cast-ivar-access.mm @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7575882 + +@interface F { + int supervar; +} +@end + +@interface G : F { +@public + int ivar; +} +@end + +@implementation G +- (void)foo:(F *)arg { + int q = arg->supervar; + int v = ((G *)arg)->ivar; +} +@end + +void objc_assign_strongCast(id); +void __CFAssignWithWriteBarrier(void **location, void *value) { + objc_assign_strongCast((id)value); +} + +// radar 7607605 +@interface RealClass { + @public + int f; +} +@end + +@implementation RealClass +@end + +@interface Foo { + id reserved; +} +@end + +@implementation Foo +- (void)bar { + ((RealClass*)reserved)->f = 99; +} +@end + +// CHECK-LP: ((struct G_IMPL *)arg)->ivar + +// CHECK-LP: objc_assign_strongCast((id)value) + +// CHECK-LP: ((struct RealClass_IMPL *)((RealClass *)((struct Foo_IMPL *)self)->reserved))->f diff --git a/test/Rewriter/rewrite-category-property.mm b/test/Rewriter/rewrite-category-property.mm new file mode 100644 index 0000000..6b8f076 --- /dev/null +++ b/test/Rewriter/rewrite-category-property.mm @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -x objective-c++ -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7630636 + +@class Y, Z; + +@interface A +@property (readonly) Y *y; +@end + +@interface A (cat) +@property (readonly) Z *z; +@end + +// CHECK-LP: // @property (readonly) Z *z; diff --git a/test/Rewriter/rewrite-implementation.mm b/test/Rewriter/rewrite-implementation.mm new file mode 100644 index 0000000..608707c --- /dev/null +++ b/test/Rewriter/rewrite-implementation.mm @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -DSEL="void *" -S %t-rw.cpp +// radar 7649577 + +@interface a +@end + +@interface b : a +@end + +@implementation b +@end + diff --git a/test/Rewriter/rewrite-message-expr.mm b/test/Rewriter/rewrite-message-expr.mm new file mode 100644 index 0000000..d909f3e --- /dev/null +++ b/test/Rewriter/rewrite-message-expr.mm @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7617047 + +@interface Baz +- (id)y; ++ (id)z; +@end + +@interface Foo { +@public + int bar; +} +@end + +extern Foo* x(id a); + +int f(Baz *baz) { + int i = x([Baz z])->bar; + int j = ((Foo*)[Baz z])->bar; + int k = x([baz y])->bar; + return i+j+k; +} + +// CHECK-LP: ((struct Foo_IMPL *)x(((id (*)(id, SEL))(void *)objc_msgSend)(objc_getClass("Baz"), sel_registerName("z"))))->bar diff --git a/test/Rewriter/rewrite-nested-ivar.mm b/test/Rewriter/rewrite-nested-ivar.mm new file mode 100644 index 0000000..bbc9d28 --- /dev/null +++ b/test/Rewriter/rewrite-nested-ivar.mm @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7583971 + + +@interface NSURLResponse { +@public + NSURLResponse *InnerResponse; +} +@end + +@interface NSCachedURLResponseInternal +{ + @public + NSURLResponse *response; +} +@end + +@interface NSCachedURLResponse +{ + @private + NSCachedURLResponseInternal *_internal; +} +- (void) Meth; +@end + +@implementation NSCachedURLResponse +- (void) Meth { + _internal->response->InnerResponse = 0; + } +@end + +// CHECK-LP: ((struct NSURLResponse_IMPL *)((struct NSCachedURLResponseInternal_IMPL *)((struct NSCachedURLResponse_IMPL *)self)->_internal)->response)->InnerResponse diff --git a/test/Rewriter/rewrite-protocol-qualified.mm b/test/Rewriter/rewrite-protocol-qualified.mm new file mode 100644 index 0000000..e91c3db --- /dev/null +++ b/test/Rewriter/rewrite-protocol-qualified.mm @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7589414 + +@protocol NSPortDelegate; +@interface NSConnection @end + +@interface NSMessagePort +- (void) clone; +@end + +@implementation NSMessagePort +- (void) clone { + NSConnection <NSPortDelegate> *conn = 0; + id <NSPortDelegate> *idc = 0; +} +@end + +// radar 7607413 +@protocol Proto1, Proto2; + +@protocol Proto +@end + +unsigned char func(id<Proto1, Proto2> inProxy); + +id bar(id); + +void f() { + id a; + id b = bar((id <Proto>)a); +} + +// CHECK-LP: NSConnection /*<NSPortDelegate>*/ *conn = 0; + +// CHECK-LP: id /*<NSPortDelegate>*/ *idc = 0; + +// CHECK-LP: func(id/*<Proto1, Proto2>*/ inProxy); + +// CHECK-LP: bar((id /*<Proto>*/)a); + diff --git a/test/Rewriter/rewrite-typeof.mm b/test/Rewriter/rewrite-typeof.mm index f95cd9a..b859ac3 100644 --- a/test/Rewriter/rewrite-typeof.mm +++ b/test/Rewriter/rewrite-typeof.mm @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -o - %s +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s extern "C" { extern "C" void *_Block_copy(const void *aBlock); @@ -18,3 +19,21 @@ int main() { return 0; } +// CHECK-LP: ((void (^)(void))_Block_copy((const void *)(b))) + +// radar 7628153 +void f() { + int a; + __typeof__(a) aVal = a; + char *a1t = (char *)@encode(__typeof__(a)); + __typeof__(aVal) bVal; + char *a2t = (char *)@encode(__typeof__(bVal)); + __typeof__(bVal) cVal = bVal; + char *a3t = (char *)@encode(__typeof__(cVal)); + +} + + +// CHECK-LP: int aVal = a; + +// CHECK-LP: int bVal; diff --git a/test/Rewriter/rewrite-unique-block-api.mm b/test/Rewriter/rewrite-unique-block-api.mm new file mode 100644 index 0000000..780a3f0 --- /dev/null +++ b/test/Rewriter/rewrite-unique-block-api.mm @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7630551 + +void f(void (^b)(char c)); + +@interface a +- (void)processStuff; +@end + +@implementation a +- (void)processStuff { + f(^(char x) { }); +} +@end + +@interface b +- (void)processStuff; +@end + +@implementation b +- (void)processStuff { + f(^(char x) { }); +} +@end + +// CHECK-LP: struct __a__processStuff_block_impl_0 +// CHECK-LP: static void __a__processStuff_block_func_0 + +// CHECK-LP: struct __b__processStuff_block_impl_0 +// CHECK-LP: static void __b__processStuff_block_func_0 diff --git a/test/Sema/Inputs/conversion.h b/test/Sema/Inputs/conversion.h new file mode 100644 index 0000000..9f6ed2e --- /dev/null +++ b/test/Sema/Inputs/conversion.h @@ -0,0 +1,3 @@ +/* Fake system header for Sema/conversion.c */ + +#define LONG_MAX __LONG_MAX__ diff --git a/test/Sema/arm-layout.c b/test/Sema/arm-layout.c new file mode 100644 index 0000000..1e239d2 --- /dev/null +++ b/test/Sema/arm-layout.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple armv7-unknown-unknown -target-abi apcs-gnu %s -verify +// RUN: %clang_cc1 -triple armv7-unknown-unknown -target-abi aapcs %s -verify + +#ifdef __ARM_EABI__ + +struct s0 { char field0; double field1; }; +int g0[sizeof(struct s0) == 16 ? 1 : -1]; + +struct s1 { char field0; long double field1; }; +int g1[sizeof(struct s1) == 16 ? 1 : -1]; + +#else + +struct s0 { char field0; double field1; }; +int g0[sizeof(struct s0) == 12 ? 1 : -1]; + +struct s1 { char field0; long double field1; }; +int g1[sizeof(struct s1) == 12 ? 1 : -1]; + +#endif diff --git a/test/Sema/asm.c b/test/Sema/asm.c index 18d900c..6f2272d 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -76,3 +76,6 @@ int test7(unsigned long long b) { asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}} return a; } + +// <rdar://problem/7574870> +asm volatile (""); // expected-warning {{meaningless 'volatile' on asm outside function}} diff --git a/test/Sema/attr-mode.c b/test/Sema/attr-mode.c index 9acd2c6..0c53362 100644 --- a/test/Sema/attr-mode.c +++ b/test/Sema/attr-mode.c @@ -1,4 +1,7 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -DTEST_32BIT_X86 -fsyntax-only \ +// RUN: -verify %s +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -DTEST_64BIT_X86 -fsyntax-only \ +// RUN: -verify %s typedef int i16_1 __attribute((mode(HI))); int i16_1_test[sizeof(i16_1) == 2 ? 1 : -1]; @@ -20,3 +23,37 @@ typedef _Complex double c32 __attribute((mode(SC))); int c32_test[sizeof(c32) == 8 ? 1 : -1]; typedef _Complex float c64 __attribute((mode(DC))); typedef _Complex float c80 __attribute((mode(XC))); + +// PR6108: Correctly select 'long' built in type on 64-bit platforms for 64 bit +// modes. Also test other mode-based conversions. +typedef int i8_mode_t __attribute__ ((__mode__ (__QI__))); +typedef unsigned int ui8_mode_t __attribute__ ((__mode__ (__QI__))); +typedef int i16_mode_t __attribute__ ((__mode__ (__HI__))); +typedef unsigned int ui16_mode_t __attribute__ ((__mode__ (__HI__))); +typedef int i32_mode_t __attribute__ ((__mode__ (__SI__))); +typedef unsigned int ui32_mode_t __attribute__ ((__mode__ (__SI__))); +typedef int i64_mode_t __attribute__ ((__mode__ (__DI__))); +typedef unsigned int ui64_mode_t __attribute__ ((__mode__ (__DI__))); +void f_i8_arg(i8_mode_t* x) { (void)x; } +void f_ui8_arg(ui8_mode_t* x) { (void)x; } +void f_i16_arg(i16_mode_t* x) { (void)x; } +void f_ui16_arg(ui16_mode_t* x) { (void)x; } +void f_i32_arg(i32_mode_t* x) { (void)x; } +void f_ui32_arg(ui32_mode_t* x) { (void)x; } +void f_i64_arg(i64_mode_t* x) { (void)x; } +void f_ui64_arg(ui64_mode_t* x) { (void)x; } +void test_char_to_i8(signed char* y) { f_i8_arg(y); } +void test_char_to_ui8(unsigned char* y) { f_ui8_arg(y); } +void test_short_to_i16(short* y) { f_i16_arg(y); } +void test_short_to_ui16(unsigned short* y) { f_ui16_arg(y); } +void test_int_to_i32(int* y) { f_i32_arg(y); } +void test_int_to_ui32(unsigned int* y) { f_ui32_arg(y); } +#if TEST_32BIT_X86 +void test_long_to_i64(long long* y) { f_i64_arg(y); } +void test_long_to_ui64(unsigned long long* y) { f_ui64_arg(y); } +#elif TEST_64BIT_X86 +void test_long_to_i64(long* y) { f_i64_arg(y); } +void test_long_to_ui64(unsigned long* y) { f_ui64_arg(y); } +#else +#error Unknown test architecture. +#endif diff --git a/test/Sema/attr-noreturn.c b/test/Sema/attr-noreturn.c index 3f064a0..b17f9fd 100644 --- a/test/Sema/attr-noreturn.c +++ b/test/Sema/attr-noreturn.c @@ -11,7 +11,7 @@ static void __attribute__((noreturn)) f0(void) { // On K&R int f1() __attribute__((noreturn)); -int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' attribute only applies to function types}} +int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' only applies to function types; type here is 'int'}} int f2() __attribute__((noreturn(1, 2))); // expected-error {{attribute requires 0 argument(s)}} diff --git a/test/Sema/block-args.c b/test/Sema/block-args.c index 08af9b3..a07c82e 100644 --- a/test/Sema/block-args.c +++ b/test/Sema/block-args.c @@ -27,3 +27,9 @@ int main(int argc, char** argv) { argCount = 3; }(argc); } + +// radar 7528255 +void f0() { + ^(int, double d, char) {}(1, 1.34, 'a'); // expected-error {{parameter name omitted}} \ + // expected-error {{parameter name omitted}} +} diff --git a/test/Sema/block-printf-attribute-1.c b/test/Sema/block-printf-attribute-1.c index 8ea77ec..c19b378 100644 --- a/test/Sema/block-printf-attribute-1.c +++ b/test/Sema/block-printf-attribute-1.c @@ -6,7 +6,6 @@ int main() { void (^z) (int arg, const char * format, ...) __attribute__ ((__format__ (__printf__, 2, 3))) = ^ __attribute__ ((__format__ (__printf__, 2, 3))) (int arg, const char * format, ...) {}; - // FIXME: argument type poking not yet supportted. - z(1, "%s", 1); /* { dg-warning "format \\'\%s\\' expects type \\'char \\*\\'\, but argument 3 has type \\'int\\'" } */ - z(1, "%s", "HELLO"); // OK + z(1, "%s", 1); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}} + z(1, "%s", "HELLO"); // no-warning } diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c index 6416545..2385106 100644 --- a/test/Sema/block-return.c +++ b/test/Sema/block-return.c @@ -109,7 +109,7 @@ void foo6() { void foo7() { - const int (^BB) (void) = ^{ const int i = 1; return i; }; // OK + const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'int (^)(void)', expected 'int const (^)(void)'}} const int (^CC) (void) = ^const int{ const int i = 1; return i; }; // OK int i; @@ -123,9 +123,8 @@ void foo7() __block const int k; const int cint = 100; - int (^MM) (void) = ^{ return k; }; // expected-error {{incompatible block pointer types initializing 'int const (^)(void)', expected 'int (^)(void)'}} - int (^NN) (void) = ^{ return cint; }; // expected-error {{incompatible block pointer types initializing 'int const (^)(void)', expected 'int (^)(void)'}} - + int (^MM) (void) = ^{ return k; }; + int (^NN) (void) = ^{ return cint; }; } diff --git a/test/Sema/builtin-unary-fp.c b/test/Sema/builtin-unary-fp.c index 8f48d7f..57568db 100644 --- a/test/Sema/builtin-unary-fp.c +++ b/test/Sema/builtin-unary-fp.c @@ -9,4 +9,8 @@ void a() { check(__builtin_isfinite(1)); // expected-error{{requires argument of floating point type}} check(__builtin_isinf()); // expected-error{{too few arguments}} check(__builtin_isnan(1,2)); // expected-error{{too many arguments}} + check(__builtin_fpclassify(0, 0, 0, 0, 0, 1.0)); + check(__builtin_fpclassify(0, 0, 0, 0, 0, 1)); // expected-error{{requires argument of floating point type}} + check(__builtin_fpclassify(0, 0, 0, 0, 1)); // expected-error{{too few arguments}} + check(__builtin_fpclassify(0, 0, 0, 0, 0, 1, 0)); // expected-error{{too many arguments}} } diff --git a/test/Sema/callingconv.c b/test/Sema/callingconv.c index a32a495..0752606 100644 --- a/test/Sema/callingconv.c +++ b/test/Sema/callingconv.c @@ -9,15 +9,30 @@ void __attribute__((stdcall)) bar(float *a) { void __attribute__((fastcall(1))) baz(float *a) { // expected-error {{attribute requires 0 argument(s)}} } -void __attribute__((fastcall)) test0() { // expected-error {{function with no prototype cannot use 'fastcall' calling convention}} +void __attribute__((fastcall)) test0() { // expected-error {{function with no prototype cannot use fastcall calling convention}} } void __attribute__((fastcall)) test1(void) { } -void __attribute__((fastcall)) test2(int a, ...) { // expected-error {{variadic function cannot use 'fastcall' calling convention}} +void __attribute__((fastcall)) test2(int a, ...) { // expected-error {{variadic function cannot use fastcall calling convention}} } void __attribute__((cdecl)) ctest0() {} void __attribute__((cdecl(1))) ctest1(float x) {} // expected-error {{attribute requires 0 argument(s)}} + +void (__attribute__((fastcall)) *pfoo)(float*) = foo; + +void (__attribute__((stdcall)) *pbar)(float*) = bar; + +void (__attribute__((cdecl)) *ptest1)(void) = test1; // expected-warning {{incompatible pointer types}} + +void (*pctest0)() = ctest0; + +void ctest2() {} +void (__attribute__((cdecl)) *pctest2)() = ctest2; + +typedef void (__attribute__((fastcall)) *Handler) (float *); +Handler H = foo; + diff --git a/test/Sema/compare.c b/test/Sema/compare.c index 579c3e5..2821a93 100644 --- a/test/Sema/compare.c +++ b/test/Sema/compare.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare %s -Wno-unreachable-code int test(char *C) { // nothing here should warn. return C != ((void*)0); diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index fee8d97..9c53725 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -75,3 +75,4 @@ EVAL_EXPR(35, constbool) EVAL_EXPR(36, constbool) EVAL_EXPR(37, (1,2.0) == 2.0) +EVAL_EXPR(38, __builtin_expect(1,1) == 1) diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index 298bf75..8b93a46 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wconversion -triple x86_64-apple-darwin %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wconversion -nostdinc -isystem %S/Inputs -triple x86_64-apple-darwin %s -Wno-unreachable-code + +#include <conversion.h> #define BIG 0x7f7f7f7f7f7f7f7fL @@ -271,3 +273,9 @@ unsigned char test19(unsigned long u64) { unsigned char x3 = u64 & mask; return x1 + x2 + x3; } + +// <rdar://problem/7631400> +void test_7631400(void) { + // This should show up despite the caret being inside a macro substitution + char s = LONG_MAX; // expected-warning {{implicit cast loses integer precision: 'long' to 'char'}} +} diff --git a/test/Sema/declspec.c b/test/Sema/declspec.c index 5b11960..d9f4157 100644 --- a/test/Sema/declspec.c +++ b/test/Sema/declspec.c @@ -7,11 +7,13 @@ void foof(const char *, ...) __attribute__((__format__(__printf__, 1, 2))), barf int typedef validTypeDecl() { } // expected-error {{function definition declared 'typedef'}} -struct _zend_module_entry { } -typedef struct _zend_function_entry { } // expected-error {{cannot combine with previous 'struct' declaration specifier}} -static void buggy(int *x) { } // expected-error {{function definition declared 'typedef'}} \ - // expected-error {{cannot combine with previous 'typedef' declaration specifier}} \ - // expected-error {{cannot combine with previous 'struct' declaration specifier}} +struct _zend_module_entry { } // expected-error {{expected ';' after struct}} +int gv1; +typedef struct _zend_function_entry { } // expected-error {{expected ';' after struct}} \ + // expected-error {{declaration does not declare anything}} +int gv2; + +static void buggy(int *x) { } // Type qualifiers. typedef int f(void); @@ -22,3 +24,10 @@ __restrict__ fptr v3; // expected-error {{pointer to function type 'f' (aka 'int f *__restrict__ v4; // expected-error {{pointer to function type 'f' (aka 'int (void)') may not be 'restrict' qualified}} restrict struct hallo; // expected-error {{restrict requires a pointer or reference}} + +// PR6180 +struct test1 { +} // expected-error {{expected ';' after struct}} + +void test2() {} + diff --git a/test/Sema/enum.c b/test/Sema/enum.c index 916de41..9b46500 100644 --- a/test/Sema/enum.c +++ b/test/Sema/enum.c @@ -92,3 +92,7 @@ typedef enum { } an_enum; // FIXME: why is this only a warning? char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer to pointer conversion initializing 'an_enum', expected 'char *'}} + +// PR4515 +enum PR4515 {PR4515a=1u,PR4515b=(PR4515a-2)/2}; +int CheckPR4515[PR4515b==0?1:-1]; diff --git a/test/Sema/format-string-percentm.c b/test/Sema/format-string-percentm.c index f2e9dd8..1ffc439 100644 --- a/test/Sema/format-string-percentm.c +++ b/test/Sema/format-string-percentm.c @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -triple i686-pc-linux-gnu +// PR 4142 - support glibc extension to printf: '%m' (which prints strerror(errno)). int printf(char const*,...); void percentm(void) { printf("%m"); diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 20e4dcd..f1fa658 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -40,18 +40,22 @@ void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { // rdar://6079877 printf("abc" - "%*d", (unsigned) 1, 1); // expected-warning {{field width should have type 'int'}} + "%*d", 1, 1); // no-warning printf("abc\ def" - "%*d", (unsigned) 1, 1); // expected-warning {{field width should have type 'int'}} - + "%*d", 1, 1); // no-warning + + // <rdar://problem/6079850>, allow 'unsigned' (instead of 'int') to be used for both + // the field width and precision. This deviates from C99, but is reasonably safe + // and is also accepted by GCC. + printf("%*d", (unsigned) 1, 1); // no-warning } void check_conditional_literal(const char* s, int i) { printf(i == 1 ? "yes" : "no"); // no-warning printf(i == 0 ? (i == 1 ? "yes" : "no") : "dont know"); // no-warning printf(i == 0 ? (i == 1 ? s : "no") : "dont know"); // expected-warning{{format string is not a string literal}} - printf("yes" ?: "no %d", 1); // expected-warning{{more data arguments than '%' conversions}} + printf("yes" ?: "no %d", 1); // expected-warning{{more data arguments than format specifiers}} } void check_writeback_specifier() @@ -65,10 +69,10 @@ void check_writeback_specifier() void check_invalid_specifier(FILE* fp, char *buf) { - printf("%s%lb%d","unix",10,20); // expected-warning {{lid conversion '%lb'}} - fprintf(fp,"%%%l"); // expected-warning {{lid conversion '%l'}} - sprintf(buf,"%%%%%ld%d%d", 1, 2, 3); // no-warning - snprintf(buf, 2, "%%%%%ld%;%d", 1, 2, 3); // expected-warning {{sion '%;'}} + printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion specifier 'b'}} + fprintf(fp,"%%%l"); // expected-warning {{incomplete format specifier}} + sprintf(buf,"%%%%%ld%d%d", 1, 2, 3); // expected-warning{{conversion specifies type 'long' but the argument has type 'int'}} + snprintf(buf, 2, "%%%%%ld%;%d", 1, 2, 3); // expected-warning{{conversion specifies type 'long' but the argument has type 'int'}} expected-warning {{invalid conversion specifier ';'}} } void check_null_char_string(char* b) @@ -137,5 +141,66 @@ void test9(char *P) { void torture(va_list v8) { vprintf ("%*.*d", v8); // no-warning + +} + +void test10(int x, float f, int i, long long lli) { + printf("%@", 12); // expected-warning{{invalid conversion specifier '@'}} + printf("\0"); // expected-warning{{format string contains '\0' within the string body}} + printf("xs\0"); // expected-warning{{format string contains '\0' within the string body}} + printf("%*d\n"); // expected-warning{{'*' specified field width is missing a matching 'int' argument}} + printf("%*.*d\n", x); // expected-warning{{'.*' specified field precision is missing a matching 'int' argument}} + printf("%*d\n", f, x); // expected-warning{{field width should have type 'int', but argument has type 'double'}} + printf("%*.*d\n", x, f, x); // expected-warning{{field precision should have type 'int', but argument has type 'double'}} + printf("%**\n"); // expected-warning{{invalid conversion specifier '*'}} + printf("%n", &i); // expected-warning{{use of '%n' in format string discouraged (potentially insecure)}} + printf("%d%d\n", x); // expected-warning{{more '%' conversions than data arguments}} + printf("%d\n", x, x); // expected-warning{{more data arguments than format specifiers}} + printf("%W%d%Z\n", x, x, x); // expected-warning{{invalid conversion specifier 'W'}} expected-warning{{invalid conversion specifier 'Z'}} + printf("%"); // expected-warning{{incomplete format specifier}} + printf("%.d", x); // no-warning + printf("%.", x); // expected-warning{{incomplete format specifier}} + printf("%f", 4); // expected-warning{{conversion specifies type 'double' but the argument has type 'int'}} + printf("%qd", lli); + printf("hhX %hhX", (unsigned char)10); // no-warning + printf("llX %llX", (long long) 10); // no-warning + // This is fine, because there is an implicit conversion to an int. + printf("%d", (unsigned char) 10); // no-warning + printf("%d", (long long) 10); // expected-warning{{conversion specifies type 'int' but the argument has type 'long long'}} + printf("%Lf\n", (long double) 1.0); // no-warning + printf("%f\n", (long double) 1.0); // expected-warning{{conversion specifies type 'double' but the argument has type 'long double'}} +} + +void test11(void *p, char *s) { + printf("%p", p); // no-warning + printf("%.4p", p); // expected-warning{{precision used in 'p' conversion specifier (where it has no meaning)}} + printf("%+p", p); // expected-warning{{flag '+' results in undefined behavior in 'p' conversion specifier}} + printf("% p", p); // expected-warning{{flag ' ' results in undefined behavior in 'p' conversion specifier}} + printf("%0p", p); // expected-warning{{flag '0' results in undefined behavior in 'p' conversion specifier}} + printf("%s", s); // no-warning + printf("%+s", p); // expected-warning{{flag '+' results in undefined behavior in 's' conversion specifier}} + printf("% s", p); // expected-warning{{flag ' ' results in undefined behavior in 's' conversion specifier}} + printf("%0s", p); // expected-warning{{flag '0' results in undefined behavior in 's' conversion specifier}} +} + +void test12(char *b) { + unsigned char buf[4]; + printf ("%.4s\n", buf); // no-warning + printf ("%.4s\n", &buf); // expected-warning{{conversion specifies type 'char *' but the argument has type 'unsigned char (*)[4]'}} + + // Verify that we are checking asprintf + asprintf(&b, "%d", "asprintf"); // expected-warning{{conversion specifies type 'int' but the argument has type 'char *'}} +} + +typedef struct __aslclient *aslclient; +typedef struct __aslmsg *aslmsg; +int asl_log(aslclient asl, aslmsg msg, int level, const char *format, ...) __attribute__((__format__ (__printf__, 4, 5))); +void test_asl(aslclient asl) { + // Test case from <rdar://problem/7341605>. + asl_log(asl, 0, 3, "Error: %m"); // no-warning + asl_log(asl, 0, 3, "Error: %W"); // expected-warning{{invalid conversion specifier 'W'}} } +// <rdar://problem/7595366> +typedef enum { A } int_t; +void f0(int_t x) { printf("%d\n", x); } diff --git a/test/Sema/function-redecl.c b/test/Sema/function-redecl.c index 9544dc9..1302b34 100644 --- a/test/Sema/function-redecl.c +++ b/test/Sema/function-redecl.c @@ -125,3 +125,7 @@ void test_x() { x(5); x2(5); // expected-warning{{incompatible integer to pointer conversion passing 'int', expected 'int *'}} } + +enum e0 {}; +void f3(); +void f3(enum e0 x) {} diff --git a/test/Sema/incomplete-decl.c b/test/Sema/incomplete-decl.c index 753d9c0..e5b6d5f 100644 --- a/test/Sema/incomplete-decl.c +++ b/test/Sema/incomplete-decl.c @@ -16,7 +16,7 @@ int ary[]; // expected-warning {{tentative array definition assumed to have one struct foo bary[]; // expected-error {{array has incomplete element type 'struct foo'}} void func() { - int ary[]; // expected-error{{variable has incomplete type 'int []'}} + int ary[]; // expected-error{{definition of variable with array type needs an explicit size or an initializer}} void b; // expected-error {{variable has incomplete type 'void'}} struct foo f; // expected-error {{variable has incomplete type 'struct foo'}} } diff --git a/test/Sema/indirect-goto.c b/test/Sema/indirect-goto.c index 134ccd8..4c1c6c3 100644 --- a/test/Sema/indirect-goto.c +++ b/test/Sema/indirect-goto.c @@ -2,6 +2,9 @@ struct c {int x;}; int a(struct c x, long long y) { + void const* l1_ptr = &&l1; + goto *l1_ptr; +l1: goto *x; // expected-error{{incompatible type}} goto *y; // expected-warning{{incompatible integer to pointer conversion}} } diff --git a/test/Sema/return-noreturn.c b/test/Sema/return-noreturn.c index 198ab11..ff43754 100644 --- a/test/Sema/return-noreturn.c +++ b/test/Sema/return-noreturn.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn +// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn -Wno-unreachable-code int j; void test1() { // expected-warning {{function could be attribute 'noreturn'}} diff --git a/test/Sema/return.c b/test/Sema/return.c index 17d2178..5d1c97f 100644 --- a/test/Sema/return.c +++ b/test/Sema/return.c @@ -1,4 +1,4 @@ -// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks +// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wno-unreachable-code // clang emits the following warning by default. // With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the diff --git a/test/Sema/scope-check.c b/test/Sema/scope-check.c index 74bc7c4..7d293f2 100644 --- a/test/Sema/scope-check.c +++ b/test/Sema/scope-check.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=gnu99 %s +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=gnu99 %s -Wno-unreachable-code int test1(int x) { goto L; // expected-error{{illegal goto into protected scope}} diff --git a/test/Sema/statements.c b/test/Sema/statements.c index 3cd2460..6da2daa 100644 --- a/test/Sema/statements.c +++ b/test/Sema/statements.c @@ -33,3 +33,11 @@ void *test10() { bar: return &&bar; // expected-warning {{returning address of label, which is local}} } + +// PR6034 +void test11(int bit) { + switch (bit) + switch (env->fpscr) // expected-error {{use of undeclared identifier 'env'}} + { + } +} diff --git a/test/Sema/stdcall-fastcall.c b/test/Sema/stdcall-fastcall.c index c45f93e..a069526 100644 --- a/test/Sema/stdcall-fastcall.c +++ b/test/Sema/stdcall-fastcall.c @@ -1,10 +1,10 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // CC qualifier can be applied only to functions -int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' attribute only applies to function types}} -int __attribute__((fastcall)) var2; // expected-warning{{'fastcall' attribute only applies to function types}} +int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' only applies to function types; type here is 'int'}} +int __attribute__((fastcall)) var2; // expected-warning{{'fastcall' only applies to function types; type here is 'int'}} // Different CC qualifiers are not compatible void __attribute__((stdcall, fastcall)) foo3(void); // expected-error{{stdcall and fastcall attributes are not compatible}} -void __attribute__((stdcall)) foo4(); -void __attribute__((fastcall)) foo4(void); // expected-error{{fastcall and stdcall attributes are not compatible}} +void __attribute__((stdcall)) foo4(); // expected-note{{previous declaration is here}} +void __attribute__((fastcall)) foo4(void); // expected-error{{function declared 'fastcall' here was previously declared 'stdcall'}} diff --git a/test/Sema/switch.c b/test/Sema/switch.c index 08ab0e0..2690ad2 100644 --- a/test/Sema/switch.c +++ b/test/Sema/switch.c @@ -85,3 +85,141 @@ int f0(int var) { // expected-note{{'var' declared here}} } return 2; } + +void test7() { + enum { + A = 1, + B + } a; + switch(a) { //expected-warning{{enumeration value 'B' not handled in switch}} + case A: + break; + } + switch(a) { + case B: + case A: + break; + } + switch(a) { + case A: + case B: + case 3: // expected-warning{{case value not in enumerated type ''}} + break; + } + switch(a) { + case A: + case B: + case 3 ... //expected-warning{{case value not in enumerated type ''}} + 4: //expected-warning{{case value not in enumerated type ''}} + break; + } + switch(a) { + case 1 ... 2: + break; + } + switch(a) { + case 0 ... 2: //expected-warning{{case value not in enumerated type ''}} + break; + } + switch(a) { + case 1 ... 3: //expected-warning{{case value not in enumerated type ''}} + break; + } + switch(a) { + case 0 ... //expected-warning{{case value not in enumerated type ''}} + 3: //expected-warning{{case value not in enumerated type ''}} + break; + } + +} + +void test8() { + enum { + A, + B, + C = 1 + } a; + switch(a) { + case A: + case B: + break; + } + switch(a) { + case A: + case C: + break; + } + switch(a) { //expected-warning{{enumeration value 'B' not handled in switch}} + case A: + break; + } +} + +void test9() { + enum { + A = 3, + C = 1 + } a; + switch(a) { + case 0: //expected-warning{{case value not in enumerated type ''}} + case 1: + case 2: //expected-warning{{case value not in enumerated type ''}} + case 3: + case 4: //expected-warning{{case value not in enumerated type ''}} + break; + } +} + +void test10() { + enum { + A = 10, + C = 2, + B = 4, + D = 12 + } a; + switch(a) { + case 0 ... //expected-warning{{case value not in enumerated type ''}} + 1: //expected-warning{{case value not in enumerated type ''}} + case 2 ... 4: + case 5 ... //expected-warning{{case value not in enumerated type ''}} + 9: //expected-warning{{case value not in enumerated type ''}} + case 10 ... 12: + case 13 ... //expected-warning{{case value not in enumerated type ''}} + 16: //expected-warning{{case value not in enumerated type ''}} + break; + } +} + +void test11() { + enum { + A = -1, + B, + C + } a; + switch(a) { //expected-warning{{enumeration value 'A' not handled in switch}} + case B: + case C: + break; + } + + switch(a) { + case B: + case C: + break; + + default: + break; + } +} + +void test12() { + enum { + A = -1, + B = 4294967286 + } a; + switch(a) { + case A: + case B: + break; + } +} diff --git a/test/Sema/ucn-cstring.c b/test/Sema/ucn-cstring.c index f5bf457..ac1d37f 100644 --- a/test/Sema/ucn-cstring.c +++ b/test/Sema/ucn-cstring.c @@ -5,8 +5,8 @@ int printf(const char *, ...); int main(void) { int a[sizeof("hello \u2192 \u2603 \u2190 world") == 24 ? 1 : -1]; - printf("%s (%d)\n", "hello \u2192 \u2603 \u2190 world", sizeof("hello \u2192 \u2603 \u2190 world")); - printf("%s (%d)\n", "\U00010400\U0001D12B", sizeof("\U00010400\U0001D12B")); + printf("%s (%zd)\n", "hello \u2192 \u2603 \u2190 world", sizeof("hello \u2192 \u2603 \u2190 world")); + printf("%s (%zd)\n", "\U00010400\U0001D12B", sizeof("\U00010400\U0001D12B")); // Some error conditions... printf("%s\n", "\U"); // expected-error{{\u used with no following hex digits}} printf("%s\n", "\U00"); // expected-error{{incomplete universal character name}} diff --git a/test/Sema/unused-expr.c b/test/Sema/unused-expr.c index 68503bd..4c6c47b 100644 --- a/test/Sema/unused-expr.c +++ b/test/Sema/unused-expr.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code int foo(int X, int Y); diff --git a/test/Sema/vla.c b/test/Sema/vla.c index 7ddd432..ebf9b88 100644 --- a/test/Sema/vla.c +++ b/test/Sema/vla.c @@ -54,3 +54,9 @@ int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}} const int f5_ci = 1; void f5() { char a[][f5_ci] = {""}; } // expected-error {{variable-sized object may not be initialized}} + +// PR5185 +void pr5185(int a[*]); +void pr5185(int a[*]) // expected-error {{variable length array must be bound in function definition}} +{ +} diff --git a/test/Sema/warn-unused-function.c b/test/Sema/warn-unused-function.c new file mode 100644 index 0000000..178527f --- /dev/null +++ b/test/Sema/warn-unused-function.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -Wunused-function -verify %s + +void foo() {} +static void f2() {} +static void f1() {f2();} // expected-warning{{unused}} + +static int f0() { return 17; } // expected-warning{{unused}} +int x = sizeof(f0()); + +static void f3(); +extern void f3() { } // expected-warning{{unused}} + +// FIXME: This will trigger a warning when it should not. +// Update once PR6281 is fixed. +//inline static void f4(); +//void f4() { }
\ No newline at end of file diff --git a/test/Sema/x86-attr-force-align-arg-pointer.c b/test/Sema/x86-attr-force-align-arg-pointer.c new file mode 100644 index 0000000..9609fad --- /dev/null +++ b/test/Sema/x86-attr-force-align-arg-pointer.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple i386-apple-darwin10 -fsyntax-only -verify %s + +int a __attribute__((force_align_arg_pointer)); // expected-warning{{attribute only applies to function types}} + +// It doesn't matter where the attribute is located. +void b(void) __attribute__((force_align_arg_pointer)); +void __attribute__((force_align_arg_pointer)) c(void); + +// Functions only have to be declared force_align_arg_pointer once. +void b(void) {} + +// It doesn't matter which declaration has the attribute. +void d(void); +void __attribute__((force_align_arg_pointer)) d(void) {} + +// Attribute is ignored on function pointer types. +void (__attribute__((force_align_arg_pointer)) *p)(); //expected-warning{{force_align_arg_pointer used on function pointer; attribute ignored}} + diff --git a/test/SemaCXX/Inputs/lit.local.cfg b/test/SemaCXX/Inputs/lit.local.cfg new file mode 100644 index 0000000..e6f55ee --- /dev/null +++ b/test/SemaCXX/Inputs/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes = [] diff --git a/test/SemaCXX/Inputs/malloc.h b/test/SemaCXX/Inputs/malloc.h new file mode 100644 index 0000000..c54d621 --- /dev/null +++ b/test/SemaCXX/Inputs/malloc.h @@ -0,0 +1,3 @@ +extern "C" { +extern void *malloc (__SIZE_TYPE__ __size) throw () __attribute__ ((__malloc__)) ; +} diff --git a/test/SemaCXX/access-base-class.cpp b/test/SemaCXX/access-base-class.cpp index f4c58d9..d0b0fb8 100644 --- a/test/SemaCXX/access-base-class.cpp +++ b/test/SemaCXX/access-base-class.cpp @@ -2,10 +2,10 @@ namespace T1 { class A { }; -class B : private A { }; // expected-note {{'private' inheritance specifier here}} +class B : private A { }; // expected-note {{declared private here}} void f(B* b) { - A *a = b; // expected-error{{conversion from 'class T1::B' to inaccessible base class 'class T1::A'}} + A *a = b; // expected-error{{cannot cast 'class T1::B' to its private base class 'class T1::A'}} } } @@ -13,10 +13,10 @@ void f(B* b) { namespace T2 { class A { }; -class B : A { }; // expected-note {{inheritance is implicitly 'private'}} +class B : A { }; // expected-note {{implicitly declared private here}} void f(B* b) { - A *a = b; // expected-error {{conversion from 'class T2::B' to inaccessible base class 'class T2::A'}} + A *a = b; // expected-error {{cannot cast 'class T2::B' to its private base class 'class T2::A'}} } } @@ -63,13 +63,13 @@ namespace T6 { class A {}; - class B : private A { // expected-note {{'private' inheritance specifier here}} + class B : private A { // expected-note {{declared private here}} void f(C* c); }; class C : public B { void f(C *c) { - A* a = c; // expected-error {{conversion from 'class T6::C' to inaccessible base class 'class T6::A'}} + A* a = c; // expected-error {{cannot cast 'class T6::C' to its private base class 'class T6::A'}} } }; @@ -77,3 +77,14 @@ namespace T6 { A *a = c; } } + +namespace T7 { + class A {}; + class B : public A {}; + class C : private B { + void f(C *c) { + A* a = c; // okay + } + }; +} + diff --git a/test/SemaCXX/access-control-check.cpp b/test/SemaCXX/access-control-check.cpp index cf2d191..783d4de 100644 --- a/test/SemaCXX/access-control-check.cpp +++ b/test/SemaCXX/access-control-check.cpp @@ -11,5 +11,5 @@ class P { class N : M,P { N() {} - int PR() { return iP + PPR(); } // expected-error 2 {{access to private member of 'class P'}} + int PR() { return iP + PPR(); } // expected-error 2 {{private member of 'class P'}} }; diff --git a/test/SemaCXX/aggregate-initialization.cpp b/test/SemaCXX/aggregate-initialization.cpp index ac48215..83f4179 100644 --- a/test/SemaCXX/aggregate-initialization.cpp +++ b/test/SemaCXX/aggregate-initialization.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s // Verify that we can't initialize non-aggregates with an initializer // list. @@ -30,3 +30,40 @@ NonAggr4 na4 = { 17 }; // expected-error{{non-aggregate type 'struct NonAggr4' c // PR5817 typedef int type[][2]; const type foo = {0}; + +// Vector initialization. +typedef short __v4hi __attribute__ ((__vector_size__ (8))); +__v4hi v1 = { (void *)1, 2, 3 }; // expected-error {{cannot initialize a vector element of type 'short' with an rvalue of type 'void *'}} + +// Array initialization. +int a[] = { (void *)1 }; // expected-error {{cannot initialize an array element of type 'int' with an rvalue of type 'void *'}} + +// Struct initialization. +struct S { int a; } s = { (void *)1 }; // expected-error {{cannot initialize a member subobject of type 'int' with an rvalue of type 'void *'}} + +// Check that we're copy-initializing the structs. +struct A { + A(); + A(int); + ~A(); + + A(const A&) = delete; // expected-note 2 {{function has been explicitly marked deleted here}} +}; + +struct B { + A a; +}; + +struct C { + const A& a; +}; + +void f() { + A as1[1] = { }; + A as2[1] = { 1 }; // expected-error {{copying array element of type 'struct A' invokes deleted copy constructor}} + + B b1 = { }; + B b2 = { 1 }; // expected-error {{copying member subobject of type 'struct A' invokes deleted copy constructor}} + + C c1 = { 1 }; +} diff --git a/test/SemaCXX/builtin-exception-spec.cpp b/test/SemaCXX/builtin-exception-spec.cpp new file mode 100644 index 0000000..324d20e --- /dev/null +++ b/test/SemaCXX/builtin-exception-spec.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -verify %s +#include <malloc.h> + +extern "C" { +void *malloc(__SIZE_TYPE__); +} diff --git a/test/SemaCXX/builtins.cpp b/test/SemaCXX/builtins.cpp index a75b4f2..568ba5d 100644 --- a/test/SemaCXX/builtins.cpp +++ b/test/SemaCXX/builtins.cpp @@ -5,3 +5,5 @@ typedef const struct __CFString * CFStringRef; void f() { (void)CFStringRef(CFSTR("Hello")); } + +void a() { __builtin_va_list x, y; ::__builtin_va_copy(x, y); } diff --git a/test/SemaCXX/cast-conversion.cpp b/test/SemaCXX/cast-conversion.cpp index 77f4a52..074e133 100644 --- a/test/SemaCXX/cast-conversion.cpp +++ b/test/SemaCXX/cast-conversion.cpp @@ -30,7 +30,7 @@ X0<T> make_X0(const T &Val) { } void test_X0() { - const char array[2]; + const char array[2] = { 'a', 'b' }; make_X0(array); } diff --git a/test/SemaCXX/comma.cpp b/test/SemaCXX/comma.cpp new file mode 100644 index 0000000..79ff7d1 --- /dev/null +++ b/test/SemaCXX/comma.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR6076 +void f(); +void (&g)() = (void(), f); + +int a[1]; +int (&b)[1] = (void(), a); diff --git a/test/SemaCXX/conditional-expr.cpp b/test/SemaCXX/conditional-expr.cpp index b71133b..b961ff2 100644 --- a/test/SemaCXX/conditional-expr.cpp +++ b/test/SemaCXX/conditional-expr.cpp @@ -25,7 +25,7 @@ struct Derived : Base { void fn2(); }; struct Convertible { operator Base&(); }; -struct Priv : private Base {}; // expected-note 4 {{'private' inheritance specifier here}} +struct Priv : private Base {}; // expected-note 4 {{declared private here}} struct Mid : Base {}; struct Fin : Mid, Derived {}; typedef void (Derived::*DFnPtr)(); @@ -111,12 +111,12 @@ void test() Priv priv; Fin fin; - (void)(i1 ? Base() : Priv()); // expected-error{{conversion from 'struct Priv' to inaccessible base class 'struct Base'}} - (void)(i1 ? Priv() : Base()); // expected-error{{error: conversion from 'struct Priv' to inaccessible base class 'struct Base'}} + (void)(i1 ? Base() : Priv()); // expected-error{{private base class}} + (void)(i1 ? Priv() : Base()); // expected-error{{private base class}} (void)(i1 ? Base() : Fin()); // expected-error{{ambiguous conversion from derived class 'struct Fin' to base class 'struct Base'}} (void)(i1 ? Fin() : Base()); // expected-error{{ambiguous conversion from derived class 'struct Fin' to base class 'struct Base'}} - (void)(i1 ? base : priv); // expected-error {{conversion from 'struct Priv' to inaccessible base class 'struct Base'}} - (void)(i1 ? priv : base); // expected-error {{conversion from 'struct Priv' to inaccessible base class 'struct Base'}} + (void)(i1 ? base : priv); // expected-error {{private base class}} + (void)(i1 ? priv : base); // expected-error {{private base class}} (void)(i1 ? base : fin); // expected-error {{ambiguous conversion from derived class 'struct Fin' to base class 'struct Base'}} (void)(i1 ? fin : base); // expected-error {{ambiguous conversion from derived class 'struct Fin' to base class 'struct Base'}} diff --git a/test/SemaCXX/constructor-initializer.cpp b/test/SemaCXX/constructor-initializer.cpp index 53f057e..2efb7b9 100644 --- a/test/SemaCXX/constructor-initializer.cpp +++ b/test/SemaCXX/constructor-initializer.cpp @@ -104,8 +104,8 @@ struct M { // expected-note 2 {{candidate constructor (the implicit }; struct N : M { - N() : M(1), // expected-error {{no matching constructor for initialization of 'M'}} - m1(100) { } // expected-error {{no matching constructor for initialization of 'm1'}} + N() : M(1), // expected-error {{no matching constructor for initialization of 'struct M'}} + m1(100) { } // expected-error {{no matching constructor for initialization of 'struct M'}} M m1; }; @@ -116,8 +116,8 @@ struct P : M { }; struct Q { - Q() : f1(1,2), // expected-error {{Too many arguments for member initializer 'f1'}} - pf(0.0) { } // expected-error {{incompatible type passing 'double', expected 'float *'}} + Q() : f1(1,2), // expected-error {{excess elements in scalar initializer}} + pf(0.0) { } // expected-error {{cannot initialize a member subobject of type 'float *' with an rvalue of type 'double'}} float f1; float *pf; diff --git a/test/SemaCXX/copy-assignment.cpp b/test/SemaCXX/copy-assignment.cpp index 315e29a..d7eb5cf 100644 --- a/test/SemaCXX/copy-assignment.cpp +++ b/test/SemaCXX/copy-assignment.cpp @@ -47,22 +47,22 @@ struct ConvertibleToInt { void test() { A a, na; - const A constA; + const A constA = A(); ConvertibleToA convertibleToA; ConvertibleToConstA convertibleToConstA; B b, nb; - const B constB; + const B constB = B(); ConvertibleToB convertibleToB; ConvertibleToBref convertibleToBref; ConvertibleToConstB convertibleToConstB; ConvertibleToConstBref convertibleToConstBref; C c, nc; - const C constC; + const C constC = C(); D d, nd; - const D constD; + const D constD = D(); ConvertibleToInt convertibleToInt; diff --git a/test/SemaCXX/dcl_ambig_res.cpp b/test/SemaCXX/dcl_ambig_res.cpp index 859d204..f0ba297 100644 --- a/test/SemaCXX/dcl_ambig_res.cpp +++ b/test/SemaCXX/dcl_ambig_res.cpp @@ -12,8 +12,8 @@ void foo(double a) { S w(int(a)); // expected-warning{{disambiguated}} w(17); - S x(int()); // expected-warning{{disambiguated}} - x(&returns_an_int); + S x1(int()); // expected-warning{{disambiguated}} + x1(&returns_an_int); S y((int)a); y.bar(); S z = int(a); diff --git a/test/SemaCXX/dcl_init_aggr.cpp b/test/SemaCXX/dcl_init_aggr.cpp index 07ddb0a..861eb3d 100644 --- a/test/SemaCXX/dcl_init_aggr.cpp +++ b/test/SemaCXX/dcl_init_aggr.cpp @@ -120,4 +120,4 @@ u u1 = { 1 }; u u2 = u1; u u3 = 1; // expected-error{{no viable conversion}} u u4 = { 0, "asdf" }; // expected-error{{excess elements in union initializer}} -u u5 = { "asdf" }; // expected-error{{incompatible type initializing 'char const [5]', expected 'int'}} +u u5 = { "asdf" }; // expected-error{{cannot initialize a member subobject of type 'int' with an lvalue of type 'char const [5]'}} diff --git a/test/SemaCXX/decl-init-ref.cpp b/test/SemaCXX/decl-init-ref.cpp index 656f343..2f7d8a4 100644 --- a/test/SemaCXX/decl-init-ref.cpp +++ b/test/SemaCXX/decl-init-ref.cpp @@ -24,3 +24,6 @@ int main() { const A& rca = f(); // expected-error {{reference initialization of type 'struct A const &' with initializer of type 'class B' is ambiguous}} A& ra = f(); // expected-error {{non-const lvalue reference to type 'struct A' cannot bind to a temporary of type 'class B'}} } + +struct PR6139 { A (&x)[1]; }; +PR6139 x = {{A()}}; // expected-error{{non-const lvalue reference to type 'struct A [1]' cannot bind to a temporary of type 'struct A'}} diff --git a/test/SemaCXX/enum.cpp b/test/SemaCXX/enum.cpp index 47ae06a..dc4a506 100644 --- a/test/SemaCXX/enum.cpp +++ b/test/SemaCXX/enum.cpp @@ -67,3 +67,7 @@ namespace PR6061 { enum { id }; }; } + +namespace Conditional { + enum a { A }; a x(const enum a x) { return 1?x:A; } +} diff --git a/test/SemaCXX/explicit.cpp b/test/SemaCXX/explicit.cpp new file mode 100644 index 0000000..717ed1e --- /dev/null +++ b/test/SemaCXX/explicit.cpp @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s +namespace Constructor { +struct A { + A(int); +}; + +struct B { + explicit B(int); +}; + +B::B(int) { } + +struct C { + void f(const A&); + void f(const B&); +}; + +void f(C c) { + c.f(10); +} +} + +namespace Conversion { + struct A { + operator int(); + explicit operator bool(); + }; + + A::operator bool() { return false; } + + struct B { + void f(int); + void f(bool); + }; + + void f(A a, B b) { + b.f(a); + } +} diff --git a/test/SemaCXX/i-c-e-cxx.cpp b/test/SemaCXX/i-c-e-cxx.cpp index 8c70bc2..4f2f197 100644 --- a/test/SemaCXX/i-c-e-cxx.cpp +++ b/test/SemaCXX/i-c-e-cxx.cpp @@ -21,3 +21,19 @@ int a() { case t:; // expected-error {{not an integer constant expression}} } } + +// PR6206: out-of-line definitions are legit +namespace pr6206 { + class Foo { + public: + static const int kBar; + }; + + const int Foo::kBar = 20; + + char Test() { + char str[Foo::kBar]; + str[0] = '0'; + return str[0]; + } +} diff --git a/test/SemaCXX/illegal-member-initialization.cpp b/test/SemaCXX/illegal-member-initialization.cpp index 1890dbc..be5f91d 100644 --- a/test/SemaCXX/illegal-member-initialization.cpp +++ b/test/SemaCXX/illegal-member-initialization.cpp @@ -1,9 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s struct A { - A() : value(), cvalue() { } // expected-error {{cannot initialize the member to null in default constructor because reference member 'value' cannot be null-initialized}} \ - // expected-error {{constructor for 'struct A' must explicitly initialize the reference member 'value'}} - int &value; // expected-note{{declared at}} {{expected-note{{declared at}} + A() : value(), cvalue() { } // expected-error {{reference to type 'int' requires an initializer}} + int &value; const int cvalue; }; @@ -18,7 +17,7 @@ struct X { int &value; // expected-note{{declared at}} const int cvalue; // expected-note{{declared at}} B& b; // expected-note{{declared at}} - const B cb; // expected-note{{declared at}} + const B cb; // expected-note{{declared here}} }; diff --git a/test/SemaCXX/namespace-alias.cpp b/test/SemaCXX/namespace-alias.cpp index f983606..06114c3 100644 --- a/test/SemaCXX/namespace-alias.cpp +++ b/test/SemaCXX/namespace-alias.cpp @@ -62,3 +62,24 @@ namespace J { func(); } } + +namespace K { + namespace KA { void func(); } + + void f() { + namespace KB = KA; + KB::func(); + } + + template <class T> void g() { + namespace KC = KA; + KC::func(); + } + template void g<int>(); + template void g<long>(); + + void h() { + KB::func(); // expected-error {{undeclared identifier 'KB'}} + KC::func(); // expected-error {{undeclared identifier 'KC'}} + } +} diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index 8618f03..8a217b3 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/test/SemaCXX/nested-name-spec.cpp @@ -212,7 +212,7 @@ namespace test1 { // non-lexical scope. namespace test2 { namespace ns { - int *count_ptr; + extern int *count_ptr; } namespace { int count = 0; @@ -220,3 +220,12 @@ namespace test2 { int *ns::count_ptr = &count; } + +// PR6259, invalid case +namespace test3 { + // FIXME: this should really only trigger once + class A; // expected-note 2 {{forward declaration}} + void foo(const char *path) { + A::execute(path); // expected-error 2 {{incomplete type 'class test3::A' named in nested name specifier}} + } +} diff --git a/test/SemaCXX/new-delete-predefined-decl.cpp b/test/SemaCXX/new-delete-predefined-decl.cpp new file mode 100644 index 0000000..20b15b7 --- /dev/null +++ b/test/SemaCXX/new-delete-predefined-decl.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -DTEMPLATE_OVERLOAD -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s + +#include <stddef.h> + +// Note that each test must be run separately so it can be the first operator +// new declaration in the file. + +#if defined(TEMPLATE_OVERLOAD) +// Don't crash on global template operator new overloads. +template<typename T> void* operator new(size_t, T); +void test_template_overload() { + (void)new(0) double; +} +#endif + +void test_predefined() { + (void)new double; +} diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index b058fc1..acd4a23 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -216,3 +216,18 @@ static void* f(void* g) { return new (g) X13(); } + +class X14 { + static void operator delete(void*, const size_t); +}; + +void f(X14 *x14a, X14 *x14b) { + delete x14a; +} + +namespace PR5918 { // Look for template operator new overloads. + struct S { template<typename T> static void* operator new(size_t, T); }; + void test() { + (void)new(0) S; + } +} diff --git a/test/SemaCXX/overload-call-copycon.cpp b/test/SemaCXX/overload-call-copycon.cpp index 472fae2..f57484e 100644 --- a/test/SemaCXX/overload-call-copycon.cpp +++ b/test/SemaCXX/overload-call-copycon.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only %s -Wnon-pod-varargs +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wnon-pod-varargs class X { }; int& copycon(X x); @@ -37,7 +37,6 @@ void test_copycon3(B b, const B bc) { float& f1 = copycon3(bc); // expected-warning {{cannot pass object of non-POD type}} } - class C : public B { }; float& copycon4(A a); diff --git a/test/SemaCXX/overload-call.cpp b/test/SemaCXX/overload-call.cpp index 12dc5da..e2a4fd8 100644 --- a/test/SemaCXX/overload-call.cpp +++ b/test/SemaCXX/overload-call.cpp @@ -347,3 +347,15 @@ namespace test3 { foo(*P); // expected-error {{no matching function for call to 'foo'}} } } + +namespace DerivedToBaseVsVoid { + struct A { }; + struct B : A { }; + + float &f(void *); + int &f(const A*); + + void g(B *b) { + int &ir = f(b); + } +} diff --git a/test/SemaCXX/overload-member-call.cpp b/test/SemaCXX/overload-member-call.cpp index 22416f3..77d9965 100644 --- a/test/SemaCXX/overload-member-call.cpp +++ b/test/SemaCXX/overload-member-call.cpp @@ -89,7 +89,7 @@ namespace test1 { A a; a.foo(4, "hello"); //expected-error {{no matching member function for call to 'foo'}} - const A b; + const A b = A(); b.bar(0); //expected-error {{no matching member function for call to 'bar'}} a.baz(b); //expected-error {{no matching member function for call to 'baz'}} diff --git a/test/SemaCXX/overloaded-operator-decl.cpp b/test/SemaCXX/overloaded-operator-decl.cpp index c43d7c2..5f8655c 100644 --- a/test/SemaCXX/overloaded-operator-decl.cpp +++ b/test/SemaCXX/overloaded-operator-decl.cpp @@ -37,3 +37,9 @@ Y operator++(Y&, INT); X operator++(X&, FLOAT); // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'FLOAT' (aka 'float'))}} int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}} + +namespace PR6238 { + static struct { + void operator()(); + } plus; +} diff --git a/test/SemaCXX/overloaded-operator.cpp b/test/SemaCXX/overloaded-operator.cpp index 861d679..e07afe2 100644 --- a/test/SemaCXX/overloaded-operator.cpp +++ b/test/SemaCXX/overloaded-operator.cpp @@ -344,7 +344,7 @@ namespace pr5900 { int operator[](unsigned); // expected-note {{candidate}} }; int test1() { - const NonConstArray x; + const NonConstArray x = NonConstArray(); return x[0]; // expected-error {{no viable overloaded operator[] for type}} } diff --git a/test/SemaCXX/references.cpp b/test/SemaCXX/references.cpp index 630f53f..df8337b 100644 --- a/test/SemaCXX/references.cpp +++ b/test/SemaCXX/references.cpp @@ -102,3 +102,16 @@ string getInput(); void test9() { string &s = getInput(); // expected-error{{lvalue reference}} } + +void test10() { + __attribute((vector_size(16))) typedef int vec4; + typedef __attribute__(( ext_vector_type(4) )) int ext_vec4; + + vec4 v; + int &a = v[0]; // expected-error{{non-const reference cannot bind to vector element}} + const int &b = v[0]; + + ext_vec4 ev; + int &c = ev.x; // expected-error{{non-const reference cannot bind to vector element}} + const int &d = ev.x; +} diff --git a/test/SemaCXX/reinterpret-cast.cpp b/test/SemaCXX/reinterpret-cast.cpp index da67560..f7ab80e 100644 --- a/test/SemaCXX/reinterpret-cast.cpp +++ b/test/SemaCXX/reinterpret-cast.cpp @@ -47,7 +47,7 @@ void constness() // Invalid: T1 const* -> T2* (void)reinterpret_cast<int*>(icp); // expected-error {{reinterpret_cast from 'int const *' to 'int *' casts away constness}} // Invalid: T1*** -> T2 const* const** - int const *const **icpcpp = reinterpret_cast<int const* const**>(ipppc); // expected-error {{reinterpret_cast from 'int ***const' to 'int const *const **' casts away constness}} + int const *const **icpcpp = reinterpret_cast<int const* const**>(ipppc); // expected-error {{reinterpret_cast from 'int ***' to 'int const *const **' casts away constness}} // Valid: T1* -> T2* int *ip = reinterpret_cast<int*>(icpcpp); // Valid: T* -> T const* diff --git a/test/SemaCXX/static-cast.cpp b/test/SemaCXX/static-cast.cpp index cdaa843..4818b04 100644 --- a/test/SemaCXX/static-cast.cpp +++ b/test/SemaCXX/static-cast.cpp @@ -4,7 +4,7 @@ struct B : public A {}; // Single public base. struct C1 : public virtual B {}; // Single virtual base. struct C2 : public virtual B {}; struct D : public C1, public C2 {}; // Diamond -struct E : private A {}; // Single private base. expected-note 3 {{'private' inheritance specifier here}} +struct E : private A {}; // Single private base. expected-note 3 {{declared private here}} struct F : public C1 {}; // Single path to B with virtual. struct G1 : public B {}; struct G2 : public B {}; @@ -56,7 +56,7 @@ void t_529_2() // Bad code below (void)static_cast<void*>((const int*)0); // expected-error {{static_cast from 'int const *' to 'void *' is not allowed}} - (void)static_cast<A*>((E*)0); // expected-error {{inaccessible base class 'struct A'}} + (void)static_cast<A*>((E*)0); // expected-error {{private base class 'struct A'}} (void)static_cast<A*>((H*)0); // expected-error {{ambiguous conversion}} (void)static_cast<int>((int*)0); // expected-error {{static_cast from 'int *' to 'int' is not allowed}} (void)static_cast<A**>((B**)0); // expected-error {{static_cast from 'struct B **' to 'struct A **' is not allowed}} @@ -86,8 +86,8 @@ void t_529_5_8() (void)static_cast<D&>(*((A*)0)); // expected-error {{cannot cast 'struct A' to 'struct D &' via virtual base 'struct B'}} (void)static_cast<B*>((const A*)0); // expected-error {{static_cast from 'struct A const *' to 'struct B *' casts away constness}} (void)static_cast<B&>(*((const A*)0)); // expected-error {{static_cast from 'struct A const' to 'struct B &' casts away constness}} - (void)static_cast<E*>((A*)0); // expected-error {{cannot cast 'struct A' to 'struct E' due to inaccessible}} - (void)static_cast<E&>(*((A*)0)); // expected-error {{cannot cast 'struct A' to 'struct E' due to inaccessible}} + (void)static_cast<E*>((A*)0); // expected-error {{cannot cast private base class 'struct A' to 'struct E'}} + (void)static_cast<E&>(*((A*)0)); // expected-error {{cannot cast private base class 'struct A' to 'struct E'}} (void)static_cast<H*>((A*)0); // expected-error {{ambiguous cast from base 'struct A' to derived 'struct H':\n struct A -> struct B -> struct G1 -> struct H\n struct A -> struct B -> struct G2 -> struct H}} (void)static_cast<H&>(*((A*)0)); // expected-error {{ambiguous cast from base 'struct A' to derived 'struct H':\n struct A -> struct B -> struct G1 -> struct H\n struct A -> struct B -> struct G2 -> struct H}} (void)static_cast<E*>((B*)0); // expected-error {{static_cast from 'struct B *' to 'struct E *' is not allowed}} @@ -178,3 +178,6 @@ struct X4 { const X2 *x2; }; + +// PR5897 - accept static_cast from const void* to const int (*)[1]. +void PR5897() { (void)static_cast<const int(*)[1]>((const void*)0); } diff --git a/test/SemaCXX/templated-friend-decl.cpp b/test/SemaCXX/templated-friend-decl.cpp new file mode 100644 index 0000000..c0034cd --- /dev/null +++ b/test/SemaCXX/templated-friend-decl.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s + +template <typename T> +struct Foo { + template <typename U> + struct Bar {}; + + // The templated declaration for class Bar should not be instantiated when + // Foo<int> is. This is to protect against PR5848; for now, this "parses" but + // requires a rewrite of the templated friend code to be properly fixed. + template <typename U> + friend struct Bar; +}; + +Foo<int> x; diff --git a/test/SemaCXX/using-decl-1.cpp b/test/SemaCXX/using-decl-1.cpp index e8a7d70..30c4cfd 100644 --- a/test/SemaCXX/using-decl-1.cpp +++ b/test/SemaCXX/using-decl-1.cpp @@ -60,3 +60,38 @@ namespace P { g(f); } } + +// Make sure that ADL can find names brought in by using decls. +namespace test0 { + namespace ns { + class Foo {}; + + namespace inner { + void foo(char *); // expected-note {{no known conversion}} + } + + using inner::foo; + } + + void test(ns::Foo *p) { + foo(*p); // expected-error {{no matching function for call to 'foo'}} + } +} + +// Redeclarations! +namespace test1 { + namespace ns0 { struct Foo {}; } + namespace A { void foo(ns0::Foo *p, int y, int z); } + namespace ns2 { using A::foo; } + namespace ns1 { struct Bar : ns0::Foo {}; } + namespace A { void foo(ns0::Foo *p, int y, int z = 0); } // expected-note {{candidate}} + namespace ns1 { using A::foo; } + namespace ns2 { struct Baz : ns1::Bar {}; } + namespace A { void foo(ns0::Foo *p, int y = 0, int z); } + + void test(ns2::Baz *p) { + foo(p, 0, 0); // okay! + foo(p, 0); // should be fine! + foo(p); // expected-error {{no matching function}} + } +} diff --git a/test/SemaCXX/virtual-override.cpp b/test/SemaCXX/virtual-override.cpp index 5e1e9b0..09cbfad 100644 --- a/test/SemaCXX/virtual-override.cpp +++ b/test/SemaCXX/virtual-override.cpp @@ -29,14 +29,14 @@ class B : A { namespace T3 { struct a { }; -struct b : private a { }; // expected-note{{'private' inheritance specifier here}} +struct b : private a { }; // expected-note{{declared private here}} class A { virtual a* f(); // expected-note{{overridden virtual function is here}} }; class B : A { - virtual b* f(); // expected-error{{return type of virtual function 'f' is not covariant with the return type of the function it overrides (conversion from 'struct T3::b' to inaccessible base class 'struct T3::a')}} + virtual b* f(); // expected-error{{invalid covariant return for virtual function: 'struct T3::a' is a private base class of 'struct T3::b'}} }; } @@ -215,6 +215,29 @@ namespace PR6110 { Y1<Derived*, Base*> y; } +// Defer checking for covariance if either return type is dependent. +namespace type_dependent_covariance { + struct B {}; + template <int N> struct TD : public B {}; + template <> struct TD<1> {}; + + template <int N> struct TB {}; + struct D : public TB<0> {}; + + template <int N> struct X { + virtual B* f1(); // expected-note{{overridden virtual function is here}} + virtual TB<N>* f2(); // expected-note{{overridden virtual function is here}} + }; + template <int N, int M> struct X1 : X<N> { + virtual TD<M>* f1(); // expected-error{{return type of virtual function 'f1' is not covariant with the return type of the function it overrides ('TD<1> *'}} + virtual D* f2(); // expected-error{{return type of virtual function 'f2' is not covariant with the return type of the function it overrides ('struct type_dependent_covariance::D *' is not derived from 'TB<1> *')}} + }; + + X1<0, 0> good; + X1<0, 1> bad_derived; // expected-note{{instantiation}} + X1<1, 0> bad_base; // expected-note{{instantiation}} +} + namespace T10 { struct A { }; struct B : A { }; diff --git a/test/SemaCXX/warn-missing-noreturn.cpp b/test/SemaCXX/warn-missing-noreturn.cpp new file mode 100644 index 0000000..32d020f --- /dev/null +++ b/test/SemaCXX/warn-missing-noreturn.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wmissing-noreturn +void f() __attribute__((noreturn)); + +template<typename T> void g(T) { // expected-warning {{function could be attribute 'noreturn'}} + f(); +} + +template void g<int>(int); // expected-note {{in instantiation of function template specialization 'g<int>' requested here}} + +template<typename T> struct A { + void g() { // expected-warning {{function could be attribute 'noreturn'}} + f(); + } +}; + +template struct A<int>; // expected-note {{in instantiation of member function 'A<int>::g' requested here}} + +struct B { + template<typename T> void g(T) { // expected-warning {{function could be attribute 'noreturn'}} + f(); + } +}; + +template void B::g<int>(int); // expected-note {{in instantiation of function template specialization 'B::g<int>' requested here}} diff --git a/test/SemaCXX/warn-unused-variables.cpp b/test/SemaCXX/warn-unused-variables.cpp index 5620248..3b5349a 100644 --- a/test/SemaCXX/warn-unused-variables.cpp +++ b/test/SemaCXX/warn-unused-variables.cpp @@ -1,8 +1,7 @@ -// RUN: %clang -fsyntax-only -Wunused-variable -verify %s - +// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -verify %s template<typename T> void f() { - T t; - t = 17; + T t; + t = 17; } // PR5407 @@ -27,7 +26,7 @@ namespace PR5531 { }; void test() { - A(); + A(); // expected-warning{{expression result unused}} B(17); C(); } @@ -43,3 +42,12 @@ void bah() { x.foo(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}} x2->foo(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}} } + +template<typename T> +struct X0 { }; + +template<typename T> +void test_dependent_init(T *p) { + X0<int> i(p); + (void)i; +} diff --git a/test/SemaCXX/warn-weak-vtables.cpp b/test/SemaCXX/warn-weak-vtables.cpp new file mode 100644 index 0000000..1ea88a5 --- /dev/null +++ b/test/SemaCXX/warn-weak-vtables.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -Wweak-vtables + +struct A { // expected-warning {{'A' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}} + virtual void f() { } +}; + +template<typename T> struct B { + virtual void f() { } +}; + +namespace { + struct C { + virtual void f() { } + }; +} + +void f() { + struct A { + virtual void f() { } + }; +}
\ No newline at end of file diff --git a/test/SemaObjC/cocoa.m b/test/SemaObjC/cocoa.m index 9c92731..a8cfb72 100644 --- a/test/SemaObjC/cocoa.m +++ b/test/SemaObjC/cocoa.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -target-cpu pentium4 %s -print-stats +// RUN: %clang -arch x86_64 %s -fsyntax-only -Xclang -print-stats #ifdef __APPLE__ #include <Cocoa/Cocoa.h> #endif diff --git a/test/SemaObjC/default-synthesize.m b/test/SemaObjC/default-synthesize.m new file mode 100644 index 0000000..be2397b --- /dev/null +++ b/test/SemaObjC/default-synthesize.m @@ -0,0 +1,81 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s + +@interface NSString @end + +@interface NSObject @end + +@interface SynthItAll +@property int howMany; +@property (retain) NSString* what; +@end + +@implementation SynthItAll +//@synthesize howMany, what; +@end + + +@interface SynthSetter : NSObject +@property (nonatomic) int howMany; // REM: nonatomic to avoid warnings about only implementing one of the pair +@property (nonatomic, retain) NSString* what; +@end + +@implementation SynthSetter +//@synthesize howMany, what; + +- (int) howMany { + return howMany; +} +// - (void) setHowMany: (int) value + +- (NSString*) what { + return what; +} +// - (void) setWhat: (NSString*) value +@end + + +@interface SynthGetter : NSObject +@property (nonatomic) int howMany; // REM: nonatomic to avoid warnings about only implementing one of the pair +@property (nonatomic, retain) NSString* what; +@end + +@implementation SynthGetter +//@synthesize howMany, what; + +// - (int) howMany +- (void) setHowMany: (int) value { + howMany = value; +} + +// - (NSString*) what +- (void) setWhat: (NSString*) value { + if (what != value) { + } +} +@end + + +@interface SynthNone : NSObject +@property int howMany; +@property (retain) NSString* what; +@end + +@implementation SynthNone +//@synthesize howMany, what; // REM: Redundant anyway + +- (int) howMany { + return howMany; +} +- (void) setHowMany: (int) value { + howMany = value; +} + +- (NSString*) what { + return what; +} +- (void) setWhat: (NSString*) value { + if (what != value) { + } +} +@end + diff --git a/test/SemaObjC/duplicate-property-class-extension.m b/test/SemaObjC/duplicate-property-class-extension.m new file mode 100644 index 0000000..bdf4786c --- /dev/null +++ b/test/SemaObjC/duplicate-property-class-extension.m @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@interface Foo +@property (readonly) char foo; +@end + +@interface Foo () +@property (readwrite) char foo; // expected-note {{property declared here}} +@end + +@interface Foo () +@property (readwrite) char foo; // expected-error {{property has a previous declaration}} +@end diff --git a/test/SemaObjC/exprs.m b/test/SemaObjC/exprs.m index f4424f5..33b1444 100644 --- a/test/SemaObjC/exprs.m +++ b/test/SemaObjC/exprs.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify +// RUN: %clang_cc1 %s -fsyntax-only -verify -Wno-unreachable-code // rdar://6597252 Class test1(Class X) { diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m index e7550a7..7abfe96 100644 --- a/test/SemaObjC/format-strings-objc.m +++ b/test/SemaObjC/format-strings-objc.m @@ -29,15 +29,24 @@ extern void *_NSConstantStringClassReference; typedef const struct __CFString * CFStringRef; extern void CFStringCreateWithFormat(CFStringRef format, ...) __attribute__((format(CFString, 1, 2))); +int printf(const char * restrict, ...) ; + //===----------------------------------------------------------------------===// // Test cases. //===----------------------------------------------------------------------===// void check_nslog(unsigned k) { NSLog(@"%d%%", k); // no-warning - NSLog(@"%s%lb%d", "unix", 10,20); // expected-warning {{lid conversion '%lb'}} + NSLog(@"%s%lb%d", "unix", 10,20); // expected-warning {{invalid conversion specifier 'b'}} } // Check type validation extern void NSLog2(int format, ...) __attribute__((format(__NSString__, 1, 2))); // expected-error {{format argument not an NSString}} extern void CFStringCreateWithFormat2(int *format, ...) __attribute__((format(CFString, 1, 2))); // expected-error {{format argument not a CFString}} + +// <rdar://problem/7068334> - Catch use of long long with int arguments. +void rdar_7068334() { + long long test = 500; + printf("%i ",test); // expected-warning{{conversion specifies type 'int' but the argument has type 'long long'}} + NSLog(@"%i ",test); // expected-warning{{conversion specifies type 'int' but the argument has type 'long long'}} +} diff --git a/test/SemaObjC/method-arg-decay.m b/test/SemaObjC/method-arg-decay.m index 82bdc6d..f600029 100644 --- a/test/SemaObjC/method-arg-decay.m +++ b/test/SemaObjC/method-arg-decay.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -checker-cfref -verify %s +// RUN: %clang_cc1 -analyzer-check-objc-mem -verify %s typedef signed char BOOL; typedef int NSInteger; typedef unsigned int NSUInteger; diff --git a/test/SemaObjC/property-13.m b/test/SemaObjC/property-13.m index f34ec56..6d56dab 100644 --- a/test/SemaObjC/property-13.m +++ b/test/SemaObjC/property-13.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code @interface NSObject + alloc; diff --git a/test/SemaObjC/property-not-lvalue.m b/test/SemaObjC/property-not-lvalue.m index f1bda09..473ef86 100644 --- a/test/SemaObjC/property-not-lvalue.m +++ b/test/SemaObjC/property-not-lvalue.m @@ -18,3 +18,17 @@ void foo() { 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}} } + +// radar 7628953 + +@interface Gorf { +} +- (NSSize)size; +@end + +@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}} +} +- (NSSize)size {} +@end diff --git a/test/SemaObjC/protocol-warn.m b/test/SemaObjC/protocol-warn.m new file mode 100644 index 0000000..d0c51e3 --- /dev/null +++ b/test/SemaObjC/protocol-warn.m @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// radar 7638810 + +@protocol NSObject @end + +@interface NSObject <NSObject> @end + +@interface UIResponder : NSObject +@end + +@implementation UIResponder +@end + +@interface UIView : UIResponder +@end + +@implementation UIView +@end + +@interface UIWebTiledView : UIView +@end + +@implementation UIWebTiledView +@end + +@interface UIWebDocumentView : UIWebTiledView +@end + +@implementation UIWebDocumentView +@end + +@interface UIWebBrowserView : UIWebDocumentView +@end + +@implementation UIWebBrowserView +@end + +@interface UIPDFView : UIView +@end + +@implementation UIPDFView +@end + +@interface UIWebPDFView : UIPDFView +@end + +@implementation UIWebPDFView +@end + +UIWebPDFView *getView() +{ + UIWebBrowserView *browserView; + UIWebPDFView *pdfView; + return pdfView ? pdfView : browserView; // expected-warning {{incompatible pointer types returning 'UIView<NSObject> *', expected 'UIWebPDFView *'}} +} diff --git a/test/SemaObjCXX/reinterpret-cast-objc-pointertype.mm b/test/SemaObjCXX/reinterpret-cast-objc-pointertype.mm new file mode 100644 index 0000000..fcabade --- /dev/null +++ b/test/SemaObjCXX/reinterpret-cast-objc-pointertype.mm @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@interface NSString @end + +typedef const struct __CFString * CFStringRef; +const NSString* fRef; + +CFStringRef func() { + return reinterpret_cast<CFStringRef>(fRef); +} + +CFStringRef fRef1; + +const NSString* func1() { + return reinterpret_cast<const NSString*>(fRef1); +} + +@interface I @end +const I *fRef2; + +const NSString* func2() { + return reinterpret_cast<const NSString*>(fRef2); +} diff --git a/test/SemaTemplate/deduction.cpp b/test/SemaTemplate/deduction.cpp index 375d199..8d00bb7 100644 --- a/test/SemaTemplate/deduction.cpp +++ b/test/SemaTemplate/deduction.cpp @@ -86,3 +86,15 @@ int array4[is_same<Replace<vector<int, _2>, double, float>::type, vector<int, fl template <typename T, int N> void f(const T (&a)[N]); int iarr[] = { 1 }; void test_PR5911() { f(iarr); } + +// Must not examine base classes of incomplete type during template argument +// deduction. +namespace PR6257 { + template <typename T> struct X { + template <typename U> X(const X<U>& u); + }; + struct A; + void f(A& a); + void f(const X<A>& a); + void test(A& a) { (void)f(a); } +} diff --git a/test/SemaTemplate/default-expr-arguments.cpp b/test/SemaTemplate/default-expr-arguments.cpp index 131b80c..3da43fa 100644 --- a/test/SemaTemplate/default-expr-arguments.cpp +++ b/test/SemaTemplate/default-expr-arguments.cpp @@ -177,3 +177,10 @@ namespace PR5810 { X<float> x; // expected-note{{member function}} } } + +template<typename T> void f4(T, int = 17); +template<> void f4<int>(int, int); + +void f4_test(int i) { + f4(i); +} diff --git a/test/SemaTemplate/explicit-instantiation.cpp b/test/SemaTemplate/explicit-instantiation.cpp index 227856f..de51f09 100644 --- a/test/SemaTemplate/explicit-instantiation.cpp +++ b/test/SemaTemplate/explicit-instantiation.cpp @@ -76,3 +76,10 @@ template void print_type<double>(double*); // PR5069 template<int I> void foo0 (int (&)[I + 1]) { } template void foo0<2> (int (&)[3]); + +namespace explicit_instantiation_after_implicit_instantiation { + template <int I> struct X0 { static int x; }; + template <int I> int X0<I>::x; + void test1() { (void)&X0<1>::x; } + template struct X0<1>; +} diff --git a/test/SemaTemplate/instantiate-decl-init.cpp b/test/SemaTemplate/instantiate-decl-init.cpp index b0c2aa8..6b76d72 100644 --- a/test/SemaTemplate/instantiate-decl-init.cpp +++ b/test/SemaTemplate/instantiate-decl-init.cpp @@ -20,3 +20,27 @@ void fn(T t, const arg& arg) { void test() { fn(1, arg()); } + +struct X0 { }; + +struct X1 { + explicit X1(const X0 &x0 = X0()); +}; + +template<typename T> +void f0() { + X1 x1; +} + +template void f0<int>(); +template void f0<float>(); + +struct NonTrivial { + NonTrivial(); + ~NonTrivial(); +}; + +template<int N> void f1() { + NonTrivial array[N]; +} +template<> void f1<2>(); diff --git a/test/SemaTemplate/instantiate-declref-ice.cpp b/test/SemaTemplate/instantiate-declref-ice.cpp index e4e071d..e88b494 100644 --- a/test/SemaTemplate/instantiate-declref-ice.cpp +++ b/test/SemaTemplate/instantiate-declref-ice.cpp @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s - template<int i> struct x { static const int j = i; x<j>* y; @@ -10,7 +9,6 @@ const int x<i>::j; int array0[x<2>::j]; - template<typename T> struct X0 { static const unsigned value = sizeof(T); diff --git a/test/SemaTemplate/instantiate-declref.cpp b/test/SemaTemplate/instantiate-declref.cpp index da8b263..f883b93 100644 --- a/test/SemaTemplate/instantiate-declref.cpp +++ b/test/SemaTemplate/instantiate-declref.cpp @@ -87,3 +87,11 @@ struct smart_ptr { void test_smart_ptr(smart_ptr<int> p) { if (p) { } } + +// PR5517 +namespace test0 { + template <int K> struct X { + X() { extern void x(); } + }; + void g() { X<2>(); } +} diff --git a/test/SemaTemplate/instantiate-expr-1.cpp b/test/SemaTemplate/instantiate-expr-1.cpp index 663749d..d1b05f6 100644 --- a/test/SemaTemplate/instantiate-expr-1.cpp +++ b/test/SemaTemplate/instantiate-expr-1.cpp @@ -87,6 +87,18 @@ void add(const T &x) { (void)(x + x); } +namespace PR6237 { + template <typename T> + void f(T t) { + t++; + } + + struct B { }; + B operator++(B &, int); + + template void f(B); +} + struct Addable { Addable operator+(const Addable&) const; }; @@ -112,3 +124,16 @@ void test_call_operator(CallOperator call_op, int i, double d) { int &ir = test_call_operator<int&>(call_op, i); double &dr = test_call_operator<double&>(call_op, d); } + +template<typename T> +void test_asm(T t) { + asm ("nop" : "=a"(*t) : "r"(*t)); // expected-error {{indirection requires pointer operand ('int' invalid)}} +} + +void test_asm() { + int* a; + test_asm(a); + + int b; + test_asm(b); // expected-note {{in instantiation of function template specialization 'test_asm<int>' requested here}} +} diff --git a/test/SemaTemplate/instantiate-expr-4.cpp b/test/SemaTemplate/instantiate-expr-4.cpp index 428ef1b..c5eb3cc 100644 --- a/test/SemaTemplate/instantiate-expr-4.cpp +++ b/test/SemaTemplate/instantiate-expr-4.cpp @@ -173,8 +173,8 @@ struct is_pod { static const bool value = __is_pod(T); }; -static const int is_pod0[is_pod<X>::value? -1 : 1]; -static const int is_pod1[is_pod<Y>::value? 1 : -1]; +static int is_pod0[is_pod<X>::value? -1 : 1]; +static int is_pod1[is_pod<Y>::value? 1 : -1]; // --------------------------------------------------------------------- // initializer lists @@ -197,7 +197,7 @@ template struct InitList1<APair, int*>; template<typename T, typename Val1, typename Val2> struct InitList2 { void f(Val1 val1, Val2 val2) { - T x = { val1, val2 }; // expected-error{{incompatible}} + T x = { val1, val2 }; // expected-error{{cannot initialize}} } }; diff --git a/test/SemaTemplate/instantiate-local-class.cpp b/test/SemaTemplate/instantiate-local-class.cpp index 768eb21..72ad90a 100644 --- a/test/SemaTemplate/instantiate-local-class.cpp +++ b/test/SemaTemplate/instantiate-local-class.cpp @@ -32,3 +32,21 @@ namespace PR5764 { } } +// Instantiation of local classes with virtual functions. +namespace local_class_with_virtual_functions { + template <typename T> struct X { }; + template <typename T> struct Y { }; + + template <typename T> + void f() { + struct Z : public X<Y<T>*> { + virtual void g(Y<T>* y) { } + void g2(int x) {(void)x;} + }; + Z z; + (void)z; + } + + struct S { }; + void test() { f<S>(); } +} diff --git a/test/SemaTemplate/instantiate-member-initializers.cpp b/test/SemaTemplate/instantiate-member-initializers.cpp index f7b7e47..eecb445 100644 --- a/test/SemaTemplate/instantiate-member-initializers.cpp +++ b/test/SemaTemplate/instantiate-member-initializers.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -Wall -verify %s template<typename T> struct A { - A() : a(1) { } // expected-error{{incompatible type passing 'int', expected 'void *'}} + A() : a(1) { } // expected-error{{cannot initialize a member subobject of type 'void *' with an rvalue of type 'int'}} T a; }; diff --git a/test/SemaTemplate/instantiate-member-template.cpp b/test/SemaTemplate/instantiate-member-template.cpp index b4f0a9c..c1260cf 100644 --- a/test/SemaTemplate/instantiate-member-template.cpp +++ b/test/SemaTemplate/instantiate-member-template.cpp @@ -131,3 +131,28 @@ namespace N0 { x1.f(x0l); } } + +namespace PR6239 { + template <typename T> + struct X0 { + class type { + typedef T E; + template <E e> // subsitute T for E and bug goes away + struct sfinae { }; + + template <class U> + typename sfinae<&U::operator=>::type test(int); + }; + }; + + template <typename T> + struct X1 { + typedef T E; + template <E e> // subsitute T for E and bug goes away + struct sfinae { }; + + template <class U> + typename sfinae<&U::operator=>::type test(int); + }; + +} diff --git a/test/SemaTemplate/member-function-template.cpp b/test/SemaTemplate/member-function-template.cpp index 5ea8c101..aea6285 100644 --- a/test/SemaTemplate/member-function-template.cpp +++ b/test/SemaTemplate/member-function-template.cpp @@ -73,3 +73,15 @@ void test_incomplete_access(X1<int> *x1, X2<int> *x2) { float &fr = x1->get<float>(); (void)x2->get<float>(); // expected-error{{implicit instantiation of undefined template}} } + +// Instantiation of template template parameters in a member function +// template. +namespace TTP { + template<int Dim> struct X { + template<template<class> class M, class T> void f(const M<T>&); + }; + + template<typename T> struct Y { }; + + void test_f(X<3> x, Y<int> y) { x.f(y); } +} diff --git a/test/SemaTemplate/qualified-id.cpp b/test/SemaTemplate/qualified-id.cpp index 655a80e..2e3a826 100644 --- a/test/SemaTemplate/qualified-id.cpp +++ b/test/SemaTemplate/qualified-id.cpp @@ -29,3 +29,18 @@ namespace test2 { } }; } + +namespace PR6063 { + template <typename T> void f(T, T); + + namespace detail + { + using PR6063::f; + } + + template <typename T> + void g(T a, T b) + { + detail::f(a, b); + } +} diff --git a/test/SemaTemplate/recursive-template-instantiation.cpp b/test/SemaTemplate/recursive-template-instantiation.cpp index 0ddedaf..d6a0b24 100644 --- a/test/SemaTemplate/recursive-template-instantiation.cpp +++ b/test/SemaTemplate/recursive-template-instantiation.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -template<typename T> void f(T* t) { // expected-note{{candidate function}} +template<typename T> void f(T* t) { // expected-note{{failed template argument deduction}} f(*t); // expected-error{{no matching function}}\ // expected-note 3{{requested here}} } diff --git a/test/SemaTemplate/temp_arg_nontype.cpp b/test/SemaTemplate/temp_arg_nontype.cpp index 133b8db..fdfd4e4 100644 --- a/test/SemaTemplate/temp_arg_nontype.cpp +++ b/test/SemaTemplate/temp_arg_nontype.cpp @@ -34,16 +34,6 @@ public: }; A<X(17, 42)> *a11; // expected-error{{non-type template argument of type 'class X' must have an integral or enumeration type}} -template<X const *Ptr> struct A2; - -X *X_ptr; -X an_X; -X array_of_Xs[10]; -A2<X_ptr> *a12; -A2<array_of_Xs> *a13; -A2<&an_X> *a13_2; -A2<(&an_X)> *a13_3; // expected-error{{non-type template argument cannot be surrounded by parentheses}} - float f(float); float g(float); @@ -67,6 +57,7 @@ struct Y { } y; volatile X * X_volatile_ptr; template<X const &AnX> struct A4; // expected-note 2{{template parameter is declared here}} +X an_X; A4<an_X> *a15_1; // okay A4<*X_volatile_ptr> *a15_2; // expected-error{{reference binding of non-type template parameter of type 'class X const &' to template argument of type 'class X volatile' ignores qualifiers}} A4<y> *15_3; // expected-error{{non-type template parameter of reference type 'class X const &' cannot bind to template argument of type 'struct Y'}} \ @@ -170,3 +161,13 @@ struct X1 { void test_X0_X1() { X0<X1::pfunc> x01; } + +// PR6249 +namespace pr6249 { + template<typename T, T (*func)()> T f() { + return func(); + } + + int h(); + template int f<int, h>(); +} diff --git a/test/SemaTemplate/temp_class_spec.cpp b/test/SemaTemplate/temp_class_spec.cpp index e86f07a..8a07fd7 100644 --- a/test/SemaTemplate/temp_class_spec.cpp +++ b/test/SemaTemplate/temp_class_spec.cpp @@ -348,3 +348,16 @@ namespace PR6025 { { }; } + +namespace PR6181 { + template <class T> + class a; + + class s; + + template <class U> + class a<s> // expected-error{{partial specialization of 'a' does not use any of its template parameters}} + { + }; + +} diff --git a/test/SemaTemplate/template-id-expr.cpp b/test/SemaTemplate/template-id-expr.cpp index 70a1062..b3f41be 100644 --- a/test/SemaTemplate/template-id-expr.cpp +++ b/test/SemaTemplate/template-id-expr.cpp @@ -27,3 +27,20 @@ struct X0 { void test_X0_int(X0<int> xi, float f) { xi.f2(f); } + +// Not template-id expressions, but they almost look like it. +template<typename F> +struct Y { + Y(const F&); +}; + +template<int I> +struct X { + X(int, int); + void f() { + Y<X<I> >(X<I>(0, 0)); + Y<X<I> >(::X<I>(0, 0)); + } +}; + +template struct X<3>; diff --git a/test/SemaTemplate/typename-specifier-4.cpp b/test/SemaTemplate/typename-specifier-4.cpp index 7fd88f13..0a6fef7 100644 --- a/test/SemaTemplate/typename-specifier-4.cpp +++ b/test/SemaTemplate/typename-specifier-4.cpp @@ -68,3 +68,34 @@ struct X0 { void f2(typename X0<T>::Inner<T*, T&>::type); // expected-note{{here}} void f2(typename X0<T>::template Inner<T*, T&>::type); // expected-error{{redecl}} }; + +namespace PR6236 { + template<typename T, typename U> struct S { }; + + template<typename T> struct S<T, T> { + template<typename U> struct K { }; + + void f() { + typedef typename S<T, T>::template K<T> Foo; + } + }; +} + +namespace PR6268 { + template <typename T> + struct Outer { + template <typename U> + struct Inner {}; + + template <typename U> + typename Outer<T>::template Inner<U> + foo(typename Outer<T>::template Inner<U>); + }; + + template <typename T> + template <typename U> + typename Outer<T>::template Inner<U> + Outer<T>::foo(typename Outer<T>::template Inner<U>) { + return Inner<U>(); + } +} |