blob: 09d644a859832347b7d7b75c0009aac709097b85 [file] [log] [blame]
Roman Lebedev536b0ee2019-10-10 09:25:02 +00001// 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
10extern "C" {
11#endif
12
13struct S {
14 int x, y;
15};
16
Fangrui Songdbc96b52020-02-03 10:09:39 -080017// CHECK-LABEL: define i64 @{{.*}}get_offset_of_y_naively{{.*}}(
Roman Lebedev536b0ee2019-10-10 09:25:02 +000018uintptr_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 Songdbc96b52020-02-03 10:09:39 -080025// CHECK-LABEL: define i64 @{{.*}}get_offset_of_y_via_builtin{{.*}}(
Roman Lebedev536b0ee2019-10-10 09:25:02 +000026uintptr_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