diff options
author | dim <dim@FreeBSD.org> | 2011-07-17 15:40:56 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-07-17 15:40:56 +0000 |
commit | 611ba3ea3300b71eb95dc4e45f20eee5dddd32e1 (patch) | |
tree | 2097d084eb235c0b12c0bff3445f4ec7bbaa8a12 /test | |
parent | c49018d9cce52d8c9f34b44865ec3ba8e89a1488 (diff) | |
download | FreeBSD-src-611ba3ea3300b71eb95dc4e45f20eee5dddd32e1.zip FreeBSD-src-611ba3ea3300b71eb95dc4e45f20eee5dddd32e1.tar.gz |
Vendor import of clang trunk r135360:
http://llvm.org/svn/llvm-project/cfe/trunk@135360
Diffstat (limited to 'test')
428 files changed, 12737 insertions, 800 deletions
diff --git a/test/ARCMT/Common.h b/test/ARCMT/Common.h new file mode 100644 index 0000000..c57f3e7 --- /dev/null +++ b/test/ARCMT/Common.h @@ -0,0 +1,55 @@ +#if __has_feature(objc_arr) +#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode"))) +#else +#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE +#endif + +typedef int BOOL; +typedef unsigned NSUInteger; +typedef int int32_t; +typedef unsigned char uint8_t; +typedef int32_t UChar32; +typedef unsigned char UChar; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +@end + +@interface NSObject <NSObject> {} +- (id)init; + ++ (id)new; ++ (id)alloc; +- (void)dealloc; + +- (void)finalize; + +- (id)copy; +- (id)mutableCopy; +@end + +NS_AUTOMATED_REFCOUNT_UNAVAILABLE +@interface NSAutoreleasePool : NSObject { +@private + void *_token; + void *_reserved3; + void *_reserved2; + void *_reserved; +} + ++ (void)addObject:(id)anObject; + +- (void)addObject:(id)anObject; + +- (void)drain; + +@end + +typedef const void* objc_objectptr_t; +extern __attribute__((ns_returns_retained)) id objc_retainedObject(objc_objectptr_t __attribute__((cf_consumed)) pointer); +extern __attribute__((ns_returns_not_retained)) id objc_unretainedObject(objc_objectptr_t pointer); +extern objc_objectptr_t objc_unretainedPointer(id object); diff --git a/test/ARCMT/Inputs/test.h b/test/ARCMT/Inputs/test.h new file mode 100644 index 0000000..756295f --- /dev/null +++ b/test/ARCMT/Inputs/test.h @@ -0,0 +1,15 @@ +@protocol NSObject +- (oneway void)release; +@end + +#ifdef PART1 +static inline void part1(id p) { + [p release]; +} +#endif + +#ifdef PART2 +static inline void part2(id p) { + [p release]; +} +#endif diff --git a/test/ARCMT/Inputs/test.h.result b/test/ARCMT/Inputs/test.h.result new file mode 100644 index 0000000..0638a33 --- /dev/null +++ b/test/ARCMT/Inputs/test.h.result @@ -0,0 +1,13 @@ +@protocol NSObject +- (oneway void)release; +@end + +#ifdef PART1 +static inline void part1(id p) { +} +#endif + +#ifdef PART2 +static inline void part2(id p) { +} +#endif diff --git a/test/ARCMT/Inputs/test1.m.in b/test/ARCMT/Inputs/test1.m.in new file mode 100644 index 0000000..8416a88 --- /dev/null +++ b/test/ARCMT/Inputs/test1.m.in @@ -0,0 +1,6 @@ +#define PART1 +#include "test.h" + +void test1(id p) { + [p release]; +} diff --git a/test/ARCMT/Inputs/test1.m.in.result b/test/ARCMT/Inputs/test1.m.in.result new file mode 100644 index 0000000..f351fe6 --- /dev/null +++ b/test/ARCMT/Inputs/test1.m.in.result @@ -0,0 +1,5 @@ +#define PART1 +#include "test.h" + +void test1(id p) { +} diff --git a/test/ARCMT/Inputs/test2.m.in b/test/ARCMT/Inputs/test2.m.in new file mode 100644 index 0000000..99f87b0 --- /dev/null +++ b/test/ARCMT/Inputs/test2.m.in @@ -0,0 +1,6 @@ +#define PART2 +#include "test.h" + +void test2(id p) { + [p release]; +} diff --git a/test/ARCMT/Inputs/test2.m.in.result b/test/ARCMT/Inputs/test2.m.in.result new file mode 100644 index 0000000..f8e918c --- /dev/null +++ b/test/ARCMT/Inputs/test2.m.in.result @@ -0,0 +1,5 @@ +#define PART2 +#include "test.h" + +void test2(id p) { +} diff --git a/test/ARCMT/assign-prop-no-arc-runtime.m b/test/ARCMT/assign-prop-no-arc-runtime.m new file mode 100644 index 0000000..0baa1d2 --- /dev/null +++ b/test/ARCMT/assign-prop-no-arc-runtime.m @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fobjc-nonfragile-abi -fsyntax-only %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface Foo : NSObject { + NSObject *x; +} +@property (readonly,assign) id x; +@end + +@implementation Foo +@synthesize x; +@end diff --git a/test/ARCMT/assign-prop-no-arc-runtime.m.result b/test/ARCMT/assign-prop-no-arc-runtime.m.result new file mode 100644 index 0000000..49e91d8 --- /dev/null +++ b/test/ARCMT/assign-prop-no-arc-runtime.m.result @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fobjc-nonfragile-abi -fsyntax-only %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface Foo : NSObject { + NSObject *__unsafe_unretained x; +} +@property (readonly,unsafe_unretained) id x; +@end + +@implementation Foo +@synthesize x; +@end diff --git a/test/ARCMT/assign-prop-with-arc-runtime.m b/test/ARCMT/assign-prop-with-arc-runtime.m new file mode 100644 index 0000000..4e4ae77 --- /dev/null +++ b/test/ARCMT/assign-prop-with-arc-runtime.m @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fobjc-nonfragile-abi -fsyntax-only %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface WeakOptOut +@end + +@class _NSCachedAttributedString; +typedef _NSCachedAttributedString *BadClassForWeak; + +@class Forw; + +@interface Foo : NSObject { + Foo *x, *w, *q1, *q2; + WeakOptOut *oo; + BadClassForWeak bcw; + id not_safe1; + NSObject *not_safe2; + Forw *not_safe3; +} +@property (readonly,assign) Foo *x; +@property (assign) Foo *w; +@property Foo *q1, *q2; +@property (assign) WeakOptOut *oo; +@property (assign) BadClassForWeak bcw; +@property (assign) id not_safe1; +@property () NSObject *not_safe2; +@property Forw *not_safe3; + +@property (assign) Foo *no_user_ivar1; +@property (readonly) Foo *no_user_ivar2; +@end + +@implementation Foo +@synthesize x,w,q1,q2,oo,bcw,not_safe1,not_safe2,not_safe3; +@synthesize no_user_ivar1, no_user_ivar2; +@end diff --git a/test/ARCMT/assign-prop-with-arc-runtime.m.result b/test/ARCMT/assign-prop-with-arc-runtime.m.result new file mode 100644 index 0000000..eb34c16 --- /dev/null +++ b/test/ARCMT/assign-prop-with-arc-runtime.m.result @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fobjc-nonfragile-abi -fsyntax-only %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface WeakOptOut +@end + +@class _NSCachedAttributedString; +typedef _NSCachedAttributedString *BadClassForWeak; + +@class Forw; + +@interface Foo : NSObject { + Foo *__weak x, *__weak w, *__weak q1, *__weak q2; + WeakOptOut *__unsafe_unretained oo; + BadClassForWeak __unsafe_unretained bcw; + id __unsafe_unretained not_safe1; + NSObject *__unsafe_unretained not_safe2; + Forw *__unsafe_unretained not_safe3; +} +@property (readonly,weak) Foo *x; +@property (weak) Foo *w; +@property (weak) Foo *q1, *q2; +@property (unsafe_unretained) WeakOptOut *oo; +@property (unsafe_unretained) BadClassForWeak bcw; +@property (unsafe_unretained) id not_safe1; +@property (unsafe_unretained) NSObject *not_safe2; +@property (unsafe_unretained) Forw *not_safe3; + +@property (weak) Foo *no_user_ivar1; +@property (weak, readonly) Foo *no_user_ivar2; +@end + +@implementation Foo +@synthesize x,w,q1,q2,oo,bcw,not_safe1,not_safe2,not_safe3; +@synthesize no_user_ivar1, no_user_ivar2; +@end diff --git a/test/ARCMT/atautorelease-2.m b/test/ARCMT/atautorelease-2.m new file mode 100644 index 0000000..5d29772 --- /dev/null +++ b/test/ARCMT/atautorelease-2.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +@interface NSAutoreleasePool +- drain; ++new; ++alloc; +-init; +-autorelease; +-release; +@end + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *chunkPool = [[NSAutoreleasePool alloc] init]; + + while (argc) { + [chunkPool release]; + return 0; + } + + [chunkPool drain]; + [pool drain]; + + return 0; +} diff --git a/test/ARCMT/atautorelease-2.m.result b/test/ARCMT/atautorelease-2.m.result new file mode 100644 index 0000000..7bb1647 --- /dev/null +++ b/test/ARCMT/atautorelease-2.m.result @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +@interface NSAutoreleasePool +- drain; ++new; ++alloc; +-init; +-autorelease; +-release; +@end + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + @autoreleasepool { + @autoreleasepool { + + while (argc) { + return 0; + } + + } + } + + return 0; +} diff --git a/test/ARCMT/atautorelease-3.m b/test/ARCMT/atautorelease-3.m new file mode 100644 index 0000000..5d71c33 --- /dev/null +++ b/test/ARCMT/atautorelease-3.m @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +@interface NSAutoreleasePool +- drain; ++new; ++alloc; +-init; +-autorelease; +- release; +@end + +void NSLog(id, ...); + +void test1(int x) { + // All this stuff get removed since nothing is happening inside. + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *chunkPool = [[NSAutoreleasePool alloc] init]; + while (x) { + chunkPool = [[NSAutoreleasePool alloc] init]; + [chunkPool release]; + } + + [chunkPool drain]; + [pool drain]; +} + +void test2(int x) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *chunkPool = [[NSAutoreleasePool alloc] init]; + while (x) { + chunkPool = [[NSAutoreleasePool alloc] init]; + ++x; + [chunkPool release]; + } + + [chunkPool drain]; + [pool drain]; +} diff --git a/test/ARCMT/atautorelease-3.m.result b/test/ARCMT/atautorelease-3.m.result new file mode 100644 index 0000000..682118e --- /dev/null +++ b/test/ARCMT/atautorelease-3.m.result @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +@interface NSAutoreleasePool +- drain; ++new; ++alloc; +-init; +-autorelease; +- release; +@end + +void NSLog(id, ...); + +void test1(int x) { + // All this stuff get removed since nothing is happening inside. +} + +void test2(int x) { + @autoreleasepool { + @autoreleasepool { + while (x) { + @autoreleasepool { + ++x; + } + } + + } + } +} diff --git a/test/ARCMT/atautorelease-check.m b/test/ARCMT/atautorelease-check.m new file mode 100644 index 0000000..6528f3e --- /dev/null +++ b/test/ARCMT/atautorelease-check.m @@ -0,0 +1,144 @@ +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi %s + +#if __has_feature(objc_arr) +#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode"))) +#else +#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE +#endif + +typedef struct _NSZone NSZone; +typedef int BOOL; +typedef unsigned NSUInteger; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE; + +- (NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +@end + +@protocol NSCopying +- (id)copyWithZone:(NSZone *)zone; +@end + +@protocol NSMutableCopying +- (id)mutableCopyWithZone:(NSZone *)zone; +@end + +@interface NSObject <NSObject> {} +- (id)init; + ++ (id)new; ++ (id)allocWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; ++ (id)alloc; +- (void)dealloc; + +- (void)finalize; + +- (id)copy; +- (id)mutableCopy; + ++ (id)copyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; ++ (id)mutableCopyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +@end + +extern void NSRecycleZone(NSZone *zone); + +NS_AUTOMATED_REFCOUNT_UNAVAILABLE +@interface NSAutoreleasePool : NSObject { // expected-note 13 {{marked unavailable here}} +@private + void *_token; + void *_reserved3; + void *_reserved2; + void *_reserved; +} + ++ (void)addObject:(id)anObject; + +- (void)addObject:(id)anObject; + +- (void)drain; + +@end + + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *chunkPool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} + + while (argc) { + [chunkPool release]; + // the following pool was not released in this scope, don't touch it. + chunkPool = [[NSAutoreleasePool alloc] init]; // expected-error {{'NSAutoreleasePool' is unavailable}} + } + + [chunkPool drain]; + [pool drain]; + + return 0; +} + +void f(void) { + NSAutoreleasePool * pool; // expected-error {{'NSAutoreleasePool' is unavailable}} + + for (int i=0; i != 10; ++i) { + id x = pool; // We won't touch a NSAutoreleasePool if we can't safely + // remove all the references to it. + } + + pool = [[NSAutoreleasePool alloc] init]; // expected-error {{'NSAutoreleasePool' is unavailable}} + NSLog(@"%s", "YES"); + [pool release]; +} + +void f2(void) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \ + // expected-note {{scope begins here}} + + // 'x' is declared inside the "pool scope" but used outside it, if we create + // a @autorelease scope it will be undefined outside it so don't touch the pool. + int x = 0; // expected-note {{declared here}} + + [pool release]; // expected-note {{scope ends here}} + + ++x; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}} +} + +void f3(void) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \ + // expected-note {{scope begins here}} + + struct S { int x; }; // expected-note {{declared here}} + + [pool release]; // expected-note {{scope ends here}} + + struct S *var; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}} + var->x = 0; +} + +void f4(void) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \ + // expected-note {{scope begins here}} + + enum { Bar }; // expected-note {{declared here}} + + [pool release]; // expected-note {{scope ends here}} + + int x = Bar; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}} +} + +void f5(void) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \ + // expected-note {{scope begins here}} + + typedef int Bar; // expected-note {{declared here}} + + [pool release]; // expected-note {{scope ends here}} + + Bar x; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}} +} diff --git a/test/ARCMT/atautorelease.m b/test/ARCMT/atautorelease.m new file mode 100644 index 0000000..bdf7719 --- /dev/null +++ b/test/ARCMT/atautorelease.m @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + if (argc) { + NSAutoreleasePool * pool = [NSAutoreleasePool new]; + NSLog(@"%s", "YES"); + [pool drain]; + } + [pool drain]; + + NSAutoreleasePool * pool1 = [[NSAutoreleasePool alloc] init]; + NSLog(@"%s", "YES"); + [pool1 release]; + + return 0; +} + +void f(void) { + NSAutoreleasePool *pool1; + + pool1 = [NSAutoreleasePool new]; + int x = 4; + + NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init]; + ++x; + [pool2 drain]; + + [pool1 release]; +} + +int UIApplicationMain(int argc, char *argv[]); + +int main2(int argc, char *argv[]) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + int result = UIApplicationMain(argc, argv); + [pool release]; + return result; +} diff --git a/test/ARCMT/atautorelease.m.result b/test/ARCMT/atautorelease.m.result new file mode 100644 index 0000000..ccce1bd --- /dev/null +++ b/test/ARCMT/atautorelease.m.result @@ -0,0 +1,46 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + + @autoreleasepool { + + if (argc) { + @autoreleasepool { + NSLog(@"%s", "YES"); + } + } + } + + @autoreleasepool { + NSLog(@"%s", "YES"); + } + + return 0; +} + +void f(void) { + + @autoreleasepool { + int x = 4; + + @autoreleasepool { + ++x; + } + + } +} + +int UIApplicationMain(int argc, char *argv[]); + +int main2(int argc, char *argv[]) { + @autoreleasepool { + int result = UIApplicationMain(argc, argv); + return result; + } +} diff --git a/test/ARCMT/autoreleases.m b/test/ARCMT/autoreleases.m new file mode 100644 index 0000000..a12db81 --- /dev/null +++ b/test/ARCMT/autoreleases.m @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +typedef unsigned char BOOL; + +@interface NSObject { + id isa; +} ++new; ++alloc; +-init; +-autorelease; +@end + +@interface NSAutoreleasePool : NSObject +- drain; +@end + +@interface A : NSObject { +@package + id object; +} +@end + +@interface B : NSObject +- (BOOL)containsSelf:(A*)a; +@end + +@implementation A +@end + +@implementation B +- (BOOL)containsSelf:(A*)a { + return a->object == self; +} +@end + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + A *a = [[A new] autorelease]; + B *b = [[B new] autorelease]; + NSLog(@"%s", [b containsSelf:a] ? "YES" : "NO"); + [pool drain]; + return 0; +} diff --git a/test/ARCMT/autoreleases.m.result b/test/ARCMT/autoreleases.m.result new file mode 100644 index 0000000..796bfbb --- /dev/null +++ b/test/ARCMT/autoreleases.m.result @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +typedef unsigned char BOOL; + +@interface NSObject { + id isa; +} ++new; ++alloc; +-init; +-autorelease; +@end + +@interface NSAutoreleasePool : NSObject +- drain; +@end + +@interface A : NSObject { +@package + id object; +} +@end + +@interface B : NSObject +- (BOOL)containsSelf:(A*)a; +@end + +@implementation A +@end + +@implementation B +- (BOOL)containsSelf:(A*)a { + return a->object == self; +} +@end + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + @autoreleasepool { + A *a = [A new]; + B *b = [B new]; + NSLog(@"%s", [b containsSelf:a] ? "YES" : "NO"); + } + return 0; +} diff --git a/test/ARCMT/checking.m b/test/ARCMT/checking.m new file mode 100644 index 0000000..eea7a9f --- /dev/null +++ b/test/ARCMT/checking.m @@ -0,0 +1,295 @@ +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi %s + +#include "Common.h" + +typedef const struct __CFString * CFStringRef; +extern const CFStringRef kUTTypePlainText; +extern const CFStringRef kUTTypeRTF; +@class NSString; +@class A; + +struct UnsafeS { + A *__unsafe_unretained unsafeObj; +}; + +@interface A : NSObject +- (id)retain; +- (id)retainCount; +- (id)autorelease; +- (id)init; +- (oneway void)release; +- (void)dealloc; +-(void)test; +-(id)delegate; +@end + +@implementation A +-(void)test { + [super dealloc]; +} +-(void)dealloc { + [super dealloc]; +} + +- (id)retain { return self; } // expected-error {{ARC forbids implementation}} +- (id)retainCount { return self; } // expected-error {{ARC forbids implementation}} +- (id)autorelease { return self; } // expected-error {{ARC forbids implementation}} +- (oneway void)release { } // expected-error {{ARC forbids implementation}} + +-(id)delegate { return self; } +@end + +id global_foo; + +void test1(A *a, BOOL b, struct UnsafeS *unsafeS) { + [[a delegate] release]; // expected-error {{it is not safe to remove 'retain' message on the result of a 'delegate' message; the object that was passed to 'setDelegate:' may not be properly retained}} \ + // expected-error {{ARC forbids explicit message send}} + [a.delegate release]; // expected-error {{it is not safe to remove 'retain' message on the result of a 'delegate' message; the object that was passed to 'setDelegate:' may not be properly retained}} \ + // expected-error {{ARC forbids explicit message send}} + [unsafeS->unsafeObj retain]; // expected-error {{it is not safe to remove 'retain' message on an __unsafe_unretained type}} \ + // expected-error {{ARC forbids explicit message send}} + id foo = [unsafeS->unsafeObj retain]; // no warning. + [global_foo retain]; // expected-error {{it is not safe to remove 'retain' message on a global variable}} \ + // expected-error {{ARC forbids explicit message send}} + [global_foo release]; // expected-error {{it is not safe to remove 'release' message on a global variable}} \ + // expected-error {{ARC forbids explicit message send}} + [a dealloc]; + [a retain]; + [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}} + [a release]; + [a autorelease]; // expected-error {{it is not safe to remove an unused 'autorelease' message; its receiver may be destroyed immediately}} \ + // expected-error {{ARC forbids explicit message send}} + + CFStringRef cfstr; + NSString *str = (NSString *)cfstr; // expected-error {{cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \ + // expected-note{{use __bridge to convert directly (no change in ownership)}} \ + // expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}} + str = (NSString *)kUTTypePlainText; + str = b ? kUTTypeRTF : kUTTypePlainText; + str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText); + str = (NSString *)a; // no change. + + SEL s = @selector(retain); // expected-error {{ARC forbids use of 'retain' in a @selector}} + s = @selector(release); // expected-error {{ARC forbids use of 'release' in a @selector}} + s = @selector(autorelease); // expected-error {{ARC forbids use of 'autorelease' in a @selector}} + s = @selector(dealloc); // expected-error {{ARC forbids use of 'dealloc' in a @selector}} + + static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} +} + +struct S { + A* a; // expected-error {{ARC forbids Objective-C objects in structs or unions}} +}; + +@interface B +-(id)alloc; +- (id)initWithInt: (int) i; +@end + +void rdar8861761() { + B *o1 = [[B alloc] initWithInt:0]; + B *o2 = [B alloc]; + [o2 initWithInt:0]; +} + +@interface Test13 +- (id) init0; +- (void) noninit; +@end +@implementation Test13 +- (id) init0 { + self = 0; +} +- (void) noninit { + self = 0; // expected-error {{cannot assign to 'self' outside of a method in the init family}} + + for (id x in collection) { // expected-error {{use of undeclared identifier 'collection'}} + x = 0; + } +} +@end + +void * cvt(id arg) +{ + void* voidp_val; + (void)(int*)arg; // expected-error {{disallowed}} + (void)(id)arg; + (void)(__autoreleasing id*)arg; // expected-error {{disallowed}} + (void)(id*)arg; // expected-error {{disallowed}} + + (void)(__autoreleasing id**)voidp_val; + (void)(void*)voidp_val; + (void)(void**)arg; // expected-error {{disallowed}} + cvt((void*)arg); // expected-error {{requires a bridged cast}} expected-error {{disallowed}} \ + // expected-note {{use __bridge}} expected-note {{use __bridge_retained}} + cvt(0); + (void)(__strong id**)(0); + return arg; // expected-error {{disallowed}} +} + + +void test12(id collection) { + for (id x in collection) { + x = 0; + } + + for (__strong id x in collection) { + x = 0; + } +} + +void test6(unsigned cond) { + // FIXME: Fix this automatically ? + switch (cond) { + case 0: + ; + id x; // expected-note {{jump bypasses initialization of retaining variable}} + + case 1: // expected-error {{switch case is in protected scope}} + break; + } +} + +@class Test8_incomplete; +@interface Test8_complete @end; +@interface Test8_super @end; +@interface Test8 : Test8_super +- (id) init00; +- (id) init01; // expected-note {{declaration in interface}} +- (id) init02; +- (id) init03; // covariance +- (id) init04; // covariance +- (id) init05; + +- (void) init10; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} +- (void) init11; +- (void) init12; +- (void) init13; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} +- (void) init14; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} +- (void) init15; + +// These should be invalid to actually call. +- (Test8_incomplete*) init20; +- (Test8_incomplete*) init21; // expected-note {{declaration in interface}} +- (Test8_incomplete*) init22; +- (Test8_incomplete*) init23; +- (Test8_incomplete*) init24; +- (Test8_incomplete*) init25; + +- (Test8_super*) init30; // id exception to covariance +- (Test8_super*) init31; // expected-note {{declaration in interface}} +- (Test8_super*) init32; +- (Test8_super*) init33; +- (Test8_super*) init34; // covariance +- (Test8_super*) init35; + +- (Test8*) init40; // id exception to covariance +- (Test8*) init41; // expected-note {{declaration in interface}} +- (Test8*) init42; +- (Test8*) init43; // this should be a warning, but that's a general language thing, not an ARC thing +- (Test8*) init44; +- (Test8*) init45; + +- (Test8_complete*) init50; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init51; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init52; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init53; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init54; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init55; // expected-error {{init methods must return a type related to the receiver type}} +@end +@implementation Test8 +- (id) init00 { return 0; } +- (id) init10 { return 0; } // expected-error {{method implementation does not match its declaration}} +- (id) init20 { return 0; } +- (id) init30 { return 0; } +- (id) init40 { return 0; } +- (id) init50 { return 0; } + +- (void) init01 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} +- (void) init11 {} +- (void) init21 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} +- (void) init31 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} +- (void) init41 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} +- (void) init51 {} + +- (Test8_incomplete*) init02 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init12 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init22 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init32 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init42 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init52 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} + +- (Test8_super*) init03 { return 0; } +- (Test8_super*) init13 { return 0; } // expected-error {{method implementation does not match its declaration}} +- (Test8_super*) init23 { return 0; } +- (Test8_super*) init33 { return 0; } +- (Test8_super*) init43 { return 0; } +- (Test8_super*) init53 { return 0; } + +- (Test8*) init04 { return 0; } +- (Test8*) init14 { return 0; } // expected-error {{method implementation does not match its declaration}} +- (Test8*) init24 { return 0; } +- (Test8*) init34 { return 0; } +- (Test8*) init44 { return 0; } +- (Test8*) init54 { return 0; } + +- (Test8_complete*) init05 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init15 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init25 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init35 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init45 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init55 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +@end + +@class Test9_incomplete; +@interface Test9 +- (Test9_incomplete*) init1; // expected-error {{init methods must return a type related to the receiver type}} +- (Test9_incomplete*) init2; +@end +id test9(Test9 *v) { + return [v init1]; +} + +// rdar://9491791 +void rdar9491791(int p) { + switch (p) { + case 3:; + NSObject *o = [[NSObject alloc] init]; // expected-note {{jump bypasses initialization of retaining variable}} + [o release]; + break; + default: // expected-error {{switch case is in protected scope}} + break; + } +} + +#define RELEASE_MACRO(x) do { [x release]; } while(1) + +// rdar://9504750 +void rdar9504750(id p) { + RELEASE_MACRO(p); // expected-error {{ARC forbids explicit message send of 'release'}} +} + +// rdar://8939557 +@interface TestReadonlyProperty : NSObject +@property(assign,readonly) NSObject *value; +@end + +@implementation TestReadonlyProperty +@synthesize value; +- (void)viewDidLoad { + value = [NSObject new]; // expected-error {{assigning retained object}} +} +@end + +// rdar://9601437 +@interface I9601437 { + __unsafe_unretained id x; +} +-(void)Meth; +@end + +@implementation I9601437 +-(void)Meth { + self->x = [NSObject new]; // expected-error {{assigning retained object}} +} +@end diff --git a/test/ARCMT/cxx-checking.mm b/test/ARCMT/cxx-checking.mm new file mode 100644 index 0000000..27e0ea3 --- /dev/null +++ b/test/ARCMT/cxx-checking.mm @@ -0,0 +1,105 @@ +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fblocks -Warc-abi %s + +// Classes that have an Objective-C object pointer. +struct HasObjectMember0 { // expected-warning{{'HasObjectMember0' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + id x; +}; + +struct HasObjectMember1 { // expected-warning{{'HasObjectMember1' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + id x[3]; +}; + +struct HasObjectMember2 { // expected-warning{{'HasObjectMember2' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + id x[3][2]; +}; + +// Don't complain if the type has non-external linkage +namespace { + struct HasObjectMember3 { + id x[3][2]; + }; +} + +// Don't complain if the Objective-C pointer type was explicitly given +// no lifetime. +struct HasObjectMember3 { + __unsafe_unretained id x[3][2]; +}; + +struct HasBlockPointerMember0 { // expected-warning{{'HasBlockPointerMember0' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + int (^bp)(int); +}; + +struct HasBlockPointerMember1 { // expected-warning{{'HasBlockPointerMember1' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + int (^bp[2][3])(int); +}; + +struct NonPOD { + NonPOD(const NonPOD&); +}; + +struct HasObjectMemberAndNonPOD0 { // expected-warning{{'HasObjectMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ + // expected-warning{{'HasObjectMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + id x; + NonPOD np; +}; + +struct HasObjectMemberAndNonPOD1 { // expected-warning{{'HasObjectMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ + // expected-warning{{'HasObjectMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + id x[3]; +}; + +struct HasObjectMemberAndNonPOD2 { // expected-warning{{'HasObjectMemberAndNonPOD2' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ + // expected-warning{{'HasObjectMemberAndNonPOD2' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + id x[3][2]; +}; + +struct HasObjectMemberAndNonPOD3 { + HasObjectMemberAndNonPOD3 &operator=(const HasObjectMemberAndNonPOD3&); + ~HasObjectMemberAndNonPOD3(); + NonPOD np; + id x[3][2]; +}; + +struct HasBlockPointerMemberAndNonPOD0 { // expected-warning{{'HasBlockPointerMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ +// expected-warning{{'HasBlockPointerMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + int (^bp)(int); +}; + +struct HasBlockPointerMemberAndNonPOD1 { // expected-warning{{'HasBlockPointerMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ +// expected-warning{{'HasBlockPointerMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + int (^bp[2][3])(int); +}; + +int check_non_pod_objc_pointer0[__is_pod(id)? 1 : -1]; +int check_non_pod_objc_pointer1[__is_pod(__strong id)? -1 : 1]; +int check_non_pod_objc_pointer2[__is_pod(__unsafe_unretained id)? 1 : -1]; +int check_non_pod_objc_pointer3[__is_pod(id[2][3])? 1 : -1]; +int check_non_pod_objc_pointer4[__is_pod(__unsafe_unretained id[2][3])? 1 : -1]; +int check_non_pod_block0[__is_pod(int (^)(int))? 1 : -1]; +int check_non_pod_block1[__is_pod(int (^ __unsafe_unretained)(int))? 1 : -1]; + +struct FlexibleArrayMember0 { + int length; + id array[]; // expected-error{{flexible array member 'array' of non-POD element type 'id __strong[]'}} +}; + +struct FlexibleArrayMember1 { + int length; + __unsafe_unretained id array[]; +}; + +// It's okay to pass a retainable type through an ellipsis. +void variadic(...); +void test_variadic() { + variadic(1, 17, @"Foo"); +} + +// It's okay to create a VLA of retainable types. +void vla(int n) { + id vla[n]; +} diff --git a/test/ARCMT/cxx-rewrite.mm b/test/ARCMT/cxx-rewrite.mm new file mode 100644 index 0000000..aba3f75 --- /dev/null +++ b/test/ARCMT/cxx-rewrite.mm @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c++ %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c++ %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface NSString : NSObject ++(id)string; +@end + +struct foo { + NSString *s; + foo(NSString *s): s([s retain]){ + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + [[[NSString string] retain] release]; + [pool drain]; + } + ~foo(){ [s release]; } +private: + foo(foo const &); + foo &operator=(foo const &); +}; + +int main(){ + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + + foo f([[NSString string] autorelease]); + + [pool drain]; + return 0; +} diff --git a/test/ARCMT/cxx-rewrite.mm.result b/test/ARCMT/cxx-rewrite.mm.result new file mode 100644 index 0000000..145ccd3 --- /dev/null +++ b/test/ARCMT/cxx-rewrite.mm.result @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c++ %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c++ %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface NSString : NSObject ++(id)string; +@end + +struct foo { + NSString *s; + foo(NSString *s): s(s){ + @autoreleasepool { + [NSString string]; + } + } + ~foo(){ s; } +private: + foo(foo const &); + foo &operator=(foo const &); +}; + +int main(){ + @autoreleasepool { + + foo f([NSString string]); + + } + return 0; +} diff --git a/test/ARCMT/dealloc.m b/test/ARCMT/dealloc.m new file mode 100644 index 0000000..dac9644 --- /dev/null +++ b/test/ARCMT/dealloc.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +@interface A +- (id)retain; +- (id)autorelease; +- (oneway void)release; +- (void)dealloc; +@end + +void test1(A *a) { + [a dealloc]; +} + +@interface Test2 : A +- (void) dealloc; +@end + +@implementation Test2 +- (void) dealloc { + [super dealloc]; +} +@end diff --git a/test/ARCMT/dealloc.m.result b/test/ARCMT/dealloc.m.result new file mode 100644 index 0000000..24756d2 --- /dev/null +++ b/test/ARCMT/dealloc.m.result @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +@interface A +- (id)retain; +- (id)autorelease; +- (oneway void)release; +- (void)dealloc; +@end + +void test1(A *a) { +} + +@interface Test2 : A +- (void) dealloc; +@end + +@implementation Test2 +@end diff --git a/test/ARCMT/driver-migrate.m b/test/ARCMT/driver-migrate.m new file mode 100644 index 0000000..e283857 --- /dev/null +++ b/test/ARCMT/driver-migrate.m @@ -0,0 +1,3 @@ +// RUN: %clang -### -ccc-arcmt-migrate /foo/bar -fsyntax-only %s 2>&1 | FileCheck %s + +// CHECK: "-arcmt-migrate" "-arcmt-migrate-directory" "{{[^"]*}}/foo/bar" diff --git a/test/ARCMT/init.m b/test/ARCMT/init.m new file mode 100644 index 0000000..f0d24f6 --- /dev/null +++ b/test/ARCMT/init.m @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +@interface NSObject +-init; +@end + +@interface A : NSObject +-init; +-init2; +-foo; ++alloc; +@end + +@implementation A +-(id) init { + [self init]; + id a; + [a init]; + a = [[A alloc] init]; + + return self; +} + +-(id) init2 { + [super init]; + return self; +} + +-(id) foo { + [self init]; + [super init]; + + return self; +} +@end diff --git a/test/ARCMT/init.m.result b/test/ARCMT/init.m.result new file mode 100644 index 0000000..4f3b4e7 --- /dev/null +++ b/test/ARCMT/init.m.result @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +@interface NSObject +-init; +@end + +@interface A : NSObject +-init; +-init2; +-foo; ++alloc; +@end + +@implementation A +-(id) init { + self = [self init]; + id a; + [a init]; + a = [[A alloc] init]; + + return self; +} + +-(id) init2 { + self = [super init]; + return self; +} + +-(id) foo { + [self init]; + [super init]; + + return self; +} +@end diff --git a/test/ARCMT/migrate.m b/test/ARCMT/migrate.m new file mode 100644 index 0000000..51029c5 --- /dev/null +++ b/test/ARCMT/migrate.m @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -arcmt-migrate -arcmt-migrate-directory %t %S/Inputs/test1.m.in -x objective-c -fobjc-nonfragile-abi +// RUN: %clang_cc1 -arcmt-migrate -arcmt-migrate-directory %t %S/Inputs/test2.m.in -x objective-c -fobjc-nonfragile-abi +// RUN: c-arcmt-test -arcmt-migrate-directory %t | arcmt-test -verify-transformed-files %S/Inputs/test1.m.in.result %S/Inputs/test2.m.in.result %S/Inputs/test.h.result +// RUN: rm -rf %t diff --git a/test/ARCMT/nonobjc-to-objc-cast-2.m b/test/ARCMT/nonobjc-to-objc-cast-2.m new file mode 100644 index 0000000..46ef024 --- /dev/null +++ b/test/ARCMT/nonobjc-to-objc-cast-2.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi %s + +typedef int BOOL; +typedef const struct __CFString * CFStringRef; + +@class NSString; + +void f(BOOL b) { + CFStringRef cfstr; + NSString *str = (NSString *)cfstr; // expected-error {{cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \ + // expected-note{{use __bridge to convert directly (no change in ownership)}} \ + // expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}} + void *vp = str; // expected-error {{disallowed}} +} diff --git a/test/ARCMT/nonobjc-to-objc-cast.m b/test/ARCMT/nonobjc-to-objc-cast.m new file mode 100644 index 0000000..4e1e293 --- /dev/null +++ b/test/ARCMT/nonobjc-to-objc-cast.m @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface NSString : NSObject +@end + +typedef const struct __CFString * CFStringRef; +extern const CFStringRef kUTTypePlainText; +extern const CFStringRef kUTTypeRTF; + +typedef const struct __CFAllocator * CFAllocatorRef; +typedef const struct __CFUUID * CFUUIDRef; + +extern const CFAllocatorRef kCFAllocatorDefault; + +extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid); + +void f(BOOL b, id p) { + NSString *str = (NSString *)kUTTypePlainText; + str = b ? kUTTypeRTF : kUTTypePlainText; + str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText); + str = (NSString *)p; // no change. + + CFUUIDRef _uuid; + NSString *_uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid); + _uuidString = [(NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid) autorelease]; +} + +@implementation NSString (StrExt) +- (NSString *)stringEscapedAsURI { + CFStringRef str = (CFStringRef)self; + CFStringRef str2 = self; + return self; +} +@end diff --git a/test/ARCMT/nonobjc-to-objc-cast.m.result b/test/ARCMT/nonobjc-to-objc-cast.m.result new file mode 100644 index 0000000..53dde75 --- /dev/null +++ b/test/ARCMT/nonobjc-to-objc-cast.m.result @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface NSString : NSObject +@end + +typedef const struct __CFString * CFStringRef; +extern const CFStringRef kUTTypePlainText; +extern const CFStringRef kUTTypeRTF; + +typedef const struct __CFAllocator * CFAllocatorRef; +typedef const struct __CFUUID * CFUUIDRef; + +extern const CFAllocatorRef kCFAllocatorDefault; + +extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid); + +void f(BOOL b, id p) { + NSString *str = (__bridge NSString *)kUTTypePlainText; + str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText); + str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText); + str = (NSString *)p; // no change. + + CFUUIDRef _uuid; + NSString *_uuidString = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid); + _uuidString = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid); +} + +@implementation NSString (StrExt) +- (NSString *)stringEscapedAsURI { + CFStringRef str = (__bridge CFStringRef)self; + CFStringRef str2 = (__bridge CFStringRef)(self); + return self; +} +@end diff --git a/test/ARCMT/releases-driver.m b/test/ARCMT/releases-driver.m new file mode 100644 index 0000000..a016b26 --- /dev/null +++ b/test/ARCMT/releases-driver.m @@ -0,0 +1,68 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: cp %s %t +// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -fobjc-nonfragile-abi -x objective-c %t +// RUN: diff %t %s.result +// RUN: rm %t + +typedef int BOOL; + +id IhaveSideEffect(); + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain; +- (oneway void)release; +@end + +@interface NSObject <NSObject> {} +@end + +@interface Foo : NSObject { + id bar; +} +@property (retain) id bar; +-(void)test:(id)obj; +@end + +@implementation Foo + +@synthesize bar; + +-(void)test:(id)obj { + id x = self.bar; + [x retain]; + self.bar = obj; + // do stuff with x; + [x release]; + + [IhaveSideEffect() release]; + + [x release], x = 0; +} + +@end + +void func(Foo *p) { + [p release]; + (([p release])); +} + +@interface Baz { + id <NSObject> _foo; +} +@end + +@implementation Baz +- dealloc { + [_foo release]; + return 0; +} +@end + +#define RELEASE_MACRO(x) [x release] +#define RELEASE_MACRO2(x) RELEASE_MACRO(x) + +void test2(id p) { + RELEASE_MACRO(p); + RELEASE_MACRO2(p); +} diff --git a/test/ARCMT/releases-driver.m.result b/test/ARCMT/releases-driver.m.result new file mode 100644 index 0000000..c5f527f --- /dev/null +++ b/test/ARCMT/releases-driver.m.result @@ -0,0 +1,61 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: cp %s %t +// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -fobjc-nonfragile-abi -x objective-c %t +// RUN: diff %t %s.result +// RUN: rm %t + +typedef int BOOL; + +id IhaveSideEffect(); + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain; +- (oneway void)release; +@end + +@interface NSObject <NSObject> {} +@end + +@interface Foo : NSObject { + id bar; +} +@property (strong) id bar; +-(void)test:(id)obj; +@end + +@implementation Foo + +@synthesize bar; + +-(void)test:(id)obj { + id x = self.bar; + self.bar = obj; + // do stuff with x; + + IhaveSideEffect(); + + x = 0; +} + +@end + +void func(Foo *p) { +} + +@interface Baz { + id <NSObject> _foo; +} +@end + +@implementation Baz +- dealloc { + return 0; +} +@end + +#define RELEASE_MACRO(x) [x release] +#define RELEASE_MACRO2(x) RELEASE_MACRO(x) + +void test2(id p) { +} diff --git a/test/ARCMT/releases.m b/test/ARCMT/releases.m new file mode 100644 index 0000000..d5f21dc --- /dev/null +++ b/test/ARCMT/releases.m @@ -0,0 +1,87 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-exceptions -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-exceptions -fblocks -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#define nil 0 + +typedef int BOOL; + +id IhaveSideEffect(); + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain; +- (oneway void)release; +@end + +@interface NSObject <NSObject> {} +@end + +@interface Foo : NSObject { + id bar; +} +@property (retain) id bar; +-(void)test:(id)obj; +@end + +@implementation Foo + +@synthesize bar; + +-(void)test:(id)obj { + id x = self.bar; + [x retain]; + self.bar = obj; + // do stuff with x; + [x release]; + + [IhaveSideEffect() release]; + + [x release], x = 0; + + @try { + } @finally { + [x release]; + } +} + +@end + +void func(Foo *p) { + [p release]; + (([p release])); +} + +@interface Baz { + id <NSObject> _foo; +} +@end + +@implementation Baz +- dealloc { + [_foo release]; + return 0; +} +@end + +void block_test(Foo *p) { + id (^B)() = ^() { + if (p) { + id (^IB)() = ^() { + id bar = [p retain]; + [p release]; + return bar; + }; + IB(); + } + return [p retain]; + }; +} + +#define RELEASE_MACRO(x) [x release] +#define RELEASE_MACRO2(x) RELEASE_MACRO(x) + +void test2(id p) { + RELEASE_MACRO(p); + RELEASE_MACRO2(p); +} diff --git a/test/ARCMT/releases.m.result b/test/ARCMT/releases.m.result new file mode 100644 index 0000000..1d36f3e --- /dev/null +++ b/test/ARCMT/releases.m.result @@ -0,0 +1,79 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-exceptions -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-exceptions -fblocks -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#define nil 0 + +typedef int BOOL; + +id IhaveSideEffect(); + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain; +- (oneway void)release; +@end + +@interface NSObject <NSObject> {} +@end + +@interface Foo : NSObject { + id bar; +} +@property (strong) id bar; +-(void)test:(id)obj; +@end + +@implementation Foo + +@synthesize bar; + +-(void)test:(id)obj { + id x = self.bar; + self.bar = obj; + // do stuff with x; + + IhaveSideEffect(); + + x = 0; + + @try { + } @finally { + x = nil; + } +} + +@end + +void func(Foo *p) { +} + +@interface Baz { + id <NSObject> _foo; +} +@end + +@implementation Baz +- dealloc { + return 0; +} +@end + +void block_test(Foo *p) { + id (^B)() = ^() { + if (p) { + id (^IB)() = ^() { + id bar = p; + return bar; + }; + IB(); + } + return p; + }; +} + +#define RELEASE_MACRO(x) [x release] +#define RELEASE_MACRO2(x) RELEASE_MACRO(x) + +void test2(id p) { +} diff --git a/test/ARCMT/remove-dealloc-method.m b/test/ARCMT/remove-dealloc-method.m new file mode 100644 index 0000000..5c2d785 --- /dev/null +++ b/test/ARCMT/remove-dealloc-method.m @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#define nil ((void*) 0) + +@interface Foo +@property (retain) id x; +@property (retain) id y; +@property (retain) id w; +@property (retain) id z; +@end + +@implementation Foo +@synthesize x; +@synthesize y; +@synthesize w; +@synthesize z; + +- (void) dealloc { + self.x = 0; + [self setY:nil]; + w = nil; + self.z = nil; +} +@end diff --git a/test/ARCMT/remove-dealloc-method.m.result b/test/ARCMT/remove-dealloc-method.m.result new file mode 100644 index 0000000..ecb752c --- /dev/null +++ b/test/ARCMT/remove-dealloc-method.m.result @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#define nil ((void*) 0) + +@interface Foo +@property (strong) id x; +@property (strong) id y; +@property (strong) id w; +@property (strong) id z; +@end + +@implementation Foo +@synthesize x; +@synthesize y; +@synthesize w; +@synthesize z; + +@end diff --git a/test/ARCMT/remove-dealloc-zerouts.m b/test/ARCMT/remove-dealloc-zerouts.m new file mode 100644 index 0000000..3ba85f1 --- /dev/null +++ b/test/ARCMT/remove-dealloc-zerouts.m @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +@interface Foo +@property (retain) id x; +@property (retain) id y; +@property (retain) id w; +@property (retain) id z; +@property (strong) id q; +@end + +@implementation Foo +@synthesize x; +@synthesize y; +@synthesize w; +@synthesize q; +@dynamic z; + +- (void) dealloc { + self.x = self.y = self.w = 0; + self.x = 0, w = 0, y = 0; + [self setY:0]; + w = 0; + q = 0; + self.z = 0; +} +@end + +@interface Bar +@property (retain) Foo *a; +- (void) setA:(Foo*) val; +- (id) a; +@end + +@implementation Bar +- (void) dealloc { + [self setA:0]; // This is user-defined setter overriding synthesize, don't touch it. + self.a.x = 0; // every dealloc must zero out its own ivar. This patter is not recognized. +} +@synthesize a; +- (void) setA:(Foo*) val { } +- (id) a {return 0;} +@end diff --git a/test/ARCMT/remove-dealloc-zerouts.m.result b/test/ARCMT/remove-dealloc-zerouts.m.result new file mode 100644 index 0000000..dc6ffd3 --- /dev/null +++ b/test/ARCMT/remove-dealloc-zerouts.m.result @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +@interface Foo +@property (strong) id x; +@property (strong) id y; +@property (strong) id w; +@property (strong) id z; +@property (strong) id q; +@end + +@implementation Foo +@synthesize x; +@synthesize y; +@synthesize w; +@synthesize q; +@dynamic z; + +- (void) dealloc { + self.z = 0; +} +@end + +@interface Bar +@property (strong) Foo *a; +- (void) setA:(Foo*) val; +- (id) a; +@end + +@implementation Bar +- (void) dealloc { + [self setA:0]; // This is user-defined setter overriding synthesize, don't touch it. + self.a.x = 0; // every dealloc must zero out its own ivar. This patter is not recognized. +} +@synthesize a; +- (void) setA:(Foo*) val { } +- (id) a {return 0;} +@end diff --git a/test/ARCMT/remove-statements.m b/test/ARCMT/remove-statements.m new file mode 100644 index 0000000..7e10296 --- /dev/null +++ b/test/ARCMT/remove-statements.m @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface myController : NSObject +-(id)test:(id)x; +@end + +#define MY_MACRO1(x) +#define MY_MACRO2(x) (void)x + +@implementation myController +-(id) test:(id) x { + [[x retain] release]; + return [[x retain] autorelease]; +} + +-(void)dealloc +{ + id array, array_already_empty; + for (id element in array_already_empty) { + } + + [array release]; + ; + + int b, b_array_already_empty; + if (b) + [array release]; + if (b_array_already_empty) ; + + if (b) { + [array release]; + } + if (b_array_already_empty) { + } + + if (b) + MY_MACRO1(array); + if (b) + MY_MACRO2(array); +} +@end diff --git a/test/ARCMT/remove-statements.m.result b/test/ARCMT/remove-statements.m.result new file mode 100644 index 0000000..9a1153e --- /dev/null +++ b/test/ARCMT/remove-statements.m.result @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface myController : NSObject +-(id)test:(id)x; +@end + +#define MY_MACRO1(x) +#define MY_MACRO2(x) (void)x + +@implementation myController +-(id) test:(id) x { + return x; +} + +-(void)dealloc +{ + id array, array_already_empty; + for (id element in array_already_empty) { + } + + ; + + int b, b_array_already_empty; + if (b_array_already_empty) ; + + if (b_array_already_empty) { + } + + if (b) + MY_MACRO1(array); + if (b) + MY_MACRO2(array); +} +@end diff --git a/test/ARCMT/retains.m b/test/ARCMT/retains.m new file mode 100644 index 0000000..fa90f21 --- /dev/null +++ b/test/ARCMT/retains.m @@ -0,0 +1,71 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fblocks -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +id IhaveSideEffect(); + +@interface Foo : NSObject { + id bar; +} +@property (retain) id bar; +-(id)test:(id)obj; +-(id)something; +@end + +#define Something_Macro(key, comment) \ + [[Foo new] something] + +@implementation Foo + +@synthesize bar; + +-(id)something {} + +-(id)test:(id)obj { + id x = self.bar; + [x retain]; + self.bar = obj; + if (obj) + [obj retain]; + + [Something_Macro(@"foo", "@bar") retain]; + + [IhaveSideEffect() retain]; + + [[self something] retain]; + + [[self retain] something]; + + [[IhaveSideEffect() retain] release]; + [[x retain] release]; + // do stuff with x; + [x release]; + return [self retain]; +} + +- (id)test1 { + id x=0; + ([x retain]); + return ((([x retain]))); +} +@end + +id foo (Foo *p) { + p = [p retain]; + return ([p retain]); +} + +void block_tests(Foo *p) { + id (^B)() = ^() { + if (p) { + id (^IB)() = ^() { + id bar = [p retain]; + return bar; + }; + IB(); + } + return [p retain]; + }; +} diff --git a/test/ARCMT/retains.m.result b/test/ARCMT/retains.m.result new file mode 100644 index 0000000..54df864 --- /dev/null +++ b/test/ARCMT/retains.m.result @@ -0,0 +1,65 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fblocks -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +id IhaveSideEffect(); + +@interface Foo : NSObject { + id bar; +} +@property (strong) id bar; +-(id)test:(id)obj; +-(id)something; +@end + +#define Something_Macro(key, comment) \ + [[Foo new] something] + +@implementation Foo + +@synthesize bar; + +-(id)something {} + +-(id)test:(id)obj { + id x = self.bar; + self.bar = obj; + + Something_Macro(@"foo", "@bar"); + + IhaveSideEffect(); + + [self something]; + + [self something]; + + IhaveSideEffect(); + // do stuff with x; + return self; +} + +- (id)test1 { + id x=0; + return (((x))); +} +@end + +id foo (Foo *p) { + p = p; + return (p); +} + +void block_tests(Foo *p) { + id (^B)() = ^() { + if (p) { + id (^IB)() = ^() { + id bar = p; + return bar; + }; + IB(); + } + return p; + }; +} diff --git a/test/ARCMT/rewrite-block-var.m b/test/ARCMT/rewrite-block-var.m new file mode 100644 index 0000000..81407f9 --- /dev/null +++ b/test/ARCMT/rewrite-block-var.m @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fblocks -fsyntax-only -fobjc-arc -x objective-c -fobjc-runtime-has-weak %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fobjc-nonfragile-abi -fblocks -fsyntax-only %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface Foo : NSObject +-(Foo *)something; +@end + +void bar(void (^block)()); + +void test1(Foo *p) { + __block Foo *x = p; // __block used just to break cycle. + bar(^{ + [x something]; + }); +} + +void test2(Foo *p) { + __block Foo *x; // __block used as output variable. + bar(^{ + x = [p something]; + }); +} diff --git a/test/ARCMT/rewrite-block-var.m.result b/test/ARCMT/rewrite-block-var.m.result new file mode 100644 index 0000000..85093ac --- /dev/null +++ b/test/ARCMT/rewrite-block-var.m.result @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fblocks -fsyntax-only -fobjc-arc -x objective-c -fobjc-runtime-has-weak %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fobjc-nonfragile-abi -fblocks -fsyntax-only %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface Foo : NSObject +-(Foo *)something; +@end + +void bar(void (^block)()); + +void test1(Foo *p) { + __weak Foo *x = p; // __block used just to break cycle. + bar(^{ + [x something]; + }); +} + +void test2(Foo *p) { + __block Foo *x; // __block used as output variable. + bar(^{ + x = [p something]; + }); +} diff --git a/test/ARCMT/safe-arc-assign.m b/test/ARCMT/safe-arc-assign.m new file mode 100644 index 0000000..368c2b6 --- /dev/null +++ b/test/ARCMT/safe-arc-assign.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +void test12(id collection) { + for (id x in collection) { + x = 0; + x = 0; + } + + for (__strong id x in collection) { + x = 0; + } +} diff --git a/test/ARCMT/safe-arc-assign.m.result b/test/ARCMT/safe-arc-assign.m.result new file mode 100644 index 0000000..cacd109 --- /dev/null +++ b/test/ARCMT/safe-arc-assign.m.result @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +void test12(id collection) { + for (__strong id x in collection) { + x = 0; + x = 0; + } + + for (__strong id x in collection) { + x = 0; + } +} diff --git a/test/ARCMT/with-arc-mode-check.m b/test/ARCMT/with-arc-mode-check.m new file mode 100644 index 0000000..c3146ef --- /dev/null +++ b/test/ARCMT/with-arc-mode-check.m @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -arcmt-check -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { + [p release]; +} diff --git a/test/ARCMT/with-arc-mode-migrate.m b/test/ARCMT/with-arc-mode-migrate.m new file mode 100644 index 0000000..3851bc7 --- /dev/null +++ b/test/ARCMT/with-arc-mode-migrate.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: %clang_cc1 -arcmt-migrate -arcmt-migrate-directory %t -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc %s +// RUN: c-arcmt-test -arcmt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result +// RUN: rm -rf %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { + [p release]; +} diff --git a/test/ARCMT/with-arc-mode-migrate.m.result b/test/ARCMT/with-arc-mode-migrate.m.result new file mode 100644 index 0000000..c2222ae --- /dev/null +++ b/test/ARCMT/with-arc-mode-migrate.m.result @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: %clang_cc1 -arcmt-migrate -arcmt-migrate-directory %t -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc %s +// RUN: c-arcmt-test -arcmt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result +// RUN: rm -rf %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { +} diff --git a/test/ARCMT/with-arc-mode-modify.m b/test/ARCMT/with-arc-mode-modify.m new file mode 100644 index 0000000..17a3980 --- /dev/null +++ b/test/ARCMT/with-arc-mode-modify.m @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: cp %s %t +// RUN: %clang_cc1 -arcmt-modify -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %t +// RUN: diff %t %s.result +// RUN: rm %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { + [p release]; +} diff --git a/test/ARCMT/with-arc-mode-modify.m.result b/test/ARCMT/with-arc-mode-modify.m.result new file mode 100644 index 0000000..97c5128 --- /dev/null +++ b/test/ARCMT/with-arc-mode-modify.m.result @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: cp %s %t +// RUN: %clang_cc1 -arcmt-modify -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %t +// RUN: diff %t %s.result +// RUN: rm %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { +} diff --git a/test/Analysis/bstring.c b/test/Analysis/bstring.c index 68bbb1a..cd43e36 100644 --- a/test/Analysis/bstring.c +++ b/test/Analysis/bstring.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,cplusplus.experimental.CString -analyzer-store=region -Wno-null-dereference -verify %s -// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-checker=core,cplusplus.experimental.CString -analyzer-store=region -Wno-null-dereference -verify %s -// RUN: %clang_cc1 -analyze -DVARIANT -analyzer-checker=core,cplusplus.experimental.CString -analyzer-store=region -Wno-null-dereference -verify %s -// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -DVARIANT -analyzer-checker=core,cplusplus.experimental.CString -analyzer-store=region -Wno-null-dereference -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.experimental.CString -analyzer-store=region -Wno-null-dereference -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-checker=core,unix.experimental.CString -analyzer-store=region -Wno-null-dereference -verify %s +// RUN: %clang_cc1 -analyze -DVARIANT -analyzer-checker=core,unix.experimental.CString -analyzer-store=region -Wno-null-dereference -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -DVARIANT -analyzer-checker=core,unix.experimental.CString -analyzer-store=region -Wno-null-dereference -verify %s //===----------------------------------------------------------------------=== // Declarations @@ -64,14 +64,14 @@ void memcpy1 () { char src[] = {1, 2, 3, 4}; char dst[10]; - memcpy(dst, src, 5); // expected-warning{{Byte string function accesses out-of-bound array element}} + memcpy(dst, src, 5); // expected-warning{{Memory copy function accesses out-of-bound array element}} } void memcpy2 () { char src[] = {1, 2, 3, 4}; char dst[1]; - memcpy(dst, src, 4); // expected-warning{{Byte string function overflows destination buffer}} + memcpy(dst, src, 4); // expected-warning{{Memory copy function overflows destination buffer}} } void memcpy3 () { @@ -85,14 +85,14 @@ void memcpy4 () { char src[] = {1, 2, 3, 4}; char dst[10]; - memcpy(dst+2, src+2, 3); // expected-warning{{Byte string function accesses out-of-bound array element}} + memcpy(dst+2, src+2, 3); // expected-warning{{Memory copy function accesses out-of-bound array element}} } void memcpy5() { char src[] = {1, 2, 3, 4}; char dst[3]; - memcpy(dst+2, src+2, 2); // expected-warning{{Byte string function overflows destination buffer}} + memcpy(dst+2, src+2, 2); // expected-warning{{Memory copy function overflows destination buffer}} } void memcpy6() { @@ -118,12 +118,12 @@ void memcpy9() { void memcpy10() { char a[4] = {0}; - memcpy(0, a, 4); // expected-warning{{Null pointer argument in call to byte string function}} + memcpy(0, a, 4); // expected-warning{{Null pointer argument in call to memory copy function}} } void memcpy11() { char a[4] = {0}; - memcpy(a, 0, 4); // expected-warning{{Null pointer argument in call to byte string function}} + memcpy(a, 0, 4); // expected-warning{{Null pointer argument in call to memory copy function}} } void memcpy12() { @@ -144,7 +144,7 @@ void memcpy_unknown_size (size_t n) { void memcpy_unknown_size_warn (size_t n) { char a[4]; - if (memcpy(a, 0, n) != a) // expected-warning{{Null pointer argument in call to byte string function}} + if (memcpy(a, 0, n) != a) // expected-warning{{Null pointer argument in call to memory copy function}} (void)*(char*)0; // no-warning } @@ -186,14 +186,14 @@ void mempcpy1 () { char src[] = {1, 2, 3, 4}; char dst[10]; - mempcpy(dst, src, 5); // expected-warning{{Byte string function accesses out-of-bound array element}} + mempcpy(dst, src, 5); // expected-warning{{Memory copy function accesses out-of-bound array element}} } void mempcpy2 () { char src[] = {1, 2, 3, 4}; char dst[1]; - mempcpy(dst, src, 4); // expected-warning{{Byte string function overflows destination buffer}} + mempcpy(dst, src, 4); // expected-warning{{Memory copy function overflows destination buffer}} } void mempcpy3 () { @@ -207,14 +207,14 @@ void mempcpy4 () { char src[] = {1, 2, 3, 4}; char dst[10]; - mempcpy(dst+2, src+2, 3); // expected-warning{{Byte string function accesses out-of-bound array element}} + mempcpy(dst+2, src+2, 3); // expected-warning{{Memory copy function accesses out-of-bound array element}} } void mempcpy5() { char src[] = {1, 2, 3, 4}; char dst[3]; - mempcpy(dst+2, src+2, 2); // expected-warning{{Byte string function overflows destination buffer}} + mempcpy(dst+2, src+2, 2); // expected-warning{{Memory copy function overflows destination buffer}} } void mempcpy6() { @@ -240,12 +240,12 @@ void mempcpy9() { void mempcpy10() { char a[4] = {0}; - mempcpy(0, a, 4); // expected-warning{{Null pointer argument in call to byte string function}} + mempcpy(0, a, 4); // expected-warning{{Null pointer argument in call to memory copy function}} } void mempcpy11() { char a[4] = {0}; - mempcpy(a, 0, 4); // expected-warning{{Null pointer argument in call to byte string function}} + mempcpy(a, 0, 4); // expected-warning{{Null pointer argument in call to memory copy function}} } void mempcpy12() { @@ -260,7 +260,7 @@ void mempcpy13() { void mempcpy_unknown_size_warn (size_t n) { char a[4]; - if (mempcpy(a, 0, n) != a) // expected-warning{{Null pointer argument in call to byte string function}} + if (mempcpy(a, 0, n) != a) // expected-warning{{Null pointer argument in call to memory copy function}} (void)*(char*)0; // no-warning } diff --git a/test/Analysis/misc-ps-eager-assume.m b/test/Analysis/misc-ps-eager-assume.m index 649c4b0..4380a18 100644 --- a/test/Analysis/misc-ps-eager-assume.m +++ b/test/Analysis/misc-ps-eager-assume.m @@ -12,6 +12,7 @@ typedef struct _NSZone NSZone; @end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end @interface NSObject <NSObject> {} + (id)alloc; +- (id)init; @end typedef struct {} NSFastEnumerationState; @protocol NSFastEnumeration - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; diff --git a/test/Analysis/nullptr.cpp b/test/Analysis/nullptr.cpp index b74a5ab..6f78bae 100644 --- a/test/Analysis/nullptr.cpp +++ b/test/Analysis/nullptr.cpp @@ -39,3 +39,11 @@ void foo4(void) { *np = 0; // no-warning } + +int pr10372(void *& x) { + // GNU null is a pointer-sized integer, not a pointer. + x = __null; + // This used to crash. + return __null; +} + diff --git a/test/Analysis/objc-arc.m b/test/Analysis/objc-arc.m new file mode 100644 index 0000000..6b22fd0 --- /dev/null +++ b/test/Analysis/objc-arc.m @@ -0,0 +1,149 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core -analyzer-checker=deadcode -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks -fobjc-nonfragile-abi -fobjc-arc %s + +typedef signed char BOOL; +typedef struct _NSZone NSZone; +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +@end +@protocol NSCopying +- (id)copyWithZone:(NSZone *)zone; +@end +@protocol NSCoding +- (void)encodeWithCoder:(NSCoder *)aCoder; +@end +@interface NSObject <NSObject> {} ++ (id)alloc; +@end +typedef const struct __CFAllocator * CFAllocatorRef; +extern const CFAllocatorRef kCFAllocatorDefault; +typedef double CFTimeInterval; +typedef CFTimeInterval CFAbsoluteTime; +extern CFAbsoluteTime CFAbsoluteTimeGetCurrent(void); +typedef const struct __CFDate * CFDateRef; +extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at); + +typedef const void* objc_objectptr_t; +__attribute__((ns_returns_retained)) id objc_retainedObject(objc_objectptr_t __attribute__((cf_consumed)) pointer); +__attribute__((ns_returns_not_retained)) id objc_unretainedObject(objc_objectptr_t pointer); + +// Test the analyzer is working at all. +void test_working() { + int *p = 0; + *p = 0xDEADBEEF; // expected-warning {{null}} +} + +// Test that in ARC mode that blocks are correctly automatically copied +// and not flagged as warnings by the analyzer. +typedef void (^Block)(void); +void testblock_bar(int x); + +Block testblock_foo(int x) { + Block b = ^{ testblock_bar(x); }; + return b; // no-warning +} + +Block testblock_baz(int x) { + return ^{ testblock_bar(x); }; // no-warning +} + +Block global_block; + +void testblock_qux(int x) { + global_block = ^{ testblock_bar(x); }; // no-warning +} + +// Test that Objective-C pointers are null initialized. +void test_nil_initialized() { + id x; + if (x == 0) + return; + int *p = 0; + *p = 0xDEADBEEF; // no-warning +} + +// Test that we don't flag leaks of Objective-C objects. +void test_alloc() { + [NSObject alloc]; // no-warning +} + +// Test that CF allocations are still caught as leaks. +void test_cf_leak() { + CFAbsoluteTime t = CFAbsoluteTimeGetCurrent(); + CFDateRef date = CFDateCreate(0, t); // expected-warning {{Potential leak}} + (void) date; +} + +// Test that 'init' methods do not try to claim ownerhip of an *unowned* allocated object +// in ARC mode. +@interface RDar9424890_A : NSObject +- (id)initWithCleaner:(int)pop mop:(NSString *)mop ; +- (RDar9424890_A *)rdar9424890:(NSString *)identifier; +@end +@interface RDar9424890_B : NSObject +@end +@implementation RDar9424890_B +- (RDar9424890_A *)obj:(RDar9424890_A *)obj { + static NSString *WhizFiz = @"WhizFiz"; + RDar9424890_A *cell = [obj rdar9424890:WhizFiz]; + if (cell == ((void*)0)) { + cell = [[RDar9424890_A alloc] initWithCleaner:0 mop:WhizFiz]; // no-warning + } + return cell; +} +@end + +// Test that dead store checking works in the prescence of "cleanups" in the AST. +void rdar9424882() { + id x = [NSObject alloc]; // expected-warning {{Value stored to 'x' during its initialization is never read}} +} + +// Test +typedef const void *CFTypeRef; +typedef const struct __CFString *CFStringRef; + +@interface NSString +- (id) self; +@end + +CFTypeRef CFCreateSomething(); +CFStringRef CFCreateString(); +CFTypeRef CFGetSomething(); +CFStringRef CFGetString(); + +id CreateSomething(); +NSString *CreateNSString(); + +void from_cf() { + id obj1 = (__bridge_transfer id)CFCreateSomething(); // expected-warning{{never read}} + id obj2 = (__bridge_transfer NSString*)CFCreateString(); + [obj2 self]; // Add a use, to show we can use the object after it has been transfered. + id obj3 = (__bridge id)CFGetSomething(); + [obj3 self]; // Add a use, to show we can use the object after it has been bridged. + id obj4 = (__bridge NSString*)CFGetString(); // expected-warning{{never read}} + id obj5 = (__bridge id)CFCreateSomething(); // expected-warning{{never read}} expected-warning{{leak}} + id obj6 = (__bridge NSString*)CFCreateString(); // expected-warning{{never read}} expected-warning{{leak}} +} + +void to_cf(id obj) { + CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); // expected-warning{{never read}} + CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString(); // expected-warning{{never read}} + CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); // expected-warning{{never read}} + CFStringRef cf4 = (__bridge CFStringRef)CreateNSString(); // expected-warning{{never read}} +} + +void test_objc_retainedObject() { + CFAbsoluteTime t = CFAbsoluteTimeGetCurrent(); + CFDateRef date = CFDateCreate(0, t); + id x = objc_retainedObject(date); + (void) x; +} + +void test_objc_unretainedObject() { + CFAbsoluteTime t = CFAbsoluteTimeGetCurrent(); + CFDateRef date = CFDateCreate(0, t); // expected-warning {{Potential leak}} + id x = objc_unretainedObject(date); + (void) x; +} + diff --git a/test/Analysis/pr4209.m b/test/Analysis/pr4209.m index 1e0fd32..e3bc5cc 100644 --- a/test/Analysis/pr4209.m +++ b/test/Analysis/pr4209.m @@ -49,17 +49,17 @@ CMProfileLocation; GSEbayCategory *rootCategory; } - (NSMutableDictionary*)categoryDictionaryForCategoryID:(int)inID inRootTreeCategories:(NSMutableArray*)inRootTreeCategories; // expected-note {{method definition for 'categoryDictionaryForCategoryID:inRootTreeCategories:' not found}} --(NSString*) categoryID; // expected-note {{method definition for 'categoryID' not found}} +-(NSString*) categoryID; // expected-note {{method definition for 'categoryID' not found}} expected-note {{using}} @end @interface GSEbayCategory : NSObject <NSCoding> { } -- (int) categoryID; +- (int) categoryID; // expected-note {{also found}} - (GSEbayCategory *) parent; - (GSEbayCategory*) subcategoryWithID:(int) inID; @end @implementation GBCategoryChooserPanelController + (int) chooseCategoryIDFromCategories:(NSArray*) inCategories searchRequest:(GBSearchRequest*)inRequest parentWindow:(NSWindow*) inParent { // expected-warning {{incomplete implementation}} return 0; } - (void) addCategory:(EBayCategoryType*)inCategory toRootTreeCategory:(NSMutableArray*)inRootTreeCategories { - GSEbayCategory *category = [rootCategory subcategoryWithID:[[inCategory categoryID] intValue]]; + GSEbayCategory *category = [rootCategory subcategoryWithID:[[inCategory categoryID] intValue]]; // expected-warning {{multiple methods named 'categoryID' found}} if (rootCategory != category) { GSEbayCategory *parent = category; diff --git a/test/Analysis/retain-release-gc-only.m b/test/Analysis/retain-release-gc-only.m index cbf00a2..ee1a6b4 100644 --- a/test/Analysis/retain-release-gc-only.m +++ b/test/Analysis/retain-release-gc-only.m @@ -113,6 +113,7 @@ NSFastEnumerationState; @end @interface NSAutoreleasePool : NSObject { } - (void)drain; +- (id)init; @end extern NSString * const NSBundleDidLoadNotification; typedef double NSTimeInterval; @interface NSDate : NSObject <NSCopying, NSCoding> - (NSTimeInterval)timeIntervalSinceReferenceDate; diff --git a/test/Analysis/retain-release-path-notes-gc.m b/test/Analysis/retain-release-path-notes-gc.m new file mode 100644 index 0000000..21d314f --- /dev/null +++ b/test/Analysis/retain-release-path-notes-gc.m @@ -0,0 +1,74 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease -analyzer-store=basic -analyzer-output=text -fobjc-gc-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease -analyzer-store=region -analyzer-output=text -fobjc-gc-only -verify %s + +/*** +This file is for testing the path-sensitive notes for retain/release errors. +Its goal is to have simple branch coverage of any path-based diagnostics, +not to actually check all possible retain/release errors. + +This file is for notes that only appear in a GC-enabled analysis. +Non-specific and ref-count-only notes should go in retain-release-path-notes.m. +***/ + +@interface NSObject ++ (id)alloc; +- (id)init; +- (void)dealloc; + +- (Class)class; + +- (id)retain; +- (void)release; +- (void)autorelease; +@end + +@interface Foo : NSObject +- (id)methodWithValue; +@property(retain) id propertyValue; +@end + +typedef struct CFType *CFTypeRef; +CFTypeRef CFRetain(CFTypeRef); +void CFRelease(CFTypeRef); + +id NSMakeCollectable(CFTypeRef); +CFTypeRef CFMakeCollectable(CFTypeRef); + +CFTypeRef CFCreateSomething(); +CFTypeRef CFGetSomething(); + + +void creationViaCFCreate () { + CFTypeRef leaked = CFCreateSomething(); // expected-warning{{leak}} expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation object with a +1 retain count. Core Foundation objects are not automatically garbage collected}} + return; // expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}} +} + +void makeCollectable () { + CFTypeRef leaked = CFCreateSomething(); // expected-warning{{leak}} expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation object with a +1 retain count. Core Foundation objects are not automatically garbage collected}} + CFRetain(leaked); // expected-note{{Reference count incremented. The object now has a +2 retain count}} + CFMakeCollectable(leaked); // expected-note{{In GC mode a call to 'CFMakeCollectable' decrements an object's retain count and registers the object with the garbage collector. An object must have a 0 retain count to be garbage collected. After this call its retain count is +1.}} + NSMakeCollectable(leaked); // expected-note{{In GC mode a call to 'NSMakeCollectable' decrements an object's retain count and registers the object with the garbage collector. Since it now has a 0 retain count the object can be automatically collected by the garbage collector}} + CFRetain(leaked); // expected-note{{Reference count incremented. The object now has a +1 retain count. The object is not eligible for garbage collection until the retain count reaches 0 again.}} + return; // expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}} +} + +void retainReleaseIgnored () { + id object = [[NSObject alloc] init]; // expected-note{{Method returns an Objective-C object with a +0 retain count}} + [object retain]; // expected-note{{In GC mode the 'retain' message has no effect}} + [object release]; // expected-note{{In GC mode the 'release' message has no effect}} + [object autorelease]; // expected-note{{In GC mode an 'autorelease' has no effect}} + CFRelease((CFTypeRef)object); // expected-warning{{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}} expected-note{{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}} +} + +@implementation Foo (FundamentalRuleUnderGC) +- (id)getViolation { + id object = (id) CFCreateSomething(); // expected-warning{{leak}} expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation object with a +1 retain count. Core Foundation objects are not automatically garbage collected.}} + return object; // expected-note{{Object returned to caller as an owning reference (single retain count transferred to caller)}} expected-note{{Object leaked: object allocated and stored into 'object' and returned from method 'getViolation' is potentially leaked when using garbage collection. Callers of this method do not expect a returned object with a +1 retain count since they expect the object to be managed by the garbage collector}} +} + +- (id)copyViolation { + id object = (id) CFCreateSomething(); // expected-warning{{leak}} expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation object with a +1 retain count. Core Foundation objects are not automatically garbage collected.}} + return object; // expected-note{{Object returned to caller as an owning reference (single retain count transferred to caller)}} expected-note{{Object leaked: object allocated and stored into 'object' and returned from method 'copyViolation' is potentially leaked when using garbage collection. Callers of this method do not expect a returned object with a +1 retain count since they expect the object to be managed by the garbage collector}} +} +@end + diff --git a/test/Analysis/retain-release-path-notes.m b/test/Analysis/retain-release-path-notes.m new file mode 100644 index 0000000..bac0afb --- /dev/null +++ b/test/Analysis/retain-release-path-notes.m @@ -0,0 +1,123 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease -analyzer-store=basic -analyzer-output=text -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease -analyzer-store=region -analyzer-output=text -verify %s + +/*** +This file is for testing the path-sensitive notes for retain/release errors. +Its goal is to have simple branch coverage of any path-based diagnostics, +not to actually check all possible retain/release errors. + +This file includes notes that only appear in a ref-counted analysis. +GC-specific notes should go in retain-release-path-notes-gc.m. +***/ + +@interface NSObject ++ (id)alloc; +- (id)init; +- (void)dealloc; + +- (Class)class; + +- (id)retain; +- (void)release; +- (void)autorelease; +@end + +@interface Foo : NSObject +- (id)methodWithValue; +@property(retain) id propertyValue; +@end + +typedef struct CFType *CFTypeRef; +CFTypeRef CFRetain(CFTypeRef); +void CFRelease(CFTypeRef); + +id NSMakeCollectable(CFTypeRef); +CFTypeRef CFMakeCollectable(CFTypeRef); + +CFTypeRef CFCreateSomething(); +CFTypeRef CFGetSomething(); + + +void creationViaAlloc () { + id leaked = [[NSObject alloc] init]; // expected-warning{{leak}} expected-note{{Method returns an Objective-C object with a +1 retain count}} + return; // expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}} +} + +void creationViaCFCreate () { + CFTypeRef leaked = CFCreateSomething(); // expected-warning{{leak}} expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation object with a +1 retain count}} + return; // expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}} +} + +void acquisitionViaMethod (Foo *foo) { + id leaked = [foo methodWithValue]; // expected-warning{{leak}} expected-note{{Method returns an Objective-C object with a +0 retain count}} + [leaked retain]; // expected-note{{Reference count incremented. The object now has a +1 retain count}} + [leaked retain]; // expected-note{{Reference count incremented. The object now has a +2 retain count}} + [leaked release]; // expected-note{{Reference count decremented. The object now has a +1 retain count}} + return; // expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}} +} + +void acquisitionViaProperty (Foo *foo) { + id leaked = foo.propertyValue; // expected-warning{{leak}} expected-note{{Property returns an Objective-C object with a +0 retain count}} + [leaked retain]; // expected-note{{Reference count incremented. The object now has a +1 retain count}} + return; // expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}} +} + +void acquisitionViaCFFunction () { + CFTypeRef leaked = CFGetSomething(); // expected-warning{{leak}} expected-note{{Call to function 'CFGetSomething' returns a Core Foundation object with a +0 retain count}} + CFRetain(leaked); // expected-note{{Reference count incremented. The object now has a +1 retain count}} + return; // expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}} +} + +void explicitDealloc () { + id object = [[NSObject alloc] init]; // expected-note{{Method returns an Objective-C object with a +1 retain count}} + [object dealloc]; // expected-note{{Object released by directly sending the '-dealloc' message}} + [object class]; // expected-warning{{Reference-counted object is used after it is released}} // expected-note{{Reference-counted object is used after it is released}} +} + +void implicitDealloc () { + id object = [[NSObject alloc] init]; // expected-note{{Method returns an Objective-C object with a +1 retain count}} + [object release]; // expected-note{{Object released}} + [object class]; // expected-warning{{Reference-counted object is used after it is released}} // expected-note{{Reference-counted object is used after it is released}} +} + +void overAutorelease () { + id object = [[NSObject alloc] init]; // expected-note{{Method returns an Objective-C object with a +1 retain count}} + [object autorelease]; // expected-note{{Object sent -autorelease message}} + [object autorelease]; // expected-note{{Object sent -autorelease message}} + return; // expected-warning{{Object sent -autorelease too many times}} expected-note{{Object over-autoreleased: object was sent -autorelease 2 times but the object has a +1 retain count}} +} + +void autoreleaseUnowned (Foo *foo) { + id object = foo.propertyValue; // expected-note{{Property returns an Objective-C object with a +0 retain count}} + [object autorelease]; // expected-note{{Object sent -autorelease message}} + return; // expected-warning{{Object sent -autorelease too many times}} expected-note{{Object over-autoreleased: object was sent -autorelease but the object has a +0 retain count}} +} + +void makeCollectableIgnored () { + CFTypeRef leaked = CFCreateSomething(); // expected-warning{{leak}} expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation object with a +1 retain count}} + CFMakeCollectable(leaked); // expected-note{{When GC is not enabled a call to 'CFMakeCollectable' has no effect on its argument}} + NSMakeCollectable(leaked); // expected-note{{When GC is not enabled a call to 'NSMakeCollectable' has no effect on its argument}} + return; // expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}} +} + +CFTypeRef CFCopyRuleViolation () { + CFTypeRef object = CFGetSomething(); // expected-note{{Call to function 'CFGetSomething' returns a Core Foundation object with a +0 retain counte}} + return object; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} expected-note{{Object returned to caller with a +0 retain count}} expected-note{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} +} + +CFTypeRef CFGetRuleViolation () { + CFTypeRef object = CFCreateSomething(); // expected-warning{{leak}} expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation object with a +1 retain counte}} + return object; // expected-note{{Object returned to caller as an owning reference (single retain count transferred to caller)}} expected-note{{Object leaked: object allocated and stored into 'object' is return from a function whose name ('CFGetRuleViolation') does not contain 'Copy' or 'Create'. This violates the naming convention rules given the Memory Management Guide for Core Foundation}} +} + +@implementation Foo (FundamentalMemoryManagementRules) +- (id)copyViolation { + id result = self.propertyValue; // expected-note{{Property returns an Objective-C object with a +0 retain count}} + return result; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} expected-note{{Object returned to caller with a +0 retain count}} expected-note{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} +} + +- (id)getViolation { + id result = [[Foo alloc] init]; // expected-warning{{leak}} expected-note{{Method returns an Objective-C object with a +1 retain count}} + return result; // expected-note{{Object returned to caller as an owning reference (single retain count transferred to caller)}} expected-note{{Object leaked: object allocated and stored into 'result' is returned from a method whose name ('getViolation') does not start with 'copy', 'mutableCopy', 'alloc' or 'new'. This violates the naming convention rules given in the Memory Management Guide for Cocoa}} +} +@end diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index 7af14f1..71ae756 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -116,6 +116,7 @@ typedef struct _NSZone NSZone; - (id)retain; - (oneway void)release; - (id)autorelease; +- (id)init; @end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @@ -517,7 +518,7 @@ void f17(int x, CFTypeRef p) { @implementation TestReturnNotOwnedWhenExpectedOwned - (NSString*)newString { NSString *s = [NSString stringWithUTF8String:"hello"]; - return s; // expected-warning{{Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected}} + return s; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} } @end @@ -735,7 +736,7 @@ typedef CFTypeRef OtherRef; - (id)initReturningNewClassBad2 { [self release]; self = [[RDar6320065Subclass alloc] init]; - return [self autorelease]; // expected-warning{{Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected}} + return [self autorelease]; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} } @end @@ -1302,7 +1303,7 @@ CFDateRef returnsRetainedCFDate() { } - (CFDateRef) newCFRetainedAsCFNoAttr { - return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease]; // expected-warning{{Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected}} + return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease]; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} } - (NSDate*) alsoReturnsRetained { @@ -1445,7 +1446,7 @@ static void rdar_8724287(CFErrorRef error) while (error_to_dump != ((void*)0)) { CFDictionaryRef info; - info = CFErrorCopyUserInfo(error_to_dump); // expected-warning{{Potential leak of an object allocated on line 1448 and stored into 'info'}} + info = CFErrorCopyUserInfo(error_to_dump); // expected-warning{{Potential leak of an object allocated on line 1449 and stored into 'info'}} if (info != ((void*)0)) { } @@ -1461,3 +1462,81 @@ extern void rdar_9234108_helper(void *key, void * CF_CONSUMED value); void rdar_9234108() { rdar_9234108_helper(0, CFStringCreate()); } + +// <rdar://problem/9726279> - Make sure that objc_method_family works +// to override naming conventions. +struct TwoDoubles { + double one; + double two; +}; +typedef struct TwoDoubles TwoDoubles; + +@interface NSValue (Mine) +- (id)_prefix_initWithTwoDoubles:(TwoDoubles)twoDoubles __attribute__((objc_method_family(init))); +@end + +@implementation NSValue (Mine) +- (id)_prefix_initWithTwoDoubles:(TwoDoubles)twoDoubles +{ + return [self init]; +} +@end + +void rdar9726279() { + TwoDoubles twoDoubles = { 0.0, 0.0 }; + NSValue *value = [[NSValue alloc] _prefix_initWithTwoDoubles:twoDoubles]; + [value release]; +} + +// <rdar://problem/9732321> +// Test camelcase support for CF conventions. While Core Foundation APIs +// don't use camel casing, other code is allowed to use it. +CFArrayRef camelcase_create_1() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning +} + +CFArrayRef camelcase_createno() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}} +} + +CFArrayRef camelcase_copy() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning +} + +CFArrayRef camelcase_copying() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}} +} + +CFArrayRef copyCamelCase() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning +} + +CFArrayRef __copyCamelCase() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning +} + +CFArrayRef __createCamelCase() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning +} + +CFArrayRef camel_create() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning +} + + +CFArrayRef camel_creat() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}} +} + +CFArrayRef camel_copy() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning +} + +CFArrayRef camel_copyMachine() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning +} + +CFArrayRef camel_copymachine() { + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}} +} + diff --git a/test/Analysis/retain-release.mm b/test/Analysis/retain-release.mm index 0faeb1a..bdc3dc0 100644 --- a/test/Analysis/retain-release.mm +++ b/test/Analysis/retain-release.mm @@ -121,6 +121,7 @@ typedef struct _NSZone NSZone; + (id)allocWithZone:(NSZone *)zone; + (id)alloc; - (void)dealloc; +- (id)init; @end @interface NSObject (NSCoderMethods) - (id)awakeAfterUsingCoder:(NSCoder *)aDecoder; diff --git a/test/Analysis/string-fail.c b/test/Analysis/string-fail.c new file mode 100644 index 0000000..64ac504 --- /dev/null +++ b/test/Analysis/string-fail.c @@ -0,0 +1,113 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.experimental.CString,deadcode.experimental.UnreachableCode -analyzer-store=region -Wno-null-dereference -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-checker=core,unix.experimental.CString,deadcode.experimental.UnreachableCode -analyzer-store=region -Wno-null-dereference -verify %s +// XFAIL: * + +// This file is for tests that may eventually go into string.c, or may be +// deleted outright. At one point these tests passed, but only because we +// weren't correctly modelling the behavior of the relevant string functions. +// The tests aren't incorrect, but require the analyzer to be smarter about +// conjured values than it currently is. + +//===----------------------------------------------------------------------=== +// 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 available 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 */ + +#define NULL 0 +typedef typeof(sizeof(int)) size_t; + + +//===----------------------------------------------------------------------=== +// strnlen() +//===----------------------------------------------------------------------=== + +#define strnlen BUILTIN(strnlen) +size_t strnlen(const char *s, size_t maxlen); + +void strnlen_liveness(const char *x) { + if (strnlen(x, 10) < 5) + return; + if (strnlen(x, 10) < 5) + (void)*(char*)0; // no-warning +} + +void strnlen_subregion() { + struct two_stringsn { char a[2], b[2]; }; + extern void use_two_stringsn(struct two_stringsn *); + + struct two_stringsn z; + use_two_stringsn(&z); + + size_t a = strnlen(z.a, 10); + z.b[0] = 5; + size_t b = strnlen(z.a, 10); + if (a == 0 && b != 0) + (void)*(char*)0; // expected-warning{{never executed}} + + use_two_stringsn(&z); + + size_t c = strnlen(z.a, 10); + if (a == 0 && c != 0) + (void)*(char*)0; // expected-warning{{null}} +} + +extern void use_stringn(char *); +void strnlen_argument(char *x) { + size_t a = strnlen(x, 10); + size_t b = strnlen(x, 10); + if (a == 0 && b != 0) + (void)*(char*)0; // expected-warning{{never executed}} + + use_stringn(x); + + size_t c = strnlen(x, 10); + if (a == 0 && c != 0) + (void)*(char*)0; // expected-warning{{null}} +} + +extern char global_strn[]; +void strnlen_global() { + size_t a = strnlen(global_strn, 10); + size_t b = strnlen(global_strn, 10); + if (a == 0 && b != 0) + (void)*(char*)0; // expected-warning{{never executed}} + + // Call a function with unknown effects, which should invalidate globals. + use_stringn(0); + + size_t c = strnlen(global_strn, 10); + if (a == 0 && c != 0) + (void)*(char*)0; // expected-warning{{null}} +} + +void strnlen_indirect(char *x) { + size_t a = strnlen(x, 10); + char *p = x; + char **p2 = &p; + size_t b = strnlen(x, 10); + if (a == 0 && b != 0) + (void)*(char*)0; // expected-warning{{never executed}} + + extern void use_stringn_ptr(char*const*); + use_stringn_ptr(p2); + + size_t c = strnlen(x, 10); + if (a == 0 && c != 0) + (void)*(char*)0; // expected-warning{{null}} +} diff --git a/test/Analysis/string.c b/test/Analysis/string.c index e6baf51..dc97e1a 100644 --- a/test/Analysis/string.c +++ b/test/Analysis/string.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,cplusplus.experimental.CString,deadcode.experimental.UnreachableCode -analyzer-store=region -Wno-null-dereference -verify %s -// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-checker=core,cplusplus.experimental.CString,deadcode.experimental.UnreachableCode -analyzer-store=region -Wno-null-dereference -verify %s -// RUN: %clang_cc1 -analyze -DVARIANT -analyzer-checker=core,cplusplus.experimental.CString,deadcode.experimental.UnreachableCode -analyzer-store=region -Wno-null-dereference -verify %s -// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -DVARIANT -analyzer-checker=core,cplusplus.experimental.CString,deadcode.experimental.UnreachableCode -analyzer-store=region -Wno-null-dereference -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.experimental.CString,deadcode.experimental.UnreachableCode -analyzer-store=region -Wno-null-dereference -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-checker=core,unix.experimental.CString,deadcode.experimental.UnreachableCode -analyzer-store=region -Wno-null-dereference -verify %s +// RUN: %clang_cc1 -analyze -DVARIANT -analyzer-checker=core,unix.experimental.CString,deadcode.experimental.UnreachableCode -analyzer-store=region -Wno-null-dereference -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -DVARIANT -analyzer-checker=core,unix.experimental.CString,deadcode.experimental.UnreachableCode -analyzer-store=region -Wno-null-dereference -verify %s //===----------------------------------------------------------------------=== // Declarations @@ -55,16 +55,16 @@ void strlen_constant2(char x) { } size_t strlen_null() { - return strlen(0); // expected-warning{{Null pointer argument in call to byte string function}} + return strlen(0); // expected-warning{{Null pointer argument in call to string length function}} } size_t strlen_fn() { - return strlen((char*)&strlen_fn); // expected-warning{{Argument to byte string function is the address of the function 'strlen_fn', which is not a null-terminated string}} + return strlen((char*)&strlen_fn); // expected-warning{{Argument to string length function is the address of the function 'strlen_fn', which is not a null-terminated string}} } size_t strlen_nonloc() { label: - return strlen((char*)&&label); // expected-warning{{Argument to byte string function is the address of the label 'label', which is not a null-terminated string}} + return strlen((char*)&&label); // expected-warning{{Argument to string length function is the address of the label 'label', which is not a null-terminated string}} } void strlen_subregion() { @@ -143,24 +143,23 @@ void strlen_liveness(const char *x) { // strnlen() //===----------------------------------------------------------------------=== -#define strnlen BUILTIN(strnlen) size_t strnlen(const char *s, size_t maxlen); void strnlen_constant0() { if (strnlen("123", 10) != 3) - (void)*(char*)0; // no-warning + (void)*(char*)0; // expected-warning{{never executed}} } void strnlen_constant1() { const char *a = "123"; if (strnlen(a, 10) != 3) - (void)*(char*)0; // no-warning + (void)*(char*)0; // expected-warning{{never executed}} } void strnlen_constant2(char x) { char a[] = "123"; if (strnlen(a, 10) != 3) - (void)*(char*)0; // no-warning + (void)*(char*)0; // expected-warning{{never executed}} a[0] = x; if (strnlen(a, 10) != 3) (void)*(char*)0; // expected-warning{{null}} @@ -168,107 +167,90 @@ void strnlen_constant2(char x) { void strnlen_constant4() { if (strnlen("123456", 3) != 3) - (void)*(char*)0; // no-warning + (void)*(char*)0; // expected-warning{{never executed}} } void strnlen_constant5() { const char *a = "123456"; if (strnlen(a, 3) != 3) - (void)*(char*)0; // no-warning + (void)*(char*)0; // expected-warning{{never executed}} } void strnlen_constant6(char x) { char a[] = "123456"; if (strnlen(a, 3) != 3) - (void)*(char*)0; // no-warning + (void)*(char*)0; // expected-warning{{never executed}} a[0] = x; if (strnlen(a, 3) != 3) (void)*(char*)0; // expected-warning{{null}} } size_t strnlen_null() { - return strnlen(0, 3); // expected-warning{{Null pointer argument in call to byte string function}} + return strnlen(0, 3); // expected-warning{{Null pointer argument in call to string length function}} } size_t strnlen_fn() { - return strnlen((char*)&strlen_fn, 3); // expected-warning{{Argument to byte string function is the address of the function 'strlen_fn', which is not a null-terminated string}} + return strnlen((char*)&strlen_fn, 3); // expected-warning{{Argument to string length function is the address of the function 'strlen_fn', which is not a null-terminated string}} } size_t strnlen_nonloc() { label: - return strnlen((char*)&&label, 3); // expected-warning{{Argument to byte string function is the address of the label 'label', which is not a null-terminated string}} + return strnlen((char*)&&label, 3); // expected-warning{{Argument to string length function is the address of the label 'label', which is not a null-terminated string}} } -void strnlen_subregion() { - struct two_stringsn { char a[2], b[2]; }; - extern void use_two_stringsn(struct two_stringsn *); - - struct two_stringsn z; - use_two_stringsn(&z); - - size_t a = strnlen(z.a, 10); - z.b[0] = 5; - size_t b = strnlen(z.a, 10); - if (a == 0 && b != 0) +void strnlen_zero() { + if (strnlen("abc", 0) != 0) (void)*(char*)0; // expected-warning{{never executed}} + if (strnlen(NULL, 0) != 0) // no-warning + (void)*(char*)0; // no-warning +} + +size_t strnlen_compound_literal() { + // This used to crash because we don't model the string lengths of + // compound literals. + return strnlen((char[]) { 'a', 'b', 0 }, 1); +} - use_two_stringsn(&z); +size_t strnlen_unknown_limit(float f) { + // This used to crash because we don't model the integer values of floats. + return strnlen("abc", (int)f); +} - size_t c = strnlen(z.a, 10); - if (a == 0 && c != 0) +void strnlen_is_not_strlen(char *x) { + if (strnlen(x, 10) != strlen(x)) (void)*(char*)0; // expected-warning{{null}} } -extern void use_stringn(char *); -void strnlen_argument(char *x) { - size_t a = strnlen(x, 10); - size_t b = strnlen(x, 10); - if (a == 0 && b != 0) +void strnlen_at_limit(char *x) { + size_t len = strnlen(x, 10); + if (len > 10) (void)*(char*)0; // expected-warning{{never executed}} - - use_stringn(x); - - size_t c = strnlen(x, 10); - if (a == 0 && c != 0) - (void)*(char*)0; // expected-warning{{null}} + if (len == 10) + (void)*(char*)0; // expected-warning{{null}} } -extern char global_strn[]; -void strnlen_global() { - size_t a = strnlen(global_strn, 10); - size_t b = strnlen(global_strn, 10); - if (a == 0 && b != 0) +void strnlen_less_than_limit(char *x) { + size_t len = strnlen(x, 10); + if (len > 10) (void)*(char*)0; // expected-warning{{never executed}} - - // Call a function with unknown effects, which should invalidate globals. - use_stringn(0); - - size_t c = strnlen(global_str, 10); - if (a == 0 && c != 0) - (void)*(char*)0; // expected-warning{{null}} + if (len < 10) + (void)*(char*)0; // expected-warning{{null}} } -void strnlen_indirect(char *x) { - size_t a = strnlen(x, 10); - char *p = x; - char **p2 = &p; - size_t b = strnlen(x, 10); - if (a == 0 && b != 0) +void strnlen_at_actual(size_t limit) { + size_t len = strnlen("abc", limit); + if (len > 3) (void)*(char*)0; // expected-warning{{never executed}} - - extern void use_stringn_ptr(char*const*); - use_stringn_ptr(p2); - - size_t c = strnlen(x, 10); - if (a == 0 && c != 0) + if (len == 3) (void)*(char*)0; // expected-warning{{null}} } -void strnlen_liveness(const char *x) { - if (strnlen(x, 10) < 5) - return; - if (strnlen(x, 10) < 5) - (void)*(char*)0; // no-warning +void strnlen_less_than_actual(size_t limit) { + size_t len = strnlen("abc", limit); + if (len > 3) + (void)*(char*)0; // expected-warning{{never executed}} + if (len < 3) + (void)*(char*)0; // expected-warning{{null}} } //===----------------------------------------------------------------------=== @@ -291,15 +273,15 @@ char *strcpy(char *restrict s1, const char *restrict s2); void strcpy_null_dst(char *x) { - strcpy(NULL, x); // expected-warning{{Null pointer argument in call to byte string function}} + strcpy(NULL, x); // expected-warning{{Null pointer argument in call to string copy function}} } void strcpy_null_src(char *x) { - strcpy(x, NULL); // expected-warning{{Null pointer argument in call to byte string function}} + strcpy(x, NULL); // expected-warning{{Null pointer argument in call to string copy function}} } void strcpy_fn(char *x) { - strcpy(x, (char*)&strcpy_fn); // expected-warning{{Argument to byte string function is the address of the function 'strcpy_fn', which is not a null-terminated string}} + strcpy(x, (char*)&strcpy_fn); // expected-warning{{Argument to string copy function is the address of the function 'strcpy_fn', which is not a null-terminated string}} } void strcpy_effects(char *x, char *y) { @@ -318,7 +300,7 @@ void strcpy_effects(char *x, char *y) { void strcpy_overflow(char *y) { char x[4]; if (strlen(y) == 4) - strcpy(x, y); // expected-warning{{Byte string function overflows destination buffer}} + strcpy(x, y); // expected-warning{{String copy function overflows destination buffer}} } void strcpy_no_overflow(char *y) { @@ -362,7 +344,7 @@ void stpcpy_effect(char *x, char *y) { void stpcpy_overflow(char *y) { char x[4]; if (strlen(y) == 4) - stpcpy(x, y); // expected-warning{{Byte string function overflows destination buffer}} + stpcpy(x, y); // expected-warning{{String copy function overflows destination buffer}} } void stpcpy_no_overflow(char *y) { @@ -391,15 +373,15 @@ char *strcat(char *restrict s1, const char *restrict s2); void strcat_null_dst(char *x) { - strcat(NULL, x); // expected-warning{{Null pointer argument in call to byte string function}} + strcat(NULL, x); // expected-warning{{Null pointer argument in call to string copy function}} } void strcat_null_src(char *x) { - strcat(x, NULL); // expected-warning{{Null pointer argument in call to byte string function}} + strcat(x, NULL); // expected-warning{{Null pointer argument in call to string copy function}} } void strcat_fn(char *x) { - strcat(x, (char*)&strcat_fn); // expected-warning{{Argument to byte string function is the address of the function 'strcat_fn', which is not a null-terminated string}} + strcat(x, (char*)&strcat_fn); // expected-warning{{Argument to string copy function is the address of the function 'strcat_fn', which is not a null-terminated string}} } void strcat_effects(char *y) { @@ -415,27 +397,24 @@ void strcat_effects(char *y) { if ((int)strlen(x) != (orig_len + strlen(y))) (void)*(char*)0; // no-warning - - if (a != x[0]) - (void)*(char*)0; // expected-warning{{null}} } void strcat_overflow_0(char *y) { char x[4] = "12"; if (strlen(y) == 4) - strcat(x, y); // expected-warning{{Byte string function overflows destination buffer}} + strcat(x, y); // expected-warning{{String copy function overflows destination buffer}} } void strcat_overflow_1(char *y) { char x[4] = "12"; if (strlen(y) == 3) - strcat(x, y); // expected-warning{{Byte string function overflows destination buffer}} + strcat(x, y); // expected-warning{{String copy function overflows destination buffer}} } void strcat_overflow_2(char *y) { char x[4] = "12"; if (strlen(y) == 2) - strcat(x, y); // expected-warning{{Byte string function overflows destination buffer}} + strcat(x, y); // expected-warning{{String copy function overflows destination buffer}} } void strcat_no_overflow(char *y) { @@ -444,6 +423,136 @@ void strcat_no_overflow(char *y) { strcat(x, y); // no-warning } +void strcat_symbolic_dst_length(char *dst) { + strcat(dst, "1234"); + if (strlen(dst) < 4) + (void)*(char*)0; // no-warning +} + +void strcat_symbolic_src_length(char *src) { + char dst[8] = "1234"; + strcat(dst, src); + if (strlen(dst) < 4) + (void)*(char*)0; // no-warning +} + +void strcat_unknown_src_length(char *src, int offset) { + char dst[8] = "1234"; + strcat(dst, &src[offset]); + if (strlen(dst) < 4) + (void)*(char*)0; // no-warning +} + +// There is no strcat_unknown_dst_length because if we can't get a symbolic +// length for the "before" strlen, we won't be able to set one for "after". + +void strcat_too_big(char *dst, char *src) { + if (strlen(dst) != (((size_t)0) - 2)) + return; + if (strlen(src) != 2) + return; + strcat(dst, src); // expected-warning{{This expression will create a string whose length is too big to be represented as a size_t}} +} + + +//===----------------------------------------------------------------------=== +// strncpy() +//===----------------------------------------------------------------------=== + +#ifdef VARIANT + +#define __strncpy_chk BUILTIN(__strncpy_chk) +char *__strncpy_chk(char *restrict s1, const char *restrict s2, size_t n, size_t destlen); + +#define strncpy(a,b,n) __strncpy_chk(a,b,n,(size_t)-1) + +#else /* VARIANT */ + +#define strncpy BUILTIN(strncpy) +char *strncpy(char *restrict s1, const char *restrict s2, size_t n); + +#endif /* VARIANT */ + + +void strncpy_null_dst(char *x) { + strncpy(NULL, x, 5); // expected-warning{{Null pointer argument in call to string copy function}} +} + +void strncpy_null_src(char *x) { + strncpy(x, NULL, 5); // expected-warning{{Null pointer argument in call to string copy function}} +} + +void strncpy_fn(char *x) { + strncpy(x, (char*)&strcpy_fn, 5); // expected-warning{{Argument to string copy function is the address of the function 'strcpy_fn', which is not a null-terminated string}} +} + +void strncpy_effects(char *x, char *y) { + char a = x[0]; + + if (strncpy(x, y, 5) != x) + (void)*(char*)0; // no-warning + + if (strlen(x) != strlen(y)) + (void)*(char*)0; // expected-warning{{null}} + + if (a != x[0]) + (void)*(char*)0; // expected-warning{{null}} +} + +void strncpy_overflow(char *y) { + char x[4]; + if (strlen(y) == 4) + strncpy(x, y, 5); // expected-warning{{Size argument is greater than the length of the destination buffer}} +} + +void strncpy_no_overflow(char *y) { + char x[4]; + if (strlen(y) == 3) + strncpy(x, y, 5); // expected-warning{{Size argument is greater than the length of the destination buffer}} +} + +void strncpy_no_overflow2(char *y, int n) { + if (n <= 4) + return; + + char x[4]; + if (strlen(y) == 3) + strncpy(x, y, n); // expected-warning{{Size argument is greater than the length of the destination buffer}} +} + +void strncpy_truncate(char *y) { + char x[4]; + if (strlen(y) == 4) + strncpy(x, y, 3); // no-warning +} + +void strncpy_no_truncate(char *y) { + char x[4]; + if (strlen(y) == 3) + strncpy(x, y, 3); // no-warning +} + +void strncpy_exactly_matching_buffer(char *y) { + char x[4]; + strncpy(x, y, 4); // no-warning + + // strncpy does not null-terminate, so we have no idea what the strlen is + // after this. + if (strlen(x) > 4) + (void)*(int*)0; // expected-warning{{null}} +} + +void strncpy_exactly_matching_buffer2(char *y) { + if (strlen(y) >= 4) + return; + + char x[4]; + strncpy(x, y, 4); // no-warning + + // This time, we know that y fits in x anyway. + if (strlen(x) > 3) + (void)*(int*)0; // no-warning +} //===----------------------------------------------------------------------=== // strncat() @@ -465,15 +574,15 @@ char *strncat(char *restrict s1, const char *restrict s2, size_t n); void strncat_null_dst(char *x) { - strncat(NULL, x, 4); // expected-warning{{Null pointer argument in call to byte string function}} + strncat(NULL, x, 4); // expected-warning{{Null pointer argument in call to string copy function}} } void strncat_null_src(char *x) { - strncat(x, NULL, 4); // expected-warning{{Null pointer argument in call to byte string function}} + strncat(x, NULL, 4); // expected-warning{{Null pointer argument in call to string copy function}} } void strncat_fn(char *x) { - strncat(x, (char*)&strncat_fn, 4); // expected-warning{{Argument to byte string function is the address of the function 'strncat_fn', which is not a null-terminated string}} + strncat(x, (char*)&strncat_fn, 4); // expected-warning{{Argument to string copy function is the address of the function 'strncat_fn', which is not a null-terminated string}} } void strncat_effects(char *y) { @@ -489,33 +598,30 @@ void strncat_effects(char *y) { if (strlen(x) != orig_len + strlen(y)) (void)*(char*)0; // no-warning - - if (a != x[0]) - (void)*(char*)0; // expected-warning{{null}} } void strncat_overflow_0(char *y) { char x[4] = "12"; if (strlen(y) == 4) - strncat(x, y, strlen(y)); // expected-warning{{Byte string function overflows destination buffer}} + strncat(x, y, strlen(y)); // expected-warning{{Size argument is greater than the free space in the destination buffer}} } void strncat_overflow_1(char *y) { char x[4] = "12"; if (strlen(y) == 3) - strncat(x, y, strlen(y)); // expected-warning{{Byte string function overflows destination buffer}} + strncat(x, y, strlen(y)); // expected-warning{{Size argument is greater than the free space in the destination buffer}} } void strncat_overflow_2(char *y) { char x[4] = "12"; if (strlen(y) == 2) - strncat(x, y, strlen(y)); // expected-warning{{Byte string function overflows destination buffer}} + strncat(x, y, strlen(y)); // expected-warning{{Size argument is greater than the free space in the destination buffer}} } void strncat_overflow_3(char *y) { char x[4] = "12"; if (strlen(y) == 4) - strncat(x, y, 2); // expected-warning{{Byte string function overflows destination buffer}} + strncat(x, y, 2); // expected-warning{{Size argument is greater than the free space in the destination buffer}} } void strncat_no_overflow_1(char *y) { char x[5] = "12"; @@ -529,12 +635,69 @@ void strncat_no_overflow_2(char *y) { strncat(x, y, 1); // no-warning } +void strncat_symbolic_dst_length(char *dst) { + strncat(dst, "1234", 5); + if (strlen(dst) < 4) + (void)*(char*)0; // no-warning +} + +void strncat_symbolic_src_length(char *src) { + char dst[8] = "1234"; + strncat(dst, src, 3); + if (strlen(dst) < 4) + (void)*(char*)0; // no-warning + + char dst2[8] = "1234"; + strncat(dst2, src, 4); // expected-warning{{Size argument is greater than the free space in the destination buffer}} +} + +void strncat_unknown_src_length(char *src, int offset) { + char dst[8] = "1234"; + strncat(dst, &src[offset], 3); + if (strlen(dst) < 4) + (void)*(char*)0; // no-warning + + char dst2[8] = "1234"; + strncat(dst2, &src[offset], 4); // expected-warning{{Size argument is greater than the free space in the destination buffer}} +} + +// There is no strncat_unknown_dst_length because if we can't get a symbolic +// length for the "before" strlen, we won't be able to set one for "after". + +void strncat_symbolic_limit(unsigned limit) { + char dst[6] = "1234"; + char src[] = "567"; + strncat(dst, src, limit); // no-warning + if (strlen(dst) < 4) + (void)*(char*)0; // no-warning + if (strlen(dst) == 4) + (void)*(char*)0; // expected-warning{{null}} +} + +void strncat_unknown_limit(float limit) { + char dst[6] = "1234"; + char src[] = "567"; + strncat(dst, src, (size_t)limit); // no-warning + if (strlen(dst) < 4) + (void)*(char*)0; // no-warning + if (strlen(dst) == 4) + (void)*(char*)0; // expected-warning{{null}} +} + +void strncat_too_big(char *dst, char *src) { + if (strlen(dst) != (((size_t)0) - 2)) + return; + if (strlen(src) != 2) + return; + strncat(dst, src, 2); // expected-warning{{This expression will create a string whose length is too big to be represented as a size_t}} +} + //===----------------------------------------------------------------------=== // strcmp() //===----------------------------------------------------------------------=== #define strcmp BUILTIN(strcmp) -int strcmp(const char *restrict s1, const char *restrict s2); +int strcmp(const char * s1, const char * s2); void strcmp_constant0() { if (strcmp("123", "123") != 0) @@ -577,13 +740,13 @@ void strcmp_2() { void strcmp_null_0() { char *x = NULL; char *y = "123"; - strcmp(x, y); // expected-warning{{Null pointer argument in call to byte string function}} + strcmp(x, y); // expected-warning{{Null pointer argument in call to string comparison function}} } void strcmp_null_1() { char *x = "123"; char *y = NULL; - strcmp(x, y); // expected-warning{{Null pointer argument in call to byte string function}} + strcmp(x, y); // expected-warning{{Null pointer argument in call to string comparison function}} } void strcmp_diff_length_0() { @@ -614,12 +777,22 @@ void strcmp_diff_length_3() { (void)*(char*)0; // no-warning } +void strcmp_embedded_null () { + if (strcmp("\0z", "\0y") != 0) + (void)*(char*)0; // no-warning +} + +void strcmp_unknown_arg (char *unknown) { + if (strcmp(unknown, unknown) != 0) + (void)*(char*)0; // no-warning +} + //===----------------------------------------------------------------------=== // strncmp() //===----------------------------------------------------------------------=== #define strncmp BUILTIN(strncmp) -int strncmp(const char *restrict s1, const char *restrict s2, size_t n); +int strncmp(const char *s1, const char *s2, size_t n); void strncmp_constant0() { if (strncmp("123", "123", 3) != 0) @@ -662,13 +835,13 @@ void strncmp_2() { void strncmp_null_0() { char *x = NULL; char *y = "123"; - strncmp(x, y, 3); // expected-warning{{Null pointer argument in call to byte string function}} + strncmp(x, y, 3); // expected-warning{{Null pointer argument in call to string comparison function}} } void strncmp_null_1() { char *x = "123"; char *y = NULL; - strncmp(x, y, 3); // expected-warning{{Null pointer argument in call to byte string function}} + strncmp(x, y, 3); // expected-warning{{Null pointer argument in call to string comparison function}} } void strncmp_diff_length_0() { @@ -720,12 +893,17 @@ void strncmp_diff_length_6() { (void)*(char*)0; // no-warning } +void strncmp_embedded_null () { + if (strncmp("ab\0zz", "ab\0yy", 4) != 0) + (void)*(char*)0; // no-warning +} + //===----------------------------------------------------------------------=== // strcasecmp() //===----------------------------------------------------------------------=== #define strcasecmp BUILTIN(strcasecmp) -int strcasecmp(const char *restrict s1, const char *restrict s2); +int strcasecmp(const char *s1, const char *s2); void strcasecmp_constant0() { if (strcasecmp("abc", "Abc") != 0) @@ -768,13 +946,13 @@ void strcasecmp_2() { void strcasecmp_null_0() { char *x = NULL; char *y = "123"; - strcasecmp(x, y); // expected-warning{{Null pointer argument in call to byte string function}} + strcasecmp(x, y); // expected-warning{{Null pointer argument in call to string comparison function}} } void strcasecmp_null_1() { char *x = "123"; char *y = NULL; - strcasecmp(x, y); // expected-warning{{Null pointer argument in call to byte string function}} + strcasecmp(x, y); // expected-warning{{Null pointer argument in call to string comparison function}} } void strcasecmp_diff_length_0() { @@ -805,12 +983,17 @@ void strcasecmp_diff_length_3() { (void)*(char*)0; // no-warning } +void strcasecmp_embedded_null () { + if (strcasecmp("ab\0zz", "ab\0yy") != 0) + (void)*(char*)0; // no-warning +} + //===----------------------------------------------------------------------=== // strncasecmp() //===----------------------------------------------------------------------=== #define strncasecmp BUILTIN(strncasecmp) -int strncasecmp(const char *restrict s1, const char *restrict s2, size_t n); +int strncasecmp(const char *s1, const char *s2, size_t n); void strncasecmp_constant0() { if (strncasecmp("abc", "Abc", 3) != 0) @@ -853,13 +1036,13 @@ void strncasecmp_2() { void strncasecmp_null_0() { char *x = NULL; char *y = "123"; - strncasecmp(x, y, 3); // expected-warning{{Null pointer argument in call to byte string function}} + strncasecmp(x, y, 3); // expected-warning{{Null pointer argument in call to string comparison function}} } void strncasecmp_null_1() { char *x = "123"; char *y = NULL; - strncasecmp(x, y, 3); // expected-warning{{Null pointer argument in call to byte string function}} + strncasecmp(x, y, 3); // expected-warning{{Null pointer argument in call to string comparison function}} } void strncasecmp_diff_length_0() { @@ -910,3 +1093,8 @@ void strncasecmp_diff_length_6() { if (strncasecmp(x, y, 3) != 1) (void)*(char*)0; // no-warning } + +void strncasecmp_embedded_null () { + if (strncasecmp("ab\0zz", "ab\0yy", 4) != 0) + (void)*(char*)0; // no-warning +} diff --git a/test/Analysis/uninit-ps-rdar6145427.m b/test/Analysis/uninit-ps-rdar6145427.m index f179406..f4df913 100644 --- a/test/Analysis/uninit-ps-rdar6145427.m +++ b/test/Analysis/uninit-ps-rdar6145427.m @@ -11,7 +11,10 @@ typedef struct _NSZone NSZone; @protocol NSObject - (BOOL)isEqual:(id)object; @end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end -@interface NSObject <NSObject> {} + (id)alloc; @end +@interface NSObject <NSObject> {} ++ (id)alloc; +- (id)init; +@end extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); @interface NSValue : NSObject <NSCopying, NSCoding> - (void)getValue:(void *)value; @end @class NSString, NSData; diff --git a/test/Analysis/uninit-vals-ps-region.m b/test/Analysis/uninit-vals-ps-region.m index 1700f54..c62818a 100644 --- a/test/Analysis/uninit-vals-ps-region.m +++ b/test/Analysis/uninit-vals-ps-region.m @@ -67,3 +67,12 @@ void rdar_7780304() { b.x |= 1; // expected-warning{{The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage}} } + +// The flip side of PR10163 -- float arrays that are actually uninitialized +// (The main test is in uninit-vals.m) +void test_PR10163(float); +void PR10163 (void) { + float x[2]; + test_PR10163(x[1]); // expected-warning{{uninitialized value}} +} + diff --git a/test/Analysis/uninit-vals.m b/test/Analysis/uninit-vals.m index 2cd5e0c..4b7e6f4 100644 --- a/test/Analysis/uninit-vals.m +++ b/test/Analysis/uninit-vals.m @@ -23,3 +23,12 @@ NSUInteger f8(A* x){ return n; } + + +// PR10163 -- don't warn for default-initialized float arrays. +// (An additional test is in uninit-vals-ps-region.m) +void test_PR10163(float); +void PR10163 (void) { + float x[2] = {0}; + test_PR10163(x[1]); // no-warning +} diff --git a/test/Analysis/variadic-method-types.m b/test/Analysis/variadic-method-types.m index 018956a..03c309a 100644 --- a/test/Analysis/variadic-method-types.m +++ b/test/Analysis/variadic-method-types.m @@ -73,13 +73,13 @@ void f(id a, id<P> b, C* c, C<P> *d, FooType fooType, BarType barType) { [NSDictionary dictionaryWithObjectsAndKeys:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSDictionary' method 'dictionaryWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}} [NSSet setWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSSet' method 'setWithObjects:' should be an Objective-C pointer type, not 'char *'}} - [[[NSArray alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} - [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}} + [[[NSArray alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to 'NSArray' method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} + [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to 'NSDictionary' method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}} [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", (void*) 0, nil] autorelease]; // no-warning [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", kCGImageSourceShouldCache, nil] autorelease]; // no-warning [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", fooType, nil] autorelease]; // no-warning - [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", barType, nil] autorelease]; // expected-warning {{Argument to method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'BarType'}} - [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} + [[[NSDictionary alloc] initWithObjectsAndKeys:@"Foo", barType, nil] autorelease]; // expected-warning {{Argument to 'NSDictionary' method 'initWithObjectsAndKeys:' should be an Objective-C pointer type, not 'BarType'}} + [[[NSSet alloc] initWithObjects:@"Foo", "Bar", nil] autorelease]; // expected-warning {{Argument to 'NSSet' method 'initWithObjects:' should be an Objective-C pointer type, not 'char *'}} } // This previously crashed the variadic argument checker. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e35413a..0f00e50 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -99,10 +99,10 @@ if(PYTHONINTERP_FOUND) COMMENT "Running Clang and LLVM regression tests") add_dependencies(check-all clang-test.deps) if ( LLVM_INCLUDE_TESTS ) - add_dependencies(check-all check.deps ClangUnitTests) + add_dependencies(clang-test.deps check.deps ClangUnitTests) endif ( LLVM_INCLUDE_TESTS ) add_dependencies(clang-test.deps - llvm-dis opt + llvm-dis llc opt FileCheck count not ) set_target_properties(check-all PROPERTIES FOLDER "Clang tests") @@ -110,7 +110,7 @@ if(PYTHONINTERP_FOUND) add_dependencies(clang-test clang-test.deps) add_dependencies(clang-test.deps - clang clang-headers c-index-test + clang clang-headers c-index-test arcmt-test c-arcmt-test ) endif() diff --git a/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp b/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp index ccadf41..15d86b7 100644 --- a/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp +++ b/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp @@ -19,8 +19,9 @@ namespace D { } namespace C { - class C {}; - void func(C); + class C {}; // expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'B::B' to 'const C::C &' for 1st argument}} + void func(C); // expected-note {{'C::func' declared here}} \ + // expected-note {{passing argument to parameter here}} C operator+(C,C); D::D operator+(D::D,D::D); } @@ -32,7 +33,13 @@ namespace D { namespace Test { void test() { func(A::A()); - func(B::B()); // expected-error {{use of undeclared identifier 'func'}} + // FIXME: namespace-aware typo correction causes an extra, misleading + // message in this case; some form of backtracking, diagnostic message + // delaying, or argument checking before emitting diagnostics is needed to + // avoid accepting and printing out a typo correction that proves to be + // incorrect once argument-dependent lookup resolution has occurred. + func(B::B()); // expected-error {{use of undeclared identifier 'func'; did you mean 'C::func'?}} \ + // expected-error {{no viable conversion from 'B::B' to 'C::C'}} func(C::C()); A::A() + A::A(); B::B() + B::B(); diff --git a/test/CXX/class/p6-0x.cpp b/test/CXX/class/p6-0x.cpp new file mode 100644 index 0000000..fc83e06 --- /dev/null +++ b/test/CXX/class/p6-0x.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x + +class Trivial { int n; void f(); }; +class NonTrivial1 { NonTrivial1(const NonTrivial1 &); }; +class NonTrivial2 { NonTrivial2(NonTrivial2 &&); }; +class NonTrivial3 { NonTrivial3 operator=(const NonTrivial3 &); }; +class NonTrivial4 { NonTrivial4 operator=(NonTrivial4 &&); }; +class NonTrivial5 { ~NonTrivial5(); }; + +static_assert(__is_trivial(Trivial), "Trivial is not trivial"); +static_assert(!__is_trivial(NonTrivial1), "NonTrivial1 is trivial"); +static_assert(!__is_trivial(NonTrivial2), "NonTrivial2 is trivial"); +static_assert(!__is_trivial(NonTrivial3), "NonTrivial3 is trivial"); +static_assert(!__is_trivial(NonTrivial4), "NonTrivial4 is trivial"); +static_assert(!__is_trivial(NonTrivial5), "NonTrivial5 is trivial"); diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p1.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p1.cpp index 40917b8..cbb439e 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p1.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p1.cpp @@ -7,13 +7,13 @@ template<typename T> void f(T) {} template<typename T> static void g(T) {} -template<> static void f<int>(int); // expected-error{{explicit specialization cannot have a storage class}} +template<> static void f<int>(int); // expected-error{{explicit specialization has extraneous, inconsistent storage class 'static'}} template static void f<float>(float); // expected-error{{explicit instantiation cannot have a storage class}} template<> void f<double>(double); template void f<long>(long); -template<> static void g<int>(int); // expected-error{{explicit specialization cannot have a storage class}} +template<> static void g<int>(int); // expected-warning{{explicit specialization cannot have a storage class}} template static void g<float>(float); // expected-error{{explicit instantiation cannot have a storage class}} template<> void g<double>(double); diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp index fabfb53..54da854 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp @@ -46,7 +46,7 @@ void j() { U<auto> v; // expected-error{{'auto' not allowed in template argument}} int n; - (void)dynamic_cast<auto&>(S()); // expected-error{{'auto' not allowed here}} + (void)dynamic_cast<auto&>(n); // expected-error{{'auto' not allowed here}} (void)static_cast<auto*>(&n); // expected-error{{'auto' not allowed here}} (void)reinterpret_cast<auto*>(&n); // expected-error{{'auto' not allowed here}} (void)const_cast<auto>(n); // expected-error{{'auto' not allowed here}} diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp index 06aeaa6..8b4b703 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp @@ -54,8 +54,7 @@ void f() { auto *fail1 = 0; // expected-error {{variable 'fail1' with type 'auto *' has incompatible initializer of type 'int'}} int **p; - // FIXME: due to PR9233, we get the wrong diagnostic here. - const auto **fail2(p); // desired-error {{variable 'fail2' with type 'auto const **' has incompatible initializer of type 'int **'}} expected-error {{cannot initialize}} + const auto **fail2(p); // expected-error {{variable 'fail2' with type 'auto const **' has incompatible initializer of type 'int **'}} } struct S { diff --git a/test/CXX/except/except.spec/canonical.cpp b/test/CXX/except/except.spec/canonical.cpp new file mode 100644 index 0000000..9bc26de --- /dev/null +++ b/test/CXX/except/except.spec/canonical.cpp @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +// PR10087: Make sure that we don't conflate exception specifications +// from different functions in the canonical type system. +namespace std +{ + +template <class _Tp> _Tp&& declval() noexcept; + +template <class _Tp, class... _Args> +struct __is_nothrow_constructible +{ + static const bool value = noexcept(_Tp(declval<_Args>()...)); +}; + +template<class, class _Traits, class _Allocator> +class basic_string +{ +public: + typedef typename _Traits::char_type value_type; + typedef _Allocator allocator_type; + + basic_string() + noexcept(__is_nothrow_constructible<allocator_type>::value); +}; + +template <class, class, class _Compare> +struct __map_value_compare +{ +public: + __map_value_compare() + noexcept(__is_nothrow_constructible<_Compare>::value); +}; + +struct less +{ +}; + +struct map +{ + typedef __map_value_compare<int, short, less> __vc; + __vc vc_; +}; + + +template<class T, class _Traits, class _Allocator> +basic_string<T, _Traits, _Allocator>::basic_string() noexcept(__is_nothrow_constructible<allocator_type>::value) {} + +template <class T, class Value, class _Compare> +__map_value_compare<T, Value, _Compare>::__map_value_compare() + noexcept(__is_nothrow_constructible<_Compare>::value) {} + +} // std diff --git a/test/CXX/except/except.spec/p14-ir.cpp b/test/CXX/except/except.spec/p14-ir.cpp index c681727..81fbf7d 100644 --- a/test/CXX/except/except.spec/p14-ir.cpp +++ b/test/CXX/except/except.spec/p14-ir.cpp @@ -26,12 +26,12 @@ struct X4 { struct X5 : X0, X4 { }; void test(X2 x2, X3 x3, X5 x5) { - // CHECK: define linkonce_odr void @_ZN2X2C1ERKS_(%struct.X0* %this, %struct.X0*) unnamed_addr + // CHECK: define linkonce_odr void @_ZN2X2C1ERKS_(%struct.X2* %this, %struct.X2*) unnamed_addr // CHECK: call void @_ZN2X2C2ERKS_({{.*}}) nounwind // CHECK-NEXT: ret void // CHECK-NEXT: } X2 x2a(x2); - // CHECK: define linkonce_odr void @_ZN2X3C1ERKS_(%struct.X0* %this, %struct.X0*) unnamed_addr + // CHECK: define linkonce_odr void @_ZN2X3C1ERKS_(%struct.X3* %this, %struct.X3*) unnamed_addr // CHECK: call void @_ZN2X3C2ERKS_({{.*}}) nounwind // CHECK-NEXT: ret void // CHECK-NEXT: } @@ -55,24 +55,25 @@ struct X8 : X6 { }; struct X9 : X6, X7 { }; void test() { - // CHECK: define linkonce_odr void @_ZN2X8C1Ev(%struct.X0* %this) unnamed_addr + // CHECK: define linkonce_odr void @_ZN2X8C1Ev(%struct.X8* %this) unnamed_addr // CHECK: call void @_ZN2X8C2Ev({{.*}}) nounwind // CHECK-NEXT: ret void X8(); - // CHECK: define linkonce_odr void @_ZN2X9C1Ev(%struct.X0* %this) unnamed_addr + // CHECK: define linkonce_odr void @_ZN2X9C1Ev(%struct.X9* %this) unnamed_addr // 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(%struct.X0* %this) unnamed_addr + // CHECK: define linkonce_odr void @_ZN2X9C2Ev(%struct.X9* %this) unnamed_addr // CHECK: call void @_ZN2X6C2Ev({{.*}}) nounwind // FIXME: and here: + // CHECK-NEXT: bitcast // CHECK-NEXT: call void @_ZN2X7C2Ev({{.*}}) // CHECK: ret void - // CHECK: define linkonce_odr void @_ZN2X8C2Ev(%struct.X0* %this) unnamed_addr + // CHECK: define linkonce_odr void @_ZN2X8C2Ev(%struct.X8* %this) unnamed_addr // CHECK: call void @_ZN2X6C2Ev({{.*}}) nounwind // CHECK-NEXT: ret void } diff --git a/test/CXX/special/class.copy/p33-0x.cpp b/test/CXX/special/class.copy/p33-0x.cpp index 1e6a025..b196865 100644 --- a/test/CXX/special/class.copy/p33-0x.cpp +++ b/test/CXX/special/class.copy/p33-0x.cpp @@ -23,3 +23,35 @@ void throw_move_only(X x) { throw x2; } +namespace PR10142 { + struct X { + X(); + X(X&&); + X(const X&) = delete; // expected-note 2{{function has been explicitly marked deleted here}} + }; + + void f(int i) { + X x; + try { + X x2; + if (i) + throw x2; // okay + throw x; // expected-error{{call to deleted constructor of 'PR10142::X'}} + } catch (...) { + } + } + + template<typename T> + void f2(int i) { + T x; + try { + T x2; + if (i) + throw x2; // okay + throw x; // expected-error{{call to deleted constructor of 'PR10142::X'}} + } catch (...) { + } + } + + template void f2<X>(int); // expected-note{{in instantiation of function template specialization 'PR10142::f2<PR10142::X>' requested here}} +} diff --git a/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp b/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp index b415044..40b4c23 100644 --- a/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp +++ b/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp @@ -30,13 +30,13 @@ struct Y { void f(); void test_Y() { - goto end; - Y y; + goto end; // expected-error{{goto into protected scope}} + Y y; // expected-note{{jump bypasses variable with a non-trivial destructor}} end: f(); - goto inner; + goto inner; // expected-error{{goto into protected scope}} { - Y y2; + Y y2; // expected-note{{jump bypasses variable with a non-trivial destructor}} inner: f(); } diff --git a/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp b/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp index 7bfa6fe..0c92f62 100644 --- a/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp +++ b/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp @@ -129,7 +129,7 @@ void g() { void *begin(); // expected-note {{selected 'begin' function with iterator type 'void *'}} void *end(); }; - for (auto u : NoIncr()) { // expected-error {{arithmetic on pointer to void type}} + for (auto u : NoIncr()) { // expected-error {{arithmetic on a pointer to void type}} } struct NoNotEq { diff --git a/test/CXX/temp/p3.cpp b/test/CXX/temp/p3.cpp new file mode 100644 index 0000000..16ebb38 --- /dev/null +++ b/test/CXX/temp/p3.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -verify %s + +template<typename T> struct S { + static int a, b; +}; + +template<typename T> int S<T>::a, S<T>::b; // expected-error {{can only declare a single entity}} + +// FIXME: the last two diagnostics here are terrible. +template<typename T> struct A { static A a; } A<T>::a; // expected-error {{expected ';' after struct}} \ + expected-error {{use of undeclared identifier 'T'}} \ + expected-error {{cannot name the global scope}} \ + expected-error {{no member named 'a' in the global namespace}} + +template<typename T> struct B { } f(); // expected-error {{expected ';' after struct}} \ + expected-error {{requires a type specifier}} + +template<typename T> struct C { } // expected-error {{expected ';' after struct}} + +A<int> c; diff --git a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp index 3c22cf3..295f080 100644 --- a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp +++ b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp @@ -71,7 +71,21 @@ void test_f3(int ***ip, volatile int ***vip) { A<int> a0 = f3(ip); A<volatile int> a1 = f3(vip); } - + +// Also accept conversions for pointer types which require removing +// [[noreturn]]. +namespace noreturn_stripping { + template <class R> + void f(R (*function)()); + + void g() __attribute__ ((__noreturn__)); + void h(); + void test() { + f(g); + f(h); + } +} + // - If P is a class, and P has the form template-id, then A can be a // derived class of the deduced A. Likewise, if P is a pointer to a class // of the form template-id, A can be a pointer to a derived class pointed @@ -123,3 +137,12 @@ namespace N { N::F<T1>(d); // OK } } + +namespace PR9233 { + template<typename T> void f(const T **q); // expected-note{{candidate template ignored: substitution failure [with T = int]}} + + void g(int **p) { + f(p); // expected-error{{no matching function for call to 'f'}} + } + +} diff --git a/test/CXX/temp/temp.res/temp.local/p3.cpp b/test/CXX/temp/temp.res/temp.local/p3.cpp index 88f8963..54da885 100644 --- a/test/CXX/temp/temp.res/temp.local/p3.cpp +++ b/test/CXX/temp/temp.res/temp.local/p3.cpp @@ -22,11 +22,11 @@ template <class T> struct Derived: Base<int>, Base<char> { namespace PR6717 { template <typename T> class WebVector { - } + } // expected-error {{expected ';' after class}} - WebVector(const WebVector<T>& other) { } + WebVector(const WebVector<T>& other) { } // expected-error{{undeclared identifier 'T'}} \ + expected-error{{requires a type specifier}} template <typename C> - WebVector<T>& operator=(const C& other) { } // expected-error{{unknown type name 'WebVector'}} \ - // expected-error{{unqualified-id}} + WebVector<T>& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}} } diff --git a/test/CXX/temp/temp.spec/temp.explicit/p7.cpp b/test/CXX/temp/temp.spec/temp.explicit/p7.cpp index b62e0cb..7398dca 100644 --- a/test/CXX/temp/temp.spec/temp.explicit/p7.cpp +++ b/test/CXX/temp/temp.spec/temp.explicit/p7.cpp @@ -7,14 +7,14 @@ struct X0 { }; T* f0(T* ptr) { - return ptr + 1; // expected-error{{pointer to function}} + return ptr + 1; // expected-error{{pointer to the function}} } static T* static_member; }; template<typename T> -T* X0<T>::static_member = ((T*)0) + 1; // expected-error{{pointer to function}} +T* X0<T>::static_member = ((T*)0) + 1; // expected-error{{pointer to the function}} template class X0<int>; // okay diff --git a/test/CodeGen/annotate.c b/test/CodeGen/annotate.c index ffaeebb..9ed187d 100644 --- a/test/CodeGen/annotate.c +++ b/test/CodeGen/annotate.c @@ -7,4 +7,4 @@ void a(char *a) { // CHECK: private unnamed_addr global // CHECK: private unnamed_addr global -// CHECK: @llvm.global.annotations = appending global [2 x %0] +// CHECK: @llvm.global.annotations = appending global [2 x { i8*, i8*, i8*, i32 }] diff --git a/test/CodeGen/arm-arguments.c b/test/CodeGen/arm-arguments.c index 73bc03d..081bc89 100644 --- a/test/CodeGen/arm-arguments.c +++ b/test/CodeGen/arm-arguments.c @@ -61,7 +61,7 @@ struct s10 { int f0; int : 0; int : 0; }; struct s10 f10(void) {} // APCS-GNU: define void @f11( -// APCS-GNU: struct.s10* sret +// APCS-GNU: struct.s11* sret // AAPCS: define arm_aapcscc i32 @f11() struct s11 { int : 0; int f0; }; struct s11 f11(void) {} @@ -80,7 +80,7 @@ struct s13 { float f0; }; struct s13 f13(void) {} // APCS-GNU: define void @f14( -// APCS-GNU: struct.s13* sret +// APCS-GNU: union.u14* sret // AAPCS: define arm_aapcscc i32 @f14() union u14 { float f0; }; union u14 f14(void) {} diff --git a/test/CodeGen/arm-asm-variable.c b/test/CodeGen/arm-asm-variable.c new file mode 100644 index 0000000..865d197 --- /dev/null +++ b/test/CodeGen/arm-asm-variable.c @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -w -o - %s | FileCheck %s + +typedef long long int64_t; +typedef unsigned int uint32_t; + +int64_t foo(int64_t v, volatile int64_t *p) +{ + register uint32_t rl asm("r1"); + register uint32_t rh asm("r2"); + + int64_t r; + uint32_t t; + + __asm__ __volatile__( \ + "ldrexd%[_rl], %[_rh], [%[_p]]" \ + : [_rl] "=&r" (rl), [_rh] "=&r" (rh) \ + : [_p] "p" (p) : "memory"); + + // CHECK: call { i32, i32 } asm sideeffect "ldrexd$0, $1, [$2]", "={r1},={r2},r,~{memory}"(i64* + + return r; +} + +// Make sure we translate register names properly. +void bar (void) { + register unsigned int rn asm("r14"); + register unsigned int d asm("r2"); + + // CHECK: call i32 asm sideeffect "sub $1, $1, #32", "={r2},{lr}" + asm volatile ("sub %1, %1, #32" : "=r"(d) : "r"(rn)); +} diff --git a/test/CodeGen/asm-errors.c b/test/CodeGen/asm-errors.c index cd4d1ff..438c82b 100644 --- a/test/CodeGen/asm-errors.c +++ b/test/CodeGen/asm-errors.c @@ -1,6 +1,8 @@ // REQUIRES: x86-registered-target -// RUN: not %clang_cc1 -triple i386-apple-darwin10 -emit-obj %s -o /dev/null > %t 2>&1 -// RUN: FileCheck %s < %t + +// RUN: true +// UN: not %clang_cc1 -triple i386-apple-darwin10 -emit-obj %s -o /dev/null > %t 2>&1 +// UN: FileCheck %s < %t int test1(int X) { // CHECK: error: invalid instruction mnemonic 'abc' diff --git a/test/CodeGen/asm-inout.c b/test/CodeGen/asm-inout.c index 29142f7..ce524fe 100644 --- a/test/CodeGen/asm-inout.c +++ b/test/CodeGen/asm-inout.c @@ -21,7 +21,7 @@ void test2() { // PR7338 void test3(int *vout, int vin) { - // CHECK: call void asm "opr $0,$1", "=*r|m|r,r|m|r,~{di},~{dirflag},~{fpsr},~{flags}" + // CHECK: call void asm "opr $0,$1", "=*r|m|r,r|m|r,~{edi},~{dirflag},~{fpsr},~{flags}" asm( "opr %[vout],%[vin]" : [vout] "=r,=m,=r" (*vout) @@ -37,4 +37,3 @@ int test4(volatile int *addr) { return (int)oldval; // CHECK: call i8 asm "frob $0", "=r,0{{.*}}"(i8 -1) } - diff --git a/test/CodeGen/asm.c b/test/CodeGen/asm.c index eb11285..7199f09 100644 --- a/test/CodeGen/asm.c +++ b/test/CodeGen/asm.c @@ -49,10 +49,10 @@ unsigned t9(unsigned int a) { // PR3908 void t10(int r) { __asm__("PR3908 %[lf] %[xx] %[li] %[r]" : [r] "+r" (r) : [lf] "mx" (0), [li] "mr" (0), [xx] "x" ((double)(0))); - + // CHECK: @t10( // CHECK:PR3908 $1 $3 $2 $0 -} +} // PR3373 @@ -119,7 +119,7 @@ int t16() { void t17() { int i; __asm__ ( "nop": "=m"(i)); - + // CHECK: @t17() // CHECK: call void asm "nop", "=*m, } @@ -127,7 +127,7 @@ void t17() { // <rdar://problem/6841383> int t18(unsigned data) { int a, b; - + asm("xyz" :"=a"(a), "=d"(b) : "a"(data)); return a + b; // CHECK: t18(i32 @@ -140,7 +140,7 @@ int t18(unsigned data) { // PR6780 int t19(unsigned data) { int a, b; - + asm("x{abc|def|ghi}z" :"=r"(a): "r"(data)); return a + b; // CHECK: t19(i32 @@ -153,7 +153,7 @@ double t20(double x) { register long double result; __asm __volatile ("frndint" : "=t" (result) : "0" (x)); return result; - + // CHECK: @t20 // CHECK: fpext double {{.*}} to x86_fp80 // CHECK-NEXT: call x86_fp80 asm sideeffect "frndint" @@ -190,3 +190,17 @@ unsigned char t23(unsigned char a, unsigned char b) { "edx", "cc"); return res; } + + +// PR10299 - fpsr, fpcr +void test(void) +{ + __asm__ __volatile__( \ + "finit" \ + : \ + : \ + :"st","st(1)","st(2)","st(3)", \ + "st(4)","st(5)","st(6)","st(7)", \ + "fpsr","fpcr" \ + ); +} diff --git a/test/CodeGen/attr-weak-import.c b/test/CodeGen/attr-weak-import.c new file mode 100644 index 0000000..0707f59 --- /dev/null +++ b/test/CodeGen/attr-weak-import.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple x86_64-darwin-apple -emit-llvm -o - %s | FileCheck %s +// rdar://9538608 + +extern int A __attribute__((weak_import)); +int A; + +extern int B __attribute__((weak_import)); +extern int B; + +int C; +extern int C __attribute__((weak_import)); + +extern int D __attribute__((weak_import)); +extern int D __attribute__((weak_import)); +int D; + +extern int E __attribute__((weak_import)); +int E; +extern int E __attribute__((weak_import)); + +// CHECK: @A = global i32 +// CHECK-NOT: @B = +// CHECK: @C = common global i32 +// CHECK: @D = global i32 +// CHECK: @E = global i32 + diff --git a/test/CodeGen/attributes.c b/test/CodeGen/attributes.c index 770ce76..4e73af6 100644 --- a/test/CodeGen/attributes.c +++ b/test/CodeGen/attributes.c @@ -4,7 +4,7 @@ // CHECK: @t5 = weak global i32 2 int t5 __attribute__((weak)) = 2; -// CHECK: @t13 = global %0 zeroinitializer, section "SECT" +// CHECK: @t13 = global %struct.s0 zeroinitializer, section "SECT" struct s0 { int x; }; struct s0 t13 __attribute__((section("SECT"))) = { 0 }; diff --git a/test/CodeGen/bitfield-2.c b/test/CodeGen/bitfield-2.c index 8de432f..69ed5b1 100644 --- a/test/CodeGen/bitfield-2.c +++ b/test/CodeGen/bitfield-2.c @@ -11,7 +11,7 @@ // CHECK-RECORD: *** Dumping IRgen Record Layout // CHECK-RECORD: Record: struct s0 // CHECK-RECORD: Layout: <CGRecordLayout -// CHECK-RECORD: LLVMType:<{ [3 x i8] }> +// CHECK-RECORD: LLVMType:%struct.s0 = type <{ [3 x i8] }> // CHECK-RECORD: IsZeroInitializable:1 // CHECK-RECORD: BitFields:[ // CHECK-RECORD: <CGBitFieldInfo Size:24 IsSigned:1 @@ -56,7 +56,7 @@ unsigned long long test_0() { // CHECK-RECORD: *** Dumping IRgen Record Layout // CHECK-RECORD: Record: struct s1 // CHECK-RECORD: Layout: <CGRecordLayout -// CHECK-RECORD: LLVMType:<{ [2 x i8], i8 }> +// CHECK-RECORD: LLVMType:%struct.s1 = type <{ [2 x i8], i8 }> // CHECK-RECORD: IsZeroInitializable:1 // CHECK-RECORD: BitFields:[ // CHECK-RECORD: <CGBitFieldInfo Size:10 IsSigned:1 @@ -113,7 +113,7 @@ unsigned long long test_1() { // CHECK-RECORD: *** Dumping IRgen Record Layout // CHECK-RECORD: Record: union u2 // CHECK-RECORD: Layout: <CGRecordLayout -// CHECK-RECORD: LLVMType:<{ i8 }> +// CHECK-RECORD: LLVMType:%union.u2 = type <{ i8 }> // CHECK-RECORD: IsZeroInitializable:1 // CHECK-RECORD: BitFields:[ // CHECK-RECORD: <CGBitFieldInfo Size:3 IsSigned:0 @@ -288,7 +288,7 @@ _Bool test_6() { // CHECK-RECORD: *** Dumping IRgen Record Layout // CHECK-RECORD: Record: struct s7 // CHECK-RECORD: Layout: <CGRecordLayout -// CHECK-RECORD: LLVMType:{ i32, i32, i32, i8, [3 x i8], [4 x i8], [12 x i8] } +// CHECK-RECORD: LLVMType:%struct.s7 = type { i32, i32, i32, i8, [3 x i8], [4 x i8], [12 x i8] } // CHECK-RECORD: IsZeroInitializable:1 // CHECK-RECORD: BitFields:[ // CHECK-RECORD: <CGBitFieldInfo Size:5 IsSigned:1 diff --git a/test/CodeGen/blocksignature.c b/test/CodeGen/blocksignature.c index 7526f19..63fe124 100644 --- a/test/CodeGen/blocksignature.c +++ b/test/CodeGen/blocksignature.c @@ -2,13 +2,13 @@ // RUN: %clang_cc1 -fblocks -triple i686-apple-darwin9 %s -emit-llvm -o - | FileCheck %s -check-prefix=X32 // X64: @.str = private unnamed_addr constant [6 x i8] c"v8@?0\00" -// X64: @__block_literal_global = internal constant %1 { i8** @_NSConcreteGlobalBlock, i32 1342177280, +// X64: @__block_literal_global = internal constant {{.*}} { i8** @_NSConcreteGlobalBlock, i32 1342177280, // X64: @.str1 = private unnamed_addr constant [12 x i8] c"i16@?0c8f12\00" // X64: store i32 1073741824, i32* // X32: [[STR1:@.*]] = private unnamed_addr constant [6 x i8] c"v4@?0\00" -// X32: @__block_descriptor_tmp = internal constant [[FULL_DESCRIPTOR_T:%.*]] { i32 0, i32 20, i8* getelementptr inbounds ([6 x i8]* [[STR1]], i32 0, i32 0), i8* null } -// X32: @__block_literal_global = internal constant [[GLOBAL_LITERAL_T:%.*]] { i8** @_NSConcreteGlobalBlock, i32 1342177280, i32 0, i8* bitcast (void (i8*)* @__block_global_{{.*}} to i8*), [[DESCRIPTOR_T:%.*]]* bitcast ([[FULL_DESCRIPTOR_T]]* @__block_descriptor_tmp to {{%.*}}*) } +// X32: @__block_descriptor_tmp = internal constant [[FULL_DESCRIPTOR_T:.*]] { i32 0, i32 20, i8* getelementptr inbounds ([6 x i8]* [[STR1]], i32 0, i32 0), i8* null } +// X32: @__block_literal_global = internal constant [[GLOBAL_LITERAL_T:.*]] { i8** @_NSConcreteGlobalBlock, i32 1342177280, i32 0, i8* bitcast (void (i8*)* @__block_global_{{.*}} to i8*), [[DESCRIPTOR_T:%.*]]* bitcast ([[FULL_DESCRIPTOR_T]]* @__block_descriptor_tmp to {{%.*}}*) } // X32: [[STR2:@.*]] = private unnamed_addr constant [11 x i8] c"i12@?0c4f8\00" // X32: @__block_descriptor_tmp{{.*}} = internal constant [[FULL_DESCRIPTOR_T]] { i32 0, i32 24, i8* getelementptr inbounds ([11 x i8]* [[STR2]], i32 0, i32 0), i8* null } // X32: store i32 1073741824, i32* diff --git a/test/CodeGen/blockstret.c b/test/CodeGen/blockstret.c index e49b52a..d5dae6f 100644 --- a/test/CodeGen/blockstret.c +++ b/test/CodeGen/blockstret.c @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin9 %s -emit-llvm -o - | FileCheck %s -check-prefix=X64 // RUN: %clang_cc1 -fblocks -triple i686-apple-darwin9 %s -emit-llvm -o - | FileCheck %s -check-prefix=X32 -// X64: internal constant {{%.*}} { i8** @_NSConcreteGlobalBlock, i32 1879048192 +// X64: internal constant {{.*}} { i8** @_NSConcreteGlobalBlock, i32 1879048192 // X64: store i32 1610612736, i32* %want // X32: @_NSConcreteGlobalBlock, i32 1879048192, i32 0, diff --git a/test/CodeGen/builtin-expect.c b/test/CodeGen/builtin-expect.c index 88479d9..664c6b6 100644 --- a/test/CodeGen/builtin-expect.c +++ b/test/CodeGen/builtin-expect.c @@ -19,3 +19,29 @@ int main() { // CHECK: call void @isigprocmask() // CHECK: [[C:%.*]] = call i64 (...)* @bar() + + +// CHECK: @test1 +int test1(int x) { +// CHECK: @llvm.expect + if (__builtin_expect (x, 1)) + return 0; + return x; +} + +// CHECK: @test2 +int test2(int x) { +// CHECK: @llvm.expect + switch(__builtin_expect(x, 5)) { + default: + return 0; + case 0: + case 1: + case 2: + return 1; + case 5: + return 5; + }; + + return 0; +} diff --git a/test/CodeGen/byval-memcpy-elim.c b/test/CodeGen/byval-memcpy-elim.c index 8aa08fb..76cdafb 100644 --- a/test/CodeGen/byval-memcpy-elim.c +++ b/test/CodeGen/byval-memcpy-elim.c @@ -18,3 +18,36 @@ void test1a(struct Test1S, struct Test2S); void test1(struct Test1S *A, struct Test2S *B) { test1a(*A, *B); } + +// The above gets tricker when the byval argument requires higher alignment +// than the natural alignment of the type in question. +// rdar://9483886 + +// Make sure we do generate a memcpy when we cannot guarantee alignment. +struct Test3S { + int a,b,c,d,e,f,g,h,i,j,k,l; +}; +void test2a(struct Test3S q); +// CHECK: define void @test2( +// CHECK: alloca %struct.Test3S, align 8 +// CHECK: memcpy +// CHECK: call void @test2a +void test2(struct Test3S *q) { + test2a(*q); +} + +// But make sure we don't generate a memcpy when we can guarantee alignment. +void fooey(void); +// CHECK: define void @test3( +// CHECK: alloca %struct.Test3S, align 8 +// CHECK: call void @fooey +// CHECK-NOT: memcpy +// CHECK: call void @test2a +// CHECK-NOT: memcpy +// CHECK: call void @test2a +void test3(struct Test3S a) { + struct Test3S b = a; + fooey(); + test2a(a); + test2a(b); +} diff --git a/test/CodeGen/call-knr-indirect.c b/test/CodeGen/call-knr-indirect.c deleted file mode 100644 index 2e923b3..0000000 --- a/test/CodeGen/call-knr-indirect.c +++ /dev/null @@ -1,11 +0,0 @@ -// RUN: %clang %s -O0 -emit-llvm -S -o - | grep 'call.*rb_define_global_function' -// This should call rb_define_global_function, not rb_f_chop. - -void rb_define_global_function (const char*,void(*)(),int); -static void rb_f_chop(); -void Init_String() { - rb_define_global_function("chop", rb_f_chop, 0); -} -static void rb_f_chop() { -} - diff --git a/test/CodeGen/call.c b/test/CodeGen/call.c new file mode 100644 index 0000000..ef32775 --- /dev/null +++ b/test/CodeGen/call.c @@ -0,0 +1,39 @@ +// RUN: %clang %s -O0 -emit-llvm -S -o - | FileCheck %s + +// This should call rb_define_global_function, not rb_f_chop. +void rb_define_global_function (const char*,void(*)(),int); +static void rb_f_chop(); +void Init_String() { + rb_define_global_function("chop", rb_f_chop, 0); +} +static void rb_f_chop() { +} + +// CHECK: call{{.*}}rb_define_global_function + +// PR10335 +typedef void (* JSErrorCallback)(void); +void js_GetErrorMessage(void); +void JS_ReportErrorNumber(JSErrorCallback errorCallback, ...); +void Interpret() { + JS_ReportErrorNumber(js_GetErrorMessage, 0); + + // CHECK: call void ({{.*}}, ...)* @JS_ReportErrorNumber({{.*}}@js_GetErrorMessage +} + + + + +// PR10337 +struct sigaction { int (*_sa_handler)(int); }; +typedef int SigHandler (); +typedef struct sigaction sighandler_cxt; +SigHandler *rl_set_sighandler(ohandler) +sighandler_cxt *ohandler; { + return 0; +} + +void rl_set_signals() { + SigHandler *oh; + oh = rl_set_sighandler(0); +} diff --git a/test/CodeGen/complex-indirect.c b/test/CodeGen/complex-indirect.c new file mode 100644 index 0000000..45eb195 --- /dev/null +++ b/test/CodeGen/complex-indirect.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 | FileCheck %s + +// Make sure this doesn't crash, and that we don't generate a byval alloca +// with insufficient alignment. + +void a(int,int,int,int,int,int,__complex__ char); +void b(__complex__ char *y) { a(0,0,0,0,0,0,*y); } +// CHECK: define void @b +// CHECK: alloca { i8, i8 }*, align 8 +// CHECK: call void @a(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { i8, i8 }* byval align 8 diff --git a/test/CodeGen/complex.c b/test/CodeGen/complex.c index 055383e..1212660 100644 --- a/test/CodeGen/complex.c +++ b/test/CodeGen/complex.c @@ -93,3 +93,7 @@ void t6() { double t7(double _Complex c) { return __builtin_fabs(__real__(c)); } + +void t8() { + __complex__ int *x = &(__complex__ int){1}; +} diff --git a/test/CodeGen/compound-literal.c b/test/CodeGen/compound-literal.c index 4b995db..0164c2b 100644 --- a/test/CodeGen/compound-literal.c +++ b/test/CodeGen/compound-literal.c @@ -1,12 +1,33 @@ -// RUN: %clang_cc1 < %s -emit-llvm +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s int* a = &(int){1}; struct s {int a, b, c;} * b = &(struct s) {1, 2, 3}; // Not working; complex constants are broken // _Complex double * x = &(_Complex double){1.0f}; -int xxx() { +void xxx() { int* a = &(int){1}; struct s {int a, b, c;} * b = &(struct s) {1, 2, 3}; _Complex double * x = &(_Complex double){1.0f}; } + +// CHECK: define void @f() +void f() { + typedef struct S { int x,y; } S; + // CHECK: [[S:%[a-zA-Z0-9.]+]] = alloca [[STRUCT:%[a-zA-Z0-9.]+]], + struct S s; + // CHECK-NEXT: [[COMPOUNDLIT:%[a-zA-Z0-9.]+]] = alloca [[STRUCT]] + // CHECK-NEXT: [[CX:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]]* [[COMPOUNDLIT]], i32 0, i32 0 + // CHECK-NEXT: [[SY:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]]* [[S]], i32 0, i32 1 + // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32* [[SY]] + // CHECK-NEXT: store i32 [[TMP]], i32* [[CX]] + // CHECK-NEXT: [[CY:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]]* [[COMPOUNDLIT]], i32 0, i32 1 + // CHECK-NEXT: [[SX:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]]* [[S]], i32 0, i32 0 + // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32* [[SX]] + // CHECK-NEXT: store i32 [[TMP]], i32* [[CY]] + // CHECK-NEXT: [[SI8:%[a-zA-Z0-9.]+]] = bitcast [[STRUCT]]* [[S]] to i8* + // CHECK-NEXT: [[COMPOUNDLITI8:%[a-zA-Z0-9.]+]] = bitcast [[STRUCT]]* [[COMPOUNDLIT]] to i8* + // CHECK-NEXT: call void @llvm.memcpy{{.*}}(i8* [[SI8]], i8* [[COMPOUNDLITI8]] + s = (S){s.y,s.x}; + // CHECK-NEXT: ret void +} diff --git a/test/CodeGen/const-init.c b/test/CodeGen/const-init.c index c677863..9bc3bba 100644 --- a/test/CodeGen/const-init.c +++ b/test/CodeGen/const-init.c @@ -26,21 +26,21 @@ union s2 { int g0 = (int)(&(((union s2 *) 0)->f0.f0) - 0); -// CHECK: @g1x = global {{%.}} { double 1.000000e+00{{[0]*}}, double 0.000000e+00{{[0]*}} } +// CHECK: @g1x = global { double, double } { double 1.000000e+00{{[0]*}}, double 0.000000e+00{{[0]*}} } _Complex double g1x = 1.0f; -// CHECK: @g1y = global {{%.}} { double 0.000000e+00{{[0]*}}, double 1.000000e+00{{[0]*}} } +// CHECK: @g1y = global { double, double } { double 0.000000e+00{{[0]*}}, double 1.000000e+00{{[0]*}} } _Complex double g1y = 1.0fi; -// CHECK: @g1 = global {{%.}} { i8 1, i8 10 } +// CHECK: @g1 = global { i8, i8 } { i8 1, i8 10 } _Complex char g1 = (char) 1 + (char) 10 * 1i; -// CHECK: @g2 = global %2 { i32 1, i32 10 } +// CHECK: @g2 = global { i32, i32 } { i32 1, i32 10 } _Complex int g2 = 1 + 10i; -// CHECK: @g3 = global {{%.}} { float 1.000000e+00{{[0]*}}, float 1.000000e+0{{[0]*}}1 } +// CHECK: @g3 = global { float, float } { float 1.000000e+00{{[0]*}}, float 1.000000e+0{{[0]*}}1 } _Complex float g3 = 1.0 + 10.0i; -// CHECK: @g4 = global {{%.}} { double 1.000000e+00{{[0]*}}, double 1.000000e+0{{[0]*}}1 } +// CHECK: @g4 = global { double, double } { double 1.000000e+00{{[0]*}}, double 1.000000e+0{{[0]*}}1 } _Complex double g4 = 1.0 + 10.0i; -// CHECK: @g5 = global %2 zeroinitializer +// CHECK: @g5 = global { i32, i32 } zeroinitializer _Complex int g5 = (2 + 3i) == (5 + 7i); -// CHECK: @g6 = global {{%.}} { double -1.100000e+0{{[0]*}}1, double 2.900000e+0{{[0]*}}1 } +// CHECK: @g6 = global { double, double } { double -1.100000e+0{{[0]*}}1, double 2.900000e+0{{[0]*}}1 } _Complex double g6 = (2.0 + 3.0i) * (5.0 + 7.0i); // CHECK: @g7 = global i32 1 int g7 = (2 + 3i) * (5 + 7i) == (-11 + 29i); @@ -52,14 +52,14 @@ int g9 = (2 + 3i) * (5 + 7i) != (-11 + 29i); int g10 = (2.0 + 3.0i) * (5.0 + 7.0i) != (-11.0 + 29.0i); // PR5108 -// CHECK: @gv1 = global %4 <{ i32 0, i8 7 }>, align 1 +// CHECK: @gv1 = global %struct.anon <{ i32 0, i8 7 }>, align 1 struct { unsigned long a; unsigned long b:3; } __attribute__((__packed__)) gv1 = { .a = 0x0, .b = 7, }; // PR5118 -// CHECK: @gv2 = global %5 <{ i8 1, i8* null }>, align 1 +// CHECK: @gv2 = global %struct.anon.0 <{ i8 1, i8* null }>, align 1 struct { unsigned char a; char *b; diff --git a/test/CodeGen/darwin-thread-specifier.c b/test/CodeGen/darwin-thread-specifier.c new file mode 100644 index 0000000..605d461 --- /dev/null +++ b/test/CodeGen/darwin-thread-specifier.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o - %s | FileCheck %s +// CHECK: @b = thread_local global i32 5, align 4 +__thread int b = 5; diff --git a/test/CodeGen/debug-info-iv.c b/test/CodeGen/debug-info-iv.c new file mode 100644 index 0000000..9265473 --- /dev/null +++ b/test/CodeGen/debug-info-iv.c @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -triple x86_64-darwin-apple -Os -S -g -o - %s | FileCheck %s + +int calculate(int); +static void test_indvars(int *Array1, int Array2[100][200]) { + unsigned i, j; + Array1[1] = Array2[3][6] = 12345; + + for (i = 0; i < 100; i+=2) + Array1[i] = i; /* Step by non unit amount */ + + for (i = 3; i < 103; i++) + Array1[i] = i+4; /* Step with an offset */ + + for (i = 13; i < 100; i++) + for (j = 0; j < 100; j+=3) /* 2d array access */ + Array2[i][j/3] = Array2[i][i]; +} + + +int main() { + int Array[100][200], i, j; + double sum = 0.0; + + for (i=0; i < 100; i+=2) + for (j=0; j < 200; j++) + Array[i][j] = 0; + test_indvars(Array[0], Array); + +//CHECK: .loc 2 30 3 + for (i=0; i < 100; i+=2) + for (j=0; j < 200; j++) + sum += Array[i][j]; + + return calculate(sum); +} diff --git a/test/CodeGen/debug-info-member.c b/test/CodeGen/debug-info-member.c new file mode 100644 index 0000000..54066fa --- /dev/null +++ b/test/CodeGen/debug-info-member.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -emit-llvm -g < %s | grep DW_TAG_member | grep \!3 + +struct A { int x; } a; diff --git a/test/CodeGen/debug-info.c b/test/CodeGen/debug-info.c index 876c6c2..af2ce96 100644 --- a/test/CodeGen/debug-info.c +++ b/test/CodeGen/debug-info.c @@ -54,3 +54,8 @@ __uint128_t foo128 () __uint128_t int128 = 44; return int128; } + +// CHECK: uint64x2_t +typedef unsigned long long uint64_t; +typedef uint64_t uint64x2_t __attribute__((ext_vector_type(2))); +uint64x2_t extvectbar[4]; diff --git a/test/CodeGen/decl.c b/test/CodeGen/decl.c index 29520d7..21b7579 100644 --- a/test/CodeGen/decl.c +++ b/test/CodeGen/decl.c @@ -2,8 +2,8 @@ // CHECK: @test1.x = internal constant [12 x i32] [i32 1 // CHECK: @test2.x = internal unnamed_addr constant [13 x i32] [i32 1, -// CHECK: @test5w = global %0 { i32 2, [4 x i8] undef } -// CHECK: @test5y = global %union.test5u { double 7.300000e+0{{[0]*}}1 } +// CHECK: @test5w = global { i32, [4 x i8] } { i32 2, [4 x i8] undef } +// CHECK: @test5y = global { double } { double 7.300000e+0{{[0]*}}1 } // CHECK: @test6.x = internal unnamed_addr constant %struct.SelectDest { i8 1, i8 2, i32 3, i32 0 } diff --git a/test/CodeGen/designated-initializers.c b/test/CodeGen/designated-initializers.c index d928296..6561ce5 100644 --- a/test/CodeGen/designated-initializers.c +++ b/test/CodeGen/designated-initializers.c @@ -8,10 +8,10 @@ struct foo { // CHECK: @u = global %union.anon zeroinitializer union { int i; float f; } u = { }; -// CHECK: @u2 = global %1 { i32 0, [4 x i8] undef } +// CHECK: @u2 = global { i32, [4 x i8] } { i32 0, [4 x i8] undef } union { int i; double f; } u2 = { }; -// CHECK: @u3 = global %2 zeroinitializer +// CHECK: @u3 = global %union.anon.1 zeroinitializer union { double f; int i; } u3 = { }; // CHECK: @b = global [2 x i32] [i32 0, i32 22] @@ -39,11 +39,11 @@ struct ds ds0 = { { { .a = 0 } } }; struct ds ds1 = { { .a = 1 } }; struct ds ds2 = { { .b = 1 } }; struct ds ds3 = { .a = 0 }; -// CHECK: @ds4 = global %3 { %4 { %struct.anon zeroinitializer, i16 0, %struct.anon { i16 1 } } } +// CHECK: @ds4 = global %struct.ds { %struct.anon.3 { %struct.anon zeroinitializer, i16 0, %struct.anon.2 { i16 1 } } } struct ds ds4 = { .c = 1 }; struct ds ds5 = { { { .a = 0 } }, .b = 1 }; struct ds ds6 = { { .a = 0, .b = 1 } }; -// CHECK: @ds7 = global %3 { %4 { %struct.anon { i16 2 }, i16 3, %struct.anon zeroinitializer } } +// CHECK: @ds7 = global %struct.ds { %struct.anon.3 { %struct.anon { i16 2 }, i16 3, %struct.anon.2 zeroinitializer } } struct ds ds7 = { { { .a = 1 @@ -59,7 +59,7 @@ void test1(int argc, char **argv) .b = 1024, }; - // CHECK: bitcast %union.anon* %u2 + // CHECK: bitcast %union.anon.4* %u2 // CHECK: call void @llvm.memset union { int i; float f; } u2 = { }; diff --git a/test/CodeGen/flexible-array-init.c b/test/CodeGen/flexible-array-init.c index 3632350..d3079dc 100644 --- a/test/CodeGen/flexible-array-init.c +++ b/test/CodeGen/flexible-array-init.c @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s struct { int x; int y[]; } a = { 1, 7, 11 }; -// CHECK: @a = global %0 { i32 1, [2 x i32] [i32 7, i32 11] } +// CHECK: @a = global { i32, [2 x i32] } { i32 1, [2 x i32] [i32 7, i32 11] } struct { int x; int y[]; } b = { 1, { 13, 15 } }; -// CHECK: @b = global %0 { i32 1, [2 x i32] [i32 13, i32 15] } +// CHECK: @b = global { i32, [2 x i32] } { i32 1, [2 x i32] [i32 13, i32 15] } diff --git a/test/CodeGen/functions.c b/test/CodeGen/functions.c index a2c692d..e51f93e 100644 --- a/test/CodeGen/functions.c +++ b/test/CodeGen/functions.c @@ -59,3 +59,9 @@ void f8_test() { // CHECK: declare void @f8_user({{.*}}*) // CHECK: declare void @f8_callback() } + +// PR10204: don't crash +static void test9_helper(void) {} +void test9() { + (void) test9_helper; +} diff --git a/test/CodeGen/global-init.c b/test/CodeGen/global-init.c index 351ca9e..074c2a0 100644 --- a/test/CodeGen/global-init.c +++ b/test/CodeGen/global-init.c @@ -27,12 +27,12 @@ struct ManyFields { int f; }; -// CHECK: global %0 { i32 1, i32 2, i32 0, i8 0, i32 0, i32 0 } +// CHECK: global %struct.ManyFields { i32 1, i32 2, i32 0, i8 0, i32 0, i32 0 } struct ManyFields FewInits = {1, 2}; // PR6766 -// CHECK: @l = global %1 { [24 x i8] c"f\00\00\00o\00\00\00o\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 1 } +// CHECK: @l = global { [24 x i8], i32 } { [24 x i8] c"f\00\00\00o\00\00\00o\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i32 1 } typedef __WCHAR_TYPE__ wchar_t; struct K { wchar_t L[6]; diff --git a/test/CodeGen/init.c b/test/CodeGen/init.c index 0f94729..599b4f2 100644 --- a/test/CodeGen/init.c +++ b/test/CodeGen/init.c @@ -115,3 +115,11 @@ void test11(struct test11S *P) { // CHECK: store i32 4 // CHECK: ret void } + + +// Verify that we can convert a recursive struct with a memory that returns +// an instance of the struct we're converting. +struct test12 { + struct test12 (*p)(void); +} test12g; + diff --git a/test/CodeGen/libcalls.c b/test/CodeGen/libcalls.c index 828d7de..5ff684f 100644 --- a/test/CodeGen/libcalls.c +++ b/test/CodeGen/libcalls.c @@ -50,3 +50,26 @@ void test_pow(float a0, double a1, long double a2) { // CHECK-NO: declare float @llvm.pow.f32(float, float) nounwind readonly // CHECK-NO: declare double @llvm.pow.f64(double, double) nounwind readonly // CHECK-NO: declare x86_fp80 @llvm.pow.f80(x86_fp80, x86_fp80) nounwind readonly + +// CHECK-YES: define void @test_fma +// CHECK-NO: define void @test_fma +void test_fma(float a0, double a1, long double a2) { + // CHECK-YES: call float @llvm.fma.f32 + // CHECK-NO: call float @llvm.fma.f32 + float l0 = fmaf(a0, a0, a0); + + // CHECK-YES: call double @llvm.fma.f64 + // CHECK-NO: call double @llvm.fma.f64 + double l1 = fma(a1, a1, a1); + + // CHECK-YES: call x86_fp80 @llvm.fma.f80 + // CHECK-NO: call x86_fp80 @llvm.fma.f80 + long double l2 = fmal(a2, a2, a2); +} + +// CHECK-YES: declare float @llvm.fma.f32(float, float, float) nounwind readnone +// CHECK-YES: declare double @llvm.fma.f64(double, double, double) nounwind readnone +// CHECK-YES: declare x86_fp80 @llvm.fma.f80(x86_fp80, x86_fp80, x86_fp80) nounwind readnone +// CHECK-NO: declare float @llvm.fma.f32(float, float, float) nounwind readnone +// CHECK-NO: declare double @llvm.fma.f64(double, double, double) nounwind readnone +// CHECK-NO: declare x86_fp80 @llvm.fma.f80(x86_fp80, x86_fp80, x86_fp80) nounwind readnone diff --git a/test/CodeGen/mmx-inline-asm.c b/test/CodeGen/mmx-inline-asm.c index c473a93..5d1371e 100644 --- a/test/CodeGen/mmx-inline-asm.c +++ b/test/CodeGen/mmx-inline-asm.c @@ -2,7 +2,7 @@ // <rdar://problem/9091220> #include <mmintrin.h> -// CHECK: type { x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx } +// CHECK: { x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx } void foo(long long fill) { __m64 vfill = _mm_cvtsi64_m64(fill); diff --git a/test/CodeGen/ms-anonymous-struct.c b/test/CodeGen/ms-anonymous-struct.c index 3afe440..b41caab 100644 --- a/test/CodeGen/ms-anonymous-struct.c +++ b/test/CodeGen/ms-anonymous-struct.c @@ -1,19 +1,19 @@ // RUN: %clang_cc1 -fms-extensions -emit-llvm -o - %s | FileCheck %s +// CHECK: %struct.test = type { i32, %struct.nested2, i32 } +// CHECK: %struct.nested2 = type { i32, %struct.nested1, i32 } // CHECK: %struct.nested1 = type { i32, i32 } typedef struct nested1 { int a1; int b1; } NESTED1; -// CHECK: %struct.nested2 = type { i32, %struct.nested1, i32 } struct nested2 { int a; NESTED1; int b; }; -// CHECK: %struct.test = type { i32, %struct.nested2, i32 } struct test { int x; struct nested2; diff --git a/test/CodeGen/packed-union.c b/test/CodeGen/packed-union.c index 0aeed00..31ce614 100644 --- a/test/CodeGen/packed-union.c +++ b/test/CodeGen/packed-union.c @@ -1,6 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm %s -o %t -// RUN: grep "struct._attrs = type <{ i32, i8 }>" %t typedef struct _attrs { unsigned file_attributes; unsigned char filename_length; diff --git a/test/CodeGen/pragma-pack-3.c b/test/CodeGen/pragma-pack-3.c index 676f0d7..04b636e 100644 --- a/test/CodeGen/pragma-pack-3.c +++ b/test/CodeGen/pragma-pack-3.c @@ -1,9 +1,7 @@ // RUN: %clang_cc1 -triple i386-apple-darwin9 %s -emit-llvm -o - | FileCheck -check-prefix X32 %s -// CHECK-X32: %struct.menu = type <{ i8*, i8, i8 }> // CHECK-X32: %union.command = type <{ i8*, [2 x i8] }> // RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -emit-llvm -o - | FileCheck -check-prefix X64 %s -// CHECK-X64: %struct.menu = type <{ i8*, i8, i8 }> // CHECK-X64: %union.command = type <{ i8*, [2 x i8] }> // <rdar://problem/7184250> diff --git a/test/CodeGen/private-extern-redef.c b/test/CodeGen/private-extern-redef.c new file mode 100644 index 0000000..580ce9b --- /dev/null +++ b/test/CodeGen/private-extern-redef.c @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -triple x86_64-darwin-apple -emit-llvm -o - %s | FileCheck %s +// rdar://9609649 + +__private_extern__ const int I; +__private_extern__ const int J = 927; + +__private_extern__ const int K; +const int K = 37; + +const int L = 10; +__private_extern__ const int L; + +__private_extern__ int M; +int M = 20; + +__private_extern__ int N; +int N; + +__private_extern__ int O; +int O=1; + +__private_extern__ int P; +extern int P; + +void bar(int); + +void foo() { + bar(I); +} + +// CHECK: @J = hidden constant +// CHECK: @K = hidden constant +// CHECK: @L = constant +// CHECK: @M = hidden global +// CHECK: @O = hidden global +// CHECK: @I = external hidden +// CHECK: @N = common hidden global +// CHECK-NOT: @P + diff --git a/test/CodeGen/struct-init.c b/test/CodeGen/struct-init.c index 861c41e..8a605c1 100644 --- a/test/CodeGen/struct-init.c +++ b/test/CodeGen/struct-init.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -emit-llvm-only +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s typedef struct _zend_ini_entry zend_ini_entry; struct _zend_ini_entry { @@ -29,3 +29,11 @@ typedef struct __simd64_uint32_t { void foo() { const uint32x2_t signBit = { (uint2) 0x80000000 }; } + +// CHECK: %struct.fp_struct_foo = type { void (i32)* } +struct fp_struct_bar { int a; }; + +struct fp_struct_foo { + void (*FP)(struct fp_struct_bar); +} G; + diff --git a/test/CodeGen/struct.c b/test/CodeGen/struct.c index 25477a0..e173931 100644 --- a/test/CodeGen/struct.c +++ b/test/CodeGen/struct.c @@ -181,3 +181,16 @@ range f18() { rangepair rp; return (rp = f18_ext()).range1; } + + + +// Complex forward reference of struct. +struct f19S; +extern struct f19T { + struct f19S (*p)(void); +} t; +struct f19S { int i; }; +void f19(void) { + t.p(); +} + diff --git a/test/CodeGen/trapv.c b/test/CodeGen/trapv.c index 7f192c6..f52dad5 100644 --- a/test/CodeGen/trapv.c +++ b/test/CodeGen/trapv.c @@ -1,7 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -ftrapv %s -emit-llvm -o - | FileCheck %s -// CHECK: [[I32O:%.*]] = type { i32, i1 } - unsigned int ui, uj, uk; int i, j, k; @@ -16,9 +14,9 @@ void test0() { // CHECK: [[T1:%.*]] = load i32* @j // CHECK-NEXT: [[T2:%.*]] = load i32* @k - // CHECK-NEXT: [[T3:%.*]] = call [[I32O]] @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 [[T2]]) - // CHECK-NEXT: [[T4:%.*]] = extractvalue [[I32O]] [[T3]], 0 - // CHECK-NEXT: [[T5:%.*]] = extractvalue [[I32O]] [[T3]], 1 + // CHECK-NEXT: [[T3:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 [[T2]]) + // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T3]], 0 + // CHECK-NEXT: [[T5:%.*]] = extractvalue { i32, i1 } [[T3]], 1 // CHECK-NEXT: br i1 [[T5]] // CHECK: call void @llvm.trap() i = j + k; @@ -30,9 +28,9 @@ void test1() { opaque(i++); // CHECK: [[T1:%.*]] = load i32* @i - // CHECK-NEXT: [[T2:%.*]] = call [[I32O]] @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1) - // CHECK-NEXT: [[T3:%.*]] = extractvalue [[I32O]] [[T2]], 0 - // CHECK-NEXT: [[T4:%.*]] = extractvalue [[I32O]] [[T2]], 1 + // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1) + // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0 + // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T2]], 1 // CHECK-NEXT: br i1 [[T4]] // CHECK: call void @llvm.trap() } @@ -43,9 +41,9 @@ void test2() { opaque(++i); // CHECK: [[T1:%.*]] = load i32* @i - // CHECK-NEXT: [[T2:%.*]] = call [[I32O]] @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1) - // CHECK-NEXT: [[T3:%.*]] = extractvalue [[I32O]] [[T2]], 0 - // CHECK-NEXT: [[T4:%.*]] = extractvalue [[I32O]] [[T2]], 1 + // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1) + // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0 + // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T2]], 1 // CHECK-NEXT: br i1 [[T4]] // CHECK: call void @llvm.trap() } diff --git a/test/CodeGen/union-init2.c b/test/CodeGen/union-init2.c index 1386c27..bf20696 100644 --- a/test/CodeGen/union-init2.c +++ b/test/CodeGen/union-init2.c @@ -1,11 +1,11 @@ // RUN: %clang_cc1 -emit-llvm %s -o - -triple i686-pc-linux-gnu | FileCheck %s // Make sure we generate something sane instead of a ptrtoint -// CHECK: bitcast (%0* @r to %union.x*), [4 x i8] undef +// CHECK: bitcast ({ %union.x*, [4 x i8] }* @r to %union.x*), [4 x i8] undef union x {long long b;union x* a;} r = {.a = &r}; -// CHECK: global %1 { [3 x i8] zeroinitializer, [5 x i8] undef } +// CHECK: global { [3 x i8], [5 x i8] } { [3 x i8] zeroinitializer, [5 x i8] undef } union z { char a[3]; long long b; diff --git a/test/CodeGen/vla.c b/test/CodeGen/vla.c index e5114a5..c9612bc 100644 --- a/test/CodeGen/vla.c +++ b/test/CodeGen/vla.c @@ -88,13 +88,60 @@ int test2(int n) // http://llvm.org/PR8567 // CHECK: define double @test_PR8567 double test_PR8567(int n, double (*p)[n][5]) { - // CHECK: store [[vla_type:.*]] %p, - // CHECK: load i32* - // CHECK-NEXT: mul i32 40 - // CHECK-NEXT: [[byte_idx:%.*]] = mul i32 1 - // CHECK-NEXT: [[tmp_1:%.*]] = load [[vla_type]]* - // CHECK-NEXT: [[tmp_2:%.*]] = bitcast [[vla_type]] [[tmp_1]] to i8* - // CHECK-NEXT: [[idx:%.*]] = getelementptr inbounds i8* [[tmp_2]], i32 [[byte_idx]] - // CHECK-NEXT: bitcast i8* [[idx]] to [[vla_type]] + // CHECK: [[NV:%.*]] = alloca i32, align 4 + // CHECK-NEXT: [[PV:%.*]] = alloca [5 x double]*, align 4 + // CHECK-NEXT: store + // CHECK-NEXT: store + // CHECK-NEXT: [[N:%.*]] = load i32* [[NV]], align 4 + // CHECK-NEXT: [[P:%.*]] = load [5 x double]** [[PV]], align 4 + // CHECK-NEXT: [[T0:%.*]] = mul nsw i32 1, [[N]] + // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [5 x double]* [[P]], i32 [[T0]] + // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds [5 x double]* [[T1]], i32 2 + // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds [5 x double]* [[T2]], i32 0, i32 3 + // CHECK-NEXT: [[T4:%.*]] = load double* [[T3]] + // CHECK-NEXT: ret double [[T4]] return p[1][2][3]; } + +int test4(unsigned n, char (*p)[n][n+1][6]) { + // CHECK: define i32 @test4( + // CHECK: [[N:%.*]] = alloca i32, align 4 + // CHECK-NEXT: [[P:%.*]] = alloca [6 x i8]*, align 4 + // CHECK-NEXT: [[P2:%.*]] = alloca [6 x i8]*, align 4 + // CHECK-NEXT: store i32 + // CHECK-NEXT: store [6 x i8]* + + // VLA captures. + // CHECK-NEXT: [[DIM0:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[DIM1:%.*]] = add i32 [[T0]], 1 + + // __typeof. FIXME: does this really need to be loaded? + // CHECK-NEXT: load [6 x i8]** [[P]] + + // CHECK-NEXT: [[T0:%.*]] = load [6 x i8]** [[P]], align 4 + // CHECK-NEXT: [[T1:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[T2:%.*]] = udiv i32 [[T1]], 2 + // CHECK-NEXT: [[T3:%.*]] = mul nuw i32 [[DIM0]], [[DIM1]] + // CHECK-NEXT: [[T4:%.*]] = mul nsw i32 [[T2]], [[T3]] + // CHECK-NEXT: [[T5:%.*]] = getelementptr inbounds [6 x i8]* [[T0]], i32 [[T4]] + // CHECK-NEXT: [[T6:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[T7:%.*]] = udiv i32 [[T6]], 4 + // CHECK-NEXT: [[T8:%.*]] = sub i32 0, [[T7]] + // CHECK-NEXT: [[T9:%.*]] = mul nuw i32 [[DIM0]], [[DIM1]] + // CHECK-NEXT: [[T10:%.*]] = mul nsw i32 [[T8]], [[T9]] + // CHECK-NEXT: [[T11:%.*]] = getelementptr inbounds [6 x i8]* [[T5]], i32 [[T10]] + // CHECK-NEXT: store [6 x i8]* [[T11]], [6 x i8]** [[P2]], align 4 + __typeof(p) p2 = (p + n/2) - n/4; + + // CHECK-NEXT: [[T0:%.*]] = load [6 x i8]** [[P2]], align 4 + // CHECK-NEXT: [[T1:%.*]] = load [6 x i8]** [[P]], align 4 + // CHECK-NEXT: [[T2:%.*]] = ptrtoint [6 x i8]* [[T0]] to i32 + // CHECK-NEXT: [[T3:%.*]] = ptrtoint [6 x i8]* [[T1]] to i32 + // CHECK-NEXT: [[T4:%.*]] = sub i32 [[T2]], [[T3]] + // CHECK-NEXT: [[T5:%.*]] = mul nuw i32 [[DIM0]], [[DIM1]] + // CHECK-NEXT: [[T6:%.*]] = mul nuw i32 6, [[T5]] + // CHECK-NEXT: [[T7:%.*]] = sdiv exact i32 [[T4]], [[T6]] + // CHECK-NEXT: ret i32 [[T7]] + return p2 - p; +} diff --git a/test/CodeGen/volatile-1.c b/test/CodeGen/volatile-1.c index f54afff..7c7a822 100644 --- a/test/CodeGen/volatile-1.c +++ b/test/CodeGen/volatile-1.c @@ -4,7 +4,7 @@ volatile int i, j, k; volatile int ar[5]; volatile char c; -// CHECK: @ci = common global [[CINT:%.*]] zeroinitializer +// CHECK: @ci = common global [[CINT:.*]] zeroinitializer volatile _Complex int ci; volatile struct S { #ifdef __cplusplus diff --git a/test/CodeGen/volatile-2.c b/test/CodeGen/volatile-2.c index 1ceaf17..490b7d7 100644 --- a/test/CodeGen/volatile-2.c +++ b/test/CodeGen/volatile-2.c @@ -3,8 +3,8 @@ void test0() { // CHECK: define void @test0() // CHECK: [[F:%.*]] = alloca float - // CHECK-NEXT: [[REAL:%.*]] = volatile load float* getelementptr inbounds ({{%.*}} @test0_v, i32 0, i32 0) - // CHECK-NEXT: volatile load float* getelementptr inbounds ({{%.*}} @test0_v, i32 0, i32 1) + // CHECK-NEXT: [[REAL:%.*]] = volatile load float* getelementptr inbounds ({ float, float }* @test0_v, i32 0, i32 0) + // CHECK-NEXT: volatile load float* getelementptr inbounds ({{.*}} @test0_v, i32 0, i32 1) // CHECK-NEXT: store float [[REAL]], float* [[F]], align 4 // CHECK-NEXT: ret void extern volatile _Complex float test0_v; @@ -13,10 +13,10 @@ void test0() { void test1() { // CHECK: define void @test1() - // CHECK: [[REAL:%.*]] = volatile load float* getelementptr inbounds ({{%.*}} @test1_v, i32 0, i32 0) - // CHECK-NEXT: [[IMAG:%.*]] = volatile load float* getelementptr inbounds ({{%.*}} @test1_v, i32 0, i32 1) - // CHECK-NEXT: volatile store float [[REAL]], float* getelementptr inbounds ({{%.*}} @test1_v, i32 0, i32 0) - // CHECK-NEXT: volatile store float [[IMAG]], float* getelementptr inbounds ({{%.*}} @test1_v, i32 0, i32 1) + // CHECK: [[REAL:%.*]] = volatile load float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 0) + // CHECK-NEXT: [[IMAG:%.*]] = volatile load float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 1) + // CHECK-NEXT: volatile store float [[REAL]], float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 0) + // CHECK-NEXT: volatile store float [[IMAG]], float* getelementptr inbounds ({{.*}} @test1_v, i32 0, i32 1) // CHECK-NEXT: ret void extern volatile _Complex float test1_v; test1_v = test1_v; diff --git a/test/CodeGen/x86_32-arguments-darwin.c b/test/CodeGen/x86_32-arguments-darwin.c index f7e2a53..731d4f6 100644 --- a/test/CodeGen/x86_32-arguments-darwin.c +++ b/test/CodeGen/x86_32-arguments-darwin.c @@ -1,5 +1,4 @@ -// RUN: %clang_cc1 -w -fblocks -triple i386-apple-darwin9 -emit-llvm -o %t %s -// RUN: FileCheck < %t %s +// RUN: %clang_cc1 -w -fblocks -triple i386-apple-darwin9 -target-cpu yonah -emit-llvm -o - %s | FileCheck %s // CHECK: define signext i8 @f0() char f0(void) { @@ -232,7 +231,7 @@ v4i32 f55(v4i32 arg) { return arg+arg; } // CHECK: i8 signext %a0, %struct.s56_0* byval align 4 %a1, // CHECK: x86_mmx %a2.coerce, %struct.s56_1* byval align 4, // CHECK: i64 %a4.coerce, %struct.s56_2* byval align 4, -// CHECK: <4 x i32> %a6, %struct.s39* byval align 16 %a7, +// CHECK: <4 x i32> %a6, %struct.s56_3* byval align 16 %a7, // CHECK: <2 x double> %a8, %struct.s56_4* byval align 16 %a9, // CHECK: <8 x i32> %a10, %struct.s56_5* byval align 4, // CHECK: <4 x double> %a12, %struct.s56_6* byval align 4) @@ -241,7 +240,7 @@ v4i32 f55(v4i32 arg) { return arg+arg; } // CHECK: i32 %{{[^ ]*}}, %struct.s56_0* byval align 4 %{{[^ ]*}}, // CHECK: x86_mmx %{{[^ ]*}}, %struct.s56_1* byval align 4 %{{[^ ]*}}, // CHECK: i64 %{{[^ ]*}}, %struct.s56_2* byval align 4 %{{[^ ]*}}, -// CHECK: <4 x i32> %{{[^ ]*}}, %struct.s39* byval align 16 %{{[^ ]*}}, +// CHECK: <4 x i32> %{{[^ ]*}}, %struct.s56_3* byval align 16 %{{[^ ]*}}, // CHECK: <2 x double> %{{[^ ]*}}, %struct.s56_4* byval align 16 %{{[^ ]*}}, // CHECK: <8 x i32> {{[^ ]*}}, %struct.s56_5* byval align 4 %{{[^ ]*}}, // CHECK: <4 x double> {{[^ ]*}}, %struct.s56_6* byval align 4 %{{[^ ]*}}) diff --git a/test/CodeGen/x86_32-arguments-linux.c b/test/CodeGen/x86_32-arguments-linux.c index 2f246f8..81dcaf6 100644 --- a/test/CodeGen/x86_32-arguments-linux.c +++ b/test/CodeGen/x86_32-arguments-linux.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -w -fblocks -triple i386-pc-linux-gnu -emit-llvm -o %t %s +// RUN: %clang_cc1 -w -fblocks -triple i386-pc-linux-gnu -target-cpu pentium4 -emit-llvm -o %t %s // RUN: FileCheck < %t %s // CHECK: define void @f56( diff --git a/test/CodeGen/x86_32-arguments-nommx.c b/test/CodeGen/x86_32-arguments-nommx.c new file mode 100644 index 0000000..40362f7 --- /dev/null +++ b/test/CodeGen/x86_32-arguments-nommx.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -target-feature -mmx -target-feature +sse2 -triple i686-pc-linux-gnu -emit-llvm -o - %s | FileCheck %s + +// no-mmx should put mmx into memory +typedef int __attribute__((vector_size (8))) i32v2; +int a(i32v2 x) { return x[0]; } +// CHECK: define i32 @a(i64 %x.coerce) + +// but SSE2 vectors should still go into an SSE2 register +typedef int __attribute__((vector_size (16))) i32v4; +int b(i32v4 x) { return x[0]; } +// CHECK: define i32 @b(<4 x i32> %x) diff --git a/test/CodeGen/x86_64-arguments.c b/test/CodeGen/x86_64-arguments.c index 75c4788..221c7d3 100644 --- a/test/CodeGen/x86_64-arguments.c +++ b/test/CodeGen/x86_64-arguments.c @@ -42,8 +42,8 @@ void f7(e7 a0) { // Test merging/passing of upper eightbyte with X87 class. // -// CHECK: define void @f8_1(%struct.s19* sret %agg.result) -// CHECK: define void @f8_2(%struct.s19* byval align 16 %a0) +// CHECK: define void @f8_1(%union.u8* sret %agg.result) +// CHECK: define void @f8_2(%union.u8* byval align 16 %a0) union u8 { long double a; int b; @@ -58,7 +58,7 @@ struct s9 { int a; int b; int : 0; } f9(void) { while (1) {} } struct s10 { int a; int b; int : 0; }; void f10(struct s10 a0) {} -// CHECK: define void @f11(%struct.s19* sret %agg.result) +// CHECK: define void @f11(%union.anon* sret %agg.result) union { long double a; float b; } f11() { while (1) {} } // CHECK: define i32 @f12_0() @@ -147,7 +147,7 @@ struct f24s { long a; int b; }; struct f23S f24(struct f23S *X, struct f24s *P2) { return *X; - // CHECK: define %struct.f24s @f24(%struct.f23S* %X, %struct.f24s* %P2) + // CHECK: define { i64, i32 } @f24(%struct.f23S* %X, %struct.f24s* %P2) } // rdar://8248065 @@ -169,7 +169,7 @@ struct foo26 { }; struct foo26 f26(struct foo26 *P) { - // CHECK: define %struct.foo26 @f26(%struct.foo26* %P) + // CHECK: define { i32*, float* } @f26(%struct.foo26* %P) return *P; } @@ -259,3 +259,48 @@ void f9122143() func(ss); } +// CHECK: define double @f36(double %arg.coerce) +typedef unsigned v2i32 __attribute((__vector_size__(8))); +v2i32 f36(v2i32 arg) { return arg; } + +// CHECK: declare void @f38(<8 x float>) +// CHECK: declare void @f37(<8 x float>) +typedef float __m256 __attribute__ ((__vector_size__ (32))); +typedef struct { + __m256 m; +} s256; + +s256 x38; +__m256 x37; + +void f38(s256 x); +void f37(__m256 x); +void f39() { f38(x38); f37(x37); } + +// The two next tests make sure that the struct below is passed +// in the same way regardless of avx being used + +// CHECK: declare void @func40(%struct.t128* byval align 16) +typedef float __m128 __attribute__ ((__vector_size__ (16))); +typedef struct t128 { + __m128 m; + __m128 n; +} two128; + +extern void func40(two128 s); +void func41(two128 s) { + func40(s); +} + +// CHECK: declare void @func42(%struct.t128_2* byval align 16) +typedef struct xxx { + __m128 array[2]; +} Atwo128; +typedef struct t128_2 { + Atwo128 x; +} SA; + +extern void func42(SA s); +void func43(SA s) { + func42(s); +} diff --git a/test/CodeGenCXX/anonymous-union-member-initializer.cpp b/test/CodeGenCXX/anonymous-union-member-initializer.cpp index 2ddafec..324ff4a 100644 --- a/test/CodeGenCXX/anonymous-union-member-initializer.cpp +++ b/test/CodeGenCXX/anonymous-union-member-initializer.cpp @@ -86,7 +86,7 @@ namespace test3 { // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0 // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to // CHECK-NEXT: [[CALLBACK:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 0 - // CHECK-NEXT: store void (i8*)* null, void (i8*)** [[CALLBACK]] + // CHECK: store // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0 // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to // CHECK-NEXT: [[CVALUE:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 1 @@ -114,3 +114,19 @@ template <typename T> struct Foo { }; }; Foo<int> f; + +namespace PR9683 { + struct QueueEntry { + union { + struct { + void* mPtr; + union { + unsigned mSubmissionTag; + }; + }; + unsigned mValue; + }; + QueueEntry() {} + }; + QueueEntry QE; +} diff --git a/test/CodeGenCXX/attr-used.cpp b/test/CodeGenCXX/attr-used.cpp index 26109e7..2c82184 100644 --- a/test/CodeGenCXX/attr-used.cpp +++ b/test/CodeGenCXX/attr-used.cpp @@ -2,8 +2,8 @@ // <rdar://problem/8684363>: clang++ not respecting __attribute__((used)) on destructors struct X0 { - // CHECK: define linkonce_odr void @_ZN2X0C1Ev + // CHECK: define linkonce_odr {{.*}} @_ZN2X0C1Ev __attribute__((used)) X0() {} - // CHECK: define linkonce_odr void @_ZN2X0D1Ev + // CHECK: define linkonce_odr {{.*}} @_ZN2X0D1Ev __attribute__((used)) ~X0() {} }; diff --git a/test/CodeGenCXX/block-byref-cxx-objc.cpp b/test/CodeGenCXX/block-byref-cxx-objc.cpp index a4fbd6c..135e0c7 100644 --- a/test/CodeGenCXX/block-byref-cxx-objc.cpp +++ b/test/CodeGenCXX/block-byref-cxx-objc.cpp @@ -16,9 +16,9 @@ int main() } // CHECK: define internal void @__Block_byref_object_copy_ -// CHECK: call void @_ZN1AC1ERKS_ +// CHECK: call {{.*}} @_ZN1AC1ERKS_ // CHECK: define internal void @__Block_byref_object_dispose_ -// CHECK: call void @_ZN1AD1Ev +// CHECK: call {{.*}} @_ZN1AD1Ev // CHECK: define internal void @__copy_helper_block_ // CHECK: call void @_Block_object_assign // CHECK: define internal void @__destroy_helper_block_ diff --git a/test/CodeGenCXX/blocks.cpp b/test/CodeGenCXX/blocks.cpp index a4d5b86..0e310bd 100644 --- a/test/CodeGenCXX/blocks.cpp +++ b/test/CodeGenCXX/blocks.cpp @@ -31,7 +31,7 @@ namespace test1 { // ...unless they have mutable fields... // CHECK: define void @_ZN5test15test3Ev() - // CHECK: [[BLOCK:%.*]] = alloca [[BLOCK_T:%.*]], + // CHECK: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], // CHECK: [[T0:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] to void ()* // CHECK: store void ()* [[T0]], void ()** @out struct mut { mutable int x; }; @@ -43,7 +43,7 @@ namespace test1 { // ...or non-trivial destructors... // CHECK: define void @_ZN5test15test4Ev() // CHECK: [[OBJ:%.*]] = alloca - // CHECK: [[BLOCK:%.*]] = alloca [[BLOCK_T:%.*]], + // CHECK: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], // CHECK: [[T0:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] to void ()* // CHECK: store void ()* [[T0]], void ()** @out struct scope { int x; ~scope(); }; diff --git a/test/CodeGenCXX/class-layout.cpp b/test/CodeGenCXX/class-layout.cpp index 96fbae8..9569f47 100644 --- a/test/CodeGenCXX/class-layout.cpp +++ b/test/CodeGenCXX/class-layout.cpp @@ -20,8 +20,8 @@ namespace Test3 { namespace Test4 { // Test from PR5589. - // CHECK: %"struct.Test4::A" = type { i32, i8, float } // CHECK: %"struct.Test4::B" = type { %"struct.Test4::A", i16, double } + // CHECK: %"struct.Test4::A" = type { i32, i8, float } struct A { int a; char c; diff --git a/test/CodeGenCXX/compound-literals.cpp b/test/CodeGenCXX/compound-literals.cpp new file mode 100644 index 0000000..cd44e97 --- /dev/null +++ b/test/CodeGenCXX/compound-literals.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +struct X { + X(); + X(const X&); + X(const char*); + ~X(); +}; + +struct Y { + int i; + X x; +}; + +// CHECK: define i32 @_Z1fv() +int f() { + // CHECK: [[LVALUE:%[a-z0-9.]+]] = alloca + // CHECK-NEXT: [[I:%[a-z0-9]+]] = getelementptr inbounds {{.*}}* [[LVALUE]], i32 0, i32 0 + // CHECK-NEXT: store i32 17, i32* [[I]] + // CHECK-NEXT: [[X:%[a-z0-9]+]] = getelementptr inbounds {{.*}} [[LVALUE]], i32 0, i32 1 + // CHECK-NEXT: call void @_ZN1XC1EPKc({{.*}}[[X]] + // CHECK-NEXT: [[I:%[a-z0-9]+]] = getelementptr inbounds {{.*}} [[LVALUE]], i32 0, i32 0 + // CHECK-NEXT: [[RESULT:%[a-z0-9]+]] = load i32* + // CHECK-NEXT: call void @_ZN1YD1Ev + // CHECK-NEXT: ret i32 [[RESULT]] + return ((Y){17, "seventeen"}).i; +} diff --git a/test/CodeGenCXX/const-init.cpp b/test/CodeGenCXX/const-init.cpp index a8c6f30..797d137 100644 --- a/test/CodeGenCXX/const-init.cpp +++ b/test/CodeGenCXX/const-init.cpp @@ -10,7 +10,7 @@ void f(); void (&fr)() = f; struct S { int& a; }; -// CHECK: @s = global %0 { i32* @a } +// CHECK: @s = global %struct.S { i32* @a } S s = { a }; // PR5581 @@ -21,7 +21,7 @@ public: unsigned f; }; -// CHECK: @_ZN6PR55812g0E = global %1 { i32 1 } +// CHECK: @_ZN6PR55812g0E = global %"class.PR5581::C" { i32 1 } C g0 = { C::e1 }; } diff --git a/test/CodeGenCXX/constructor-init.cpp b/test/CodeGenCXX/constructor-init.cpp index 47e3b7b..a195afe 100644 --- a/test/CodeGenCXX/constructor-init.cpp +++ b/test/CodeGenCXX/constructor-init.cpp @@ -113,6 +113,22 @@ namespace InitVTable { B::B(int x) : A(x + 5) {} } +namespace rdar9694300 { + struct X { + int x; + }; + + // CHECK: define void @_ZN11rdar96943001fEv + void f() { + // CHECK: alloca + X x; + // CHECK-NEXT: [[I:%.*]] = alloca i32 + // CHECK-NEXT: store i32 17, i32* [[I]] + int i = 17; + // CHECK-NEXT: ret void + } +} + template<typename T> struct X { X(const X &); diff --git a/test/CodeGenCXX/constructors.cpp b/test/CodeGenCXX/constructors.cpp index 75588ce..ec7f06c 100644 --- a/test/CodeGenCXX/constructors.cpp +++ b/test/CodeGenCXX/constructors.cpp @@ -83,12 +83,12 @@ struct D : A { D::D(int x, ...) : A(ValueClass(x, x+1)), mem(x*x) {} -// CHECK: define void @_ZN1DC1Eiz(%struct.B* %this, i32 %x, ...) unnamed_addr +// CHECK: define void @_ZN1DC1Eiz(%struct.D* %this, i32 %x, ...) unnamed_addr // CHECK: call void @_ZN10ValueClassC1Eii( // CHECK: call void @_ZN1AC2E10ValueClass( // CHECK: call void @_ZN6MemberC1Ei( -// CHECK: define void @_ZN1DC2Eiz(%struct.B* %this, i32 %x, ...) unnamed_addr +// CHECK: define void @_ZN1DC2Eiz(%struct.D* %this, i32 %x, ...) unnamed_addr // CHECK: call void @_ZN10ValueClassC1Eii( // CHECK: call void @_ZN1AC2E10ValueClass( // CHECK: call void @_ZN6MemberC1Ei( @@ -104,3 +104,14 @@ namespace test0 { C tmp = in; } } + +namespace test1 { + struct A { A(); void *ptr; }; + struct B { B(); int x; A a[0]; }; + B::B() {} + // CHECK: define void @_ZN5test11BC2Ev( + // CHECK: [[THIS:%.*]] = load [[B:%.*]]** + // CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [[B:%.*]]* [[THIS]], i32 0, i32 1 + // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [0 x {{%.*}}]* [[A]], i32 0, i32 0 + // CHECK-NEXT: ret void +} diff --git a/test/CodeGenCXX/copy-constructor-elim-2.cpp b/test/CodeGenCXX/copy-constructor-elim-2.cpp index 4f4a8e9..a4a688f 100644 --- a/test/CodeGenCXX/copy-constructor-elim-2.cpp +++ b/test/CodeGenCXX/copy-constructor-elim-2.cpp @@ -3,7 +3,7 @@ struct A { int x; A(int); ~A(); }; A f() { return A(0); } // CHECK: define void @_Z1fv -// CHECK: call void @_ZN1AC1Ei +// CHECK: call {{.*}} @_ZN1AC1Ei // CHECK-NEXT: ret void // Verify that we do not elide copies when constructing a base class. @@ -21,14 +21,14 @@ namespace no_elide_base { Derived(const Other &O); }; - // CHECK: define void @_ZN13no_elide_base7DerivedC1ERKNS_5OtherE(%"struct.no_elide_base::Derived"* %this, %"struct.PR8683::A"* %O) unnamed_addr + // CHECK: define {{.*}} @_ZN13no_elide_base7DerivedC1ERKNS_5OtherE(%"struct.no_elide_base::Derived"* %this, %"struct.no_elide_base::Other"* %O) unnamed_addr Derived::Derived(const Other &O) - // CHECK: call void @_ZNK13no_elide_base5OthercvNS_4BaseEEv - // CHECK: call void @_ZN13no_elide_base4BaseC2ERKS0_ - // CHECK: call void @_ZN13no_elide_base4BaseD1Ev + // CHECK: call {{.*}} @_ZNK13no_elide_base5OthercvNS_4BaseEEv + // CHECK: call {{.*}} @_ZN13no_elide_base4BaseC2ERKS0_ + // CHECK: call {{.*}} @_ZN13no_elide_base4BaseD1Ev : Base(O) { - // CHECK: ret void + // CHECK: ret } } @@ -48,7 +48,7 @@ struct B { void f() { // Verify that we don't mark the copy constructor in this expression as elidable. - // CHECK: call void @_ZN6PR86831AC1ERKS0_ + // CHECK: call {{.*}} @_ZN6PR86831AC1ERKS0_ A a = (B().a); } diff --git a/test/CodeGenCXX/copy-constructor-synthesis-2.cpp b/test/CodeGenCXX/copy-constructor-synthesis-2.cpp index a556679..d028a28 100644 --- a/test/CodeGenCXX/copy-constructor-synthesis-2.cpp +++ b/test/CodeGenCXX/copy-constructor-synthesis-2.cpp @@ -3,5 +3,5 @@ struct A { virtual void a(); }; A x(A& y) { return y; } -// CHECK: define linkonce_odr void @_ZN1AC1ERKS_(%struct.A* %this, %struct.A*) unnamed_addr +// CHECK: define linkonce_odr {{.*}} @_ZN1AC1ERKS_(%struct.A* %this, %struct.A*) unnamed_addr // CHECK: store i8** getelementptr inbounds ([3 x i8*]* @_ZTV1A, i64 0, i64 2) diff --git a/test/CodeGenCXX/copy-initialization.cpp b/test/CodeGenCXX/copy-initialization.cpp index 62b9f26..aecd64e 100644 --- a/test/CodeGenCXX/copy-initialization.cpp +++ b/test/CodeGenCXX/copy-initialization.cpp @@ -12,7 +12,7 @@ struct Bar { void f(Foo); -// CHECK: define void @_Z1g3Foo(%struct.Bar* %foo) +// CHECK: define void @_Z1g3Foo(%struct.Foo* %foo) void g(Foo foo) { // CHECK: call void @_ZN3BarC1Ev // CHECK: @_ZNK3BarcvRK3FooEv diff --git a/test/CodeGenCXX/cxx0x-defaulted-templates.cpp b/test/CodeGenCXX/cxx0x-defaulted-templates.cpp index 3d4000e..09eb4fe 100644 --- a/test/CodeGenCXX/cxx0x-defaulted-templates.cpp +++ b/test/CodeGenCXX/cxx0x-defaulted-templates.cpp @@ -5,15 +5,15 @@ struct X { X(); }; -// CHECK: define void @_ZN1XIbEC1Ev -// CHECK: define void @_ZN1XIbEC2Ev +// CHECK: define {{.*}} @_ZN1XIbEC1Ev +// CHECK: define {{.*}} @_ZN1XIbEC2Ev template <> X<bool>::X() = default; -// CHECK: define weak_odr void @_ZN1XIiEC1Ev -// CHECK: define weak_odr void @_ZN1XIiEC2Ev +// CHECK: define weak_odr {{.*}} @_ZN1XIiEC1Ev +// CHECK: define weak_odr {{.*}} @_ZN1XIiEC2Ev template <typename T> X<T>::X() = default; template X<int>::X(); -// CHECK: define linkonce_odr void @_ZN1XIcEC1Ev -// CHECK: define linkonce_odr void @_ZN1XIcEC2Ev +// CHECK: define linkonce_odr {{.*}} @_ZN1XIcEC1Ev +// CHECK: define linkonce_odr {{.*}} @_ZN1XIcEC2Ev X<char> x; diff --git a/test/CodeGenCXX/cxx0x-delegating-ctors.cpp b/test/CodeGenCXX/cxx0x-delegating-ctors.cpp index 15c8e7f..0bac492 100644 --- a/test/CodeGenCXX/cxx0x-delegating-ctors.cpp +++ b/test/CodeGenCXX/cxx0x-delegating-ctors.cpp @@ -26,28 +26,28 @@ delegator::delegator() { delegator::delegator(bool) {} -// CHECK: define void @_ZN9delegatorC1Ec -// CHECK: void @_ZN9delegatorC1Eb +// CHECK: define {{.*}} @_ZN9delegatorC1Ec +// CHECK: {{.*}} @_ZN9delegatorC1Eb // CHECK: void @__cxa_throw // CHECK: void @_ZSt9terminatev -// CHECK: void @_ZN9delegatorD1Ev -// CHECK: define void @_ZN9delegatorC2Ec -// CHECK: void @_ZN9delegatorC2Eb +// CHECK: {{.*}} @_ZN9delegatorD1Ev +// CHECK: define {{.*}} @_ZN9delegatorC2Ec +// CHECK: {{.*}} @_ZN9delegatorC2Eb // CHECK: void @__cxa_throw // CHECK: void @_ZSt9terminatev -// CHECK: void @_ZN9delegatorD2Ev +// CHECK: {{.*}} @_ZN9delegatorD2Ev delegator::delegator(char) : delegator(true) { throw 0; } -// CHECK: define void @_ZN9delegatorC1Ei -// CHECK: void @_ZN9delegatorC1Ev +// CHECK: define {{.*}} @_ZN9delegatorC1Ei +// CHECK: {{.*}} @_ZN9delegatorC1Ev // CHECK-NOT: void @_ZSt9terminatev // CHECK: ret // CHECK-NOT: void @_ZSt9terminatev -// CHECK: define void @_ZN9delegatorC2Ei -// CHECK: void @_ZN9delegatorC2Ev +// CHECK: define {{.*}} @_ZN9delegatorC2Ei +// CHECK: {{.*}} @_ZN9delegatorC2Ev // CHECK-NOT: void @_ZSt9terminatev // CHECK: ret // CHECK-NOT: void @_ZSt9terminatev diff --git a/test/CodeGenCXX/default-constructor-default-argument.cpp b/test/CodeGenCXX/default-constructor-default-argument.cpp index f2c7f6d..374a967 100644 --- a/test/CodeGenCXX/default-constructor-default-argument.cpp +++ b/test/CodeGenCXX/default-constructor-default-argument.cpp @@ -5,4 +5,4 @@ struct A { A(int x = 2); }; struct B : public A {}; B x; -// CHECK: call void @_ZN1AC2Ei +// CHECK: call {{.*}} @_ZN1AC2Ei diff --git a/test/CodeGenCXX/default-constructor-template-member.cpp b/test/CodeGenCXX/default-constructor-template-member.cpp index 422cc09..0dd64df 100644 --- a/test/CodeGenCXX/default-constructor-template-member.cpp +++ b/test/CodeGenCXX/default-constructor-template-member.cpp @@ -5,6 +5,6 @@ struct B { A<int> x; }; void a() { B b; } -// CHECK: call void @_ZN1BC1Ev -// CHECK: define linkonce_odr void @_ZN1BC1Ev(%struct.B* %this) unnamed_addr -// CHECK: call void @_ZN1AIiEC1Ev +// CHECK: call {{.*}} @_ZN1BC1Ev +// CHECK: define linkonce_odr {{.*}} @_ZN1BC1Ev(%struct.B* %this) unnamed_addr +// CHECK: call {{.*}} @_ZN1AIiEC1Ev diff --git a/test/CodeGenCXX/delete.cpp b/test/CodeGenCXX/delete.cpp index ddc7bb8..08ce0de 100644 --- a/test/CodeGenCXX/delete.cpp +++ b/test/CodeGenCXX/delete.cpp @@ -54,7 +54,7 @@ namespace test0 { delete a; } - // CHECK: define linkonce_odr void @_ZN5test01AD1Ev(%class.A* %this) unnamed_addr + // CHECK: define linkonce_odr void @_ZN5test01AD1Ev(%"struct.test0::A"* %this) unnamed_addr // CHECK: define linkonce_odr void @_ZN5test01AdlEPv } @@ -67,31 +67,22 @@ namespace test1 { // CHECK: define void @_ZN5test14testEPA10_A20_NS_1AE( void test(A (*arr)[10][20]) { delete [] arr; - // CHECK: icmp eq [10 x [20 x [[S:%.*]]]]* [[PTR:%.*]], null + // CHECK: icmp eq [10 x [20 x [[A:%.*]]]]* [[PTR:%.*]], null // CHECK-NEXT: br i1 - // CHECK: [[ARR:%.*]] = getelementptr inbounds [10 x [20 x [[S]]]]* [[PTR]], i32 0, i32 0, i32 0 - // CHECK-NEXT: bitcast {{.*}} to i8* - // CHECK-NEXT: [[ALLOC:%.*]] = getelementptr inbounds {{.*}}, i64 -8 - // CHECK-NEXT: bitcast i8* [[ALLOC]] to i64* - // CHECK-NEXT: load - // CHECK-NEXT: store i64 {{.*}}, i64* [[IDX:%.*]] - - // CHECK: load i64* [[IDX]] - // CHECK-NEXT: icmp ne {{.*}}, 0 - // CHECK-NEXT: br i1 - - // CHECK: load i64* [[IDX]] - // CHECK-NEXT: [[I:%.*]] = sub i64 {{.*}}, 1 - // CHECK-NEXT: getelementptr inbounds [[S]]* [[ARR]], i64 [[I]] - // CHECK-NEXT: call void @_ZN5test11AD1Ev( - // CHECK-NEXT: br label - - // CHECK: load i64* [[IDX]] - // CHECK-NEXT: sub - // CHECK-NEXT: store {{.*}}, i64* [[IDX]] - // CHECK-NEXT: br label - + // CHECK: [[BEGIN:%.*]] = getelementptr inbounds [10 x [20 x [[A]]]]* [[PTR]], i32 0, i32 0, i32 0 + // CHECK-NEXT: [[T0:%.*]] = bitcast [[A]]* [[BEGIN]] to i8* + // CHECK-NEXT: [[ALLOC:%.*]] = getelementptr inbounds i8* [[T0]], i64 -8 + // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[ALLOC]] to i64* + // CHECK-NEXT: [[COUNT:%.*]] = load i64* [[T1]] + // CHECK: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 [[COUNT]] + // CHECK-NEXT: [[ISEMPTY:%.*]] = icmp eq [[A]]* [[BEGIN]], [[END]] + // CHECK-NEXT: br i1 [[ISEMPTY]], + // CHECK: [[PAST:%.*]] = phi [[A]]* [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] + // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds [[A]]* [[PAST]], i64 -1 + // CHECK-NEXT: call void @_ZN5test11AD1Ev([[A]]* [[CUR]]) + // CHECK-NEXT: [[ISDONE:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]] + // CHECK-NEXT: br i1 [[ISDONE]] // CHECK: call void @_ZdaPv(i8* [[ALLOC]]) } } @@ -112,3 +103,22 @@ namespace test3 { delete a; } } + +namespace test4 { + // PR10341: ::delete with a virtual destructor + struct X { + virtual ~X(); + void operator delete (void *); + }; + + // CHECK: define void @_ZN5test421global_delete_virtualEPNS_1XE + void global_delete_virtual(X *xp) { + // CHECK: [[VTABLE:%.*]] = load void ([[X:%.*]])*** + // CHECK-NEXT: [[VFN:%.*]] = getelementptr inbounds void ([[X]])** [[VTABLE]], i64 0 + // CHECK-NEXT: [[VFNPTR:%.*]] = load void ([[X]])** [[VFN]] + // CHECK-NEXT: call void [[VFNPTR]]([[X]] [[OBJ:%.*]]) + // CHECK-NEXT: [[OBJVOID:%.*]] = bitcast [[X]] [[OBJ]] to i8* + // CHECK-NEXT: call void @_ZdlPv(i8* [[OBJVOID]]) nounwind + ::delete xp; + } +} diff --git a/test/CodeGenCXX/destructors.cpp b/test/CodeGenCXX/destructors.cpp index 94d8833..3381985 100644 --- a/test/CodeGenCXX/destructors.cpp +++ b/test/CodeGenCXX/destructors.cpp @@ -40,11 +40,11 @@ namespace PR7526 { struct allocator_derived : allocator { }; - // CHECK: define void @_ZN6PR75269allocatorD2Ev(%"struct.PR5529::A"* %this) unnamed_addr + // CHECK: define void @_ZN6PR75269allocatorD2Ev(%"struct.PR7526::allocator"* %this) unnamed_addr // CHECK: call void @__cxa_call_unexpected allocator::~allocator() throw() { foo(); } - // CHECK: define linkonce_odr void @_ZN6PR752617allocator_derivedD1Ev(%"struct.PR5529::A"* %this) unnamed_addr + // CHECK: define linkonce_odr void @_ZN6PR752617allocator_derivedD1Ev(%"struct.PR7526::allocator_derived"* %this) unnamed_addr // CHECK-NOT: call void @__cxa_call_unexpected // CHECK: } void foo() { @@ -145,10 +145,10 @@ namespace test1 { P::~P() {} // CHECK: define void @_ZN5test11PD2Ev(%"struct.test1::P"* %this) unnamed_addr struct Q : A, B { ~Q(); }; - Q::~Q() {} // CHECK: define void @_ZN5test11QD2Ev(%"struct.test1::M"* %this) unnamed_addr + Q::~Q() {} // CHECK: define void @_ZN5test11QD2Ev(%"struct.test1::Q"* %this) unnamed_addr struct R : A { ~R(); }; - R::~R() { A a; } // CHECK: define void @_ZN5test11RD2Ev(%"struct.test1::M"* %this) unnamed_addr + R::~R() { A a; } // CHECK: define void @_ZN5test11RD2Ev(%"struct.test1::R"* %this) unnamed_addr struct S : A { ~S(); int x; }; S::~S() {} // alias tested above @@ -168,7 +168,7 @@ namespace test2 { struct B : A { ~B(); }; B::~B() {} - // CHECK: define void @_ZN5test21BD2Ev(%"struct.test1::M"* %this) unnamed_addr + // CHECK: define void @_ZN5test21BD2Ev(%"struct.test2::B"* %this) unnamed_addr // CHECK: call void @_ZN5test21AD2Ev } @@ -233,28 +233,28 @@ namespace test4 { 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: [[EXN:%.*]] = alloca i8* + // CHECK-NEXT: [[SEL:%.*]] = alloca i32 + // CHECK-NEXT: [[EHCLEANUP:%.*]] = alloca i32 + // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [5 x [[A]]]* [[ELEMS]], i32 0, i32 0 + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 5 // CHECK-NEXT: br label + // CHECK: [[POST:%.*]] = phi [[A]]* [ [[END]], {{%.*}} ], [ [[ELT:%.*]], {{%.*}} ] + // CHECK-NEXT: [[ELT]] = getelementptr inbounds [[A]]* [[POST]], i64 -1 + // CHECK-NEXT: invoke void @_ZN5test51AD1Ev([[A]]* [[ELT]]) + // CHECK: [[T0:%.*]] = icmp eq [[A]]* [[ELT]], [[BEGIN]] + // CHECK-NEXT: br i1 [[T0]], // CHECK: ret void + // lpad + // CHECK: [[EMPTY:%.*]] = icmp eq [[A]]* [[BEGIN]], [[ELT]] + // CHECK-NEXT: br i1 [[EMPTY]] + // CHECK: [[AFTER:%.*]] = phi [[A]]* [ [[ELT]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] + // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds [[A]]* [[AFTER]], i64 -1 + // CHECK-NEXT: invoke void @_ZN5test51AD1Ev([[A]]* [[CUR]]) + // CHECK: [[DONE:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]] + // CHECK-NEXT: br i1 [[DONE]], void foo() { A elems[5]; } diff --git a/test/CodeGenCXX/eh.cpp b/test/CodeGenCXX/eh.cpp index 44219b4..58cb445 100644 --- a/test/CodeGenCXX/eh.cpp +++ b/test/CodeGenCXX/eh.cpp @@ -14,7 +14,7 @@ void test1() { // CHECK-NEXT: [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSTAR:%[^*]*\*]] // CHECK-NEXT: [[EXN2:%.*]] = bitcast [[DSTAR]] [[EXN]] to i8* // CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[EXN2]], i8* bitcast ([[DSTAR]] @d1 to i8*), i64 8, i32 8, i1 false) -// CHECK-NEXT: call void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast (%0* @_ZTI7test1_D to i8*), i8* null) noreturn +// CHECK-NEXT: call void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({ i8*, i8* }* @_ZTI7test1_D to i8*), i8* null) noreturn // CHECK-NEXT: unreachable @@ -38,7 +38,7 @@ void test2() { // CHECK-NEXT: invoke void @_ZN7test2_DC1ERKS_([[DSTAR]] [[EXN]], [[DSTAR]] @d2) // CHECK-NEXT: to label %[[CONT:.*]] unwind label %{{.*}} // : [[CONT]]: (can't check this in Release-Asserts builds) -// CHECK: call void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast (%{{.*}}* @_ZTI7test2_D to i8*), i8* null) noreturn +// CHECK: call void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({{.*}}* @_ZTI7test2_D to i8*), i8* null) noreturn // CHECK-NEXT: unreachable @@ -56,7 +56,7 @@ void test3() { // CHECK: [[EXNOBJ:%.*]] = call i8* @__cxa_allocate_exception(i64 8) // CHECK-NEXT: [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[D:%[^*]+]]** // CHECK-NEXT: store [[D]]* null, [[D]]** [[EXN]] -// CHECK-NEXT: call void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast (%1* @_ZTIPV7test3_D to i8*), i8* null) noreturn +// CHECK-NEXT: call void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({ i8*, i8*, i32, i8* }* @_ZTIPV7test3_D to i8*), i8* null) noreturn // CHECK-NEXT: unreachable @@ -84,10 +84,10 @@ namespace test5 { // CHECK: [[EXNOBJ:%.*]] = call i8* @__cxa_allocate_exception(i64 1) // CHECK: [[EXNCAST:%.*]] = bitcast i8* [[EXNOBJ]] to [[A:%[^*]*]]* // CHECK-NEXT: invoke void @_ZN5test51AC1Ev([[A]]* [[EXNCAST]]) -// CHECK: invoke void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({{%.*}}* @_ZTIN5test51AE to i8*), i8* bitcast (void ([[A]]*)* @_ZN5test51AD1Ev to i8*)) noreturn +// CHECK: invoke void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({{.*}}* @_ZTIN5test51AE to i8*), i8* bitcast (void ([[A]]*)* @_ZN5test51AD1Ev to i8*)) noreturn // CHECK-NEXT: to label {{%.*}} unwind label %[[HANDLER:[^ ]*]] // : [[HANDLER]]: (can't check this in Release-Asserts builds) -// CHECK: {{%.*}} = call i32 @llvm.eh.typeid.for(i8* bitcast ({{%.*}}* @_ZTIN5test51AE to i8*)) +// CHECK: {{%.*}} = call i32 @llvm.eh.typeid.for(i8* bitcast ({{.*}}* @_ZTIN5test51AE to i8*)) } namespace test6 { @@ -177,11 +177,11 @@ namespace test9 { struct A { A(); }; - // CHECK: define void @_ZN5test91AC1Ev(%"struct.test10::A"* %this) unnamed_addr + // CHECK: define void @_ZN5test91AC1Ev(%"struct.test9::A"* %this) unnamed_addr // CHECK: call void @_ZN5test91AC2Ev // CHECK-NEXT: ret void - // CHECK: define void @_ZN5test91AC2Ev(%"struct.test10::A"* %this) unnamed_addr + // CHECK: define void @_ZN5test91AC2Ev(%"struct.test9::A"* %this) unnamed_addr A::A() try { // CHECK: invoke void @_ZN5test96opaqueEv() opaque(); diff --git a/test/CodeGenCXX/elide-call-reference.cpp b/test/CodeGenCXX/elide-call-reference.cpp index c82eee7..55d30e2 100644 --- a/test/CodeGenCXX/elide-call-reference.cpp +++ b/test/CodeGenCXX/elide-call-reference.cpp @@ -7,5 +7,5 @@ void b() { A x = a(); } -// CHECK: call void @_ZN1AC1ERKS_ -// CHECK: call void @_ZN1AD1Ev +// CHECK: call {{.*}} @_ZN1AC1ERKS_ +// CHECK: call {{.*}} @_ZN1AD1Ev diff --git a/test/CodeGenCXX/for-range.cpp b/test/CodeGenCXX/for-range.cpp index af46644..ab1a231 100644 --- a/test/CodeGenCXX/for-range.cpp +++ b/test/CodeGenCXX/for-range.cpp @@ -69,8 +69,8 @@ void for_range() { A a; for (B b : C()) { // CHECK: call void @_ZN1CC1Ev( - // CHECK: = call %struct.A* @_ZSt5beginR1C( - // CHECK: = call %struct.A* @_ZSt3endR1C( + // CHECK: = call %struct.B* @_ZSt5beginR1C( + // CHECK: = call %struct.B* @_ZSt3endR1C( // CHECK: br label %[[COND:.*]] // CHECK: [[COND]]: @@ -101,8 +101,8 @@ void for_member_range() { A a; for (B b : D()) { // CHECK: call void @_ZN1DC1Ev( - // CHECK: = call %struct.A* @_ZN1D5beginEv( - // CHECK: = call %struct.A* @_ZN1D3endEv( + // CHECK: = call %struct.B* @_ZN1D5beginEv( + // CHECK: = call %struct.B* @_ZN1D3endEv( // CHECK: br label %[[COND:.*]] // CHECK: [[COND]]: diff --git a/test/CodeGenCXX/global-init.cpp b/test/CodeGenCXX/global-init.cpp index 9bd7390..053210b 100644 --- a/test/CodeGenCXX/global-init.cpp +++ b/test/CodeGenCXX/global-init.cpp @@ -21,21 +21,21 @@ struct D { ~D(); }; // PR6205: The casts should not require global initializers // CHECK: @_ZN6PR59741cE = external global %"struct.PR5974::C" // CHECK: @_ZN6PR59741aE = global %"struct.PR5974::A"* getelementptr inbounds (%"struct.PR5974::C"* @_ZN6PR59741cE, i32 0, i32 0) -// CHECK: @_ZN6PR59741bE = global %"struct.PR5974::A"* bitcast (i8* getelementptr (i8* bitcast (%"struct.PR5974::C"* @_ZN6PR59741cE to i8*), i64 4) to %"struct.PR5974::A"*), align 8 +// CHECK: @_ZN6PR59741bE = global %"struct.PR5974::B"* bitcast (i8* getelementptr (i8* bitcast (%"struct.PR5974::C"* @_ZN6PR59741cE to i8*), i64 4) to %"struct.PR5974::B"*), align 8 // CHECK: call void @_ZN1AC1Ev(%struct.A* @a) // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @a, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) A a; -// CHECK: call void @_ZN1BC1Ev(%struct.A* @b) -// CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1BD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @b, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) +// CHECK: call void @_ZN1BC1Ev(%struct.B* @b) +// CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.B*)* @_ZN1BD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.B* @b, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) B b; // PR6205: this should not require a global initializer // CHECK-NOT: call void @_ZN1CC1Ev(%struct.C* @c) C c; -// CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1DD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @d, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) +// CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.D*)* @_ZN1DD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.D* @d, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) D d; // <rdar://problem/7458115> @@ -70,6 +70,20 @@ namespace test3 { const char *test() { return var; } } +namespace test6 { + struct A { + A(); + }; + extern int foo(); + + // This needs an initialization function and guard variables. + // CHECK: load i8* bitcast (i64* @_ZGVN5test61xE + // CHECK: [[CALL:%.*]] = call i32 @_ZN5test63fooEv + // CHECK-NEXT: store i32 [[CALL]], i32* @_ZN5test61xE + // CHECK-NEXT: store i64 1, i64* @_ZGVN5test61xE + __attribute__((weak)) int x = foo(); +} + namespace PR5974 { struct A { int a; }; struct B { int b; }; @@ -97,15 +111,6 @@ namespace test5 { }; } -namespace test6 { - struct A { - A(); - }; - extern int foo(); - - // This needs an initialization function but not guard variables. - __attribute__((weak)) int x = foo(); -} // At the end of the file, we check that y is initialized before z. diff --git a/test/CodeGenCXX/implicit-copy-constructor.cpp b/test/CodeGenCXX/implicit-copy-constructor.cpp index 5008601..8bc84a5 100644 --- a/test/CodeGenCXX/implicit-copy-constructor.cpp +++ b/test/CodeGenCXX/implicit-copy-constructor.cpp @@ -70,3 +70,13 @@ void test_X2() pimpl pdata; pdata.f0( new impl(*i)); } + +// rdar://problem/9598341 +namespace test3 { + struct A { A(const A&); A&operator=(const A&); }; + struct B { A a; unsigned : 0; }; + void test(const B &x) { + B y = x; + y = x; + } +} diff --git a/test/CodeGenCXX/init-incomplete-type.cpp b/test/CodeGenCXX/init-incomplete-type.cpp index 3312d3e..1755dfb 100644 --- a/test/CodeGenCXX/init-incomplete-type.cpp +++ b/test/CodeGenCXX/init-incomplete-type.cpp @@ -10,3 +10,22 @@ static struct Bar<int> bar[1] = { { 0 } }; + + +namespace incomplete_type_refs { + struct A; + extern A g[]; + void foo(A*); + void f(void) { + foo(g); // Reference to array with unknown element type. + } + + struct A { // define the element type. + int a,b,c; + }; + + A *f2() { + return &g[1]; + } + +}
\ No newline at end of file diff --git a/test/CodeGenCXX/mangle-subst-std.cpp b/test/CodeGenCXX/mangle-subst-std.cpp index 837d4fa..30b579c 100644 --- a/test/CodeGenCXX/mangle-subst-std.cpp +++ b/test/CodeGenCXX/mangle-subst-std.cpp @@ -15,8 +15,8 @@ namespace std { struct A { A(); }; - // CHECK: define void @_ZNSt1AC1Ev(%"struct.N::std::A"* %this) unnamed_addr - // CHECK: define void @_ZNSt1AC2Ev(%"struct.N::std::A"* %this) unnamed_addr + // CHECK: define void @_ZNSt1AC1Ev(%"struct.std::A"* %this) unnamed_addr + // CHECK: define void @_ZNSt1AC2Ev(%"struct.std::A"* %this) unnamed_addr A::A() { } }; diff --git a/test/CodeGenCXX/mangle-template.cpp b/test/CodeGenCXX/mangle-template.cpp index 463f15d..f95e152 100644 --- a/test/CodeGenCXX/mangle-template.cpp +++ b/test/CodeGenCXX/mangle-template.cpp @@ -82,7 +82,7 @@ namespace test7 { X(U*, typename int_c<(meta<T>::value + meta<U>::value)>::type *) { } }; - // CHECK: define weak_odr void @_ZN5test71XIiEC1IdEEPT_PNS_5int_cIXplL_ZNS_4metaIiE5valueEEsrNS6_IS3_EE5valueEE4typeE(%"class.test1::T"* %this, double*, float*) unnamed_addr + // CHECK: define weak_odr {{.*}} @_ZN5test71XIiEC1IdEEPT_PNS_5int_cIXplL_ZNS_4metaIiE5valueEEsr4metaIS3_EE5valueEE4typeE(%"struct.test7::X"* %this, double*, float*) unnamed_addr template X<int>::X(double*, float*); } @@ -101,7 +101,7 @@ namespace test8 { template<typename T> void f(int_c<meta<T>::type::value>) { } - // CHECK: define weak_odr void @_ZN5test81fIiEEvNS_5int_cIXsrNS_4metaIT_E4typeE5valueEEE + // CHECK: define weak_odr void @_ZN5test81fIiEEvNS_5int_cIXsr4metaIT_E4typeE5valueEEE template void f<int>(int_c<sizeof(int)>); } diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp index 01dcf8b..453b7b7 100644 --- a/test/CodeGenCXX/mangle.cpp +++ b/test/CodeGenCXX/mangle.cpp @@ -196,9 +196,9 @@ template<typename T> struct __enable_if<true, T> { // PR5063 template<typename T> typename __enable_if<__is_scalar_type<T>::__value, void>::__type ft7() { } -// CHECK: @_Z3ft7IiEN11__enable_ifIXsr16__is_scalar_typeIT_E7__valueEvE6__typeEv +// CHECK: @_Z3ft7IiEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv template void ft7<int>(); -// CHECK: @_Z3ft7IPvEN11__enable_ifIXsr16__is_scalar_typeIT_E7__valueEvE6__typeEv +// CHECK: @_Z3ft7IPvEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv template void ft7<void*>(); // PR5144 @@ -226,9 +226,9 @@ S7::S7() {} // PR5063 template<typename T> typename __enable_if<(__is_scalar_type<T>::__value), void>::__type ft8() { } -// CHECK: @_Z3ft8IiEN11__enable_ifIXsr16__is_scalar_typeIT_E7__valueEvE6__typeEv +// CHECK: @_Z3ft8IiEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv template void ft8<int>(); -// CHECK: @_Z3ft8IPvEN11__enable_ifIXsr16__is_scalar_typeIT_E7__valueEvE6__typeEv +// CHECK: @_Z3ft8IPvEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv template void ft8<void*>(); // PR5796 @@ -241,7 +241,7 @@ template<bool, typename> struct __enable_if {}; template<typename T> struct __enable_if<true, T> { typedef T __type; }; template<typename T> -// CHECK: define linkonce_odr void @_ZN6PR57968__fill_aIiEENS_11__enable_ifIXntsrNS_16__is_scalar_typeIT_EE7__valueEvE6__typeEv +// CHECK: define linkonce_odr void @_ZN6PR57968__fill_aIiEENS_11__enable_ifIXntsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv typename __enable_if<!__is_scalar_type<T>::__value, void>::__type __fill_a() { }; void f() { __fill_a<int>(); } @@ -711,3 +711,150 @@ namespace test27 { b<A>(f); } } + +// An injected class name type in a unresolved-name. +namespace test28 { + template <class T> struct A { + enum { bit }; + }; + + template <class T> void foo(decltype(A<T>::A::bit) x); + + void test() { + foo<char>(A<char>::bit); + // CHECK: call void @_ZN6test283fooIcEEvDtsr1AIT_E1AE3bitE( + } +} + +// An enclosing template type parameter in an unresolved-name. +namespace test29 { + template <class T> struct A { + template <class U> static void foo(decltype(T::fn(U())) x); + }; + struct B { static int fn(int); static long fn(long); }; + + void test() { + A<B>::foo<int>(0); + // CHECK: call void @_ZN6test291AINS_1BEE3fooIiEEvDTclsrS1_2fncvT__EEE( + } +} + +// An enclosing template template parameter in an unresolved-name. +namespace test30 { + template <template <class> class T> struct A { + template <class U> static void foo(decltype(T<U>::fn()) x); + }; + template <class T> struct B { static T fn(); }; + + void test() { + A<B>::foo<int>(0); + // CHECK: call void @_ZN6test301AINS_1BEE3fooIiEEvDTclsrS1_IT_EE2fnEE( + } +} + +namespace test31 { // instantiation-dependent mangling of decltype + int x; + template<class T> auto f1(T p)->decltype(x) { return 0; } + // The return type in the mangling of the template signature + // is encoded as "i". + template<class T> auto f2(T p)->decltype(p) { return 0; } + // The return type in the mangling of the template signature + // is encoded as "Dtfp_E". + void g(int); + template<class T> auto f3(T p)->decltype(g(p)) {} + + // CHECK: define weak_odr i32 @_ZN6test312f1IiEEiT_( + template int f1(int); + // CHECK: define weak_odr i32 @_ZN6test312f2IiEEDtfp_ET_ + template int f2(int); + // CHECK: define weak_odr void @_ZN6test312f3IiEEDTcl1gfp_EET_ + template void f3(int); +} + +// PR10205 +namespace test32 { + template<typename T, int=T::value> struct A { + typedef int type; + }; + struct B { enum { value = 4 }; }; + + template <class T> typename A<T>::type foo() { return 0; } + void test() { + foo<B>(); + // CHECK: call i32 @_ZN6test323fooINS_1BEEENS_1AIT_XsrS3_5valueEE4typeEv() + } +} + +namespace test33 { + template <class T> struct X { + enum { value = T::value }; + }; + + template<typename T, int=X<T>::value> struct A { + typedef int type; + }; + struct B { enum { value = 4 }; }; + + template <class T> typename A<T>::type foo() { return 0; } + + void test() { + foo<B>(); + // CHECK: call i32 @_ZN6test333fooINS_1BEEENS_1AIT_Xsr1XIS3_EE5valueEE4typeEv() + } +} + +namespace test34 { + // Mangling for instantiation-dependent decltype expressions. + template<typename T> + void f(decltype(sizeof(decltype(T() + T())))) {} + + // CHECK: define weak_odr void @_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE + template void f<int>(decltype(sizeof(1))); + + // Mangling for non-instantiation-dependent sizeof expressions. + template<unsigned N> + void f2(int (&)[N + sizeof(int*)]) {} + + // CHECK: define weak_odr void @_ZN6test342f2ILj4EEEvRAplT_Lm8E_i + template void f2<4>(int (&)[4 + sizeof(int*)]); + + // Mangling for non-instantiation-dependent sizeof expressions + // involving an implicit conversion of the result of the sizeof. + template<unsigned long long N> + void f3(int (&)[N + sizeof(int*)]) {} + + // CHECK: define weak_odr void @_ZN6test342f3ILy4EEEvRAplT_Ly8E_i + template void f3<4>(int (&)[4 + sizeof(int*)]); + + // Mangling for instantiation-dependent sizeof() expressions as + // template arguments. + template<unsigned> struct A { }; + + template<typename T> void f4(::test34::A<sizeof(sizeof(decltype(T() + T())))>) { } + + // CHECK: define weak_odr void @_ZN6test342f4IiEEvNS_1AIXszstDTplcvT__EcvS2__EEEEE + template void f4<int>(A<sizeof(sizeof(int))>); +} + +namespace test35 { + // Dependent operator names of unknown arity. + struct A { + template<typename U> A operator+(U) const; + }; + + template<typename T> + void f1(decltype(sizeof(&T::template operator+<int>))) {} + + // CHECK: define weak_odr void @_ZN6test352f1INS_1AEEEvDTszadsrT_plIiEE + template void f1<A>(__SIZE_TYPE__); +} + +namespace test36 { + template<unsigned> struct A { }; + + template<typename ...Types> + auto f1(Types... values) -> A<sizeof...(values)> { } + + // CHECK: define weak_odr {{.*}} @_ZN6test362f1IJifEEENS_1AIXsZfp_EEEDpT_ + template A<2> f1(int, float); +} diff --git a/test/CodeGenCXX/member-function-pointers.cpp b/test/CodeGenCXX/member-function-pointers.cpp index 011e9cd..4c42bd8 100644 --- a/test/CodeGenCXX/member-function-pointers.cpp +++ b/test/CodeGenCXX/member-function-pointers.cpp @@ -11,56 +11,56 @@ void (A::*volatile vpa)(); void (B::*pb)(); void (C::*pc)(); -// CHECK: @pa2 = global %0 { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 0 }, align 8 +// CHECK: @pa2 = global { i64, i64 } { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 0 }, align 8 void (A::*pa2)() = &A::f; -// CHECK: @pa3 = global %0 { i64 1, i64 0 }, align 8 -// CHECK-LP32: @pa3 = global %0 { i32 1, i32 0 }, align 4 +// CHECK: @pa3 = global { i64, i64 } { i64 1, i64 0 }, align 8 +// CHECK-LP32: @pa3 = global { i32, i32 } { i32 1, i32 0 }, align 4 void (A::*pa3)() = &A::vf1; -// CHECK: @pa4 = global %0 { i64 9, i64 0 }, align 8 -// CHECK-LP32: @pa4 = global %0 { i32 5, i32 0 }, align 4 +// CHECK: @pa4 = global { i64, i64 } { i64 9, i64 0 }, align 8 +// CHECK-LP32: @pa4 = global { i32, i32 } { i32 5, i32 0 }, align 4 void (A::*pa4)() = &A::vf2; -// CHECK: @pc2 = global %0 { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 16 }, align 8 +// CHECK: @pc2 = global { i64, i64 } { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 16 }, align 8 void (C::*pc2)() = &C::f; -// CHECK: @pc3 = global %0 { i64 1, i64 0 }, align 8 +// CHECK: @pc3 = global { i64, i64 } { i64 1, i64 0 }, align 8 void (A::*pc3)() = &A::vf1; void f() { - // CHECK: store %0 zeroinitializer, %0* @pa + // CHECK: store { i64, i64 } zeroinitializer, { i64, i64 }* @pa pa = 0; // Is this okay? What are LLVM's volatile semantics for structs? - // CHECK: volatile store %0 zeroinitializer, %0* @vpa + // CHECK: volatile store { i64, i64 } zeroinitializer, { i64, i64 }* @vpa vpa = 0; - // CHECK: [[TMP:%.*]] = load %0* @pa, align 8 - // CHECK: [[TMPADJ:%.*]] = extractvalue %0 [[TMP]], 1 + // CHECK: [[TMP:%.*]] = load { i64, i64 }* @pa, align 8 + // CHECK: [[TMPADJ:%.*]] = extractvalue { i64, i64 } [[TMP]], 1 // CHECK: [[ADJ:%.*]] = add nsw i64 [[TMPADJ]], 16 - // CHECK: [[RES:%.*]] = insertvalue %0 [[TMP]], i64 [[ADJ]], 1 - // CHECK: store %0 [[RES]], %0* @pc, align 8 + // CHECK: [[RES:%.*]] = insertvalue { i64, i64 } [[TMP]], i64 [[ADJ]], 1 + // CHECK: store { i64, i64 } [[RES]], { i64, i64 }* @pc, align 8 pc = pa; - // CHECK: [[TMP:%.*]] = load %0* @pc, align 8 - // CHECK: [[TMPADJ:%.*]] = extractvalue %0 [[TMP]], 1 + // CHECK: [[TMP:%.*]] = load { i64, i64 }* @pc, align 8 + // CHECK: [[TMPADJ:%.*]] = extractvalue { i64, i64 } [[TMP]], 1 // CHECK: [[ADJ:%.*]] = sub nsw i64 [[TMPADJ]], 16 - // CHECK: [[RES:%.*]] = insertvalue %0 [[TMP]], i64 [[ADJ]], 1 - // CHECK: store %0 [[RES]], %0* @pa, align 8 + // CHECK: [[RES:%.*]] = insertvalue { i64, i64 } [[TMP]], i64 [[ADJ]], 1 + // CHECK: store { i64, i64 } [[RES]], { i64, i64 }* @pa, align 8 pa = static_cast<void (A::*)()>(pc); } void f2() { - // CHECK: store %0 { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 0 } + // CHECK: store { i64, i64 } { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 0 } void (A::*pa2)() = &A::f; - // CHECK: store %0 { i64 1, i64 0 } - // CHECK-LP32: store %0 { i32 1, i32 0 } + // CHECK: store { i64, i64 } { i64 1, i64 0 } + // CHECK-LP32: store { i32, i32 } { i32 1, i32 0 } void (A::*pa3)() = &A::vf1; - // CHECK: store %0 { i64 9, i64 0 } - // CHECK-LP32: store %0 { i32 5, i32 0 } + // CHECK: store { i64, i64 } { i64 9, i64 0 } + // CHECK-LP32: store { i32, i32 } { i32 5, i32 0 } void (A::*pa4)() = &A::vf2; } diff --git a/test/CodeGenCXX/member-init-assignment.cpp b/test/CodeGenCXX/member-init-assignment.cpp index 128cb88..84c4a36 100644 --- a/test/CodeGenCXX/member-init-assignment.cpp +++ b/test/CodeGenCXX/member-init-assignment.cpp @@ -10,8 +10,8 @@ struct Foo { Foo::Foo(unsigned arg) : file_id(arg = 42) { } -// CHECK: define void @_ZN3FooC2Ej(%struct.Foo* %this, i32 %arg) unnamed_addr +// CHECK: define {{.*}} @_ZN3FooC2Ej(%struct.Foo* %this, i32 %arg) unnamed_addr // CHECK: [[ARG:%.*]] = alloca i32 // CHECK: store i32 42, i32* [[ARG]] // CHECK: store i32 42, i32* %{{.*}} -// CHECK: ret void +// CHECK: ret {{void|%struct.Foo}} diff --git a/test/CodeGenCXX/member-init-ctor.cpp b/test/CodeGenCXX/member-init-ctor.cpp index d9a6734..d70947b 100644 --- a/test/CodeGenCXX/member-init-ctor.cpp +++ b/test/CodeGenCXX/member-init-ctor.cpp @@ -7,7 +7,7 @@ struct S { S s; -// CHECK: define{{.*}} void @_ZN1SC2Ev( +// CHECK: define {{.*}} @_ZN1SC2Ev( // CHECK-NOT } // CHECK: call {{.*}} @_Z1bv() // CHECK-NOT } diff --git a/test/CodeGenCXX/new-overflow.cpp b/test/CodeGenCXX/new-overflow.cpp new file mode 100644 index 0000000..68f89c3 --- /dev/null +++ b/test/CodeGenCXX/new-overflow.cpp @@ -0,0 +1,209 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s + +// rdar://problem/9246208 + +// Basic test. +namespace test0 { + struct A { + A(); + int x; + }; + + typedef A elt; + + // CHECK: define [[A:%.*]]* @_ZN5test04testEs(i16 signext + // CHECK: [[N:%.*]] = sext i16 {{%.*}} to i32 + // CHECK-NEXT: [[T0:%.*]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 [[N]], i32 4) + // CHECK-NEXT: [[T1:%.*]] = extractvalue { i32, i1 } [[T0]], 1 + // CHECK-NEXT: [[T2:%.*]] = extractvalue { i32, i1 } [[T0]], 0 + // CHECK-NEXT: [[T3:%.*]] = select i1 [[T1]], i32 -1, i32 [[T2]] + // CHECK-NEXT: call noalias i8* @_Znaj(i32 [[T3]]) + // CHECK: getelementptr inbounds {{.*}}, i32 [[N]] + elt *test(short s) { + return new elt[s]; + } +} + +// test0 with a nested array. +namespace test1 { + struct A { + A(); + int x; + }; + + typedef A elt[100]; + + // CHECK: define [100 x [[A:%.*]]]* @_ZN5test14testEs(i16 signext + // CHECK: [[N:%.*]] = sext i16 {{%.*}} to i32 + // CHECK-NEXT: [[T0:%.*]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 [[N]], i32 400) + // CHECK-NEXT: [[T1:%.*]] = extractvalue { i32, i1 } [[T0]], 1 + // CHECK-NEXT: [[T2:%.*]] = extractvalue { i32, i1 } [[T0]], 0 + // CHECK-NEXT: [[T3:%.*]] = mul i32 [[N]], 100 + // CHECK-NEXT: [[T4:%.*]] = select i1 [[T1]], i32 -1, i32 [[T2]] + // CHECK-NEXT: call noalias i8* @_Znaj(i32 [[T4]]) + // CHECK: getelementptr inbounds {{.*}}, i32 [[T3]] + elt *test(short s) { + return new elt[s]; + } +} + +// test1 with an array cookie. +namespace test2 { + struct A { + A(); + ~A(); + int x; + }; + + typedef A elt[100]; + + // CHECK: define [100 x [[A:%.*]]]* @_ZN5test24testEs(i16 signext + // CHECK: [[N:%.*]] = sext i16 {{%.*}} to i32 + // CHECK-NEXT: [[T0:%.*]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 [[N]], i32 400) + // CHECK-NEXT: [[T1:%.*]] = extractvalue { i32, i1 } [[T0]], 1 + // CHECK-NEXT: [[T2:%.*]] = extractvalue { i32, i1 } [[T0]], 0 + // CHECK-NEXT: [[T3:%.*]] = mul i32 [[N]], 100 + // CHECK-NEXT: [[T4:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[T2]], i32 4) + // CHECK-NEXT: [[T5:%.*]] = extractvalue { i32, i1 } [[T4]], 1 + // CHECK-NEXT: [[T6:%.*]] = or i1 [[T1]], [[T5]] + // CHECK-NEXT: [[T7:%.*]] = extractvalue { i32, i1 } [[T4]], 0 + // CHECK-NEXT: [[T8:%.*]] = select i1 [[T6]], i32 -1, i32 [[T7]] + // CHECK-NEXT: call noalias i8* @_Znaj(i32 [[T8]]) + // CHECK: getelementptr inbounds {{.*}}, i32 [[T3]] + elt *test(short s) { + return new elt[s]; + } +} + +// test0 with a 1-byte element. +namespace test4 { + struct A { + A(); + }; + + typedef A elt; + + // CHECK: define [[A:%.*]]* @_ZN5test44testEs(i16 signext + // CHECK: [[N:%.*]] = sext i16 {{%.*}} to i32 + // CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[N]], 0 + // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i32 -1, i32 [[N]] + // CHECK-NEXT: call noalias i8* @_Znaj(i32 [[T1]]) + // CHECK: getelementptr inbounds {{.*}}, i32 [[N]] + elt *test(short s) { + return new elt[s]; + } +} + +// test4 with no sext required. +namespace test5 { + struct A { + A(); + }; + + typedef A elt; + + // CHECK: define [[A:%.*]]* @_ZN5test54testEi(i32 + // CHECK: [[N:%.*]] = load i32* + // CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[N]], 0 + // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i32 -1, i32 [[N]] + // CHECK-NEXT: call noalias i8* @_Znaj(i32 [[T1]]) + // CHECK: getelementptr inbounds {{.*}}, i32 [[N]] + elt *test(int s) { + return new elt[s]; + } +} + +// test0 with an unsigned size. +namespace test6 { + struct A { + A(); + int x; + }; + + typedef A elt; + + // CHECK: define [[A:%.*]]* @_ZN5test64testEt(i16 zeroext + // CHECK: [[N:%.*]] = zext i16 {{%.*}} to i32 + // CHECK-NEXT: [[T0:%.*]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 [[N]], i32 4) + // CHECK-NEXT: [[T1:%.*]] = extractvalue { i32, i1 } [[T0]], 1 + // CHECK-NEXT: [[T2:%.*]] = extractvalue { i32, i1 } [[T0]], 0 + // CHECK-NEXT: [[T3:%.*]] = select i1 [[T1]], i32 -1, i32 [[T2]] + // CHECK-NEXT: call noalias i8* @_Znaj(i32 [[T3]]) + // CHECK: getelementptr inbounds {{.*}}, i32 [[N]] + elt *test(unsigned short s) { + return new elt[s]; + } +} + +// test1 with an unsigned size. +namespace test7 { + struct A { + A(); + int x; + }; + + typedef A elt[100]; + + // CHECK: define [100 x [[A:%.*]]]* @_ZN5test74testEt(i16 zeroext + // CHECK: [[N:%.*]] = zext i16 {{%.*}} to i32 + // CHECK-NEXT: [[T0:%.*]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 [[N]], i32 400) + // CHECK-NEXT: [[T1:%.*]] = extractvalue { i32, i1 } [[T0]], 1 + // CHECK-NEXT: [[T2:%.*]] = extractvalue { i32, i1 } [[T0]], 0 + // CHECK-NEXT: [[T3:%.*]] = mul i32 [[N]], 100 + // CHECK-NEXT: [[T4:%.*]] = select i1 [[T1]], i32 -1, i32 [[T2]] + // CHECK-NEXT: call noalias i8* @_Znaj(i32 [[T4]]) + // CHECK: getelementptr inbounds {{.*}}, i32 [[T3]] + elt *test(unsigned short s) { + return new elt[s]; + } +} + +// test0 with a signed type larger than size_t. +namespace test8 { + struct A { + A(); + int x; + }; + + typedef A elt; + + // CHECK: define [[A:%.*]]* @_ZN5test84testEx(i64 + // CHECK: [[N:%.*]] = load i64* + // CHECK-NEXT: [[T0:%.*]] = icmp uge i64 [[N]], 4294967296 + // CHECK-NEXT: [[T1:%.*]] = trunc i64 [[N]] to i32 + // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 [[T1]], i32 4) + // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 1 + // CHECK-NEXT: [[T4:%.*]] = or i1 [[T0]], [[T3]] + // CHECK-NEXT: [[T5:%.*]] = extractvalue { i32, i1 } [[T2]], 0 + // CHECK-NEXT: [[T6:%.*]] = select i1 [[T4]], i32 -1, i32 [[T5]] + // CHECK-NEXT: call noalias i8* @_Znaj(i32 [[T6]]) + // CHECK: getelementptr inbounds {{.*}}, i32 [[T1]] + elt *test(long long s) { + return new elt[s]; + } +} + +// test8 with an unsigned type. +namespace test9 { + struct A { + A(); + int x; + }; + + typedef A elt; + + // CHECK: define [[A:%.*]]* @_ZN5test94testEy(i64 + // CHECK: [[N:%.*]] = load i64* + // CHECK-NEXT: [[T0:%.*]] = icmp uge i64 [[N]], 4294967296 + // CHECK-NEXT: [[T1:%.*]] = trunc i64 [[N]] to i32 + // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 [[T1]], i32 4) + // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 1 + // CHECK-NEXT: [[T4:%.*]] = or i1 [[T0]], [[T3]] + // CHECK-NEXT: [[T5:%.*]] = extractvalue { i32, i1 } [[T2]], 0 + // CHECK-NEXT: [[T6:%.*]] = select i1 [[T4]], i32 -1, i32 [[T5]] + // CHECK-NEXT: call noalias i8* @_Znaj(i32 [[T6]]) + // CHECK: getelementptr inbounds {{.*}}, i32 [[T1]] + elt *test(unsigned long long s) { + return new elt[s]; + } +} diff --git a/test/CodeGenCXX/new.cpp b/test/CodeGenCXX/new.cpp index d14a5e2..3a72bb84 100644 --- a/test/CodeGenCXX/new.cpp +++ b/test/CodeGenCXX/new.cpp @@ -182,12 +182,17 @@ namespace test15 { } // CHECK: define void @_ZN6test155test1EPv( - // CHECK: [[P:%.*]] = load i8* + // CHECK: [[P:%.*]] = load i8** // CHECK-NEXT: icmp eq i8* [[P]], null // CHECK-NEXT: br i1 - // CHECK: [[T0:%.*]] = bitcast i8* [[P]] to [[A:%.*]]* - // CHECK: [[T1:%.*]] = getelementptr inbounds [[A]]* [[T0]], - // CHECK-NEXT: call void @_ZN6test151AC1Ev([[A]]* [[T1]]) + // CHECK: [[BEGIN:%.*]] = bitcast i8* [[P]] to [[A:%.*]]* + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 5 + // CHECK-NEXT: br label + // CHECK: [[CUR:%.*]] = phi [[A]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] + // CHECK-NEXT: call void @_ZN6test151AC1Ev([[A]]* [[CUR]]) + // CHECK-NEXT: [[NEXT]] = getelementptr inbounds [[A]]* [[CUR]], i64 1 + // CHECK-NEXT: [[DONE:%.*]] = icmp eq [[A]]* [[NEXT]], [[END]] + // CHECK-NEXT: br i1 [[DONE]] void test1(void *p) { new (p) A[5]; } @@ -202,10 +207,27 @@ namespace test15 { // CHECK-NEXT: [[P:%.*]] = load i8* // CHECK-NEXT: icmp eq i8* [[P]], null // CHECK-NEXT: br i1 - // CHECK: [[T0:%.*]] = bitcast i8* [[P]] to [[A:%.*]]* - // CHECK: [[T1:%.*]] = getelementptr inbounds [[A]]* [[T0]], - // CHECK-NEXT: call void @_ZN6test151AC1Ev([[A]]* [[T1]]) + // CHECK: [[BEGIN:%.*]] = bitcast i8* [[P]] to [[A:%.*]]* + // CHECK-NEXT: [[ISEMPTY:%.*]] = icmp eq i64 [[T0]], 0 + // CHECK-NEXT: br i1 [[ISEMPTY]], + // CHECK: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 [[T0]] + // CHECK-NEXT: br label + // CHECK: [[CUR:%.*]] = phi [[A]]* [ [[BEGIN]], + // CHECK-NEXT: call void @_ZN6test151AC1Ev([[A]]* [[CUR]]) void test2(void *p, int n) { new (p) A[n]; } } + +namespace PR10197 { + // CHECK: define weak_odr void @_ZN7PR101971fIiEEvv() + template<typename T> + void f() { + // CHECK: [[CALL:%.*]] = call noalias i8* @_Znwm + // CHECK-NEXT: [[CASTED:%.*]] = bitcast i8* [[CALL]] to + new T; + // CHECK-NEXT: ret void + } + + template void f<int>(); +} diff --git a/test/CodeGenCXX/noinline-template.cpp b/test/CodeGenCXX/noinline-template.cpp new file mode 100644 index 0000000..6ee3935 --- /dev/null +++ b/test/CodeGenCXX/noinline-template.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// This was a problem in Sema, but only shows up as noinline missing +// in CodeGen. + +// CHECK: define linkonce_odr void @_ZN6VectorIiE13growStorageByEv(%struct.Vector* %this) nounwind noinline + +template <class Ty> struct Vector { + void growStorageBy(); +}; +template <class T> __attribute__((noinline)) void Vector<T>::growStorageBy() { +} +void foo() { + Vector<int> strs; + strs.growStorageBy(); +} diff --git a/test/CodeGenCXX/nrvo.cpp b/test/CodeGenCXX/nrvo.cpp index 82caff8..0efb355 100644 --- a/test/CodeGenCXX/nrvo.cpp +++ b/test/CodeGenCXX/nrvo.cpp @@ -13,10 +13,10 @@ public: // CHECK-EH: define void @_Z5test0v X test0() { X x; - // CHECK: call void @_ZN1XC1Ev + // CHECK: call {{.*}} @_ZN1XC1Ev // CHECK-NEXT: ret void - // CHECK-EH: call void @_ZN1XC1Ev + // CHECK-EH: call {{.*}} @_ZN1XC1Ev // CHECK-EH-NEXT: ret void return x; } @@ -24,13 +24,13 @@ X test0() { // CHECK: define void @_Z5test1b( // CHECK-EH: define void @_Z5test1b( X test1(bool B) { - // CHECK: tail call void @_ZN1XC1Ev + // CHECK: tail call {{.*}} @_ZN1XC1Ev // CHECK-NEXT: ret void X x; if (B) return (x); return x; - // CHECK-EH: tail call void @_ZN1XC1Ev + // CHECK-EH: tail call {{.*}} @_ZN1XC1Ev // CHECK-EH-NEXT: ret void } @@ -45,18 +45,18 @@ X test2(bool B) { return y; 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: call {{.*}} @_ZN1XC1Ev + // CHECK-NEXT: call {{.*}} @_ZN1XC1Ev + // CHECK: call {{.*}} @_ZN1XC1ERKS_ + // CHECK: call {{.*}} @_ZN1XC1ERKS_ + // CHECK: call {{.*}} @_ZN1XD1Ev + // CHECK: call {{.*}} @_ZN1XD1Ev // CHECK: ret void // The block ordering in the -fexceptions IR is unfortunate. - // CHECK-EH: call void @_ZN1XC1Ev - // CHECK-EH-NEXT: invoke void @_ZN1XC1Ev + // CHECK-EH: call {{.*}} @_ZN1XC1Ev + // CHECK-EH-NEXT: invoke {{.*}} @_ZN1XC1Ev // -> %invoke.cont, %lpad // %invoke.cont: @@ -64,7 +64,7 @@ X test2(bool B) { // -> %if.then, %if.end // %if.then: returning 'x' - // CHECK-EH: invoke void @_ZN1XC1ERKS_ + // CHECK-EH: invoke {{.*}} @_ZN1XC1ERKS_ // -> %cleanup, %lpad1 // %lpad: landing pad for ctor of 'y', dtor of 'y' @@ -74,23 +74,23 @@ X test2(bool B) { // -> %eh.cleanup // %lpad1: landing pad for return copy ctors, EH cleanup for 'y' - // CHECK-EH: invoke void @_ZN1XD1Ev + // CHECK-EH: invoke {{.*}} @_ZN1XD1Ev // -> %eh.cleanup, %terminate.lpad // %if.end: returning 'y' - // CHECK-EH: invoke void @_ZN1XC1ERKS_ + // CHECK-EH: invoke {{.*}} @_ZN1XC1ERKS_ // -> %cleanup, %lpad1 // %cleanup: normal cleanup for 'y' - // CHECK-EH: invoke void @_ZN1XD1Ev + // CHECK-EH: invoke {{.*}} @_ZN1XD1Ev // -> %invoke.cont11, %lpad // %invoke.cont11: normal cleanup for 'x' - // CHECK-EH: call void @_ZN1XD1Ev + // CHECK-EH: call {{.*}} @_ZN1XD1Ev // CHECK-EH-NEXT: ret void // %eh.cleanup: EH cleanup for 'x' - // CHECK-EH: invoke void @_ZN1XD1Ev + // CHECK-EH: invoke {{.*}} @_ZN1XD1Ev // -> %invoke.cont17, %terminate.lpad // %invoke.cont17: rethrow block for %eh.cleanup. @@ -121,13 +121,13 @@ extern "C" void exit(int) throw(); // CHECK: define void @_Z5test4b X test4(bool B) { { - // CHECK: tail call void @_ZN1XC1Ev + // CHECK: tail call {{.*}} @_ZN1XC1Ev X x; // CHECK: br i1 if (B) return x; } - // CHECK: tail call void @_ZN1XD1Ev + // CHECK: tail call {{.*}} @_ZN1XD1Ev // CHECK: tail call void @exit(i32 1) exit(1); } @@ -139,7 +139,7 @@ X test5() { try { may_throw(); } catch (X x) { - // CHECK-EH: invoke void @_ZN1XC1ERKS_ + // CHECK-EH: invoke {{.*}} @_ZN1XC1ERKS_ // CHECK-EH: call void @__cxa_end_catch() // CHECK-EH: ret void return x; diff --git a/test/CodeGenCXX/partial-destruction.cpp b/test/CodeGenCXX/partial-destruction.cpp new file mode 100644 index 0000000..82deca0 --- /dev/null +++ b/test/CodeGenCXX/partial-destruction.cpp @@ -0,0 +1,169 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s + +// Test IR generation for partial destruction of aggregates. + +void opaque(); + +// Initializer lists. +namespace test0 { + struct A { A(int); A(); ~A(); void *v; }; + void test() { + A as[10] = { 5, 7 }; + opaque(); + } + // CHECK: define void @_ZN5test04testEv() + // CHECK: [[AS:%.*]] = alloca [10 x [[A:%.*]]], align + // CHECK-NEXT: [[ENDVAR:%.*]] = alloca [[A]]* + // CHECK-NEXT: [[EXN:%.*]] = alloca i8* + // CHECK-NEXT: [[SEL:%.*]] = alloca i32 + // CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32 + + // Initialize. + // CHECK-NEXT: [[E_BEGIN:%.*]] = getelementptr inbounds [10 x [[A]]]* [[AS]], i64 0, i64 0 + // CHECK-NEXT: store [[A]]* [[E_BEGIN]], [[A]]** [[ENDVAR]] + // CHECK-NEXT: invoke void @_ZN5test01AC1Ei([[A]]* [[E_BEGIN]], i32 5) + // CHECK: [[E1:%.*]] = getelementptr inbounds [[A]]* [[E_BEGIN]], i64 1 + // CHECK-NEXT: store [[A]]* [[E1]], [[A]]** [[ENDVAR]] + // CHECK-NEXT: invoke void @_ZN5test01AC1Ei([[A]]* [[E1]], i32 7) + // CHECK: [[E2:%.*]] = getelementptr inbounds [[A]]* [[E1]], i64 1 + // CHECK-NEXT: store [[A]]* [[E2]], [[A]]** [[ENDVAR]] + // CHECK-NEXT: [[E_END:%.*]] = getelementptr inbounds [[A]]* [[E_BEGIN]], i64 10 + // CHECK-NEXT: br label + // CHECK: [[E_CUR:%.*]] = phi [[A]]* [ [[E2]], {{%.*}} ], [ [[E_NEXT:%.*]], {{%.*}} ] + // CHECK-NEXT: invoke void @_ZN5test01AC1Ev([[A]]* [[E_CUR]]) + // CHECK: [[E_NEXT]] = getelementptr inbounds [[A]]* [[E_CUR]], i64 1 + // CHECK-NEXT: store [[A]]* [[E_NEXT]], [[A]]** [[ENDVAR]] + // CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[E_NEXT]], [[E_END]] + // CHECK-NEXT: br i1 [[T0]], + + // Run. + // CHECK: invoke void @_Z6opaquev() + + // Normal destroy. + // CHECK: [[ED_BEGIN:%.*]] = getelementptr inbounds [10 x [[A]]]* [[AS]], i32 0, i32 0 + // CHECK-NEXT: [[ED_END:%.*]] = getelementptr inbounds [[A]]* [[ED_BEGIN]], i64 10 + // CHECK-NEXT: br label + // CHECK: [[ED_AFTER:%.*]] = phi [[A]]* [ [[ED_END]], {{%.*}} ], [ [[ED_CUR:%.*]], {{%.*}} ] + // CHECK-NEXT: [[ED_CUR]] = getelementptr inbounds [[A]]* [[ED_AFTER]], i64 -1 + // CHECK-NEXT: invoke void @_ZN5test01AD1Ev([[A]]* [[ED_CUR]]) + // CHECK: [[T0:%.*]] = icmp eq [[A]]* [[ED_CUR]], [[ED_BEGIN]] + // CHECK-NEXT: br i1 [[T0]], + // CHECK: ret void + + // Partial destroy for initialization. + // CHECK: llvm.eh.selector({{.*}}, i32 0) + // CHECK: [[PARTIAL_END:%.*]] = load [[A]]** [[ENDVAR]] + // CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[E_BEGIN]], [[PARTIAL_END]] + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[E_AFTER:%.*]] = phi [[A]]* [ [[PARTIAL_END]], {{%.*}} ], [ [[E_CUR:%.*]], {{%.*}} ] + // CHECK-NEXT: [[E_CUR]] = getelementptr inbounds [[A]]* [[E_AFTER]], i64 -1 + // CHECK-NEXT: invoke void @_ZN5test01AD1Ev([[A]]* [[E_CUR]]) + // CHECK: [[T0:%.*]] = icmp eq [[A]]* [[E_CUR]], [[E_BEGIN]] + // CHECK-NEXT: br i1 [[T0]], + + // Primary EH destructor. + // CHECK: llvm.eh.selector({{.*}}, i32 0) + // CHECK: [[E0:%.*]] = getelementptr inbounds [10 x [[A]]]* [[AS]], i32 0, i32 0 + // CHECK-NEXT: [[E_END:%.*]] = getelementptr inbounds [[A]]* [[E0]], i64 10 + // CHECK-NEXT: br label + + // Partial destructor for primary normal destructor. + // FIXME: There's some really bad block ordering here which causes + // the partial destroy for the primary normal destructor to fall + // within the primary EH destructor. + // CHECK: llvm.eh.selector({{.*}}, i32 0) + // CHECK: [[T0:%.*]] = icmp eq [[A]]* [[ED_BEGIN]], [[ED_CUR]] + // CHECK-NEXT: br i1 [[T0]] + // CHECK: [[EDD_AFTER:%.*]] = phi [[A]]* [ [[ED_CUR]], {{%.*}} ], [ [[EDD_CUR:%.*]], {{%.*}} ] + // CHECK-NEXT: [[EDD_CUR]] = getelementptr inbounds [[A]]* [[EDD_AFTER]], i64 -1 + // CHECK-NEXT: invoke void @_ZN5test01AD1Ev([[A]]* [[EDD_CUR]]) + // CHECK: [[T0:%.*]] = icmp eq [[A]]* [[EDD_CUR]], [[ED_BEGIN]] + // CHECK-NEXT: br i1 [[T0]] + + // Back to the primary EH destructor. + // CHECK: [[E_AFTER:%.*]] = phi [[A]]* [ [[E_END]], {{%.*}} ], [ [[E_CUR:%.*]], {{%.*}} ] + // CHECK-NEXT: [[E_CUR]] = getelementptr inbounds [[A]]* [[E_AFTER]], i64 -1 + // CHECK-NEXT: invoke void @_ZN5test01AD1Ev([[A]]* [[E_CUR]]) + // CHECK: [[T0:%.*]] = icmp eq [[A]]* [[E_CUR]], [[E0]] + // CHECK-NEXT: br i1 [[T0]], + +} + +namespace test1 { + struct A { A(); A(int); ~A(); }; + struct B { A x, y, z; int w; }; + + void test() { + B v = { 5, 6, 7, 8 }; + } + // CHECK: define void @_ZN5test14testEv() + // CHECK: [[V:%.*]] = alloca [[B:%.*]], align 4 + // CHECK-NEXT: alloca i8* + // CHECK-NEXT: alloca i32 + // CHECK-NEXT: alloca i32 + // CHECK-NEXT: [[X:%.*]] = getelementptr inbounds [[B]]* [[V]], i32 0, i32 0 + // CHECK-NEXT: call void @_ZN5test11AC1Ei([[A:%.*]]* [[X]], i32 5) + // CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds [[B]]* [[V]], i32 0, i32 1 + // CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* [[Y]], i32 6) + // CHECK: [[Z:%.*]] = getelementptr inbounds [[B]]* [[V]], i32 0, i32 2 + // CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* [[Z]], i32 7) + // CHECK: [[W:%.*]] = getelementptr inbounds [[B]]* [[V]], i32 0, i32 3 + // CHECK-NEXT: store i32 8, i32* [[W]], align 4 + // CHECK-NEXT: call void @_ZN5test11BD1Ev([[B]]* [[V]]) + // CHECK-NEXT: ret void + + // FIXME: again, the block ordering is pretty bad here + // CHECK: eh.selector({{.*}}, i32 0) + // CHECK: eh.selector({{.*}}, i32 0) + // CHECK: invoke void @_ZN5test11AD1Ev([[A]]* [[Y]]) + // CHECK: invoke void @_ZN5test11AD1Ev([[A]]* [[X]]) +} + +namespace test2 { + struct A { A(); ~A(); }; + + void test() { + A v[4][7]; + + // CHECK: define void @_ZN5test24testEv() + // CHECK: [[V:%.*]] = alloca [4 x [7 x [[A:%.*]]]], align 1 + // CHECK-NEXT: alloca i8* + // CHECK-NEXT: alloca i32 + // CHECK-NEXT: alloca i32 + + // Main initialization loop. + // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [4 x [7 x [[A]]]]* [[V]], i32 0, i32 0, i32 0 + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 28 + // CHECK-NEXT: br label + // CHECK: [[CUR:%.*]] = phi [[A]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] + // CHECK-NEXT: invoke void @_ZN5test21AC1Ev([[A]]* [[CUR]]) + // CHECK: [[NEXT:%.*]] = getelementptr inbounds [[A]]* [[CUR]], i64 1 + // CHECK-NEXT: [[DONE:%.*]] = icmp eq [[A]]* [[NEXT]], [[END]] + // CHECK-NEXT: br i1 [[DONE]], + + // Partial destruction landing pad. + // CHECK: llvm.eh.exception() + // CHECK: [[EMPTY:%.*]] = icmp eq [[A]]* [[BEGIN]], [[CUR]] + // CHECK-NEXT: br i1 [[EMPTY]], + // CHECK: [[PAST:%.*]] = phi [[A]]* [ [[CUR]], {{%.*}} ], [ [[DEL:%.*]], {{%.*}} ] + // CHECK-NEXT: [[DEL]] = getelementptr inbounds [[A]]* [[PAST]], i64 -1 + // CHECK-NEXT: invoke void @_ZN5test21AD1Ev([[A]]* [[DEL]]) + // CHECK: [[T0:%.*]] = icmp eq [[A]]* [[DEL]], [[BEGIN]] + // CHECK-NEXT: br i1 [[T0]], + } + +} + +// PR10351 +namespace test3 { + struct A { A(); ~A(); void *p; }; + struct B { + B() {} + A a; + }; + + B *test() { + return new B[10]; + // invoke void @_ZN5test31BD1Ev( + } +} diff --git a/test/CodeGenCXX/pointers-to-data-members.cpp b/test/CodeGenCXX/pointers-to-data-members.cpp index 2a22d23..f0246c8 100644 --- a/test/CodeGenCXX/pointers-to-data-members.cpp +++ b/test/CodeGenCXX/pointers-to-data-members.cpp @@ -35,7 +35,7 @@ namespace ZeroInit { } ssa[2]; void test_ssa() { (void) ssa; } - // CHECK-GLOBAL: @_ZN8ZeroInit2ssE = internal global %1 { %struct.anon { i64 -1 } } + // CHECK-GLOBAL: @_ZN8ZeroInit2ssE = internal global %struct.anon.1 { %struct.anon.2 { i64 -1 } } struct { struct { int A::*pa; @@ -55,7 +55,7 @@ namespace ZeroInit { }; struct C : A, B { int j; }; - // CHECK-GLOBAL: @_ZN8ZeroInit1cE = global {{%.*}} { %"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }, %"struct.ZeroInit::B" { [10 x %"struct.PR7139::ptr_to_member_struct"] [%"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }, %"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }, %"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }, %"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }, %"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }, %"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }, %"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }, %"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }, %"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }, %"struct.PR7139::ptr_to_member_struct" { i64 -1, i32 0 }], i8 0, i64 -1 }, i32 0 }, align 8 + // CHECK-GLOBAL: @_ZN8ZeroInit1cE = global {{%.*}} { %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::B" { [10 x %"struct.ZeroInit::A"] [%"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }], i8 0, i64 -1 }, i32 0 }, align 8 C c; } @@ -227,6 +227,6 @@ namespace test4 { struct C : virtual B { int *C_p; }; struct D : C { int *D_p; }; - // CHECK-GLOBAL: @_ZN5test41dE = global %"struct.test4::D" { %"struct.test4::C.base" zeroinitializer, i32* null, %"struct.VirtualBases::C.base" { i32 (...)** null, i64 -1 }, %"struct.test4::A" zeroinitializer }, align 8 + // CHECK-GLOBAL: @_ZN5test41dE = global %"struct.test4::D" { %"struct.test4::C.base" zeroinitializer, i32* null, %"struct.test4::B.base" { i32 (...)** null, i64 -1 }, %"struct.test4::A" zeroinitializer }, align 8 D d; } diff --git a/test/CodeGenCXX/pr9965.cpp b/test/CodeGenCXX/pr9965.cpp index b87fcf4..596dee9 100644 --- a/test/CodeGenCXX/pr9965.cpp +++ b/test/CodeGenCXX/pr9965.cpp @@ -7,6 +7,6 @@ struct X X<int> x; // CHECK: define internal void @__cxx_global_var_init() -// CHECK: call void @_ZN1XIiEC1Ev -// CHECK: define linkonce_odr void @_ZN1XIiEC1Ev -// CHECK: define linkonce_odr void @_ZN1XIiEC2Ev +// CHECK: call {{.*}} @_ZN1XIiEC1Ev +// CHECK: define linkonce_odr {{.*}} @_ZN1XIiEC1Ev +// CHECK: define linkonce_odr {{.*}} @_ZN1XIiEC2Ev diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp index 25bc8d8..4bbc251 100644 --- a/test/CodeGenCXX/references.cpp +++ b/test/CodeGenCXX/references.cpp @@ -235,7 +235,7 @@ struct A { }; // CHECK: define internal void @__cxx_global_var_init -// CHECK: call void @_ZN2N31AC1Ei(%"class.N2::X"* @_ZGRN2N35sA123E, i32 123) +// CHECK: call void @_ZN2N31AC1Ei(%"struct.N3::A"* @_ZGRN2N35sA123E, i32 123) // CHECK: call i32 @__cxa_atexit // CHECK: ret void const A &sA123 = A(123); @@ -250,7 +250,7 @@ struct A { void f() { // CHECK: define void @_ZN2N41fEv - // CHECK: call void @_ZN2N41AC1Ev(%"class.N2::X"* @_ZGRZN2N41fEvE2ar) + // CHECK: call void @_ZN2N41AC1Ev(%"struct.N4::A"* @_ZGRZN2N41fEvE2ar) // CHECK: call i32 @__cxa_atexit // CHECK: ret void static const A& ar = A(); @@ -269,3 +269,31 @@ void h() { f(g().b); } } + +// PR9565 +namespace PR9565 { + struct a { int a : 10, b : 10; }; + // CHECK: define void @_ZN6PR95651fEv() + void f() { + // CHECK: call void @llvm.memcpy + a x = { 0, 0 }; + // CHECK: [[WITH_SEVENTEEN:%[a-zA-Z0-9]+]] = or i32 [[WITHOUT_SEVENTEEN:%[a-zA-Z0-9]+]], 17 + // CHECK: store i32 [[WITH_SEVENTEEN]], i32* [[XA:%[a-zA-Z0-9]+]] + x.a = 17; + // CHECK-NEXT: bitcast + // CHECK-NEXT: load + // CHECK-NEXT: and + // CHECK-NEXT: shl + // CHECK-NEXT: ashr + // CHECK-NEXT: store i32 + // CHECK-NEXT: store i32* + const int &y = x.a; + // CHECK-NEXT: bitcast + // CHECK-NEXT: load + // CHECK-NEXT: and + // CHECK-NEXT: or + // CHECK-NEXT: store i32 + x.b = 19; + // CHECK-NEXT: ret void + } +} diff --git a/test/CodeGenCXX/static-init-3.cpp b/test/CodeGenCXX/static-init-3.cpp index bd717ca..dc28d5a 100644 --- a/test/CodeGenCXX/static-init-3.cpp +++ b/test/CodeGenCXX/static-init-3.cpp @@ -16,8 +16,8 @@ struct X1 } }; -// CHECK: @_ZN2X1I2X2I1BEE8instanceE = weak_odr global %struct.X0* null, align 8 -// CHECJ: @_ZN2X1I2X2I1AEE8instanceE = weak_odr global %struct.X0* null, align 8 +// CHECK: @_ZN2X1I2X2I1BEE8instanceE = weak_odr global %struct.X2* null, align 8 +// CHECJ: @_ZN2X1I2X2I1AEE8instanceE = weak_odr global %struct.X2* null, align 8 template<class T> T & X1<T>::instance = X1<T>::get(); class A { }; diff --git a/test/CodeGenCXX/static-init.cpp b/test/CodeGenCXX/static-init.cpp index 78749a7..d488e63 100644 --- a/test/CodeGenCXX/static-init.cpp +++ b/test/CodeGenCXX/static-init.cpp @@ -16,6 +16,9 @@ void f() { // CHECK: call void @_ZN1AC1Ev // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @_ZZ1fvE1a, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) // CHECK: call void @__cxa_guard_release + + // rdar://problem/9496726 + // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 false, i1 false, i1 false) static A a; } diff --git a/test/CodeGenCXX/stmtexpr.cpp b/test/CodeGenCXX/stmtexpr.cpp index 0828d59..1f0e4ac 100644 --- a/test/CodeGenCXX/stmtexpr.cpp +++ b/test/CodeGenCXX/stmtexpr.cpp @@ -46,11 +46,11 @@ void foo3() void foo4() { -// CHECK: call void @_ZN1AC1Ei -// CHECK: call void @_ZN1AC1ERKS_ -// CHECK: call void @_ZN1AD1Ev -// CHECK: call void @_ZN1BC1ERK1A -// CHECK: call void @_ZN1AD1Ev +// CHECK: call {{.*}} @_ZN1AC1Ei +// CHECK: call {{.*}} @_ZN1AC1ERKS_ +// CHECK: call {{.*}} @_ZN1AD1Ev +// CHECK: call {{.*}} @_ZN1BC1ERK1A +// CHECK: call {{.*}} @_ZN1AD1Ev const B &b = ({ A a(1); a; }); if (b.i != 1) abort(); diff --git a/test/CodeGenCXX/template-anonymous-types.cpp b/test/CodeGenCXX/template-anonymous-types.cpp index 68bdc0c..72fe090 100644 --- a/test/CodeGenCXX/template-anonymous-types.cpp +++ b/test/CodeGenCXX/template-anonymous-types.cpp @@ -32,6 +32,6 @@ void test() { // CHECK: define internal void @"_ZN1XIN1S3$_1EEC2ES1_"(%struct.X* %this, i32 %t) unnamed_addr // // FOO's instantiation of X: - // CHECK: define internal i32 @"_ZN1XIN1S3$_0EE1fEv"(%struct.X* %this) - // CHECK: define internal void @"_ZN1XIN1S3$_0EEC2ES1_"(%struct.X* %this, i32 %t) unnamed_addr + // CHECK: define internal i32 @"_ZN1XIN1S3$_0EE1fEv"(%struct.X.0* %this) + // CHECK: define internal void @"_ZN1XIN1S3$_0EEC2ES1_"(%struct.X.0* %this, i32 %t) unnamed_addr } diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp index 348d51e..8aeca65 100644 --- a/test/CodeGenCXX/temporaries.cpp +++ b/test/CodeGenCXX/temporaries.cpp @@ -421,28 +421,24 @@ namespace Elision { void test4() { // CHECK: [[X:%.*]] = alloca [[A]], align 8 // CHECK-NEXT: [[XS:%.*]] = alloca [2 x [[A]]], align 16 - // CHECK-NEXT: [[I:%.*]] = alloca i64 // CHECK-NEXT: call void @_ZN7Elision1AC1Ev([[A]]* [[X]]) A x; - // CHECK-NEXT: [[XS0:%.*]] = getelementptr inbounds [2 x [[A]]]* [[XS]], i32 0, i32 0 + // CHECK-NEXT: [[XS0:%.*]] = getelementptr inbounds [2 x [[A]]]* [[XS]], i64 0, i64 0 // CHECK-NEXT: call void @_ZN7Elision1AC1Ev([[A]]* [[XS0]]) - // CHECK-NEXT: [[XS1:%.*]] = getelementptr inbounds [2 x [[A]]]* [[XS]], i32 0, i32 1 + // CHECK-NEXT: [[XS1:%.*]] = getelementptr inbounds [[A]]* [[XS0]], i64 1 // CHECK-NEXT: call void @_ZN7Elision1AC1ERKS0_([[A]]* [[XS1]], [[A]]* [[X]]) - // CHECK-NEXT: [[XSB:%.*]] = bitcast [2 x [[A]]]* [[XS]] to [[A]]* A xs[] = { A(), x }; - // CHECK-NEXT: store i64 2, i64* [[I]] - // CHECK-NEXT: br label - // CHECK: [[I0:%.*]] = load i64* [[I]] - // CHECK-NEXT: icmp ne i64 [[I0]], 0 - // CHECK-NEXT: br i1 - // CHECK: [[I1:%.*]] = load i64* [[I]] - // CHECK-NEXT: [[I2:%.*]] = sub i64 [[I1]], 1 - // CHECK-NEXT: [[XSI:%.*]] = getelementptr inbounds [[A]]* [[XSB]], i64 [[I2]] - // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[XSI]]) + // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [2 x [[A]]]* [[XS]], i32 0, i32 0 + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 2 // CHECK-NEXT: br label + // CHECK: [[AFTER:%.*]] = phi [[A]]* + // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds [[A]]* [[AFTER]], i64 -1 + // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[CUR]]) + // CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]] + // CHECK-NEXT: br i1 [[T0]], // CHECK: call void @_ZN7Elision1AD1Ev([[A]]* [[X]]) } diff --git a/test/CodeGenCXX/value-init.cpp b/test/CodeGenCXX/value-init.cpp index a5a0b67..04a18b3 100644 --- a/test/CodeGenCXX/value-init.cpp +++ b/test/CodeGenCXX/value-init.cpp @@ -105,34 +105,24 @@ void f() { // CHECK: call void @_ZN6PR98014TestC1Ei // CHECK-NOT: call void @llvm.memset.p0i8.i64 // CHECK: call void @_ZN6PR98014TestC1Ev - // CHECK-NOT: call void @llvm.memset.p0i8.i64 - // CHECK: call void @_ZN6PR98014TestC1Ev Test partial[3] = { 1 }; // CHECK-NOT: call void @llvm.memset.p0i8.i64 // CHECK: call void @_ZN6PR98014TestC1Ev - // CHECK-NOT: call void @llvm.memset.p0i8.i64 - // CHECK: call void @_ZN6PR98014TestC1Ev - // CHECK-NOT: call void @llvm.memset.p0i8.i64 - // CHECK: call void @_ZN6PR98014TestC1Ev + // CHECK-NOT: call void @_ZN6PR98014TestC1Ev Test empty[3] = {}; // CHECK: call void @llvm.memset.p0i8.i64 // CHECK-NOT: call void @llvm.memset.p0i8.i64 // CHECK: call void @_ZN6PR98015Test2C1Ev - // CHECK-NOT: call void @llvm.memset.p0i8.i64 - // CHECK: call void @_ZN6PR98015Test2C1Ev - // CHECK-NOT: call void @llvm.memset.p0i8.i64 - // CHECK: call void @_ZN6PR98015Test2C1Ev + // CHECK-NOT: call void @_ZN6PR98015Test2C1Ev Test2 empty2[3] = {}; // CHECK: call void @llvm.memset.p0i8.i64 // CHECK-NOT: call void @llvm.memset.p0i8.i64 // CHECK: call void @_ZN6PR98015Test3C1Ev // CHECK-NOT: call void @llvm.memset.p0i8.i64 - // CHECK: call void @_ZN6PR98015Test3C1Ev - // CHECK-NOT: call void @llvm.memset.p0i8.i64 - // CHECK: call void @_ZN6PR98015Test3C1Ev + // CHECK-NOT: call void @_ZN6PR98015Test3C1Ev Test3 empty3[3] = {}; } @@ -189,10 +179,7 @@ namespace zeroinit { X3<int>().f(); } - // CHECK: define linkonce_odr void @_ZN8zeroinit2X3IiEC2Ev(%"struct.zeroinit::X3"* %this) unnamed_addr - // CHECK: call void @llvm.memset.p0i8.i64 - // CHECK-NEXT: call void @_ZN8zeroinit2X2IiEC2Ev - // CHECK-NEXT: ret void + // More checks at EOF } namespace PR8726 { @@ -207,3 +194,51 @@ void f(const C& c) { } } + +// rdar://problem/9355931 +namespace test6 { + struct A { A(); A(int); }; + + void test() { + A arr[10][20] = { 5 }; + }; + // CHECK: define void @_ZN5test64testEv() + // CHECK: [[ARR:%.*]] = alloca [10 x [20 x [[A:%.*]]]], + + // CHECK-NEXT: [[INNER:%.*]] = getelementptr inbounds [10 x [20 x [[A]]]]* [[ARR]], i64 0, i64 0 + // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [20 x [[A]]]* [[INNER]], i64 0, i64 0 + // CHECK-NEXT: call void @_ZN5test61AC1Ei([[A]]* [[T0]], i32 5) + // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [[A]]* [[T0]], i64 1 + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[T0]], i64 20 + // CHECK-NEXT: br label + // CHECK: [[CUR:%.*]] = phi [[A]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] + // CHECK-NEXT: call void @_ZN5test61AC1Ev([[A]]* [[CUR]]) + // CHECK-NEXT: [[NEXT]] = getelementptr inbounds [[A]]* [[CUR]], i64 1 + // CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[NEXT]], [[END]] + // CHECK-NEXT: br i1 + + // CHECK: [[BEGIN:%.*]] = getelementptr inbounds [20 x [[A]]]* [[INNER]], i64 1 + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [20 x [[A]]]* [[INNER]], i64 10 + // CHECK-NEXT: br label + // CHECK: [[CUR:%.*]] = phi [20 x [[A]]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] + + // Inner loop. + // CHECK-NEXT: [[IBEGIN:%.*]] = getelementptr inbounds [20 x [[A]]]* [[CUR]], i32 0, i32 0 + // CHECK-NEXT: [[IEND:%.*]] = getelementptr inbounds [[A]]* [[IBEGIN]], i64 20 + // CHECK-NEXT: br label + // CHECK: [[ICUR:%.*]] = phi [[A]]* [ [[IBEGIN]], {{%.*}} ], [ [[INEXT:%.*]], {{%.*}} ] + // CHECK-NEXT: call void @_ZN5test61AC1Ev([[A]]* [[ICUR]]) + // CHECK-NEXT: [[INEXT:%.*]] = getelementptr inbounds [[A]]* [[ICUR]], i64 1 + // CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[INEXT]], [[IEND]] + // CHECK-NEXT: br i1 [[T0]], + + // CHECK: [[NEXT]] = getelementptr inbounds [20 x [[A]]]* [[CUR]], i64 1 + // CHECK-NEXT: [[T0:%.*]] = icmp eq [20 x [[A]]]* [[NEXT]], [[END]] + // CHECK-NEXT: br i1 [[T0]] + // CHECK: ret void +} + +// CHECK: define linkonce_odr void @_ZN8zeroinit2X3IiEC2Ev(%"struct.zeroinit::X3"* %this) unnamed_addr +// CHECK: call void @llvm.memset.p0i8.i64 +// CHECK-NEXT: call void @_ZN8zeroinit2X2IiEC2Ev +// CHECK-NEXT: ret void diff --git a/test/CodeGenCXX/variadic-templates.cpp b/test/CodeGenCXX/variadic-templates.cpp index 4f3cf1f..90c8370 100644 --- a/test/CodeGenCXX/variadic-templates.cpp +++ b/test/CodeGenCXX/variadic-templates.cpp @@ -9,4 +9,15 @@ int get_num_types(Types...) { // CHECK: ret i32 3 template int get_num_types(int, float, double); +// PR10260 - argument packs that expand to nothing +namespace test1 { + template <class... T> void foo() { + int values[sizeof...(T)+1] = { T::value... }; + // CHECK: define linkonce_odr void @_ZN5test13fooIJEEEvv() + // CHECK: alloca [1 x i32], align 4 + } + void test() { + foo<>(); + } +} diff --git a/test/CodeGenCXX/virt-call-offsets.cpp b/test/CodeGenCXX/virt-call-offsets.cpp index 3eb6b5d..5eef6fe 100644 --- a/test/CodeGenCXX/virt-call-offsets.cpp +++ b/test/CodeGenCXX/virt-call-offsets.cpp @@ -5,4 +5,4 @@ struct B : A {}; struct C : B { virtual void a(); }; void (C::*x)() = &C::a; -// CHECK: @x = global %0 { i{{[0-9]+}} 1, i{{[0-9]+}} 0 } +// CHECK: @x = global { i{{[0-9]+}}, i{{[0-9]+}} } { i{{[0-9]+}} 1, i{{[0-9]+}} 0 } diff --git a/test/CodeGenCXX/virtual-base-destructor-call.cpp b/test/CodeGenCXX/virtual-base-destructor-call.cpp index f028e4c..2424d21 100644 --- a/test/CodeGenCXX/virtual-base-destructor-call.cpp +++ b/test/CodeGenCXX/virtual-base-destructor-call.cpp @@ -18,34 +18,34 @@ int main() { // basic_iostream's complete dtor calls its base dtor, then its // virtual base's dtor. -// CHECK: define linkonce_odr void @_ZN14basic_iostreamIcED1Ev(%struct.basic_iostream* %this) unnamed_addr -// CHECK: call void @_ZN14basic_iostreamIcED2Ev -// CHECK: call void @_ZN9basic_iosD2Ev +// CHECK: define linkonce_odr {{.*}} @_ZN14basic_iostreamIcED1Ev(%struct.basic_iostream* %this) unnamed_addr +// CHECK: call {{.*}} @_ZN14basic_iostreamIcED2Ev +// CHECK: call {{.*}} @_ZN9basic_iosD2Ev // basic_iostream's base dtor calls its non-virtual base dtor. -// CHECK: define linkonce_odr void @_ZN14basic_iostreamIcED2Ev(%struct.basic_iostream* %this, i8** %vtt) unnamed_addr -// CHECK: call void @_ZN13basic_istreamIcED2Ev +// CHECK: define linkonce_odr {{.*}} @_ZN14basic_iostreamIcED2Ev(%struct.basic_iostream* %this, i8** %vtt) unnamed_addr +// CHECK: call {{.*}} @_ZN13basic_istreamIcED2Ev // CHECK: } // basic_iostream's deleting dtor calls its complete dtor, then // operator delete(). -// CHECK: define linkonce_odr void @_ZN14basic_iostreamIcED0Ev(%struct.basic_iostream* %this) unnamed_addr -// CHECK: call void @_ZN14basic_iostreamIcED1Ev -// CHECK: call void @_ZdlPv +// CHECK: define linkonce_odr {{.*}} @_ZN14basic_iostreamIcED0Ev(%struct.basic_iostream* %this) unnamed_addr +// CHECK: call {{.*}} @_ZN14basic_iostreamIcED1Ev +// CHECK: call {{.*}} @_ZdlPv // basic_istream's complete dtor calls the base dtor, // then its virtual base's base dtor. -// CHECK: define linkonce_odr void @_ZN13basic_istreamIcED1Ev(%struct.basic_istream* %this) unnamed_addr -// CHECK: call void @_ZN13basic_istreamIcED2Ev -// CHECK: call void @_ZN9basic_iosD2Ev +// CHECK: define linkonce_odr {{.*}} @_ZN13basic_istreamIcED1Ev(%struct.basic_istream* %this) unnamed_addr +// CHECK: call {{.*}} @_ZN13basic_istreamIcED2Ev +// CHECK: call {{.*}} @_ZN9basic_iosD2Ev // basic_istream's deleting dtor calls the complete dtor, then // operator delete(). -// CHECK: define linkonce_odr void @_ZN13basic_istreamIcED0Ev(%struct.basic_istream* %this) unnamed_addr -// CHECK: call void @_ZN13basic_istreamIcED1Ev -// CHECK: call void @_ZdlPv +// CHECK: define linkonce_odr {{.*}} @_ZN13basic_istreamIcED0Ev(%struct.basic_istream* %this) unnamed_addr +// CHECK: call {{.*}} @_ZN13basic_istreamIcED1Ev +// CHECK: call {{.*}} @_ZdlPv // basic_istream's base dtor is a no-op. -// CHECK: define linkonce_odr void @_ZN13basic_istreamIcED2Ev(%struct.basic_istream* %this, i8** %vtt) unnamed_addr +// CHECK: define linkonce_odr {{.*}} @_ZN13basic_istreamIcED2Ev(%struct.basic_istream* %this, i8** %vtt) unnamed_addr // CHECK-NOT: call // CHECK: } diff --git a/test/CodeGenCXX/virtual-bases.cpp b/test/CodeGenCXX/virtual-bases.cpp index cfb4c83..c9f13f8 100644 --- a/test/CodeGenCXX/virtual-bases.cpp +++ b/test/CodeGenCXX/virtual-bases.cpp @@ -20,8 +20,8 @@ struct C : virtual A { C(bool); }; -// CHECK: define void @_ZN1CC1Eb(%struct.B* %this, i1 zeroext) unnamed_addr -// CHECK: define void @_ZN1CC2Eb(%struct.B* %this, i8** %vtt, i1 zeroext) unnamed_addr +// CHECK: define void @_ZN1CC1Eb(%struct.C* %this, i1 zeroext) unnamed_addr +// CHECK: define void @_ZN1CC2Eb(%struct.C* %this, i8** %vtt, i1 zeroext) unnamed_addr C::C(bool) { } // PR6251 diff --git a/test/CodeGenCXX/virtual-functions-incomplete-types.cpp b/test/CodeGenCXX/virtual-functions-incomplete-types.cpp index 052a019..afa658f 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 i32 @_ZN1D1gEv(%struct.B* %this) +// CHECK: define i32 @_ZN1D1gEv(%struct.D* %this) // CHECK: declare void @_ZN1B1gEv() struct C; diff --git a/test/CodeGenCXX/virtual-pseudo-destructor-call.cpp b/test/CodeGenCXX/virtual-pseudo-destructor-call.cpp index 285e3da..0d3574e 100644 --- a/test/CodeGenCXX/virtual-pseudo-destructor-call.cpp +++ b/test/CodeGenCXX/virtual-pseudo-destructor-call.cpp @@ -5,6 +5,10 @@ struct A { }; void f(A *a) { - // CHECK: call void % + // CHECK: define {{.*}} @_Z1fP1A + // CHECK: load + // CHECK: load + // CHECK: [[CALLEE:%[a-zA-Z0-9.]*]] = load + // CHECK: call {{.*}} [[CALLEE]]( a->~A(); } diff --git a/test/CodeGenCXX/visibility-inlines-hidden.cpp b/test/CodeGenCXX/visibility-inlines-hidden.cpp index 760879a..f7fabed 100644 --- a/test/CodeGenCXX/visibility-inlines-hidden.cpp +++ b/test/CodeGenCXX/visibility-inlines-hidden.cpp @@ -77,7 +77,7 @@ namespace test1 { a.foo(); } // CHECK: declare void @_ZN5test11A3fooEv -// CHECK: declare void @_ZN5test11AD1Ev +// CHECK: declare {{.*}} @_ZN5test11AD1Ev } // PR8713 diff --git a/test/CodeGenCXX/visibility.cpp b/test/CodeGenCXX/visibility.cpp index 7644e47..fdccd46 100644 --- a/test/CodeGenCXX/visibility.cpp +++ b/test/CodeGenCXX/visibility.cpp @@ -422,3 +422,35 @@ namespace test21 { // CHECK: define weak_odr void @_ZN6test211AILNS_2EnE0EE3fooEv( template void A<en>::foo(); } + +// rdar://problem/9616154 +// Visibility on explicit specializations should take precedence. +namespace test22 { + class A1 {}; + class A2 {}; + + template <class T> struct B {}; + template <> struct DEFAULT B<A1> { + static void foo(); + static void bar() {} + }; + template <> struct B<A2> { + static void foo(); + static void bar() {} + }; + + void test() { + B<A1>::foo(); + B<A1>::bar(); + B<A2>::foo(); + B<A2>::bar(); + } + // CHECK: declare void @_ZN6test221BINS_2A1EE3fooEv() + // CHECK: define linkonce_odr void @_ZN6test221BINS_2A1EE3barEv() + // CHECK: declare void @_ZN6test221BINS_2A2EE3fooEv() + // CHECK: define linkonce_odr void @_ZN6test221BINS_2A2EE3barEv() + // CHECK-HIDDEN: declare void @_ZN6test221BINS_2A1EE3fooEv() + // CHECK-HIDDEN: define linkonce_odr void @_ZN6test221BINS_2A1EE3barEv() + // CHECK-HIDDEN: declare void @_ZN6test221BINS_2A2EE3fooEv() + // CHECK-HIDDEN: define linkonce_odr hidden void @_ZN6test221BINS_2A2EE3barEv() +} diff --git a/test/CodeGenCXX/vla.cpp b/test/CodeGenCXX/vla.cpp new file mode 100644 index 0000000..58cdf79 --- /dev/null +++ b/test/CodeGenCXX/vla.cpp @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s + +// rdar://problem/9506377 +void test0(void *array, int n) { + // CHECK: define void @_Z5test0Pvi( + // CHECK: [[ARRAY:%.*]] = alloca i8*, align 8 + // CHECK-NEXT: [[N:%.*]] = alloca i32, align 4 + // CHECK-NEXT: [[REF:%.*]] = alloca i16*, align 8 + // CHECK-NEXT: [[S:%.*]] = alloca i16, align 2 + // CHECK-NEXT: store i8* + // CHECK-NEXT: store i32 + + // Capture the bounds. + // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[DIM0:%.*]] = zext i32 [[T0]] to i64 + // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[T1:%.*]] = add nsw i32 [[T0]], 1 + // CHECK-NEXT: [[DIM1:%.*]] = zext i32 [[T1]] to i64 + typedef short array_t[n][n+1]; + + // CHECK-NEXT: [[T0:%.*]] = load i8** [[ARRAY]], align 8 + // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to i16* + // CHECK-NEXT: store i16* [[T1]], i16** [[REF]], align 8 + array_t &ref = *(array_t*) array; + + // CHECK-NEXT: [[T0:%.*]] = load i16** [[REF]] + // CHECK-NEXT: [[T1:%.*]] = mul nsw i64 1, [[DIM1]] + // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i16* [[T0]], i64 [[T1]] + // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i16* [[T2]], i64 2 + // CHECK-NEXT: store i16 3, i16* [[T3]] + ref[1][2] = 3; + + // CHECK-NEXT: [[T0:%.*]] = load i16** [[REF]] + // CHECK-NEXT: [[T1:%.*]] = mul nsw i64 4, [[DIM1]] + // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i16* [[T0]], i64 [[T1]] + // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i16* [[T2]], i64 5 + // CHECK-NEXT: [[T4:%.*]] = load i16* [[T3]] + // CHECK-NEXT: store i16 [[T4]], i16* [[S]], align 2 + short s = ref[4][5]; + + // CHECK-NEXT: ret void +} + diff --git a/test/CodeGenCXX/volatile-1.cpp b/test/CodeGenCXX/volatile-1.cpp index 3ae17bd..1a69648 100644 --- a/test/CodeGenCXX/volatile-1.cpp +++ b/test/CodeGenCXX/volatile-1.cpp @@ -4,7 +4,7 @@ volatile int i, j, k; volatile int ar[5]; volatile char c; -// CHECK: @ci = global [[CINT:%.*]] zeroinitializer +// CHECK: @ci = global [[CINT:.*]] zeroinitializer volatile _Complex int ci; volatile struct S { #ifdef __cplusplus diff --git a/test/CodeGenCXX/vtable-pointer-initialization.cpp b/test/CodeGenCXX/vtable-pointer-initialization.cpp index f629c2d..9b1eaa5 100644 --- a/test/CodeGenCXX/vtable-pointer-initialization.cpp +++ b/test/CodeGenCXX/vtable-pointer-initialization.cpp @@ -41,16 +41,16 @@ struct B : Base { void f() { B b; } -// CHECK: define linkonce_odr void @_ZN1BC1Ev(%struct.A* %this) unnamed_addr +// CHECK: define linkonce_odr void @_ZN1BC1Ev(%struct.B* %this) unnamed_addr // CHECK: call void @_ZN1BC2Ev( -// CHECK: define linkonce_odr void @_ZN1BD1Ev(%struct.A* %this) unnamed_addr +// CHECK: define linkonce_odr void @_ZN1BD1Ev(%struct.B* %this) unnamed_addr // CHECK: store i8** getelementptr inbounds ([3 x i8*]* @_ZTV1B, i64 0, i64 2) // CHECK: call void @_ZN5FieldD1Ev( // CHECK: call void @_ZN4BaseD2Ev( // CHECK: ret void -// CHECK: define linkonce_odr void @_ZN1BC2Ev(%struct.A* %this) unnamed_addr +// CHECK: define linkonce_odr void @_ZN1BC2Ev(%struct.B* %this) unnamed_addr // CHECK: call void @_ZN4BaseC2Ev( // CHECK: store i8** getelementptr inbounds ([3 x i8*]* @_ZTV1B, i64 0, i64 2) // CHECK: call void @_ZN5FieldC1Ev diff --git a/test/CodeGenCXX/x86_32-arguments.cpp b/test/CodeGenCXX/x86_32-arguments.cpp index 4c06033..4d43393 100644 --- a/test/CodeGenCXX/x86_32-arguments.cpp +++ b/test/CodeGenCXX/x86_32-arguments.cpp @@ -89,7 +89,7 @@ struct s5 { s5(); int &x; }; s5 f5() { return s5(); } // CHECK: define i32 @_Z4f6_0M2s6i(i32 %a) -// CHECK: define i64 @_Z4f6_1M2s6FivE(%{{.*}} byval align 4) +// CHECK: define i64 @_Z4f6_1M2s6FivE({ i32, i32 }* byval align 4) // FIXME: It would be nice to avoid byval on the previous case. struct s6 {}; typedef int s6::* s6_mdp; diff --git a/test/CodeGenCXX/x86_64-arguments.cpp b/test/CodeGenCXX/x86_64-arguments.cpp index 01f1a44..e1d9dfc 100644 --- a/test/CodeGenCXX/x86_64-arguments.cpp +++ b/test/CodeGenCXX/x86_64-arguments.cpp @@ -115,3 +115,37 @@ namespace test6 { } // CHECK: define i32 @_ZN5test64testENS_5outerE(i64 %x.coerce0, i32 %x.coerce1) } + +namespace test7 { + struct StringRef {char* ptr; long len; }; + class A { public: ~A(); }; + A x(A, A, long, long, StringRef) { return A(); } + // Check that the StringRef is passed byval instead of expanded + // (which would split it between registers and memory). + // rdar://problem/9686430 + // CHECK: define void @_ZN5test71xENS_1AES0_llNS_9StringRefE({{.*}} byval align 8) + + // And a couple extra related tests: + A y(A, long double, long, long, StringRef) { return A(); } + // CHECK: define void @_ZN5test71yENS_1AEellNS_9StringRefE({{.*}} i8* + struct StringDouble {char * ptr; double d;}; + A z(A, A, A, A, A, StringDouble) { return A(); } + A zz(A, A, A, A, StringDouble) { return A(); } + // CHECK: define void @_ZN5test71zENS_1AES0_S0_S0_S0_NS_12StringDoubleE({{.*}} byval align 8) + // CHECK: define void @_ZN5test72zzENS_1AES0_S0_S0_NS_12StringDoubleE({{.*}} i8* +} + +namespace test8 { + // CHECK: declare void @_ZN5test83fooENS_1BE(%"class.test8::B"* byval align 8) + class A { + char big[17]; + }; + + class B : public A {}; + + void foo(B b); + void bar() { + B b; + foo(b); + } +} diff --git a/test/CodeGenObjC/arc-arm.m b/test/CodeGenObjC/arc-arm.m new file mode 100644 index 0000000..a3d55c2 --- /dev/null +++ b/test/CodeGenObjC/arc-arm.m @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple armv7-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -o - %s | FileCheck %s + +id test0(void) { + extern id test0_helper(void); + // CHECK: [[T0:%.*]] = call arm_aapcscc i8* @test0_helper() + // CHECK-NEXT: ret i8* [[T0]] + return test0_helper(); +} + +void test1(void) { + extern id test1_helper(void); + // CHECK: [[T0:%.*]] = call arm_aapcscc i8* @test1_helper() + // CHECK-NEXT: call void asm sideeffect "mov\09r7, r7 + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T1]], + // CHECK-NEXT: load + // CHECK-NEXT: call void @objc_release + // CHECK-NEXT: ret void + id x = test1_helper(); +} diff --git a/test/CodeGenObjC/arc-block-ivar-layout.m b/test/CodeGenObjC/arc-block-ivar-layout.m new file mode 100644 index 0000000..50c35ba --- /dev/null +++ b/test/CodeGenObjC/arc-block-ivar-layout.m @@ -0,0 +1,60 @@ +// RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-weak -triple x86_64-apple-darwin -O0 -emit-llvm %s -o %t-64.s +// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s +// rdar://8991729 + +__weak id wid; +void x(id y) {} +void y(int a) {} + +extern id opaque_id(); + +void f() { + __block int byref_int = 0; + char ch = 'a'; + char ch1 = 'b'; + char ch2 = 'c'; + short sh = 2; + const id bar = (id) opaque_id(); + id baz = 0; + __strong id strong_void_sta; + __block id byref_bab = (id)0; + __block id bl_var1; + int i; double dob; + +// The patterns here are a sequence of bytes, each saying first how +// many sizeof(void*) chunks to skip (high nibble) and then how many +// to scan (low nibble). A zero byte says that we've reached the end +// of the pattern. +// +// All of these patterns start with 01 3x because the block header on +// LP64 consists of an isa pointer (which we're supposed to scan for +// some reason) followed by three words (2 ints, a function pointer, +// and a descriptor pointer). + +// Test 1 +// byref int, short, char, char, char, id, id, strong id, byref id +// 01 35 10 00 +// CHECK-LP64: @"\01L_OBJC_CLASS_NAME_{{.*}}" = internal global [4 x i8] c"\015\10\00" + void (^b)() = ^{ + byref_int = sh + ch+ch1+ch2 ; + x(bar); + x(baz); + x((id)strong_void_sta); + x(byref_bab); + }; + b(); + +// Test 2 +// byref int, short, char, char, char, id, id, strong id, byref void*, byref id +// 01 36 10 00 +// CHECK-LP64: @"\01L_OBJC_CLASS_NAME_{{.*}}" = internal global [4 x i8] c"\016\10\00" + void (^c)() = ^{ + byref_int = sh + ch+ch1+ch2 ; + x(bar); + x(baz); + x((id)strong_void_sta); + x(wid); + bl_var1 = 0; + x(byref_bab); + }; +} diff --git a/test/CodeGenObjC/arc-bridged-cast.m b/test/CodeGenObjC/arc-bridged-cast.m new file mode 100644 index 0000000..3354bda --- /dev/null +++ b/test/CodeGenObjC/arc-bridged-cast.m @@ -0,0 +1,90 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -O2 -disable-llvm-optzns -o - %s | FileCheck %s + +typedef const void *CFTypeRef; +typedef const struct __CFString *CFStringRef; + +@interface NSString +@end + +CFTypeRef CFCreateSomething(void); +CFStringRef CFCreateString(void); +CFTypeRef CFGetSomething(void); +CFStringRef CFGetString(void); + +id CreateSomething(void); +NSString *CreateNSString(void); + +// CHECK: define void @bridge_transfer_from_cf +void bridge_transfer_from_cf(int *i) { + // CHECK: store i32 7 + *i = 7; + // CHECK: call i8* @CFCreateSomething() + id obj1 = (__bridge_transfer id)CFCreateSomething(); + // CHECK-NOT: retain + // CHECK: store i32 11 + *i = 11; + // CHECK: call i8* @CFCreateSomething() + // CHECK-NOT: retain + // CHECK: store i32 13 + (void)(__bridge_transfer id)CFCreateSomething(), *i = 13; + // CHECK: call void @objc_release + // CHECK: store i32 17 + *i = 17; + // CHECK: call void @objc_release + // CHECK-NEXT: ret void +} + +// CHECK: define void @bridge_from_cf +void bridge_from_cf(int *i) { + // CHECK: store i32 7 + *i = 7; + // CHECK: call i8* @CFCreateSomething() + id obj1 = (__bridge id)CFCreateSomething(); + // CHECK: objc_retainAutoreleasedReturnValue + // CHECK: store i32 11 + *i = 11; + // CHECK: call i8* @CFCreateSomething() + // CHECK-NOT: release + // CHECK: store i32 13 + (void)(__bridge id)CFCreateSomething(), *i = 13; + // CHECK: store i32 17 + *i = 17; + // CHECK: call void @objc_release + // CHECK-NEXT: ret void +} + +// CHECK: define void @bridge_retained_of_cf +void bridge_retained_of_cf(int *i) { + *i = 7; + // CHECK: call i8* @CreateSomething() + CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); + // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue + // CHECK: store i32 11 + *i = 11; + // CHECK: call i8* @CreateSomething() + (__bridge_retained CFTypeRef)CreateSomething(), *i = 13; + // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue + // CHECK: store i32 13 + // CHECK: store i32 17 + *i = 17; + // CHECK-NEXT: ret void +} + +// CHECK: define void @bridge_of_cf +void bridge_of_cf(int *i) { + // CHECK: store i32 7 + *i = 7; + // CHECK: call i8* @CreateSomething() + CFTypeRef cf1 = (__bridge CFTypeRef)CreateSomething(); + // CHECK-NOT: retain + // CHECK: store i32 11 + *i = 11; + // CHECK: call i8* @CreateSomething + (__bridge CFTypeRef)CreateSomething(), *i = 13; + // CHECK: store i32 13 + // CHECK-NOT: release + // CHECK: store i32 17 + *i = 17; + // CHECK-NEXT: ret void +} + diff --git a/test/CodeGenObjC/arc-compound-stmt.m b/test/CodeGenObjC/arc-compound-stmt.m new file mode 100644 index 0000000..946d72f --- /dev/null +++ b/test/CodeGenObjC/arc-compound-stmt.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fobjc-arc -o - %s +// rdar://9694706 + +typedef unsigned long NSUInteger; + +@interface NSString +- (NSString *)stringByAppendingString:(NSString *)aString; +- (NSString *)substringFromIndex:(NSUInteger)from; +@end + +@interface MyClass +- (void)inst; +@end + +@implementation MyClass + +- (void)inst; +{ + NSString *propName; + + NSString *capitalPropName = ({ + NSString *cap; + if (propName) + cap = [cap stringByAppendingString:[propName substringFromIndex:1]]; + cap; + }); +} + +@end diff --git a/test/CodeGenObjC/arc-foreach.m b/test/CodeGenObjC/arc-foreach.m new file mode 100644 index 0000000..f9d7782 --- /dev/null +++ b/test/CodeGenObjC/arc-foreach.m @@ -0,0 +1,72 @@ +// RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-weak -triple x86_64-apple-darwin -O0 -emit-llvm %s -o %t-64.s +// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s +// rdar://9503326 +// rdar://9606600 + +extern void use(id); +extern void use_block(void (^)(void)); +@class NSArray; + +void test0(NSArray *array) { + // 'x' should be initialized without a retain. + // We should actually do a non-constant capture, and that + // capture should require a retain. + for (id x in array) { + use_block(^{ use(x); }); + } +} + +// CHECK-LP64: define void @test0( +// CHECK-LP64: alloca [[ARRAY_T:%.*]]*, +// CHECK-LP64-NEXT: [[X:%.*]] = alloca i8*, +// CHECK-LP64-NEXT: [[STATE:%.*]] = alloca [[STATE_T:%.*]], +// CHECK-LP64-NEXT: alloca [16 x i8*], align 8 +// CHECK-LP64-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + +// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]]* [[STATE]], i32 0, i32 1 +// CHECK-LP64-NEXT: [[T1:%.*]] = load i8*** [[T0]] +// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr i8** [[T1]], i64 +// CHECK-LP64-NEXT: [[T3:%.*]] = load i8** [[T2]] +// CHECK-LP64-NEXT: store i8* [[T3]], i8** [[X]] + +// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-LP64-NEXT: [[T1:%.*]] = load i8** [[X]] +// CHECK-LP64-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) +// CHECK-LP64-NEXT: store i8* [[T2]], i8** [[T0]] +// CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] +// CHECK-LP64: call void @use_block( +// CHECK-LP64-NEXT: [[T1:%.*]] = load i8** [[T0]] +// CHECK-LP64-NEXT: call void @objc_release(i8* [[T1]]) + +// CHECK-LP64: define internal void @__test0_block_invoke +// CHECK-LP64: [[BLOCK:%.*]] = bitcast i8* {{%.*}} to [[BLOCK_T]]* +// CHECK-LP64-NEXT: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-LP64-NEXT: [[T2:%.*]] = load i8** [[T0]], align 8 +// CHECK-LP64-NEXT: call void @use(i8* [[T2]]) + +void test1(NSArray *array) { + for (__weak id x in array) { + use_block(^{ use(x); }); + } +} + +// CHECK-LP64: define void @test1( +// CHECK-LP64: alloca [[ARRAY_T:%.*]]*, +// CHECK-LP64-NEXT: [[X:%.*]] = alloca i8*, +// CHECK-LP64-NEXT: [[STATE:%.*]] = alloca [[STATE_T:%.*]], +// CHECK-LP64-NEXT: alloca [16 x i8*], align 8 +// CHECK-LP64-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + +// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]]* [[STATE]], i32 0, i32 1 +// CHECK-LP64-NEXT: [[T1:%.*]] = load i8*** [[T0]] +// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr i8** [[T1]], i64 +// CHECK-LP64-NEXT: [[T3:%.*]] = load i8** [[T2]] +// CHECK-LP64-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T3]]) + +// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-LP64-NEXT: [[T1:%.*]] = call i8* @objc_loadWeak(i8** [[X]]) +// CHECK-LP64-NEXT: call i8* @objc_initWeak(i8** [[T0]], i8* [[T1]]) +// CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] to +// CHECK-LP64: call void @use_block +// CHECK-LP64-NEXT: call void @objc_destroyWeak(i8** [[T0]]) +// CHECK-LP64-NEXT: call void @objc_destroyWeak(i8** [[X]]) diff --git a/test/CodeGenObjC/arc-ivar-layout.m b/test/CodeGenObjC/arc-ivar-layout.m new file mode 100644 index 0000000..cb930fe --- /dev/null +++ b/test/CodeGenObjC/arc-ivar-layout.m @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-weak -triple x86_64-apple-darwin -O0 -S %s -o %t-64.s +// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s +// rdar://8991729 + +@interface NSObject { + id isa; +} +@end + +@interface AllPointers : NSObject { + id foo; + id __strong bar; + NSObject *bletch; +} +@end + +@implementation AllPointers +@end +// CHECK-LP64: L_OBJC_CLASS_NAME_1: +// CHECK-LP64-NEXT: .asciz "\003" + +@class NSString, NSNumber; +@interface A : NSObject { + NSString *foo; + NSNumber *bar; + unsigned int bletch; + __weak id delegate; +} +@end + +@interface B : A { + unsigned int x; + NSString *y; + NSString *z; +} +@end + +@implementation A @end + +@implementation B @end + +// CHECK-LP64: L_OBJC_CLASS_NAME_15: +// CHECK-LP64-NEXT: .asciz "\022" + diff --git a/test/CodeGenObjC/arc-no-runtime.m b/test/CodeGenObjC/arc-no-runtime.m new file mode 100644 index 0000000..39f7da3 --- /dev/null +++ b/test/CodeGenObjC/arc-no-runtime.m @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fobjc-nonfragile-abi -emit-llvm %s -o - | FileCheck %s + +// rdar://problem/9224855 +void test0() { + id x = 0; + // CHECK: call void @objc_release( +} + +// CHECK: declare extern_weak void @objc_release( diff --git a/test/CodeGenObjC/arc-related-result-type.m b/test/CodeGenObjC/arc-related-result-type.m new file mode 100644 index 0000000..c51757d --- /dev/null +++ b/test/CodeGenObjC/arc-related-result-type.m @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -o - %s | FileCheck %s + +@interface Test0 +- (id) self; +@end +void test0(Test0 *val) { + Test0 *x = [val self]; + +// CHECK: define void @test0( +// CHECK: [[VAL:%.*]] = alloca [[TEST0:%.*]]* +// CHECK-NEXT: [[X:%.*]] = alloca [[TEST0]]* +// CHECK-NEXT: bitcast +// CHECK-NEXT: call i8* @objc_retain( +// CHECK-NEXT: bitcast +// CHECK-NEXT: store +// CHECK-NEXT: load [[TEST0]]** [[VAL]], +// CHECK-NEXT: load +// CHECK-NEXT: bitcast +// CHECK-NEXT: [[T0:%.*]] = call i8* bitcast ( +// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[TEST0]]* +// CHECK-NEXT: store [[TEST0]]* [[T2]], [[TEST0]]** [[X]] +// CHECK-NEXT: [[T0:%.*]] = load [[TEST0]]** [[X]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST0]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) +// CHECK-NEXT: [[T0:%.*]] = load [[TEST0]]** [[VAL]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST0]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) +// CHECK-NEXT: ret void +} diff --git a/test/CodeGenObjC/arc-unbridged-cast.m b/test/CodeGenObjC/arc-unbridged-cast.m new file mode 100644 index 0000000..0f3db09 --- /dev/null +++ b/test/CodeGenObjC/arc-unbridged-cast.m @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -emit-llvm -fobjc-nonfragile-abi -fobjc-arc -o - %s | FileCheck %s +// rdar://9744349 + +typedef const struct __CFString * CFStringRef; + +@interface I +@property CFStringRef P; +- (CFStringRef) CFMeth __attribute__((cf_returns_retained)); +- (CFStringRef) newSomething; +- (CFStringRef) P __attribute__((cf_returns_retained)); +@end + +@implementation I +@synthesize P; +- (id) Meth { + I* p1 = (id)[p1 P]; + id p2 = (id)[p1 CFMeth]; + id p3 = (id)[p1 newSomething]; + return (id) p1.P; +} +- (CFStringRef) CFMeth { return 0; } +- (CFStringRef) newSomething { return 0; } +- (CFStringRef) P { return 0; } +- (void) setP : (CFStringRef)arg {} +@end + +// rdar://9544832 +CFStringRef SomeOtherFunc() __attribute__((cf_returns_retained)); +id MMM() +{ + id obj = (id)((CFStringRef) __builtin___CFStringMakeConstantString ("" "Some CF String" "")); + if (obj) + return (id) SomeOtherFunc(); + return 0; +} + +// CHECK-NOT: call i8* @objc_retainAutoreleasedReturnValue diff --git a/test/CodeGenObjC/arc-unopt.m b/test/CodeGenObjC/arc-unopt.m new file mode 100644 index 0000000..ed46052 --- /dev/null +++ b/test/CodeGenObjC/arc-unopt.m @@ -0,0 +1,69 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fblocks -fobjc-arc -o - %s | FileCheck %s + +// A test to ensure that we generate fused calls at -O0. + +@class Test0; +Test0 *test0(void) { + extern Test0 *test0_helper; + return test0_helper; + + // CHECK: [[LD:%.*]] = load [[TEST0:%.*]]** @test0_helper + // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST0]]* [[LD]] to i8* + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleaseReturnValue(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[TEST0]]* + // CHECK-NEXT: ret [[TEST0]]* [[T2]] +} + +id test1(void) { + extern id test1_helper; + return test1_helper; + + // CHECK: [[LD:%.*]] = load i8** @test1_helper + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleaseReturnValue(i8* [[LD]]) + // CHECK-NEXT: ret i8* [[T0]] +} + +void test2(void) { + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) + // CHECK-NEXT: ret void + __weak id x; +} + +id test3(void) { + extern id test3_helper(void); + // CHECK: [[T0:%.*]] = call i8* @test3_helper() + // CHECK-NEXT: ret i8* [[T0]] + return test3_helper(); +} + +@interface Test4 { id x; } @end +@interface Test4_sub : Test4 { id y; } @end +Test4 *test4(void) { + extern Test4_sub *test4_helper(void); + // CHECK: [[T0:%.*]] = call [[TEST4S:%.*]]* @test4_helper() + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST4S]]* [[T0]] to [[TEST4:%.*]]* + // CHECK-NEXT: ret [[TEST4]]* [[T1]] + return test4_helper(); +} + +// rdar://problem/9418404 +@class Test5; +void test5(void) { + Test5 *x, *y; + if ((x = y)) + y = 0; + +// CHECK: define void @test5() +// CHECK: [[X:%.*]] = alloca [[TEST5:%.*]]*, +// CHECK-NEXT: [[Y:%.*]] = alloca [[TEST5:%.*]]*, +// CHECK-NEXT: store [[TEST5]]* null, [[TEST5]]** [[X]], +// CHECK-NEXT: store [[TEST5]]* null, [[TEST5]]** [[Y]], +// CHECK-NEXT: [[T0:%.*]] = load [[TEST5]]** [[Y]], +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST5]]** [[X]] to i8** +// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST5]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_storeStrong(i8** [[T1]], i8* [[T2]]) +// CHECK-NEXT: [[T3:%.*]] = icmp ne [[TEST5]]* [[T0]], null +// CHECK-NEXT: br i1 [[T3]], +} diff --git a/test/CodeGenObjC/arc-weak-property.m b/test/CodeGenObjC/arc-weak-property.m new file mode 100644 index 0000000..c079604 --- /dev/null +++ b/test/CodeGenObjC/arc-weak-property.m @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fblocks -fobjc-arc -o - %s | FileCheck %s +// rdar://8899430 + +@interface WeakPropertyTest { + __weak id PROP; +} +@property () __weak id PROP; +@end + +@implementation WeakPropertyTest +@synthesize PROP; +@end + +// CHECK: define internal i8* @"\01-[WeakPropertyTest PROP]" +// CHECK: [[SELF:%.*]] = alloca [[WPT:%.*]]*, +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, +// CHECK-NEXT: store [[WPT]]* {{%.*}}, [[WPT]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] +// CHECK-NEXT: [[T0:%.*]] = load [[WPT]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_WeakPropertyTest.PROP" +// CHECK-NEXT: [[T2:%.*]] = bitcast [[WPT]]* [[T0]] to i8* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] +// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** +// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_loadWeakRetained(i8** [[T4]]) +// CHECK-NEXT: [[T6:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[T5]]) +// CHECK-NEXT: ret i8* [[T6]] + +// CHECK: define internal void @"\01-[WeakPropertyTest setPROP:]" +// CHECK: [[SELF:%.*]] = alloca [[WPT:%.*]]*, +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, +// CHECK-NEXT: [[PROP:%.*]] = alloca i8*, +// CHECK-NEXT: store [[WPT]]* {{%.*}}, [[WPT]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[PROP]] +// CHECK-NEXT: [[V:%.*]] = load i8** [[PROP]] +// CHECK-NEXT: [[T0:%.*]] = load [[WPT]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_WeakPropertyTest.PROP" +// CHECK-NEXT: [[T2:%.*]] = bitcast [[WPT]]* [[T0]] to i8* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] +// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** +// CHECK-NEXT: call i8* @objc_storeWeak(i8** [[T4]], i8* [[V]]) +// CHECK-NEXT: ret void + +// CHECK: define internal void @"\01-[WeakPropertyTest .cxx_destruct]" +// CHECK: [[SELF:%.*]] = alloca [[WPT:%.*]]*, +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, +// CHECK-NEXT: store [[WPT]]* {{%.*}}, [[WPT]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] +// CHECK-NEXT: [[T0:%.*]] = load [[WPT]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_WeakPropertyTest.PROP" +// CHECK-NEXT: [[T2:%.*]] = bitcast [[WPT]]* [[T0]] to i8* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] +// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** +// CHECK-NEXT: call void @objc_destroyWeak(i8** [[T4]]) +// CHECK-NEXT: ret void diff --git a/test/CodeGenObjC/arc.m b/test/CodeGenObjC/arc.m new file mode 100644 index 0000000..407b3eb --- /dev/null +++ b/test/CodeGenObjC/arc.m @@ -0,0 +1,1554 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-optzns -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=CHECK-GLOBALS %s + +// CHECK: define void @test0 +void test0(id x) { + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{.*}}) + // CHECK-NEXT: store i8* [[PARM]], i8** [[X]] + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) + // CHECK-NEXT: ret void +} + +// CHECK: define i8* @test1(i8* +id test1(id x) { + // CHECK: [[RET:%.*]] = alloca i8* + // CHECK-NEXT: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[Y:%.*]] = alloca i8* + // CHECK-NEXT: alloca i32 + // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{%.*}}) + // CHECK-NEXT: store i8* [[PARM]], i8** [[X]] + // CHECK-NEXT: store i8* null, i8** [[Y]] + // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T1]], i8** [[RET]] + // CHECK-NEXT: store i32 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // CHECK-NEXT: [[T0:%.*]] = load i8** [[RET]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[T0]]) + // CHECK-NEXT: ret i8* [[T1]] + id y; + return y; +} + +@interface Test2 ++ (void) class_method; +- (void) inst_method; +@end +@implementation Test2 + +// The self pointer of a class method is not retained. +// CHECK: define internal void @"\01+[Test2 class_method]" +// CHECK: alloca +// CHECK-NEXT: alloca +// CHECK-NEXT: store +// CHECK-NEXT: store +// CHECK-NEXT: ret void ++ (void) class_method {} + +// The self pointer of an instance method is not retained. +// CHECK: define internal void @"\01-[Test2 inst_method]" +// CHECK: alloca +// CHECK-NEXT: alloca +// CHECK-NEXT: store +// CHECK-NEXT: store +// CHECK-NEXT: ret void +- (void) inst_method {} +@end + +@interface Test3 ++ (id) alloc; +- (id) initWith: (int) x; +- (id) copy; +@end + +// CHECK: define void @test3_unelided() +void test3_unelided() { + extern void test3_helper(void); + + // CHECK: [[X:%.*]] = alloca [[TEST3:%.*]]* + // CHECK-NEXT: store [[TEST3]]* null, [[TEST3]]** [[X]], align + Test3 *x; + + // Call to +alloc. + // CHECK-NEXT: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_ + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend + // CHECK-NEXT: bitcast + // CHECK-NEXT: bitcast + // CHECK-NEXT: call void @objc_release(i8* + [Test3 alloc]; + + // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8* + // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[T1]], + // CHECK-NEXT: call void @objc_release(i8* [[COPY]]) nounwind + [x copy]; + + // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind + // CHECK-NEXT: ret void +} + +// CHECK: define void @test3() +void test3() { + // CHECK: [[X:%.*]] = alloca i8* + + id x = [[Test3 alloc] initWith: 5]; + + // Call to +alloc. + // CHECK-NEXT: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_ + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend + // CHECK-NEXT: bitcast + + // Call to -initWith: with elided retain of consumed argument. + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8* + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[INIT:%.*]] = bitcast + // Assignment for initialization, retention elided. + // CHECK-NEXT: store i8* [[INIT]], i8** [[X]] + + // Call to -copy. + // CHECK-NEXT: [[V:%.*]] = load i8** [[X]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[V]], + + // Assignment to x. + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] + // CHECK-NEXT: store i8* [[COPY]], i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind + + x = [x copy]; + + // Cleanup for x. + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind + + // CHECK-NEXT: ret void +} + +// CHECK: define i8* @test4() +id test4() { + // Call to +alloc. + // CHECK: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_ + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend + // CHECK-NEXT: [[ALLOC:%.*]] = bitcast + + // Call to -initWith: with elided retain of consumed argument. + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: [[ALLOC:%.*]] = bitcast + // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8* [[ALLOC]], + + // Initialization of return value, occuring within full-expression. + // Retain/release elided. + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[INIT:%.*]] = bitcast + // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[INIT]]) + + // CHECK-NEXT: ret i8* [[RET]] + + return [[Test3 alloc] initWith: 6]; +} + +@interface Test5 { +@public + id var; +} +@end + +// CHECK: define void @test5 +void test5(Test5 *x, id y) { + // Prologue. + // CHECK: [[X:%.*]] = alloca [[TEST5:%.*]]*, + // CHECK-NEXT: [[Y:%.*]] = alloca i8* + // CHECK-NEXT: bitcast [[TEST5]]* {{%.*}} to i8* + // CHECK-NEXT: call i8* @objc_retain + // CHECK-NEXT: [[PARMX:%.*]] = bitcast i8* {{%.*}} to [[TEST5]]* + // CHECK-NEXT: store [[TEST5]]* [[PARMX]], [[TEST5]]** [[X]] + // CHECK-NEXT: call i8* @objc_retain + // CHECK-NEXT: store + + // CHECK-NEXT: load [[TEST5]]** [[X]] + // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var" + // CHECK-NEXT: bitcast + // CHECK-NEXT: getelementptr + // CHECK-NEXT: [[VAR:%.*]] = bitcast + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]] + // CHECK-NEXT: store i8* null, i8** [[VAR]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind + x->var = 0; + + // CHECK-NEXT: [[YVAL:%.*]] = load i8** [[Y]] + // CHECK-NEXT: load [[TEST5]]** [[X]] + // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var" + // CHECK-NEXT: bitcast + // CHECK-NEXT: getelementptr + // CHECK-NEXT: [[VAR:%.*]] = bitcast + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[YVAL]]) nounwind + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]] + // CHECK-NEXT: store i8* [[T0]], i8** [[VAR]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind + x->var = y; + + // Epilogue. + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[Y]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind + // CHECK-NEXT: [[T0:%.*]] = load [[TEST5]]** [[X]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST5]]* [[T0]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind + // CHECK-NEXT: ret void +} + +id test6_helper(void) __attribute__((ns_returns_retained)); +// CHECK: define void @test6() +void test6() { + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[CALL:%.*]] = call i8* @test6_helper() + // CHECK-NEXT: store i8* [[CALL]], i8** [[X]] + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: ret void + id x = test6_helper(); +} + +void test7_helper(id __attribute__((ns_consumed))); +// CHECK: define void @test7() +void test7() { + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) nounwind + // CHECK-NEXT: call void @test7_helper(i8* [[T1]]) + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: ret void + id x; + test7_helper(x); +} + +id test8_helper(void) __attribute__((ns_returns_retained)); +void test8() { + __unsafe_unretained id x = test8_helper(); + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[T0:%.*]] = call i8* @test8_helper() + // CHECK-NEXT: store i8* [[T0]], i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind + // CHECK-NOT: imprecise_release + // CHECK-NEXT: ret void +} + +id test9_helper(void) __attribute__((ns_returns_retained)); +void test9() { + id x __attribute__((objc_precise_lifetime)) = test9_helper(); + x = 0; + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[CALL:%.*]] = call i8* @test9_helper() + // CHECK-NEXT: store i8* [[CALL]], i8** [[X]] + + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release + + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind + // CHECK-NOT: clang.imprecise_release + + // CHECK-NEXT: ret void +} + +@interface Test10 +@property (retain) Test10 *me; +@end +void test10() { + Test10 *x; + id y = x.me.me; + + // CHECK: define void @test10() + // CHECK: [[X:%.*]] = alloca [[TEST10:%.*]]*, align + // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align + // CHECK-NEXT: store [[TEST10]]* null, [[TEST10]]** [[X]] + // CHECK-NEXT: load [[TEST10]]** [[X]], align + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}" + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) + // CHECK-NEXT: [[V:%.*]] = bitcast i8* [[T2]] to [[TEST10]]* + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}" + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) + // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST10]]* + // CHECK-NEXT: [[T4:%.*]] = bitcast [[TEST10]]* [[T3]] to i8* + // CHECK-NEXT: store i8* [[T4]], i8** [[Y]] + // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST10]]* [[V]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: [[T0:%.*]] = load [[TEST10]]** [[X]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // CHECK-NEXT: ret void +} + +void test11(id (*f)(void) __attribute__((ns_returns_retained))) { + // CHECK: define void @test11( + // CHECK: [[F:%.*]] = alloca i8* ()*, align + // CHECK-NEXT: [[X:%.*]] = alloca i8*, align + // CHECK-NEXT: store i8* ()* {{%.*}}, i8* ()** [[F]], align + // CHECK-NEXT: [[T0:%.*]] = load i8* ()** [[F]], align + // CHECK-NEXT: [[T1:%.*]] = call i8* [[T0]]() + // CHECK-NEXT: store i8* [[T1]], i8** [[X]], align + // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T3]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: ret void + id x = f(); +} + +void test12(void) { + extern id test12_helper(void); + + // CHECK: define void @test12() + // CHECK: [[X:%.*]] = alloca i8*, align + // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align + + __weak id x = test12_helper(); + // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T1]]) + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + + x = test12_helper(); + // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[X]], i8* [[T1]]) + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + + id y = x; + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_loadWeakRetained(i8** [[X]]) + // CHECK-NEXT: store i8* [[T2]], i8** [[Y]], align + + // CHECK-NEXT: [[T4:%.*]] = load i8** [[Y]] + // CHECK-NEXT: call void @objc_release(i8* [[T4]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) + // CHECK-NEXT: ret void +} + +// Indirect consuming calls. +void test13(void) { + // CHECK: define void @test13() + // CHECK: [[X:%.*]] = alloca i8*, align + // CHECK-NEXT: store i8* null, i8** [[X]], align + id x; + + typedef void fnty(id __attribute__((ns_consumed))); + extern fnty *test13_func; + // CHECK-NEXT: [[FN:%.*]] = load void (i8*)** @test13_func, align + // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align + // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) nounwind + // CHECK-NEXT: call void [[FN]](i8* [[X_TMP]]) + test13_func(x); + + extern fnty ^test13_block; + // CHECK-NEXT: [[TMP:%.*]] = load void (i8*)** @test13_block, align + // CHECK-NEXT: [[BLOCK:%.*]] = bitcast void (i8*)* [[TMP]] to [[BLOCKTY:%.*]]* + // CHECK-NEXT: [[BLOCK_FN_PTR:%.*]] = getelementptr inbounds [[BLOCKTY]]* [[BLOCK]], i32 0, i32 3 + // CHECK-NEXT: [[BLOCK_OPAQUE:%.*]] = bitcast [[BLOCKTY]]* [[BLOCK]] to i8* + // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align + // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) nounwind + // CHECK-NEXT: [[BLOCK_FN_TMP:%.*]] = load i8** [[BLOCK_FN_PTR]] + // CHECK-NEXT: [[BLOCK_FN:%.*]] = bitcast i8* [[BLOCK_FN_TMP]] to void (i8*, i8*)* + // CHECK-NEXT: call void [[BLOCK_FN]](i8* [[BLOCK_OPAQUE]], i8* [[X_TMP]]) + test13_block(x); + + // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind + // CHECK-NEXT: ret void +} + +@interface Test16_super @end +@interface Test16 : Test16_super { + id z; +} +@property (assign) int x; +@property (retain) id y; +- (void) dealloc; +@end +@implementation Test16 +@synthesize x; +@synthesize y; +- (void) dealloc { + // CHECK: define internal void @"\01-[Test16 dealloc]"( + // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align + // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align + // CHECK-NEXT: alloca + // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align + // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] + // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]] + + // Call super. + // CHECK-NEXT: [[BASE2:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* + // CHECK-NEXT: [[T0:%.*]] = getelementptr + // CHECK-NEXT: store i8* [[BASE2]], i8** [[T0]] + // CHECK-NEXT: load {{%.*}}** @"\01L_OBJC_CLASSLIST_SUP_REFS_$_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: getelementptr + // CHECK-NEXT: store + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: call void bitcast (i8* ({{.*}})* @objc_msgSendSuper2 to void ( + // CHECK-NEXT: ret void +} + +// .cxx_destruct + // CHECK: define internal void @"\01-[Test16 .cxx_destruct]"( + // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align + // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align + // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align + // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] + // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]] + + // Destroy y. + // CHECK-NEXT: [[Y_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.y" + // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* + // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Y_OFF]] + // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** + // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) nounwind + + // Destroy z. + // CHECK-NEXT: [[Z_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.z" + // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* + // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Z_OFF]] + // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** + // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) nounwind + + // CHECK-NEXT: ret void + +@end + +// This shouldn't crash. +@interface Test17A +@property (assign) int x; +@end +@interface Test17B : Test17A +@end +@implementation Test17B +- (int) x { return super.x + 1; } +@end + +// This shouldn't crash. +void test18(id (^maker)(void)) { + maker(); +} + +void test19() { + // CHECK: define void @test19() + // CHECK: [[X:%.*]] = alloca [5 x i8*], align 16 + // CHECK-NEXT: [[T0:%.*]] = bitcast [5 x i8*]* [[X]] to i8* + // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 40, i32 16, i1 false) + id x[5]; + + extern id test19_helper(void); + x[2] = test19_helper(); + + // CHECK-NEXT: [[CALL:%.*]] = call i8* @test19_helper() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) nounwind + // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i64 2 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]] + // CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind + + // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i32 0 + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 5 + // CHECK-NEXT: br label + + // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] + // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] + // CHECK-NEXT: br i1 [[EQ]], + + // CHECK: ret void +} + +void test20(unsigned n) { + // CHECK: define void @test20 + // CHECK: [[N:%.*]] = alloca i32, align 4 + // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8* + // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4 + + id x[n]; + + // Capture the VLA size. + // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64 + + // Save the stack pointer. + // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave() + // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]] + + // Allocate the VLA. + // CHECK-NEXT: [[VLA:%.*]] = alloca i8*, i64 [[DIM]], align 16 + + // Zero-initialize. + // CHECK-NEXT: [[T0:%.*]] = bitcast i8** [[VLA]] to i8* + // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[DIM]], 8 + // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 [[T1]], i32 8, i1 false) + + // Destroy. + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[VLA]], i64 [[DIM]] + // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[VLA]], [[END]] + // CHECK-NEXT: br i1 [[EMPTY]] + + // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] + // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[VLA]] + // CHECK-NEXT: br i1 [[EQ]], + + // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]] + // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]]) + // CHECK-NEXT: ret void +} + +void test21(unsigned n) { + // CHECK: define void @test21 + // CHECK: [[N:%.*]] = alloca i32, align 4 + // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8* + // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4 + + id x[2][n][3]; + + // Capture the VLA size. + // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64 + + // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave() + // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]] + + + // Allocate the VLA. + // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]] + // CHECK-NEXT: [[VLA:%.*]] = alloca [3 x i8*], i64 [[T0]], align 16 + + // Zero-initialize. + // CHECK-NEXT: [[T0:%.*]] = bitcast [3 x i8*]* [[VLA]] to i8* + // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 2, [[DIM]] + // CHECK-NEXT: [[T2:%.*]] = mul nuw i64 [[T1]], 24 + // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 [[T2]], i32 8, i1 false) + + // Destroy. + // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]] + // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [3 x i8*]* [[VLA]], i32 0, i32 0 + // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[T0]], 3 + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[T1]] + // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[BEGIN]], [[END]] + // CHECK-NEXT: br i1 [[EMPTY]] + + // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] + // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] + // CHECK-NEXT: br i1 [[EQ]], + + // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]] + // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]]) + // CHECK-NEXT: ret void +} + +void test22(_Bool cond) { + id test22_helper(void) __attribute__((ns_returns_retained)); + + // CHECK: define void @test22( + // CHECK: [[COND:%.*]] = alloca i8, + // CHECK-NEXT: [[X:%.*]] = alloca i8*, + // CHECK-NEXT: [[RELCOND:%.*]] = alloca i1 + // CHECK-NEXT: [[RELVAL:%.*]] = alloca i8* + // CHECK-NEXT: store i1 false, i1* [[RELCOND]] + // CHECK-NEXT: zext + // CHECK-NEXT: store + // CHECK-NEXT: [[T0:%.*]] = load i8* [[COND]] + // CHECK-NEXT: [[T1:%.*]] = trunc i8 [[T0]] to i1 + // CHECK-NEXT: br i1 [[T1]], + // CHECK: br label + // CHECK: [[CALL:%.*]] = call i8* @test22_helper() + // CHECK-NEXT: store i1 true, i1* [[RELCOND]] + // CHECK-NEXT: store i8* [[CALL]], i8** [[RELVAL]] + // CHECK-NEXT: br label + // CHECK: [[T0:%.*]] = phi i8* [ null, {{%.*}} ], [ [[CALL]], {{%.*}} ] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) nounwind + // CHECK-NEXT: store i8* [[T1]], i8** [[X]], + // CHECK-NEXT: [[REL:%.*]] = load i1* [[RELCOND]] + // CHECK-NEXT: br i1 [[REL]], + // CHECK: [[T0:%.*]] = load i8** [[RELVAL]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind + // CHECK-NEXT: br label + // CHECK: [[T0:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind + // CHECK-NEXT: ret void + id x = (cond ? 0 : test22_helper()); +} + +// rdar://problem/8922540 +// Note that we no longer emit .release_ivars flags. +// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test23" = internal global [[RO_T:%.*]] { i32 134, +@interface Test23 { id x; } @end +@implementation Test23 @end + +// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test24" = internal global [[RO_T:%.*]] { i32 130, +@interface Test24 {} @end +@implementation Test24 @end + +int (^test25(int x))(void) { + // CHECK: define i32 ()* @test25( + // CHECK: [[X:%.*]] = alloca i32, + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + // CHECK-NEXT: store i32 {{%.*}}, i32* [[X]] + // CHECK: [[T0:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] to i32 ()* + // CHECK-NEXT: [[T1:%.*]] = bitcast i32 ()* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainBlock(i8* [[T1]]) nounwind + // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to i32 ()* + // CHECK-NEXT: [[T4:%.*]] = bitcast i32 ()* [[T3]] to i8* + // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[T4]]) nounwind + // CHECK-NEXT: [[T6:%.*]] = bitcast i8* [[T5]] to i32 ()* + // CHECK-NEXT: ret i32 ()* [[T6]] + return ^{ return x; }; +} + +// rdar://problem/8941012 +@interface Test26 { id x[4]; } @end +@implementation Test26 @end +// CHECK: define internal void @"\01-[Test26 .cxx_destruct]"( +// CHECK: [[SELF:%.*]] = load [[TEST26:%.*]]** +// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test26.x" +// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST26]]* [[SELF]] to i8* +// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]] +// CHECK-NEXT: [[X:%.*]] = bitcast i8* [[T1]] to [4 x i8*]* +// CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [4 x i8*]* [[X]], i32 0, i32 0 +// CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 4 +// CHECK-NEXT: br label +// CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] +// CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1 +// CHECK-NEXT: call void @objc_storeStrong(i8** [[CUR]], i8* null) +// CHECK-NEXT: [[ISDONE:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] +// CHECK-NEXT: br i1 [[ISDONE]], +// CHECK: ret void + +// Check that 'init' retains self. +@interface Test27 +- (id) init; +@end +@implementation Test27 +- (id) init { return self; } +// CHECK: define internal i8* @"\01-[Test27 init]" +// CHECK: [[RET:%.*]] = alloca i8*, +// CHECK-NEXT: [[SELF:%.*]] = alloca [[TEST27:%.*]]*, +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, +// CHECK-NEXT: [[DEST:%.*]] = alloca i32 +// CHECK-NEXT: store [[TEST27]]* {{%.*}}, [[TEST27]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] +// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8* +// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) +// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] +// CHECK-NEXT: [[T2:%.*]] = bitcast +// CHECK-NEXT: store i8* [[T2]], i8** [[RET]] +// CHECK-NEXT: store i32 {{[0-9]+}}, i32* [[DEST]] +// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) +// CHECK-NEXT: [[T0:%.*]] = load i8** [[RET]] +// CHECK-NEXT: ret i8* [[T0]] + +@end + +// rdar://problem/8087194 +@interface Test28 +@property (copy) id prop; +@end +@implementation Test28 +@synthesize prop; +@end +// CHECK: define internal void @"\01-[Test28 .cxx_destruct]" +// CHECK: [[SELF:%.*]] = load [[TEST28:%.*]]** +// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test28.prop" +// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST28]]* [[SELF]] to i8* +// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]] +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** +// CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) +// CHECK-NEXT: ret void + +@interface Test29_super +- (id) initWithAllocator: (id) allocator; +@end +@interface Test29 : Test29_super +- (id) init; +- (id) initWithAllocator: (id) allocator; +@end +@implementation Test29 +static id _test29_allocator = 0; +- (id) init { +// CHECK: define internal i8* @"\01-[Test29 init]"([[TEST29:%.*]]* {{%.*}}, +// CHECK: [[RET:%.*]] = alloca i8*, align 8 +// CHECK-NEXT: [[SELF:%.*]] = alloca [[TEST29]]*, align 8 +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8 +// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32 +// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] + +// Evaluate arguments. Note that the send argument is evaluated +// before the zeroing of self. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]], align 8 +// CHECK-NEXT: [[T1:%.*]] = load i8** @_test29_allocator, align 8 + +// Implicit null of 'self', i.e. direct transfer of ownership. +// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]] + +// Actual message send. +// CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ +// CHECK-NEXT: [[T3:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* +// CHECK-NEXT: [[CALL:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T3]], i8* [[T2]], i8* [[T1]]) + +// Implicit write of result back into 'self'. This is not supposed to +// be detectable because we're supposed to ban accesses to the old +// self value past the delegate init call. +// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* +// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]] + +// Return statement. +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[CALL]] +// CHECK-NEXT: [[CALL:%.*]] = bitcast +// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[CALL]]) nounwind +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] +// CHECK-NEXT: [[T1:%.*]] = bitcast +// CHECK-NEXT: store i8* [[T1]], i8** [[RET]] +// CHECK-NEXT: store i32 1, i32* [[CLEANUP]] + +// Cleanup. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release + +// Return. +// CHECK-NEXT: [[T0:%.*]] = load i8** [[RET]] +// CHECK-NEXT: ret i8* [[T0]] + return [self initWithAllocator: _test29_allocator]; +} +- (id) initWithAllocator: (id) allocator { +// CHECK: define internal i8* @"\01-[Test29 initWithAllocator:]"( +// CHECK: [[RET:%.*]] = alloca i8*, align 8 +// CHECK-NEXT: [[SELF:%.*]] = alloca [[TEST29]]*, align 8 +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8 +// CHECK-NEXT: [[ALLOCATOR:%.*]] = alloca i8*, align 8 +// CHECK-NEXT: alloca +// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32 +// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] +// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* {{%.*}}) +// CHECK-NEXT: store i8* [[T0]], i8** [[ALLOCATOR]] + +// Evaluate arguments. Note that the send argument is evaluated +// before the zeroing of self. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = load i8** [[ALLOCATOR]], align 8 + +// Implicit null of 'self', i.e. direct transfer of ownership. +// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]] + +// Actual message send. +// CHECK: [[CALL:%.*]] = call {{.*}} @objc_msgSendSuper2 + +// Implicit write of result back into 'self'. This is not supposed to +// be detectable because we're supposed to ban accesses to the old +// self value past the delegate init call. +// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* +// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]] + +// Assignment. +// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* +// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) nounwind +// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST29]]* +// CHECK-NEXT: [[T4:%.*]] = load [[TEST29]]** [[SELF]], align +// CHECK-NEXT: store [[TEST29]]* [[T3]], [[TEST29]]** [[SELF]], align +// CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST29]]* [[T4]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T5]]) + +// Return statement. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* +// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) nounwind +// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] +// CHECK-NEXT: [[T2:%.*]] = bitcast +// CHECK-NEXT: store i8* [[T2]], i8** [[RET]] +// CHECK-NEXT: store i32 1, i32* [[CLEANUP]] + +// Cleanup. +// CHECK-NEXT: [[T0:%.*]] = load i8** [[ALLOCATOR]] +// CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release + +// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release + +// Return. +// CHECK-NEXT: [[T0:%.*]] = load i8** [[RET]] +// CHECK-NEXT: ret i8* [[T0]] + self = [super initWithAllocator: allocator]; + return self; +} +@end + +typedef struct Test30_helper Test30_helper; +@interface Test30 +- (id) init; +- (Test30_helper*) initHelper; +@end +@implementation Test30 { +char *helper; +} +- (id) init { +// CHECK: define internal i8* @"\01-[Test30 init]"([[TEST30:%.*]]* {{%.*}}, +// CHECK: [[RET:%.*]] = alloca i8* +// CHECK-NEXT: [[SELF:%.*]] = alloca [[TEST30]]* +// CHECK-NEXT: alloca i8* +// CHECK-NEXT: alloca i32 +// CHECK-NEXT: store [[TEST30]]* {{%.*}}, [[TEST30]]** [[SELF]] +// CHECK-NEXT: store + +// Call. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ +// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* +// CHECK-NEXT: [[CALL:%.*]] = call [[TEST30_HELPER:%.*]]* bitcast {{.*}} @objc_msgSend {{.*}}(i8* [[T2]], i8* [[T1]]) + +// Assignment. +// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST30_HELPER]]* [[CALL]] to i8* +// CHECK-NEXT: [[T1:%.*]] = load [[TEST30]]** [[SELF]] +// CHECK-NEXT: [[IVAR:%.*]] = load i64* @"OBJC_IVAR_$_Test30.helper" +// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T1]] to i8* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[IVAR]] +// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** +// CHECK-NEXT#: [[T5:%.*]] = load i8** [[T4]] +// CHECK-NEXT#: [[T6:%.*]] = call i8* @objc_retain(i8* [[T0]]) +// CHECK-NEXT#: call void @objc_release(i8* [[T5]]) +// CHECK-NEXT: store i8* [[T0]], i8** [[T4]] + +// Return. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* +// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) +// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] +// CHECK-NEXT: [[T2:%.*]] = bitcast +// CHECK-NEXT: store i8* [[T2]], i8** [[RET]] +// CHECK-NEXT: store i32 1 + +// Cleanup. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) + +// Epilogue. +// CHECK-NEXT: [[T0:%.*]] = load i8** [[RET]] +// CHECK-NEXT: ret i8* [[T0]] + self->helper = [self initHelper]; + return self; +} +- (Test30_helper*) initHelper { +// CHECK: define internal [[TEST30_HELPER]]* @"\01-[Test30 initHelper]"( +// CHECK: alloca +// CHECK-NEXT: alloca +// CHECK-NEXT: store +// CHECK-NEXT: store +// CHECK-NEXT: ret [[TEST30_HELPER]]* null + return 0; +} + +@end + +void test31(id x) { +// CHECK: define void @test31( +// CHECK: [[X:%.*]] = alloca i8*, +// CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], +// CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{%.*}}) +// CHECK-NEXT: store i8* [[PARM]], i8** [[X]] +// CHECK: [[SLOT:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-NEXT: [[T0:%.*]] = load i8** [[X]], +// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) +// CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]], +// CHECK-NEXT: bitcast +// CHECK-NEXT: call void @test31_helper( +// CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]] +// CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release +// CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] +// CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release +// CHECK-NEXT: ret void + extern void test31_helper(id (^)(void)); + test31_helper(^{ return x; }); +} + +__attribute__((ns_returns_retained)) id test32(void) { +// CHECK: define i8* @test32() +// CHECK: [[CALL:%.*]] = call i8* @test32_helper() +// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) +// CHECK-NEXT: ret i8* [[T0]] + extern id test32_helper(void); + return test32_helper(); +} + +@class Test33_a; +@interface Test33 +- (void) give: (Test33_a **) x; +- (void) take: (Test33_a **) x; +- (void) giveStrong: (out __strong Test33_a **) x; +- (void) takeStrong: (inout __strong Test33_a **) x; +- (void) giveOut: (out Test33_a **) x; +@end +void test33(Test33 *ptr) { + Test33_a *a; + [ptr give: &a]; + [ptr take: &a]; + [ptr giveStrong: &a]; + [ptr takeStrong: &a]; + [ptr giveOut: &a]; + + // CHECK: define void @test33([[TEST33:%.*]]* + // CHECK: [[PTR:%.*]] = alloca [[TEST33]]* + // CHECK-NEXT: [[A:%.*]] = alloca [[A_T:%.*]]* + // CHECK-NEXT: [[TEMP0:%.*]] = alloca [[A_T]]* + // CHECK-NEXT: [[TEMP1:%.*]] = alloca [[A_T]]* + // CHECK-NEXT: [[TEMP2:%.*]] = alloca [[A_T]]* + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_retain + // CHECK-NEXT: bitcast + // CHECK-NEXT: store + // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[A]] + + // CHECK-NEXT: load [[TEST33]]** [[PTR]] + // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[A]] + // CHECK-NEXT: store [[A_T]]* [[T0]], [[A_T]]** [[TEMP0]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP0]]) + // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP0]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) + // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* + // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] + // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] + // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T5]]) + + // CHECK-NEXT: load [[TEST33]]** [[PTR]] + // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[A]] + // CHECK-NEXT: store [[A_T]]* [[T0]], [[A_T]]** [[TEMP1]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP1]]) + // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP1]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) + // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* + // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] + // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] + // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T5]]) + + // CHECK-NEXT: load [[TEST33]]** [[PTR]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]]) + + // CHECK-NEXT: load [[TEST33]]** [[PTR]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]]) + + // 'out' + // CHECK-NEXT: load [[TEST33]]** [[PTR]] + // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[TEMP2]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP2]]) + // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP2]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) + // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* + // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] + // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] + // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T5]]) + + // CHECK-NEXT: load + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_release + // CHECK-NEXT: load + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_release + // CHECK-NEXT: ret void +} + +void test34(int cond) { + __strong id strong; + __weak id weak; + extern void test34_sink(id *); + test34_sink(cond ? &strong : 0); + test34_sink(cond ? &weak : 0); + + // CHECK: define void @test34( + // CHECK: [[COND:%.*]] = alloca i32 + // CHECK-NEXT: [[STRONG:%.*]] = alloca i8* + // CHECK-NEXT: [[WEAK:%.*]] = alloca i8* + // CHECK-NEXT: [[TEMP1:%.*]] = alloca i8* + // CHECK-NEXT: [[TEMP2:%.*]] = alloca i8* + // CHECK-NEXT: store i32 + // CHECK-NEXT: store i8* null, i8** [[STRONG]] + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[WEAK]], i8* null) + + // CHECK-NEXT: [[T0:%.*]] = load i32* [[COND]] + // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0 + // CHECK: [[ARG:%.*]] = phi i8** + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i8** null, i8** [[TEMP1]] + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = load i8** [[ARG]] + // CHECK-NEXT: store i8* [[T0]], i8** [[TEMP1]] + // CHECK-NEXT: br label + // CHECK: call void @test34_sink(i8** [[T1]]) + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = load i8** [[TEMP1]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8** [[ARG]] + // CHECK-NEXT: store i8* [[T1]], i8** [[ARG]] + // CHECK-NEXT: call void @objc_release(i8* [[T2]]) + // CHECK-NEXT: br label + + // CHECK: [[T0:%.*]] = load i32* [[COND]] + // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0 + // CHECK: [[ARG:%.*]] = phi i8** + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i8** null, i8** [[TEMP2]] + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = call i8* @objc_loadWeak(i8** [[ARG]]) + // CHECK-NEXT: store i8* [[T0]], i8** [[TEMP2]] + // CHECK-NEXT: br label + // CHECK: call void @test34_sink(i8** [[T1]]) + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = load i8** [[TEMP2]] + // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[ARG]], i8* [[T0]]) + // CHECK-NEXT: br label + + // CHECK: call void @objc_destroyWeak(i8** [[WEAK]]) + // CHECK: ret void +} + +void test35(void (^sink)(id*)) { + __strong id strong; + sink(&strong); + + // CHECK: define void @test35( + // CHECK: [[SINK:%.*]] = alloca void (i8**)* + // CHECK-NEXT: [[STRONG:%.*]] = alloca i8* + // CHECK-NEXT: [[TEMP:%.*]] = alloca i8* + // CHECK-NEXT: bitcast void (i8**)* {{%.*}} to i8* + // CHECK-NEXT: call i8* @objc_retain( + // CHECK-NEXT: bitcast i8* + // CHECK-NEXT: store void (i8**)* {{%.*}}, void (i8**)** [[SINK]] + // CHECK-NEXT: store i8* null, i8** [[STRONG]] + + // CHECK-NEXT: load void (i8**)** [[SINK]] + // CHECK-NEXT: bitcast + // CHECK-NEXT: getelementptr + // CHECK-NEXT: [[BLOCK:%.*]] = bitcast + // CHECK-NEXT: [[T0:%.*]] = load i8** [[STRONG]] + // CHECK-NEXT: store i8* [[T0]], i8** [[TEMP1]] + // CHECK-NEXT: [[F0:%.*]] = load i8** + // CHECK-NEXT: [[F1:%.*]] = bitcast i8* [[F0]] to void (i8*, i8**)* + // CHECK-NEXT: call void [[F1]](i8* [[BLOCK]], i8** [[TEMP1]]) + // CHECK-NEXT: [[T0:%.*]] = load i8** [[TEMP1]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8** [[STRONG]] + // CHECK-NEXT: store i8* [[T1]], i8** [[STRONG]] + // CHECK-NEXT: call void @objc_release(i8* [[T2]]) + + // CHECK-NEXT: [[T0:%.*]] = load i8** [[STRONG]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + + // CHECK-NEXT: load void (i8**)** [[SINK]] + // CHECK-NEXT: bitcast + // CHECK-NEXT: call void @objc_release + // CHECK-NEXT: ret void + +} + +// CHECK: define void @test36 +void test36(id x) { + // CHECK: [[X:%.*]] = alloca i8* + + // CHECK: call i8* @objc_retain + // CHECK: call i8* @objc_retain + // CHECK: call i8* @objc_retain + id array[3] = { @"A", x, @"y" }; + + // CHECK: [[T0:%.*]] = load i8** [[X]] + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + x = 0; + + // CHECK: br label + // CHECK: call void @objc_release + // CHECK: br i1 + + // CHECK: call void @objc_release + // CHECK-NEXT: ret void +} + +@class Test37; +void test37(void) { + extern void test37_helper(id *); + Test37 *var; + test37_helper(&var); + + // CHECK: define void @test37() + // CHECK: [[VAR:%.*]] = alloca [[TEST37:%.*]]*, + // CHECK-NEXT: [[TEMP:%.*]] = alloca i8* + // CHECK-NEXT: store [[TEST37]]* null, [[TEST37]]** [[VAR]] + + // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8* + // CHECK-NEXT: store i8* [[T1]], i8** [[TEMP]] + // CHECK-NEXT: call void @test37_helper(i8** [[TEMP]]) + // CHECK-NEXT: [[T0:%.*]] = load i8** [[TEMP]] + // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST37]]* + // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST37]]* [[T1]] to i8* + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) + // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[TEST37]]* + // CHECK-NEXT: [[T5:%.*]] = load [[TEST37]]** [[VAR]] + // CHECK-NEXT: store [[TEST37]]* [[T4]], [[TEST37]]** [[VAR]] + // CHECK-NEXT: [[T6:%.*]] = bitcast [[TEST37]]* [[T5]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T6]]) + + // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // CHECK-NEXT: ret void +} + +void test38(void) { + id test38_source(void); + void test38_helper(void (^)(void)); + __block id var = test38_source(); + test38_helper(^{ var = 0; }); + + // CHECK: define void @test38() + // CHECK: [[VAR:%.*]] = alloca [[BYREF_T:%.*]], + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 2 + // 0x02000000 - has copy/dispose helpers + // CHECK-NEXT: store i32 33554432, i32* [[T0]] + // CHECK: [[SLOT:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 6 + // CHECK-NEXT: [[T0:%.*]] = call i8* @test38_source() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]] + // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 6 + // 0x42000000 - has signature, copy/dispose helpers + // CHECK: store i32 1107296256, + // CHECK: [[T0:%.*]] = bitcast [[BYREF_T]]* [[VAR]] to i8* + // CHECK-NEXT: store i8* [[T0]], i8** + // CHECK: call void @test38_helper( + // CHECK: [[T0:%.*]] = bitcast [[BYREF_T]]* [[VAR]] to i8* + // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T0]], i32 8) + // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__Block_byref_object_copy_ + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: load i8** + // CHECK-NEXT: bitcast i8* {{%.*}} to [[BYREF_T]]* + // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: [[T2:%.*]] = load i8** [[T1]] + // CHECK-NEXT: store i8* [[T2]], i8** [[T0]] + // CHECK-NEXT: store i8* null, i8** [[T1]] + + // CHECK: define internal void @__Block_byref_object_dispose_ + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: [[T1:%.*]] = load i8** [[T0]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + + // CHECK: define internal void @__test38_block_invoke_ + // CHECK: [[SLOT:%.*]] = getelementptr inbounds {{.*}}, i32 0, i32 6 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]], align 8 + // CHECK-NEXT: store i8* null, i8** [[SLOT]], + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__copy_helper_block_ + // CHECK: call void @_Block_object_assign(i8* {{%.*}}, i8* {{%.*}}, i32 8) + + // CHECK: define internal void @__destroy_helper_block_ + // CHECK: call void @_Block_object_dispose(i8* {{%.*}}, i32 8) +} + +void test39(void) { + extern id test39_source(void); + void test39_helper(void (^)(void)); + __unsafe_unretained id var = test39_source(); + test39_helper(^{ (void) var; }); + + // CHECK: define void @test39() + // CHECK: [[VAR:%.*]] = alloca i8* + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + // CHECK: [[T0:%.*]] = call i8* @test39_source() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T1]], i8** [[VAR]], + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // 0x40000000 - has signature but no copy/dispose + // CHECK: store i32 1073741824, i32* + // CHECK: [[CAPTURE:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[VAR]] + // CHECK-NEXT: store i8* [[T0]], i8** [[CAPTURE]] + // CHECK-NEXT: [[T0:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] to + // CHECK: call void @test39_helper + // CHECK-NEXT: ret void +} + +void test40(void) { + id test40_source(void); + void test40_helper(void (^)(void)); + __block __weak id var = test40_source(); + test40_helper(^{ var = 0; }); + + // CHECK: define void @test40() + // CHECK: [[VAR:%.*]] = alloca [[BYREF_T:%.*]], + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 2 + // 0x02000000 - has copy/dispose helpers + // CHECK-NEXT: store i32 33554432, i32* [[T0]] + // CHECK: [[SLOT:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 6 + // CHECK-NEXT: [[T0:%.*]] = call i8* @test40_source() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[SLOT]], i8* [[T1]]) + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 6 + // 0x42000000 - has signature, copy/dispose helpers + // CHECK: store i32 1107296256, + // CHECK: [[T0:%.*]] = bitcast [[BYREF_T]]* [[VAR]] to i8* + // CHECK-NEXT: store i8* [[T0]], i8** + // CHECK: call void @test40_helper( + // CHECK: [[T0:%.*]] = bitcast [[BYREF_T]]* [[VAR]] to i8* + // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T0]], i32 8) + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[SLOT]]) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__Block_byref_object_copy_ + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: load i8** + // CHECK-NEXT: bitcast i8* {{%.*}} to [[BYREF_T]]* + // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: call void @objc_moveWeak(i8** [[T0]], i8** [[T1]]) + + // CHECK: define internal void @__Block_byref_object_dispose_ + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[T0]]) + + // CHECK: define internal void @__test40_block_invoke_ + // CHECK: [[SLOT:%.*]] = getelementptr inbounds {{.*}}, i32 0, i32 6 + // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[SLOT]], i8* null) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__copy_helper_block_ + // 0x8 - FIELD_IS_BYREF (no FIELD_IS_WEAK because clang in control) + // CHECK: call void @_Block_object_assign(i8* {{%.*}}, i8* {{%.*}}, i32 8) + + // CHECK: define internal void @__destroy_helper_block_ + // 0x8 - FIELD_IS_BYREF (no FIELD_IS_WEAK because clang in control) + // CHECK: call void @_Block_object_dispose(i8* {{%.*}}, i32 8) +} + +void test41(void) { + id test41_source(void); + void test41_helper(void (^)(void)); + void test41_consume(id); + __weak id var = test41_source(); + test41_helper(^{ test41_consume(var); }); + + // CHECK: define void @test41() + // CHECK: [[VAR:%.*]] = alloca i8*, + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + // CHECK: [[T0:%.*]] = call i8* @test41_source() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[VAR]], i8* [[T1]]) + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // 0x42000000 - has signature, copy/dispose helpers + // CHECK: store i32 1107296256, + // CHECK: [[SLOT:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_loadWeak(i8** [[VAR]]) + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[SLOT]], i8* [[T0]]) + // CHECK: call void @test41_helper( + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[SLOT]]) + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[VAR]]) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__test41_block_invoke_ + // CHECK: [[SLOT:%.*]] = getelementptr inbounds [[BLOCK_T]]* {{%.*}}, i32 0, i32 5 + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_loadWeak(i8** [[SLOT]]) + // CHECK-NEXT: call void @test41_consume(i8* [[T0]]) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__copy_helper_block_ + // CHECK: getelementptr + // CHECK-NEXT: getelementptr + // CHECK-NEXT: call void @objc_copyWeak( + + // CHECK: define internal void @__destroy_helper_block_ + // CHECK: getelementptr + // CHECK-NEXT: call void @objc_destroyWeak( +} + +@interface Test42 @end +@implementation Test42 +- (void) test { +// CHECK: define internal void @"\01-[Test42 test]" +// CHECK: [[SELF:%.*]] = alloca [[TEST42:%.*]]*, +// CHECK-NEXT: alloca i8* +// CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], +// CHECK: store +// CHECK-NEXT: store +// CHECK: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-NEXT: [[T1:%.*]] = load [[TEST42]]** [[SELF]], +// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST42]]* [[T1]] to i8* +// CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) +// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[TEST42]]* +// CHECK-NEXT: store [[TEST42]]* [[T4]], [[TEST42]]** [[T0]] +// CHECK-NEXT: bitcast [[BLOCK_T]]* [[BLOCK]] to +// CHECK: call void @test42_helper( +// CHECK-NEXT: [[T1:%.*]] = load [[TEST42]]** [[T0]] +// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST42]]* [[T1]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T2]]) +// CHECK-NEXT: ret void + + extern void test42_helper(void (^)(void)); + test42_helper(^{ (void) self; }); +} +@end + +@interface Test43 @end +@implementation Test43 +- (id) test __attribute__((ns_returns_retained)) { + extern id test43_produce(void); + return test43_produce(); + // CHECK: call i8* @test43_produce() + // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue( + // CHECK-NEXT: ret +} +@end + +id test44(void) { + typedef id __attribute__((ns_returns_retained)) blocktype(void); + extern test44_consume_block(blocktype^); + return ^blocktype { + extern id test44_produce(void); + return test44_produce(); + }(); + +// CHECK: define i8* @test44( +// CHECK: load i8** getelementptr +// CHECK-NEXT: bitcast i8* +// CHECK-NEXT: call i8* +// CHECK-NEXT: call i8* @objc_autoreleaseReturnValue +// CHECK-NEXT: ret i8* + +// CHECK: call i8* @test44_produce() +// CHECK-NEXT: call i8* @objc_retain +// CHECK-NEXT: ret i8* +} + +@interface Test45 +@property (retain) id x; +@end +@implementation Test45 +@synthesize x; +@end +// CHECK: define internal i8* @"\01-[Test45 x]"( +// CHECK: [[CALL:%.*]] = call i8* @objc_getProperty( +// CHECK-NEXT: ret i8* [[CALL]] + +// rdar://problem/9315552 +void test46(__weak id *wp, __weak volatile id *wvp) { + extern id test46_helper(void); + + // TODO: this is sub-optimal, we should retain at the actual call site. + + // CHECK: [[T0:%.*]] = call i8* @test46_helper() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8 + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]]) + // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]]) + // CHECK-NEXT: store i8* [[T4]], i8** + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + id x = *wp = test46_helper(); + + // CHECK: [[T0:%.*]] = call i8* @test46_helper() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8 + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]]) + // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]]) + // CHECK-NEXT: store i8* [[T4]], i8** + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + id y = *wvp = test46_helper(); +} + +// rdar://problem/9378887 +void test47(void) { + extern id test47_helper(void); + id x = x = test47_helper(); + + // CHECK: define void @test47() + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: [[CALL:%.*]] = call i8* @test47_helper() + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: store i8* [[T0]], i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]] + // CHECK-NEXT: store i8* [[T2]], i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T3]]) + // CHECK-NEXT: [[T4:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T4]]) + // CHECK-NEXT: ret void +} + +void test48(void) { + extern id test48_helper(void); + __weak id x = x = test48_helper(); + // CHECK: define void @test48() + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_initWeak(i8** [[X]], i8* null) + // CHECK-NEXT: [[T1:%.*]] = call i8* @test48_helper() + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T2]]) + // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T3]]) + // CHECK-NEXT: call void @objc_release(i8* [[T2]]) + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) + // CHECK-NEXT: ret void +} + +void test49(void) { + extern id test49_helper(void); + __autoreleasing id x = x = test49_helper(); + // CHECK: define void @test49() + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: [[CALL:%.*]] = call i8* @test49_helper() + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_autorelease(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T2]], i8** [[X]] + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]]) + // CHECK-NEXT: store i8* [[T3]], i8** [[X]] + // CHECK-NEXT: ret void +} + +// rdar://9380136 +id x(); +void test50(id y) { + ({x();}); +// CHECK: [[T0:%.*]] = call i8* @objc_retain +// CHECK: call void @objc_release +} + + +// rdar://9400762 +struct CGPoint { + float x; + float y; +}; +typedef struct CGPoint CGPoint; + +@interface Foo +@property (assign) CGPoint point; +@end + +@implementation Foo +@synthesize point; +@end + +// rdar://problem/9400398 +id test52(void) { + id test52_helper(int) __attribute__((ns_returns_retained)); + return ({ int x = 5; test52_helper(x); }); + +// CHECK: define i8* @test52() +// CHECK: [[X:%.*]] = alloca i32 +// CHECK-NEXT: store i32 5, i32* [[X]], +// CHECK-NEXT: [[T0:%.*]] = load i32* [[X]], +// CHECK-NEXT: [[T1:%.*]] = call i8* @test52_helper(i32 [[T0]]) +// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[T1]]) +// CHECK-NEXT: ret i8* [[T2]] +} + +// rdar://problem/9400644 +void test53(void) { + id test53_helper(void); + id x = ({ id y = test53_helper(); y; }); + (void) x; +// CHECK: define void @test53() +// CHECK: [[X:%.*]] = alloca i8*, +// CHECK-NEXT: [[Y:%.*]] = alloca i8*, +// CHECK-NEXT: [[T0:%.*]] = call i8* @test53_helper() +// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) +// CHECK-NEXT: store i8* [[T1]], i8** [[Y]], +// CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]], +// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) +// CHECK-NEXT: [[T2:%.*]] = load i8** [[Y]] +// CHECK-NEXT: call void @objc_release(i8* [[T2]]) +// CHECK-NEXT: store i8* [[T1]], i8** [[X]], +// CHECK-NEXT: load i8** [[X]], +// CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] +// CHECK-NEXT: call void @objc_release(i8* [[T0]]) +// CHECK-NEXT: ret void +} + +// <rdar://problem/9758798> +// CHECK: define void @test54(i32 %first, ...) +void test54(int first, ...) { + __builtin_va_list arglist; + // CHECK: call void @llvm.va_start + __builtin_va_start(arglist, first); + // CHECK: call i8* @objc_retain + id obj = __builtin_va_arg(arglist, id); + // CHECK: call void @llvm.va_end + __builtin_va_end(arglist); + // CHECK: call void @objc_release + // CHECK: ret void +} + +// PR10228 +@interface Test55Base @end +@interface Test55 : Test55Base @end +@implementation Test55 (Category) +- (void) dealloc {} +@end +// CHECK: define internal void @"\01-[Test55(Category) dealloc]"( +// CHECK-NOT: ret +// CHECK: call void bitcast (i8* ({{%.*}}*, i8*, ...)* @objc_msgSendSuper2 to void ({{%.*}}*, i8*)*)( diff --git a/test/CodeGenObjC/autorelease.m b/test/CodeGenObjC/autorelease.m new file mode 100644 index 0000000..7bf40f1 --- /dev/null +++ b/test/CodeGenObjC/autorelease.m @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-arc -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -emit-llvm -fobjc-nonfragile-abi -fobjc-runtime-has-arc -o - %s | FileCheck %s +// rdar://8881826 +// rdar://9412038 + +@interface I +{ + id ivar; +} +- (id) Meth; ++ (id) MyAlloc;; +@end + +@implementation I +- (id) Meth { + @autoreleasepool { + id p = [I MyAlloc]; + if (!p) + return ivar; + } + return 0; +} ++ (id) MyAlloc { + return 0; +} +@end + +// CHECK: call i8* @objc_autoreleasePoolPush +// CHECK: [[T:%.*]] = load i8** [[A:%.*]] +// CHECK: call void @objc_autoreleasePoolPop diff --git a/test/CodeGenObjC/block-6.m b/test/CodeGenObjC/block-6.m index 3720a87..44c7a78 100644 --- a/test/CodeGenObjC/block-6.m +++ b/test/CodeGenObjC/block-6.m @@ -2,10 +2,16 @@ // rdar://8893785 void MYFUNC() { -// CHECK: [[T1:%.*]] = bitcast i8* ()* -// CHECK-NEXT: [[FORWARDING:%.*]] = getelementptr inbounds [[N_T:%.*]]* [[N:%.*]], i32 0, i32 1 -// CHECK-NEXT: [[T0:%.*]] = load [[N_T]]** [[FORWARDING]] -// CHECK-NEXT: [[OBSERVER:%.*]] = getelementptr inbounds [[N_T]]* [[T0]], i32 0, i32 6 +// CHECK: define void @MYFUNC() +// CHECK: [[OBSERVER_SLOT:%.*]] = alloca [[OBSERVER_T:%.*]], align 8 + +// CHECK: [[T0:%.*]] = getelementptr inbounds [[OBSERVER_T]]* [[OBSERVER_SLOT]], i32 0, i32 1 +// CHECK: store [[OBSERVER_T]]* [[OBSERVER_SLOT]], [[OBSERVER_T]]** [[T0]] + +// CHECK: [[T1:%.*]] = bitcast i8* ()* +// CHECK: [[FORWARDING:%.*]] = getelementptr inbounds [[OBSERVER_T]]* [[OBSERVER_SLOT]], i32 0, i32 1 +// CHECK-NEXT: [[T0:%.*]] = load [[OBSERVER_T]]** [[FORWARDING]] +// CHECK-NEXT: [[OBSERVER:%.*]] = getelementptr inbounds [[OBSERVER_T]]* [[T0]], i32 0, i32 6 // CHECK-NEXT: store i8* [[T1]], i8** [[OBSERVER]] __block id observer = ^{ return observer; }; } diff --git a/test/CodeGenObjC/blocks.m b/test/CodeGenObjC/blocks.m index 151c162..47d47cc 100644 --- a/test/CodeGenObjC/blocks.m +++ b/test/CodeGenObjC/blocks.m @@ -46,7 +46,7 @@ void test2(Test2 *x) { // CHECK: define void @test2( // CHECK: [[X:%.*]] = alloca [[TEST2:%.*]]*, // CHECK-NEXT: [[WEAKX:%.*]] = alloca [[WEAK_T:%.*]], - // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:%.*]], + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], // CHECK-NEXT: store [[TEST2]]* // isa=1 for weak byrefs. @@ -95,8 +95,8 @@ void test2(Test2 *x) { // CHECK: [[BLOCK:%.*]] = bitcast i8* {{%.*}} to [[BLOCK_T]]* // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 // CHECK-NEXT: [[T1:%.*]] = load i8** [[T0]] -// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[WEAK_T]]* -// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds [[WEAK_T]]* [[T2]], i32 0, i32 1 -// CHECK-NEXT: [[T4:%.*]] = load [[WEAK_T]]** [[T3]] -// CHECK-NEXT: [[WEAKX:%.*]] = getelementptr inbounds [[WEAK_T]]* [[T4]], i32 0, i32 6 +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[WEAK_T]]{{.*}}* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds [[WEAK_T]]{{.*}}* [[T2]], i32 0, i32 1 +// CHECK-NEXT: [[T4:%.*]] = load [[WEAK_T]]{{.*}}** [[T3]] +// CHECK-NEXT: [[WEAKX:%.*]] = getelementptr inbounds [[WEAK_T]]{{.*}}* [[T4]], i32 0, i32 6 // CHECK-NEXT: [[T0:%.*]] = load [[TEST2]]** [[WEAKX]], align 4 diff --git a/test/CodeGenObjC/debug-info-foreach.m b/test/CodeGenObjC/debug-info-foreach.m deleted file mode 100644 index 89b409c..0000000 --- a/test/CodeGenObjC/debug-info-foreach.m +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fobjc-default-synthesize-properties -emit-llvm -g %s -o %t -// RUN: grep DW_TAG_lexical_block %t | count 5 -// rdar://8757124 - -@class NSArray; - -int i; -void f(NSArray *a) { - id keys; - for (id thisKey in keys) { - int j = i; - ++j; - i = j; - } - for (id thisKey in keys) { - int k = i; - ++k; - i = k; - } -} diff --git a/test/CodeGenObjC/encode-test.m b/test/CodeGenObjC/encode-test.m index ade0c61..f30fb26 100644 --- a/test/CodeGenObjC/encode-test.m +++ b/test/CodeGenObjC/encode-test.m @@ -161,3 +161,7 @@ struct f // CHECK: @g10 = constant [14 x i8] c"{f=i[0{?=}]i}\00" const char g10[] = @encode(struct f); + +// rdar://9622422 +// CHECK: @g11 = constant [2 x i8] c"v\00" +const char g11[] = @encode(void); diff --git a/test/CodeGenObjC/exceptions-nonfragile.m b/test/CodeGenObjC/exceptions-nonfragile.m index 280b5d4..2557aab 100644 --- a/test/CodeGenObjC/exceptions-nonfragile.m +++ b/test/CodeGenObjC/exceptions-nonfragile.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fexceptions -fobjc-exceptions -O2 -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fexceptions -fobjc-exceptions -o - %s | FileCheck %s // rdar://problem/8535238 // CHECK: declare void @objc_exception_rethrow() @@ -15,3 +15,17 @@ void protos() { void throwing() { @throw(@"error!"); } + +// rdar://problem/9431547 +void die(void) __attribute__((nothrow, noreturn)); +void test2(void) { + @try { + die(); + } @finally { + extern void test2_helper(void); + test2_helper(); + } + + // CHECK: define void @test2() + // CHECK-NOT: call void @test2_helper() +} diff --git a/test/CodeGenObjC/gc.m b/test/CodeGenObjC/gc.m new file mode 100644 index 0000000..93554e6 --- /dev/null +++ b/test/CodeGenObjC/gc.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-gc -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck %s + +void test0(void) { + extern id test0_helper(void); + __attribute__((objc_precise_lifetime)) id x = test0_helper(); + test0_helper(); + // CHECK: define void @test0() + // CHECK: [[T0:%.*]] = call i8* @test0_helper() + // CHECK-NEXT: store i8* [[T0]], i8** [[X:%.*]], align 8 + // CHECK-NEXT: call i8* @test0_helper() + // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]], align 8 + // CHECK-NEXT: call void asm sideeffect "", "r"(i8* [[T0]]) nounwind + // CHECK-NEXT: ret void +} diff --git a/test/CodeGenObjC/mrr-autorelease.m b/test/CodeGenObjC/mrr-autorelease.m new file mode 100644 index 0000000..10f549f --- /dev/null +++ b/test/CodeGenObjC/mrr-autorelease.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -emit-llvm -o - %s | FileCheck %s +// rdar://8881826 +// rdar://9423507 + +@interface I +{ + id ivar; +} +- (id) Meth; +@end + +@implementation I +- (id) Meth { + @autoreleasepool { + } + return 0; +} +@end + +// CHECK-NOT: call i8* @objc_getClass +// CHECK: call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend +// CHECK: call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend +// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend diff --git a/test/CodeGenObjC/nonlazy-msgSend.m b/test/CodeGenObjC/nonlazy-msgSend.m new file mode 100644 index 0000000..3d7ba10 --- /dev/null +++ b/test/CodeGenObjC/nonlazy-msgSend.m @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-llvm -o %t %s +// RUN: grep -F 'declare i8* @objc_msgSend(i8*, i8*, ...) nonlazybind' %t + +void f0(id x) { + [x foo]; +} diff --git a/test/CodeGenObjC/property-list-in-class.m b/test/CodeGenObjC/property-list-in-class.m index a5d0dc8..0521058 100644 --- a/test/CodeGenObjC/property-list-in-class.m +++ b/test/CodeGenObjC/property-list-in-class.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -emit-llvm -o %t %s -// RUN: grep -F 'l_OBJC_$_PROP_LIST_C2" = internal global %8 { i32 16, i32 3' %t +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -emit-llvm %s -o - | FileCheck %s +// CHECK: l_OBJC_$_PROP_LIST_C2" = internal global { i32, i32, [3 x %struct._prop_t] } { i32 16, i32 3 @protocol P @property int i; diff --git a/test/CodeGenObjC/related-result-type.m b/test/CodeGenObjC/related-result-type.m new file mode 100644 index 0000000..ef38661 --- /dev/null +++ b/test/CodeGenObjC/related-result-type.m @@ -0,0 +1,54 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +@interface NSObject ++ (id)alloc; +- (id)init; +- (id)retain; +@end + +@interface NSString : NSObject +@end + +// CHECK: define void @test1() +void test1() { + // CHECK: {{call.*@objc_msgSend}} + // CHECK: {{call.*@objc_msgSend}} + // CHECK: {{call.*@objc_msgSend}} + // CHECK: bitcast i8* + NSString *str1 = [[[NSString alloc] init] retain]; +} + +// CHECK: define void @test2() +void test2() { + // CHECK: {{call.*@objc_msgSend}} + // CHECK: {{call.*@objc_msgSend}} + // CHECK: {{call.*@objc_msgSend}} + // CHECK: bitcast i8* + NSString *str1 = NSString.alloc.init.retain; +} + +@interface Test2 : NSString +- (id)init; +@end + +@implementation Test2 +// CHECK: define internal i8* @"\01-[Test2 init]" +- (id)init { + // CHECK: {{call.*@objc_msgSendSuper}} + // CHECK-NEXT: bitcast i8* + return [super init]; +} +@end + +@interface Test3 : NSString +- (id)init; +@end + +@implementation Test3 +// CHECK: define internal i8* @"\01-[Test3 init]" +- (id)init { + // CHECK: {{call.*@objc_msgSendSuper}} + // CHECK-NEXT: bitcast i8* + return [super init]; +} +@end diff --git a/test/CodeGenObjC/terminate.m b/test/CodeGenObjC/terminate.m new file mode 100644 index 0000000..f04eb6a --- /dev/null +++ b/test/CodeGenObjC/terminate.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fexceptions -fobjc-exceptions -fobjc-runtime-has-terminate -o - %s | FileCheck %s -check-prefix=CHECK-WITH +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fexceptions -fobjc-exceptions -o - %s | FileCheck %s -check-prefix=CHECK-WITHOUT + +void destroy(void**); + +// rdar://problem/9519113 +void test0(void) { + void test0_helper(void); + void *ptr __attribute__((cleanup(destroy))); + test0_helper(); + + // CHECK-WITH: define void @test0() + // CHECK-WITH: [[PTR:%.*]] = alloca i8*, + // CHECK-WITH: call void @destroy(i8** [[PTR]]) + // CHECK-WITH-NEXT: ret void + // CHECK-WITH: invoke void @destroy(i8** [[PTR]]) + // CHECK-WITH: call i8* @llvm.eh.exception() + // CHECK-WITH-NEXT: @llvm.eh.selector + // CHECK-WITH-NEXT: call void @objc_terminate() + + // CHECK-WITHOUT: define void @test0() + // CHECK-WITHOUT: [[PTR:%.*]] = alloca i8*, + // CHECK-WITHOUT: call void @destroy(i8** [[PTR]]) + // CHECK-WITHOUT-NEXT: ret void + // CHECK-WITHOUT: invoke void @destroy(i8** [[PTR]]) + // CHECK-WITHOUT: call i8* @llvm.eh.exception() + // CHECK-WITHOUT-NEXT: @llvm.eh.selector + // CHECK-WITHOUT-NEXT: call void @abort() +} diff --git a/test/CodeGenObjC/variadic-sends.m b/test/CodeGenObjC/variadic-sends.m index ea13823..6b04b50 100644 --- a/test/CodeGenObjC/variadic-sends.m +++ b/test/CodeGenObjC/variadic-sends.m @@ -28,13 +28,13 @@ void f2(A *a) { @interface B : A @end @implementation B : A -(void) foo { - // CHECK-X86-32: call void bitcast (i8* (%struct._objc_method_description*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_method_description*, i8*, i32)*) - // CHECK-X86-64: call void bitcast (i8* (%struct._objc_method_description*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_method_description*, i8*, i32)*) + // CHECK-X86-32: call void bitcast (i8* (%struct._objc_super*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_super*, i8*, i32)*) + // CHECK-X86-64: call void bitcast (i8* (%struct._objc_super*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_super*, i8*, i32)*) [super im1: 1]; } -(void) bar { - // CHECK-X86-32: call void (%struct._objc_method_description*, i8*, i32, i32, ...)* bitcast (i8* (%struct._objc_method_description*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_method_description*, i8*, i32, i32, ...)*) - // CHECK-X86-64: call void (%struct._objc_method_description*, i8*, i32, i32, ...)* bitcast (i8* (%struct._objc_method_description*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_method_description*, i8*, i32, i32, ...)*) + // CHECK-X86-32: call void (%struct._objc_super*, i8*, i32, i32, ...)* bitcast (i8* (%struct._objc_super*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_super*, i8*, i32, i32, ...)*) + // CHECK-X86-64: call void (%struct._objc_super*, i8*, i32, i32, ...)* bitcast (i8* (%struct._objc_super*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_super*, i8*, i32, i32, ...)*) [super im2: 1, 2]; } diff --git a/test/CodeGenObjCXX/arc-globals.mm b/test/CodeGenObjCXX/arc-globals.mm new file mode 100644 index 0000000..7167dbc --- /dev/null +++ b/test/CodeGenObjCXX/arc-globals.mm @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -O2 -disable-llvm-optzns -o - %s | FileCheck %s + +// Test that we're properly retaining lifetime-qualified pointers +// initialized statically and wrapping up those initialization in an +// autorelease pool. +id getObject(); + +// CHECK: define internal void @__cxx_global_var_init +// CHECK: call i8* @_Z9getObjectv +// CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue +// CHECK-NEXT: {{store i8*.*@global_obj}} +// CHECK-NEXT: ret void +id global_obj = getObject(); + +// CHECK: define internal void @__cxx_global_var_init +// CHECK: call i8* @_Z9getObjectv +// CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue +// CHECK-NEXT: {{store i8*.*@global_obj2}} +// CHECK-NEXT: ret void +id global_obj2 = getObject(); + +// CHECK: define internal void @_GLOBAL__I_a +// CHECK: call i8* @objc_autoreleasePoolPush() +// CHECK-NEXT: call void @__cxx_global_var_init +// CHECK-NEXT: call void @__cxx_global_var_init1 +// CHECK-NEXT: call void @objc_autoreleasePoolPop( +// CHECK-NEXT: ret void diff --git a/test/CodeGenObjCXX/arc-mangle.mm b/test/CodeGenObjCXX/arc-mangle.mm new file mode 100644 index 0000000..1955348 --- /dev/null +++ b/test/CodeGenObjCXX/arc-mangle.mm @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-arc -fobjc-runtime-has-weak -emit-llvm -o - %s | FileCheck %s + +// CHECK: define void @_Z1fPU8__strongP11objc_object(i8**) +void f(__strong id *) {} +// CHECK: define void @_Z1fPU6__weakP11objc_object(i8**) +void f(__weak id *) {} +// CHECK: define void @_Z1fPU15__autoreleasingP11objc_object(i8**) +void f(__autoreleasing id *) {} +// CHECK: define void @_Z1fPP11objc_object(i8**) +void f(__unsafe_unretained id *) {} +// CHECK: define void @_Z1fPKU8__strongP11objc_object(i8**) +void f(const __strong id *) {} +// CHECK: define void @_Z1fPKU6__weakP11objc_object(i8**) +void f(const __weak id *) {} +// CHECK: define void @_Z1fPKU15__autoreleasingP11objc_object(i8**) +void f(const __autoreleasing id *) {} +// CHECK: define void @_Z1fPKP11objc_object(i8**) +void f(const __unsafe_unretained id *) {} + + +template<unsigned N> struct unsigned_c { }; + +// CHECK: define weak_odr void @_Z1gIKvEvP10unsigned_cIXplszv1U8__bridgecvPT_v1U8__bridgecvP11objc_objectcvS3_Li0ELi1EEE +template<typename T>void g(unsigned_c<sizeof((__bridge T*)(__bridge id)(T*)0) + 1>*) {} +template void g<const void>(unsigned_c<sizeof(id) + 1> *); diff --git a/test/CodeGenObjCXX/arc-move.mm b/test/CodeGenObjCXX/arc-move.mm new file mode 100644 index 0000000..70469e6 --- /dev/null +++ b/test/CodeGenObjCXX/arc-move.mm @@ -0,0 +1,75 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -O2 -std=c++0x -disable-llvm-optzns -o - %s | FileCheck %s + +// define void @_Z11simple_moveRU8__strongP11objc_objectS2_ +void simple_move(__strong id &x, __strong id &y) { + // CHECK: = load i8** + // CHECK: store i8* null + // CHECK: = load i8** + // CHECK: store i8* + // CHECK-NEXT: call void @objc_release + x = static_cast<__strong id&&>(y); + // CHECK-NEXT: ret void +} + +template<typename T> +struct remove_reference { + typedef T type; +}; + +template<typename T> +struct remove_reference<T&> { + typedef T type; +}; + +template<typename T> +struct remove_reference<T&&> { + typedef T type; +}; + +template<typename T> +typename remove_reference<T>::type&& move(T &&x) { + return static_cast<typename remove_reference<T>::type&&>(x); +} + +// CHECK: define void @_Z12library_moveRU8__strongP11objc_objectS2_ +void library_move(__strong id &x, __strong id &y) { + // CHECK: call i8** @_Z4moveIRU8__strongP11objc_objectEON16remove_referenceIT_E4typeEOS5_ + // CHECK: load i8** + // CHECK: store i8* null, i8** + // CHECK: load i8*** + // CHECK-NEXT: load i8** + // CHECK-NEXT: store i8* + // CHECK-NEXT: call void @objc_release + // CHECK-NEXT: ret void + x = move(y); +} + +// CHECK: define void @_Z12library_moveRU8__strongP11objc_object +void library_move(__strong id &y) { + // CHECK: [[Y:%[a-zA-Z0-9]+]] = call i8** @_Z4moveIRU8__strongP11objc_objectEON16remove_referenceIT_E4typeEOS5_ + // Load the object + // CHECK-NEXT: [[OBJ:%[a-zA-Z0-9]+]] = load i8** [[Y]] + // Null out y + // CHECK-NEXT: store i8* null, i8** [[Y]] + // Initialize x with the object + // CHECK-NEXT: store i8* [[OBJ]], i8** [[X:%[a-zA-Z0-9]+]] + id x = move(y); + + // CHECK-NEXT: store i32 17 + int i = 17; + // CHECK-NEXT: [[OBJ:%[a-zA-Z0-9]+]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[OBJ]]) + // CHECK-NEXT: ret void +} + +// CHECK: define void @_Z10const_moveRKU8__strongP11objc_object( +void const_move(const __strong id &x) { + // CHECK: [[Y:%.*]] = alloca i8*, + // CHECK: [[X:%.*]] = call i8** @_Z4moveIRKU8__strongP11objc_objectEON16remove_referenceIT_E4typeEOS5_( + // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T1]], i8** [[Y]] + // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + id y = move(x); +} diff --git a/test/CodeGenObjCXX/arc-new-delete.mm b/test/CodeGenObjCXX/arc-new-delete.mm new file mode 100644 index 0000000..4597985 --- /dev/null +++ b/test/CodeGenObjCXX/arc-new-delete.mm @@ -0,0 +1,95 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-arc -fobjc-runtime-has-weak -fblocks -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s | FileCheck %s + +typedef __strong id strong_id; +typedef __weak id weak_id; + +// CHECK: define void @_Z8test_newP11objc_object +void test_new(id invalue) { + // CHECK: alloca i8* + // CHECK-NEXT: call i8* @objc_retain + + // CHECK: call noalias i8* @_Znwm + // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} + // CHECK-NEXT: store i8* null, i8** + new strong_id; + // CHECK: call noalias i8* @_Znwm + // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} + // CHECK-NEXT: store i8* null, i8** + new weak_id; + + // CHECK: call noalias i8* @_Znwm + // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} + // CHECK-NEXT: store i8* null, i8** + new __strong id; + // CHECK: call noalias i8* @_Znwm + // CHECK-NEXT: {{bitcast i8\*.*to i8\*\*}} + // CHECK-NEXT: store i8* null, i8** + new __weak id; + + // CHECK: call noalias i8* @_Znwm + // CHECK: call i8* @objc_retain + // CHECK: store i8* + new __strong id(invalue); + + // CHECK: call noalias i8* @_Znwm + // CHECK: call i8* @objc_initWeak + new __weak id(invalue); + + // CHECK: call void @objc_release + // CHECK: ret void +} + +// CHECK: define void @_Z14test_array_new +void test_array_new() { + // CHECK: call noalias i8* @_Znam + // CHECK: store i64 17, i64* + // CHECK: call void @llvm.memset.p0i8.i64 + new strong_id[17]; + + // CHECK: call noalias i8* @_Znam + // CHECK: store i64 17, i64* + // CHECK: call void @llvm.memset.p0i8.i64 + new weak_id[17]; + // CHECK: ret void +} + +// CHECK: define void @_Z11test_deletePU8__strongP11objc_objectPU6__weakS0_ +void test_delete(__strong id *sptr, __weak id *wptr) { + // CHECK: br i1 + // CHECK: load i8** + // CHECK-NEXT: call void @objc_release + // CHECK: call void @_ZdlPv + delete sptr; + + // CHECK: call void @objc_destroyWeak + // CHECK: call void @_ZdlPv + delete wptr; + + // CHECK: ret void +} + +// CHECK: define void @_Z17test_array_deletePU8__strongP11objc_objectPU6__weakS0_ +void test_array_delete(__strong id *sptr, __weak id *wptr) { + // CHECK: icmp eq i8** [[BEGIN:%.*]], null + // CHECK: [[LEN:%.*]] = load i64* {{%.*}} + // CHECK: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[LEN]] + // CHECK-NEXT: icmp eq i8** [[BEGIN]], [[END]] + // CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], + // CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: icmp eq i8** [[CUR]], [[BEGIN]] + // CHECK: call void @_ZdaPv + delete [] sptr; + + // CHECK: icmp eq i8** [[BEGIN:%.*]], null + // CHECK: [[LEN:%.*]] = load i64* {{%.*}} + // CHECK: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[LEN]] + // CHECK-NEXT: icmp eq i8** [[BEGIN]], [[END]] + // CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], + // CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1 + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[CUR]]) + // CHECK-NEXT: icmp eq i8** [[CUR]], [[BEGIN]] + // CHECK: call void @_ZdaPv + delete [] wptr; +} diff --git a/test/CodeGenObjCXX/arc-pseudo-destructors.mm b/test/CodeGenObjCXX/arc-pseudo-destructors.mm new file mode 100644 index 0000000..4023e90 --- /dev/null +++ b/test/CodeGenObjCXX/arc-pseudo-destructors.mm @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-arc -fobjc-runtime-has-weak -fblocks -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s | FileCheck %s + +// CHECK: define void @_Z28test_objc_object_pseudo_dtorPU8__strongP11objc_objectPU6__weakS0_ +void test_objc_object_pseudo_dtor(__strong id *ptr, __weak id *wptr) { + // CHECK: load i8*** + // CHECK-NEXT: load i8** + // CHECK-NEXT: call void @objc_release + ptr->~id(); + + // CHECK: call void @objc_destroyWeak(i8** {{%.*}}) + wptr->~id(); + + // CHECK: load i8*** + // CHECK-NEXT: load i8** + // CHECK-NEXT: call void @objc_release + (*ptr).~id(); + + // CHECK: call void @objc_destroyWeak(i8** {{%.*}}) + (*wptr).~id(); + // CHECK: ret void +} diff --git a/test/CodeGenObjCXX/arc-references.mm b/test/CodeGenObjCXX/arc-references.mm new file mode 100644 index 0000000..3d0313d --- /dev/null +++ b/test/CodeGenObjCXX/arc-references.mm @@ -0,0 +1,83 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fblocks -fobjc-arc -O2 -disable-llvm-optzns -o - %s | FileCheck %s + +@interface A +@end + +id getObject(); +void callee(); + +// Lifetime extension for binding a reference to an rvalue +// CHECK: define void @_Z5test0v() +void test0() { + // CHECK: call i8* @_Z9getObjectv + // CHECK-NEXT:: call i8* @objc_retainAutoreleasedReturnValue + const __strong id &ref1 = getObject(); + // CHECK: call void @_Z6calleev + callee(); + // CHECK: call i8* @_Z9getObjectv + // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue + // CHECK-NEXT: call i8* @objc_autorelease + const __autoreleasing id &ref2 = getObject(); + // CHECK: call void @_Z6calleev + callee(); + // CHECK: call void @objc_release + // CHECK-NEXT: ret +} + +// No lifetime extension when we're binding a reference to an lvalue. +// CHECK: define void @_Z5test1RU8__strongP11objc_objectRU6__weakS0_ +void test1(__strong id &x, __weak id &y) { + // CHECK-NOT: release + const __strong id &ref1 = x; + const __autoreleasing id &ref2 = x; + const __weak id &ref3 = y; + // CHECK: ret void +} + +typedef __strong id strong_id; + +//CHECK: define void @_Z5test3v +void test3() { + // CHECK: call i8* @objc_initWeak + // CHECK-NEXT: store i8** + const __weak id &ref = strong_id(); + // CHECK-NEXT: call void @_Z6calleev() + callee(); + // CHECK-NEXT: call void @objc_destroyWeak + // CHECK-NEXT: ret void +} + +// CHECK: define void @_Z5test4RU8__strongP11objc_object +void test4(__strong id &x) { + // CHECK: call i8* @objc_retain + __strong A* const &ar = x; + // CHECK: store i32 17, i32* + int i = 17; + // CHECK: call void @objc_release( + // CHECK: ret void +} + +void sink(__strong A* &&); + +// CHECK: define void @_Z5test5RU8__strongP11objc_object +void test5(__strong id &x) { + // CHECK: [[OBJ_ID:%[a-zA-Z0-9]+]] = call i8* @objc_retain + // CHECK-NEXT: [[OBJ_A:%[a-zA-Z0-9]+]] = bitcast i8* [[OBJ_ID]] to [[A:%[a-zA-Z0-9]+]]* + // CHECK-NEXT: store [[A]]* [[OBJ_A]], [[A]]** [[REFTMP:%[a-zA-Z0-9]+]] + // CHECK-NEXT: call void @_Z4sinkOU8__strongP1A + sink(x); + // CHECK-NEXT: [[OBJ_A:%[a-zA-Z0-9]+]] = load [[A]]** [[REFTMP]] + // CHECK-NEXT: [[OBJ_ID:%[a-zA-Z0-9]+]] = bitcast [[A]]* [[OBJ_A]] to i8* + // CHECK-NEXT: call void @objc_release + // CHECK-NEXT: store i32 17, i32 + int i = 17; + // CHECK-NEXT: ret void +} + +// CHECK: define internal void @__cxx_global_var_init( +// CHECK: call i8* @_Z9getObjectv +// CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue +const __strong id &global_ref = getObject(); + +// Note: we intentionally don't release the object. + diff --git a/test/CodeGenObjCXX/arc-special-member-functions.mm b/test/CodeGenObjCXX/arc-special-member-functions.mm new file mode 100644 index 0000000..d88a2bd --- /dev/null +++ b/test/CodeGenObjCXX/arc-special-member-functions.mm @@ -0,0 +1,161 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-arc -fblocks -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s | FileCheck %s + +struct ObjCMember { + id member; +}; + +struct ObjCArrayMember { + id member[2][3]; +}; + +struct ObjCBlockMember { + int (^bp)(int); +}; + +// CHECK: define void @_Z42test_ObjCMember_default_construct_destructv( +void test_ObjCMember_default_construct_destruct() { + // CHECK: call void @_ZN10ObjCMemberC1Ev + // CHECK: call void @_ZN10ObjCMemberD1Ev + ObjCMember m1; +} + +// CHECK: define void @_Z39test_ObjCMember_copy_construct_destruct10ObjCMember +void test_ObjCMember_copy_construct_destruct(ObjCMember m1) { + // CHECK: call void @_ZN10ObjCMemberC1ERKS_ + // CHECK: call void @_ZN10ObjCMemberD1Ev + ObjCMember m2 = m1; + // CHECK: ret void +} + +// CHECK: define void @_Z27test_ObjCMember_copy_assign10ObjCMemberS_ +void test_ObjCMember_copy_assign(ObjCMember m1, ObjCMember m2) { + // CHECK: {{call.*_ZN10ObjCMemberaSERKS_}} + m1 = m2; + // CHECK-NEXT: ret void +} + +// Implicitly-generated copy assignment operator for ObjCMember +// CHECK: {{define linkonce_odr.*@_ZN10ObjCMemberaSERKS_}} +// CHECK: call void @objc_storeStrong +// CHECK: ret + +// CHECK: define void @_Z47test_ObjCArrayMember_default_construct_destructv +void test_ObjCArrayMember_default_construct_destruct() { + // CHECK: call void @_ZN15ObjCArrayMemberC1Ev + ObjCArrayMember m1; + // CHECK: call void @_ZN15ObjCArrayMemberD1Ev + // CHECK: ret void +} + +// CHECK: define void @_Z44test_ObjCArrayMember_copy_construct_destruct15ObjCArrayMember +void test_ObjCArrayMember_copy_construct_destruct(ObjCArrayMember m1) { + // CHECK: call void @_ZN15ObjCArrayMemberC1ERKS_ + ObjCArrayMember m2 = m1; + // CHECK: call void @_ZN15ObjCArrayMemberD1Ev + // CHECK: ret void +} + +void test_ObjCArrayMember_copy_assign(ObjCArrayMember m1, ObjCArrayMember m2) { + // CHECK: {{call.*@_ZN15ObjCArrayMemberaSERKS_}} + m1 = m2; + // CHECK-NEXT: ret void +} + +// Implicitly-generated copy assignment operator for ObjCArrayMember +// CHECK: {{define linkonce_odr.*@_ZN15ObjCArrayMemberaSERKS_}} +// CHECK: call void @objc_storeStrong +// CHECK-NEXT: br label +// CHECK: ret + +// CHECK: define void @_Z47test_ObjCBlockMember_default_construct_destructv +void test_ObjCBlockMember_default_construct_destruct() { + // CHECK: call void @_ZN15ObjCBlockMemberC1Ev + ObjCBlockMember m; + // CHECK-NEXT: call void @_ZN15ObjCBlockMemberD1Ev + // CHECK-NEXT: ret void +} + +// CHECK: define void @_Z44test_ObjCBlockMember_copy_construct_destruct15ObjCBlockMember +void test_ObjCBlockMember_copy_construct_destruct(ObjCBlockMember m1) { + // CHECK: call void @_ZN15ObjCBlockMemberC1ERKS_ + ObjCBlockMember m2 = m1; + // CHECK-NEXT: call void @_ZN15ObjCBlockMemberD1Ev + // CHECK-NEXT: ret void +} + +// CHECK: define void @_Z32test_ObjCBlockMember_copy_assign15ObjCBlockMemberS_ +void test_ObjCBlockMember_copy_assign(ObjCBlockMember m1, ObjCBlockMember m2) { + // CHECK: {{call.*_ZN15ObjCBlockMemberaSERKS_}} + m1 = m2; + // CHECK-NEXT: ret void +} + +// Implicitly-generated copy assignment operator for ObjCBlockMember +// CHECK: define linkonce_odr {{%.*}}* @_ZN15ObjCBlockMemberaSERKS_( +// CHECK: [[T0:%.*]] = call i8* @objc_retainBlock( +// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to i32 (i32)* +// CHECK-NEXT: [[T2:%.*]] = load {{.*}} [[SLOT:%.*]], +// CHECK: store +// CHECK-NEXT: [[T3:%.*]] = bitcast +// CHECK-NEXT: call void @objc_release(i8* [[T3]]) +// CHECK-NEXT: ret + +// Implicitly-generated copy constructor for ObjCBlockMember +// CHECK: define linkonce_odr void @_ZN15ObjCBlockMemberC2ERKS_ +// CHECK: call i8* @objc_retainBlock +// CHECK: ret + +// Implicitly-generated destructor for ObjCBlockMember +// CHECK: define linkonce_odr void @_ZN15ObjCBlockMemberD2Ev +// CHECK: call void @objc_release(i8* +// CHECK: ret + +// Implicitly-generated default constructor for ObjCBlockMember +// CHECK: define linkonce_odr void @_ZN15ObjCBlockMemberC2Ev +// CHECK: store {{.*}} null, +// CHECK-NEXT: ret void + +// Implicitly-generated copy constructor for ObjCArrayMember +// CHECK: define linkonce_odr void @_ZN15ObjCArrayMemberC2ERKS_ +// CHECK: br i1 +// CHECK: call i8* @objc_retain +// CHECK-NEXT: store i8* +// CHECK-NEXT: br label +// CHECK: ret + +// Implicitly-generated destructor for ObjCArrayMember +// CHECK: define linkonce_odr void @_ZN15ObjCArrayMemberD2Ev +// CHECK: [[BEGIN:%.*]] = getelementptr inbounds [2 x [3 x i8*]]* +// CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 6 +// CHECK-NEXT: br label +// CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] +// CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1 +// CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] +// CHECK-NEXT: call void @objc_release(i8* [[T0]]) +// CHECK-NEXT: [[T1:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] +// CHECK-NEXT: br i1 [[T1]], +// CHECK: ret void + +// Implicitly-generated default constructor for ObjCArrayMember +// CHECK: define linkonce_odr void @_ZN15ObjCArrayMemberC2Ev +// CHECK: call void @llvm.memset.p0i8.i64 +// CHECK: ret + +// Implicitly-generated copy constructor for ObjCMember +// CHECK: define linkonce_odr void @_ZN10ObjCMemberC2ERKS_ +// CHECK-NOT: objc_release +// CHECK: call i8* @objc_retain +// CHECK-NEXT: store i8* +// CHECK-NEXT: ret void + +// Implicitly-generated destructor for ObjCMember +// CHECK: define linkonce_odr void @_ZN10ObjCMemberD2Ev +// CHECK: call void @objc_release +// CHECK: ret void + +// Implicitly-generated default constructor for ObjCMember +// CHECK: define linkonce_odr void @_ZN10ObjCMemberC2Ev +// CHECK-NOT: objc_release +// CHECK: store i8* null +// CHECK-NEXT: ret void + diff --git a/test/CodeGenObjCXX/arc.mm b/test/CodeGenObjCXX/arc.mm new file mode 100644 index 0000000..0c5466a --- /dev/null +++ b/test/CodeGenObjCXX/arc.mm @@ -0,0 +1,166 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fblocks -fobjc-arc -O2 -disable-llvm-optzns -o - %s | FileCheck %s + +// rdar://problem/9315552 +// The analogous ObjC testcase test46 in arr.m. +void test0(__weak id *wp, __weak volatile id *wvp) { + extern id test0_helper(void); + + // TODO: this is sub-optimal, we should retain at the actual call site. + // TODO: in the non-volatile case, we do not need to be reloading. + + // CHECK: [[T0:%.*]] = call i8* @_Z12test0_helperv() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8 + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]]) + // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]]) + // CHECK-NEXT: store i8* [[T4]], i8** + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + id x = *wp = test0_helper(); + + // CHECK: [[T0:%.*]] = call i8* @_Z12test0_helperv() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8 + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]]) + // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_loadWeakRetained(i8** [[T2]]) + // CHECK-NEXT: store i8* [[T4]], i8** + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + id y = *wvp = test0_helper(); +} + +// rdar://problem/9320648 +struct Test1_helper { Test1_helper(); }; +@interface Test1 @end +@implementation Test1 { Test1_helper x; } @end +// CHECK: define internal i8* @"\01-[Test1 .cxx_construct]"( +// CHECK: call void @_ZN12Test1_helperC1Ev( +// CHECK-NEXT: load +// CHECK-NEXT: bitcast +// CHECK-NEXT: ret i8* + +void test34(int cond) { + __strong id strong; + __weak id weak; + extern void test34_sink(id *); + test34_sink(cond ? &strong : 0); + test34_sink(cond ? &weak : 0); + + // CHECK: define void @_Z6test34i( + // CHECK: [[COND:%.*]] = alloca i32 + // CHECK-NEXT: [[STRONG:%.*]] = alloca i8* + // CHECK-NEXT: [[WEAK:%.*]] = alloca i8* + // CHECK-NEXT: [[TEMP1:%.*]] = alloca i8* + // CHECK-NEXT: [[TEMP2:%.*]] = alloca i8* + // CHECK-NEXT: store i32 + // CHECK-NEXT: store i8* null, i8** [[STRONG]] + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[WEAK]], i8* null) + + // CHECK-NEXT: [[T0:%.*]] = load i32* [[COND]] + // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0 + // CHECK: [[ARG:%.*]] = phi i8** + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i8** null, i8** [[TEMP1]] + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = load i8** [[ARG]] + // CHECK-NEXT: store i8* [[T0]], i8** [[TEMP1]] + // CHECK-NEXT: br label + // CHECK: call void @_Z11test34_sinkPU15__autoreleasingP11objc_object(i8** [[T1]]) + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = load i8** [[TEMP1]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8** [[ARG]] + // CHECK-NEXT: store i8* [[T1]], i8** [[ARG]] + // CHECK-NEXT: call void @objc_release(i8* [[T2]]) + // CHECK-NEXT: br label + + // CHECK: [[T0:%.*]] = load i32* [[COND]] + // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0 + // CHECK: [[ARG:%.*]] = phi i8** + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i8** null, i8** [[TEMP2]] + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = call i8* @objc_loadWeak(i8** [[ARG]]) + // CHECK-NEXT: store i8* [[T0]], i8** [[TEMP2]] + // CHECK-NEXT: br label + // CHECK: call void @_Z11test34_sinkPU15__autoreleasingP11objc_object(i8** [[T1]]) + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = load i8** [[TEMP2]] + // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[ARG]], i8* [[T0]]) + // CHECK-NEXT: br label + + // CHECK: call void @objc_destroyWeak(i8** [[WEAK]]) + // CHECK: ret void +} + +struct Test35_Helper { + static id makeObject1() __attribute__((ns_returns_retained)); + id makeObject2() __attribute__((ns_returns_retained)); + static id makeObject3(); + id makeObject4(); +}; + +// CHECK: define void @_Z6test3513Test35_HelperPS_ +void test35(Test35_Helper x0, Test35_Helper *x0p) { + // CHECK: call i8* @_ZN13Test35_Helper11makeObject1Ev + // CHECK-NOT: call i8* @objc_retain + id obj1 = Test35_Helper::makeObject1(); + // CHECK: call i8* @_ZN13Test35_Helper11makeObject2Ev + // CHECK-NOT: call i8* @objc_retain + id obj2 = x0.makeObject2(); + // CHECK: call i8* @_ZN13Test35_Helper11makeObject2Ev + // CHECK-NOT: call i8* @objc_retain + id obj3 = x0p->makeObject2(); + id (Test35_Helper::*pmf)() __attribute__((ns_returns_retained)) + = &Test35_Helper::makeObject2; + // CHECK: call i8* % + // CHECK-NOT: call i8* @objc_retain + id obj4 = (x0.*pmf)(); + // CHECK: call i8* % + // CHECK-NOT: call i8* @objc_retain + id obj5 = (x0p->*pmf)(); + + // CHECK: call void @objc_release + // CHECK: call void @objc_release + // CHECK: call void @objc_release + // CHECK: call void @objc_release + // CHECK: call void @objc_release + // CHECK-NEXT: ret void +} + +// CHECK: define void @_Z7test35b13Test35_HelperPS_ +void test35b(Test35_Helper x0, Test35_Helper *x0p) { + // CHECK: call i8* @_ZN13Test35_Helper11makeObject3Ev + // CHECK: call i8* @objc_retain + id obj1 = Test35_Helper::makeObject3(); + // CHECK: call i8* @_ZN13Test35_Helper11makeObject4Ev + // CHECK: call i8* @objc_retain + id obj2 = x0.makeObject4(); + // CHECK: call i8* @_ZN13Test35_Helper11makeObject4Ev + // CHECK: call i8* @objc_retain + id obj3 = x0p->makeObject4(); + id (Test35_Helper::*pmf)() = &Test35_Helper::makeObject4; + // CHECK: call i8* % + // CHECK: call i8* @objc_retain + id obj4 = (x0.*pmf)(); + // CHECK: call i8* % + // CHECK: call i8* @objc_retain + id obj5 = (x0p->*pmf)(); + + // CHECK: call void @objc_release + // CHECK: call void @objc_release + // CHECK: call void @objc_release + // CHECK: call void @objc_release + // CHECK: call void @objc_release + // CHECK-NEXT: ret void +} + +// rdar://problem/9603128 +// CHECK: define i8* @_Z6test36P11objc_object( +id test36(id z) { + // CHECK: objc_retain + // CHECK: objc_retain + // CHECK: objc_release + // CHECK: objc_autoreleaseReturnValue + return z; +} diff --git a/test/CodeGenObjCXX/catch-id-type.mm b/test/CodeGenObjCXX/catch-id-type.mm new file mode 100644 index 0000000..ece342b --- /dev/null +++ b/test/CodeGenObjCXX/catch-id-type.mm @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -triple i386-apple-macosx10.6.6 -emit-llvm -fobjc-exceptions -fcxx-exceptions -fexceptions -o - %s | FileCheck %s +// rdar://8940528 + +@interface ns_array ++ (id) array; +@end + +@implementation ns_array ++ (id) array { return 0; } +@end + +id Groups(); + +@protocol P @end; + +@interface INTF<P> { + double dd; +} +@end + +id FUNC() { + id groups; + try + { + groups = Groups(); // throws on errors. + } + catch( INTF<P>* error ) + { + Groups(); + } + catch( id error ) + { + // CHECK: call i32 (i8*, i8*, ...)* @llvm.eh.selector({{.*}} @__gxx_personality_v0 {{.*}} @_ZTIP4INTF {{.*}} @_ZTIP11objc_object {{.*}} @_ZTIP10objc_class + error = error; + groups = [ns_array array]; + } + catch (Class cl) { + cl = cl; + groups = [ns_array array]; + } + return groups; + +} + +int main() { + FUNC(); + return 0; +} diff --git a/test/CodeGenObjCXX/copy.mm b/test/CodeGenObjCXX/copy.mm new file mode 100644 index 0000000..133910f --- /dev/null +++ b/test/CodeGenObjCXX/copy.mm @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s + +// rdar://problem/9158302 +// This should not use a memmove_collectable in non-GC mode. +namespace test0 { + struct A { + id x; + }; + + // CHECK: define [[A:%.*]]* @_ZN5test04testENS_1AE( + // CHECK: alloca + // CHECK-NEXT: getelementptr + // CHECK-NEXT: store + // CHECK-NEXT: call noalias i8* @_Znwm( + // CHECK-NEXT: bitcast + // CHECK-NEXT: bitcast + // CHECK-NEXT: call void @llvm.memset.p0i8.i64( + // CHECK-NEXT: bitcast + // CHECK-NEXT: bitcast + // CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64( + // CHECK-NEXT: ret + A *test(A a) { + return new A(a); + } +} + diff --git a/test/CodeGenObjCXX/encode.mm b/test/CodeGenObjCXX/encode.mm index dce3d70..2c10fbc 100644 --- a/test/CodeGenObjCXX/encode.mm +++ b/test/CodeGenObjCXX/encode.mm @@ -91,6 +91,20 @@ namespace rdar9357400 { const char gg[] = @encode(vector4f); } +// rdar://9624314 +namespace rdar9624314 { + struct B2 { int x; }; + struct B3 {}; + struct S : B2, B3 {}; + + // CHECK: @_ZN11rdar9624314L2ggE = internal constant [6 x i8] c"{S=i}\00" + const char gg[] = @encode(S); + + struct S2 { unsigned : 0; int x; unsigned : 0; }; + // CHECK: @_ZN11rdar9624314L2g2E = internal constant [11 x i8] c"{S2=b0ib0}\00" + const char g2[] = @encode(S2); +} + struct Base1 { char x; }; diff --git a/test/CodeGenObjCXX/gc.mm b/test/CodeGenObjCXX/gc.mm new file mode 100644 index 0000000..aa293da --- /dev/null +++ b/test/CodeGenObjCXX/gc.mm @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fobjc-gc -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s + +namespace test0 { + extern id x; + + struct A { + id x; + A(); + }; + A::A() : x(test0::x) {} + +// CHECK: define void @_ZN5test01AC2Ev( +// CHECK: [[THIS:%.*]] = alloca [[TEST0:%.*]]*, align 8 +// CHECK-NEXT: store +// CHECK-NEXT: [[T0:%.*]] = load [[TEST0]]** [[THIS]] +// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[TEST0]]* [[T0]], i32 0, i32 0 +// CHECK-NEXT: [[T2:%.*]] = load i8** @_ZN5test01xE +// CHECK-NEXT: call i8* @objc_assign_strongCast(i8* [[T2]], i8** [[T1]]) +// CHECK-NEXT: ret void +} diff --git a/test/CodeGenObjCXX/property-object-conditional-exp.mm b/test/CodeGenObjCXX/property-object-conditional-exp.mm index a3c1027..5d8a882 100644 --- a/test/CodeGenObjCXX/property-object-conditional-exp.mm +++ b/test/CodeGenObjCXX/property-object-conditional-exp.mm @@ -22,11 +22,12 @@ extern "C" bool CGRectIsEmpty(CGRect); CGRect dataRect; CGRect virtualBounds; -// CHECK: [[SRC:%.*]] = call %struct.CGRect bitcast (i8* (i8*, i8*, ...)* @objc_msgSend -// CHECK-NEXT:getelementptr %struct.CGRect* [[SRC:%.*]] +// CHECK: [[SRC:%.*]] = call { i8*, i32 } bitcast (i8* (i8*, i8*, ...)* @objc_msgSend +// CHECK-NEXT: bitcast +// CHECK-NEXT:getelementptr { i8*, i32 }* [[SRC:%.*]] // CHECK-NEXT:extractvalue // CHECK-NEXT:store -// CHECK-NEXT:getelementptr %struct.CGRect* [[SRC:%.*]] +// CHECK-NEXT:getelementptr { i8*, i32 }* [[SRC:%.*]] // CHECK-NEXT:extractvalue // CHECK-NEXT:store dataRect = CGRectIsEmpty(virtualBounds) ? self.bounds : virtualBounds; diff --git a/test/CodeGenObjCXX/property-objects.mm b/test/CodeGenObjCXX/property-objects.mm index 8e98b0d..1f43117 100644 --- a/test/CodeGenObjCXX/property-objects.mm +++ b/test/CodeGenObjCXX/property-objects.mm @@ -2,7 +2,7 @@ // CHECK-NOT: callq _objc_msgSend_stret // CHECK: call void @_ZN1SC1ERKS_ // CHECK: call %class.S* @_ZN1SaSERKS_ -// CHECK: call %class.S* @_ZN6CGRectaSERKS_ +// CHECK: call %struct.CGRect* @_ZN6CGRectaSERKS_ class S { public: diff --git a/test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl b/test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl index c61be69..fbe3d89 100644 --- a/test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl +++ b/test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl @@ -1,12 +1,11 @@ // RUN: %clang_cc1 %s -emit-llvm -o %t typedef __attribute__((ext_vector_type(4))) unsigned char uchar4; -typedef __attribute__((ext_vector_type(4))) unsigned int int4; typedef __attribute__((ext_vector_type(8))) unsigned char uchar8; // OpenCL allows vectors to be initialized by vectors Handle bug in // VisitInitListExpr for this case below. -void foo( int4 v ) +void foo( uchar8 x ) { - uchar4 val[4] = {{(uchar4){((uchar8)(v.lo)).lo}}}; -}
\ No newline at end of file + uchar4 val[4] = {{(uchar4){x.lo}}}; +} diff --git a/test/CodeGenOpenCL/vector_literals_valid.cl b/test/CodeGenOpenCL/vector_literals_valid.cl new file mode 100644 index 0000000..bba5b23 --- /dev/null +++ b/test/CodeGenOpenCL/vector_literals_valid.cl @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -emit-llvm %s -o %t + +typedef __attribute__(( ext_vector_type(2) )) int int2; +typedef __attribute__(( ext_vector_type(3) )) int int3; +typedef __attribute__(( ext_vector_type(4) )) int int4; +typedef __attribute__(( ext_vector_type(8) )) int int8; +typedef __attribute__(( ext_vector_type(4) )) float float4; + +void vector_literals_valid() { + int4 a_1_1_1_1 = (int4)(1,2,3,4); + int4 a_2_1_1 = (int4)((int2)(1,2),3,4); + int4 a_1_2_1 = (int4)(1,(int2)(2,3),4); + int4 a_1_1_2 = (int4)(1,2,(int2)(3,4)); + int4 a_2_2 = (int4)((int2)(1,2),(int2)(3,4)); + int4 a_3_1 = (int4)((int3)(1,2,3),4); + int4 a_1_3 = (int4)(1,(int3)(2,3,4)); + int4 a = (int4)(1); + int8 b = (int8)(1,2,a.xy,a); + float4 V2 = (float4) (1); +} + + diff --git a/test/Driver/arc-exceptions.m b/test/Driver/arc-exceptions.m new file mode 100644 index 0000000..4501ccd --- /dev/null +++ b/test/Driver/arc-exceptions.m @@ -0,0 +1,5 @@ +// RUN: %clang -### -x objective-c -arch x86_64 -fobjc-arc -fsyntax-only %s 2> %t.log +// RUN: grep objective-c %t.log +// RUN: not grep "fobjc-arc-exceptions" %t.log +// RUN: %clang -### -x objective-c++ -arch x86_64 -fobjc-arc -fsyntax-only %s 2> %t.log +// RUN: grep "fobjc-arc-exceptions" %t.log diff --git a/test/Driver/arc.c b/test/Driver/arc.c new file mode 100644 index 0000000..a4d4ed1 --- /dev/null +++ b/test/Driver/arc.c @@ -0,0 +1,14 @@ +// RUN: %clang -ObjC -ccc-host-triple i386-apple-darwin9 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck %s +// RUN: %clang -x objective-c -ccc-host-triple i386-apple-darwin9 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck %s +// RUN: %clang -x objective-c++ -ccc-host-triple i386-apple-darwin9 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck %s +// RUN: %clang -x c -ccc-host-triple i386-apple-darwin9 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck -check-prefix NOTOBJC %s +// RUN: %clang -x c++ -ccc-host-triple i386-apple-darwin9 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck -check-prefix NOTOBJC %s + +// Just to test clang is working. +# foo + +// CHECK: error: -fobjc-arc is not supported with fragile abi +// CHECK-NOT: invalid preprocessing directive + +// NOTOBJC-NOT: error: -fobjc-arc is not supported with fragile abi +// NOTOBJC: invalid preprocessing directive diff --git a/test/Driver/darwin-ld.c b/test/Driver/darwin-ld.c index 91d47ea..33b4858 100644 --- a/test/Driver/darwin-ld.c +++ b/test/Driver/darwin-ld.c @@ -18,9 +18,9 @@ // // 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 -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: %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 -force_load ARG28 -fpie -fprofile-arcs -headerpad_max_install_names -image_base ARG29 -init ARG30 -install_name ARG31 -m ARG33 -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: FileCheck -check-prefix=SPLATTER %s < %t.log -// SPLATTER: {{".*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" "-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" "-allow_stack_execute" ".*/libprofile_rt.a" "-T" "ARG4" "-FARG1"}} +// SPLATTER: {{".*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" "-force_load" "ARG28" "-headerpad_max_install_names" "-image_base" "ARG29" "-init" "ARG30" "-macosx_version_min" "10.3.2" "-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" "-allow_stack_execute" ".*/libprofile_rt.*" "-T" "ARG4" "-FARG1"}} // Check linker changes that came with new linkedit format. // RUN: touch %t.o @@ -92,3 +92,19 @@ // LINK_OLDER_NODEMANGLE: {{ld(.exe)?"}} // LINK_OLDER_NODEMANGLE-NOT: "-demangle" // LINK_OLDER_NODEMANGLE: "-lSystem" + +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -### %t.o \ +// RUN: -mlinker-version=117 -flto 2> %t.log +// RUN: cat %t.log +// RUN: FileCheck -check-prefix=LINK_OBJECT_LTO_PATH %s < %t.log +// +// LINK_OBJECT_LTO_PATH: {{ld(.exe)?"}} +// LINK_OBJECT_LTO_PATH: "-object_path_lto" + +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -### %t.o \ +// RUN: -force_load a -force_load b 2> %t.log +// RUN: cat %t.log +// RUN: FileCheck -check-prefix=FORCE_LOAD %s < %t.log +// +// FORCE_LOAD: {{ld(.exe)?"}} +// FORCE_LOAD: "-force_load" "a" "-force_load" "b" diff --git a/test/Driver/darwin-objc-options.m b/test/Driver/darwin-objc-options.m index bc0b12c..50daa72 100644 --- a/test/Driver/darwin-objc-options.m +++ b/test/Driver/darwin-objc-options.m @@ -15,5 +15,7 @@ // CHECK-CHECK-I386_ABI2: "-cc1" // CHECK-CHECK-I386_ABI2: -fobjc-nonfragile-abi +// CHECK-CHECK-I386_ABI2: -fobjc-exceptions +// CHECK-CHECK-I386_ABI2: -fexceptions // CHECK-CHECK-I386_ABI2-NOT: -fobjc-dispatch-method // CHECK-CHECK-I386_ABI2: darwin-objc-options diff --git a/test/Driver/darwin-xarch.c b/test/Driver/darwin-xarch.c index d16d531..4c6689c 100644 --- a/test/Driver/darwin-xarch.c +++ b/test/Driver/darwin-xarch.c @@ -12,3 +12,9 @@ // RUN: FileCheck --check-prefix=CHECK-LINK < %t %s // // CHECK-LINK: ld{{.*}} "-arch" "i386"{{.*}} "-some-linker-arg" + +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -### \ +// RUN: -arch armv7 -Xarch_armv7 -Wl,-some-linker-arg -filelist X 2> %t +// RUN: FileCheck --check-prefix=CHECK-ARMV7-LINK < %t %s +// +// CHECK-ARMV7-LINK: ld{{.*}} "-arch" "armv7"{{.*}} "-some-linker-arg" diff --git a/test/Driver/gnu-runtime.m b/test/Driver/gnu-runtime.m new file mode 100644 index 0000000..5a3654c --- /dev/null +++ b/test/Driver/gnu-runtime.m @@ -0,0 +1,5 @@ +// RUN: %clang -ccc-host-triple i386-apple-darwin10 -### -fsyntax-only -fgnu-runtime %s 2>&1 | FileCheck %s +// RUN: %clang -ccc-host-triple i386-apple-darwin10 -### -x objective-c++ -fsyntax-only -fgnu-runtime %s 2>&1 | FileCheck %s +// CHECK: -fgnu-runtime +// CHECK: -fobjc-runtime-has-arc +// CHECK: -fobjc-runtime-has-weak diff --git a/test/Driver/ios-simulator-arcruntime.c b/test/Driver/ios-simulator-arcruntime.c new file mode 100644 index 0000000..bec9f7b --- /dev/null +++ b/test/Driver/ios-simulator-arcruntime.c @@ -0,0 +1,6 @@ +// RUN: %clang -### -x objective-c -ccc-host-triple i386-apple-darwin10 -arch i386 -mmacosx-version-min=10.6 -D__IPHONE_OS_VERSION_MIN_REQUIRED=40201 -fobjc-arc -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS1 %s +// RUN: %clang -### -x objective-c -ccc-host-triple i386-apple-darwin10 -arch i386 -mmacosx-version-min=10.6 -D__IPHONE_OS_VERSION_MIN_REQUIRED=50000 -fobjc-arc -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS2 %s +// + +// CHECK-OPTIONS1-NOT: -fobjc-runtime-has-weak +// CHECK-OPTIONS2: -fobjc-runtime-has-weak diff --git a/test/Driver/mg.c b/test/Driver/mg.c new file mode 100644 index 0000000..4f43814 --- /dev/null +++ b/test/Driver/mg.c @@ -0,0 +1,5 @@ +// RUN: %clang -M -MG -include nonexistent-preinclude.h %s > %t +// RUN: fgrep nonexistent-preinclude.h %t +// RUN: fgrep nonexistent-ppinclude.h %t + +#include "nonexistent-ppinclude.h" diff --git a/test/Driver/no-objc-arr.m b/test/Driver/no-objc-arr.m new file mode 100644 index 0000000..15fbdc2 --- /dev/null +++ b/test/Driver/no-objc-arr.m @@ -0,0 +1,8 @@ +// RUN: %clang -Werror -fobjc-arc -fsyntax-only -fno-objc-arc -verify %s +// rdar://8949617 + +void * FOO() { + id string = @"Hello World.\n"; + void *pointer = string; // No error must be issued + return pointer; +} diff --git a/test/Driver/noexecstack.c b/test/Driver/noexecstack.c new file mode 100644 index 0000000..1f47728 --- /dev/null +++ b/test/Driver/noexecstack.c @@ -0,0 +1 @@ +// RUN: %clang -### %s -c -o tmp.o -triple i686-pc-linux-gnu -integrated-as -Wa,--noexecstack 2>&1 | grep "mnoexecstack" diff --git a/test/Driver/rewrite-objc.m b/test/Driver/rewrite-objc.m index 2fe2cce..c47b523 100644 --- a/test/Driver/rewrite-objc.m +++ b/test/Driver/rewrite-objc.m @@ -3,7 +3,7 @@ // TEST0: clang{{.*}}" "-cc1" // TEST0: "-rewrite-objc" // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency instead. -// TEST0: "-fmessage-length" "0" "-fobjc-infer-related-result-type" "-fobjc-exceptions" "-fdiagnostics-show-option" +// TEST0: "-fmessage-length" "0" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fdiagnostics-show-option" // TEST0: rewrite-objc.m" // RUN: not %clang -ccc-no-clang -ccc-host-triple unknown -rewrite-objc %s -o - -### 2>&1 | \ diff --git a/test/Driver/sysroot.c b/test/Driver/sysroot.c index 34f3100..79db900 100644 --- a/test/Driver/sysroot.c +++ b/test/Driver/sysroot.c @@ -1,18 +1,18 @@ // Check that --sysroot= also applies to header search paths. // RUN: %clang -ccc-host-triple i386-unk-unk --sysroot=/FOO -### -E %s 2> %t1 // RUN: FileCheck --check-prefix=CHECK-SYSROOTEQ < %t1 %s -// CHECK-SYSROOTEQ: "-cc1"{{.*}} "-isysroot" "/FOO" +// CHECK-SYSROOTEQ: "-cc1"{{.*}} "-isysroot" "{{[^"]*}}/FOO" // Apple Darwin uses -isysroot as the syslib root, too. // RUN: touch %t2.o // RUN: %clang -ccc-host-triple i386-apple-darwin10 \ // RUN: -isysroot /FOO -### %t2.o 2> %t2 // RUN: FileCheck --check-prefix=CHECK-APPLE-ISYSROOT < %t2 %s -// CHECK-APPLE-ISYSROOT: "-arch" "i386"{{.*}} "-syslibroot" "/FOO" +// CHECK-APPLE-ISYSROOT: "-arch" "i386"{{.*}} "-syslibroot" "{{[^"]*}}/FOO" // Check that honor --sysroot= over -isysroot, for Apple Darwin. // RUN: touch %t3.o // RUN: %clang -ccc-host-triple i386-apple-darwin10 \ // RUN: -isysroot /FOO --sysroot=/BAR -### %t3.o 2> %t3 // RUN: FileCheck --check-prefix=CHECK-APPLE-SYSROOT < %t3 %s -// CHECK-APPLE-SYSROOT: "-arch" "i386"{{.*}} "-syslibroot" "/BAR" +// CHECK-APPLE-SYSROOT: "-arch" "i386"{{.*}} "-syslibroot" "{{[^"]*}}/BAR" diff --git a/test/Driver/x86_features.c b/test/Driver/x86_features.c index 9dbdd0a..0db372e 100644 --- a/test/Driver/x86_features.c +++ b/test/Driver/x86_features.c @@ -1,3 +1,3 @@ // RUN: %clang -ccc-host-triple i386-unknown-unknown -### -S %s -msse -msse4 -mno-sse -mno-mmx -msse 2> %t -// RUN: grep '"-target-feature" "+sse" "-target-feature" "+sse4" "-target-feature" "-sse" "-target-feature" "-mmx" "-target-feature" "+sse"' %t - +// RUN: grep '"pentium4" "-target-feature" "+sse4" "-target-feature" "-mmx" "-target-feature" "+sse"' %t +// Note that we filter out all but the last -m(no)sse. diff --git a/test/FixIt/fixit-objc.m b/test/FixIt/fixit-objc.m index bf704c6..2e8bfae 100644 --- a/test/FixIt/fixit-objc.m +++ b/test/FixIt/fixit-objc.m @@ -39,3 +39,17 @@ void f(Test *t) { [t test:@"Foo"]]; // expected-error{{extraneous ']' before ';'}} g(@"Foo")); // expected-error{{extraneous ')' before ';'}} } + +// rdar://7861841 +@interface Radar7861841 { +@public + int x; +} + +@property (assign) int y; +@end + +int f0(Radar7861841 *a) { return a.x; } // expected-error {{property 'x' not found on object of type 'Radar7861841 *'; did you mean to access ivar 'x'}} + +int f1(Radar7861841 *a) { return a->y; } // expected-error {{property 'y' found on object of type 'Radar7861841 *'; did you mean to access it with the "." operator?}} + diff --git a/test/FixIt/fixit.c b/test/FixIt/fixit.c index 1a6ef63..ba45cf2 100644 --- a/test/FixIt/fixit.c +++ b/test/FixIt/fixit.c @@ -33,9 +33,14 @@ void f1(x, y) int i0 = { 17 }; +#define ONE 1 +#define TWO 2 + int test_cond(int y, int fooBar) { // CHECK: int x = y ? 1 : 4+fooBar; int x = y ? 1 4+foobar; +// CHECK: x = y ? ONE : TWO; + x = y ? ONE TWO; return x; } diff --git a/test/FixIt/typo-crash.cpp b/test/FixIt/typo-crash.cpp new file mode 100644 index 0000000..b156e1b --- /dev/null +++ b/test/FixIt/typo-crash.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// FIXME: The diagnostics and recovery here are very, very poor. + +// PR10355 +template<typename T> void template_id1() { + template_id2<> t; // expected-error 2{{use of undeclared identifier 'template_id2'; did you mean 'template_id1'?}} \ + // expected-error{{expected expression}} \ + // expected-error{{use of undeclared identifier 't'}} + } + diff --git a/test/FixIt/typo.cpp b/test/FixIt/typo.cpp index f8b5352..3d40da8 100644 --- a/test/FixIt/typo.cpp +++ b/test/FixIt/typo.cpp @@ -74,3 +74,15 @@ int foo() { unsinged *ptr = 0; // expected-error{{use of undeclared identifier 'unsinged'; did you mean 'unsigned'?}} return *i + *ptr + global_val; // expected-error{{use of undeclared identifier 'global_val'; did you mean 'global_value'?}} } + +namespace nonstd { + typedef std::basic_string<char> yarn; // expected-note{{'nonstd::yarn' declared here}} +} + +yarn str4; // expected-error{{unknown type name 'yarn'; did you mean 'nonstd::yarn'?}} + +namespace check_bool { + void f() { + Bool b; // expected-error{{use of undeclared identifier 'Bool'; did you mean 'bool'?}} + } +} diff --git a/test/Frontend/dependency-gen.c b/test/Frontend/dependency-gen.c index 0f8adab..49d3f28 100644 --- a/test/Frontend/dependency-gen.c +++ b/test/Frontend/dependency-gen.c @@ -1,19 +1,27 @@ -// rdar://6533411 -// RUN: %clang -MD -MF %t.d -S -x c -o %t.o %s -// RUN: grep '.*dependency-gen.*:' %t.d -// RUN: grep 'dependency-gen.c' %t.d - -// RUN: %clang -S -M -x c %s -o %t.d -// RUN: grep '.*dependency-gen.*:' %t.d -// RUN: grep 'dependency-gen.c' %t.d - -// PR8974 // REQUIRES: shell -// "cd %t.dir" requires shell. +// Basic test // RUN: rm -rf %t.dir // RUN: mkdir -p %t.dir/a/b // RUN: echo > %t.dir/a/b/x.h // RUN: cd %t.dir -// RUN: %clang -include a/b/x.h -MD -MF %t.d -S -x c -o %t.o %s -// RUN: grep ' a/b/x\.h' %t.d +// RUN: %clang -MD -MF - %s -fsyntax-only -I a/b | FileCheck -check-prefix=CHECK-ONE %s +// CHECK-ONE: {{ }}a/b/x.h + +// PR8974 (-include flag) +// RUN: %clang -MD -MF - %s -fsyntax-only -include a/b/x.h -DINCLUDE_FLAG_TEST | FileCheck -check-prefix=CHECK-TWO %s +// CHECK-TWO: {{ }}a/b/x.h + +// rdar://problem/9734352 (paths involving ".") +// RUN: %clang -MD -MF - %s -fsyntax-only -I ./a/b | FileCheck -check-prefix=CHECK-THREE %s +// CHECK-THREE: {{ }}a/b/x.h +// RUN: %clang -MD -MF - %s -fsyntax-only -I .//./a/b/ | FileCheck -check-prefix=CHECK-FOUR %s +// CHECK-FOUR: {{ }}a/b/x.h +// RUN: %clang -MD -MF - %s -fsyntax-only -I a/b/. | FileCheck -check-prefix=CHECK-FIVE %s +// CHECK-FIVE: {{ }}a/b/./x.h +// RUN: cd a/b +// RUN: %clang -MD -MF - %s -fsyntax-only -I ./ | FileCheck -check-prefix=CHECK-SIX %s +// CHECK-SIX: {{ }}x.h +#ifndef INCLUDE_FLAG_TEST +#include <x.h> +#endif diff --git a/test/Index/annotate-tokens-pp.c b/test/Index/annotate-tokens-pp.c index 01a615f..e6bb086 100644 --- a/test/Index/annotate-tokens-pp.c +++ b/test/Index/annotate-tokens-pp.c @@ -53,14 +53,14 @@ void test() { // CHECK: Identifier: "X" [4:22 - 4:23] macro definition=WIBBLE // CHECK: Punctuation: "##" [4:23 - 4:25] macro definition=WIBBLE // CHECK: Identifier: "Y" [4:25 - 4:26] macro definition=WIBBLE -// CHECK: Identifier: "NOTHING" [5:1 - 5:8] macro instantiation=NOTHING:1:9 +// CHECK: Identifier: "NOTHING" [5:1 - 5:8] macro expansion=NOTHING:1:9 // CHECK: Punctuation: "(" [5:8 - 5:9] // CHECK: Identifier: "more" [5:9 - 5:13] // CHECK: Punctuation: "," [5:13 - 5:14] // CHECK: Identifier: "junk" [5:14 - 5:18] // CHECK: Punctuation: ")" [5:18 - 5:19] // CHECK: Keyword: "float" [5:20 - 5:25] -// CHECK: Identifier: "WIBBLE" [5:26 - 5:32] macro instantiation=WIBBLE:4:9 +// CHECK: Identifier: "WIBBLE" [5:26 - 5:32] macro expansion=WIBBLE:4:9 // CHECK: Punctuation: "(" [5:32 - 5:33] // CHECK: Keyword: "int" [5:33 - 5:36] // CHECK: Punctuation: "," [5:36 - 5:37] @@ -68,8 +68,8 @@ void test() { // CHECK: Punctuation: ")" [5:43 - 5:44] // CHECK: Punctuation: ";" [5:44 - 5:45] // CHECK: Keyword: "int" [6:1 - 6:4] -// CHECK: Identifier: "BAR" [6:5 - 6:8] macro instantiation=BAR:3:9 -// CHECK: Identifier: "STILL_NOTHING" [6:9 - 6:22] macro instantiation=STILL_NOTHING:2:9 +// CHECK: Identifier: "BAR" [6:5 - 6:8] macro expansion=BAR:3:9 +// CHECK: Identifier: "STILL_NOTHING" [6:9 - 6:22] macro expansion=STILL_NOTHING:2:9 // CHECK: Punctuation: ";" [6:22 - 6:23] // CHECK: Punctuation: "#" [7:1 - 7:2] inclusion directive=foo.h // CHECK: Identifier: "include" [7:2 - 7:9] inclusion directive=foo.h @@ -115,7 +115,7 @@ void test() { // CHECK: Keyword: "int" [16:3 - 16:6] VarDecl=k:16:7 (Definition) // CHECK: Identifier: "k" [16:7 - 16:8] VarDecl=k:16:7 (Definition) // CHECK: Punctuation: "=" [16:9 - 16:10] VarDecl=k:16:7 (Definition) -// CHECK: Identifier: "REVERSE_MACRO" [16:11 - 16:24] macro instantiation=REVERSE_MACRO:10:9 +// CHECK: Identifier: "REVERSE_MACRO" [16:11 - 16:24] macro expansion=REVERSE_MACRO:10:9 // CHECK: Punctuation: "(" [16:24 - 16:25] UnexposedStmt= // CHECK: Identifier: "t" [16:25 - 16:26] DeclRefExpr=t:15:7 // CHECK: Punctuation: "," [16:26 - 16:27] UnexposedStmt= @@ -125,7 +125,7 @@ void test() { // CHECK: Keyword: "int" [17:3 - 17:6] VarDecl=j:17:7 (Definition) // CHECK: Identifier: "j" [17:7 - 17:8] VarDecl=j:17:7 (Definition) // CHECK: Punctuation: "=" [17:9 - 17:10] VarDecl=j:17:7 (Definition) -// CHECK: Identifier: "TWICE_MACRO" [17:11 - 17:22] macro instantiation=TWICE_MACRO:11:9 +// CHECK: Identifier: "TWICE_MACRO" [17:11 - 17:22] macro expansion=TWICE_MACRO:11:9 // CHECK: Punctuation: "(" [17:22 - 17:23] UnexposedStmt= // CHECK: Identifier: "k" [17:23 - 17:24] DeclRefExpr=k:16:7 // CHECK: Punctuation: "+" [17:25 - 17:26] UnexposedStmt= @@ -170,7 +170,7 @@ void test() { // CHECK: Punctuation: "=" [24:9 - 24:10] VarDecl=x:24:7 (Definition) // CHECK: Literal: "10" [24:11 - 24:13] UnexposedExpr= // CHECK: Punctuation: ";" [24:13 - 24:14] UnexposedStmt= -// CHECK: Identifier: "fun_with_macro_bodies" [25:3 - 25:24] macro instantiation=fun_with_macro_bodies:21:9 +// CHECK: Identifier: "fun_with_macro_bodies" [25:3 - 25:24] macro expansion=fun_with_macro_bodies:21:9 // CHECK: Punctuation: "(" [25:24 - 25:25] UnexposedStmt= // CHECK: Identifier: "x" [25:25 - 25:26] DeclRefExpr=x:24:7 // CHECK: Punctuation: "," [25:26 - 25:27] UnexposedStmt= diff --git a/test/Index/annotate-tokens.cpp b/test/Index/annotate-tokens.cpp index ccc9e96..165420a 100644 --- a/test/Index/annotate-tokens.cpp +++ b/test/Index/annotate-tokens.cpp @@ -17,9 +17,10 @@ struct S1 { void f(); }; struct S2 { S1 *operator->(); }; void test3(S2 s2) { s2->f(); + X foo; } -// RUN: c-index-test -test-annotate-tokens=%s:1:1:20:1 %s | FileCheck %s +// RUN: c-index-test -test-annotate-tokens=%s:1:1:21:1 %s | FileCheck %s // CHECK: Keyword: "struct" [1:1 - 1:7] StructDecl=bonk:1:8 (Definition) // CHECK: Identifier: "bonk" [1:8 - 1:12] StructDecl=bonk:1:8 (Definition) // CHECK: Punctuation: "{" [1:13 - 1:14] StructDecl=bonk:1:8 (Definition) @@ -115,4 +116,7 @@ void test3(S2 s2) { // CHECK: Punctuation: "(" [19:8 - 19:9] CallExpr=f:16:18 // CHECK: Punctuation: ")" [19:9 - 19:10] CallExpr=f:16:18 // CHECK: Punctuation: ";" [19:10 - 19:11] UnexposedStmt= -// CHECK: Punctuation: "}" [20:1 - 20:2] UnexposedStmt= +// CHECK: Identifier: "X" [20:3 - 20:4] TypeRef=struct X:7:8 +// CHECK: Identifier: "foo" [20:5 - 20:8] VarDecl=foo:20:5 (Definition) +// CHECK: Punctuation: ";" [20:8 - 20:9] UnexposedStmt= +// CHECK: Punctuation: "}" [21:1 - 21:2] UnexposedStmt= diff --git a/test/Index/annotate-tokens.m b/test/Index/annotate-tokens.m index 1eb7794..1dc7621 100644 --- a/test/Index/annotate-tokens.m +++ b/test/Index/annotate-tokens.m @@ -134,6 +134,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; @interface Rdar8062781 + (Foo*)getB; @property (readonly, nonatomic) Foo *blah; +@property (readonly, atomic) Foo *abah; @end // RUN: c-index-test -test-annotate-tokens=%s:1:1:118:1 %s -DIBOutlet='__attribute__((iboutlet))' -DIBAction='void)__attribute__((ibaction)' | FileCheck %s @@ -226,7 +227,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Identifier: "IBActionTests" [32:12 - 32:25] ObjCInterfaceDecl=IBActionTests:32:12 // CHECK: Punctuation: "-" [33:1 - 33:2] ObjCInstanceMethodDecl=actionMethod::33:1 // CHECK: Punctuation: "(" [33:3 - 33:4] ObjCInstanceMethodDecl=actionMethod::33:1 -// CHECK: Identifier: "IBAction" [33:4 - 33:12] macro instantiation=IBAction +// CHECK: Identifier: "IBAction" [33:4 - 33:12] macro expansion=IBAction // CHECK: Punctuation: ")" [33:12 - 33:13] ObjCInstanceMethodDecl=actionMethod::33:1 // CHECK: Identifier: "actionMethod" [33:14 - 33:26] ObjCInstanceMethodDecl=actionMethod::33:1 // CHECK: Punctuation: ":" [33:26 - 33:27] ObjCInstanceMethodDecl=actionMethod::33:1 @@ -261,7 +262,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Identifier: "IBActionTests" [37:17 - 37:30] ObjCImplementationDecl=IBActionTests:37:1 (Definition) // CHECK: Punctuation: "-" [38:1 - 38:2] ObjCInstanceMethodDecl=actionMethod::38:1 (Definition) // CHECK: Punctuation: "(" [38:3 - 38:4] ObjCInstanceMethodDecl=actionMethod::38:1 (Definition) -// CHECK: Identifier: "IBAction" [38:4 - 38:12] macro instantiation=IBAction +// CHECK: Identifier: "IBAction" [38:4 - 38:12] macro expansion=IBAction // CHECK: Punctuation: ")" [38:12 - 38:13] ObjCInstanceMethodDecl=actionMethod::38:1 (Definition) // CHECK: Identifier: "actionMethod" [38:14 - 38:26] ObjCInstanceMethodDecl=actionMethod::38:1 (Definition) // CHECK: Punctuation: ":" [38:26 - 38:27] ObjCInstanceMethodDecl=actionMethod::38:1 (Definition) @@ -305,7 +306,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Keyword: "interface" [51:2 - 51:11] ObjCInterfaceDecl=IBOutletTests:51:12 // CHECK: Identifier: "IBOutletTests" [51:12 - 51:25] ObjCInterfaceDecl=IBOutletTests:51:12 // CHECK: Punctuation: "{" [52:1 - 52:2] ObjCInterfaceDecl=IBOutletTests:51:12 -// CHECK: Identifier: "IBOutlet" [53:5 - 53:13] macro instantiation=IBOutlet +// CHECK: Identifier: "IBOutlet" [53:5 - 53:13] macro expansion=IBOutlet // CHECK: Keyword: "char" [53:14 - 53:18] ObjCIvarDecl=anOutlet:53:21 (Definition) // CHECK: Punctuation: "*" [53:19 - 53:20] ObjCIvarDecl=anOutlet:53:21 (Definition) // CHECK: Identifier: "anOutlet" [53:21 - 53:29] ObjCIvarDecl=anOutlet:53:21 (Definition) @@ -313,7 +314,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Punctuation: "}" [54:1 - 54:2] ObjCInterfaceDecl=IBOutletTests:51:12 // CHECK: Punctuation: "-" [55:1 - 55:2] ObjCInstanceMethodDecl=actionMethod::55:1 // CHECK: Punctuation: "(" [55:3 - 55:4] ObjCInstanceMethodDecl=actionMethod::55:1 -// CHECK: Identifier: "IBAction" [55:4 - 55:12] macro instantiation=IBAction +// CHECK: Identifier: "IBAction" [55:4 - 55:12] macro expansion=IBAction // CHECK: Punctuation: ")" [55:12 - 55:13] ObjCInstanceMethodDecl=actionMethod::55:1 // CHECK: Identifier: "actionMethod" [55:14 - 55:26] ObjCInstanceMethodDecl=actionMethod::55:1 // CHECK: Punctuation: ":" [55:26 - 55:27] ObjCInstanceMethodDecl=actionMethod::55:1 @@ -324,7 +325,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Punctuation: ";" [55:34 - 55:35] ObjCInstanceMethodDecl=actionMethod::55:1 // CHECK: Punctuation: "@" [56:1 - 56:2] ObjCPropertyDecl=aPropOutlet:56:26 // CHECK: Keyword: "property" [56:2 - 56:10] ObjCPropertyDecl=aPropOutlet:56:26 -// CHECK: Identifier: "IBOutlet" [56:11 - 56:19] macro instantiation=IBOutlet +// CHECK: Identifier: "IBOutlet" [56:11 - 56:19] macro expansion=IBOutlet // CHECK: Keyword: "int" [56:20 - 56:23] ObjCPropertyDecl=aPropOutlet:56:26 // CHECK: Punctuation: "*" [56:24 - 56:25] ObjCPropertyDecl=aPropOutlet:56:26 // CHECK: Identifier: "aPropOutlet" [56:26 - 56:37] ObjCPropertyDecl=aPropOutlet:56:26 @@ -388,7 +389,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK: Identifier: "self" [76:18 - 76:22] DeclRefExpr=self:0:0 // CHECK: Identifier: "foo" [76:23 - 76:26] ObjCMessageExpr=foo::66:1 // CHECK: Punctuation: ":" [76:26 - 76:27] ObjCMessageExpr=foo::66:1 -// CHECK: Identifier: "VAL" [76:27 - 76:30] macro instantiation=VAL:63:9 +// CHECK: Identifier: "VAL" [76:27 - 76:30] macro expansion=VAL:63:9 // CHECK: Punctuation: "]" [76:30 - 76:31] ObjCMessageExpr=foo::66:1 // CHECK: Punctuation: ";" [76:31 - 76:32] UnexposedStmt= // CHECK: Keyword: "int" [77:5 - 77:8] VarDecl=second:77:9 (Definition) @@ -526,7 +527,7 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK-INSIDE_BLOCK: Punctuation: "=" [128:20 - 128:21] VarDecl=a:128:18 (Definition) // CHECK-INSIDE_BLOCK: Identifier: "self" [128:22 - 128:26] DeclRefExpr=self:0:0 -// RUN: c-index-test -test-annotate-tokens=%s:134:1:137:1 %s -DIBOutlet='__attribute__((iboutlet))' -DIBAction='void)__attribute__((ibaction)' | FileCheck -check-prefix=CHECK-PROP-AFTER-METHOD %s +// RUN: c-index-test -test-annotate-tokens=%s:134:1:138:1 %s -DIBOutlet='__attribute__((iboutlet))' -DIBAction='void)__attribute__((ibaction)' | FileCheck -check-prefix=CHECK-PROP-AFTER-METHOD %s // CHECK-PROP-AFTER-METHOD: Punctuation: "@" [134:1 - 134:2] ObjCInterfaceDecl=Rdar8062781:134:12 // CHECK-PROP-AFTER-METHOD: Keyword: "interface" [134:2 - 134:11] ObjCInterfaceDecl=Rdar8062781:134:12 // CHECK-PROP-AFTER-METHOD: Identifier: "Rdar8062781" [134:12 - 134:23] ObjCInterfaceDecl=Rdar8062781:134:12 @@ -548,4 +549,15 @@ static Rdar8595462_A * Rdar8595462_staticVar; // CHECK-PROP-AFTER-METHOD: Punctuation: "*" [136:37 - 136:38] ObjCPropertyDecl=blah:136:38 // CHECK-PROP-AFTER-METHOD: Identifier: "blah" [136:38 - 136:42] ObjCPropertyDecl=blah:136:38 // CHECK-PROP-AFTER-METHOD: Punctuation: ";" [136:42 - 136:43] ObjCInterfaceDecl=Rdar8062781:134:12 -// CHECK-PROP-AFTER-METHOD: Punctuation: "@" [137:1 - 137:2] ObjCInterfaceDecl=Rdar8062781:134:12 +// CHECK-PROP-AFTER-METHOD: Punctuation: "@" [137:1 - 137:2] ObjCPropertyDecl=abah:137:35 +// CHECK-PROP-AFTER-METHOD: Keyword: "property" [137:2 - 137:10] ObjCPropertyDecl=abah:137:35 +// CHECK-PROP-AFTER-METHOD: Punctuation: "(" [137:11 - 137:12] ObjCPropertyDecl=abah:137:35 +// CHECK-PROP-AFTER-METHOD: Keyword: "readonly" [137:12 - 137:20] ObjCPropertyDecl=abah:137:35 +// CHECK-PROP-AFTER-METHOD: Punctuation: "," [137:20 - 137:21] ObjCPropertyDecl=abah:137:35 +// CHECK-PROP-AFTER-METHOD: Keyword: "atomic" [137:22 - 137:28] ObjCPropertyDecl=abah:137:35 +// CHECK-PROP-AFTER-METHOD: Punctuation: ")" [137:28 - 137:29] ObjCPropertyDecl=abah:137:35 +// CHECK-PROP-AFTER-METHOD: Identifier: "Foo" [137:30 - 137:33] ObjCClassRef=Foo:1:12 +// CHECK-PROP-AFTER-METHOD: Punctuation: "*" [137:34 - 137:35] ObjCPropertyDecl=abah:137:35 +// CHECK-PROP-AFTER-METHOD: Identifier: "abah" [137:35 - 137:39] ObjCPropertyDecl=abah:137:35 +// CHECK-PROP-AFTER-METHOD: Punctuation: ";" [137:39 - 137:40] ObjCInterfaceDecl=Rdar8062781:134:12 +// CHECK-PROP-AFTER-METHOD: Punctuation: "@" [138:1 - 138:2] ObjCInterfaceDecl=Rdar8062781:134:12 diff --git a/test/Index/arc-annotate.m b/test/Index/arc-annotate.m new file mode 100644 index 0000000..b836bc8 --- /dev/null +++ b/test/Index/arc-annotate.m @@ -0,0 +1,38 @@ +@interface A +@property (strong, nonatomic) id property; +@property (nonatomic, weak) id second_property; +@property (unsafe_unretained, nonatomic) id third_property; +@end + +// RUN: c-index-test -test-annotate-tokens=%s:1:1:5:1 %s -fobjc-arc -fobjc-nonfragile-abi | FileCheck %s +// CHECK: Punctuation: "@" [1:1 - 1:2] ObjCInterfaceDecl=A:1:12 +// CHECK: Keyword: "interface" [1:2 - 1:11] ObjCInterfaceDecl=A:1:12 +// CHECK: Identifier: "A" [1:12 - 1:13] ObjCInterfaceDecl=A:1:12 +// CHECK: Punctuation: "@" [2:1 - 2:2] ObjCPropertyDecl=property:2:34 +// CHECK: Keyword: "property" [2:2 - 2:10] ObjCPropertyDecl=property:2:34 +// CHECK: Punctuation: "(" [2:11 - 2:12] ObjCPropertyDecl=property:2:34 +// CHECK: Keyword: "strong" [2:12 - 2:18] ObjCPropertyDecl=property:2:34 +// CHECK: Punctuation: "," [2:18 - 2:19] ObjCPropertyDecl=property:2:34 +// CHECK: Keyword: "nonatomic" [2:20 - 2:29] ObjCPropertyDecl=property:2:34 +// CHECK: Punctuation: ")" [2:29 - 2:30] ObjCPropertyDecl=property:2:34 +// CHECK: Identifier: "id" [2:31 - 2:33] TypeRef=id:0:0 +// CHECK: Identifier: "property" [2:34 - 2:42] ObjCPropertyDecl=property:2:34 +// CHECK: Punctuation: ";" [2:42 - 2:43] ObjCInterfaceDecl=A:1:12 +// CHECK: Punctuation: "@" [3:1 - 3:2] ObjCPropertyDecl=second_property:3:32 +// CHECK: Keyword: "property" [3:2 - 3:10] ObjCPropertyDecl=second_property:3:32 +// CHECK: Punctuation: "(" [3:11 - 3:12] ObjCPropertyDecl=second_property:3:32 +// CHECK: Keyword: "nonatomic" [3:12 - 3:21] ObjCPropertyDecl=second_property:3:32 +// CHECK: Punctuation: "," [3:21 - 3:22] ObjCPropertyDecl=second_property:3:32 +// CHECK: Keyword: "weak" [3:23 - 3:27] ObjCPropertyDecl=second_property:3:32 +// CHECK: Punctuation: ")" [3:27 - 3:28] ObjCPropertyDecl=second_property:3:32 +// CHECK: Identifier: "id" [3:29 - 3:31] TypeRef=id:0:0 +// CHECK: Identifier: "second_property" [3:32 - 3:47] ObjCPropertyDecl=second_property:3:32 +// CHECK: Punctuation: "@" [4:1 - 4:2] ObjCPropertyDecl=third_property:4:45 +// CHECK: Keyword: "property" [4:2 - 4:10] ObjCPropertyDecl=third_property:4:45 +// CHECK: Punctuation: "(" [4:11 - 4:12] ObjCPropertyDecl=third_property:4:45 +// CHECK: Keyword: "unsafe_unretained" [4:12 - 4:29] ObjCPropertyDecl=third_property:4:45 +// CHECK: Punctuation: "," [4:29 - 4:30] ObjCPropertyDecl=third_property:4:45 +// CHECK: Keyword: "nonatomic" [4:31 - 4:40] ObjCPropertyDecl=third_property:4:45 +// CHECK: Punctuation: ")" [4:40 - 4:41] ObjCPropertyDecl=third_property:4:45 +// CHECK: Identifier: "id" [4:42 - 4:44] TypeRef=id:0:0 +// CHECK: Identifier: "third_property" [4:45 - 4:59] ObjCPropertyDecl=third_property:4:45 diff --git a/test/Index/arc-complete.m b/test/Index/arc-complete.m new file mode 100644 index 0000000..328983c --- /dev/null +++ b/test/Index/arc-complete.m @@ -0,0 +1,16 @@ +typedef const void *CFTypeRef; + +void test(id x) { + (__bridge CFTypeRef)x; +} + + + +// RUN: c-index-test -code-completion-at=%s:4:4 %s -fobjc-arc -fobjc-nonfragile-abi | FileCheck -check-prefix=CHECK-CC1 %s +// CHECK-CC1: macro definition:{TypedText __autoreleasing} (70) +// CHECK-CC1: NotImplemented:{TypedText __bridge}{HorizontalSpace }{Placeholder type}{RightParen )}{Placeholder expression} (40) +// CHECK-CC1: NotImplemented:{TypedText __bridge_retained}{HorizontalSpace }{Placeholder CF type}{RightParen )}{Placeholder expression} (40) +// CHECK-CC1: NotImplemented:{TypedText __bridge_transfer}{HorizontalSpace }{Placeholder Objective-C type}{RightParen )}{Placeholder expression} (40) +// CHECK-CC1: macro definition:{TypedText __strong} (70) +// CHECK-CC1: macro definition:{TypedText __unsafe_unretained} (70) +// CHECK-CC1: macro definition:{TypedText __weak} (70) diff --git a/test/Index/c-index-api-loadTU-test.m b/test/Index/c-index-api-loadTU-test.m index 98a41d8..ab5f9a9 100644 --- a/test/Index/c-index-api-loadTU-test.m +++ b/test/Index/c-index-api-loadTU-test.m @@ -70,6 +70,11 @@ typedef struct X0 X1; struct X0; struct X0 {}; +@interface TestAttributes() +// <rdar://problem/9561076> +@property (retain) IBOutlet id anotherOutlet; +@end + // CHECK: c-index-api-loadTU-test.m:4:12: ObjCInterfaceDecl=Foo:4:12 Extent=[4:1 - 12:5] // CHECK: c-index-api-loadTU-test.m:6:32: ObjCIvarDecl=myoutlet:6:32 (Definition) Extent=[6:3 - 6:40] // CHECK: <invalid loc>:0:0: attribute(iboutlet)= @@ -150,3 +155,9 @@ struct X0 {}; // CHECK: c-index-api-loadTU-test.m:70:8: StructDecl=X0:70:8 Extent=[70:1 - 70:10] // CHECK: c-index-api-loadTU-test.m:71:8: StructDecl=X0:71:8 (Definition) Extent=[71:1 - 71:14] +// CHECK: <invalid loc>:0:0: attribute(iboutlet)= +// CHECK: c-index-api-loadTU-test.m:75:29: TypeRef=id:0:0 Extent=[75:29 - 75:31] +// CHECK: c-index-api-loadTU-test.m:75:32: ObjCInstanceMethodDecl=anotherOutlet:75:32 Extent=[75:32 - 75:45] +// CHECK: c-index-api-loadTU-test.m:75:32: ObjCInstanceMethodDecl=setAnotherOutlet::75:32 Extent=[75:32 - 75:45] +// CHECK: c-index-api-loadTU-test.m:75:32: ParmDecl=anotherOutlet:75:32 (Definition) Extent=[75:32 - 75:45] + diff --git a/test/Index/c-index-getCursor-pp.c b/test/Index/c-index-getCursor-pp.c index 8f98691..df61ec0 100644 --- a/test/Index/c-index-getCursor-pp.c +++ b/test/Index/c-index-getCursor-pp.c @@ -18,15 +18,15 @@ B(int x); // RUN: c-index-test -cursor-at=%s:2:14 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-2 %s // CHECK-2: macro definition=DECORATION // RUN: c-index-test -cursor-at=%s:5:7 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-3 %s -// CHECK-3: macro instantiation=OBSCURE:1:9 +// CHECK-3: macro expansion=OBSCURE:1:9 // RUN: c-index-test -cursor-at=%s:6:6 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-4 %s -// CHECK-4: macro instantiation=OBSCURE:1:9 +// CHECK-4: macro expansion=OBSCURE:1:9 // RUN: c-index-test -cursor-at=%s:6:19 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-5 %s -// CHECK-5: macro instantiation=DECORATION:2:9 +// CHECK-5: macro expansion=DECORATION:2:9 // RUN: c-index-test -cursor-at=%s:9:10 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-6 %s // CHECK-6: inclusion directive=a.h // RUN: c-index-test -cursor-at=%s:14:1 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-7 %s -// CHECK-7: macro instantiation=B:12:9 +// CHECK-7: macro expansion=B:12:9 // Same tests, but with "editing" optimizations // RUN: env CINDEXTEST_EDITING=1 c-index-test -cursor-at=%s:1:11 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-1 %s diff --git a/test/Index/c-index-getCursor-test.m b/test/Index/c-index-getCursor-test.m index c2ff696..6df8c1a 100644 --- a/test/Index/c-index-getCursor-test.m +++ b/test/Index/c-index-getCursor-test.m @@ -165,4 +165,4 @@ void f() { // CHECK: [55:9 - 55:26] macro definition=CONCAT // CHECK: [57:1 - 57:10] FunctionDecl=f:57:6 (Definition) // CHECK: [58:4 - 58:8] VarDecl=my_var:58:8 (Definition) -// CHECK: [58:8 - 58:14] macro instantiation=CONCAT:55:9 +// CHECK: [58:8 - 58:14] macro expansion=CONCAT:55:9 diff --git a/test/Index/code-completion.cpp b/test/Index/code-completion.cpp index 62b9e4d..f75d61f 100644 --- a/test/Index/code-completion.cpp +++ b/test/Index/code-completion.cpp @@ -52,10 +52,21 @@ Z::operator int() const { // CHECK-MEMBER: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} // CHECK-MEMBER: CXXDestructor:{ResultType void}{Informative Y::}{TypedText ~Y}{LeftParen (}{RightParen )} // CHECK-MEMBER: CXXDestructor:{ResultType void}{TypedText ~Z}{LeftParen (}{RightParen )} +// CHECK-MEMBER: Completion contexts: +// CHECK-MEMBER-NEXT: Dot member access // 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 )} +// CHECK-OVERLOAD: Completion contexts: +// CHECK-OVERLOAD-NEXT: Any type +// CHECK-OVERLOAD-NEXT: Any value +// CHECK-OVERLOAD-NEXT: Enum tag +// CHECK-OVERLOAD-NEXT: Union tag +// CHECK-OVERLOAD-NEXT: Struct tag +// CHECK-OVERLOAD-NEXT: Class name +// CHECK-OVERLOAD-NEXT: Nested name specifier +// CHECK-OVERLOAD-NEXT: Objective-C interface // RUN: c-index-test -code-completion-at=%s:37:10 %s | FileCheck -check-prefix=CHECK-EXPR %s // CHECK-EXPR: NotImplemented:{TypedText int} (50) @@ -65,3 +76,12 @@ Z::operator int() const { // CHECK-EXPR: FieldDecl:{ResultType float}{Text Y::}{TypedText member} (18) // CHECK-EXPR: CXXMethod:{ResultType void}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )} (37) // CHECK-EXPR: Namespace:{TypedText N}{Text ::} (75) +// CHECK-EXPR: Completion contexts: +// CHECK-EXPR-NEXT: Any type +// CHECK-EXPR-NEXT: Any value +// CHECK-EXPR-NEXT: Enum tag +// CHECK-EXPR-NEXT: Union tag +// CHECK-EXPR-NEXT: Struct tag +// CHECK-EXPR-NEXT: Class name +// CHECK-EXPR-NEXT: Nested name specifier +// CHECK-EXPR-NEXT: Objective-C interface diff --git a/test/Index/complete-exprs.m b/test/Index/complete-exprs.m index 0446dcd..dfa114d 100644 --- a/test/Index/complete-exprs.m +++ b/test/Index/complete-exprs.m @@ -7,10 +7,10 @@ typedef signed char BOOL; @property int prop1; @end - +__strong id global; @implementation A - (int)method:(id)param1 { - + void foo(id (^block)(id x, A* y)); for(BOOL B = YES; ; ) { } } @end @@ -27,3 +27,8 @@ typedef signed char BOOL; // CHECK-CC2: TypedefDecl:{TypedText BOOL} (50) // CHECK-CC2: NotImplemented:{TypedText char} (50) // CHECK-CC2: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (40) +// RUN: c-index-test -code-completion-at=%s:15:1 -fobjc-arc -fobjc-nonfragile-abi %s | FileCheck -check-prefix=CHECK-CC3 %s +// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:15:1 -fobjc-arc -fobjc-nonfragile-abi %s | FileCheck -check-prefix=CHECK-CC3 %s +// CHECK-CC3: FunctionDecl:{ResultType void}{TypedText foo}{LeftParen (}{Placeholder ^id(id x, A *y)block}{RightParen )} (34) +// CHECK-CC3: VarDecl:{ResultType id}{TypedText global} (50) +// CHECK-CC3: ParmDecl:{ResultType id}{TypedText param1} (34) diff --git a/test/Index/complete-natural.m b/test/Index/complete-natural.m index e1aba39..326b8a7 100644 --- a/test/Index/complete-natural.m +++ b/test/Index/complete-natural.m @@ -11,8 +11,9 @@ char in_char = 'a'; // RUN: c-index-test -code-completion-at=%s:4:32 %s > %t // RUN: echo "DONE" >> %t // RUN: FileCheck -check-prefix=CHECK-CC1 %s < %t -// CHECK-CC1-NOT: : -// CHECK-CC1: DONE +// CHECK-CC1: Completion contexts: +// CHECK-CC1-NEXT: Natural language +// CHECK-CC1-NEXT: DONE // RUN: c-index-test -code-completion-at=%s:5:18 %s > %t // RUN: echo "DONE" >> %t // RUN: FileCheck -check-prefix=CHECK-CC1 %s < %t diff --git a/test/Index/complete-property-flags.m b/test/Index/complete-property-flags.m index af9e214..f2e08c3 100644 --- a/test/Index/complete-property-flags.m +++ b/test/Index/complete-property-flags.m @@ -16,6 +16,8 @@ // CHECK-CC1-NEXT: {TypedText readwrite} // CHECK-CC1-NEXT: {TypedText retain} // CHECK-CC1-NEXT: {TypedText setter}{Text = }{Placeholder method} +// CHECK-CC1-NEXT: {TypedText strong} +// CHECK-CC1-NEXT: {TypedText unsafe_unretained} // RUN: c-index-test -code-completion-at=%s:8:18 %s | FileCheck -check-prefix=CHECK-CC2 %s // CHECK-CC2: {TypedText getter}{Text = }{Placeholder method} // CHECK-CC2-NEXT: {TypedText nonatomic} diff --git a/test/Index/get-cursor.cpp b/test/Index/get-cursor.cpp index f26d982..2aa76c4 100644 --- a/test/Index/get-cursor.cpp +++ b/test/Index/get-cursor.cpp @@ -31,6 +31,10 @@ struct YDerived : Y { X getAnotherX() { return member; } }; +void test() { + X foo; +} + // RUN: c-index-test -cursor-at=%s:12:20 %s | FileCheck -check-prefix=CHECK-VALUE-REF %s // RUN: c-index-test -cursor-at=%s:13:21 %s | FileCheck -check-prefix=CHECK-VALUE-REF %s // RUN: c-index-test -cursor-at=%s:13:28 %s | FileCheck -check-prefix=CHECK-VALUE-REF %s @@ -61,3 +65,6 @@ struct YDerived : Y { // RUN: c-index-test -cursor-at=%s:27:10 %s | FileCheck -check-prefix=CHECK-IMPLICIT-MEMREF %s // RUN: c-index-test -cursor-at=%s:31:28 %s | FileCheck -check-prefix=CHECK-IMPLICIT-MEMREF %s // CHECK-IMPLICIT-MEMREF: MemberRefExpr=member:21:7 + +// RUN: c-index-test -cursor-at=%s:35:5 %s | FileCheck -check-prefix=CHECK-DECL %s +// CHECK-DECL: VarDecl=foo:35:5 diff --git a/test/Index/nested-macro-instantiations.cpp b/test/Index/nested-macro-instantiations.cpp index d0c9bbb1..9d0c052 100644 --- a/test/Index/nested-macro-instantiations.cpp +++ b/test/Index/nested-macro-instantiations.cpp @@ -7,14 +7,14 @@ WIBBLE(int x); // RUN: env CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source-reparse 5 all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s -// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: macro instantiation=WIBBLE:3:9 Extent=[5:1 - 5:7] -// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:3:19: macro instantiation=BAR:2:9 Extent=[3:19 - 5:14] -// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:2:16: macro instantiation=FOO:1:9 Extent=[2:16 - 5:14] +// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: macro expansion=WIBBLE:3:9 Extent=[5:1 - 5:7] +// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:3:19: macro expansion=BAR:2:9 Extent=[3:19 - 5:14] +// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:2:16: macro expansion=FOO:1:9 Extent=[2:16 - 5:14] // CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: VarDecl=x:5:1 (Definition) Extent=[5:1 - 5:14] // RUN: c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s // RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s // RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s -// CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: macro instantiation=WIBBLE:3:9 Extent=[5:1 - 5:7] -// CHECK-WITHOUT-NESTED-NOT: nested-macro-instantiations.cpp:3:19: macro instantiation=BAR:2:9 Extent=[3:19 - 5:14] +// CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: macro expansion=WIBBLE:3:9 Extent=[5:1 - 5:7] +// CHECK-WITHOUT-NESTED-NOT: nested-macro-instantiations.cpp:3:19: macro expansion=BAR:2:9 Extent=[3:19 - 5:14] // CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: VarDecl=x:5:1 (Definition) Extent=[5:1 - 5:14] diff --git a/test/Index/werror.c b/test/Index/werror.c new file mode 100644 index 0000000..150095d --- /dev/null +++ b/test/Index/werror.c @@ -0,0 +1,15 @@ +inline int *get_int_ptr(float *fp) { + return fp; +} + +#ifdef FATAL +void fatal(int); +void fatal(float); +#endif + +// CHECK-FATAL: translation errors + +// RUN: c-index-test -write-pch %t.pch -Werror %s +// RUN: not c-index-test -write-pch %t.pch -DFATAL -Werror %s 2>%t.err +// RUN: FileCheck -check-prefix=CHECK-FATAL %s < %t.err + diff --git a/test/Lexer/has_feature_objc_arc.m b/test/Lexer/has_feature_objc_arc.m new file mode 100644 index 0000000..cd41900 --- /dev/null +++ b/test/Lexer/has_feature_objc_arc.m @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -E %s -fobjc-nonfragile-abi -fobjc-arc "-triple" "x86_64-apple-macosx10.7.0" -fobjc-runtime-has-weak | FileCheck --check-prefix=CHECK-ARC %s +// RUN: %clang_cc1 -E %s -fobjc-nonfragile-abi -fobjc-arc "-triple" "x86_64-apple-macosx10.6.0" | FileCheck --check-prefix=CHECK-ARCLITE %s + +#if __has_feature(objc_arc) +void has_objc_arc_feature(); +#else +void no_objc_arc_feature(); +#endif + +#if __has_feature(objc_arc_weak) +void has_objc_arc_weak_feature(); +#else +void no_objc_arc_weak_feature(); +#endif + +// CHECK-ARC: void has_objc_arc_feature(); +// CHECK-ARC: void has_objc_arc_weak_feature(); + +// CHECK-ARCLITE: void has_objc_arc_feature(); +// CHECK-ARCLITE: void no_objc_arc_weak_feature(); diff --git a/test/Makefile b/test/Makefile index 050c3a5..4fdafe1 100644 --- a/test/Makefile +++ b/test/Makefile @@ -18,7 +18,7 @@ ifndef TESTARGS ifdef VERBOSE TESTARGS = -v else -TESTARGS = -s -v +TESTARGS = -s -v endif endif diff --git a/test/Misc/caret-diags-macros.c b/test/Misc/caret-diags-macros.c index e45ad2a..ac83ecc 100644 --- a/test/Misc/caret-diags-macros.c +++ b/test/Misc/caret-diags-macros.c @@ -5,9 +5,9 @@ void foo() { M1( M2); - // CHECK: {{.*}}:6:{{[0-9]+}}: warning: expression result unused - // CHECK: {{.*}}:7:{{[0-9]+}}: note: instantiated from: - // CHECK: {{.*}}:4:{{[0-9]+}}: note: instantiated from: + // CHECK: :7:{{[0-9]+}}: warning: expression result unused + // CHECK: :4:{{[0-9]+}}: note: expanded from: + // CHECK: :3:{{[0-9]+}}: note: expanded from: } #define A 1 @@ -15,13 +15,12 @@ void foo() { #define C B void bar() { C; - // CHECK: {{.*}}:17:{{[0-9]+}}: warning: expression result unused - // CHECK: {{.*}}:15:{{[0-9]+}}: note: instantiated from: - // CHECK: {{.*}}:14:{{[0-9]+}}: note: instantiated from: - // CHECK: {{.*}}:13:{{[0-9]+}}: note: instantiated from: + // CHECK: :17:3: warning: expression result unused + // CHECK: :15:11: note: expanded from: + // CHECK: :14:11: note: expanded from: + // CHECK: :13:11: note: expanded from: } - // rdar://7597492 #define sprintf(str, A, B) \ __builtin___sprintf_chk (str, 0, 42, A, B) @@ -30,3 +29,95 @@ void baz(char *Msg) { sprintf(Msg, " sizeof FoooLib : =%3u\n", 12LL); } + +// PR9279: comprehensive tests for multi-level macro back traces +#define macro_args1(x) x +#define macro_args2(x) macro_args1(x) +#define macro_args3(x) macro_args2(x) + +#define macro_many_args1(x, y, z) y +#define macro_many_args2(x, y, z) macro_many_args1(x, y, z) +#define macro_many_args3(x, y, z) macro_many_args2(x, y, z) + +void test() { + macro_args3(1); + // CHECK: {{.*}}:43:15: warning: expression result unused + // Also check that the 'caret' printing agrees with the location here where + // its easy to FileCheck. + // CHECK-NEXT: macro_args3(1); + // CHECK-NEXT: ~~~~~~~~~~~~^~ + // CHECK: {{.*}}:36:36: note: expanded from: + // CHECK: {{.*}}:35:36: note: expanded from: + // CHECK: {{.*}}:34:24: note: expanded from: + + macro_many_args3( + 1, + 2, + 3); + // CHECK: {{.*}}:55:5: warning: expression result unused + // CHECK: {{.*}}:40:55: note: expanded from: + // CHECK: {{.*}}:39:55: note: expanded from: + // CHECK: {{.*}}:38:35: note: expanded from: + + macro_many_args3( + 1, + M2, + 3); + // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:4:12: note: expanded from: + // CHECK: {{.*}}:40:55: note: expanded from: + // CHECK: {{.*}}:39:55: note: expanded from: + // CHECK: {{.*}}:38:35: note: expanded from: + + macro_many_args3( + 1, + macro_args2(2), + 3); + // CHECK: {{.*}}:74:17: warning: expression result unused + // This caret location needs to be printed *inside* a different macro's + // arguments. + // CHECK-NEXT: macro_args2(2), + // CHECK-NEXT: ~~~~~~~~~~~~^~~ + // CHECK: {{.*}}:35:36: note: expanded from: + // CHECK: {{.*}}:34:24: note: expanded from: + // CHECK: {{.*}}:40:55: note: expanded from: + // CHECK: {{.*}}:39:55: note: expanded from: + // CHECK: {{.*}}:38:35: note: expanded from: +} + +#define variadic_args1(x, y, ...) y +#define variadic_args2(x, ...) variadic_args1(x, __VA_ARGS__) +#define variadic_args3(x, y, ...) variadic_args2(x, y, __VA_ARGS__) + +void test2() { + variadic_args3(1, 2, 3, 4); + // CHECK: {{.*}}:93:21: warning: expression result unused + // CHECK-NEXT: variadic_args3(1, 2, 3, 4); + // CHECK-NEXT: ~~~~~~~~~~~~~~~~~~^~~~~~~~ + // CHECK: {{.*}}:90:53: note: expanded from: + // CHECK: {{.*}}:89:50: note: expanded from: + // CHECK: {{.*}}:88:35: note: expanded from: +} + +#define variadic_pasting_args1(x, y, z) y +#define variadic_pasting_args2(x, ...) variadic_pasting_args1(x ## __VA_ARGS__) +#define variadic_pasting_args2a(x, y, ...) variadic_pasting_args1(x, y ## __VA_ARGS__) +#define variadic_pasting_args3(x, y, ...) variadic_pasting_args2(x, y, __VA_ARGS__) +#define variadic_pasting_args3a(x, y, ...) variadic_pasting_args2a(x, y, __VA_ARGS__) + +void test3() { + variadic_pasting_args3(1, 2, 3, 4); + // CHECK: {{.*}}:109:32: warning: expression result unused + // CHECK: {{.*}}:105:72: note: expanded from: + // CHECK: {{.*}}:103:68: note: expanded from: + // CHECK: {{.*}}:102:41: note: expanded from: + + variadic_pasting_args3a(1, 2, 3, 4); + // FIXME: It'd be really nice to retain the start location of the first token + // involved in the token paste instead of falling back on the full macro + // location in the first two locations here. + // CHECK: {{.*}}:115:3: warning: expression result unused + // CHECK: {{.*}}:106:44: note: expanded from: + // CHECK: {{.*}}:104:72: note: expanded from: + // CHECK: {{.*}}:102:41: note: expanded from: +} diff --git a/test/Misc/diag-aka-types.cpp b/test/Misc/diag-aka-types.cpp index e0e6b8c..042c70b 100644 --- a/test/Misc/diag-aka-types.cpp +++ b/test/Misc/diag-aka-types.cpp @@ -12,3 +12,41 @@ char c2 = ref; // expected-error{{'const foo_t' (aka 'const X')}} // deduced auto should not produce an aka. auto aut = X(); char c3 = aut; // expected-error{{from 'X' to 'char'}} + +// There are two classes named Foo::foo here. Make sure the message gives +// a way to them apart. +namespace Foo { + class foo {}; +} + +namespace bar { + namespace Foo { + class foo; + } + void f(Foo::foo* x); // expected-note{{passing argument to parameter 'x' here}} +} + +void test(Foo::foo* x) { + bar::f(x); // expected-error{{cannot initialize a parameter of type 'Foo::foo *' (aka 'bar::Foo::foo *') with an lvalue of type 'Foo::foo *')}} +} + +// PR9548 - "no known conversion from 'vector<string>' to 'vector<string>'" +// vector<string> refers to two different types here. Make sure the message +// gives a way to tell them apart. +class versa_string; +typedef versa_string string; + +namespace std {template <typename T> class vector;} +using std::vector; + +void f(vector<string> v); // expected-note {{candidate function not viable: no known conversion from 'vector<string>' (aka 'std::vector<std::basic_string>') to 'vector<string>' (aka 'std::vector<versa_string>') for 1st argument}} + +namespace std { + class basic_string; + typedef basic_string string; + template <typename T> class vector {}; + void g() { + vector<string> v; + f(v); // expected-error{{no matching function for call to 'f'}} + } +} diff --git a/test/Misc/include-stack-for-note-flag.cpp b/test/Misc/include-stack-for-note-flag.cpp index 328999d..cfec506 100644 --- a/test/Misc/include-stack-for-note-flag.cpp +++ b/test/Misc/include-stack-for-note-flag.cpp @@ -18,11 +18,11 @@ bool macro(int x, int y) { // STACK: note: candidate function not viable // STACK: error: comparison between pointer and integer // STACK: In file included from -// STACK: note: instantiated from: +// STACK: note: expanded from: // STACKLESS: error: no matching function for call to 'foo' // STACKLESS-NOT: In file included from // STACKLESS: note: candidate function not viable // STACKLESS: error: comparison between pointer and integer // STACKLESS-NOT: In file included from -// STACKLESS: note: instantiated from: +// STACKLESS: note: expanded from: diff --git a/test/Misc/macro-backtrace-limit.c b/test/Misc/macro-backtrace-limit.c index 1e512fe..ee73c61 100644 --- a/test/Misc/macro-backtrace-limit.c +++ b/test/Misc/macro-backtrace-limit.c @@ -17,16 +17,16 @@ void f(int *ip, float *fp) { // CHECK: macro-backtrace-limit.c:31:7: warning: comparison of distinct pointer types ('int *' and 'float *') // CHECK: if (M12(ip, fp)) { } - // CHECK: macro-backtrace-limit.c:15:19: note: instantiated from: + // CHECK: macro-backtrace-limit.c:15:19: note: expanded from: // CHECK: #define M12(A, B) M11(A, B) - // CHECK: macro-backtrace-limit.c:14:19: note: instantiated from: + // CHECK: macro-backtrace-limit.c:14:19: note: expanded from: // CHECK: #define M11(A, B) M10(A, B) - // CHECK: note: (skipping 7 contexts in backtrace; use -fmacro-backtrace-limit=0 to see all) - // CHECK: macro-backtrace-limit.c:6:18: note: instantiated from: + // CHECK: note: (skipping 7 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all) + // CHECK: macro-backtrace-limit.c:6:18: note: expanded from: // CHECK: #define M3(A, B) M2(A, B) - // CHECK: macro-backtrace-limit.c:5:18: note: instantiated from: + // CHECK: macro-backtrace-limit.c:5:18: note: expanded from: // CHECK: #define M2(A, B) M1(A, B) - // CHECK: macro-backtrace-limit.c:4:23: note: instantiated from: + // CHECK: macro-backtrace-limit.c:4:23: note: expanded from: // CHECK: #define M1(A, B) ((A) < (B)) if (M12(ip, fp)) { } } diff --git a/test/PCH/Inputs/arc.h b/test/PCH/Inputs/arc.h new file mode 100644 index 0000000..793fc64 --- /dev/null +++ b/test/PCH/Inputs/arc.h @@ -0,0 +1,20 @@ +// Header for Objective-C ARC-related PCH tests + +typedef const void *CFTypeRef; +typedef const struct __CFString *CFStringRef; + +CFTypeRef CFCreateSomething(); +CFStringRef CFCreateString(); +CFTypeRef CFGetSomething(); +CFStringRef CFGetString(); + +@interface NSString +@end + +id CreateSomething(); +NSString *CreateNSString(); + +typedef int array0[sizeof((__bridge id)CFCreateSomething())]; +typedef int array1[sizeof((__bridge CFTypeRef)CreateSomething())]; + + diff --git a/test/PCH/Inputs/typo.hpp b/test/PCH/Inputs/typo.hpp new file mode 100644 index 0000000..c811595 --- /dev/null +++ b/test/PCH/Inputs/typo.hpp @@ -0,0 +1,8 @@ +namespace boost { + template<typename F> class function {}; + + namespace graph { + template<typename V, typename E> class adjacency_list { }; + }; +} + diff --git a/test/PCH/arc.m b/test/PCH/arc.m new file mode 100644 index 0000000..6f7b870 --- /dev/null +++ b/test/PCH/arc.m @@ -0,0 +1,9 @@ +// Test this without pch. +// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-arc -include %S/Inputs/arc.h -fsyntax-only -emit-llvm -o - %s + +// Test with pch. +// RUN: %clang_cc1 -emit-pch -fblocks -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-arc -x objective-c-header -o %t %S/Inputs/arc.h +// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-arc -include-pch %t -fsyntax-only -emit-llvm -o - %s + +array0 a0; +array1 a1; diff --git a/test/PCH/typo.cpp b/test/PCH/typo.cpp new file mode 100644 index 0000000..4c88614 --- /dev/null +++ b/test/PCH/typo.cpp @@ -0,0 +1,17 @@ + +// In header: expected-note{{ 'boost::function' declared here}} + + +// In header: expected-note{{ 'boost::graph::adjacency_list' declared here}} + + + +adjacent_list<int, int> g; // expected-error{{no template named 'adjacent_list'; did you mean 'boost::graph::adjacency_list'?}} +Function<int(int)> f; // expected-error{{no template named 'Function'; did you mean 'boost::function'?}} + +// Without PCH +// RUN: %clang_cc1 -include %S/Inputs/typo.hpp -verify %s + +// With PCH +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/Inputs/typo.hpp +// RUN: %clang_cc1 -include-pch %t -verify %s diff --git a/test/PCH/variables.c b/test/PCH/variables.c index 58fd8ae..9f90b37 100644 --- a/test/PCH/variables.c +++ b/test/PCH/variables.c @@ -1,18 +1,40 @@ // Test this without pch. -// RUN: %clang_cc1 -include %S/variables.h -fsyntax-only -verify %s +// RUN: %clang_cc1 -include %s -fsyntax-only -verify %s // Test with pch. -// RUN: %clang_cc1 -emit-pch -o %t %S/variables.h +// RUN: %clang_cc1 -emit-pch -o %t %s // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +#ifndef HEADER +#define HEADER + +extern float y; +extern int *ip, x; + +float z; // expected-note{{previous}} + +int z2 = 17; // expected-note{{previous}} + +#define MAKE_HAPPY(X) X##Happy +int MAKE_HAPPY(Very); // expected-note{{previous definition is here}} + +#define A_MACRO_IN_THE_PCH 492 +#define FUNCLIKE_MACRO(X, Y) X ## Y + +#define PASTE2(x,y) x##y +#define PASTE1(x,y) PASTE2(x,y) +#define UNIQUE(x) PASTE1(x,__COUNTER__) + +int UNIQUE(a); // a0 +int UNIQUE(a); // a1 + +#else + int *ip2 = &x; float *fp = &ip; // expected-warning{{incompatible pointer types}} -// FIXME:variables.h expected-note{{previous}} double z; // expected-error{{redefinition}} -// FIXME:variables.h expected-note{{previous}} int z2 = 18; // expected-error{{redefinition}} double VeryHappy; // expected-error{{redefinition}} -// FIXME:variables.h expected-note{{previous definition is here}} int Q = A_MACRO_IN_THE_PCH; @@ -21,3 +43,5 @@ int R = FUNCLIKE_MACRO(A_MACRO_, IN_THE_PCH); int UNIQUE(a); // a2 int *Arr[] = { &a0, &a1, &a2 }; + +#endif diff --git a/test/PCH/variables.h b/test/PCH/variables.h index c937429..23d2cd3 100644 --- a/test/PCH/variables.h +++ b/test/PCH/variables.h @@ -23,4 +23,3 @@ int MAKE_HAPPY(Very); int UNIQUE(a); // a0 int UNIQUE(a); // a1 - diff --git a/test/Parser/MicrosoftExtensions.c b/test/Parser/MicrosoftExtensions.c index 2f5da52..2b8451b 100644 --- a/test/Parser/MicrosoftExtensions.c +++ b/test/Parser/MicrosoftExtensions.c @@ -60,5 +60,5 @@ void ms_intrinsics(int a) { __noop(); __assume(a); - + __debugbreak(); } diff --git a/test/Parser/parenthesis-balance.cpp b/test/Parser/parenthesis-balance.cpp new file mode 100644 index 0000000..5bfa639 --- /dev/null +++ b/test/Parser/parenthesis-balance.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +int f(int x) { + if (int foo = f(bar)) {} // expected-error{{use of undeclared identifier 'bar'}} + while (int foo = f(bar)) {} // expected-error{{use of undeclared identifier 'bar'}} + for (int foo = f(bar);;) {} // expected-error{{use of undeclared identifier 'bar'}} + + int bar; + if (int foo = f(bar)) {} + while (int foo = f(bar)) {} + for (int foo = f(bar);;) {} + + return 0; +} + diff --git a/test/Parser/recovery.c b/test/Parser/recovery.c index 1b33f02..0747aec 100644 --- a/test/Parser/recovery.c +++ b/test/Parser/recovery.c @@ -74,6 +74,11 @@ void foo() { X = 4 // expected-error{{expected ';' after expression}} } +// rdar://9045701 +void test9045701(int x) { +#define VALUE 0 + x = VALUE // expected-error{{expected ';' after expression}} +} // rdar://7980651 typedef int intptr_t; // expected-note {{'intptr_t' declared here}} @@ -84,3 +89,12 @@ void test1(void) { int y = x; int z = y; } + +void test2(int x) { +#define VALUE2 VALUE+VALUE +#define VALUE3 VALUE+0 +#define VALUE4(x) x+0 + x = VALUE2 // expected-error{{expected ';' after expression}} + x = VALUE3 // expected-error{{expected ';' after expression}} + x = VALUE4(0) // expected-error{{expected ';' after expression}} +} diff --git a/test/Parser/switch-recovery.cpp b/test/Parser/switch-recovery.cpp index 0e4dcfa..a1df4261 100644 --- a/test/Parser/switch-recovery.cpp +++ b/test/Parser/switch-recovery.cpp @@ -156,3 +156,17 @@ void test12(int x) { } } } + +void missing_statement_case(int x) { + switch (x) { + case 1: + case 0: // expected-error {{label at end of compound statement: expected statement}} + } +} + +void missing_statement_default(int x) { + switch (x) { + case 0: + default: // expected-error {{label at end of compound statement: expected statement}} + } +} diff --git a/test/Preprocessor/include-directive2.c b/test/Preprocessor/include-directive2.c index 5f1ee3c..b1a9940 100644 --- a/test/Preprocessor/include-directive2.c +++ b/test/Preprocessor/include-directive2.c @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -ffreestanding -Eonly -verify %s -# define HEADER <float.h> +# define HEADER <stdarg.h> # include HEADER diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c index b0515b3..f0920c9 100644 --- a/test/Preprocessor/init.c +++ b/test/Preprocessor/init.c @@ -15,7 +15,7 @@ // CXX0X:#define __GXX_EXPERIMENTAL_CXX0X__ 1 // CXX0X:#define __GXX_RTTI 1 // CXX0X:#define __GXX_WEAK__ 1 -// CXX0X:#define __cplusplus 199711L +// CXX0X:#define __cplusplus 201103L // CXX0X:#define __private_extern__ extern // // diff --git a/test/Preprocessor/macro_paste_bad.c b/test/Preprocessor/macro_paste_bad.c index 2af0173..0a028a4 100644 --- a/test/Preprocessor/macro_paste_bad.c +++ b/test/Preprocessor/macro_paste_bad.c @@ -32,4 +32,3 @@ XX // expected-error {{attempt to use a poisoned identifier}} #define VA __VA_ ## ARGS__ int VA; // expected-warning {{__VA_ARGS__ can only appear in the expansion of a C99 variadic macro}} - diff --git a/test/Preprocessor/macro_paste_hashhash.c b/test/Preprocessor/macro_paste_hashhash.c index e7993cc..f4b03be 100644 --- a/test/Preprocessor/macro_paste_hashhash.c +++ b/test/Preprocessor/macro_paste_hashhash.c @@ -1,7 +1,11 @@ -// RUN: %clang_cc1 -E %s | grep '^"x ## y";$' +// RUN: %clang_cc1 -E %s | FileCheck %s #define hash_hash # ## # #define mkstr(a) # a #define in_between(a) mkstr(a) #define join(c, d) in_between(c hash_hash d) +// CHECK: "x ## y"; join(x, y); +#define FOO(x) A x B +// CHECK: A ## B; +FOO(##); diff --git a/test/Preprocessor/macro_paste_simple.c b/test/Preprocessor/macro_paste_simple.c index 563d7f4..0e62ba4 100644 --- a/test/Preprocessor/macro_paste_simple.c +++ b/test/Preprocessor/macro_paste_simple.c @@ -1,5 +1,14 @@ -// RUN: %clang_cc1 %s -E | grep "barbaz123" +// RUN: %clang_cc1 %s -E | FileCheck %s #define FOO bar ## baz ## 123 -FOO +// CHECK: A: barbaz123 +A: FOO + +// PR9981 +#define M1(A) A +#define M2(X) X +B: M1(M2(##)) + +// CHECK: B: ## + diff --git a/test/Preprocessor/pragma_diagnostic_output.c b/test/Preprocessor/pragma_diagnostic_output.c new file mode 100644 index 0000000..e847107 --- /dev/null +++ b/test/Preprocessor/pragma_diagnostic_output.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -E %s | FileCheck %s +// CHECK: #pragma GCC diagnostic warning "-Wall" +#pragma GCC diagnostic warning "-Wall" +// CHECK: #pragma GCC diagnostic ignored "-Wall" +#pragma GCC diagnostic ignored "-Wall" +// CHECK: #pragma GCC diagnostic error "-Wall" +#pragma GCC diagnostic error "-Wall" +// CHECK: #pragma GCC diagnostic fatal "-Wall" +#pragma GCC diagnostic fatal "-Wall" +// CHECK: #pragma GCC diagnostic push +#pragma GCC diagnostic push +// CHECK: #pragma GCC diagnostic pop +#pragma GCC diagnostic pop + +// CHECK: #pragma clang diagnostic warning "-Wall" +#pragma clang diagnostic warning "-Wall" +// CHECK: #pragma clang diagnostic ignored "-Wall" +#pragma clang diagnostic ignored "-Wall" +// CHECK: #pragma clang diagnostic error "-Wall" +#pragma clang diagnostic error "-Wall" +// CHECK: #pragma clang diagnostic fatal "-Wall" +#pragma clang diagnostic fatal "-Wall" +// CHECK: #pragma clang diagnostic push +#pragma clang diagnostic push +// CHECK: #pragma clang diagnostic pop +#pragma clang diagnostic pop diff --git a/test/Preprocessor/warn-macro-unused.c b/test/Preprocessor/warn-macro-unused.c index 8a6d7c2..c33aeb5 100644 --- a/test/Preprocessor/warn-macro-unused.c +++ b/test/Preprocessor/warn-macro-unused.c @@ -1,5 +1,10 @@ // RUN: %clang_cc1 %s -Wunused-macros -Dfoo -Dfoo -verify +#include "warn-macro-unused.h" + #define unused // expected-warning {{macro is not used}} #define unused unused + +// rdar://9745065 +#undef unused_from_header // no warning diff --git a/test/Preprocessor/warn-macro-unused.h b/test/Preprocessor/warn-macro-unused.h new file mode 100644 index 0000000..0c2c267 --- /dev/null +++ b/test/Preprocessor/warn-macro-unused.h @@ -0,0 +1 @@ +#define unused_from_header diff --git a/test/Sema/arm-neon-types.c b/test/Sema/arm-neon-types.c index 1e8c9bf..4be83da 100644 --- a/test/Sema/arm-neon-types.c +++ b/test/Sema/arm-neon-types.c @@ -18,3 +18,10 @@ float32x2_t test3(uint32x2_t x) { // removed when that is fixed. return vcvt_n_f32_u32(x, 0); // expected-error {{argument should be a value from 1 to 32}} expected-error {{incompatible result type}} } + +typedef signed int vSInt32 __attribute__((__vector_size__(16))); +int32x4_t test4(int32x4_t a, vSInt32 b) { + a += b; + b += a; + return b += a; +} diff --git a/test/Sema/asm.c b/test/Sema/asm.c index d8161c8..359431c 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -5,7 +5,7 @@ void f() { asm ("foo\n" : : "a" (i + 2)); asm ("foo\n" : : "a" (f())); // expected-error {{invalid type 'void' in asm input}} - + asm ("foo\n" : "=a" (f())); // expected-error {{invalid lvalue in asm output}} asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}} @@ -21,7 +21,7 @@ void clobbers() { asm ("nop" : : : "0", "%0", "#0"); asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}} asm ("nop" : : : "52"); - asm ("nop" : : : "53"); // expected-error {{unknown register name '53' in asm}} + asm ("nop" : : : "54"); // expected-error {{unknown register name '54' in asm}} asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}} asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}} } @@ -47,7 +47,7 @@ void test4(const volatile void *addr) // <rdar://problem/6512595> void test5() { - asm("nop" : : "X" (8)); + asm("nop" : : "X" (8)); } // PR3385 @@ -56,7 +56,7 @@ void test6(long i) { } void asm_string_tests(int i) { - asm("%!"); // simple asm string, %! is not an error. + asm("%!"); // simple asm string, %! is not an error. asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}} asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}} @@ -64,7 +64,7 @@ void asm_string_tests(int i) { asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}} asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}} asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}} - + // PR3258 asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}} asm("%1" : "+r"(i)); // ok, referring to input. @@ -113,3 +113,13 @@ void test11(void) { _Bool b; asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L)); } + +void test12(void) { + register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}} +} + +// PR10223 +void test13(void) { + void *esp; + __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}} +} diff --git a/test/Sema/attr-deprecated.c b/test/Sema/attr-deprecated.c index b26171b..eeef0d7 100644 --- a/test/Sema/attr-deprecated.c +++ b/test/Sema/attr-deprecated.c @@ -37,6 +37,8 @@ struct foo { void test1(struct foo *F) { ++F->x; // expected-warning {{'x' is deprecated}} + struct foo f1 = { .x = 17 }; // expected-warning {{'x' is deprecated}} + struct foo f2 = { 17 }; // expected-warning {{'x' is deprecated}} } typedef struct foo foo_dep __attribute__((deprecated)); diff --git a/test/Sema/attr-naked.c b/test/Sema/attr-naked.c index 1ebd784..d9fa542 100644 --- a/test/Sema/attr-naked.c +++ b/test/Sema/attr-naked.c @@ -2,6 +2,10 @@ int a __attribute__((naked)); // expected-warning {{'naked' attribute only applies to functions}} +__attribute__((naked)) int t0(void) { + __asm__ volatile("mov r0, #0"); +} + void t1() __attribute__((naked)); void t2() __attribute__((naked(2))); // expected-error {{attribute takes no arguments}} diff --git a/test/Sema/attr-unavailable-message.c b/test/Sema/attr-unavailable-message.c index a1e047c..9f663fc 100644 --- a/test/Sema/attr-unavailable-message.c +++ b/test/Sema/attr-unavailable-message.c @@ -16,3 +16,13 @@ void test_foo() { } char test2[__has_feature(attribute_unavailable_with_message) ? 1 : -1]; + +// rdar://9623855 +void unavail(void) __attribute__((__unavailable__)); +void unavail(void) { + // No complains inside an unavailable function. + int ir = foo(1); + double dr = dfoo(1.0); + void (*fp)() = &bar; + double (*fp4)(double) = dfoo; +} diff --git a/test/Sema/attr-weak.c b/test/Sema/attr-weak.c index 41c9fd7..adedf12 100644 --- a/test/Sema/attr-weak.c +++ b/test/Sema/attr-weak.c @@ -12,3 +12,7 @@ struct __attribute__((weak)) s0 {}; // expected-warning {{'weak' attribute only struct __attribute__((weak_import)) s1 {}; // expected-warning {{'weak_import' attribute only applies to variables and functions}} static int x __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} + +// rdar://9538608 +int C; // expected-note {{previous definition is here}} +extern int C __attribute__((weak_import)); // expected-warning {{an already-declared variable is made a weak_import declaration}} diff --git a/test/Sema/bitfield.c b/test/Sema/bitfield.c index 49c1c7d..a1ce894 100644 --- a/test/Sema/bitfield.c +++ b/test/Sema/bitfield.c @@ -32,6 +32,7 @@ int y; struct {unsigned x : 2;} x2; __typeof__((x.x+=1)+1) y; +__typeof__((0,x.x)+1) y; __typeof__(x.x<<1) y; int y; diff --git a/test/Sema/compare.c b/test/Sema/compare.c index 5221b17..cd973d4 100644 --- a/test/Sema/compare.c +++ b/test/Sema/compare.c @@ -312,3 +312,18 @@ int rdar8511238() { return 0; return 20; } + +// PR10336 +int test9(int sv, unsigned uv, long slv) { + return sv == (uv ^= slv); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}} +} + +void test10(void) { + int si; + unsigned int ui; + long sl; + + _Bool b; + b = (si == (ui = sl)); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}} + b = (si == (ui = sl&15)); +} diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index 56c429c..bdb40ae 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -36,7 +36,7 @@ int g17[(3?:1) - 2]; EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1); struct s { - int a[(int)-1.0f]; // expected-error {{array size is negative}} + int a[(int)-1.0f]; // expected-error {{'a' declared as an array with a negative size}} }; EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1)); diff --git a/test/Sema/conversion-64-32.c b/test/Sema/conversion-64-32.c index aa72829..112e995 100644 --- a/test/Sema/conversion-64-32.c +++ b/test/Sema/conversion-64-32.c @@ -3,3 +3,13 @@ int test0(long v) { return v; // expected-warning {{implicit conversion loses integer precision}} } + + +// rdar://9546171 +typedef int int4 __attribute__ ((vector_size(16))); +typedef long long long2 __attribute__((__vector_size__(16))); + +int4 test1(long2 a) { + int4 v127 = a; // no warning. + return v127; +} diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index 1eaf708..03204c6 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -335,3 +335,11 @@ void test_8559831(enum E8559831b value_a, E8559831c value_c) { enum E8559831a a3 = value_d; a3 = value_d; } + +void test26(int si, long sl) { + si = sl % sl; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}} + si = sl % si; + si = si % sl; + si = si / sl; + si = sl / si; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}} +} diff --git a/test/Sema/ext_vector_casts.c b/test/Sema/ext_vector_casts.c index 75d41ca..848ec1f 100644 --- a/test/Sema/ext_vector_casts.c +++ b/test/Sema/ext_vector_casts.c @@ -37,7 +37,7 @@ static void test() { vec4 /= 5.2f; vec4 %= 4; // expected-error {{invalid operands to binary expression ('float4' and 'int')}} ivec4 %= 4; - ivec4 += vec4; // expected-error {{can't convert between vector values of different size ('float4' and 'int4')}} + ivec4 += vec4; // expected-error {{can't convert between vector values of different size ('int4' and 'float4')}} ivec4 += (int4)vec4; ivec4 -= ivec4; ivec4 |= ivec4; diff --git a/test/Sema/extern-redecl.c b/test/Sema/extern-redecl.c index 067e3c2..c176725 100644 --- a/test/Sema/extern-redecl.c +++ b/test/Sema/extern-redecl.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only %s +// RUN: %clang_cc1 -fsyntax-only -verify %s // rdar: // 8125274 static int a16[]; // expected-warning {{tentative array definition assumed to have one element}} @@ -7,3 +7,16 @@ void f16(void) { extern int a16[]; } + +// PR10013: Scope of extern declarations extend past enclosing block +extern int PR10013_x; +int PR10013(void) { + int *PR10013_x = 0; + { + extern int PR10013_x; + extern int PR10013_x; + } + + return PR10013_x; // expected-warning{{incompatible pointer to integer conversion}} +} + diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index c78095a..b47d3ca 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -358,3 +358,17 @@ void pr9314() { printf(__func__); // no-warning } +int printf(const char * restrict, ...) __attribute__((__format__ (__printf__, 1, 2))); + +void rdar9612060(void) { + printf("%s", 2); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}} +} + +void check_char(unsigned char x, signed char y) { + printf("%c", y); // no-warning + printf("%hhu", x); // no-warning + printf("%hhi", y); // no-warning + printf("%hhi", x); // no-warning + printf("%c", x); // no-warning + printf("%hhu", y); // no-warning +} diff --git a/test/Sema/i-c-e.c b/test/Sema/i-c-e.c index 4d7007c..1aac51e 100644 --- a/test/Sema/i-c-e.c +++ b/test/Sema/i-c-e.c @@ -1,4 +1,4 @@ -// RUN: %clang %s -ffreestanding -fsyntax-only -Xclang -verify -pedantic -fpascal-strings +// RUN: %clang %s -ffreestanding -fsyntax-only -Xclang -verify -pedantic -fpascal-strings -std=c99 #include <stdint.h> #include <limits.h> diff --git a/test/Sema/incomplete-decl.c b/test/Sema/incomplete-decl.c index e5b6d5f..0214a0c 100644 --- a/test/Sema/incomplete-decl.c +++ b/test/Sema/incomplete-decl.c @@ -22,7 +22,7 @@ void func() { } int h[]; // expected-warning {{tentative array definition assumed to have one element}} -int (*i)[] = &h+1; // expected-error {{arithmetic on pointer to incomplete type 'int (*)[]'}} +int (*i)[] = &h+1; // expected-error {{arithmetic on a pointer to an incomplete type 'int []'}} struct bar j = {1}; // expected-error {{variable has incomplete type 'struct bar'}} \ expected-note {{forward declaration of 'struct bar'}} diff --git a/test/Sema/inline-redef.c b/test/Sema/inline-redef.c new file mode 100644 index 0000000..4a46e11 --- /dev/null +++ b/test/Sema/inline-redef.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -std=gnu89 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s + +#if __STDC_VERSION__ >= 199901 +#define GNU_INLINE __attribute((__gnu_inline__)) +#else +#define GNU_INLINE +#endif + +// PR5253 +// rdar://9559708 (same extension in C99 mode) +// GNU Extension: check that we can redefine an extern inline function +GNU_INLINE extern inline int f(int a) {return a;} +int f(int b) {return b;} // expected-note{{previous definition is here}} +// And now check that we can't redefine a normal function +int f(int c) {return c;} // expected-error{{redefinition of 'f'}} + +// Check that we can redefine an extern inline function as a static function +GNU_INLINE extern inline int g(int a) {return a;} +static int g(int b) {return b;} + +// Check that we ensure the types of the two definitions are the same +GNU_INLINE extern inline int h(int a) {return a;} // expected-note{{previous definition is here}} +int h(short b) {return b;} // expected-error{{conflicting types for 'h'}} diff --git a/test/Sema/inline.c b/test/Sema/inline.c index b4795d3..3c99f24 100644 --- a/test/Sema/inline.c +++ b/test/Sema/inline.c @@ -1,22 +1,6 @@ -// RUN: %clang_cc1 -std=gnu89 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s // Check that we don't allow illegal uses of inline inline int a; // expected-error{{'inline' can only appear on functions}} typedef inline int b; // expected-error{{'inline' can only appear on functions}} int d(inline int a); // expected-error{{'inline' can only appear on functions}} - -// PR5253 -// GNU Extension: check that we can redefine an extern inline function -extern inline int f(int a) {return a;} -int f(int b) {return b;} // expected-note{{previous definition is here}} -// And now check that we can't redefine a normal function -int f(int c) {return c;} // expected-error{{redefinition of 'f'}} - -// Check that we can redefine an extern inline function as a static function -extern inline int g(int a) {return a;} -static int g(int b) {return b;} - -// Check that we ensure the types of the two definitions are the same -extern inline int h(int a) {return a;} // expected-note{{previous definition is here}} -int h(short b) {return b;} // expected-error{{conflicting types for 'h'}} - diff --git a/test/Sema/no-format-y2k-turnsoff-format.c b/test/Sema/no-format-y2k-turnsoff-format.c new file mode 100644 index 0000000..bd06e50 --- /dev/null +++ b/test/Sema/no-format-y2k-turnsoff-format.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -Wformat -Wno-format-y2k +// rdar://9504680 + +void foo(const char *, ...) __attribute__((__format__ (__printf__, 1, 2))); + +void bar(unsigned int a) { + foo("%s", a); // expected-warning {{conversion specifies type 'char *' but the argument has type 'unsigned int'}} +} + diff --git a/test/Sema/nonnull.c b/test/Sema/nonnull.c new file mode 100644 index 0000000..cea8e3d --- /dev/null +++ b/test/Sema/nonnull.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only %s +// rdar://9584012 + +typedef struct { + char *str; +} Class; + +typedef union { + Class *object; +} Instance __attribute__((transparent_union)); + +__attribute__((nonnull(1))) void Class_init(Instance this, char *str) { + this.object->str = str; +} + +int main(void) { + Class *obj; + Class_init(0, "Hello World"); // expected-warning {{null passed to a callee which requires a non-null argument}} + Class_init(obj, "Hello World"); +} + diff --git a/test/Sema/paren-list-expr-type.cpp b/test/Sema/paren-list-expr-type.cpp new file mode 100644 index 0000000..ad5b7fb --- /dev/null +++ b/test/Sema/paren-list-expr-type.cpp @@ -0,0 +1,17 @@ +// RUN: %clang -cc1 -ast-dump %s | not grep NULL +// Makes sure that we don't introduce null types when handling +// ParenListExpr. + +template<typename T> class X { void f() { X x(*this); } }; + +template<typename T> class Y { Y() : t(1) {} T t; }; + +template<typename T> class Z { Z() : b(true) {} const bool b; }; + +template<typename T> class A : public Z<T> { A() : Z<T>() {} }; + +class C {}; +template<typename T> class D : public C { D(): C() {} }; + +void f() { (int)(1, 2); } + diff --git a/test/Sema/parentheses.c b/test/Sema/parentheses.c index fa3c3c2..13ea3ec 100644 --- a/test/Sema/parentheses.c +++ b/test/Sema/parentheses.c @@ -26,6 +26,12 @@ void bitwise_rel(unsigned i) { (void)(i == 1 | i == 2 | i == 3); (void)(i != 1 & i != 2 & i != 3); + (void)(i & i | i); // expected-warning {{'&' within '|'}} \ + // expected-note {{place parentheses around the '&' expression to silence this warning}} + + (void)(i | i & i); // expected-warning {{'&' within '|'}} \ + // expected-note {{place parentheses around the '&' expression to silence this warning}} + (void)(i || i && i); // expected-warning {{'&&' within '||'}} \ // expected-note {{place parentheses around the '&&' expression to silence this warning}} @@ -42,21 +48,21 @@ void bitwise_rel(unsigned i) { _Bool someConditionFunc(); void conditional_op(int x, int y, _Bool b) { - (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{?: has lower precedence than +}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the + expression to silence this warning}} + (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '+' expression to silence this warning}} - (void)(x - b ? 1 : 2); // expected-warning {{?: has lower precedence than -}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the - expression to silence this warning}} + (void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '-' expression to silence this warning}} - (void)(x * (x == y) ? 1 : 2); // expected-warning {{?: has lower precedence than *}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the * expression to silence this warning}} + (void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '*' expression to silence this warning}} - (void)(x / !x ? 1 : 2); // expected-warning {{?: has lower precedence than /}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the / expression to silence this warning}} + (void)(x / !x ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '/'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '/' expression to silence this warning}} (void)(x % 2 ? 1 : 2); // no warning diff --git a/test/Sema/parentheses.cpp b/test/Sema/parentheses.cpp index a25f2a0..252455d 100644 --- a/test/Sema/parentheses.cpp +++ b/test/Sema/parentheses.cpp @@ -4,17 +4,17 @@ bool someConditionFunc(); void conditional_op(int x, int y, bool b) { - (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{?: has lower precedence than +}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the + expression to silence this warning}} + (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '+' expression to silence this warning}} - (void)(x - b ? 1 : 2); // expected-warning {{?: has lower precedence than -}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the - expression to silence this warning}} + (void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '-' expression to silence this warning}} - (void)(x * (x == y) ? 1 : 2); // expected-warning {{?: has lower precedence than *}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the * expression to silence this warning}} + (void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '*' expression to silence this warning}} } class Stream { @@ -25,7 +25,21 @@ public: }; void f(Stream& s, bool b) { - (void)(s << b ? "foo" : "bar"); // expected-warning {{?: has lower precedence than <<}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the << expression to silence this warning}} + (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '<<' expression to silence this warning}} +} + +struct S { + operator int() { return 42; } + friend S operator+(const S &lhs, bool) { return S(); } +}; + +void test(S *s, bool (S::*m_ptr)()) { + (void)(*s + true ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '+'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '+' expression to silence this warning}} + + // Don't crash on unusual member call expressions. + (void)((s->*m_ptr)() ? "foo" : "bar"); } diff --git a/test/Sema/pointer-addition.c b/test/Sema/pointer-addition.c index aa425a7..21ce63b 100644 --- a/test/Sema/pointer-addition.c +++ b/test/Sema/pointer-addition.c @@ -3,18 +3,19 @@ typedef struct S S; // expected-note 3 {{forward declaration of 'struct S'}} void a(S* b, void* c) { void (*fp)(int) = 0; - b++; // expected-error {{arithmetic on pointer to incomplete type}} - b += 1; // expected-error {{arithmetic on pointer to incomplete type}} - c++; // expected-warning {{use of GNU void* extension}} - c += 1; // expected-warning {{use of GNU void* extension}} - c--; // expected-warning {{use of GNU void* extension}} - c -= 1; // expected-warning {{use of GNU void* extension}} - (void) c[1]; // expected-warning {{use of GNU void* extension}} - b = 1+b; // expected-error {{arithmetic on pointer to incomplete type}} + b++; // expected-error {{arithmetic on a pointer to an incomplete type}} + b += 1; // expected-error {{arithmetic on a pointer to an incomplete type}} + c++; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} + c += 1; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} + c--; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} + c -= 1; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} + (void) c[1]; // expected-warning {{subscript of a pointer to void is a GNU extension}} + b = 1+b; // expected-error {{arithmetic on a pointer to an incomplete type}} /* The next couple tests are only pedantic warnings in gcc */ void (*d)(S*,void*) = a; - d += 1; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}} - d++; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}} - d--; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}} - d -= 1; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}} + d += 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} + d++; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} + d--; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} + d -= 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} + (void)(1 + d); // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} } diff --git a/test/Sema/pointer-subtract-compat.c b/test/Sema/pointer-subtract-compat.c index 70340c6..b801f81 100644 --- a/test/Sema/pointer-subtract-compat.c +++ b/test/Sema/pointer-subtract-compat.c @@ -7,5 +7,5 @@ int a(char* a, rchar* b) { // <rdar://problem/6520707> void f0(void (*fp)(void)) { - int x = fp - fp; // expected-warning{{arithmetic on pointer to function type 'void (*)(void)' is a GNU extension}} + int x = fp - fp; // expected-warning{{arithmetic on pointers to the function type 'void (void)' is a GNU extension}} } diff --git a/test/Sema/shift.c b/test/Sema/shift.c index 28407be..142d83c 100644 --- a/test/Sema/shift.c +++ b/test/Sema/shift.c @@ -38,7 +38,7 @@ void test() { int i; i = 1 << (WORD_BIT - 2); i = 2 << (WORD_BIT - 1); // expected-warning {{bits to represent, but 'int' only has}} - i = 1 << (WORD_BIT - 1); // expected-warning {{overrides the sign bit of the shift expression}} + i = 1 << (WORD_BIT - 1); // expected-warning {{sets the sign bit of the shift expression}} i = -1 << (WORD_BIT - 1); i = 0 << (WORD_BIT - 1); i = (char)1 << (WORD_BIT - 2); diff --git a/test/Sema/sign-conversion.c b/test/Sema/sign-conversion.c new file mode 100644 index 0000000..4b1ee75 --- /dev/null +++ b/test/Sema/sign-conversion.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wsign-conversion %s + +// PR9345: make a subgroup of -Wconversion for signedness changes + +void test(int x) { + unsigned t0 = x; // expected-warning {{implicit conversion changes signedness}} + unsigned t1 = (t0 == 5 ? x : 0); // expected-warning {{operand of ? changes signedness}} +} diff --git a/test/Sema/struct-decl.c b/test/Sema/struct-decl.c index e1c7073..6070e87 100644 --- a/test/Sema/struct-decl.c +++ b/test/Sema/struct-decl.c @@ -6,7 +6,7 @@ struct bar { struct foo { char name[(int)&((struct bar *)0)->n]; - char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{array size is negative}} + char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{'name2' declared as an array with a negative size}} }; // PR3430 diff --git a/test/Sema/typecheck-binop.c b/test/Sema/typecheck-binop.c index 712dad2..be52d0b 100644 --- a/test/Sema/typecheck-binop.c +++ b/test/Sema/typecheck-binop.c @@ -7,15 +7,15 @@ int sub1(int *a, double *b) { } void *sub2(struct incomplete *P) { - return P-4; /* expected-error{{subtraction of pointer 'struct incomplete *' requires pointee to be a complete object type}} */ + return P-4; /* expected-error{{arithmetic on a pointer to an incomplete type 'struct incomplete'}} */ } void *sub3(void *P) { - return P-4; /* expected-warning{{GNU void* extension}} */ + return P-4; /* expected-warning{{arithmetic on a pointer to void is a GNU extension}} */ } int sub4(void *P, void *Q) { - return P-Q; /* expected-warning{{GNU void* extension}} */ + return P-Q; /* expected-warning{{arithmetic on pointers to void is a GNU extension}} */ } int sub5(void *P, int *Q) { diff --git a/test/Sema/typedef-variable-type.c b/test/Sema/typedef-variable-type.c index b805b1e..8a7ee8b 100644 --- a/test/Sema/typedef-variable-type.c +++ b/test/Sema/typedef-variable-type.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic -Wno-typedef-redefinition +// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic -Wno-typedef-redefinition -std=c99 // Make sure we accept a single typedef typedef int (*a)[!.0]; // expected-warning{{size of static array must be an integer constant expression}} diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c index b70a295..0caab3d 100644 --- a/test/Sema/uninit-variables.c +++ b/test/Sema/uninit-variables.c @@ -352,3 +352,18 @@ int test52(int a, int b) { } return x; // expected-warning {{variable 'x' may be uninitialized when used here}} } + +// This CFG caused the uninitialized values warning to inf-loop. +extern int PR10379_g(); +void PR10379_f(int *len) { + int new_len; // expected-note {{variable 'new_len' is declared here}} expected-note{{add initialization to silence this warning}} + for (int i = 0; i < 42 && PR10379_g() == 0; i++) { + if (PR10379_g() == 1) + continue; + if (PR10379_g() == 2) + PR10379_f(&new_len); + else if (PR10379_g() == 3) + PR10379_f(&new_len); + *len += new_len; // expected-warning {{variable 'new_len' may be uninitialized when used here}} + } +} diff --git a/test/Sema/varargs.c b/test/Sema/varargs.c index e399f89..07081ed 100644 --- a/test/Sema/varargs.c +++ b/test/Sema/varargs.c @@ -61,3 +61,18 @@ void f7(int a, ...) { __builtin_va_end(ap); } +void f8(int a, ...) { + __builtin_va_list ap; + __builtin_va_start(ap, a); + (void)__builtin_va_arg(ap, void); // expected-error {{second argument to 'va_arg' is of incomplete type 'void'}} + __builtin_va_end(ap); +} + +enum E { x = -1, y = 2, z = 10000 }; +void f9(__builtin_va_list args) +{ + (void)__builtin_va_arg(args, float); // expected-warning {{second argument to 'va_arg' is of promotable type 'float'}} + (void)__builtin_va_arg(args, enum E); // Don't warn here in C + (void)__builtin_va_arg(args, short); // expected-warning {{second argument to 'va_arg' is of promotable type 'short'}} + (void)__builtin_va_arg(args, char); // expected-warning {{second argument to 'va_arg' is of promotable type 'char'}} +} diff --git a/test/Sema/vla.c b/test/Sema/vla.c index ebf9b88..fd7a6bf 100644 --- a/test/Sema/vla.c +++ b/test/Sema/vla.c @@ -42,7 +42,7 @@ void f3() } // PR3663 -static const unsigned array[((2 * (int)((((4) / 2) + 1.0/3.0) * (4) - 1e-8)) + 1)]; // expected-warning {{size of static array must be an integer constant expression}} +static const unsigned array[((2 * (int)((((4) / 2) + 1.0/3.0) * (4) - 1e-8)) + 1)]; // expected-warning {{variable length array folded to constant array as an extension}} int a[*]; // expected-error {{star modifier used outside of function prototype}} int f4(int a[*][*]); @@ -53,7 +53,7 @@ int pr2044b; int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}} const int f5_ci = 1; -void f5() { char a[][f5_ci] = {""}; } // expected-error {{variable-sized object may not be initialized}} +void f5() { char a[][f5_ci] = {""}; } // expected-warning {{variable length array folded to constant array as an extension}} // PR5185 void pr5185(int a[*]); diff --git a/test/Sema/warn-sizeof-arrayarg.c b/test/Sema/warn-sizeof-arrayarg.c new file mode 100644 index 0000000..ba8a5fa --- /dev/null +++ b/test/Sema/warn-sizeof-arrayarg.c @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef int Arr[10]; + +typedef int trungl_int; + +void f(int a[10], Arr arr) { // \ +// expected-note {{declared here}} \ +// expected-note {{declared here}} \ +// expected-note {{declared here}} \ +// expected-note {{declared here}} + + /* Should warn. */ + (void)sizeof(a); // \ + // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'int [10]'}} + (void)sizeof((((a)))); // \ + // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'int [10]'}} + (void)sizeof a; // \ + // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'int [10]'}} + (void)sizeof arr; // \ + // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'Arr' (aka 'int [10]')}} + + /* Shouldn't warn. */ + int b[10]; + (void)sizeof b; + Arr brr; + (void)sizeof brr; + (void)sizeof(Arr); + (void)sizeof(int); +} diff --git a/test/Sema/x86-builtin-palignr.c b/test/Sema/x86-builtin-palignr.c index 83719a3..6e1303c 100644 --- a/test/Sema/x86-builtin-palignr.c +++ b/test/Sema/x86-builtin-palignr.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -verify -triple x86_64-pc-linux-gnu %s -// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -verify -triple i686-apple-darwin10 %s +// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -target-feature +mmx -verify -triple x86_64-pc-linux-gnu %s +// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -target-feature +mmx -verify -triple i686-apple-darwin10 %s #include <tmmintrin.h> diff --git a/test/SemaCXX/PR10243.cpp b/test/SemaCXX/PR10243.cpp new file mode 100644 index 0000000..9a58510 --- /dev/null +++ b/test/SemaCXX/PR10243.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +struct S; // expected-note 4{{forward declaration of 'S'}} + +struct T0 { + S s; // expected-error{{field has incomplete type 'S'}} + T0() = default; +}; + +struct T1 { + S s; // expected-error{{field has incomplete type 'S'}} + T1(T1&) = default; +}; + +struct T2 { + S s; // expected-error{{field has incomplete type 'S'}} + T2& operator=(T2&) = default; +}; + +struct T3 { + S s; // expected-error{{field has incomplete type 'S'}} + ~T3() = default; +}; diff --git a/test/SemaCXX/PR7410.cpp b/test/SemaCXX/PR7410.cpp new file mode 100644 index 0000000..6d2cda9 --- /dev/null +++ b/test/SemaCXX/PR7410.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct BaseReturn {}; + +struct Base { + virtual BaseReturn Foo() = 0; // expected-note{{overridden virtual function is here}} +}; +struct X {}; +struct Derived : Base { + X Foo(); // expected-error{{virtual function 'Foo' has a different return type ('X') than the function it overrides (which has return type 'BaseReturn')}} +}; + +Derived d; diff --git a/test/SemaCXX/PR9459.cpp b/test/SemaCXX/PR9459.cpp index dfb242d..2b96f34 100644 --- a/test/SemaCXX/PR9459.cpp +++ b/test/SemaCXX/PR9459.cpp @@ -3,5 +3,5 @@ // Don't crash. template<typename>struct ae_same; -template<typename>struct ts{}ap() +template<typename>struct ts{}ap() // expected-error {{expected ';' after struct}} expected-error {{requires a type specifier}} {ts<a>::ap<ae_same<int>::&ae_same<>>::p(a); }; // expected-error {{use of undeclared identifier 'a'}} diff --git a/test/SemaCXX/alignof-sizeof-reference.cpp b/test/SemaCXX/alignof-sizeof-reference.cpp index b517e43..93ba203 100644 --- a/test/SemaCXX/alignof-sizeof-reference.cpp +++ b/test/SemaCXX/alignof-sizeof-reference.cpp @@ -13,3 +13,9 @@ void f(int); // expected-note{{candidate function}} void g() { sizeof(&f); // expected-error{{cannot resolve overloaded function 'f' from context}} } + +template<typename T> void f_template(); // expected-note{{candidate function}} +template<typename T> void f_template(T*); // expected-note{{candidate function}} +void rdar9659191() { + (void)alignof(f_template<int>); // expected-error{{cannot resolve overloaded function 'f_template' from context}} +} diff --git a/test/SemaCXX/attr-unavailable.cpp b/test/SemaCXX/attr-unavailable.cpp index 5f34ed9..2d82668 100644 --- a/test/SemaCXX/attr-unavailable.cpp +++ b/test/SemaCXX/attr-unavailable.cpp @@ -28,3 +28,12 @@ void bar() { foo(); // expected-error {{call to unavailable function 'foo': not available - replaced}} } } + +void unavail(short* sp) __attribute__((__unavailable__)); +void unavail(short* sp) { + // No complains inside an unavailable function. + int &ir = foo(1); + double &dr = foo(1.0); + foo(sp); + foo(); +} diff --git a/test/SemaCXX/c99-variable-length-array.cpp b/test/SemaCXX/c99-variable-length-array.cpp index 98df1db..3f1d6a8 100644 --- a/test/SemaCXX/c99-variable-length-array.cpp +++ b/test/SemaCXX/c99-variable-length-array.cpp @@ -121,3 +121,12 @@ namespace PR8209 { (void)new vla_type; // expected-error{{variably}} } } + +namespace rdar8733881 { // rdar://8733881 + +static const int k_cVal3 = (int)(1000*0.2f); + int f() { + // Ok, fold to a constant size array as an extension. + char rgch[k_cVal3] = {0}; + } +} diff --git a/test/SemaCXX/condition.cpp b/test/SemaCXX/condition.cpp index 61d1762..3441bae 100644 --- a/test/SemaCXX/condition.cpp +++ b/test/SemaCXX/condition.cpp @@ -16,8 +16,9 @@ void test() { for (;s;) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}} - while (struct S {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} expected-note{{candidate constructor (the implicit copy constructor)}} - while (struct {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{not contextually convertible to 'bool'}} expected-note{{candidate constructor (the implicit copy constructor)}} + while (struct NewS *x=0) ; + while (struct S {} *x=0) ; // expected-error {{types may not be defined in conditions}} + while (struct {} *x=0) ; // expected-error {{types may not be defined in conditions}} switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}} \ // expected-warning{{enumeration value 'E' not handled in switch}} diff --git a/test/SemaCXX/conversion-function.cpp b/test/SemaCXX/conversion-function.cpp index aa47ae0..a7a1782 100644 --- a/test/SemaCXX/conversion-function.cpp +++ b/test/SemaCXX/conversion-function.cpp @@ -378,3 +378,17 @@ namespace PR9336 { generic_list<generic_list<int> > l; array<array<int> > a = l; } + +namespace PR8800 { + struct A; + struct C { + operator A&(); + }; + void f() { + C c; + A& a1(c); + A& a2 = c; + A& a3 = static_cast<A&>(c); + A& a4 = (A&)c; + } +} diff --git a/test/SemaCXX/copy-assignment.cpp b/test/SemaCXX/copy-assignment.cpp index f3dadc44..7aca9d6 100644 --- a/test/SemaCXX/copy-assignment.cpp +++ b/test/SemaCXX/copy-assignment.cpp @@ -99,15 +99,17 @@ void test() { // <rdar://problem/8315440>: Don't crash // FIXME: the recovery here is really bad. -namespace test1 { // expected-note{{to match this '{'}} - template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}} \ - // expected-note{{template parameter is declared here}} +namespace test1 { + template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}} A(UndeclaredType n) : X(n) {} // expected-error{{expected ')'}} expected-note{{to match this '('}} \ - // expected-error{{use of undeclared identifier 'n'}} + // expected-error{{use of undeclared identifier 'n'}} \ + // expected-error{{expected ';' at end of declaration list}} \ + // expected-error{{field has incomplete type 'test1::A<char>'}} }; - template<typename T> class B : public A<T> { // expected-error{{declaration of 'T' shadows template parameter}} + template<typename T> class B : public A<T> { virtual void foo() {} }; - extern template class A<char>; // expected-error{{expected member name or ';' after declaration specifiers}} - extern template class B<char>; // expected-error{{expected member name or ';' after declaration specifiers}} -} // expected-error{{expected ';' after class}} // expected-error{{expected '}'}} + extern template class A<char>; // expected-note {{in instantiation of template class 'test1::A<char>' requested here}} \ + // expected-note {{definition of 'test1::A<char>' is not complete until the closing '}'}} + extern template class B<char>; +} diff --git a/test/SemaCXX/crashes.cpp b/test/SemaCXX/crashes.cpp index c75b040..b77248e 100644 --- a/test/SemaCXX/crashes.cpp +++ b/test/SemaCXX/crashes.cpp @@ -95,3 +95,12 @@ namespace PR9026 { Write(x); } } + +namespace PR10270 { + template<typename T> class C; + template<typename T> void f() { + if (C<T> == 1) // expected-error{{expected unqualified-id}} \ + // expected-error{{invalid '==' at end of declaration}} + return; + } +} diff --git a/test/SemaCXX/decltype.cpp b/test/SemaCXX/decltype.cpp index d4ef7e3..f61a92b 100644 --- a/test/SemaCXX/decltype.cpp +++ b/test/SemaCXX/decltype.cpp @@ -16,3 +16,8 @@ void test_f2() { float &fr = f2(AC().a); } +namespace pr10154 { + class A{ + A(decltype(nullptr) param); + }; +}
\ No newline at end of file diff --git a/test/SemaCXX/enum-scoped.cpp b/test/SemaCXX/enum-scoped.cpp index fc871cf..73e7578 100644 --- a/test/SemaCXX/enum-scoped.cpp +++ b/test/SemaCXX/enum-scoped.cpp @@ -119,3 +119,26 @@ namespace rdar9366066 { x % 8; // expected-error{{invalid operands to binary expression ('rdar9366066::X' and 'int')}} } } + +// Part 1 of PR10264 +namespace test5 { + namespace ns { + typedef unsigned Atype; + enum A : Atype; + } + enum ns::A : ns::Atype { + x, y, z + }; +} + +// Part 2 of PR10264 +namespace test6 { + enum A : unsigned; + struct A::a; // expected-error {{incomplete type 'test6::A' named in nested name specifier}} + enum A::b; // expected-error {{incomplete type 'test6::A' named in nested name specifier}} + int A::c; // expected-error {{incomplete type 'test6::A' named in nested name specifier}} + void A::d(); // expected-error {{incomplete type 'test6::A' named in nested name specifier}} + void test() { + (void) A::e; // expected-error {{incomplete type 'test6::A' named in nested name specifier}} + } +} diff --git a/test/SemaCXX/expressions.cpp b/test/SemaCXX/expressions.cpp index 95ece48..8a294fa 100644 --- a/test/SemaCXX/expressions.cpp +++ b/test/SemaCXX/expressions.cpp @@ -63,3 +63,25 @@ int test2(int x) { return x && (-1); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}} return x && (5); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}} } + +template<unsigned int A, unsigned int B> struct S +{ + enum { + e1 = A && B, + e2 = A && 7 // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}} + }; + + int foo() { + int x = A && B; + int y = B && 3; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}} + + return x + y; + } +}; + +void test3() { + S<5, 8> s1; + S<2, 7> s2; + (void)s1.foo(); + (void)s2.foo(); +} diff --git a/test/SemaCXX/for-range-unused.cpp b/test/SemaCXX/for-range-unused.cpp new file mode 100644 index 0000000..7b7d84d --- /dev/null +++ b/test/SemaCXX/for-range-unused.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x -Wunused + +// PR9968: We used to warn that __range is unused in a dependent for-range. + +template <typename T> + struct Vector { + void doIt() { + int a; // expected-warning {{unused variable 'a'}} + + for (auto& e : elements) + ; + } + + T elements[10]; + }; + + +int main(int, char**) { + Vector<int> vector; + vector.doIt(); +} diff --git a/test/SemaCXX/function-overload-typo-crash.cpp b/test/SemaCXX/function-overload-typo-crash.cpp new file mode 100644 index 0000000..0fea312 --- /dev/null +++ b/test/SemaCXX/function-overload-typo-crash.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR10283 +void min(); +void min(int); + +template <typename T> void max(T); + +void f() { + fin(); //expected-error {{use of undeclared identifier 'fin'; did you mean 'min'}} + fax(0); //expected-error {{use of undeclared identifier 'fax'; did you mean 'max'}} +} diff --git a/test/SemaCXX/generalized-initializers.cpp b/test/SemaCXX/generalized-initializers.cpp index ec37a0c..6e2bee7 100644 --- a/test/SemaCXX/generalized-initializers.cpp +++ b/test/SemaCXX/generalized-initializers.cpp @@ -85,23 +85,52 @@ namespace integral { namespace objects { + struct X1 { X1(int); }; + struct X2 { explicit X2(int); }; + template <int N> struct A { A() { static_assert(N == 0, ""); } A(int, double) { static_assert(N == 1, ""); } - A(int, int) { static_assert(N == 2, ""); } A(std::initializer_list<int>) { static_assert(N == 3, ""); } }; - void initialization() { + template <int N> + struct D { + D(std::initializer_list<int>) { static_assert(N == 0, ""); } // expected-note 1 {{candidate}} + D(std::initializer_list<double>) { static_assert(N == 1, ""); } // expected-note 1 {{candidate}} + }; + + template <int N> + struct E { + E(int, int) { static_assert(N == 0, ""); } + E(X1, int) { static_assert(N == 1, ""); } + }; + + void overload_resolution() { { A<0> a{}; } { A<0> a = {}; } - { A<1> a{1, 1.0}; } - { A<1> a = {1, 1.0}; } + // Narrowing conversions don't affect viability. The next two choose + // the initializer_list constructor. + { A<3> a{1, 1.0}; } // expected-error {{narrowing conversion}} + { A<3> a = {1, 1.0}; } // expected-error {{narrowing conversion}} { A<3> a{1, 2, 3, 4, 5, 6, 7, 8}; } { A<3> a = {1, 2, 3, 4, 5, 6, 7, 8}; } { A<3> a{1, 2, 3, 4, 5, 6, 7, 8}; } { A<3> a{1, 2}; } + + { D<0> d{1, 2, 3}; } + { D<1> d{1.0, 2.0, 3.0}; } + { D<-1> d{1, 2.0}; } // expected-error {{ambiguous}} + + { E<0> e{1, 2}; } + } + + void explicit_implicit() { + { X1 x{0}; } + { X1 x = {0}; } + { X2 x{0}; } + { X2 x = {0}; } // expected-error {{explicit}} } struct C { @@ -172,3 +201,28 @@ namespace litb { B g({1, 2, 3}); } + +namespace aggregate { + // Direct list initialization does NOT allow braces to be elided! + struct S { + int ar[2]; + struct T { + int i1; + int i2; + } t; + struct U { + int i1; + } u[2]; + struct V { + int var[2]; + } v; + }; + + void test() { + S s1 = { 1, 2, 3 ,4, 5, 6, 7, 8 }; // no-error + S s2{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } }; // completely braced + S s3{ 1, 2, 3, 4, 5, 6 }; // xpected-error + S s4{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } }; // xpected-error + S s5{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} }; // xpected-error + } +} diff --git a/test/SemaCXX/i-c-e-cxx.cpp b/test/SemaCXX/i-c-e-cxx.cpp index 2d08ea9..186e321 100644 --- a/test/SemaCXX/i-c-e-cxx.cpp +++ b/test/SemaCXX/i-c-e-cxx.cpp @@ -42,3 +42,16 @@ namespace pr6206 { void pr6373(const unsigned x = 0) { unsigned max = 80 / x; } + + +// rdar://9204520 +namespace rdar9204520 { + +struct A { + static const int B = int(0.75 * 1000 * 1000); +}; + +int foo() { return A::B; } +} + + diff --git a/test/SemaCXX/member-init.cpp b/test/SemaCXX/member-init.cpp index 1b8c523..7ca1f0e 100644 --- a/test/SemaCXX/member-init.cpp +++ b/test/SemaCXX/member-init.cpp @@ -48,3 +48,7 @@ struct CheckExcSpecFail { CheckExcSpecFail() noexcept(true) = default; // expected-error {{exception specification of explicitly defaulted default constructor does not match the calculated one}} ThrowCtor tc = 123; }; + +struct TypedefInit { + typedef int A = 0; // expected-error {{illegal initializer}} +}; diff --git a/test/SemaCXX/member-pointer.cpp b/test/SemaCXX/member-pointer.cpp index de3b211..cf64810 100644 --- a/test/SemaCXX/member-pointer.cpp +++ b/test/SemaCXX/member-pointer.cpp @@ -296,3 +296,19 @@ namespace PR9973 { mem_fn(&test::nullary_v)(t); // expected-note{{in instantiation of}} } } + +namespace test8 { + struct A { int foo; }; + int test1() { + // Verify that we perform (and check) an lvalue conversion on the operands here. + return (*((A**) 0)) // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}} + ->**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}} + } + + int test2() { + // Verify that we perform (and check) an lvalue conversion on the operands here. + // TODO: the .* should itself warn about being a dereference of null. + return (*((A*) 0)) + .**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}} + } +} diff --git a/test/SemaCXX/missing-namespace-qualifier-typo-corrections.cpp b/test/SemaCXX/missing-namespace-qualifier-typo-corrections.cpp new file mode 100644 index 0000000..fd0c976 --- /dev/null +++ b/test/SemaCXX/missing-namespace-qualifier-typo-corrections.cpp @@ -0,0 +1,72 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++0x-extensions %s + +namespace fizbin { class Foobar; } // expected-note{{'fizbin::Foobar' declared here}} +Foobar *my_bar = new Foobar; // expected-error{{unknown type name 'Foobar'; did you mean 'fizbin::Foobar'?}} \ + // expected-error{{expected a type}} + +namespace barstool { int toFoobar() { return 1; } } // expected-note 3 {{'barstool::toFoobar' declared here}} +int Double(int x) { return x + x; } +void empty() { + Double(toFoobar()); // expected-error{{{use of undeclared identifier 'toFoobar'; did you mean 'barstool::toFoobar'?}} +} + +namespace fizbin { + namespace baztool { bool toFoobar() { return true; } } // expected-note{{'fizbin::baztool' declared here}} + namespace nested { bool moreFoobar() { return true; } } // expected-note{{'fizbin::nested::moreFoobar' declared here}} + namespace nested { bool lessFoobar() { return true; } } // expected-note{{'fizbin::nested' declared here}} \ + // expected-note{{'fizbin::nested::lessFoobar' declared here}} + class dummy { // expected-note 2 {{'fizbin::dummy' declared here}} + public: + static bool moreFoobar() { return false; } // expected-note{{'moreFoobar' declared here}} + }; +} +void Check() { // expected-note{{'Check' declared here}} + if (toFoobar()) Double(7); // expected-error{{use of undeclared identifier 'toFoobar'; did you mean 'barstool::toFoobar'?}} + if (noFoobar()) Double(7); // expected-error{{use of undeclared identifier 'noFoobar'; did you mean 'barstool::toFoobar'?}} + if (moreFoobar()) Double(7); // expected-error{{use of undeclared identifier 'moreFoobar'; did you mean 'fizbin::nested::moreFoobar'}} + if (lessFoobar()) Double(7); // expected-error{{use of undeclared identifier 'lessFoobar'; did you mean 'fizbin::nested::lessFoobar'?}} + if (baztool::toFoobar()) Double(7); // expected-error{{use of undeclared identifier 'baztool'; did you mean 'fizbin::baztool'?}} + if (nested::moreFoobar()) Double(7); // expected-error{{use of undeclared identifier 'nested'; did you mean 'fizbin::nested'?}} + if (dummy::moreFoobar()) Double(7); // expected-error{{use of undeclared identifier 'dummy'; did you mean 'fizbin::dummy'?}} + if (dummy::mreFoobar()) Double(7); // expected-error{{use of undeclared identifier 'dummy'; did you mean 'fizbin::dummy'?}} \ + // expected-error{{no member named 'mreFoobar' in 'fizbin::dummy'; did you mean 'moreFoobar'?}} + if (moFoobin()) Double(7); // expected-error{{use of undeclared identifier 'moFoobin'}} +} + +void Alt() { + Cleck(); // expected-error{{{use of undeclared identifier 'Cleck'; did you mean 'Check'?}} +} + +namespace N { + namespace inner { + class myvector { /* ... */ }; // expected-note{{'inner::myvector' declared here}} + } + + void f() { + myvector v; // expected-error{{unknown type name 'myvector'; did you mean 'inner::myvector'?}} + } +} + +namespace realstd { + inline namespace __1 { + class mylinkedlist { /* ... */ }; // expected-note 2 {{'realstd::mylinkedlist' declared here}} + } + + class linkedlist { /* ... */ }; +} + +void f() { + mylinkedlist v; // expected-error{{unknown type name 'mylinkedlist'; did you mean 'realstd::mylinkedlist'?}} + nylinkedlist w; // expected-error{{unknown type name 'nylinkedlist'; did you mean 'realstd::mylinkedlist'?}} +} + +// Test case from http://llvm.org/bugs/show_bug.cgi?id=10318 +namespace llvm { + template <typename T> class GraphWriter {}; // expected-note{{'llvm::GraphWriter' declared here}} +} + +struct S {}; +void bar() { + GraphWriter<S> x; //expected-error{{no template named 'GraphWriter'; did you mean 'llvm::GraphWriter'?}} + +} diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index fef7093..ee6ca88 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/test/SemaCXX/nested-name-spec.cpp @@ -261,8 +261,27 @@ namespace PR8159 { namespace rdar7980179 { class A { void f0(); }; // expected-note {{previous}} - int A::f0() {} // expected-error {{out-of-line definition of 'rdar7980179::A::f0' differ from the declaration in the return type}} + int A::f0() {} // expected-error {{out-of-line definition of 'rdar7980179::A::f0' differs from the declaration in the return type}} } namespace alias = A; double *dp = (alias::C*)0; // expected-error{{cannot initialize a variable of type 'double *' with an rvalue of type 'alias::C *'}} + +// http://llvm.org/PR10109 +namespace PR10109 { +template<typename T> +struct A { +protected: + struct B; + struct B::C; // expected-error {{requires a template parameter list}} \ + // expected-error {{no struct named 'C'}} +}; + +template<typename T> +struct A2 { +protected: + struct B; +}; +template <typename T> +struct A2<T>::B::C; // expected-error {{no struct named 'C'}} +} diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index 13ef461..efdfa0f 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -389,3 +389,11 @@ namespace PR7702 { new DoesNotExist; // expected-error {{expected a type}} } } + +namespace ArrayNewNeedsDtor { + struct A { A(); private: ~A(); }; // expected-note {{declared private here}} + struct B { B(); A a; }; // expected-error {{field of type 'ArrayNewNeedsDtor::A' has private destructor}} + B *test9() { + return new B[5]; // expected-note {{implicit default destructor for 'ArrayNewNeedsDtor::B' first required here}} + } +} diff --git a/test/SemaCXX/null_in_arithmetic_ops.cpp b/test/SemaCXX/null_in_arithmetic_ops.cpp new file mode 100644 index 0000000..fab6f10 --- /dev/null +++ b/test/SemaCXX/null_in_arithmetic_ops.cpp @@ -0,0 +1,93 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -fblocks -Wnull-arithmetic -verify %s +#include <stddef.h> + +void f() { + int a; + bool b; + void (^c)(); + class X; + void (X::*d) (); + extern void e(); + int f[2]; + const void *v; + + a = 0 ? NULL + a : a + NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + a = 0 ? NULL - a : a - NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + a = 0 ? NULL / a : a / NULL; // expected-warning 2{{use of NULL in arithmetic operation}} \ + // expected-warning {{division by zero is undefined}} + a = 0 ? NULL * a : a * NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + a = 0 ? NULL >> a : a >> NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + a = 0 ? NULL << a : a << NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + a = 0 ? NULL % a : a % NULL; // expected-warning 2{{use of NULL in arithmetic operation}} \ + expected-warning {{remainder by zero is undefined}} + a = 0 ? NULL & a : a & NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + a = 0 ? NULL | a : a | NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + a = 0 ? NULL ^ a : a ^ NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + + // Check for warnings or errors when doing arithmetic on pointers and other + // types. + v = 0 ? NULL + &a : &a + NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + v = 0 ? NULL + c : c + NULL; // \ + expected-error {{invalid operands to binary expression ('long' and 'void (^)()')}} \ + expected-error {{invalid operands to binary expression ('void (^)()' and 'long')}} + v = 0 ? NULL + d : d + NULL; // \ + expected-error {{invalid operands to binary expression ('long' and 'void (X::*)()')}} \ + expected-error {{invalid operands to binary expression ('void (X::*)()' and 'long')}} + v = 0 ? NULL + e : e + NULL; // expected-error 2{{arithmetic on a pointer to the function type 'void ()'}} + v = 0 ? NULL + f : f + NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + v = 0 ? NULL + "f" : "f" + NULL; // expected-warning 2{{use of NULL in arithmetic operation}} + + // Using two NULLs should only give one error instead of two. + a = NULL + NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL - NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL / NULL; // expected-warning{{use of NULL in arithmetic operation}} \ + // expected-warning{{division by zero is undefined}} + a = NULL * NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL >> NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL << NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL % NULL; // expected-warning{{use of NULL in arithmetic operation}} \ + // expected-warning{{remainder by zero is undefined}} + a = NULL & NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL | NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL ^ NULL; // expected-warning{{use of NULL in arithmetic operation}} + + a += NULL; // expected-warning{{use of NULL in arithmetic operation}} + a -= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a /= NULL; // expected-warning{{use of NULL in arithmetic operation}} \ + // expected-warning{{division by zero is undefined}} + a *= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a >>= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a <<= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a %= NULL; // expected-warning{{use of NULL in arithmetic operation}} \ + // expected-warning{{remainder by zero is undefined}} + a &= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a |= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a ^= NULL; // expected-warning{{use of NULL in arithmetic operation}} + + b = a < NULL || NULL < a; // expected-warning 2{{use of NULL in arithmetic operation}} + b = a > NULL || NULL > a; // expected-warning 2{{use of NULL in arithmetic operation}} + b = a <= NULL || NULL <= a; // expected-warning 2{{use of NULL in arithmetic operation}} + b = a >= NULL || NULL >= a; // expected-warning 2{{use of NULL in arithmetic operation}} + b = a == NULL || NULL == a; // expected-warning 2{{use of NULL in arithmetic operation}} + b = a != NULL || NULL != a; // expected-warning 2{{use of NULL in arithmetic operation}} + + b = &a < NULL || NULL < &a || &a > NULL || NULL > &a; + b = &a <= NULL || NULL <= &a || &a >= NULL || NULL >= &a; + b = &a == NULL || NULL == &a || &a != NULL || NULL != &a; + + b = 0 == a; + b = 0 == &a; + + b = NULL < NULL || NULL > NULL; + b = NULL <= NULL || NULL >= NULL; + b = NULL == NULL || NULL != NULL; + + b = ((NULL)) != a; // expected-warning{{use of NULL in arithmetic operation}} + + // Check that even non-standard pointers don't warn. + b = c == NULL || NULL == c || c != NULL || NULL != c; + b = d == NULL || NULL == d || d != NULL || NULL != d; + b = e == NULL || NULL == e || e != NULL || NULL != e; + b = f == NULL || NULL == f || f != NULL || NULL != f; + b = "f" == NULL || NULL == "f" || "f" != NULL || NULL != "f"; +} diff --git a/test/SemaCXX/nullptr_in_arithmetic_ops.cpp b/test/SemaCXX/nullptr_in_arithmetic_ops.cpp new file mode 100644 index 0000000..e839ed1 --- /dev/null +++ b/test/SemaCXX/nullptr_in_arithmetic_ops.cpp @@ -0,0 +1,73 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -std=c++0x -verify %s + +void foo() { + int a; + bool b; + + a = 0 ? nullptr + a : a + nullptr; // expected-error 2{{invalid operands to binary expression}} + a = 0 ? nullptr - a : a - nullptr; // expected-error 2{{invalid operands to binary expression}} + a = 0 ? nullptr / a : a / nullptr; // expected-error 2{{invalid operands to binary expression}} + a = 0 ? nullptr * a : a * nullptr; // expected-error 2{{invalid operands to binary expression}} + a = 0 ? nullptr >> a : a >> nullptr; // expected-error 2{{invalid operands to binary expression}} + a = 0 ? nullptr << a : a << nullptr; // expected-error 2{{invalid operands to binary expression}} + a = 0 ? nullptr % a : a % nullptr; // expected-error 2{{invalid operands to binary expression}} + a = 0 ? nullptr & a : a & nullptr; // expected-error 2{{invalid operands to binary expression}} + a = 0 ? nullptr | a : a | nullptr; // expected-error 2{{invalid operands to binary expression}} + a = 0 ? nullptr ^ a : a ^ nullptr; // expected-error 2{{invalid operands to binary expression}} + + // Using two nullptrs should only give one error instead of two. + a = nullptr + nullptr; // expected-error{{invalid operands to binary expression}} + a = nullptr - nullptr; // expected-error{{invalid operands to binary expression}} + a = nullptr / nullptr; // expected-error{{invalid operands to binary expression}} + a = nullptr * nullptr; // expected-error{{invalid operands to binary expression}} + a = nullptr >> nullptr; // expected-error{{invalid operands to binary expression}} + a = nullptr << nullptr; // expected-error{{invalid operands to binary expression}} + a = nullptr % nullptr; // expected-error{{invalid operands to binary expression}} + a = nullptr & nullptr; // expected-error{{invalid operands to binary expression}} + a = nullptr | nullptr; // expected-error{{invalid operands to binary expression}} + a = nullptr ^ nullptr; // expected-error{{invalid operands to binary expression}} + + a += nullptr; // expected-error{{invalid operands to binary expression}} + a -= nullptr; // expected-error{{invalid operands to binary expression}} + a /= nullptr; // expected-error{{invalid operands to binary expression}} + a *= nullptr; // expected-error{{invalid operands to binary expression}} + a >>= nullptr; // expected-error{{invalid operands to binary expression}} + a <<= nullptr; // expected-error{{invalid operands to binary expression}} + a %= nullptr; // expected-error{{invalid operands to binary expression}} + a &= nullptr; // expected-error{{invalid operands to binary expression}} + a |= nullptr; // expected-error{{invalid operands to binary expression}} + a ^= nullptr; // expected-error{{invalid operands to binary expression}} + + b = a < nullptr || nullptr < a; // expected-error 2{{invalid operands to binary expression}} + b = a > nullptr || nullptr > a; // expected-error 2{{invalid operands to binary expression}} + b = a <= nullptr || nullptr <= a; // expected-error 2{{invalid operands to binary expression}} + b = a >= nullptr || nullptr >= a; // expected-error 2{{invalid operands to binary expression}} + b = a == nullptr || nullptr == a; // expected-error 2{{invalid operands to binary expression}} + b = a != nullptr || nullptr != a; // expected-error 2{{invalid operands to binary expression}} + + b = &a < nullptr || nullptr < &a || &a > nullptr || nullptr > &a; + b = &a <= nullptr || nullptr <= &a || &a >= nullptr || nullptr >= &a; + b = &a == nullptr || nullptr == &a || &a != nullptr || nullptr != &a; + + b = nullptr < nullptr || nullptr > nullptr; + b = nullptr <= nullptr || nullptr >= nullptr; + b = nullptr == nullptr || nullptr != nullptr; + + b = ((nullptr)) != a; // expected-error{{invalid operands to binary expression}} + + void (^c)(); + c = nullptr; + b = c == nullptr || nullptr == c || c != nullptr || nullptr != c; + + class X; + void (X::*d) (); + d = nullptr; + b = d == nullptr || nullptr == d || d != nullptr || nullptr != d; + + extern void e(); + b = e == nullptr || nullptr == e || e != nullptr || nullptr != e; + + int f[2]; + b = f == nullptr || nullptr == f || f != nullptr || nullptr != f; + b = "f" == nullptr || nullptr == "f" || "f" != nullptr || nullptr != "f"; +} diff --git a/test/SemaCXX/overloaded-name.cpp b/test/SemaCXX/overloaded-name.cpp index 5a87cc8..73f12a9 100644 --- a/test/SemaCXX/overloaded-name.cpp +++ b/test/SemaCXX/overloaded-name.cpp @@ -12,3 +12,19 @@ void test(bool b) { (void)(b? ovl<float> : &ovl); // expected-error{{cannot resolve overloaded function 'ovl' from context}} (void)(b? ovl<float> : ovl<float>); } + +namespace rdar9623945 { + void f(...) { + } + + class X { + public: + const char* text(void); + void g(void) { + f(text()); + f(text); // expected-error{{a bound member function may only be called}} + f(text()); + f(text); // expected-error{{a bound member function may only be called}} + } + }; +} diff --git a/test/SemaCXX/return.cpp b/test/SemaCXX/return.cpp index b457f6a..2f98a27 100644 --- a/test/SemaCXX/return.cpp +++ b/test/SemaCXX/return.cpp @@ -69,3 +69,14 @@ namespace PR10057 { return S() = value; } } + +namespace return_has_expr { + struct S { + S() { + return 42; // expected-error {{constructor 'S' should not return a value}} + } + ~S() { + return 42; // expected-error {{destructor '~S' should not return a value}} + } + }; +} diff --git a/test/SemaCXX/vararg-non-pod.cpp b/test/SemaCXX/vararg-non-pod.cpp index df0080f..3ca07b0 100644 --- a/test/SemaCXX/vararg-non-pod.cpp +++ b/test/SemaCXX/vararg-non-pod.cpp @@ -101,3 +101,21 @@ void t6(Foo somearg, ... ) { __builtin_va_start(list, somearg); } +void t7(int n, ...) { + __builtin_va_list list; + __builtin_va_start(list, n); + (void)__builtin_va_arg(list, C); // expected-warning{{second argument to 'va_arg' is of non-POD type 'C'}} + __builtin_va_end(list); +} + +struct Abstract { + virtual void doit() = 0; // expected-note{{unimplemented pure virtual method}} +}; + +void t8(int n, ...) { + __builtin_va_list list; + __builtin_va_start(list, n); + (void)__builtin_va_arg(list, Abstract); // expected-error{{second argument to 'va_arg' is of abstract type 'Abstract'}} + __builtin_va_end(list); +} + diff --git a/test/SemaCXX/vector.cpp b/test/SemaCXX/vector.cpp index 9ae2c82..4d3d939 100644 --- a/test/SemaCXX/vector.cpp +++ b/test/SemaCXX/vector.cpp @@ -176,10 +176,10 @@ void test_implicit_conversions(bool Cond, char16 c16, longlong16 ll16, (void)(to_c16 * to_c16e); (void)(to_c16 / to_c16e); (void)(rto_c16 = c16e); // expected-error{{no viable overloaded '='}} - (void)(rto_c16 += to_c16e); // expected-error{{expression is not assignable}} - (void)(rto_c16 -= to_c16e); // expected-error{{expression is not assignable}} - (void)(rto_c16 *= to_c16e); // expected-error{{expression is not assignable}} - (void)(rto_c16 /= to_c16e); // expected-error{{expression is not assignable}} + (void)(rto_c16 += to_c16e); + (void)(rto_c16 -= to_c16e); + (void)(rto_c16 *= to_c16e); + (void)(rto_c16 /= to_c16e); (void)(Cond? to_c16 : to_c16e); (void)(Cond? to_ll16e : to_ll16); diff --git a/test/SemaCXX/virtuals.cpp b/test/SemaCXX/virtuals.cpp index 792467e..d8c26ef 100644 --- a/test/SemaCXX/virtuals.cpp +++ b/test/SemaCXX/virtuals.cpp @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++0x %s class A { virtual void f(); - virtual void g() = 0; + virtual void g() = 0; // expected-note{{unimplemented pure virtual method 'g' in 'A'}} void h() = 0; // expected-error {{'h' is not virtual and cannot be declared pure}} void i() = 1; // expected-error {{initializer on function does not look like a pure-specifier}} @@ -19,20 +19,29 @@ virtual void A::k() { } // expected-error{{'virtual' can only be specified insid class B : public A { // Needs to recognize that overridden function is virtual. - //void g() = 0; + void g() = 0; // Needs to recognize that function does not override. - //void g(int) = 0; + void g(int) = 0; // expected-error{{'g' is not virtual and cannot be declared pure}} }; // Needs to recognize invalid uses of abstract classes. -/* -A fn(A) +A fn(A) // expected-error{{parameter type 'A' is an abstract class}} \ + // expected-error{{return type 'A' is an abstract class}} { - A a; - static_cast<A>(0); + A a; // expected-error{{variable type 'A' is an abstract class}} + (void)static_cast<A>(0); try { - } catch(A) { + } catch(A) { // expected-error{{variable type 'A' is an abstract class}} } } -*/ + +namespace rdar9670557 { + typedef int func(int); + func *a(); + struct X { + virtual func f = 0; + virtual func (g) = 0; + func *h = 0; + }; +} diff --git a/test/SemaCXX/warn-bad-memaccess.cpp b/test/SemaCXX/warn-bad-memaccess.cpp index e7d095f..9a998f0 100644 --- a/test/SemaCXX/warn-bad-memaccess.cpp +++ b/test/SemaCXX/warn-bad-memaccess.cpp @@ -38,6 +38,46 @@ void test_warn() { memcpy(0, &x1, sizeof x1); // \ // expected-warning{{source of this 'memcpy' call is a pointer to dynamic class}} \ // expected-note {{explicitly cast the pointer to silence this warning}} + + __builtin_memset(&x1, 0, sizeof x1); // \ + // expected-warning {{destination for this '__builtin_memset' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + __builtin_memset(&x2, 0, sizeof x2); // \ + // expected-warning {{destination for this '__builtin_memset' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + + __builtin_memmove(&x1, 0, sizeof x1); // \ + // expected-warning{{destination for this '__builtin_memmove' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + __builtin_memmove(0, &x1, sizeof x1); // \ + // expected-warning{{source of this '__builtin_memmove' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + __builtin_memcpy(&x1, 0, sizeof x1); // \ + // expected-warning{{destination for this '__builtin_memcpy' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + __builtin_memcpy(0, &x1, sizeof x1); // \ + // expected-warning{{source of this '__builtin_memcpy' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + + __builtin___memset_chk(&x1, 0, sizeof x1, sizeof x1); // \ + // expected-warning {{destination for this '__builtin___memset_chk' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + __builtin___memset_chk(&x2, 0, sizeof x2, sizeof x2); // \ + // expected-warning {{destination for this '__builtin___memset_chk' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + + __builtin___memmove_chk(&x1, 0, sizeof x1, sizeof x1); // \ + // expected-warning{{destination for this '__builtin___memmove_chk' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + __builtin___memmove_chk(0, &x1, sizeof x1, sizeof x1); // \ + // expected-warning{{source of this '__builtin___memmove_chk' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + __builtin___memcpy_chk(&x1, 0, sizeof x1, sizeof x1); // \ + // expected-warning{{destination for this '__builtin___memcpy_chk' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} + __builtin___memcpy_chk(0, &x1, sizeof x1, sizeof x1); // \ + // expected-warning{{source of this '__builtin___memcpy_chk' call is a pointer to dynamic class}} \ + // expected-note {{explicitly cast the pointer to silence this warning}} } void test_nowarn(void *void_ptr) { @@ -68,3 +108,5 @@ namespace N { N::memset(&x1, 0, sizeof x1); } } + + diff --git a/test/SemaCXX/warn-memset-bad-sizeof.cpp b/test/SemaCXX/warn-memset-bad-sizeof.cpp new file mode 100644 index 0000000..90ac504 --- /dev/null +++ b/test/SemaCXX/warn-memset-bad-sizeof.cpp @@ -0,0 +1,101 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-sizeof-array-argument %s +// +extern "C" void *memset(void *, int, unsigned); +extern "C" void *memmove(void *s1, const void *s2, unsigned n); +extern "C" void *memcpy(void *s1, const void *s2, unsigned n); + +struct S {int a, b, c, d;}; +typedef S* PS; + +struct Foo {}; +typedef const Foo& CFooRef; +typedef const Foo CFoo; +typedef volatile Foo VFoo; +typedef const volatile Foo CVFoo; + +typedef double Mat[4][4]; + +template <class Dest, class Source> +inline Dest bit_cast(const Source& source) { + Dest dest; + memcpy(&dest, &source, sizeof(dest)); + return dest; +} + +// http://www.lysator.liu.se/c/c-faq/c-2.html#2-6 +void f(Mat m, const Foo& const_foo, char *buffer) { + S s; + S* ps = &s; + PS ps2 = &s; + char arr[5]; + char* parr[5]; + Foo foo; + char* heap_buffer = new char[42]; + + /* Should warn */ + memset(&s, 0, sizeof(&s)); // \ + // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}} + memset(ps, 0, sizeof(ps)); // \ + // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}} + memset(ps2, 0, sizeof(ps2)); // \ + // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}} + memset(ps2, 0, sizeof(typeof(ps2))); // \ + // expected-warning {{argument to 'sizeof' in 'memset' call is the same pointer type}} + memset(ps2, 0, sizeof(PS)); // \ + // expected-warning {{argument to 'sizeof' in 'memset' call is the same pointer type}} + memset(heap_buffer, 0, sizeof(heap_buffer)); // \ + // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}} + + memcpy(&s, 0, sizeof(&s)); // \ + // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the destination}} + memcpy(0, &s, sizeof(&s)); // \ + // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the source}} + + /* Shouldn't warn */ + memset((void*)&s, 0, sizeof(&s)); + memset(&s, 0, sizeof(s)); + memset(&s, 0, sizeof(S)); + memset(&s, 0, sizeof(const S)); + memset(&s, 0, sizeof(volatile S)); + memset(&s, 0, sizeof(volatile const S)); + memset(&foo, 0, sizeof(CFoo)); + memset(&foo, 0, sizeof(VFoo)); + memset(&foo, 0, sizeof(CVFoo)); + memset(ps, 0, sizeof(*ps)); + memset(ps2, 0, sizeof(*ps2)); + memset(ps2, 0, sizeof(typeof(*ps2))); + memset(arr, 0, sizeof(arr)); + memset(parr, 0, sizeof(parr)); + + memcpy(&foo, &const_foo, sizeof(Foo)); + memcpy((void*)&s, 0, sizeof(&s)); + memcpy(0, (void*)&s, sizeof(&s)); + char *cptr; + memcpy(&cptr, buffer, sizeof(cptr)); + memcpy((char*)&cptr, buffer, sizeof(cptr)); + + CFooRef cfoo = foo; + memcpy(&foo, &cfoo, sizeof(Foo)); + + memcpy(0, &arr, sizeof(arr)); + typedef char Buff[8]; + memcpy(0, &arr, sizeof(Buff)); + + unsigned char* puc; + bit_cast<char*>(puc); + + float* pf; + bit_cast<int*>(pf); + + int iarr[14]; + memset(&iarr[0], 0, sizeof iarr); + + int* iparr[14]; + memset(&iparr[0], 0, sizeof iparr); + + memset(m, 0, sizeof(Mat)); + + // Copy to raw buffer shouldn't warn either + memcpy(&foo, &arr, sizeof(Foo)); + memcpy(&arr, &foo, sizeof(Foo)); +} diff --git a/test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp b/test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp index 698eccd..ade6198 100644 --- a/test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp +++ b/test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp @@ -5,3 +5,10 @@ struct A { virtual void f() = 0; // expected-note 2 {{'f' declared here}} }; + +// Don't warn (or note) when calling the function on a pointer. (PR10195) +struct B { + A *a; + B() { a->f(); }; + ~B() { a->f(); }; +}; diff --git a/test/SemaCXX/warn-unused-variables.cpp b/test/SemaCXX/warn-unused-variables.cpp index 81f22a7..5ba1f2a 100644 --- a/test/SemaCXX/warn-unused-variables.cpp +++ b/test/SemaCXX/warn-unused-variables.cpp @@ -54,3 +54,29 @@ void unused_local_static() { static int y = 0; // expected-warning{{unused variable 'y'}} #pragma unused(x) } + +// PR10168 +namespace PR10168 { + // We expect a warning in the definition only for non-dependent variables, and + // a warning in the instantiation only for dependent variables. + template<typename T> + struct S { + void f() { + int a; // expected-warning {{unused variable 'a'}} + T b; // expected-warning 2{{unused variable 'b'}} + } + }; + + template<typename T> + void f() { + int a; // expected-warning {{unused variable 'a'}} + T b; // expected-warning 2{{unused variable 'b'}} + } + + void g() { + S<int>().f(); // expected-note {{here}} + S<char>().f(); // expected-note {{here}} + f<int>(); // expected-note {{here}} + f<char>(); // expected-note {{here}} + } +} diff --git a/test/SemaObjC/Inputs/arc-system-header.h b/test/SemaObjC/Inputs/arc-system-header.h new file mode 100644 index 0000000..5012a2a --- /dev/null +++ b/test/SemaObjC/Inputs/arc-system-header.h @@ -0,0 +1,52 @@ +static inline void *test0(id x) { + return x; +} + +static inline void **test1(__strong id* x) { + return (void**) x; +} + + + + + +struct Test3 { + id *field; +}; + +@interface Test4 { +@public + id *field1; + __strong id *field2; +} +@end + +struct Test5 { + id field; +}; + + + + + + + +extern struct Test6 *const kMagicConstant; + + + + + +@interface Test7 +@property id *prop; +@end + + + + + + + +static inline void *test8(id ptr) { + return (__bridge_retain void*) ptr; +} diff --git a/test/SemaObjC/arc-bridged-cast.m b/test/SemaObjC/arc-bridged-cast.m new file mode 100644 index 0000000..e883406 --- /dev/null +++ b/test/SemaObjC/arc-bridged-cast.m @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fblocks %s + +typedef const void *CFTypeRef; +typedef const struct __CFString *CFStringRef; + +@interface NSString +@end + +CFTypeRef CFCreateSomething(); +CFStringRef CFCreateString(); +CFTypeRef CFGetSomething(); +CFStringRef CFGetString(); + +id CreateSomething(); +NSString *CreateNSString(); + +void from_cf() { + id obj1 = (__bridge_transfer id)CFCreateSomething(); + id obj2 = (__bridge_transfer NSString*)CFCreateString(); + (__bridge int*)CFCreateSomething(); // expected-error{{incompatible types casting 'CFTypeRef' (aka 'const void *') to 'int *' with a __bridge cast}} + id obj3 = (__bridge id)CFGetSomething(); + id obj4 = (__bridge NSString*)CFGetString(); +} + +void to_cf(id obj) { + CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); + CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString(); + CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); + CFStringRef cf4 = (__bridge CFStringRef)CreateNSString(); + + // rdar://problem/9629566 - temporary workaround + CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}} +} + +void fixits() { + id obj1 = (id)CFCreateSomething(); // expected-error{{cast of C pointer type 'CFTypeRef' (aka 'const void *') to Objective-C pointer type 'id' requires a bridged cast}} \ + // expected-note{{use __bridge to convert directly (no change in ownership)}} \ + // expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}} + CFTypeRef cf1 = (CFTypeRef)CreateSomething(); // expected-error{{cast of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \ + // expected-note{{use __bridge to convert directly (no change in ownership)}} \ + // expected-note{{use __bridge_retained to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}} +} diff --git a/test/SemaObjC/arc-decls.m b/test/SemaObjC/arc-decls.m new file mode 100644 index 0000000..e713d23 --- /dev/null +++ b/test/SemaObjC/arc-decls.m @@ -0,0 +1,64 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-nonfragile-abi -verify %s + +// rdar://8843524 + +struct A { + id x; // expected-error {{ARC forbids Objective-C objects in structs or unions}} +}; + +union u { + id u; // expected-error {{ARC forbids Objective-C objects in structs or unions}} +}; + +@interface I { + struct A a; + struct B { + id y[10][20]; // expected-error {{ARC forbids Objective-C objects in structs or unions}} + id z; + } b; + + union u c; +}; +@end + +struct S { + id __attribute__((objc_ownership(none))) i; + void * vp; + int i1; +}; + +// rdar://9046528 + +@class NSError; + +__autoreleasing id X; // expected-error {{global variables cannot have __autoreleasing ownership}} +__autoreleasing NSError *E; // expected-error {{global variables cannot have __autoreleasing ownership}} + + +extern id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} + +void func() +{ + id X; + static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} + extern id __autoreleasing E; // expected-error {{global variables cannot have __autoreleasing ownership}} + +} + +// rdar://9157348 + +@interface J +@property (retain) id newFoo; // expected-note {{property declared here}} +@property (strong) id copyBar; // expected-note {{property declared here}} +@property (copy) id allocBaz; // expected-note {{property declared here}} +@property (copy, nonatomic) id new; +@end + +@implementation J +@synthesize newFoo; // expected-error {{property's synthesized getter follows Cocoa naming convention for returning}} +@synthesize copyBar; // expected-error {{property's synthesized getter follows Cocoa naming convention for returning}} +@synthesize allocBaz; // expected-error {{property's synthesized getter follows Cocoa naming convention for returning}} +@synthesize new; +- new {return 0; }; +@end + diff --git a/test/SemaObjC/arc-jump-block.m b/test/SemaObjC/arc-jump-block.m new file mode 100644 index 0000000..1c7b21e --- /dev/null +++ b/test/SemaObjC/arc-jump-block.m @@ -0,0 +1,84 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fblocks -verify %s +// rdar://9535237 + +typedef struct dispatch_queue_s *dispatch_queue_t; + +typedef void (^dispatch_block_t)(void); + +void dispatch_async(dispatch_queue_t queue, dispatch_block_t block); + +extern __attribute__((visibility("default"))) struct dispatch_queue_s _dispatch_main_q; + +@interface SwitchBlockCrashAppDelegate +- (void)pageLeft; +- (void)pageRight;; +@end + +@implementation SwitchBlockCrashAppDelegate + +- (void)choose:(int)button { + switch (button) { + case 0: + dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; }); // expected-note 3 {{jump enters lifetime of block which strongly captures a variable}} + break; + case 2: // expected-error {{switch case is in protected scope}} + dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); // expected-note 2 {{jump enters lifetime of block which strongly captures a variable}} + break; + case 3: // expected-error {{switch case is in protected scope}} + { + dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); + break; + } + case 4: // expected-error {{switch case is in protected scope}} + break; + } + + __block SwitchBlockCrashAppDelegate *captured_block_obj; + switch (button) { + case 10: + { + dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; }); + break; + } + case 12: + if (button) + dispatch_async((&_dispatch_main_q), ^{ [captured_block_obj pageRight]; }); + break; + case 13: + while (button) + dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); + break; + case 14: + break; + } + + switch (button) { + case 10: + { + dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; }); + break; + } + case 12: + if (button) + dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); + switch (button) { + case 0: + { + dispatch_async((&_dispatch_main_q), ^{ [self pageLeft]; }); + break; + } + case 4: + break; + } + break; + case 13: + while (button) + dispatch_async((&_dispatch_main_q), ^{ [self pageRight]; }); + break; + case 14: + break; + } +} +- (void)pageLeft {} +- (void)pageRight {} +@end diff --git a/test/SemaObjC/arc-no-runtime.m b/test/SemaObjC/arc-no-runtime.m new file mode 100644 index 0000000..94299e2 --- /dev/null +++ b/test/SemaObjC/arc-no-runtime.m @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fobjc-arc -fobjc-nonfragile-abi -verify %s + +// rdar://problem/9150784 +void test(void) { + __weak id x; // expected-error {{the current deployment target does not support automated __weak references}} +} + +@interface A +@property (weak) id testObjectWeakProperty; // expected-note {{declared here}} +@end + +@implementation A +// rdar://9605088 +@synthesize testObjectWeakProperty; // expected-error {{the current deployment target does not support automated __weak references}} +@end diff --git a/test/SemaObjC/arc-non-pod-memaccess.m b/test/SemaObjC/arc-non-pod-memaccess.m new file mode 100644 index 0000000..c9a7751 --- /dev/null +++ b/test/SemaObjC/arc-non-pod-memaccess.m @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s +// RUN: %clang_cc1 -x objective-c++ -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s + +#ifdef __cplusplus +extern "C" { +#endif + +void *memset(void *, int, __SIZE_TYPE__); +void *memmove(void *s1, const void *s2, __SIZE_TYPE__ n); +void *memcpy(void *s1, const void *s2, __SIZE_TYPE__ n); + +#ifdef __cplusplus +} +#endif + +void test(id __strong *sip, id __weak *wip, id __autoreleasing *aip, + id __unsafe_unretained *uip, void *ptr) { + // All okay. + memset(sip, 0, 17); + memset(wip, 0, 17); + memset(aip, 0, 17); + memset(uip, 0, 17); + + memcpy(sip, ptr, 17); // expected-warning{{destination for this 'memcpy' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memcpy(wip, ptr, 17); // expected-warning{{destination for this 'memcpy' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memcpy(aip, ptr, 17); // expected-warning{{destination for this 'memcpy' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memcpy(uip, ptr, 17); + + memcpy(ptr, sip, 17); // expected-warning{{source of this 'memcpy' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memcpy(ptr, wip, 17); // expected-warning{{source of this 'memcpy' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memcpy(ptr, aip, 17); // expected-warning{{source of this 'memcpy' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memcpy(ptr, uip, 17); + + memmove(sip, ptr, 17); // expected-warning{{destination for this 'memmove' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memmove(wip, ptr, 17); // expected-warning{{destination for this 'memmove' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memmove(aip, ptr, 17); // expected-warning{{destination for this 'memmove' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memmove(uip, ptr, 17); + + memmove(ptr, sip, 17); // expected-warning{{source of this 'memmove' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memmove(ptr, wip, 17); // expected-warning{{source of this 'memmove' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memmove(ptr, aip, 17); // expected-warning{{source of this 'memmove' call is a pointer to ownership-qualified type}} \ + // expected-note{{explicitly cast the pointer to silence this warning}} + memmove(ptr, uip, 17); +} diff --git a/test/SemaObjC/arc-peformselector.m b/test/SemaObjC/arc-peformselector.m new file mode 100644 index 0000000..e637f3d --- /dev/null +++ b/test/SemaObjC/arc-peformselector.m @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify %s +// rdar://9659270 + +@interface NSObject +- (id)copy; // expected-note {{method declared here}} +- (id) test __attribute__((ns_returns_retained)); // expected-note {{method declared here}} ++ (id) new ; // expected-note {{method declared here}} +- (id) init __attribute__((ns_returns_not_retained)); +- (id)PlusZero; +- (id)PlusOne __attribute__((ns_returns_retained)); // expected-note {{method declared here}} +@end + +@interface I : NSObject +{ + SEL sel1; +} +- (id)performSelector:(SEL)aSelector; +- (id)performSelector:(SEL)aSelector withObject:(id)object; +- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2; +@end + +@implementation I +- (id) Meth { + return [self performSelector : @selector(copy)]; // expected-error {{performSelector names a selector which retains the object}} + return [self performSelector : @selector(test)]; // expected-error {{performSelector names a selector which retains the object}} + return [self performSelector : @selector(new)]; // expected-error {{performSelector names a selector which retains the object}} + return [self performSelector : @selector(init)]; + return [self performSelector : sel1]; // expected-warning {{performSelector may cause a leak because its selector is unknown}} \ + // expected-note {{used here}} + + return [self performSelector : @selector(PlusZero)]; + return [self performSelector : @selector(PlusOne)]; // expected-error {{performSelector names a selector which retains the object}} +} + +- (id)performSelector:(SEL)aSelector { return 0; } +- (id)performSelector:(SEL)aSelector withObject:(id)object { return 0; } +- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2 { return 0; } +@end diff --git a/test/SemaObjC/arc-property-decl-attrs.m b/test/SemaObjC/arc-property-decl-attrs.m new file mode 100644 index 0000000..0dd74b8 --- /dev/null +++ b/test/SemaObjC/arc-property-decl-attrs.m @@ -0,0 +1,67 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s +// rdar://9340606 + +@interface Foo { +@public + id __unsafe_unretained x; + id __weak y; + id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}} +} +@property(strong) id x; +@property(strong) id y; +@property(strong) id z; +@end + +@interface Bar { +@public + id __unsafe_unretained x; + id __weak y; + id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}} +} +@property(retain) id x; +@property(retain) id y; +@property(retain) id z; +@end + +@interface Bas { +@public + id __unsafe_unretained x; + id __weak y; + id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}} +} +@property(copy) id x; +@property(copy) id y; +@property(copy) id z; +@end + +// Errors should start about here :-) + +@interface Bat +@property(strong) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} +@property(strong) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}} expected-error {{property attributes 'strong' and 'weak' are mutually exclusive}} +@property(strong) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} +@end + +@interface Bau +@property(retain) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} +@property(retain) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}} expected-error {{property attributes 'retain' and 'weak' are mutually exclusive}} +@property(retain) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} +@end + +@interface Bav +@property(copy) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} +@property(copy) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}} expected-error {{property attributes 'copy' and 'weak' are mutually exclusive}} +@property(copy) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} +@end + +@interface Bingo +@property(assign) __unsafe_unretained id x; +@property(assign) __weak id y; // expected-error {{property attributes 'assign' and 'weak' are mutually exclusive}} +@property(assign) __autoreleasing id z; // expected-error {{unsafe_unretained property 'z' may not also be declared __autoreleasing}} +@end + +@interface Batman +@property(unsafe_unretained) __unsafe_unretained id x; +@property(unsafe_unretained) __weak id y; // expected-error {{property attributes 'unsafe_unretained' and 'weak' are mutually exclusive}} +@property(unsafe_unretained) __autoreleasing id z; // expected-error {{unsafe_unretained property 'z' may not also be declared __autoreleasing}} +@end diff --git a/test/SemaObjC/arc-property-lifetime.m b/test/SemaObjC/arc-property-lifetime.m new file mode 100644 index 0000000..b1c84c7 --- /dev/null +++ b/test/SemaObjC/arc-property-lifetime.m @@ -0,0 +1,112 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s +// rdar://9340606 + +@interface Foo { +@public + id __unsafe_unretained x; + id __weak y; + id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}} +} +@property(strong) id x; // expected-note {{property declared here}} +@property(strong) id y; // expected-note {{property declared here}} +@property(strong) id z; +@end + +@implementation Foo +@synthesize x; // expected-error {{existing ivar 'x' for strong property 'x' may not be __unsafe_unretained}} +@synthesize y; // expected-error {{existing ivar 'y' for strong property 'y' may not be __weak}} +@synthesize z; // suppressed +@end + +@interface Bar { +@public + id __unsafe_unretained x; + id __weak y; + id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}} +} +@property(retain) id x; // expected-note {{property declared here}} +@property(retain) id y; // expected-note {{property declared here}} +@property(retain) id z; +@end + +@implementation Bar +@synthesize x; // expected-error {{existing ivar 'x' for strong property 'x' may not be __unsafe_unretained}} +@synthesize y; // expected-error {{existing ivar 'y' for strong property 'y' may not be __weak}} +@synthesize z; // suppressed +@end + +@interface Bas { +@public + id __unsafe_unretained x; + id __weak y; + id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}} +} +@property(copy) id x; // expected-note {{property declared here}} +@property(copy) id y; // expected-note {{property declared here}} +@property(copy) id z; +@end + +@implementation Bas +@synthesize x; // expected-error {{existing ivar 'x' for strong property 'x' may not be __unsafe_unretained}} +@synthesize y; // expected-error {{existing ivar 'y' for strong property 'y' may not be __weak}} +@synthesize z; // suppressed +@end + +@interface Bat +@property(strong) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} +@property(strong) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} +@end + +@interface Bau +@property(retain) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} +@property(retain) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} +@end + +@interface Bav +@property(copy) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} +@property(copy) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} +@end + +// rdar://9341593 +@interface Gorf { + id __unsafe_unretained x; + id y; +} +@property(assign) id __unsafe_unretained x; +@property(assign) id y; // expected-note {{property declared here}} +@property(assign) id z; +@end + +@implementation Gorf +@synthesize x; +@synthesize y; // expected-error {{existing ivar 'y' for unsafe_unretained property 'y' must be __unsafe_unretained}} +@synthesize z; +@end + +@interface Gorf2 { + id __unsafe_unretained x; + id y; +} +@property(unsafe_unretained) id __unsafe_unretained x; +@property(unsafe_unretained) id y; // expected-note {{property declared here}} +@property(unsafe_unretained) id z; +@end + +@implementation Gorf2 +@synthesize x; +@synthesize y; // expected-error {{existing ivar 'y' for unsafe_unretained property 'y' must be __unsafe_unretained}} +@synthesize z; +@end + +// rdar://9355230 +@interface I { + char _isAutosaving; +} +@property char isAutosaving; + +@end + +@implementation I +@synthesize isAutosaving = _isAutosaving; +@end + diff --git a/test/SemaObjC/arc-property.m b/test/SemaObjC/arc-property.m new file mode 100644 index 0000000..0651f18 --- /dev/null +++ b/test/SemaObjC/arc-property.m @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify %s +// rdar://9309489 + +@interface MyClass { + id __weak myString; + id StrongIvar; + id __weak myString2; + id __weak myString3; + id StrongIvar5; +} +@property (strong) id myString; // expected-note {{property declared here}} +@property (strong) id myString1; +@property (retain) id myString2; // expected-note {{property declared here}} +// +@property (weak) id myString3; +@property (weak) id myString4; +@property __weak id myString5; // expected-note {{property declared here}} +@end + +@implementation MyClass +@synthesize myString; // expected-error {{existing ivar 'myString' for strong property 'myString' may not be __weak}} +@synthesize myString1 = StrongIvar; // OK +@synthesize myString2 = myString2; // expected-error {{existing ivar 'myString2' for strong property 'myString2' may not be __weak}} +// +@synthesize myString3; // OK +@synthesize myString4; // OK +@synthesize myString5 = StrongIvar5; // expected-error {{existing ivar 'StrongIvar5' for __weak property 'myString5' must be __weak}} + +@end + +// rdar://9340692 +@interface Foo { +@public + id __unsafe_unretained x; // should be __weak + id __strong y; + id __autoreleasing z; // expected-error {{ivars cannot have __autoreleasing ownership}} +} +@property(weak) id x; // expected-note {{property declared here}} +@property(weak) id y; // expected-note {{property declared here}} +@property(weak) id z; +@end + +@implementation Foo +@synthesize x; // expected-error {{existing ivar 'x' for __weak property 'x' must be __weak}} +@synthesize y; // expected-error {{existing ivar 'y' for __weak property 'y' must be __weak}} +@synthesize z; // suppressed +@end + diff --git a/test/SemaObjC/arc-system-header.m b/test/SemaObjC/arc-system-header.m new file mode 100644 index 0000000..3f17657 --- /dev/null +++ b/test/SemaObjC/arc-system-header.m @@ -0,0 +1,50 @@ +// silly workaround expected-note {{marked unavailable here}} +// RUN: %clang_cc1 -fobjc-arc -fobjc-nonfragile-abi -isystem %S/Inputs %s -DNO_USE +// RUN: %clang_cc1 -fobjc-arc -fobjc-nonfragile-abi -isystem %S/Inputs %s -verify + +// another silly workaround expected-note {{marked unavailable here}} +#include <arc-system-header.h> + +#ifndef NO_USE +void test(id op, void *cp) { + cp = test0(op); // expected-error {{'test0' is unavailable: converts between Objective-C and C pointers in -fobjc-arc}} + cp = *test1(&op); // expected-error {{'test1' is unavailable: converts between Objective-C and C pointers in -fobjc-arc}} +} + +// workaround expected-note {{marked unavailable here}} +void test3(struct Test3 *p) { + p->field = 0; // expected-error {{'field' is unavailable: this system declaration uses an unsupported type}} +} + +// workaround expected-note {{marked unavailable here}} +void test4(Test4 *p) { + p->field1 = 0; // expected-error {{'field1' is unavailable: this system declaration uses an unsupported type}} + p->field2 = 0; +} + +// workaround expected-note {{marked unavailable here}} +void test5(struct Test5 *p) { + p->field = 0; // expected-error {{'field' is unavailable: this system field has retaining ownership}} +} + +id test6() { + // This is actually okay to use if declared in a system header. + id x; + x = (id) kMagicConstant; + x = (id) (x ? kMagicConstant : kMagicConstant); + x = (id) (x ? kMagicConstant : (void*) 0); + + extern void test6_helper(); + x = (id) (test6_helper(), kMagicConstant); +} + +// workaround expected-note 4 {{marked unavailable here}} +void test7(Test7 *p) { + *p.prop = 0; // expected-error {{'prop' is unavailable: this system declaration uses an unsupported type}} + p.prop = 0; // expected-error {{'prop' is unavailable: this system declaration uses an unsupported type}} + *[p prop] = 0; // expected-error {{'prop' is unavailable: this system declaration uses an unsupported type}} + [p setProp: 0]; // expected-error {{'setProp:' is unavailable: this system declaration uses an unsupported type}} +} +#endif + +// test8 in header diff --git a/test/SemaObjC/arc-type-conversion.m b/test/SemaObjC/arc-type-conversion.m new file mode 100644 index 0000000..103db56 --- /dev/null +++ b/test/SemaObjC/arc-type-conversion.m @@ -0,0 +1,77 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-weak -verify -fblocks %s + +void * cvt(id arg) +{ + void* voidp_val; + (void)(int*)arg; // expected-error {{cast of an Objective-C pointer to 'int *' is disallowed with ARC}} + (void)(id)arg; + (void)(__autoreleasing id*)arg; // expected-error {{cast of an Objective-C pointer to '__autoreleasing id *' is disallowed with ARC}} + (void)(id*)arg; // expected-error {{cast of an Objective-C pointer to '__strong id *' is disallowed with ARC}} + + (void)(__autoreleasing id**)voidp_val; + (void)(void*)voidp_val; + (void)(void**)arg; // expected-error {{cast of an Objective-C pointer to 'void **' is disallowed with ARC}} + cvt((void*)arg); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \ + // expected-error {{implicit conversion of a non-Objective-C pointer type 'void *' to 'id' is disallowed with ARC}} \ + // expected-note{{use __bridge to convert directly (no change in ownership)}} \ + // expected-note{{use __bridge_retained to make an ARC object available as a +1 'void *'}} + cvt(0); + (void)(__strong id**)(0); + return arg; // expected-error {{implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC}} +} + +void to_void(__strong id *sip, __weak id *wip, + __autoreleasing id *aip, + __unsafe_unretained id *uip) { + void *vp1 = sip; + void *vp2 = wip; + void *vp3 = aip; + void *vp4 = uip; + (void)(void*)sip; + (void)(void*)wip; + (void)(void*)aip; + (void)(void*)uip; + (void)(void*)&sip; + (void)(void*)&wip; + (void)(void*)&aip; + (void)(void*)&uip; +} + +void from_void(void *vp) { + __strong id *sip = (__strong id *)vp; + __weak id *wip = (__weak id *)vp; + __autoreleasing id *aip = (__autoreleasing id *)vp; + __unsafe_unretained id *uip = (__unsafe_unretained id *)vp; + + __strong id **sipp = (__strong id **)vp; + __weak id **wipp = (__weak id **)vp; + __autoreleasing id **aipp = (__autoreleasing id **)vp; + __unsafe_unretained id **uipp = (__unsafe_unretained id **)vp; + + sip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__strong id *' is disallowed with ARC}} + wip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__weak id *' is disallowed with ARC}} + aip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__autoreleasing id *' is disallowed with ARC}} + uip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__unsafe_unretained id *' is disallowed with ARC}} +} + +typedef void (^Block)(); +typedef void (^Block_strong)() __strong; +typedef void (^Block_autoreleasing)() __autoreleasing; + +@class NSString; + +void ownership_transfer_in_cast(void *vp, Block *pblk) { + __strong NSString **sip = (NSString**)(__strong id *)vp; + __weak NSString **wip = (NSString**)(__weak id *)vp; + __autoreleasing id *aip = (id*)(__autoreleasing id *)vp; + __unsafe_unretained id *uip = (id*)(__unsafe_unretained id *)vp; + + __strong id **sipp = (id**)(__strong id **)vp; + __weak id **wipp = (id**)(__weak id **)vp; + __autoreleasing id **aipp = (id**)(__autoreleasing id **)vp; + __unsafe_unretained id **uipp = (id**)(__unsafe_unretained id **)vp; + + Block_strong blk_strong1; + Block_strong blk_strong2 = (Block)blk_strong1; + Block_autoreleasing *blk_auto = (Block*)pblk; +} diff --git a/test/SemaObjC/arc-unavailable-for-weakref.m b/test/SemaObjC/arc-unavailable-for-weakref.m new file mode 100644 index 0000000..104314e --- /dev/null +++ b/test/SemaObjC/arc-unavailable-for-weakref.m @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s +// rdar://9693477 + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface NSOptOut1072 // expected-note {{class is declared here}} +@end + +@interface sub : NSOptOut1072 @end // expected-note 2 {{class is declared here}} + +int main() { + __weak sub *w2; // expected-error {{class is incompatible with __weak references}} + + __weak NSOptOut1072 *ns1; // expected-error {{class is incompatible with __weak references}} + + id obj; + + ns1 = (__weak sub *)obj; // expected-error {{assignment of a weak-unavailable object to a __weak object}} \ + // expected-error {{class is incompatible with __weak references}} +} + +// rdar://9732636 +__attribute__((objc_arc_weak_reference_unavailable)) +@interface NOWEAK ++ (id) new; +@end + +NOWEAK * Test1() { + NOWEAK * strong1 = [NOWEAK new]; + __weak id weak1; + weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} + + __weak id weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} + return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}} +} + +@protocol P @end +@protocol P1 @end + +NOWEAK<P, P1> * Test2() { + NOWEAK<P, P1> * strong1 = 0; + __weak id<P> weak1; + weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} + + __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} + return (__weak id<P>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P>'}} +} + diff --git a/test/SemaObjC/arc-unbridged-cast.m b/test/SemaObjC/arc-unbridged-cast.m new file mode 100644 index 0000000..03c84cf --- /dev/null +++ b/test/SemaObjC/arc-unbridged-cast.m @@ -0,0 +1,18 @@ +// // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify %s +// rdar://9744349 + +typedef const struct __CFString * CFStringRef; + +@interface I +@property CFStringRef P; +@end + +@implementation I +@synthesize P; +- (id) Meth { + I* p1 = (id)[p1 P]; + id p2 = (__bridge_transfer id)[p1 P]; + id p3 = (__bridge I*)[p1 P]; + return (id) p1.P; +} +@end diff --git a/test/SemaObjC/arc-unsafe-assigns.m b/test/SemaObjC/arc-unsafe-assigns.m new file mode 100644 index 0000000..be8f902 --- /dev/null +++ b/test/SemaObjC/arc-unsafe-assigns.m @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify %s +// rdar://9495837 + +@interface Foo { + __unsafe_unretained id unsafe_ivar; +} + +@property (assign,nonatomic) id unsafe_prop; + +- (id)init; ++ (id)new; ++ (id)alloc; + +-(void)Meth; +@end + +@implementation Foo +@synthesize unsafe_prop; +-(id)init { return self; } ++(id)new { return 0; } ++(id)alloc { return 0; } + +-(void)Meth { + self.unsafe_prop = [Foo new]; // expected-warning {{assigning retained object to unsafe property}} + self->unsafe_ivar = [Foo new]; // expected-warning {{assigning retained object to unsafe_unretained}} + self.unsafe_prop = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe property}} + self->unsafe_ivar = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe_unretained}} + + __unsafe_unretained id unsafe_var; + unsafe_var = [Foo new]; // expected-warning {{assigning retained object to unsafe_unretained}} + unsafe_var = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe_unretained}} +} +@end + +void bar(Foo *f) { + f.unsafe_prop = [Foo new]; // expected-warning {{assigning retained object to unsafe property}} + + __unsafe_unretained id unsafe_var; + unsafe_var = [Foo new]; // expected-warning {{assigning retained object to unsafe_unretained}} + unsafe_var = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe_unretained}} +} diff --git a/test/SemaObjC/arc-unsafe_unretained.m b/test/SemaObjC/arc-unsafe_unretained.m new file mode 100644 index 0000000..77bdded --- /dev/null +++ b/test/SemaObjC/arc-unsafe_unretained.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -fobjc-nonfragile-abi %s +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -fobjc-nonfragile-abi -fobjc-arc %s + +struct X { + __unsafe_unretained id object; + int (^ __unsafe_unretained block)(int, int); +}; + +void f(struct X x) { + x.object = 0; + x.block = ^(int x, int y) { return x + y; }; +} diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m new file mode 100644 index 0000000..3d190e5 --- /dev/null +++ b/test/SemaObjC/arc.m @@ -0,0 +1,628 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify %s + +typedef unsigned long NSUInteger; + +void test0(void (*fn)(int), int val) { + fn(val); +} + +@interface A +- (id)retain; +- (id)autorelease; +- (oneway void)release; +- (void)dealloc; +- (NSUInteger)retainCount; +@end + +void test1(A *a) { + SEL s = @selector(retain); // expected-error {{ARC forbids use of 'retain' in a @selector}} + s = @selector(release); // expected-error {{ARC forbids use of 'release' in a @selector}} + s = @selector(autorelease); // expected-error {{ARC forbids use of 'autorelease' in a @selector}} + s = @selector(dealloc); // expected-error {{ARC forbids use of 'dealloc' in a @selector}} + [a dealloc]; // expected-error {{ARC forbids explicit message send of 'dealloc'}} + [a retain]; // expected-error {{ARC forbids explicit message send of 'retain'}} + [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}} + [a release]; // expected-error {{ARC forbids explicit message send of 'release'}} + [a autorelease]; // expected-error {{ARC forbids explicit message send of 'autorelease'}} +} + +@interface Test2 : A +- (void) dealloc; +@end +@implementation Test2 +- (void) dealloc { + // This should maybe just be ignored. We're just going to warn about it for now. + [super dealloc]; // expected-error {{ARC forbids explicit message send of 'dealloc'}} +} +@end + +__weak __strong id x; // expected-error {{the type '__strong id' already has retainment attributes}} + +// rdar://8843638 + +@interface I +- (id)retain; +- (id)autorelease; +- (oneway void)release; +- (NSUInteger)retainCount; +@end + +@implementation I +- (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}} +- (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}} +- (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}} +- (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}} +@end + +@implementation I(CAT) +- (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}} +- (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}} +- (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}} +- (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}} +@end + +// rdar://8861761 + +@interface B +-(id)alloc; +- (id)initWithInt: (int) i; +@end + +void rdar8861761() { + B *o1 = [[B alloc] initWithInt:0]; + B *o2 = [B alloc]; + [o2 initWithInt:0]; // expected-warning {{expression result unused}} +} + +// rdar://8925835 +@interface rdar8925835 +- (void)foo:(void (^)(unsigned captureCount, I * const capturedStrings[captureCount]))block; +@end + +void test5() { + extern void test5_helper(__autoreleasing id *); + id x; + + // Okay because of magic temporaries. + test5_helper(&x); + + __autoreleasing id *a = &x; // expected-error {{initializing '__autoreleasing id *' with an expression of type '__strong id *' changes retain/release properties of pointer}} + + a = &x; // expected-error {{assigning '__strong id *' to '__autoreleasing id *' changes retain/release properties of pointer}} + + extern void test5_helper2(id const *); + test5_helper2(&x); + + extern void test5_helper3(__weak id *); // expected-note {{passing argument to parameter here}} + test5_helper3(&x); // expected-error {{passing '__strong id *' to parameter of type '__weak id *' changes retain/release properties of pointer}} +} + +// rdar://problem/8937869 +void test6(unsigned cond) { + switch (cond) { + case 0: + ; + id x; // expected-note {{jump bypasses initialization of retaining variable}} + + case 1: // expected-error {{switch case is in protected scope}} + break; + } +} + +@class NSError; +void test7(void) { + extern void test7_helper(NSError **); + NSError *err; + test7_helper(&err); +} +void test7_weak(void) { + extern void test7_helper(NSError **); + __weak NSError *err; + test7_helper(&err); +} +void test7_unsafe(void) { + extern void test7_helper(NSError **); // expected-note {{passing argument to parameter here}} + __unsafe_unretained NSError *err; + test7_helper(&err); // expected-error {{passing 'NSError *__unsafe_unretained *' to parameter of type 'NSError *__autoreleasing *' changes retain/release properties of pointer}} +} + +@class Test8_incomplete; +@interface Test8_complete @end; +@interface Test8_super @end; +@interface Test8 : Test8_super +- (id) init00; +- (id) init01; // expected-note {{declaration in interface}} \ + // expected-note{{overridden method}} +- (id) init02; // expected-note{{overridden method}} +- (id) init03; // covariance +- (id) init04; // covariance +- (id) init05; // expected-note{{overridden method}} + +- (void) init10; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} +- (void) init11; +- (void) init12; +- (void) init13; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} +- (void) init14; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} +- (void) init15; + +// These should be invalid to actually call. +- (Test8_incomplete*) init20; +- (Test8_incomplete*) init21; // expected-note {{declaration in interface}} +- (Test8_incomplete*) init22; +- (Test8_incomplete*) init23; +- (Test8_incomplete*) init24; +- (Test8_incomplete*) init25; + +- (Test8_super*) init30; // id exception to covariance +- (Test8_super*) init31; // expected-note {{declaration in interface}} \ + // expected-note{{overridden method}} +- (Test8_super*) init32; // expected-note{{overridden method}} +- (Test8_super*) init33; +- (Test8_super*) init34; // covariance +- (Test8_super*) init35; // expected-note{{overridden method}} + +- (Test8*) init40; // id exception to covariance +- (Test8*) init41; // expected-note {{declaration in interface}} \ + // expected-note{{overridden method}} +- (Test8*) init42; // expected-note{{overridden method}} +- (Test8*) init43; // this should be a warning, but that's a general language thing, not an ARC thing +- (Test8*) init44; +- (Test8*) init45; // expected-note{{overridden method}} + +- (Test8_complete*) init50; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init51; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init52; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init53; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init54; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init55; // expected-error {{init methods must return a type related to the receiver type}} +@end +@implementation Test8 +- (id) init00 { return 0; } +- (id) init10 { return 0; } // expected-error {{method implementation does not match its declaration}} +- (id) init20 { return 0; } +- (id) init30 { return 0; } +- (id) init40 { return 0; } +- (id) init50 { return 0; } + +- (void) init01 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \ + // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}} +- (void) init11 {} +- (void) init21 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} +- (void) init31 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \ + // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}} +- (void) init41 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \ + // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}} +- (void) init51 {} + +- (Test8_incomplete*) init02 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \ + // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}} +- (Test8_incomplete*) init12 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init22 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init32 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \ + // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}} +- (Test8_incomplete*) init42 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \ + // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}} +- (Test8_incomplete*) init52 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} + +- (Test8_super*) init03 { return 0; } +- (Test8_super*) init13 { return 0; } // expected-error {{method implementation does not match its declaration}} +- (Test8_super*) init23 { return 0; } +- (Test8_super*) init33 { return 0; } +- (Test8_super*) init43 { return 0; } +- (Test8_super*) init53 { return 0; } + +- (Test8*) init04 { return 0; } +- (Test8*) init14 { return 0; } // expected-error {{method implementation does not match its declaration}} +- (Test8*) init24 { return 0; } +- (Test8*) init34 { return 0; } +- (Test8*) init44 { return 0; } +- (Test8*) init54 { return 0; } + +- (Test8_complete*) init05 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \ + // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}} +- (Test8_complete*) init15 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init25 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init35 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \ + // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}} +- (Test8_complete*) init45 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \ + // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}} +- (Test8_complete*) init55 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +@end + +@class Test9_incomplete; +@interface Test9 +- (Test9_incomplete*) init1; // expected-error {{init methods must return a type related to the receiver type}} +- (Test9_incomplete*) init2; +@end +id test9(Test9 *v) { + return [v init1]; +} + +// Test that the inference rules are different for fast enumeration variables. +void test10(id collection) { + for (id x in collection) { + __strong id *ptr = &x; // expected-warning {{initializing '__strong id *' with an expression of type 'const __strong id *' discards qualifiers}} + } + + for (__strong id x in collection) { + __weak id *ptr = &x; // expected-error {{initializing '__weak id *' with an expression of type '__strong id *' changes retain/release properties of pointer}} + } +} + +// rdar://problem/9078626 +#define nil ((void*) 0) +void test11(id op, void *vp) { + _Bool b; + b = (op == nil); + b = (nil == op); + + b = (vp == nil); + b = (nil == vp); + + b = (vp == op); // expected-error {{implicit conversion of an Objective-C pointer to 'void *'}} + b = (op == vp); // expected-error {{implicit conversion of a non-Objective-C pointer type 'void *' to 'id'}} +} + +void test12(id collection) { + for (id x in collection) { + x = 0; // expected-error {{fast enumeration variables can't be modified in ARC by default; declare the variable __strong to allow this}} + } + + for (const id x in collection) { + x = 0; // expected-error {{read-only variable is not assignable}} + } + + for (__strong id x in collection) { + x = 0; + } +} + +@interface Test13 +- (id) init0; +- (void) noninit; +@end +@implementation Test13 +- (id) init0 { + self = 0; +} +- (void) noninit { + self = 0; // expected-error {{cannot assign to 'self' outside of a method in the init family}} +} +@end + +// rdar://problem/9172151 +@class Test14A, Test14B; +void test14() { + extern void test14_consume(id *); + extern int test14_cond(void); + extern float test14_nowriteback(id __autoreleasing const *); // expected-note{{passing argument to parameter here}} + + Test14A *a; + Test14B *b; + id i; + id cla[10]; + id vla[test14_cond() + 10]; + + test14_consume((__strong id*) &a); + test14_consume((test14_cond() ? (__strong id*) &b : &i)); + test14_consume(test14_cond() ? 0 : &a); + test14_consume(test14_cond() ? (void*) 0 : (&a)); + test14_consume(cla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}} + test14_consume(vla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}} + test14_consume(&cla[5]); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}} + + __strong id *test14_indirect(void); + test14_consume(test14_indirect()); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}} + + extern id test14_global; + test14_consume(&test14_global); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}} + + extern __strong id *test14_global_ptr; + test14_consume(test14_global_ptr); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}} + + static id static_local; + test14_consume(&static_local); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}} + + __weak id* wip; + test14_nowriteback(&static_local); // okay, not a write-back. + test14_nowriteback(wip); // expected-error{{passing '__weak id *' to parameter of type '__autoreleasing id const *' changes retain/release properties of pointer}} +} + +void test15() { + __block __autoreleasing id x; // expected-error {{__block variables cannot have __autoreleasing ownership}} +} + +struct Test16; +@interface Test16a +- (void) test16_0: (int) x; +- (int) test16_1: (int) x; // expected-note {{one possibility}} +- (int) test16_2: (int) x; // expected-note {{one possibility}} +- (id) test16_3: (int) x __attribute__((ns_returns_retained)); // expected-note {{one possibility}} +- (void) test16_4: (int) x __attribute__((ns_consumes_self)); // expected-note {{one possibility}} +- (void) test16_5: (id) __attribute__((ns_consumed)) x; // expected-note {{one possibility}} +- (void) test16_6: (id) x; +@end + +@interface Test16b +- (void) test16_0: (int) x; +- (int) test16_1: (char*) x; // expected-note {{also found}} +- (char*) test16_2: (int) x; // expected-note {{also found}} +- (id) test16_3: (int) x; // expected-note {{also found}} +- (void) test16_4: (int) x; // expected-note {{also found}} +- (void) test16_5: (id) x; // expected-note {{also found}} +- (void) test16_6: (struct Test16 *) x; +@end + +void test16(void) { + id v; + [v test16_0: 0]; + [v test16_1: 0]; // expected-error {{multiple methods named 'test16_1:' found with mismatched result, parameter type or attributes}} + [v test16_2: 0]; // expected-error {{multiple methods named}} + [v test16_3: 0]; // expected-error {{multiple methods named}} + [v test16_4: 0]; // expected-error {{multiple methods named}} + [v test16_5: 0]; // expected-error {{multiple methods named}} + [v test16_6: 0]; +} + +@class Test17; +@protocol Test17p +- (void) test17; ++ (void) test17; +@end +void test17(void) { + Test17 *v0; + [v0 test17]; // expected-error {{receiver type 'Test17' for instance message is a forward declaration}} + + Test17<Test17p> *v1; + [v1 test17]; // expected-error {{receiver type 'Test17<Test17p>' for instance message is a forward declaration}} + + [Test17 test17]; // expected-error {{receiver 'Test17' for class message is a forward declaration}} +} + +void test18(void) { + id x; + [x test18]; // expected-error {{no known instance method for selector 'test18'}} +} + +extern struct Test19 *test19a; +struct Test19 *const test19b = 0; +void test19(void) { + id x; + x = (id) test19a; // expected-error {{bridged cast}} \ + // expected-note{{use __bridge to convert directly (no change in ownership))}} \ + // expected-note{{use __bridge_transfer to transfer ownership of a +1 'struct Test19 *' into ARC}} + x = (id) test19b; // expected-error {{bridged cast}} \ + // expected-note{{use __bridge to convert directly (no change in ownership)}} \ + // expected-note{{use __bridge_transfer to transfer ownership of a +1 'struct Test19 *' into ARC}} +} + +// rdar://problem/8951453 +static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}} +static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}} +static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}} +static __thread __autoreleasing id test20_autoreleasing; // expected-error {{thread-local variable has non-trivial ownership: type is '__autoreleasing id'}} expected-error {{global variables cannot have __autoreleasing ownership}} +static __thread __unsafe_unretained id test20_unsafe; +void test20(void) { + static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}} + static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}} + static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}} + static __thread __autoreleasing id test20_autoreleasing; // expected-error {{thread-local variable has non-trivial ownership: type is '__autoreleasing id'}} expected-error {{global variables cannot have __autoreleasing ownership}} + static __thread __unsafe_unretained id test20_unsafe; +} + +// rdar://9310049 +_Bool fn(id obj) { + return (_Bool)obj; +} + +// Check casting w/ ownership qualifiers. +void test21() { + __strong id *sip; + (void)(__weak id *)sip; // expected-error{{casting '__strong id *' to type '__weak id *' changes retain/release properties of pointer}} + (void)(__weak const id *)sip; // expected-error{{casting '__strong id *' to type '__weak id const *' changes retain/release properties of pointer}} + (void)(__autoreleasing id *)sip; // expected-error{{casting '__strong id *' to type '__autoreleasing id *' changes retain/release properties of pointer}} + (void)(__autoreleasing const id *)sip; // okay +} + +// rdar://problem/9340462 +void test22(id x[]) { // expected-error {{must explicitly describe intended ownership of an object array parameter}} +} + +// rdar://problem/9400219 +void test23(void) { + void *ptr; + ptr = @"foo"; + ptr = (ptr ? @"foo" : 0); + ptr = (ptr ? @"foo" : @"bar"); +} + +id test24(void) { + extern void test24_helper(void); + return test24_helper(), (void*) 0; +} + +// rdar://9400841 +@interface Base +@property (assign) id content; +@end + +@interface Foo : Base +-(void)test; +@end + +@implementation Foo +-(void)test { + super.content = 0; +} +@end + +// <rdar://problem/9398437> +void test25(Class *classes) { + Class *other_classes; + test25(other_classes); +} + +void test26(id y) { + extern id test26_var1; + __sync_swap(&test26_var1, 0, y); // expected-error {{cannot perform atomic operation on a pointer to type '__strong id': type has non-trivial ownership}} + + extern __unsafe_unretained id test26_var2; + __sync_swap(&test26_var2, 0, y); +} + +@interface Test26 +- (id) init; +- (id) initWithInt: (int) x; +@end +@implementation Test26 +- (id) init { return self; } +- (id) initWithInt: (int) x { + [self init]; // expected-error {{the result of a delegate init call must be immediately returned or assigned to 'self'}} + return self; +} +@end + +// rdar://9525555 +@interface Test27 +@property id x; // expected-warning {{no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed}} \ + // expected-warning {{default property attribute 'assign' not appropriate for non-gc object}} \ + // expected-note {{declared here}} +@property (readonly) id ro; // expected-note {{declared here}} +@property (readonly) id custom_ro; +@property int y; +@end + +@implementation Test27 +@synthesize x; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified storage attribute}} +@synthesize ro; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified storage attribute}} +@synthesize y; +-(id)custom_ro { return 0; } +@end + +// rdar://9569264 +@interface Test28 +@property (nonatomic, assign) __strong id a; // expected-error {{unsafe_unretained property 'a' may not also be declared __strong}} +@end + +@interface Test28 () +@property (nonatomic, assign) __strong id b; // expected-error {{unsafe_unretained property 'b' may not also be declared __strong}} +@end + +@implementation Test28 +@synthesize a; +@synthesize b; +@end + +// rdar://9573962 +typedef struct Bark Bark; +@interface Test29 +@property Bark* P; +@end + +@implementation Test29 +@synthesize P; +- (id)Meth { + Bark** f = &P; + return 0; +} +@end + +// rdar://9495837 +@interface Test30 ++ (id) new; +- (void)Meth; +@end + +@implementation Test30 ++ (id) new { return 0; } +- (void) Meth { + __weak id x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}} + id __unsafe_unretained u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}} + id y = [Test30 new]; + x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}} + u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}} + y = [Test30 new]; +} +@end + +// rdar://9411838 +@protocol PTest31 @end + +int Test31() { + Class cls; + id ids; + id<PTest31> pids; + Class<PTest31> pcls; + + int i = (ids->isa ? 1 : 0); // expected-error {{member reference base type 'id' is not a structure or union}} + int j = (pids->isa ? 1 : 0); // expected-error {{member reference base type 'id<PTest31>' is not a structure or union}} + int k = (pcls->isa ? i : j); // expected-error {{member reference base type 'Class<PTest31>' is not a structure or union}} + return cls->isa ? i : j; // expected-error {{member reference base type 'Class' is not a structure or union}} +} + +// rdar://9612030 +@interface ITest32 { +@public + id ivar; +} +@end + +id Test32(__weak ITest32 *x) { + __weak ITest32 *y; + x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}} + return y ? y->ivar // expected-error {{dereferencing a __weak pointer is not allowed}} + : (*x).ivar; // expected-error {{dereferencing a __weak pointer is not allowed}} +} + +// rdar://9619861 +extern int printf(const char*, ...); +typedef long intptr_t; + +int Test33(id someid) { + printf( "Hello%ld", (intptr_t)someid); + return (int)someid; +} + +// rdar://9636091 +@interface I34 +@property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ; + +@property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ; +- (id) newName1 __attribute__((ns_returns_not_retained)); + +@property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}} +- (id) newName2; // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}} +@end + +@implementation I34 +@synthesize newName; + +@synthesize newName1; +- (id) newName1 { return 0; } + +@synthesize newName2; +@end + +void test35(void) { + extern void test36_helper(id*); + id x; + __strong id *xp = 0; + + test36_helper(&x); + test36_helper(xp); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}} + + // rdar://problem/9665710 + __block id y; + test36_helper(&y); + ^{ test36_helper(&y); }(); + + __strong int non_objc_type; // expected-warning {{'__strong' only applies to objective-c object or block pointer types}} +} + +void test36(int first, ...) { + // <rdar://problem/9758798> + __builtin_va_list arglist; + __builtin_va_start(arglist, first); + id obj = __builtin_va_arg(arglist, id); + __builtin_va_end(arglist); +} diff --git a/test/SemaObjC/autoreleasepool.m b/test/SemaObjC/autoreleasepool.m new file mode 100644 index 0000000..41e1768 --- /dev/null +++ b/test/SemaObjC/autoreleasepool.m @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +void *objc_autoreleasepool_push(); +void autoreleasepool_pop(void*); + +@interface AUTORP @end + +@implementation AUTORP +- (void) unregisterTask:(id) task { + goto L; // expected-error {{goto into protected scope}} + + @autoreleasepool { // expected-note {{jump bypasses auto release push of @autoreleasepool block}} + void *tmp = objc_autoreleasepool_push(); + L: + autoreleasepool_pop(tmp); + @autoreleasepool { + return; + } + } +} +@end + diff --git a/test/SemaObjC/class-proto-1.m b/test/SemaObjC/class-proto-1.m index 246b500..8030976 100644 --- a/test/SemaObjC/class-proto-1.m +++ b/test/SemaObjC/class-proto-1.m @@ -23,9 +23,9 @@ @interface E2 <p1,p2,p3> @end // expected-warning {{cannot find protocol definition for 'p3'}} -@class U1, U2; +@class U1, U2; // expected-note {{forward class is declared here}} -@interface E3 : U1 @end // expected-error {{cannot find interface declaration for 'U1', superclass of 'E3'}} +@interface E3 : U1 @end // expected-error {{attempting to use the forward class 'U1' as superclass of 'E3'}} @interface I3 : E3 @end diff --git a/test/SemaObjC/class-unavail-warning.m b/test/SemaObjC/class-unavail-warning.m index 426ac77..408647a 100644 --- a/test/SemaObjC/class-unavail-warning.m +++ b/test/SemaObjC/class-unavail-warning.m @@ -2,7 +2,7 @@ // rdar://9092208 __attribute__((unavailable("not available"))) -@interface MyClass { // expected-note 5 {{function has been explicitly marked unavailable here}} +@interface MyClass { // expected-note 5 {{declaration has been explicitly marked unavailable here}} @public void *_test; } diff --git a/test/SemaObjC/debugger-support.m b/test/SemaObjC/debugger-support.m new file mode 100644 index 0000000..21c096e --- /dev/null +++ b/test/SemaObjC/debugger-support.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fdebugger-support %s -emit-llvm -o - | FileCheck %s + +// rdar://problem/9416370 +void test0(id x) { + struct A { int w, x, y, z; }; + struct A result = (struct A) [x makeStruct]; + // CHECK: define void @test0( + // CHECK: [[X:%.*]] = alloca i8*, align 8 + // CHECK-NEXT: [[RESULT:%.*]] = alloca [[A:%.*]], align 4 + // CHECK-NEXT: store i8* {{%.*}}, i8** [[X]], + // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]], + // CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_" + // CHECK-NEXT: [[T2:%.*]] = call { i64, i64 } bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to { i64, i64 } (i8*, i8*)*)(i8* [[T0]], i8* [[T1]]) +} diff --git a/test/SemaObjC/error-property-gc-attr.m b/test/SemaObjC/error-property-gc-attr.m index a77b68b..829c082 100644 --- a/test/SemaObjC/error-property-gc-attr.m +++ b/test/SemaObjC/error-property-gc-attr.m @@ -20,9 +20,9 @@ @implementation INTF @synthesize pweak=IVAR; // expected-error {{existing ivar 'IVAR' for __weak property 'pweak' must be __weak}} -@synthesize NOT=II; // expected-error {{property 'NOT' must be declared __weak to match existing ivar 'II' with __weak attribute}} +@synthesize NOT=II; // expected-error {{existing ivar 'II' for strong property 'NOT' may not be __weak}} @synthesize WID; @synthesize ID; -@synthesize AWEAK; // expected-error {{property 'AWEAK' must be declared __weak to match existing ivar 'AWEAK' with __weak attribute}} +@synthesize AWEAK; // expected-error {{existing ivar 'AWEAK' for strong property 'AWEAK' may not be __weak}} @synthesize WI; @end diff --git a/test/SemaObjC/forward-class-1.m b/test/SemaObjC/forward-class-1.m index ab213fb..de94e88 100644 --- a/test/SemaObjC/forward-class-1.m +++ b/test/SemaObjC/forward-class-1.m @@ -1,9 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -@class FOO, BAR; +@class FOO, BAR; // expected-note {{forward class is declared here}} @class FOO, BAR; -@interface INTF : FOO // expected-error {{cannot find interface declaration for 'FOO', superclass of 'INTF'}} +@interface INTF : FOO // expected-error {{attempting to use the forward class 'FOO' as superclass of 'INTF'}} @end @interface FOO @@ -45,3 +45,14 @@ typedef NSObject <XCElementP> XCElement; @end +// rdar://9653341 +@class B; // expected-note {{forward class is declared here}} +@interface A : B {} // expected-error {{attempting to use the forward class 'B' as superclass of 'A'}} +@end + +@interface B : A {} +@end + +@implementation A @end +@implementation B @end + diff --git a/test/SemaObjC/ivar-ref-misuse.m b/test/SemaObjC/ivar-ref-misuse.m index ba2f115..f6d9c94 100644 --- a/test/SemaObjC/ivar-ref-misuse.m +++ b/test/SemaObjC/ivar-ref-misuse.m @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -@interface Sprite { +@interface Sprite { // expected-note{{'Sprite' declared here}} int sprite, spree; int UseGlobalBar; } @@ -17,7 +17,8 @@ int UseGlobalBar; + (void)setFoo:(int)foo { sprite = foo; // expected-error {{instance variable 'sprite' accessed in class method}} spree = foo; - Xsprite = foo; // expected-error {{use of undeclared identifier 'Xsprite'}} + Xsprite = foo; // expected-error {{unknown type name 'Xsprite'; did you mean 'Sprite'?}} \ + // expected-error{{expected identifier or '('}} UseGlobalBar = 10; } + (void)setSprite:(int)sprite { diff --git a/test/SemaObjC/method-lookup-3.m b/test/SemaObjC/method-lookup-3.m index 882b3d1..b3d9c46 100644 --- a/test/SemaObjC/method-lookup-3.m +++ b/test/SemaObjC/method-lookup-3.m @@ -55,3 +55,19 @@ void f5(id a0, Abstract *a1) { void f6(id<A> a0) { Abstract *l = [a0 x]; } + +struct test3a { int x, y; }; +struct test3b { unsigned x, y; }; +@interface Test3A - (struct test3a) test3; @end +@interface Test3B - (struct test3b) test3; @end +void test3(id x) { + (void) [x test3]; +} + +struct test4a { int x, y; }; +struct test4b { float x, y; }; +@interface Test4A - (struct test4a) test4; @end //expected-note{{using}} +@interface Test4B - (struct test4b) test4; @end //expected-note{{also found}} +void test4(id x) { + (void) [x test4]; //expected-warning {{multiple methods named 'test4' found}} +} diff --git a/test/SemaObjC/no-warning-unavail-unimp.m b/test/SemaObjC/no-warning-unavail-unimp.m new file mode 100644 index 0000000..9409322 --- /dev/null +++ b/test/SemaObjC/no-warning-unavail-unimp.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9651605 + +@interface Foo +@property (getter=getVal) int val __attribute__((unavailable)); +- Method __attribute__((unavailable)); ++ CMethod __attribute__((unavailable)); +@end + +@implementation Foo +@end + diff --git a/test/SemaObjC/property-10.m b/test/SemaObjC/property-10.m index 0119273..e89d68e 100644 --- a/test/SemaObjC/property-10.m +++ b/test/SemaObjC/property-10.m @@ -5,14 +5,24 @@ @interface I0 @property(readonly, readwrite) int p0; // expected-error {{property attributes 'readonly' and 'readwrite' are mutually exclusive}} -@property(retain) int p1; // expected-error {{property with 'retain' attribute must be of object type}} +@property(retain) int p1; // expected-error {{property with 'retain (or strong)' attribute must be of object type}} +@property(strong) int s1; // expected-error {{property with 'retain (or strong)' attribute must be of object type}} @property(copy) int p2; // expected-error {{property with 'copy' attribute must be of object type}} @property(assign, copy) id p3_0; // expected-error {{property attributes 'assign' and 'copy' are mutually exclusive}} @property(assign, retain) id p3_1; // expected-error {{property attributes 'assign' and 'retain' are mutually exclusive}} +@property(assign, strong) id s3_1; // expected-error {{property attributes 'assign' and 'strong' are mutually exclusive}} @property(copy, retain) id p3_2; // expected-error {{property attributes 'copy' and 'retain' are mutually exclusive}} +@property(copy, strong) id s3_2; // expected-error {{property attributes 'copy' and 'strong' are mutually exclusive}} @property(assign, copy, retain) id p3_3; // expected-error {{property attributes 'assign' and 'copy' are mutually exclusive}}, expected-error {{property attributes 'assign' and 'retain' are mutually exclusive}} +@property(assign, copy, strong) id s3_3; // expected-error {{property attributes 'assign' and 'copy' are mutually exclusive}}, expected-error {{property attributes 'assign' and 'strong' are mutually exclusive}} + +@property(unsafe_unretained, copy) id p4_0; // expected-error {{property attributes 'unsafe_unretained' and 'copy' are mutually exclusive}} +@property(unsafe_unretained, retain) id p4_1; // expected-error {{property attributes 'unsafe_unretained' and 'retain' are mutually exclusive}} +@property(unsafe_unretained, strong) id s4_1; // expected-error {{property attributes 'unsafe_unretained' and 'strong' are mutually exclusive}} +@property(unsafe_unretained, copy, retain) id p4_3; // expected-error {{property attributes 'unsafe_unretained' and 'copy' are mutually exclusive}}, expected-error {{property attributes 'unsafe_unretained' and 'retain' are mutually exclusive}} +@property(unsafe_unretained, copy, strong) id s4_3; // expected-error {{property attributes 'unsafe_unretained' and 'copy' are mutually exclusive}}, expected-error {{property attributes 'unsafe_unretained' and 'strong' are mutually exclusive}} @property id p4; // expected-warning {{no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed}}, expected-warning {{default property attribute 'assign' not appropriate for non-gc object}} @@ -22,7 +32,8 @@ @end @interface I0() -@property (retain) int PROP; // expected-error {{property with 'retain' attribute must be of object type}} +@property (retain) int PROP; // expected-error {{property with 'retain (or strong)' attribute must be of object type}} +@property (strong) int SPROP; // expected-error {{property with 'retain (or strong)' attribute must be of object type}} @property(nonatomic,copy) int (*PROP1)(); // expected-error {{property with 'copy' attribute must be of object type}} +@property(nonatomic,weak) int (*PROP2)(); // expected-error {{property with 'weak' attribute must be of object type}} @end - diff --git a/test/SemaObjC/property-inherited.m b/test/SemaObjC/property-inherited.m index 5c5631e..11ef2be 100644 --- a/test/SemaObjC/property-inherited.m +++ b/test/SemaObjC/property-inherited.m @@ -1,6 +1,8 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify +// RUN: %clang_cc1 -x objective-c++ %s -fsyntax-only -verify -// <rdar://problem/6497242> Inherited overridden protocol declared objects don't work +// rdar://6497242 Inherited overridden protocol declared objects don't work +// rdar://9740328 Case for c++ @protocol NSObject @end @interface NSObject @end diff --git a/test/SemaObjC/property-ns-returns-not-retained-attr.m b/test/SemaObjC/property-ns-returns-not-retained-attr.m new file mode 100644 index 0000000..187c93f --- /dev/null +++ b/test/SemaObjC/property-ns-returns-not-retained-attr.m @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -verify %s +// rdar://9636091 + +@interface I +@property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ; + +@property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ; +- (id) newName1 __attribute__((ns_returns_not_retained)); + +@property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}} +- (id) newName2; // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}} +@end + +@implementation I +@synthesize newName; + +@synthesize newName1; +- (id) newName1 { return 0; } + +@synthesize newName2; +@end diff --git a/test/SemaObjC/related-result-type-inference.m b/test/SemaObjC/related-result-type-inference.m index f539918..094f19a 100644 --- a/test/SemaObjC/related-result-type-inference.m +++ b/test/SemaObjC/related-result-type-inference.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fobjc-infer-related-result-type -verify %s +// RUN: %clang_cc1 -verify %s @interface Unrelated @end diff --git a/test/SemaObjC/selector-3.m b/test/SemaObjC/selector-3.m index 69a74f8..b248a5d 100644 --- a/test/SemaObjC/selector-3.m +++ b/test/SemaObjC/selector-3.m @@ -27,3 +27,28 @@ SEL func() { return @selector(length); // expected-warning {{unimplemented selector 'length'}} } + +// rdar://9545564 +@class MSPauseManager; + +@protocol MSPauseManagerDelegate +@optional +- (void)pauseManagerDidPause:(MSPauseManager *)manager; +- (int)respondsToSelector:(SEL)aSelector; +@end + +@interface MSPauseManager +{ + id<MSPauseManagerDelegate> _delegate; +} +@end + + +@implementation MSPauseManager +- (id) Meth { + if ([_delegate respondsToSelector:@selector(pauseManagerDidPause:)]) + return 0; + return 0; +} +@end + diff --git a/test/SemaObjC/self-declared-in-block.m b/test/SemaObjC/self-declared-in-block.m index 4bd7202..2131095 100644 --- a/test/SemaObjC/self-declared-in-block.m +++ b/test/SemaObjC/self-declared-in-block.m @@ -7,11 +7,12 @@ @implementation Blocky { int _a; } -- (void)doAThing { +- (int)doAThing { ^{ - char self; // expected-note {{declared here}} - _a; // expected-error {{instance variable '_a' cannot be accessed because 'self' has been redeclared}} + char self; + return _a; }(); + return _a; } @end @@ -37,14 +38,14 @@ (void)_anIvar; } { - C* self; // expected-note {{declared here}} - (void) _anIvar; // expected-error {{instance variable '_anIvar' cannot be accessed because 'self' has been redeclared}} + C* self; + (void) _anIvar; } } - (void)doAThing { ^{ - id self; // expected-note {{declared here}} - (void)_anIvar; // expected-error {{instance variable '_anIvar' cannot be accessed because 'self' has been redeclared}} + id self; + (void)_anIvar; }(); } @end diff --git a/test/SemaObjC/sizeof-interface.m b/test/SemaObjC/sizeof-interface.m index 3fe3964..65c8e49 100644 --- a/test/SemaObjC/sizeof-interface.m +++ b/test/SemaObjC/sizeof-interface.m @@ -7,7 +7,7 @@ int g0 = sizeof(I0); // expected-error{{invalid application of 'sizeof' to an in // rdar://6821047 void *g3(I0 *P) { - P = P+5; // expected-error {{arithmetic on pointer to incomplete type 'I0 *'}} + P = P+5; // expected-error {{arithmetic on a pointer to an incomplete type 'I0'}} return &P[4]; // expected-error{{subscript of pointer to incomplete type 'I0'}} } diff --git a/test/SemaObjC/special-dep-unavail-warning.m b/test/SemaObjC/special-dep-unavail-warning.m index 1d07a49..57a2fa3 100644 --- a/test/SemaObjC/special-dep-unavail-warning.m +++ b/test/SemaObjC/special-dep-unavail-warning.m @@ -3,24 +3,24 @@ @interface B - (void) depInA; -- (void) unavailMeth __attribute__((unavailable)); // expected-note {{function has been explicitly marked unavailable here}} +- (void) unavailMeth __attribute__((unavailable)); // expected-note {{has been explicitly marked unavailable here}} - (void) depInA1 __attribute__((deprecated)); - (void) unavailMeth1; - (void) depInA2 __attribute__((deprecated)); -- (void) unavailMeth2 __attribute__((unavailable)); // expected-note {{function has been explicitly marked unavailable here}} +- (void) unavailMeth2 __attribute__((unavailable)); // expected-note {{has been explicitly marked unavailable here}} - (void) depunavailInA; -- (void) depunavailInA1 __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{function has been explicitly marked unavailable here}} +- (void) depunavailInA1 __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{has been explicitly marked unavailable here}} - (void)FuzzyMeth __attribute__((deprecated)); - (void)FuzzyMeth1 __attribute__((unavailable)); @end @interface A -- (void) unavailMeth1 __attribute__((unavailable)); // expected-note {{function has been explicitly marked unavailable here}} +- (void) unavailMeth1 __attribute__((unavailable)); // expected-note {{has been explicitly marked unavailable here}} - (void) depInA __attribute__((deprecated)); - (void) depInA2 __attribute__((deprecated)); - (void) depInA1; - (void) unavailMeth2 __attribute__((unavailable)); -- (void) depunavailInA __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{function has been explicitly marked unavailable here}} +- (void) depunavailInA __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{has been explicitly marked unavailable here}} - (void) depunavailInA1; - (void)FuzzyMeth __attribute__((unavailable)); - (void)FuzzyMeth1 __attribute__((deprecated)); diff --git a/test/SemaObjC/synthesized-ivar.m b/test/SemaObjC/synthesized-ivar.m index 3bc372b..4786d80 100644 --- a/test/SemaObjC/synthesized-ivar.m +++ b/test/SemaObjC/synthesized-ivar.m @@ -51,3 +51,11 @@ int f0(I *a) { return a->IP; } // expected-error {{instance variable 'IP' is pri } @end +@interface A +@property (weak) id testObjectWeakProperty; // expected-note {{declared here}} +@end + +@implementation A +// rdar://9605088 +@synthesize testObjectWeakProperty; // expected-error {{@synthesize of 'weak' property is only allowed in ARC or GC mode}} +@end diff --git a/test/SemaObjC/typedef-class.m b/test/SemaObjC/typedef-class.m index 0f7e682..c983195 100644 --- a/test/SemaObjC/typedef-class.m +++ b/test/SemaObjC/typedef-class.m @@ -5,7 +5,7 @@ typedef struct _NSZone NSZone; @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; -@protocol NSObject - (BOOL) isEqual:(id) object; @end +@protocol NSObject - (BOOL) isEqual:(id) object; - (id)init; @end @protocol NSCopying - (id) copyWithZone:(NSZone *) zone; @end @protocol NSCoding - (void) encodeWithCoder:(NSCoder *) aCoder; @end diff --git a/test/SemaObjC/undef-superclass-1.m b/test/SemaObjC/undef-superclass-1.m index c941f82..41cf143 100644 --- a/test/SemaObjC/undef-superclass-1.m +++ b/test/SemaObjC/undef-superclass-1.m @@ -1,8 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -@class SUPER, Y; +@class SUPER, Y; // expected-note 2 {{forward class is declared here}} -@interface INTF :SUPER // expected-error {{cannot find interface declaration for 'SUPER', superclass of 'INTF'}} +@interface INTF :SUPER // expected-error {{attempting to use the forward class 'SUPER' as superclass of 'INTF'}} @end @interface SUPER @end @@ -13,7 +13,7 @@ @interface INTF2 : INTF1 @end -@interface INTF3 : Y // expected-error {{cannot find interface declaration for 'Y', superclass of 'INTF3'}} \ +@interface INTF3 : Y // expected-error {{attempting to use the forward class 'Y' as superclass of 'INTF3'}} \ // expected-note{{'INTF3' declared here}} @end diff --git a/test/SemaObjC/warn-retain-cycle.m b/test/SemaObjC/warn-retain-cycle.m new file mode 100644 index 0000000..71385b8 --- /dev/null +++ b/test/SemaObjC/warn-retain-cycle.m @@ -0,0 +1,91 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fobjc-arc -fblocks -verify %s + +@interface Test0 +- (void) setBlock: (void(^)(void)) block; +- (void) addBlock: (void(^)(void)) block; +- (void) actNow; +@end +void test0(Test0 *x) { + [x setBlock: // expected-note {{block will be retained by the captured object}} + ^{ [x actNow]; }]; // expected-warning {{capturing 'x' strongly in this block is likely to lead to a retain cycle}} + x.block = // expected-note {{block will be retained by the captured object}} + ^{ [x actNow]; }; // expected-warning {{capturing 'x' strongly in this block is likely to lead to a retain cycle}} + + [x addBlock: // expected-note {{block will be retained by the captured object}} + ^{ [x actNow]; }]; // expected-warning {{capturing 'x' strongly in this block is likely to lead to a retain cycle}} + + // These actually don't cause retain cycles. + __weak Test0 *weakx = x; + [x addBlock: ^{ [weakx actNow]; }]; + [x setBlock: ^{ [weakx actNow]; }]; + x.block = ^{ [weakx actNow]; }; + + // These do cause retain cycles, but we're not clever enough to figure that out. + [weakx addBlock: ^{ [x actNow]; }]; + [weakx setBlock: ^{ [x actNow]; }]; + weakx.block = ^{ [x actNow]; }; +} + +@interface BlockOwner +@property (retain) void (^strong)(void); +@end + +@interface Test1 { +@public + BlockOwner *owner; +}; +@property (retain) BlockOwner *owner; +@property (assign) __strong BlockOwner *owner2; // expected-error {{unsafe_unretained property 'owner2' may not also be declared __strong}} +@property (assign) BlockOwner *owner3; +@end +void test1(Test1 *x) { + x->owner.strong = ^{ (void) x; }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}} + x.owner.strong = ^{ (void) x; }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}} + x.owner2.strong = ^{ (void) x; }; + x.owner3.strong = ^{ (void) x; }; +} + +@implementation Test1 { + BlockOwner * __unsafe_unretained owner3ivar; + __weak BlockOwner *weakowner; +} +@dynamic owner; +@dynamic owner2; +@synthesize owner3 = owner3ivar; + +- (id) init { + self.owner.strong = ^{ (void) owner; }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}} + self.owner2.strong = ^{ (void) owner; }; + + // TODO: should we warn here? What's the story with this kind of mismatch? + self.owner3.strong = ^{ (void) owner; }; + + owner.strong = ^{ (void) owner; }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}} + + owner.strong = ^{ ^{ (void) owner; }(); }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}} + + owner.strong = ^{ (void) sizeof(self); // expected-note {{block will be retained by an object strongly retained by the captured object}} + (void) owner; }; // expected-warning {{capturing 'self' strongly in this block is likely to lead to a retain cycle}} + + weakowner.strong = ^{ (void) owner; }; + + return self; +} +- (void) foo { + owner.strong = ^{ (void) owner; }; // expected-warning {{retain cycle}} expected-note {{block will be retained by an object strongly retained by the captured object}} +} +@end + +void test2_helper(id); +@interface Test2 { + void (^block)(void); + id x; +} +@end +@implementation Test2 +- (void) test { + block = ^{ // expected-note {{block will be retained by an object strongly retained by the captured object}} + test2_helper(x); // expected-warning {{capturing 'self' strongly in this block is likely to lead to a retain cycle}} + }; +} +@end diff --git a/test/SemaObjC/weak-property.m b/test/SemaObjC/weak-property.m new file mode 100644 index 0000000..f000607 --- /dev/null +++ b/test/SemaObjC/weak-property.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fobjc-arc -verify %s +// rdar://8899430 + +@interface WeakPropertyTest { + Class isa; + __weak id value; + id x; +} +@property (weak) id value1; +@property __weak id value; +@property () __weak id value2; + +@property (weak, assign) id v1; // expected-error {{property attributes 'assign' and 'weak' are mutually exclusive}} +@property (weak, copy) id v2; // expected-error {{property attributes 'copy' and 'weak' are mutually exclusive}} +@property (weak, retain) id v3; // expected-error {{property attributes 'retain' and 'weak' are mutually exclusive}} +@property (weak, assign) id v4; // expected-error {{property attributes 'assign' and 'weak' are mutually exclusive}} + +@property () __weak id x; // expected-note {{property declared here}} +@end + +@implementation WeakPropertyTest +@synthesize x; // expected-error {{existing ivar 'x' for __weak property 'x' must be __weak}} +@dynamic value1, value, value2, v1,v2,v3,v4; +@end diff --git a/test/SemaObjCXX/Inputs/arc-system-header.h b/test/SemaObjCXX/Inputs/arc-system-header.h new file mode 100644 index 0000000..d7adeb4 --- /dev/null +++ b/test/SemaObjCXX/Inputs/arc-system-header.h @@ -0,0 +1,14 @@ +@interface B +@end + + +@interface A { +@public + union { + struct { + B *b; + } a_b; + void *void_ptr; + } data; +} +@end diff --git a/test/SemaObjCXX/arc-0x.mm b/test/SemaObjCXX/arc-0x.mm new file mode 100644 index 0000000..fa022af --- /dev/null +++ b/test/SemaObjCXX/arc-0x.mm @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=c++0x -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify -fblocks -fobjc-exceptions %s + +// "Move" semantics, trivial version. +void move_it(__strong id &&from) { + id to = static_cast<__strong id&&>(from); +} + +// Deduction with 'auto'. +@interface A ++ alloc; +- init; +@end + +// Ensure that deduction works with lifetime qualifiers. +void deduction(id obj) { + auto a = [[A alloc] init]; + __strong A** aPtr = &a; + + auto a2([[A alloc] init]); + __strong A** aPtr2 = &a2; + + __strong id *idp = new auto(obj); + + __strong id array[17]; + for (auto x : array) { + __strong id *xPtr = &x; + } + + @try { + } @catch (auto e) { // expected-error {{'auto' not allowed in exception declaration}} + } +} diff --git a/test/SemaObjCXX/arc-bool-conversion.mm b/test/SemaObjCXX/arc-bool-conversion.mm new file mode 100644 index 0000000..86da3ca --- /dev/null +++ b/test/SemaObjCXX/arc-bool-conversion.mm @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s +// rdar://9310049 + +bool fn(id obj) { + return (bool)obj; +} + diff --git a/test/SemaObjCXX/arc-bridged-cast.mm b/test/SemaObjCXX/arc-bridged-cast.mm new file mode 100644 index 0000000..cbbe79e --- /dev/null +++ b/test/SemaObjCXX/arc-bridged-cast.mm @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fblocks -verify %s + +typedef const void *CFTypeRef; +typedef const struct __CFString *CFStringRef; + +@interface NSString +@end + +CFTypeRef CFCreateSomething(); +CFStringRef CFCreateString(); +CFTypeRef CFGetSomething(); +CFStringRef CFGetString(); + +id CreateSomething(); +NSString *CreateNSString(); + +template<typename IdType, typename StringType, typename IntPtrType> +void from_cf() { + id obj1 = (__bridge_transfer IdType)CFCreateSomething(); + id obj2 = (__bridge_transfer StringType)CFCreateString(); + (__bridge IntPtrType)CFCreateSomething(); // expected-error{{incompatible types casting 'CFTypeRef' (aka 'const void *') to 'int *' with a __bridge cast}} + id obj3 = (__bridge IdType)CFGetSomething(); + id obj4 = (__bridge StringType)CFGetString(); +} + +template void from_cf<id, NSString*, int*>(); // expected-note{{in instantiation of function template specialization}} + +template<typename IdType, typename StringType> +void to_cf(id obj) { + CFTypeRef cf1 = (__bridge_retained IdType)CreateSomething(); + CFStringRef cf2 = (__bridge_retained StringType)CreateNSString(); + CFTypeRef cf3 = (__bridge IdType)CreateSomething(); + CFStringRef cf4 = (__bridge StringType)CreateNSString(); +} + +template void to_cf<CFTypeRef, CFStringRef>(id); diff --git a/test/SemaObjCXX/arc-libcxx.mm b/test/SemaObjCXX/arc-libcxx.mm new file mode 100644 index 0000000..7992f60 --- /dev/null +++ b/test/SemaObjCXX/arc-libcxx.mm @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-arc-cxxlib=libc++ -fobjc-nonfragile-abi -fobjc-runtime-has-weak -verify %s + +@interface A @end + +void f(__strong id &sir, __weak id &wir, __autoreleasing id &air, + __unsafe_unretained id &uir) { + __strong id *sip = std::addressof(sir); + __weak id *wip = std::addressof(wir); + __autoreleasing id *aip = std::addressof(air); + __unsafe_unretained id *uip = std::addressof(uir); +} diff --git a/test/SemaObjCXX/arc-libstdcxx.mm b/test/SemaObjCXX/arc-libstdcxx.mm new file mode 100644 index 0000000..edb7a9e --- /dev/null +++ b/test/SemaObjCXX/arc-libstdcxx.mm @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-arc-cxxlib=libstdc++ -fobjc-nonfragile-abi -fobjc-runtime-has-weak -verify %s + +@interface A @end + +int check0[std::__is_scalar<__strong id>::__value? -1 : 1]; +int check1[std::__is_scalar<__weak id>::__value? -1 : 1]; +int check2[std::__is_scalar<__autoreleasing id>::__value? -1 : 1]; +int check3[std::__is_scalar<__strong A*>::__value? -1 : 1]; +int check4[std::__is_scalar<__weak A*>::__value? -1 : 1]; +int check5[std::__is_scalar<__autoreleasing A*>::__value? -1 : 1]; diff --git a/test/SemaObjCXX/arc-memfunc.mm b/test/SemaObjCXX/arc-memfunc.mm new file mode 100644 index 0000000..75b94c6 --- /dev/null +++ b/test/SemaObjCXX/arc-memfunc.mm @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify -fblocks %s + +struct X0 { + static id makeObject1() __attribute__((ns_returns_retained)); + id makeObject2() __attribute__((ns_returns_retained)); +}; + +void test_X0(X0 x0, X0 *x0p) { + X0::makeObject1(); + x0.makeObject2(); + x0p->makeObject2(); + id (X0::*pmf)() __attribute__((ns_returns_retained)) = &X0::makeObject2; + (x0.*pmf)(); + (x0p->*pmf)(); +} diff --git a/test/SemaObjCXX/arc-non-pod.mm b/test/SemaObjCXX/arc-non-pod.mm new file mode 100644 index 0000000..6a47b3d --- /dev/null +++ b/test/SemaObjCXX/arc-non-pod.mm @@ -0,0 +1,116 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -Warc-abi -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s + +// Classes that have an Objective-C object pointer. +struct HasObjectMember0 { // expected-warning{{'HasObjectMember0' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + id x; +}; + +struct HasObjectMember1 { // expected-warning{{'HasObjectMember1' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + id x[3]; +}; + +struct HasObjectMember2 { // expected-warning{{'HasObjectMember2' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + id x[3][2]; +}; + +// Don't complain if the type has non-external linkage +namespace { + struct HasObjectMember3 { + id x[3][2]; + }; +} + +// Don't complain if the Objective-C pointer type was explicitly given +// no ownership. +struct HasObjectMember3 { + __unsafe_unretained id x[3][2]; +}; + +struct HasBlockPointerMember0 { // expected-warning{{'HasBlockPointerMember0' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + int (^bp)(int); +}; + +struct HasBlockPointerMember1 { // expected-warning{{'HasBlockPointerMember1' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + int (^bp[2][3])(int); +}; + +struct NonPOD { + NonPOD(const NonPOD&); +}; + +struct HasObjectMemberAndNonPOD0 { // expected-warning{{'HasObjectMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ + // expected-warning{{'HasObjectMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + id x; + NonPOD np; +}; + +struct HasObjectMemberAndNonPOD1 { // expected-warning{{'HasObjectMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ + // expected-warning{{'HasObjectMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + id x[3]; +}; + +struct HasObjectMemberAndNonPOD2 { // expected-warning{{'HasObjectMemberAndNonPOD2' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ + // expected-warning{{'HasObjectMemberAndNonPOD2' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + id x[3][2]; +}; + +struct HasObjectMemberAndNonPOD3 { + HasObjectMemberAndNonPOD3 &operator=(const HasObjectMemberAndNonPOD3&); + ~HasObjectMemberAndNonPOD3(); + NonPOD np; + id x[3][2]; +}; + +struct HasBlockPointerMemberAndNonPOD0 { // expected-warning{{'HasBlockPointerMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ +// expected-warning{{'HasBlockPointerMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + int (^bp)(int); +}; + +struct HasBlockPointerMemberAndNonPOD1 { // expected-warning{{'HasBlockPointerMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ +// expected-warning{{'HasBlockPointerMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + int (^bp[2][3])(int); +}; + +int check_non_pod_objc_pointer0[__is_pod(id)? 1 : -1]; +int check_non_pod_objc_pointer1[__is_pod(__strong id)? -1 : 1]; +int check_non_pod_objc_pointer2[__is_pod(__unsafe_unretained id)? 1 : -1]; +int check_non_pod_objc_pointer3[__is_pod(id[2][3])? 1 : -1]; +int check_non_pod_objc_pointer4[__is_pod(__unsafe_unretained id[2][3])? 1 : -1]; +int check_non_pod_block0[__is_pod(int (^)(int))? 1 : -1]; +int check_non_pod_block1[__is_pod(int (^ __unsafe_unretained)(int))? 1 : -1]; +int check_non_pod_block2[__is_pod(int (^ __strong)(int))? -1 : 1]; + +struct FlexibleArrayMember0 { + int length; + id array[]; // expected-error{{flexible array member 'array' of non-POD element type 'id __strong[]'}} +}; + +struct FlexibleArrayMember1 { + int length; + __unsafe_unretained id array[]; +}; + +// It's okay to pass a retainable type through an ellipsis. +void variadic(...); +void test_variadic() { + variadic(1, 17, @"Foo"); +} + +// It's okay to create a VLA of retainable types. +void vla(int n) { + id vla[n]; +} + +@interface Crufty { + union { + struct { + id object; // expected-note{{has __strong ownership}} + } an_object; // expected-error{{union member 'an_object' has a non-trivial copy constructor}} + void *ptr; + } storage; +} +@end diff --git a/test/SemaObjCXX/arc-object-init-destroy.mm b/test/SemaObjCXX/arc-object-init-destroy.mm new file mode 100644 index 0000000..196f493 --- /dev/null +++ b/test/SemaObjCXX/arc-object-init-destroy.mm @@ -0,0 +1,52 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Warc-abi -fblocks -triple x86_64-apple-darwin10.0.0 %s + +typedef __strong id strong_id; +typedef __weak id weak_id; +void test_pseudo_destructors(__strong id *sptr, __weak id *wptr) { + sptr->~id(); // okay + wptr->~id(); // okay + sptr->~strong_id(); // okay + wptr->~weak_id(); + sptr->~weak_id(); // expected-error{{pseudo-destructor destroys object of type '__strong id' with inconsistently-qualified type 'weak_id' (aka '__weak id')}} + wptr->strong_id::~strong_id(); // expected-error{{pseudo-destructor destroys object of type '__weak id' with inconsistently-qualified type 'strong_id' (aka '__strong id')}} + + sptr->id::~id(); // okay + wptr->id::~id(); // okay +} + +void test_delete(__strong id *sptr, __weak id *wptr) { + delete sptr; + delete wptr; + delete [] sptr; // expected-warning{{destroying an array of '__strong id'; this array must not have been allocated from non-ARC code}} + delete [] wptr; // expected-warning{{destroying an array of '__weak id'; this array must not have been allocated from non-ARC code}} +} + +void test_new(int n) { + (void)new strong_id; + (void)new weak_id; + (void)new strong_id [n]; // expected-warning{{allocating an array of 'strong_id' (aka '__strong id'); this array must not be deleted in non-ARC code}} + (void)new weak_id [n]; // expected-warning{{allocating an array of 'weak_id' (aka '__weak id'); this array must not be deleted in non-ARC code}} + + (void)new __strong id; + (void)new __weak id; + (void)new __strong id [n]; // expected-warning{{allocating an array of '__strong id'; this array must not be deleted in non-ARC code}} + + // Infer '__strong'. + __strong id *idptr = new id; + __strong id *idptr2 = new id [n]; // expected-warning{{allocating an array of '__strong id'; this array must not be deleted in non-ARC code}} + + // ... but not for arrays. + typedef id id_array[2][3]; + (void)new id_array; // expected-error{{'new' cannot allocate an array of 'id' with no explicit ownership}} + + typedef __strong id strong_id_array[2][3]; + typedef __strong id strong_id_3[3]; + strong_id_3 *idptr3 = new strong_id_array; // expected-warning{{allocating an array of '__strong id'; this array must not be deleted in non-ARC code}} +} + +void test_jump_scope() { + goto done; // expected-error{{goto into protected scope}} + __strong id x; // expected-note{{jump bypasses initialization of retaining variable}} + done: + return; +} diff --git a/test/SemaObjCXX/arc-overloading.mm b/test/SemaObjCXX/arc-overloading.mm new file mode 100644 index 0000000..06b332c --- /dev/null +++ b/test/SemaObjCXX/arc-overloading.mm @@ -0,0 +1,175 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -fblocks %s + +// Simple ownership conversions + diagnostics. +int &f0(id __strong const *); // expected-note{{candidate function not viable: 1st argument ('__weak id *') has __weak ownership, but parameter has __strong ownership}} + +void test_f0() { + id __strong *sip; + id __strong const *csip; + id __weak *wip; + id __autoreleasing *aip; + id __unsafe_unretained *uip; + + int &ir1 = f0(sip); + int &ir2 = f0(csip); + int &ir3 = f0(aip); + int &ir4 = f0(uip); + f0(wip); // expected-error{{no matching function for call to 'f0'}} +} + +// Simple overloading +int &f1(id __strong const *); +float &f1(id __weak const *); + +void test_f1() { + id __strong *sip; + id __strong const *csip; + id __weak *wip; + id __autoreleasing *aip; + id __unsafe_unretained *uip; + + int &ir1 = f1(sip); + int &ir2 = f1(csip); + float &fr1 = f1(wip); + int &ir3 = f1(aip); + int &ir4 = f1(uip); +} + +// Simple overloading +int &f2(id __strong const *); // expected-note{{candidate function}} +float &f2(id __autoreleasing const *); // expected-note{{candidate function}} + +void test_f2() { + id __strong *sip; + id __strong const *csip; + id __weak *wip; + id __autoreleasing *aip; + id __unsafe_unretained *uip; + + // Prefer non-ownership conversions to ownership conversions. + int &ir1 = f2(sip); + int &ir2 = f2(csip); + float &fr1 = f2(aip); + + f2(uip); // expected-error{{call to 'f2' is ambiguous}} +} + +// Writeback conversion +int &f3(id __autoreleasing *); // expected-note{{candidate function not viable: 1st argument ('__unsafe_unretained id *') has __unsafe_unretained ownership, but parameter has __autoreleasing ownership}} + +void test_f3() { + id __strong sip; + id __weak wip; + id __autoreleasing aip; + id __unsafe_unretained uip; + + int &ir1 = f3(&sip); + int &ir2 = f3(&wip); + int &ir3 = f3(&aip); + f3(&uip); // expected-error{{no matching function for call to 'f3'}} +} + +// Writeback conversion vs. no conversion +int &f4(id __autoreleasing *); +float &f4(id __strong *); + +void test_f4() { + id __strong sip; + id __weak wip; + id __autoreleasing aip; + extern __weak id weak_global_ptr; + + float &fr1 = f4(&sip); + int &ir1 = f4(&wip); + int &ir2 = f4(&aip); + int &ir3 = f4(&weak_global_ptr); // expected-error{{passing address of non-local object to __autoreleasing parameter for write-back}} +} + +// Writeback conversion vs. other conversion. +int &f5(id __autoreleasing *); +float &f5(id const __unsafe_unretained *); + +void test_f5() { + id __strong sip; + id __weak wip; + id __autoreleasing aip; + + int &ir1 = f5(&wip); + float &fr1 = f5(&sip); + int &ir2 = f5(&aip); +} + +@interface A +@end + +int &f6(id __autoreleasing *); +float &f6(id const __unsafe_unretained *); + +void test_f6() { + A* __strong sip; + A* __weak wip; + A* __autoreleasing aip; + + int &ir1 = f6(&wip); + float &fr1 = f6(&sip); + int &ir2 = f6(&aip); +} + +// Reference binding +void f7(__strong id&); // expected-note{{candidate function not viable: 1st argument ('__weak id') has __weak ownership, but parameter has __strong ownership}} \ + // expected-note{{candidate function not viable: 1st argument ('__autoreleasing id') has __autoreleasing ownership, but parameter has __strong ownership}} \ + // expected-note{{candidate function not viable: 1st argument ('__unsafe_unretained id') has __unsafe_unretained ownership, but parameter has __strong ownership}} + +void test_f7() { + __strong id strong_id; + __weak id weak_id; + __autoreleasing id autoreleasing_id; + __unsafe_unretained id unsafe_id; + f7(strong_id); + f7(weak_id); // expected-error{{no matching function for call to 'f7'}} + f7(autoreleasing_id); // expected-error{{no matching function for call to 'f7'}} + f7(unsafe_id); // expected-error{{no matching function for call to 'f7'}} +} + +void f8(const __strong id&); + +void test_f8() { + __strong id strong_id; + __weak id weak_id; + __autoreleasing id autoreleasing_id; + __unsafe_unretained id unsafe_id; + + f8(strong_id); + f8(weak_id); + f8(autoreleasing_id); + f8(unsafe_id); +} + +int &f9(__strong id&); +float &f9(const __autoreleasing id&); + +void test_f9() { + __strong id strong_id; + __weak id weak_id; + __autoreleasing id autoreleasing_id; + __unsafe_unretained id unsafe_id; + + int &ir1 = f9(strong_id); + float &fr1 = f9(autoreleasing_id); + float &fr2 = f9(unsafe_id); + float &fr2a = f9(weak_id); + + __strong A *strong_a; + __weak A *weak_a; + __autoreleasing A *autoreleasing_a; + __unsafe_unretained A *unsafe_unretained_a; + float &fr3 = f9(strong_a); + float &fr4 = f9(autoreleasing_a); + float &fr5 = f9(unsafe_unretained_a); + float &fr6 = f9(weak_a); + + const __autoreleasing id& ar1 = strong_a; + const __autoreleasing id& ar2 = autoreleasing_a; + const __autoreleasing id& ar3 = unsafe_unretained_a; + const __autoreleasing id& ar4 = weak_a; +} diff --git a/test/SemaObjCXX/arc-system-header.mm b/test/SemaObjCXX/arc-system-header.mm new file mode 100644 index 0000000..cb2b858 --- /dev/null +++ b/test/SemaObjCXX/arc-system-header.mm @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fobjc-arc -fobjc-nonfragile-abi -isystem %S/Inputs %s -verify + +#include <arc-system-header.h> + +void f(A* a) { + a->data.void_ptr = 0; + a->data.a_b.b = 0; // expected-error{{'a_b' is unavailable: this system field has retaining ownership}} +} +// Silly location below +// expected-note{{declaration has been explicitly marked unavailable here}} diff --git a/test/SemaObjCXX/arc-templates.mm b/test/SemaObjCXX/arc-templates.mm new file mode 100644 index 0000000..fa4e0a7 --- /dev/null +++ b/test/SemaObjCXX/arc-templates.mm @@ -0,0 +1,254 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -fblocks %s + +@interface A +@end + +template<typename T, typename U> +struct is_same { + static const bool value = false; +}; + +template<typename T> +struct is_same<T, T> { + static const bool value = true; +}; + +// Instantiation for reference/pointer types that will get lifetime +// adjustments. +template<typename T> +struct X0 { + typedef T* pointer; // okay: ends up being strong. + typedef T& reference; // okay: ends up being strong +}; + +void test_X0() { + X0<id> x0id; + X0<A*> x0a; + X0<__strong A*> x0sa; + + id __strong *ptr; + id __strong val; + X0<__strong id>::pointer &ptr_ref = ptr; + X0<__strong id>::reference ref = val; +} + +int check_infer_strong[is_same<id, __strong id>::value? 1 : -1]; + +// Check template argument deduction (e.g., for specialization) using +// lifetime qualifiers. +template<typename T> +struct is_pointer_strong { + static const bool value = false; +}; + +template<typename T> +struct is_pointer_strong<__strong T*> { + static const bool value = true; +}; + +int check_ptr_strong1[is_pointer_strong<__strong id*>::value? 1 : -1]; +int check_ptr_strong2[is_pointer_strong<__weak id*>::value? -1 : 1]; +int check_ptr_strong3[is_pointer_strong<__autoreleasing id*>::value? -1 : 1]; +int check_ptr_strong4[is_pointer_strong<__unsafe_unretained id*>::value? -1 : 1]; +int check_ptr_strong5[is_pointer_strong<id>::value? -1 : 1]; + +// Check substitution into lifetime-qualified dependent types. +template<typename T> +struct make_strong_pointer { + typedef __strong T *type; +}; + +template<typename T> +struct make_strong_pointer<__weak T> { + typedef __strong T *type; +}; + +template<typename T> +struct make_strong_pointer<__autoreleasing T> { + typedef __strong T *type; +}; + +template<typename T> +struct make_strong_pointer<__unsafe_unretained T> { + typedef __strong T *type; +}; + +// Adding qualifiers +int check_make_strong1[is_same<make_strong_pointer<id>::type, __strong id *>::value ? 1 : -1]; +int check_make_strong2[is_same<make_strong_pointer<A*>::type, A* __strong *>::value ? 1 : -1]; + +// Adding redundant qualifiers +int check_make_strong3[is_same<make_strong_pointer<__strong id>::type, __strong id *>::value ? 1 : -1]; +int check_make_strong4[is_same<make_strong_pointer<__strong A*>::type, A* __strong *>::value ? 1 : -1]; + +// Adding nonsensical qualifiers. +int check_make_strong5[is_same<make_strong_pointer<int>::type, int *>::value ? 1 : -1]; +int check_make_strong6[is_same<make_strong_pointer<__weak id>::type, __strong id *>::value ? 1 : -1]; + +template<typename T> +struct make_weak { + typedef __weak T type; +}; + +int check_make_weak0[is_same<make_weak<id>::type, __weak id>::value? 1 : -1]; +int check_make_weak1[is_same<make_weak<__strong id>::type, __weak id>::value? 1 : -1]; +int check_make_weak2[is_same<make_weak<__autoreleasing id>::type, __weak id>::value? 1 : -1]; + +template<typename T> +struct make_weak_fail { + typedef T T_type; + typedef __weak T_type type; // expected-error{{the type 'T_type' (aka '__weak id') already has retainment attributes set on it}} \ + // expected-error{{the type 'T_type' (aka '__strong id') already has retainment attributes set on it}} +}; + +int check_make_weak_fail0[is_same<make_weak_fail<__weak id>::type, __weak id>::value? 1 : -1]; // expected-note{{in instantiation of template class 'make_weak_fail<__weak id>' requested here}} + +int check_make_weak_fail1[is_same<make_weak_fail<id>::type, __weak id>::value? -1 : 1]; // expected-note{{in instantiation of template class 'make_weak_fail<id>' requested here}} + +// Check template argument deduction from function templates. +template<typename T> struct identity { }; + +template<typename T> identity<T> accept_strong_ptr(__strong T*); +template<typename T> identity<T> accept_strong_ref(__strong T&); + +template<typename T> identity<T> accept_any_ptr(T*); +template<typename T> identity<T> accept_any_ref(T&); + +void test_func_deduction_id() { + __strong id *sip; + __weak id *wip; + __autoreleasing id *aip; + __unsafe_unretained id *uip; + + identity<id> res1 = accept_strong_ptr(sip); + identity<__strong id> res2 = accept_any_ptr(sip); + + __strong id si; + __weak id wi; + __autoreleasing id ai; + __unsafe_unretained id ui; + identity<id> res3 = accept_strong_ref(si); + identity<__strong id> res4 = accept_any_ref(si); + identity<__weak id> res5 = accept_any_ref(wi); + identity<__autoreleasing id> res6 = accept_any_ref(ai); + identity<__unsafe_unretained id> res7 = accept_any_ref(ui); +} + +void test_func_deduction_A() { + __strong A * *sip; + __weak A * *wip; + __autoreleasing A * *aip; + __unsafe_unretained A * *uip; + + identity<A *> res1 = accept_strong_ptr(sip); + identity<__strong A *> res2 = accept_any_ptr(sip); + + __strong A * si; + __weak A * wi; + __autoreleasing A * ai; + __unsafe_unretained A * ui; + identity<A *> res3 = accept_strong_ref(si); + identity<__strong A *> res4 = accept_any_ref(si); + identity<__weak A *> res5 = accept_any_ref(wi); + identity<__autoreleasing A *> res6 = accept_any_ref(ai); + identity<__unsafe_unretained A *> res7 = accept_any_ref(ui); +} + +// Test partial ordering (qualified vs. non-qualified). +template<typename T> +struct classify_pointer_pointer { + static const unsigned value = 0; +}; + +template<typename T> +struct classify_pointer_pointer<T*> { + static const unsigned value = 1; +}; + +template<typename T> +struct classify_pointer_pointer<__strong T*> { + static const unsigned value = 2; +}; + +template<typename T> +struct classify_pointer_pointer<__weak T*> { + static const unsigned value = 3; +}; + +template<typename T> +struct classify_pointer_pointer<T&> { + static const unsigned value = 4; +}; + +template<typename T> +struct classify_pointer_pointer<__strong T&> { + static const unsigned value = 5; +}; + +template<typename T> +struct classify_pointer_pointer<__weak T&> { + static const unsigned value = 6; +}; + +int classify_ptr1[classify_pointer_pointer<int>::value == 0? 1 : -1]; +int classify_ptr2[classify_pointer_pointer<int *>::value == 1? 1 : -1]; +int classify_ptr3[classify_pointer_pointer<id __strong *>::value == 2? 1 : -1]; +int classify_ptr4[classify_pointer_pointer<id __weak *>::value == 3? 1 : -1]; +int classify_ptr5[classify_pointer_pointer<int&>::value == 4? 1 : -1]; +int classify_ptr6[classify_pointer_pointer<id __strong&>::value == 5? 1 : -1]; +int classify_ptr7[classify_pointer_pointer<id __weak&>::value == 6? 1 : -1]; +int classify_ptr8[classify_pointer_pointer<id __autoreleasing&>::value == 4? 1 : -1]; +int classify_ptr9[classify_pointer_pointer<id __unsafe_unretained&>::value == 4? 1 : -1]; +int classify_ptr10[classify_pointer_pointer<id __autoreleasing *>::value == 1? 1 : -1]; +int classify_ptr11[classify_pointer_pointer<id __unsafe_unretained *>::value == 1? 1 : -1]; +int classify_ptr12[classify_pointer_pointer<int *>::value == 1? 1 : -1]; +int classify_ptr13[classify_pointer_pointer<A * __strong *>::value == 2? 1 : -1]; +int classify_ptr14[classify_pointer_pointer<A * __weak *>::value == 3? 1 : -1]; +int classify_ptr15[classify_pointer_pointer<int&>::value == 4? 1 : -1]; +int classify_ptr16[classify_pointer_pointer<A * __strong&>::value == 5? 1 : -1]; +int classify_ptr17[classify_pointer_pointer<A * __weak&>::value == 6? 1 : -1]; +int classify_ptr18[classify_pointer_pointer<A * __autoreleasing&>::value == 4? 1 : -1]; +int classify_ptr19[classify_pointer_pointer<A * __unsafe_unretained&>::value == 4? 1 : -1]; +int classify_ptr20[classify_pointer_pointer<A * __autoreleasing *>::value == 1? 1 : -1]; +int classify_ptr21[classify_pointer_pointer<A * __unsafe_unretained *>::value == 1? 1 : -1]; + +template<typename T> int& qual_vs_unqual_ptr(__strong T*); +template<typename T> double& qual_vs_unqual_ptr(__weak T*); +template<typename T> float& qual_vs_unqual_ptr(T*); +template<typename T> int& qual_vs_unqual_ref(__strong T&); +template<typename T> double& qual_vs_unqual_ref(__weak T&); +template<typename T> float& qual_vs_unqual_ref(T&); + +void test_qual_vs_unqual_id() { + __strong id *sip; + __weak id *wip; + __autoreleasing id *aip; + __unsafe_unretained id *uip; + + int &ir1 = qual_vs_unqual_ptr(sip); + double &dr1 = qual_vs_unqual_ptr(wip); + float &fr1 = qual_vs_unqual_ptr(aip); + float &fr2 = qual_vs_unqual_ptr(uip); + + int &ir2 = qual_vs_unqual_ref(*sip); + double &dr2 = qual_vs_unqual_ref(*wip); + float &fr3 = qual_vs_unqual_ref(*aip); + float &fr4 = qual_vs_unqual_ref(*uip); +} + +void test_qual_vs_unqual_a() { + __strong A * *sap; + __weak A * *wap; + __autoreleasing A * *aap; + __unsafe_unretained A * *uap; + + int &ir1 = qual_vs_unqual_ptr(sap); + double &dr1 = qual_vs_unqual_ptr(wap); + float &fr1 = qual_vs_unqual_ptr(aap); + float &fr2 = qual_vs_unqual_ptr(uap); + + int &ir2 = qual_vs_unqual_ref(*sap); + double &dr2 = qual_vs_unqual_ref(*wap); + float &fr3 = qual_vs_unqual_ref(*aap); + float &fr4 = qual_vs_unqual_ref(*uap); +} diff --git a/test/SemaObjCXX/arc-type-conversion.mm b/test/SemaObjCXX/arc-type-conversion.mm new file mode 100644 index 0000000..f52f54a --- /dev/null +++ b/test/SemaObjCXX/arc-type-conversion.mm @@ -0,0 +1,221 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -fblocks %s +// rdar://8843600 + +void * cvt(id arg) // expected-note{{candidate function not viable: cannot convert argument of incomplete type 'void *' to '__strong id'}} +{ + void* voidp_val; + (void)(int*)arg; // expected-error {{cast of an Objective-C pointer to 'int *' is disallowed with ARC}} + (void)(id)arg; + (void)(__autoreleasing id*)arg; // expected-error{{C-style cast from 'id' to '__autoreleasing id *' casts away qualifiers}} + (void)(id*)arg; // expected-error{{C-style cast from 'id' to '__strong id *' casts away qualifiers}} + + (void)(__autoreleasing id**)voidp_val; + (void)(void*)voidp_val; + (void)(void**)arg; // expected-error {{cast of an Objective-C pointer to 'void **' is disallowed}} + cvt((void*)arg); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \ + // expected-error {{no matching function for call to 'cvt'}} \ + // expected-note{{use __bridge to convert directly (no change in ownership)}} \ + // expected-note{{use __bridge_retained to make an ARC object available as a +1 'void *'}} + cvt(0); + (void)(__strong id**)(0); + + // FIXME: Diagnostic could be better here. + return arg; // expected-error{{cannot initialize return object of type 'void *' with an lvalue of type '__strong id'}} +} + +// rdar://8898937 +namespace rdar8898937 { + +typedef void (^dispatch_block_t)(void); + +void dispatch_once(dispatch_block_t block); +static void _dispatch_once(dispatch_block_t block) +{ + dispatch_once(block); +} + +} + +void static_casts(id arg) { + void* voidp_val; + (void)static_cast<int*>(arg); // expected-error {{cannot cast from type 'id' to pointer type 'int *'}} + (void)static_cast<id>(arg); + (void)static_cast<__autoreleasing id*>(arg); // expected-error{{cannot cast from type 'id' to pointer type '__autoreleasing id *'}} + (void)static_cast<id*>(arg); // expected-error {{cannot cast from type 'id' to pointer type '__strong id *'}} + + (void)static_cast<__autoreleasing id**>(voidp_val); + (void)static_cast<void*>(voidp_val); + (void)static_cast<void**>(arg); // expected-error {{cannot cast from type 'id' to pointer type 'void **'}} + (void)static_cast<__strong id**>(0); + + __strong id *idp; + (void)static_cast<__autoreleasing id*>(idp); // expected-error{{static_cast from '__strong id *' to '__autoreleasing id *' is not allowed}} + (void)static_cast<__weak id*>(idp); // expected-error{{static_cast from '__strong id *' to '__weak id *' is not allowed}} +} + +void test_const_cast(__strong id *sip, __weak id *wip, + const __strong id *csip, __weak const id *cwip) { + // Cannot use const_cast to cast between ownership qualifications or + // add/remove ownership qualifications. + (void)const_cast<__strong id *>(wip); // expected-error{{is not allowed}} + (void)const_cast<__weak id *>(sip); // expected-error{{is not allowed}} + + // It's acceptable to cast away constness. + (void)const_cast<__strong id *>(csip); + (void)const_cast<__weak id *>(cwip); +} + +void test_reinterpret_cast(__strong id *sip, __weak id *wip, + const __strong id *csip, __weak const id *cwip) { + // Okay to reinterpret_cast to add/remove/change ownership + // qualifications. + (void)reinterpret_cast<__strong id *>(wip); + (void)reinterpret_cast<__weak id *>(sip); + + // Not allowed to cast away constness + (void)reinterpret_cast<__strong id *>(csip); // expected-error{{reinterpret_cast from '__strong id const *' to '__strong id *' casts away qualifiers}} + (void)reinterpret_cast<__weak id *>(cwip); // expected-error{{reinterpret_cast from '__weak id const *' to '__weak id *' casts away qualifiers}} + (void)reinterpret_cast<__weak id *>(csip); // expected-error{{reinterpret_cast from '__strong id const *' to '__weak id *' casts away qualifiers}} + (void)reinterpret_cast<__strong id *>(cwip); // expected-error{{reinterpret_cast from '__weak id const *' to '__strong id *' casts away qualifiers}} +} + +void test_cstyle_cast(__strong id *sip, __weak id *wip, + const __strong id *csip, __weak const id *cwip) { + // C-style casts aren't allowed to change Objective-C ownership + // qualifiers (beyond what the normal implicit conversion allows). + + (void)(__strong id *)wip; // expected-error{{C-style cast from '__weak id *' to '__strong id *' casts away qualifiers}} + (void)(__strong id *)cwip; // expected-error{{C-style cast from '__weak id const *' to '__strong id *' casts away qualifiers}} + (void)(__weak id *)sip; // expected-error{{C-style cast from '__strong id *' to '__weak id *' casts away qualifiers}} + (void)(__weak id *)csip; // expected-error{{C-style cast from '__strong id const *' to '__weak id *' casts away qualifiers}} + + (void)(__strong const id *)wip; // expected-error{{C-style cast from '__weak id *' to '__strong id const *' casts away qualifiers}} + (void)(__strong const id *)cwip; // expected-error{{C-style cast from '__weak id const *' to '__strong id const *' casts away qualifiers}} + (void)(__weak const id *)sip; // expected-error{{C-style cast from '__strong id *' to '__weak id const *' casts away qualifiers}} + (void)(__weak const id *)csip; // expected-error{{C-style cast from '__strong id const *' to '__weak id const *' casts away qualifiers}} + (void)(__autoreleasing const id *)wip; // expected-error{{C-style cast from '__weak id *' to '__autoreleasing id const *' casts away qualifiers}} + (void)(__autoreleasing const id *)cwip; // expected-error{{C-style cast from '__weak id const *' to '__autoreleasing id const *' casts away qualifiers}} + (void)(__autoreleasing const id *)sip; + (void)(__autoreleasing const id *)csip; +} + +void test_functional_cast(__strong id *sip, __weak id *wip, + __autoreleasing id *aip) { + // Functional casts aren't allowed to change Objective-C ownership + // qualifiers (beyond what the normal implicit conversion allows). + + typedef __strong id *strong_id_pointer; + typedef __weak id *weak_id_pointer; + typedef __autoreleasing id *autoreleasing_id_pointer; + + typedef const __strong id *const_strong_id_pointer; + typedef const __weak id *const_weak_id_pointer; + typedef const __autoreleasing id *const_autoreleasing_id_pointer; + + (void)strong_id_pointer(wip); // expected-error{{functional-style cast from '__weak id *' to 'strong_id_pointer' (aka '__strong id *') casts away qualifiers}} + (void)weak_id_pointer(sip); // expected-error{{functional-style cast from '__strong id *' to 'weak_id_pointer' (aka '__weak id *') casts away qualifiers}} + (void)autoreleasing_id_pointer(sip); // expected-error{{functional-style cast from '__strong id *' to 'autoreleasing_id_pointer' (aka '__autoreleasing id *') casts away qualifiers}} + (void)autoreleasing_id_pointer(wip); // expected-error{{functional-style cast from '__weak id *' to 'autoreleasing_id_pointer' (aka '__autoreleasing id *') casts away qualifiers}} + (void)const_strong_id_pointer(wip); // expected-error{{functional-style cast from '__weak id *' to 'const_strong_id_pointer' (aka 'const __strong id *') casts away qualifiers}} + (void)const_weak_id_pointer(sip); // expected-error{{functional-style cast from '__strong id *' to 'const_weak_id_pointer' (aka 'const __weak id *') casts away qualifiers}} + (void)const_autoreleasing_id_pointer(sip); + (void)const_autoreleasing_id_pointer(aip); + (void)const_autoreleasing_id_pointer(wip); // expected-error{{functional-style cast from '__weak id *' to 'const_autoreleasing_id_pointer' (aka 'const __autoreleasing id *') casts away qualifiers}} +} + +void test_unsafe_unretained(__strong id *sip, __weak id *wip, + __autoreleasing id *aip, + __unsafe_unretained id *uip, + const __unsafe_unretained id *cuip) { + uip = sip; // expected-error{{assigning to '__unsafe_unretained id *' from incompatible type '__strong id *'}} + uip = wip; // expected-error{{assigning to '__unsafe_unretained id *' from incompatible type '__weak id *'}} + uip = aip; // expected-error{{assigning to '__unsafe_unretained id *' from incompatible type '__autoreleasing id *'}} + + cuip = sip; + cuip = wip; // expected-error{{assigning to '__unsafe_unretained id const *' from incompatible type '__weak id *'}} + cuip = aip; +} + +void to_void(__strong id *sip, __weak id *wip, + __autoreleasing id *aip, + __unsafe_unretained id *uip) { + void *vp1 = sip; + void *vp2 = wip; + void *vp3 = aip; + void *vp4 = uip; + (void)(void*)sip; + (void)(void*)wip; + (void)(void*)aip; + (void)(void*)uip; + (void)static_cast<void*>(sip); + (void)static_cast<void*>(wip); + (void)static_cast<void*>(aip); + (void)static_cast<void*>(uip); + (void)reinterpret_cast<void*>(sip); + (void)reinterpret_cast<void*>(wip); + (void)reinterpret_cast<void*>(aip); + (void)reinterpret_cast<void*>(uip); + + (void)(void*)&sip; + (void)(void*)&wip; + (void)(void*)&aip; + (void)(void*)&uip; + (void)static_cast<void*>(&sip); + (void)static_cast<void*>(&wip); + (void)static_cast<void*>(&aip); + (void)static_cast<void*>(&uip); + (void)reinterpret_cast<void*>(&sip); + (void)reinterpret_cast<void*>(&wip); + (void)reinterpret_cast<void*>(&aip); + (void)reinterpret_cast<void*>(&uip); +} + +void from_void(void *vp) { + __strong id *sip = (__strong id *)vp; + __weak id *wip = (__weak id *)vp; + __autoreleasing id *aip = (__autoreleasing id *)vp; + __unsafe_unretained id *uip = (__unsafe_unretained id *)vp; + __strong id *sip2 = static_cast<__strong id *>(vp); + __weak id *wip2 = static_cast<__weak id *>(vp); + __autoreleasing id *aip2 = static_cast<__autoreleasing id *>(vp); + __unsafe_unretained id *uip2 = static_cast<__unsafe_unretained id *>(vp); + __strong id *sip3 = reinterpret_cast<__strong id *>(vp); + __weak id *wip3 = reinterpret_cast<__weak id *>(vp); + __autoreleasing id *aip3 = reinterpret_cast<__autoreleasing id *>(vp); + __unsafe_unretained id *uip3 = reinterpret_cast<__unsafe_unretained id *>(vp); + + __strong id **sipp = (__strong id **)vp; + __weak id **wipp = (__weak id **)vp; + __autoreleasing id **aipp = (__autoreleasing id **)vp; + __unsafe_unretained id **uipp = (__unsafe_unretained id **)vp; + + sip = vp; // expected-error{{assigning to '__strong id *' from incompatible type 'void *'}} + wip = vp; // expected-error{{assigning to '__weak id *' from incompatible type 'void *'}} + aip = vp; // expected-error{{assigning to '__autoreleasing id *' from incompatible type 'void *'}} + uip = vp; // expected-error{{assigning to '__unsafe_unretained id *' from incompatible type 'void *'}} +} + +typedef void (^Block)(); +typedef void (^Block_strong)() __strong; +typedef void (^Block_autoreleasing)() __autoreleasing; + +@class NSString; + +void ownership_transfer_in_cast(void *vp, Block *pblk) { + __strong NSString **sip2 = static_cast<NSString **>(static_cast<__strong id *>(vp)); + __strong NSString **&si2pref = static_cast<NSString **&>(sip2); + __weak NSString **wip2 = static_cast<NSString **>(static_cast<__weak id *>(vp)); + __autoreleasing id *aip2 = static_cast<id *>(static_cast<__autoreleasing id *>(vp)); + __unsafe_unretained id *uip2 = static_cast<id *>(static_cast<__unsafe_unretained id *>(vp)); + __strong id *sip3 = reinterpret_cast<id *>(reinterpret_cast<__strong id *>(vp)); + __weak id *wip3 = reinterpret_cast<id *>(reinterpret_cast<__weak id *>(vp)); + __autoreleasing id *aip3 = reinterpret_cast<id *>(reinterpret_cast<__autoreleasing id *>(vp)); + __unsafe_unretained id *uip3 = reinterpret_cast<id *>(reinterpret_cast<__unsafe_unretained id *>(vp)); + + Block_strong blk_strong1; + Block_strong blk_strong2 = static_cast<Block>(blk_strong1); + Block_autoreleasing *blk_auto = static_cast<Block*>(pblk); +} + +// Make sure we don't crash. +void writeback_test(NSString & &) {} // expected-error {{type name declared as a reference to a reference}} diff --git a/test/SemaObjCXX/arc-type-traits.mm b/test/SemaObjCXX/arc-type-traits.mm new file mode 100644 index 0000000..f50904b --- /dev/null +++ b/test/SemaObjCXX/arc-type-traits.mm @@ -0,0 +1,90 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-weak -verify %s + +// Check the results of the various type-trait query functions on +// lifetime-qualified types in ARC. + +#define JOIN3(X,Y) X ## Y +#define JOIN2(X,Y) JOIN3(X,Y) +#define JOIN(X,Y) JOIN2(X,Y) + +#define TRAIT_IS_TRUE(Trait, Type) char JOIN2(Trait,__LINE__)[Trait(Type)? 1 : -1] +#define TRAIT_IS_FALSE(Trait, Type) char JOIN2(Trait,__LINE__)[Trait(Type)? -1 : 1] + +// __has_nothrow_assign +TRAIT_IS_TRUE(__has_nothrow_assign, __strong id); +TRAIT_IS_TRUE(__has_nothrow_assign, __weak id); +TRAIT_IS_TRUE(__has_nothrow_assign, __autoreleasing id); +TRAIT_IS_TRUE(__has_nothrow_assign, __unsafe_unretained id); + +// __has_nothrow_copy +TRAIT_IS_TRUE(__has_nothrow_copy, __strong id); +TRAIT_IS_TRUE(__has_nothrow_copy, __weak id); +TRAIT_IS_TRUE(__has_nothrow_copy, __autoreleasing id); +TRAIT_IS_TRUE(__has_nothrow_copy, __unsafe_unretained id); + +// __has_nothrow_constructor +TRAIT_IS_TRUE(__has_nothrow_constructor, __strong id); +TRAIT_IS_TRUE(__has_nothrow_constructor, __weak id); +TRAIT_IS_TRUE(__has_nothrow_constructor, __autoreleasing id); +TRAIT_IS_TRUE(__has_nothrow_constructor, __unsafe_unretained id); + +// __has_trivial_assign +TRAIT_IS_FALSE(__has_trivial_assign, __strong id); +TRAIT_IS_FALSE(__has_trivial_assign, __weak id); +TRAIT_IS_FALSE(__has_trivial_assign, __autoreleasing id); +TRAIT_IS_TRUE(__has_trivial_assign, __unsafe_unretained id); + +// __has_trivial_copy +TRAIT_IS_FALSE(__has_trivial_copy, __strong id); +TRAIT_IS_FALSE(__has_trivial_copy, __weak id); +TRAIT_IS_FALSE(__has_trivial_copy, __autoreleasing id); +TRAIT_IS_TRUE(__has_trivial_copy, __unsafe_unretained id); + +// __has_trivial_constructor +TRAIT_IS_FALSE(__has_trivial_constructor, __strong id); +TRAIT_IS_FALSE(__has_trivial_constructor, __weak id); +TRAIT_IS_FALSE(__has_trivial_constructor, __autoreleasing id); +TRAIT_IS_TRUE(__has_trivial_constructor, __unsafe_unretained id); + +// __has_trivial_destructor +TRAIT_IS_FALSE(__has_trivial_destructor, __strong id); +TRAIT_IS_FALSE(__has_trivial_destructor, __weak id); +TRAIT_IS_TRUE(__has_trivial_destructor, __autoreleasing id); +TRAIT_IS_TRUE(__has_trivial_destructor, __unsafe_unretained id); + +// __is_literal +TRAIT_IS_FALSE(__is_literal, __strong id); +TRAIT_IS_FALSE(__is_literal, __weak id); +TRAIT_IS_FALSE(__is_literal, __autoreleasing id); +TRAIT_IS_FALSE(__is_literal, __unsafe_unretained id); + +// __is_literal_type +TRAIT_IS_FALSE(__is_literal_type, __strong id); +TRAIT_IS_FALSE(__is_literal_type, __weak id); +TRAIT_IS_FALSE(__is_literal_type, __autoreleasing id); +TRAIT_IS_FALSE(__is_literal_type, __unsafe_unretained id); + +// __is_pod +TRAIT_IS_FALSE(__is_pod, __strong id); +TRAIT_IS_FALSE(__is_pod, __weak id); +TRAIT_IS_FALSE(__is_pod, __autoreleasing id); +TRAIT_IS_TRUE(__is_pod, __unsafe_unretained id); + +// __is_trivial +TRAIT_IS_FALSE(__is_trivial, __strong id); +TRAIT_IS_FALSE(__is_trivial, __weak id); +TRAIT_IS_FALSE(__is_trivial, __autoreleasing id); +TRAIT_IS_TRUE(__is_trivial, __unsafe_unretained id); + +// __is_scalar +TRAIT_IS_FALSE(__is_scalar, __strong id); +TRAIT_IS_FALSE(__is_scalar, __weak id); +TRAIT_IS_FALSE(__is_scalar, __autoreleasing id); +TRAIT_IS_TRUE(__is_scalar, __unsafe_unretained id); + +// __is_standard_layout +TRAIT_IS_TRUE(__is_standard_layout, __strong id); +TRAIT_IS_TRUE(__is_standard_layout, __weak id); +TRAIT_IS_TRUE(__is_standard_layout, __autoreleasing id); +TRAIT_IS_TRUE(__is_standard_layout, __unsafe_unretained id); + diff --git a/test/SemaObjCXX/arc-unavailable-for-weakref.mm b/test/SemaObjCXX/arc-unavailable-for-weakref.mm new file mode 100644 index 0000000..a7b3570 --- /dev/null +++ b/test/SemaObjCXX/arc-unavailable-for-weakref.mm @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s +// rdar://9693477 + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface NSOptOut1072 // expected-note {{class is declared here}} +@end + +@interface sub : NSOptOut1072 @end // expected-note 2 {{class is declared here}} + +int main() { + __weak sub *w2; // expected-error {{class is incompatible with __weak references}} + + __weak NSOptOut1072 *ns1; // expected-error {{class is incompatible with __weak references}} + + id obj; + + ns1 = (__weak sub *)obj; // expected-error {{assignment of a weak-unavailable object to a __weak object}} \ + // expected-error {{class is incompatible with __weak references}} +} + +// rdar://9732636 +__attribute__((objc_arc_weak_reference_unavailable)) +@interface NOWEAK ++ (id) new; +@end + +NOWEAK * Test1() { + NOWEAK * strong1 = [NOWEAK new]; + __weak id weak1; + weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} + + __weak id weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} + return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}} +} + +@protocol P @end +@protocol P1 @end + +NOWEAK<P, P1> * Test2() { + NOWEAK<P, P1> * strong1 = 0; + __weak id<P> weak1; + weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} + + __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} + return (__weak id<P, P1>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P,P1>'}} +} + diff --git a/test/SemaObjCXX/exceptions-fragile.mm b/test/SemaObjCXX/exceptions-fragile.mm index d1e7077..71e259a 100644 --- a/test/SemaObjCXX/exceptions-fragile.mm +++ b/test/SemaObjCXX/exceptions-fragile.mm @@ -6,7 +6,7 @@ void opaque(); namespace test0 { void test() { try { - } catch (NSException *e) { // expected-error {{can't catch Objective C exceptions in C++ in the non-unified exception model}} + } catch (NSException *e) { // expected-warning {{can not catch an exception thrown with @throw in C++ in the non-unified exception model}} } } } diff --git a/test/SemaObjCXX/gc-attributes.mm b/test/SemaObjCXX/gc-attributes.mm index 70a93b2..4549683 100644 --- a/test/SemaObjCXX/gc-attributes.mm +++ b/test/SemaObjCXX/gc-attributes.mm @@ -3,7 +3,7 @@ @interface A @end -void f0(__strong A**); // expected-note{{candidate function not viable: 1st argument ('A *__weak *') has __weak lifetime, but parameter has __strong lifetime}} +void f0(__strong A**); // expected-note{{candidate function not viable: 1st argument ('A *__weak *') has __weak ownership, but parameter has __strong ownership}} void test_f0() { A *a; @@ -12,7 +12,7 @@ void test_f0() { f0(&a2); // expected-error{{no matching function}} } -void f1(__weak A**); // expected-note{{candidate function not viable: 1st argument ('A *__strong *') has __strong lifetime, but parameter has __weak lifetime}} +void f1(__weak A**); // expected-note{{candidate function not viable: 1st argument ('A *__strong *') has __strong ownership, but parameter has __weak ownership}} void test_f1() { A *a; diff --git a/test/SemaObjCXX/null_objc_pointer.mm b/test/SemaObjCXX/null_objc_pointer.mm new file mode 100644 index 0000000..0da9e50 --- /dev/null +++ b/test/SemaObjCXX/null_objc_pointer.mm @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wnull-arithmetic %s +#define NULL __null + +@interface X +@end + +void f() { + bool b; + X *d; + b = d < NULL || NULL < d || d > NULL || NULL > d; + b = d <= NULL || NULL <= d || d >= NULL || NULL >= d; + b = d == NULL || NULL == d || d != NULL || NULL != d; +} diff --git a/test/SemaObjCXX/nullptr.mm b/test/SemaObjCXX/nullptr.mm index 4cd5669..4a9d1a0 100644 --- a/test/SemaObjCXX/nullptr.mm +++ b/test/SemaObjCXX/nullptr.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++0x -fblocks -fsyntax-only -verify %s @interface A @end @@ -11,3 +11,6 @@ void comparisons(A *a) { void assignment(A *a) { a = nullptr; } + +int PR10145a = (void(^)())0 == nullptr; +int PR10145b = nullptr == (void(^)())0; diff --git a/test/SemaObjCXX/property-type-mismatch.mm b/test/SemaObjCXX/property-type-mismatch.mm new file mode 100644 index 0000000..059793c --- /dev/null +++ b/test/SemaObjCXX/property-type-mismatch.mm @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9740328 + +@protocol P1; + +@interface NSObject +@end + +@interface A : NSObject +@property (assign) NSObject<P1> *prop; +@end + +@protocol P2 <P1> +@end + +@interface B : A +@property (assign) NSObject<P2> *prop; +@end + diff --git a/test/SemaObjCXX/related-result-type-inference.mm b/test/SemaObjCXX/related-result-type-inference.mm index c3cab05..675e6ac 100644 --- a/test/SemaObjCXX/related-result-type-inference.mm +++ b/test/SemaObjCXX/related-result-type-inference.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fobjc-infer-related-result-type -verify %s +// RUN: %clang_cc1 -verify %s @interface Unrelated @end diff --git a/test/SemaOpenCL/vector_literals_invalid.cl b/test/SemaOpenCL/vector_literals_invalid.cl new file mode 100644 index 0000000..957680f --- /dev/null +++ b/test/SemaOpenCL/vector_literals_invalid.cl @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -verify %s + +typedef __attribute__(( ext_vector_type(4) )) float float4; +typedef __attribute__(( ext_vector_type(4) )) int int4; +typedef __attribute__(( ext_vector_type(8) )) int int8; + +void vector_literals_invalid() +{ + int4 a = (int4)(1,2,3); // expected-error{{too few elements}} + int4 b = (int4)(1,2,3,4,5); // expected-error{{excess elements in vector}} + ((float4)(1.0f))++; // expected-error{{expression is not assignable}} + int8 d = (int8)(a,(float4)(1)); // expected-error{{initializing 'int' with an expression of incompatible type 'float4'}} +} diff --git a/test/SemaTemplate/class-template-decl.cpp b/test/SemaTemplate/class-template-decl.cpp index e772212..2e84e93 100644 --- a/test/SemaTemplate/class-template-decl.cpp +++ b/test/SemaTemplate/class-template-decl.cpp @@ -50,7 +50,7 @@ void f() { template<typename T> class X; // expected-error{{expression}} } -template<typename T> class X1 { } var; // expected-error{{declared as a template}} +template<typename T> class X1 var; // expected-error{{declared as a template}} namespace M { } diff --git a/test/SemaTemplate/deduction.cpp b/test/SemaTemplate/deduction.cpp index 15c061c..aecb5ee 100644 --- a/test/SemaTemplate/deduction.cpp +++ b/test/SemaTemplate/deduction.cpp @@ -150,3 +150,15 @@ namespace test3 { } }; } + +// Verify that we can deduce enum-typed arguments correctly. +namespace test14 { + enum E { E0, E1 }; + template <E> struct A {}; + template <E e> void foo(const A<e> &a) {} + + void test() { + A<E0> a; + foo(a); + } +} diff --git a/test/SemaTemplate/default-arguments.cpp b/test/SemaTemplate/default-arguments.cpp index 9ea0fc2..6391369 100644 --- a/test/SemaTemplate/default-arguments.cpp +++ b/test/SemaTemplate/default-arguments.cpp @@ -121,3 +121,18 @@ X6<long, X5b> x6c; template<template<class> class X = B<int> > struct X7; // expected-error{{must be a class template}} + +namespace PR9643 { + template<typename T> class allocator {}; + template<typename T, typename U = allocator<T> > class vector {}; + + template<template<typename U, typename = allocator<U> > class container, + typename DT> + container<DT> initializer(const DT& d) { + return container<DT>(); + } + + void f() { + vector<int, allocator<int> > v = initializer<vector>(5); + } +} diff --git a/test/SemaTemplate/dependent-names-no-std.cpp b/test/SemaTemplate/dependent-names-no-std.cpp index e9ac99f..2fb9d99 100644 --- a/test/SemaTemplate/dependent-names-no-std.cpp +++ b/test/SemaTemplate/dependent-names-no-std.cpp @@ -11,7 +11,7 @@ namespace PR10053 { template<typename T> struct A { T t; A() { - f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument dependent lookup}} + f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}} } }; diff --git a/test/SemaTemplate/dependent-names.cpp b/test/SemaTemplate/dependent-names.cpp index 2a50df5..7bab5d1 100644 --- a/test/SemaTemplate/dependent-names.cpp +++ b/test/SemaTemplate/dependent-names.cpp @@ -148,7 +148,7 @@ namespace PR10053 { template<typename T> struct A { T t; A() { - f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument dependent lookup}} + f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}} } }; @@ -160,7 +160,7 @@ namespace PR10053 { namespace N { namespace M { template<typename T> int g(T t) { - f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument dependent lookup}} + f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}} }; } @@ -187,7 +187,7 @@ namespace PR10053 { // Example from www/compatibility.html namespace my_file { template <typename T> T Squared(T x) { - return Multiply(x, x); // expected-error {{neither visible in the template definition nor found by argument dependent lookup}} + return Multiply(x, x); // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}} } int Multiply(int x, int y) { // expected-note {{should be declared prior to the call site}} @@ -203,7 +203,7 @@ namespace PR10053 { namespace my_file2 { template<typename T> void Dump(const T& value) { - std::cout << value << "\n"; // expected-error {{neither visible in the template definition nor found by argument dependent lookup}} + std::cout << value << "\n"; // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}} } namespace ns { @@ -222,7 +222,7 @@ namespace PR10053 { namespace my_file2_a { template<typename T> void Dump(const T &value) { - print(std::cout, value); // expected-error 4{{neither visible in the template definition nor found by argument dependent lookup}} + print(std::cout, value); // expected-error 4{{neither visible in the template definition nor found by argument-dependent lookup}} } namespace ns { @@ -248,7 +248,7 @@ namespace PR10053 { namespace unary { template<typename T> T Negate(const T& value) { - return !value; // expected-error {{call to function 'operator!' that is neither visible in the template definition nor found by argument dependent lookup}} + return !value; // expected-error {{call to function 'operator!' that is neither visible in the template definition nor found by argument-dependent lookup}} } namespace ns { @@ -262,3 +262,33 @@ namespace PR10053 { } } } + +namespace PR10187 { + namespace A { + template<typename T> + struct S { + void f() { + for (auto &a : e) + __range(a); // expected-error {{undeclared identifier '__range'}} + } + int e[10]; + }; + void g() { + S<int>().f(); // expected-note {{here}} + } + } + + namespace B { + template<typename T> void g(); // expected-note {{not viable}} + template<typename T> void f() { + g<int>(T()); // expected-error {{no matching function}} + } + + namespace { + struct S {}; + } + void g(S); + + template void f<S>(); // expected-note {{here}} + } +} diff --git a/test/SemaTemplate/ext-vector-type.cpp b/test/SemaTemplate/ext-vector-type.cpp index 7334e88..f968c13 100644 --- a/test/SemaTemplate/ext-vector-type.cpp +++ b/test/SemaTemplate/ext-vector-type.cpp @@ -58,3 +58,37 @@ int test_make6() { y.x = -1; y.w = -1; // expected-error{{vector component access exceeds type}} } + +namespace Deduction { + template<typename T> struct X0; + + template<typename T, unsigned N> + struct X0<T __attribute__((ext_vector_type(N)))> { + static const unsigned value = 0; + }; + + template<typename T> + struct X0<T __attribute__((ext_vector_type(4)))> { + static const unsigned value = 1; + }; + + template<unsigned N> + struct X0<float __attribute__((ext_vector_type(N)))> { + static const unsigned value = 2; + }; + + template<> + struct X0<float __attribute__((ext_vector_type(4)))> { + static const unsigned value = 3; + }; + + typedef int __attribute__((ext_vector_type(2))) int2; + typedef int __attribute__((ext_vector_type(4))) int4; + typedef float __attribute__((ext_vector_type(2))) float2; + typedef float __attribute__((ext_vector_type(4))) float4; + + int array0[X0<int2>::value == 0? 1 : -1]; + int array1[X0<int4>::value == 1? 1 : -1]; + int array2[X0<float2>::value == 2? 1 : -1]; + int array3[X0<float4>::value == 3? 1 : -1]; +} diff --git a/test/SemaTemplate/instantiate-call.cpp b/test/SemaTemplate/instantiate-call.cpp index a0e48c8..da1eb49 100644 --- a/test/SemaTemplate/instantiate-call.cpp +++ b/test/SemaTemplate/instantiate-call.cpp @@ -25,7 +25,7 @@ namespace N3 { struct call_f0 { void test_f0(T t) { Result &result = f0(t); // expected-error {{undeclared identifier}} \ - expected-error {{neither visible in the template definition nor found by argument dependent lookup}} + expected-error {{neither visible in the template definition nor found by argument-dependent lookup}} } }; } diff --git a/test/SemaTemplate/instantiate-function-2.cpp b/test/SemaTemplate/instantiate-function-2.cpp index ebc0ef3..087ede2 100644 --- a/test/SemaTemplate/instantiate-function-2.cpp +++ b/test/SemaTemplate/instantiate-function-2.cpp @@ -31,3 +31,36 @@ namespace UsedAttr { foo<int>(); // expected-note{{instantiation of}} } } + +namespace PR9654 { + typedef void ftype(int); + + template<typename T> + ftype f; + + void g() { + f<int>(0); + } +} + +namespace AliasTagDef { + template<typename T> + T f() { + using S = struct { // expected-warning {{C++0x}} + T g() { + return T(); + } + }; + return S().g(); + } + + int n = f<int>(); +} + +namespace PR10273 { + template<typename T> void (f)(T t) {} + + void g() { + (f)(17); + } +} diff --git a/test/SemaTemplate/instantiate-member-class.cpp b/test/SemaTemplate/instantiate-member-class.cpp index 74c2609..1028b45 100644 --- a/test/SemaTemplate/instantiate-member-class.cpp +++ b/test/SemaTemplate/instantiate-member-class.cpp @@ -104,3 +104,17 @@ namespace test2 { }; template class C<int>; } + +namespace AliasTagDef { + template<typename T> + struct F { + using S = struct U { // expected-warning {{C++0x}} + T g() { + return T(); + } + }; + }; + + int m = F<int>::S().g(); + int n = F<int>::U().g(); +} diff --git a/test/SemaTemplate/instantiate-try-catch.cpp b/test/SemaTemplate/instantiate-try-catch.cpp index 1c6c26f..f4ce0e1 100644 --- a/test/SemaTemplate/instantiate-try-catch.cpp +++ b/test/SemaTemplate/instantiate-try-catch.cpp @@ -12,3 +12,20 @@ template struct TryCatch0<int&>; // okay template struct TryCatch0<int&&>; // expected-note{{instantiation}} template struct TryCatch0<int>; // expected-note{{instantiation}} + +namespace PR10232 { + template <typename T> + class Templated { + struct Exception { + private: + Exception(const Exception&); // expected-note{{declared private here}} + }; + void exception() { + try { + } catch(Exception e) { // expected-error{{calling a private constructor of class 'PR10232::Templated<int>::Exception'}} + } + } + }; + + template class Templated<int>; // expected-note{{in instantiation of member function 'PR10232::Templated<int>::exception' requested here}} +} diff --git a/test/SemaTemplate/member-inclass-init-value-dependent.cpp b/test/SemaTemplate/member-inclass-init-value-dependent.cpp new file mode 100644 index 0000000..d1ae4f2 --- /dev/null +++ b/test/SemaTemplate/member-inclass-init-value-dependent.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm-only %s +// PR10290 + +template<int Flags> struct foo { + int value = Flags && 0; +}; + +void test() { + foo<4> bar; +} + diff --git a/test/SemaTemplate/unresolved-construct.cpp b/test/SemaTemplate/unresolved-construct.cpp new file mode 100644 index 0000000..0d1ba17 --- /dev/null +++ b/test/SemaTemplate/unresolved-construct.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s +class A +{ +public: + A() {} + + template <class _F> + explicit A(_F&& __f); + + A(A&&) {} + A& operator=(A&&) {return *this;} +}; + +template <class T> +void f(T t) +{ + A a; + a = f(t); +} diff --git a/test/Unit/lit.cfg b/test/Unit/lit.cfg index 794234c..8f27781 100644 --- a/test/Unit/lit.cfg +++ b/test/Unit/lit.cfg @@ -30,14 +30,6 @@ if 'TEMP' in os.environ: ### -# If necessary, point the dynamic loader at libLLVM.so. -if config.enable_shared: - shlibpath = config.environment.get(config.shlibpath_var,'') - if shlibpath: - shlibpath = os.pathsep + shlibpath - shlibpath = config.shlibdir + shlibpath - config.environment[config.shlibpath_var] = shlibpath - # Check that the object root is known. if config.test_exec_root is None: # Otherwise, we haven't loaded the site specific configuration (the user is @@ -71,7 +63,7 @@ if config.test_exec_root is None: # Validate that we got a tree which points to here, using the standard # tools/clang layout. - this_src_root = os.path.dirname(config.test_source_root) + this_src_root = os.path.join(os.path.dirname(__file__),'..','..') if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root): lit.fatal('No site specific configuration available!') @@ -84,3 +76,11 @@ if config.test_exec_root is None: lit.note('using out-of-tree build at %r' % clang_obj_root) lit.load_config(config, site_cfg) raise SystemExit + +# If necessary, point the dynamic loader at libLLVM.so. +if config.enable_shared: + shlibpath = config.environment.get(config.shlibpath_var,'') + if shlibpath: + shlibpath = os.pathsep + shlibpath + shlibpath = config.shlibdir + shlibpath + config.environment[config.shlibpath_var] = shlibpath |