Skip to content

Commit

Permalink
[BasicAA] Add tests for strcat/strncat/strcpy.
Browse files Browse the repository at this point in the history
  • Loading branch information
fhahn committed Dec 2, 2021
1 parent 68782a8 commit 222442e
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions llvm/test/Analysis/BasicAA/libfuncs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,81 @@ entry:
ret i8* %res
}

declare i8* @strcat(i8*, i8*)

define i8* @test_strcat_read_write_after(i8* noalias %a, i8* noalias %b) {
; CHECK-LABEL: Function: test_strcat_read_write_after
; CHECK: Both ModRef: Ptr: i8* %a <-> %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Just Ref: Ptr: i8* %b <-> %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Both ModRef: Ptr: i8* %a.gep.1 <-> %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.1 <-> %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Both ModRef: Ptr: i8* %res <-> %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Both ModRef: Ptr: i8* %a.gep.5 <-> %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.5 <-> %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
;
entry:
store i8 0, i8* %a
store i8 2, i8* %b
%a.gep.1 = getelementptr i8, i8* %a, i32 1
%b.gep.1 = getelementptr i8, i8* %b, i32 1
%res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
%a.gep.5 = getelementptr i8, i8* %a, i32 5
store i8 1, i8* %a.gep.5
%b.gep.5 = getelementptr i8, i8* %b, i32 5
store i8 3, i8* %b.gep.5
ret i8* %res
}

declare i8* @strncat(i8*, i8*, i64)

define i8* @test_strncat_read_write_after(i8* noalias %a, i8* noalias %b, i64 %n) {
; CHECK-LABEL: Function: test_strncat_read_write_after
; CHECK: Both ModRef: Ptr: i8* %a <-> %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
; CHECK-NEXT: Just Ref: Ptr: i8* %b <-> %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
; CHECK-NEXT: Both ModRef: Ptr: i8* %a.gep.1 <-> %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.1 <-> %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
; CHECK-NEXT: Both ModRef: Ptr: i8* %res <-> %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
; CHECK-NEXT: Both ModRef: Ptr: i8* %a.gep.5 <-> %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.5 <-> %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
;
entry:
store i8 0, i8* %a
store i8 2, i8* %b
%a.gep.1 = getelementptr i8, i8* %a, i32 1
%b.gep.1 = getelementptr i8, i8* %b, i32 1
%res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
%a.gep.5 = getelementptr i8, i8* %a, i32 5
store i8 1, i8* %a.gep.5
%b.gep.5 = getelementptr i8, i8* %b, i32 5
store i8 3, i8* %b.gep.5
ret i8* %res
}

declare i8* @strcpy(i8*, i8*)

define i8* @test_strcpy_read_write_after(i8* noalias %a, i8* noalias %b) {
; CHECK-LABEL: Function: test_strcpy_read_write_after
; CHECK: Just Mod: Ptr: i8* %a <-> %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Just Ref: Ptr: i8* %b <-> %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Just Mod: Ptr: i8* %a.gep.1 <-> %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.1 <-> %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Just Mod: Ptr: i8* %res <-> %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Just Mod: Ptr: i8* %a.gep.5 <-> %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.5 <-> %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
;
entry:
store i8 0, i8* %a
store i8 2, i8* %b
%a.gep.1 = getelementptr i8, i8* %a, i32 1
%b.gep.1 = getelementptr i8, i8* %b, i32 1
%res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
%a.gep.5 = getelementptr i8, i8* %a, i32 5
store i8 1, i8* %a.gep.5
%b.gep.5 = getelementptr i8, i8* %b, i32 5
store i8 3, i8* %b.gep.5
ret i8* %res
}

declare i8* @strncpy(i8*, i8*, i64)

define i8* @test_strncpy_const_size(i8* noalias %a, i8* noalias %b) {
Expand Down

0 comments on commit 222442e

Please sign in to comment.