llvm-project/clang/test/CodeGen/pointer-overflow.c
Yingwei Zheng c0480738cb
[Clang][CodeGen] Respect -fwrapv-pointer when emitting struct GEPs (#134269)
This patch turns off inbounds/nuw flags for member accesses when
`-fwrapv-pointer` is set.

Closes https://github.com/llvm/llvm-project/issues/132449.

It is required by https://github.com/llvm/llvm-project/pull/130734.
2025-04-10 00:48:18 +08:00

34 lines
1.1 KiB
C

// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s --check-prefix=DEFAULT
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fwrapv | FileCheck %s --check-prefix=DEFAULT
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv | FileCheck %s --check-prefix=DEFAULT
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fwrapv-pointer | FileCheck %s --check-prefix=FWRAPV-POINTER
void test(void) {
// -fwrapv-pointer should turn off inbounds for GEP's
extern int* P;
++P;
// DEFAULT: getelementptr inbounds nuw i32, ptr
// FWRAPV-POINTER: getelementptr i32, ptr
}
struct S {
int a;
int b;
int c: 10;
int d: 10;
};
int test_struct(struct S* s) {
// -fwrapv-pointer should turn off inbounds nuw for struct GEP's
return s->b;
// DEFAULT: getelementptr inbounds nuw %struct.S, ptr
// FWRAPV-POINTER: getelementptr %struct.S, ptr
}
int test_struct_bitfield(struct S* s) {
// -fwrapv-pointer should turn off inbounds nuw for struct GEP's
return s->d;
// DEFAULT: getelementptr inbounds nuw %struct.S, ptr
// FWRAPV-POINTER: getelementptr %struct.S, ptr
}