Skip to content

jcaha/my_analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

my_analysis

From MG1933027-蒋承

本次实验使用LLVM生成C语言程序中间代码(IR)。原始代码如下

int a = 10;
int test(int b){
	int *p = &a;
	*p = b+1;
	return a; 
}

使用以下命令,生成LLVM IR。需要注意的是,-O1参数用来选择优化方法,生成SSA中间代码。

clang -c test.c -S -O1 -emit-llvm -o test.ll

得到的test.ll文件中间代码部分如下。

@a = local_unnamed_addr global i32 10, align 4

; Function Attrs: norecurse nounwind uwtable
define i32 @test(i32 %b) local_unnamed_addr #0 {
entry:
  %add = add nsw i32 %b, 1
  store i32 %add, i32* @a, align 4, !tbaa !2
  ret i32 %add
}

IR中test1函数内部,对变量a的内存位置上,进行了重复赋值。

@a = local_unnamed_addr global i32 10, align 4把值10赋给全局变量@a

store i32 %add, i32* @a, align 4, !tbaa !2第二次对@a进行赋值

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published