diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
commit | 4ba675006b5a8edfc48b6a9bd3dcf54a70cc08f2 (patch) | |
tree | 48b44512b5db8ced345df4a1a56b5065cf2a14d9 /test | |
parent | d7279c4c177bca357ef96ff1379fd9bc420bfe83 (diff) |
Notes
Diffstat (limited to 'test')
339 files changed, 7403 insertions, 721 deletions
diff --git a/test/ASTMerge/Inputs/class1.cpp b/test/ASTMerge/Inputs/class1.cpp new file mode 100644 index 0000000000000..e13faf0539b1b --- /dev/null +++ b/test/ASTMerge/Inputs/class1.cpp @@ -0,0 +1,8 @@ +struct A { + int x; +}; + +struct B : A { + float y; + float foo(); +}; diff --git a/test/ASTMerge/Inputs/class2.cpp b/test/ASTMerge/Inputs/class2.cpp new file mode 100644 index 0000000000000..91b84dc13b751 --- /dev/null +++ b/test/ASTMerge/Inputs/class2.cpp @@ -0,0 +1,8 @@ +struct A { + int x; +}; + +struct B : A { + int y; + int foo(); +}; diff --git a/test/ASTMerge/class.cpp b/test/ASTMerge/class.cpp new file mode 100644 index 0000000000000..114687f8d9847 --- /dev/null +++ b/test/ASTMerge/class.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/class1.cpp +// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/class2.cpp +// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +// CHECK: class1.cpp:5:8: warning: type 'B' has incompatible definitions in different translation units +// CHECK: class1.cpp:6:9: note: field 'y' has type 'float' here +// CHECK: class2.cpp:6:7: note: field 'y' has type 'int' here + +// FIXME: we should also complain about mismatched types on the method diff --git a/test/Analysis/PR7218.c b/test/Analysis/PR7218.c new file mode 100644 index 0000000000000..635e56f053ec7 --- /dev/null +++ b/test/Analysis/PR7218.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -verify %s +char PR7218(char a) { + char buf[2]; + buf[0] = a; + return buf[1]; // expected-warning {{Undefined or garbage value returned to caller}} +} diff --git a/test/Analysis/additive-folding-range-constraints.c b/test/Analysis/additive-folding-range-constraints.c new file mode 100644 index 0000000000000..a8ca5d2e351dc --- /dev/null +++ b/test/Analysis/additive-folding-range-constraints.c @@ -0,0 +1,99 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -verify -analyzer-constraints=range %s + +// These are used to trigger warnings. +typedef typeof(sizeof(int)) size_t; +void *malloc(size_t); +void free(void *); +#define NULL ((void*)0) +#define UINT_MAX (__INT_MAX__ *2U +1U) + +// Each of these adjusted ranges has an adjustment small enough to split the +// solution range across an overflow boundary (Min for <, Max for >). +// This corresponds to one set of branches in RangeConstraintManager. +void smallAdjustmentGT (unsigned a) { + char* b = NULL; + if (a+2 > 1) + b = malloc(1); + if (a == UINT_MAX-1 || a == UINT_MAX) + return; // no-warning + else if (a < UINT_MAX-1) + free(b); + return; // no-warning +} + +void smallAdjustmentGE (unsigned a) { + char* b = NULL; + if (a+2 >= 1) + b = malloc(1); + if (a == UINT_MAX-1) + return; // no-warning + else if (a < UINT_MAX-1 || a == UINT_MAX) + free(b); + return; // no-warning +} + +void smallAdjustmentLT (unsigned a) { + char* b = NULL; + if (a+1 < 2) + b = malloc(1); + if (a == 0 || a == UINT_MAX) + free(b); + return; // no-warning +} + +void smallAdjustmentLE (unsigned a) { + char* b = NULL; + if (a+1 <= 2) + b = malloc(1); + if (a == 0 || a == 1 || a == UINT_MAX) + free(b); + return; // no-warning +} + + +// Each of these adjusted ranges has an adjustment large enough to push the +// comparison value over an overflow boundary (Min for <, Max for >). +// This corresponds to one set of branches in RangeConstraintManager. +void largeAdjustmentGT (unsigned a) { + char* b = NULL; + if (a-2 > UINT_MAX-1) + b = malloc(1); + if (a == 1 || a == 0) + free(b); + else if (a > 1) + free(b); + return; // no-warning +} + +void largeAdjustmentGE (unsigned a) { + char* b = NULL; + if (a-2 >= UINT_MAX-1) + b = malloc(1); + if (a > 1) + return; // no-warning + else if (a == 1 || a == 0) + free(b); + return; // no-warning +} + +void largeAdjustmentLT (unsigned a) { + char* b = NULL; + if (a+2 < 1) + b = malloc(1); + if (a == UINT_MAX-1 || a == UINT_MAX) + free(b); + else if (a < UINT_MAX-1) + return; // no-warning + return; // no-warning +} + +void largeAdjustmentLE (unsigned a) { + char* b = NULL; + if (a+2 <= 1) + b = malloc(1); + if (a < UINT_MAX-1) + return; // no-warning + else if (a == UINT_MAX-1 || a == UINT_MAX) + free(b); + return; // no-warning +} diff --git a/test/Analysis/additive-folding.c b/test/Analysis/additive-folding.c new file mode 100644 index 0000000000000..15d758800adc3 --- /dev/null +++ b/test/Analysis/additive-folding.c @@ -0,0 +1,203 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -verify -analyzer-constraints=basic %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -verify -analyzer-constraints=range %s + +// These are used to trigger warnings. +typedef typeof(sizeof(int)) size_t; +void *malloc(size_t); +void free(void *); +#define NULL ((void*)0) +#define UINT_MAX -1U + +//--------------- +// Plus/minus +//--------------- + +void separateExpressions (int a) { + int b = a + 1; + --b; + + char* buf = malloc(1); + if (a != 0 && b == 0) + return; // no-warning + free(buf); +} + +void oneLongExpression (int a) { + // Expression canonicalization should still allow this to work, even though + // the first term is on the left. + int b = 15 + a + 15 - 10 - 20; + + char* buf = malloc(1); + if (a != 0 && b == 0) + return; // no-warning + free(buf); +} + +void mixedTypes (int a) { + char* buf = malloc(1); + + // Different additive types should not cause crashes when constant-folding. + // This is part of PR7406. + int b = a + 1LL; + if (a != 0 && (b-1) == 0) // not crash + return; // no warning + + int c = a + 1U; + if (a != 0 && (c-1) == 0) // not crash + return; // no warning + + free(buf); +} + +//--------------- +// Comparisons +//--------------- + +// Equality and inequality only +void eq_ne (unsigned a) { + char* b = NULL; + if (a == UINT_MAX) + b = malloc(1); + if (a+1 != 0) + return; // no-warning + if (a-1 != UINT_MAX-1) + return; // no-warning + free(b); +} + +void ne_eq (unsigned a) { + char* b = NULL; + if (a != UINT_MAX) + b = malloc(1); + if (a+1 == 0) + return; // no-warning + if (a-1 == UINT_MAX-1) + return; // no-warning + free(b); +} + +// Mixed typed inequalities (part of PR7406) +// These should not crash. +void mixed_eq_ne (int a) { + char* b = NULL; + if (a == 1) + b = malloc(1); + if (a+1U != 2) + return; // no-warning + if (a-1U != 0) + return; // no-warning + free(b); +} + +void mixed_ne_eq (int a) { + char* b = NULL; + if (a != 1) + b = malloc(1); + if (a+1U == 2) + return; // no-warning + if (a-1U == 0) + return; // no-warning + free(b); +} + + +// Simple order comparisons with no adjustment +void baselineGT (unsigned a) { + char* b = NULL; + if (a > 0) + b = malloc(1); + if (a == 0) + return; // no-warning + free(b); +} + +void baselineGE (unsigned a) { + char* b = NULL; + if (a >= UINT_MAX) + b = malloc(1); + if (a == UINT_MAX) + free(b); + return; // no-warning +} + +void baselineLT (unsigned a) { + char* b = NULL; + if (a < UINT_MAX) + b = malloc(1); + if (a == UINT_MAX) + return; // no-warning + free(b); +} + +void baselineLE (unsigned a) { + char* b = NULL; + if (a <= 0) + b = malloc(1); + if (a == 0) + free(b); + return; // no-warning +} + + +// Adjustment gives each of these an extra solution! +void adjustedGT (unsigned a) { + char* b = NULL; + if (a-1 > UINT_MAX-1) + b = malloc(1); + return; // expected-warning{{leak}} +} + +void adjustedGE (unsigned a) { + char* b = NULL; + if (a-1 >= UINT_MAX-1) + b = malloc(1); + if (a == UINT_MAX) + free(b); + return; // expected-warning{{leak}} +} + +void adjustedLT (unsigned a) { + char* b = NULL; + if (a+1 < 1) + b = malloc(1); + return; // expected-warning{{leak}} +} + +void adjustedLE (unsigned a) { + char* b = NULL; + if (a+1 <= 1) + b = malloc(1); + if (a == 0) + free(b); + return; // expected-warning{{leak}} +} + + +// Tautologies +void tautologyGT (unsigned a) { + char* b = malloc(1); + if (a > UINT_MAX) + return; // no-warning + free(b); +} + +void tautologyGE (unsigned a) { + char* b = malloc(1); + if (a >= 0) + free(b); + return; // no-warning +} + +void tautologyLT (unsigned a) { + char* b = malloc(1); + if (a < 0) + return; // no-warning + free(b); +} + +void tautologyLE (unsigned a) { + char* b = malloc(1); + if (a <= UINT_MAX) + free(b); + return; // no-warning +} diff --git a/test/Analysis/analyze_display_progress.c b/test/Analysis/analyze_display_progress.c new file mode 100644 index 0000000000000..958ed009ff10c --- /dev/null +++ b/test/Analysis/analyze_display_progress.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -analyze -analyzer-display-progress %s 2>&1 | FileCheck %s + +void f() {}; +void g() {}; +void h() {} + +// CHECK: analyze_display_progress.c f +// CHECK: analyze_display_progress.c g +// CHECK: analyze_display_progress.c h
\ No newline at end of file diff --git a/test/Analysis/bstring.c b/test/Analysis/bstring.c new file mode 100644 index 0000000000000..f4ddb0a3d080d --- /dev/null +++ b/test/Analysis/bstring.c @@ -0,0 +1,277 @@ +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s +// RUN: %clang_cc1 -analyze -DVARIANT -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -DVARIANT -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s + +//===----------------------------------------------------------------------=== +// Declarations +//===----------------------------------------------------------------------=== + +// Some functions are so similar to each other that they follow the same code +// path, such as memcpy and __memcpy_chk, or memcmp and bcmp. If VARIANT is +// defined, make sure to use the variants instead to make sure they are still +// checked by the analyzer. + +// Some functions are implemented as builtins. These should be #defined as +// BUILTIN(f), which will prepend "__builtin_" if USE_BUILTINS is defined. + +// Functions that have variants and are also availabe as builtins should be +// declared carefully! See memcpy() for an example. + +#ifdef USE_BUILTINS +# define BUILTIN(f) __builtin_ ## f +#else /* USE_BUILTINS */ +# define BUILTIN(f) f +#endif /* USE_BUILTINS */ + +typedef typeof(sizeof(int)) size_t; + +//===----------------------------------------------------------------------=== +// memcpy() +//===----------------------------------------------------------------------=== + +#ifdef VARIANT + +#define __memcpy_chk BUILTIN(__memcpy_chk) +void *__memcpy_chk(void *restrict s1, const void *restrict s2, size_t n, + size_t destlen); + +#define memcpy(a,b,c) __memcpy_chk(a,b,c,(size_t)-1) + +#else /* VARIANT */ + +#define memcpy BUILTIN(memcpy) +void *memcpy(void *restrict s1, const void *restrict s2, size_t n); + +#endif /* VARIANT */ + + +void memcpy0 () { + char src[] = {1, 2, 3, 4}; + char dst[4]; + + memcpy(dst, src, 4); // no-warning + + if (memcpy(dst, src, 4) != dst) { + (void)*(char*)0; // no-warning -- should be unreachable + } +} + +void memcpy1 () { + char src[] = {1, 2, 3, 4}; + char dst[10]; + + memcpy(dst, src, 5); // expected-warning{{out-of-bound}} +} + +void memcpy2 () { + char src[] = {1, 2, 3, 4}; + char dst[1]; + + memcpy(dst, src, 4); // expected-warning{{out-of-bound}} +} + +void memcpy3 () { + char src[] = {1, 2, 3, 4}; + char dst[3]; + + memcpy(dst+1, src+2, 2); // no-warning +} + +void memcpy4 () { + char src[] = {1, 2, 3, 4}; + char dst[10]; + + memcpy(dst+2, src+2, 3); // expected-warning{{out-of-bound}} +} + +void memcpy5() { + char src[] = {1, 2, 3, 4}; + char dst[3]; + + memcpy(dst+2, src+2, 2); // expected-warning{{out-of-bound}} +} + +void memcpy6() { + int a[4] = {0}; + memcpy(a, a, 8); // expected-warning{{overlapping}} +} + +void memcpy7() { + int a[4] = {0}; + memcpy(a+2, a+1, 8); // expected-warning{{overlapping}} +} + +void memcpy8() { + int a[4] = {0}; + memcpy(a+1, a+2, 8); // expected-warning{{overlapping}} +} + +void memcpy9() { + int a[4] = {0}; + memcpy(a+2, a+1, 4); // no-warning + memcpy(a+1, a+2, 4); // no-warning +} + +void memcpy10() { + char a[4] = {0}; + memcpy(0, a, 4); // expected-warning{{Null pointer argument in call to byte string function}} +} + +void memcpy11() { + char a[4] = {0}; + memcpy(a, 0, 4); // expected-warning{{Null pointer argument in call to byte string function}} +} + +void memcpy12() { + char a[4] = {0}; + memcpy(0, a, 0); // no-warning + memcpy(a, 0, 0); // no-warning +} + +//===----------------------------------------------------------------------=== +// memmove() +//===----------------------------------------------------------------------=== + +#ifdef VARIANT + +#define __memmove_chk BUILTIN(__memmove_chk) +void *__memmove_chk(void *s1, const void *s2, size_t n, size_t destlen); + +#define memmove(a,b,c) __memmove_chk(a,b,c,(size_t)-1) + +#else /* VARIANT */ + +#define memmove BUILTIN(memmove) +void *memmove(void *s1, const void *s2, size_t n); + +#endif /* VARIANT */ + + +void memmove0 () { + char src[] = {1, 2, 3, 4}; + char dst[4]; + + memmove(dst, src, 4); // no-warning + + if (memmove(dst, src, 4) != dst) { + (void)*(char*)0; // no-warning -- should be unreachable + } +} + +void memmove1 () { + char src[] = {1, 2, 3, 4}; + char dst[10]; + + memmove(dst, src, 5); // expected-warning{{out-of-bound}} +} + +void memmove2 () { + char src[] = {1, 2, 3, 4}; + char dst[1]; + + memmove(dst, src, 4); // expected-warning{{out-of-bound}} +} + +//===----------------------------------------------------------------------=== +// memcmp() +//===----------------------------------------------------------------------=== + +#ifdef VARIANT + +#define bcmp BUILTIN(bcmp) +// __builtin_bcmp is not defined with const in Builtins.def. +int bcmp(/*const*/ void *s1, /*const*/ void *s2, size_t n); +#define memcmp bcmp + +#else /* VARIANT */ + +#define memcmp BUILTIN(memcmp) +int memcmp(const void *s1, const void *s2, size_t n); + +#endif /* VARIANT */ + + +void memcmp0 () { + char a[] = {1, 2, 3, 4}; + char b[4] = { 0 }; + + memcmp(a, b, 4); // no-warning +} + +void memcmp1 () { + char a[] = {1, 2, 3, 4}; + char b[10] = { 0 }; + + memcmp(a, b, 5); // expected-warning{{out-of-bound}} +} + +void memcmp2 () { + char a[] = {1, 2, 3, 4}; + char b[1] = { 0 }; + + memcmp(a, b, 4); // expected-warning{{out-of-bound}} +} + +void memcmp3 () { + char a[] = {1, 2, 3, 4}; + + if (memcmp(a, a, 4)) + (void)*(char*)0; // no-warning +} + +void memcmp4 (char *input) { + char a[] = {1, 2, 3, 4}; + + if (memcmp(a, input, 4)) + (void)*(char*)0; // expected-warning{{null}} +} + +void memcmp5 (char *input) { + char a[] = {1, 2, 3, 4}; + + if (memcmp(a, 0, 0)) // no-warning + (void)*(char*)0; // no-warning + if (memcmp(0, a, 0)) // no-warning + (void)*(char*)0; // no-warning + if (memcmp(a, input, 0)) // no-warning + (void)*(char*)0; // no-warning +} + +void memcmp6 (char *a, char *b, size_t n) { + int result = memcmp(a, b, n); + if (result != 0) + return; + if (n == 0) + (void)*(char*)0; // expected-warning{{null}} +} + +//===----------------------------------------------------------------------=== +// bcopy() +//===----------------------------------------------------------------------=== + +#define bcopy BUILTIN(bcopy) +// __builtin_bcopy is not defined with const in Builtins.def. +void bcopy(/*const*/ void *s1, void *s2, size_t n); + + +void bcopy0 () { + char src[] = {1, 2, 3, 4}; + char dst[4]; + + bcopy(src, dst, 4); // no-warning +} + +void bcopy1 () { + char src[] = {1, 2, 3, 4}; + char dst[10]; + + bcopy(src, dst, 5); // expected-warning{{out-of-bound}} +} + +void bcopy2 () { + char src[] = {1, 2, 3, 4}; + char dst[1]; + + bcopy(src, dst, 4); // expected-warning{{out-of-bound}} +} diff --git a/test/Analysis/constant-folding.c b/test/Analysis/constant-folding.c new file mode 100644 index 0000000000000..6ed2b390cf7af --- /dev/null +++ b/test/Analysis/constant-folding.c @@ -0,0 +1,72 @@ +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-experimental-checks -verify %s + +// Trigger a warning if the analyzer reaches this point in the control flow. +#define WARN ((void)*(char*)0) + +// There should be no warnings unless otherwise indicated. + +void testComparisons (int a) { + // Sema can already catch the simple comparison a==a, + // since that's usually a logic error (and not path-dependent). + int b = a; + if (!(b==a)) WARN; + if (!(b>=a)) WARN; + if (!(b<=a)) WARN; + if (b!=a) WARN; + if (b>a) WARN; + if (b<a) WARN; +} + +void testSelfOperations (int a) { + if ((a|a) != a) WARN; + if ((a&a) != a) WARN; + if ((a^a) != 0) WARN; + if ((a-a) != 0) WARN; +} + +void testIdempotent (int a) { + if ((a*1) != a) WARN; + if ((a/1) != a) WARN; + if ((a+0) != a) WARN; + if ((a-0) != a) WARN; + if ((a<<0) != a) WARN; + if ((a>>0) != a) WARN; + if ((a^0) != a) WARN; + if ((a&(~0)) != a) WARN; + if ((a|0) != a) WARN; +} + +void testReductionToConstant (int a) { + if ((a*0) != 0) WARN; + if ((a&0) != 0) WARN; + if ((a|(~0)) != (~0)) WARN; +} + +void testSymmetricIntSymOperations (int a) { + if ((2+a) != (a+2)) WARN; + if ((2*a) != (a*2)) WARN; + if ((2&a) != (a&2)) WARN; + if ((2^a) != (a^2)) WARN; + if ((2|a) != (a|2)) WARN; +} + +void testAsymmetricIntSymOperations (int a) { + if (((~0) >> a) != (~0)) WARN; + if ((0 >> a) != 0) WARN; + if ((0 << a) != 0) WARN; + + // Unsigned right shift shifts in zeroes. + if ((((unsigned)(~0)) >> ((unsigned) a)) != ((unsigned)(~0))) + WARN; // expected-warning{{}} +} + +void testLocations (char *a) { + char *b = a; + if (!(b==a)) WARN; + if (!(b>=a)) WARN; + if (!(b<=a)) WARN; + if (b!=a) WARN; + if (b>a) WARN; + if (b<a) WARN; + if (b-a) WARN; +} diff --git a/test/Analysis/dead-stores.c b/test/Analysis/dead-stores.c index 1c600276ba43b..defd7e0b7bdf9 100644 --- a/test/Analysis/dead-stores.c +++ b/test/Analysis/dead-stores.c @@ -300,11 +300,11 @@ void f22() { case 7: (void)(0 && x); (void)y7; - (void)(0 || (y8, ({ return; }), 1)); + (void)(0 || (y8, ({ return; }), 1)); // expected-warning {{expression result unused}} (void)x; break; case 8: - (void)(1 && (y9, ({ return; }), 1)); + (void)(1 && (y9, ({ return; }), 1)); // expected-warning {{expression result unused}} (void)x; break; case 9: diff --git a/test/Analysis/dead-stores.cpp b/test/Analysis/dead-stores.cpp index 22d446e170212..b21ffad6c5f07 100644 --- a/test/Analysis/dead-stores.cpp +++ b/test/Analysis/dead-stores.cpp @@ -92,3 +92,11 @@ void test3_e(int &x) { int &y = x; } +//===----------------------------------------------------------------------===// +// Dead stores involving 'new' +//===----------------------------------------------------------------------===// + +static void test_new(unsigned n) { + char **p = new char* [n]; // expected-warning{{never read}} +} + diff --git a/test/Analysis/free.c b/test/Analysis/free.c new file mode 100644 index 0000000000000..60bb3f2eb5a65 --- /dev/null +++ b/test/Analysis/free.c @@ -0,0 +1,71 @@ +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -fblocks -verify %s +void free(void *); + +void t1 () { + int a[] = { 1 }; + free(a); // expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}} +} + +void t2 () { + int a = 1; + free(&a); // expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}} +} + +void t3 () { + static int a[] = { 1 }; + free(a); // expected-warning {{Argument to free() is the address of the static variable 'a', which is not memory allocated by malloc()}} +} + +void t4 (char *x) { + free(x); // no-warning +} + +void t5 () { + extern char *ptr(); + free(ptr()); // no-warning +} + +void t6 () { + free((void*)1000); // expected-warning {{Argument to free() is a constant address (1000), which is not memory allocated by malloc()}} +} + +void t7 (char **x) { + free(*x); // no-warning +} + +void t8 (char **x) { + // ugh + free((*x)+8); // no-warning +} + +void t9 () { +label: + free(&&label); // expected-warning {{Argument to free() is the address of the label 'label', which is not memory allocated by malloc()}} +} + +void t10 () { + free((void*)&t10); // expected-warning {{Argument to free() is the address of the function 't10', which is not memory allocated by malloc()}} +} + +void t11 () { + char *p = (char*)__builtin_alloca(2); + free(p); // expected-warning {{Argument to free() was allocated by alloca(), not malloc()}} +} + +void t12 () { + free(^{return;}); // expected-warning {{Argument to free() is a block, which is not memory allocated by malloc()}} +} + +void t13 (char a) { + free(&a); // expected-warning {{Argument to free() is the address of the parameter 'a', which is not memory allocated by malloc()}} +} + +static int someGlobal[2]; +void t14 () { + free(someGlobal); // expected-warning {{Argument to free() is the address of the global variable 'someGlobal', which is not memory allocated by malloc()}} +} + +void t15 (char **x, int offset) { + // Unknown value + free(x[offset]); // no-warning +} diff --git a/test/Analysis/idempotent-operations.c b/test/Analysis/idempotent-operations.c new file mode 100644 index 0000000000000..9cef08edc43f8 --- /dev/null +++ b/test/Analysis/idempotent-operations.c @@ -0,0 +1,52 @@ +// RUN: %clang_cc1 -analyze -analyzer-idempotent-operation -analyzer-store=region -analyzer-constraints=range -fblocks -verify -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -verify %s + +// Basic tests + +extern void test(int i); + +void basic() { + int x = 10, zero = 0, one = 1; + + // x op x + x = x; // expected-warning {{idempotent operation; both operands are always equal in value}} + test(x - x); // expected-warning {{idempotent operation; both operands are always equal in value}} + x -= x; // expected-warning {{idempotent operation; both operands are always equal in value}} + x = 10; // no-warning + test(x / x); // expected-warning {{idempotent operation; both operands are always equal in value}} + x /= x; // expected-warning {{idempotent operation; both operands are always equal in value}} + x = 10; // no-warning + test(x & x); // expected-warning {{idempotent operation; both operands are always equal in value}} + x &= x; // expected-warning {{idempotent operation; both operands are always equal in value}} + test(x | x); // expected-warning {{idempotent operation; both operands are always equal in value}} + x |= x; // expected-warning {{idempotent operation; both operands are always equal in value}} + + // x op 1 + test(x * one); // expected-warning {{idempotent operation; the right operand is always 1}} + x *= one; // expected-warning {{idempotent operation; the right operand is always 1}} + test(x / one); // expected-warning {{idempotent operation; the right operand is always 1}} + x /= one; // expected-warning {{idempotent operation; the right operand is always 1}} + + // 1 op x + test(one * x); // expected-warning {{idempotent operation; the left operand is always 1}} + + // x op 0 + test(x + zero); // expected-warning {{idempotent operation; the right operand is always 0}} + test(x - zero); // expected-warning {{idempotent operation; the right operand is always 0}} + test(x * zero); // expected-warning {{idempotent operation; the right operand is always 0}} + test(x & zero); // expected-warning {{idempotent operation; the right operand is always 0}} + test(x | zero); // expected-warning {{idempotent operation; the right operand is always 0}} + test(x ^ zero); // expected-warning {{idempotent operation; the right operand is always 0}} + test(x << zero); // expected-warning {{idempotent operation; the right operand is always 0}} + test(x >> zero); // expected-warning {{idempotent operation; the right operand is always 0}} + + // 0 op x + test(zero + x); // expected-warning {{idempotent operation; the left operand is always 0}} + test(zero - x); // expected-warning {{idempotent operation; the left operand is always 0}} + test(zero / x); // expected-warning {{idempotent operation; the left operand is always 0}} + test(zero * x); // expected-warning {{idempotent operation; the left operand is always 0}} + test(zero & x); // expected-warning {{idempotent operation; the left operand is always 0}} + test(zero | x); // expected-warning {{idempotent operation; the left operand is always 0}} + test(zero ^ x); // expected-warning {{idempotent operation; the left operand is always 0}} + test(zero << x); // expected-warning {{idempotent operation; the left operand is always 0}} + test(zero >> x); // expected-warning {{idempotent operation; the left operand is always 0}} +} diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index fe24bc19e61c4..b4c1314b34cfe 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -75,5 +75,49 @@ void PR6123() { void PR7217() { int *buf = malloc(2); // expected-warning{{Cast a region whose size is not a multiple of the destination type size.}} buf[1] = 'c'; // not crash +} + +void mallocCastToVoid() { + void *p = malloc(2); + const void *cp = p; // not crash + free(p); +} + +void mallocCastToFP() { + void *p = malloc(2); + void (*fp)() = p; // not crash + free(p); +} + +// This tests that malloc() buffers are undefined by default +char mallocGarbage () { + char *buf = malloc(2); + char result = buf[1]; // expected-warning{{undefined}} + free(buf); + return result; +} + +// This tests that calloc() buffers need to be freed +void callocNoFree () { + char *buf = calloc(2,2); + return; // expected-warning{{never released}} +} + +// These test that calloc() buffers are zeroed by default +char callocZeroesGood () { + char *buf = calloc(2,2); + char result = buf[3]; // no-warning + if (buf[1] == 0) { + free(buf); + } + return result; // no-warning +} +char callocZeroesBad () { + char *buf = calloc(2,2); + char result = buf[3]; // no-warning + if (buf[1] != 0) { + free(buf); + } + return result; // expected-warning{{never released}} } diff --git a/test/Analysis/misc-ps-region-store.m b/test/Analysis/misc-ps-region-store.m index 52516abc397bd..6b4f658a3f856 100644 --- a/test/Analysis/misc-ps-region-store.m +++ b/test/Analysis/misc-ps-region-store.m @@ -1033,3 +1033,11 @@ double rdar_8032791_1() { return x; } +// PR 7450 - Handle pointer arithmetic with __builtin_alloca +void pr_7450_aux(void *x); +void pr_7450() { + void *p = __builtin_alloca(10); + // Don't crash when analyzing the following statement. + pr_7450_aux(p + 8); +} + diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m index 8323c62390e84..b1d47e214ef79 100644 --- a/test/Analysis/misc-ps.m +++ b/test/Analysis/misc-ps.m @@ -582,7 +582,7 @@ void pr4781(unsigned long *raw1) { - (id) foo { if (self) return self; - *((int *) 0x0) = 0xDEADBEEF; // no-warning + *((volatile int *) 0x0) = 0xDEADBEEF; // no-warning return self; } @end @@ -971,3 +971,52 @@ void r7979430(id x) { @synchronized(x) {} } +//===----------------------------------------------------------------------=== +// PR 7361 - Test that functions wrapped in macro instantiations are analyzed. +//===----------------------------------------------------------------------=== +#define MAKE_TEST_FN() \ + void test_pr7361 (char a) {\ + char* b = 0x0; *b = a;\ + } + +MAKE_TEST_FN() // expected-warning{{null pointer}} + +//===----------------------------------------------------------------------=== +// PR 7491 - Test that symbolic expressions can be used as conditions. +//===----------------------------------------------------------------------=== + +void pr7491 () { + extern int getint(); + int a = getint()-1; + if (a) { + return; + } + if (!a) { + return; + } else { + // Should be unreachable + (void)*(char*)0; // no-warning + } +} + +//===----------------------------------------------------------------------=== +// PR 7475 - Test that assumptions about global variables are reset after +// calling a global function. +//===----------------------------------------------------------------------=== + +int *pr7475_someGlobal; +void pr7475_setUpGlobal(); + +void pr7475() { + if (pr7475_someGlobal == 0) + pr7475_setUpGlobal(); + *pr7475_someGlobal = 0; // no-warning +} + +void pr7475_warn() { + static int *someStatic = 0; + if (someStatic == 0) + pr7475_setUpGlobal(); + *someStatic = 0; // expected-warning{{null pointer}} +} + diff --git a/test/Analysis/no-outofbounds.c b/test/Analysis/no-outofbounds.c index 771323b811143..a97b68e2d6df5 100644 --- a/test/Analysis/no-outofbounds.c +++ b/test/Analysis/no-outofbounds.c @@ -12,3 +12,20 @@ void f() { short *z = (short*) &x; short s = z[0] + z[1]; // no-warning } + +void g() { + int a[2]; + char *b = (char*)a; + b[3] = 'c'; // no-warning +} + +typedef typeof(sizeof(int)) size_t; +void *malloc(size_t); +void free(void *); + +void field() { + struct vec { size_t len; int data[0]; }; + struct vec *a = malloc(sizeof(struct vec) + 10); + a->len = 10; + a->data[1] = 5; // no-warning +} diff --git a/test/Analysis/null-deref-ps.c b/test/Analysis/null-deref-ps.c index 5a1049c7d71ec..7ca22ada7da7f 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 -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 +// 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 -Wreturn-type +// 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 -Wreturn-type +// 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 -Wreturn-type +// 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 -Wreturn-type typedef unsigned uintptr_t; @@ -118,6 +118,11 @@ void f6d(int *p) { } } +void f6e(int *p, int offset) { + // PR7406 - crash from treating an UnknownVal as defined, to see if it's 0. + bar((p+offset)+1, 0); // not crash +} + int* qux(); int f7(int x) { diff --git a/test/Analysis/outofbound.c b/test/Analysis/outofbound.c index e1ff66ccf4dc1..9b487300c88ad 100644 --- a/test/Analysis/outofbound.c +++ b/test/Analysis/outofbound.c @@ -2,6 +2,7 @@ typedef __typeof(sizeof(int)) size_t; void *malloc(size_t); +void *calloc(size_t, size_t); char f1() { char* s = "abcd"; @@ -36,3 +37,37 @@ void f4() { p[1] = a; // no-warning p[2] = a; // expected-warning{{Access out-of-bound array element (buffer overflow)}} } + +void f5() { + char *p = calloc(2,2); + p[3] = '.'; // no-warning + p[4] = '!'; // expected-warning{{out-of-bound}} +} + +void f6() { + char a[2]; + int *b = (int*)a; + b[1] = 3; // expected-warning{{out-of-bound}} +} + +void f7() { + struct three_words a; + a.c[3] = 1; // expected-warning{{out-of-bound}} +} + +void vla(int a) { + if (a == 5) { + int x[a]; + x[4] = 4; // no-warning + x[5] = 5; // expected-warning{{out-of-bound}} + } +} + +void sizeof_vla(int a) { + if (a == 5) { + char x[a]; + int y[sizeof(x)]; + y[4] = 4; // no-warning + y[5] = 5; // expected-warning{{out-of-bound}} + } +} diff --git a/test/Analysis/ptr-arith.c b/test/Analysis/ptr-arith.c index f6bd61c074a33..0c2e221398216 100644 --- a/test/Analysis/ptr-arith.c +++ b/test/Analysis/ptr-arith.c @@ -1,6 +1,9 @@ // 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 +// Used to trigger warnings for unreachable paths. +#define WARN do { int a, b; int c = &b-&a; } while (0) + void f1() { int a[10]; int *p = a; @@ -60,3 +63,226 @@ void f5() { void f6(int *p, int *q) { int d = q - p; // no-warning } + +void null_operand(int *a) { +start: + // LHS is a label, RHS is NULL + if (&&start == 0) + WARN; // no-warning + if (&&start < 0) + WARN; // no-warning + if (&&start <= 0) + WARN; // no-warning + if (!(&&start != 0)) + WARN; // no-warning + if (!(&&start > 0)) + WARN; // no-warning + if (!(&&start >= 0)) + WARN; // no-warning + if (!(&&start - 0)) + WARN; // no-warning + + // LHS is a non-symbolic value, RHS is NULL + if (&a == 0) + WARN; // no-warning + if (&a < 0) + WARN; // no-warning + if (&a <= 0) + WARN; // no-warning + if (!(&a != 0)) + WARN; // no-warning + if (!(&a > 0)) + WARN; // no-warning + if (!(&a >= 0)) + WARN; // no-warning + + if (!(&a - 0)) // expected-warning{{Pointer arithmetic done on non-array variables}} + WARN; // no-warning + + // LHS is NULL, RHS is non-symbolic + // The same code is used for labels and non-symbolic values. + if (0 == &a) + WARN; // no-warning + if (0 > &a) + WARN; // no-warning + if (0 >= &a) + WARN; // no-warning + if (!(0 != &a)) + WARN; // no-warning + if (!(0 < &a)) + WARN; // no-warning + if (!(0 <= &a)) + WARN; // no-warning + + // LHS is a symbolic value, RHS is NULL + if (a == 0) + WARN; // expected-warning{{}} + if (a < 0) + WARN; // no-warning + if (a <= 0) + WARN; // expected-warning{{}} + if (!(a != 0)) + WARN; // expected-warning{{}} + if (!(a > 0)) + WARN; // expected-warning{{}} + if (!(a >= 0)) + WARN; // no-warning + if (!(a - 0)) + WARN; // expected-warning{{}} + + // LHS is NULL, RHS is a symbolic value + if (0 == a) + WARN; // expected-warning{{}} + if (0 > a) + WARN; // no-warning + if (0 >= a) + WARN; // expected-warning{{}} + if (!(0 != a)) + WARN; // expected-warning{{}} + if (!(0 < a)) + WARN; // expected-warning{{}} + if (!(0 <= a)) + WARN; // no-warning +} + +void const_locs() { + char *a = (char*)0x1000; + char *b = (char*)0x1100; +start: + if (a==b) + WARN; // no-warning + if (!(a!=b)) + WARN; // no-warning + if (a>b) + WARN; // no-warning + if (b<a) + WARN; // no-warning + if (a>=b) + WARN; // no-warning + if (b<=a) + WARN; // no-warning + if (b-a != 0x100) + WARN; // no-warning + + if (&&start == a) + WARN; // expected-warning{{}} + if (a == &&start) + WARN; // expected-warning{{}} + if (&a == (char**)a) + WARN; // expected-warning{{}} + if ((char**)a == &a) + WARN; // expected-warning{{}} +} + +void array_matching_types() { + int array[10]; + int *a = &array[2]; + int *b = &array[5]; + + if (a==b) + WARN; // no-warning + if (!(a!=b)) + WARN; // no-warning + if (a>b) + WARN; // no-warning + if (b<a) + WARN; // no-warning + if (a>=b) + WARN; // no-warning + if (b<=a) + WARN; // no-warning + if ((b-a) == 0) + WARN; // no-warning +} + +// This takes a different code path than array_matching_types() +void array_different_types() { + int array[10]; + int *a = &array[2]; + char *b = (char*)&array[5]; + + if (a==b) // expected-warning{{comparison of distinct pointer types}} + WARN; // no-warning + if (!(a!=b)) // expected-warning{{comparison of distinct pointer types}} + WARN; // no-warning + if (a>b) // expected-warning{{comparison of distinct pointer types}} + WARN; // no-warning + if (b<a) // expected-warning{{comparison of distinct pointer types}} + WARN; // no-warning + if (a>=b) // expected-warning{{comparison of distinct pointer types}} + WARN; // no-warning + if (b<=a) // expected-warning{{comparison of distinct pointer types}} + WARN; // no-warning +} + +struct test { int x; int y; }; +void struct_fields() { + struct test a, b; + + if (&a.x == &a.y) + WARN; // no-warning + if (!(&a.x != &a.y)) + WARN; // no-warning + if (&a.x > &a.y) + WARN; // no-warning + if (&a.y < &a.x) + WARN; // no-warning + if (&a.x >= &a.y) + WARN; // no-warning + if (&a.y <= &a.x) + WARN; // no-warning + + if (&a.x == &b.x) + WARN; // no-warning + if (!(&a.x != &b.x)) + WARN; // no-warning + if (&a.x > &b.x) + WARN; // expected-warning{{}} + if (&b.x < &a.x) + WARN; // expected-warning{{}} + if (&a.x >= &b.x) + WARN; // expected-warning{{}} + if (&b.x <= &a.x) + WARN; // expected-warning{{}} +} + +void mixed_region_types() { + struct test s; + int array[2]; + void *a = &array, *b = &s; + + if (&a == &b) + WARN; // no-warning + if (!(&a != &b)) + WARN; // no-warning + if (&a > &b) + WARN; // expected-warning{{}} + if (&b < &a) + WARN; // expected-warning{{}} + if (&a >= &b) + WARN; // expected-warning{{}} + if (&b <= &a) + WARN; // expected-warning{{}} +} + +void symbolic_region(int *p) { + int a; + + if (&a == p) + WARN; // expected-warning{{}} + if (&a != p) + WARN; // expected-warning{{}} + if (&a > p) + WARN; // expected-warning{{}} + if (&a < p) + WARN; // expected-warning{{}} + if (&a >= p) + WARN; // expected-warning{{}} + if (&a <= p) + WARN; // expected-warning{{}} +} + +void PR7527 (int *p) { + if (((int) p) & 1) // not crash + return; +} diff --git a/test/Analysis/rdar-6442306-1.m b/test/Analysis/rdar-6442306-1.m index a2af94637d0e7..dfe9b722d13fe 100644 --- a/test/Analysis/rdar-6442306-1.m +++ b/test/Analysis/rdar-6442306-1.m @@ -10,7 +10,7 @@ struct QuxSize {}; typedef struct QuxSize QuxSize; typedef struct { Foo_record_t Foo; - QuxSize size; + QuxSize size[0]; } __Request__SetPortalSize_t; double __Foo_READSWAP__double(double*); diff --git a/test/Analysis/rdar-7168531.m b/test/Analysis/rdar-7168531.m index bb34713b41f68..5a7b08584f57a 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 -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 +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -triple i386-apple-darwin10 -analyzer-store=region %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -triple i386-apple-darwin10 -analyzer-store=basic %s // 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/reference.cpp b/test/Analysis/reference.cpp index 54d7cf57e0c40..f1694163a20c9 100644 --- a/test/Analysis/reference.cpp +++ b/test/Analysis/reference.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s +typedef typeof(sizeof(int)) size_t; +void malloc (size_t); void f1() { int const &i = 3; @@ -9,3 +11,46 @@ void f1() { if (b != 3) *p = 1; // no-warning } + +char* ptr(); +char& ref(); + +// These next two tests just shouldn't crash. +char t1 () { + ref() = 'c'; + return '0'; +} + +// just a sanity test, the same behavior as t1() +char t2 () { + *ptr() = 'c'; + return '0'; +} + +// Each of the tests below is repeated with pointers as well as references. +// This is mostly a sanity check, but then again, both should work! +char t3 () { + char& r = ref(); + r = 'c'; // no-warning + if (r) return r; + return *(char*)0; // no-warning +} + +char t4 () { + char* p = ptr(); + *p = 'c'; // no-warning + if (*p) return *p; + return *(char*)0; // no-warning +} + +char t5 (char& r) { + r = 'c'; // no-warning + if (r) return r; + return *(char*)0; // no-warning +} + +char t6 (char* p) { + *p = 'c'; // no-warning + if (*p) return *p; + return *(char*)0; // no-warning +} diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index 9e5151d167048..c9c7d271347b1 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -468,6 +468,20 @@ void f16(int x, CFTypeRef p) { } } +// Test that an object is non-null after being CFRetained/CFReleased. +void f17(int x, CFTypeRef p) { + if (x) { + CFRelease(p); + if (!p) + CFRelease(0); // no-warning + } + else { + CFRetain(p); + if (!p) + CFRetain(0); // no-warning + } +} + // Test basic tracking of ivars associated with 'self'. For the retain/release // checker we currently do not want to flag leaks associated with stores // of tracked objects to ivars. diff --git a/test/Analysis/stack-addr-ps.c b/test/Analysis/stack-addr-ps.c index f8cadbe281be6..342b3b1430a20 100644 --- a/test/Analysis/stack-addr-ps.c +++ b/test/Analysis/stack-addr-ps.c @@ -3,11 +3,11 @@ int* f1() { int x = 0; - return &x; // expected-warning{{Address of stack memory associated with local variable 'x' returned.}} expected-warning{{address of stack memory associated with local variable 'x' returned}} + return &x; // expected-warning{{Address of stack memory associated with local variable 'x' returned}} expected-warning{{address of stack memory associated with local variable 'x' returned}} } int* f2(int y) { - return &y; // expected-warning{{Address of stack memory associated with local variable 'y' returned.}} expected-warning{{address of stack memory associated with local variable 'y' returned}} + return &y; // expected-warning{{Address of stack memory associated with local variable 'y' returned}} expected-warning{{address of stack memory associated with local variable 'y' returned}} } int* f3(int x, int *y) { @@ -16,7 +16,7 @@ int* f3(int x, int *y) { if (x) y = &w; - return y; // expected-warning{{Address of stack memory associated with local variable 'w' returned.}} + return y; // expected-warning{{Address of stack memory associated with local variable 'w' returned to caller}} } void* compound_literal(int x, int y) { diff --git a/test/Analysis/stackaddrleak.c b/test/Analysis/stackaddrleak.c new file mode 100644 index 0000000000000..39808ed873c80 --- /dev/null +++ b/test/Analysis/stackaddrleak.c @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -verify %s + +char const *p; + +void f0() { + char const str[] = "This will change"; + p = str; // expected-warning{{Address of stack memory associated with local variable 'str' is still referred to by the global variable 'p' upon returning to the caller. This will be a dangling reference}} +} + +void f1() { + char const str[] = "This will change"; + p = str; + p = 0; // no-warning +} + +void f2() { + p = (const char *) __builtin_alloca(12); // expected-warning{{Address of stack memory allocated by call to alloca() on line 17 is still referred to by the global variable 'p' upon returning to the caller. This will be a dangling reference}} +} + +// PR 7383 - previosly the stack address checker would crash on this example +// because it would attempt to do a direct load from 'pr7383_list'. +static int pr7383(__const char *__) +{ + return 0; +} +extern __const char *__const pr7383_list[]; + +// Test that we catch multiple returns via globals when analyzing a function. +void test_multi_return() { + static int *a, *b; + int x; + a = &x; + b = &x; // expected-warning{{Address of stack memory associated with local variable 'x' is still referred to by the global variable 'a' upon returning}} expected-warning{{Address of stack memory associated with local variable 'x' is still referred to by the global variable 'b' upon returning}} +} diff --git a/test/Analysis/stream.c b/test/Analysis/stream.c new file mode 100644 index 0000000000000..2b6a90353b9bd --- /dev/null +++ b/test/Analysis/stream.c @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -analyzer-store region -verify %s + +typedef __typeof__(sizeof(int)) size_t; +typedef struct _IO_FILE FILE; +#define SEEK_SET 0 /* Seek from beginning of file. */ +#define SEEK_CUR 1 /* Seek from current position. */ +#define SEEK_END 2 /* Seek from end of file. */ +extern FILE *fopen(const char *path, const char *mode); +extern size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); +extern int fseek (FILE *__stream, long int __off, int __whence); +extern long int ftell (FILE *__stream); +extern void rewind (FILE *__stream); + +void f1(void) { + FILE *p = fopen("foo", "r"); + char buf[1024]; + fread(buf, 1, 1, p); // expected-warning {{Stream pointer might be NULL.}} +} + +void f2(void) { + FILE *p = fopen("foo", "r"); + fseek(p, 1, SEEK_SET); // expected-warning {{Stream pointer might be NULL.}} +} + +void f3(void) { + FILE *p = fopen("foo", "r"); + ftell(p); // expected-warning {{Stream pointer might be NULL.}} +} + +void f4(void) { + FILE *p = fopen("foo", "r"); + rewind(p); // expected-warning {{Stream pointer might be NULL.}} +} + +void f5(void) { + FILE *p = fopen("foo", "r"); + if (!p) + return; + fseek(p, 1, SEEK_SET); // no-warning + fseek(p, 1, 3); // expected-warning {{The whence argument to fseek() should be SEEK_SET, SEEK_END, or SEEK_CUR.}} +} diff --git a/test/Analysis/undef-buffers.c b/test/Analysis/undef-buffers.c new file mode 100644 index 0000000000000..4c5beb320ac97 --- /dev/null +++ b/test/Analysis/undef-buffers.c @@ -0,0 +1,32 @@ +// 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 *); + +char stackBased1 () { + char buf[2]; + buf[0] = 'a'; + return buf[1]; // expected-warning{{Undefined}} +} + +char stackBased2 () { + char buf[2]; + buf[1] = 'a'; + return buf[0]; // expected-warning{{Undefined}} +} + +char heapBased1 () { + char *buf = malloc(2); + buf[0] = 'a'; + char result = buf[1]; // expected-warning{{undefined}} + free(buf); + return result; +} + +char heapBased2 () { + char *buf = malloc(2); + buf[1] = 'a'; + char result = buf[0]; // expected-warning{{undefined}} + free(buf); + return result; +} diff --git a/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp b/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp index 0e262f3eb1d6a..0c905fbf325d7 100644 --- a/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp +++ b/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp @@ -86,3 +86,25 @@ namespace P { } } +namespace test5 { + namespace NS { + struct A; + void foo(void (*)(A&)); + } + void bar(NS::A& a); + + void test() { + foo(&bar); + } +} + +// PR6762: __builtin_va_list should be invisible to ADL on all platforms. +void test6_function(__builtin_va_list &argv); +namespace test6 { + void test6_function(__builtin_va_list &argv); + + void test() { + __builtin_va_list args; + test6_function(args); + } +} diff --git a/test/CXX/basic/basic.lookup/basic.lookup.classref/p1.cpp b/test/CXX/basic/basic.lookup/basic.lookup.classref/p1.cpp new file mode 100644 index 0000000000000..3fde0daa96cfb --- /dev/null +++ b/test/CXX/basic/basic.lookup/basic.lookup.classref/p1.cpp @@ -0,0 +1,46 @@ +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify %s + +// C++98 [basic.lookup.classref]p1: +// In a class member access expression (5.2.5), if the . or -> token is +// immediately followed by an identifier followed by a <, the identifier must +// be looked up to determine whether the < is the beginning of a template +// argument list (14.2) or a less-than operator. The identifier is first +// looked up in the class of the object expression. If the identifier is not +// found, it is then looked up in the context of the entire postfix-expression +// and shall name a class or function template. If the lookup in the class of +// the object expression finds a template, the name is also looked up in the +// context of the entire postfix-expression and +// -- if the name is not found, the name found in the class of the object +// expression is used, otherwise +// -- if the name is found in the context of the entire postfix-expression +// and does not name a class template, the name found in the class of the +// object expression is used, otherwise +// -- if the name found is a class template, it must refer to the same +// entity as the one found in the class of the object expression, +// otherwise the program is ill-formed. + +// From PR 7247 +template<typename T> +struct set{}; // expected-note{{lookup from the current scope refers here}} +struct Value { + template<typename T> + void set(T value) {} // expected-note{{lookup in the object type 'Value' refers here}} + + void resolves_to_same() { + Value v; + v.set<double>(3.2); + } +}; +void resolves_to_different() { + { + Value v; + // The fact that the next line is a warning rather than an error is an + // extension. + v.set<double>(3.2); // expected-warning{{lookup of 'set' in member access expression is ambiguous; using member of 'Value' [-Wambiguous-member-template]}} + } + { + int set; // Non-template. + Value v; + v.set<double>(3.2); + } +} diff --git a/test/CXX/basic/basic.lookup/basic.lookup.qual/p6-0x.cpp b/test/CXX/basic/basic.lookup/basic.lookup.qual/p6-0x.cpp index 35efba571ddc2..355ac4a2ecad8 100644 --- a/test/CXX/basic/basic.lookup/basic.lookup.qual/p6-0x.cpp +++ b/test/CXX/basic/basic.lookup/basic.lookup.qual/p6-0x.cpp @@ -1,4 +1,7 @@ // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s +// XFAIL: * +// Our C++0x doesn't currently have specialized destructor name handling, +// since the specification is still in flux. struct C { typedef int I; }; diff --git a/test/CXX/basic/basic.lookup/basic.lookup.qual/p6.cpp b/test/CXX/basic/basic.lookup/basic.lookup.qual/p6.cpp index 633d5cda9963c..0956de3c2a889 100644 --- a/test/CXX/basic/basic.lookup/basic.lookup.qual/p6.cpp +++ b/test/CXX/basic/basic.lookup/basic.lookup.qual/p6.cpp @@ -20,5 +20,5 @@ struct A { typedef A AB; int main() { AB *p; - p->AB::~AB(); // expected-error{{identifier 'AB' in pseudo-destructor expression does not name a type}} + p->AB::~AB(); // expected-error{{expected the class name after '~' to name a destructor}} } diff --git a/test/CXX/basic/basic.scope/basic.scope.pdecl/p9.cpp b/test/CXX/basic/basic.scope/basic.scope.pdecl/p9.cpp new file mode 100644 index 0000000000000..e64b6752f0824 --- /dev/null +++ b/test/CXX/basic/basic.scope/basic.scope.pdecl/p9.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Template type parameters. +typedef unsigned char T; +template<typename T = T> struct X0 { }; +template<> struct X0<unsigned char> { static const bool value = true; }; +int array0[X0<>::value? 1 : -1]; + +// Non-type template parameters. +const int N = 17; +template<int N = N> struct X1 { }; +template<> struct X1<17> { static const bool value = true; }; +int array1[X1<>::value? 1 : -1]; + +// Template template parameters. +template<template<class> class X0 = X0> struct X2 { }; +template<> struct X2<X0> { static const bool value = true; }; +int array2[X2<>::value? 1 : -1]; diff --git a/test/CXX/class.access/class.access.base/p1.cpp b/test/CXX/class.access/class.access.base/p1.cpp index 09884316f9cd5..43cc99eb8b493 100644 --- a/test/CXX/class.access/class.access.base/p1.cpp +++ b/test/CXX/class.access/class.access.base/p1.cpp @@ -54,8 +54,10 @@ namespace test0 { // of the base class are accessible as protected members of the // derived class. namespace test1 { - class Base { - public: int pub; static int spub; + class Base { // expected-note 6{{member is declared here}} + public: + int pub; // expected-note{{member is declared here}} + static int spub; // expected-note{{member is declared here}} protected: int prot; static int sprot; // expected-note 4 {{declared protected here}} private: int priv; static int spriv; // expected-note 8 {{declared private here}} }; @@ -102,13 +104,15 @@ namespace test1 { // the base class are accessible as private members of the derived // class. namespace test2 { - class Base { + class Base { // expected-note 6{{member is declared here}} public: - int pub; - static int spub; + int pub; // expected-note{{member is declared here}} + static int spub; // expected-note{{member is declared here}} protected: - int prot; // expected-note {{declared protected here}} - static int sprot; // expected-note {{declared protected here}} + int prot; // expected-note {{declared protected here}} \ + // expected-note{{member is declared here}} + static int sprot; // expected-note {{declared protected here}} \ + // expected-note{{member is declared here}} private: int priv; // expected-note 4 {{declared private here}} static int spriv; // expected-note 4 {{declared private here}} diff --git a/test/CXX/class.access/class.access.base/p5.cpp b/test/CXX/class.access/class.access.base/p5.cpp index 938d9fbe9bf8a..255fbfc9fc93e 100644 --- a/test/CXX/class.access/class.access.base/p5.cpp +++ b/test/CXX/class.access/class.access.base/p5.cpp @@ -27,7 +27,7 @@ namespace test1 { }; struct D { - public: static int x; + public: static int x; // expected-note{{member is declared here}} static int test() { return x; } }; struct E : private D { // expected-note{{constrained by private inheritance}} @@ -45,7 +45,7 @@ namespace test1 { namespace test2 { class A { - protected: static int x; + protected: static int x; // expected-note{{member is declared here}} }; class B : private A {}; // expected-note {{private inheritance}} diff --git a/test/CXX/class.access/class.access.dcl/p1.cpp b/test/CXX/class.access/class.access.dcl/p1.cpp index 5d7905f9da817..aab5fff5ea3f7 100644 --- a/test/CXX/class.access/class.access.dcl/p1.cpp +++ b/test/CXX/class.access/class.access.dcl/p1.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify +// RUN: %clang_cc1 -fsyntax-only -verify %s // This is just the test for [namespace.udecl]p4 with 'using' // uniformly stripped out. diff --git a/test/CXX/class.access/class.friend/p1.cpp b/test/CXX/class.access/class.friend/p1.cpp index 563ae4f63c4d6..277b70bee6bdb 100644 --- a/test/CXX/class.access/class.friend/p1.cpp +++ b/test/CXX/class.access/class.friend/p1.cpp @@ -6,9 +6,6 @@ // its friends, if any, by way of friend declarations. Such declarations give // special access rights to the friends, but they do not make the nominated // friends members of the befriending class. -// -// FIXME: Add tests for access control when implemented. Currently we only test -// for parsing. struct S { static void f(); }; S* g() { return 0; } @@ -124,7 +121,7 @@ namespace test2 { friend struct ilist_walker_bad; X *Prev; protected: - X *getPrev() { return Prev; } + X *getPrev() { return Prev; } // expected-note{{member is declared here}} }; class ilist_node : private ilist_half_node { // expected-note {{declared private here}} expected-note {{constrained by private inheritance here}} @@ -287,3 +284,25 @@ namespace test9 { friend class test9; }; } + +// PR7230 +namespace test10 { + extern "C" void f(void); + extern "C" void g(void); + + namespace NS { + class C { + void foo(void); // expected-note {{declared private here}} + friend void test10::f(void); + }; + static C* bar; + } + + void f(void) { + NS::bar->foo(); + } + + void g(void) { + NS::bar->foo(); // expected-error {{private member}} + } +} diff --git a/test/CXX/class.access/class.protected/p1.cpp b/test/CXX/class.access/class.protected/p1.cpp index 6ff630c996972..778e16aa3f533 100644 --- a/test/CXX/class.access/class.protected/p1.cpp +++ b/test/CXX/class.access/class.protected/p1.cpp @@ -2,8 +2,10 @@ namespace test0 { class A { - protected: int x; // expected-note 3 {{declared}} - static int sx; // expected-note 3 {{declared}} + protected: int x; // expected-note 3 {{declared}} \ + // expected-note {{member is declared here}} + static int sx; // expected-note 3 {{declared}} \ + // expected-note {{member is declared here}} }; class B : public A { }; @@ -136,8 +138,8 @@ namespace test3 { namespace test4 { class C; class A { - protected: int x; // expected-note 2 {{declared}} - static int sx; + protected: int x; // expected-note 3 {{declared}} + static int sx; // expected-note 3{{member is declared here}} static void test(C&); }; class B : public A { @@ -174,8 +176,8 @@ namespace test4 { namespace test5 { class D; class A { - protected: int x; - static int sx; + protected: int x; // expected-note 3{{member is declared here}} + static int sx; // expected-note 3{{member is declared here}} static void test(D&); }; class B : public A { @@ -326,11 +328,12 @@ namespace test8 { } namespace test9 { - class A { - protected: int foo(); // expected-note 8 {{declared}} + class A { // expected-note {{member is declared here}} + protected: int foo(); // expected-note 8 {{declared}} \ + // expected-note {{member is declared here}} }; - class B : public A { + class B : public A { // expected-note {{member is declared here}} friend class D; }; diff --git a/test/CXX/class.access/p4.cpp b/test/CXX/class.access/p4.cpp index e8afbe7a39249..90a1449610f31 100644 --- a/test/CXX/class.access/p4.cpp +++ b/test/CXX/class.access/p4.cpp @@ -160,7 +160,7 @@ namespace test4 { private: operator Private(); // expected-note 4 {{declared private here}} public: - operator Public(); + operator Public(); // expected-note 2{{member is declared here}} }; class Derived1 : private Base { // expected-note 2 {{declared private here}} \ @@ -267,7 +267,7 @@ namespace test8 { // Don't silently upgrade forbidden-access paths to private. namespace test9 { class A { - public: static int x; + public: static int x; // expected-note {{member is declared here}} }; class B : private A { // expected-note {{constrained by private inheritance here}} }; @@ -420,3 +420,10 @@ namespace test15 { template class B<int>; // expected-note {{in instantiation}} template class B<long>; // expected-note 4 {{in instantiation}} } + +// PR7281 +namespace test16 { + class A { ~A(); }; // expected-note 2{{declared private here}} + void b() { throw A(); } // expected-error{{temporary of type 'test16::A' has private destructor}} \ + // expected-error{{exception object of type 'test16::A' has private destructor}} +} diff --git a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp index 1aa163a8d8d7a..27b41a755ed05 100644 --- a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp +++ b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp @@ -1,4 +1,4 @@ -// RUN: %clang -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s namespace test0 { namespace ns0 { diff --git a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p12.cpp b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p12.cpp index 25371c7029b98..cc28bf6c28c4c 100644 --- a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p12.cpp +++ b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p12.cpp @@ -111,34 +111,53 @@ namespace test3 { struct Derived1 : Base { using Base::foo; - template <int n> Opaque<2> foo() { return Opaque<2>(); } + template <int n> Opaque<2> foo() { return Opaque<2>(); } // expected-note {{invalid explicitly-specified argument for template parameter 'n'}} }; struct Derived2 : Base { - template <int n> Opaque<2> foo() { return Opaque<2>(); } + template <int n> Opaque<2> foo() { return Opaque<2>(); } // expected-note {{invalid explicitly-specified argument for template parameter 'n'}} using Base::foo; }; struct Derived3 : Base { using Base::foo; - template <class T> Opaque<3> foo() { return Opaque<3>(); } + template <class T> Opaque<3> foo() { return Opaque<3>(); } // expected-note {{invalid explicitly-specified argument for template parameter 'T'}} }; struct Derived4 : Base { - template <class T> Opaque<3> foo() { return Opaque<3>(); } + template <class T> Opaque<3> foo() { return Opaque<3>(); } // expected-note {{invalid explicitly-specified argument for template parameter 'T'}} using Base::foo; }; void test() { expect<0>(Base().foo<int>()); expect<1>(Base().foo<0>()); - expect<0>(Derived1().foo<int>()); + expect<0>(Derived1().foo<int>()); // expected-error {{no matching member function for call to 'foo'}} expect<2>(Derived1().foo<0>()); - expect<0>(Derived2().foo<int>()); + expect<0>(Derived2().foo<int>()); // expected-error {{no matching member function for call to 'foo'}} expect<2>(Derived2().foo<0>()); expect<3>(Derived3().foo<int>()); - expect<1>(Derived3().foo<0>()); + expect<1>(Derived3().foo<0>()); // expected-error {{no matching member function for call to 'foo'}} expect<3>(Derived4().foo<int>()); - expect<1>(Derived4().foo<0>()); + expect<1>(Derived4().foo<0>()); // expected-error {{no matching member function for call to 'foo'}} + } +} + +// PR7384: access control for member templates. +namespace test4 { + class Base { + protected: + template<typename T> void foo(T); + template<typename T> void bar(T); // expected-note {{declared protected here}} + }; + + struct Derived : Base { + using Base::foo; + }; + + void test() { + Derived d; + d.foo<int>(3); + d.bar<int>(3); // expected-error {{'bar' is a protected member}} } } diff --git a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p13.cpp b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p13.cpp index ec814b1ab97c6..dd44bfc914b2d 100644 --- a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p13.cpp +++ b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p13.cpp @@ -55,6 +55,19 @@ namespace test0 { } } +// Typedef redeclaration. +namespace rdar8018262 { + typedef void (*fp)(); + + namespace N { + typedef void (*fp)(); + } + + using N::fp; + + fp fp_1; +} + // Things to test: // member operators // conversion operators diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp new file mode 100644 index 0000000000000..cd71d55fc5ce2 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp @@ -0,0 +1,78 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// XFAIL: * + +struct notlit { + notlit() {} +}; +struct notlit2 { + notlit2() {} +}; + +// valid declarations +constexpr int i1 = 0; +constexpr int f1() { return 0; } +struct s1 { + constexpr static int mi = 0; +}; + +// invalid declarations +// not a definition of an object +constexpr extern int i2; // x +// not a literal type +constexpr notlit nl1; // x +// function parameters +void f2(constexpr int i) {} // x +// non-static member +struct s2 { + constexpr int mi; // x +}; +// redeclaration mismatch +constexpr int f3(); // n +int f3(); // x +int f4(); // n +constexpr int f4(); // x + +// template stuff +template <typename T> +constexpr T ft(T t) { return t; } + +// specialization can differ in constepxr +template <> +notlit ft(notlit nl) { return nl; } + +constexpr int i3 = ft(1); + +void test() { + // ignore constexpr when instantiating with non-literal + notlit2 nl2; + (void)ft(nl2); +} + +// Examples from the standard: +constexpr int square(int x); +constexpr int bufsz = 1024; + +constexpr struct pixel { // x + int x; + int y; + constexpr pixel(int); +}; + +constexpr pixel::pixel(int a) + : x(square(a)), y(square(a)) + { } + +constexpr pixel small(2); // x (no definition of square(int) yet, so can't + // constexpr-eval pixel(int)) + +constexpr int square(int x) { + return x * x; +} + +constexpr pixel large(4); // now valid + +int next(constexpr int x) { // x + return x + 1; +} + +extern constexpr int memsz; // x diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp index 16394110d0546..ae59598f691ec 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp @@ -1,9 +1,10 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify %s // C++03 requires that we check for a copy constructor when binding a // reference to a temporary, since we are allowed to make a copy, Even // though we don't actually make that copy, make sure that we diagnose -// cases where that copy constructor is somehow unavailable. +// cases where that copy constructor is somehow unavailable. As an +// extension, this is only a warning. struct X1 { X1(); @@ -28,6 +29,7 @@ private: template<typename T> T get_value_badly() { double *dp = 0; + // The extension doesn't extend far enough to turn this error into a warning. T *tp = dp; // expected-error{{ cannot initialize a variable of type 'int *' with an lvalue of type 'double *'}} return T(); } @@ -41,7 +43,7 @@ struct X4 { // Check for "dangerous" default arguments that could cause recursion. struct X5 { X5(); - X5(const X5&, const X5& = X5()); // expected-error{{no viable constructor copying parameter of type 'X5'}} + X5(const X5&, const X5& = X5()); // expected-warning{{no viable constructor copying parameter of type 'X5'}} }; void g1(const X1&); @@ -51,11 +53,25 @@ void g4(const X4<int>&); void g5(const X5&); void test() { - g1(X1()); // expected-error{{no viable constructor copying parameter of type 'X1'}} - g2(X2()); // expected-error{{calling a private constructor of class 'X2'}} - g3(X3()); // expected-error{{no viable constructor copying parameter of type 'X3'}} + g1(X1()); // expected-warning{{no viable constructor copying parameter of type 'X1'; C++98 requires a copy constructor when binding a reference to a temporary [-Wbind-to-temporary-copy]}} + g2(X2()); // expected-warning{{C++98 requires an accessible copy constructor for class 'X2' when binding a reference to a temporary; was private [-Wbind-to-temporary-copy]}} + g3(X3()); // expected-warning{{no viable constructor copying parameter of type 'X3'}} g4(X4<int>()); - g5(X5()); // expected-error{{no viable constructor copying parameter of type 'X5'}} + g5(X5()); // Generates a warning in the default argument. } -// Check for dangerous recursion in default arguments. +// Check that unavailable copy constructors still cause SFINAE failures. +template<int> struct int_c { }; + +template<typename T> T f(const T&); + +// Would be ambiguous with the next g(), except the instantiation failure in +// sizeof() prevents that. +template<typename T> +int &g(int_c<sizeof(f(T()))> * = 0); + +template<typename T> float &g(); + +void h() { + float &fp2 = g<X3>(); // Not ambiguous. +} diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p16-cxx0x-no-extra-copy.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx0x-no-extra-copy.cpp index 5a342d423a2de..5cfb11a1fc1b5 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p16-cxx0x-no-extra-copy.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx0x-no-extra-copy.cpp @@ -48,3 +48,17 @@ void test() { g3(X3()); g4(X4<int>()); } + +// Check that unavailable copy constructors do not cause SFINAE failures. +template<int> struct int_c { }; + +template<typename T> T f(const T&); + +template<typename T> +int &g(int_c<sizeof(f(T()))> * = 0); // expected-note{{candidate function [with T = X3]}} + +template<typename T> float &g(); // expected-note{{candidate function [with T = X3]}} + +void h() { + float &fp = g<X3>(); // expected-error{{call to 'g' is ambiguous}} +} diff --git a/test/CXX/except/except.spec/p14-ir.cpp b/test/CXX/except/except.spec/p14-ir.cpp new file mode 100644 index 0000000000000..4d8d1f7c4018a --- /dev/null +++ b/test/CXX/except/except.spec/p14-ir.cpp @@ -0,0 +1,78 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fexceptions -o - %s | FileCheck %s + +// Copy constructor +struct X0 { + X0(); + X0(const X0 &) throw(); + X0(X0 &); +}; + +struct X1 { + X1(); + X1(const X1 &) throw(); +}; + +struct X2 : X1 { + X2(); +}; +struct X3 : X0, X1 { + X3(); +}; + +struct X4 { + X4(X4 &) throw(); +}; + +struct X5 : X0, X4 { }; + +void test(X2 x2, X3 x3, X5 x5) { + // CHECK: define linkonce_odr void @_ZN2X2C1ERKS_ + // CHECK: call void @_ZN2X2C2ERKS_({{.*}}) nounwind + // CHECK-NEXT: ret void + // CHECK-NEXT: } + X2 x2a(x2); + // CHECK: define linkonce_odr void @_ZN2X3C1ERKS_ + // CHECK: call void @_ZN2X3C2ERKS_({{.*}}) nounwind + // CHECK-NEXT: ret void + // CHECK-NEXT: } + X3 x3a(x3); + // CHECK: define linkonce_odr void @_ZN2X5C1ERS_ + // CHECK-NOT: call void @__cxa_call_unexpected + // CHECK: ret void + X5 x5a(x5); +} + +// Default constructor +struct X6 { + X6() throw(); +}; + +struct X7 { + X7(); +}; + +struct X8 : X6 { }; +struct X9 : X6, X7 { }; + +void test() { + // CHECK: define linkonce_odr void @_ZN2X8C1Ev + // CHECK: call void @_ZN2X8C2Ev({{.*}}) nounwind + // CHECK-NEXT: ret void + X8(); + + // CHECK: define linkonce_odr void @_ZN2X9C1Ev + // FIXME: check that this is the end of the line here: + // CHECK: call void @_ZN2X9C2Ev({{.*}}) + // CHECK-NEXT: ret void + X9(); + + // CHECK: define linkonce_odr void @_ZN2X9C2Ev + // CHECK: call void @_ZN2X6C2Ev({{.*}}) nounwind + // FIXME: and here: + // CHECK-NEXT: call void @_ZN2X7C2Ev({{.*}}) + // CHECK: ret void + + // CHECK: define linkonce_odr void @_ZN2X8C2Ev + // CHECK: call void @_ZN2X6C2Ev({{.*}}) nounwind + // CHECK-NEXT: ret void +} diff --git a/test/CXX/except/except.spec/p14.cpp b/test/CXX/except/except.spec/p14.cpp new file mode 100644 index 0000000000000..9450b1cf80d7f --- /dev/null +++ b/test/CXX/except/except.spec/p14.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -fexceptions -verify %s +struct A { }; +struct B { }; +struct C { }; + +// Destructor +struct X0 { + virtual ~X0() throw(A); // expected-note{{overridden virtual function is here}} +}; +struct X1 { + virtual ~X1() throw(B); // expected-note{{overridden virtual function is here}} +}; +struct X2 : public X0, public X1 { }; // expected-error 2{{exception specification of overriding function is more lax than base version}} + +// Copy-assignment operator. +struct CA0 { + CA0 &operator=(const CA0&) throw(A); +}; +struct CA1 { + CA1 &operator=(const CA1&) throw(B); +}; +struct CA2 : CA0, CA1 { }; + +void test_CA() { + CA2 &(CA2::*captr1)(const CA2&) throw(A, B) = &CA2::operator=; + CA2 &(CA2::*captr2)(const CA2&) throw(A, B, C) = &CA2::operator=; + CA2 &(CA2::*captr3)(const CA2&) throw(A) = &CA2::operator=; // expected-error{{target exception specification is not superset of source}} + CA2 &(CA2::*captr4)(const CA2&) throw(B) = &CA2::operator=; // expected-error{{target exception specification is not superset of source}} +} diff --git a/test/CXX/special/class.copy/p20.cpp b/test/CXX/special/class.copy/p20.cpp new file mode 100644 index 0000000000000..8dfb7ca8a068d --- /dev/null +++ b/test/CXX/special/class.copy/p20.cpp @@ -0,0 +1,46 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct ConstCopy { + ConstCopy(); + ConstCopy &operator=(const ConstCopy&); +}; + +struct NonConstCopy { + NonConstCopy(); + NonConstCopy &operator=(NonConstCopy&); +}; + +struct VirtualInheritsNonConstCopy : virtual NonConstCopy { + VirtualInheritsNonConstCopy(); + VirtualInheritsNonConstCopy &operator=(const VirtualInheritsNonConstCopy&); +}; + +struct ImplicitNonConstCopy1 : NonConstCopy { // expected-note{{the implicit copy assignment operator}} + ImplicitNonConstCopy1(); +}; + +struct ImplicitNonConstCopy2 { // expected-note{{the implicit copy assignment operator}} + ImplicitNonConstCopy2(); + NonConstCopy ncc; +}; + +struct ImplicitNonConstCopy3 { // expected-note{{the implicit copy assignment operator}} + ImplicitNonConstCopy3(); + NonConstCopy ncc_array[2][3]; +}; + +struct ImplicitNonConstCopy4 : VirtualInheritsNonConstCopy { + ImplicitNonConstCopy4(); +}; + +void test_non_const_copy(const ImplicitNonConstCopy1 &cincc1, + const ImplicitNonConstCopy2 &cincc2, + const ImplicitNonConstCopy3 &cincc3, + const ImplicitNonConstCopy4 &cincc4, + const VirtualInheritsNonConstCopy &vincc) { + (void)sizeof(ImplicitNonConstCopy1() = cincc1); // expected-error{{no viable overloaded '='}} + (void)sizeof(ImplicitNonConstCopy2() = cincc2); // expected-error{{no viable overloaded '='}} + (void)sizeof(ImplicitNonConstCopy3() = cincc3); // expected-error{{no viable overloaded '='}} + (void)sizeof(ImplicitNonConstCopy4() = cincc4); // okay + (void)sizeof(VirtualInheritsNonConstCopy() = vincc); +} diff --git a/test/CXX/special/class.copy/p9.cpp b/test/CXX/special/class.copy/p9.cpp new file mode 100644 index 0000000000000..d03794420e01b --- /dev/null +++ b/test/CXX/special/class.copy/p9.cpp @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct ConstCopy { + ConstCopy(); + ConstCopy(const ConstCopy&); +}; + +struct NonConstCopy { + NonConstCopy(); + NonConstCopy(NonConstCopy&); +}; + +struct VirtualInheritsNonConstCopy : virtual NonConstCopy { + VirtualInheritsNonConstCopy(); + VirtualInheritsNonConstCopy(const VirtualInheritsNonConstCopy&); +}; + +struct ImplicitNonConstCopy1 : NonConstCopy { + ImplicitNonConstCopy1(); +}; + +struct ImplicitNonConstCopy2 { + ImplicitNonConstCopy2(); + NonConstCopy ncc; +}; + +struct ImplicitNonConstCopy3 { + ImplicitNonConstCopy3(); + NonConstCopy ncc_array[2][3]; +}; + +struct ImplicitNonConstCopy4 : VirtualInheritsNonConstCopy { + ImplicitNonConstCopy4(); +}; + +void test_non_const_copy(const ImplicitNonConstCopy1 &cincc1, + const ImplicitNonConstCopy2 &cincc2, + const ImplicitNonConstCopy3 &cincc3, + const ImplicitNonConstCopy4 &cincc4) { + (void)sizeof(ImplicitNonConstCopy1(cincc1)); // expected-error{{functional-style cast from 'ImplicitNonConstCopy1 const' to 'ImplicitNonConstCopy1' is not allowed}} + (void)sizeof(ImplicitNonConstCopy2(cincc2)); // expected-error{{functional-style cast from 'ImplicitNonConstCopy2 const' to 'ImplicitNonConstCopy2' is not allowed}} + (void)sizeof(ImplicitNonConstCopy3(cincc3)); // expected-error{{functional-style cast from 'ImplicitNonConstCopy3 const' to 'ImplicitNonConstCopy3' is not allowed}} + (void)sizeof(ImplicitNonConstCopy4(cincc4)); // expected-error{{functional-style cast from 'ImplicitNonConstCopy4 const' to 'ImplicitNonConstCopy4' is not allowed}} +} diff --git a/test/CXX/temp/temp.decls/temp.variadic/parameter-matching.cpp b/test/CXX/temp/temp.decls/temp.variadic/parameter-matching.cpp new file mode 100644 index 0000000000000..7352be2d72f0e --- /dev/null +++ b/test/CXX/temp/temp.decls/temp.variadic/parameter-matching.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +// Check for template type parameter pack (mis-)matches with template +// type parameters. +template<typename ...T> struct X0t; +template<typename ...T> struct X0t; + +template<typename ...T> struct X1t; // expected-note{{previous template type parameter pack declared here}} +template<typename T> struct X1t; // expected-error{{template type parameter conflicts with previous template type parameter pack}} + +template<typename T> struct X2t; // expected-note{{previous template type parameter declared here}} +template<typename ...T> struct X2t; // expected-error{{template type parameter pack conflicts with previous template type parameter}} + +template<template<typename ...T> class> struct X0tt; +template<template<typename ...T> class> struct X0tt; + +template<template<typename ...T> class> struct X1tt; // expected-note{{previous template type parameter pack declared here}} +template<template<typename T> class> struct X1tt; // expected-error{{template type parameter conflicts with previous template type parameter pack}} + +template<template<typename T> class> struct X2tt; // expected-note{{previous template type parameter declared here}} +template<template<typename ...T> class> struct X2tt; // expected-error{{template type parameter pack conflicts with previous template type parameter}} diff --git a/test/CXX/temp/temp.param/p2.cpp b/test/CXX/temp/temp.param/p2.cpp index 41868c5c1ac72..fed6e9c266be8 100644 --- a/test/CXX/temp/temp.param/p2.cpp +++ b/test/CXX/temp/temp.param/p2.cpp @@ -14,4 +14,9 @@ template<typename T, typename X<T>::type Value> struct Y1; // A storage class shall not be specified in a template-parameter declaration. template<static int Value> struct Z; // FIXME: expect an error +// Make sure that we properly disambiguate non-type template parameters that +// start with 'class'. +class X1 { }; +template<class X1 *xptr> struct Y2 { }; + // FIXME: add the example from p2 diff --git a/test/CXX/temp/temp.spec/temp.explicit/p11.cpp b/test/CXX/temp/temp.spec/temp.explicit/p11.cpp new file mode 100644 index 0000000000000..4ca54283157b0 --- /dev/null +++ b/test/CXX/temp/temp.spec/temp.explicit/p11.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +class X { + template <typename T> class Y {}; +}; + +class A { + class B {}; + class C {}; +}; + +// C++0x [temp.explicit] 14.7.2/11: +// The usual access checking rules do not apply to names used to specify +// explicit instantiations. +template class X::Y<A::B>; + +// As an extension, this rule is applied to explicit specializations as well. +template <> class X::Y<A::C> {}; diff --git a/test/CXX/temp/temp.spec/temp.explicit/p2.cpp b/test/CXX/temp/temp.spec/temp.explicit/p2.cpp index 0da316cc9cef4..70d338b9f6454 100644 --- a/test/CXX/temp/temp.spec/temp.explicit/p2.cpp +++ b/test/CXX/temp/temp.spec/temp.explicit/p2.cpp @@ -25,9 +25,9 @@ T X0<T>::value = 17; typedef X0<int> XInt; -template struct XInt::Inner; // expected-error{{template-id}} -template void XInt::f(); // expected-error{{template-id}} -template int XInt::value; // expected-error{{template-id}} +template struct XInt::Inner; // expected-warning{{template-id}} +template void XInt::f(); // expected-warning{{template-id}} +template int XInt::value; // expected-warning{{template-id}} namespace N { template<typename T> diff --git a/test/CXX/temp/temp.spec/temp.explicit/p9-linkage.cpp b/test/CXX/temp/temp.spec/temp.explicit/p9-linkage.cpp index e67233c375476..57b012f9a9463 100644 --- a/test/CXX/temp/temp.spec/temp.explicit/p9-linkage.cpp +++ b/test/CXX/temp/temp.spec/temp.explicit/p9-linkage.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm -std=c++0x -o - %s | FileCheck %s +// RUN: %clang_cc1 -O1 -emit-llvm -std=c++0x -o - %s | FileCheck %s template<typename T> struct X0 { diff --git a/test/CodeCompletion/call.cpp b/test/CodeCompletion/call.cpp index 46494e7619f5a..f06470f4cbe73 100644 --- a/test/CodeCompletion/call.cpp +++ b/test/CodeCompletion/call.cpp @@ -18,7 +18,7 @@ void f(); void test() { f(Y(), 0, 0); // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:19:9 %s -o - | FileCheck -check-prefix=CC1 %s - // CHECK-CC1: COMPLETION: Pattern : dynamic_cast<<#type-id#>>(<#expression#>) + // CHECK-CC1: COMPLETION: Pattern : dynamic_cast<<#type#>>(<#expression#>) // CHECK-CC1: f(N::Y y, <#int ZZ#>) // CHECK-CC1-NEXT: f(int i, <#int j#>, int k) // CHECK-CC1-NEXT: f(float x, <#float y#>) diff --git a/test/CodeCompletion/ordinary-name.cpp b/test/CodeCompletion/ordinary-name.cpp index 20f661a280352..7e08c728fab65 100644 --- a/test/CodeCompletion/ordinary-name.cpp +++ b/test/CodeCompletion/ordinary-name.cpp @@ -9,32 +9,32 @@ void foo() { // CHECK-CC1-NEXT: COMPLETION: char // CHECK-CC1-NEXT: COMPLETION: class // CHECK-CC1-NEXT: COMPLETION: const - // CHECK-CC1-NEXT: COMPLETION: Pattern : const_cast<<#type-id#>>(<#expression#>) + // CHECK-CC1-NEXT: COMPLETION: Pattern : const_cast<<#type#>>(<#expression#>) // CHECK-CC1: COMPLETION: Pattern : delete <#expression#> - // CHECK-CC1-NEXT: COMPLETION: Pattern : delete[] <#expression#> + // CHECK-CC1-NEXT: COMPLETION: Pattern : delete [] <#expression#> // CHECK-CC1-NEXT: COMPLETION: Pattern : do{<#statements#> // CHECK-CC1: COMPLETION: double - // CHECK-CC1-NEXT: COMPLETION: Pattern : dynamic_cast<<#type-id#>>(<#expression#>) + // CHECK-CC1-NEXT: COMPLETION: Pattern : dynamic_cast<<#type#>>(<#expression#>) // CHECK-CC1-NEXT: COMPLETION: enum // CHECK-CC1-NEXT: COMPLETION: extern // CHECK-CC1-NEXT: COMPLETION: false // CHECK-CC1-NEXT: COMPLETION: float // CHECK-CC1-NEXT: COMPLETION: foo : [#void#]foo() // CHECK-CC1-NEXT: COMPLETION: Pattern : for(<#init-statement#>;<#condition#>;<#inc-expression#>){<#statements#> - // CHECK-CC1: COMPLETION: Pattern : goto <#identifier#> + // CHECK-CC1: COMPLETION: Pattern : goto <#label#> // CHECK-CC1-NEXT: COMPLETION: Pattern : if(<#condition#>){<#statements#> // CHECK-CC1: COMPLETION: int // CHECK-CC1-NEXT: COMPLETION: long - // CHECK-CC1-NEXT: COMPLETION: Pattern : new <#type-id#>(<#expressions#>) - // CHECK-CC1-NEXT: COMPLETION: Pattern : new <#type-id#>[<#size#>](<#expressions#>) + // CHECK-CC1-NEXT: COMPLETION: Pattern : new <#type#>(<#expressions#>) + // CHECK-CC1-NEXT: COMPLETION: Pattern : new <#type#>[<#size#>](<#expressions#>) // CHECK-CC1-NEXT: COMPLETION: operator - // CHECK-CC1-NEXT: COMPLETION: Pattern : reinterpret_cast<<#type-id#>>(<#expression#>) + // CHECK-CC1-NEXT: COMPLETION: Pattern : reinterpret_cast<<#type#>>(<#expression#>) // CHECK-CC1-NEXT: COMPLETION: Pattern : return // CHECK-CC1-NEXT: COMPLETION: short // CHECK-CC1-NEXT: COMPLETION: signed // CHECK-CC1-NEXT: COMPLETION: Pattern : sizeof(<#expression-or-type#>) // CHECK-CC1-NEXT: COMPLETION: static - // CHECK-CC1-NEXT: COMPLETION: Pattern : static_cast<<#type-id#>>(<#expression#>) + // CHECK-CC1-NEXT: COMPLETION: Pattern : static_cast<<#type#>>(<#expression#>) // CHECK-CC1-NEXT: COMPLETION: struct // CHECK-CC1-NEXT: COMPLETION: Pattern : switch(<#condition#>){ // CHECK-CC1: COMPLETION: t : t @@ -42,10 +42,11 @@ void foo() { // CHECK-CC1-NEXT: COMPLETION: true // CHECK-CC1-NEXT: COMPLETION: Pattern : try{<#statements#> // CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF - // CHECK-CC1-NEXT: COMPLETION: typedef + // CHECK-CC1-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#> // CHECK-CC1-NEXT: COMPLETION: Pattern : typeid(<#expression-or-type#>) - // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#qualified-id#> - // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#expression-or-type#>) + // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#> + // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof <#expression#> + // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>) // CHECK-CC1-NEXT: COMPLETION: union // CHECK-CC1-NEXT: COMPLETION: unsigned // CHECK-CC1-NEXT: COMPLETION: Pattern : using namespace <#identifier#> @@ -71,7 +72,7 @@ void foo() { // CHECK-CC2-NEXT: COMPLETION: int // CHECK-CC2-NEXT: COMPLETION: long // CHECK-CC2-NEXT: COMPLETION: Pattern : namespace <#identifier#>{<#declarations#> - // CHECK-CC2: COMPLETION: Pattern : namespace <#identifier#> = <#identifier#> + // CHECK-CC2: COMPLETION: Pattern : namespace <#name#> = <#namespace#> // CHECK-CC2-NEXT: COMPLETION: operator // CHECK-CC2-NEXT: COMPLETION: short // CHECK-CC2-NEXT: COMPLETION: signed @@ -81,13 +82,14 @@ void foo() { // CHECK-CC2-NEXT: COMPLETION: Pattern : template <#declaration#> // CHECK-CC2-NEXT: COMPLETION: Pattern : template<<#parameters#>> // CHECK-CC2-NEXT: COMPLETION: TYPEDEF : TYPEDEF - // CHECK-CC2-NEXT: COMPLETION: typedef - // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#qualified-id#> - // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#expression-or-type#>) + // CHECK-CC2-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#> + // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#> + // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof <#expression#> + // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#type#>) // CHECK-CC2-NEXT: COMPLETION: union // CHECK-CC2-NEXT: COMPLETION: unsigned // CHECK-CC2-NEXT: COMPLETION: Pattern : using namespace <#identifier#> - // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualified-id#> + // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#> // CHECK-CC2-NEXT: COMPLETION: void // CHECK-CC2-NEXT: COMPLETION: volatile // CHECK-CC2-NEXT: COMPLETION: wchar_t @@ -117,12 +119,13 @@ void foo() { // CHECK-CC3-NEXT: COMPLETION: static // CHECK-CC3-NEXT: COMPLETION: struct // CHECK-CC3-NEXT: COMPLETION: Pattern : template<<#parameters#>> - // CHECK-CC3-NEXT: COMPLETION: typedef - // CHECK-CC3-NEXT: COMPLETION: Pattern : typename <#qualified-id#> - // CHECK-CC3-NEXT: COMPLETION: Pattern : typeof(<#expression-or-type#>) + // CHECK-CC3-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#> + // CHECK-CC3-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#> + // CHECK-CC3-NEXT: COMPLETION: Pattern : typeof <#expression#> + // CHECK-CC3-NEXT: COMPLETION: Pattern : typeof(<#type#>) // CHECK-CC3-NEXT: COMPLETION: union // CHECK-CC3-NEXT: COMPLETION: unsigned - // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualified-id#> + // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#> // CHECK-CC3-NEXT: COMPLETION: virtual // CHECK-CC3-NEXT: COMPLETION: void // CHECK-CC3-NEXT: COMPLETION: volatile @@ -134,33 +137,34 @@ void foo() { // CHECK-CC4-NEXT: COMPLETION: char // CHECK-CC4-NEXT: COMPLETION: class // CHECK-CC4-NEXT: COMPLETION: const - // CHECK-CC4-NEXT: COMPLETION: Pattern : const_cast<<#type-id#>>(<#expression#>) + // CHECK-CC4-NEXT: COMPLETION: Pattern : const_cast<<#type#>>(<#expression#>) // CHECK-CC4-NEXT: COMPLETION: Pattern : delete <#expression#> - // CHECK-CC4-NEXT: COMPLETION: Pattern : delete[] <#expression#> + // CHECK-CC4-NEXT: COMPLETION: Pattern : delete [] <#expression#> // CHECK-CC4-NEXT: COMPLETION: double - // CHECK-CC4-NEXT: COMPLETION: Pattern : dynamic_cast<<#type-id#>>(<#expression#>) + // CHECK-CC4-NEXT: COMPLETION: Pattern : dynamic_cast<<#type#>>(<#expression#>) // CHECK-CC4-NEXT: COMPLETION: enum // CHECK-CC4-NEXT: COMPLETION: false // CHECK-CC4-NEXT: COMPLETION: float // CHECK-CC4-NEXT: COMPLETION: foo : [#void#]foo() // CHECK-CC4-NEXT: COMPLETION: int // CHECK-CC4-NEXT: COMPLETION: long - // CHECK-CC4-NEXT: COMPLETION: Pattern : new <#type-id#>(<#expressions#>) - // CHECK-CC4-NEXT: COMPLETION: Pattern : new <#type-id#>[<#size#>](<#expressions#>) + // CHECK-CC4-NEXT: COMPLETION: Pattern : new <#type#>(<#expressions#>) + // CHECK-CC4-NEXT: COMPLETION: Pattern : new <#type#>[<#size#>](<#expressions#>) // CHECK-CC4-NEXT: COMPLETION: operator - // CHECK-CC4-NEXT: COMPLETION: Pattern : reinterpret_cast<<#type-id#>>(<#expression#>) + // CHECK-CC4-NEXT: COMPLETION: Pattern : reinterpret_cast<<#type#>>(<#expression#>) // CHECK-CC4-NEXT: COMPLETION: short // CHECK-CC4-NEXT: COMPLETION: signed // CHECK-CC4-NEXT: COMPLETION: Pattern : sizeof(<#expression-or-type#>) - // CHECK-CC4-NEXT: COMPLETION: Pattern : static_cast<<#type-id#>>(<#expression#>) + // CHECK-CC4-NEXT: COMPLETION: Pattern : static_cast<<#type#>>(<#expression#>) // CHECK-CC4-NEXT: COMPLETION: struct // CHECK-CC4-NEXT: COMPLETION: t : t // CHECK-CC4-NEXT: COMPLETION: Pattern : throw <#expression#> // CHECK-CC4-NEXT: COMPLETION: true // CHECK-CC4-NEXT: COMPLETION: TYPEDEF : TYPEDEF // CHECK-CC4-NEXT: COMPLETION: Pattern : typeid(<#expression-or-type#>) - // CHECK-CC4-NEXT: COMPLETION: Pattern : typename <#qualified-id#> - // CHECK-CC4-NEXT: COMPLETION: Pattern : typeof(<#expression-or-type#>) + // CHECK-CC4-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#> + // CHECK-CC4-NEXT: COMPLETION: Pattern : typeof <#expression#> + // CHECK-CC4-NEXT: COMPLETION: Pattern : typeof(<#type#>) // CHECK-CC4-NEXT: COMPLETION: union // CHECK-CC4-NEXT: COMPLETION: unsigned // CHECK-CC4-NEXT: COMPLETION: void diff --git a/test/CodeGen/2008-07-29-override-alias-decl.c b/test/CodeGen/2008-07-29-override-alias-decl.c index a4bea0e06cd88..dbe10b395f4fa 100644 --- a/test/CodeGen/2008-07-29-override-alias-decl.c +++ b/test/CodeGen/2008-07-29-override-alias-decl.c @@ -2,10 +2,7 @@ int x() { return 1; } -// CHECK: [[retval:%.*]] = alloca i32 -// CHECK: store i32 1, i32* [[retval]] -// CHECK: [[load:%.*]] = load i32* [[retval]] -// CHECK: ret i32 [[load]] +// CHECK: ret i32 1 int f() __attribute__((weak, alias("x"))); @@ -17,9 +14,6 @@ int h() { return f(); } -// CHECK: [[retval:%.*]] = alloca i32 // CHECK: [[call:%.*]] = call i32 (...)* @f() -// CHECK: store i32 [[call]], i32* [[retval]] -// CHECK: [[load:%.*]] = load i32* [[retval]] -// CHECK: ret i32 [[load]] +// CHECK: ret i32 [[call]] diff --git a/test/CodeGen/2008-12-02-logical-or-fold.c b/test/CodeGen/2008-12-02-logical-or-fold.c deleted file mode 100644 index 167ad299ce61b..0000000000000 --- a/test/CodeGen/2008-12-02-logical-or-fold.c +++ /dev/null @@ -1,4 +0,0 @@ -// RUN: %clang_cc1 -emit-llvm -o - %s | grep "store i32 1" -// PR3150 - -int a() {return 1||1;} diff --git a/test/CodeGen/address-space-field2.c b/test/CodeGen/address-space-field2.c index 198fd22a3a74d..9c21cab3a566a 100644 --- a/test/CodeGen/address-space-field2.c +++ b/test/CodeGen/address-space-field2.c @@ -16,10 +16,6 @@ // CHECK: addrspace(1) // CHECK: addrspace(1) // CHECK: addrspace(1) -// CHECK: addrspace(1) -// CHECK: addrspace(1) -// CHECK: addrspace(2) -// CHECK: addrspace(2) // CHECK: addrspace(2) // CHECK: addrspace(2) // CHECK: addrspace(2) diff --git a/test/CodeGen/address-space-field3.c b/test/CodeGen/address-space-field3.c index 090f4a104b052..c17085cdf48be 100644 --- a/test/CodeGen/address-space-field3.c +++ b/test/CodeGen/address-space-field3.c @@ -16,10 +16,6 @@ // CHECK: addrspace(2) // CHECK: addrspace(2) // CHECK: addrspace(2) -// CHECK: addrspace(2) -// CHECK: addrspace(2) -// CHECK: addrspace(1) -// CHECK: addrspace(1) // CHECK: addrspace(1) // CHECK: addrspace(1) // CHECK: addrspace(1) diff --git a/test/CodeGen/address-space-field4.c b/test/CodeGen/address-space-field4.c index a1906c0c00597..a896ab652d98d 100644 --- a/test/CodeGen/address-space-field4.c +++ b/test/CodeGen/address-space-field4.c @@ -23,9 +23,6 @@ // CHECK: addrspace(3) // CHECK: addrspace(3) // CHECK: addrspace(1) -// CHECK: addrspace(3) -// CHECK: addrspace(3) -// CHECK: addrspace(1) // CHECK: addrspace(1) // CHECK: addrspace(1) // CHECK: addrspace(1) @@ -35,9 +32,6 @@ // CHECK: addrspace(1) // CHECK: addrspace(1) // CHECK: addrspace(2) -// CHECK: addrspace(1) -// CHECK: addrspace(2) -// CHECK: addrspace(2) // CHECK: addrspace(2) // Check the load and store are using the correct address space to access diff --git a/test/CodeGen/address-space.c b/test/CodeGen/address-space.c index 5b58919557148..04f88dc20a1a4 100644 --- a/test/CodeGen/address-space.c +++ b/test/CodeGen/address-space.c @@ -1,20 +1,44 @@ -// RUN: %clang_cc1 -emit-llvm < %s | grep '@foo.*global.*addrspace(1)' -// RUN: %clang_cc1 -emit-llvm < %s | grep '@ban.*global.*addrspace(1)' -// RUN: %clang_cc1 -emit-llvm < %s | grep 'load.*addrspace(1)' | count 2 +// RUN: %clang_cc1 -emit-llvm < %s | FileCheck %s // RUN: %clang_cc1 -emit-llvm < %s | grep 'load.*addrspace(2).. @A' // RUN: %clang_cc1 -emit-llvm < %s | grep 'load.*addrspace(2).. @B' + +// CHECK: @foo = common addrspace(1) global int foo __attribute__((address_space(1))); + +// CHECK: @ban = common addrspace(1) global int ban[10] __attribute__((address_space(1))); -int bar() { return foo; } +// CHECK: define i32 @test1() +// CHECK: load i32 addrspace(1)* @foo +int test1() { return foo; } -int baz(int i) { return ban[i]; } +// CHECK: define i32 @test2(i32 %i) +// CHECK: load i32 addrspace(1)* +// CHECK-NEXT: ret i32 +int test2(int i) { return ban[i]; } // Both A and B point into addrspace(2). __attribute__((address_space(2))) int *A, *B; +// CHECK: define void @test3() +// CHECK: load i32 addrspace(2)** @B +// CHECK: load i32 addrspace(2)* +// CHECK: load i32 addrspace(2)** @A +// CHECK: store i32 {{.*}}, i32 addrspace(2)* void test3() { *A = *B; } +// PR7437 +typedef struct { + float aData[1]; +} MyStruct; + +// CHECK: define void @test4( +// CHECK: call void @llvm.memcpy.p0i8.p2i8 +// CHECK: call void @llvm.memcpy.p2i8.p0i8 +void test4(MyStruct __attribute__((address_space(2))) *pPtr) { + MyStruct s = pPtr[0]; + pPtr[0] = s; +} diff --git a/test/CodeGen/altivec.c b/test/CodeGen/altivec.c new file mode 100644 index 0000000000000..9e38df50930c0 --- /dev/null +++ b/test/CodeGen/altivec.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -faltivec -triple powerpc-unknown-unknown -emit-llvm %s -o - | FileCheck %s + +// CHECK: @test0 = global <4 x i32> <i32 1, i32 1, i32 1, i32 1> +vector int test0 = (vector int)(1); diff --git a/test/CodeGen/arm-arguments.c b/test/CodeGen/arm-arguments.c index 72fd7c3f8b71d..73bc03dac7f5f 100644 --- a/test/CodeGen/arm-arguments.c +++ b/test/CodeGen/arm-arguments.c @@ -1,131 +1,131 @@ // RUN: %clang_cc1 -triple armv7-apple-darwin9 -target-abi apcs-gnu -emit-llvm -w -o - %s | FileCheck -check-prefix=APCS-GNU %s // RUN: %clang_cc1 -triple armv7-apple-darwin9 -target-abi aapcs -emit-llvm -w -o - %s | FileCheck -check-prefix=AAPCS %s -// APCS-GNU: define arm_apcscc signext i8 @f0() +// APCS-GNU: define signext i8 @f0() // AAPCS: define arm_aapcscc signext i8 @f0() char f0(void) { return 0; } -// APCS-GNU: define arm_apcscc i8 @f1() +// APCS-GNU: define i8 @f1() // AAPCS: define arm_aapcscc i8 @f1() struct s1 { char f0; }; struct s1 f1(void) {} -// APCS-GNU: define arm_apcscc i16 @f2() +// APCS-GNU: define i16 @f2() // AAPCS: define arm_aapcscc i16 @f2() struct s2 { short f0; }; struct s2 f2(void) {} -// APCS-GNU: define arm_apcscc i32 @f3() +// APCS-GNU: define i32 @f3() // AAPCS: define arm_aapcscc i32 @f3() struct s3 { int f0; }; struct s3 f3(void) {} -// APCS-GNU: define arm_apcscc i32 @f4() +// APCS-GNU: define i32 @f4() // AAPCS: define arm_aapcscc i32 @f4() struct s4 { struct s4_0 { int f0; } f0; }; struct s4 f4(void) {} -// APCS-GNU: define arm_apcscc void @f5( +// APCS-GNU: define void @f5( // APCS-GNU: struct.s5* sret // AAPCS: define arm_aapcscc i32 @f5() struct s5 { struct { } f0; int f1; }; struct s5 f5(void) {} -// APCS-GNU: define arm_apcscc void @f6( +// APCS-GNU: define void @f6( // APCS-GNU: struct.s6* sret // AAPCS: define arm_aapcscc i32 @f6() struct s6 { int f0[1]; }; struct s6 f6(void) {} -// APCS-GNU: define arm_apcscc void @f7() +// APCS-GNU: define void @f7() // AAPCS: define arm_aapcscc void @f7() struct s7 { struct { int : 0; } f0; }; struct s7 f7(void) {} -// APCS-GNU: define arm_apcscc void @f8( +// APCS-GNU: define void @f8( // APCS-GNU: struct.s8* sret // AAPCS: define arm_aapcscc void @f8() struct s8 { struct { int : 0; } f0[1]; }; struct s8 f8(void) {} -// APCS-GNU: define arm_apcscc i32 @f9() +// APCS-GNU: define i32 @f9() // AAPCS: define arm_aapcscc i32 @f9() struct s9 { int f0; int : 0; }; struct s9 f9(void) {} -// APCS-GNU: define arm_apcscc i32 @f10() +// APCS-GNU: define i32 @f10() // AAPCS: define arm_aapcscc i32 @f10() struct s10 { int f0; int : 0; int : 0; }; struct s10 f10(void) {} -// APCS-GNU: define arm_apcscc void @f11( +// APCS-GNU: define void @f11( // APCS-GNU: struct.s10* sret // AAPCS: define arm_aapcscc i32 @f11() struct s11 { int : 0; int f0; }; struct s11 f11(void) {} -// APCS-GNU: define arm_apcscc i32 @f12() +// APCS-GNU: define i32 @f12() // AAPCS: define arm_aapcscc i32 @f12() union u12 { char f0; short f1; int f2; }; union u12 f12(void) {} -// APCS-GNU: define arm_apcscc void @f13( +// APCS-GNU: define void @f13( // APCS-GNU: struct.s13* sret // FIXME: This should return a float. -// AAPCS-FIXME: define arm_aapcscc float @f13() +// AAPCS-FIXME: darm_aapcscc efine float @f13() struct s13 { float f0; }; struct s13 f13(void) {} -// APCS-GNU: define arm_apcscc void @f14( +// APCS-GNU: define void @f14( // APCS-GNU: struct.s13* sret // AAPCS: define arm_aapcscc i32 @f14() union u14 { float f0; }; union u14 f14(void) {} -// APCS-GNU: define arm_apcscc void @f15() +// APCS-GNU: define void @f15() // AAPCS: define arm_aapcscc void @f15() void f15(struct s7 a0) {} -// APCS-GNU: define arm_apcscc void @f16() +// APCS-GNU: define void @f16() // AAPCS: define arm_aapcscc void @f16() void f16(struct s8 a0) {} -// APCS-GNU: define arm_apcscc i32 @f17() +// APCS-GNU: define 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() +// APCS-GNU: define 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: define void @f19( // APCS-GNU: struct.s19* 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: define void @f20( // APCS-GNU: struct.s20* sret // AAPCS: define arm_aapcscc i32 @f20() struct s20 { struct s8 f1; int f0; }; struct s20 f20(void) {} -// APCS-GNU: define arm_apcscc i8 @f21() +// APCS-GNU: define i8 @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() +// APCS-GNU: define i16 @f22() +// APCS-GNU: define i32 @f23() +// APCS-GNU: define i64 @f24() +// APCS-GNU: define i128 @f25() +// APCS-GNU: define i64 @f26() +// APCS-GNU: define i128 @f27() // AAPCS: define arm_aapcscc i16 @f22() // AAPCS: define arm_aapcscc i32 @f23() // AAPCS: define arm_aapcscc void @f24({{.*}} sret @@ -139,17 +139,17 @@ _Complex long long f25(void) {} _Complex float f26(void) {} _Complex double f27(void) {} -// APCS-GNU: define arm_apcscc i16 @f28() +// APCS-GNU: define i16 @f28() // AAPCS: define arm_aapcscc i16 @f28() struct s28 { _Complex char f0; }; struct s28 f28() {} -// APCS-GNU: define arm_apcscc i32 @f29() +// APCS-GNU: define i32 @f29() // AAPCS: define arm_aapcscc i32 @f29() struct s29 { _Complex short f0; }; struct s29 f29() {} -// APCS-GNU: define arm_apcscc void @f30({{.*}} sret +// APCS-GNU: define void @f30({{.*}} sret // AAPCS: define arm_aapcscc void @f30({{.*}} sret struct s30 { _Complex int f0; }; struct s30 f30() {} diff --git a/test/CodeGen/arm-cc.c b/test/CodeGen/arm-cc.c new file mode 100644 index 0000000000000..74eecc755f750 --- /dev/null +++ b/test/CodeGen/arm-cc.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple armv7-apple-darwin9 -target-abi apcs-gnu -emit-llvm -w -o - %s | FileCheck -check-prefix=DARWIN-APCS %s +// RUN: %clang_cc1 -triple armv7-apple-darwin9 -target-abi aapcs -emit-llvm -w -o - %s | FileCheck -check-prefix=DARWIN-AAPCS %s +// RUN: %clang_cc1 -triple arm-none-linux-gnueabi -target-abi apcs-gnu -emit-llvm -w -o - %s | FileCheck -check-prefix=LINUX-APCS %s +// RUN: %clang_cc1 -triple arm-none-linux-gnueabi -target-abi aapcs -emit-llvm -w -o - %s | FileCheck -check-prefix=LINUX-AAPCS %s + + +// DARWIN-APCS: define void @f() +// DARWIN-APCS: call void @g +// DARWIN-AAPCS: define arm_aapcscc void @f() +// DARWIN-AAPCS: call arm_aapcscc void @g +// LINUX-APCS: define arm_apcscc void @f() +// LINUX-APCS: call arm_apcscc void @g +// LINUX-AAPCS: define void @f() +// LINUX-AAPCS: call void @g +void g(void); +void f(void) { + g(); +} diff --git a/test/CodeGen/assign.c b/test/CodeGen/assign.c new file mode 100644 index 0000000000000..eab3d357692d6 --- /dev/null +++ b/test/CodeGen/assign.c @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -triple x86_64 -emit-llvm -o - %s | FileCheck %s + +// Check that we don't generate unnecessary reloads. +// +// CHECK: define void @f0() +// CHECK: [[x_0:%.*]] = alloca i32, align 4 +// CHECK-NEXT: [[y_0:%.*]] = alloca i32, align 4 +// CHECK-NEXT: store i32 1, i32* [[x_0]] +// CHECK-NEXT: store i32 1, i32* [[x_0]] +// CHECK-NEXT: store i32 1, i32* [[y_0]] +// CHECK: } +void f0() { + int x, y; + x = 1; + y = (x = 1); +} + +// Check that we do generate reloads for volatile access. +// +// CHECK: define void @f1() +// CHECK: [[x_1:%.*]] = alloca i32, align 4 +// CHECK-NEXT: [[y_1:%.*]] = alloca i32, align 4 +// CHECK-NEXT: volatile store i32 1, i32* [[x_1]] +// CHECK-NEXT: volatile store i32 1, i32* [[x_1]] +// CHECK-NEXT: [[tmp_1:%.*]] = volatile load i32* [[x_1]] +// CHECK-NEXT: volatile store i32 [[tmp_1]], i32* [[y_1]] +// CHECK: } +void f1() { + volatile int x, y; + x = 1; + y = (x = 1); +} diff --git a/test/CodeGen/available-externally-suppress.c b/test/CodeGen/available-externally-suppress.c new file mode 100644 index 0000000000000..c3b7a213baf6e --- /dev/null +++ b/test/CodeGen/available-externally-suppress.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple x86_64-apple-darwin10 %s | FileCheck %s + +// Ensure that we don't emit available_externally functions at -O0. +int x; + +inline void f0(int y) { x = y; } + +// CHECK: define void @test() +// CHECK: declare void @f0(i32) +void test() { + f0(17); +} diff --git a/test/CodeGen/blocks-aligned-byref-variable.c b/test/CodeGen/blocks-aligned-byref-variable.c index 79ac41dcd5d5e..07d683c3526e4 100644 --- a/test/CodeGen/blocks-aligned-byref-variable.c +++ b/test/CodeGen/blocks-aligned-byref-variable.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-apple-darwin10 -// RUN: %clang_cc1 -emit-llvm -o - -triple i386-apple-darwin10 +// RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-apple-darwin10 -fblocks %s +// RUN: %clang_cc1 -emit-llvm -o - -triple i386-apple-darwin10 -fblocks %s typedef int __attribute__((aligned(32))) ai; void f() { diff --git a/test/CodeGen/blocks.c b/test/CodeGen/blocks.c index a0f5dae6f44d4..6888356a5a1d6 100644 --- a/test/CodeGen/blocks.c +++ b/test/CodeGen/blocks.c @@ -27,3 +27,9 @@ void (^test1)(void) = ^(void) { ^ { i = 1; }(); }; +typedef double ftype(double); +// It's not clear that we *should* support this syntax, but until that decision +// is made, we should support it properly and not crash. +ftype ^test2 = ^ftype { + return 0; +}; diff --git a/test/CodeGen/builtin-attributes.c b/test/CodeGen/builtin-attributes.c index 944aac3f521fa..afde3fab84816 100644 --- a/test/CodeGen/builtin-attributes.c +++ b/test/CodeGen/builtin-attributes.c @@ -1,11 +1,11 @@ -// RUN: %clang_cc1 -triple arm-unknown-unknown -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple arm-unknown-linux-gnueabi -emit-llvm -o - %s | FileCheck %s -// CHECK: declare arm_aapcscc i32 @printf(i8*, ...) +// CHECK: declare i32 @printf(i8*, ...) void f0() { printf("a\n"); } -// CHECK: call arm_aapcscc void @exit +// CHECK: call void @exit // CHECK: unreachable void f1() { exit(1); diff --git a/test/CodeGen/builtins-arm.c b/test/CodeGen/builtins-arm.c index 5553757549598..546f57a4a18a3 100644 --- a/test/CodeGen/builtins-arm.c +++ b/test/CodeGen/builtins-arm.c @@ -1,6 +1,12 @@ -// RUN: %clang_cc1 -triple thumbv7-eabi -target-cpu cortex-a8 -O3 -emit-llvm -o %t %s +// RUN: %clang_cc1 -Wall -Werror -triple thumbv7-eabi -target-cpu cortex-a8 -O3 -emit-llvm -o - %s | FileCheck %s void *f0() { return __builtin_thread_pointer(); } + +void f1(char *a, char *b) { + __clear_cache(a,b); +} + +// CHECK: call void @__clear_cache diff --git a/test/CodeGen/builtins-ppc-altivec.c b/test/CodeGen/builtins-ppc-altivec.c index 04249cc1ee703..6f65866ae56a7 100644 --- a/test/CodeGen/builtins-ppc-altivec.c +++ b/test/CodeGen/builtins-ppc-altivec.c @@ -1,191 +1,1099 @@ // RUN: %clang_cc1 -faltivec -triple powerpc-unknown-unknown -emit-llvm %s -o - | FileCheck %s -#include "altivec.h" - -int main () -{ - vector signed char vsc = { 1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16 }; - vector unsigned char vuc = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; - vector short vs = { -1, 2, -3, 4, -5, 6, -7, 8 }; - vector unsigned short vus = { 1, 2, 3, 4, 5, 6, 7, 8 }; - vector int vi = { -1, 2, -3, 4 }; - vector unsigned int vui = { 1, 2, 3, 4 }; - vector float vf = { -1.5, 2.5, -3.5, 4.5 }; - - vector signed char res_vsc; - vector unsigned char res_vuc; - vector short res_vs; - vector unsigned short res_vus; - vector int res_vi; - vector unsigned int res_vui; - vector float res_vf; - - int param_i; - int res_i; +// TODO: uncomment +/* vector bool char vbc = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }; */ +vector signed char vsc = { 1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16 }; +vector unsigned char vuc = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; +// TODO: uncomment +/* vector bool short vbs = { 1, 0, 1, 0, 1, 0, 1, 0 }; */ +vector short vs = { -1, 2, -3, 4, -5, 6, -7, 8 }; +vector unsigned short vus = { 1, 2, 3, 4, 5, 6, 7, 8 }; +// TODO: uncomment +/* vector bool int vbi = { 1, 0, 1, 0 }; */ +vector int vi = { -1, 2, -3, 4 }; +vector unsigned int vui = { 1, 2, 3, 4 }; +vector float vf = { -1.5, 2.5, -3.5, 4.5 }; + +// TODO: uncomment +/* vector bool char res_vbc; */ +vector signed char res_vsc; +vector unsigned char res_vuc; +// TODO: uncomment +/* vector bool short res_vbs; */ +vector short res_vs; +vector unsigned short res_vus; +// TODO: uncomment +vector pixel res_vp; +// TODO: uncomment +/* vector bool int res_vbi; */ +vector int res_vi; +vector unsigned int res_vui; +vector float res_vf; + +signed char param_sc; +unsigned char param_uc; +short param_s; +unsigned short param_us; +int param_i; +unsigned int param_ui; +float param_f; + +int res_i; + +int test1() { +// CHECK: define i32 @test1 /* vec_abs */ - vsc = vec_abs(vsc); // CHECK: sub <16 x i8> zeroinitializer - // CHECK: @llvm.ppc.altivec.vmaxsb + vsc = vec_abs(vsc); // CHECK: sub nsw <16 x i8> zeroinitializer + // CHECK: @llvm.ppc.altivec.vmaxsb - vs = __builtin_vec_abs(vs); // CHECK: sub <8 x i16> zeroinitializer - // CHECK: @llvm.ppc.altivec.vmaxsh + vs = vec_abs(vs); // CHECK: sub nsw <8 x i16> zeroinitializer + // CHECK: @llvm.ppc.altivec.vmaxsh - vi = vec_abs(vi); // CHECK: sub <4 x i32> zeroinitializer - // CHECK: @llvm.ppc.altivec.vmaxsw + vi = vec_abs(vi); // CHECK: sub nsw <4 x i32> zeroinitializer + // CHECK: @llvm.ppc.altivec.vmaxsw - vf = vec_abs(vf); // CHECK: store <4 x i32> <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647> - // CHECK: and <4 x i32> + vf = vec_abs(vf); // CHECK: and <4 x i32> /* vec_abs */ - vsc = vec_abss(vsc); // CHECK: @llvm.ppc.altivec.vsubsbs - // CHECK: @llvm.ppc.altivec.vmaxsb + vsc = vec_abss(vsc); // CHECK: @llvm.ppc.altivec.vsubsbs + // CHECK: @llvm.ppc.altivec.vmaxsb - vs = __builtin_vec_abss(vs); // CHECK: @llvm.ppc.altivec.vsubshs - // CHECK: @llvm.ppc.altivec.vmaxsh + vs = vec_abss(vs); // CHECK: @llvm.ppc.altivec.vsubshs + // CHECK: @llvm.ppc.altivec.vmaxsh - vi = vec_abss(vi); // CHECK: @llvm.ppc.altivec.vsubsws - // CHECK: @llvm.ppc.altivec.vmaxsw + vi = vec_abss(vi); // CHECK: @llvm.ppc.altivec.vsubsws + // CHECK: @llvm.ppc.altivec.vmaxsw /* vec_add */ - res_vsc = vec_add(vsc, vsc); // CHECK: add nsw <16 x i8> + res_vsc = vec_add(vsc, vsc); // CHECK: add nsw <16 x i8> + res_vuc = vec_add(vuc, vuc); // CHECK: add <16 x i8> + res_vs = vec_add(vs, vs); // CHECK: add nsw <8 x i16> + res_vus = vec_add(vus, vus); // CHECK: add <8 x i16> + res_vi = vec_add(vi, vi); // CHECK: add nsw <4 x i32> + res_vui = vec_add(vui, vui); // CHECK: add <4 x i32> + res_vf = vec_add(vf, vf); // CHECK: fadd <4 x float> + res_vsc = vec_vaddubm(vsc, vsc); // CHECK: add nsw <16 x i8> res_vuc = vec_vaddubm(vuc, vuc); // CHECK: add <16 x i8> - res_vs = __builtin_altivec_vadduhm(vs, vs); // CHECK: add nsw <8 x i16> + res_vs = vec_vadduhm(vs, vs); // CHECK: add nsw <8 x i16> res_vus = vec_vadduhm(vus, vus); // CHECK: add <8 x i16> - res_vi = __builtin_vec_vadduwm(vi, vi); // CHECK: add nsw <4 x i32> + res_vi = vec_vadduwm(vi, vi); // CHECK: add nsw <4 x i32> res_vui = vec_vadduwm(vui, vui); // CHECK: add <4 x i32> - res_vf = __builtin_vec_vaddfp(vf, vf); // CHECK: fadd <4 x float> + res_vf = vec_vaddfp(vf, vf); // CHECK: fadd <4 x float> /* vec_addc */ + res_vui = vec_addc(vui, vui); // HECK: @llvm.ppc.altivec.vaddcuw res_vui = vec_vaddcuw(vui, vui); // HECK: @llvm.ppc.altivec.vaddcuw /* vec_adds */ - res_vsc = vec_adds(vsc, vsc); // CHECK: @llvm.ppc.altivec.vaddsbs + res_vsc = vec_adds(vsc, vsc); // CHECK: @llvm.ppc.altivec.vaddsbs + res_vuc = vec_adds(vuc, vuc); // CHECK: @llvm.ppc.altivec.vaddubs + res_vs = vec_adds(vs, vs); // CHECK: @llvm.ppc.altivec.vaddshs + res_vus = vec_adds(vus, vus); // CHECK: @llvm.ppc.altivec.vadduhs + res_vi = vec_adds(vi, vi); // CHECK: @llvm.ppc.altivec.vaddsws + res_vui = vec_adds(vui, vui); // CHECK: @llvm.ppc.altivec.vadduws + res_vsc = vec_vaddsbs(vsc, vsc); // CHECK: @llvm.ppc.altivec.vaddsbs res_vuc = vec_vaddubs(vuc, vuc); // CHECK: @llvm.ppc.altivec.vaddubs - res_vs = __builtin_vec_vaddshs(vs, vs); // CHECK: @llvm.ppc.altivec.vaddshs + res_vs = vec_vaddshs(vs, vs); // CHECK: @llvm.ppc.altivec.vaddshs res_vus = vec_vadduhs(vus, vus); // CHECK: @llvm.ppc.altivec.vadduhs - res_vi = __builtin_vec_vaddsws(vi, vi); // CHECK: @llvm.ppc.altivec.vaddsws + res_vi = vec_vaddsws(vi, vi); // CHECK: @llvm.ppc.altivec.vaddsws res_vui = vec_vadduws(vui, vui); // CHECK: @llvm.ppc.altivec.vadduws - /* vec_sub */ - res_vsc = vec_sub(vsc, vsc); // CHECK: sub nsw <16 x i8> - res_vuc = vec_vsububm(vuc, vuc); // CHECK: sub <16 x i8> - res_vs = __builtin_altivec_vsubuhm(vs, vs); // CHECK: sub nsw <8 x i16> - res_vus = vec_vsubuhm(vus, vus); // CHECK: sub <8 x i16> - res_vi = __builtin_vec_vsubuwm(vi, vi); // CHECK: sub nsw <4 x i32> - res_vui = vec_vsubuwm(vui, vui); // CHECK: sub <4 x i32> - res_vf = __builtin_vec_vsubfp(vf, vf); // CHECK: fsub <4 x float> + /* vec_and */ + res_vsc = vec_and(vsc, vsc); // CHECK: and <16 x i8> + res_vuc = vec_and(vuc, vuc); // CHECK: and <16 x i8> + res_vs = vec_and(vs, vs); // CHECK: and <8 x i16> + res_vus = vec_and(vus, vus); // CHECK: and <8 x i16> + res_vi = vec_and(vi, vi); // CHECK: and <4 x i32> + res_vui = vec_and(vui, vui); // CHECK: and <4 x i32> + res_vsc = vec_vand(vsc, vsc); // CHECK: and <16 x i8> + res_vuc = vec_vand(vuc, vuc); // CHECK: and <16 x i8> + res_vs = vec_vand(vs, vs); // CHECK: and <8 x i16> + res_vus = vec_vand(vus, vus); // CHECK: and <8 x i16> + res_vi = vec_vand(vi, vi); // CHECK: and <4 x i32> + res_vui = vec_vand(vui, vui); // CHECK: and <4 x i32> - /* vec_subs */ - res_vsc = vec_subs(vsc, vsc); // CHECK: @llvm.ppc.altivec.vsubsbs - res_vuc = vec_vsububs(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsububs - res_vs = __builtin_vec_vsubshs(vs, vs); // CHECK: @llvm.ppc.altivec.vsubshs - res_vus = vec_vsubuhs(vus, vus); // CHECK: @llvm.ppc.altivec.vsubuhs - res_vi = __builtin_vec_vsubsws(vi, vi); // CHECK: @llvm.ppc.altivec.vsubsws - res_vui = vec_vsubuws(vui, vui); // CHECK: @llvm.ppc.altivec.vsubuws + /* vec_andc */ + res_vsc = vec_andc(vsc, vsc); // CHECK: xor <16 x i8> + // CHECK: and <16 x i8> + + res_vuc = vec_andc(vuc, vuc); // CHECK: xor <16 x i8> + // CHECK: and <16 x i8> + + res_vs = vec_andc(vs, vs); // CHECK: xor <8 x i16> + // CHECK: and <8 x i16> + + res_vus = vec_andc(vus, vus); // CHECK: xor <8 x i16> + // CHECK: and <8 x i16> + + res_vi = vec_andc(vi, vi); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + + res_vui = vec_andc(vui, vui); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + + res_vf = vec_andc(vf, vf); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + + res_vsc = vec_vandc(vsc, vsc); // CHECK: xor <16 x i8> + // CHECK: and <16 x i8> + + res_vuc = vec_vandc(vuc, vuc); // CHECK: xor <16 x i8> + // CHECK: and <16 x i8> + res_vs = vec_vandc(vs, vs); // CHECK: xor <8 x i16> + // CHECK: and <8 x i16> + + res_vus = vec_vandc(vus, vus); // CHECK: xor <8 x i16> + // CHECK: and <8 x i16> + + res_vi = vec_vandc(vi, vi); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + + res_vui = vec_vandc(vui, vui); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + + res_vf = vec_vandc(vf, vf); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> +} + +// CHECK: i32 @test2 +int test2() { /* vec_avg */ - res_vsc = vec_avg(vsc, vsc); // CHECK: @llvm.ppc.altivec.vavgsb - res_vuc = __builtin_vec_vavgub(vuc, vuc); // CHECK: @llvm.ppc.altivec.vavgub + res_vsc = vec_avg(vsc, vsc); // CHECK: call {{.*}}@llvm.ppc.altivec.vavgsb + res_vuc = vec_avg(vuc, vuc); // CHECK: @llvm.ppc.altivec.vavgub + res_vs = vec_avg(vs, vs); // CHECK: @llvm.ppc.altivec.vavgsh + res_vus = vec_avg(vus, vus); // CHECK: @llvm.ppc.altivec.vavguh + res_vi = vec_avg(vi, vi); // CHECK: @llvm.ppc.altivec.vavgsw + res_vui = vec_avg(vui, vui); // CHECK: @llvm.ppc.altivec.vavguw + res_vsc = vec_vavgsb(vsc, vsc); // CHECK: @llvm.ppc.altivec.vavgsb + res_vuc = vec_vavgub(vuc, vuc); // CHECK: @llvm.ppc.altivec.vavgub res_vs = vec_vavgsh(vs, vs); // CHECK: @llvm.ppc.altivec.vavgsh - res_vus = __builtin_vec_vavguh(vus, vus); // CHECK: @llvm.ppc.altivec.vavguh + res_vus = vec_vavguh(vus, vus); // CHECK: @llvm.ppc.altivec.vavguh res_vi = vec_vavgsw(vi, vi); // CHECK: @llvm.ppc.altivec.vavgsw - res_vui = __builtin_vec_vavguw(vui, vui); // CHECK: @llvm.ppc.altivec.vavguw + res_vui = vec_vavguw(vui, vui); // CHECK: @llvm.ppc.altivec.vavguw - /* vec_st */ - param_i = 5; - vec_st(vsc, 0, &res_vsc); // CHECK: @llvm.ppc.altivec.stvx - __builtin_vec_st(vuc, param_i, &res_vuc); // CHECK: @llvm.ppc.altivec.stvx - vec_stvx(vs, 1, &res_vs); // CHECK: @llvm.ppc.altivec.stvx - vec_st(vus, 1000, &res_vus); // CHECK: @llvm.ppc.altivec.stvx - vec_st(vi, 0, &res_vi); // CHECK: @llvm.ppc.altivec.stvx - vec_st(vui, 0, &res_vui); // CHECK: @llvm.ppc.altivec.stvx - vec_st(vf, 0, &res_vf); // CHECK: @llvm.ppc.altivec.stvx - - /* vec_stl */ - param_i = 10000; - vec_stl(vsc, param_i, &res_vsc); // CHECK: @llvm.ppc.altivec.stvxl - __builtin_vec_stl(vuc, 1, &res_vuc); // CHECK: @llvm.ppc.altivec.stvxl - vec_stvxl(vs, 0, &res_vs); // CHECK: @llvm.ppc.altivec.stvxl - vec_stl(vus, 0, &res_vus); // CHECK: @llvm.ppc.altivec.stvxl - vec_stl(vi, 0, &res_vi); // CHECK: @llvm.ppc.altivec.stvxl - vec_stl(vui, 0, &res_vui); // CHECK: @llvm.ppc.altivec.stvxl - vec_stl(vf, 0, &res_vf); // CHECK: @llvm.ppc.altivec.stvxl - - /* vec_ste */ - param_i = 10000; - vec_ste(vsc, param_i, &res_vsc); // CHECK: @llvm.ppc.altivec.stvebx - vec_stvebx(vuc, 1, &res_vuc); // CHECK: @llvm.ppc.altivec.stvebx - __builtin_vec_stvehx(vs, 0, &res_vs); // CHECK: @llvm.ppc.altivec.stvehx - vec_stvehx(vus, 0, &res_vus); // CHECK: @llvm.ppc.altivec.stvehx - vec_stvewx(vi, 0, &res_vi); // CHECK: @llvm.ppc.altivec.stvewx - __builtin_vec_stvewx(vui, 0, &res_vui); // CHECK: @llvm.ppc.altivec.stvewx - vec_stvewx(vf, 0, &res_vf); // CHECK: @llvm.ppc.altivec.stvewx + /* vec_ceil */ + res_vf = vec_ceil(vf); // CHECK: @llvm.ppc.altivec.vrfip + res_vf = vec_vrfip(vf); // CHECK: @llvm.ppc.altivec.vrfip /* vec_cmpb */ + res_vi = vec_cmpb(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpbfp res_vi = vec_vcmpbfp(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpbfp /* vec_cmpeq */ - res_vi = vec_cmpeq(vsc, vsc); // CHECK: @llvm.ppc.altivec.vcmpequb - res_vi = __builtin_vec_cmpeq(vuc, vuc); // CHECK: @llvm.ppc.altivec.vcmpequb - res_vi = vec_cmpeq(vs, vs); // CHECK: @llvm.ppc.altivec.vcmpequh - res_vi = vec_cmpeq(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpequh - res_vi = vec_cmpeq(vi, vi); // CHECK: @llvm.ppc.altivec.vcmpequw - res_vi = vec_cmpeq(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpequw - res_vi = vec_cmpeq(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpeqfp + vsc = vec_cmpeq(vsc, vsc); // CHCK: call {{.*}}@llvm.ppc.altivec.vcmpequb + vuc = vec_cmpeq(vuc, vuc); // CHCK: @llvm.ppc.altivec.vcmpequb + vs = vec_cmpeq(vs, vs); // CHCK: @llvm.ppc.altivec.vcmpequh + vs = vec_cmpeq(vus, vus); // CHCK: @llvm.ppc.altivec.vcmpequh + vi = vec_cmpeq(vi, vi); // CHCK: @llvm.ppc.altivec.vcmpequw + vui = vec_cmpeq(vui, vui); // CHCK: @llvm.ppc.altivec.vcmpequw + vf = vec_cmpeq(vf, vf); // CHCK: @llvm.ppc.altivec.vcmpeqfp /* vec_cmpge */ - res_vi = __builtin_vec_cmpge(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgefp + vf = vec_cmpge(vf, vf); // CHCK: @llvm.ppc.altivec.vcmpgefp + vf = vec_vcmpgefp(vf, vf); // CHCK: call {{.*}}@llvm.ppc.altivec.vcmpgefp + +} +// CHECK: define i32 @test5 +int test5() { + /* vec_cmpgt */ - res_vi = vec_cmpgt(vsc, vsc); // CHECK: @llvm.ppc.altivec.vcmpgtsb - res_vi = vec_vcmpgtub(vuc, vuc); // CHECK: @llvm.ppc.altivec.vcmpgtub - res_vi = __builtin_vec_vcmpgtsh(vs, vs); // CHECK: @llvm.ppc.altivec.vcmpgtsh - res_vi = vec_cmpgt(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpgtuh - res_vi = vec_cmpgt(vi, vi); // CHECK: @llvm.ppc.altivec.vcmpgtsw - res_vi = vec_cmpgt(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpgtuw - res_vi = vec_cmpgt(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgtfp + vsc = vec_cmpgt(vsc, vsc); // CHECK: call {{.*}}@llvm.ppc.altivec.vcmpgtsb + vuc = vec_cmpgt(vuc, vuc); // CHECK: call {{.*}}@llvm.ppc.altivec.vcmpgtub + vs = vec_cmpgt(vs, vs); // CHECK: call {{.*}}@llvm.ppc.altivec.vcmpgtsh + vus = vec_cmpgt(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpgtuh + vi = vec_cmpgt(vi, vi); // CHECK: @llvm.ppc.altivec.vcmpgtsw + vui = vec_cmpgt(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpgtuw + vf = vec_cmpgt(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgtfp + vsc = vec_vcmpgtsb(vsc, vsc); // CHECK: @llvm.ppc.altivec.vcmpgtsb + vuc = vec_vcmpgtub(vuc, vuc); // CHECK: @llvm.ppc.altivec.vcmpgtub + vs = vec_vcmpgtsh(vs, vs); // CHECK: @llvm.ppc.altivec.vcmpgtsh + vus = vec_vcmpgtuh(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpgtuh + vi = vec_vcmpgtsw(vi, vi); // CHECK: @llvm.ppc.altivec.vcmpgtsw + vui = vec_vcmpgtuw(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpgtuw + vf = vec_vcmpgtfp(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgtfp /* vec_cmple */ - res_vi = __builtin_vec_cmple(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgefp + vf = vec_cmple(vf, vf); // CHECK: call {{.*}}@llvm.ppc.altivec.vcmpgefp +} +// CHECK: define i32 @test6 +int test6() { /* vec_cmplt */ - res_vi = vec_cmplt(vsc, vsc); // CHECK: @llvm.ppc.altivec.vcmpgtsb - res_vi = __builtin_vec_cmplt(vuc, vuc); // CHECK: @llvm.ppc.altivec.vcmpgtub - res_vi = vec_cmplt(vs, vs); // CHECK: @llvm.ppc.altivec.vcmpgtsh - res_vi = vec_cmplt(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpgtuh - res_vi = vec_cmplt(vi, vi); // CHECK: @llvm.ppc.altivec.vcmpgtsw - res_vi = vec_cmplt(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpgtuw - res_vi = vec_cmplt(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgtfp + vsc =vec_cmplt(vsc, vsc); // CHECK: call {{.*}}@llvm.ppc.altivec.vcmpgtsb + vsc =vec_cmplt(vuc, vuc); // CHECK: call {{.*}}@llvm.ppc.altivec.vcmpgtub + vs = vec_cmplt(vs, vs); // CHECK: call {{.*}}@llvm.ppc.altivec.vcmpgtsh + vs = vec_cmplt(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpgtuh + vi = vec_cmplt(vi, vi); // CHECK: @llvm.ppc.altivec.vcmpgtsw + vui = vec_cmplt(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpgtuw + vf = vec_cmplt(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgtfp + + /* vec_ctf */ + res_vf = vec_ctf(vi, param_i); // CHECK: @llvm.ppc.altivec.vcfsx + res_vf = vec_ctf(vui, 0); // CHECK: @llvm.ppc.altivec.vcfux + res_vf = vec_vcfsx(vi, 0); // CHECK: @llvm.ppc.altivec.vcfsx + res_vf = vec_vcfux(vui, 0); // CHECK: @llvm.ppc.altivec.vcfux + + /* vec_cts */ + res_vi = vec_cts(vf, 0); // CHECK: @llvm.ppc.altivec.vctsxs + res_vi = vec_vctsxs(vf, 0); // CHECK: @llvm.ppc.altivec.vctsxs + + /* vec_ctu */ + res_vui = vec_ctu(vf, 0); // CHECK: @llvm.ppc.altivec.vctuxs + res_vui = vec_vctuxs(vf, 0); // CHECK: @llvm.ppc.altivec.vctuxs + + /* vec_dss */ + vec_dss(param_i); // CHECK: @llvm.ppc.altivec.dss + + /* vec_dssall */ + vec_dssall(); // CHECK: @llvm.ppc.altivec.dssall + + /* vec_dst */ + vec_dst(&vsc, 0, 0); // CHECK: @llvm.ppc.altivec.dst + + /* vec_dstst */ + vec_dstst(&vs, 0, 0); // CHECK: @llvm.ppc.altivec.dstst + + /* vec_dststt */ + vec_dststt(¶m_i, 0, 0); // CHECK: @llvm.ppc.altivec.dststt + + /* vec_dstt */ + vec_dstt(&vf, 0, 0); // CHECK: @llvm.ppc.altivec.dstt + + /* vec_expte */ + res_vf = vec_expte(vf); // CHECK: @llvm.ppc.altivec.vexptefp + res_vf = vec_vexptefp(vf); // CHECK: @llvm.ppc.altivec.vexptefp + + /* vec_floor */ + res_vf = vec_floor(vf); // CHECK: @llvm.ppc.altivec.vrfim + res_vf = vec_vrfim(vf); // CHECK: @llvm.ppc.altivec.vrfim + + /* vec_ld */ + res_vsc = vec_ld(0, &vsc); // CHECK: @llvm.ppc.altivec.lvx + res_vsc = vec_ld(0, ¶m_sc); // CHECK: @llvm.ppc.altivec.lvx + res_vuc = vec_ld(0, &vuc); // CHECK: @llvm.ppc.altivec.lvx + res_vuc = vec_ld(0, ¶m_uc); // CHECK: @llvm.ppc.altivec.lvx + res_vs = vec_ld(0, &vs); // CHECK: @llvm.ppc.altivec.lvx + res_vs = vec_ld(0, ¶m_s); // CHECK: @llvm.ppc.altivec.lvx + res_vus = vec_ld(0, &vus); // CHECK: @llvm.ppc.altivec.lvx + res_vus = vec_ld(0, ¶m_us); // CHECK: @llvm.ppc.altivec.lvx + res_vi = vec_ld(0, &vi); // CHECK: @llvm.ppc.altivec.lvx + res_vi = vec_ld(0, ¶m_i); // CHECK: @llvm.ppc.altivec.lvx + res_vui = vec_ld(0, &vui); // CHECK: @llvm.ppc.altivec.lvx + res_vui = vec_ld(0, ¶m_ui); // CHECK: @llvm.ppc.altivec.lvx + res_vf = vec_ld(0, &vf); // CHECK: @llvm.ppc.altivec.lvx + res_vf = vec_ld(0, ¶m_f); // CHECK: @llvm.ppc.altivec.lvx + res_vsc = vec_lvx(0, &vsc); // CHECK: @llvm.ppc.altivec.lvx + res_vsc = vec_lvx(0, ¶m_sc); // CHECK: @llvm.ppc.altivec.lvx + res_vuc = vec_lvx(0, &vuc); // CHECK: @llvm.ppc.altivec.lvx + res_vuc = vec_lvx(0, ¶m_uc); // CHECK: @llvm.ppc.altivec.lvx + res_vs = vec_lvx(0, &vs); // CHECK: @llvm.ppc.altivec.lvx + res_vs = vec_lvx(0, ¶m_s); // CHECK: @llvm.ppc.altivec.lvx + res_vus = vec_lvx(0, &vus); // CHECK: @llvm.ppc.altivec.lvx + res_vus = vec_lvx(0, ¶m_us); // CHECK: @llvm.ppc.altivec.lvx + res_vi = vec_lvx(0, &vi); // CHECK: @llvm.ppc.altivec.lvx + res_vi = vec_lvx(0, ¶m_i); // CHECK: @llvm.ppc.altivec.lvx + res_vui = vec_lvx(0, &vui); // CHECK: @llvm.ppc.altivec.lvx + res_vui = vec_lvx(0, ¶m_ui); // CHECK: @llvm.ppc.altivec.lvx + res_vf = vec_lvx(0, &vf); // CHECK: @llvm.ppc.altivec.lvx + res_vf = vec_lvx(0, ¶m_f); // CHECK: @llvm.ppc.altivec.lvx + + /* vec_lde */ + res_vsc = vec_lde(0, &vsc); // CHECK: @llvm.ppc.altivec.lvebx + res_vuc = vec_lde(0, &vuc); // CHECK: @llvm.ppc.altivec.lvebx + res_vs = vec_lde(0, &vs); // CHECK: @llvm.ppc.altivec.lvehx + res_vus = vec_lde(0, &vus); // CHECK: @llvm.ppc.altivec.lvehx + res_vi = vec_lde(0, &vi); // CHECK: @llvm.ppc.altivec.lvewx + res_vui = vec_lde(0, &vui); // CHECK: @llvm.ppc.altivec.lvewx + res_vf = vec_lde(0, &vf); // CHECK: @llvm.ppc.altivec.lvewx + res_vsc = vec_lvebx(0, &vsc); // CHECK: @llvm.ppc.altivec.lvebx + res_vuc = vec_lvebx(0, &vuc); // CHECK: @llvm.ppc.altivec.lvebx + res_vs = vec_lvehx(0, &vs); // CHECK: @llvm.ppc.altivec.lvehx + res_vus = vec_lvehx(0, &vus); // CHECK: @llvm.ppc.altivec.lvehx + res_vi = vec_lvewx(0, &vi); // CHECK: @llvm.ppc.altivec.lvewx + res_vui = vec_lvewx(0, &vui); // CHECK: @llvm.ppc.altivec.lvewx + res_vf = vec_lvewx(0, &vf); // CHECK: @llvm.ppc.altivec.lvewx + + /* vec_ldl */ + res_vsc = vec_ldl(0, &vsc); // CHECK: @llvm.ppc.altivec.lvxl + res_vsc = vec_ldl(0, ¶m_sc); // CHECK: @llvm.ppc.altivec.lvxl + res_vuc = vec_ldl(0, &vuc); // CHECK: @llvm.ppc.altivec.lvxl + res_vuc = vec_ldl(0, ¶m_uc); // CHECK: @llvm.ppc.altivec.lvxl + res_vs = vec_ldl(0, &vs); // CHECK: @llvm.ppc.altivec.lvxl + res_vs = vec_ldl(0, ¶m_s); // CHECK: @llvm.ppc.altivec.lvxl + res_vus = vec_ldl(0, &vus); // CHECK: @llvm.ppc.altivec.lvxl + res_vus = vec_ldl(0, ¶m_us); // CHECK: @llvm.ppc.altivec.lvxl + res_vi = vec_ldl(0, &vi); // CHECK: @llvm.ppc.altivec.lvxl + res_vi = vec_ldl(0, ¶m_i); // CHECK: @llvm.ppc.altivec.lvxl + res_vui = vec_ldl(0, &vui); // CHECK: @llvm.ppc.altivec.lvxl + res_vui = vec_ldl(0, ¶m_ui); // CHECK: @llvm.ppc.altivec.lvxl + res_vf = vec_ldl(0, &vf); // CHECK: @llvm.ppc.altivec.lvxl + res_vf = vec_ldl(0, ¶m_f); // CHECK: @llvm.ppc.altivec.lvxl + res_vsc = vec_lvxl(0, &vsc); // CHECK: @llvm.ppc.altivec.lvxl + res_vsc = vec_lvxl(0, ¶m_sc); // CHECK: @llvm.ppc.altivec.lvxl + res_vuc = vec_lvxl(0, &vuc); // CHECK: @llvm.ppc.altivec.lvxl + res_vuc = vec_lvxl(0, ¶m_uc); // CHECK: @llvm.ppc.altivec.lvxl + res_vs = vec_lvxl(0, &vs); // CHECK: @llvm.ppc.altivec.lvxl + res_vs = vec_lvxl(0, ¶m_s); // CHECK: @llvm.ppc.altivec.lvxl + res_vus = vec_lvxl(0, &vus); // CHECK: @llvm.ppc.altivec.lvxl + res_vus = vec_lvxl(0, ¶m_us); // CHECK: @llvm.ppc.altivec.lvxl + res_vi = vec_lvxl(0, &vi); // CHECK: @llvm.ppc.altivec.lvxl + res_vi = vec_lvxl(0, ¶m_i); // CHECK: @llvm.ppc.altivec.lvxl + res_vui = vec_lvxl(0, &vui); // CHECK: @llvm.ppc.altivec.lvxl + res_vui = vec_lvxl(0, ¶m_ui); // CHECK: @llvm.ppc.altivec.lvxl + res_vf = vec_lvxl(0, &vf); // CHECK: @llvm.ppc.altivec.lvxl + res_vf = vec_lvxl(0, ¶m_f); // CHECK: @llvm.ppc.altivec.lvxl + + /* vec_loge */ + res_vf = vec_loge(vf); // CHECK: @llvm.ppc.altivec.vlogefp + res_vf = vec_vlogefp(vf); // CHECK: @llvm.ppc.altivec.vlogefp + + /* vec_lvsl */ + res_vuc = vec_lvsl(0, ¶m_i); // CHECK: @llvm.ppc.altivec.lvsl + + /* vec_lvsr */ + res_vuc = vec_lvsr(0, ¶m_i); // CHECK: @llvm.ppc.altivec.lvsr + + /* vec_madd */ + res_vf =vec_madd(vf, vf, vf); // CHECK: @llvm.ppc.altivec.vmaddfp + res_vf = vec_vmaddfp(vf, vf, vf); // CHECK: @llvm.ppc.altivec.vmaddfp + + /* vec_madds */ + res_vs = vec_madds(vs, vs, vs); // CHECK: @llvm.ppc.altivec.vmhaddshs + res_vs = vec_vmhaddshs(vs, vs, vs); // CHECK: @llvm.ppc.altivec.vmhaddshs /* vec_max */ - res_vsc = vec_max(vsc, vsc); // CHECK: @llvm.ppc.altivec.vmaxsb - res_vuc = __builtin_vec_vmaxub(vuc, vuc); // CHECK: @llvm.ppc.altivec.vmaxub - res_vs = vec_vmaxsh(vs, vs); // CHECK: @llvm.ppc.altivec.vmaxsh + res_vsc = vec_max(vsc, vsc); // CHECK: @llvm.ppc.altivec.vmaxsb + res_vuc = vec_max(vuc, vuc); // CHECK: @llvm.ppc.altivec.vmaxub + res_vs = vec_max(vs, vs); // CHECK: @llvm.ppc.altivec.vmaxsh res_vus = vec_max(vus, vus); // CHECK: @llvm.ppc.altivec.vmaxuh - res_vi = __builtin_vec_vmaxsw(vi, vi); // CHECK: @llvm.ppc.altivec.vmaxsw + res_vi = vec_max(vi, vi); // CHECK: @llvm.ppc.altivec.vmaxsw + res_vui = vec_max(vui, vui); // CHECK: @llvm.ppc.altivec.vmaxuw + res_vf = vec_max(vf, vf); // CHECK: @llvm.ppc.altivec.vmaxfp + res_vsc = vec_vmaxsb(vsc, vsc); // CHECK: @llvm.ppc.altivec.vmaxsb + res_vuc = vec_vmaxub(vuc, vuc); // CHECK: @llvm.ppc.altivec.vmaxub + res_vs = vec_vmaxsh(vs, vs); // CHECK: @llvm.ppc.altivec.vmaxsh + res_vus = vec_vmaxuh(vus, vus); // CHECK: @llvm.ppc.altivec.vmaxuh + res_vi = vec_vmaxsw(vi, vi); // CHECK: @llvm.ppc.altivec.vmaxsw res_vui = vec_vmaxuw(vui, vui); // CHECK: @llvm.ppc.altivec.vmaxuw - res_vf = __builtin_vec_max(vf, vf); // CHECK: @llvm.ppc.altivec.vmaxfp + res_vf = vec_vmaxfp(vf, vf); // CHECK: @llvm.ppc.altivec.vmaxfp + + /* vec_mergeh */ + res_vsc = vec_mergeh(vsc, vsc); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_mergeh(vuc, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_mergeh(vs, vs); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_mergeh(vus, vus); // CHECK: @llvm.ppc.altivec.vperm + res_vi = vec_mergeh(vi, vi); // CHECK: @llvm.ppc.altivec.vperm + res_vui = vec_mergeh(vui, vui); // CHECK: @llvm.ppc.altivec.vperm + res_vf = vec_mergeh(vf, vf); // CHECK: @llvm.ppc.altivec.vperm + res_vsc = vec_vmrghb(vsc, vsc); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_vmrghb(vuc, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_vmrghh(vs, vs); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_vmrghh(vus, vus); // CHECK: @llvm.ppc.altivec.vperm + res_vi = vec_vmrghw(vi, vi); // CHECK: @llvm.ppc.altivec.vperm + res_vui = vec_vmrghw(vui, vui); // CHECK: @llvm.ppc.altivec.vperm + res_vf = vec_vmrghw(vf, vf); // CHECK: @llvm.ppc.altivec.vperm + + /* vec_mergel */ + res_vsc = vec_mergel(vsc, vsc); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_mergel(vuc, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_mergel(vs, vs); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_mergel(vus, vus); // CHECK: @llvm.ppc.altivec.vperm + res_vi = vec_mergel(vi, vi); // CHECK: @llvm.ppc.altivec.vperm + res_vui = vec_mergel(vui, vui); // CHECK: @llvm.ppc.altivec.vperm + res_vf = vec_mergel(vf, vf); // CHECK: @llvm.ppc.altivec.vperm + res_vsc = vec_vmrglb(vsc, vsc); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_vmrglb(vuc, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_vmrglh(vs, vs); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_vmrglh(vus, vus); // CHECK: @llvm.ppc.altivec.vperm + res_vi = vec_vmrglw(vi, vi); // CHECK: @llvm.ppc.altivec.vperm + res_vui = vec_vmrglw(vui, vui); // CHECK: @llvm.ppc.altivec.vperm + res_vf = vec_vmrglw(vf, vf); // CHECK: @llvm.ppc.altivec.vperm /* vec_mfvscr */ - vf = vec_mfvscr(); // CHECK: @llvm.ppc.altivec.mfvscr + vus = vec_mfvscr(); // CHECK: @llvm.ppc.altivec.mfvscr /* vec_min */ - res_vsc = vec_min(vsc, vsc); // CHECK: @llvm.ppc.altivec.vminsb - res_vuc = __builtin_vec_vminub(vuc, vuc); // CHECK: @llvm.ppc.altivec.vminub - res_vs = vec_vminsh(vs, vs); // CHECK: @llvm.ppc.altivec.vminsh + res_vsc = vec_min(vsc, vsc); // CHECK: @llvm.ppc.altivec.vminsb + res_vuc = vec_min(vuc, vuc); // CHECK: @llvm.ppc.altivec.vminub + res_vs = vec_min(vs, vs); // CHECK: @llvm.ppc.altivec.vminsh res_vus = vec_min(vus, vus); // CHECK: @llvm.ppc.altivec.vminuh - res_vi = __builtin_vec_vminsw(vi, vi); // CHECK: @llvm.ppc.altivec.vminsw + res_vi = vec_min(vi, vi); // CHECK: @llvm.ppc.altivec.vminsw + res_vui = vec_min(vui, vui); // CHECK: @llvm.ppc.altivec.vminuw + res_vf = vec_min(vf, vf); // CHECK: @llvm.ppc.altivec.vminfp + res_vsc = vec_vminsb(vsc, vsc); // CHECK: @llvm.ppc.altivec.vminsb + res_vuc = vec_vminub(vuc, vuc); // CHECK: @llvm.ppc.altivec.vminub + res_vs = vec_vminsh(vs, vs); // CHECK: @llvm.ppc.altivec.vminsh + res_vus = vec_vminuh(vus, vus); // CHECK: @llvm.ppc.altivec.vminuh + res_vi = vec_vminsw(vi, vi); // CHECK: @llvm.ppc.altivec.vminsw res_vui = vec_vminuw(vui, vui); // CHECK: @llvm.ppc.altivec.vminuw - res_vf = __builtin_vec_min(vf, vf); // CHECK: @llvm.ppc.altivec.vminfp + res_vf = vec_vminfp(vf, vf); // CHECK: @llvm.ppc.altivec.vminfp + + /* vec_mladd */ + res_vus = vec_mladd(vus, vus, vus); // CHECK: mul <8 x i16> + // CHECK: add <8 x i16> + + res_vs = vec_mladd(vus, vs, vs); // CHECK: mul nsw <8 x i16> + // CHECK: add nsw <8 x i16> + + res_vs = vec_mladd(vs, vus, vus); // CHECK: mul nsw <8 x i16> + // CHECK: add nsw <8 x i16> + + res_vs = vec_mladd(vs, vs, vs); // CHECK: mul nsw <8 x i16> + // CHECK: add nsw <8 x i16> + + /* vec_mradds */ + res_vs = vec_mradds(vs, vs, vs); // CHECK: @llvm.ppc.altivec.vmhraddshs + res_vs = vec_vmhraddshs(vs, vs, vs); // CHECK: @llvm.ppc.altivec.vmhraddshs + + /* vec_msum */ + res_vi = vec_msum(vsc, vuc, vi); // CHECK: @llvm.ppc.altivec.vmsummbm + res_vui = vec_msum(vuc, vuc, vui); // CHECK: @llvm.ppc.altivec.vmsumubm + res_vi = vec_msum(vs, vs, vi); // CHECK: @llvm.ppc.altivec.vmsumshm + res_vui = vec_msum(vus, vus, vui); // CHECK: @llvm.ppc.altivec.vmsumuhm + res_vi = vec_vmsummbm(vsc, vuc, vi); // CHECK: @llvm.ppc.altivec.vmsummbm + res_vui = vec_vmsumubm(vuc, vuc, vui); // CHECK: @llvm.ppc.altivec.vmsumubm + res_vi = vec_vmsumshm(vs, vs, vi); // CHECK: @llvm.ppc.altivec.vmsumshm + res_vui = vec_vmsumuhm(vus, vus, vui); // CHECK: @llvm.ppc.altivec.vmsumuhm + + /* vec_msums */ + res_vi = vec_msums(vs, vs, vi); // CHECK: @llvm.ppc.altivec.vmsumshs + res_vui = vec_msums(vus, vus, vui); // CHECK: @llvm.ppc.altivec.vmsumuhs + res_vi = vec_vmsumshs(vs, vs, vi); // CHECK: @llvm.ppc.altivec.vmsumshs + res_vui = vec_vmsumuhs(vus, vus, vui); // CHECK: @llvm.ppc.altivec.vmsumuhs /* vec_mtvscr */ vec_mtvscr(vsc); // CHECK: @llvm.ppc.altivec.mtvscr - /* ------------------------------ predicates -------------------------------------- */ + /* vec_mule */ + res_vs = vec_mule(vsc, vsc); // CHECK: @llvm.ppc.altivec.vmulesb + res_vus = vec_mule(vuc, vuc); // CHECK: @llvm.ppc.altivec.vmuleub + res_vi = vec_mule(vs, vs); // CHECK: @llvm.ppc.altivec.vmulesh + res_vui = vec_mule(vus, vus); // CHECK: @llvm.ppc.altivec.vmuleuh + res_vs = vec_vmulesb(vsc, vsc); // CHECK: @llvm.ppc.altivec.vmulesb + res_vus = vec_vmuleub(vuc, vuc); // CHECK: @llvm.ppc.altivec.vmuleub + res_vi = vec_vmulesh(vs, vs); // CHECK: @llvm.ppc.altivec.vmulesh + res_vui = vec_vmuleuh(vus, vus); // CHECK: @llvm.ppc.altivec.vmuleuh + + /* vec_mulo */ + res_vs = vec_mulo(vsc, vsc); // CHECK: @llvm.ppc.altivec.vmulosb + res_vus = vec_mulo(vuc, vuc); // CHECK: @llvm.ppc.altivec.vmuloub + res_vi = vec_mulo(vs, vs); // CHECK: @llvm.ppc.altivec.vmulosh + res_vui = vec_mulo(vus, vus); // CHECK: @llvm.ppc.altivec.vmulouh + res_vs = vec_vmulosb(vsc, vsc); // CHECK: @llvm.ppc.altivec.vmulosb + res_vus = vec_vmuloub(vuc, vuc); // CHECK: @llvm.ppc.altivec.vmuloub + res_vi = vec_vmulosh(vs, vs); // CHECK: @llvm.ppc.altivec.vmulosh + res_vui = vec_vmulouh(vus, vus); // CHECK: @llvm.ppc.altivec.vmulouh + + /* vec_nmsub */ + res_vf = vec_nmsub(vf, vf, vf); // CHECK: @llvm.ppc.altivec.vnmsubfp + res_vf = vec_vnmsubfp(vf, vf, vf); // CHECK: @llvm.ppc.altivec.vnmsubfp + + /* vec_nor */ + res_vsc = vec_nor(vsc, vsc); // CHECK: or <16 x i8> + // CHECK: xor <16 x i8> + + res_vuc = vec_nor(vuc, vuc); // CHECK: or <16 x i8> + // CHECK: xor <16 x i8> + + res_vs = vec_nor(vs, vs); // CHECK: or <8 x i16> + // CHECK: xor <8 x i16> + + res_vus = vec_nor(vus, vus); // CHECK: or <8 x i16> + // CHECK: xor <8 x i16> + + res_vi = vec_nor(vi, vi); // CHECK: or <4 x i32> + // CHECK: xor <4 x i32> + + res_vui = vec_nor(vui, vui); // CHECK: or <4 x i32> + // CHECK: xor <4 x i32> + + res_vf = vec_nor(vf, vf); // CHECK: or <4 x i32> + // CHECK: xor <4 x i32> + + res_vsc = vec_vnor(vsc, vsc); // CHECK: or <16 x i8> + // CHECK: xor <16 x i8> + + res_vuc = vec_vnor(vuc, vuc); // CHECK: or <16 x i8> + // CHECK: xor <16 x i8> - res_i = __builtin_vec_vcmpeq_p(__CR6_EQ, vsc, vui); // CHECK: @llvm.ppc.altivec.vcmpeqfp.p - res_i = __builtin_vec_vcmpge_p(__CR6_EQ, vs, vi); // CHECK: @llvm.ppc.altivec.vcmpgefp.p - res_i = __builtin_vec_vcmpgt_p(__CR6_EQ, vuc, vf); // CHECK: @llvm.ppc.altivec.vcmpgtfp.p + res_vs = vec_vnor(vs, vs); // CHECK: or <8 x i16> + // CHECK: xor <8 x i16> + + res_vus = vec_vnor(vus, vus); // CHECK: or <8 x i16> + // CHECK: xor <8 x i16> + + res_vi = vec_vnor(vi, vi); // CHECK: or <4 x i32> + // CHECK: xor <4 x i32> + + res_vui = vec_vnor(vui, vui); // CHECK: or <4 x i32> + // CHECK: xor <4 x i32> + + res_vf = vec_vnor(vf, vf); // CHECK: or <4 x i32> + // CHECK: xor <4 x i32> + + /* vec_or */ + res_vsc = vec_or(vsc, vsc); // CHECK: or <16 x i8> + res_vuc = vec_or(vuc, vuc); // CHECK: or <16 x i8> + res_vs = vec_or(vs, vs); // CHECK: or <8 x i16> + res_vus = vec_or(vus, vus); // CHECK: or <8 x i16> + res_vi = vec_or(vi, vi); // CHECK: or <4 x i32> + res_vui = vec_or(vui, vui); // CHECK: or <4 x i32> + res_vf = vec_or(vf, vf); // CHECK: or <4 x i32> + res_vsc = vec_vor(vsc, vsc); // CHECK: or <16 x i8> + res_vuc = vec_vor(vuc, vuc); // CHECK: or <16 x i8> + res_vs = vec_vor(vs, vs); // CHECK: or <8 x i16> + res_vus = vec_vor(vus, vus); // CHECK: or <8 x i16> + res_vi = vec_vor(vi, vi); // CHECK: or <4 x i32> + res_vui = vec_vor(vui, vui); // CHECK: or <4 x i32> + res_vf = vec_vor(vf, vf); // CHECK: or <4 x i32> + + /* vec_pack */ + res_vsc = vec_pack(vs, vs); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_pack(vus, vus); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_pack(vi, vi); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_pack(vui, vui); // CHECK: @llvm.ppc.altivec.vperm + res_vsc = vec_vpkuhum(vs, vs); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_vpkuhum(vus, vus); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_vpkuwum(vi, vi); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_vpkuwum(vui, vui); // CHECK: @llvm.ppc.altivec.vperm + + /* vec_packpx */ + res_vp = vec_packpx(vui, vui); // CHECK: @llvm.ppc.altivec.vpkpx + res_vp = vec_vpkpx(vui, vui); // CHECK: @llvm.ppc.altivec.vpkpx + + /* vec_packs */ + res_vsc = vec_packs(vs, vs); // CHECK: @llvm.ppc.altivec.vpkshss + res_vuc = vec_packs(vus, vus); // CHECK: @llvm.ppc.altivec.vpkuhus + res_vs = vec_packs(vi, vi); // CHECK: @llvm.ppc.altivec.vpkswss + res_vus = vec_packs(vui, vui); // CHECK: @llvm.ppc.altivec.vpkuwus + res_vsc = vec_vpkshss(vs, vs); // CHECK: @llvm.ppc.altivec.vpkshss + res_vuc = vec_vpkuhus(vus, vus); // CHECK: @llvm.ppc.altivec.vpkuhus + res_vs = vec_vpkswss(vi, vi); // CHECK: @llvm.ppc.altivec.vpkswss + res_vus = vec_vpkuwus(vui, vui); // CHECK: @llvm.ppc.altivec.vpkuwus + + /* vec_packsu */ + res_vuc = vec_packsu(vs, vs); // CHECK: @llvm.ppc.altivec.vpkshus + res_vuc = vec_packsu(vus, vus); // CHECK: @llvm.ppc.altivec.vpkuhus + res_vus = vec_packsu(vi, vi); // CHECK: @llvm.ppc.altivec.vpkswus + res_vus = vec_packsu(vui, vui); // CHECK: @llvm.ppc.altivec.vpkuwus + res_vuc = vec_vpkshus(vs, vs); // CHECK: @llvm.ppc.altivec.vpkshus + res_vuc = vec_vpkshus(vus, vus); // CHECK: @llvm.ppc.altivec.vpkuhus + res_vus = vec_vpkswus(vi, vi); // CHECK: @llvm.ppc.altivec.vpkswus + res_vus = vec_vpkswus(vui, vui); // CHECK: @llvm.ppc.altivec.vpkuwus + + /* vec_perm */ + res_vsc = vec_perm(vsc, vsc, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_perm(vuc, vuc, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_perm(vs, vs, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_perm(vus, vus, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vi = vec_perm(vi, vi, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vui = vec_perm(vui, vui, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vf = vec_perm(vf, vf, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vsc = vec_vperm(vsc, vsc, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_vperm(vuc, vuc, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_vperm(vs, vs, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_vperm(vus, vus, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vi = vec_vperm(vi, vi, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vui = vec_vperm(vui, vui, vuc); // CHECK: @llvm.ppc.altivec.vperm + res_vf = vec_vperm(vf, vf, vuc); // CHECK: @llvm.ppc.altivec.vperm + + /* vec_re */ + res_vf = vec_re(vf); // CHECK: @llvm.ppc.altivec.vrefp + res_vf = vec_vrefp(vf); // CHECK: @llvm.ppc.altivec.vrefp + + /* vec_rl */ + res_vsc = vec_rl(vsc, vuc); // CHECK: @llvm.ppc.altivec.vrlb + res_vuc = vec_rl(vuc, vuc); // CHECK: @llvm.ppc.altivec.vrlb + res_vs = vec_rl(vs, vus); // CHECK: @llvm.ppc.altivec.vrlh + res_vus = vec_rl(vus, vus); // CHECK: @llvm.ppc.altivec.vrlh + res_vi = vec_rl(vi, vui); // CHECK: @llvm.ppc.altivec.vrlw + res_vui = vec_rl(vui, vui); // CHECK: @llvm.ppc.altivec.vrlw + res_vsc = vec_vrlb(vsc, vuc); // CHECK: @llvm.ppc.altivec.vrlb + res_vuc = vec_vrlb(vuc, vuc); // CHECK: @llvm.ppc.altivec.vrlb + res_vs = vec_vrlh(vs, vus); // CHECK: @llvm.ppc.altivec.vrlh + res_vus = vec_vrlh(vus, vus); // CHECK: @llvm.ppc.altivec.vrlh + res_vi = vec_vrlw(vi, vui); // CHECK: @llvm.ppc.altivec.vrlw + res_vui = vec_vrlw(vui, vui); // CHECK: @llvm.ppc.altivec.vrlw + + /* vec_round */ + res_vf = vec_round(vf); // CHECK: @llvm.ppc.altivec.vrfin + res_vf = vec_vrfin(vf); // CHECK: @llvm.ppc.altivec.vrfin + + /* vec_rsqrte */ + res_vf = vec_rsqrte(vf); // CHECK: @llvm.ppc.altivec.vrsqrtefp + res_vf = vec_vrsqrtefp(vf); // CHECK: @llvm.ppc.altivec.vrsqrtefp + + /* vec_sel */ + res_vsc = vec_sel(vsc, vsc, vuc); // CHECK: xor <16 x i8> + // CHECK: and <16 x i8> + // CHECK: and <16 x i8> + // CHECK: or <16 x i8> + + res_vuc = vec_sel(vuc, vuc, vuc); // CHECK: xor <16 x i8> + // CHECK: and <16 x i8> + // CHECK: and <16 x i8> + // CHECK: or <16 x i8> + + res_vs = vec_sel(vs, vs, vus); // CHECK: xor <8 x i16> + // CHECK: and <8 x i16> + // CHECK: and <8 x i16> + // CHECK: or <8 x i16> + + + res_vus = vec_sel(vus, vus, vus); // CHECK: xor <8 x i16> + // CHECK: and <8 x i16> + // CHECK: and <8 x i16> + // CHECK: or <8 x i16> + + res_vi = vec_sel(vi, vi, vui); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + // CHECK: and <4 x i32> + // CHECK: or <4 x i32> + + + res_vui = vec_sel(vui, vui, vui); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + // CHECK: and <4 x i32> + // CHECK: or <4 x i32> + + + res_vf = vec_sel(vf, vf, vui); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + // CHECK: and <4 x i32> + // CHECK: or <4 x i32> + + res_vsc = vec_vsel(vsc, vsc, vuc); // CHECK: xor <16 x i8> + // CHECK: and <16 x i8> + // CHECK: and <16 x i8> + // CHECK: or <16 x i8> + + res_vuc = vec_vsel(vuc, vuc, vuc); // CHECK: xor <16 x i8> + // CHECK: and <16 x i8> + // CHECK: and <16 x i8> + // CHECK: or <16 x i8> + + res_vs = vec_vsel(vs, vs, vus); // CHECK: xor <8 x i16> + // CHECK: and <8 x i16> + // CHECK: and <8 x i16> + // CHECK: or <8 x i16> + + + res_vus = vec_vsel(vus, vus, vus); // CHECK: xor <8 x i16> + // CHECK: and <8 x i16> + // CHECK: and <8 x i16> + // CHECK: or <8 x i16> + + res_vi = vec_vsel(vi, vi, vui); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + // CHECK: and <4 x i32> + // CHECK: or <4 x i32> + + + res_vui = vec_vsel(vui, vui, vui); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + // CHECK: and <4 x i32> + // CHECK: or <4 x i32> + + + res_vf = vec_vsel(vf, vf, vui); // CHECK: xor <4 x i32> + // CHECK: and <4 x i32> + // CHECK: and <4 x i32> + // CHECK: or <4 x i32> + + + /* vec_sl */ + res_vsc = vec_sl(vsc, vuc); // CHECK: shl <16 x i8> + res_vuc = vec_sl(vuc, vuc); // CHECK: shl <16 x i8> + res_vs = vec_sl(vs, vus); // CHECK: shl <8 x i16> + res_vus = vec_sl(vus, vus); // CHECK: shl <8 x i16> + res_vi = vec_sl(vi, vui); // CHECK: shl <4 x i32> + res_vui = vec_sl(vui, vui); // CHECK: shl <4 x i32> + res_vsc = vec_vslb(vsc, vuc); // CHECK: shl <16 x i8> + res_vuc = vec_vslb(vuc, vuc); // CHECK: shl <16 x i8> + res_vs = vec_vslh(vs, vus); // CHECK: shl <8 x i16> + res_vus = vec_vslh(vus, vus); // CHECK: shl <8 x i16> + res_vi = vec_vslw(vi, vui); // CHECK: shl <4 x i32> + res_vui = vec_vslw(vui, vui); // CHECK: shl <4 x i32> + + /* vec_sld */ + res_vsc = vec_sld(vsc, vsc, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_sld(vuc, vuc, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_sld(vs, vs, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_sld(vus, vus, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vi = vec_sld(vi, vi, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vui = vec_sld(vui, vui, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vf = vec_sld(vf, vf, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vsc = vec_vsldoi(vsc, vsc, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_vsldoi(vuc, vuc, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_vsldoi(vs, vs, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_vsldoi(vus, vus, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vi = vec_vsldoi(vi, vi, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vui = vec_vsldoi(vui, vui, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vf = vec_vsldoi(vf, vf, 0); // CHECK: @llvm.ppc.altivec.vperm + + /* vec_sll */ + res_vsc = vec_sll(vsc, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vsc = vec_sll(vsc, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vsc = vec_sll(vsc, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vuc = vec_sll(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vuc = vec_sll(vuc, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vuc = vec_sll(vuc, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vs = vec_sll(vs, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vs = vec_sll(vs, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vs = vec_sll(vs, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vus = vec_sll(vus, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vus = vec_sll(vus, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vus = vec_sll(vus, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vi = vec_sll(vi, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vi = vec_sll(vi, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vi = vec_sll(vi, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vui = vec_sll(vui, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vui = vec_sll(vui, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vui = vec_sll(vui, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vsc = vec_vsl(vsc, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vsc = vec_vsl(vsc, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vsc = vec_vsl(vsc, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vuc = vec_vsl(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vuc = vec_vsl(vuc, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vuc = vec_vsl(vuc, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vs = vec_vsl(vs, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vs = vec_vsl(vs, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vs = vec_vsl(vs, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vus = vec_vsl(vus, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vus = vec_vsl(vus, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vus = vec_vsl(vus, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vi = vec_vsl(vi, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vi = vec_vsl(vi, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vi = vec_vsl(vi, vui); // CHECK: @llvm.ppc.altivec.vsl + res_vui = vec_vsl(vui, vuc); // CHECK: @llvm.ppc.altivec.vsl + res_vui = vec_vsl(vui, vus); // CHECK: @llvm.ppc.altivec.vsl + res_vui = vec_vsl(vui, vui); // CHECK: @llvm.ppc.altivec.vsl + + /* vec_slo */ + res_vsc = vec_slo(vsc, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vsc = vec_slo(vsc, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vuc = vec_slo(vuc, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vuc = vec_slo(vuc, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vs = vec_slo(vs, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vs = vec_slo(vs, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vus = vec_slo(vus, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vus = vec_slo(vus, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vi = vec_slo(vi, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vi = vec_slo(vi, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vui = vec_slo(vui, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vui = vec_slo(vui, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vf = vec_slo(vf, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vf = vec_slo(vf, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vsc = vec_vslo(vsc, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vsc = vec_vslo(vsc, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vuc = vec_vslo(vuc, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vuc = vec_vslo(vuc, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vs = vec_vslo(vs, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vs = vec_vslo(vs, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vus = vec_vslo(vus, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vus = vec_vslo(vus, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vi = vec_vslo(vi, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vi = vec_vslo(vi, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vui = vec_vslo(vui, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vui = vec_vslo(vui, vuc); // CHECK: @llvm.ppc.altivec.vslo + res_vf = vec_vslo(vf, vsc); // CHECK: @llvm.ppc.altivec.vslo + res_vf = vec_vslo(vf, vuc); // CHECK: @llvm.ppc.altivec.vslo + + /* vec_splat */ + res_vsc = vec_splat(vsc, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_splat(vuc, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_splat(vs, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_splat(vus, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vi = vec_splat(vi, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vui = vec_splat(vui, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vf = vec_splat(vf, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vsc = vec_vspltb(vsc, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vuc = vec_vspltb(vuc, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vs = vec_vsplth(vs, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vus = vec_vsplth(vus, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vi = vec_vspltw(vi, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vui = vec_vspltw(vui, 0); // CHECK: @llvm.ppc.altivec.vperm + res_vf = vec_vspltw(vf, 0); // CHECK: @llvm.ppc.altivec.vperm + + /* vec_splat_s8 */ + res_vsc = vec_splat_s8(0x09); // TODO: add check + res_vsc = vec_vspltisb(0x09); // TODO: add check + + /* vec_splat_s16 */ + res_vs = vec_splat_s16(0x09); // TODO: add check + res_vs = vec_vspltish(0x09); // TODO: add check + + /* vec_splat_s32 */ + res_vi = vec_splat_s32(0x09); // TODO: add check + res_vi = vec_vspltisw(0x09); // TODO: add check + + /* vec_splat_u8 */ + res_vuc = vec_splat_u8(0x09); // TODO: add check + + /* vec_splat_u16 */ + res_vus = vec_splat_u16(0x09); // TODO: add check + + /* vec_splat_u32 */ + res_vui = vec_splat_u32(0x09); // TODO: add check + + /* vec_sr */ + res_vsc = vec_sr(vsc, vuc); // CHECK: shr <16 x i8> + res_vuc = vec_sr(vuc, vuc); // CHECK: shr <16 x i8> + res_vs = vec_sr(vs, vus); // CHECK: shr <8 x i16> + res_vus = vec_sr(vus, vus); // CHECK: shr <8 x i16> + res_vi = vec_sr(vi, vui); // CHECK: shr <4 x i32> + res_vui = vec_sr(vui, vui); // CHECK: shr <4 x i32> + res_vsc = vec_vsrb(vsc, vuc); // CHECK: shr <16 x i8> + res_vuc = vec_vsrb(vuc, vuc); // CHECK: shr <16 x i8> + res_vs = vec_vsrh(vs, vus); // CHECK: shr <8 x i16> + res_vus = vec_vsrh(vus, vus); // CHECK: shr <8 x i16> + res_vi = vec_vsrw(vi, vui); // CHECK: shr <4 x i32> + res_vui = vec_vsrw(vui, vui); // CHECK: shr <4 x i32> + + /* vec_sra */ + res_vsc = vec_sra(vsc, vuc); // CHECK: @llvm.ppc.altivec.vsrab + res_vuc = vec_sra(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsrab + res_vs = vec_sra(vs, vus); // CHECK: @llvm.ppc.altivec.vsrah + res_vus = vec_sra(vus, vus); // CHECK: @llvm.ppc.altivec.vsrah + res_vi = vec_sra(vi, vui); // CHECK: @llvm.ppc.altivec.vsraw + res_vui = vec_sra(vui, vui); // CHECK: @llvm.ppc.altivec.vsraw + res_vsc = vec_vsrab(vsc, vuc); // CHECK: @llvm.ppc.altivec.vsrab + res_vuc = vec_vsrab(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsrab + res_vs = vec_vsrah(vs, vus); // CHECK: @llvm.ppc.altivec.vsrah + res_vus = vec_vsrah(vus, vus); // CHECK: @llvm.ppc.altivec.vsrah + res_vi = vec_vsraw(vi, vui); // CHECK: @llvm.ppc.altivec.vsraw + res_vui = vec_vsraw(vui, vui); // CHECK: @llvm.ppc.altivec.vsraw + + /* vec_srl */ + res_vsc = vec_srl(vsc, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vsc = vec_srl(vsc, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vsc = vec_srl(vsc, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vuc = vec_srl(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vuc = vec_srl(vuc, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vuc = vec_srl(vuc, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vs = vec_srl(vs, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vs = vec_srl(vs, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vs = vec_srl(vs, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vus = vec_srl(vus, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vus = vec_srl(vus, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vus = vec_srl(vus, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vi = vec_srl(vi, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vi = vec_srl(vi, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vi = vec_srl(vi, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vui = vec_srl(vui, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vui = vec_srl(vui, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vui = vec_srl(vui, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vsc = vec_vsr(vsc, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vsc = vec_vsr(vsc, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vsc = vec_vsr(vsc, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vuc = vec_vsr(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vuc = vec_vsr(vuc, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vuc = vec_vsr(vuc, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vs = vec_vsr(vs, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vs = vec_vsr(vs, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vs = vec_vsr(vs, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vus = vec_vsr(vus, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vus = vec_vsr(vus, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vus = vec_vsr(vus, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vi = vec_vsr(vi, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vi = vec_vsr(vi, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vi = vec_vsr(vi, vui); // CHECK: @llvm.ppc.altivec.vsr + res_vui = vec_vsr(vui, vuc); // CHECK: @llvm.ppc.altivec.vsr + res_vui = vec_vsr(vui, vus); // CHECK: @llvm.ppc.altivec.vsr + res_vui = vec_vsr(vui, vui); // CHECK: @llvm.ppc.altivec.vsr + + /* vec_sro */ + res_vsc = vec_sro(vsc, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vsc = vec_sro(vsc, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vuc = vec_sro(vuc, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vuc = vec_sro(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vs = vec_sro(vs, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vs = vec_sro(vs, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vus = vec_sro(vus, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vus = vec_sro(vus, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vi = vec_sro(vi, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vi = vec_sro(vi, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vui = vec_sro(vui, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vui = vec_sro(vui, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vf = vec_sro(vf, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vf = vec_sro(vf, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vsc = vec_vsro(vsc, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vsc = vec_vsro(vsc, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vuc = vec_vsro(vuc, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vuc = vec_vsro(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vs = vec_vsro(vs, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vs = vec_vsro(vs, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vus = vec_vsro(vus, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vus = vec_vsro(vus, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vi = vec_vsro(vi, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vi = vec_vsro(vi, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vui = vec_vsro(vui, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vui = vec_vsro(vui, vuc); // CHECK: @llvm.ppc.altivec.vsro + res_vf = vec_vsro(vf, vsc); // CHECK: @llvm.ppc.altivec.vsro + res_vf = vec_vsro(vf, vuc); // CHECK: @llvm.ppc.altivec.vsro + + /* vec_st */ + vec_st(vsc, 0, &vsc); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vsc, 0, ¶m_sc); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vuc, 0, &vuc); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vuc, 0, ¶m_uc); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vs, 0, &vs); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vs, 0, ¶m_s); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vus, 0, &vus); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vus, 0, ¶m_us); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vi, 0, &vi); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vi, 0, ¶m_i); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vui, 0, &vui); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vui, 0, ¶m_ui); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vf, 0, &vf); // CHECK: @llvm.ppc.altivec.stvx + vec_st(vf, 0, ¶m_f); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vsc, 0, &vsc); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vsc, 0, ¶m_sc); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vuc, 0, &vuc); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vuc, 0, ¶m_uc); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vs, 0, &vs); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vs, 0, ¶m_s); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vus, 0, &vus); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vus, 0, ¶m_us); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vi, 0, &vi); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vi, 0, ¶m_i); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vui, 0, &vui); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vui, 0, ¶m_ui); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vf, 0, &vf); // CHECK: @llvm.ppc.altivec.stvx + vec_stvx(vf, 0, ¶m_f); // CHECK: @llvm.ppc.altivec.stvx + + /* vec_ste */ + vec_ste(vsc, 0, ¶m_sc); // CHECK: @llvm.ppc.altivec.stvebx + vec_ste(vuc, 0, ¶m_uc); // CHECK: @llvm.ppc.altivec.stvebx + vec_ste(vs, 0, ¶m_s); // CHECK: @llvm.ppc.altivec.stvehx + vec_ste(vus, 0, ¶m_us); // CHECK: @llvm.ppc.altivec.stvehx + vec_ste(vi, 0, ¶m_i); // CHECK: @llvm.ppc.altivec.stvewx + vec_ste(vui, 0, ¶m_ui); // CHECK: @llvm.ppc.altivec.stvewx + vec_ste(vf, 0, ¶m_f); // CHECK: @llvm.ppc.altivec.stvewx + vec_stvebx(vsc, 0, ¶m_sc); // CHECK: @llvm.ppc.altivec.stvebx + vec_stvebx(vuc, 0, ¶m_uc); // CHECK: @llvm.ppc.altivec.stvebx + vec_stvehx(vs, 0, ¶m_s); // CHECK: @llvm.ppc.altivec.stvehx + vec_stvehx(vus, 0, ¶m_us); // CHECK: @llvm.ppc.altivec.stvehx + vec_stvewx(vi, 0, ¶m_i); // CHECK: @llvm.ppc.altivec.stvewx + vec_stvewx(vui, 0, ¶m_ui); // CHECK: @llvm.ppc.altivec.stvewx + vec_stvewx(vf, 0, ¶m_f); // CHECK: @llvm.ppc.altivec.stvewx + + /* vec_stl */ + vec_stl(vsc, 0, &vsc); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vsc, 0, ¶m_sc); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vuc, 0, &vuc); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vuc, 0, ¶m_uc); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vs, 0, &vs); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vs, 0, ¶m_s); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vus, 0, &vus); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vus, 0, ¶m_us); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vi, 0, &vi); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vi, 0, ¶m_i); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vui, 0, &vui); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vui, 0, ¶m_ui); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vf, 0, &vf); // CHECK: @llvm.ppc.altivec.stvxl + vec_stl(vf, 0, ¶m_f); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vsc, 0, &vsc); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vsc, 0, ¶m_sc); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vuc, 0, &vuc); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vuc, 0, ¶m_uc); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vs, 0, &vs); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vs, 0, ¶m_s); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vus, 0, &vus); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vus, 0, ¶m_us); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vi, 0, &vi); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vi, 0, ¶m_i); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vui, 0, &vui); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vui, 0, ¶m_ui); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vf, 0, &vf); // CHECK: @llvm.ppc.altivec.stvxl + vec_stvxl(vf, 0, ¶m_f); // CHECK: @llvm.ppc.altivec.stvxl + + /* vec_sub */ + res_vsc = vec_sub(vsc, vsc); // CHECK: sub nsw <16 x i8> + res_vuc = vec_sub(vuc, vuc); // CHECK: sub <16 x i8> + res_vs = vec_sub(vs, vs); // CHECK: sub nsw <8 x i16> + res_vus = vec_sub(vus, vus); // CHECK: sub <8 x i16> + res_vi = vec_sub(vi, vi); // CHECK: sub nsw <4 x i32> + res_vui = vec_sub(vui, vui); // CHECK: sub <4 x i32> + res_vf = vec_sub(vf, vf); // CHECK: fsub <4 x float> + res_vsc = vec_vsububm(vsc, vsc); // CHECK: sub nsw <16 x i8> + res_vuc = vec_vsububm(vuc, vuc); // CHECK: sub <16 x i8> + res_vs = vec_vsubuhm(vs, vs); // CHECK: sub nsw <8 x i16> + res_vus = vec_vsubuhm(vus, vus); // CHECK: sub <8 x i16> + res_vi = vec_vsubuwm(vi, vi); // CHECK: sub nsw <4 x i32> + res_vui = vec_vsubuwm(vui, vui); // CHECK: sub <4 x i32> + res_vf = vec_vsubfp(vf, vf); // CHECK: fsub <4 x float> + + /* vec_subc */ + res_vui = vec_subc(vui, vui); // CHECK: @llvm.ppc.altivec.vsubcuw + res_vui = vec_vsubcuw(vui, vui); // CHECK: @llvm.ppc.altivec.vsubcuw + + /* vec_subs */ + res_vsc = vec_subs(vsc, vsc); // CHECK: @llvm.ppc.altivec.vsubsbs + res_vuc = vec_subs(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsububs + res_vs = vec_subs(vs, vs); // CHECK: @llvm.ppc.altivec.vsubshs + res_vus = vec_subs(vus, vus); // CHECK: @llvm.ppc.altivec.vsubuhs + res_vi = vec_subs(vi, vi); // CHECK: @llvm.ppc.altivec.vsubsws + res_vui = vec_subs(vui, vui); // CHECK: @llvm.ppc.altivec.vsubuws + res_vsc = vec_vsubsbs(vsc, vsc); // CHECK: @llvm.ppc.altivec.vsubsbs + res_vuc = vec_vsububs(vuc, vuc); // CHECK: @llvm.ppc.altivec.vsububs + res_vs = vec_vsubshs(vs, vs); // CHECK: @llvm.ppc.altivec.vsubshs + res_vus = vec_vsubuhs(vus, vus); // CHECK: @llvm.ppc.altivec.vsubuhs + res_vi = vec_vsubsws(vi, vi); // CHECK: @llvm.ppc.altivec.vsubsws + res_vui = vec_vsubuws(vui, vui); // CHECK: @llvm.ppc.altivec.vsubuws + + /* vec_sum4s */ + res_vi = vec_sum4s(vsc, vi); // CHECK: @llvm.ppc.altivec.vsum4sbs + res_vui = vec_sum4s(vuc, vui); // CHECK: @llvm.ppc.altivec.vsum4ubs + res_vi = vec_sum4s(vs, vi); // CHECK: @llvm.ppc.altivec.vsum4shs + res_vi = vec_vsum4sbs(vsc, vi); // CHECK: @llvm.ppc.altivec.vsum4sbs + res_vui = vec_vsum4ubs(vuc, vui); // CHECK: @llvm.ppc.altivec.vsum4ubs + res_vi = vec_vsum4shs(vs, vi); // CHECK: @llvm.ppc.altivec.vsum4shs + + /* vec_sum2s */ + res_vi = vec_sum2s(vi, vi); // CHECK: @llvm.ppc.altivec.vsum2sws + res_vi = vec_vsum2sws(vi, vi); // CHECK: @llvm.ppc.altivec.vsum2sws + + /* vec_sums */ + res_vi = vec_sums(vi, vi); // CHECK: @llvm.ppc.altivec.vsumsws + res_vi = vec_vsumsws(vi, vi); // CHECK: @llvm.ppc.altivec.vsumsws + + /* vec_trunc */ + res_vf = vec_trunc(vf); // CHECK: @llvm.ppc.altivec.vrfiz + res_vf = vec_vrfiz(vf); // CHECK: @llvm.ppc.altivec.vrfiz + + /* vec_unpackh */ + res_vs = vec_unpackh(vsc); // CHECK: @llvm.ppc.altivec.vupkhsb + res_vi = vec_unpackh(vs); // CHECK: @llvm.ppc.altivec.vupkhsh + res_vs = vec_vupkhsb(vsc); // CHECK: @llvm.ppc.altivec.vupkhsb + res_vi = vec_vupkhsh(vs); // CHECK: @llvm.ppc.altivec.vupkhsh + + /* vec_unpackl */ + res_vs = vec_unpackl(vsc); // CHECK: @llvm.ppc.altivec.vupklsb + res_vi = vec_vupklsh(vs); // CHECK: @llvm.ppc.altivec.vupklsh + res_vs = vec_vupklsb(vsc); // CHECK: @llvm.ppc.altivec.vupklsb + res_vi = vec_vupklsh(vs); // CHECK: @llvm.ppc.altivec.vupklsh + + /* vec_xor */ + res_vsc = vec_xor(vsc, vsc); // CHECK: xor <16 x i8> + res_vuc = vec_xor(vuc, vuc); // CHECK: xor <16 x i8> + res_vs = vec_xor(vs, vs); // CHECK: xor <8 x i16> + res_vus = vec_xor(vus, vus); // CHECK: xor <8 x i16> + res_vi = vec_xor(vi, vi); // CHECK: xor <4 x i32> + res_vui = vec_xor(vui, vui); // CHECK: xor <4 x i32> + res_vf = vec_xor(vf, vf); // CHECK: xor <4 x i32> + res_vsc = vec_vxor(vsc, vsc); // CHECK: xor <16 x i8> + res_vuc = vec_vxor(vuc, vuc); // CHECK: xor <16 x i8> + res_vs = vec_vxor(vs, vs); // CHECK: xor <8 x i16> + res_vus = vec_vxor(vus, vus); // CHECK: xor <8 x i16> + res_vi = vec_vxor(vi, vi); // CHECK: xor <4 x i32> + res_vui = vec_vxor(vui, vui); // CHECK: xor <4 x i32> + res_vf = vec_vxor(vf, vf); // CHECK: xor <4 x i32> + + /* ------------------------------ predicates -------------------------------------- */ /* vec_all_eq */ res_i = vec_all_eq(vsc, vsc); // CHECK: @llvm.ppc.altivec.vcmpequb.p @@ -203,7 +1111,7 @@ int main () res_i = vec_all_ge(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpgtuh.p res_i = vec_all_ge(vi, vi); // CHECK: @llvm.ppc.altivec.vcmpgtsw.p res_i = vec_all_ge(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpgtuw.p - res_i = vec_all_ge(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgtfp.p + res_i = vec_all_ge(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgefp.p /* vec_all_gt */ res_i = vec_all_gt(vsc, vsc); // CHECK: @llvm.ppc.altivec.vcmpgtsb.p @@ -224,7 +1132,7 @@ int main () res_i = vec_all_le(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpgtuh.p res_i = vec_all_le(vi, vi); // CHECK: @llvm.ppc.altivec.vcmpgtsw.p res_i = vec_all_le(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpgtuw.p - res_i = vec_all_le(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgtfp.p + res_i = vec_all_le(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgefp.p /* vec_all_nan */ res_i = vec_all_nan(vf); // CHECK: @llvm.ppc.altivec.vcmpeqfp.p @@ -269,7 +1177,7 @@ int main () res_i = vec_any_ge(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpgtuh.p res_i = vec_any_ge(vi, vi); // CHECK: @llvm.ppc.altivec.vcmpgtsw.p res_i = vec_any_ge(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpgtuw.p - res_i = vec_any_ge(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgtfp.p + res_i = vec_any_ge(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgefp.p /* vec_any_gt */ res_i = vec_any_gt(vsc, vsc); // CHECK: @llvm.ppc.altivec.vcmpgtsb.p @@ -287,7 +1195,7 @@ int main () res_i = vec_any_le(vus, vus); // CHECK: @llvm.ppc.altivec.vcmpgtuh.p res_i = vec_any_le(vi, vi); // CHECK: @llvm.ppc.altivec.vcmpgtsw.p res_i = vec_any_le(vui, vui); // CHECK: @llvm.ppc.altivec.vcmpgtuw.p - res_i = vec_any_le(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgtfp.p + res_i = vec_any_le(vf, vf); // CHECK: @llvm.ppc.altivec.vcmpgefp.p /* vec_any_lt */ res_i = vec_any_lt(vsc, vsc); // CHECK: @llvm.ppc.altivec.vcmpgtsb.p diff --git a/test/CodeGen/builtins.c b/test/CodeGen/builtins.c index 8b6125806eff4..40f77249f918c 100644 --- a/test/CodeGen/builtins.c +++ b/test/CodeGen/builtins.c @@ -39,9 +39,10 @@ int main() { Q(inff, ()); Q(infl, ()); + P(fpclassify, (0, 1, 2, 3, 4, 1.0)); + P(fpclassify, (0, 1, 2, 3, 4, 1.0f)); + P(fpclassify, (0, 1, 2, 3, 4, 1.0l)); // FIXME: - // XXX note funny semantics for the (last) argument - // P(fpclassify, (FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, 1.0)); // P(isinf_sign, (1.0)); Q(nan, ("")); @@ -195,3 +196,10 @@ void test_float_builtins(float F, double D, long double LD) { // CHECK: and i1 } +// CHECK: define void @test_builtin_longjmp +void test_builtin_longjmp(void **buffer) { + // CHECK: [[BITCAST:%.*]] = bitcast + // CHECK-NEXT: call void @llvm.eh.sjlj.longjmp(i8* [[BITCAST]]) + __builtin_longjmp(buffer, 1); + // CHECK-NEXT: unreachable +} diff --git a/test/CodeGen/const-arithmetic.c b/test/CodeGen/const-arithmetic.c index e12b4f6d92c1d..92c02f0b3dfb6 100644 --- a/test/CodeGen/const-arithmetic.c +++ b/test/CodeGen/const-arithmetic.c @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s -// CHECK: @g1 = global [2 x i8*] [i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -2), i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -46)], align 8 ; <[2 x i8*]*> [#uses=0] -// CHECK: @g2 = global [2 x i8*] [i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -2), i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -46)], align 8 ; <[2 x i8*]*> [#uses=0] +// CHECK: @g1 = global [2 x i8*] [i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -2), i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -46)], align 16 ; <[2 x i8*]*> [#uses=0] +// CHECK: @g2 = global [2 x i8*] [i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -2), i8* getelementptr (i8* getelementptr inbounds ([0 x %struct.anon]* @g0, i32 0, i32 0, i32 0), i64 -46)], align 16 ; <[2 x i8*]*> [#uses=0] extern struct { unsigned char a, b; } g0[]; void *g1[] = {g0 + -1, g0 + -23 }; diff --git a/test/CodeGen/const-unordered-compare.c b/test/CodeGen/const-unordered-compare.c index ac7d35bcd5422..ffd04db6f8621 100644 --- a/test/CodeGen/const-unordered-compare.c +++ b/test/CodeGen/const-unordered-compare.c @@ -2,6 +2,6 @@ // Checks folding of an unordered comparison int nan_ne_check() { - // CHECK: store i32 1 + // CHECK: ret i32 1 return (__builtin_nanf("") != __builtin_nanf("")) ? 1 : 0; } diff --git a/test/CodeGen/decl.c b/test/CodeGen/decl.c index 7ffb7006b05b1..7a9971ee18127 100644 --- a/test/CodeGen/decl.c +++ b/test/CodeGen/decl.c @@ -89,3 +89,31 @@ struct test7s { int a; int b; } test7[] = { struct test8s { int f0; char f1; } test8g = {}; +// PR7519 + +struct S { + void (*x) (struct S *); +}; + +extern struct S *global_dc; +void cp_diagnostic_starter(struct S *); + +void init_error(void) { + global_dc->x = cp_diagnostic_starter; +} + + + +// rdar://8147692 - ABI crash in recursive struct-through-function-pointer. +typedef struct { + int x5a; +} x5; + +typedef struct x2 *x0; +typedef long (*x1)(x0 x0a, x5 x6); +struct x2 { + x1 x4; +}; +long x3(x0 x0a, x5 a) { + return x0a->x4(x0a, a); +} diff --git a/test/CodeGen/exprs.c b/test/CodeGen/exprs.c index d82cbf48d30a1..7cc1134077ee6 100644 --- a/test/CodeGen/exprs.c +++ b/test/CodeGen/exprs.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -emit-llvm -o - +// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s // PR1895 // sizeof function @@ -119,3 +119,29 @@ void f9(struct S *x) { void f10() { __builtin_sin(0); } + +// rdar://7530813 +// CHECK: define i32 @f11 +int f11(long X) { + int A[100]; + return A[X]; + +// CHECK: [[Xaddr:%[^ ]+]] = alloca i64, align 8 +// CHECK: load {{.*}}* [[Xaddr]] +// CHECK-NEXT: getelementptr inbounds [100 x i32]* %A, i32 0, +// CHECK-NEXT: load i32* +} + +int f12() { + // PR3150 + // CHECK: define i32 @f12 + // CHECK: ret i32 1 + return 1||1; +} + +// Make sure negate of fp uses -0.0 for proper -0 handling. +double f13(double X) { + // CHECK: define double @f13 + // CHECK: fsub double -0.0 + return -X; +} diff --git a/test/CodeGen/extern-inline.c b/test/CodeGen/extern-inline.c index 5dd9bfda574c9..60f6d034bf1fd 100644 --- a/test/CodeGen/extern-inline.c +++ b/test/CodeGen/extern-inline.c @@ -19,7 +19,7 @@ int g2(void) {return f2(0,1);} static int f2(int a, int b) {return a*b;} // CHECK: load i32* %{{.*}} // CHECK: load i32* %{{.*}} -// CHECK: mul i32 %{{.*}}, %{{.*}} +// CHECK: mul nsw i32 %{{.*}}, %{{.*}} int h2(void) {return f2(1,2);} // CHECK: call i32 @f2 diff --git a/test/CodeGen/frame-pointer-elim.c b/test/CodeGen/frame-pointer-elim.c new file mode 100644 index 0000000000000..79c0599467a9c --- /dev/null +++ b/test/CodeGen/frame-pointer-elim.c @@ -0,0 +1,29 @@ +// RUN: %clang -ccc-host-triple i386 -S -o - %s | \ +// RUN: FileCheck --check-prefix=DEFAULT %s +// DEFAULT: f0: +// DEFAULT: pushl %ebp +// DEFAULT: ret +// DEFAULT: f1: +// DEFAULT: pushl %ebp +// DEFAULT: ret + +// RUN: %clang -ccc-host-triple i386 -S -o - -fomit-frame-pointer %s | \ +// RUN: FileCheck --check-prefix=OMIT_ALL %s +// OMIT_ALL: f0: +// OMIT_ALL-NOT: pushl %ebp +// OMIT_ALL: ret +// OMIT_ALL: f1: +// OMIT_ALL-NOT: pushl %ebp +// OMIT_ALL: ret + +// RUN: %clang -ccc-host-triple i386 -S -o - -momit-leaf-frame-pointer %s | \ +// RUN: FileCheck --check-prefix=OMIT_LEAF %s +// OMIT_LEAF: f0: +// OMIT_LEAF-NOT: pushl %ebp +// OMIT_LEAF: ret +// OMIT_LEAF: f1: +// OMIT_LEAF: pushl %ebp +// OMIT_LEAF: ret + +void f0() {} +void f1() { f0(); } diff --git a/test/CodeGen/func-in-block.c b/test/CodeGen/func-in-block.c new file mode 100644 index 0000000000000..27e0c09609973 --- /dev/null +++ b/test/CodeGen/func-in-block.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -emit-llvm -o - %s | FileCheck %s +// rdar: // 7860965 + +extern void PRINTF(const char *); +extern void B(void (^)(void)); + +int main() +{ + PRINTF(__func__); + B( + ^{ + PRINTF(__func__); + } + ); + return 0; // not reached +} + +// CHECK: call void @PRINTF({{.*}}@__func__.__main_block_invoke_ diff --git a/test/CodeGen/init.c b/test/CodeGen/init.c index d48e723c58a1a..c8de99d901777 100644 --- a/test/CodeGen/init.c +++ b/test/CodeGen/init.c @@ -40,3 +40,9 @@ vec3 f5(vec3 value) { .x = value.x }}; } + +// rdar://problem/8154689 +void f6() { + int x; + long ids[] = { (long) &x }; +} diff --git a/test/CodeGen/inline.c b/test/CodeGen/inline.c index a17b069929688..a6b4b3e4483ba 100644 --- a/test/CodeGen/inline.c +++ b/test/CodeGen/inline.c @@ -1,5 +1,5 @@ // RUN: echo "GNU89 tests:" -// RUN: %clang %s -emit-llvm -S -o %t -std=gnu89 +// RUN: %clang %s -O1 -emit-llvm -S -o %t -std=gnu89 // RUN: grep "define available_externally i32 @ei()" %t // RUN: grep "define i32 @foo()" %t // RUN: grep "define i32 @bar()" %t @@ -14,7 +14,7 @@ // RUN: grep "define available_externally i32 @test5" %t // RUN: echo "\nC99 tests:" -// RUN: %clang %s -emit-llvm -S -o %t -std=c99 +// RUN: %clang %s -O1 -emit-llvm -S -o %t -std=c99 // RUN: grep "define i32 @ei()" %t // RUN: grep "define available_externally i32 @foo()" %t // RUN: grep "define i32 @bar()" %t @@ -29,7 +29,7 @@ // RUN: grep "define available_externally i32 @test5" %t // RUN: echo "\nC++ tests:" -// RUN: %clang %s -emit-llvm -S -o %t -std=c++98 +// RUN: %clang %s -O1 -emit-llvm -S -o %t -std=c++98 // RUN: grep "define linkonce_odr i32 @_Z2eiv()" %t // RUN: grep "define linkonce_odr i32 @_Z3foov()" %t // RUN: grep "define i32 @_Z3barv()" %t diff --git a/test/CodeGen/inline2.c b/test/CodeGen/inline2.c index 737b58fa44c62..fca4fff7ca8d7 100644 --- a/test/CodeGen/inline2.c +++ b/test/CodeGen/inline2.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -std=gnu89 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix GNU89 %s -// RUN: %clang_cc1 -std=c99 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix C99 %s +// RUN: %clang_cc1 -O1 -std=gnu89 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix GNU89 %s +// RUN: %clang_cc1 -O1 -std=c99 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix C99 %s // CHECK-GNU89: define i32 @f0() // CHECK-C99: define i32 @f0() diff --git a/test/CodeGen/instrument-functions.c b/test/CodeGen/instrument-functions.c new file mode 100644 index 0000000000000..d80385e2239ab --- /dev/null +++ b/test/CodeGen/instrument-functions.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s + +// CHECK: @test1 +int test1(int x) { +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret + return x; +} + +// CHECK: @test2 +int test2(int) __attribute__((no_instrument_function)); +int test2(int x) { +// CHECK-NOT: __cyg_profile_func_enter +// CHECK-NOT: __cyg_profile_func_exit +// CHECK: ret + return x; +} diff --git a/test/CodeGen/integer-overflow.c b/test/CodeGen/integer-overflow.c new file mode 100644 index 0000000000000..9bed741b3236a --- /dev/null +++ b/test/CodeGen/integer-overflow.c @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s --check-prefix=DEFAULT +// RUN: %clang_cc1 %s -emit-llvm -o - -fwrapv | FileCheck %s --check-prefix=WRAPV +// RUN: %clang_cc1 %s -emit-llvm -o - -ftrapv | FileCheck %s --check-prefix=TRAPV + + +// Tests for signed integer overflow stuff. +// rdar://7432000 rdar://7221421 +void test1() { + // DEFAULT: define void @test1 + // WRAPV: define void @test1 + // TRAPV: define void @test1 + extern volatile int f11G, a, b; + + // DEFAULT: add nsw i32 + // WRAPV: add i32 + // TRAPV: llvm.sadd.with.overflow.i32 + f11G = a + b; + + // DEFAULT: sub nsw i32 + // WRAPV: sub i32 + // TRAPV: llvm.ssub.with.overflow.i32 + f11G = a - b; + + // DEFAULT: mul nsw i32 + // WRAPV: mul i32 + // TRAPV: llvm.smul.with.overflow.i32 + f11G = a * b; + + // DEFAULT: sub nsw i32 0, + // WRAPV: sub i32 0, + // TRAPV: llvm.ssub.with.overflow.i32(i32 0 + f11G = -a; + + // PR7426 - Overflow checking for increments. + + // DEFAULT: add nsw i32 {{.*}}, 1 + // WRAPV: add i32 {{.*}}, 1 + // TRAPV: llvm.sadd.with.overflow.i32({{.*}}, i32 1) + ++a; + + // DEFAULT: add nsw i32 {{.*}}, -1 + // WRAPV: add i32 {{.*}}, -1 + // TRAPV: llvm.sadd.with.overflow.i32({{.*}}, i32 -1) + --a; +} diff --git a/test/CodeGen/object-size.c b/test/CodeGen/object-size.c index 3920ec5934de2..287d742b877d5 100644 --- a/test/CodeGen/object-size.c +++ b/test/CodeGen/object-size.c @@ -13,32 +13,38 @@ char gbuf[63]; char *gp; int gi, gj; +// CHECK: define void @test1 void test1() { // CHECK: = call i8* @__strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i32 0, i64 4), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i64 59) strcpy(&gbuf[4], "Hi there"); } +// CHECK: define void @test2 void test2() { // CHECK: = call i8* @__strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i64 63) strcpy(gbuf, "Hi there"); } +// CHECK: define void @test3 void test3() { // CHECK: = call i8* @__strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i64 1, i64 37), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i64 0) strcpy(&gbuf[100], "Hi there"); } +// CHECK: define void @test4 void test4() { // CHECK: = call i8* @__strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i32 0, i64 -1), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i64 0) strcpy((char*)(void*)&gbuf[-1], "Hi there"); } +// CHECK: define void @test5 void test5() { // CHECK: = load i8** @gp // CHECK-NEXT:= call i64 @llvm.objectsize.i64(i8* %{{.*}}, i1 false) strcpy(gp, "Hi there"); } +// CHECK: define void @test6 void test6() { char buf[57]; @@ -46,6 +52,7 @@ void test6() { strcpy(&buf[4], "Hi there"); } +// CHECK: define void @test7 void test7() { int i; // CHECK-NOT: __strcpy_chk @@ -53,6 +60,7 @@ void test7() { strcpy((++i, gbuf), "Hi there"); } +// CHECK: define void @test8 void test8() { char *buf[50]; // CHECK-NOT: __strcpy_chk @@ -60,12 +68,14 @@ void test8() { strcpy(buf[++gi], "Hi there"); } +// CHECK: define void @test9 void test9() { // CHECK-NOT: __strcpy_chk // CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0)) strcpy((char *)((++gi) + gj), "Hi there"); } +// CHECK: define void @test10 char **p; void test10() { // CHECK-NOT: __strcpy_chk @@ -73,36 +83,42 @@ void test10() { strcpy(*(++p), "Hi there"); } +// CHECK: define void @test11 void test11() { // CHECK-NOT: __strcpy_chk - // CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0)) + // CHECK: = call i8* @__inline_strcpy_chk(i8* getelementptr inbounds ([63 x i8]* @gbuf, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0)) strcpy(gp = gbuf, "Hi there"); } +// CHECK: define void @test12 void test12() { // CHECK-NOT: __strcpy_chk // CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0)) strcpy(++gp, "Hi there"); } +// CHECK: define void @test13 void test13() { // CHECK-NOT: __strcpy_chk // CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0)) strcpy(gp++, "Hi there"); } +// CHECK: define void @test14 void test14() { // CHECK-NOT: __strcpy_chk // CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0)) strcpy(--gp, "Hi there"); } +// CHECK: define void @test15 void test15() { // CHECK-NOT: __strcpy_chk // CHECK: = call i8* @__inline_strcpy_chk(i8* %{{..*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0)) strcpy(gp--, "Hi there"); } +// CHECK: define void @test16 void test16() { // CHECK-NOT: __strcpy_chk // CHECK: = call i8* @__inline_strcpy_chk(i8* %{{.*}}, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0)) diff --git a/test/CodeGen/pascal-wchar-string.c b/test/CodeGen/pascal-wchar-string.c new file mode 100644 index 0000000000000..89e4de489f09f --- /dev/null +++ b/test/CodeGen/pascal-wchar-string.c @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s -fpascal-strings -fshort-wchar | FileCheck %s +// rdar: // 8020384 + +extern void abort (void); + +typedef unsigned short UInt16; + +typedef UInt16 UniChar; + +int main(int argc, char* argv[]) +{ + + char st[] = "\pfoo"; // pascal string + UniChar wt[] = L"\pbar"; // pascal Unicode string + UniChar wt1[] = L"\p"; + UniChar wt2[] = L"\pgorf"; + + if (st[0] != 3) + abort (); + if (wt[0] != 3) + abort (); + if (wt1[0] != 0) + abort (); + if (wt2[0] != 4) + abort (); + + return 0; +} + +// CHECK: c"\03\00b\00a\00r\00\00\00" +// CHECK: c"\04\00g\00o\00r\00f\00\00\00" diff --git a/test/CodeGen/pragma-pack-1.c b/test/CodeGen/pragma-pack-1.c index f5d301639e056..c30a62ac3c4e1 100644 --- a/test/CodeGen/pragma-pack-1.c +++ b/test/CodeGen/pragma-pack-1.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm -o - +// RUN: %clang_cc1 -emit-llvm -o - %s // PR4610 #pragma pack(4) diff --git a/test/CodeGen/regparm.c b/test/CodeGen/regparm.c index b60f8c70d762d..ec5cbab16a5b5 100644 --- a/test/CodeGen/regparm.c +++ b/test/CodeGen/regparm.c @@ -14,6 +14,11 @@ FType bar; static void FASTCALL reduced(char b, double c, foo* d, double e, int f); +// PR7025 +void FASTCALL f1(int i, int j, int k); +// CHECK: define void @f1(i32 inreg %i, i32 inreg %j, i32 %k) +void f1(int i, int j, int k) { } + int main(void) { // CHECK: call void @reduced(i8 signext inreg 0, {{.*}} %struct.anon* inreg null diff --git a/test/CodeGen/statements.c b/test/CodeGen/statements.c index e3835f062a690..7ed82add69b0a 100644 --- a/test/CodeGen/statements.c +++ b/test/CodeGen/statements.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 < %s -emit-llvm +// RUN: %clang_cc1 -Wreturn-type < %s -emit-llvm void test1(int x) { switch (x) { diff --git a/test/CodeGen/struct-init.c b/test/CodeGen/struct-init.c index 88b57a26478a4..926e5a7f5dd9b 100644 --- a/test/CodeGen/struct-init.c +++ b/test/CodeGen/struct-init.c @@ -10,3 +10,11 @@ char a; const zend_ini_entry ini_entries[] = { { ((char*)&((zend_ini_entry*)0)->mh_arg1 - (char*)(void*)0)}, }; + +// PR7564 +struct GLGENH { + int : 27; + int EMHJAA : 1; +}; + +struct GLGENH ABHFBF = {1}; diff --git a/test/CodeGen/typedef-func.c b/test/CodeGen/typedef-func.c index bc08b359d70f6..1467e8b1f74a9 100644 --- a/test/CodeGen/typedef-func.c +++ b/test/CodeGen/typedef-func.c @@ -2,7 +2,7 @@ // PR2414 struct mad_frame{}; -enum mad_flow {}; +enum mad_flow {ont}; typedef enum mad_flow filter_func_t(void *, struct mad_frame *); diff --git a/test/CodeGen/volatile.c b/test/CodeGen/volatile.c index db87a375152a6..1a996defcf010 100644 --- a/test/CodeGen/volatile.c +++ b/test/CodeGen/volatile.c @@ -1,8 +1,8 @@ // RUN: %clang_cc1 -emit-llvm < %s -o %t -// RUN: grep volatile %t | count 29 +// RUN: grep volatile %t | count 28 // RUN: grep memcpy %t | count 7 -// The number 29 comes from the current codegen for volatile loads; +// The number 28 comes from the current codegen for volatile loads; // if this number changes, it's not necessarily something wrong, but // something has changed to affect volatile load/store codegen @@ -64,7 +64,7 @@ int main() { i=vV[3]; i=VE.yx[1]; i=vVE.zy[1]; - i = aggFct().x; + i = aggFct().x; // Note: not volatile i=vtS; diff --git a/test/CodeGen/x86_64-arguments.c b/test/CodeGen/x86_64-arguments.c index 47b2eb1585e21..cc318dc749b36 100644 --- a/test/CodeGen/x86_64-arguments.c +++ b/test/CodeGen/x86_64-arguments.c @@ -45,7 +45,7 @@ void f7(e7 a0) { // Test merging/passing of upper eightbyte with X87 class. // // CHECK: define %0 @f8_1() -// CHECK: define void @f8_2(%0) +// CHECK: define void @f8_2(i64 %a0.coerce0, double %a0.coerce1) union u8 { long double a; int b; @@ -56,7 +56,7 @@ void f8_2(union u8 a0) {} // CHECK: define i64 @f9() struct s9 { int a; int b; int : 0; } f9(void) { while (1) {} } -// CHECK: define void @f10(i64) +// CHECK: define void @f10(i64 %a0.coerce) struct s10 { int a; int b; int : 0; }; void f10(struct s10 a0) {} @@ -64,14 +64,14 @@ void f10(struct s10 a0) {} union { long double a; float b; } f11() { while (1) {} } // CHECK: define i64 @f12_0() -// CHECK: define void @f12_1(i64) +// CHECK: define void @f12_1(i64 %a0.coerce) struct s12 { int a __attribute__((aligned(16))); }; struct s12 f12_0(void) { while (1) {} } void f12_1(struct s12 a0) {} // Check that sret parameter is accounted for when checking available integer // registers. -// CHECK: define void @f13(%struct.s13_0* sret %agg.result, i32 %a, i32 %b, i32 %c, i32 %d, %struct.s13_1* byval %e, i32 %f) +// CHECK: define void @f13(%struct.s13_0* sret %agg.result, i32 %a, i32 %b, i32 %c, i32 %d, {{.*}}* byval %e, i32 %f) struct s13_0 { long long f0[3]; }; struct s13_1 { long long f0[2]; }; @@ -92,10 +92,10 @@ void f16(float a, float b, float c, float d, float e, float f, float g, float h, void f17(float a, float b, float c, float d, float e, float f, float g, float h, long double X) {} -// Check for valid coercion. -// CHECK: [[f18_t0:%.*]] = bitcast i64* {{.*}} to %struct.f18_s0* -// CHECK: [[f18_t1:%.*]] = load %struct.f18_s0* [[f18_t0]], align 1 -// CHECK: store %struct.f18_s0 [[f18_t1]], %struct.f18_s0* %f18_arg1 +// Check for valid coercion. The struct should be passed/returned as i32, not +// as i64 for better code quality. +// rdar://8135035 +// CHECK: define void @f18(i32 %a, i32 %f18_arg1.coerce) struct f18_s0 { int f0; }; void f18(int a, struct f18_s0 f18_arg1) { while (1) {} } @@ -113,3 +113,21 @@ struct __attribute__((aligned(32))) s20 { int y; }; void f20(struct s20 x) {} + +struct StringRef { + long x; + const char *Ptr; +}; + +// rdar://7375902 +// CHECK: define i8* @f21(i64 %S.coerce0, i8* %S.coerce1) +const char *f21(struct StringRef S) { return S.x+S.Ptr; } + +// PR7567 +typedef __attribute__ ((aligned(16))) struct f22s { unsigned long long x[2]; } L; +void f22(L x, L y) { } +// CHECK: @f22 +// CHECK: %x = alloca{{.*}}, align 16 +// CHECK: %y = alloca{{.*}}, align 16 + + diff --git a/test/CodeGenCXX/DynArrayInit.cpp b/test/CodeGenCXX/DynArrayInit.cpp new file mode 100644 index 0000000000000..4b4c2ecf1d3e4 --- /dev/null +++ b/test/CodeGenCXX/DynArrayInit.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -O3 -emit-llvm -o - %s | FileCheck %s +// PR7490 + +// CHECK: define signext i8 @_Z2f0v +// CHECK: ret i8 0 +// CHECK: } +inline void* operator new[](unsigned long, void* __p) { return __p; } +static void f0_a(char *a) { + new (a) char[4](); +} +char f0() { + char a[4]; + f0_a(a); + return a[0] + a[1] + a[2] + a[3]; +} diff --git a/test/CodeGenCXX/alloca-align.cpp b/test/CodeGenCXX/alloca-align.cpp index b70e366f4cfbd..99d6ab5845f26 100644 --- a/test/CodeGenCXX/alloca-align.cpp +++ b/test/CodeGenCXX/alloca-align.cpp @@ -18,7 +18,7 @@ extern "C" void f1() { (void) (struct s0) { 0, 0, 0, 0 }; } -// CHECK: define i64 @f2 +// CHECK: define i32 @f2 // CHECK: alloca %struct.s1, align 2 struct s1 { short x; short y; }; extern "C" struct s1 f2(int a, struct s1 *x, struct s1 *y) { diff --git a/test/CodeGenCXX/arm-cc.cpp b/test/CodeGenCXX/arm-cc.cpp new file mode 100644 index 0000000000000..6027746b9ae80 --- /dev/null +++ b/test/CodeGenCXX/arm-cc.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 %s -triple=arm-unknown-linux-gnueabi -target-abi aapcs -emit-llvm -o - | FileCheck %s + +class SMLoc { + const char *Ptr; +public: + SMLoc(); + SMLoc(const SMLoc &RHS); +}; +SMLoc foo(void *p); +void bar(void *x) { + foo(x); +} +void zed(SMLoc x); +void baz() { + SMLoc a; + zed(a); +} + +// CHECK: declare void @_Z3fooPv(%class.SMLoc* sret, i8*) +// CHECK: declare void @_Z3zed5SMLoc(%class.SMLoc*) diff --git a/test/CodeGenCXX/arm.cpp b/test/CodeGenCXX/arm.cpp index 5cca7885b7d72..1d4085ca231d2 100644 --- a/test/CodeGenCXX/arm.cpp +++ b/test/CodeGenCXX/arm.cpp @@ -16,5 +16,4 @@ public: bar baz; // CHECK: @_GLOBAL__D_a() -// CHECK: call arm_apcscc void @_ZN3barD1Ev(%class.bar* @baz) - +// CHECK: call void @_ZN3barD1Ev(%class.bar* @baz) diff --git a/test/CodeGenCXX/block-in-ctor-dtor.cpp b/test/CodeGenCXX/block-in-ctor-dtor.cpp new file mode 100644 index 0000000000000..e4389a4eeec83 --- /dev/null +++ b/test/CodeGenCXX/block-in-ctor-dtor.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 %s -fblocks -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s + +typedef void (^dispatch_block_t)(void); + +void dispatch_once(dispatch_block_t); + +class Zone { +public: + Zone(); + ~Zone(); +}; + +Zone::Zone() { + dispatch_once(^{}); + dispatch_once(^{}); +} + +Zone::~Zone() { + dispatch_once(^{}); + dispatch_once(^{}); +} + +class X : public virtual Zone { + X(); + ~X(); +}; + +X::X() { + dispatch_once(^{}); + dispatch_once(^{}); +}; + +X::~X() { + dispatch_once(^{}); + dispatch_once(^{}); +}; + + +// CHECK: define internal void @___ZN4ZoneC2Ev_block_invoke_ +// CHECK: define internal void @___ZN4ZoneC2Ev_block_invoke_ +// CHECK: define internal void @___ZN4ZoneD2Ev_block_invoke_ +// CHECK: define internal void @___ZN4ZoneD2Ev_block_invoke_ +// CHECK: define internal void @___ZN1XC1Ev_block_invoke_ +// CHECK: define internal void @___ZN1XC1Ev_block_invoke_ +// CHECK: define internal void @___ZN1XC2Ev_block_invoke_ +// CHECK: define internal void @___ZN1XC2Ev_block_invoke_ +// CHECK: define internal void @___ZN1XD2Ev_block_invoke_ +// CHECK: define internal void @___ZN1XD2Ev_block_invoke_ diff --git a/test/CodeGenCXX/condition.cpp b/test/CodeGenCXX/condition.cpp index f5b43d2ef491f..bbc6d2f73b855 100644 --- a/test/CodeGenCXX/condition.cpp +++ b/test/CodeGenCXX/condition.cpp @@ -72,12 +72,10 @@ void switch_destruct(int z) { break; default: - // CHECK: {{sw.default:|:5}} // CHECK: store i32 19 z = 19; break; } - // CHECK: {{sw.epilog:|:6}} // CHECK: call void @_ZN16ConvertibleToIntD1Ev // CHECK: store i32 20 z = 20; @@ -96,66 +94,132 @@ void switch_destruct(int z) { int foo(); +// CHECK: define void @_Z14while_destructi void while_destruct(int z) { - // CHECK: define void @_Z14while_destructi - // CHECK: {{while.cond:|:3}} + // CHECK: [[Z:%.*]] = alloca i32 + // CHECK: [[CLEANUPDEST:%.*]] = alloca i32 while (X x = X()) { // CHECK: call void @_ZN1XC1Ev + // CHECK-NEXT: [[COND:%.*]] = call zeroext i1 @_ZN1XcvbEv + // CHECK-NEXT: br i1 [[COND]] - // CHECK: {{while.body:|:5}} - // CHECK: store i32 21 + // Loop-exit staging block. + // CHECK: store i32 1, i32* [[CLEANUPDEST]] + // CHECK-NEXT: br + + // While body. + // CHECK: store i32 21, i32* [[Z]] + // CHECK: store i32 2, i32* [[CLEANUPDEST]] + // CHECK-NEXT: br z = 21; - // CHECK: {{while.cleanup:|:6}} + // Cleanup. // CHECK: call void @_ZN1XD1Ev + // CHECK-NEXT: [[DEST:%.*]] = load i32* [[CLEANUPDEST]] + // CHECK-NEXT: switch i32 [[DEST]] } - // CHECK: {{while.end|:8}} - // CHECK: store i32 22 + + // CHECK: store i32 22, i32* [[Z]] z = 22; // CHECK: call void @_Z4getXv - // CHECK: call zeroext i1 @_ZN1XcvbEv - // CHECK: call void @_ZN1XD1Ev - // CHECK: br + // CHECK-NEXT: call zeroext i1 @_ZN1XcvbEv + // CHECK-NEXT: call void @_ZN1XD1Ev + // CHECK-NEXT: br while(getX()) { } - // CHECK: store i32 25 + // CHECK: store i32 25, i32* [[Z]] z = 25; // CHECK: ret } +// CHECK: define void @_Z12for_destructi( void for_destruct(int z) { - // CHECK: define void @_Z12for_destruct + // CHECK: [[Z:%.*]] = alloca i32 + // CHECK: [[XDEST:%.*]] = alloca i32 + // CHECK: [[I:%.*]] = alloca i32 // CHECK: call void @_ZN1YC1Ev - for(Y y = Y(); X x = X(); ++z) - // CHECK: {{for.cond:|:4}} + // CHECK-NEXT: br + // -> %for.cond + + for(Y y = Y(); X x = X(); ++z) { + // %for.cond: The loop condition. // CHECK: call void @_ZN1XC1Ev - // CHECK: {{for.body:|:6}} - // CHECK: store i32 23 + // CHECK-NEXT: [[COND:%.*]] = call zeroext i1 @_ZN1XcvbEv( + // CHECK-NEXT: br i1 [[COND]] + // -> %for.body, %for.cond.cleanup + + // %for.cond.cleanup: Exit cleanup staging. + // CHECK: store i32 1, i32* [[XDEST]] + // CHECK-NEXT: br + // -> %cleanup + + // %for.body: + // CHECK: store i32 23, i32* [[Z]] + // CHECK-NEXT: br + // -> %for.inc z = 23; - // CHECK: {{for.inc:|:7}} - // CHECK: br label %{{for.cond.cleanup|10}} - // CHECK: {{for.cond.cleanup:|:10}} + + // %for.inc: + // CHECK: [[TMP:%.*]] = load i32* [[Z]] + // CHECK-NEXT: [[INC:%.*]] = add nsw i32 [[TMP]], 1 + // CHECK-NEXT: store i32 [[INC]], i32* [[Z]] + // CHECK-NEXT: store i32 2, i32* [[XDEST]] + // CHECK-NEXT: br + // -> %cleanup + + // %cleanup: Destroys X. // CHECK: call void @_ZN1XD1Ev - // CHECK: {{for.end:|:12}} - // CHECK: call void @_ZN1YD1Ev + // CHECK-NEXT: [[YDESTTMP:%.*]] = load i32* [[XDEST]] + // CHECK-NEXT: switch i32 [[YDESTTMP]] + // 1 -> %cleanup4, 2 -> %cleanup.cont + + // %cleanup.cont: (eliminable) + // CHECK: br + // -> %for.cond + + // %cleanup4: Destroys Y. + // CHECK: call void @_ZN1YD1Ev( + // CHECK-NEXT: br + // -> %for.end + } + + // %for.end: // CHECK: store i32 24 z = 24; + // CHECK-NEXT: store i32 0, i32* [[I]] + // CHECK-NEXT: br + // -> %for.cond6 + + // %for.cond6: // CHECK: call void @_Z4getXv - // CHECK: call zeroext i1 @_ZN1XcvbEv - // CHECK: call void @_ZN1XD1Ev + // CHECK-NEXT: call zeroext i1 @_ZN1XcvbEv + // CHECK-NEXT: call void @_ZN1XD1Ev + // CHECK-NEXT: br + // -> %for.body10, %for.end16 + + // %for.body10: // CHECK: br + // -> %for.inc11 + + // %for.inc11: // CHECK: call void @_Z4getXv - // CHECK: load - // CHECK: add - // CHECK: call void @_ZN1XD1Ev + // CHECK-NEXT: load i32* [[I]] + // CHECK-NEXT: add + // CHECK-NEXT: store + // CHECK-NEXT: call void @_ZN1XD1Ev + // CHECK-NEXT: br + // -> %for.cond6 int i = 0; for(; getX(); getX(), ++i) { } - z = 26; + + // %for.end16 // CHECK: store i32 26 - // CHECK: ret + z = 26; + + // CHECK-NEXT: ret void } void do_destruct(int z) { diff --git a/test/CodeGenCXX/constructor-convert.cpp b/test/CodeGenCXX/constructor-convert.cpp index 7de07724bf17f..338febbe97a9a 100644 --- a/test/CodeGenCXX/constructor-convert.cpp +++ b/test/CodeGenCXX/constructor-convert.cpp @@ -1,4 +1,4 @@ -// RUN: %clang -emit-llvm -S -o - %s +// RUN: %clang_cc1 -emit-llvm -o - %s // PR5775 class Twine { diff --git a/test/CodeGenCXX/copy-in-cplus-object.cpp b/test/CodeGenCXX/copy-in-cplus-object.cpp new file mode 100644 index 0000000000000..bdfca5e4ee0a2 --- /dev/null +++ b/test/CodeGenCXX/copy-in-cplus-object.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 %s -fblocks -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s + +struct S { + S(const char *); + ~S(); +}; + +struct TestObject +{ + TestObject(const TestObject& inObj, int def = 100, const S &Silly = "silly"); + TestObject(); + ~TestObject(); + TestObject& operator=(const TestObject& inObj); + int version() const; + +}; + +void testRoutine() { + TestObject one; + int (^V)() = ^{ return one.version(); }; +} + +// CHECK: call void @_ZN10TestObjectC1Ev +// CHECK: call void @_ZN1SC1EPKc +// CHECK: call void @_ZN10TestObjectC1ERKS_iRK1S +// CHECK: call void @_ZN1SD1Ev +// CHECK: call void @_ZN10TestObjectD1Ev +// CHECK: call void @_ZN10TestObjectD1Ev diff --git a/test/CodeGenCXX/cxx-apple-kext.cpp b/test/CodeGenCXX/cxx-apple-kext.cpp index 4ba69069bedda..e9a17277b0bbe 100644 --- a/test/CodeGenCXX/cxx-apple-kext.cpp +++ b/test/CodeGenCXX/cxx-apple-kext.cpp @@ -1,6 +1,6 @@ -// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 %s -flto -S -o - |\ +// RUN: %clangxx -ccc-host-triple x86_64-apple-darwin10 %s -flto -S -o - |\ // RUN: FileCheck --check-prefix=CHECK-NO-KEXT %s -// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 %s -fapple-kext -flto -S -o - |\ +// RUN: %clangxx -ccc-host-triple x86_64-apple-darwin10 %s -fapple-kext -flto -S -o - |\ // RUN: FileCheck --check-prefix=CHECK-KEXT %s // CHECK-NO-KEXT-NOT: _GLOBAL__D_a diff --git a/test/CodeGenCXX/default-arg-temps.cpp b/test/CodeGenCXX/default-arg-temps.cpp index e4a06770cd9bb..c4419850f12d4 100644 --- a/test/CodeGenCXX/default-arg-temps.cpp +++ b/test/CodeGenCXX/default-arg-temps.cpp @@ -44,7 +44,6 @@ class obj{ int a; float b; double d; }; // CHECK: define void @_Z1hv() void h() { // CHECK: call void @llvm.memset.p0i8.i64( - // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64( obj o = obj(); } diff --git a/test/CodeGenCXX/destructors.cpp b/test/CodeGenCXX/destructors.cpp index 1442e37403939..8efaf01f3c608 100644 --- a/test/CodeGenCXX/destructors.cpp +++ b/test/CodeGenCXX/destructors.cpp @@ -32,6 +32,26 @@ struct C { C::~C() { } +namespace PR7526 { + extern void foo(); + struct allocator { + ~allocator() throw(); + }; + + struct allocator_derived : allocator { }; + + // CHECK: define void @_ZN6PR75269allocatorD2Ev + // CHECK: call void @__cxa_call_unexpected + allocator::~allocator() throw() { foo(); } + + // CHECK: define linkonce_odr void @_ZN6PR752617allocator_derivedD1Ev + // CHECK-NOT: call void @__cxa_call_unexpected + // CHECK: } + void foo() { + allocator_derived ad; + } +} + // PR5084 template<typename T> class A1 { @@ -168,15 +188,92 @@ namespace test3 { // Checked at top of file: // @_ZN5test312_GLOBAL__N_11CD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev + // More checks at end of file. + +} + +namespace test4 { + struct A { ~A(); }; + + // CHECK: define void @_ZN5test43fooEv() + // CHECK: call void @_ZN5test41AD1Ev + // CHECK: ret void + void foo() { + { + A a; + goto failure; + } + + failure: + return; + } + + // CHECK: define void @_ZN5test43barEi( + // CHECK: [[X:%.*]] = alloca i32 + // CHECK-NEXT: [[A:%.*]] = alloca + // CHECK: br label + // CHECK: [[TMP:%.*]] = load i32* [[X]] + // CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP]], 0 + // CHECK-NEXT: br i1 + // CHECK: call void @_ZN5test41AD1Ev( + // CHECK: br label + // CHECK: [[TMP:%.*]] = load i32* [[X]] + // CHECK: [[TMP2:%.*]] = add nsw i32 [[TMP]], -1 + // CHECK: store i32 [[TMP2]], i32* [[X]] + // CHECK: br label + // CHECK: ret void + void bar(int x) { + for (A a; x; ) { + x--; + } + } +} + +// PR7575 +namespace test5 { + struct A { ~A(); }; + + // This is really unnecessarily verbose; we should be using phis, + // even at -O0. + + // CHECK: define void @_ZN5test53fooEv() + // CHECK: [[ELEMS:%.*]] = alloca [5 x [[A:%.*]]], align + // CHECK-NEXT: [[IVAR:%.*]] = alloca i64 + // CHECK: [[ELEMSARRAY:%.*]] = bitcast [5 x [[A]]]* [[ELEMS]] to [[A]] + // CHECK-NEXT: store i64 5, i64* [[IVAR]] + // CHECK-NEXT: br label + // CHECK: [[I:%.*]] = load i64* [[IVAR]] + // CHECK-NEXT: icmp ne i64 [[I]], 0 + // CHECK-NEXT: br i1 + // CHECK: [[I:%.*]] = load i64* [[IVAR]] + // CHECK-NEXT: [[I2:%.*]] = sub i64 [[I]], 1 + // CHECK-NEXT: getelementptr inbounds [[A]]* [[ELEMSARRAY]], i64 [[I2]] + // CHECK-NEXT: call void @_ZN5test51AD1Ev( + // CHECK-NEXT: br label + // CHECK: [[I:%.*]] = load i64* [[IVAR]] + // CHECK-NEXT: [[I1:%.*]] = sub i64 [[I]], 1 + // CHECK-NEXT: store i64 [[I1]], i64* [[IVAR]] + // CHECK-NEXT: br label + // CHECK: ret void + void foo() { + A elems[5]; + } +} + +// Checks from test3: + // CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD2Ev( // CHECK: call void @_ZN5test31BD2Ev( // CHECK: call void @_ZN5test31AD2Ev( // CHECK: ret void // CHECK: define internal void @_ZN5test312_GLOBAL__N_11DD0Ev( - // CHECK: call void @_ZN5test312_GLOBAL__N_11DD1Ev( - // CHECK: call void @_ZdlPv( + // CHECK: invoke void @_ZN5test312_GLOBAL__N_11DD1Ev( + // CHECK: call void @_ZdlPv({{.*}}) nounwind // CHECK: ret void + // CHECK: call i8* @llvm.eh.exception( + // CHECK: call void @_ZdlPv({{.*}}) nounwind + // CHECK: call void @_Unwind_Resume_or_Rethrow // Checked at top of file: // @_ZN5test312_GLOBAL__N_11DD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11DD2Ev @@ -196,9 +293,12 @@ namespace test3 { // CHECK: declare void @_ZN5test31AD2Ev( // CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD0Ev( - // CHECK: call void @_ZN5test312_GLOBAL__N_11CD1Ev( - // CHECK: call void @_ZdlPv( + // CHECK: invoke void @_ZN5test312_GLOBAL__N_11CD1Ev( + // CHECK: call void @_ZdlPv({{.*}}) nounwind // CHECK: ret void + // CHECK: call i8* @llvm.eh.exception() + // CHECK: call void @_ZdlPv({{.*}}) nounwind + // CHECK: call void @_Unwind_Resume_or_Rethrow( // CHECK: define internal void @_ZThn8_N5test312_GLOBAL__N_11CD1Ev( // CHECK: getelementptr inbounds i8* {{.*}}, i64 -8 @@ -209,4 +309,3 @@ namespace test3 { // CHECK: getelementptr inbounds i8* {{.*}}, i64 -8 // CHECK: call void @_ZN5test312_GLOBAL__N_11CD0Ev( // CHECK: ret void -} diff --git a/test/CodeGenCXX/eh.cpp b/test/CodeGenCXX/eh.cpp index f2629d19d9022..d03dc9171539e 100644 --- a/test/CodeGenCXX/eh.cpp +++ b/test/CodeGenCXX/eh.cpp @@ -38,6 +38,7 @@ void test2() { // CHECK: define void @_Z5test2v() // CHECK: [[FREEVAR:%.*]] = alloca i1 // CHECK-NEXT: [[EXNOBJVAR:%.*]] = alloca i8* +// CHECK-NEXT: [[EXNSLOTVAR:%.*]] = alloca i8* // CHECK-NEXT: store i1 false, i1* [[FREEVAR]] // CHECK-NEXT: [[EXNOBJ:%.*]] = call i8* @__cxa_allocate_exception(i64 16) // CHECK-NEXT: store i8* [[EXNOBJ]], i8** [[EXNOBJVAR]] @@ -104,3 +105,118 @@ namespace test5 { // : [[HANDLER]]: (can't check this in Release-Asserts builds) // CHECK: {{%.*}} = call i32 @llvm.eh.typeid.for(i8* bitcast ({{%.*}}* @_ZTIN5test51AE to i8*)) } + +namespace test6 { + template <class T> struct allocator { + ~allocator() throw() { } + }; + + void foo() { + allocator<int> a; + } +} + +// PR7127 +namespace test7 { +// CHECK: define i32 @_ZN5test73fooEv() + int foo() { +// CHECK: [[FREEEXNOBJ:%.*]] = alloca i1 +// CHECK-NEXT: [[EXNALLOCVAR:%.*]] = alloca i8* +// CHECK-NEXT: [[CAUGHTEXNVAR:%.*]] = alloca i8* +// CHECK-NEXT: [[INTCATCHVAR:%.*]] = alloca i32 +// CHECK-NEXT: store i1 false, i1* [[FREEEXNOBJ]] + try { + try { +// CHECK-NEXT: [[EXNALLOC:%.*]] = call i8* @__cxa_allocate_exception +// CHECK-NEXT: store i8* [[EXNALLOC]], i8** [[EXNALLOCVAR]] +// CHECK-NEXT: store i1 true, i1* [[FREEEXNOBJ]] +// CHECK-NEXT: bitcast i8* [[EXNALLOC]] to i32* +// CHECK-NEXT: store i32 1, i32* +// CHECK-NEXT: store i1 false, i1* [[FREEEXNOBJ]] +// CHECK-NEXT: invoke void @__cxa_throw(i8* [[EXNALLOC]], i8* bitcast (i8** @_ZTIi to i8*), i8* null + throw 1; + } +// This cleanup ends up here for no good reason. It's actually unused. +// CHECK: load i8** [[EXNALLOCVAR]] +// CHECK-NEXT: call void @__cxa_free_exception( + +// CHECK: [[CAUGHTEXN:%.*]] = call i8* @llvm.eh.exception() +// CHECK-NEXT: store i8* [[CAUGHTEXN]], i8** [[CAUGHTEXNVAR]] +// CHECK-NEXT: call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* [[CAUGHTEXN]], i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTIi to i8*), i8* null) +// CHECK-NEXT: call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) +// CHECK-NEXT: icmp eq +// CHECK-NEXT: br i1 +// CHECK: load i8** [[CAUGHTEXNVAR]] +// CHECK-NEXT: call i8* @__cxa_begin_catch +// CHECK: invoke void @__cxa_rethrow + catch (int) { + throw; + } + } +// CHECK: [[CAUGHTEXN:%.*]] = call i8* @llvm.eh.exception() +// CHECK-NEXT: store i8* [[CAUGHTEXN]], i8** [[CAUGHTEXNVAR]] +// CHECK-NEXT: call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* [[CAUGHTEXN]], i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null) +// CHECK-NEXT: call void @__cxa_end_catch() +// CHECK-NEXT: br label +// CHECK: load i8** [[CAUGHTEXNVAR]] +// CHECK-NEXT: call i8* @__cxa_begin_catch +// CHECK-NEXT: call void @__cxa_end_catch + catch (...) { + } +// CHECK: ret i32 0 + return 0; + } +} + +// Ordering of destructors in a catch handler. +namespace test8 { + struct A { A(const A&); ~A(); }; + void bar(); + + // CHECK: define void @_ZN5test83fooEv() + void foo() { + try { + // CHECK: invoke void @_ZN5test83barEv() + bar(); + } catch (A a) { + // CHECK: call i8* @__cxa_get_exception_ptr + // CHECK-NEXT: bitcast + // CHECK-NEXT: invoke void @_ZN5test81AC1ERKS0_( + // CHECK: call i8* @__cxa_begin_catch + // CHECK-NEXT: invoke void @_ZN5test81AD1Ev( + + // CHECK: call void @__cxa_end_catch() + // CHECK-NEXT: load + // CHECK-NEXT: switch + + // CHECK: ret void + } + } +} + +// Constructor function-try-block must rethrow on fallthrough. +// rdar://problem/7696603 +namespace test9 { + void opaque(); + + struct A { A(); }; + + // CHECK: define void @_ZN5test91AC1Ev + // CHECK: call void @_ZN5test91AC2Ev + // CHECK-NEXT: ret void + + // CHECK: define void @_ZN5test91AC2Ev( + A::A() try { + // CHECK: invoke void @_ZN5test96opaqueEv() + opaque(); + } catch (int x) { + // CHECK: call i8* @__cxa_begin_catch + // CHECK: invoke void @_ZN5test96opaqueEv() + // CHECK: invoke void @__cxa_rethrow() + opaque(); + } + + // landing pad from first call to invoke + // CHECK: call i8* @llvm.eh.exception + // CHECK: call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* {{.*}}, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTIi to i8*), i8* null) +} diff --git a/test/CodeGenCXX/global-dtor-no-atexit.cpp b/test/CodeGenCXX/global-dtor-no-atexit.cpp index 81e219989800a..1e125e3f7d814 100644 --- a/test/CodeGenCXX/global-dtor-no-atexit.cpp +++ b/test/CodeGenCXX/global-dtor-no-atexit.cpp @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -triple x86_64 %s -fno-use-cxa-atexit -emit-llvm -o - | FileCheck %s +// PR7097 +// RUN: %clang_cc1 -triple x86_64 %s -fno-use-cxa-atexit -mconstructor-aliases -emit-llvm -o - | FileCheck %s + // CHECK: define internal void @_GLOBAL__D_a() // CHECK: call void @_ZN1AD1Ev(%class.A* @b) // CHECK: call void @_ZN1AD1Ev(%class.A* @a) diff --git a/test/CodeGenCXX/global-init-darwin.cpp b/test/CodeGenCXX/global-init-darwin.cpp new file mode 100644 index 0000000000000..20c13c6eef779 --- /dev/null +++ b/test/CodeGenCXX/global-init-darwin.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm %s -o - |FileCheck %s + +struct A { + A(); + ~A(); +}; + +A a; +A as[2]; + +struct B { + B(); + ~B(); + int f(); +}; + +int i = B().f(); + +// CHECK: "__TEXT,__StaticInit,regular,pure_instructions" { +// CHECK: "__TEXT,__StaticInit,regular,pure_instructions" { +// CHECK: "__TEXT,__StaticInit,regular,pure_instructions" { +// CHECK: "__TEXT,__StaticInit,regular,pure_instructions" { +// CHECK: "__TEXT,__StaticInit,regular,pure_instructions" { diff --git a/test/CodeGenCXX/global-init.cpp b/test/CodeGenCXX/global-init.cpp index 7cbd55940b439..8ee087e29d11f 100644 --- a/test/CodeGenCXX/global-init.cpp +++ b/test/CodeGenCXX/global-init.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm %s -o - |FileCheck %s +// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fexceptions %s -o - |FileCheck %s +// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm %s -o - |FileCheck -check-prefix NOEXC %s struct A { A(); @@ -28,4 +29,7 @@ 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 @_GLOBAL__I_a() { +// CHECK: define internal void @_GLOBAL__I_a() section "__TEXT,__StaticInit,regular,pure_instructions" { + +// rdar://problem/8090834: this should be nounwind +// CHECK-NOEXC: define internal void @_GLOBAL__I_a() nounwind section "__TEXT,__StaticInit,regular,pure_instructions" { diff --git a/test/CodeGenCXX/incomplete-member-function-pointer.cpp b/test/CodeGenCXX/incomplete-member-function-pointer.cpp new file mode 100644 index 0000000000000..b97e44c9172d8 --- /dev/null +++ b/test/CodeGenCXX/incomplete-member-function-pointer.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -emit-llvm-only +// PR7040 +struct fake_tuple; +struct connection { + void bar(fake_tuple); +}; +void (connection::*a)(fake_tuple) = &connection::bar; +void f() { + void (connection::*b)(fake_tuple) = &connection::bar; +} diff --git a/test/CodeGenCXX/instantiate-blocks.cpp b/test/CodeGenCXX/instantiate-blocks.cpp new file mode 100644 index 0000000000000..c8f897de82002 --- /dev/null +++ b/test/CodeGenCXX/instantiate-blocks.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -fblocks -emit-llvm -o - %s +// rdar : // 6182276 + +template <typename T> T foo(T t) +{ + void (^block)(int); + return 1; +} + +int test1(void) +{ + int i = 1; + int b = 2; + i = foo(b); + return 0; +} + +template <typename T, typename T1> void foo(T t, T1 r) +{ + T block_arg; + __block T1 byref_block_arg; + + T1 (^block)(char, T, T1, double) = + ^ T1 (char ch, T arg, T1 arg2, double d1) { byref_block_arg = arg2; + return byref_block_arg + block_arg + arg; }; + + void (^block2)() = ^{}; +} + +void test2(void) +{ + foo(100, 'a'); +} diff --git a/test/CodeGenCXX/internal-linkage.cpp b/test/CodeGenCXX/internal-linkage.cpp index 4263891e57f51..9fdb7274e1469 100644 --- a/test/CodeGenCXX/internal-linkage.cpp +++ b/test/CodeGenCXX/internal-linkage.cpp @@ -17,3 +17,40 @@ Anon anon1; // CHECK: @anon2 = internal global X<Anon> anon2; +// rdar: // 8071804 +char const * const xyzzy = "Hello, world!"; +extern char const * const xyzzy; + +char const * const *test1() +{ + // CHECK: @_ZL5xyzzy = internal constant + return &xyzzy; +} + +static char const * const static_xyzzy = "Hello, world!"; +extern char const * const static_xyzzy; + +char const * const *test2() +{ + // CHECK: @_ZL12static_xyzzy = internal constant + return &static_xyzzy; +} + +static char const * static_nonconst_xyzzy = "Hello, world!"; +extern char const * static_nonconst_xyzzy; + +char const * *test3() +{ + // CHECK: @_ZL21static_nonconst_xyzzy = internal global + return &static_nonconst_xyzzy; +} + + +char const * extern_nonconst_xyzzy = "Hello, world!"; +extern char const * extern_nonconst_xyzzy; + +char const * *test4() +{ + // CHECK: @extern_nonconst_xyzzy = global + return &extern_nonconst_xyzzy; +} diff --git a/test/CodeGenCXX/mangle-address-space.cpp b/test/CodeGenCXX/mangle-address-space.cpp new file mode 100644 index 0000000000000..fbbcbfa35b58f --- /dev/null +++ b/test/CodeGenCXX/mangle-address-space.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +// CHECK: define void @_Z2f0Pc +void f0(char *p) { } +// CHECK: define void @_Z2f0PU3AS1c +void f0(char __attribute__((address_space(1))) *p) { } diff --git a/test/CodeGenCXX/mangle-exprs.cpp b/test/CodeGenCXX/mangle-exprs.cpp index 6f1ca5568ed6d..d68425f5a578d 100644 --- a/test/CodeGenCXX/mangle-exprs.cpp +++ b/test/CodeGenCXX/mangle-exprs.cpp @@ -39,6 +39,6 @@ namespace Casts { // CHECK: define weak_odr void @_ZN5Casts7static_ILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE template void static_<4>(void*); - // CHECK: define weak_odr i64 @_ZN5Casts1fILi6EEENS_1TIXT_EEEv + // CHECK: define weak_odr i8 @_ZN5Casts1fILi6EEENS_1TIXT_EEEv template T<6> f<6>(); } diff --git a/test/CodeGenCXX/mangle-ms.cpp b/test/CodeGenCXX/mangle-ms.cpp new file mode 100644 index 0000000000000..61f8a595fc4fc --- /dev/null +++ b/test/CodeGenCXX/mangle-ms.cpp @@ -0,0 +1,96 @@ +// RUN: %clang_cc1 -fms-extensions -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-apple-darwin10 | FileCheck %s + +// CHECK: @"\01?a@@3HA" +// CHECK: @"\01?b@N@@3HA" +// CHECK: @c +// CHECK: @"\01?d@foo@@0FB" +// CHECK: @"\01?e@foo@@1JC" +// CHECK: @"\01?f@foo@@2DD" +// CHECK: @"\01?g@bar@@2HA" +// CHECK: @"\01?h@@3QAHA" +// CHECK: @"\01?i@@3PAY0BE@HA" +// CHECK: @"\01?j@@3P6GHCE@ZA" +// CHECK: @"\01?k@@3PTfoo@@DA" +// CHECK: @"\01?l@@3P8foo@@AAHH@ZA" + +int a; + +namespace N { int b; } + +static int c; +int _c(void) {return c;} +// CHECK: @"\01?_c@@YAHXZ" + +class foo { + static const short d; +protected: + static volatile long e; +public: + static const volatile char f; + int operator+(int a); +}; + +struct bar { + static int g; +}; + +union baz { + int a; + char b; + double c; +}; + +enum quux { + qone, + qtwo, + qthree +}; + +// NOTE: The calling convention is supposed to be __thiscall by default, +// but that needs to be fixed in Sema/AST. +int foo::operator+(int a) {return a;} +// CHECK: @"\01??Hfoo@@QAAHH@Z" + +const short foo::d = 0; +volatile long foo::e; +const volatile char foo::f = 'C'; + +int bar::g; + +extern int * const h = &a; + +int i[10][20]; + +int (__stdcall *j)(signed char, unsigned char); + +const volatile char foo::*k; + +int (foo::*l)(int); + +// Static functions are mangled, too. +// Also make sure calling conventions, arglists, and throw specs work. +static void __stdcall alpha(float a, double b) throw() {} +bool __fastcall beta(long long a, wchar_t b) throw(signed char, unsigned char) { +// CHECK: @"\01?beta@@YI_N_J_W@Z" + alpha(0.f, 0.0); + return false; +} + +// CHECK: @"\01?alpha@@YGXMN@Z" + +// Make sure tag-type mangling works. +void gamma(class foo, struct bar, union baz, enum quux) {} +// CHECK: @"\01?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z" + +// Make sure pointer/reference-type mangling works. +void delta(int * const a, const long &) {} +// CHECK: @"\01?delta@@YAXQAHABJ@Z" + +// Array mangling. +void epsilon(int a[][10][20]) {} +// CHECK: @"\01?epsilon@@YAXQAY19BE@H@Z" + +// Blocks mangling (Clang extension). +void zeta(int (^)(int, int)) {} +// CHECK: @"\01?zeta@@YAXP_EAHHH@Z@Z" + diff --git a/test/CodeGenCXX/mangle-subst-std.cpp b/test/CodeGenCXX/mangle-subst-std.cpp index 4c15eaac8835a..9c1e978294c86 100644 --- a/test/CodeGenCXX/mangle-subst-std.cpp +++ b/test/CodeGenCXX/mangle-subst-std.cpp @@ -99,3 +99,13 @@ void f(not_string) { } void create_streams() { std::basic_iostream<char> bio(17); } + +// Make sure we don't mangle 'std' as 'St' here. +namespace N { + namespace std { + struct A { void f(); }; + + // CHECK: define void @_ZN1N3std1A1fEv + void A::f() { } + } +} diff --git a/test/CodeGenCXX/mangle-subst.cpp b/test/CodeGenCXX/mangle-subst.cpp index bd06869ff7f97..d83a081dd76ab 100644 --- a/test/CodeGenCXX/mangle-subst.cpp +++ b/test/CodeGenCXX/mangle-subst.cpp @@ -67,3 +67,16 @@ namespace NS { // CHECK: @_ZN2NS1fERNS_1CE void f(C&) { } } + +namespace Test1 { + +struct A { }; +struct B { }; + +// CHECK: @_ZN5Test11fEMNS_1BEFvvENS_1AES3_ +void f(void (B::*)(), A, A) { } + +// CHECK: @_ZN5Test11fEMNS_1BEFvvENS_1AES3_MS0_FvS3_EMS3_FvvE +void f(void (B::*)(), A, A, void (B::*)(A), void (A::*)()) { } + +} diff --git a/test/CodeGenCXX/mangle-unnamed.cpp b/test/CodeGenCXX/mangle-unnamed.cpp index 4aec7dbf4a76f..83b46d69454ea 100644 --- a/test/CodeGenCXX/mangle-unnamed.cpp +++ b/test/CodeGenCXX/mangle-unnamed.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm-only -verify %s +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 | FileCheck %s struct S { virtual ~S() { } @@ -37,3 +37,35 @@ struct A { }; int f4() { return A().a(); } + +int f5() { + static union { + int a; + }; + + // CHECK: _ZZ2f5vE1a + return a; +} + +int f6() { + static union { + union { + int : 1; + }; + int b; + }; + + // CHECK: _ZZ2f6vE1b + return b; +} + +int f7() { + static union { + union { + int b; + } a; + }; + + // CHECK: _ZZ2f7vE1a + return a.b; +} diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp index 8f3d356848843..54a4060352e0a 100644 --- a/test/CodeGenCXX/mangle.cpp +++ b/test/CodeGenCXX/mangle.cpp @@ -477,3 +477,22 @@ namespace test10 { // CHECK: define weak_odr void @_ZN6test101fILc3EEEvNS_1SIXquLb0ELc97ET_EEE( template void f<(char) 3>(struct S<3>); } + +namespace test11 { + // CHECK: @_ZN6test111fEz + void f(...) { } + + struct A { + void f(...); + }; + + // CHECK: @_ZN6test111A1fEz + void A::f(...) { } +} + +namespace test12 { + + // CHECK: _ZN6test121fENS_1AILt33000EEE + template <unsigned short> struct A { }; + void f(A<33000>) { } +}
\ No newline at end of file diff --git a/test/CodeGenCXX/member-functions.cpp b/test/CodeGenCXX/member-functions.cpp index 087e62c5bb370..b363552a4806f 100644 --- a/test/CodeGenCXX/member-functions.cpp +++ b/test/CodeGenCXX/member-functions.cpp @@ -58,6 +58,6 @@ struct T { void test3() { T t1, t2; - // RUN: grep "call i64 @_ZN1TplERKS_" %t + // RUN: grep "call i8 @_ZN1TplERKS_" %t T result = t1 + t2; } diff --git a/test/CodeGenCXX/member-init-assignment.cpp b/test/CodeGenCXX/member-init-assignment.cpp new file mode 100644 index 0000000000000..57ab7ebd1f2f9 --- /dev/null +++ b/test/CodeGenCXX/member-init-assignment.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s +// PR7291 + +struct Foo { + unsigned file_id; + + Foo(unsigned arg); +}; + +Foo::Foo(unsigned arg) : file_id(arg = 42) +{ } + +// CHECK: define void @_ZN3FooC2Ej +// CHECK: [[ARG:%.*]] = alloca i32 +// CHECK: store i32 42, i32* [[ARG]] +// CHECK: store i32 42, i32* %{{.*}} +// CHECK: ret void diff --git a/test/CodeGenCXX/nrvo.cpp b/test/CodeGenCXX/nrvo.cpp index 9ee553673f18e..6181f0eee131e 100644 --- a/test/CodeGenCXX/nrvo.cpp +++ b/test/CodeGenCXX/nrvo.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -emit-llvm -O1 -o - %s | FileCheck %s -// RUN: %clang_cc1 -emit-llvm -fexceptions -o - %s | FileCheck --check-prefix=CHECK-EH %s +// RUN: %clang_cc1 -emit-llvm -O1 -fexceptions -o - %s | FileCheck --check-prefix=CHECK-EH %s // Test code generation for the named return value optimization. class X { @@ -13,48 +13,97 @@ public: // CHECK-EH: define void @_Z5test0v X test0() { X x; - // CHECK-NOT: call void @_ZN1XD1Ev - // CHECK: ret void - // CHECK-EH: br label - // CHECK-EH: call void @_ZN1XD1Ev - // CHECK-EH: br label - // CHECK-EH: invoke void @_ZN1XD1Ev - // CHECK-EH: ret void + // CHECK: call void @_ZN1XC1Ev + // CHECK-NEXT: ret void + + // CHECK-EH: call void @_ZN1XC1Ev + // CHECK-EH-NEXT: ret void return x; } // CHECK: define void @_Z5test1b( +// CHECK-EH: define void @_Z5test1b( X test1(bool B) { - // CHECK: call void @_ZN1XC1Ev + // CHECK: tail call void @_ZN1XC1Ev + // CHECK-NEXT: ret void X x; - // CHECK-NOT: call void @_ZN1XD1Ev - // CHECK: ret void if (B) return (x); return x; - // CHECK-EH: invoke void @_ZN1XD1Ev + // CHECK-EH: tail call void @_ZN1XC1Ev + // CHECK-EH-NEXT: ret void } // CHECK: define void @_Z5test2b // CHECK-EH: define void @_Z5test2b X test2(bool B) { - // No NRVO - // CHECK: call void @_ZN1XC1Ev + // No NRVO. + X x; - // CHECK: call void @_ZN1XC1Ev X y; - // CHECK: call void @_ZN1XC1ERKS_ - // CHECK-EH: invoke void @_ZN1XC1ERKS_ if (B) return y; - // CHECK: call void @_ZN1XC1ERKS_ - // CHECK-EH: invoke void @_ZN1XC1ERKS_ return x; + + // CHECK: call void @_ZN1XC1Ev + // CHECK-NEXT: call void @_ZN1XC1Ev + // CHECK: call void @_ZN1XC1ERKS_ + // CHECK: call void @_ZN1XC1ERKS_ // CHECK: call void @_ZN1XD1Ev // CHECK: call void @_ZN1XD1Ev // CHECK: ret void + + // The block ordering in the -fexceptions IR is unfortunate. + + // CHECK-EH: call void @_ZN1XC1Ev + // CHECK-EH-NEXT: invoke void @_ZN1XC1Ev + // -> %invoke.cont1, %lpad + + // %invoke.cont1: + // CHECK-EH: br i1 + // -> %if.then, %if.end + + // %if.then: returning 'x' + // CHECK-EH: invoke void @_ZN1XC1ERKS_ + // -> %cleanup, %lpad5 + + // %invoke.cont: rethrow block for %eh.cleanup. + // This really should be elsewhere in the function. + // CHECK-EH: call void @_Unwind_Resume_or_Rethrow + // CHECK-EH-NEXT: unreachable + + // %lpad: landing pad for ctor of 'y', dtor of 'y' + // CHECK-EH: call i8* @llvm.eh.exception() + // CHECK-EH: call i32 (i8*, i8*, ...)* @llvm.eh.selector + // CHECK-EH-NEXT: br label + // -> %eh.cleanup + + // %invoke.cont2: normal cleanup for 'x' + // CHECK-EH: call void @_ZN1XD1Ev + // CHECK-EH-NEXT: ret void + + // %lpad5: landing pad for return copy ctors, EH cleanup for 'y' + // CHECK-EH: invoke void @_ZN1XD1Ev + // -> %eh.cleanup, %terminate.lpad + + // %if.end: returning 'y' + // CHECK-EH: invoke void @_ZN1XC1ERKS_ + // -> %cleanup, %lpad5 + + // %cleanup: normal cleanup for 'y' // CHECK-EH: invoke void @_ZN1XD1Ev + // -> %invoke.cont2, %lpad + + // %eh.cleanup: EH cleanup for 'x' // CHECK-EH: invoke void @_ZN1XD1Ev + // -> %invoke.cont, %terminate.lpad + + // %terminate.lpad: terminate landing pad. + // CHECK-EH: call i8* @llvm.eh.exception() + // CHECK-EH-NEXT: call i32 (i8*, i8*, ...)* @llvm.eh.selector + // CHECK-EH-NEXT: call void @_ZSt9terminatev() + // CHECK-EH-NEXT: unreachable + } X test3(bool B) { diff --git a/test/CodeGenCXX/pointers-to-data-members.cpp b/test/CodeGenCXX/pointers-to-data-members.cpp index affe1f7d18deb..70308c6abc5f9 100644 --- a/test/CodeGenCXX/pointers-to-data-members.cpp +++ b/test/CodeGenCXX/pointers-to-data-members.cpp @@ -68,11 +68,11 @@ void f() { // CHECK: store i64 -1, i64* @_ZN5Casts2paE pa = 0; - // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = add i64 {{.*}}, 4 + // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = add nsw i64 {{.*}}, 4 // CHECK: store i64 [[ADJ]], i64* @_ZN5Casts2pcE pc = pa; - // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = sub i64 {{.*}}, 4 + // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = sub nsw i64 {{.*}}, 4 // CHECK: store i64 [[ADJ]], i64* @_ZN5Casts2paE pa = static_cast<int A::*>(pc); } @@ -151,3 +151,35 @@ bool check2() { } } + +namespace VirtualBases { + +struct A { + char c; + int A::*i; +}; + +// FIXME: A::i should be initialized to -1 here. +struct B : virtual A { }; +B b; + +// FIXME: A::i should be initialized to -1 here. +struct C : virtual A { int A::*i; }; +C c; + +// FIXME: C::A::i should be initialized to -1 here. +struct D : C { int A::*i; }; +D d; + +} + +namespace Test1 { + +// Don't crash when A contains a bit-field. +struct A { + int A::* a; + int b : 10; +}; +A a; + +} diff --git a/test/CodeGenCXX/reference-in-block-args.cpp b/test/CodeGenCXX/reference-in-block-args.cpp new file mode 100644 index 0000000000000..1ff1ae2dc8560 --- /dev/null +++ b/test/CodeGenCXX/reference-in-block-args.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -fblocks %s -emit-llvm -o %t +// rdar: // 8041962 + +extern "C" int printf(const char*, ...); + +struct ST { + int filler; + int referrer; +}; + +void OUTER_BLOCK(void (^fixer)(ST& ref)) { + ST ref = {2, 100}; + fixer(ref); +} + +void INNER_BLOCK(int (^largeDo) ()) { + printf("%d\n", largeDo()); +} + +void scan() { + OUTER_BLOCK(^(ST &ref) { + INNER_BLOCK(^() { return ref.referrer + ref.filler; }); + }); + +} + +int main() { + scan(); +} diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp index 6fc610298bd22..d2ad980135538 100644 --- a/test/CodeGenCXX/references.cpp +++ b/test/CodeGenCXX/references.cpp @@ -150,10 +150,9 @@ void f0(s1 a) { s1 b = a; } // PR6024 // CHECK: @_Z2f2v() -// CHECK: alloca -// CHECK: store -// CHECK: load -// CHECK: ret +// CHECK: alloca i32, +// CHECK-NEXT: store +// CHECK-NEXT: ret const int &f2() { return 0; } // Don't constant fold const reference parameters with default arguments to @@ -161,7 +160,7 @@ const int &f2() { return 0; } namespace N1 { const int foo = 1; // CHECK: @_ZN2N14test - int test(const int& arg = foo) { + void test(const int& arg = foo) { // Ensure this array is on the stack where we can set values instead of // being a global constant. // CHECK: %args_array = alloca @@ -225,3 +224,37 @@ namespace N2 { i = 19; } } + +namespace N3 { + +// PR7326 + +struct A { + explicit A(int); + ~A(); +}; + +// CHECK: define internal void @__cxx_global_var_init +// CHECK: call void @_ZN2N31AC1Ei(%"class.N2::X"* @_ZGRN2N35sA123E, i32 123) +// CHECK: call i32 @__cxa_atexit +// CHECK: ret void +const A &sA123 = A(123); +} + +namespace N4 { + +struct A { + A(); + ~A(); +}; + +void f() { + // CHECK: define void @_ZN2N41fEv + // CHECK: call void @_ZN2N41AC1Ev(%"class.N2::X"* @_ZGRZN2N41fEvE2ar) + // CHECK: call i32 @__cxa_atexit + // CHECK: ret void + static const A& ar = A(); + +} +} + diff --git a/test/CodeGenCXX/rtti-layout.cpp b/test/CodeGenCXX/rtti-layout.cpp index 1ad87fbc7ef78..7128c4e4d07bc 100644 --- a/test/CodeGenCXX/rtti-layout.cpp +++ b/test/CodeGenCXX/rtti-layout.cpp @@ -93,6 +93,14 @@ struct VMI7 : VMIBase1, VMI5, private VMI6 { }; #define CHECK_BASE_INFO_TYPE(type, index, base) CHECK(to<__vmi_class_type_info>(typeid(type)).__base_info[(index)].__base_type == &typeid(base)) #define CHECK_BASE_INFO_OFFSET_FLAGS(type, index, offset, flags) CHECK(to<__vmi_class_type_info>(typeid(type)).__base_info[(index)].__offset_flags == (((offset) << 8) | (flags))) +struct B { + static int const volatile (*a)[10]; + static int (*b)[10]; + + static int const volatile (B::*c)[10]; + static int (B::*d)[10]; +}; + // CHECK: define i32 @_Z1fv() int f() { // Vectors should be treated as fundamental types. @@ -168,6 +176,12 @@ int f() { CHECK(to<__pbase_type_info>(typeid(Incomplete Incomplete::*)).__flags == (__pbase_type_info::__incomplete_class_mask | __pbase_type_info::__incomplete_mask)); CHECK(to<__pbase_type_info>(typeid(Incomplete A::*)).__flags == (__pbase_type_info::__incomplete_mask)); + // Check that when stripping qualifiers off the pointee type, we correctly handle arrays. + CHECK(to<__pbase_type_info>(typeid(B::a)).__flags == (__pbase_type_info::__const_mask | __pbase_type_info::__volatile_mask)); + CHECK(to<__pbase_type_info>(typeid(B::a)).__pointee == to<__pbase_type_info>(typeid(B::b)).__pointee); + CHECK(to<__pbase_type_info>(typeid(B::c)).__flags == (__pbase_type_info::__const_mask | __pbase_type_info::__volatile_mask)); + CHECK(to<__pbase_type_info>(typeid(B::c)).__pointee == to<__pbase_type_info>(typeid(B::d)).__pointee); + // Success! // CHECK: ret i32 0 return 0; diff --git a/test/CodeGenCXX/rtti-linkage.cpp b/test/CodeGenCXX/rtti-linkage.cpp index 9d85a2c69ba06..f8c1167b53db0 100644 --- a/test/CodeGenCXX/rtti-linkage.cpp +++ b/test/CodeGenCXX/rtti-linkage.cpp @@ -14,6 +14,7 @@ // CHECK: _ZTI1A = weak_odr constant // CHECK: _ZTI1B = constant // CHECK: _ZTI1C = internal constant +// CHECK: _ZTIA10_i = weak_odr constant // CHECK: _ZTIFN12_GLOBAL__N_11DEvE = internal constant // CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal constant // CHECK: _ZTIFvvE = weak_odr @@ -33,6 +34,7 @@ // CHECK: _ZTS1B = constant // CHECK: _ZTS1C = internal constant // CHECK: _ZTS1F = weak_odr constant +// CHECK: _ZTSA10_i = weak_odr constant // CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant // CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant // CHECK: _ZTSFvvE = weak_odr constant @@ -107,3 +109,12 @@ const std::type_info &t2() { return typeid(getD()); } + +namespace Arrays { + struct A { + static const int a[10]; + }; + const std::type_info &f() { + return typeid(A::a); + } +} diff --git a/test/CodeGenCXX/sel-address.mm b/test/CodeGenCXX/sel-address.mm new file mode 100644 index 0000000000000..c3db9a7d00e54 --- /dev/null +++ b/test/CodeGenCXX/sel-address.mm @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 %s -verify -emit-llvm -o %t +// pr7390 + +void f(const SEL& v2) {} +void g() { + f(@selector(dealloc)); + + SEL s = @selector(dealloc); + SEL* ps = &s; + + @selector(dealloc) = s; // expected-error {{expression is not assignable}} + + SEL* ps2 = &@selector(dealloc); +} diff --git a/test/CodeGenCXX/static-init.cpp b/test/CodeGenCXX/static-init.cpp index 9ad87df8f0c36..09b398a530a13 100644 --- a/test/CodeGenCXX/static-init.cpp +++ b/test/CodeGenCXX/static-init.cpp @@ -2,7 +2,7 @@ // CHECK: @_ZZ1hvE1i = internal global i32 0, align 4 -// CHECK: @_ZZN5test16getvarEiE3var = internal constant [4 x i32] [i32 1, i32 0, i32 2, i32 4], align 4 +// CHECK: @_ZZN5test16getvarEiE3var = internal constant [4 x i32] [i32 1, i32 0, i32 2, i32 4], align 16 // CHECK: @_ZZ2h2vE1i = linkonce_odr global i32 0 // CHECK: @_ZGVZ2h2vE1i = linkonce_odr global i64 0 diff --git a/test/CodeGenCXX/template-instantiation.cpp b/test/CodeGenCXX/template-instantiation.cpp index 4a3857542d06d..cb6c812316412 100644 --- a/test/CodeGenCXX/template-instantiation.cpp +++ b/test/CodeGenCXX/template-instantiation.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 %s -O1 -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s // CHECK-NOT: @_ZTVN5test118stdio_sync_filebufIwEE = constant // CHECK-NOT: _ZTVN5test315basic_fstreamXXIcEE diff --git a/test/CodeGenCXX/template-static-var-defer.cpp b/test/CodeGenCXX/template-static-var-defer.cpp new file mode 100644 index 0000000000000..fe18c21a2927f --- /dev/null +++ b/test/CodeGenCXX/template-static-var-defer.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | not grep define +// PR7415 +class X { + template <class Dummy> struct COMTypeInfo { + static const int kIID; + }; + static const int& GetIID() {return COMTypeInfo<int>::kIID;} +}; +template <class Dummy> const int X::COMTypeInfo<Dummy>::kIID = 10; + + + diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp index eb543cb545525..9a397abfc0cfb 100644 --- a/test/CodeGenCXX/temporaries.cpp +++ b/test/CodeGenCXX/temporaries.cpp @@ -320,3 +320,21 @@ namespace UserConvertToValue { f(1); } } + +namespace PR7556 { + struct A { ~A(); }; + struct B { int i; ~B(); }; + struct C { int C::*pm; ~C(); }; + // CHECK: define void @_ZN6PR75563fooEv() + void foo() { + // CHECK: call void @_ZN6PR75561AD1Ev + A(); + // CHECK: call void @llvm.memset.p0i8.i64 + // CHECK: call void @_ZN6PR75561BD1Ev + B(); + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 + // CHECK: call void @_ZN6PR75561CD1Ev + C(); + // CHECK-NEXT: ret void + } +} diff --git a/test/CodeGenCXX/threadsafe-statics-exceptions.cpp b/test/CodeGenCXX/threadsafe-statics-exceptions.cpp index 9347cc9616a19..17c10301d4fa9 100644 --- a/test/CodeGenCXX/threadsafe-statics-exceptions.cpp +++ b/test/CodeGenCXX/threadsafe-statics-exceptions.cpp @@ -12,15 +12,18 @@ void f() { // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVZ1fvE1x) // CHECK: invoke void @_ZN1XC1Ev // CHECK: call void @__cxa_guard_release(i64* @_ZGVZ1fvE1x) - // CHECK: call i32 @__cxa_atexit + // CHECK-NEXT: call i32 @__cxa_atexit // CHECK: br static X x; + + // CHECK: call i8* @__cxa_allocate_exception + // CHECK: invoke void @__cxa_throw + throw Y(); + + // Finally, the landing pad. // CHECK: call i8* @llvm.eh.exception() // CHECK: call i32 (i8*, i8*, ...)* @llvm.eh.selector // CHECK: call void @__cxa_guard_abort(i64* @_ZGVZ1fvE1x) // CHECK: call void @_Unwind_Resume_or_Rethrow // CHECK: unreachable - - // CHECK: call i8* @__cxa_allocate_exception - throw Y(); } diff --git a/test/CodeGenCXX/throw-expression-dtor.cpp b/test/CodeGenCXX/throw-expression-dtor.cpp new file mode 100644 index 0000000000000..f87657fdcc01c --- /dev/null +++ b/test/CodeGenCXX/throw-expression-dtor.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 %s -emit-llvm-only -verify -fexceptions +// PR7281 + +class A { +public: + ~A(); +}; +class B : public A { + void ice_throw(); +}; +void B::ice_throw() { + throw *this; +} diff --git a/test/CodeGenCXX/thunks.cpp b/test/CodeGenCXX/thunks.cpp index 79ca709f470da..1de576128a11d 100644 --- a/test/CodeGenCXX/thunks.cpp +++ b/test/CodeGenCXX/thunks.cpp @@ -234,6 +234,18 @@ namespace Test8 { void C::bar(NonPOD var) {} } +// PR7241: Emitting thunks for a method shouldn't require the vtable for +// that class to be emitted. +namespace Test9 { + struct A { virtual ~A() { } }; + struct B : A { virtual void test() const {} }; + struct C : B { C(); ~C(); }; + struct D : C { D() {} }; + void test() { + D d; + } +} + /**** The following has to go at the end of the file ****/ // This is from Test5: diff --git a/test/CodeGenCXX/virtual-base-destructor-call.cpp b/test/CodeGenCXX/virtual-base-destructor-call.cpp index 22c49a089d0d2..4618a03b9d3f6 100644 --- a/test/CodeGenCXX/virtual-base-destructor-call.cpp +++ b/test/CodeGenCXX/virtual-base-destructor-call.cpp @@ -27,6 +27,11 @@ int main() { // CHECK: call void @_ZN13basic_istreamIcED2Ev // CHECK: } +// basic_istream's base dtor is a no-op. +// CHECK: define linkonce_odr void @_ZN13basic_istreamIcED2Ev +// CHECK-NOT: call +// CHECK: } + // basic_iostream's deleting dtor calls its complete dtor, then // operator delete(). // CHECK: define linkonce_odr void @_ZN14basic_iostreamIcED0Ev @@ -44,9 +49,3 @@ int main() { // CHECK: define linkonce_odr void @_ZN13basic_istreamIcED0Ev // CHECK: call void @_ZN13basic_istreamIcED1Ev // CHECK: call void @_ZdlPv - -// basic_istream's base dtor is a no-op. -// CHECK: define linkonce_odr void @_ZN13basic_istreamIcED2Ev -// CHECK-NOT: call -// CHECK: } - diff --git a/test/CodeGenCXX/virtual-functions-incomplete-types.cpp b/test/CodeGenCXX/virtual-functions-incomplete-types.cpp index 991c2bc7220f8..052a0192d6658 100644 --- a/test/CodeGenCXX/virtual-functions-incomplete-types.cpp +++ b/test/CodeGenCXX/virtual-functions-incomplete-types.cpp @@ -9,7 +9,7 @@ struct B { void B::f() { } -// CHECK: define i64 @_ZN1D1gEv(%struct.B* %this) +// CHECK: define i32 @_ZN1D1gEv(%struct.B* %this) // CHECK: declare void @_ZN1B1gEv() struct C; diff --git a/test/CodeGenCXX/visibility-hidden-extern-templates.cpp b/test/CodeGenCXX/visibility-hidden-extern-templates.cpp new file mode 100644 index 0000000000000..7629b77c2ceef --- /dev/null +++ b/test/CodeGenCXX/visibility-hidden-extern-templates.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -O1 -emit-llvm -o - -fvisibility hidden %s | FileCheck %s + +template<typename T> +struct X { + void f(); + void g() { } +}; + +template<typename T> void X<T>::f() { } + +extern template struct X<int>; +template struct X<int>; +extern template struct X<char>; + +// <rdar://problem/8109763> +void test_X(X<int> xi, X<char> xc) { + // CHECK: define weak_odr hidden void @_ZN1XIiE1fEv + xi.f(); + // CHECK: define weak_odr hidden void @_ZN1XIiE1gEv + xi.g(); + // CHECK: declare void @_ZN1XIcE1fEv + xc.f(); + // CHECK: define available_externally void @_ZN1XIcE1gEv + xc.g(); +} + diff --git a/test/CodeGenCXX/visibility-inlines-hidden.cpp b/test/CodeGenCXX/visibility-inlines-hidden.cpp new file mode 100644 index 0000000000000..bb1574fe9d5f4 --- /dev/null +++ b/test/CodeGenCXX/visibility-inlines-hidden.cpp @@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -fvisibility-inlines-hidden -emit-llvm -o - %s | FileCheck %s +struct X0 { + void __attribute__((visibility("default"))) f1() { } + void f2() { } + void f3(); + static void f5() { } + virtual void f6() { } +}; + +inline void X0::f3() { } + +template<typename T> +struct X1 { + void __attribute__((visibility("default"))) f1() { } + void f2() { } + void f3(); + void f4(); + static void f5() { } + virtual void f6() { } +}; + +template<typename T> +inline void X1<T>::f3() { } + +template<> +inline void X1<int>::f4() { } + +struct __attribute__((visibility("default"))) X2 { + void f2() { } +}; + +void use(X0 *x0, X1<int> *x1, X2 *x2) { + // CHECK: define linkonce_odr void @_ZN2X02f1Ev + x0->f1(); + // CHECK: define linkonce_odr hidden void @_ZN2X02f2Ev + x0->f2(); + // CHECK: define linkonce_odr hidden void @_ZN2X02f3Ev + x0->f3(); + // CHECK: define linkonce_odr hidden void @_ZN2X02f5Ev + X0::f5(); + // CHECK: define linkonce_odr hidden void @_ZN2X02f6Ev + x0->X0::f6(); + // CHECK: define linkonce_odr void @_ZN2X1IiE2f1Ev + x1->f1(); + // CHECK: define linkonce_odr hidden void @_ZN2X1IiE2f2Ev + x1->f2(); + // CHECK: define linkonce_odr hidden void @_ZN2X1IiE2f3Ev + x1->f3(); + // CHECK: define linkonce_odr hidden void @_ZN2X1IiE2f4Ev + x1->f4(); + // CHECK: define linkonce_odr hidden void @_ZN2X1IiE2f5Ev + X1<int>::f5(); + // CHECK: define linkonce_odr hidden void @_ZN2X1IiE2f6Ev + x1->X1::f6(); + // CHECK: define linkonce_odr hidden void @_ZN2X22f2Ev + x2->f2(); +} diff --git a/test/CodeGenCXX/visibility.cpp b/test/CodeGenCXX/visibility.cpp index 5edd27b8b2793..ee3c1795fbb7c 100644 --- a/test/CodeGenCXX/visibility.cpp +++ b/test/CodeGenCXX/visibility.cpp @@ -5,7 +5,7 @@ #define DEFAULT __attribute__((visibility("default"))) // CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10 - +// CHECK: @_ZTVN5Test63fooE = weak_odr hidden constant namespace Test1 { // CHECK: define hidden void @_ZN5Test11fEv void HIDDEN f() { } @@ -64,3 +64,21 @@ namespace Test5 { void g() { } } } + +// <rdar://problem/8091955> +namespace Test6 { + struct HIDDEN foo { + foo() { } + void bonk(); + virtual void bar() = 0; + + virtual void zonk() {} + }; + + struct barc : public foo { + barc(); + virtual void bar(); + }; + + barc::barc() {} +} diff --git a/test/CodeGenCXX/x86_64-arguments.cpp b/test/CodeGenCXX/x86_64-arguments.cpp index 4bc83b85134eb..df0c78ad941ee 100644 --- a/test/CodeGenCXX/x86_64-arguments.cpp +++ b/test/CodeGenCXX/x86_64-arguments.cpp @@ -1,24 +1,21 @@ // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s -// CHECK: [[i64_i64_ty:%.*]] = type { i64, i64 } -// CHECK: [[i64_double_ty:%.*]] = type { i64, double } - // Basic base class test. struct f0_s0 { unsigned a; }; struct f0_s1 : public f0_s0 { void *b; }; -// CHECK: define void @_Z2f05f0_s1([[i64_i64_ty]]) +// CHECK: define void @_Z2f05f0_s1(i64 %a0.coerce0, i8* %a0.coerce1) void f0(f0_s1 a0) { } // Check with two eight-bytes in base class. struct f1_s0 { unsigned a; unsigned b; float c; }; struct f1_s1 : public f1_s0 { float d;}; -// CHECK: define void @_Z2f15f1_s1([[i64_double_ty]]) +// CHECK: define void @_Z2f15f1_s1(i64 %a0.coerce0, double %a0.coerce1) void f1(f1_s1 a0) { } // Check with two eight-bytes in base class and merge. struct f2_s0 { unsigned a; unsigned b; float c; }; struct f2_s1 : public f2_s0 { char d;}; -// CHECK: define void @_Z2f25f2_s1([[i64_i64_ty]]) +// CHECK: define void @_Z2f25f2_s1(i64 %a0.coerce0, i64 %a0.coerce1) void f2(f2_s1 a0) { } // PR5831 @@ -26,10 +23,25 @@ struct s3_0 {}; struct s3_1 { struct s3_0 a; long b; }; void f3(struct s3_1 x) {} -// CHECK: define i64 @_Z4f4_0M2s4i(i64) -// CHECK: define [[i64_i64_ty]] @_Z4f4_1M2s4FivE([[i64_i64_ty]]) +// CHECK: define i64 @_Z4f4_0M2s4i(i64 %a.coerce) +// CHECK: define {{.*}} @_Z4f4_1M2s4FivE(i64 %a.coerce0, i64 %a.coerce1) struct s4 {}; typedef int s4::* s4_mdp; typedef int (s4::*s4_mfp)(); s4_mdp f4_0(s4_mdp a) { return a; } s4_mfp f4_1(s4_mfp a) { return a; } + + +namespace PR7523 { +struct StringRef { + char *a; +}; + +void AddKeyword(StringRef, int x); + +void foo() { + // CHECK: define void @_ZN6PR75233fooEv() + // CHECK: call void @_ZN6PR752310AddKeywordENS_9StringRefEi(i8* {{.*}}, i32 4) + AddKeyword(StringRef(), 4); +} +}
\ No newline at end of file diff --git a/test/CodeGenObjC/assign.m b/test/CodeGenObjC/assign.m new file mode 100644 index 0000000000000..87e3834fc8740 --- /dev/null +++ b/test/CodeGenObjC/assign.m @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -triple x86_64 -emit-llvm -o - %s | FileCheck %s + +struct s0 { + int x; +}; + +@interface C0 +@property int x0; +@property _Complex int x1; +@property struct s0 x2; +@end + +// Check that we get exactly the message sends we expect, and no more. +// +// CHECK: define void @f0 +void f0(C0 *a) { +// CHECK: objc_msgSend + int l0 = (a.x0 = 1); + +// CHECK: objc_msgSend + _Complex int l1 = (a.x1 = 1); + +// CHECK: objc_msgSend + struct s0 l2 = (a.x2 = (struct s0) { 1 }); + +// CHECK: objc_msgSend +// CHECK: objc_msgSend + int l3 = (a.x0 += 1); + +// CHECK: objc_msgSend +// CHECK: objc_msgSend + _Complex int l4 = (a.x1 += 1); + +// CHECK-NOT: objc_msgSend +// CHECK: } +} diff --git a/test/CodeGenObjC/bitfield_encoding.m b/test/CodeGenObjC/bitfield_encoding.m new file mode 100644 index 0000000000000..03cf9bfba722c --- /dev/null +++ b/test/CodeGenObjC/bitfield_encoding.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o %t %s +// RUN: grep "ib1b14" %t | count 1 +// RUN: %clang_cc1 -triple i386-unknown-unknown -fgnu-runtime -emit-llvm -o %t %s +// RUN: grep "ib32i1b33i14" %t | count 1 + +struct foo{ + int a; + int b:1; + int c:14; +}; + +const char *encoding = @encode(struct foo); diff --git a/test/CodeGenObjC/blocks-5.m b/test/CodeGenObjC/blocks-5.m new file mode 100644 index 0000000000000..2d48b46a4316d --- /dev/null +++ b/test/CodeGenObjC/blocks-5.m @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-llvm -fblocks -o %t %s + +// rdar: // 8064140 + +@interface IDEWorkspaceDocument +{ + id _defaultEditorStateTree; +} +- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, unsigned char *stop))block ; +@end + + + +int foo(); +extern void DVT (volatile const void * object, volatile const void * selector, const char * functionName); +@implementation IDEWorkspaceDocument + +- (void)stateSavingDefaultEditorStatesForURLs { + [_defaultEditorStateTree enumerateKeysAndObjectsUsingBlock:^(id identifier, id urlsToEditorStates, unsigned char *stop) { + do{ +if (foo() ) + DVT(&self,&_cmd,__PRETTY_FUNCTION__); + +}while(0); + + do{ + DVT(&self,&_cmd,__PRETTY_FUNCTION__); + }while(0); + + + }]; + +} + +- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, unsigned char *stop))block {} + +@end diff --git a/test/CodeGenObjC/category-class.m b/test/CodeGenObjC/category-class.m new file mode 100644 index 0000000000000..22d197380f325 --- /dev/null +++ b/test/CodeGenObjC/category-class.m @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm -o - %s | FileCheck %s +// PR7431 + +// CHECK: module asm "\09.lazy_reference .objc_class_name_A" +// CHECK: module asm "\09.objc_category_name_A_foo=0" +// CHECK: module asm "\09.globl .objc_category_name_A_foo" + +@interface A +@end +@interface A(foo) +- (void)foo_myStuff; +@end +@implementation A(foo) +- (void)foo_myStuff { +} +@end + diff --git a/test/CodeGenObjC/dot-syntax-2.m b/test/CodeGenObjC/dot-syntax-2.m new file mode 100644 index 0000000000000..020868a807129 --- /dev/null +++ b/test/CodeGenObjC/dot-syntax-2.m @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -emit-llvm -o %t %s +// rdar: // 8062778 + +@interface NSDictionary @end + +@interface NSMutableDictionary : NSDictionary +@end + +@interface MutableMyClass +- (NSMutableDictionary *)myDict; +- (void)setMyDict:(NSDictionary *)myDict; + +- (NSMutableDictionary *)myLang; +- (void)setMyLang:(NSDictionary *)myLang; +@end + +@interface AnotherClass @end + +@implementation AnotherClass +- (void)foo +{ + MutableMyClass * myObject; + NSDictionary * newDict; + myObject.myDict = newDict; + myObject.myLang = newDict; +} +@end diff --git a/test/CodeGenObjC/exceptions.m b/test/CodeGenObjC/exceptions.m index a74dee95ddab5..5be695932b0f5 100644 --- a/test/CodeGenObjC/exceptions.m +++ b/test/CodeGenObjC/exceptions.m @@ -1,11 +1,8 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o %t %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fexceptions -O2 -o - %s | FileCheck %s // // <rdar://problem/7471679> [irgen] [eh] Exception code built with clang (x86_64) crashes // Just check that we don't emit any dead blocks. -// -// RUN: grep 'No predecessors' %t | count 0 - @interface NSArray @end void f0() { @try { @@ -16,3 +13,27 @@ void f0() { } @catch (id e) { } } + +// CHECK: define void @f1() +void f1() { + extern void foo(void); + + while (1) { + // CHECK: call void @objc_exception_try_enter + // CHECK-NEXT: getelementptr + // CHECK-NEXT: call i32 @_setjmp( + // CHECK-NEXT: icmp + // CHECK-NEXT: br i1 + @try { + // CHECK: call void @foo() + foo(); + // CHECK: call void @objc_exception_try_exit + // CHECK-NEXT: ret void + + // CHECK: call i8* @objc_exception_extract + // CHECK-NEXT: ret void + } @finally { + break; + } + } +} diff --git a/test/CodeGenObjC/metadata_symbols.m b/test/CodeGenObjC/metadata_symbols.m index 921168c1616b4..59441e523fd6d 100644 --- a/test/CodeGenObjC/metadata_symbols.m +++ b/test/CodeGenObjC/metadata_symbols.m @@ -33,8 +33,8 @@ // CHECK-ARMV6: @"OBJC_EHTYPE_$_EH2" = external global // CHECK-ARMV6: @"OBJC_EHTYPE_$_EH3" = global {{.*}}, section "__DATA,__objc_const", align 4 // CHECK-ARMV6: @"\01L_OBJC_LABEL_CLASS_$" = internal global {{.*}}, section "__DATA, __objc_classlist, regular, no_dead_strip", align 4 -// CHECK-ARMV6: define internal arm_apcscc void @"\01-[A im0]" -// CHECK-ARMV6: define internal arm_apcscc void @"\01-[A(Cat) im1]" +// CHECK-ARMV6: define internal void @"\01-[A im0]" +// CHECK-ARMV6: define internal void @"\01-[A(Cat) im1]" @interface A @end diff --git a/test/CodeGenObjC/property-category-impl.m b/test/CodeGenObjC/property-category-impl.m new file mode 100644 index 0000000000000..80a18cb1daab3 --- /dev/null +++ b/test/CodeGenObjC/property-category-impl.m @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck %s + +// rdar : // 8093297 + +@interface Foo @end + +@protocol Proto +@property (readonly) int proto_property; +@end + +@interface Foo (Category) <Proto> @end + +@implementation Foo (Category) +-(int)proto_property { return 0; } +@end + + +// CHECK: l_OBJC_$_PROP_LIST_Foo_$_Category" = internal global +// CHECK: l_OBJC_$_CATEGORY_Foo_$_Category" = internal global +// CHECK: l_OBJC_$_PROP_LIST_Foo_$_Category diff --git a/test/CodeGenObjCXX/copyable-property-object.mm b/test/CodeGenObjCXX/copyable-property-object.mm new file mode 100644 index 0000000000000..8962c536ea29d --- /dev/null +++ b/test/CodeGenObjCXX/copyable-property-object.mm @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -fobjc-gc -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s + +struct POD { + int array[3][4]; + id objc_obj; +}; + +struct D { + POD pod_array[2][3]; +}; + +@interface I +{ + D Property1; +} +@property D Property1; +- (D) val; +- (void) set : (D) d1; +@end + +@implementation I +@synthesize Property1; +- (D) val { return Property1; } +- (void) set : (D) d1 { Property1 = d1; } +@end +// CHECK: {{call.*@objc_memmove_collectable}} +// CHECK: {{call.*@objc_memmove_collectable}} + diff --git a/test/CodeGenObjCXX/foreach-statement.mm b/test/CodeGenObjCXX/foreach-statement.mm new file mode 100644 index 0000000000000..d0ad5b3a8f0fc --- /dev/null +++ b/test/CodeGenObjCXX/foreach-statement.mm @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s +// rdar: // 8027844 + +// CHECK: call void @llvm.memset + +int main() { + id foo; + for (id a in foo) { + } +} diff --git a/test/CodeGenObjCXX/implicit-copy-assign-operator.mm b/test/CodeGenObjCXX/implicit-copy-assign-operator.mm new file mode 100644 index 0000000000000..16ae1472ddfd3 --- /dev/null +++ b/test/CodeGenObjCXX/implicit-copy-assign-operator.mm @@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -fobjc-gc -emit-llvm -triple x86_64-apple-darwin10.0.0 -o - %s | FileCheck %s +struct A { + A &operator=(const A&); + A &operator=(A&); +}; + +struct B { + B &operator=(B&); +}; + +struct C { + virtual C& operator=(const C&); +}; + +struct POD { + id myobjc; + int array[3][4]; +}; + +struct CopyByValue { + CopyByValue(const CopyByValue&); + CopyByValue &operator=(CopyByValue); +}; + +struct D : A, B, virtual C { + int scalar; + int scalar_array[2][3]; + B class_member; + C class_member_array[2][3]; + POD pod_array[2][3]; + + union { + int x; + float f[3]; + }; + + CopyByValue by_value; +}; + +void test_D(D d1, D d2) { + d1 = d2; +} + +// CHECK: define linkonce_odr %struct.D* @_ZN1DaSERS_ +// CHECK: {{call.*_ZN1AaSERS_}} +// CHECK: {{call.*_ZN1BaSERS_}} +// CHECK: {{call.*_ZN1CaSERKS_}} +// CHECK: {{call void @llvm.memcpy.p0i8.p0i8.i64.*i64 24}} +// CHECK: {{call.*_ZN1BaSERS_}} +// CHECK: br +// CHECK: {{call.*_ZN1CaSERKS_}} +// CHECK: {{call.*@objc_memmove_collectable}} +// CHECK: {{call void @llvm.memcpy.p0i8.p0i8.i64.*i64 12}} +// CHECK: call void @_ZN11CopyByValueC1ERKS_ +// CHECK: {{call.*_ZN11CopyByValueaSES_}} +// CHECK: ret + diff --git a/test/CodeGenObjCXX/implicit-copy-constructor.mm b/test/CodeGenObjCXX/implicit-copy-constructor.mm new file mode 100644 index 0000000000000..489fd9758e163 --- /dev/null +++ b/test/CodeGenObjCXX/implicit-copy-constructor.mm @@ -0,0 +1,73 @@ +// RUN: %clang_cc1 -fobjc-gc -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s + +struct A { + A(); + A(const A&); + A(A&); + ~A(); +}; + +struct B { + B(); + B(B&); +}; + +struct C { + C() {} + C(C& other, A a = A()); + int i, j; +}; + +struct POD { + id myobjc; + int array[3][4]; +}; + +struct D : A, B, virtual C { + D(); + int scalar; + int scalar_array[2][3]; + B class_member; + C class_member_array[2][3]; + POD pod_array[2][3]; + + union { + int x; + float f[3]; + }; +}; + +void f(D d) { + D d2(d); +} + +// CHECK: define linkonce_odr void @_ZN1DC1ERS_ +// CHECK: call void @_ZN1AC1Ev +// CHECK: call void @_ZN1CC2ERS_1A +// CHECK: call void @_ZN1AD1Ev +// CHECK: call void @_ZN1AC2ERS_ +// CHECK: call void @_ZN1BC2ERS_ +// CHECK: {{call void @llvm.memcpy.p0i8.p0i8.i64.*i64 24}} +// CHECK: call void @_ZN1BC1ERS_ +// CHECK: br +// CHECK: {{icmp ult.*, 2}} +// CHECK: {{icmp ult.*, 3}} +// CHECK: call void @_ZN1AC1Ev +// CHECK: call void @_ZN1CC1ERS_1A +// CHECK: call void @_ZN1AD1Ev +// CHECK: {{call.*@objc_memmove_collectable}} +// CHECK: {{call void @llvm.memcpy.p0i8.p0i8.i64.*i64 12}} +// CHECK: ret void + + +template<class T> struct X0 { void f0(T * ) { } }; +template <class > struct X1 { X1( X1& , int = 0 ) { } }; +struct X2 { X1<int> result; }; +void test_X2() +{ + typedef X2 impl; + typedef X0<impl> pimpl; + impl* i; + pimpl pdata; + pdata.f0( new impl(*i)); +} diff --git a/test/CodeGenObjCXX/method-local-extern-mangle.mm b/test/CodeGenObjCXX/method-local-extern-mangle.mm new file mode 100644 index 0000000000000..794075da1adbc --- /dev/null +++ b/test/CodeGenObjCXX/method-local-extern-mangle.mm @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s + +// CHECK: @gGlobals = external global + +@interface I +- (int) Meth; +@end + +@implementation I +- (int) Meth { + extern int gGlobals; + return gGlobals; +} +@end diff --git a/test/CodeGenObjCXX/property-derived-to-base-conv.mm b/test/CodeGenObjCXX/property-derived-to-base-conv.mm new file mode 100644 index 0000000000000..ada1202848a8f --- /dev/null +++ b/test/CodeGenObjCXX/property-derived-to-base-conv.mm @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fobjc-gc -triple x86_64-apple-darwin10 -emit-llvm -o - %s +// rdar: // 7501812 + +struct A { int member; }; +struct B : A { }; + +@interface BInt { +@private + B *b; +} +- (B)value; +- (void)setValue : (B) arg; +@property B value; +@end + +void g(BInt *bint) { + bint.value.member = 17; +} + diff --git a/test/CodeGenObjCXX/references.mm b/test/CodeGenObjCXX/references.mm new file mode 100644 index 0000000000000..c2232e2e02f85 --- /dev/null +++ b/test/CodeGenObjCXX/references.mm @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s + +struct A { ~A(); }; + +@interface B { + A a; +} + +- (const A&)getA; +@end + +@implementation B + +- (const A&)getA { + return a; +} + +@end + +// CHECK: define void @_Z1fP1B +// CHECK: objc_msgSend to +// CHECK: ret void +void f(B* b) { + (void)[b getA]; +} diff --git a/test/CodeGenObjCXX/selector-expr-lvalue.mm b/test/CodeGenObjCXX/selector-expr-lvalue.mm new file mode 100644 index 0000000000000..030545119be43 --- /dev/null +++ b/test/CodeGenObjCXX/selector-expr-lvalue.mm @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s +// PR7390 + +@interface NSObject {} +- (void)respondsToSelector:(const SEL&)s : (SEL*)s1; +- (void) setPriority:(int)p; +- (void)Meth; +@end + +@implementation NSObject +- (void)Meth { + [self respondsToSelector:@selector(setPriority:) : &@selector(setPriority:)]; +} +- (void) setPriority:(int)p{} +- (void)respondsToSelector:(const SEL&)s : (SEL*)s1 {} +@end diff --git a/test/Driver/Wp-args.c b/test/Driver/Wp-args.c new file mode 100644 index 0000000000000..e072263c4f7a4 --- /dev/null +++ b/test/Driver/Wp-args.c @@ -0,0 +1,13 @@ +// Check that we extract -MD from '-Wp,-MD,FOO', which is used by a number of +// major projects (e.g., FireFox and the Linux Kernel). + +// RUN: %clang --ccc-host-triple i386-pc-linux-gnu -### \ +// RUN: -Wp,-MD,FOO.d -fsyntax-only %s 2> %t +// RUN: FileCheck < %t %s +// +// CHECK: "-cc1" +// CHECK-NOT: -MD +// CHECK: "-dependency-file" "FOO.d" +// CHECK: "-MT" +// +// PR4062 diff --git a/test/Driver/Xlinker-args.c b/test/Driver/Xlinker-args.c new file mode 100644 index 0000000000000..b009bffd59428 --- /dev/null +++ b/test/Driver/Xlinker-args.c @@ -0,0 +1,9 @@ +// Check that we extract --no-demangle from '-Xlinker' and '-Wl,', since that +// was a collect2 argument. + +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### \ +// RUN: -Xlinker one -Xlinker --no-demangle \ +// RUN: -Wl,two,--no-demangle,three -Xlinker four %s 2> %t +// RUN: FileCheck < %t %s +// +// CHECK: "one" "two" "three" "four" diff --git a/test/Driver/arch.c b/test/Driver/arch.c new file mode 100644 index 0000000000000..69693ee0a3cbf --- /dev/null +++ b/test/Driver/arch.c @@ -0,0 +1,3 @@ +// RUN: %clang -ccc-host-triple armv7a-unknown-linux-gnueabi -S -emit-llvm %s -o - | FileCheck %s + +// CHECK: target triple = "armv7-unknown-linux-gnueabi" diff --git a/test/Driver/cxx-pth.cpp b/test/Driver/cxx-pth.cpp index e349691d423b7..97afb5ebe8a87 100644 --- a/test/Driver/cxx-pth.cpp +++ b/test/Driver/cxx-pth.cpp @@ -1,12 +1,12 @@ // Test forced PTH for CXX support. -// RUN: %clang -x c++-header %s -### 2> %t.log +// RUN: %clangxx -x c++-header %s -### 2> %t.log // RUN: FileCheck -check-prefix EMIT -input-file %t.log %s // EMIT: "{{.*}}/clang{{.*}}" {{.*}} "-emit-pth" "{{.*}}.cpp.gch" "-x" "c++-header" "{{.*}}.cpp" // RUN: touch %t.h.gch -// RUN: %clang -E -include %t.h %s -### 2> %t.log +// RUN: %clangxx -E -include %t.h %s -### 2> %t.log // RUN: FileCheck -check-prefix USE -input-file %t.log %s // USE: "{{.*}}/clang{{.*}}" {{.*}}"-include-pth" "{{.*}}.h.gch" {{.*}}"-x" "c++" "{{.*}}.cpp" diff --git a/test/Driver/darwin-cc.c b/test/Driver/darwin-cc.c index 7a3a378f89a03..3cb9df6ceac6b 100644 --- a/test/Driver/darwin-cc.c +++ b/test/Driver/darwin-cc.c @@ -1,5 +1,5 @@ // RUN: %clang -ccc-no-clang -ccc-host-triple i386-apple-darwin10 -m32 -### -MD -g -fast -Q -dA -mkernel -ansi -aFOO -S -o /tmp/OUTPUTNAME -g0 -gfull -O2 -Werror -pedantic -Wmost -w -std=c99 -trigraphs -v -pg -fFOO -undef -Qn --param a=b -fmudflap -coverage -save-temps -nostdinc -I ARG0 -F ARG1 -I ARG2 -P -MF ARG3 -MG -MP -remap -g3 -H -D ARG4 -U ARG5 -A ARG6 -D ARG7 -U ARG8 -A ARG9 -include ARG10 -pthread %s 2> %t.log -// RUN: grep ' ".*cc1" "-E" "-nostdinc" "-v" "-I" "ARG0" "-F" "ARG1" "-I" "ARG2" "-P" "-MD" "/tmp/OUTPUTNAME.d" "-MF" "ARG3" "-MG" "-MP" "-MQ" "/tmp/OUTPUTNAME" "-remap" "-dD" "-H" "-D__STATIC__" "-D_REENTRANT" "-D" "ARG4" "-U" "ARG5" "-A" "ARG6" "-D" "ARG7" "-U" "ARG8" "-A" "ARG9" "-include" "ARG10" ".*darwin-cc.c" "-D_MUDFLAP" "-include" "mf-runtime.h" "-mmacosx-version-min=10.6.0" "-m32" "-mkernel" "-mtune=core2" "-ansi" "-std=c99" "-trigraphs" "-Werror" "-pedantic" "-Wmost" "-w" "-fast" "-fno-eliminate-unused-debug-symbols" "-fFOO" "-fmudflap" "-O2" "-undef" "-fpch-preprocess" "-o" ".*darwin-cc.i"' %t.log +// RUN: grep ' ".*cc1" "-E" "-nostdinc" "-v" "-I" "ARG0" "-FARG1" "-I" "ARG2" "-P" "-MD" "/tmp/OUTPUTNAME.d" "-MF" "ARG3" "-MG" "-MP" "-MQ" "/tmp/OUTPUTNAME" "-remap" "-dD" "-H" "-D__STATIC__" "-D_REENTRANT" "-D" "ARG4" "-U" "ARG5" "-A" "ARG6" "-D" "ARG7" "-U" "ARG8" "-A" "ARG9" "-include" "ARG10" ".*darwin-cc.c" "-D_MUDFLAP" "-include" "mf-runtime.h" "-mmacosx-version-min=10.6.0" "-m32" "-mkernel" "-mtune=core2" "-ansi" "-std=c99" "-trigraphs" "-Werror" "-pedantic" "-Wmost" "-w" "-fast" "-fno-eliminate-unused-debug-symbols" "-fFOO" "-fmudflap" "-O2" "-undef" "-fpch-preprocess" "-o" ".*darwin-cc.i"' %t.log // RUN: grep ' ".*cc1" "-fpreprocessed" ".*darwin-cc.i" "-O3" "-dumpbase" ".*darwin-cc.c" "-dA" "-mmacosx-version-min=10.6.0" "-m32" "-mkernel" "-mtune=core2" "-ansi" "-aFOO" "-auxbase-strip" "/tmp/OUTPUTNAME" "-g" "-g0" "-g" "-g3" "-O2" "-Werror" "-pedantic" "-Wmost" "-w" "-ansi" "-std=c99" "-trigraphs" "-version" "-p" "-fast" "-fno-eliminate-unused-debug-symbols" "-fFOO" "-fmudflap" "-undef" "-fno-ident" "-o" "/tmp/OUTPUTNAME" "--param" "a=b" "-fno-builtin" "-fno-merge-constants" "-fprofile-arcs" "-ftest-coverage"' %t.log diff --git a/test/Driver/darwin-debug-flags.c b/test/Driver/darwin-debug-flags.c index 7ce61378413ae..6f245271d5825 100644 --- a/test/Driver/darwin-debug-flags.c +++ b/test/Driver/darwin-debug-flags.c @@ -2,10 +2,8 @@ // <rdar://problem/7256886> // CHECK: !1 = metadata !{ -// CHECK: -cc1 -// CHECK: -triple i386-apple-darwin9 -// CHECK: -g -// CHECK: -Os +// CHECK: -mmacosx-version-min=10.5.0 +// CHECK: -g -Os // CHECK: [ DW_TAG_compile_unit ] int x; diff --git a/test/Driver/darwin-dsymutil.c b/test/Driver/darwin-dsymutil.c new file mode 100644 index 0000000000000..f1ffcdc589d40 --- /dev/null +++ b/test/Driver/darwin-dsymutil.c @@ -0,0 +1,38 @@ +// Check that we run dsymutil properly with multiple -arch options. +// +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -ccc-print-phases \ +// RUN: -arch i386 -arch x86_64 %s -g 2> %t +// RUN: FileCheck -check-prefix=CHECK-MULTIARCH-ACTIONS < %t %s +// +// CHECK-MULTIARCH-ACTIONS: 0: input, "{{.*}}darwin-dsymutil.c", c +// CHECK-MULTIARCH-ACTIONS: 1: preprocessor, {0}, cpp-output +// CHECK-MULTIARCH-ACTIONS: 2: compiler, {1}, assembler +// CHECK-MULTIARCH-ACTIONS: 3: assembler, {2}, object +// CHECK-MULTIARCH-ACTIONS: 4: linker, {3}, image +// CHECK-MULTIARCH-ACTIONS: 5: bind-arch, "i386", {4}, image +// CHECK-MULTIARCH-ACTIONS: 6: bind-arch, "x86_64", {4}, image +// CHECK-MULTIARCH-ACTIONS: 7: lipo, {5, 6}, image +// CHECK-MULTIARCH-ACTIONS: 8: dsymutil, {7}, dSYM +// +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -ccc-print-bindings \ +// RUN: -arch i386 -arch x86_64 %s -g 2> %t +// RUN: FileCheck -check-prefix=CHECK-MULTIARCH-BINDINGS < %t %s +// +// CHECK-MULTIARCH-BINDINGS: "x86_64-apple-darwin10" - "darwin::Lipo", inputs: [{{.*}}, {{.*}}], output: "a.out" +// CHECK-MULTIARCH-BINDINGS: # "x86_64-apple-darwin10" - "darwin::Dsymutil", inputs: ["a.out"], output: "a.out.dSYM" + +// Check output name derivation. +// +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -ccc-print-bindings \ +// RUN: -o foo %s -g 2> %t +// RUN: FileCheck -check-prefix=CHECK-OUTPUT-NAME < %t %s +// +// CHECK-OUTPUT-NAME: "x86_64-apple-darwin10" - "darwin::Link", inputs: [{{.*}}], output: "foo" +// CHECK-OUTPUT-NAME: "x86_64-apple-darwin10" - "darwin::Dsymutil", inputs: ["foo"], output: "foo.dSYM" + +// Check that we only use dsymutil when needed. +// +// RUN: touch %t.o +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -ccc-print-bindings \ +// RUN: -o foo %t.o -g 2> %t +// RUN: grep "Dsymutil" %t | count 0 diff --git a/test/Driver/darwin-ld.c b/test/Driver/darwin-ld.c index 76ddaa8732783..0a8989567605f 100644 --- a/test/Driver/darwin-ld.c +++ b/test/Driver/darwin-ld.c @@ -33,11 +33,7 @@ // Note that at conception, this exactly matches gcc. // RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -A ARG0 -F ARG1 -L ARG2 -Mach -T ARG4 -X -Z -all_load -allowable_client ARG8 -bind_at_load -compatibility_version ARG11 -current_version ARG12 -d -dead_strip -dylib_file ARG14 -dylinker -dylinker_install_name ARG16 -dynamic -dynamiclib -e ARG19 -exported_symbols_list ARG20 -fexceptions -flat_namespace -fnested-functions -fopenmp -force_cpusubtype_ALL -fpie -fprofile-arcs -headerpad_max_install_names -image_base ARG29 -init ARG30 -install_name ARG31 -m ARG33 -miphoneos-version-min=2.0 -mmacosx-version-min=10.3.2 -multi_module -multiply_defined ARG37 -multiply_defined_unused ARG38 -no_dead_strip_inits_and_terms -nodefaultlibs -nofixprebinding -nomultidefs -noprebind -noseglinkedit -nostartfiles -nostdlib -pagezero_size ARG54 -pg -prebind -prebind_all_twolevel_modules -preload -r -read_only_relocs ARG55 -s -sectalign ARG57_0 ARG57_1 ARG57_2 -sectcreate ARG58_0 ARG58_1 ARG58_2 -sectobjectsymbols ARG59_0 ARG59_1 -sectorder ARG60_0 ARG60_1 ARG60_2 -seg1addr ARG61 -seg_addr_table ARG62 -seg_addr_table_filename ARG63 -segaddr ARG64_0 ARG64_1 -segcreate ARG65_0 ARG65_1 ARG65_2 -seglinkedit -segprot ARG67_0 ARG67_1 ARG67_2 -segs_read_FOO -segs_read_only_addr ARG69 -segs_read_write_addr ARG70 -shared-libgcc -single_module -static -static-libgcc -sub_library ARG77 -sub_umbrella ARG78 -t -twolevel_namespace -twolevel_namespace_hints -u ARG82 -umbrella ARG83 -undefined ARG84 -unexported_symbols_list ARG85 -w -weak_reference_mismatches ARG87 -whatsloaded -whyload -y -filelist FOO -l FOO 2> %t.log -// RUN: grep '".*ld.*" "-static" "-dylib" "-dylib_compatibility_version" "ARG11" "-dylib_current_version" "ARG12" "-arch" "i386" "-dylib_install_name" "ARG31" "-all_load" "-allowable_client" "ARG8" "-bind_at_load" "-dead_strip" "-no_dead_strip_inits_and_terms" "-dylib_file" "ARG14" "-dynamic" "-exported_symbols_list" "ARG20" "-flat_namespace" "-headerpad_max_install_names" "-image_base" "ARG29" "-init" "ARG30" "-macosx_version_min" "10.3.2" "-iphoneos_version_min" "2.0" "-nomultidefs" "-multi_module" "-single_module" "-multiply_defined" "ARG37" "-multiply_defined_unused" "ARG38" "-pie" "-prebind" "-noprebind" "-nofixprebinding" "-prebind_all_twolevel_modules" "-read_only_relocs" "ARG55" "-sectcreate" "ARG58_0" "ARG58_1" "ARG58_2" "-sectorder" "ARG60_0" "ARG60_1" "ARG60_2" "-seg1addr" "ARG61" "-segprot" "ARG67_0" "ARG67_1" "ARG67_2" "-segaddr" "ARG64_0" "ARG64_1" "-segs_read_only_addr" "ARG69" "-segs_read_write_addr" "ARG70" "-seg_addr_table" "ARG62" "-seg_addr_table_filename" "ARG63" "-sub_library" "ARG77" "-sub_umbrella" "ARG78" "-twolevel_namespace" "-twolevel_namespace_hints" "-umbrella" "ARG83" "-undefined" "ARG84" "-unexported_symbols_list" "ARG85" "-weak_reference_mismatches" "ARG87" "-X" "-y" "-w" "-pagezero_size" "ARG54" "-segs_read_FOO" "-seglinkedit" "-noseglinkedit" "-sectalign" "ARG57_0" "ARG57_1" "ARG57_2" "-sectobjectsymbols" "ARG59_0" "ARG59_1" "-segcreate" "ARG65_0" "ARG65_1" "ARG65_2" "-whyload" "-whatsloaded" "-dylinker_install_name" "ARG16" "-dylinker" "-Mach" "-d" "-s" "-t" "-Z" "-u" "ARG82" "-undefined" "ARG84" "-A" "ARG0" "-e" "ARG19" "-m" "ARG33" "-r" "-o" "a.out" "-L" "ARG2" "-lgomp".* "-filelist" "FOO" "-lFOO" "-lgcov" "-allow_stack_execute" "-T" "ARG4" "-F" "ARG1"' %t.log - -// Don't run dsymutil on a fat build of an executable. -// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -arch i386 -arch x86_64 -g %s 2> %t.log -// RUN: grep dsymutil %t.log | count 0 +// RUN: grep '".*ld.*" "-static" "-dylib" "-dylib_compatibility_version" "ARG11" "-dylib_current_version" "ARG12" "-arch" "i386" "-dylib_install_name" "ARG31" "-all_load" "-allowable_client" "ARG8" "-bind_at_load" "-dead_strip" "-no_dead_strip_inits_and_terms" "-dylib_file" "ARG14" "-dynamic" "-exported_symbols_list" "ARG20" "-flat_namespace" "-headerpad_max_install_names" "-image_base" "ARG29" "-init" "ARG30" "-macosx_version_min" "10.3.2" "-iphoneos_version_min" "2.0" "-nomultidefs" "-multi_module" "-single_module" "-multiply_defined" "ARG37" "-multiply_defined_unused" "ARG38" "-pie" "-prebind" "-noprebind" "-nofixprebinding" "-prebind_all_twolevel_modules" "-read_only_relocs" "ARG55" "-sectcreate" "ARG58_0" "ARG58_1" "ARG58_2" "-sectorder" "ARG60_0" "ARG60_1" "ARG60_2" "-seg1addr" "ARG61" "-segprot" "ARG67_0" "ARG67_1" "ARG67_2" "-segaddr" "ARG64_0" "ARG64_1" "-segs_read_only_addr" "ARG69" "-segs_read_write_addr" "ARG70" "-seg_addr_table" "ARG62" "-seg_addr_table_filename" "ARG63" "-sub_library" "ARG77" "-sub_umbrella" "ARG78" "-twolevel_namespace" "-twolevel_namespace_hints" "-umbrella" "ARG83" "-undefined" "ARG84" "-unexported_symbols_list" "ARG85" "-weak_reference_mismatches" "ARG87" "-X" "-y" "-w" "-pagezero_size" "ARG54" "-segs_read_FOO" "-seglinkedit" "-noseglinkedit" "-sectalign" "ARG57_0" "ARG57_1" "ARG57_2" "-sectobjectsymbols" "ARG59_0" "ARG59_1" "-segcreate" "ARG65_0" "ARG65_1" "ARG65_2" "-whyload" "-whatsloaded" "-dylinker_install_name" "ARG16" "-dylinker" "-Mach" "-d" "-s" "-t" "-Z" "-u" "ARG82" "-undefined" "ARG84" "-A" "ARG0" "-e" "ARG19" "-m" "ARG33" "-r" "-o" "a.out" "-LARG2" "-lgomp".* "-filelist" "FOO" "-lFOO" "-lgcov" "-allow_stack_execute" "-T" "ARG4" "-FARG1"' %t.log // Check linker changes that came with new linkedit format. // RUN: touch %t.o diff --git a/test/Driver/lto.c b/test/Driver/lto.c index 4543ffcd023e6..22b47882691d5 100644 --- a/test/Driver/lto.c +++ b/test/Driver/lto.c @@ -1,15 +1,14 @@ -// -emit-llvm, -flto, and -O4 all cause a switch to llvm-bc object -// files. +// -emit-llvm, -flto, and -O4 all cause a switch to llvm-bc object files. // RUN: %clang -ccc-print-phases -c %s -flto 2> %t.log -// RUN: grep '2: compiler, {1}, llvm-bc' %t.log +// RUN: grep '2: compiler, {1}, lto-bc' %t.log // RUN: %clang -ccc-print-phases -c %s -O4 2> %t.log -// RUN: grep '2: compiler, {1}, llvm-bc' %t.log +// RUN: grep '2: compiler, {1}, lto-bc' %t.log // and -emit-llvm doesn't alter pipeline (unfortunately?). // RUN: %clang -ccc-print-phases %s -emit-llvm 2> %t.log // RUN: grep '0: input, ".*lto.c", c' %t.log // RUN: grep '1: preprocessor, {0}, cpp-output' %t.log -// RUN: grep '2: compiler, {1}, llvm-bc' %t.log +// RUN: grep '2: compiler, {1}, lto-bc' %t.log // RUN: grep '3: linker, {2}, image' %t.log // llvm-bc and llvm-ll outputs need to match regular suffixes diff --git a/test/Driver/option-aliases.c b/test/Driver/option-aliases.c new file mode 100644 index 0000000000000..38bf4b1a57776 --- /dev/null +++ b/test/Driver/option-aliases.c @@ -0,0 +1,11 @@ +// RUN: %clang -ccc-print-options \ +// RUN: --save-temps --undefine-macro=FOO --undefine-macro FOO \ +// RUN: --param=FOO --output=FOO 2> %t +// RUN: FileCheck --check-prefix=CHECK-OPTIONS < %t %s + +// CHECK-OPTIONS: Option 0 - Name: "-ccc-print-options", Values: {} +// CHECK-OPTIONS: Option 1 - Name: "-save-temps", Values: {} +// CHECK-OPTIONS: Option 2 - Name: "-U", Values: {"FOO"} +// CHECK-OPTIONS: Option 3 - Name: "-U", Values: {"FOO"} +// CHECK-OPTIONS: Option 4 - Name: "--param", Values: {"FOO"} +// CHECK-OPTIONS: Option 5 - Name: "-o", Values: {"FOO"} diff --git a/test/FixIt/no-typo.c b/test/FixIt/no-typo.c new file mode 100644 index 0000000000000..05947e88e923b --- /dev/null +++ b/test/FixIt/no-typo.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -fno-spell-checking -verify %s +typedef struct { + float x, y; +} Point; + +point p1; // expected-error{{unknown type name 'point'}} diff --git a/test/FixIt/typo.cpp b/test/FixIt/typo.cpp index 5b9e68bbfd3de..077aa9c6f78f4 100644 --- a/test/FixIt/typo.cpp +++ b/test/FixIt/typo.cpp @@ -12,7 +12,8 @@ namespace std { typedef basic_string<char> string; // expected-note 2{{'string' declared here}} } -namespace otherstd { // expected-note 2{{'otherstd' declared here}} +namespace otherstd { // expected-note 2{{'otherstd' declared here}} \ + // expected-note{{namespace 'otherstd' defined here}} using namespace std; } @@ -29,6 +30,13 @@ float area(float radius, // expected-note{{'radius' declared here}} return radious * pi; // expected-error{{did you mean 'radius'?}} } +using namespace othestd; // expected-error{{no namespace named 'othestd'; did you mean 'otherstd'?}} +namespace blargh = otherstd; // expected-note 3{{namespace 'blargh' defined here}} +using namespace ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}} + +namespace wibble = blarg; // expected-error{{no namespace named 'blarg'; did you mean 'blargh'?}} +namespace wobble = ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}} + bool test_string(std::string s) { basc_string<char> b1; // expected-error{{no template named 'basc_string'; did you mean 'basic_string'?}} std::basic_sting<char> b2; // expected-error{{no template named 'basic_sting' in namespace 'std'; did you mean 'basic_string'?}} diff --git a/test/FixIt/typo.m b/test/FixIt/typo.m index 7197bc746d127..6853ab693afbd 100644 --- a/test/FixIt/typo.m +++ b/test/FixIt/typo.m @@ -24,7 +24,8 @@ void test() { int his_ivar; // expected-note 2{{'his_ivar' declared here}} float wibble; } - +- (void)methodA; ++ (void)methodA; @property int his_prop; // expected-note{{'his_prop' declared here}} @end @@ -40,6 +41,8 @@ void test() { @implementation A @synthesize his_prop = his_ivar; +- (void)methodA { } ++ (void)methodA { } @end @implementation B @@ -145,4 +148,9 @@ double *isupper(int); @end #endif +void f(A *a) { + f(a) // expected-error{{expected ';' after expression}} + [a methodA] // expected-error{{expected ';' after expression}} + [A methodA] // expected-error{{expected ';' after expression}} +} diff --git a/test/Frontend/ir-support-codegen.ll b/test/Frontend/ir-support-codegen.ll new file mode 100644 index 0000000000000..046b3af1c3ed6 --- /dev/null +++ b/test/Frontend/ir-support-codegen.ll @@ -0,0 +1,8 @@ +; RUN: %clang_cc1 -S -o - %s | FileCheck %s + +target triple = "x86_64-apple-darwin10" + +; CHECK: .globl _f0 +define i32 @f0() nounwind ssp { + ret i32 0 +} diff --git a/test/Frontend/ir-support-errors.ll b/test/Frontend/ir-support-errors.ll new file mode 100644 index 0000000000000..98227d46f7ae8 --- /dev/null +++ b/test/Frontend/ir-support-errors.ll @@ -0,0 +1,8 @@ +; RUN: %clang_cc1 -S -o - %s 2>&1 | FileCheck %s + +target triple = "x86_64-apple-darwin10" + +define i32 @f0() nounwind ssp { +; CHECK: {{.*}}ir-support-errors.ll:7:16: error: expected value token + ret i32 x +} diff --git a/test/Frontend/lit.local.cfg b/test/Frontend/lit.local.cfg new file mode 100644 index 0000000000000..4c135982a452c --- /dev/null +++ b/test/Frontend/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes = ['.c', '.cpp', '.m', '.mm', '.ll', '.bc'] diff --git a/test/Frontend/preprocessed-output-macro-first-token.c b/test/Frontend/preprocessed-output-macro-first-token.c new file mode 100644 index 0000000000000..06b78c2e1fae6 --- /dev/null +++ b/test/Frontend/preprocessed-output-macro-first-token.c @@ -0,0 +1,5 @@ +// This is the first thing other than comments and preprocessor stuff in the +// file. +// +// RUN: %clang_cc1 -fms-extensions -E %s +#pragma comment(lib, "somelib") diff --git a/test/Frontend/unknown-pragmas.c b/test/Frontend/unknown-pragmas.c new file mode 100644 index 0000000000000..53a5a45a43379 --- /dev/null +++ b/test/Frontend/unknown-pragmas.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -Eonly -Wall -verify %s +// RUN: %clang_cc1 -E -dM -Wall -verify %s + +#pragma adgohweopihweotnwet diff --git a/test/Headers/int64-type.c b/test/Headers/int64-type.c new file mode 100644 index 0000000000000..16b42d2d7f8f4 --- /dev/null +++ b/test/Headers/int64-type.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -verify %s -ffreestanding + +#include <stdint.h> +typedef unsigned long long uint64_t; diff --git a/test/Headers/x86-intrinsics-headers.c b/test/Headers/x86-intrinsics-headers.c index 24c2d925e00de..08abcefed7a76 100644 --- a/test/Headers/x86-intrinsics-headers.c +++ b/test/Headers/x86-intrinsics-headers.c @@ -1,6 +1,6 @@ // RUN: %clang -fsyntax-only %s // RUN: %clang -fsyntax-only -fno-lax-vector-conversions %s -// RUN: %clang -fsyntax-only -x c++ %s +// RUN: %clangxx -fsyntax-only -x c++ %s #if defined(i386) || defined(__x86_64__) diff --git a/test/Index/blocks.c b/test/Index/blocks.c new file mode 100644 index 0000000000000..08241cbcd196d --- /dev/null +++ b/test/Index/blocks.c @@ -0,0 +1,29 @@ +// RUN: c-index-test -test-load-source local -fblocks %s | FileCheck %s + +typedef int int_t; +struct foo { long x; }; + +void test() { + static struct foo _foo; + ^ int_t(struct foo *foo) { return (int_t) foo->x; }(&_foo); +} + +// TODO: expose the BlockExpr, CastExpr, and UnaryOperatorExpr here + +// CHECK: blocks.c:3:13: TypedefDecl=int_t:3:13 (Definition) Extent=[3:13 - 3:18] +// CHECK: blocks.c:4:8: StructDecl=foo:4:8 (Definition) Extent=[4:1 - 4:23] +// CHECK: blocks.c:4:19: FieldDecl=x:4:19 (Definition) Extent=[4:19 - 4:20] +// CHECK: blocks.c:6:6: FunctionDecl=test:6:6 (Definition) Extent=[6:6 - 9:2] +// CHECK: blocks.c:7:21: VarDecl=_foo:7:21 (Definition) Extent=[7:17 - 7:25] +// CHECK: blocks.c:7:17: TypeRef=struct foo:4:8 Extent=[7:17 - 7:20] +// CHECK: blocks.c:8:3: CallExpr= Extent=[8:3 - 8:61] +// CHECK: blocks.c:8:3: UnexposedExpr= Extent=[8:3 - 8:54] +// CHECK: blocks.c:8:5: TypeRef=int_t:3:13 Extent=[8:5 - 8:10] +// CHECK: blocks.c:8:23: ParmDecl=foo:8:23 (Definition) Extent=[8:18 - 8:26] +// CHECK: blocks.c:8:18: TypeRef=struct foo:4:8 Extent=[8:18 - 8:21] +// CHECK: blocks.c:8:37: UnexposedExpr=x:4:19 Extent=[8:37 - 8:51] +// CHECK: blocks.c:8:38: TypeRef=int_t:3:13 Extent=[8:38 - 8:43] +// CHECK: blocks.c:8:50: MemberRefExpr=x:4:19 Extent=[8:45 - 8:51] +// CHECK: blocks.c:8:45: DeclRefExpr=foo:8:23 Extent=[8:45 - 8:48] +// CHECK: blocks.c:8:55: UnexposedExpr= Extent=[8:55 - 8:60] +// CHECK: blocks.c:8:56: DeclRefExpr=_foo:7:21 Extent=[8:56 - 8:60] diff --git a/test/Index/code-complete-errors.c b/test/Index/code-complete-errors.c index 29c2a86198693..01c298c01d992 100644 --- a/test/Index/code-complete-errors.c +++ b/test/Index/code-complete-errors.c @@ -1,7 +1,7 @@ _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 + int x, y;; // CHECK: code-complete-errors.c:4:12: warning: extra ';' inside a struct }; // 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 diff --git a/test/Index/code-completion.cpp b/test/Index/code-completion.cpp index 670b13f6344b5..1d50fd3469a19 100644 --- a/test/Index/code-completion.cpp +++ b/test/Index/code-completion.cpp @@ -33,6 +33,10 @@ void test_overloaded() { overloaded(Z(), 0); } +Z::operator int() const { + return 0; +} + // CHECK-MEMBER: FieldDecl:{ResultType double}{TypedText member} // CHECK-MEMBER: FieldDecl:{ResultType int}{Text X::}{TypedText member} // CHECK-MEMBER: FieldDecl:{ResultType float}{Text Y::}{TypedText member} @@ -52,3 +56,12 @@ void test_overloaded() { // CHECK-OVERLOAD: NotImplemented:{ResultType int &}{Text overloaded}{LeftParen (}{Text Z z}{Comma , }{CurrentParameter int second}{RightParen )} // CHECK-OVERLOAD: NotImplemented:{ResultType float &}{Text overloaded}{LeftParen (}{Text int i}{Comma , }{CurrentParameter long second}{RightParen )} // CHECK-OVERLOAD: NotImplemented:{ResultType double &}{Text overloaded}{LeftParen (}{Text float f}{Comma , }{CurrentParameter int second}{RightParen )} + +// RUN: c-index-test -code-completion-at=%s:37:10 %s | FileCheck -check-prefix=CHECK-EXPR %s +// CHECK-EXPR: NotImplemented:{TypedText int} (40) +// CHECK-EXPR: NotImplemented:{TypedText long} (40) +// CHECK-EXPR: FieldDecl:{ResultType double}{TypedText member} (10) +// CHECK-EXPR: FieldDecl:{ResultType int}{Text X::}{TypedText member} (5) +// CHECK-EXPR: FieldDecl:{ResultType float}{Text Y::}{TypedText member} (11) +// CHECK-EXPR: FunctionDecl:{ResultType void}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )} (22) + diff --git a/test/Index/complete-at-directives.m b/test/Index/complete-at-directives.m index a278ce883666b..219d434ea4dac 100644 --- a/test/Index/complete-at-directives.m +++ b/test/Index/complete-at-directives.m @@ -6,7 +6,7 @@ @end // RUN: c-index-test -code-completion-at=%s:2:2 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s -// CHECK-CC1: {TypedText class}{HorizontalSpace }{Placeholder identifier} +// CHECK-CC1: {TypedText class}{HorizontalSpace }{Placeholder name} // CHECK-CC1: {TypedText compatibility_alias}{HorizontalSpace }{Placeholder alias}{HorizontalSpace }{Placeholder class} // CHECK-CC1: {TypedText implementation}{HorizontalSpace }{Placeholder class} // CHECK-CC1: {TypedText interface}{HorizontalSpace }{Placeholder class} @@ -24,7 +24,7 @@ // CHECK-CC3: {TypedText synthesize}{HorizontalSpace }{Placeholder property} // RUN: c-index-test -code-completion-at=%s:2:1 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC4 %s -// CHECK-CC4: NotImplemented:{TypedText @class}{HorizontalSpace }{Placeholder identifier} +// CHECK-CC4: NotImplemented:{TypedText @class}{HorizontalSpace }{Placeholder name} // CHECK-CC4: NotImplemented:{TypedText @compatibility_alias}{HorizontalSpace }{Placeholder alias}{HorizontalSpace }{Placeholder class} // CHECK-CC4: NotImplemented:{TypedText @implementation}{HorizontalSpace }{Placeholder class} // CHECK-CC4: NotImplemented:{TypedText @interface}{HorizontalSpace }{Placeholder class} @@ -39,11 +39,6 @@ // CHECK-CC5: {TypedText @optional} // CHECK-CC5: {TypedText @property} // CHECK-CC5: {TypedText @required} -// CHECK-CC5: NotImplemented:{TypedText _Bool} -// CHECK-CC5: TypedefDecl:{TypedText Class} -// CHECK-CC5: TypedefDecl:{TypedText id} -// CHECK-CC5: ObjCInterfaceDecl:{TypedText MyClass} -// CHECK-CC5: TypedefDecl:{TypedText SEL} // RUN: c-index-test -code-completion-at=%s:2:23 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC6 %s // CHECK-CC6: NotImplemented:{TypedText package} diff --git a/test/Index/complete-exprs.c b/test/Index/complete-exprs.c index 65af2419213ab..b7bed8c5fde80 100644 --- a/test/Index/complete-exprs.c +++ b/test/Index/complete-exprs.c @@ -7,12 +7,36 @@ int test(int i, int j, int k, int l) { return i | j | k & l; } +struct X f1 = { 17 }; +void f2() { f1(17); } + +const char *str = "Hello, \nWorld"; + // RUN: c-index-test -code-completion-at=%s:7:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s // CHECK-CC1: macro definition:{TypedText __VERSION__} (70) -// CHECK-CC1: FunctionDecl:{ResultType int}{TypedText f}{LeftParen (}{Placeholder int}{RightParen )} (50) -// CHECK-CC1: NotImplemented:{TypedText float} (40) -// CHECK-CC1: ParmDecl:{ResultType int}{TypedText j} (8) +// CHECK-CC1: FunctionDecl:{ResultType int}{TypedText f}{LeftParen (}{Placeholder int}{RightParen )} (12) +// CHECK-CC1-NOT: NotImplemented:{TypedText float} (40) +// CHECK-CC1: ParmDecl:{ResultType int}{TypedText j} (2) // CHECK-CC1: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30) -// RUN: c-index-test -code-completion-at=%s:7:14 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s -// RUN: c-index-test -code-completion-at=%s:7:18 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s -// RUN: c-index-test -code-completion-at=%s:7:22 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s +// RUN: c-index-test -code-completion-at=%s:7:14 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC3 %s +// CHECK-CC3: macro definition:{TypedText __VERSION__} (70) +// CHECK-CC3: FunctionDecl:{ResultType int}{TypedText f}{LeftParen (}{Placeholder int}{RightParen )} (50) +// CHECK-CC3-NOT: NotImplemented:{TypedText float} (40) +// CHECK-CC3: ParmDecl:{ResultType int}{TypedText j} (8) +// CHECK-CC3: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expressio + +// RUN: c-index-test -code-completion-at=%s:7:18 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC3 %s +// RUN: c-index-test -code-completion-at=%s:7:22 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC3 %s +// RUN: c-index-test -code-completion-at=%s:7:2 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC2 %s +// CHECK-CC2: macro definition:{TypedText __VERSION__} (70) +// CHECK-CC2: FunctionDecl:{ResultType int}{TypedText f}{LeftParen (}{Placeholder int}{RightParen )} (50) +// CHECK-CC2: NotImplemented:{TypedText float} (40) +// CHECK-CC2: ParmDecl:{ResultType int}{TypedText j} (8) +// CHECK-CC2: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30) +// RUN: c-index-test -code-completion-at=%s:11:16 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC4 %s +// CHECK-CC4: FunctionDecl:{ResultType int}{TypedText f}{LeftParen (}{Placeholder int}{RightParen )} (50) +// CHECK-CC4: VarDecl:{ResultType struct X}{TypedText f1} (50) + +// RUN: c-index-test -code-completion-at=%s:13:28 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC5 %s +// CHECK-CC5: NotImplemented:{TypedText void} (40) +// CHECK-CC5: NotImplemented:{TypedText volatile} (40) diff --git a/test/Index/complete-macros.c b/test/Index/complete-macros.c index c33d8c02e13b8..9a898e152a7fe 100644 --- a/test/Index/complete-macros.c +++ b/test/Index/complete-macros.c @@ -2,10 +2,23 @@ // matter in this test. #define FOO(Arg1,Arg2) foobar - +#define nil 0 void f() { } +void g(int); + +void f2() { + int *ip = nil; + ip = nil; + g(nil); +} + // RUN: c-index-test -code-completion-at=%s:7:1 %s | FileCheck -check-prefix=CHECK-CC1 %s // CHECK-CC1: macro definition:{TypedText FOO}{LeftParen (}{Placeholder Arg1}{Comma , }{Placeholder Arg2}{RightParen )} +// RUN: c-index-test -code-completion-at=%s:13:13 %s | FileCheck -check-prefix=CHECK-CC2 %s +// RUN: c-index-test -code-completion-at=%s:14:8 %s | FileCheck -check-prefix=CHECK-CC2 %s +// CHECK-CC2: macro definition:{TypedText nil} (30) +// RUN: c-index-test -code-completion-at=%s:15:5 %s | FileCheck -check-prefix=CHECK-CC3 %s +// CHECK-CC3: macro definition:{TypedText nil} (60) diff --git a/test/Index/complete-method-decls.m b/test/Index/complete-method-decls.m index c18994ec20a91..a30874b8a28e2 100644 --- a/test/Index/complete-method-decls.m +++ b/test/Index/complete-method-decls.m @@ -42,6 +42,16 @@ - (id)categoryFunction:(int)x { return self; } @end +@interface C +- (int)first:(int)x second:(float)y third:(double)z; +- (id)first:(int)xx second2:(float)y2 third:(double)z; +- (void*)first:(int)xxx second3:(float)y3 third:(double)z; +@end + +@interface D +- (int)first:(int)x second2:(float)y third:(double)z; +@end + // RUN: c-index-test -code-completion-at=%s:17:3 %s | FileCheck -check-prefix=CHECK-CC1 %s // CHECK-CC1: NotImplemented:{LeftParen (}{Text id}{RightParen )}{TypedText abc} // CHECK-CC1: NotImplemented:{LeftParen (}{Text int}{RightParen )}{TypedText getInt} @@ -59,24 +69,35 @@ // CHECK-CC3: NotImplemented:{TypedText init} // CHECK-CC3: NotImplemented:{TypedText initWithInt}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text x} // CHECK-CC3: NotImplemented:{TypedText initWithTwoInts}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace }{Text second}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text y} -// RUN: c-index-test -code-completion-at=%s:33:3 %s | FileCheck -check-prefix=CHECK-CC4 %s -// CHECK-CC4: NotImplemented:{LeftParen (}{Text id}{RightParen )}{TypedText abc}{HorizontalSpace }{LeftBrace {}{VerticalSpace +// RUN: c-index-test -code-completion-at=%s:33:3 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC4 %s +// CHECK-CC4: NotImplemented:{LeftParen (}{Text id}{RightParen )}{TypedText abc} // CHECK-CC4: NotImplemented:{LeftParen (}{Text int}{RightParen )}{TypedText getInt}{HorizontalSpace }{LeftBrace {}{VerticalSpace // CHECK-CC4: NotImplemented:{LeftParen (}{Text int}{RightParen )}{TypedText getSecondValue}{HorizontalSpace }{LeftBrace {}{VerticalSpace // CHECK-CC4: NotImplemented:{LeftParen (}{Text id}{RightParen )}{TypedText getSelf}{HorizontalSpace }{LeftBrace {}{VerticalSpace // CHECK-CC4: NotImplemented:{LeftParen (}{Text id}{RightParen )}{TypedText initWithInt}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace }{LeftBrace {}{VerticalSpace // CHECK-CC4: NotImplemented:{LeftParen (}{Text id}{RightParen )}{TypedText initWithTwoInts}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace }{Text second}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text y}{HorizontalSpace }{LeftBrace {}{VerticalSpace // CHECK-CC4: NotImplemented:{LeftParen (}{Text int}{RightParen )}{TypedText setValue}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace }{LeftBrace {}{VerticalSpace -// RUN: c-index-test -code-completion-at=%s:33:8 %s | FileCheck -check-prefix=CHECK-CC5 %s +// RUN: c-index-test -code-completion-at=%s:33:8 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC5 %s // CHECK-CC5: NotImplemented:{TypedText getInt}{HorizontalSpace }{LeftBrace {}{VerticalSpace // CHECK-CC5: NotImplemented:{TypedText getSecondValue}{HorizontalSpace }{LeftBrace {}{VerticalSpace // CHECK-CC5-NOT: {TypedText getSelf}{HorizontalSpace }{LeftBrace {}{VerticalSpace // CHECK-CC5: NotImplemented:{TypedText setValue}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace }{LeftBrace {}{VerticalSpace -// RUN: c-index-test -code-completion-at=%s:37:7 %s | FileCheck -check-prefix=CHECK-CC6 %s +// RUN: c-index-test -code-completion-at=%s:37:7 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC6 %s // CHECK-CC6: NotImplemented:{TypedText abc}{HorizontalSpace }{LeftBrace {}{VerticalSpace // CHECK-CC6-NOT: getSelf // CHECK-CC6: NotImplemented:{TypedText initWithInt}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace }{LeftBrace {}{VerticalSpace // CHECK-CC6: NotImplemented:{TypedText initWithTwoInts}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace }{Text second}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text y}{HorizontalSpace }{LeftBrace {}{VerticalSpace -// RUN: c-index-test -code-completion-at=%s:42:3 %s | FileCheck -check-prefix=CHECK-CC7 %s +// RUN: c-index-test -code-completion-at=%s:42:3 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC7 %s // CHECK-CC7: NotImplemented:{LeftParen (}{Text id}{RightParen )}{TypedText categoryFunction}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace }{LeftBrace {}{VerticalSpace +// RUN: c-index-test -code-completion-at=%s:52:21 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC8 %s +// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType id}{Informative first:}{TypedText second2:}{Text (float)y2}{HorizontalSpace }{Text third:}{Text (double)z} (20) +// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType void *}{Informative first:}{TypedText second3:}{Text (float)y3}{HorizontalSpace }{Text third:}{Text (double)z} (20) +// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative first:}{TypedText second:}{Text (float)y}{HorizontalSpace }{Text third:}{Text (double)z} (5) +// RUN: c-index-test -code-completion-at=%s:52:19 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC9 %s +// CHECK-CC9: NotImplemented:{TypedText x} (30) +// CHECK-CC9: NotImplemented:{TypedText xx} (30) +// CHECK-CC9: NotImplemented:{TypedText xxx} (30) +// RUN: c-index-test -code-completion-at=%s:52:36 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CCA %s +// CHECK-CCA: NotImplemented:{TypedText y2} (30) + diff --git a/test/Index/complete-objc-message.m b/test/Index/complete-objc-message.m index e65a056e36c33..321d75f3fe170 100644 --- a/test/Index/complete-objc-message.m +++ b/test/Index/complete-objc-message.m @@ -51,7 +51,7 @@ void func() { return 3; } @end - +MyClass *getMyClass(); @implementation MySubClass + (int)MySubClassMethod { return 2; @@ -160,14 +160,13 @@ void msg_id(id x) { // CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText Arg2:}{Placeholder (int)i2} // CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)obj} // RUN: c-index-test -code-completion-at=%s:61:11 %s | FileCheck -check-prefix=CHECK-CCA %s -// CHECK-CCA: {ResultType SEL}{TypedText _cmd} // CHECK-CCA: TypedefDecl:{TypedText Class} -// CHECK-CCA: ObjCInterfaceDecl:{TypedText Foo} -// CHECK-CCA: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )} +// CHECK-CCA-NEXT: ObjCInterfaceDecl:{TypedText Foo} +// CHECK-CCA-NOT: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )} +// CHECK-CCA:FunctionDecl:{ResultType MyClass *}{TypedText getMyClass}{LeftParen (}{RightParen )} // CHECK-CCA: TypedefDecl:{TypedText id} // CHECK-CCA: ObjCInterfaceDecl:{TypedText MyClass} // CHECK-CCA: ObjCInterfaceDecl:{TypedText MySubClass} -// CHECK-CCA: TypedefDecl:{TypedText SEL} // CHECK-CCA: {ResultType Class}{TypedText self} // CHECK-CCA: {TypedText super} // RUN: c-index-test -code-completion-at=%s:103:6 %s | FileCheck -check-prefix=CHECK-CCB %s @@ -188,14 +187,12 @@ void msg_id(id x) { // CHECK-CCE: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText Arg2:}{Placeholder (int)i2} // CHECK-CCE: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)obj} // RUN: c-index-test -code-completion-at=%s:61:11 %s | FileCheck -check-prefix=CHECK-CCF %s -// CHECK-CCF: {ResultType SEL}{TypedText _cmd} // CHECK-CCF: TypedefDecl:{TypedText Class} // CHECK-CCF: ObjCInterfaceDecl:{TypedText Foo} -// CHECK-CCF: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )} +// CHECK-CCF-NOT: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )} // CHECK-CCF: TypedefDecl:{TypedText id} // CHECK-CCF: ObjCInterfaceDecl:{TypedText MyClass} // CHECK-CCF: ObjCInterfaceDecl:{TypedText MySubClass} -// CHECK-CCF: TypedefDecl:{TypedText SEL} // CHECK-CCF: {ResultType Class}{TypedText self} // CHECK-CCF: {TypedText super} // RUN: c-index-test -code-completion-at=%s:120:6 %s | FileCheck -check-prefix=CHECK-CCG %s @@ -230,4 +227,3 @@ void msg_id(id x) { // CHECK-CCH: ObjCClassMethodDecl:{ResultType id}{TypedText new} // CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText OtherMethod:}{Placeholder (float)f}{HorizontalSpace }{Text Arg1:}{Placeholder (int)i1}{HorizontalSpace }{Text Arg2:}{Placeholder (int)i2} // CHECK-CCH: ObjCClassMethodDecl:{ResultType id}{TypedText protocolClassMethod} - diff --git a/test/Index/complete-recovery.m b/test/Index/complete-recovery.m index c28438da66f8d..e03834ee15b74 100644 --- a/test/Index/complete-recovery.m +++ b/test/Index/complete-recovery.m @@ -14,8 +14,12 @@ // RUN: c-index-test -code-completion-at=%s:9:20 -Xclang -code-completion-patterns %s 2>%t | FileCheck -check-prefix=CHECK-CC1 %s // RUN: not grep error %t // CHECK-CC1: NotImplemented:{TypedText @encode}{LeftParen (}{Placeholder type-name}{RightParen )} -// CHECK-CC1: NotImplemented:{TypedText _Bool} +// CHECK-CC1-NOT: NotImplemented:{TypedText _Bool} // CHECK-CC1: VarDecl:{ResultType A *}{TypedText a} // CHECK-CC1: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} -// RUN: c-index-test -code-completion-at=%s:10:24 -Xclang -code-completion-patterns %s 2>%t | FileCheck -check-prefix=CHECK-CC1 %s +// RUN: c-index-test -code-completion-at=%s:10:24 -Xclang -code-completion-patterns %s 2>%t | FileCheck -check-prefix=CHECK-CC2 %s +// CHECK-CC2: NotImplemented:{TypedText @encode}{LeftParen (}{Placeholder type-name}{RightParen )} +// CHECK-CC2: NotImplemented:{TypedText _Bool} +// CHECK-CC2: VarDecl:{ResultType A *}{TypedText a} +// CHECK-CC2: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} diff --git a/test/Index/complete-type-factors.m b/test/Index/complete-type-factors.m new file mode 100644 index 0000000000000..2048cd35233ae --- /dev/null +++ b/test/Index/complete-type-factors.m @@ -0,0 +1,107 @@ +/* Run lines are at the end, since line/column matter in this test. */ + +enum Color { + Red, Green, Blue +}; + +enum Priority { + Low, + High +}; + +int func1(enum Color); +enum Priority func2(int); +void func3(float); +enum Priority test1(enum Priority priority, enum Color color, int integer) { + int i = integer; + enum Color c = color; + return priority; + func1(c); + void (^block)(enum Color, int); + block(c, 17); + c = color; +} + +// FIXME: It would be great for message sends to have the same +// benefits as function calls, but we don't quite have the +// infrastructure yet. + +// RUN: c-index-test -code-completion-at=%s:16:11 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s +// CHECK-CC1: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (30) +// CHECK-CC1: ParmDecl:{ResultType enum Color}{TypedText color} (4) +// CHECK-CC1: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (12) +// CHECK-CC1: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (25) +// CHECK-CC1: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (30) +// CHECK-CC1: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (30) +// CHECK-CC1: VarDecl:{ResultType int}{TypedText i} (2) +// CHECK-CC1: ParmDecl:{ResultType int}{TypedText integer} (2) +// CHECK-CC1: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (30) +// CHECK-CC1: ParmDecl:{ResultType enum Priority}{TypedText priority} (4) +// CHECK-CC1: EnumConstantDecl:{ResultType enum Color}{TypedText Red} (30) +// CHECK-CC1: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30) +// CHECK-CC1: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (25) +// RUN: c-index-test -code-completion-at=%s:17:18 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC2 %s +// CHECK-CC2: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (15) +// CHECK-CC2: VarDecl:{ResultType enum Color}{TypedText c} (2) +// CHECK-CC2: ParmDecl:{ResultType enum Color}{TypedText color} (2) +// CHECK-CC2: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (25) +// CHECK-CC2: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (50) +// CHECK-CC2: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (15) +// CHECK-CC2: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (60) +// CHECK-CC2: VarDecl:{ResultType int}{TypedText i} (4) +// CHECK-CC2: ParmDecl:{ResultType int}{TypedText integer} (4) +// CHECK-CC2: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (60) +// CHECK-CC2: ParmDecl:{ResultType enum Priority}{TypedText priority} (8) +// CHECK-CC2: EnumConstantDecl:{ResultType enum Color}{TypedText Red} (15) +// CHECK-CC2: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30) +// CHECK-CC2: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (50) +// RUN: c-index-test -code-completion-at=%s:18:10 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC3 %s +// CHECK-CC3: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (60) +// CHECK-CC3: VarDecl:{ResultType enum Color}{TypedText c} (8) +// CHECK-CC3: ParmDecl:{ResultType enum Color}{TypedText color} (8) +// CHECK-CC3: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (25) +// CHECK-CC3: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (12) +// CHECK-CC3: FunctionDecl:{ResultType void}{TypedText func3}{LeftParen (}{Placeholder float}{RightParen )} (50) +// CHECK-CC3: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (60) +// CHECK-CC3: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (15) +// CHECK-CC3: VarDecl:{ResultType int}{TypedText i} (4) +// CHECK-CC3: ParmDecl:{ResultType int}{TypedText integer} (4) +// CHECK-CC3: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (15) +// CHECK-CC3: ParmDecl:{ResultType enum Priority}{TypedText priority} (2) +// CHECK-CC3: EnumConstantDecl:{ResultType enum Color}{TypedText Red} (60) +// CHECK-CC3: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30) +// CHECK-CC3: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (12) +// RUN: c-index-test -code-completion-at=%s:19:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC4 %s +// CHECK-CC4: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (15) +// CHECK-CC4: VarDecl:{ResultType enum Color}{TypedText c} (2) +// CHECK-CC4: ParmDecl:{ResultType enum Color}{TypedText color} (2) +// CHECK-CC4: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (25) +// CHECK-CC4: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (50) +// CHECK-CC4: FunctionDecl:{ResultType void}{TypedText func3}{LeftParen (}{Placeholder float}{RightParen )} (50) +// CHECK-CC4: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (15) +// CHECK-CC4: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (60) +// CHECK-CC4: VarDecl:{ResultType int}{TypedText i} (4) +// CHECK-CC4: ParmDecl:{ResultType int}{TypedText integer} (4) +// CHECK-CC4: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (60) +// CHECK-CC4: ParmDecl:{ResultType enum Priority}{TypedText priority} (8) +// CHECK-CC4: EnumConstantDecl:{ResultType enum Color}{TypedText Red} (15) +// CHECK-CC4: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30) +// CHECK-CC4: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (50) +// RUN: c-index-test -code-completion-at=%s:21:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC4 %s +// RUN: c-index-test -code-completion-at=%s:22:7 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC6 %s +// CHECK-CC6: VarDecl:{ResultType void (^)(enum Color, int)}{TypedText block} (8) +// CHECK-CC6: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (15) +// CHECK-CC6: VarDecl:{ResultType enum Color}{TypedText c} (2) +// CHECK-CC6: ParmDecl:{ResultType enum Color}{TypedText color} (2) +// CHECK-CC6: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (25) +// CHECK-CC6: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (50) +// CHECK-CC6: FunctionDecl:{ResultType void}{TypedText func3}{LeftParen (}{Placeholder float}{RightParen )} (50) +// CHECK-CC6: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (15) +// CHECK-CC6: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (60) +// CHECK-CC6: VarDecl:{ResultType int}{TypedText i} (4) +// CHECK-CC6: ParmDecl:{ResultType int}{TypedText integer} (4) +// CHECK-CC6: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (60) +// CHECK-CC6: ParmDecl:{ResultType enum Priority}{TypedText priority} (8) +// CHECK-CC6: EnumConstantDecl:{ResultType enum Color}{TypedText Red} (15) +// CHECK-CC6: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30) +// CHECK-CC6: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (50) diff --git a/test/Index/print-typekind.c b/test/Index/print-typekind.c index 79a9965d4d85c..13b41198f1278 100644 --- a/test/Index/print-typekind.c +++ b/test/Index/print-typekind.c @@ -8,7 +8,7 @@ int *f(int *p, char *x, FooType z) { // RUN: c-index-test -test-print-typekind %s | FileCheck %s // CHECK: TypedefDecl=FooType:1:13 (Definition) typekind=Typedef [canonical=Int] // CHECK: VarDecl=p:2:6 typekind=Pointer -// CHECK: FunctionDecl=f:3:6 (Definition) typekind=Unexposed [canonical=Unexposed] +// CHECK: FunctionDecl=f:3:6 (Definition) typekind=FunctionProto [canonical=FunctionProto] [result=Pointer] // CHECK: ParmDecl=p:3:13 (Definition) typekind=Pointer // CHECK: ParmDecl=x:3:22 (Definition) typekind=Pointer // CHECK: ParmDecl=z:3:33 (Definition) typekind=Typedef [canonical=Int] diff --git a/test/Index/print-typekind.m b/test/Index/print-typekind.m new file mode 100644 index 0000000000000..68827fb7ca6e9 --- /dev/null +++ b/test/Index/print-typekind.m @@ -0,0 +1,10 @@ +@interface Foo +@property (readonly) id x; +-(int) mymethod; +@end + +// RUN: c-index-test -test-print-typekind %s | FileCheck %s +// CHECK: ObjCPropertyDecl=x:2:25 typekind=Typedef [canonical=ObjCObjectPointer] +// CHECK: ObjCInstanceMethodDecl=mymethod:3:1 typekind=Invalid [result=Int] + + diff --git a/test/Index/usrs.m b/test/Index/usrs.m index bffd0ee4bbc75..0b56cca1ef645 100644 --- a/test/Index/usrs.m +++ b/test/Index/usrs.m @@ -48,6 +48,15 @@ int z; static int local_func(int x) { return x; } +@interface CWithExt +@end +@interface CWithExt () +@end +@interface CWithExt () +@end +@implementation CWithExt +@end + // CHECK: usrs.m c:usrs.m@3:19@F@my_helper Extent=[3:19 - 3:60] // CHECK: usrs.m c:usrs.m@3:29@F@my_helper@x Extent=[3:29 - 3:34] // CHECK: usrs.m c:usrs.m@3:36@F@my_helper@y Extent=[3:36 - 3:41] @@ -84,4 +93,9 @@ static int local_func(int x) { return x; } // CHECK: usrs.m c:@z Extent=[47:1 - 47:6] // CHECK: usrs.m c:usrs.m@49:12@F@local_func Extent=[49:12 - 49:43] // CHECK: usrs.m c:usrs.m@49:23@F@local_func@x Extent=[49:23 - 49:28] +// CHECK: usrs.m c:objc(cs)CWithExt Extent=[51:1 - 52:5] +// CHECK: usrs.m c:objc(cy)CWithExt@ Extent=[53:1 - 54:5] +// CHECK: usrs.m c:objc(cy)CWithExt@ Extent=[55:1 - 56:5] +// CHECK: usrs.m c:objc(cs)CWithExt Extent=[57:1 - 58:2] + diff --git a/test/Lexer/block_cmt_end.c b/test/Lexer/block_cmt_end.c index 72bc836a0ef0c..b03fb23f8eeb4 100644 --- a/test/Lexer/block_cmt_end.c +++ b/test/Lexer/block_cmt_end.c @@ -17,7 +17,7 @@ next comment ends with normal escaped newline: /* expected-warning {{escaped newline}} expected-warning {{backslash and newline}} *\ / -int bar /* expected-error {{invalid token after top level declarator}} */ +int bar /* expected-error {{expected ';' after top level declarator}} */ /* xyz diff --git a/test/Lexer/constants.c b/test/Lexer/constants.c index b833e7b43f471..2602ec255656e 100644 --- a/test/Lexer/constants.c +++ b/test/Lexer/constants.c @@ -24,6 +24,13 @@ t', 'abcd' // expected-warning {{multi-character character constant}} }; +// PR4499 +int m0 = '0'; +int m1 = '\\\''; // expected-warning {{multi-character character constant}} +int m2 = '\\\\'; // expected-warning {{multi-character character constant}} +int m3 = '\\\ +'; + #pragma clang diagnostic ignored "-Wmultichar" diff --git a/test/Lexer/has_feature_cxx0x.cpp b/test/Lexer/has_feature_cxx0x.cpp index 7ea4c2c1cdcf9..650e577ca72c8 100644 --- a/test/Lexer/has_feature_cxx0x.cpp +++ b/test/Lexer/has_feature_cxx0x.cpp @@ -1,5 +1,5 @@ -// RUN: %clang -E -std=c++0x %s -o - | FileCheck --check-prefix=CHECK-0X %s -// RUN: %clang -E %s -o - | FileCheck --check-prefix=CHECK-NO-0X %s +// RUN: %clang_cc1 -E -std=c++0x %s -o - | FileCheck --check-prefix=CHECK-0X %s +// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-0X %s #if __has_feature(cxx_lambdas) int lambdas(); diff --git a/test/Lexer/has_feature_exceptions.cpp b/test/Lexer/has_feature_exceptions.cpp index cfd1efbf84645..bb5dc0c133626 100644 --- a/test/Lexer/has_feature_exceptions.cpp +++ b/test/Lexer/has_feature_exceptions.cpp @@ -1,5 +1,5 @@ -// RUN: %clang -E -fexceptions %s -o - | FileCheck --check-prefix=CHECK-EXCEPTIONS %s -// RUN: %clang -E -fno-exceptions %s -o - | FileCheck --check-prefix=CHECK-NO-EXCEPTIONS %s +// RUN: %clang_cc1 -E -fexceptions %s -o - | FileCheck --check-prefix=CHECK-EXCEPTIONS %s +// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-EXCEPTIONS %s #if __has_feature(cxx_exceptions) int foo(); diff --git a/test/Lexer/has_feature_rtti.cpp b/test/Lexer/has_feature_rtti.cpp index 690906c292f23..4bfeead329972 100644 --- a/test/Lexer/has_feature_rtti.cpp +++ b/test/Lexer/has_feature_rtti.cpp @@ -1,5 +1,5 @@ -// RUN: %clang -E -frtti %s -o - | FileCheck --check-prefix=CHECK-RTTI %s -// RUN: %clang -E -fno-rtti %s -o - | FileCheck --check-prefix=CHECK-NO-RTTI %s +// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-RTTI %s +// RUN: %clang_cc1 -E -fno-rtti %s -o - | FileCheck --check-prefix=CHECK-NO-RTTI %s #if __has_feature(cxx_rtti) int foo(); diff --git a/test/Lexer/hexfloat.cpp b/test/Lexer/hexfloat.cpp index a3b230e78f161..493b64e627402 100644 --- a/test/Lexer/hexfloat.cpp +++ b/test/Lexer/hexfloat.cpp @@ -1,5 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s +// XFAIL: * #ifndef __GXX_EXPERIMENTAL_CXX0X__ float f = 0x1p+1; // expected-warning {{incompatible with C++0x}} diff --git a/test/Makefile b/test/Makefile index c3b3eab589455..5bb50c622afd8 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,5 +1,5 @@ -LEVEL = ../../.. -include $(LEVEL)/Makefile.common +CLANG_LEVEL := .. +include $(CLANG_LEVEL)/Makefile # Test in all immediate subdirectories if unset. ifdef TESTSUITE diff --git a/test/Misc/macro-backtrace-limit.c b/test/Misc/macro-backtrace-limit.c index bc7a4da93a51d..1e512febefa25 100644 --- a/test/Misc/macro-backtrace-limit.c +++ b/test/Misc/macro-backtrace-limit.c @@ -1,4 +1,4 @@ -// RUN: %clang-cc1 -fsyntax-only -fmacro-backtrace-limit 5 %s > %t 2>&1 +// RUN: %clang_cc1 -fsyntax-only -fmacro-backtrace-limit 5 %s > %t 2>&1 // RUN: FileCheck %s < %t #define M1(A, B) ((A) < (B)) diff --git a/test/PCH/attrs.h b/test/PCH/attrs.h index 0d0156515c88b..58f0589704319 100644 --- a/test/PCH/attrs.h +++ b/test/PCH/attrs.h @@ -4,4 +4,4 @@ -int f(int) __attribute__((overloadable)); +int f(int) __attribute__((visibility("default"), overloadable)); diff --git a/test/PCH/cxx-friends.cpp b/test/PCH/cxx-friends.cpp new file mode 100644 index 0000000000000..a8d75586e4311 --- /dev/null +++ b/test/PCH/cxx-friends.cpp @@ -0,0 +1,13 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-friends.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-friends.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +class F { + void m() { + A* a; + a->x = 0; + } +}; diff --git a/test/PCH/cxx-friends.h b/test/PCH/cxx-friends.h new file mode 100644 index 0000000000000..2a33f15a53298 --- /dev/null +++ b/test/PCH/cxx-friends.h @@ -0,0 +1,6 @@ +// Header for PCH test cxx-friends.cpp + +class A { + int x; + friend class F; +}; diff --git a/test/PCH/cxx-namespaces.cpp b/test/PCH/cxx-namespaces.cpp new file mode 100644 index 0000000000000..0fd3de7f6c884 --- /dev/null +++ b/test/PCH/cxx-namespaces.cpp @@ -0,0 +1,10 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-namespaces.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-namespaces.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +void m() { + N::x = 0; +} diff --git a/test/PCH/cxx-namespaces.h b/test/PCH/cxx-namespaces.h new file mode 100644 index 0000000000000..f3389533d001e --- /dev/null +++ b/test/PCH/cxx-namespaces.h @@ -0,0 +1,7 @@ +// Header for PCH test cxx-namespaces.cpp + +namespace N { + namespace { + int x; + } +} diff --git a/test/PCH/cxx-templates.cpp b/test/PCH/cxx-templates.cpp new file mode 100644 index 0000000000000..f12742755a9f7 --- /dev/null +++ b/test/PCH/cxx-templates.cpp @@ -0,0 +1,25 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-templates.h -verify %s -ast-dump + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-templates.h +// RUN: %clang_cc1 -include-pch %t -verify %s -ast-dump + +struct A { + typedef int type; + static void my_f(); + template <typename T> + static T my_templf(T x) { return x; } +}; + +void test() { + int x = templ_f<int, 5>(3); + + S<char, float>::templ(); + S<int, char>::partial(); + S<int, float>::explicit_special(); + + Dep<A>::Ty ty; + Dep<A> a; + a.f(); +} diff --git a/test/PCH/cxx-templates.h b/test/PCH/cxx-templates.h new file mode 100644 index 0000000000000..396853686fadd --- /dev/null +++ b/test/PCH/cxx-templates.h @@ -0,0 +1,102 @@ +// Header for PCH test cxx-templates.cpp + +template <typename T1, typename T2> +struct S; + +template <typename T1, typename T2> +struct S { + S() { } + static void templ(); +}; + +template <typename T> +struct S<int, T> { + static void partial(); +}; + +template <> +struct S<int, float> { + static void explicit_special(); +}; + +template <int x> +int tmpl_f2() { return x; } + +template <typename T, int y> +T templ_f(T x) { + int z = templ_f<int, 5>(3); + z = tmpl_f2<y+2>(); + T data[y]; + return x+y; +} + +void govl(int); +void govl(char); + +template <typename T> +struct Unresolv { + void f() { + govl(T()); + } +}; + +template <typename T> +struct Dep { + typedef typename T::type Ty; + void f() { + Ty x = Ty(); + T::my_f(); + int y = T::template my_templf<int>(0); + ovl(y); + } + + void ovl(int); + void ovl(float); +}; + +template<typename T, typename A1> +inline T make_a(const A1& a1) { + T::depend_declref(); + return T(a1); +} + +template <class T> class UseBase { + void foo(); + typedef int bar; +}; + +template <class T> class UseA : public UseBase<T> { + using UseBase<T>::foo; + using typename UseBase<T>::bar; +}; + +template <class T> class Sub : public UseBase<int> { }; + +template <class _Ret, class _Tp> + class mem_fun_t + { + public: + explicit + mem_fun_t(_Ret (_Tp::*__pf)()) + {} + + private: + _Ret (_Tp::*_M_f)(); + }; + +template<unsigned N> +bool isInt(int x); + +template<> bool isInt<8>(int x) { + return true; +} + +template<typename _CharT> +int __copy_streambufs_eof(_CharT); + +class basic_streambuf +{ + void m() { } + friend int __copy_streambufs_eof<>(int); +}; + diff --git a/test/PCH/cxx-using.cpp b/test/PCH/cxx-using.cpp new file mode 100644 index 0000000000000..2ca7dad0dd16c --- /dev/null +++ b/test/PCH/cxx-using.cpp @@ -0,0 +1,15 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-using.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-using.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +void m() { + D s; // expected-note {{candidate function}} + s.f(); // expected-error {{no matching member}} +} + + + +// expected-note {{candidate function}} diff --git a/test/PCH/cxx-using.h b/test/PCH/cxx-using.h new file mode 100644 index 0000000000000..572cea2814277 --- /dev/null +++ b/test/PCH/cxx-using.h @@ -0,0 +1,16 @@ +// Header for PCH test cxx-using.cpp + + + + + + +struct B { + void f(char c); +}; + +struct D : B +{ + using B::f; + void f(int); +}; diff --git a/test/PCH/cxx_exprs.cpp b/test/PCH/cxx_exprs.cpp index ec7041b9843a6..2b9a5abbf11a9 100644 --- a/test/PCH/cxx_exprs.cpp +++ b/test/PCH/cxx_exprs.cpp @@ -1,9 +1,9 @@ // Test this without pch. -// RUN: %clang_cc1 -include %S/cxx_exprs.h -std=c++0x -fsyntax-only -verify %s +// RUN: %clang_cc1 -include %S/cxx_exprs.h -std=c++0x -fsyntax-only -verify %s -ast-dump -// Test with pch. +// Test with pch. Use '-ast-dump' to force deserialization of function bodies. // RUN: %clang_cc1 -x c++-header -std=c++0x -emit-pch -o %t %S/cxx_exprs.h -// RUN: %clang_cc1 -std=c++0x -include-pch %t -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++0x -include-pch %t -fsyntax-only -verify %s -ast-dump int integer; double floating; @@ -36,4 +36,4 @@ cxx_null_ptr_result null_ptr = nullptr; // CXXTypeidExpr typeid_result1 typeid_1 = 0; -typeid_result2 typeid_2 = 0;
\ No newline at end of file +typeid_result2 typeid_2 = 0; diff --git a/test/PCH/cxx_exprs.h b/test/PCH/cxx_exprs.h index f647922389912..67ab4a6d34db9 100644 --- a/test/PCH/cxx_exprs.h +++ b/test/PCH/cxx_exprs.h @@ -68,8 +68,8 @@ void Derived::g() { int A = int(0.5); // CXXFunctionalCastExpr A = int(); // CXXZeroInitValueExpr - new Base(4); // CXXNewExpr - + Base *b = new Base(4); // CXXNewExpr + delete b; // CXXDeleteExpr } diff --git a/test/PCH/exprs.c b/test/PCH/exprs.c index 038a18ba5b26b..d855defe7eed0 100644 --- a/test/PCH/exprs.c +++ b/test/PCH/exprs.c @@ -59,6 +59,8 @@ add_result *int_ptr5 = &integer; // CompoundAssignOperator addeq_result *int_ptr6 = &integer; +add_result_with_typeinfo *int_typeinfo_ptr6; + // ConditionalOperator conditional_operator *double_ptr4 = &floating; diff --git a/test/PCH/exprs.h b/test/PCH/exprs.h index 5af8c7c1a9004..80768f8df24e7 100644 --- a/test/PCH/exprs.h +++ b/test/PCH/exprs.h @@ -72,6 +72,8 @@ typedef typeof((void *)0) void_ptr; // CompoundLiteral typedef typeof((struct S){.x = 3.5}) compound_literal; +typedef typeof(i + sizeof(int[i + Enumerator])) add_result_with_typeinfo; + // ExtVectorElementExpr typedef __attribute__(( ext_vector_type(2) )) double double2; extern double2 vec2, vec2b; diff --git a/test/PCH/types.c b/test/PCH/types.c index c21b33a4ee519..73a2205b78b6c 100644 --- a/test/PCH/types.c +++ b/test/PCH/types.c @@ -3,7 +3,7 @@ // Test with pch. // RUN: %clang_cc1 -emit-pch -fblocks -o %t %S/types.h -// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -verify %s +// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -verify %s -ast-print typedef int INT; INT int_value; diff --git a/test/PCH/types.h b/test/PCH/types.h index df9f5c8607f70..ab42331fe4133 100644 --- a/test/PCH/types.h +++ b/test/PCH/types.h @@ -42,3 +42,8 @@ typedef typeof(17) typeof_17; // TYPE_TYPEOF typedef typeof(int_ptr *) int_ptr_ptr2; + +struct S2; +struct S2 {}; +enum E; +enum E { myenum }; diff --git a/test/Parser/altivec.c b/test/Parser/altivec.c index ed144573fcd29..92ec688bc01da 100644 --- a/test/Parser/altivec.c +++ b/test/Parser/altivec.c @@ -13,7 +13,9 @@ __vector int vv_i; __vector signed int vv_sint; __vector unsigned int vv_ui; __vector float vv_f; -__vector bool vv_b; +__vector bool char vv_bc; +__vector bool short vv_bs; +__vector bool int vv_bi; __vector __pixel vv_p; __vector pixel vv__p; __vector int vf__r(); @@ -33,7 +35,9 @@ vector int v_i; vector signed int v_sint; vector unsigned int v_ui; vector float v_f; -vector bool v_b; +vector bool char v_bc; +vector bool short v_bs; +vector bool int v_bi; vector __pixel v_p; vector pixel v__p; vector int f__r(); @@ -57,14 +61,20 @@ vector signed long int v_sli; // expected-warning {{Use of 'long' with '__ 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'}} +vector bool v_b; // expected-warning {{type specifier missing, defaults to 'int'}} // 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'}} +__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'}} +vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}} +vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}} +vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}} +vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}} +vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}} +vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}} +vector bool long long v_bll; // expected-error {{cannot use 'long long' with '__vector bool'}} void f() { __vector unsigned int v = {0,0,0,0}; @@ -91,3 +101,11 @@ void f() { gccv = v; gccvector unsigned int tgv = v; } + +// bug 6895 - Vectorl literal casting confusion. +vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
+vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
+vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
+vector int v4 = (vector int)(1, 2, 3, 4);
+vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); +vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3))); diff --git a/test/Parser/backtrack-crash.cpp b/test/Parser/backtrack-crash.cpp new file mode 100644 index 0000000000000..cc26873729699 --- /dev/null +++ b/test/Parser/backtrack-crash.cpp @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic +// PR7072 +()( // expected-error {{expected unqualified-id}} + diff --git a/test/Parser/bracket-crash.cpp b/test/Parser/bracket-crash.cpp new file mode 100644 index 0000000000000..fd18e0e25fefd --- /dev/null +++ b/test/Parser/bracket-crash.cpp @@ -0,0 +1,6 @@ +// RUN: not %clang_cc1 -fsyntax-only %s +// PR7481 +struct{ + a +} + diff --git a/test/Parser/cxx-altivec.cpp b/test/Parser/cxx-altivec.cpp index 66d4f3263b9ae..a70eea077e7af 100644 --- a/test/Parser/cxx-altivec.cpp +++ b/test/Parser/cxx-altivec.cpp @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify %s -// This is the same as the C version: __vector char vv_c; __vector signed char vv_sc; @@ -14,7 +13,9 @@ __vector int vv_i; __vector signed int vv_sint; __vector unsigned int vv_ui; __vector float vv_f; -__vector bool vv_b; +__vector bool char vv_bc; +__vector bool short vv_bs; +__vector bool int vv_bi; __vector __pixel vv_p; __vector pixel vv__p; __vector int vf__r(); @@ -34,7 +35,9 @@ vector int v_i; vector signed int v_sint; vector unsigned int v_ui; vector float v_f; -vector bool v_b; +vector bool char v_bc; +vector bool short v_bs; +vector bool int v_bi; vector __pixel v_p; vector pixel v__p; vector int f__r(); @@ -64,6 +67,14 @@ __vector double vv_d1; // expected-error {{cannot use 'double' wit 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'}} +vector bool v_b; // expected-error {{error: C++ requires a type specifier for all declarations}} +vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}} +vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}} +vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}} +vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}} +vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}} +vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}} +vector bool long long v_bll; // expected-error {{cannot use 'long long' with '__vector bool'}} void f() { __vector unsigned int v = {0,0,0,0}; @@ -107,3 +118,11 @@ class c_v { void f__a2(int b, vector int a); }; + +// bug 6895 - Vectorl literal casting confusion. +vector char v1 = (vector char)((vector int)(1, 2, 3, 4)); +vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f)); +vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd')); +vector int v4 = (vector int)(1, 2, 3, 4); +vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); +vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3))); diff --git a/test/Parser/cxx-class.cpp b/test/Parser/cxx-class.cpp index 4abbbc5b9b580..57831a463b9bb 100644 --- a/test/Parser/cxx-class.cpp +++ b/test/Parser/cxx-class.cpp @@ -7,7 +7,7 @@ protected: static int sf(), u; struct S {}; - enum {}; + enum {}; // expected-warning{{declaration does not declare anything}} int; // expected-warning {{declaration does not declare anything}} int : 1, : 2; diff --git a/test/Parser/cxx-decl.cpp b/test/Parser/cxx-decl.cpp index ae004ce81c1d5..e4c703c334bd1 100644 --- a/test/Parser/cxx-decl.cpp +++ b/test/Parser/cxx-decl.cpp @@ -37,6 +37,10 @@ class someclass { } }; +class asm_class_test { + void foo() __asm__("baz"); +}; + enum { fooenum = 1 }; struct a { diff --git a/test/Parser/cxx-undeclared-identifier.cpp b/test/Parser/cxx-undeclared-identifier.cpp index 36d8f7a65381a..f15deabc6da52 100644 --- a/test/Parser/cxx-undeclared-identifier.cpp +++ b/test/Parser/cxx-undeclared-identifier.cpp @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s +// PR7180 +int f(a::b::c); // expected-error {{use of undeclared identifier 'a'}} + class Foo::Bar { // expected-error {{use of undeclared identifier 'Foo'}} \ // expected-note {{to match this '{'}} \ // expected-error {{expected ';' after class}} diff --git a/test/Parser/declarators.c b/test/Parser/declarators.c index 31712af26c745..fb69fa9c1d05a 100644 --- a/test/Parser/declarators.c +++ b/test/Parser/declarators.c @@ -83,3 +83,14 @@ void test12() { // rdar://7608537 struct test13 { int a; } (test13x); + +// <rdar://problem/8044088> +struct X<foo::int> { }; // expected-error{{expected identifier or '('}} + + +// PR7617 - error recovery on missing ;. + +void test14() // expected-error {{expected ';' after top level declarator}} + +void test14a(); +void *test14b = (void*)test14a; // Make sure test14a didn't get skipped. diff --git a/test/Parser/objc-try-catch-1.m b/test/Parser/objc-try-catch-1.m index 1934cbd3b83d0..719369124e5cf 100644 --- a/test/Parser/objc-try-catch-1.m +++ b/test/Parser/objc-try-catch-1.m @@ -27,13 +27,15 @@ void * foo() return proc(); } @catch (Frob* ex) { - @throw 1,2; // expected-error {{@throw requires an Objective-C object type ('int' invalid)}} + @throw 1,2; // expected-error {{@throw requires an Objective-C object type ('int' invalid)}} \ + // expected-warning {{expression result unused}} } @catch (float x) { // expected-error {{@catch parameter is not a pointer to an interface type}} } @catch(...) { - @throw (4,3,proc()); + @throw (4,3,proc()); // expected-warning {{expression result unused}} \ + // expected-warning {{expression result unused}} } } diff --git a/test/Parser/pragma-options.c b/test/Parser/pragma-options.c index 332249fdcfe31..daf385dddba73 100644 --- a/test/Parser/pragma-options.c +++ b/test/Parser/pragma-options.c @@ -9,4 +9,4 @@ #pragma options align=natural #pragma options align=reset #pragma options align=mac68k -/* expected-warning {{unsupported alignment option}} */ #pragma options align=power +#pragma options align=power diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c index b9850983a2a14..8283671b6636f 100644 --- a/test/Preprocessor/init.c +++ b/test/Preprocessor/init.c @@ -14,6 +14,7 @@ // CXX0X:#define __DEPRECATED 1 // CXX0X:#define __GNUG__ // CXX0X:#define __GXX_EXPERIMENTAL_CXX0X__ 1 +// CXX0X:#define __GXX_RTTI 1 // CXX0X:#define __GXX_WEAK__ 1 // CXX0X:#define __cplusplus 199711L // CXX0X:#define __private_extern__ extern @@ -23,6 +24,7 @@ // // CXX98:#define __DEPRECATED 1 // CXX98:#define __GNUG__ +// CXX98:#define __GXX_RTTI 1 // CXX98:#define __GXX_WEAK__ 1 // CXX98:#define __cplusplus 199711L // CXX98:#define __private_extern__ extern @@ -48,9 +50,9 @@ // COMMON:#define __STDC__ 1 // COMMON:#define __VERSION__ // COMMON:#define __clang__ 1 -// COMMON:#define __clang_major__ 2 -// COMMON:#define __clang_minor__ 0 -// COMMON:#define __clang_patchlevel__ 0 +// COMMON:#define __clang_major__ {{[0-9]+}} +// COMMON:#define __clang_minor__ {{[0-9]+}} +// COMMON:#define __clang_patchlevel__ {{[0-9]+}} // COMMON:#define __clang_version__ // COMMON:#define __llvm__ 1 // @@ -120,6 +122,8 @@ // ARM:#define __APCS_32__ 1 // ARM:#define __ARMEL__ 1 // ARM:#define __ARM_ARCH_6J__ 1 +// ARM:#define __CHAR16_TYPE__ unsigned short +// ARM:#define __CHAR32_TYPE__ unsigned int // ARM:#define __CHAR_BIT__ 8 // ARM:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // ARM:#define __DBL_DIG__ 15 @@ -185,6 +189,18 @@ // ARM:#define __SCHAR_MAX__ 127 // ARM:#define __SHRT_MAX__ 32767 // ARM:#define __SIG_ATOMIC_WIDTH__ 32 +// ARM:#define __SIZEOF_DOUBLE__ 8 +// ARM:#define __SIZEOF_FLOAT__ 4 +// ARM:#define __SIZEOF_INT__ 4 +// ARM:#define __SIZEOF_LONG_DOUBLE__ 8 +// ARM:#define __SIZEOF_LONG_LONG__ 8 +// ARM:#define __SIZEOF_LONG__ 4 +// ARM:#define __SIZEOF_POINTER__ 4 +// ARM:#define __SIZEOF_PTRDIFF_T__ 4 +// ARM:#define __SIZEOF_SHORT__ 2 +// ARM:#define __SIZEOF_SIZE_T__ 4 +// ARM:#define __SIZEOF_WCHAR_T__ 4 +// ARM:#define __SIZEOF_WINT_T__ 4 // ARM:#define __SIZE_TYPE__ unsigned int // ARM:#define __SIZE_WIDTH__ 32 // ARM:#define __THUMB_INTERWORK__ 1 @@ -205,6 +221,8 @@ // BFIN:#define __ADSPLPBLACKFIN__ 1 // BFIN:#define __BFIN 1 // BFIN:#define __BFIN__ 1 +// BFIN:#define __CHAR16_TYPE__ unsigned short +// BFIN:#define __CHAR32_TYPE__ unsigned int // BFIN:#define __CHAR_BIT__ 8 // BFIN:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // BFIN:#define __DBL_DIG__ 15 @@ -268,6 +286,18 @@ // BFIN:#define __SCHAR_MAX__ 127 // BFIN:#define __SHRT_MAX__ 32767 // BFIN:#define __SIG_ATOMIC_WIDTH__ 32 +// BFIN:#define __SIZEOF_DOUBLE__ 8 +// BFIN:#define __SIZEOF_FLOAT__ 4 +// BFIN:#define __SIZEOF_INT__ 4 +// BFIN:#define __SIZEOF_LONG_DOUBLE__ 8 +// BFIN:#define __SIZEOF_LONG_LONG__ 8 +// BFIN:#define __SIZEOF_LONG__ 4 +// BFIN:#define __SIZEOF_POINTER__ 4 +// BFIN:#define __SIZEOF_PTRDIFF_T__ 4 +// BFIN:#define __SIZEOF_SHORT__ 2 +// BFIN:#define __SIZEOF_SIZE_T__ 4 +// BFIN:#define __SIZEOF_WCHAR_T__ 4 +// BFIN:#define __SIZEOF_WINT_T__ 4 // BFIN:#define __SIZE_TYPE__ long unsigned int // BFIN:#define __SIZE_WIDTH__ 32 // BFIN:#define __UINTMAX_TYPE__ long long unsigned int @@ -283,6 +313,8 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-none-none < /dev/null | FileCheck -check-prefix I386 %s // +// I386:#define __CHAR16_TYPE__ unsigned short +// I386:#define __CHAR32_TYPE__ unsigned int // I386:#define __CHAR_BIT__ 8 // I386:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // I386:#define __DBL_DIG__ 15 @@ -349,6 +381,18 @@ // I386:#define __SCHAR_MAX__ 127 // I386:#define __SHRT_MAX__ 32767 // I386:#define __SIG_ATOMIC_WIDTH__ 32 +// I386:#define __SIZEOF_DOUBLE__ 8 +// I386:#define __SIZEOF_FLOAT__ 4 +// I386:#define __SIZEOF_INT__ 4 +// I386:#define __SIZEOF_LONG_DOUBLE__ 12 +// I386:#define __SIZEOF_LONG_LONG__ 8 +// I386:#define __SIZEOF_LONG__ 4 +// I386:#define __SIZEOF_POINTER__ 4 +// I386:#define __SIZEOF_PTRDIFF_T__ 4 +// I386:#define __SIZEOF_SHORT__ 2 +// I386:#define __SIZEOF_SIZE_T__ 4 +// I386:#define __SIZEOF_WCHAR_T__ 4 +// I386:#define __SIZEOF_WINT_T__ 4 // I386:#define __SIZE_TYPE__ unsigned int // I386:#define __SIZE_WIDTH__ 32 // I386:#define __UINTMAX_TYPE__ long long unsigned int @@ -368,6 +412,8 @@ // RUN: %clang_cc1 -E -dM -ffreestanding -triple=msp430-none-none < /dev/null | FileCheck -check-prefix MSP430 %s // // MSP430:#define MSP430 1 +// MSP430:#define __CHAR16_TYPE__ unsigned short +// MSP430:#define __CHAR32_TYPE__ unsigned int // MSP430:#define __CHAR_BIT__ 8 // MSP430:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // MSP430:#define __DBL_DIG__ 15 @@ -431,6 +477,18 @@ // MSP430:#define __SCHAR_MAX__ 127 // MSP430:#define __SHRT_MAX__ 32767 // MSP430:#define __SIG_ATOMIC_WIDTH__ 32 +// MSP430:#define __SIZEOF_DOUBLE__ 8 +// MSP430:#define __SIZEOF_FLOAT__ 4 +// MSP430:#define __SIZEOF_INT__ 2 +// MSP430:#define __SIZEOF_LONG_DOUBLE__ 8 +// MSP430:#define __SIZEOF_LONG_LONG__ 8 +// MSP430:#define __SIZEOF_LONG__ 4 +// MSP430:#define __SIZEOF_POINTER__ 2 +// MSP430:#define __SIZEOF_PTRDIFF_T__ 2 +// MSP430:#define __SIZEOF_SHORT__ 2 +// MSP430:#define __SIZEOF_SIZE_T__ 2 +// MSP430:#define __SIZEOF_WCHAR_T__ 2 +// MSP430:#define __SIZEOF_WINT_T__ 2 // MSP430:#define __SIZE_TYPE__ unsigned int // MSP430:#define __SIZE_WIDTH__ 16 // MSP430:#define __UINTMAX_TYPE__ long unsigned int @@ -444,6 +502,8 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=pic16-none-none < /dev/null | FileCheck -check-prefix PIC16 %s // +// PIC16:#define __CHAR16_TYPE__ unsigned short +// PIC16:#define __CHAR32_TYPE__ unsigned int // PIC16:#define __CHAR_BIT__ 8 // PIC16:#define __DBL_DENORM_MIN__ 1.40129846e-45F // PIC16:#define __DBL_DIG__ 6 @@ -507,6 +567,18 @@ // PIC16:#define __SCHAR_MAX__ 127 // PIC16:#define __SHRT_MAX__ 32767 // PIC16:#define __SIG_ATOMIC_WIDTH__ 32 +// PIC16:#define __SIZEOF_DOUBLE__ 4 +// PIC16:#define __SIZEOF_FLOAT__ 4 +// PIC16:#define __SIZEOF_INT__ 2 +// PIC16:#define __SIZEOF_LONG_DOUBLE__ 4 +// PIC16:#define __SIZEOF_LONG_LONG__ 4 +// PIC16:#define __SIZEOF_LONG__ 4 +// PIC16:#define __SIZEOF_POINTER__ 2 +// PIC16:#define __SIZEOF_PTRDIFF_T__ 2 +// PIC16:#define __SIZEOF_SHORT__ 2 +// PIC16:#define __SIZEOF_SIZE_T__ 2 +// PIC16:#define __SIZEOF_WCHAR_T__ 2 +// PIC16:#define __SIZEOF_WINT_T__ 2 // PIC16:#define __SIZE_TYPE__ unsigned int // PIC16:#define __SIZE_WIDTH__ 16 // PIC16:#define __UINTMAX_TYPE__ long unsigned int @@ -535,6 +607,8 @@ // PPC64:#define _BIG_ENDIAN 1 // PPC64:#define _LP64 1 // PPC64:#define __BIG_ENDIAN__ 1 +// PPC64:#define __CHAR16_TYPE__ unsigned short +// PPC64:#define __CHAR32_TYPE__ unsigned int // PPC64:#define __CHAR_BIT__ 8 // PPC64:#define __CHAR_UNSIGNED__ 1 // PPC64:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 @@ -604,6 +678,18 @@ // PPC64:#define __SCHAR_MAX__ 127 // PPC64:#define __SHRT_MAX__ 32767 // PPC64:#define __SIG_ATOMIC_WIDTH__ 32 +// PPC64:#define __SIZEOF_DOUBLE__ 8 +// PPC64:#define __SIZEOF_FLOAT__ 4 +// PPC64:#define __SIZEOF_INT__ 4 +// PPC64:#define __SIZEOF_LONG_DOUBLE__ 8 +// PPC64:#define __SIZEOF_LONG_LONG__ 8 +// PPC64:#define __SIZEOF_LONG__ 8 +// PPC64:#define __SIZEOF_POINTER__ 8 +// PPC64:#define __SIZEOF_PTRDIFF_T__ 8 +// PPC64:#define __SIZEOF_SHORT__ 2 +// PPC64:#define __SIZEOF_SIZE_T__ 8 +// PPC64:#define __SIZEOF_WCHAR_T__ 4 +// PPC64:#define __SIZEOF_WINT_T__ 4 // PPC64:#define __SIZE_TYPE__ long unsigned int // PPC64:#define __SIZE_WIDTH__ 64 // PPC64:#define __UINTMAX_TYPE__ long unsigned int @@ -621,6 +707,8 @@ // PPC:#define _ARCH_PPC 1 // PPC:#define _BIG_ENDIAN 1 // PPC:#define __BIG_ENDIAN__ 1 +// PPC:#define __CHAR16_TYPE__ unsigned short +// PPC:#define __CHAR32_TYPE__ unsigned int // PPC:#define __CHAR_BIT__ 8 // PPC:#define __CHAR_UNSIGNED__ 1 // PPC:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 @@ -689,6 +777,18 @@ // PPC:#define __SCHAR_MAX__ 127 // PPC:#define __SHRT_MAX__ 32767 // PPC:#define __SIG_ATOMIC_WIDTH__ 32 +// PPC:#define __SIZEOF_DOUBLE__ 8 +// PPC:#define __SIZEOF_FLOAT__ 4 +// PPC:#define __SIZEOF_INT__ 4 +// PPC:#define __SIZEOF_LONG_DOUBLE__ 8 +// PPC:#define __SIZEOF_LONG_LONG__ 8 +// PPC:#define __SIZEOF_LONG__ 4 +// PPC:#define __SIZEOF_POINTER__ 4 +// PPC:#define __SIZEOF_PTRDIFF_T__ 4 +// PPC:#define __SIZEOF_SHORT__ 2 +// PPC:#define __SIZEOF_SIZE_T__ 4 +// PPC:#define __SIZEOF_WCHAR_T__ 4 +// PPC:#define __SIZEOF_WINT_T__ 4 // PPC:#define __SIZE_TYPE__ long unsigned int // PPC:#define __SIZE_WIDTH__ 32 // PPC:#define __UINTMAX_TYPE__ long long unsigned int @@ -702,6 +802,8 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-none -fno-signed-char < /dev/null | FileCheck -check-prefix S390X %s // +// S390X:#define __CHAR16_TYPE__ unsigned short +// S390X:#define __CHAR32_TYPE__ unsigned int // S390X:#define __CHAR_BIT__ 8 // S390X:#define __CHAR_UNSIGNED__ 1 // S390X:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 @@ -736,7 +838,7 @@ // S390X:#define __INT16_TYPE__ short // S390X:#define __INT32_TYPE__ int // S390X:#define __INT64_C_SUFFIX__ L -// S390X:#define __INT64_TYPE__ long int +// S390X:#define __INT64_TYPE__ long long int // S390X:#define __INT8_TYPE__ char // S390X:#define __INTMAX_MAX__ 9223372036854775807LL // S390X:#define __INTMAX_TYPE__ long long int @@ -766,6 +868,18 @@ // S390X:#define __SCHAR_MAX__ 127 // S390X:#define __SHRT_MAX__ 32767 // S390X:#define __SIG_ATOMIC_WIDTH__ 32 +// S390X:#define __SIZEOF_DOUBLE__ 8 +// S390X:#define __SIZEOF_FLOAT__ 4 +// S390X:#define __SIZEOF_INT__ 4 +// S390X:#define __SIZEOF_LONG_DOUBLE__ 8 +// S390X:#define __SIZEOF_LONG_LONG__ 8 +// S390X:#define __SIZEOF_LONG__ 8 +// S390X:#define __SIZEOF_POINTER__ 8 +// S390X:#define __SIZEOF_PTRDIFF_T__ 8 +// S390X:#define __SIZEOF_SHORT__ 2 +// S390X:#define __SIZEOF_SIZE_T__ 8 +// S390X:#define __SIZEOF_WCHAR_T__ 4 +// S390X:#define __SIZEOF_WINT_T__ 4 // S390X:#define __SIZE_TYPE__ long unsigned int // S390X:#define __SIZE_WIDTH__ 64 // S390X:#define __UINTMAX_TYPE__ long long unsigned int @@ -780,6 +894,8 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc-none-none < /dev/null | FileCheck -check-prefix SPARC %s // +// SPARC:#define __CHAR16_TYPE__ unsigned short +// SPARC:#define __CHAR32_TYPE__ unsigned int // SPARC:#define __CHAR_BIT__ 8 // SPARC:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // SPARC:#define __DBL_DIG__ 15 @@ -844,6 +960,18 @@ // SPARC:#define __SCHAR_MAX__ 127 // SPARC:#define __SHRT_MAX__ 32767 // SPARC:#define __SIG_ATOMIC_WIDTH__ 32 +// SPARC:#define __SIZEOF_DOUBLE__ 8 +// SPARC:#define __SIZEOF_FLOAT__ 4 +// SPARC:#define __SIZEOF_INT__ 4 +// SPARC:#define __SIZEOF_LONG_DOUBLE__ 8 +// SPARC:#define __SIZEOF_LONG_LONG__ 8 +// SPARC:#define __SIZEOF_LONG__ 4 +// SPARC:#define __SIZEOF_POINTER__ 4 +// SPARC:#define __SIZEOF_PTRDIFF_T__ 4 +// SPARC:#define __SIZEOF_SHORT__ 2 +// SPARC:#define __SIZEOF_SIZE_T__ 4 +// SPARC:#define __SIZEOF_WCHAR_T__ 4 +// SPARC:#define __SIZEOF_WINT_T__ 4 // SPARC:#define __SIZE_TYPE__ long unsigned int // SPARC:#define __SIZE_WIDTH__ 32 // SPARC:#define __UINTMAX_TYPE__ long long unsigned int @@ -861,6 +989,8 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=tce-none-none < /dev/null | FileCheck -check-prefix TCE %s // +// TCE:#define __CHAR16_TYPE__ unsigned short +// TCE:#define __CHAR32_TYPE__ unsigned int // TCE:#define __CHAR_BIT__ 8 // TCE:#define __DBL_DENORM_MIN__ 1.40129846e-45F // TCE:#define __DBL_DIG__ 6 @@ -922,6 +1052,18 @@ // TCE:#define __SCHAR_MAX__ 127 // TCE:#define __SHRT_MAX__ 32767 // TCE:#define __SIG_ATOMIC_WIDTH__ 32 +// TCE:#define __SIZEOF_DOUBLE__ 4 +// TCE:#define __SIZEOF_FLOAT__ 4 +// TCE:#define __SIZEOF_INT__ 4 +// TCE:#define __SIZEOF_LONG_DOUBLE__ 4 +// TCE:#define __SIZEOF_LONG_LONG__ 4 +// TCE:#define __SIZEOF_LONG__ 4 +// TCE:#define __SIZEOF_POINTER__ 4 +// TCE:#define __SIZEOF_PTRDIFF_T__ 4 +// TCE:#define __SIZEOF_SHORT__ 2 +// TCE:#define __SIZEOF_SIZE_T__ 4 +// TCE:#define __SIZEOF_WCHAR_T__ 4 +// TCE:#define __SIZEOF_WINT_T__ 4 // TCE:#define __SIZE_TYPE__ unsigned int // TCE:#define __SIZE_WIDTH__ 32 // TCE:#define __TCE_V1__ 1 @@ -940,6 +1082,8 @@ // RUN: %clang_cc1 -E -dM -ffreestanding -triple=x86_64-none-none < /dev/null | FileCheck -check-prefix X86_64 %s // // X86_64:#define _LP64 1 +// X86_64:#define __CHAR16_TYPE__ unsigned short +// X86_64:#define __CHAR32_TYPE__ unsigned int // X86_64:#define __CHAR_BIT__ 8 // X86_64:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // X86_64:#define __DBL_DIG__ 15 @@ -1008,6 +1152,18 @@ // X86_64:#define __SCHAR_MAX__ 127 // X86_64:#define __SHRT_MAX__ 32767 // X86_64:#define __SIG_ATOMIC_WIDTH__ 32 +// X86_64:#define __SIZEOF_DOUBLE__ 8 +// X86_64:#define __SIZEOF_FLOAT__ 4 +// X86_64:#define __SIZEOF_INT__ 4 +// X86_64:#define __SIZEOF_LONG_DOUBLE__ 16 +// X86_64:#define __SIZEOF_LONG_LONG__ 8 +// X86_64:#define __SIZEOF_LONG__ 8 +// X86_64:#define __SIZEOF_POINTER__ 8 +// X86_64:#define __SIZEOF_PTRDIFF_T__ 8 +// X86_64:#define __SIZEOF_SHORT__ 2 +// X86_64:#define __SIZEOF_SIZE_T__ 8 +// X86_64:#define __SIZEOF_WCHAR_T__ 4 +// X86_64:#define __SIZEOF_WINT_T__ 4 // X86_64:#define __SIZE_TYPE__ long unsigned int // X86_64:#define __SIZE_WIDTH__ 64 // X86_64:#define __SSE2_MATH__ 1 @@ -1032,3 +1188,7 @@ // RUN: %clang_cc1 -x c++ -triple i686-pc-linux-gnu -E -dM < /dev/null | FileCheck -check-prefix GNUSOURCE %s // GNUSOURCE:#define _GNU_SOURCE 1 // +// RUN: %clang_cc1 -x c++ -std=c++98 -fno-rtti -E -dM < /dev/null | FileCheck -check-prefix NORTTI %s +// NORTTI: __GXX_ABI_VERSION +// NORTTI-NOT:#define __GXX_RTTI +// NORTTI: __STDC__ diff --git a/test/Preprocessor/print_line_track.c b/test/Preprocessor/print_line_track.c index c87fe00f407e0..fb2ccf270e242 100644 --- a/test/Preprocessor/print_line_track.c +++ b/test/Preprocessor/print_line_track.c @@ -3,8 +3,8 @@ * RUN: %clang_cc1 -E -P %s | grep 'a 3' * RUN: %clang_cc1 -E -P %s | grep 'b 16' * RUN: %clang_cc1 -E %s | not grep '# 0 ' - * PR1848 - * PR3437 + * RUN: %clang_cc1 -E -P %s | count 4 + * PR1848 PR3437 PR7360 */ #define t(x) x diff --git a/test/Preprocessor/stdint.c b/test/Preprocessor/stdint.c index e701494c20b60..f8bb921a68cb7 100644 --- a/test/Preprocessor/stdint.c +++ b/test/Preprocessor/stdint.c @@ -31,8 +31,8 @@ // ARM:typedef int32_t intptr_t; // ARM:typedef uint32_t uintptr_t; // -// ARM:typedef int64_t intmax_t; -// ARM:typedef uint64_t uintmax_t; +// ARM:typedef long long int intmax_t; +// ARM:typedef long long unsigned int uintmax_t; // // ARM:INT8_MAX_ 127 // ARM:INT8_MIN_ (-127 -1) @@ -139,8 +139,8 @@ // BFIN:typedef int32_t intptr_t; // BFIN:typedef uint32_t uintptr_t; // -// BFIN:typedef int64_t intmax_t; -// BFIN:typedef uint64_t uintmax_t; +// BFIN:typedef long long int intmax_t; +// BFIN:typedef long long unsigned int uintmax_t; // // BFIN:INT8_MAX_ 127 // BFIN:INT8_MIN_ (-127 -1) @@ -247,8 +247,8 @@ // I386:typedef int32_t intptr_t; // I386:typedef uint32_t uintptr_t; // -// I386:typedef int64_t intmax_t; -// I386:typedef uint64_t uintmax_t; +// I386:typedef long long int intmax_t; +// I386:typedef long long unsigned int uintmax_t; // // I386:INT8_MAX_ 127 // I386:INT8_MIN_ (-127 -1) @@ -347,8 +347,8 @@ // MSP430:typedef int16_t intptr_t; // MSP430:typedef uint16_t uintptr_t; // -// MSP430:typedef int32_t intmax_t; -// MSP430:typedef uint32_t uintmax_t; +// MSP430:typedef long int intmax_t; +// MSP430:typedef long unsigned int uintmax_t; // // MSP430:INT8_MAX_ 127 // MSP430:INT8_MIN_ (-127 -1) @@ -447,8 +447,8 @@ // PIC16:typedef int16_t intptr_t; // PIC16:typedef uint16_t uintptr_t; // -// PIC16:typedef int32_t intmax_t; -// PIC16:typedef uint32_t uintmax_t; +// PIC16:typedef long int intmax_t; +// PIC16:typedef long unsigned int uintmax_t; // // PIC16:INT8_MAX_ 127 // PIC16:INT8_MIN_ (-127 -1) @@ -554,8 +554,8 @@ // PPC64:typedef int64_t intptr_t; // PPC64:typedef uint64_t uintptr_t; // -// PPC64:typedef int64_t intmax_t; -// PPC64:typedef uint64_t uintmax_t; +// PPC64:typedef long int intmax_t; +// PPC64:typedef long unsigned int uintmax_t; // // PPC64:INT8_MAX_ 127 // PPC64:INT8_MIN_ (-127 -1) @@ -662,8 +662,8 @@ // PPC:typedef int32_t intptr_t; // PPC:typedef uint32_t uintptr_t; // -// PPC:typedef int64_t intmax_t; -// PPC:typedef uint64_t uintmax_t; +// PPC:typedef long long int intmax_t; +// PPC:typedef long long unsigned int uintmax_t; // // PPC:INT8_MAX_ 127 // PPC:INT8_MIN_ (-127 -1) @@ -738,8 +738,8 @@ // // RUN: %clang_cc1 -E -ffreestanding -triple=s390x-none-none %s | FileCheck -check-prefix S390X %s // -// S390X:typedef signed long int int64_t; -// S390X:typedef unsigned long int uint64_t; +// S390X:typedef signed long long int int64_t; +// S390X:typedef unsigned long long int uint64_t; // S390X:typedef int64_t int_least64_t; // S390X:typedef uint64_t uint_least64_t; // S390X:typedef int64_t int_fast64_t; @@ -769,8 +769,8 @@ // S390X:typedef int64_t intptr_t; // S390X:typedef uint64_t uintptr_t; // -// S390X:typedef int64_t intmax_t; -// S390X:typedef uint64_t uintmax_t; +// S390X:typedef long long int intmax_t; +// S390X:typedef long long unsigned int uintmax_t; // // S390X:INT8_MAX_ 127 // S390X:INT8_MIN_ (-127 -1) @@ -803,23 +803,23 @@ // S390X:UINT_FAST32_MAX_ 4294967295U // // S390X:INT64_MAX_ 9223372036854775807L -// S390X:INT64_MIN_ (-9223372036854775807L -1) +// S390X:INT64_MIN_ (-9223372036854775807LL -1) // S390X:UINT64_MAX_ 18446744073709551615UL -// S390X:INT_LEAST64_MIN_ (-9223372036854775807L -1) +// S390X:INT_LEAST64_MIN_ (-9223372036854775807LL -1) // S390X:INT_LEAST64_MAX_ 9223372036854775807L // S390X:UINT_LEAST64_MAX_ 18446744073709551615UL -// S390X:INT_FAST64_MIN_ (-9223372036854775807L -1) +// S390X:INT_FAST64_MIN_ (-9223372036854775807LL -1) // S390X:INT_FAST64_MAX_ 9223372036854775807L // S390X:UINT_FAST64_MAX_ 18446744073709551615UL // -// S390X:INTPTR_MIN_ (-9223372036854775807L -1) +// S390X:INTPTR_MIN_ (-9223372036854775807LL -1) // S390X:INTPTR_MAX_ 9223372036854775807L // S390X:UINTPTR_MAX_ 18446744073709551615UL -// S390X:PTRDIFF_MIN_ (-9223372036854775807L -1) +// S390X:PTRDIFF_MIN_ (-9223372036854775807LL -1) // S390X:PTRDIFF_MAX_ 9223372036854775807L // S390X:SIZE_MAX_ 18446744073709551615UL // -// S390X:INTMAX_MIN_ (-9223372036854775807L -1) +// S390X:INTMAX_MIN_ (-9223372036854775807LL -1) // S390X:INTMAX_MAX_ 9223372036854775807L // S390X:UINTMAX_MAX_ 18446744073709551615UL // @@ -876,8 +876,8 @@ // SPARC:typedef int32_t intptr_t; // SPARC:typedef uint32_t uintptr_t; // -// SPARC:typedef int64_t intmax_t; -// SPARC:typedef uint64_t uintmax_t; +// SPARC:typedef long long int intmax_t; +// SPARC:typedef long long unsigned int uintmax_t; // // SPARC:INT8_MAX_ 127 // SPARC:INT8_MIN_ (-127 -1) @@ -976,8 +976,8 @@ // TCE:typedef int32_t intptr_t; // TCE:typedef uint32_t uintptr_t; // -// TCE:typedef int32_t intmax_t; -// TCE:typedef uint32_t uintmax_t; +// TCE:typedef long int intmax_t; +// TCE:typedef long unsigned int uintmax_t; // // TCE:INT8_MAX_ 127 // TCE:INT8_MIN_ (-127 -1) @@ -1084,8 +1084,8 @@ // X86_64:typedef int64_t intptr_t; // X86_64:typedef uint64_t uintptr_t; // -// X86_64:typedef int64_t intmax_t; -// X86_64:typedef uint64_t uintmax_t; +// X86_64:typedef long int intmax_t; +// X86_64:typedef long unsigned int uintmax_t; // // X86_64:INT8_MAX_ 127 // X86_64:INT8_MIN_ (-127 -1) @@ -1165,11 +1165,11 @@ // the identifiers used in the operations (int, uint, _t, INT, UINT, _MIN, // _MAX, and _C(v)) are themselves macros. // -// RUN: %clang_cc1 -E -ffreestanding -Dint=a -Duint=b -D_t=c -DINT=d -DUINT=e -D_MIN=f -D_MAX=g '-D_C(v)=h' -triple=i386-none-none %s | FileCheck -check-prefix JOIN %s +// RUN: %clang_cc1 -E -ffreestanding -U__UINTMAX_TYPE__ -U__INTMAX_TYPE__ -Dint=a -Duint=b -D_t=c -DINT=d -DUINT=e -D_MIN=f -D_MAX=g '-D_C(v)=h' -triple=i386-none-none %s | FileCheck -check-prefix JOIN %s // JOIN:typedef int32_t intptr_t; // JOIN:typedef uint32_t uintptr_t; -// JOIN:typedef int64_t intmax_t; -// JOIN:typedef uint64_t uintmax_t; +// JOIN:typedef __INTMAX_TYPE__ intmax_t; +// JOIN:typedef __UINTMAX_TYPE__ uintmax_t; // JOIN:INTPTR_MIN_ (-2147483647 -1) // JOIN:INTPTR_MAX_ 2147483647 // JOIN:UINTPTR_MAX_ 4294967295U diff --git a/test/Rewriter/dllimport-typedef.c b/test/Rewriter/dllimport-typedef.c index b86fa4a1c7375..441f498668174 100644 --- a/test/Rewriter/dllimport-typedef.c +++ b/test/Rewriter/dllimport-typedef.c @@ -9,9 +9,9 @@ typedef __declspec(dllimport) int CB(void); // diagnostics we expect. void bar() { return 1; } -// CHECK-NEG: warning: void function 'bar' should not return a value -// CHECK-NEG: 1 warning generated +// CHECK-NEG: error: void function 'bar' should not return a value +// CHECK-NEG: 1 error generated // CHECK-POS: warning: 'dllimport' attribute only applies to variable and function type -// CHECK-POS: warning: void function 'bar' should not return a value -// CHECK-POS: 2 warnings generated +// CHECK-POS: error: void function 'bar' should not return a value +// CHECK-POS: 1 warning and 1 error generated diff --git a/test/Rewriter/missing-dllimport.c b/test/Rewriter/missing-dllimport.c index c060379db0fd9..1dfc04c5b80c3 100644 --- a/test/Rewriter/missing-dllimport.c +++ b/test/Rewriter/missing-dllimport.c @@ -11,9 +11,9 @@ inline int __cdecl foo() { return 0; } // diagnostics we expect. void bar() { return 1; } -// CHECK-NEG: warning: void function 'bar' should not return a value -// CHECK-NEG: 1 warning generated +// CHECK-NEG: error: void function 'bar' should not return a value +// CHECK-NEG: 1 error generated // CHECK-POS: warning: 'foo' redeclared without dllimport attribute: previous dllimport ignored -// CHECK-POS: warning: void function 'bar' should not return a value -// CHECK-POS: 2 warnings generated +// CHECK-POS: error: void function 'bar' should not return a value +// CHECK-POS: 1 warning and 1 error generated diff --git a/test/Rewriter/rewrite-elaborated-type.mm b/test/Rewriter/rewrite-elaborated-type.mm new file mode 100644 index 0000000000000..9867b4d6de1ee --- /dev/null +++ b/test/Rewriter/rewrite-elaborated-type.mm @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D_Bool=bool -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 8143056 + +typedef struct objc_class *Class; +typedef unsigned NSPointerFunctionsOptions; +extern "C" id NSClassFromObject(id object); +void *sel_registerName(const char *); + +struct NSSlice { + int i1; +}; + +@interface NSConcretePointerFunctions { + @public + struct NSSlice slice; +} +- (bool)initializeSlice:(struct NSSlice *)slicep withOptions:(NSPointerFunctionsOptions)options; +@end + +@implementation NSConcretePointerFunctions +- (id)initWithOptions:(NSPointerFunctionsOptions)options { + if (![NSClassFromObject(self) initializeSlice:&slice withOptions:options]) + return 0; + return self; + } +- (bool)initializeSlice:(struct NSSlice *)slicep withOptions:(NSPointerFunctionsOptions)options { + return 0; + } +@end + +@implementation I1 ++ (struct s1 *) f0 { + return 0; +} +@end diff --git a/test/Sema/address_spaces.c b/test/Sema/address_spaces.c index 6258114578db3..23c1405011a3d 100644 --- a/test/Sema/address_spaces.c +++ b/test/Sema/address_spaces.c @@ -36,7 +36,7 @@ struct _st { // rdar://6774906 __attribute__((address_space(256))) void * * const base = 0; void * get_0(void) { - return base[0]; // expected-error {{illegal implicit cast between two pointers with different address spaces}} \ + return base[0]; // expected-error {{illegal implicit conversion between two pointers with different address spaces}} \ expected-warning {{returning 'void __attribute__((address_space(256))) *' from a function with result type 'void *' discards qualifiers}} } diff --git a/test/Sema/align-x86-64.c b/test/Sema/align-x86-64.c new file mode 100644 index 0000000000000..6dcf5714b0053 --- /dev/null +++ b/test/Sema/align-x86-64.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify %s + +// PR5599 + +void frob(void *); + +void foo(void) { + float x[4]; + char y[__alignof__(x) == 16 ? 1 : -1]; + frob(y); +} diff --git a/test/Sema/attr-deprecated.c b/test/Sema/attr-deprecated.c index e723255c0cfa6..e7c997f3ee23d 100644 --- a/test/Sema/attr-deprecated.c +++ b/test/Sema/attr-deprecated.c @@ -4,8 +4,6 @@ int f() __attribute__((deprecated)); void g() __attribute__((deprecated)); void g(); -void z() __attribute__((bogusattr)); // expected-warning {{'bogusattr' attribute ignored}} - extern int var __attribute__((deprecated)); int a() { @@ -45,7 +43,7 @@ typedef struct foo foo_dep __attribute__((deprecated)); foo_dep *test2; // expected-warning {{'foo_dep' is deprecated}} struct bar_dep __attribute__((deprecated, - invalid_attribute)); // expected-warning {{'invalid_attribute' attribute ignored}} + invalid_attribute)); // expected-warning {{unknown attribute 'invalid_attribute' ignored}} struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}} diff --git a/test/Sema/attr-regparm.c b/test/Sema/attr-regparm.c index 045a41396e3f2..4049e0e8a13fd 100644 --- a/test/Sema/attr-regparm.c +++ b/test/Sema/attr-regparm.c @@ -1,7 +1,11 @@ // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s -__attribute((regparm(2))) int x(void); -__attribute((regparm(1.0))) int x(void); // expected-error{{'regparm' attribute requires integer constant}} -__attribute((regparm(-1))) int x(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}} -__attribute((regparm(5))) int x(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}} -__attribute((regparm(5,3))) int x(void); // expected-error{{attribute requires 1 argument(s)}} +__attribute((regparm(2))) int x0(void); +__attribute((regparm(1.0))) int x1(void); // expected-error{{'regparm' attribute requires integer constant}} +__attribute((regparm(-1))) int x2(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}} +__attribute((regparm(5))) int x3(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}} +__attribute((regparm(5,3))) int x4(void); // expected-error{{attribute requires 1 argument(s)}} + +void __attribute__((regparm(3))) x5(int); +void x5(int); // expected-note{{previous declaration is here}} +void __attribute__((regparm(2))) x5(int); // expected-error{{function declared with with regparm(2) attribute was previously declared with the regparm(3) attribute}} diff --git a/test/Sema/attr-unknown.c b/test/Sema/attr-unknown.c new file mode 100644 index 0000000000000..bec2e29585d94 --- /dev/null +++ b/test/Sema/attr-unknown.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wunknown-attributes %s + +int x __attribute__((foobar)); // expected-warning {{unknown attribute 'foobar' ignored}} +void z() __attribute__((bogusattr)); // expected-warning {{unknown attribute 'bogusattr' ignored}} diff --git a/test/Sema/bitfield-layout.c b/test/Sema/bitfield-layout.c index edc44bdefa08e..2655fc70cd4c4 100644 --- a/test/Sema/bitfield-layout.c +++ b/test/Sema/bitfield-layout.c @@ -30,3 +30,13 @@ CHECK_ALIGN(struct, e, 1) struct f {__attribute((aligned(8))) int x : 30, y : 30, z : 30;}; CHECK_SIZE(struct, f, 24) CHECK_ALIGN(struct, f, 8) + +// Large structure (overflows i32, in bits). +struct s0 { + char a[0x32100000]; + int x:30, y:30; +}; + +CHECK_SIZE(struct, s0, 0x32100008) +CHECK_ALIGN(struct, s0, 4) + diff --git a/test/Sema/block-call.c b/test/Sema/block-call.c index 318bc6b2a3b11..28e6c68a80069 100644 --- a/test/Sema/block-call.c +++ b/test/Sema/block-call.c @@ -13,9 +13,11 @@ int main() { int (^IFP) () = PFR; // OK - const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int const (^)()' with an expression of type 'int (^)()'}} + const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int const (^)()' with an expression of type 'int (^)()'}} \ + // expected-warning{{type qualifier on return type has no effect}} + + const int (^CICC) () = CIC; // expected-warning{{type qualifier on return type has no effect}} - const int (^CICC) () = CIC; int * const (^IPCC) () = 0; diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c index 10b3b8480cc96..33fd183be069e 100644 --- a/test/Sema/block-return.c +++ b/test/Sema/block-return.c @@ -109,8 +109,11 @@ void foo6() { void foo7() { - const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'int const (^)(void)' with an expression of type 'int (^)(void)'}} - const int (^CC) (void) = ^const int{ 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 const (^)(void)' with an expression of type 'int (^)(void)'}} \ + // expected-warning{{type qualifier on return type has no effect}} + + const int (^CC) (void) = ^const int{ const int i = 1; return i; }; // expected-warning{{type qualifier on return type has no effect}} + int i; int (^FF) (void) = ^{ return i; }; // OK diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c index 6fa563b31137b..c0a2131868e48 100644 --- a/test/Sema/builtins.c +++ b/test/Sema/builtins.c @@ -40,7 +40,10 @@ void test9(short v) { old = __sync_fetch_and_add(); // expected-error {{too few arguments to function call}} old = __sync_fetch_and_add(&old); // expected-error {{too few arguments to function call}} - old = __sync_fetch_and_add((int**)0, 42i); // expected-warning {{imaginary constants are an extension}} + old = __sync_fetch_and_add((unsigned*)0, 42i); // expected-warning {{imaginary constants are an extension}} + + // PR7600: Pointers are implicitly casted to integers and back. + void *old_ptr = __sync_val_compare_and_swap((void**)0, 0, 0); } diff --git a/test/Sema/compare.c b/test/Sema/compare.c index f997dc1a73bf4..b2c35633953da 100644 --- a/test/Sema/compare.c +++ b/test/Sema/compare.c @@ -3,7 +3,7 @@ int test(char *C) { // nothing here should warn. return C != ((void*)0); return C != (void*)0; - return C != 0; + return C != 0; return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}} } @@ -218,7 +218,7 @@ int pointers(int *a) { int function_pointers(int (*a)(int), int (*b)(int), void (*c)(int)) { return a > b; // expected-warning {{ordered comparison of function pointers}} - return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}} + return function_pointers > function_pointers; // expected-warning {{self-comparison always evaluates to false}} expected-warning{{ordered comparison of function pointers}} return a > c; // expected-warning {{comparison of distinct pointer types}} return a == (void *) 0; return a == (void *) 1; // expected-warning {{equality comparison between function pointer and void pointer}} @@ -229,6 +229,7 @@ int void_pointers(void* foo) { return foo == (void*) 1; } + int test1(int i) { enum en { zero }; return i > zero; diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index 9c537250a93a0..c132b347d7b2d 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -74,5 +74,5 @@ const _Bool constbool = 0; EVAL_EXPR(35, constbool) EVAL_EXPR(36, constbool) -EVAL_EXPR(37, (1,2.0) == 2.0) +EVAL_EXPR(37, (1,2.0) == 2.0) // expected-warning {{expression result unused}} EVAL_EXPR(38, __builtin_expect(1,1) == 1) diff --git a/test/Sema/conversion-64-32.c b/test/Sema/conversion-64-32.c index 104399641d280..aa7282962f8e6 100644 --- a/test/Sema/conversion-64-32.c +++ b/test/Sema/conversion-64-32.c @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wshorten-64-to-32 -triple x86_64-apple-darwin %s int test0(long v) { - return v; // expected-warning {{implicit cast loses integer precision}} + return v; // expected-warning {{implicit conversion loses integer precision}} } diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index 5b09ec6d9708a..5fbd64de5bb41 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -6,17 +6,17 @@ void test0(char c, short s, int i, long l, long long ll) { c = c; - c = s; // expected-warning {{implicit cast loses integer precision}} - c = i; // expected-warning {{implicit cast loses integer precision}} - c = l; // expected-warning {{implicit cast loses integer precision}} + c = s; // expected-warning {{implicit conversion loses integer precision}} + c = i; // expected-warning {{implicit conversion loses integer precision}} + c = l; // expected-warning {{implicit conversion loses integer precision}} s = c; s = s; - s = i; // expected-warning {{implicit cast loses integer precision}} - s = l; // expected-warning {{implicit cast loses integer precision}} + s = i; // expected-warning {{implicit conversion loses integer precision}} + s = l; // expected-warning {{implicit conversion loses integer precision}} i = c; i = s; i = i; - i = l; // expected-warning {{implicit cast loses integer precision}} + i = l; // expected-warning {{implicit conversion loses integer precision}} l = c; l = s; l = i; @@ -40,17 +40,17 @@ void test0(char c, short s, int i, long l, long long ll) { l = (long) 0; c = (char) BIG; - c = (short) BIG; // expected-warning {{implicit cast loses integer precision}} - c = (int) BIG; // expected-warning {{implicit cast loses integer precision}} - c = (long) BIG; // expected-warning {{implicit cast loses integer precision}} + c = (short) BIG; // expected-warning {{implicit conversion loses integer precision}} + c = (int) BIG; // expected-warning {{implicit conversion loses integer precision}} + c = (long) BIG; // expected-warning {{implicit conversion loses integer precision}} s = (char) BIG; s = (short) BIG; - s = (int) BIG; // expected-warning {{implicit cast loses integer precision}} - s = (long) BIG; // expected-warning {{implicit cast loses integer precision}} + s = (int) BIG; // expected-warning {{implicit conversion loses integer precision}} + s = (long) BIG; // expected-warning {{implicit conversion loses integer precision}} i = (char) BIG; i = (short) BIG; i = (int) BIG; - i = (long) BIG; // expected-warning {{implicit cast loses integer precision}} + i = (long) BIG; // expected-warning {{implicit conversion loses integer precision}} l = (char) BIG; l = (short) BIG; l = (int) BIG; @@ -58,39 +58,39 @@ void test0(char c, short s, int i, long l, long long ll) { } char test1(long long ll) { - return (long long) ll; // expected-warning {{implicit cast loses integer precision}} - return (long) ll; // expected-warning {{implicit cast loses integer precision}} - return (int) ll; // expected-warning {{implicit cast loses integer precision}} - return (short) ll; // expected-warning {{implicit cast loses integer precision}} + return (long long) ll; // expected-warning {{implicit conversion loses integer precision}} + return (long) ll; // expected-warning {{implicit conversion loses integer precision}} + return (int) ll; // expected-warning {{implicit conversion loses integer precision}} + return (short) ll; // expected-warning {{implicit conversion loses integer precision}} return (char) ll; - return (long long) BIG; // expected-warning {{implicit cast loses integer precision}} - return (long) BIG; // expected-warning {{implicit cast loses integer precision}} - return (int) BIG; // expected-warning {{implicit cast loses integer precision}} - return (short) BIG; // expected-warning {{implicit cast loses integer precision}} + return (long long) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (long) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (int) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (short) BIG; // expected-warning {{implicit conversion loses integer precision}} return (char) BIG; } short test2(long long ll) { - return (long long) ll; // expected-warning {{implicit cast loses integer precision}} - return (long) ll; // expected-warning {{implicit cast loses integer precision}} - return (int) ll; // expected-warning {{implicit cast loses integer precision}} + return (long long) ll; // expected-warning {{implicit conversion loses integer precision}} + return (long) ll; // expected-warning {{implicit conversion loses integer precision}} + return (int) ll; // expected-warning {{implicit conversion loses integer precision}} return (short) ll; return (char) ll; - return (long long) BIG; // expected-warning {{implicit cast loses integer precision}} - return (long) BIG; // expected-warning {{implicit cast loses integer precision}} - return (int) BIG; // expected-warning {{implicit cast loses integer precision}} + return (long long) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (long) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (int) BIG; // expected-warning {{implicit conversion loses integer precision}} return (short) BIG; return (char) BIG; } int test3(long long ll) { - return (long long) ll; // expected-warning {{implicit cast loses integer precision}} - return (long) ll; // expected-warning {{implicit cast loses integer precision}} + return (long long) ll; // expected-warning {{implicit conversion loses integer precision}} + return (long) ll; // expected-warning {{implicit conversion loses integer precision}} return (int) ll; return (short) ll; return (char) ll; - return (long long) BIG; // expected-warning {{implicit cast loses integer precision}} - return (long) BIG; // expected-warning {{implicit cast loses integer precision}} + return (long long) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (long) BIG; // expected-warning {{implicit conversion loses integer precision}} return (int) BIG; return (short) BIG; return (char) BIG; @@ -143,7 +143,7 @@ void test6(char v) { } void test7(short v) { - takes_char(v); // expected-warning {{implicit cast loses integer precision}} + takes_char(v); // expected-warning {{implicit conversion loses integer precision}} takes_short(v); takes_int(v); takes_long(v); @@ -154,8 +154,8 @@ void test7(short v) { } void test8(int v) { - takes_char(v); // expected-warning {{implicit cast loses integer precision}} - takes_short(v); // expected-warning {{implicit cast loses integer precision}} + takes_char(v); // expected-warning {{implicit conversion loses integer precision}} + takes_short(v); // expected-warning {{implicit conversion loses integer precision}} takes_int(v); takes_long(v); takes_longlong(v); @@ -165,9 +165,9 @@ void test8(int v) { } void test9(long v) { - takes_char(v); // expected-warning {{implicit cast loses integer precision}} - takes_short(v); // expected-warning {{implicit cast loses integer precision}} - takes_int(v); // expected-warning {{implicit cast loses integer precision}} + takes_char(v); // expected-warning {{implicit conversion loses integer precision}} + takes_short(v); // expected-warning {{implicit conversion loses integer precision}} + takes_int(v); // expected-warning {{implicit conversion loses integer precision}} takes_long(v); takes_longlong(v); takes_float(v); @@ -176,9 +176,9 @@ void test9(long v) { } void test10(long long v) { - takes_char(v); // expected-warning {{implicit cast loses integer precision}} - takes_short(v); // expected-warning {{implicit cast loses integer precision}} - takes_int(v); // expected-warning {{implicit cast loses integer precision}} + takes_char(v); // expected-warning {{implicit conversion loses integer precision}} + takes_short(v); // expected-warning {{implicit conversion loses integer precision}} + takes_int(v); // expected-warning {{implicit conversion loses integer precision}} takes_long(v); takes_longlong(v); takes_float(v); @@ -187,35 +187,35 @@ void test10(long long v) { } void test11(float v) { - takes_char(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_short(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_int(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_long(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_longlong(v); // expected-warning {{implicit cast turns floating-point number into integer}} + takes_char(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_short(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_int(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_long(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_longlong(v); // expected-warning {{implicit conversion turns floating-point number into integer}} takes_float(v); takes_double(v); takes_longdouble(v); } void test12(double v) { - takes_char(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_short(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_int(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_long(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_longlong(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_float(v); // expected-warning {{implicit cast loses floating-point precision}} + takes_char(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_short(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_int(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_long(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_longlong(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_float(v); // expected-warning {{implicit conversion loses floating-point precision}} takes_double(v); takes_longdouble(v); } void test13(long double v) { - takes_char(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_short(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_int(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_long(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_longlong(v); // expected-warning {{implicit cast turns floating-point number into integer}} - takes_float(v); // expected-warning {{implicit cast loses floating-point precision}} - takes_double(v); // expected-warning {{implicit cast loses floating-point precision}} + takes_char(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_short(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_int(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_long(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_longlong(v); // expected-warning {{implicit conversion turns floating-point number into integer}} + takes_float(v); // expected-warning {{implicit conversion loses floating-point precision}} + takes_double(v); // expected-warning {{implicit conversion loses floating-point precision}} takes_longdouble(v); } @@ -229,13 +229,13 @@ void test14(long l) { void test15(char c) { c = c + 1 + c * 2; - c = (short) c + 1 + c * 2; // expected-warning {{implicit cast loses integer precision}} + c = (short) c + 1 + c * 2; // expected-warning {{implicit conversion loses integer precision}} } // PR 5422 extern void *test16_external; void test16(void) { - int a = (unsigned long) &test16_external; // expected-warning {{implicit cast loses integer precision}} + int a = (unsigned long) &test16_external; // expected-warning {{implicit conversion loses integer precision}} } // PR 5938 @@ -249,7 +249,7 @@ void test17() { unsigned int x; x = U.a; x = U.b; - x = U.c; // expected-warning {{implicit cast loses integer precision}} + x = U.c; // expected-warning {{implicit conversion loses integer precision}} } // PR 5939 @@ -277,7 +277,7 @@ unsigned char test19(unsigned long u64) { // <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'}} + char s = LONG_MAX; // expected-warning {{implicit conversion loses integer precision: 'long' to 'char'}} } // <rdar://problem/7676608>: assertion for compound operators with non-integral RHS @@ -291,9 +291,9 @@ void test_7676608(void) { // <rdar://problem/7904686> void test_7904686(void) { const int i = -1; - unsigned u1 = i; // expected-warning {{implicit cast changes signedness}} - u1 = i; // expected-warning {{implicit cast changes signedness}} + unsigned u1 = i; // expected-warning {{implicit conversion changes signedness}} + u1 = i; // expected-warning {{implicit conversion changes signedness}} - unsigned u2 = -1; // expected-warning {{implicit cast changes signedness}} - u2 = -1; // expected-warning {{implicit cast changes signedness}} + unsigned u2 = -1; // expected-warning {{implicit conversion changes signedness}} + u2 = -1; // expected-warning {{implicit conversion changes signedness}} } diff --git a/test/Sema/enum-packed.c b/test/Sema/enum-packed.c new file mode 100644 index 0000000000000..0eb6c14dbe85a --- /dev/null +++ b/test/Sema/enum-packed.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR7477 +enum __attribute__((packed)) E { + Ea, Eb, Ec, Ed +}; + +void test_E(enum E e) { + switch (e) { + case Ea: + case Eb: + case Ec: + case Ed: + break; + } +} diff --git a/test/Sema/enum.c b/test/Sema/enum.c index ba4e56b907a72..057015011e8f6 100644 --- a/test/Sema/enum.c +++ b/test/Sema/enum.c @@ -51,7 +51,7 @@ void test4() { } // PR2416 -enum someenum {}; // expected-warning {{use of empty enum extension}} +enum someenum {}; // expected-error {{use of empty enum}} // <rdar://problem/6093889> enum e0 { // expected-note {{previous definition is here}} diff --git a/test/Sema/expr-comma-c89.c b/test/Sema/expr-comma-c89.c index d0883ba202f9b..dc427028d0d1b 100644 --- a/test/Sema/expr-comma-c89.c +++ b/test/Sema/expr-comma-c89.c @@ -11,7 +11,7 @@ int B[sizeof((a.c)) == 17 ? 1 : -1]; // comma does array/function promotion in c99. -int X[sizeof(0, (foo().c)) == sizeof(char*) ? 1 : -1]; -int Y[sizeof(0, (a,b).c) == sizeof(char*) ? 1 : -1]; -int Z[sizeof(0, (a=b).c) == sizeof(char*) ? 1 : -1]; +int X[sizeof(0, (foo().c)) == sizeof(char*) ? 1 : -1]; // expected-warning {{expression result unused}} +int Y[sizeof(0, (a,b).c) == sizeof(char*) ? 1 : -1]; // expected-warning {{expression result unused}} expected-warning {{expression result unused}} +int Z[sizeof(0, (a=b).c) == sizeof(char*) ? 1 : -1]; // expected-warning {{expression result unused}} diff --git a/test/Sema/expr-comma.c b/test/Sema/expr-comma.c index d3e4020af637f..b004fc1ba3e29 100644 --- a/test/Sema/expr-comma.c +++ b/test/Sema/expr-comma.c @@ -11,7 +11,7 @@ int B[sizeof((a.c)) == 17 ? 1 : -1]; // comma does not promote array/function in c90 unless they are lvalues. -int W[sizeof(0, a.c) == sizeof(char*) ? 1 : -1]; -int X[sizeof(0, (foo().c)) == 17 ? 1 : -1]; -int Y[sizeof(0, (a,b).c) == 17 ? 1 : -1]; -int Z[sizeof(0, (a=b).c) == 17 ? 1 : -1]; +int W[sizeof(0, a.c) == sizeof(char*) ? 1 : -1]; // expected-warning {{expression result unused}} +int X[sizeof(0, (foo().c)) == 17 ? 1 : -1]; // expected-warning {{expression result unused}} +int Y[sizeof(0, (a,b).c) == 17 ? 1 : -1]; // expected-warning {{expression result unused}} // expected-warning {{expression result unused}} +int Z[sizeof(0, (a=b).c) == 17 ? 1 : -1]; // expected-warning {{expression result unused}} diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c index dbb6e80aa6d57..b22b5220f2859 100644 --- a/test/Sema/exprs.c +++ b/test/Sema/exprs.c @@ -134,3 +134,11 @@ void test18(int b) { test18_a(b, b); // expected-error {{too many arguments to function call, expected 1, have 2}} test18_a(); // expected-error {{too few arguments to function call, expected 1, have 0}} } + +// PR7569 +void test19() { + *(int*)0 = 0; // expected-warning {{indirection of non-volatile null pointer}} \ + // expected-note {{consider using __builtin_trap}} + *(volatile int*)0 = 0; // Ok. +} + diff --git a/test/Sema/ext_vector_casts.c b/test/Sema/ext_vector_casts.c index d2976238c0e5e..76819534dbb35 100644 --- a/test/Sema/ext_vector_casts.c +++ b/test/Sema/ext_vector_casts.c @@ -43,3 +43,10 @@ static void test() { ivec4 |= ivec4; ivec4 += ptr; // expected-error {{can't convert between vector values of different size ('int4' and 'int *')}} } + +typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-error{{invalid vector element type 'float2'}} + +void inc(float2 f2) { + f2++; // expected-error{{cannot increment value of type 'float2'}} + __real f2; // expected-error{{invalid type 'float2' to __real operator}} +} diff --git a/test/Sema/ext_vector_comparisons.c b/test/Sema/ext_vector_comparisons.c new file mode 100644 index 0000000000000..605ba6c55e333 --- /dev/null +++ b/test/Sema/ext_vector_comparisons.c @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unreachable-code %s + +typedef __attribute__(( ext_vector_type(4) )) int int4; + +static int4 test1() { + int4 vec, rv; + + // comparisons to self... + return vec == vec; // expected-warning{{self-comparison always evaluates to a constant}} + return vec != vec; // expected-warning{{self-comparison always evaluates to a constant}} + return vec < vec; // expected-warning{{self-comparison always evaluates to a constant}} + return vec <= vec; // expected-warning{{self-comparison always evaluates to a constant}} + return vec > vec; // expected-warning{{self-comparison always evaluates to a constant}} + return vec >= vec; // expected-warning{{self-comparison always evaluates to a constant}} +} + + +typedef __attribute__(( ext_vector_type(4) )) float float4; + +static int4 test2() { + float4 vec, rv; + + // comparisons to self. no warning, they're floats + return vec == vec; // no-warning + return vec != vec; // no-warning + return vec < vec; // no-warning + return vec <= vec; // no-warning + return vec > vec; // no-warning + return vec >= vec; // no-warning +} diff --git a/test/Sema/extern-redecl.c b/test/Sema/extern-redecl.c new file mode 100644 index 0000000000000..067e3c21e4c43 --- /dev/null +++ b/test/Sema/extern-redecl.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only %s + +// rdar: // 8125274 +static int a16[]; // expected-warning {{tentative array definition assumed to have one element}} + +void f16(void) { + extern int a16[]; +} + diff --git a/test/Sema/format-strings-fixit.c b/test/Sema/format-strings-fixit.c new file mode 100644 index 0000000000000..7cd76c7c37e78 --- /dev/null +++ b/test/Sema/format-strings-fixit.c @@ -0,0 +1,44 @@ +// RUN: cp %s %t +// RUN: %clang_cc1 -pedantic -Wall -fixit %t || true +// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t + +/* This is a test of the various code modification hints that are + provided as part of warning or extension diagnostics. All of the + warnings will be fixed by -fixit, and the resulting file should + compile cleanly with -Werror -pedantic. */ + +int printf(char const *, ...); + +void test() { + // Basic types + printf("%s", (int) 123); + printf("abc%0f", "testing testing 123"); + printf("%u", (long) -12); + printf("%p", 123); + printf("%c\n", "x"); + printf("%c\n", 1.23); + + // Larger types + printf("%+.2d", (unsigned long long) 123456); + printf("%1d", (long double) 1.23); + + // Flag handling + printf("%0+s", (unsigned) 31337); // 0 flag should stay + printf("%#p", (void *) 0); + printf("% +f", 1.23); // + flag should stay + printf("%0-f", 1.23); // - flag should stay + + // Positional arguments + printf("%1$f:%2$.*3$f:%4$.*3$f\n", 1, 2, 3, 4); + + // Precision + printf("%10.5d", 1l); // (bug 7394) + printf("%.2c", 'a'); + + // Ignored flags + printf("%0-f", 1.23); + + // Bad length modifiers + printf("%hhs", "foo"); + printf("%1$zp", (void *)0); +} diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index d6d37961d922a..c6dee6801e80e 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -172,18 +172,21 @@ void test10(int x, float f, int i, long long lli) { printf("%f\n", (long double) 1.0); // expected-warning{{conversion specifies type 'double' but the argument has type 'long double'}} // The man page says that a zero precision is okay. printf("%.0Lf", (long double) 1.0); // no-warning + printf("%c\n", "x"); // expected-warning{{conversion specifies type 'int' but the argument has type 'char *'}} + printf("%c\n", 1.23); // expected-warning{{conversion specifies type 'int' but the argument has type '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("%p", 123); // expected-warning{{conversion specifies type 'void *' but the argument has type 'int'}} + printf("%.4p", p); // expected-warning{{precision used with 'p' conversion specifier, resulting in undefined behavior}} + printf("%+p", p); // expected-warning{{flag '+' results in undefined behavior with 'p' conversion specifier}} + printf("% p", p); // expected-warning{{flag ' ' results in undefined behavior with 'p' conversion specifier}} + printf("%0p", p); // expected-warning{{flag '0' results in undefined behavior with '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}} + printf("%+s", p); // expected-warning{{flag '+' results in undefined behavior with 's' conversion specifier}} + printf("% s", p); // expected-warning{{flag ' ' results in undefined behavior with 's' conversion specifier}} + printf("%0s", p); // expected-warning{{flag '0' results in undefined behavior with 's' conversion specifier}} } void test12(char *b) { @@ -254,3 +257,30 @@ void test_pr_6697() { void rdar8026030(FILE *fp) { fprintf(fp, "\%"); // expected-warning{{incomplete format specifier}} } + +void bug7377_bad_length_mod_usage() { + // Bad length modifiers + printf("%hhs", "foo"); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 's' conversion specifier}} + printf("%1$zp", (void *)0); // expected-warning{{length modifier 'z' results in undefined behavior or no effect with 'p' conversion specifier}} + printf("%ls", L"foo"); // no-warning + printf("%#.2Lf", (long double)1.234); // no-warning + + // Bad flag usage + printf("%#p", (void *) 0); // expected-warning{{flag '#' results in undefined behavior with 'p' conversion specifier}} + printf("%0d", -1); // no-warning + printf("%#n", (void *) 0); // expected-warning{{flag '#' results in undefined behavior with 'n' conversion specifier}} expected-warning{{use of '%n' in format string discouraged (potentially insecure)}} + printf("%-n", (void *) 0); // expected-warning{{flag '-' results in undefined behavior with 'n' conversion specifier}} expected-warning{{use of '%n' in format string discouraged (potentially insecure)}} + printf("%-p", (void *) 0); // no-warning + + // Bad optional amount use + printf("%.2c", 'a'); // expected-warning{{precision used with 'c' conversion specifier, resulting in undefined behavior}} + printf("%1n", (void *) 0); // expected-warning{{field width used with 'n' conversion specifier, resulting in undefined behavior}} expected-warning{{use of '%n' in format string discouraged (potentially insecure)}} + printf("%.9n", (void *) 0); // expected-warning{{precision used with 'n' conversion specifier, resulting in undefined behavior}} expected-warning{{use of '%n' in format string discouraged (potentially insecure)}} + + // Ignored flags + printf("% +f", 1.23); // expected-warning{{flag ' ' is ignored when flag '+' is present}} + printf("%+ f", 1.23); // expected-warning{{flag ' ' is ignored when flag '+' is present}} + printf("%0-f", 1.23); // expected-warning{{flag '0' is ignored when flag '-' is present}} + printf("%-0f", 1.23); // expected-warning{{flag '0' is ignored when flag '-' is present}} + printf("%-+f", 1.23); // no-warning +} diff --git a/test/Sema/function-redecl.c b/test/Sema/function-redecl.c index 633ad214236a2..27ec163ea9cb8 100644 --- a/test/Sema/function-redecl.c +++ b/test/Sema/function-redecl.c @@ -126,6 +126,6 @@ void test_x() { x2(5); // expected-warning{{incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'}} } -enum e0 {}; +enum e0 {one}; void f3(); void f3(enum e0 x) {} diff --git a/test/Sema/function.c b/test/Sema/function.c index 9a83519a90b52..b51c137ce7dc2 100644 --- a/test/Sema/function.c +++ b/test/Sema/function.c @@ -34,10 +34,10 @@ void t12(int) {} // expected-error{{parameter name omitted}} // PR2790 void t13() { - return 0; // expected-warning {{void function 't13' should not return a value}} + return 0; // expected-error {{void function 't13' should not return a value}} } int t14() { - return; // expected-warning {{non-void function 't14' should return a value}} + return; // expected-error {{non-void function 't14' should return a value}} } // <rdar://problem/6097326> diff --git a/test/Sema/i-c-e.c b/test/Sema/i-c-e.c index 97d9f43cfba68..c86a93fed8298 100644 --- a/test/Sema/i-c-e.c +++ b/test/Sema/i-c-e.c @@ -50,9 +50,10 @@ char y[__builtin_constant_p(expr) ? -1 : 1]; char z[__builtin_constant_p(4) ? 1 : -1]; // Comma tests -int comma1[0?1,2:3]; -int comma2[1||(1,2)]; -int comma3[(1,2)]; // expected-warning {{size of static array must be an integer constant expression}} +int comma1[0?1,2:3]; // expected-warning {{expression result unused}} +int comma2[1||(1,2)]; // expected-warning {{expression result unused}} +int comma3[(1,2)]; // expected-warning {{size of static array must be an integer constant expression}} \ + // expected-warning {{expression result unused}} // Pointer + __builtin_constant_p char pbcp[__builtin_constant_p(4) ? (intptr_t)&expr : 0]; // expected-error {{variable length array declaration not allowed at file scope}} diff --git a/test/Sema/implicit-decl.c b/test/Sema/implicit-decl.c index 830cde9b9f90d..f455977536630 100644 --- a/test/Sema/implicit-decl.c +++ b/test/Sema/implicit-decl.c @@ -10,7 +10,6 @@ void func() { if (_CFCalendarDecomposeAbsoluteTimeV(compDesc, vector, compCount)) { // expected-note {{previous implicit declaration is here}} \ expected-warning {{implicit declaration of function '_CFCalendarDecomposeAbsoluteTimeV' is invalid in C99}} } - return ((void *)0); // expected-warning {{void function 'func' should not return a value}} } Boolean _CFCalendarDecomposeAbsoluteTimeV(const char *componentDesc, int32_t **vector, int32_t count) { // expected-error{{conflicting types for '_CFCalendarDecomposeAbsoluteTimeV'}} return 0; diff --git a/test/Sema/init.c b/test/Sema/init.c index c2c29ad9b04b6..ac274a4ce2276 100644 --- a/test/Sema/init.c +++ b/test/Sema/init.c @@ -118,8 +118,6 @@ int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0); typedef int32_t ivector4 __attribute((vector_size(16))); ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1}; ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1}); -ivector4 vtest3 = __real__ (ivector4){1}; -ivector4 vtest4 = __imag__ (ivector4){1}; uintptr_t ptrasintadd1 = (uintptr_t)&a - 4; uintptr_t ptrasintadd2 = (uintptr_t)&a + 4; diff --git a/test/Sema/missing-field-initializers.c b/test/Sema/missing-field-initializers.c index 828191462444e..6aa48ba9e419d 100644 --- a/test/Sema/missing-field-initializers.c +++ b/test/Sema/missing-field-initializers.c @@ -20,6 +20,8 @@ struct Foo bar1[] = { 1 }; // expected-warning {{missing field 'b' initializer}} +struct Foo bar2[] = { {}, {}, {} }; + struct One { int a; int b; }; struct Two { float c; float d; float e; }; diff --git a/test/Sema/opencl-init.c b/test/Sema/opencl-init.c new file mode 100644 index 0000000000000..3d116bd0dae69 --- /dev/null +++ b/test/Sema/opencl-init.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s -x cl -verify -pedantic -fsyntax-only + +typedef float float8 __attribute((ext_vector_type(8))); + +typedef float float32_t; +typedef __attribute__(( __vector_size__(16) )) float32_t __neon_float32x4_t; +typedef struct __simd128_float32_t { + __neon_float32x4_t val; +} float32x4_t; + +float8 foo(float8 x) { + float32x4_t lo; + float32x4_t hi; + return (float8) (lo.val, hi.val); +} diff --git a/test/Sema/pragma-align-mac68k-unsupported.c b/test/Sema/pragma-align-mac68k-unsupported.c index 6588aa17a15e4..c23c01bf5e2ff 100644 --- a/test/Sema/pragma-align-mac68k-unsupported.c +++ b/test/Sema/pragma-align-mac68k-unsupported.c @@ -1,4 +1,4 @@ -// RUN: %clang-cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -// RUN: %clang-cc1 -triple i386-pc-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i386-pc-linux-gnu -fsyntax-only -verify %s /* expected-error {{mac68k alignment pragma is not supported}} */ #pragma options align=mac68k diff --git a/test/Sema/pragma-align-mac68k.c b/test/Sema/pragma-align-mac68k.c index d13a0bebb767f..fb8da515bbc77 100644 --- a/test/Sema/pragma-align-mac68k.c +++ b/test/Sema/pragma-align-mac68k.c @@ -1,4 +1,4 @@ -// RUN: %clang-cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s #include <stddef.h> diff --git a/test/Sema/pragma-align-packed.c b/test/Sema/pragma-align-packed.c new file mode 100644 index 0000000000000..30b87bf99695f --- /dev/null +++ b/test/Sema/pragma-align-packed.c @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s + +#pragma pack(push, 1) +struct s0 { + char f0; + int f1 __attribute__((aligned(4))); +}; +extern int a[sizeof(struct s0) == 5 ? 1 : -1]; +#pragma pack(pop) + +struct __attribute__((packed)) s1 { + char f0; + int f1 __attribute__((aligned(4))); +}; +extern int a[sizeof(struct s1) == 8 ? 1 : -1]; + +#pragma options align=packed +struct s2 { + char f0; + int f1 __attribute__((aligned(4))); +}; +extern int a[sizeof(struct s2) == 5 ? 1 : -1]; +#pragma options align=reset diff --git a/test/Sema/pragma-pack-and-options-align.c b/test/Sema/pragma-pack-and-options-align.c index c880ed6305b46..ebf1adee02f32 100644 --- a/test/Sema/pragma-pack-and-options-align.c +++ b/test/Sema/pragma-pack-and-options-align.c @@ -16,6 +16,14 @@ struct s1 { }; extern int a[sizeof(struct s1) == 8 ? 1 : -1]; +#pragma options align=reset +#pragma options align=native +struct s1_1 { + char c; + int x; +}; +extern int a[sizeof(struct s1_1) == 8 ? 1 : -1]; + #pragma pack(pop) struct s2 { char c; diff --git a/test/Sema/return.c b/test/Sema/return.c index 0d46d981bed20..2d23e08039679 100644 --- a/test/Sema/return.c +++ b/test/Sema/return.c @@ -1,4 +1,4 @@ -// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wno-unreachable-code -Wno-unused-value +// RUN: %clang %s -fsyntax-only -Wreturn-type -Xclang -verify -fblocks -Wno-unreachable-code -Wno-unused-value // clang emits the following warning by default. // With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the diff --git a/test/Sema/self-comparison.c b/test/Sema/self-comparison.c index 1baba2755f43f..c5c0611e7c94d 100644 --- a/test/Sema/self-comparison.c +++ b/test/Sema/self-comparison.c @@ -1,11 +1,21 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s int foo(int x) { - return x == x; // expected-warning {{self-comparison always results}} + return x == x; // expected-warning {{self-comparison always evaluates to true}} } int foo2(int x) { - return (x) != (((x))); // expected-warning {{self-comparison always results}} + return (x) != (((x))); // expected-warning {{self-comparison always evaluates to false}} +} + +void foo3(short s, short t) { + if (s == s) {} // expected-warning {{self-comparison always evaluates to true}} + if (s == t) {} // no-warning +} + +void foo4(void* v, void* w) { + if (v == v) {} // expected-warning {{self-comparison always evaluates to true}} + if (v == w) {} // no-warning } int qux(int x) { @@ -24,15 +34,44 @@ int bar2(float x) { return x != x; // no-warning } -// Motivated by <rdar://problem/6703892>, self-comparisons of enum constants -// should not be warned about. These can be expanded from macros, and thus -// are usually deliberate. -int compare_enum() { - enum { A }; - return A == A; // no-warning +#define IS_THE_ANSWER(x) (x == 42) + +int macro_comparison() { + return IS_THE_ANSWER(42); } // Don't complain in unevaluated contexts. int compare_sizeof(int x) { return sizeof(x == x); // no-warning } + +int array_comparisons() { + int array1[2]; + int array2[2]; + + // + // compare same array + // + return array1 == array1; // expected-warning{{self-comparison always evaluates to true}} + return array1 != array1; // expected-warning{{self-comparison always evaluates to false}} + return array1 < array1; // expected-warning{{self-comparison always evaluates to false}} + return array1 <= array1; // expected-warning{{self-comparison always evaluates to true}} + return array1 > array1; // expected-warning{{self-comparison always evaluates to false}} + return array1 >= array1; // expected-warning{{self-comparison always evaluates to true}} + + // + // compare differrent arrays + // + return array1 == array2; // expected-warning{{array comparison always evaluates to false}} + return array1 != array2; // expected-warning{{array comparison always evaluates to true}} + + // + // we don't know what these are going to be + // + return array1 < array2; // expected-warning{{array comparison always evaluates to a constant}} + return array1 <= array2; // expected-warning{{array comparison always evaluates to a constant}} + return array1 > array2; // expected-warning{{array comparison always evaluates to a constant}} + return array1 >= array2; // expected-warning{{array comparison always evaluates to a constant}} + +} + diff --git a/test/Sema/struct-cast.c b/test/Sema/struct-cast.c index dc7db130dc19a..3456665a8c55f 100644 --- a/test/Sema/struct-cast.c +++ b/test/Sema/struct-cast.c @@ -5,7 +5,8 @@ struct S { int two; }; -struct S const foo(void); +struct S const foo(void); // expected-warning{{type qualifier on return type has no effect}} + struct S tmp; diff --git a/test/Sema/struct-decl.c b/test/Sema/struct-decl.c index f8880530f9502..3639d2479b97c 100644 --- a/test/Sema/struct-decl.c +++ b/test/Sema/struct-decl.c @@ -41,3 +41,8 @@ struct s0 { }; struct s0 f0(void) {} + +// <rdar://problem/8177927> - This previously triggered an assertion failure. +struct x0 { + unsigned int x1; +}; diff --git a/test/Sema/switch.c b/test/Sema/switch.c index 27ad06657e265..bb4822916cc72 100644 --- a/test/Sema/switch.c +++ b/test/Sema/switch.c @@ -277,3 +277,14 @@ void test16() { case '6': return; } } + +// PR7359 +void test17(int x) { + switch (x >= 17) { // expected-warning {{switch condition has boolean value}} + case 0: return; + } + + switch ((int) (x <= 17)) { + case 0: return; + } +} diff --git a/test/Sema/transparent-union.c b/test/Sema/transparent-union.c index cdfc8506d1b5d..27d5c2403b43c 100644 --- a/test/Sema/transparent-union.c +++ b/test/Sema/transparent-union.c @@ -38,3 +38,10 @@ typedef union { } TU3 __attribute__((transparent_union)); typedef union { } TU4 __attribute__((transparent_union)); // expected-warning{{field}} + +typedef int int4 __attribute__((ext_vector_type(4))); +typedef union { + int4 vec; // expected-warning{{first field of a transparent union cannot have vector type 'int4'; transparent_union attribute ignored}} +} TU5 __attribute__((transparent_union)); + + diff --git a/test/Sema/types.c b/test/Sema/types.c index 1770bf5bd03e3..f3244f7799b67 100644 --- a/test/Sema/types.c +++ b/test/Sema/types.c @@ -36,4 +36,4 @@ _Decimal32 x; // expected-error {{GNU decimal type extension not supported}} // rdar://6880951 -int __attribute__ ((vector_size (8), vector_size (8))) v; // expected-error {{invalid vector type}} +int __attribute__ ((vector_size (8), vector_size (8))) v; // expected-error {{invalid vector element type}} diff --git a/test/Sema/var-redecl.c b/test/Sema/var-redecl.c index 71d7ea1baee0f..f7576b6c0255e 100644 --- a/test/Sema/var-redecl.c +++ b/test/Sema/var-redecl.c @@ -58,5 +58,5 @@ int *p=&g19; // expected-error{{use of undeclared identifier 'g19'}} \ // PR3645 static int a; -extern int a; -int a; +extern int a; // expected-note {{previous definition is here}} +int a; // expected-error {{non-static declaration of 'a' follows static declaration}} diff --git a/test/Sema/warn-unused-value.c b/test/Sema/warn-unused-value.c index 16b787f774411..1a7e745785b36 100644 --- a/test/Sema/warn-unused-value.c +++ b/test/Sema/warn-unused-value.c @@ -18,9 +18,9 @@ void pr4806() { i,foo(); // expected-warning {{expression result unused}} foo(),i; // expected-warning {{expression result unused}} - i,j,foo(); // expected-warning {{expression result unused}} - i,foo(),j; // expected-warning {{expression result unused}} - foo(),i,j; // expected-warning {{expression result unused}} + i,j,foo(); // expected-warning {{expression result unused}} expected-warning {{expression result unused}} + i,foo(),j; // expected-warning {{expression result unused}} expected-warning {{expression result unused}} + foo(),i,j; // expected-warning {{expression result unused}} expected-warning {{expression result unused}} i++; @@ -63,6 +63,16 @@ int test_logical_bar() { (x = test_logical_foo1()) || // no-warning (x = test_logical_foo2()) || // no-warning (x = test_logical_foo3()); // no-warning + + x || test_logical_foo1(); // no-warning + return x; } +struct s0 { int f0; }; + +void f0(int a); +void f1(struct s0 *a) { + // rdar://8139785 + f0((int)(a->f0 + 1, 10)); // expected-warning {{expression result unused}} +} diff --git a/test/SemaCXX/abstract.cpp b/test/SemaCXX/abstract.cpp index 3e61cc386eb81..f64fda4877e07 100644 --- a/test/SemaCXX/abstract.cpp +++ b/test/SemaCXX/abstract.cpp @@ -168,3 +168,21 @@ namespace PureImplicit { struct D : C {}; D y; } + +namespace test1 { + struct A { + virtual void foo() = 0; + }; + + struct B : A { + using A::foo; + }; + + struct C : B { + void foo(); + }; + + void test() { + C c; + } +} diff --git a/test/SemaCXX/access-base-class.cpp b/test/SemaCXX/access-base-class.cpp index 85516902163e7..f676e199b6ce8 100644 --- a/test/SemaCXX/access-base-class.cpp +++ b/test/SemaCXX/access-base-class.cpp @@ -61,7 +61,7 @@ namespace T5 { namespace T6 { class C; - class A {}; + class A {}; // expected-note{{member is declared here}} class B : private A { // expected-note {{declared private here}} expected-note {{constrained by private inheritance here}} void f(C* c); diff --git a/test/SemaCXX/ambig-user-defined-conversions.cpp b/test/SemaCXX/ambig-user-defined-conversions.cpp index 7f676748740cc..9811859fccce0 100644 --- a/test/SemaCXX/ambig-user-defined-conversions.cpp +++ b/test/SemaCXX/ambig-user-defined-conversions.cpp @@ -17,7 +17,8 @@ namespace test0 { void func(const char ci, const B b); // expected-note {{candidate function}} void func(const B b, const int ci); // expected-note {{candidate function}} - const int Test1() { + const int Test1() { // expected-warning{{type qualifier on return type has no effect}} + func(b1, f()); // expected-error {{call to 'func' is ambiguous}} return f(); // expected-error {{conversion from 'test0::B' to 'int const' is ambiguous}} } diff --git a/test/SemaCXX/attr-regparm.cpp b/test/SemaCXX/attr-regparm.cpp new file mode 100644 index 0000000000000..b98631abe5d0d --- /dev/null +++ b/test/SemaCXX/attr-regparm.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR7025 +struct X0 { + void __attribute__((regparm(3))) f0(); + void __attribute__((regparm(3))) f1(); + void __attribute__((regparm(3))) f2(); // expected-note{{previous declaration is here}} + void f3(); // expected-note{{previous declaration is here}} +}; + +void X0::f0() { } +void __attribute__((regparm(3))) X0::f1() { } +void __attribute__((regparm(2))) X0::f2() { } // expected-error{{function declared with with regparm(2) attribute was previously declared with the regparm(3) attribute}} +void __attribute__((regparm(2))) X0::f3() { } // expected-error{{function declared with with regparm(2) attribute was previously declared without the regparm attribute}} diff --git a/test/SemaCXX/blocks-1.cpp b/test/SemaCXX/blocks-1.cpp index d93997ad6835e..29de1e666ad75 100644 --- a/test/SemaCXX/blocks-1.cpp +++ b/test/SemaCXX/blocks-1.cpp @@ -33,3 +33,13 @@ int main (int argc, const char * argv[]) { return 0; } + +namespace rdar8134521 { + void foo() { + int (^P)(int) = reinterpret_cast<int(^)(int)>(1); + P = (int(^)(int))(1); + + P = reinterpret_cast<int(^)(int)>((void*)1); + P = (int(^)(int))((void*)1); + } +} diff --git a/test/SemaCXX/class-layout.cpp b/test/SemaCXX/class-layout.cpp index f3c75f4b27d35..d81944ab9b3ca 100644 --- a/test/SemaCXX/class-layout.cpp +++ b/test/SemaCXX/class-layout.cpp @@ -71,3 +71,34 @@ struct D : C { bool iv0 : 1; }; SA(10, sizeof(D) == 2); } + +namespace Test1 { + +// Test that we don't assert on this hierarchy. +struct A { }; +struct B : A { virtual void b(); }; +class C : virtual A { int c; }; +struct D : virtual B { }; +struct E : C, virtual D { }; +class F : virtual E { }; +struct G : virtual E, F { }; + +SA(0, sizeof(G) == 24); + +} + +namespace Test2 { + +// Test that this somewhat complex class structure is laid out correctly. +struct A { }; +struct B : A { virtual void b(); }; +struct C : virtual B { }; +struct D : virtual A { }; +struct E : virtual B, D { }; +struct F : E, virtual C { }; +struct G : virtual F, A { }; +struct H { G g; }; + +SA(0, sizeof(H) == 24); + +} diff --git a/test/SemaCXX/class.cpp b/test/SemaCXX/class.cpp index b5cecbcf937b9..9d9508b8ef4a6 100644 --- a/test/SemaCXX/class.cpp +++ b/test/SemaCXX/class.cpp @@ -159,3 +159,9 @@ namespace PR7196 { } }; } + +namespace rdar8066414 { + class C { + C() {} + } // expected-error{{expected ';' after class}} +} diff --git a/test/SemaCXX/compare.cpp b/test/SemaCXX/compare.cpp index 4790347220d68..ebecc0633edad 100644 --- a/test/SemaCXX/compare.cpp +++ b/test/SemaCXX/compare.cpp @@ -198,3 +198,11 @@ int test1(int i) { enum en { zero }; return i > zero; } + +enum E { e }; +void test2(int i, void *vp) { + if (test1 == vp) { } // expected-warning{{equality comparison between function pointer and void pointer}} + if (test1 == e) { } // expected-error{{comparison between pointer and integer}} + if (vp < 0) { } + if (test1 < e) { } // expected-error{{comparison between pointer and integer}} +} diff --git a/test/SemaCXX/conditional-expr.cpp b/test/SemaCXX/conditional-expr.cpp index a09ff2bd417d5..f37ccc8a15da6 100644 --- a/test/SemaCXX/conditional-expr.cpp +++ b/test/SemaCXX/conditional-expr.cpp @@ -199,17 +199,24 @@ void test() } namespace PR6595 { + struct OtherString { + OtherString(); + OtherString(const char*); + }; + struct String { String(const char *); + String(const OtherString&); operator const char*() const; }; - void f(bool Cond, String S) { + void f(bool Cond, String S, OtherString OS) { (void)(Cond? S : ""); (void)(Cond? "" : S); const char a[1] = {'a'}; (void)(Cond? S : a); (void)(Cond? a : S); + (void)(Cond? OS : S); } } @@ -275,3 +282,25 @@ namespace rdar7998817 { : X()); } } + +namespace PR7598 { + enum Enum { + v = 1, + }; + + const Enum g() { // expected-warning{{type qualifier on return type has no effect}} + return v; + } + + const volatile Enum g2() { // expected-warning{{'const volatile' type qualifiers on return type have no effect}} + return v; + } + + void f() { + const Enum v2 = v; + Enum e = false ? g() : v; + Enum e2 = false ? v2 : v; + Enum e3 = false ? g2() : v; + } + +} diff --git a/test/SemaCXX/constructor-initializer.cpp b/test/SemaCXX/constructor-initializer.cpp index 8e9e133d94cbd..cf309f5597d33 100644 --- a/test/SemaCXX/constructor-initializer.cpp +++ b/test/SemaCXX/constructor-initializer.cpp @@ -204,3 +204,20 @@ C f(C c) { } } + +// Don't build implicit initializers for anonymous union fields when we already +// have an explicit initializer for another field in the union. +namespace PR7402 { + struct S { + union { + void* ptr_; + struct { int i_; }; + }; + + template <typename T> S(T) : ptr_(0) { } + }; + + void f() { + S s(3); + } +} diff --git a/test/SemaCXX/conversion.cpp b/test/SemaCXX/conversion.cpp new file mode 100644 index 0000000000000..f6489438070a7 --- /dev/null +++ b/test/SemaCXX/conversion.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wconversion -verify %s + +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef signed long int64_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long uint64_t; + +// <rdar://problem/7909130> +namespace test0 { + int32_t test1_positive(char *I, char *E) { + return (E - I); // expected-warning {{implicit conversion loses integer precision}} + } + + int32_t test1_negative(char *I, char *E) { + return static_cast<int32_t>(E - I); + } + + uint32_t test2_positive(uint64_t x) { + return x; // expected-warning {{implicit conversion loses integer precision}} + } + + uint32_t test2_negative(uint64_t x) { + return (uint32_t) x; + } +} + +namespace test1 { + uint64_t test1(int x, unsigned y) { + return sizeof(x == y); + } + + uint64_t test2(int x, unsigned y) { + return __alignof(x == y); + } + + void * const foo(); + bool test2(void *p) { + return p == foo(); + } +} diff --git a/test/SemaCXX/crash-8124080.cpp b/test/SemaCXX/crash-8124080.cpp new file mode 100644 index 0000000000000..78a031561a5f5 --- /dev/null +++ b/test/SemaCXX/crash-8124080.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// <rdar://problem/8124080> +template<typename _Alloc> class allocator; +template<class _CharT> struct char_traits; +template<typename _CharT, typename _Traits = char_traits<_CharT>, + typename _Alloc = allocator<_CharT> > +class basic_string; +template<typename _CharT, typename _Traits, typename _Alloc> +const typename basic_string<_CharT, _Traits, _Alloc>::size_type +basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_max_size // expected-error{{no member named '_Rep' in 'basic_string<_CharT, _Traits, _Alloc>'}} + = (((npos - sizeof(_Rep_base))/sizeof(_CharT)) - 1) / 4; + +// PR7118 +template<typename T> +class Foo { + class Bar; + void f() { + Bar i; + } +}; diff --git a/test/SemaCXX/destructor.cpp b/test/SemaCXX/destructor.cpp index ae3dc86e97f50..4f6c76bc90eda 100644 --- a/test/SemaCXX/destructor.cpp +++ b/test/SemaCXX/destructor.cpp @@ -19,7 +19,9 @@ struct D { // expected-error{{type qualifier is not allowed on this function}} \ // expected-error{{destructor cannot be declared 'static'}} \ // expected-error{{destructor cannot have any parameters}} \ - // expected-error{{destructor cannot be variadic}} + // expected-error{{destructor cannot be variadic}} \ + // expected-error{{destructor cannot have a return type}} \ + // expected-error{{'const' qualifier is not allowed on a destructor}} }; struct D2 { @@ -83,3 +85,23 @@ namespace PR6709 { template<class T> class X { T v; ~X() { ++*v; } }; void a(X<int> x) {} } + +struct X0 { virtual ~X0() throw(); }; +struct X1 : public X0 { }; + +// Make sure we instantiate operator deletes when building a virtual +// destructor. +namespace test6 { + template <class T> class A { + public: + void *operator new(__SIZE_TYPE__); + void operator delete(void *p) { + T::deleteIt(p); // expected-error {{type 'int' cannot be used prior to '::'}} + } + + virtual ~A() {} // expected-note {{in instantiation of member function 'test6::A<int>::operator delete' requested here}} + }; + + class B : A<int> { B(); }; + B::B() {} +} diff --git a/test/SemaCXX/empty-class-layout.cpp b/test/SemaCXX/empty-class-layout.cpp index 27f5040e1877c..0b46bf045ac00 100644 --- a/test/SemaCXX/empty-class-layout.cpp +++ b/test/SemaCXX/empty-class-layout.cpp @@ -84,3 +84,63 @@ class F : D, E { }; SA(0, sizeof(F) == 24); } + +namespace Test2 { + +// Test that B::a isn't laid out at offset 0. +struct Empty { }; +struct A : Empty { }; +struct B : Empty { + A a; +}; + +SA(0, sizeof(B) == 2); + +} + +namespace Test3 { + +// Test that B::a isn't laid out at offset 0. +struct Empty { }; +struct A { Empty e; }; +struct B : Empty { A a; }; +SA(0, sizeof(B) == 2); + +} + +namespace Test4 { + +// Test that C::Empty isn't laid out at offset 0. +struct Empty { }; +struct A : Empty { }; +struct B { A a; }; +struct C : B, Empty { }; +SA(0, sizeof(C) == 2); + +} + +namespace Test5 { + +// Test that B::Empty isn't laid out at offset 0. +struct Empty { }; +struct Field : virtual Empty { }; +struct A { + Field f; +}; +struct B : A, Empty { }; +SA(0, sizeof(B) == 16); + +} + +namespace Test6 { + +// Test that B::A isn't laid out at offset 0. +struct Empty { }; +struct Field : virtual Empty { }; +struct A { + Field f; +}; +struct B : Empty, A { }; +SA(0, sizeof(B) == 16); + +} diff --git a/test/SemaCXX/enum.cpp b/test/SemaCXX/enum.cpp index bfb5784dd161f..0690ead250859 100644 --- a/test/SemaCXX/enum.cpp +++ b/test/SemaCXX/enum.cpp @@ -1,9 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -pedantic -std=c++98 -verify -triple x86_64-apple-darwin %s -enum E { +enum E { // expected-note{{previous definition is here}} Val1, Val2 }; +enum E; // expected-warning{{redeclaration of already-defined enum 'E' is a GNU extension}} + int& enumerator_type(int); float& enumerator_type(E); @@ -79,3 +81,7 @@ namespace PR7051 { e |= 1; // expected-error{{assigning to 'PR7051::E' from incompatible type 'int'}} } } + +// PR7466 +enum { }; // expected-warning{{declaration does not declare anything}} +typedef enum { }; // expected-warning{{typedef requires a name}} diff --git a/test/SemaCXX/exception-spec-no-exceptions.cpp b/test/SemaCXX/exception-spec-no-exceptions.cpp new file mode 100644 index 0000000000000..1fe45b0cffcbc --- /dev/null +++ b/test/SemaCXX/exception-spec-no-exceptions.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Note: this is intentionally -fno-exceptions, not just accidentally +// so because that's the current -cc1 default. + +// PR7243: redeclarations +namespace test0 { + void foo() throw(int); + void foo() throw(); +} + +// Overrides. +namespace test1 { + struct A { + virtual void foo() throw(); + }; + + struct B : A { + virtual void foo() throw(int); + }; +} + +// Calls from less permissive contexts. We don't actually do this +// check, but if we did it should also be disabled under +// -fno-exceptions. +namespace test2 { + void foo() throw(int); + void bar() throw() { + foo(); + } +} + diff --git a/test/SemaCXX/friend.cpp b/test/SemaCXX/friend.cpp index ffad0e2b44ef4..65e0da761cfd4 100644 --- a/test/SemaCXX/friend.cpp +++ b/test/SemaCXX/friend.cpp @@ -44,6 +44,21 @@ namespace test2 { // PR5134 namespace test3 { class Foo { - friend const int getInt(int inInt = 0); + friend const int getInt(int inInt = 0); // expected-warning{{'const' type qualifier on return type has no effect}} + + }; +} + +namespace test4 { + class T4A { + friend class T4B; + + public: + T4A(class T4B *); + + protected: + T4B *mB; // error here }; + + class T4B {}; } diff --git a/test/SemaCXX/function-type-qual.cpp b/test/SemaCXX/function-type-qual.cpp index be61f2ba56395..8ebb506070256 100644 --- a/test/SemaCXX/function-type-qual.cpp +++ b/test/SemaCXX/function-type-qual.cpp @@ -1,15 +1,17 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s void f() const; // expected-error {{type qualifier is not allowed on this function}} +void (*pf)() const; // expected-error {{type qualifier is not allowed on this function pointer}} +void (&rf)() const = f; // expected-error {{type qualifier is not allowed on this function reference}} typedef void cfn() const; -cfn f2; // expected-error {{a qualified function type cannot be used to declare a nonmember function or a static member function}} +cfn f2; // expected-error {{a qualified function type cannot be used to declare a nonmember function}} class C { void f() const; cfn f2; static void f3() const; // expected-error {{type qualifier is not allowed on this function}} - static cfn f4; // expected-error {{a qualified function type cannot be used to declare a nonmember function or a static member function}} + static cfn f4; // expected-error {{a qualified function type cannot be used to declare a static member function}} void m1() { x = 0; @@ -21,3 +23,6 @@ class C { int x; }; + +void (C::*mpf)() const; +cfn C::*mpg; diff --git a/test/SemaCXX/implicit-member-functions.cpp b/test/SemaCXX/implicit-member-functions.cpp index 79cc3679f4981..5333094d53bd4 100644 --- a/test/SemaCXX/implicit-member-functions.cpp +++ b/test/SemaCXX/implicit-member-functions.cpp @@ -39,3 +39,14 @@ namespace PR6570 { }; } + +namespace PR7594 { + // If the lazy declaration of special member functions is triggered + // in an out-of-line initializer, make sure the functions aren't in + // the initializer scope. This used to crash Clang: + struct C { + C(); + static C *c; + }; + C *C::c = new C(); +} diff --git a/test/SemaCXX/init-priority-attr.cpp b/test/SemaCXX/init-priority-attr.cpp new file mode 100644 index 0000000000000..6ea263d1e59da --- /dev/null +++ b/test/SemaCXX/init-priority-attr.cpp @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +class Two { +private: + int i, j, k; +public: + static int count; + Two( int ii, int jj ) { i = ii; j = jj; k = count++; }; + Two( void ) { i = 0; j = 0; k = count++; }; + int eye( void ) { return i; }; + int jay( void ) { return j; }; + int kay( void ) { return k; }; +}; + +extern Two foo; +extern Two goo; +extern Two coo[]; +extern Two koo[]; + +Two foo __attribute__((init_priority(101))) ( 5, 6 ); + +Two goo __attribute__((init_priority(2,3))) ( 5, 6 ); // expected-error {{attribute requires 1 argument(s)}} + +Two coo[2] __attribute__((init_priority(3))); // expected-error {{init_priority attribute requires integer constant between 101 and 65535 inclusive}} + +Two koo[4] __attribute__((init_priority(1.13))); // expected-error {{'init_priority' attribute requires integer constant}} + + +Two func() __attribute__((init_priority(1001))); // expected-error {{can only use ‘init_priority’ attribute on file-scope definitions of objects of class type}} + +int i __attribute__((init_priority(1001))); // expected-error {{can only use ‘init_priority’ attribute on file-scope definitions of objects of class type}} + +int main() { + Two foo __attribute__((init_priority(1001))); // expected-error {{can only use ‘init_priority’ attribute on file-scope definitions of objects of class type}} +} + diff --git a/test/SemaCXX/instantiate-blocks.cpp b/test/SemaCXX/instantiate-blocks.cpp new file mode 100644 index 0000000000000..a4001a75fa57b --- /dev/null +++ b/test/SemaCXX/instantiate-blocks.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s +// rdar: // 6182276 + +template <typename T, typename T1> void foo(T t, T1 r) +{ + T block_arg; + __block T1 byref_block_arg; + + T1 (^block)(T) = ^ T1 (T arg) { + byref_block_arg = arg; + block_arg = arg; // expected-error {{variable is not assignable (missing __block type specifier)}} + return block_arg+arg; }; +} + +int main(void) +{ + foo(100, 'a'); // expected-note {{in instantiation of function template specialization 'foo<int, char>' requested here}} +} + diff --git a/test/SemaCXX/member-expr.cpp b/test/SemaCXX/member-expr.cpp index 54a95936bed16..6830c5fdafb77 100644 --- a/test/SemaCXX/member-expr.cpp +++ b/test/SemaCXX/member-expr.cpp @@ -72,3 +72,32 @@ namespace test4 { y.f(17); } } + +namespace test5 { + struct A { + template <class T> void foo(); + }; + + void test0(int x) { + x.A::foo<int>(); // expected-error {{'int' is not a structure or union}} + } + + void test1(A *x) { + x.A::foo<int>(); // expected-error {{'test5::A *' is a pointer}} + } + + void test2(A &x) { + x->A::foo<int>(); // expected-error {{'test5::A' is not a pointer}} + } +} + +namespace PR7508 { + struct A { + struct CleanupScope {}; + void PopCleanupBlock(); + }; + + void foo(A &a) { + a.PopCleanupScope(); // expected-error{{no member named 'PopCleanupScope' in 'PR7508::A'}} + } +} diff --git a/test/SemaCXX/new-array-size-conv.cpp b/test/SemaCXX/new-array-size-conv.cpp new file mode 100644 index 0000000000000..80219a906209e --- /dev/null +++ b/test/SemaCXX/new-array-size-conv.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s + +struct ValueInt +{ + ValueInt(int v = 0) : ValueLength(v) {} + operator int () const { return ValueLength; } // expected-note 3{{conversion to integral type 'int' declared here}} +private: + int ValueLength; +}; + +enum E { e }; +struct ValueEnum { + operator E() const; // expected-note{{conversion to enumeration type 'E' declared here}} +}; + +struct ValueBoth : ValueInt, ValueEnum { }; + +struct IndirectValueInt : ValueInt { }; +struct TwoValueInts : ValueInt, IndirectValueInt { }; + +void test() { + (void)new int[ValueInt(10)]; // expected-warning{{implicit conversion from array size expression of type 'ValueInt' to integral type 'int' is a C++0x extension}} + (void)new int[ValueEnum()]; // expected-warning{{implicit conversion from array size expression of type 'ValueEnum' to enumeration type 'E' is a C++0x extension}} + (void)new int[ValueBoth()]; // expected-error{{ambiguous conversion of array size expression of type 'ValueBoth' to an integral or enumeration type}} + + (void)new int[TwoValueInts()]; // expected-error{{ambiguous conversion of array size expression of type 'TwoValueInts' to an integral or enumeration type}} +} diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index 3f1da0292b4a2..25bf823b25551 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -68,7 +68,7 @@ void bad_news(int *ip) (void)new int[1.1]; // expected-error {{array size expression must have integral or enumerated type, not 'double'}} (void)new int[1][i]; // expected-error {{only the first dimension}} (void)new (int[1][i]); // expected-error {{only the first dimension}} - (void)new (int[i]); // expected-error {{when type is in parentheses}} + (void)new (int[i]); // expected-warning {{when type is in parentheses}} (void)new int(*(S*)0); // expected-error {{no viable conversion from 'S' to 'int'}} (void)new int(1, 2); // expected-error {{excess elements in scalar initializer}} (void)new S(1); // expected-error {{no matching constructor}} @@ -263,3 +263,50 @@ template void h<unsigned>(unsigned); template void h<unsigned[10]>(unsigned); // expected-note {{in instantiation of function template specialization 'Test1::h<unsigned int [10]>' requested here}} } + +// Don't diagnose access for overload candidates that aren't selected. +namespace PR7436 { +struct S1 { + void* operator new(size_t); + void operator delete(void* p); + +private: + void* operator new(size_t, void*); // expected-note {{declared private here}} + void operator delete(void*, void*); +}; +class S2 { + void* operator new(size_t); // expected-note {{declared private here}} + void operator delete(void* p); // expected-note {{declared private here}} +}; + +void test(S1* s1, S2* s2) { + delete s1; + delete s2; // expected-error {{is a private member}} + (void)new S1(); + (void)new (0L) S1(); // expected-error {{is a private member}} + (void)new S2(); // expected-error {{is a private member}} +} +} + +namespace rdar8018245 { + struct X0 { + static const int value = 17; + }; + + const int X0::value; + + struct X1 { + static int value; + }; + + int X1::value; + + template<typename T> + int *f() { + return new (int[T::value]); // expected-warning{{when type is in parentheses, array cannot have dynamic size}} + } + + template int *f<X0>(); + template int *f<X1>(); // expected-note{{in instantiation of}} + +} diff --git a/test/SemaCXX/overload-call.cpp b/test/SemaCXX/overload-call.cpp index 29133c7c7ff10..6bf6965e46bfe 100644 --- a/test/SemaCXX/overload-call.cpp +++ b/test/SemaCXX/overload-call.cpp @@ -54,6 +54,7 @@ double* k(bool); void test_k() { int* ip1 = k("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}} + int* ip2 = k(("foo")); // expected-warning{{conversion from string literal to 'char *' is deprecated}} double* dp1 = k(L"foo"); } @@ -218,6 +219,12 @@ void test_derived(B* b, B const* bc, C* c, const C* cc, void* v, D* d) { char* d8 = derived3(d); } +void derived4(C*); // expected-note{{candidate function not viable: cannot convert from base class pointer 'A *' to derived class pointer 'C *' for 1st argument}} + +void test_base(A* a) { + derived4(a); // expected-error{{no matching function for call to 'derived4}} +} + // Test overloading of references. // (FIXME: tests binding to determine candidate sets, not overload // resolution per se). @@ -229,6 +236,12 @@ void intref_test() { float* ir2 = intref(5.5); } +void derived5(C&); // expected-note{{candidate function not viable: cannot bind base class object of type 'A' to derived class reference 'C &' for 1st argument}} + +void test_base(A& a) { + derived5(a); // expected-error{{no matching function for call to 'derived5}} +} + // Test reference binding vs. standard conversions. int& bind_vs_conv(const double&); float& bind_vs_conv(int); @@ -460,3 +473,20 @@ namespace PR7224 { float &fr = foo(d2); } } + +namespace NontrivialSubsequence { + struct X0; + + class A { + operator X0 *(); + public: + operator const X0 *(); + }; + + A a; + void foo( void const * ); + + void g() { + foo(a); + } +} diff --git a/test/SemaCXX/overloaded-builtin-operators.cpp b/test/SemaCXX/overloaded-builtin-operators.cpp index 61c2e2110a996..8a49671f1ab89 100644 --- a/test/SemaCXX/overloaded-builtin-operators.cpp +++ b/test/SemaCXX/overloaded-builtin-operators.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -verify %s struct yes; struct no; @@ -173,7 +173,8 @@ struct A { void test_dr425(A a) { // FIXME: lots of candidates here! (void)(1.0f * a); // expected-error{{ambiguous}} \ - // expected-note 81{{candidate}} + // expected-note 4{{candidate}} \ + // expected-note {{remaining 77 candidates omitted; pass -fshow-overloads=all to show them}} } // pr5432 @@ -188,3 +189,14 @@ int test_pr5432() { void f() { (void)__extension__(A()); } + +namespace PR7319 { + typedef enum { Enum1, Enum2, Enum3 } MyEnum; + + template<typename X> bool operator>(const X &inX1, const X &inX2); + + void f() { + MyEnum e1, e2; + if (e1 > e2) {} + } +} diff --git a/test/SemaCXX/overloaded-operator.cpp b/test/SemaCXX/overloaded-operator.cpp index 3d737f4d30504..24f7f66129ebd 100644 --- a/test/SemaCXX/overloaded-operator.cpp +++ b/test/SemaCXX/overloaded-operator.cpp @@ -49,6 +49,13 @@ struct B { } }; +// we shouldn't see warnings about self-comparison, +// this is a member function, we dunno what it'll do +bool i(B b) +{ + return b == b; +} + enum Enum1 { }; enum Enum2 { }; @@ -150,7 +157,7 @@ bool& operator,(X, Y); void test_comma(X x, Y y) { bool& b1 = (x, y); - X& xr = (x, x); + X& xr = (x, x); // expected-warning {{expression result unused}} } struct Callable { diff --git a/test/SemaCXX/pseudo-destructors.cpp b/test/SemaCXX/pseudo-destructors.cpp index 472e5b42fb29d..30d9faac2e284 100644 --- a/test/SemaCXX/pseudo-destructors.cpp +++ b/test/SemaCXX/pseudo-destructors.cpp @@ -14,6 +14,11 @@ namespace N { typedef int OtherInteger; } +template <typename T> +void cv_test(const volatile T* cvt) { + cvt->T::~T(); // no-warning +} + void f(A* a, Foo *f, int *i, double *d) { a->~A(); a->A::~A(); @@ -41,8 +46,14 @@ void f(A* a, Foo *f, int *i, double *d) { i->N::OtherInteger::~Integer(); // expected-error{{'Integer' does not refer to a type name in pseudo-destructor expression; expected the name of type 'int'}} i->N::~Integer(); // expected-error{{'Integer' does not refer to a type name in pseudo-destructor expression; expected the name of type 'int'}} i->Integer::~Double(); // expected-error{{the type of object expression ('int') does not match the type being destroyed ('Double' (aka 'double')) in pseudo-destructor expression}} + + cv_test(a); + cv_test(f); + cv_test(i); + cv_test(d); } + typedef int Integer; void destroy_without_call(int *ip) { @@ -57,3 +68,4 @@ namespace N1 { void test_X0(N1::X0 &x0) { x0.~X0(); } + diff --git a/test/SemaCXX/reinterpret-cast.cpp b/test/SemaCXX/reinterpret-cast.cpp index 45d41e84601a8..f054e528d2d84 100644 --- a/test/SemaCXX/reinterpret-cast.cpp +++ b/test/SemaCXX/reinterpret-cast.cpp @@ -91,8 +91,20 @@ void memptrs() (void)reinterpret_cast<int structure::*>(0); // expected-error {{reinterpret_cast from 'int' to 'int structure::*' is not allowed}} } +namespace PR5545 { // PR5545 class A; class B; void (A::*a)(); void (B::*b)() = reinterpret_cast<void (B::*)()>(a); +} + +// <rdar://problem/8018292> +void const_arrays() { + typedef char STRING[10]; + const STRING *s; + const char *c; + + (void)reinterpret_cast<char *>(s); // expected-error {{reinterpret_cast from 'STRING const *' (aka 'char const (*)[10]') to 'char *' casts away constness}} + (void)reinterpret_cast<const STRING *>(c); +} diff --git a/test/SemaCXX/rval-references.cpp b/test/SemaCXX/rval-references.cpp index d5b465f0786ef..30622ccbfed0b 100644 --- a/test/SemaCXX/rval-references.cpp +++ b/test/SemaCXX/rval-references.cpp @@ -21,6 +21,10 @@ struct conv_to_not_int_rvalue { operator not_int &&(); }; +typedef void (fun_type)(); +void fun(); +fun_type &&make_fun(); + void f() { int &&virr1; // expected-error {{declaration of reference variable 'virr1' requires an initializer}} int &&virr2 = 0; @@ -47,6 +51,9 @@ void f() { not_int &ni5 = cnir; // expected-error{{non-const lvalue reference to type 'not_int' cannot bind to a value of unrelated type 'conv_to_not_int_rvalue'}} not_int &&ni6 = conv_to_not_int_rvalue(); + fun_type &&fun_ref = fun; // works because functions are special + fun_type &&fun_ref2 = make_fun(); // same + fun_type &fun_lref = make_fun(); // also special try { } catch(int&&) { // expected-error {{cannot catch exceptions by rvalue reference}} diff --git a/test/SemaCXX/typedef-redecl.cpp b/test/SemaCXX/typedef-redecl.cpp index 49e1f3aa79e54..7db1970a70edf 100644 --- a/test/SemaCXX/typedef-redecl.cpp +++ b/test/SemaCXX/typedef-redecl.cpp @@ -48,3 +48,9 @@ namespace PR6923 { struct A; } + +namespace PR7462 { + struct A {}; + typedef int operator! (A); // expected-error{{typedef name must be an identifier}} + int i = !A(); // expected-error{{invalid argument type}} +} diff --git a/test/SemaCXX/using-directive.cpp b/test/SemaCXX/using-directive.cpp index 0d5c8400ab7ee..162f7fa07a366 100644 --- a/test/SemaCXX/using-directive.cpp +++ b/test/SemaCXX/using-directive.cpp @@ -121,3 +121,8 @@ extern "C++" { } void f4() { f2(1); } + +// PR7517 +using namespace std; // expected-warning{{using directive refers to implicitly-defined namespace 'std'}} +using namespace ::std; // expected-warning{{using directive refers to implicitly-defined namespace 'std'}} + diff --git a/test/SemaCXX/vector.cpp b/test/SemaCXX/vector.cpp index b548865553c2a..66b2d680d21a6 100644 --- a/test/SemaCXX/vector.cpp +++ b/test/SemaCXX/vector.cpp @@ -186,3 +186,33 @@ void test_implicit_conversions(bool Cond, char16 c16, longlong16 ll16, (void)(Cond? to_c16 : to_ll16); // expected-error{{can't convert between vector values of different size}} (void)(Cond? to_c16e : to_ll16e); // expected-error{{can't convert between vector values of different size}} } + +typedef float fltx2 __attribute__((__vector_size__(8))); +typedef float fltx4 __attribute__((__vector_size__(16))); +typedef double dblx2 __attribute__((__vector_size__(16))); +typedef double dblx4 __attribute__((__vector_size__(32))); + +void accept_fltx2(fltx2); // expected-note{{candidate function not viable: no known conversion from 'double' to 'fltx2' for 1st argument}} +void accept_fltx4(fltx4); +void accept_dblx2(dblx2); +void accept_dblx4(dblx4); +void accept_bool(bool); // expected-note{{candidate function not viable: no known conversion from 'fltx2' to 'bool' for 1st argument}} + +void test(fltx2 fltx2_val, fltx4 fltx4_val, dblx2 dblx2_val, dblx4 dblx4_val) { + // Exact matches + accept_fltx2(fltx2_val); + accept_fltx4(fltx4_val); + accept_dblx2(dblx2_val); + accept_dblx4(dblx4_val); + + // Same-size conversions + // FIXME: G++ rejects these conversions, we accept them. Revisit this! + accept_fltx4(dblx2_val); + accept_dblx2(fltx4_val); + + // Conversion to bool. + accept_bool(fltx2_val); // expected-error{{no matching function for call to 'accept_bool'}} + + // Scalar-to-vector conversions. + accept_fltx2(1.0); // expected-error{{no matching function for call to 'accept_fltx2'}} +} diff --git a/test/SemaCXX/warn-self-comparisons.cpp b/test/SemaCXX/warn-self-comparisons.cpp new file mode 100644 index 0000000000000..620be195c1de0 --- /dev/null +++ b/test/SemaCXX/warn-self-comparisons.cpp @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +void f(int (&array1)[2], int (&array2)[2]) { + if (array1 == array2) { } // no warning +} diff --git a/test/SemaCXX/warn-unreachable.cpp b/test/SemaCXX/warn-unreachable.cpp index 01b36de5712de..f5601cd2df081 100644 --- a/test/SemaCXX/warn-unreachable.cpp +++ b/test/SemaCXX/warn-unreachable.cpp @@ -1,4 +1,4 @@ -// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code -Wno-unused-value +// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wunreachable-code -Wno-unused-value int &halt() __attribute__((noreturn)); int &live(); diff --git a/test/SemaCXX/warn-unused-variables.cpp b/test/SemaCXX/warn-unused-variables.cpp index 5ef7e7002f65a..6992cdcd0902a 100644 --- a/test/SemaCXX/warn-unused-variables.cpp +++ b/test/SemaCXX/warn-unused-variables.cpp @@ -26,7 +26,7 @@ namespace PR5531 { }; void test() { - A(); // expected-warning{{expression result unused}} + A(); B(17); C(); } diff --git a/test/SemaCXX/warn_false_to_pointer.cpp b/test/SemaCXX/warn_false_to_pointer.cpp new file mode 100644 index 0000000000000..3a873d886f0e8 --- /dev/null +++ b/test/SemaCXX/warn_false_to_pointer.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +int* j = false; // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}} + +void foo(int* i, int *j=(false)) // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}} +{ + foo(false); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}} +} + diff --git a/test/SemaCXX/wchar_t.cpp b/test/SemaCXX/wchar_t.cpp index 789dbf643863f..f9d7b614329cc 100644 --- a/test/SemaCXX/wchar_t.cpp +++ b/test/SemaCXX/wchar_t.cpp @@ -25,3 +25,8 @@ int t(void) { basic_string<wchar_t>() + L'-'; return (0); } + + +// rdar://8040728 +wchar_t in[] = L"\x434" "\x434"; // No warning + diff --git a/test/SemaObjC/duplicate-property-class-extension.m b/test/SemaObjC/duplicate-property-class-extension.m index bdf4786c76e8f..a84f83f81fd77 100644 --- a/test/SemaObjC/duplicate-property-class-extension.m +++ b/test/SemaObjC/duplicate-property-class-extension.m @@ -1,13 +1,21 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s @interface Foo -@property (readonly) char foo; +@property (readonly) char foo; // expected-note {{property declared here}} @end @interface Foo () -@property (readwrite) char foo; // expected-note {{property declared here}} +@property (readwrite) char foo; // OK +@property (readwrite) char NewProperty; // expected-note 2 {{property declared here}} @end @interface Foo () -@property (readwrite) char foo; // expected-error {{property has a previous declaration}} +@property (readwrite) char foo; // OK again, make primary property readwrite for 2nd time! +@property (readwrite) char NewProperty; // expected-error {{illegal declaration of property in continuation class 'Foo': attribute must be readwrite, while its primary must be readonly}} @end + +@interface Foo () +@property (readonly) char foo; // expected-error {{illegal declaration of property in continuation class 'Foo': attribute must be readwrite, while its primary must be readonly}} +@property (readwrite) char NewProperty; // expected-error {{illegal declaration of property in continuation class 'Foo': attribute must be readwrite, while its primary must be readonly}} +@end + diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m index 1fcc34f695d80..d89f50afa968a 100644 --- a/test/SemaObjC/format-strings-objc.m +++ b/test/SemaObjC/format-strings-objc.m @@ -55,3 +55,11 @@ void rdar_7068334() { void rdar_7697748() { NSLog(@"%@!"); // expected-warning{{more '%' conversions than data arguments}} } + +@protocol Foo; + +void test_p_conversion_with_objc_pointer(id x, id<Foo> y) { + printf("%p", x); // no-warning + printf("%p", y); // no-warning +} + diff --git a/test/SemaObjC/return.m b/test/SemaObjC/return.m index c578bf3b6569f..116abd19e7e74 100644 --- a/test/SemaObjC/return.m +++ b/test/SemaObjC/return.m @@ -20,3 +20,22 @@ void test3(int a) { // expected-warning {{function could be attribute 'noreturn @throw (id)0; } } + +// <rdar://problem/4289832> - This code always returns, we should not +// issue a noreturn warning. +@class NSException; +@class NSString; +NSString *rdar_4289832() { // no-warning + @try + { + return @"a"; + } + @catch(NSException *exception) + { + return @"b"; + } + @finally + { + } +} + diff --git a/test/SemaObjC/super-class-protocol-conformance.m b/test/SemaObjC/super-class-protocol-conformance.m index ac8bc70a99892..f555c3203dcb9 100644 --- a/test/SemaObjC/super-class-protocol-conformance.m +++ b/test/SemaObjC/super-class-protocol-conformance.m @@ -45,3 +45,19 @@ @interface SubClass5 : SubClass4 <NewProtocol> @end @implementation SubClass5 @end // expected-note {{implementation is here}} + +// Radar 8035776 +@protocol SuperProtocol +@end + +@interface Super <SuperProtocol> +@end + +@protocol ProtocolWithProperty <SuperProtocol> +@property (readonly, assign) id invalidationBacktrace; // expected-warning {{property 'invalidationBacktrace' requires method 'invalidationBacktrace' to be defined}} +@end + +@interface INTF : Super <ProtocolWithProperty> +@end + +@implementation INTF @end // expected-note {{implementation is here}} diff --git a/test/SemaObjCXX/instantiate-message.mm b/test/SemaObjCXX/instantiate-message.mm index 46c8ede26a59f..e09b1829e300c 100644 --- a/test/SemaObjCXX/instantiate-message.mm +++ b/test/SemaObjCXX/instantiate-message.mm @@ -1,4 +1,4 @@ -// RUN: %clang -cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s // Test template instantiation of Objective-C message sends. diff --git a/test/SemaObjCXX/instantiate-method-return.mm b/test/SemaObjCXX/instantiate-method-return.mm new file mode 100644 index 0000000000000..b8ba4af092223 --- /dev/null +++ b/test/SemaObjCXX/instantiate-method-return.mm @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// PR7386 + +@class NSObject; + +class A; +template<class T> class V {}; + +@protocol Protocol +- (V<A*>)protocolMethod; +@end + + +@interface I<Protocol> +@end + + +@implementation I +- (void)randomMethod:(id)info { + V<A*> vec([self protocolMethod]); +} + +- (V<A*>)protocolMethod { + V<A*> va; return va; +} +@end diff --git a/test/SemaObjCXX/message.mm b/test/SemaObjCXX/message.mm index b75608e2327af..76bde6f57cab5 100644 --- a/test/SemaObjCXX/message.mm +++ b/test/SemaObjCXX/message.mm @@ -62,15 +62,15 @@ struct identity { // or typename-specifiers. if (false) { if (true) - return [typename identity<I3>::type method]; + return [typename identity<I3>::type method]; // expected-warning{{occurs outside of a template}} return [::I3 method]; } int* ip1 = {[super method]}; int* ip2 = {[::I3 method]}; - int* ip3 = {[typename identity<I3>::type method]}; - int* ip4 = {[typename identity<I2_holder>::type().get() method]}; + int* ip3 = {[typename identity<I3>::type method]}; // expected-warning{{occurs outside of a template}} + int* ip4 = {[typename identity<I2_holder>::type().get() method]}; // expected-warning{{occurs outside of a template}} int array[5] = {[3] = 2}; return [super method]; } diff --git a/test/SemaObjCXX/objc-pointer-conv.mm b/test/SemaObjCXX/objc-pointer-conv.mm index cc3264fcc4623..af239a8c5b894 100644 --- a/test/SemaObjCXX/objc-pointer-conv.mm +++ b/test/SemaObjCXX/objc-pointer-conv.mm @@ -36,3 +36,11 @@ void foo(const I *p, I* sel) { Func(p); // expected-error {{no matching function for call to 'Func'}} } +@interface DerivedFromI : I +@end + +void accept_derived(DerivedFromI*); // expected-note{{candidate function not viable: cannot convert from superclass 'I *' to subclass 'DerivedFromI *' for 1st argument}} + +void test_base_to_derived(I* i) { + accept_derived(i); // expected-error{{no matching function for call to 'accept_derived'}} +} diff --git a/test/SemaObjCXX/overload.mm b/test/SemaObjCXX/overload.mm index 18da69f5442ea..487a42e1a1103 100644 --- a/test/SemaObjCXX/overload.mm +++ b/test/SemaObjCXX/overload.mm @@ -93,3 +93,12 @@ void (*_NSExceptionRaiser(void))(NSException *) { objc_exception_functions_t exc_funcs; return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(NSException *)', expected 'void (*)(id)'}} } + +namespace test5 { + void foo(bool); + void foo(void *); + + void test(id p) { + foo(p); + } +} diff --git a/test/SemaTemplate/array-to-pointer-decay.cpp b/test/SemaTemplate/array-to-pointer-decay.cpp new file mode 100644 index 0000000000000..072c0e52edc6d --- /dev/null +++ b/test/SemaTemplate/array-to-pointer-decay.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct mystruct { + int member; +}; + +template <int i> +int foo() { + mystruct s[1]; + return s->member; +} + +int main() { + foo<1>(); +} + +// PR7405 +struct hb_sanitize_context_t { + int start; +}; +template <typename Type> static bool sanitize() { + hb_sanitize_context_t c[1]; + return !c->start; +} +bool closure = sanitize<int>(); diff --git a/test/SemaTemplate/attributes.cpp b/test/SemaTemplate/attributes.cpp index b696c5cd98401..f4c1887c25e2c 100644 --- a/test/SemaTemplate/attributes.cpp +++ b/test/SemaTemplate/attributes.cpp @@ -1,8 +1,21 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -template<int N> -struct X { - struct __attribute__((__aligned__((N)))) Aligned { }; // expected-error{{'aligned' attribute requires integer constant}} +namespace attribute_aligned { + template<int N> + struct X { + char c[1] __attribute__((__aligned__((N)))); // expected-error {{alignment is not a power of 2}} + }; - int __attribute__((__address_space__(N))) *ptr; // expected-error{{attribute requires 1 argument(s)}} -}; + template <bool X> struct check { + int check_failed[X ? 1 : -1]; // expected-error {{array size is negative}} + }; + + template <int N> struct check_alignment { + typedef check<N == sizeof(X<N>)> t; // expected-note {{in instantiation}} + }; + + check_alignment<1>::t c1; + check_alignment<2>::t c2; + check_alignment<3>::t c3; // expected-note 2 {{in instantiation}} + check_alignment<4>::t c4; +} diff --git a/test/SemaTemplate/class-template-ctor-initializer.cpp b/test/SemaTemplate/class-template-ctor-initializer.cpp index fd9417c795f6f..81a5e2b9c6624 100644 --- a/test/SemaTemplate/class-template-ctor-initializer.cpp +++ b/test/SemaTemplate/class-template-ctor-initializer.cpp @@ -31,3 +31,25 @@ struct TmplD : Tmpl<char>, TmplB<char> { TmplB<char>() {} }; +namespace PR7259 { + class Base { + public: + Base() {} + }; + + template <class ParentClass> + class Derived : public ParentClass { + public: + Derived() : Base() {} + }; + + class Final : public Derived<Base> { + }; + + int + main (void) + { + Final final(); + return 0; + } +} diff --git a/test/SemaTemplate/deduction.cpp b/test/SemaTemplate/deduction.cpp index 8d00bb796e946..25ffb67492a56 100644 --- a/test/SemaTemplate/deduction.cpp +++ b/test/SemaTemplate/deduction.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only %s +// RUN: %clang_cc1 -fsyntax-only -verify %s // Template argument deduction with template template parameters. template<typename T, template<T> class A> @@ -98,3 +98,10 @@ namespace PR6257 { void f(const X<A>& a); void test(A& a) { (void)f(a); } } + +// PR7463 +namespace PR7463 { + const int f (); // expected-warning{{type qualifier on return type has no effect}} + template <typename T_> void g (T_&); // expected-note{{T_ = int}} + void h (void) { g(f()); } // expected-error{{no matching function for call}} +} diff --git a/test/SemaTemplate/dependent-type-identity.cpp b/test/SemaTemplate/dependent-type-identity.cpp index feffdcf369599..731013c86387e 100644 --- a/test/SemaTemplate/dependent-type-identity.cpp +++ b/test/SemaTemplate/dependent-type-identity.cpp @@ -86,3 +86,15 @@ namespace PR6851 { template <bool w> S< S<w>::cond && 1 > N::foo() { } } + +namespace PR7460 { + template <typename T> + struct TemplateClass2 + { + enum { SIZE = 100 }; + static T member[SIZE]; + }; + + template <typename T> + T TemplateClass2<T>::member[TemplateClass2<T>::SIZE]; +} diff --git a/test/SemaTemplate/destructor-template.cpp b/test/SemaTemplate/destructor-template.cpp index fa1b3e0001c48..6fe7f69cdd5fd 100644 --- a/test/SemaTemplate/destructor-template.cpp +++ b/test/SemaTemplate/destructor-template.cpp @@ -40,3 +40,13 @@ namespace cvquals { template void f<const volatile int>(int *); } + +namespace PR7239 { + template<class E> class A { }; + class B { + void f() { + A<int>* x; + x->A<int>::~A<int>(); + } + }; +} diff --git a/test/SemaTemplate/example-dynarray.cpp b/test/SemaTemplate/example-dynarray.cpp index 1f6ede67a5225..999521e91e5f2 100644 --- a/test/SemaTemplate/example-dynarray.cpp +++ b/test/SemaTemplate/example-dynarray.cpp @@ -1,4 +1,4 @@ -// RUN: %clang -emit-llvm -S -o %t %s +// RUN: %clangxx -emit-llvm -c -o - %s #include <stddef.h> #include <stdlib.h> #include <assert.h> diff --git a/test/SemaTemplate/explicit-instantiation.cpp b/test/SemaTemplate/explicit-instantiation.cpp index de51f0992baa3..3a1446e8dd673 100644 --- a/test/SemaTemplate/explicit-instantiation.cpp +++ b/test/SemaTemplate/explicit-instantiation.cpp @@ -83,3 +83,16 @@ namespace explicit_instantiation_after_implicit_instantiation { void test1() { (void)&X0<1>::x; } template struct X0<1>; } + +namespace PR7622 { // expected-note{{to match this}} + template<typename,typename=int> + struct basic_streambuf; + + // FIXME: Very poor recovery here. + template<typename,typename> + struct basic_streambuf{friend bob<>()}; // expected-error{{unknown type name 'bob'}} \ + // expected-error{{ expected member name or ';' after declaration specifiers}} + template struct basic_streambuf<int>; // expected-error{{explicit instantiation of 'basic_streambuf' in class scope}} +} // expected-error{{expected ';' after struct}} + +//expected-error{{expected '}'}} diff --git a/test/SemaTemplate/ext-vector-type.cpp b/test/SemaTemplate/ext-vector-type.cpp index 3973102b92e7b..7334e88e9267d 100644 --- a/test/SemaTemplate/ext-vector-type.cpp +++ b/test/SemaTemplate/ext-vector-type.cpp @@ -20,7 +20,7 @@ int test_make2() { template<typename T, unsigned Length> struct make3 { - typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector type 's'}} + typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type 's'}} }; struct s {}; @@ -42,7 +42,7 @@ int test_make4() { typedef int* int_ptr; template<unsigned Length> struct make5 { - typedef int_ptr __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector type}} + typedef int_ptr __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type}} }; template<int Length> diff --git a/test/SemaTemplate/instantiate-field.cpp b/test/SemaTemplate/instantiate-field.cpp index a260635778ca2..d825cd7cc613c 100644 --- a/test/SemaTemplate/instantiate-field.cpp +++ b/test/SemaTemplate/instantiate-field.cpp @@ -81,3 +81,12 @@ namespace PR7123 { sort(x,x); } } + +namespace PR7355 { + template<typename T1> class A { + class D; // expected-note{{declared here}} + D d; //expected-error{{implicit instantiation of undefined member 'PR7355::A<int>::D'}} + }; + + A<int> ai; // expected-note{{in instantiation of}} +} diff --git a/test/SemaTemplate/instantiate-function-1.cpp b/test/SemaTemplate/instantiate-function-1.cpp index 1bda43000b2a5..a293e9a788dec 100644 --- a/test/SemaTemplate/instantiate-function-1.cpp +++ b/test/SemaTemplate/instantiate-function-1.cpp @@ -39,11 +39,11 @@ template struct X3<int>; template <typename T> struct X4 { T f() const { - return; // expected-warning{{non-void function 'f' should return a value}} + return; // expected-error{{non-void function 'f' should return a value}} } T g() const { - return 1; // expected-warning{{void function 'g' should not return a value}} + return 1; // expected-error{{void function 'g' should not return a value}} } }; diff --git a/test/SemaTemplate/instantiate-function-2.cpp b/test/SemaTemplate/instantiate-function-2.cpp index afca358784442..ebc0ef3a9f961 100644 --- a/test/SemaTemplate/instantiate-function-2.cpp +++ b/test/SemaTemplate/instantiate-function-2.cpp @@ -20,3 +20,14 @@ namespace PR7184 { template void f<int>(); } + +namespace UsedAttr { + template<typename T> + void __attribute__((used)) foo() { + T *x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} + } + + void bar() { + foo<int>(); // expected-note{{instantiation of}} + } +} diff --git a/test/SemaTemplate/instantiate-member-template.cpp b/test/SemaTemplate/instantiate-member-template.cpp index ae8425e716ee6..24a3f317e636f 100644 --- a/test/SemaTemplate/instantiate-member-template.cpp +++ b/test/SemaTemplate/instantiate-member-template.cpp @@ -156,3 +156,36 @@ namespace PR6239 { }; } + +namespace PR7587 { + template<typename> class X0; + template<typename> struct X1; + template<typename> class X2; + + template<typename T> class X3 + { + template< + template<typename> class TT, + typename U = typename X1<T>::type + > + struct Inner { + typedef X2<TT<typename X1<T>::type> > Type; + }; + + const typename Inner<X0>::Type minCoeff() const; + }; + + template<typename T> class X3<T*> + { + template< + template<typename> class TT, + typename U = typename X1<T>::type + > + struct Inner { + typedef X2<TT<typename X1<T>::type> > Type; + }; + + const typename Inner<X0>::Type minCoeff() const; + }; + +} diff --git a/test/SemaTemplate/instantiate-objc-1.mm b/test/SemaTemplate/instantiate-objc-1.mm index 92d0d6c95080a..2780f8e579783 100644 --- a/test/SemaTemplate/instantiate-objc-1.mm +++ b/test/SemaTemplate/instantiate-objc-1.mm @@ -45,3 +45,4 @@ template <typename T> struct EncodeTest { template struct EncodeTest<int>; template struct EncodeTest<double>; +template struct EncodeTest<wchar_t>; diff --git a/test/SemaTemplate/member-function-template.cpp b/test/SemaTemplate/member-function-template.cpp index aea62855c2255..44954ed881abd 100644 --- a/test/SemaTemplate/member-function-template.cpp +++ b/test/SemaTemplate/member-function-template.cpp @@ -85,3 +85,19 @@ namespace TTP { void test_f(X<3> x, Y<int> y) { x.f(y); } } + +namespace PR7387 { + template <typename T> struct X {}; + + template <typename T1> struct S { + template <template <typename> class TC> void foo(const TC<T1>& arg); + }; + + template <typename T1> template <template <typename> class TC> + void S<T1>::foo(const TC<T1>& arg) {} + + void test(const X<int>& x) { + S<int> s; + s.foo(x); + } +} diff --git a/test/SemaTemplate/nested-name-spec-template.cpp b/test/SemaTemplate/nested-name-spec-template.cpp index 54e615b4ab692..12ab48680915b 100644 --- a/test/SemaTemplate/nested-name-spec-template.cpp +++ b/test/SemaTemplate/nested-name-spec-template.cpp @@ -21,7 +21,8 @@ namespace N { } M::Promote<int>::type *ret_intptr3(int* ip) { return ip; } - M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } + M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } // expected-warning{{'template' keyword outside of a template}} + M::template Promote<int> pi; // expected-warning{{'template' keyword outside of a template}} } N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; } @@ -71,3 +72,19 @@ namespace N1 { } template<typename T> T N1::f0() { } + +namespace PR7385 { + template< typename > struct has_xxx0 + { + template< typename > struct has_xxx0_introspect + { + template< typename > struct has_xxx0_substitute ; + template< typename V > + int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 ); + }; + static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}} + typedef int type; + }; + + has_xxx0<int>::type t; // expected-note{{instantiation of}} +} diff --git a/test/SemaTemplate/self-comparison.cpp b/test/SemaTemplate/self-comparison.cpp new file mode 100644 index 0000000000000..50ab660e651b9 --- /dev/null +++ b/test/SemaTemplate/self-comparison.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template <int A, int B> void foo() { + (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} + (void)(A == B); +} +template <int A, int B> struct S1 { + void foo() { + (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} + (void)(A == B); + } +}; + +template <int A, int B> struct S2 { + template <typename T> T foo() { + (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} + (void)(A == B); + } +}; + +struct S3 { + template <int A, int B> void foo() { + (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} + (void)(A == B); + } +}; + +template <int A> struct S4 { + template <int B> void foo() { + (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} + (void)(A == B); + } +}; + +const int N = 42; +template <int X> void foo2() { + (void)(X == N); + (void)(N == X); +} + +void test() { + foo<1, 1>(); + S1<1, 1> s1; s1.foo(); + S2<1, 1> s2; s2.foo<void>(); + S3 s3; s3.foo<1, 1>(); + S4<1> s4; s4.foo<1>(); + foo2<N>(); +} diff --git a/test/SemaTemplate/typename-specifier-4.cpp b/test/SemaTemplate/typename-specifier-4.cpp index 8dfb60d707189..5a313bf2256a2 100644 --- a/test/SemaTemplate/typename-specifier-4.cpp +++ b/test/SemaTemplate/typename-specifier-4.cpp @@ -27,7 +27,8 @@ struct make_pair { int a0[is_same<metafun_apply2<make_pair, int, float>::type, pair<int, float> >::value? 1 : -1]; int a1[is_same< - typename make_pair::template apply<int, float>, + typename make_pair::template apply<int, float>, // expected-warning{{'template' keyword outside of a template}} \ + // expected-warning{{'typename' occurs outside of a template}} make_pair::apply<int, float> >::value? 1 : -1]; diff --git a/test/SemaTemplate/typename-specifier.cpp b/test/SemaTemplate/typename-specifier.cpp index 3f6fe343f5079..4c788f6a8a3cd 100644 --- a/test/SemaTemplate/typename-specifier.cpp +++ b/test/SemaTemplate/typename-specifier.cpp @@ -15,19 +15,22 @@ namespace N { int i; -typename N::A::type *ip1 = &i; -typename N::B::type *ip2 = &i; // expected-error{{no type named 'type' in 'N::B'}} -typename N::C::type *ip3 = &i; // expected-error{{typename specifier refers to non-type member 'type'}} +typename N::A::type *ip1 = &i; // expected-warning{{'typename' occurs outside of a template}} +typename N::B::type *ip2 = &i; // expected-error{{no type named 'type' in 'N::B'}} \ +// expected-warning{{'typename' occurs outside of a template}} +typename N::C::type *ip3 = &i; // expected-error{{typename specifier refers to non-type member 'type'}} \ +// expected-warning{{'typename' occurs outside of a template}} void test(double d) { - typename N::A::type f(typename N::A::type(a)); // expected-warning{{parentheses were disambiguated as a function declarator}} + typename N::A::type f(typename N::A::type(a)); // expected-warning{{parentheses were disambiguated as a function declarator}} \ + // expected-warning 2{{'typename' occurs outside of a template}} int five = f(5); using namespace N; - for (typename A::type i = 0; i < 10; ++i) + for (typename A::type i = 0; i < 10; ++i) // expected-warning{{'typename' occurs outside of a template}} five += 1; - const typename N::A::type f2(d); + const typename N::A::type f2(d); // expected-warning{{'typename' occurs outside of a template}} } namespace N { diff --git a/test/lit.cfg b/test/lit.cfg index b306331703ea2..42de5cbc5f92c 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -128,7 +128,8 @@ config.clang = inferClang(config.environment['PATH']) if not lit.quiet: lit.note('using clang: %r' % config.clang) config.substitutions.append( ('%clang_cc1', config.clang + ' -cc1') ) -config.substitutions.append( ('%clangxx', ' ' + config.clang + ' -ccc-cxx')) +config.substitutions.append( ('%clangxx', ' ' + config.clang + + ' -ccc-clang-cxx -ccc-cxx ')) config.substitutions.append( ('%clang', ' ' + config.clang + ' ') ) # FIXME: Find nicer way to prohibit this. @@ -142,3 +143,6 @@ config.substitutions.append( config.substitutions.append( (' clang -cc1 ', """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") ) +config.substitutions.append( + (' %clang-cc1 ', + """*** invalid substitution, use '%clang_cc1'. ***""") ) |