[LLVM][IR] Use splat syntax when printing ConstantExpr based splats. (#116856)
[llvm-project.git] / clang / test / CodeGen / catch-alignment-assumption-builtin_assume_aligned-polymorphism.cpp
bloba5b969d3cbc0c0e61d8ad8240f11901b6e90d8eb
1 // RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
2 // RUN: %clang_cc1 -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE
3 // RUN: %clang_cc1 -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
4 // RUN: %clang_cc1 -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE
6 // CHECK-SANITIZE-ANYRECOVER: @[[CHAR:.*]] = {{.*}} c"'B *'\00" }
7 // CHECK-SANITIZE-ANYRECOVER: @[[LINE_100_ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 100, i32 35 }, {{.*}} @[[CHAR]] }
9 struct A { int n; };
10 struct B { int n; };
11 struct C : A, B {};
13 void *f(C *c) {
14 // CHECK: define {{.*}} ptr @{{.*}}(ptr noundef %[[C:.*]]) {{.*}} {
15 // CHECK-NEXT: [[ENTRY:.*]]:
16 // CHECK-NEXT: %[[C_ADDR:.*]] = alloca ptr
17 // CHECK-NEXT: store ptr %[[C]], ptr %[[C_ADDR]]
18 // CHECK-NEXT: %[[C_RELOAD:.*]] = load ptr, ptr %[[C_ADDR]]
19 // CHECK-NEXT: %[[IS_NULL:.*]] = icmp eq ptr %[[C_RELOAD]], null
20 // CHECK-NEXT: br i1 %[[IS_NULL]], label %[[CAST_END:[^,]+]], label %[[CAST_NOT_NULL:[^,]+]]
21 // CHECK: [[CAST_NOT_NULL]]:
22 // CHECK-NOSANITIZE-NEXT: %[[ADD_PTR:.*]] = getelementptr inbounds i8, ptr %[[C_RELOAD]], i64 4
23 // CHECK-NOSANITIZE-NEXT: br label %[[CAST_END]]
24 // CHECK-SANITIZE-NEXT: %[[PTRTOINT:.*]] = ptrtoint ptr %[[C_RELOAD]] to i64, !nosanitize
25 // CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRTOINT]], 3, !nosanitize
26 // CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0, !nosanitize
27 // CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:[^,]+]], label %[[HANDLER_TYPE_MISMATCH:[^,]+]]
28 // CHECK-SANITIZE: [[HANDLER_TYPE_MISMATCH]]:
29 // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_type_mismatch_v1_abort(
30 // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_type_mismatch_v1(
31 // CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(
32 // CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize
33 // CHECK-SANITIZE: [[CONT]]:
34 // CHECK-SANITIZE-NEXT: %[[ADD_PTR:.*]] = getelementptr inbounds i8, ptr %[[C_RELOAD]], i64 4
35 // CHECK-SANITIZE-NEXT: br label %[[CAST_END]]
36 // CHECK: [[CAST_END]]:
37 // CHECK-NOSANITIZE-NEXT: %[[CAST_RESULT:.*]] = phi ptr [ %[[ADD_PTR]], %[[CAST_NOT_NULL]] ], [ null, %[[ENTRY]] ]
38 // CHECK-NOSANITIZE-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr %[[CAST_RESULT]], i64 8) ]
39 // CHECK-NOSANITIZE-NEXT: ret ptr %[[CAST_RESULT]]
40 // CHECK-NOSANITIZE-NEXT: }
41 // CHECK-SANITIZE-NEXT: %[[CAST_RESULT:.*]] = phi ptr [ %[[ADD_PTR]], %[[CONT]] ], [ null, %[[ENTRY]] ]
42 // CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint ptr %[[CAST_RESULT]] to i64
43 // CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 7
44 // CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
45 // CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint ptr %[[CAST_RESULT]] to i64, !nosanitize
46 // CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT1:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
47 // CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]:
48 // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(ptr @[[LINE_100_ALIGNMENT_ASSUMPTION]], i64 %[[PTRINT_DUP]], i64 8, i64 0){{.*}}, !nosanitize
49 // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(ptr @[[LINE_100_ALIGNMENT_ASSUMPTION]], i64 %[[PTRINT_DUP]], i64 8, i64 0){{.*}}, !nosanitize
50 // CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize
51 // CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize
52 // CHECK-SANITIZE: [[CONT1]]:
53 // CHECK-SANITIZE-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr %[[CAST_RESULT]], i64 8) ]
54 // CHECK-SANITIZE-NEXT: ret ptr %[[CAST_RESULT]]
55 // CHECK-SANITIZE-NEXT: }
56 #line 100
57 return __builtin_assume_aligned((B*)c, 8);