Add new -cc1 driver option -analyzer-config, which allows one to specify

a comma separated collection of key:value pairs (which are strings).  This
allows a general way to provide analyzer configuration data from the command line.

No clients yet.

llvm-svn: 162827
This commit is contained in:
Ted Kremenek 2012-08-29 05:55:00 +00:00
parent 5f96ca51b6
commit fb5351eed3
8 changed files with 65 additions and 7 deletions

View File

@ -141,5 +141,9 @@ def warn_drv_pch_not_first_include : Warning<
def note_drv_command_failed_diag_msg : Note<
"diagnostic msg: %0">;
def err_analyzer_config_no_value : Error<
"analyzer-config option '%0' has a key but no value">;
def err_analyzer_config_multiple_values : Error<
"analyzer-config option '%0' should contain only one ':'">;
}

View File

@ -119,6 +119,11 @@ def analyzer_disable_checker_EQ : Joined<"-analyzer-disable-checker=">,
def analyzer_checker_help : Flag<"-analyzer-checker-help">,
HelpText<"Display the list of analyzer checkers that are available">;
def analyzer_config : Separate<"-analyzer-config">,
HelpText<"Choose analyzer checkers to enable">;
def analyzer_config_EQ : Joined<"-analyzer-config=">,
Alias<analyzer_config>;
//===----------------------------------------------------------------------===//
// Migrator Options
//===----------------------------------------------------------------------===//

View File

@ -17,6 +17,7 @@
#include <string>
#include <vector>
#include "llvm/ADT/StringMap.h"
namespace clang {
class ASTConsumer;
@ -78,6 +79,7 @@ class AnalyzerOptions {
public:
/// \brief Pair of checker name and enable/disable.
std::vector<std::pair<std::string, bool> > CheckersControlList;
llvm::StringMap<std::string> Config;
AnalysisStores AnalysisStoreOpt;
AnalysisConstraints AnalysisConstraintsOpt;
AnalysisDiagClients AnalysisDiagOpt;

View File

@ -81,6 +81,11 @@ public:
/// strategy. We get better code coverage when retry is enabled.
bool NoRetryExhausted;
typedef llvm::StringMap<std::string> ConfigTable;
/// \brief A key-value table of use-specified configuration values.
const ConfigTable &Config;
public:
AnalysisManager(ASTContext &ctx,DiagnosticsEngine &diags,
const LangOptions &lang,
@ -88,6 +93,7 @@ public:
StoreManagerCreator storemgr,
ConstraintManagerCreator constraintmgr,
CheckerManager *checkerMgr,
const ConfigTable &Config,
unsigned maxnodes, unsigned maxvisit,
bool vizdot, bool vizubi, AnalysisPurgeMode purge,
bool eager, bool trim,

View File

@ -64,6 +64,10 @@ public:
return Eng.getStoreManager();
}
const AnalysisManager::ConfigTable &getConfig() const {
return Eng.getAnalysisManager().Config;
}
/// \brief Returns the previous node in the exploded graph, which includes
/// the state of the program before the checker ran. Note, checkers should
/// not retain the node in their state since the nodes might get invalidated.

View File

@ -1154,6 +1154,36 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
for (unsigned i = 0, e = checkers.size(); i != e; ++i)
Opts.CheckersControlList.push_back(std::make_pair(checkers[i], enable));
}
// Go through the analyzer configuration options.
for (arg_iterator it = Args.filtered_begin(OPT_analyzer_config),
ie = Args.filtered_end(); it != ie; ++it) {
const Arg *A = *it;
A->claim();
// We can have a list of comma separated config names, e.g:
// '-analyzer-config=key1:val1,key2:val2'
StringRef configList = A->getValue(Args);
SmallVector<StringRef, 4> configVals;
configList.split(configVals, ",");
for (unsigned i = 0, e = configVals.size(); i != e; ++i) {
StringRef key, val;
llvm::tie(key, val) = configVals[i].split(":");
if (val.empty()) {
Diags.Report(SourceLocation(),
diag::err_analyzer_config_no_value) << configVals[i];
Success = false;
break;
}
if (val.find(':') != StringRef::npos) {
Diags.Report(SourceLocation(),
diag::err_analyzer_config_multiple_values)
<< configVals[i];
Success = false;
break;
}
Opts.Config[key] = val;
}
}
return Success;
}

View File

@ -20,6 +20,7 @@ AnalysisManager::AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
StoreManagerCreator storemgr,
ConstraintManagerCreator constraintmgr,
CheckerManager *checkerMgr,
const ConfigTable &Config,
unsigned maxnodes, unsigned maxvisit,
bool vizdot, bool vizubi,
AnalysisPurgeMode purge,
@ -36,7 +37,7 @@ AnalysisManager::AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
Ctx(ctx), Diags(diags), LangOpts(lang),
PathConsumers(PDC),
CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
CheckerMgr(checkerMgr),
CheckerMgr(checkerMgr),
MaxNodes(maxnodes), MaxVisit(maxvisit),
VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
EagerlyAssume(eager), TrimGraph(trim),
@ -45,7 +46,8 @@ AnalysisManager::AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
InlineMaxStackDepth(inlineMaxStack),
InlineMaxFunctionSize(inlineMaxFunctionSize),
InliningMode(IMode),
NoRetryExhausted(NoRetry)
NoRetryExhausted(NoRetry),
Config(Config)
{
AnaCtxMgr.getCFGBuildOptions().setAllAlwaysAdd();
}

View File

@ -255,11 +255,16 @@ public:
CreateStoreMgr,
CreateConstraintMgr,
checkerMgr.get(),
Opts.MaxNodes, Opts.MaxLoop,
Opts.VisualizeEGDot, Opts.VisualizeEGUbi,
Opts.AnalysisPurgeOpt, Opts.EagerlyAssume,
Opts.Config,
Opts.MaxNodes,
Opts.MaxLoop,
Opts.VisualizeEGDot,
Opts.VisualizeEGUbi,
Opts.AnalysisPurgeOpt,
Opts.EagerlyAssume,
Opts.TrimGraph,
Opts.UnoptimizedCFG, Opts.CFGAddImplicitDtors,
Opts.UnoptimizedCFG,
Opts.CFGAddImplicitDtors,
Opts.EagerlyTrimEGraph,
Opts.IPAMode,
Opts.InlineMaxStackDepth,