Skip to content

Commit 77e2606

Browse files
committed
fix UB in testcase
1 parent ec1024d commit 77e2606

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

clang/test/CodeGen/array-bounds-constraints.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
// CHECK-LABEL: define {{.*}} @test_simple_array
99
// NO-FLAG-LABEL: define {{.*}} @test_simple_array
10+
void init_array(int *arr);
1011
int test_simple_array(int i) {
1112
int arr[10]; // C arrays are 0-based: valid indices are [0, 9]
13+
init_array(arr); // Initialize to avoid UB from uninitialized read.
1214
// CHECK: %{{.*}} = icmp ult i32 %i, 10
1315
// CHECK: call void @llvm.assume(i1 %{{.*}})
1416
// NO-FLAG-NOT: call void @llvm.assume
@@ -18,6 +20,7 @@ int test_simple_array(int i) {
1820
// CHECK-LABEL: define {{.*}} @test_multidimensional_array
1921
int test_multidimensional_array(int i, int j) {
2022
int arr[5][8]; // Valid indices: i in [0, 4], j in [0, 7]
23+
init_array(arr[0]); // Initialize to avoid UB from uninitialized read.
2124
// CHECK: %{{.*}} = icmp ult i32 %i, 5
2225
// CHECK: call void @llvm.assume(i1 %{{.*}})
2326
// CHECK: %{{.*}} = icmp ult i32 %j, 8
@@ -28,6 +31,7 @@ int test_multidimensional_array(int i, int j) {
2831
// CHECK-LABEL: define {{.*}} @test_unsigned_index
2932
int test_unsigned_index(unsigned int i) {
3033
int arr[10];
34+
init_array(arr); // Initialize to avoid UB from uninitialized read.
3135
// CHECK: %{{.*}} = icmp ult i32 %i, 10
3236
// CHECK: call void @llvm.assume(i1 %{{.*}})
3337
return arr[i];

0 commit comments

Comments
 (0)