Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / catch-nullptr-and-nonzero-offset-in-offsetof-idiom.c
blob68c0ee3a3a88525ee065b6955ccd9f78ba352f81
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2 // RUN: %clang_cc1 -x c -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
3 // RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fno-sanitize-recover=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
5 // RUN: %clang_cc1 -x c++ -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
6 // RUN: %clang_cc1 -x c++ -fsanitize=pointer-overflow -fno-sanitize-recover=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
8 #include <stdint.h>
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
14 struct S {
15 int x, y;
18 // CHECK-LABEL: @get_offset_of_y_naively(
19 // CHECK-NEXT: entry:
20 // CHECK-NEXT: ret i64 ptrtoint (ptr getelementptr inbounds nuw ([[STRUCT_S:%.*]], ptr null, i32 0, i32 1) to i64)
22 uintptr_t get_offset_of_y_naively(void) {
23 return ((uintptr_t)(&(((struct S *)0)->y)));
26 // CHECK-LABEL: @get_offset_of_y_via_builtin(
27 // CHECK-NEXT: entry:
28 // CHECK-NEXT: ret i64 4
30 uintptr_t get_offset_of_y_via_builtin(void) {
31 return __builtin_offsetof(struct S, y);
34 #ifdef __cplusplus
36 #endif