Giter Site home page Giter Site logo

software-analysis-and-testing's Introduction

Software-Analysis-and-Testing

Homework of Software-Analysis-and-Testing

软件分析测试

  • 姓名: 邵杰晶
  • 学号: MG1933046

第二次作业

  • 采用你喜欢的任意程序分析框架(如LLVM, SOOT等)

  • 构造一个无法完全转换成SSA的程序, 用所选框架转换成部分SSA

  • 提交原始代码和转换后的代码, 并说明哪些地方没有做到赋值后内存位置不变

  • 通过 Github 分享链接给助教来完成提交

  • 选用了 llvm & clang 对 c 语言程序进行 SSA 分析

原始代码

  • 文件: ssa.c
int exp() {
    int a = 3, b = 7;
    int c,d;
    int *p;

    c = a + b; //SSA

    p = &d;
    *(p+3) = a - b; 
    //*p = a + b;
    d = a + b;	// non-SSA

    return c;
}

SSA转换代码

  • 文件: ssa_mem2reg.ll
define i32 @exp() #0 {
  %d = alloca i32, align 4
  %1 = add nsw i32 3, 7
  %2 = sub nsw i32 3, 7
  %3 = getelementptr inbounds i32* %d, i64 3
  store i32 %2, i32* %3, align 4
  %4 = add nsw i32 3, 7
  store i32 %4, i32* %d, align 4
  ret i32 %1
}

说明

c = a + b 处可正常进行SSA
但在对被取过地址的d进行操作:d = a + b 时,需要通过临时变量和store来进行操作,在赋值后,该内存位置上的值仍有可能改变(通过指针)

编译相关

clang-3.5 -emit-llvm -O0 -c ssa.c -o ssa.bc
llvm-dis ssa.bc
opt -mem2reg -S ssa.ll -o ssa_mem2reg.ll

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.