| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --version 6 |
| ; RUN: opt < %s -passes=function-attrs -S | FileCheck %s |
| |
| define void @_Z4foo1Pi(ptr nocapture readnone %a) local_unnamed_addr #0 { |
| ; CHECK: Function Attrs: uwtable |
| ; CHECK-LABEL: define void @_Z4foo1Pi( |
| ; CHECK-SAME: ptr readnone captures(none) [[A:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: tail call void @_Z3extv() |
| ; CHECK-NEXT: ret void |
| ; |
| entry: |
| tail call void @_Z3extv() |
| ret void |
| } |
| |
| declare void @_Z3extv() local_unnamed_addr |
| |
| define void @_Z4foo2Pi(ptr nocapture %a) local_unnamed_addr #1 { |
| ; CHECK: Function Attrs: nounwind uwtable |
| ; CHECK-LABEL: define void @_Z4foo2Pi( |
| ; CHECK-SAME: ptr captures(none) [[A:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: tail call void @free(ptr [[A]]) #[[ATTR2:[0-9]+]] |
| ; CHECK-NEXT: ret void |
| ; |
| entry: |
| tail call void @free(ptr %a) #2 |
| ret void |
| } |
| |
| declare void @free(ptr nocapture) local_unnamed_addr #2 |
| |
| define i32 @_Z4foo3Pi(ptr nocapture readonly %a) local_unnamed_addr #3 { |
| ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable |
| ; CHECK-LABEL: define i32 @_Z4foo3Pi( |
| ; CHECK-SAME: ptr readonly captures(none) [[A:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[A]], align 4 |
| ; CHECK-NEXT: ret i32 [[TMP0]] |
| ; |
| entry: |
| %0 = load i32, ptr %a, align 4 |
| ret i32 %0 |
| } |
| |
| define double @_Z4foo4Pd(ptr nocapture readonly %a) local_unnamed_addr #1 { |
| ; CHECK: Function Attrs: nounwind uwtable |
| ; CHECK-LABEL: define double @_Z4foo4Pd( |
| ; CHECK-SAME: ptr readonly captures(none) [[A:%.*]]) local_unnamed_addr #[[ATTR1]] { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: [[TMP0:%.*]] = load double, ptr [[A]], align 8 |
| ; CHECK-NEXT: [[CALL:%.*]] = tail call double @cos(double [[TMP0]]) #[[ATTR2]] |
| ; CHECK-NEXT: ret double [[CALL]] |
| ; |
| entry: |
| %0 = load double, ptr %a, align 8 |
| %call = tail call double @cos(double %0) #2 |
| ret double %call |
| } |
| |
| declare double @cos(double) local_unnamed_addr #2 |
| |
| define noalias ptr @_Z4foo5Pm(ptr nocapture readonly %a) local_unnamed_addr #1 { |
| ; CHECK: Function Attrs: nounwind uwtable |
| ; CHECK-LABEL: define noalias ptr @_Z4foo5Pm( |
| ; CHECK-SAME: ptr readonly captures(none) [[A:%.*]]) local_unnamed_addr #[[ATTR1]] { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[A]], align 8 |
| ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias ptr @malloc(i64 [[TMP0]]) #[[ATTR2]] |
| ; CHECK-NEXT: ret ptr [[CALL]] |
| ; |
| entry: |
| %0 = load i64, ptr %a, align 8 |
| %call = tail call noalias ptr @malloc(i64 %0) #2 |
| ret ptr %call |
| } |
| |
| declare noalias ptr @malloc(i64) local_unnamed_addr #2 |
| |
| define noalias ptr @_Z4foo6Pm(ptr nocapture %a) local_unnamed_addr #1 { |
| ; CHECK: Function Attrs: nounwind uwtable |
| ; CHECK-LABEL: define noalias ptr @_Z4foo6Pm( |
| ; CHECK-SAME: ptr captures(none) [[A:%.*]]) local_unnamed_addr #[[ATTR1]] { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[A]], align 8 |
| ; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @realloc(ptr [[A]], i64 [[TMP0]]) #[[ATTR2]] |
| ; CHECK-NEXT: ret ptr [[CALL]] |
| ; |
| entry: |
| %0 = load i64, ptr %a, align 8 |
| %call = tail call ptr @realloc(ptr %a, i64 %0) #2 |
| ret ptr %call |
| } |
| |
| declare noalias ptr @realloc(ptr nocapture, i64) local_unnamed_addr #2 |
| |
| define void @_Z4foo7Pi(ptr %a) local_unnamed_addr #1 { |
| ; CHECK: Function Attrs: nounwind uwtable |
| ; CHECK-LABEL: define void @_Z4foo7Pi( |
| ; CHECK-SAME: ptr [[A:%.*]]) local_unnamed_addr #[[ATTR1]] { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq ptr [[A]], null |
| ; CHECK-NEXT: br i1 [[ISNULL]], label %[[DELETE_END:.*]], label %[[DELETE_NOTNULL:.*]] |
| ; CHECK: [[DELETE_NOTNULL]]: |
| ; CHECK-NEXT: tail call void @_ZdlPv(ptr [[A]]) #[[ATTR8:[0-9]+]] |
| ; CHECK-NEXT: br label %[[DELETE_END]] |
| ; CHECK: [[DELETE_END]]: |
| ; CHECK-NEXT: ret void |
| ; |
| entry: |
| %isnull = icmp eq ptr %a, null |
| br i1 %isnull, label %delete.end, label %delete.notnull |
| |
| delete.notnull: ; preds = %entry |
| tail call void @_ZdlPv(ptr %a) #5 |
| br label %delete.end |
| |
| delete.end: ; preds = %delete.notnull, %entry |
| ret void |
| } |
| |
| declare void @_ZdlPv(ptr) local_unnamed_addr #4 |
| |
| define void @_Z4foo8Pi(ptr %a) local_unnamed_addr #1 { |
| ; CHECK: Function Attrs: nounwind uwtable |
| ; CHECK-LABEL: define void @_Z4foo8Pi( |
| ; CHECK-SAME: ptr [[A:%.*]]) local_unnamed_addr #[[ATTR1]] { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq ptr [[A]], null |
| ; CHECK-NEXT: br i1 [[ISNULL]], label %[[DELETE_END:.*]], label %[[DELETE_NOTNULL:.*]] |
| ; CHECK: [[DELETE_NOTNULL]]: |
| ; CHECK-NEXT: tail call void @_ZdaPv(ptr [[A]]) #[[ATTR8]] |
| ; CHECK-NEXT: br label %[[DELETE_END]] |
| ; CHECK: [[DELETE_END]]: |
| ; CHECK-NEXT: ret void |
| ; |
| entry: |
| %isnull = icmp eq ptr %a, null |
| br i1 %isnull, label %delete.end, label %delete.notnull |
| |
| delete.notnull: ; preds = %entry |
| tail call void @_ZdaPv(ptr %a) #5 |
| br label %delete.end |
| |
| delete.end: ; preds = %delete.notnull, %entry |
| ret void |
| } |
| |
| declare void @may_free() |
| |
| define void @nofree_callsite_attr(ptr %a) { |
| ; CHECK: Function Attrs: nofree |
| ; CHECK-LABEL: define void @nofree_callsite_attr( |
| ; CHECK-SAME: ptr nofree readnone captures(none) [[A:%.*]]) #[[ATTR5:[0-9]+]] { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: call void @may_free() #[[ATTR5]] |
| ; CHECK-NEXT: ret void |
| ; |
| entry: |
| call void @may_free() nofree |
| ret void |
| } |
| |
| define void @unknown_call(ptr %fn) { |
| ; CHECK-LABEL: define void @unknown_call( |
| ; CHECK-SAME: ptr nofree readonly captures(none) [[FN:%.*]]) { |
| ; CHECK-NEXT: call void [[FN]]() |
| ; CHECK-NEXT: ret void |
| ; |
| call void %fn() |
| ret void |
| } |
| |
| define void @unknown_nofree_call(ptr %fn) { |
| ; CHECK: Function Attrs: nofree |
| ; CHECK-LABEL: define void @unknown_nofree_call( |
| ; CHECK-SAME: ptr nofree readonly captures(none) [[FN:%.*]]) #[[ATTR5]] { |
| ; CHECK-NEXT: call void [[FN]]() #[[ATTR5]] |
| ; CHECK-NEXT: ret void |
| ; |
| call void %fn() nofree |
| ret void |
| } |
| |
| define void @passed_to_nofree_nocapture_arg(ptr %p) { |
| ; CHECK-LABEL: define void @passed_to_nofree_nocapture_arg( |
| ; CHECK-SAME: ptr nofree captures(address) [[P:%.*]]) { |
| ; CHECK-NEXT: call void @takes_ptr(ptr nofree captures(address) [[P]]) |
| ; CHECK-NEXT: call void @may_free() |
| ; CHECK-NEXT: ret void |
| ; |
| call void @takes_ptr(ptr nofree captures(address) %p) |
| call void @may_free() |
| ret void |
| } |
| |
| ; While takes_ptr can't free %p itself, it may capture it, and then be |
| ; freed by the call to may_free. |
| define void @passed_to_nofree_maybe_capture_arg(ptr %p) { |
| ; CHECK-LABEL: define void @passed_to_nofree_maybe_capture_arg( |
| ; CHECK-SAME: ptr [[P:%.*]]) { |
| ; CHECK-NEXT: call void @takes_ptr(ptr nofree [[P]]) |
| ; CHECK-NEXT: call void @may_free() |
| ; CHECK-NEXT: ret void |
| ; |
| call void @takes_ptr(ptr nofree %p) |
| call void @may_free() |
| ret void |
| } |
| |
| ; readonly implies nofree |
| define void @passed_to_readonly_nocapture_arg(ptr %p) { |
| ; CHECK-LABEL: define void @passed_to_readonly_nocapture_arg( |
| ; CHECK-SAME: ptr nofree readonly captures(address, read_provenance) [[P:%.*]]) { |
| ; CHECK-NEXT: call void @takes_ptr(ptr readonly captures(address, read_provenance) [[P]]) |
| ; CHECK-NEXT: call void @may_free() |
| ; CHECK-NEXT: ret void |
| ; |
| call void @takes_ptr(ptr readonly captures(address, read_provenance) %p) |
| call void @may_free() |
| ret void |
| } |
| |
| define void @passed_to_nofree_fn_nocapture_arg(ptr %p) { |
| ; CHECK-LABEL: define void @passed_to_nofree_fn_nocapture_arg( |
| ; CHECK-SAME: ptr nofree captures(address) [[P:%.*]]) { |
| ; CHECK-NEXT: call void @takes_ptr(ptr captures(address) [[P]]) #[[ATTR5]] |
| ; CHECK-NEXT: call void @may_free() |
| ; CHECK-NEXT: ret void |
| ; |
| call void @takes_ptr(ptr captures(address) %p) nofree |
| call void @may_free() |
| ret void |
| } |
| |
| ; While takes_ptr can't free %p itself, it may capture it, and then be |
| ; freed by the call to may_free. |
| define void @passed_to_nofree_fn_maybe_capture_arg(ptr %p) { |
| ; CHECK-LABEL: define void @passed_to_nofree_fn_maybe_capture_arg( |
| ; CHECK-SAME: ptr [[P:%.*]]) { |
| ; CHECK-NEXT: call void @takes_ptr(ptr [[P]]) #[[ATTR5]] |
| ; CHECK-NEXT: call void @may_free() |
| ; CHECK-NEXT: ret void |
| ; |
| call void @takes_ptr(ptr %p) nofree |
| call void @may_free() |
| ret void |
| } |
| |
| ; memory(read) implies nofree |
| define void @passed_to_readonly_fn_nocapture_arg(ptr %p) { |
| ; CHECK-LABEL: define void @passed_to_readonly_fn_nocapture_arg( |
| ; CHECK-SAME: ptr nofree readonly captures(address) [[P:%.*]]) { |
| ; CHECK-NEXT: call void @takes_ptr(ptr captures(address, read_provenance) [[P]]) #[[ATTR9:[0-9]+]] |
| ; CHECK-NEXT: call void @may_free() |
| ; CHECK-NEXT: ret void |
| ; |
| call void @takes_ptr(ptr captures(address, read_provenance) %p) memory(read) |
| call void @may_free() |
| ret void |
| } |
| |
| define void @passed_to_assume_bundle(ptr %p) { |
| ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(inaccessiblemem: write) |
| ; CHECK-LABEL: define void @passed_to_assume_bundle( |
| ; CHECK-SAME: ptr nofree readnone captures(none) [[P:%.*]]) #[[ATTR6:[0-9]+]] { |
| ; CHECK-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[P]]) ] |
| ; CHECK-NEXT: ret void |
| ; |
| call void @llvm.assume(i1 true) ["nonnull"(ptr %p)] |
| ret void |
| } |
| |
| ; deopt bundle can't free or capture. |
| define void @passed_to_deopt_bundle(ptr %p) { |
| ; CHECK-LABEL: define void @passed_to_deopt_bundle( |
| ; CHECK-SAME: ptr nofree readonly captures(none) [[P:%.*]]) { |
| ; CHECK-NEXT: call void @may_free() [ "deopt"(ptr [[P]]) ] |
| ; CHECK-NEXT: call void @may_free() |
| ; CHECK-NEXT: ret void |
| ; |
| call void @may_free() ["deopt"(ptr %p)] |
| call void @may_free() |
| ret void |
| } |
| |
| ; Unknown bundle can't free, but may capture, resulting in a subsequent free. |
| define void @passed_to_unknown_bundle(ptr %p) { |
| ; CHECK-LABEL: define void @passed_to_unknown_bundle( |
| ; CHECK-SAME: ptr [[P:%.*]]) { |
| ; CHECK-NEXT: call void @may_free() [ "unknown"(ptr [[P]]) ] |
| ; CHECK-NEXT: call void @may_free() |
| ; CHECK-NEXT: ret void |
| ; |
| call void @may_free() ["unknown"(ptr %p)] |
| call void @may_free() |
| ret void |
| } |
| |
| declare void @takes_ptr(ptr) |
| |
| declare void @_ZdaPv(ptr) local_unnamed_addr #4 |
| |
| attributes #0 = { uwtable } |
| attributes #1 = { nounwind uwtable } |
| attributes #2 = { nounwind } |
| attributes #3 = { norecurse nounwind readonly uwtable } |
| attributes #4 = { nobuiltin nounwind } |
| attributes #5 = { builtin nounwind } |