Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang formatter and a workflow for checking #1530

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ BasedOnStyle: Microsoft
PointerAlignment: Left
IndentPPDirectives: AfterHash
AllowShortFunctionsOnASingleLine: Empty
ColumnLimit: 80
ColumnLimit: 120
AccessModifierOffset: -4
AllowShortIfStatementsOnASingleLine: Always
AllowShortLoopsOnASingleLine: true
AllowShortBlocksOnASingleLine: false
BreakBeforeTernaryOperators: true
SortIncludes: false
Empty file added .clang-format-ignore
Empty file.
16 changes: 16 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: clang-format

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: DoozyX/[email protected]
with:
source: '.'
exclude: './cmake'
extensions: 'c,h,hh,cpp,hpp,cc'
clangFormatVersion: 17
style: file
5 changes: 1 addition & 4 deletions .github/workflows/svf-lib_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
if: runner.os == 'macOS'
run: |
ln -sfn /Applications/Xcode_${{ env.XCODE_VERSION }}.app /Applications/Xcode.app
brew install astyle
- name: ubuntu-setup
if: runner.os == 'Linux'
run: |
Expand All @@ -42,7 +41,6 @@ jobs:
sudo apt-get update
sudo apt-get install cmake gcc g++ nodejs doxygen graphviz libncurses5-dev libtinfo5 libzstd-dev
sudo apt-get update
sudo apt-get install -y astyle
- name: env-setup
if: github.event_name == 'push' && github.repository == 'SVF-tools/SVF'
run: |
Expand All @@ -56,8 +54,7 @@ jobs:
cd $GITHUB_WORKSPACE
echo $(pwd)
git pull
astyle --style=allman -n -r "*.h" "*.cpp"
if [ ! -z $FILES_CHANGED ]; then clang-format -i $FILES_CHANGED; fi
source ${{github.workspace}}/clang-format.sh
git clone "https://github.com/SVF-tools/Test-Suite.git";
source ${{github.workspace}}/build.sh

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ autoconf/
tests/result/
doxygen/
.*
!.github/
!.clang-format-ignore
!.config.in
!.config.cmake.in
!.gitignore
Expand Down
1 change: 1 addition & 0 deletions clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git ls-tree --full-tree --name-only -r HEAD | grep -e ".*\.\(c\|h\|hpp\|cc\|cpp\|hh\)\$" | grep -vf .clang-format-ignore | xargs clang-format -i -style=file --verbose
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this line to svf-lib.publish.yml and remove this file

18 changes: 9 additions & 9 deletions svf-llvm/include/SVF-LLVM/BasicTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include <llvm/Pass.h>

#include <llvm/IR/Instructions.h>
#include <llvm/IR/GetElementPtrTypeIterator.h> //for gep iterator
#include <llvm/IR/GlobalVariable.h> // for GlobalVariable
#include <llvm/IR/GetElementPtrTypeIterator.h> //for gep iterator
#include <llvm/IR/GlobalVariable.h> // for GlobalVariable
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/IntrinsicInst.h>
#include <llvm/IR/LLVMContext.h>
Expand All @@ -53,11 +53,11 @@

#include <llvm/Support/SourceMgr.h>

#include <llvm/Bitcode/BitcodeWriter.h> // for WriteBitcodeToFile
#include <llvm/Bitcode/BitcodeReader.h> /// for isBitcode
#include <llvm/IRReader/IRReader.h> // IR reader for bit file
#include <llvm/IR/InstVisitor.h> // for instruction visitor
#include <llvm/IR/InstIterator.h> // for inst iteration
#include <llvm/Bitcode/BitcodeWriter.h> // for WriteBitcodeToFile
#include <llvm/Bitcode/BitcodeReader.h> /// for isBitcode
#include <llvm/IRReader/IRReader.h> // IR reader for bit file
#include <llvm/IR/InstVisitor.h> // for instruction visitor
#include <llvm/IR/InstIterator.h> // for inst iteration

#include <llvm/BinaryFormat/Dwarf.h> // for dwarf tags

Expand Down Expand Up @@ -157,7 +157,7 @@ typedef llvm::CallBrInst CallBrInst;
typedef llvm::ReturnInst ReturnInst;
typedef llvm::CastInst CastInst;
typedef llvm::CmpInst CmpInst;
typedef llvm::ExtractValueInst ExtractValueInst;
typedef llvm::ExtractValueInst ExtractValueInst;
typedef llvm::ExtractElementInst ExtractElementInst;
typedef llvm::GetElementPtrInst GetElementPtrInst;
typedef llvm::InvokeInst InvokeInst;
Expand Down Expand Up @@ -277,4 +277,4 @@ typedef llvm::succ_const_iterator succ_const_iterator;
#endif
} // End namespace SVF

#endif // SVF_FE_BASIC_TYPES_H
#endif // SVF_FE_BASIC_TYPES_H
11 changes: 4 additions & 7 deletions svf-llvm/include/SVF-LLVM/BreakConstantExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ class BreakConstantGEPs : public ModulePass
{
return "Remove Constant GEP Expressions";
}
virtual bool runOnModule (Module & M);
virtual bool runOnModule(Module& M);
};


//
// Pass: MergeFunctionRets
//
Expand All @@ -65,19 +64,17 @@ class MergeFunctionRets : public ModulePass
{
return "unify function exit into one dummy exit basic block";
}
virtual bool runOnModule (Module & M)
virtual bool runOnModule(Module& M)
{
UnifyFunctionExit(M);
return true;
}
inline void UnifyFunctionExit(Module& module)
{
for (Module::const_iterator iter = module.begin(), eiter = module.end();
iter != eiter; ++iter)
for (Module::const_iterator iter = module.begin(), eiter = module.end(); iter != eiter; ++iter)
{
const Function& fun = *iter;
if(fun.isDeclaration())
continue;
if (fun.isDeclaration()) continue;
getUnifyExit(fun)->runOnFunction(const_cast<Function&>(fun));
}
}
Expand Down
16 changes: 6 additions & 10 deletions svf-llvm/include/SVF-LLVM/CHGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,27 @@ class CHGBuilder
typedef CHGraph::CHNodeSetTy CHNodeSetTy;
typedef CHGraph::WorkList WorkList;

CHGBuilder(CHGraph* c): chg(c)
{

}
CHGBuilder(CHGraph* c) : chg(c) {}
void buildCHG();
void buildCHGNodes(const GlobalValue *V);
void buildCHGNodes(const GlobalValue* V);
void buildCHGNodes(const Function* F);
void buildCHGEdges(const Function* F);
void buildInternalMaps();
void readInheritanceMetadataFromModule(const Module &M);
void readInheritanceMetadataFromModule(const Module& M);

CHNode *createNode(const std::string& name);
CHNode* createNode(const std::string& name);

void connectInheritEdgeViaCall(const Function* caller, const CallBase* cs);
void connectInheritEdgeViaStore(const Function* caller, const StoreInst* store);

void buildClassNameToAncestorsDescendantsMap();
const CHGraph::CHNodeSetTy& getInstancesAndDescendants(const std::string& className);

void analyzeVTables(const Module &M);
void analyzeVTables(const Module& M);
void buildVirtualFunctionToIDMap();
void buildCSToCHAVtblsAndVfnsMap();
const CHNodeSetTy& getCSClasses(const CallBase* cs);
void addFuncToFuncVector(CHNode::FuncVector &v, const Function *f);
void addFuncToFuncVector(CHNode::FuncVector& v, const Function* f);
};

} // End namespace SVF

22 changes: 9 additions & 13 deletions svf-llvm/include/SVF-LLVM/CppUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ struct DemangledName

struct DemangledName demangle(const std::string& name);


Set<std::string> getClsNamesInBrackets(const std::string& name);

std::string getBeforeBrackets(const std::string& name);
Expand All @@ -80,7 +79,7 @@ std::string getClassNameFromVtblObj(const std::string& vtblName);
*
* See https://github.com/SVF-tools/SVF/issues/1114 for more.
*/
const ConstantStruct *getVtblStruct(const GlobalValue *vtbl);
const ConstantStruct* getVtblStruct(const GlobalValue* vtbl);

bool isValVtbl(const Value* val);
bool isVirtualCallSite(const CallBase* cs);
Expand Down Expand Up @@ -129,34 +128,31 @@ bool VCallInCtorOrDtor(const CallBase* cs);
* }
* this and this1 are the same thisPtr in the constructor
*/
bool isSameThisPtrInConstructor(const Argument* thisPtr1,
const Value* thisPtr2);
bool isSameThisPtrInConstructor(const Argument* thisPtr1, const Value* thisPtr2);

/// extract class name from the c++ function name, e.g., constructor/destructors
Set<std::string> extractClsNamesFromFunc(const Function *foo);
Set<std::string> extractClsNamesFromFunc(const Function* foo);

/// extract class names from template functions
Set<std::string> extractClsNamesFromTemplate(const std::string &oname);
Set<std::string> extractClsNamesFromTemplate(const std::string& oname);

/// class sources can be heap allocation
/// or functions where we can extract the class name (constructors/destructors or template functions)
bool isClsNameSource(const Value *val);
bool isClsNameSource(const Value* val);

/// whether foo matches the mangler label
bool matchesLabel(const std::string &foo, const std::string &label);
bool matchesLabel(const std::string& foo, const std::string& label);

/// whether foo is a cpp template function
bool isTemplateFunc(const Function *foo);
bool isTemplateFunc(const Function* foo);

/// whether foo is a cpp dyncast function
bool isDynCast(const Function *foo);
bool isDynCast(const Function* foo);

/// extract class name from cpp dyncast function
std::string extractClsNameFromDynCast(const CallBase* callBase);

const Type *cppClsNameToType(const std::string &className);


const Type* cppClsNameToType(const std::string& className);

/// Constants pertaining to CTir, for C and C++.
/// TODO: move helper functions here too?
Expand Down
Loading
Loading