[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / catch-nullptr-and-nonzero-offset-in-offsetof-idiom.cpp
blob942c36cb27afbe0b6aa70d32ff1ae560e601ae1c
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
5 #include <stdint.h>
7 struct S {
8 int x, y;
9 };
11 // CHECK-LABEL: @_Z23get_offset_of_y_naivelyv(
12 // CHECK-NEXT: entry:
13 // CHECK-NEXT: ret i64 ptrtoint (ptr getelementptr inbounds ([[STRUCT_S:%.*]], ptr null, i32 0, i32 1) to i64)
15 uintptr_t get_offset_of_y_naively() {
16 return ((uintptr_t)(&(((S *)nullptr)->y)));
19 // CHECK-LABEL: @_Z27get_offset_of_y_via_builtinv(
20 // CHECK-NEXT: entry:
21 // CHECK-NEXT: ret i64 4
23 uintptr_t get_offset_of_y_via_builtin() {
24 return __builtin_offsetof(S, y);