[cfe-dev] Best place for semantic checks

Zhongxing Xu mymlreader at gmail.com
Thu Jul 10 07:08:45 PDT 2008


To avoid unexpected troubles when doing svn update, I copy the whole
clang/Driver directory to another place and do all things in that directory,
and linking against the necessary LLVM/clang libraries to build a custom
driver.


> More specifically, you need to modify the following to use the
> AnalysisConsumer interface:
>
> --------------------
>
> Driver/AnalysisConsumer.h:
>
> Add a new value to the enum Analyses:
>
>   enum Analyses {
>   CFGDump,
>   CFGView,
>   WarnDeadStores,
>   WarnUninitVals,
>   DisplayLiveVariables,
>   CheckerCFRef,
>   CheckerSimple,
>   MyChecker  // <--------------------------
> };
>
> --------------------
>
> Driver/AnalysisConsumer.cpp:
>
> 1) Add a static "Action" function that calls your checker using the
> appropriate arguments.
>
> static void ActionMyChecker(AnalysisManager& mgr) {
>    // Call the checker using arguments provided by queries to
> AnalysisManager.
>    ...
> }
>
>
> 2) Add a case in CreateAnalysisConsumer for your Analysis using the
> enum value you added to Driver/AnalysisConsumer.h:
>
> ASTConsumer* clang::CreateAnalysisConsumer(...) {
>
>   ...
>
>   for ( ; Beg != End ; ++Beg)
>     switch (*Beg) {
>       case WarnDeadStores:
>         C->addCodeAction(&ActionDeadStores);
>         break;
>
>       case WarnUninitVals:
>         C->addCodeAction(&ActionUninitVals);
>         break;
>
>       // ADD A CASE HERE
>       case MyChecker:
>       C->addCodeAction(&ActionMyChecker);
>       break;
>
> --------------------
>
> Driver/Clang.cpp:
>
> Add your command line argument to "Analyses"
>
> static llvm::cl::list<Analyses>
> AnalysisList(llvm::cl::desc("Available Source Code Analyses:"),
> llvm::cl::values(
> clEnumValN(CFGDump, "cfg-dump", "Display Control-Flow Graphs"),
> clEnumValN(CFGView, "cfg-view", "View Control-Flow Graphs using
> GraphViz"),
> clEnumValN(DisplayLiveVariables, "dump-live-variables",
>            "Print results of live variable analysis"),
> clEnumValN(WarnDeadStores, "warn-dead-stores",
>            "Flag warnings of stores to dead variables"),
> clEnumValN(WarnUninitVals, "warn-uninit-values",
>            "Flag warnings of uses of unitialized variables"),
> clEnumValN(CheckerSimple, "checker-simple",
>            "Perform simple path-sensitive checks."),
> clEnumValN(CheckerCFRef, "checker-cfref",
>            "Run the [Core] Foundation reference count checker"),
> clEnumValnN(MyChecker, "my-checker",     //
> <------------------------------------------
>            "My Custom Checker"),
> clEnumValEnd));
>
>
> - Ted
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080710/44719b06/attachment.html>


More information about the cfe-dev mailing list