Skip to content
Closed
Show file tree
Hide file tree
Changes from 135 commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
f4768db
Constrain expression variables in unwritable files to not change. (#467)
mattmccutchen-cci Mar 4, 2021
f44b67d
Remove brainTransplant (#463)
kyleheadley Mar 5, 2021
cc7eec2
Adding Stats (#473)
Machiry Mar 6, 2021
906138e
Typedef implementation improvements (#408)
Mar 8, 2021
cbbbb09
Detect 5C files rather than requiring -DFIVE_C=ON to be passed. (#464)
mattmccutchen-cci Mar 8, 2021
ce6f419
Remove defered params (#476)
kyleheadley Mar 9, 2021
a09a543
Don't print the performance statistics unconditionally. (#479)
mattmccutchen-cci Mar 11, 2021
04b08f0
Calls to polymorphic functions in macros no longer fail an assert (#480)
kyleheadley Mar 12, 2021
16206ed
Pldi bounds changes (#474)
Machiry Mar 13, 2021
023d3a4
Enhance port_tools to be able to do more with each benchmark. (#472)
mattmccutchen-cci Mar 15, 2021
c7e3915
convert_project: Turn off -dump-intermediate by default. (#490)
mattmccutchen-cci Mar 16, 2021
7a523be
Add regression tests for diagnostic processing. (#489)
mattmccutchen-cci Mar 16, 2021
d84ef38
Avoid trying to insert cast inside macros (#491)
john-h-kastner Mar 18, 2021
e84104c
Fix for issue #468 (#497)
Mar 18, 2021
f3c00d8
Make accessing va_list parameters unchecked (fix #483) (#493)
john-h-kastner Mar 19, 2021
650ecfa
Fix rewriting for K&R style function (#500)
john-h-kastner Mar 19, 2021
fa1d7b4
Add initializer when nested structure has checked field (fix #495) (#…
john-h-kastner Mar 22, 2021
898a3a1
Use original source for unchanged function pointer params (#494)
john-h-kastner Mar 22, 2021
a381b70
Fix function pointer rewriting with itypes (fix #498) (#506)
john-h-kastner Mar 23, 2021
ad4c801
One clang pass (#488)
kyleheadley Mar 23, 2021
d5eb579
Merge branch 'master' of github.com:microsoft/checkedc-clang
mattmccutchen-cci Mar 30, 2021
73d9265
Merge commit '898a3a14af8191d7befb980ef0307a2eb04e3a61' (i.e., #494)
mattmccutchen-cci Mar 30, 2021
e5d5073
Merge branch 'main' of github.com:correctcomputation/checkedc-clang
mattmccutchen-cci Mar 30, 2021
2a6a28e
Format regression tests that were added or changed since #481.
mattmccutchen-cci Mar 30, 2021
b6fea34
test_updater: Don't trigger on pointers in `//` comments.
mattmccutchen-cci Mar 30, 2021
fc6d7e6
Update valist.c using test_updater.
mattmccutchen-cci Mar 30, 2021
d7f61d8
Manual changes to formatting of CHECK lines so that tests pass.
mattmccutchen-cci Mar 30, 2021
0a06522
Merge pull request #518 from correctcomputation/merge-from-microsoft-…
mattmccutchen-cci Mar 30, 2021
032a930
Make `3c -verify` an error for now. (#519)
mattmccutchen-cci Mar 30, 2021
5eb95e8
`convert_project`: Add option to expand macros before running 3C. (#516)
mattmccutchen-cci Mar 31, 2021
38bdf5e
Merge branch 'master' of github.com:microsoft/checkedc-clang
mattmccutchen-cci Apr 1, 2021
edf0ed7
Minimal change to convert_project to turn off #include updating by
mattmccutchen-cci Apr 1, 2021
eb3249a
Allowing multiple definitions of the same function (#505)
mwhicks1 Apr 5, 2021
4a6ae1d
Fix bounds inference breakage due to declaration merging change (#526)
Machiry Apr 7, 2021
e012f43
Ensure presumed source file paths are canonical when using a compilat…
mattmccutchen-cci Apr 7, 2021
39cae7f
Add new array bounds even when pointer type does not change (#540)
john-h-kastner Apr 12, 2021
b01052a
Update types for pointers with itypes (#539)
john-h-kastner Apr 12, 2021
6dc249d
Add special case casting for itype(nt_array_ptr) to nt_array_ptr assi…
john-h-kastner Apr 13, 2021
5df3fd7
Fix rewriting for arrays of function pointers (#510) (fix #496)
john-h-kastner Apr 13, 2021
6438874
Reversing internal and external constraint vars
Machiry Apr 13, 2021
a3a6083
Flag to reverse internal and external constraints for functions
Machiry Apr 14, 2021
09544a0
Minor fix
Machiry Apr 14, 2021
5f1bcca
Solving issue of un-nullable types solving to Nt_array (#547)
Apr 14, 2021
62fc19b
Fix thttpd macro expansion (#548)
mattmccutchen-cci Apr 14, 2021
94f096b
Constrain `printf("%s")` arguments to `_Nt_array_ptr`. (#550)
mattmccutchen-cci Apr 16, 2021
e0fb426
Change action to append for 3c args (#556)
Machiry Apr 17, 2021
8c66180
Work around Stmt::getID assertion failure on long string literals. (#…
mattmccutchen-cci Apr 18, 2021
089d5da
Fixing: https://github.com/correctcomputation/checkedc-clang/issues/5…
Machiry Apr 27, 2021
34f86cf
Use internal atoms of function parameters and return values for compu…
Machiry Apr 28, 2021
4eebf17
Fixing join of constant bounds (#558)
Machiry Apr 28, 2021
1a60b2a
Fixing bounds of ntarr when strdup is used (#559)
Machiry Apr 28, 2021
b5caa23
Don't crash on a function call with parentheses around the function n…
mattmccutchen-cci May 1, 2021
b7664e2
Add regression test for #523. (#564)
mattmccutchen-cci May 1, 2021
b52ca45
Stats computation enchancements (#566)
Machiry May 4, 2021
cfbfb4b
Remove old realloc, etc. declarations from basic.c and graphs.c. (#567)
mattmccutchen-cci May 4, 2021
4a510d5
Fix one crash due to a PSL collision in TypeParamBindings. (#569)
mattmccutchen-cci May 5, 2021
ea6dfbb
Avoid expanding macros in constant size array declarations (#570)
john-h-kastner May 5, 2021
45bfaab
Fix rewriting of typedef for struct declared later in the file. (#572)
mattmccutchen-cci May 5, 2021
666f32e
Remove 3C `#include` updating code and documentation. (#574)
mattmccutchen-cci May 10, 2021
e12989a
Merge branch 'master' of github.com:microsoft/checkedc-clang
mattmccutchen-cci May 10, 2021
9316fa0
Merge pull request #561 from correctcomputation/merge-from-microsoft-…
mattmccutchen-cci May 10, 2021
244198a
Initialize typedef info structure in copy constructor (#588)
john-h-kastner May 17, 2021
cfd85b4
Fix bug in PVConstraint copy constructor (#579)
john-h-kastner May 17, 2021
33764f8
Fix statstest. (#586)
mattmccutchen-cci May 17, 2021
2b8a064
3c: Don't raise SIGABRT when CommonOptionsParser fails. (#492)
mattmccutchen-cci May 17, 2021
81cbd4c
Move the testgenerator.py and processor.py tests to subdirectories. (…
mattmccutchen-cci May 18, 2021
1fac188
Migrate 3C regression tests from %clang_cc1 to %clang. (#596)
mattmccutchen-cci May 21, 2021
8401770
Remove hard-coded checked declarations from 3C regression tests. (#576)
mattmccutchen-cci May 21, 2021
9415bf4
Fix `canwrite_constraints` test and constrain itypes in unwritable fi…
mattmccutchen-cci May 21, 2021
8fab223
Fix intermittent error bounds inference (fix #585) (#589)
john-h-kastner May 21, 2021
abc1f9c
Don't allow type arguments to be added to generic function calls in u…
mattmccutchen-cci May 21, 2021
07ed382
Fixing Bounds issue with Function Parameters (#582)
Machiry May 28, 2021
e240faa
Fixing func_parm_bounds test case (#601)
Machiry May 30, 2021
e549c91
Fix json syntax in TotalConstraintStats.json (#605)
john-h-kastner Jun 9, 2021
76b6266
Fix the diagnostic verifier, plus a few other fixes. (#598)
mattmccutchen-cci Jun 14, 2021
222cf9a
Merge branch 'master' of github.com:microsoft/checkedc-clang
mattmccutchen-cci Jun 15, 2021
bfc3212
Merge pull request #611 from correctcomputation/merge-from-microsoft-…
mattmccutchen-cci Jun 15, 2021
b75d0a3
convert_project.py now exits w/ non-zero on error (#614)
Jun 17, 2021
2a96dfb
Adding bounds inference of the form count(i+1) (#602)
Machiry Jun 18, 2021
a929d23
Handling function pointer bounds (#587)
Machiry Jun 18, 2021
157e2cd
Fix the root-cause tests. (#613)
mattmccutchen-cci Jun 21, 2021
8c04ca6
Make invertibility methods available outside CheckBoundsDeclarations …
kkjeer Jun 21, 2021
6c601e1
Add null statements to the CFG (#1098)
sulekhark Jun 21, 2021
61e89ae
Call ExprUtil::EqualValue in CompareUpperOffsetsWithConstantFolding (…
kkjeer Jun 21, 2021
91db852
Fix regression tests to not create temp files outside the lit temp di…
mattmccutchen-cci Jun 22, 2021
da7b8f5
Minor documentation updates (#628)
mattmccutchen-cci Jun 22, 2021
50077c8
Fix escaping bugs that currently affect the JSON formatting test on W…
mattmccutchen-cci Jun 23, 2021
f10df90
Fortify source workaround (#629)
Jun 24, 2021
afc140f
LLVM 12.x introduces an enum called InitKind to identify the kind of …
sulekhark Jun 24, 2021
e754850
Setting the "RecoveryAST" option from default true to default false. …
sulekhark Jun 24, 2021
7a09afb
Make ReplaceLValue methods available outside CheckBoundsDeclarations …
kkjeer Jun 24, 2021
af12895
The addition of two new cast operations in LLVM 12.x (FloatingToFixed…
sulekhark Jun 25, 2021
9225811
Some of the "ignore" functionality has moved to the file clang/includ…
sulekhark Jun 26, 2021
be2642c
Code style pass for 3C PR to Microsoft "2021-05" (#634)
mattmccutchen-cci Jun 28, 2021
3fdde7d
Merge branch 'master' of github.com:microsoft/checkedc-clang
mattmccutchen-cci Jun 28, 2021
6c939fa
Fix for LLVM test failures caused by the name change from LLVM to Che…
sulekhark Jun 29, 2021
fbd6648
Move ExpandToRange methods into BoundsUtil (#1111)
kkjeer Jun 29, 2021
b306252
Make add_clang_tool add a dependency on checkedc-headers.
mattmccutchen-cci Apr 30, 2021
dd7a422
In LLVM 12.x setDecl on a DeclRefExpr additionally calls computeDepen…
sulekhark Jul 1, 2021
0a7c9d1
Re-resolved a merge conflict.
sulekhark Jul 1, 2021
c6edde1
Normalize bounds for BoundsDeclFacts (#1113)
kkjeer Jul 1, 2021
41734ad
[BoundsWidening] Gather lower and upper bounds variables separately
Jul 6, 2021
3d2d4dc
[BoundsWidening] Rename variables used in BoundsAnalysis.cpp
Jul 6, 2021
81879f1
[PreorderAST] Add method to compute integer diff between two expressions
Jul 6, 2021
43fe031
[BoundsWidening] Implement the bounds widening dataflow analysis
Jul 6, 2021
dea5aa3
[BoundsWidening] Invoke updated bounds widening methods from SemaBoun…
Jul 7, 2021
0752acf
[BoundsWidening] Update observed bounds with widened bounds
Jul 7, 2021
ea27046
[BoundsWidening] Delete the old bounds widening analysis source files
Jul 7, 2021
d82efdf
Reset the RecoveryAST and the RecoveryASTType options back to Default…
sulekhark Jul 7, 2021
2993259
The StringLiteral unit tests moved from TreeTest.cpp to BuildTreeTest…
sulekhark Jul 7, 2021
d3fdf2e
Frontend produces RecoveryExprs on semantic errors that prevent creat…
sulekhark Jul 7, 2021
a416f34
If there is a semantic error in the controlling expression of a switc…
sulekhark Jul 7, 2021
866c05c
In LLVM/Clang 12.x, a new FixIt hint has been added to diagnose a sin…
sulekhark Jul 7, 2021
ea8ef2c
An nt_checked array with an empty initializer list should be an error…
Jul 7, 2021
5a7de57
Merge branch 'bounds_widening_analysis' into bounds_widening_analysis2
Jul 7, 2021
cf98866
Merge pull request #1065 from correctcomputation/pr-to-microsoft-202105
sulekhark Jul 8, 2021
478fbef
Merge pull request #1122 from microsoft/bounds_widening_analysis2
Jul 9, 2021
b8b3a2e
[BoundsWidening] Dump dataflow sets computed by bounds widening analy…
Jul 12, 2021
33bbf65
In LLVM/Clang 11.x, AllowFold is a boolean parameter to function Veri…
sulekhark Jul 12, 2021
a09d380
In LLVM/Clang 12.x, a range bounds expression or a count bounds expre…
sulekhark Jul 12, 2021
2b4cf24
AvailableFactsAnalysis looks at all Exprs in all basic blocks to see …
sulekhark Jul 12, 2021
d7eb2a4
In CheckVarDecl the initializer should not be processed if it contain…
sulekhark Jul 12, 2021
65a93ec
If the input argument Stmt *S in the Check function in SemaBounds.cpp…
sulekhark Jul 13, 2021
72cc3ab
Handle incomplete types in BaseRange (#1117)
kkjeer Jul 13, 2021
f1bc16a
The cmake variable LLVM_ENABLE_ZLIB is unset in the Windows environme…
sulekhark Jul 15, 2021
34b81da
Merge branch 'master' of github.com:microsoft/checkedc-clang into che…
mattmccutchen-cci Jul 15, 2021
3fd7847
Merge branch 'master' into updated_baseline_master_12
sulekhark Jul 15, 2021
42315ba
Missed adding a commit.
sulekhark Jul 15, 2021
2392c64
Fix for the failing test case: clang-tools-extra/test/clang-tidy/chec…
sulekhark Jul 16, 2021
446a9be
Simple normalizations for +1/-1 bounds scenarios (#1128)
kkjeer Jul 20, 2021
0ddc83c
Invertibility for unchecked pointers (#1127)
kkjeer Jul 20, 2021
49a5696
Restore NormalizeUtils files (#1132)
kkjeer Jul 21, 2021
502a921
In LLVM/Clang 12.x clangd has new code to read configurations from .c…
sulekhark Jul 21, 2021
ceaac40
Relax test expectations in debug-info-gline-tables-only-codeview.cpp
zmodem Jan 28, 2021
6d06cf8
Update NormalizeUtil::TransformAssocLeft (fix Windows X86 failure) (#…
kkjeer Jul 22, 2021
ec87769
Merge branch 'master' into updated_baseline_master_12
sulekhark Jul 22, 2021
4efec47
The function isIntegerConstantExpression of LLVM/Clang 11.x is refact…
sulekhark Jul 22, 2021
2291424
[BoundsWidening] Space improvements for bounds widening (#1131)
Jul 23, 2021
87d1dc7
Merge pull request #1112 from correctcomputation/checkedc-headers-dep
sulekhark Jul 23, 2021
8d3c184
Get variable and constant from upper bounds (#1135)
kkjeer Jul 24, 2021
088d45f
[BoundsWidening] Use invertibility to support bounds widening in loop…
Jul 27, 2021
980321d
[BoundsWidening] Determine checked scope specifier per statement (#1139)
Jul 29, 2021
cf16aee
In LLVM/Clang 12.x, getIntegerConstantExpr returns an Optional<llvm::…
sulekhark Jul 29, 2021
86feac0
Merge branch 'master' into updated_baseline_master_12
sulekhark Jul 29, 2021
26d974e
Removed Windows-style carriage-return characters.
sulekhark Jul 29, 2021
373b5dc
Extract the evaluated integer constant expression into OptConstant an…
sulekhark Aug 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ For more information on Checked C and pointers to example code, see our
## 3C: Semi-automated conversion of C code to Checked C

This repository includes a tool called 3C that partially automates the
conversion of C code to Checked C. Here is [general information about the 3C
software](clang/docs/checkedc/3C/README.md), including development status and
how to contribute. Here are the [usage instructions for the `3c` command-line
tool](clang/tools/3c/README.md).
conversion of C code to Checked C. Quick documentation links:

* [General information](clang/docs/checkedc/3C/README.md), including development
status and how to contribute

* [Build instructions](clang/docs/checkedc/3C/INSTALL.md)

* [Usage instructions for the `3c` command-line tool](clang/tools/3c/README.md)

## More information

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,37 @@
# to test the path mapping, while here, we just use it to facilitate the
# TypeVariableTypeLoc test.

# RUN: valgrind --error-exitcode=1 clangd --compile_args_from=lsp --path-mappings '/test-workspace=%S/Inputs' -lit-test < %s

# Notes on upgrade to LLVM/Clang 12.x:
#
# In LLVM/Clang 12.x, clangd has code in file TidyProvider.cpp that accesses
# uninitialized memory on lines 65 thro' 68 that is allocated in function
# read in file FileCache.cpp. This is happening when clangd is trying to
# read configuration data from .clang-tidy files, with caching. Valgrind
# reports this access of uninitialized memory, causing the test case to fail.
# Additionally, this issue is present only in the release build and not in the
# debug build.
# (Note: The above uninitialized memory access was not present in LLVM 11.x.)
#
# As this is a low priority issue for the Checked C Clang compiler, a temporary
# fix is made as follows:
# Valgrind is invoked with --track-origins=yes. If Valgrind reports any access
# of an uninitialized object, or allocation of an object any of whose fields may
# be uninitialized, or if Valgrind reports any other memory error detected by
# the --memcheck option such that the error is in a function invoked by the
# compiler frontend, then this test case will fail. If the issue reported by
# Valgrind is in a function not invoked by the compiler frontend, this test
# case will pass.
#
# TODO: Need to fix the above uninitialized memory access in clangd.
#
# RUN: valgrind --track-origins=yes clangd --compile_args_from=lsp --path-mappings '/test-workspace=%S/Inputs' -lit-test < %s 2>&1 | FileCheck %s

{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
---
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///test-workspace/checkedc-typevariabletypeloc-uninit.c","languageId":"c","version":1,"text":"#include \"checkedc-typevariabletypeloc-uninit.h\""}}}

# CHECK-NOT: clang::FrontendAction::Execute()
---
{"jsonrpc":"2.0","id":2,"method":"shutdown"}
---
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/test/clang-tidy/check_clang_tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def run_test_once(args, extra_args):
# implementations of relevant APIs.
clang_extra_args.append('-nostdinc++')

# clang-tidy does not yet support code in Checked C.
clang_extra_args.append('-fno-checkedc-extension')

if resource_dir is not None:
clang_extra_args.append('-resource-dir=%s' % resource_dir)

Expand Down
52 changes: 52 additions & 0 deletions clang/docs/checkedc/3C/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,58 @@ in subdirectories, so `*.c` will not pick up all of them; instead you
can use `llvm-lit -vv .` to specify all test files under the current
directory.

### Diagnostic verification

3C supports the standard Clang diagnostic verifier
([`VerifyDiagnosticConsumer`](https://clang.llvm.org/doxygen/classclang_1_1VerifyDiagnosticConsumer.html#details))
for testing errors and warnings reported by 3C via its main `DiagnosticsEngine`.
(Some 3C errors and warnings are reported via other means and cannot be tested
this way; the best solution we have for them right now is to `grep` the stderr
of 3C.) Diagnostic verification can be enabled via the usual `-Xclang -verify`
compiler option; other diagnostic verification options (`-Xclang
-verify=PREFIX`, etc.) should also work as normal. These must be passed as
_compiler_ options, not `3c` options; for example, if you are using `--` on the
`3c` command line, these options must be passed _after_ the `--`.

Some notes about diagnostic verification in the context of 3C:

* Parsing of the source files uses some of the compiler logic and thus may
generate compiler warnings, just as if you ran `clang` on the code. These are
sent to the diagnostic verifier along with diagnostics generated by 3C's
analysis. If you find it distracting to have to include the compiler warnings
in the set of expected diagnostics for a test, you can turn them off via the
`-Wno-everything` compiler option (which does not affect diagnostics generated
by 3C's analysis).

* The `3c` tool works in several passes, where each pass runs on all translation
units: first `3c` parses the source files, then it runs several passes of
analysis. If a pass encounters at least one error, `3c` exits at the end of
that pass. Diagnostic verification does not change the _point_ at which `3c`
exits, but it changes the exit _code_ to indicate the result of verification
rather than the presence of errors. The verification includes the diagnostics
from all passes up to the point at which `3c` exits (i.e., the same
diagnostics that would be displayed if verification were not used). However,
an error that doesn't go via the main `DiagnosticsEngine` will cause an
unsuccessful exit code regardless of diagnostic verification. (This is
typically the behavior you want for a test.)

* Diagnostic verification is independent for each translation unit, so in tests
with multiple translation units, you'll have to be careful that preprocessing
of each translation unit sees the correct set of `expected-*` directives for
the diagnostics generated for that translation unit (or an
`expected-no-diagnostics` directive if that translation unit generates no
diagnostics, even if other translation units do generate diagnostics). Be
warned that since which translation unit generated a given diagnostic isn't
visible to a normal user, we don't put much work into coming up with sensible
rules for this, but it should at least be deterministic for testing.

Note that some 3C tests use diagnostic verification on calls to `clang` rather
than `3c`, so if you see `expected-*` directives in a test, you can look at the
`RUN` commands to see which command has `-Xclang -verify` and is using the
directives. If you want to verify diagnostics of more than one `RUN` command in
the same test, you can use different directive prefixes (`-Xclang
-verify=PREFIX`).

## Coding guidelines

Please follow [LLVM coding
Expand Down
3 changes: 2 additions & 1 deletion clang/docs/checkedc/3C/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ https://github.com/correctcomputation/checkedc-clang or
https://github.com/microsoft/checkedc-clang (or, of course, a
third-party fork, though we can't be responsible for that). Assuming
you have already cloned one of these repositories, run the following
(from the root of the working tree) for a basic build:
(from the `checkedc-clang` directory or whatever you named your clone)
for a basic build:

```
# Get a copy of the Checked C system headers. Use Microsoft's
Expand Down
42 changes: 32 additions & 10 deletions clang/include/clang/3C/3C.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct _3COptions {

bool AddCheckedRegions;

bool DisableCCTypeChecker;
bool EnableCCTypeChecker;

bool WarnRootCause;

Expand All @@ -68,11 +68,6 @@ struct _3COptions {
bool ForceItypes;
#endif

// Currently applies only to the rewriting phase (because it is the only phase
// that generates diagnostics, except for the declaration merging diagnostics
// that are currently fatal) and uses the default "expected" prefix.
bool VerifyDiagnosticOutput;

bool DumpUnwritableChanges;
bool AllowUnwritableChanges;

Expand Down Expand Up @@ -104,7 +99,15 @@ class _3CInterface {
const std::vector<std::string> &SourceFileList,
clang::tooling::CompilationDatabase *CompDB);

// Constraint Building.
~_3CInterface();

// Call clang to provide the data
bool parseASTs();

// Constraints

// Create ConstraintVariables to hold constraints
bool addVariables();

// Build initial constraints.
bool buildInitialConstraints();
Expand All @@ -131,13 +134,32 @@ class _3CInterface {
// Write all converted versions of the files in the source file list
// to disk
bool writeAllConvertedFilesToDisk();
// Write the current converted state of the provided file.
bool writeConvertedFileToDisk(const std::string &FilePath);

// Dump all stats related to performance.
bool dumpStats();

// Determine the exit code that the `3c` tool should exit with after the last
// 3C stage, considering diagnostic verification. Must be called exactly once
// before the _3CInterface is destructed (unless construction failed).
int determineExitCode();

private:
_3CInterface(const struct _3COptions &CCopt,
const std::vector<std::string> &SourceFileList,
clang::tooling::CompilationDatabase *CompDB, bool &Failed);
clang::tooling::CompilationDatabase *CompDB);

bool ConstructionFailed = false;
bool DeterminedExitCode = false;

bool HadNonDiagnosticError = false;

// Determine whether 3C can continue to the next stage of processing. Checks
// HadNonDiagnosticError and error diagnostics but ignores diagnostic
// verification.
bool isSuccessfulSoFar();

// saved ASTs
std::vector<std::unique_ptr<ASTUnit>> ASTs;

// Are constraints already built?
bool ConstraintsBuilt;
Expand Down
108 changes: 108 additions & 0 deletions clang/include/clang/3C/3CStats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//=--3CStats.h----------------------------------------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// This class contains all the stats related to the conversion computed by 3C.
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_3C_3CSTATS_H
#define LLVM_CLANG_3C_3CSTATS_H

#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "llvm/Support/raw_ostream.h"

class PerformanceStats {
public:
double CompileTime;
double ConstraintBuilderTime;
double ConstraintSolverTime;
double ArrayBoundsInferenceTime;
double RewritingTime;
double TotalTime;

// Rewrite Stats
unsigned long NumAssumeBoundsCasts;
unsigned long NumCheckedCasts;
unsigned long NumWildCasts;
unsigned long NumFixedCasts;
unsigned long NumITypes;
unsigned long NumCheckedRegions;
unsigned long NumUnCheckedRegions;

PerformanceStats() {
CompileTime = ConstraintBuilderTime = 0;
ConstraintSolverTime = ArrayBoundsInferenceTime = 0;
RewritingTime = TotalTime = 0;

CompileTimeSt = ConstraintBuilderTimeSt = 0;
ConstraintSolverTimeSt = ArrayBoundsInferenceTimeSt = 0;
RewritingTimeSt = TotalTimeSt = 0;

NumAssumeBoundsCasts = NumCheckedCasts = 0;
NumWildCasts = NumITypes = NumFixedCasts = 0;

NumCheckedRegions = NumUnCheckedRegions = 0;
}

void startCompileTime();
void endCompileTime();

void startConstraintBuilderTime();
void endConstraintBuilderTime();

void startConstraintSolverTime();
void endConstraintSolverTime();

void startArrayBoundsInferenceTime();
void endArrayBoundsInferenceTime();

void startRewritingTime();
void endRewritingTime();

void startTotalTime();
void endTotalTime();

void incrementNumAssumeBounds();
void incrementNumCheckedCasts();
void incrementNumWildCasts();
void incrementNumFixedCasts();
void incrementNumITypes();
void incrementNumCheckedRegions();
void incrementNumUnCheckedRegions();

void printPerformanceStats(llvm::raw_ostream &O, bool JsonFormat);

private:
clock_t CompileTimeSt;
clock_t ConstraintBuilderTimeSt;
clock_t ConstraintSolverTimeSt;
clock_t ArrayBoundsInferenceTimeSt;
clock_t RewritingTimeSt;
clock_t TotalTimeSt;
};

class ProgramInfo;

// Class to record stats by visiting AST.
class StatsRecorder : public clang::RecursiveASTVisitor<StatsRecorder> {
public:
explicit StatsRecorder(clang::ASTContext *C, ProgramInfo *I)
: Context(C), Info(I) {}

bool VisitCompoundStmt(clang::CompoundStmt *S);
bool VisitDecl(clang::Decl *D);
bool VisitCStyleCastExpr(clang::CStyleCastExpr *C);
bool VisitBoundsCastExpr(clang::BoundsCastExpr *B);

private:
clang::ASTContext *Context;
ProgramInfo *Info;
};

#endif // LLVM_CLANG_3C_3CSTATS_H
Loading