-
Notifications
You must be signed in to change notification settings - Fork 5
One clang pass #488
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
One clang pass #488
Changes from 1 commit
2efa47e
50d8d78
67e3aae
f72b851
1cc0bf6
70a9804
2ed898d
7443b1c
fcc0b99
08e04fa
889a9bd
f56b017
15ca7d2
4a5766e
123129b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -351,18 +351,25 @@ bool _3CInterface::addVariables() { | |
|
|
||
| std::lock_guard<std::mutex> Lock(InterfaceMutex); | ||
|
|
||
| // first step, so load the ASTs | ||
| ClangTool &Tool = getGlobalClangTool(); | ||
| Tool.buildASTs(ASTs); | ||
|
|
||
| // 1a. Add Variables. | ||
| std::unique_ptr<ToolAction> AdderTool = newFrontendActionFactoryA< | ||
| GenericAction<VariableAdderConsumer, ProgramInfo>>(GlobalProgramInfo); | ||
| VariableAdderConsumer VA = VariableAdderConsumer(GlobalProgramInfo, nullptr); | ||
| for (auto &TU : ASTs) { | ||
| VA.HandleTranslationUnit(TU->getASTContext()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No return code form this call?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Same question for the passes below.)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep. fixed. |
||
| } | ||
|
|
||
| if (AdderTool) { | ||
| int ToolExitCode = Tool.run(AdderTool.get()); | ||
| if (ToolExitCode != 0) | ||
| return false; | ||
| } else | ||
| llvm_unreachable("No action"); | ||
| // // 1a. Add Variables. | ||
| // std::unique_ptr<ToolAction> AdderTool = newFrontendActionFactoryA< | ||
| // GenericAction<VariableAdderConsumer, ProgramInfo>>(GlobalProgramInfo); | ||
| // | ||
| // if (AdderTool) { | ||
| // int ToolExitCode = Tool.run(AdderTool.get()); | ||
| // if (ToolExitCode != 0) | ||
| // return false; | ||
| // } else | ||
| // llvm_unreachable("No action"); | ||
|
|
||
| return true; | ||
| } | ||
|
|
@@ -371,18 +378,23 @@ bool _3CInterface::buildInitialConstraints() { | |
|
|
||
| std::lock_guard<std::mutex> Lock(InterfaceMutex); | ||
|
|
||
| ClangTool &Tool = getGlobalClangTool(); | ||
| // ClangTool &Tool = getGlobalClangTool(); | ||
|
|
||
| // 1b. Gather constraints. | ||
| std::unique_ptr<ToolAction> ConstraintTool = newFrontendActionFactoryA< | ||
| GenericAction<ConstraintBuilderConsumer, ProgramInfo>>(GlobalProgramInfo); | ||
| ConstraintBuilderConsumer CB = ConstraintBuilderConsumer(GlobalProgramInfo, nullptr); | ||
| for (auto &TU : ASTs) { | ||
| CB.HandleTranslationUnit(TU->getASTContext()); | ||
| } | ||
|
|
||
| if (ConstraintTool) { | ||
| int ToolExitCode = Tool.run(ConstraintTool.get()); | ||
| if (ToolExitCode != 0) | ||
| return false; | ||
| } else | ||
| llvm_unreachable("No action"); | ||
| // // 1b. Gather constraints. | ||
| // std::unique_ptr<ToolAction> ConstraintTool = newFrontendActionFactoryA< | ||
| // GenericAction<ConstraintBuilderConsumer, ProgramInfo>>(GlobalProgramInfo); | ||
| // | ||
| // if (ConstraintTool) { | ||
| // int ToolExitCode = Tool.run(ConstraintTool.get()); | ||
| // if (ToolExitCode != 0) | ||
| // return false; | ||
| // } else | ||
| // llvm_unreachable("No action"); | ||
|
|
||
| if (!GlobalProgramInfo.link()) { | ||
| errs() << "Linking failed!\n"; | ||
|
|
@@ -420,7 +432,8 @@ bool _3CInterface::solveConstraints() { | |
| if (DumpIntermediate) | ||
| dumpConstraintOutputJson(FINAL_OUTPUT_SUFFIX, GlobalProgramInfo); | ||
|
|
||
| ClangTool &Tool = getGlobalClangTool(); | ||
| // ClangTool &Tool = getGlobalClangTool(); | ||
|
|
||
| if (AllTypes) { | ||
| if (DebugArrSolver) | ||
| GlobalProgramInfo.getABoundsInfo().dumpAVarGraph( | ||
|
|
@@ -430,31 +443,42 @@ bool _3CInterface::solveConstraints() { | |
| // bounds declarations. | ||
| GlobalProgramInfo.getABoundsInfo().performFlowAnalysis(&GlobalProgramInfo); | ||
|
|
||
| // 3. Infer the bounds based on calls to malloc and calloc | ||
| std::unique_ptr<ToolAction> ABInfTool = newFrontendActionFactoryA< | ||
| GenericAction<AllocBasedBoundsInference, ProgramInfo>>( | ||
| GlobalProgramInfo); | ||
| if (ABInfTool) { | ||
| int ToolExitCode = Tool.run(ABInfTool.get()); | ||
| if (ToolExitCode != 0) | ||
| return false; | ||
| } else | ||
| llvm_unreachable("No Action"); | ||
| AllocBasedBoundsInference ABBI = AllocBasedBoundsInference(GlobalProgramInfo, nullptr); | ||
| for (auto &TU : ASTs) { | ||
| ABBI.HandleTranslationUnit(TU->getASTContext()); | ||
| } | ||
|
|
||
|
|
||
| // // 3. Infer the bounds based on calls to malloc and calloc | ||
| // std::unique_ptr<ToolAction> ABInfTool = newFrontendActionFactoryA< | ||
| // GenericAction<AllocBasedBoundsInference, ProgramInfo>>( | ||
| // GlobalProgramInfo); | ||
| // if (ABInfTool) { | ||
| // int ToolExitCode = Tool.run(ABInfTool.get()); | ||
| // if (ToolExitCode != 0) | ||
| // return false; | ||
| // } else | ||
| // llvm_unreachable("No Action"); | ||
|
|
||
| // Propagate the information from allocator bounds. | ||
| GlobalProgramInfo.getABoundsInfo().performFlowAnalysis(&GlobalProgramInfo); | ||
| } | ||
|
|
||
| // 4. Run intermediate tool hook to run visitors that need to be executed | ||
| // after constraint solving but before rewriting. | ||
| std::unique_ptr<ToolAction> IMTool = newFrontendActionFactoryA< | ||
| GenericAction<IntermediateToolHook, ProgramInfo>>(GlobalProgramInfo); | ||
| if (IMTool) { | ||
| int ToolExitCode = Tool.run(IMTool.get()); | ||
| if (ToolExitCode != 0) | ||
| return false; | ||
| } else | ||
| llvm_unreachable("No Action"); | ||
| IntermediateToolHook ITH = IntermediateToolHook(GlobalProgramInfo, nullptr); | ||
| for (auto &TU : ASTs) { | ||
| ITH.HandleTranslationUnit(TU->getASTContext()); | ||
| } | ||
|
|
||
| // // 4. Run intermediate tool hook to run visitors that need to be executed | ||
| // // after constraint solving but before rewriting. | ||
| // std::unique_ptr<ToolAction> IMTool = newFrontendActionFactoryA< | ||
| // GenericAction<IntermediateToolHook, ProgramInfo>>(GlobalProgramInfo); | ||
| // if (IMTool) { | ||
| // int ToolExitCode = Tool.run(IMTool.get()); | ||
| // if (ToolExitCode != 0) | ||
| // return false; | ||
| // } else | ||
| // llvm_unreachable("No Action"); | ||
|
|
||
| if (AllTypes) { | ||
| // Propagate data-flow information for Array pointers. | ||
|
|
@@ -497,48 +521,61 @@ bool _3CInterface::solveConstraints() { | |
| return true; | ||
| } | ||
|
|
||
| bool _3CInterface::writeConvertedFileToDisk(const std::string &FilePath) { | ||
| std::lock_guard<std::mutex> Lock(InterfaceMutex); | ||
| bool RetVal = false; | ||
| if (std::find(SourceFiles.begin(), SourceFiles.end(), FilePath) != | ||
| SourceFiles.end()) { | ||
| RetVal = true; | ||
| std::vector<std::string> SourceFiles; | ||
| SourceFiles.clear(); | ||
| SourceFiles.push_back(FilePath); | ||
| // Don't use global tool. Create a new tool for give single file. | ||
| ClangTool Tool(*CurrCompDB, SourceFiles); | ||
| Tool.appendArgumentsAdjuster(getIgnoreCheckedPointerAdjuster()); | ||
| std::unique_ptr<ToolAction> RewriteTool = | ||
| newFrontendActionFactoryA<RewriteAction<RewriteConsumer, ProgramInfo>>( | ||
| GlobalProgramInfo, VerifyDiagnosticOutput); | ||
|
|
||
| if (RewriteTool) { | ||
| int ToolExitCode = Tool.run(RewriteTool.get()); | ||
| if (ToolExitCode != 0) | ||
| RetVal = false; | ||
| } | ||
| } | ||
| GlobalProgramInfo.getPerfStats().endTotalTime(); | ||
| GlobalProgramInfo.getPerfStats().startTotalTime(); | ||
| return RetVal; | ||
| } | ||
| //bool _3CInterface::writeConvertedFileToDisk(const std::string &FilePath) { | ||
| // std::lock_guard<std::mutex> Lock(InterfaceMutex); | ||
| // bool RetVal = false; | ||
| // if (std::find(SourceFiles.begin(), SourceFiles.end(), FilePath) != | ||
| // SourceFiles.end()) { | ||
| // RetVal = true; | ||
| // std::vector<std::string> SourceFiles; | ||
| // SourceFiles.clear(); | ||
| // SourceFiles.push_back(FilePath); | ||
| // // Don't use global tool. Create a new tool for give single file. | ||
| // ClangTool Tool(*CurrCompDB, SourceFiles); | ||
| // Tool.appendArgumentsAdjuster(getIgnoreCheckedPointerAdjuster()); | ||
| // | ||
| // RewriteConsumer RC = RewriteConsumer(GlobalProgramInfo); | ||
| // for (auto &TU : ASTs) { | ||
| // RC.HandleTranslationUnit(TU->getASTContext()); | ||
| // } | ||
| // | ||
| // | ||
| //// std::unique_ptr<ToolAction> RewriteTool = | ||
| //// newFrontendActionFactoryA<RewriteAction<RewriteConsumer, ProgramInfo>>( | ||
| //// GlobalProgramInfo, VerifyDiagnosticOutput); | ||
| //// | ||
| //// if (RewriteTool) { | ||
| //// int ToolExitCode = Tool.run(RewriteTool.get()); | ||
| //// if (ToolExitCode != 0) | ||
| //// RetVal = false; | ||
| //// } | ||
| // | ||
| // } | ||
| // GlobalProgramInfo.getPerfStats().endTotalTime(); | ||
| // GlobalProgramInfo.getPerfStats().startTotalTime(); | ||
| // return RetVal; | ||
| //} | ||
|
|
||
| bool _3CInterface::writeAllConvertedFilesToDisk() { | ||
| std::lock_guard<std::mutex> Lock(InterfaceMutex); | ||
|
|
||
| ClangTool &Tool = getGlobalClangTool(); | ||
| // ClangTool &Tool = getGlobalClangTool(); | ||
|
|
||
| RewriteConsumer RC = RewriteConsumer(GlobalProgramInfo); | ||
| for (auto &TU : ASTs) { | ||
| RC.HandleTranslationUnit(TU->getASTContext()); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After rewriting happens, do you need to delete/free the ASTs? Maybe add another method to free them, to complement the one I'm suggesting you add, to build them?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I could tell the destructors handled everything. That might be different if we had to save/load for memory, or maintain the diagnostics for verification. If you can think of anything else, I'll check it out and add it. |
||
|
|
||
| // Rewrite the input files. | ||
| std::unique_ptr<ToolAction> RewriteTool = | ||
| newFrontendActionFactoryA<RewriteAction<RewriteConsumer, ProgramInfo>>( | ||
| GlobalProgramInfo, VerifyDiagnosticOutput); | ||
| if (RewriteTool) { | ||
| int ToolExitCode = Tool.run(RewriteTool.get()); | ||
| if (ToolExitCode != 0) | ||
| return false; | ||
| } else | ||
| llvm_unreachable("No action"); | ||
| // // Rewrite the input files. | ||
| // std::unique_ptr<ToolAction> RewriteTool = | ||
| // newFrontendActionFactoryA<RewriteAction<RewriteConsumer, ProgramInfo>>( | ||
| // GlobalProgramInfo, VerifyDiagnosticOutput); | ||
| // if (RewriteTool) { | ||
| // int ToolExitCode = Tool.run(RewriteTool.get()); | ||
| // if (ToolExitCode != 0) | ||
| // return false; | ||
| // } else | ||
| // llvm_unreachable("No action"); | ||
|
|
||
| GlobalProgramInfo.getPerfStats().endTotalTime(); | ||
| GlobalProgramInfo.getPerfStats().startTotalTime(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels odd to me to build the ASTs here, since the name of the method is
addVariables.Perhaps there should be another method call in
_3CInterfacethat you specifically invoke to the build the ASTs, and then the subsequent passes can check to confirm the ASTs have been built already?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. I'll do a minor refactor once the functionality is stable and I agree this needs its own little section.