blob: 9dc8b90b5dcb7757f4765e73c60469272962151d [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#include <stdint.h>
5
6struct S {
7 int x, y;
8};
9
Fangrui Songdbc96b52020-02-03 10:09:39 -080010// CHECK-LABEL: define i64 @{{.*}}get_offset_of_y_naively{{.*}}(
Roman Lebedev536b0ee2019-10-10 09:25:02 +000011uintptr_t get_offset_of_y_naively() {
12 // CHECK: [[ENTRY:.*]]:
13 // CHECK-NEXT: ret i64 ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64)
14 // CHECK-NEXT: }
15 return ((uintptr_t)(&(((S *)nullptr)->y)));
16}
17
Fangrui Songdbc96b52020-02-03 10:09:39 -080018// CHECK-LABEL: define i64 @{{.*}}get_offset_of_y_via_builtin{{.*}}(
Roman Lebedev536b0ee2019-10-10 09:25:02 +000019uintptr_t get_offset_of_y_via_builtin() {
20 // CHECK: [[ENTRY:.*]]:
21 // CHECK-NEXT: ret i64 4
22 // CHECK-NEXT: }
23 return __builtin_offsetof(S, y);
24}