Argyrios Kyrtzidis | 981b6fd | 2010-11-09 01:30:48 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s |
Eli Friedman | 8f39f5e | 2008-12-20 23:11:59 +0000 | [diff] [blame] | 2 | |
| 3 | int b(char* x); |
| 4 | |
| 5 | // Extremely basic VLA test |
| 6 | void a(int x) { |
| 7 | char arry[x]; |
| 8 | arry[0] = 10; |
| 9 | b(arry); |
| 10 | } |
Anders Carlsson | b50525b | 2008-12-21 03:33:21 +0000 | [diff] [blame] | 11 | |
Anders Carlsson | 0269709 | 2008-12-21 03:40:32 +0000 | [diff] [blame] | 12 | int c(int n) |
Anders Carlsson | b50525b | 2008-12-21 03:33:21 +0000 | [diff] [blame] | 13 | { |
Anders Carlsson | 0269709 | 2008-12-21 03:40:32 +0000 | [diff] [blame] | 14 | return sizeof(int[n]); |
Anders Carlsson | b50525b | 2008-12-21 03:33:21 +0000 | [diff] [blame] | 15 | } |
Anders Carlsson | c756a8e | 2009-02-09 21:48:07 +0000 | [diff] [blame] | 16 | |
| 17 | int f0(int x) { |
| 18 | int vla[x]; |
| 19 | return vla[x-1]; |
| 20 | } |
Anders Carlsson | 22ab8d8 | 2009-02-10 22:50:24 +0000 | [diff] [blame] | 21 | |
| 22 | void |
| 23 | f(int count) |
| 24 | { |
| 25 | int a[count]; |
| 26 | |
| 27 | do { } while (0); |
| 28 | |
| 29 | if (a[0] != 3) { |
| 30 | } |
| 31 | } |
Eli Friedman | bdad6b6 | 2009-05-29 19:23:46 +0000 | [diff] [blame] | 32 | |
| 33 | void g(int count) { |
| 34 | // Make sure we emit sizes correctly in some obscure cases |
| 35 | int (*a[5])[count]; |
| 36 | int (*b)[][count]; |
| 37 | } |
Argyrios Kyrtzidis | 4ada2ca | 2010-09-14 00:42:34 +0000 | [diff] [blame] | 38 | |
| 39 | // rdar://8403108 |
| 40 | // CHECK: define void @f_8403108 |
| 41 | void f_8403108(unsigned x) { |
| 42 | // CHECK: call i8* @llvm.stacksave() |
| 43 | char s1[x]; |
| 44 | while (1) { |
| 45 | // CHECK: call i8* @llvm.stacksave() |
| 46 | char s2[x]; |
| 47 | if (1) |
| 48 | break; |
| 49 | // CHECK: call void @llvm.stackrestore(i8* |
| 50 | } |
| 51 | // CHECK: call void @llvm.stackrestore(i8* |
| 52 | } |
Fariborz Jahanian | f443570 | 2010-09-21 22:53:33 +0000 | [diff] [blame] | 53 | |
| 54 | // pr7827 |
Fariborz Jahanian | 745da3a | 2010-09-24 17:30:16 +0000 | [diff] [blame] | 55 | void function(short width, int data[][width]) {} // expected-note {{passing argument to parameter 'data' here}} |
Fariborz Jahanian | f443570 | 2010-09-21 22:53:33 +0000 | [diff] [blame] | 56 | |
| 57 | void test() { |
Fariborz Jahanian | 745da3a | 2010-09-24 17:30:16 +0000 | [diff] [blame] | 58 | int bork[4][13]; |
Fariborz Jahanian | f443570 | 2010-09-21 22:53:33 +0000 | [diff] [blame] | 59 | // CHECK: call void @function(i16 signext 1, i32* null) |
| 60 | function(1, 0); |
Fariborz Jahanian | 745da3a | 2010-09-24 17:30:16 +0000 | [diff] [blame] | 61 | // CHECK: call void @function(i16 signext 1, i32* inttoptr |
| 62 | function(1, 0xbadbeef); // expected-warning {{incompatible integer to pointer conversion passing}} |
| 63 | // CHECK: call void @function(i16 signext 1, i32* {{.*}}) |
| 64 | function(1, bork); |
| 65 | } |
| 66 | |
| 67 | void function1(short width, int data[][width][width]) {} |
| 68 | void test1() { |
| 69 | int bork[4][13][15]; |
| 70 | // CHECK: call void @function1(i16 signext 1, i32* {{.*}}) |
| 71 | function1(1, bork); |
| 72 | // CHECK: call void @function(i16 signext 1, i32* {{.*}}) |
| 73 | function(1, bork[2]); |
Fariborz Jahanian | f443570 | 2010-09-21 22:53:33 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Fariborz Jahanian | c5be7b0 | 2010-09-28 20:42:35 +0000 | [diff] [blame] | 76 | // rdar://8476159 |
| 77 | static int GLOB; |
| 78 | int test2(int n) |
| 79 | { |
| 80 | GLOB = 0; |
| 81 | char b[1][n+3]; /* Variable length array. */ |
| 82 | // CHECK: [[tmp_1:%.*]] = load i32* @GLOB, align 4 |
| 83 | // CHECK-NEXT: add nsw i32 [[tmp_1]], 1 |
| 84 | __typeof__(b[GLOB++]) c; |
| 85 | return GLOB; |
| 86 | } |
| 87 | |
Argyrios Kyrtzidis | 981b6fd | 2010-11-09 01:30:48 +0000 | [diff] [blame] | 88 | // http://llvm.org/PR8567 |
| 89 | // CHECK: define double @test_PR8567 |
| 90 | double test_PR8567(int n, double (*p)[n][5]) { |
| 91 | // CHECK: store [[vla_type:.*]] %p, |
Argyrios Kyrtzidis | 4672879 | 2010-11-09 03:43:49 +0000 | [diff] [blame] | 92 | // CHECK: load i32* |
Argyrios Kyrtzidis | 981b6fd | 2010-11-09 01:30:48 +0000 | [diff] [blame] | 93 | // CHECK-NEXT: mul i32 40 |
| 94 | // CHECK-NEXT: [[byte_idx:%.*]] = mul i32 1 |
| 95 | // CHECK-NEXT: [[tmp_1:%.*]] = load [[vla_type]]* |
| 96 | // CHECK-NEXT: [[tmp_2:%.*]] = bitcast [[vla_type]] [[tmp_1]] to i8* |
| 97 | // CHECK-NEXT: [[idx:%.*]] = getelementptr inbounds i8* [[tmp_2]], i32 [[byte_idx]] |
| 98 | // CHECK-NEXT: bitcast i8* [[idx]] to [[vla_type]] |
| 99 | return p[1][2][3]; |
| 100 | } |