forked from banach-space/llvm-tutor
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinject_func_call.ll
61 lines (49 loc) · 1.82 KB
/
inject_func_call.ll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
; RUN: opt --enable-new-pm=0 -load %shlibdir/libInjectFuncCall%shlibext -verify -legacy-inject-func-call -S %s\
; RUN: | FileCheck %s
; RUN: opt -load-pass-plugin=%shlibdir/libInjectFuncCall%shlibext -passes="inject-func-call,verify" -S %s\
; RUN: | FileCheck %s
; Verify that InjectFuncCall indeed inserts calls to printf and global
; variables that contain functions names (these are needed for the calls to printf).
; The format string
; CHECK: @PrintfFormatStr = global [68 x i8] c"(llvm-tutor) Hello from: %s\0A(llvm-tutor) number of arguments: %d\0A\00"
; The function names
; CHECK-NEXT: @0 = private unnamed_addr constant [4 x i8] c"foo\00", align 1
; CHECK-NEXT: @1 = private unnamed_addr constant [4 x i8] c"bar\00", align 1
; CHECK-NEXT: @2 = private unnamed_addr constant [4 x i8] c"baz\00", align 1
; CHECK-NEXT: @3 = private unnamed_addr constant [4 x i8] c"bez\00", align 1
; CHECK-LABEL: @foo
; CHECK-NEXT: %2 = call i32 (ptr, ...) @printf
; CHECK-LABEL: @bar
; CHECK-NEXT: %3 = call i32 (ptr, ...) @printf
; CHECK-LABEL: @baz
; CHECK-NEXT: %4 = call i32 (ptr, ...) @printf
; CHECK-LABEL: @bez
; CHECK-NEXT: %2 = call i32 (ptr, ...) @printf
; CHECK: declare i32 @printf(ptr nocapture readonly, ...) #0
; CHECK: attributes #0 = { nounwind }
define i32 @foo(i32) {
%2 = shl nsw i32 %0, 1
ret i32 %2
}
define i32 @bar(i32, i32) {
%3 = tail call i32 @foo(i32 %1)
%4 = shl i32 %3, 1
%5 = add nsw i32 %4, %0
ret i32 %5
}
define i32 @baz(i32, i32, i32) {
%4 = tail call i32 @bar(i32 %0, i32 %1)
%5 = shl i32 %4, 1
%6 = mul nsw i32 %2, 3
%7 = add i32 %6, %0
%8 = add i32 %7, %5
ret i32 %8
}
define i32 @bez(i32) {
%2 = tail call i32 @foo(i32 %0)
%3 = tail call i32 @bar(i32 %0, i32 %2)
%4 = add nsw i32 %3, %2
%5 = tail call i32 @baz(i32 %0, i32 %4, i32 123)
%6 = add nsw i32 %4, %5
ret i32 %6
}