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 #include <stdint.h>
6 
7 struct S {
8   int x, y;
9 };
10 
11 // CHECK-LABEL: @_Z23get_offset_of_y_naivelyv(
12 // CHECK-NEXT:  entry:
13 // CHECK-NEXT:    ret i64 ptrtoint (i32* getelementptr inbounds ([[STRUCT_S:%.*]], %struct.S* null, i32 0, i32 1) to i64)
14 //
get_offset_of_y_naively()15 uintptr_t get_offset_of_y_naively() {
16   return ((uintptr_t)(&(((S *)nullptr)->y)));
17 }
18 
19 // CHECK-LABEL: @_Z27get_offset_of_y_via_builtinv(
20 // CHECK-NEXT:  entry:
21 // CHECK-NEXT:    ret i64 4
22 //
get_offset_of_y_via_builtin()23 uintptr_t get_offset_of_y_via_builtin() {
24   return __builtin_offsetof(S, y);
25 }
26