forked from llvm/llvm-project
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer] StdLibraryFunctionsChecker: Add support to lookup types
Summary: In this patch I am trying to get rid of the `Irrelevant` types from the signatures of the functions from the standard C library. For that I've introduced `lookupType()` to be able to lookup arbitrary types in the global scope. This makes it possible to define the signatures precisely. Note 1) `fread`'s signature is now fixed to have the proper `FILE *restrict` type when C99 is the language. Note 2) There are still existing `Irrelevant` types, but they are all from POSIX. I am planning to address those together with the missing POSIX functions (in D79433). Reviewers: xazax.hun, NoQ, Szelethus, balazske Subscribers: whisperity, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, gamesh411, Charusso, steakhal, ASDenysPetrov, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D80016
- Loading branch information
Gabor Marton
committed
May 29, 2020
1 parent
9e0b52e
commit 634258b
Showing
5 changed files
with
102 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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: unsigned int fread(void *restrict, size_t, size_t, FILE *restrict) | ||
|
||
typedef typeof(sizeof(int)) size_t; | ||
typedef struct FILE FILE; | ||
size_t fread(void *restrict, size_t, size_t, FILE *restrict); | ||
|
||
// Must have at least one call expression to initialize the summary map. | ||
int bar(void); | ||
void foo() { | ||
bar(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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: size_t fread(void *, size_t, size_t, FILE *) | ||
// CHECK-NOT: Loaded summary for: size_t fread(void *, size_t, size_t, MyFile *) | ||
|
||
typedef unsigned int size_t; | ||
typedef struct FILE FILE; | ||
size_t fread(void *, size_t, size_t, FILE *); | ||
|
||
struct MyFile; | ||
size_t fread(void *, size_t, size_t, MyFile *); | ||
|
||
// Must have at least one call expression to initialize the summary map. | ||
int bar(void); | ||
void foo() { | ||
bar(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters