Skip to content

Commit

Permalink
Implement checker config for summary configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Endre Fülöp committed Nov 10, 2022
1 parent d256712 commit b76fcea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
"If set to true, the checker models functions from the "
"POSIX standard.",
"false",
InAlpha>,
CmdLineOption<String,
"SummaryConfigPath",
"The path of the config file in YAML format",
"",
InAlpha>
]>,
Documentation<NotDocumented>,
Expand Down
11 changes: 6 additions & 5 deletions clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ class StdLibraryFunctionsChecker
bool DisplayLoadedSummaries = false;
bool ModelPOSIX = false;
bool ShouldAssumeControlledEnvironment = false;
std::string SummaryConfigPath;

private:
Optional<Summary> findFunctionSummary(const FunctionDecl *FD,
Expand Down Expand Up @@ -1452,12 +1453,10 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(

// User-provided summary configuration.
CheckerManager *Mgr = C.getAnalysisManager().getCheckerManager();
std::string Option{"Config"};
/*StringRef ConfigFile =
Mgr->getAnalyzerOptions().getCheckerStringOption(this, Option);*/
StringRef ConfigFile = "/local/workspace/llvm-project/clang/test/Analysis/Inputs/fread-summary.yaml";
std::string Option{"SummaryConfigPath"};
Mgr->getAnalyzerOptions().getCheckerStringOption(this, Option);
llvm::Optional<SummaryConfiguration> Config =
getConfiguration<SummaryConfiguration>(*Mgr, this, Option, ConfigFile);
getConfiguration<SummaryConfiguration>(*Mgr, this, Option, SummaryConfigPath);
llvm::errs() << "Config :" << Config.has_value() << "\n";

auto GetTypeFromStr = [&](StringRef TypeName) {
Expand Down Expand Up @@ -3178,6 +3177,8 @@ void ento::registerStdCLibraryFunctionsChecker(CheckerManager &mgr) {
Checker->ModelPOSIX = Opts.getCheckerBooleanOption(Checker, "ModelPOSIX");
Checker->ShouldAssumeControlledEnvironment =
Opts.ShouldAssumeControlledEnvironment;
Checker->SummaryConfigPath =
Opts.getCheckerStringOption(Checker, "SummaryConfigPath");
}

bool ento::shouldRegisterStdCLibraryFunctionsChecker(
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Analysis/std-c-library-functions-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// RUN: %clang_analyze_cc1 %s \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
// RUN: -analyzer-config apiModeling.StdCLibraryFunctions:SummaryConfigPath="%S/Inputs/fread-summary.yaml" \
// RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
// RUN: -analyzer-checker=debug.StdCLibraryFunctionsTester \
// RUN: -analyzer-checker=debug.ExprInspection \
Expand All @@ -12,6 +13,7 @@
// RUN: %clang_analyze_cc1 %s \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
// RUN: -analyzer-config apiModeling.StdCLibraryFunctions:SummaryConfigPath="%S/Inputs/fread-summary.yaml" \
// RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
// RUN: -analyzer-checker=debug.StdCLibraryFunctionsTester \
// RUN: -analyzer-checker=debug.ExprInspection \
Expand Down

0 comments on commit b76fcea

Please sign in to comment.