llvm-mirror/test/Transforms/InstCombine/realloc.ll
David Bolvansky c32ac7b1f0 Annotate return values of allocation functions with dereferenceable_or_null
Summary:
Example
define dso_local noalias i8* @_Z6maixxnv() local_unnamed_addr #0 {
entry:
  %call = tail call noalias dereferenceable_or_null(64) i8* @malloc(i64 64) #6
  ret i8* %call
}


Reviewers: jdoerfert

Reviewed By: jdoerfert

Subscribers: aaron.ballman, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66651

llvm-svn: 370168
2019-08-28 08:28:20 +00:00

25 lines
753 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
declare i8* @realloc(i8*, i64) #1
declare noalias i8* @malloc(i64) #1
define i8* @realloc_null_ptr() #0 {
; CHECK-LABEL: @realloc_null_ptr(
; CHECK-NEXT: [[MALLOC:%.*]] = call dereferenceable_or_null(100) i8* @malloc(i64 100)
; CHECK-NEXT: ret i8* [[MALLOC]]
;
%call = call i8* @realloc(i8* null, i64 100) #2
ret i8* %call
}
define i8* @realloc_unknown_ptr(i8* %ptr) #0 {
; CHECK-LABEL: @realloc_unknown_ptr(
; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable_or_null(100) i8* @realloc(i8* [[PTR:%.*]], i64 100)
; CHECK-NEXT: ret i8* [[CALL]]
;
%call = call i8* @realloc(i8* %ptr, i64 100) #2
ret i8* %call
}