| 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 |
| 4 |
|
| 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 |
| 7 |
|
| 8 |
#include <stdint.h> |
| 9 |
|
| 10 |
#ifdef __cplusplus |
| 11 |
extern "C" { |
| 12 |
#endif |
| 13 |
|
| 14 |
struct S { |
| 15 |
int x, y; |
| 16 |
}; |
| 17 |
|
| 18 |
// CHECK-LABEL: @get_offset_of_y_naively( |
| 19 |
// CHECK-NEXT: entry: |
| 20 |
// CHECK-NEXT: ret i64 ptrtoint (ptr getelementptr ([[STRUCT_S:%.*]], ptr null, i32 0, i32 1) to i64) |
| 21 |
// |
| 22 |
uintptr_t get_offset_of_y_naively(void) { |
| 23 |
return ((uintptr_t)(&(((struct S *)0)->y))); |
| 24 |
} |
| 25 |
|
| 26 |
// CHECK-LABEL: @get_offset_of_y_via_builtin( |
| 27 |
// CHECK-NEXT: entry: |
| 28 |
// CHECK-NEXT: ret i64 4 |
| 29 |
// |
| 30 |
uintptr_t get_offset_of_y_via_builtin(void) { |
| 31 |
return __builtin_offsetof(struct S, y); |
| 32 |
} |
| 33 |
|
| 34 |
#ifdef __cplusplus |
| 35 |
} |
| 36 |
#endif |