mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 13:16:08 +00:00

Add nuw attribute to inbounds GEPs where the expression used to form the GEP is an addition of unsigned indices. Relands #105496, which was reverted because it exposed a miscompilation arising from #98608. This is now fixed by #106512.
28 lines
929 B
Objective-C
28 lines
929 B
Objective-C
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s -fsanitize=pointer-overflow | FileCheck %s
|
|
|
|
// CHECK-LABEL: define{{.*}} void @variable_len_array_arith
|
|
void variable_len_array_arith(int n, int k) {
|
|
int vla[n];
|
|
int (*p)[n] = &vla;
|
|
|
|
// CHECK: getelementptr inbounds nuw i32, ptr {{.*}}, i64 [[INC:%.*]]
|
|
// CHECK: @llvm.smul.with.overflow.i64(i64 4, i64 [[INC]]), !nosanitize
|
|
// CHECK-NOT: select
|
|
// CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
|
|
++p;
|
|
|
|
// CHECK: getelementptr inbounds i32, ptr {{.*}}, i64 [[IDXPROM:%.*]]
|
|
// CHECK: @llvm.smul.with.overflow.i64(i64 4, i64 [[IDXPROM]]), !nosanitize
|
|
// CHECK: select
|
|
// CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
|
|
p + k;
|
|
}
|
|
|
|
// CHECK-LABEL: define{{.*}} void @objc_id
|
|
void objc_id(id *p) {
|
|
// CHECK: add i64 {{.*}}, 8, !nosanitize
|
|
// CHECK-NOT: select
|
|
// CHECK: @__ubsan_handle_pointer_overflow{{.*}}
|
|
p++;
|
|
}
|