Last active
March 9, 2020 18:22
-
-
Save h1994st/6441548d0fec7a48f84dfe27059f973f to your computer and use it in GitHub Desktop.
Program slice on function pointers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ModuleID = 'example_2.bc' | |
source_filename = "example_2.c" | |
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | |
target triple = "x86_64-pc-linux-gnu" | |
%struct.test_type_t = type { i8*, i32, i32 (%struct.test_type_t*)* } | |
@test_instance_2 = internal global %struct.test_type_t { i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 0, i32 (%struct.test_type_t*)* @a_func }, align 8 | |
@.str = private unnamed_addr constant [36 x i8] c"after calling the function pointer\0A\00", align 1 | |
@.str.1 = private unnamed_addr constant [11 x i8] c"instance 2\00", align 1 | |
; -- Generated by llvm-slicer -- | |
; * slicing criteria: 'a_func' | |
; * secondary slicing criteria: '' | |
; * forward slice: '0' | |
; * remove slicing criteria: '0' | |
; * undefined are pure: '0' | |
; * pointer analysis: flow-sensitive | |
; * PTA field sensitivity: full | |
; Function Attrs: noinline nounwind optnone uwtable | |
define dso_local i32 @main(i32, i8**) #0 { | |
; x %3 = alloca i32, align 4 | |
; x %4 = alloca i32, align 4 | |
; x %5 = alloca i8**, align 8 | |
; x %6 = alloca %struct.test_type_t*, align 8 | |
; x store i32 0, i32* %3, align 4 | |
; x store i32 %0, i32* %4, align 4 | |
; x store i8** %1, i8*** %5, align 8 | |
; x store %struct.test_type_t* @test_instance_2, %struct.test_type_t** %6, align 8 | |
; x %7 = load %struct.test_type_t*, %struct.test_type_t** %6, align 8 | |
; x %8 = getelementptr inbounds %struct.test_type_t, %struct.test_type_t* %7, i32 0, i32 2 | |
; x %9 = load i32 (%struct.test_type_t*)*, i32 (%struct.test_type_t*)** %8, align 8 | |
; x %10 = load %struct.test_type_t*, %struct.test_type_t** %6, align 8 | |
; x %11 = call i32 %9(%struct.test_type_t* %10) | |
; x %12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i32 0, i32 0)) | |
; x ret i32 0 | |
} | |
declare dso_local i32 @printf(i8*, ...) #1 | |
; Function Attrs: noinline nounwind optnone uwtable | |
define internal i32 @a_func(%struct.test_type_t*) #0 { | |
%2 = alloca %struct.test_type_t*, align 8 | |
store %struct.test_type_t* %0, %struct.test_type_t** %2, align 8 | |
ret i32 1 | |
} | |
attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
!llvm.module.flags = !{!0} | |
!llvm.ident = !{!1} | |
!0 = !{i32 1, !"wchar_size", i32 4} | |
!1 = !{!"clang version 8.0.0-3~ubuntu18.04.2 (tags/RELEASE_800/final)"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
struct test_type_t { | |
char *type_name; | |
int type; | |
int (*func_p)(struct test_type_t *tttttttt); | |
}; | |
static int a_func(struct test_type_t *tttttttt) { | |
return 1; | |
} | |
static struct test_type_t test_instance_2 = { | |
.type_name = "instance 2", | |
.type = 0, | |
.func_p = a_func, | |
}; | |
int main(int argc, char const *argv[]) { | |
struct test_type_t *tt = &test_instance_2; | |
tt->func_p(tt); | |
printf("after calling the function pointer\n"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NODE 4: i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 ... (points-to size: 1) | |
-> @.str.1 = private unnamed_addr constant [11 x i8] c\"instance 2\00\", al ... + 0 | |
NODE 7: a_func (points-to size: 1) | |
-> a_func + 0 | |
NODE 10: <10> PSNodeType::ENTRY (points-to size: 0) | |
NODE 11: i32 %0 (points-to size: 0) | |
NODE 12: i8** %1 (points-to size: 0) | |
NODE 13: %3 = alloca i32, align 4 [size: 4, heap: 0, zeroed: 0] (points-to size: 1) | |
-> %3 = alloca i32, align 4 + 0 | |
NODE 14: %4 = alloca i32, align 4 [size: 4, heap: 0, zeroed: 0] (points-to size: 1) | |
-> %4 = alloca i32, align 4 + 0 | |
NODE 15: %5 = alloca i8**, align 8 [size: 8, heap: 0, zeroed: 0] (points-to size: 1) | |
-> %5 = alloca i8**, align 8 + 0 | |
NODE 16: %6 = alloca %struct.test_type_t*, align 8 [size: 8, heap: 0, zeroed: 0] (points-to size: 1) | |
-> %6 = alloca %struct.test_type_t*, align 8 + 0 | |
NODE 17: store i32 0, i32* %3, align 4 (points-to size: 0) | |
NODE 18: store i32 %0, i32* %4, align 4 (points-to size: 0) | |
NODE 19: store i8** %1, i8*** %5, align 8 (points-to size: 0) | |
NODE 20: store %struct.test_type_t* @test_instance_2, %struct.test_type_t** % ... (points-to size: 0) | |
NODE 21: %7 = load %struct.test_type_t*, %struct.test_type_t** %6, align 8 (points-to size: 1) | |
-> @test_instance_2 = internal global %struct.test_type_t { i8* getelemen ... + 0 | |
NODE 22: %8 = getelementptr inbounds %struct.test_type_t, %struct.test_type_t ... (points-to size: 1) | |
-> @test_instance_2 = internal global %struct.test_type_t { i8* getelemen ... + 16 | |
NODE 23: %9 = load i32 (%struct.test_type_t*)*, i32 (%struct.test_type_t*)** ... (points-to size: 1) | |
-> null + 0 | |
NODE 24: %10 = load %struct.test_type_t*, %struct.test_type_t** %6, align 8 (points-to size: 1) | |
-> @test_instance_2 = internal global %struct.test_type_t { i8* getelemen ... + 0 | |
NODE 25: %11 = call i32 %9(%struct.test_type_t* %10) (points-to size: 0) | |
NODE 26: %11 = call i32 %9(%struct.test_type_t* %10) (points-to size: 0) | |
NODE 27: %12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x ... (points-to size: 1) | |
-> unknown + Offset::UNKNOWN | |
NODE 28: ret i32 0 (points-to size: 1) | |
-> null + 0 | |
Process finished with exit code 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment