Skip to content

Commit b76fcea

Browse files
author
Endre Fülöp
committed
Implement checker config for summary configuration
1 parent d256712 commit b76fcea

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
377377
"If set to true, the checker models functions from the "
378378
"POSIX standard.",
379379
"false",
380+
InAlpha>,
381+
CmdLineOption<String,
382+
"SummaryConfigPath",
383+
"The path of the config file in YAML format",
384+
"",
380385
InAlpha>
381386
]>,
382387
Documentation<NotDocumented>,

clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ class StdLibraryFunctionsChecker
774774
bool DisplayLoadedSummaries = false;
775775
bool ModelPOSIX = false;
776776
bool ShouldAssumeControlledEnvironment = false;
777+
std::string SummaryConfigPath;
777778

778779
private:
779780
Optional<Summary> findFunctionSummary(const FunctionDecl *FD,
@@ -1452,12 +1453,10 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
14521453

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

14631462
auto GetTypeFromStr = [&](StringRef TypeName) {
@@ -3178,6 +3177,8 @@ void ento::registerStdCLibraryFunctionsChecker(CheckerManager &mgr) {
31783177
Checker->ModelPOSIX = Opts.getCheckerBooleanOption(Checker, "ModelPOSIX");
31793178
Checker->ShouldAssumeControlledEnvironment =
31803179
Opts.ShouldAssumeControlledEnvironment;
3180+
Checker->SummaryConfigPath =
3181+
Opts.getCheckerStringOption(Checker, "SummaryConfigPath");
31813182
}
31823183

31833184
bool ento::shouldRegisterStdCLibraryFunctionsChecker(

clang/test/Analysis/std-c-library-functions-config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %clang_analyze_cc1 %s \
33
// RUN: -analyzer-checker=core \
44
// RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
5+
// RUN: -analyzer-config apiModeling.StdCLibraryFunctions:SummaryConfigPath="%S/Inputs/fread-summary.yaml" \
56
// RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
67
// RUN: -analyzer-checker=debug.StdCLibraryFunctionsTester \
78
// RUN: -analyzer-checker=debug.ExprInspection \
@@ -12,6 +13,7 @@
1213
// RUN: %clang_analyze_cc1 %s \
1314
// RUN: -analyzer-checker=core \
1415
// RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
16+
// RUN: -analyzer-config apiModeling.StdCLibraryFunctions:SummaryConfigPath="%S/Inputs/fread-summary.yaml" \
1517
// RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
1618
// RUN: -analyzer-checker=debug.StdCLibraryFunctionsTester \
1719
// RUN: -analyzer-checker=debug.ExprInspection \

0 commit comments

Comments
 (0)