Skip to content

Commit ff245c1

Browse files
3C documentation update pass 2021-02 (#438)
1 parent 76e5061 commit ff245c1

File tree

4 files changed

+240
-97
lines changed

4 files changed

+240
-97
lines changed

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

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Contributing to 3C
22

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

98
## Issues
@@ -30,19 +29,20 @@ your version.
3029

3130
If your contribution does not touch any 3C-specific code (or is a
3231
codebase-wide cleanup of low risk to 3C) and you can reasonably submit
33-
it to [Microsoft's Checked C
32+
it to [Microsoft's
3433
repository](https://github.com/microsoft/checkedc-clang) instead, we
3534
generally prefer that you do so. If such a contribution has particular
3635
benefit to 3C, feel free to let us know, and we may assist you in
3736
getting your contribution accepted upstream and/or ensure it is merged
3837
quickly to CCI's repository.
3938

4039
If the previous paragraph does not apply, just submit a pull request
41-
here. You must grant the same license on your contribution as the
42-
existing codebase. We do not have a formal contributor license
43-
agreement (CLA) process at this time, but we may set one up and
44-
require you to complete it before we accept your contribution. Also be
45-
aware that we need to keep 5C ([our proprietary extension of
40+
to CCI's repository. You must grant the same license on your
41+
contribution as the existing codebase. We do not have a formal
42+
contributor license agreement (CLA) process at this time, but we may
43+
set one up and require you to complete it before we accept your
44+
contribution. Also be aware that we need to keep 5C ([our proprietary
45+
extension of
4646
3C](README.md#what-3c-users-should-know-about-the-development-process))
4747
working, so you may have to wait for us to address 5C-specific
4848
problems arising from your 3C pull request and/or we may ask you to
@@ -58,7 +58,7 @@ an idea.) The easiest way to run it is to run the following in your
5858
build directory:
5959

6060
```
61-
ninja check-clang-3c
61+
ninja check-3c
6262
```
6363

6464
This command will build everything needed that hasn't already been
@@ -67,6 +67,32 @@ you can use it in scripts), and display some information about any
6767
failures, which may or may not be enough for you to understand what
6868
went wrong.
6969

70+
For deeper troubleshooting, run the following in your build directory
71+
to build all dependencies of the test suite:
72+
73+
```
74+
ninja check-3c-deps
75+
```
76+
77+
Then run the following in the `clang/test/3C` directory:
78+
79+
```
80+
llvm-lit -vv TEST.c
81+
```
82+
83+
where `TEST.c` is the path of the test you want to run (you can also
84+
specify more than one test). This assumes you've put the `bin`
85+
subdirectory of your build directory on your `$PATH` or arranged some
86+
other means of running `llvm-lit` from there. The first `-v` makes
87+
`llvm-lit` display the stdout and stderr of failed tests; the second
88+
makes it display the `RUN` commands as they execute so you can tell
89+
which one failed.
90+
91+
Every `.c` file under `clang/test/3C` is a test file. There are a few
92+
in subdirectories, so `*.c` will not pick up all of them; instead you
93+
can use `llvm-lit -vv .` to specify all test files under the current
94+
directory.
95+
7096
## Coding guidelines
7197

7298
Please follow [LLVM coding
@@ -88,6 +114,10 @@ in your code. Specifically:
88114

89115
* Space before and after `:` in iterators, i.e., `for (auto &k : List)`
90116

91-
All files should be formatted with `clang-format` and pass `clang-tidy` ([more
92-
information](clang-tidy.md)), and nonempty files should have a final newline
93-
(surprisingly, `clang-format` cannot enforce this).
117+
Our goal is that all files should be formatted with `clang-format` and
118+
pass `clang-tidy` ([more information](clang-tidy.md)), and nonempty
119+
files should have a final newline (surprisingly, `clang-format` cannot
120+
enforce this). However, until we have better automation, we decided it
121+
isn't reasonable to require contributors to manually run these tools
122+
and fix style nits in each change; instead, we periodically run the
123+
tools on the entire 3C codebase.

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

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,45 @@ documentation as appropriate.
99

1010
## Supported environments
1111

12-
We work primarily on Linux. Checked C supports Windows, but we do not
13-
test 3C regularly on Windows. Some of us use Mac OS X, which Checked C
14-
does not officially support; we have gotten 3C to mostly work with
15-
some additional steps (see below), but there are some known problems
16-
and [Microsoft is still considering whether to work with us to address
17-
them](https://github.com/microsoft/checkedc/issues/424#issuecomment-720648442).
12+
We aim to support Linux, Windows, and Mac OS X. We do most of our work
13+
on Linux and test the other OSes less frequently ([additional
14+
information](README.md#which-checkedc-clang-repository-to-use)), so
15+
you are more likely to run into problems on the other OSes; if you do,
16+
please [file an issue](CONTRIBUTING.md#issues) and we will try to fix
17+
it if it is severe enough. Getting 3C to work on Mac OS X [can be
18+
fiddly](#mac-os-x), but we have managed it so far.
1819

1920
## Basics
2021

21-
Assuming you have already cloned the `checkedc-clang` repository, run
22-
the following (from the root of the working tree) for a basic build:
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
26+
third-party fork, though we can't be responsible for that). Assuming
27+
you have already cloned one of these repositories, run the following
28+
(from the root of the working tree) for a basic build:
2329

2430
```
25-
(cd llvm/projects/checkedc-wrapper && git clone https://github.com/microsoft/checkedc)
31+
# Get a copy of the Checked C system headers. Use Microsoft's
32+
# "checkedc" repository regardless of which "checkedc-clang"
33+
# repository you use.
34+
git clone https://github.com/microsoft/checkedc llvm/projects/checkedc-wrapper/checkedc
2635
2736
mkdir build && cd build
2837
cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS=clang
2938
ninja TARGET
3039
```
3140

32-
where TARGET stands for the target(s) you want to build. For the `3c`
33-
command-line tool, the target is `3c`, but assuming you want to
41+
where `TARGET` stands for the target(s) you want to build. For the
42+
`3c` command-line tool, the target is `3c`, but assuming you want to
3443
actually compile the Checked C source files generated by 3C, you'll
3544
also want to build `clang` (the Checked C compiler, which is a
3645
modified version of Clang). Executables will end up in `build/bin`;
37-
you'll likely want to add this directory to your `$PATH`.
46+
you'll likely want to add this directory to your `$PATH` or write
47+
suitable wrapper scripts.
48+
49+
Here is [how to use the `3c` tool](../../../tools/3c/README.md) once
50+
you build it.
3851

3952
## Build options
4053

@@ -62,6 +75,10 @@ may reduce the build time and/or peak memory use:
6275

6376
- Pass `-DLLVM_OPTIMIZED_TABLEGEN=ON`.
6477

78+
- Pass `-DLLVM_APPEND_VC_REV=OFF` to turn off embedding of your Git
79+
head commit ID in the executables and thus avoid the need to re-link
80+
all of them every time the commit ID changes.
81+
6582
(The reference for improving build performance is [this LLVM
6683
page](https://www.llvm.org/docs/GettingStarted.html#common-problems),
6784
but we have attempted to describe the most promising options here.)
@@ -84,23 +101,3 @@ https://developer.apple.com/download/more/, log in with your Apple
84101
Developer ID, and download "Command Line Tools for Xcode 11.3.1".
85102
Then, enable these by invoking (from the command line), `sudo
86103
xcode-select -r`.
87-
88-
## CR/LF issues
89-
90-
There is a [known
91-
problem](https://github.com/correctcomputation/checkedc-clang/issues/317)
92-
where git shows source files in a clean checkout as having modified
93-
line endings, even if you only ever use Linux. The problem seems to
94-
occur less often with newer versions of git. We believe the root cause
95-
is that [the root `.gitattributes` file](../../../../.gitattributes)
96-
inaccurately states that all files have LF endings, but some have CRLF
97-
endings in the repository; we will try to fix that when we can. In the
98-
meantime, running the following commands in a working tree that is
99-
experiencing the problem seems to make it go away, at least
100-
temporarily:
101-
102-
```
103-
git rm .gitattributes
104-
git status
105-
git checkout HEAD -- .gitattributes
106-
```

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

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,88 @@ some point.
2323

2424
## What 3C users should know about the development process
2525

26-
Development of 3C is led by [Correct Computation,
27-
Inc.](https://correctcomputation.com/) (CCI) in the
26+
Checked C development as a whole is led by Microsoft in the
27+
https://github.com/microsoft/checkedc-clang repository. 3C is included
28+
in the Checked C codebase, but 3C development is led by [Correct
29+
Computation, Inc.](https://correctcomputation.com/) (CCI) in the
2830
https://github.com/correctcomputation/checkedc-clang repository, which
29-
is a fork of Microsoft's Checked C repository
30-
(https://github.com/microsoft/checkedc-clang). Issues and pull
31-
requests related to 3C should be submitted to the CCI repository; see
32-
[CONTRIBUTING.md](CONTRIBUTING.md) for more information. Changes are
33-
merged frequently from Microsoft's repository to CCI's and less
34-
frequently in the opposite direction. While some automated tests of 3C
35-
are run in Microsoft's repository, the coverage of these tests is
36-
currently mediocre, so changes to Microsoft's repository may break
37-
some functionality of its copy of 3C. Thus, users of 3C can choose
38-
either CCI's repository (for the latest 3C with a somewhat older
39-
Checked C) or Microsoft's (for the latest Checked C with 3C that is
40-
significantly older and possibly broken). This workflow may change in
41-
the future.
42-
43-
As of November 2020, 3C is pre-alpha quality and we are just starting
31+
is a fork of Microsoft's repository; changes are periodically merged
32+
back and forth. (That is, CCI plays roughly the role of a ["subsystem
33+
maintainer"](https://www.kernel.org/doc/html/latest/process/2.Process.html#how-patches-get-into-the-kernel)
34+
for 3C, for those familiar with that term from Linux kernel
35+
development.) Both 3C and the rest of the Checked C tools (including
36+
the compiler) are available in both repositories, but the repositories
37+
will generally have different versions of different parts of the code
38+
at any given time, so [you'll have to decide which repository is more
39+
suitable for your work](#which-checkedc-clang-repository-to-use).
40+
41+
Issues and pull requests related to 3C should be submitted to CCI's
42+
repository; see [CONTRIBUTING.md](CONTRIBUTING.md) for more
43+
information.
44+
45+
As of March 2021, 3C is pre-alpha quality and we are just starting
4446
to establish its public presence and processes. CCI is also working on
4547
a proprietary extension of 3C called 5C ("**C**orrect
4648
**C**omputation's **C**hecked-**C**-**C**onvert"). Our current plan is
4749
that 3C will contain the core inference logic, while 5C will add
4850
features to enhance developer productivity. If you'd like more
4951
information about 5C, please contact us at
5052
53+
54+
### Which `checkedc-clang` repository to use?
55+
56+
We typically recommend that serious 3C users use CCI's repository to
57+
get 3C fixes and enhancements sooner, but in some scenarios, you may
58+
be better off with Microsoft's repository. Here, in detail, are the
59+
factors we can think of that might affect your decision (as of
60+
March 2021):
61+
62+
- CCI strives to merge changes reasonably quickly from Microsoft's
63+
repository to CCI's, but most 3C-specific changes are made first in
64+
CCI's repository and merged to Microsoft's in batches every few
65+
months. Thus, CCI's repository typically gives you a significantly
66+
newer version of 3C, while Microsoft's repository typically gives
67+
you a somewhat newer version of the rest of the Checked C codebase,
68+
including some shared code used by 3C. The implication of that last
69+
point is that a fix to the shared code in Microsoft's repository
70+
would benefit Microsoft's copy of 3C immediately but would not take
71+
effect on CCI's copy until the next merge from Microsoft to CCI, so
72+
CCI's copy of 3C is not always newer in _all_ respects.
73+
74+
- While the [3C regression tests](CONTRIBUTING.md#testing) are run on
75+
every change to either repository, CCI's copy of 3C undergoes
76+
additional testing: a set of "benchmark" tests that run nightly,
77+
plus manual use by CCI engineers. If a change to CCI's repository
78+
passes the regression tests but breaks the additional tests, we will
79+
generally fix the problem quickly. But if the same happens in
80+
Microsoft's repository, functionality of Microsoft's copy of 3C that
81+
is not covered by the regression tests could remain broken for some
82+
time. The problem would likely be detected the next time CCI tries
83+
to merge from Microsoft, in which case we would try to get a fix
84+
into Microsoft's repository reasonably quickly.
85+
86+
- The 3C regression tests are run regularly on Windows on Microsoft's
87+
repository but not on CCI's. A change that breaks the regression
88+
tests on Windows generally won't be made to Microsoft's repository,
89+
but such a change could be made to CCI's and the problem may not be
90+
detected until the next time CCI tries to merge to Microsoft (or a
91+
user reports the problem to us). So you're less likely to encounter
92+
Windows-specific problems with Microsoft's repository.
93+
94+
- On the other hand, some CCI engineers work on Mac OS X and
95+
frequently run the regression tests and other manual tests on CCI's
96+
copy of 3C on Mac OS X, while we are unaware of any testing of
97+
Microsoft's copy of 3C on Mac OS X. So you may be less
98+
likely to encounter Mac-specific problems with CCI's repository. But
99+
so far, when we've seen Mac-specific problems, we've usually gotten
100+
a fix into Microsoft's repository reasonably quickly.
101+
102+
As noted in the [setup instructions](INSTALL.md#basics), both 3C and
103+
the Checked C compiler depend on the Checked C system headers, which
104+
Microsoft maintains in [a subdirectory of a separate repository named
105+
`checkedc`](https://github.com/microsoft/checkedc/tree/master/include).
106+
CCI has [a fork of this
107+
repository](https://github.com/correctcomputation/checkedc), but
108+
currently it is used only for submitting changes to Microsoft. All
109+
users should use Microsoft's `checkedc` repository regardless of which
110+
`checkedc-clang` repository they use.

0 commit comments

Comments
 (0)