forked from OSchip/llvm-project
[analyzer] StdLibraryFunctionsChecker: Add option to display loaded summaries
Reviewers: NoQ, Szelethus, baloghadamsoftware, balazske Subscribers: whisperity, xazax.hun, szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, gamesh411, Charusso, steakhal, ASDenysPetrov, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D78118
This commit is contained in:
parent
79941086fb
commit
ff4492c89f
|
@ -294,6 +294,14 @@ let ParentPackage = APIModeling in {
|
||||||
def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
|
def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
|
||||||
HelpText<"Improve modeling of the C standard library functions">,
|
HelpText<"Improve modeling of the C standard library functions">,
|
||||||
Dependencies<[NonNullParamChecker, CallAndMessageChecker]>,
|
Dependencies<[NonNullParamChecker, CallAndMessageChecker]>,
|
||||||
|
CheckerOptions<[
|
||||||
|
CmdLineOption<Boolean,
|
||||||
|
"DisplayLoadedSummaries",
|
||||||
|
"If set to true, the checker displays the found summaries "
|
||||||
|
"for the given translation unit.",
|
||||||
|
"false",
|
||||||
|
Released>
|
||||||
|
]>,
|
||||||
Documentation<NotDocumented>;
|
Documentation<NotDocumented>;
|
||||||
|
|
||||||
def StdCLibraryFunctionArgsChecker : Checker<"StdCLibraryFunctionArgs">,
|
def StdCLibraryFunctionArgsChecker : Checker<"StdCLibraryFunctionArgs">,
|
||||||
|
|
|
@ -300,6 +300,8 @@ public:
|
||||||
DefaultBool ChecksEnabled[CK_NumCheckKinds];
|
DefaultBool ChecksEnabled[CK_NumCheckKinds];
|
||||||
CheckerNameRef CheckNames[CK_NumCheckKinds];
|
CheckerNameRef CheckNames[CK_NumCheckKinds];
|
||||||
|
|
||||||
|
bool DisplayLoadedSummaries = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Optional<Summary> findFunctionSummary(const FunctionDecl *FD,
|
Optional<Summary> findFunctionSummary(const FunctionDecl *FD,
|
||||||
CheckerContext &C) const;
|
CheckerContext &C) const;
|
||||||
|
@ -639,8 +641,12 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
|
||||||
struct AddToFunctionSummaryMap {
|
struct AddToFunctionSummaryMap {
|
||||||
const ASTContext &ACtx;
|
const ASTContext &ACtx;
|
||||||
FunctionSummaryMapType ⤅
|
FunctionSummaryMapType ⤅
|
||||||
AddToFunctionSummaryMap(const ASTContext &ACtx, FunctionSummaryMapType &FSM)
|
bool DisplayLoadedSummaries;
|
||||||
: ACtx(ACtx), Map(FSM) {}
|
AddToFunctionSummaryMap(const ASTContext &ACtx, FunctionSummaryMapType &FSM,
|
||||||
|
bool DisplayLoadedSummaries)
|
||||||
|
: ACtx(ACtx), Map(FSM), DisplayLoadedSummaries(DisplayLoadedSummaries) {
|
||||||
|
}
|
||||||
|
|
||||||
// Add a summary to a FunctionDecl found by lookup. The lookup is performed
|
// Add a summary to a FunctionDecl found by lookup. The lookup is performed
|
||||||
// by the given Name, and in the global scope. The summary will be attached
|
// by the given Name, and in the global scope. The summary will be attached
|
||||||
// to the found FunctionDecl only if the signatures match.
|
// to the found FunctionDecl only if the signatures match.
|
||||||
|
@ -655,6 +661,11 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
|
||||||
auto Res = Map.insert({FD->getCanonicalDecl(), S});
|
auto Res = Map.insert({FD->getCanonicalDecl(), S});
|
||||||
assert(Res.second && "Function already has a summary set!");
|
assert(Res.second && "Function already has a summary set!");
|
||||||
(void)Res;
|
(void)Res;
|
||||||
|
if (DisplayLoadedSummaries) {
|
||||||
|
llvm::errs() << "Loaded summary for: ";
|
||||||
|
FD->print(llvm::errs());
|
||||||
|
llvm::errs() << "\n";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -665,7 +676,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
|
||||||
for (const Summary &S : Summaries)
|
for (const Summary &S : Summaries)
|
||||||
operator()(Name, S);
|
operator()(Name, S);
|
||||||
}
|
}
|
||||||
} addToFunctionSummaryMap(ACtx, FunctionSummaryMap);
|
} addToFunctionSummaryMap(ACtx, FunctionSummaryMap, DisplayLoadedSummaries);
|
||||||
|
|
||||||
// We are finally ready to define specifications for all supported functions.
|
// We are finally ready to define specifications for all supported functions.
|
||||||
//
|
//
|
||||||
|
@ -937,7 +948,10 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
|
||||||
}
|
}
|
||||||
|
|
||||||
void ento::registerStdCLibraryFunctionsChecker(CheckerManager &mgr) {
|
void ento::registerStdCLibraryFunctionsChecker(CheckerManager &mgr) {
|
||||||
mgr.registerChecker<StdLibraryFunctionsChecker>();
|
auto *Checker = mgr.registerChecker<StdLibraryFunctionsChecker>();
|
||||||
|
Checker->DisplayLoadedSummaries =
|
||||||
|
mgr.getAnalyzerOptions().getCheckerBooleanOption(
|
||||||
|
Checker, "DisplayLoadedSummaries");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ento::shouldRegisterStdCLibraryFunctionsChecker(const CheckerManager &mgr) {
|
bool ento::shouldRegisterStdCLibraryFunctionsChecker(const CheckerManager &mgr) {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtExec = 0x04
|
// CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtExec = 0x04
|
||||||
// CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtRead = 0x01
|
// CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtRead = 0x01
|
||||||
// CHECK-NEXT: alpha.security.taint.TaintPropagation:Config = ""
|
// CHECK-NEXT: alpha.security.taint.TaintPropagation:Config = ""
|
||||||
|
// CHECK-NEXT: apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries = false
|
||||||
// CHECK-NEXT: apply-fixits = false
|
// CHECK-NEXT: apply-fixits = false
|
||||||
// CHECK-NEXT: avoid-suppressing-null-argument-paths = false
|
// CHECK-NEXT: avoid-suppressing-null-argument-paths = false
|
||||||
// CHECK-NEXT: c++-allocator-inlining = true
|
// CHECK-NEXT: c++-allocator-inlining = true
|
||||||
|
@ -106,4 +107,4 @@
|
||||||
// CHECK-NEXT: unroll-loops = false
|
// CHECK-NEXT: unroll-loops = false
|
||||||
// CHECK-NEXT: widen-loops = false
|
// CHECK-NEXT: widen-loops = false
|
||||||
// CHECK-NEXT: [stats]
|
// CHECK-NEXT: [stats]
|
||||||
// CHECK-NEXT: num-entries = 103
|
// CHECK-NEXT: num-entries = 104
|
||||||
|
|
|
@ -30,6 +30,35 @@
|
||||||
// RUN: -triple thumbv7-a15-linux \
|
// RUN: -triple thumbv7-a15-linux \
|
||||||
// RUN: -verify
|
// RUN: -verify
|
||||||
|
|
||||||
|
// RUN: %clang_analyze_cc1 %s \
|
||||||
|
// RUN: -analyzer-checker=core \
|
||||||
|
// RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
|
||||||
|
// RUN: -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
|
||||||
|
// RUN: -analyzer-checker=debug.ExprInspection \
|
||||||
|
// RUN: -analyzer-config eagerly-assume=false \
|
||||||
|
// RUN: -triple i686-unknown-linux 2>&1 | FileCheck %s
|
||||||
|
|
||||||
|
// CHECK: Loaded summary for: int isalnum(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int isalpha(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int isascii(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int isblank(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int isdigit(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int isgraph(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int islower(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int isprint(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int ispunct(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int isspace(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int isupper(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int isxdigit(int)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int getc(FILE *)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int fgetc(FILE *)
|
||||||
|
// CHECK-NEXT: Loaded summary for: int getchar()
|
||||||
|
// CHECK-NEXT: Loaded summary for: ssize_t read(int, void *, size_t)
|
||||||
|
// CHECK-NEXT: Loaded summary for: ssize_t write(int, const void *, size_t)
|
||||||
|
// CHECK-NEXT: Loaded summary for: unsigned int fread(void *restrict, size_t, size_t, FILE *)
|
||||||
|
// CHECK-NEXT: Loaded summary for: unsigned int fwrite(const void *restrict, size_t, size_t, FILE *restrict)
|
||||||
|
// CHECK-NEXT: Loaded summary for: ssize_t getline(char **, size_t *, FILE *)
|
||||||
|
|
||||||
void clang_analyzer_eval(int);
|
void clang_analyzer_eval(int);
|
||||||
|
|
||||||
int glob;
|
int glob;
|
||||||
|
|
Loading…
Reference in New Issue