Skip to content

Commit 9d329e1

Browse files
authored
Merge pull request #1218 from souragc/main
Update documentation
2 parents 5fbb73a + 4936054 commit 9d329e1

File tree

3 files changed

+153
-122
lines changed

3 files changed

+153
-122
lines changed
Lines changed: 131 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# Contributing to 3C
22

3-
Issues and pull requests related to 3C should be submitted to [CCI's
4-
`checkedc-clang`
5-
repository](https://github.com/correctcomputation/checkedc-clang), not
6-
[Microsoft's](https://github.com/microsoft/checkedc-clang), except as
7-
stated below.
3+
Issues and pull requests related to 3C should be submitted to
4+
[checkedc](https://github.com/checkedc/checkedc-llvm-project) repo.
85

96
## Issues
107

@@ -28,39 +25,133 @@ able to use your work yourself (subject to your ability to keep up
2825
with us) and we may even direct users who want the functionality to
2926
your version.
3027

31-
If your contribution does not touch any 3C-specific code (or is a
32-
codebase-wide cleanup of low risk to 3C) and you can reasonably submit
33-
it to [Microsoft's
34-
repository](https://github.com/microsoft/checkedc-clang) instead, we
35-
generally prefer that you do so. If such a contribution has particular
36-
benefit to 3C, feel free to let us know, and we may assist you in
37-
getting your contribution accepted upstream and/or ensure it is merged
38-
quickly to CCI's repository.
39-
40-
If the previous paragraph does not apply, just submit a pull request
41-
to CCI's repository. You must grant the same license on your
42-
contribution as the existing codebase. We do not have a formal
43-
contributor license agreement (CLA) process at this time, but we may
28+
You must grant the same license on your contribution as the existing codebase.
29+
We do not have a formal contributor license agreement (CLA) process at this time, but we may
4430
set one up and require you to complete it before we accept your
45-
contribution. Also be aware that we need to keep 5C ([our proprietary
46-
extension of
47-
3C](README.md#what-3c-users-should-know-about-the-development-process))
48-
working, so you may have to wait for us to address 5C-specific
49-
problems arising from your 3C pull request and/or we may ask you to
50-
make specific changes to your pull request to accommodate 5C's code.
51-
52-
At the appropriate time during development of a pull request, please
53-
run the [regression tests](development.md#regression-tests) and
54-
correct any failures. (For example, it may not make sense to do this
55-
on a draft pull request containing an unfinished demonstration of an
56-
idea.) All regression tests must pass (or be disabled if appropriate)
57-
before your pull request can be merged. If you're changing behavior
58-
(as opposed to just cleaning up the code), we'll typically require you
59-
to add or update enough tests to exercise the important behavior
60-
changes (i.e., those tests fail before your code change and pass after
61-
it). If there's a concern that your change might affect other cases
62-
that are not adequately tested yet, we may ask you to add tests for
63-
those cases as well.
64-
65-
See the [developer's guide](development.md) for additional information
66-
that may be helpful as you work on 3C.
31+
contribution.
32+
33+
## Testing
34+
35+
3C has a regression test suite located in `clang/test/3C`. At the
36+
appropriate time during development of a pull request, please run it
37+
and correct any failures. (For example, it may not make sense to run
38+
it on a draft pull request containing an unfinished demonstration of
39+
an idea.) The easiest way to run it is to run the following in your
40+
build directory:
41+
42+
```
43+
ninja check-3c
44+
```
45+
46+
This command will build everything needed that hasn't already been
47+
built, run the test suite, report success or failure (exit 0 or 1, so
48+
you can use it in scripts), and display some information about any
49+
failures, which may or may not be enough for you to understand what
50+
went wrong.
51+
52+
For deeper troubleshooting, run the following in your build directory
53+
to build all dependencies of the test suite:
54+
55+
```
56+
ninja check-3c-deps
57+
```
58+
59+
Then run the following in the `clang/test/3C` directory:
60+
61+
```
62+
llvm-lit -vv TEST.c
63+
```
64+
65+
where `TEST.c` is the path of the test you want to run (you can also
66+
specify more than one test). This assumes you've put the `bin`
67+
subdirectory of your build directory on your `$PATH` or arranged some
68+
other means of running `llvm-lit` from there. The first `-v` makes
69+
`llvm-lit` display the stdout and stderr of failed tests; the second
70+
makes it display the `RUN` commands as they execute so you can tell
71+
which one failed.
72+
73+
Every `.c` file under `clang/test/3C` is a test file. There are a few
74+
in subdirectories, so `*.c` will not pick up all of them; instead you
75+
can use `llvm-lit -vv .` to specify all test files under the current
76+
directory.
77+
78+
### Diagnostic verification
79+
80+
3C supports the standard Clang diagnostic verifier
81+
([`VerifyDiagnosticConsumer`](https://clang.llvm.org/doxygen/classclang_1_1VerifyDiagnosticConsumer.html#details))
82+
for testing errors and warnings reported by 3C via its main `DiagnosticsEngine`.
83+
(Some 3C errors and warnings are reported via other means and cannot be tested
84+
this way; the best solution we have for them right now is to `grep` the stderr
85+
of 3C.) Diagnostic verification can be enabled via the usual `-Xclang -verify`
86+
compiler option; other diagnostic verification options (`-Xclang
87+
-verify=PREFIX`, etc.) should also work as normal. These must be passed as
88+
_compiler_ options, not `3c` options; for example, if you are using `--` on the
89+
`3c` command line, these options must be passed _after_ the `--`.
90+
91+
Some notes about diagnostic verification in the context of 3C:
92+
93+
* Parsing of the source files uses some of the compiler logic and thus may
94+
generate compiler warnings, just as if you ran `clang` on the code. These are
95+
sent to the diagnostic verifier along with diagnostics generated by 3C's
96+
analysis. If you find it distracting to have to include the compiler warnings
97+
in the set of expected diagnostics for a test, you can turn them off via the
98+
`-Wno-everything` compiler option (which does not affect diagnostics generated
99+
by 3C's analysis).
100+
101+
* The `3c` tool works in several passes, where each pass runs on all translation
102+
units: first `3c` parses the source files, then it runs several passes of
103+
analysis. If a pass encounters at least one error, `3c` exits at the end of
104+
that pass. Diagnostic verification does not change the _point_ at which `3c`
105+
exits, but it changes the exit _code_ to indicate the result of verification
106+
rather than the presence of errors. The verification includes the diagnostics
107+
from all passes up to the point at which `3c` exits (i.e., the same
108+
diagnostics that would be displayed if verification were not used). However,
109+
an error that doesn't go via the main `DiagnosticsEngine` will cause an
110+
unsuccessful exit code regardless of diagnostic verification. (This is
111+
typically the behavior you want for a test.)
112+
113+
* Diagnostic verification is independent for each translation unit, so in tests
114+
with multiple translation units, you'll have to be careful that preprocessing
115+
of each translation unit sees the correct set of `expected-*` directives for
116+
the diagnostics generated for that translation unit (or an
117+
`expected-no-diagnostics` directive if that translation unit generates no
118+
diagnostics, even if other translation units do generate diagnostics). Be
119+
warned that since which translation unit generated a given diagnostic isn't
120+
visible to a normal user, we don't put much work into coming up with sensible
121+
rules for this, but it should at least be deterministic for testing.
122+
123+
Note that some 3C tests use diagnostic verification on calls to `clang` rather
124+
than `3c`, so if you see `expected-*` directives in a test, you can look at the
125+
`RUN` commands to see which command has `-Xclang -verify` and is using the
126+
directives. If you want to verify diagnostics of more than one `RUN` command in
127+
the same test, you can use different directive prefixes (`-Xclang
128+
-verify=PREFIX`).
129+
130+
## Coding guidelines
131+
132+
Please follow [LLVM coding
133+
standards](https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly)
134+
in your code. Specifically:
135+
136+
* The maximum length of a line: 80 chars
137+
138+
* All comments should start with a Capital letter.
139+
140+
* All Local variables, including fields and parameters, should start
141+
with a Capital letter (similar to PascalCase). Short names are
142+
preferred.
143+
144+
* A space between the conditional keyword and `(` i.e., `if (`,
145+
`while (`, ``for (` etc.
146+
147+
* Space after the type name, i.e., `Type *K` _not_ `Type* K`.
148+
149+
* Space before and after `:` in iterators, i.e., `for (auto &k : List)`
150+
151+
Our goal is that all files should be formatted with `clang-format` and
152+
pass `clang-tidy` ([more information](clang-tidy.md)), and nonempty
153+
files should have a final newline (surprisingly, `clang-format` cannot
154+
enforce this). However, until we have better automation, we decided it
155+
isn't reasonable to require contributors to manually run these tools
156+
and fix style nits in each change; instead, we periodically run the
157+
tools on the entire 3C codebase.

clang/docs/checkedc/3C/INSTALL.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@ fiddly](#mac-os-x), but we have managed it so far.
1919

2020
## Basics
2121

22-
As described [here](README.md#which-checkedc-clang-repository-to-use),
23-
you can use either
24-
https://github.com/correctcomputation/checkedc-clang or
25-
https://github.com/microsoft/checkedc-clang (or, of course, a
22+
Start by cloning [checkedc](https://github.com/checkedc/checkedc-llvm-project) repo (or, of course, a
2623
third-party fork, though we can't be responsible for that). Assuming
2724
you have already cloned one of these repositories, run the following
28-
(from the `checkedc-clang` directory or whatever you named your clone)
25+
(from the `checkedc-llvm-project` directory or whatever you named your clone)
2926
for a basic build:
3027

3128
```
3229
# Get a copy of the Checked C system headers. Use Microsoft's
33-
# "checkedc" repository regardless of which "checkedc-clang"
30+
# "checkedc" repository regardless of which "checkedc-llvm-project"
3431
# repository you use.
3532
git clone https://github.com/microsoft/checkedc llvm/projects/checkedc-wrapper/checkedc
3633

clang/docs/checkedc/3C/README.md

Lines changed: 19 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,94 +12,37 @@ safety.
1212
This document describes 3C in general. Here are the [build
1313
instructions](INSTALL.md). The inference logic is implemented in the
1414
[`clang/lib/3C` directory](../../../lib/3C) in the form of a library
15-
that can potentially be used in multiple contexts. As of November
16-
2020, the only way to use 3C is via the `3c` command line tool in the
15+
that can potentially be used in multiple contexts.
16+
17+
There are two ways to
18+
use 3C.
19+
- The first method is using the command line tool `3c`
1720
[`clang/tools/3c` directory](../../../tools/3c); its usage is
1821
documented in [the readme there](../../../tools/3c/README.md).
22+
- The second method is to use a vscode extension along with
23+
clangd lsp plugin. Steps to build and use the plugin can be
24+
found [here](https://3clsp.github.io/). Note that 3CLSP is based on
25+
an older fork and therefore won't have the latest changes to 3C.
1926

2027
## What 3C users should know about the development process
2128

22-
Checked C development as a whole is led by Microsoft in the
23-
https://github.com/microsoft/checkedc-clang repository. 3C is included
24-
in the Checked C codebase, but 3C development is led by [Correct
25-
Computation, Inc.](https://correctcomputation.com/) (CCI) in the
26-
https://github.com/correctcomputation/checkedc-clang repository, which
27-
is a fork of Microsoft's repository; changes are periodically merged
28-
back and forth. (That is, CCI plays roughly the role of a ["subsystem
29-
maintainer"](https://www.kernel.org/doc/html/latest/process/2.Process.html#how-patches-get-into-the-kernel)
30-
for 3C, for those familiar with that term from Linux kernel
31-
development.) Both 3C and the rest of the Checked C tools (including
32-
the compiler) are available in both repositories, but the repositories
33-
will generally have different versions of different parts of the code
34-
at any given time, so [you'll have to decide which repository is more
35-
suitable for your work](#which-checkedc-clang-repository-to-use).
29+
The development of Checked C exclusively takes place in the repository
30+
located at https://github.com/checkedc/checkedc-llvm-project. 3C is included
31+
in the Checked C codebase. Initially 3C development was led by [Correct
32+
Computation, Inc.](https://correctcomputation.com/). As of now, 3C is
33+
integrated into [checkedc](https://github.com/checkedc/checkedc-llvm-project)
34+
checkedc-llvm-project repo and all furthur development will be in
35+
[checked](https://github.com/checkedc/checkedc-llvm-project) repo.
3636

37-
Issues and pull requests related to 3C should be submitted to CCI's
37+
Issues and pull requests related to 3C should be submitted to
38+
[checkedc](https://github.com/checkedc/checkedc-llvm-project)
3839
repository; see [CONTRIBUTING.md](CONTRIBUTING.md) for more
3940
information.
4041

4142
As of March 2021, 3C is pre-alpha quality and we are just starting to
42-
establish its public presence and processes. CCI is also working on a
43-
proprietary extension of 3C called 5C ("**C**orrect **C**omputation's
44-
**C**hecked-**C**-**C**onvert"). Our current plan is that 3C will
45-
contain the core inference logic, while 5C will add features to
46-
enhance developer productivity. If you'd like more information about
47-
5C, please contact us at [email protected].
48-
49-
### Which `checkedc-clang` repository to use?
50-
51-
We typically recommend that serious 3C users use CCI's repository to
52-
get 3C fixes and enhancements sooner, but in some scenarios, you may
53-
be better off with Microsoft's repository. Here, in detail, are the
54-
factors we can think of that might affect your decision (as of March
55-
2021):
56-
57-
- CCI strives to merge changes reasonably quickly from Microsoft's
58-
repository to CCI's, but most 3C-specific changes are made first in
59-
CCI's repository and merged to Microsoft's in batches every few
60-
months. Thus, CCI's repository typically gives you a significantly
61-
newer version of 3C, while Microsoft's repository typically gives
62-
you a somewhat newer version of the rest of the Checked C codebase,
63-
including some shared code used by 3C. The implication of that last
64-
point is that a fix to the shared code in Microsoft's repository
65-
would benefit Microsoft's copy of 3C immediately but would not take
66-
effect on CCI's copy until the next merge from Microsoft to CCI, so
67-
CCI's copy of 3C is not always newer in _all_ respects.
68-
69-
- While the [3C regression tests](CONTRIBUTING.md#testing) are run on
70-
every change to either repository, CCI's copy of 3C undergoes
71-
additional testing: a set of "benchmark" tests that run nightly,
72-
plus manual use by CCI engineers. If a change to CCI's repository
73-
passes the regression tests but breaks the additional tests, we will
74-
generally fix the problem quickly. But if the same happens in
75-
Microsoft's repository, functionality of Microsoft's copy of 3C that
76-
is not covered by the regression tests could remain broken for some
77-
time. The problem would likely be detected the next time CCI tries
78-
to merge from Microsoft, in which case we would try to get a fix
79-
into Microsoft's repository reasonably quickly.
80-
81-
- The 3C regression tests are run regularly on Windows on Microsoft's
82-
repository but not on CCI's. A change that breaks the regression
83-
tests on Windows generally won't be made to Microsoft's repository,
84-
but such a change could be made to CCI's and the problem may not be
85-
detected until the next time CCI tries to merge to Microsoft (or a
86-
user reports the problem to us). So you're less likely to encounter
87-
Windows-specific problems with Microsoft's repository.
88-
89-
- On the other hand, some CCI engineers work on Mac OS X and
90-
frequently run the regression tests and other manual tests on CCI's
91-
copy of 3C on Mac OS X, while we are unaware of any testing of
92-
Microsoft's copy of 3C on Mac OS X. So you may be less likely to
93-
encounter Mac-specific problems with CCI's repository. But so far,
94-
when we've seen Mac-specific problems, we've usually gotten a fix
95-
into Microsoft's repository reasonably quickly.
43+
establish its public presence and processes.
9644

9745
As noted in the [setup instructions](INSTALL.md#basics), both 3C and
9846
the Checked C compiler depend on the Checked C system headers, which
9947
Microsoft maintains in [a subdirectory of a separate repository named
10048
`checkedc`](https://github.com/microsoft/checkedc/tree/master/include).
101-
CCI has [a fork of this
102-
repository](https://github.com/correctcomputation/checkedc), but
103-
currently it is used only for submitting changes to Microsoft. All
104-
users should use Microsoft's `checkedc` repository regardless of which
105-
`checkedc-clang` repository they use.

0 commit comments

Comments
 (0)