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
2825with us) and we may even direct users who want the functionality to
2926your 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
4430set 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.
0 commit comments