1 // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=alignment | FileCheck %s
2 
3 struct S {
4   int I;
5 };
6 
7 extern S g_S;
8 extern S array_S[];
9 
10 // CHECK-LABEL: define i32 @_Z18load_extern_global
load_extern_global()11 int 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 i32* {{.*}} to i32, !nosanitize
15   // CHECK: [[I:%.*]] = load i32, i32* getelementptr inbounds (%struct.S, %struct.S* @g_S, i32 0, i32 0), align 4
16   // CHECK-NEXT: ret i32 [[I]]
17   return g_S.I;
18 }
19 
20 // CHECK-LABEL: define i32 @_Z22load_from_extern_array
load_from_extern_array(int I)21 int load_from_extern_array(int I) {
22   // CHECK: [[I:%.*]] = getelementptr inbounds %struct.S, %struct.S* {{.*}}, i32 0, i32 0
23   // CHECK-NEXT: [[PTRTOINT:%.*]] = ptrtoint i32* [[I]] to i64, !nosanitize
24   // CHECK-NEXT: [[AND:%.*]] = and i64 [[PTRTOINT]], 3, !nosanitize
25   // CHECK-NEXT: [[ICMP:%.*]] = icmp eq i64 [[AND]], 0, !nosanitize
26   // CHECK-NEXT: br i1 [[ICMP]]
27   // CHECK: call void @__ubsan_handle_type_mismatch
28   return array_S[I].I;
29 }
30