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 #include <stdint.h> 5 6 struct S { 7 int x, y; 8 }; 9 10 // CHECK-LABEL: define{{.*}} i64 @{{.*}}get_offset_of_y_naively{{.*}}( 11 uintptr_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 18 // CHECK-LABEL: define{{.*}} i64 @{{.*}}get_offset_of_y_via_builtin{{.*}}( 19 uintptr_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 } 25