brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · e6fc95c Raw
30 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=alignment | FileCheck %s2 3struct S {4  int I;5};6 7extern S g_S;8extern S array_S[];9 10// CHECK-LABEL: define{{.*}} i32 @_Z18load_extern_global11int load_extern_global() {12  // FIXME: The IR builder constant-folds the alignment check away to 'true'13  // here, so we never call the diagnostic. This is PR32630.14  // CHECK-NOT: ptrtoint ptr {{.*}} to i32, !nosanitize15  // CHECK: [[I:%.*]] = load i32, ptr @g_S, align 416  // CHECK-NEXT: ret i32 [[I]]17  return g_S.I;18}19 20// CHECK-LABEL: define{{.*}} i32 @_Z22load_from_extern_array21int load_from_extern_array(int I) {22  // CHECK: [[I:%.*]] = getelementptr inbounds nuw %struct.S, ptr {{.*}}, i32 0, i32 023  // CHECK-NEXT: [[PTRTOINT:%.*]] = ptrtoint ptr [[I]] to i64, !nosanitize24  // CHECK-NEXT: [[AND:%.*]] = and i64 [[PTRTOINT]], 3, !nosanitize25  // CHECK-NEXT: [[ICMP:%.*]] = icmp eq i64 [[AND]], 0, !nosanitize26  // CHECK-NEXT: br i1 [[ICMP]]27  // CHECK: call void @__ubsan_handle_type_mismatch28  return array_S[I].I;29}30