Roman Lebedev | 536b0ee | 2019-10-10 09:25:02 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -x c -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s |
| 2 | // RUN: %clang_cc1 -x c -fsanitize=pointer-overflow -fno-sanitize-recover=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s |
| 3 | |
| 4 | // RUN: %clang_cc1 -x c++ -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s |
| 5 | // RUN: %clang_cc1 -x c++ -fsanitize=pointer-overflow -fno-sanitize-recover=pointer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s |
| 6 | |
| 7 | #include <stdint.h> |
| 8 | |
| 9 | #ifdef __cplusplus |
| 10 | extern "C" { |
| 11 | #endif |
| 12 | |
| 13 | struct S { |
| 14 | int x, y; |
| 15 | }; |
| 16 | |
Fangrui Song | dbc96b5 | 2020-02-03 10:09:39 -0800 | [diff] [blame] | 17 | // CHECK-LABEL: define i64 @{{.*}}get_offset_of_y_naively{{.*}}( |
Roman Lebedev | 536b0ee | 2019-10-10 09:25:02 +0000 | [diff] [blame] | 18 | uintptr_t get_offset_of_y_naively() { |
| 19 | // CHECK: [[ENTRY:.*]]: |
| 20 | // CHECK-NEXT: ret i64 ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64) |
| 21 | // CHECK-NEXT: } |
| 22 | return ((uintptr_t)(&(((struct S *)0)->y))); |
| 23 | } |
| 24 | |
Fangrui Song | dbc96b5 | 2020-02-03 10:09:39 -0800 | [diff] [blame] | 25 | // CHECK-LABEL: define i64 @{{.*}}get_offset_of_y_via_builtin{{.*}}( |
Roman Lebedev | 536b0ee | 2019-10-10 09:25:02 +0000 | [diff] [blame] | 26 | uintptr_t get_offset_of_y_via_builtin() { |
| 27 | // CHECK: [[ENTRY:.*]]: |
| 28 | // CHECK-NEXT: ret i64 4 |
| 29 | // CHECK-NEXT: } |
| 30 | return __builtin_offsetof(struct S, y); |
| 31 | } |
| 32 | |
| 33 | #ifdef __cplusplus |
| 34 | } |
| 35 | #endif |