Richard Smith | 6b53e22 | 2013-10-22 22:51:04 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsanitize=local-bounds -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s |
2 | // RUN: %clang_cc1 -fsanitize=array-bounds -O -fsanitize-undefined-trap-on-error -emit-llvm -triple x86_64-apple-darwin10 -DNO_DYNAMIC %s -o - | FileCheck %s | ||||
Nuno Lopes | ddcce0b | 2012-05-09 15:53:34 +0000 | [diff] [blame] | 3 | |
Richard Smith | 6b53e22 | 2013-10-22 22:51:04 +0000 | [diff] [blame] | 4 | // CHECK-LABEL: @f |
Nuno Lopes | ddcce0b | 2012-05-09 15:53:34 +0000 | [diff] [blame] | 5 | double f(int b, int i) { |
6 | double a[b]; | ||||
Richard Smith | 6b53e22 | 2013-10-22 22:51:04 +0000 | [diff] [blame] | 7 | // CHECK: call {{.*}} @llvm.trap |
Nuno Lopes | ddcce0b | 2012-05-09 15:53:34 +0000 | [diff] [blame] | 8 | return a[i]; |
Nuno Lopes | ddcce0b | 2012-05-09 15:53:34 +0000 | [diff] [blame] | 9 | } |
10 | |||||
Richard Smith | 6b53e22 | 2013-10-22 22:51:04 +0000 | [diff] [blame] | 11 | // CHECK-LABEL: @f2 |
Nuno Lopes | ddcce0b | 2012-05-09 15:53:34 +0000 | [diff] [blame] | 12 | void f2() { |
Nuno Lopes | a425589 | 2012-05-22 17:19:45 +0000 | [diff] [blame] | 13 | // everything is constant; no trap possible |
Richard Smith | 6b53e22 | 2013-10-22 22:51:04 +0000 | [diff] [blame] | 14 | // CHECK-NOT: call {{.*}} @llvm.trap |
Nuno Lopes | ddcce0b | 2012-05-09 15:53:34 +0000 | [diff] [blame] | 15 | int a[2]; |
Nuno Lopes | ddcce0b | 2012-05-09 15:53:34 +0000 | [diff] [blame] | 16 | a[1] = 42; |
Richard Smith | 6b53e22 | 2013-10-22 22:51:04 +0000 | [diff] [blame] | 17 | |
18 | #ifndef NO_DYNAMIC | ||||
Nuno Lopes | ddcce0b | 2012-05-09 15:53:34 +0000 | [diff] [blame] | 19 | short *b = malloc(64); |
Nuno Lopes | a425589 | 2012-05-22 17:19:45 +0000 | [diff] [blame] | 20 | b[5] = *a + a[1] + 2; |
Richard Smith | 6b53e22 | 2013-10-22 22:51:04 +0000 | [diff] [blame] | 21 | #endif |
Nuno Lopes | a425589 | 2012-05-22 17:19:45 +0000 | [diff] [blame] | 22 | } |
23 | |||||
Richard Smith | 6b53e22 | 2013-10-22 22:51:04 +0000 | [diff] [blame] | 24 | // CHECK-LABEL: @f3 |
Nuno Lopes | a425589 | 2012-05-22 17:19:45 +0000 | [diff] [blame] | 25 | void f3() { |
26 | int a[1]; | ||||
Richard Smith | 6b53e22 | 2013-10-22 22:51:04 +0000 | [diff] [blame] | 27 | // CHECK: call {{.*}} @llvm.trap |
Nuno Lopes | a425589 | 2012-05-22 17:19:45 +0000 | [diff] [blame] | 28 | a[2] = 1; |
Nuno Lopes | ddcce0b | 2012-05-09 15:53:34 +0000 | [diff] [blame] | 29 | } |