brintos

brintos / llvm-project-archived public Read only

0
0
Text · 876 B · 6dd3dc7 Raw
28 lines · plain
1// REQUIRES: darwin2//3// RUN: %clang -framework Foundation -fsanitize=objc-cast %s -O1 -o %t4// RUN: %run %t 2>&1 | FileCheck %s5//6// RUN: %clang -framework Foundation -fsanitize=objc-cast -fno-sanitize-recover=objc-cast %s -O1 -o %t.trap7// RUN: not %run %t.trap 2>&1 | FileCheck %s8 9#include <Foundation/Foundation.h>10 11int main() {12  NSArray *arrayOfInt = [NSArray arrayWithObjects:@1, @2, @3, (void *)0];13  // CHECK: objc-cast.m:[[@LINE+1]]:{{.*}}: runtime error: invalid ObjC cast, object is a '{{__NSCFNumber|NSConstantIntegerNumber}}', but expected a 'NSString'14  for (NSString *str in arrayOfInt) {15    NSLog(@"%@", str);16  }17 18  NSArray *arrayOfStr = [NSArray arrayWithObjects:@"a", @"b", @"c", (void *)0];19  for (NSString *str in arrayOfStr) {20    NSLog(@"%@", str);21  }22 23  // The diagnostic should only be printed once.24  // CHECK-NOT: runtime error25 26  return 0;27}28