From 49e85cbd16a9616aec3410902f97f15971399282 Mon Sep 17 00:00:00 2001 From: jumormt Date: Mon, 5 Feb 2024 15:51:53 +1100 Subject: [PATCH] sync with SVF --- CMakeLists.txt | 15 +++++++++---- compile.sh | 8 +++++++ example.ll | 58 ++++++++++++++++++++++---------------------------- src/svf-ex.cpp | 17 ++++++--------- 4 files changed, 50 insertions(+), 48 deletions(-) create mode 100755 compile.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 548f55e..56da5d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/compile.sh b/compile.sh new file mode 100755 index 0000000..da283ec --- /dev/null +++ b/compile.sh @@ -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 diff --git a/example.ll b/example.ll index ebedec3..8c35ea6 100644 --- a/example.ll +++ b/example.ll @@ -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"} diff --git a/src/svf-ex.cpp b/src/svf-ex.cpp index 4f61fb4..6d5195e 100644 --- a/src/svf-ex.cpp +++ b/src/svf-ex.cpp @@ -36,9 +36,6 @@ using namespace llvm; using namespace std; using namespace SVF; -static llvm::cl::opt InputFilename(cl::Positional, - llvm::cl::desc(""), llvm::cl::init("-")); - /*! * An example to query alias results of two LLVM values */ @@ -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 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] " + ); + 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);