[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / catch-alignment-assumption-attribute-alloc_align-on-function.cpp
blob60a94c1067f512fa480436de1c0ff4b35a4dfef4
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
2 // RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-NOSANITIZE
3 // 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-NORECOVER
4 // 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-RECOVER
5 // 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-TRAP
8 char **__attribute__((alloc_align(2)))
9 // CHECK-LABEL: define dso_local noundef ptr @_Z11passthroughPPcm
10 // CHECK-SAME: (ptr noundef [[X:%.*]], i64 noundef [[ALIGNMENT:%.*]]) #[[ATTR0:[0-9]+]] {
11 // CHECK-NEXT: entry:
12 // CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
13 // CHECK-NEXT: [[ALIGNMENT_ADDR:%.*]] = alloca i64, align 8
14 // CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8
15 // CHECK-NEXT: store i64 [[ALIGNMENT]], ptr [[ALIGNMENT_ADDR]], align 8
16 // CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
17 // CHECK-NEXT: ret ptr [[TMP0]]
19 passthrough(char **x, unsigned long alignment) {
20 return x;
23 // CHECK-NOSANITIZE-LABEL: define dso_local noundef ptr @_Z6callerPPc
24 // CHECK-NOSANITIZE-SAME: (ptr noundef [[X:%.*]]) #[[ATTR0]] {
25 // CHECK-NOSANITIZE-NEXT: entry:
26 // CHECK-NOSANITIZE-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
27 // CHECK-NOSANITIZE-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8
28 // CHECK-NOSANITIZE-NEXT: [[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
29 // CHECK-NOSANITIZE-NEXT: [[CALL:%.*]] = call noundef align 128 ptr @_Z11passthroughPPcm(ptr noundef [[TMP0]], i64 noundef 128)
30 // CHECK-NOSANITIZE-NEXT: ret ptr [[CALL]]
32 // CHECK-SANITIZE-NORECOVER-LABEL: define dso_local noundef ptr @_Z6callerPPc
33 // CHECK-SANITIZE-NORECOVER-SAME: (ptr noundef [[X:%.*]]) #[[ATTR0]] {
34 // CHECK-SANITIZE-NORECOVER-NEXT: entry:
35 // CHECK-SANITIZE-NORECOVER-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
36 // CHECK-SANITIZE-NORECOVER-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8
37 // CHECK-SANITIZE-NORECOVER-NEXT: [[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
38 // CHECK-SANITIZE-NORECOVER-NEXT: [[CALL:%.*]] = call noundef ptr @_Z11passthroughPPcm(ptr noundef [[TMP0]], i64 noundef 128)
39 // CHECK-SANITIZE-NORECOVER-NEXT: [[PTRINT:%.*]] = ptrtoint ptr [[CALL]] to i64
40 // CHECK-SANITIZE-NORECOVER-NEXT: [[MASKEDPTR:%.*]] = and i64 [[PTRINT]], 127
41 // CHECK-SANITIZE-NORECOVER-NEXT: [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
42 // CHECK-SANITIZE-NORECOVER-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[CALL]] to i64, !nosanitize !2
43 // CHECK-SANITIZE-NORECOVER-NEXT: br i1 [[MASKCOND]], label [[CONT:%.*]], label [[HANDLER_ALIGNMENT_ASSUMPTION:%.*]], !prof [[PROF3:![0-9]+]], !nosanitize !2
44 // CHECK-SANITIZE-NORECOVER: handler.alignment_assumption:
45 // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(ptr @[[GLOB1:[0-9]+]], i64 [[TMP1]], i64 128, i64 0) #[[ATTR3:[0-9]+]], !nosanitize !2
46 // CHECK-SANITIZE-NORECOVER-NEXT: unreachable, !nosanitize !2
47 // CHECK-SANITIZE-NORECOVER: cont:
48 // CHECK-SANITIZE-NORECOVER-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[CALL]], i64 128) ]
49 // CHECK-SANITIZE-NORECOVER-NEXT: ret ptr [[CALL]]
51 // CHECK-SANITIZE-RECOVER-LABEL: define dso_local noundef ptr @_Z6callerPPc
52 // CHECK-SANITIZE-RECOVER-SAME: (ptr noundef [[X:%.*]]) #[[ATTR0]] {
53 // CHECK-SANITIZE-RECOVER-NEXT: entry:
54 // CHECK-SANITIZE-RECOVER-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
55 // CHECK-SANITIZE-RECOVER-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8
56 // CHECK-SANITIZE-RECOVER-NEXT: [[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
57 // CHECK-SANITIZE-RECOVER-NEXT: [[CALL:%.*]] = call noundef ptr @_Z11passthroughPPcm(ptr noundef [[TMP0]], i64 noundef 128)
58 // CHECK-SANITIZE-RECOVER-NEXT: [[PTRINT:%.*]] = ptrtoint ptr [[CALL]] to i64
59 // CHECK-SANITIZE-RECOVER-NEXT: [[MASKEDPTR:%.*]] = and i64 [[PTRINT]], 127
60 // CHECK-SANITIZE-RECOVER-NEXT: [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
61 // CHECK-SANITIZE-RECOVER-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[CALL]] to i64, !nosanitize !2
62 // CHECK-SANITIZE-RECOVER-NEXT: br i1 [[MASKCOND]], label [[CONT:%.*]], label [[HANDLER_ALIGNMENT_ASSUMPTION:%.*]], !prof [[PROF3:![0-9]+]], !nosanitize !2
63 // CHECK-SANITIZE-RECOVER: handler.alignment_assumption:
64 // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(ptr @[[GLOB1:[0-9]+]], i64 [[TMP1]], i64 128, i64 0) #[[ATTR3:[0-9]+]], !nosanitize !2
65 // CHECK-SANITIZE-RECOVER-NEXT: br label [[CONT]], !nosanitize !2
66 // CHECK-SANITIZE-RECOVER: cont:
67 // CHECK-SANITIZE-RECOVER-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[CALL]], i64 128) ]
68 // CHECK-SANITIZE-RECOVER-NEXT: ret ptr [[CALL]]
70 // CHECK-SANITIZE-TRAP-LABEL: define dso_local noundef ptr @_Z6callerPPc
71 // CHECK-SANITIZE-TRAP-SAME: (ptr noundef [[X:%.*]]) #[[ATTR0]] {
72 // CHECK-SANITIZE-TRAP-NEXT: entry:
73 // CHECK-SANITIZE-TRAP-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
74 // CHECK-SANITIZE-TRAP-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8
75 // CHECK-SANITIZE-TRAP-NEXT: [[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 8
76 // CHECK-SANITIZE-TRAP-NEXT: [[CALL:%.*]] = call noundef ptr @_Z11passthroughPPcm(ptr noundef [[TMP0]], i64 noundef 128)
77 // CHECK-SANITIZE-TRAP-NEXT: [[PTRINT:%.*]] = ptrtoint ptr [[CALL]] to i64
78 // CHECK-SANITIZE-TRAP-NEXT: [[MASKEDPTR:%.*]] = and i64 [[PTRINT]], 127
79 // CHECK-SANITIZE-TRAP-NEXT: [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
80 // CHECK-SANITIZE-TRAP-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[CALL]] to i64, !nosanitize !2
81 // CHECK-SANITIZE-TRAP-NEXT: br i1 [[MASKCOND]], label [[CONT:%.*]], label [[TRAP:%.*]], !nosanitize !2
82 // CHECK-SANITIZE-TRAP: trap:
83 // CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23) #[[ATTR3:[0-9]+]], !nosanitize !2
84 // CHECK-SANITIZE-TRAP-NEXT: unreachable, !nosanitize !2
85 // CHECK-SANITIZE-TRAP: cont:
86 // CHECK-SANITIZE-TRAP-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[CALL]], i64 128) ]
87 // CHECK-SANITIZE-TRAP-NEXT: ret ptr [[CALL]]
89 char **caller(char **x) {
90 #line 100
91 return passthrough(x, 128);