The test checks that an array of Obj-C literal integers (e.g. `@1`) gets a UBSan warning when cast to an NSString, however the actual concrete Obj-C class of literal integers doesn't always need to be __NSCFNumber. Let's relax the test expectations to allow NSConstantIntegerNumber. Which exact subclass of NSNumber is used is not actually important for the test (the test is just checking that the invalid cast warning is thrown).
28 lines
876 B
Objective-C
28 lines
876 B
Objective-C
// REQUIRES: darwin
|
|
//
|
|
// RUN: %clang -framework Foundation -fsanitize=objc-cast %s -O1 -o %t
|
|
// RUN: %run %t 2>&1 | FileCheck %s
|
|
//
|
|
// RUN: %clang -framework Foundation -fsanitize=objc-cast -fno-sanitize-recover=objc-cast %s -O1 -o %t.trap
|
|
// RUN: not %run %t.trap 2>&1 | FileCheck %s
|
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
int main() {
|
|
NSArray *arrayOfInt = [NSArray arrayWithObjects:@1, @2, @3, (void *)0];
|
|
// CHECK: objc-cast.m:[[@LINE+1]]:{{.*}}: runtime error: invalid ObjC cast, object is a '{{__NSCFNumber|NSConstantIntegerNumber}}', but expected a 'NSString'
|
|
for (NSString *str in arrayOfInt) {
|
|
NSLog(@"%@", str);
|
|
}
|
|
|
|
NSArray *arrayOfStr = [NSArray arrayWithObjects:@"a", @"b", @"c", (void *)0];
|
|
for (NSString *str in arrayOfStr) {
|
|
NSLog(@"%@", str);
|
|
}
|
|
|
|
// The diagnostic should only be printed once.
|
|
// CHECK-NOT: runtime error
|
|
|
|
return 0;
|
|
}
|