Skip to content

Commit

Permalink
Merge pull request #63 from jumormt/master
Browse files Browse the repository at this point in the history
sync with SVF
  • Loading branch information
yuleisui authored Feb 5, 2024
2 parents aa4a6c4 + 49e85cb commit 29b3978
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 48 deletions.
15 changes: 11 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
cmake_minimum_required(VERSION 3.4.3)
cmake_minimum_required(VERSION 3.23)

project(SVF-example
VERSION 1.0
DESCRIPTION "An external project example using SVF as a library"
HOMEPAGE_URL "https://github.com/SVF-tools/SVF-example"
LANGUAGES C CXX
)
if (DEFINED LLVM_DIR)
set(ENV{LLVM_DIR} "${LLVM_DIR}")
endif()
if (DEFINED ENV{LLVM_DIR})
# We need to match the build environment for LLVM:
# In particular, we need C++11 and the -fno-rtti flag
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(CMAKE_CXX_FLAGS "-fPIC -std=gnu++14 -O0 -fno-rtti -Wno-deprecated")
set(CMAKE_CXX_FLAGS "-fPIC -std=gnu++17 -O0 -fno-rtti -Wno-deprecated")
else()
set(CMAKE_CXX_FLAGS "-fPIC -std=gnu++14 -O3 -fno-rtti -Wno-deprecated")
set(CMAKE_CXX_FLAGS "-fPIC -std=gnu++17 -O3 -fno-rtti -Wno-deprecated")
endif()
set(CMAKE_C_FLAGS "-fPIC")

Expand Down
8 changes: 8 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
if [ -n $1 ]; then
file=$(basename $1 .c)
clang -S -c -Xclang -disable-O0-optnone -fno-discard-value-names -emit-llvm $1 -o $file.ll
opt -S -p=mem2reg $file.ll -o $file.ll
else
echo "please give the .c file"
fi
58 changes: 25 additions & 33 deletions example.ll
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
; ModuleID = 'swap.ll'
source_filename = "swap.c"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"
; ModuleID = 'example.ll'
source_filename = "example.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: noinline nounwind optnone ssp uwtable
define void @swap(i8** %p, i8** %q) #0 {
; Function Attrs: noinline nounwind uwtable
define dso_local void @swap(ptr noundef %p, ptr noundef %q) #0 {
entry:
%p.addr = alloca i8**, align 8
%q.addr = alloca i8**, align 8
%t = alloca i8*, align 8
store i8** %p, i8*** %p.addr, align 8
store i8** %q, i8*** %q.addr, align 8
%0 = load i8**, i8*** %p.addr, align 8
%1 = load i8*, i8** %0, align 8
store i8* %1, i8** %t, align 8
%2 = load i8**, i8*** %q.addr, align 8
%3 = load i8*, i8** %2, align 8
%4 = load i8**, i8*** %p.addr, align 8
store i8* %3, i8** %4, align 8
%5 = load i8*, i8** %t, align 8
%6 = load i8**, i8*** %q.addr, align 8
store i8* %5, i8** %6, align 8
%0 = load ptr, ptr %p, align 8
%1 = load ptr, ptr %q, align 8
store ptr %1, ptr %p, align 8
store ptr %0, ptr %q, align 8
ret void
}

; Function Attrs: noinline nounwind optnone ssp uwtable
define i32 @main() #0 {
; Function Attrs: noinline nounwind uwtable
define dso_local i32 @main() #0 {
entry:
%a1 = alloca i8, align 1
%b1 = alloca i8, align 1
%a = alloca i8*, align 8
%b = alloca i8*, align 8
store i8* %a1, i8** %a, align 8
store i8* %b1, i8** %b, align 8
call void @swap(i8** %a, i8** %b)
%a = alloca ptr, align 8
%b = alloca ptr, align 8
store ptr %a1, ptr %a, align 8
store ptr %b1, ptr %b, align 8
call void @swap(ptr noundef %a, ptr noundef %b)
ret i32 0
}

attributes #0 = { noinline nounwind optnone ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "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"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.ident = !{!5}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{!"clang version 10.0.0 "}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{i32 7, !"frame-pointer", i32 2}
!5 = !{!"clang version 16.0.0"}
17 changes: 6 additions & 11 deletions src/svf-ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ using namespace llvm;
using namespace std;
using namespace SVF;

static llvm::cl::opt<std::string> InputFilename(cl::Positional,
llvm::cl::desc("<input bitcode>"), llvm::cl::init("-"));

/*!
* An example to query alias results of two LLVM values
*/
Expand Down Expand Up @@ -152,19 +149,17 @@ void traverseOnVFG(const SVFG* vfg, Value* val)
int main(int argc, char ** argv)
{

int arg_num = 0;
char **arg_value = new char*[argc];
std::vector<std::string> moduleNameVec;
LLVMUtil::processArguments(argc, argv, arg_num, arg_value, moduleNameVec);
cl::ParseCommandLineOptions(arg_num, arg_value,
"Whole Program Points-to Analysis\n");
moduleNameVec = OptionBase::parseOptions(
argc, argv, "Whole Program Points-to Analysis", "[options] <input-bitcode...>"
);

if (Options::WriteAnder() == "ir_annotator")
{
LLVMModuleSet::getLLVMModuleSet()->preProcessBCs(moduleNameVec);
LLVMModuleSet::preProcessBCs(moduleNameVec);
}

SVFModule* svfModule = LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec);
SVFModule* svfModule = LLVMModuleSet::buildSVFModule(moduleNameVec);

/// Build Program Assignment Graph (SVFIR)
SVFIRBuilder builder(svfModule);
Expand Down

0 comments on commit 29b3978

Please sign in to comment.