-
Notifications
You must be signed in to change notification settings - Fork 79
Implicit inclusion of checked header files. #998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a9e1476
71daaa2
0eabc20
82df474
b5d7c36
1174dcb
8310aae
e0b5ed0
18b735b
fecf7d2
2e7f5e5
0091379
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…rations.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -139,41 +139,49 @@ files. | |||||||||||
## Proposed Solution: | ||||||||||||
|
||||||||||||
The proposed solution is as follows: | ||||||||||||
- Based on feedback from CCI, we implicitly include checked headers by | ||||||||||||
default. That is, the compilation flag gives a way to opt out of this | ||||||||||||
implicit inclusion. In accordance with this, we rename the compilation | ||||||||||||
flag to NO_IMPLICIT_INCLUDE_CHECKED_HDRS. | ||||||||||||
- For each system header file, say `foo.h`, that does not have clang-specific | ||||||||||||
declarations (there are 13 such header files at present), we add a new file | ||||||||||||
also called `foo.h` that will contain the following: | ||||||||||||
|
||||||||||||
#ifdef NO_IMPLICIT_INCLUDE_CHECKED_HDRS | ||||||||||||
#include_next <foo.h> | ||||||||||||
#else | ||||||||||||
#include <foo_checked.h> | ||||||||||||
#endif | ||||||||||||
|
||||||||||||
The file `foo_checked.h` will contain `#include_next <foo.h>` and the | ||||||||||||
Checked-C-specific declarations. | ||||||||||||
|
||||||||||||
- In the case that a system header file, say `bar.h`, does have clang-specific | ||||||||||||
declarations (there is one such header file at present), the pre-existing | ||||||||||||
`bar.h` contains the following: | ||||||||||||
|
||||||||||||
#include_next <bar.h> | ||||||||||||
<currently existing clang-specific declarations> | ||||||||||||
|
||||||||||||
At the end of the pre-existing `bar.h`, we will add the following: | ||||||||||||
|
||||||||||||
#ifndef NO_IMPLICIT_INCLUDE_CHECKED_HDRS | ||||||||||||
#include <bar_checked_internal.h> | ||||||||||||
#endif | ||||||||||||
|
||||||||||||
The file `bar_checked.h` will contain just the following: | ||||||||||||
|
||||||||||||
// Force the inclusion of Checked-C-specific declarations | ||||||||||||
#undef NO_IMPLICIT_INCLUDE_CHECKED_HDRS | ||||||||||||
#include <bar.h> | ||||||||||||
|
||||||||||||
All the Checked-C-specific declarations will be moved to | ||||||||||||
`bar_checked_internal.h`. | ||||||||||||
- It is a hybrid solution based on ideas in Solutions 3 and 1 that | ||||||||||||
handles the presence of both clang-specific and Checked-C-specific | ||||||||||||
declarations in header files. It also incorporates the feedback from CCI to | ||||||||||||
make implicit inclusion of checked header files as default. | ||||||||||||
- We primarily adopt Solution 3 for header files that do not have | ||||||||||||
clang-specific declarations, but have Checked-C-specific declarations (there | ||||||||||||
are 13 such header files at present). To implicitly include checked headers | ||||||||||||
by default, the compilation flag (as proposed in Solution 3) now gives a way | ||||||||||||
to **opt out** of implicit inclusion. Accordingly, it is renamed to | ||||||||||||
NO_IMPLICIT_INCLUDE_CHECKED_HDRS. | ||||||||||||
- For each system header file, say `foo.h`, that does not have | ||||||||||||
clang-specific declarations but has Checked-C-specific declarations, we | ||||||||||||
will add a new file also called `foo.h` that will contain the following: | ||||||||||||
|
||||||||||||
#ifdef NO_IMPLICIT_INCLUDE_CHECKED_HDRS | ||||||||||||
#include_next <foo.h> | ||||||||||||
#else | ||||||||||||
#include <foo_checked.h> | ||||||||||||
#endif | ||||||||||||
|
||||||||||||
- The file `foo_checked.h` will contain `#include_next <foo.h>` and the | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could change the |
||||||||||||
Checked-C-specific declarations. | ||||||||||||
|
||||||||||||
- For a system header file that contains clang-specific declarations and also | ||||||||||||
Checked-C-specific declarations (there is one such header file at present), | ||||||||||||
we will do the following: | ||||||||||||
Comment on lines
+161
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're willing to change the default include path in the driver to add a Checked-C-specific include directory (say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have decided not to change the default include path in the driver at present. |
||||||||||||
- Let `bar.h` be such a header file. Then there already | ||||||||||||
exists a file called `bar.h` in the `clang/lib/Headers` directory, | ||||||||||||
which contains clang-specific declarations in the following format: | ||||||||||||
|
||||||||||||
#include_next <bar.h> | ||||||||||||
<currently existing clang-specific declarations> | ||||||||||||
|
||||||||||||
At the end of this pre-existing `bar.h`, we will add the following: | ||||||||||||
|
||||||||||||
#ifndef NO_IMPLICIT_INCLUDE_CHECKED_HDRS | ||||||||||||
#include <bar_checked_internal.h> | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the same idea as my previous comment, this could be changed to just:
Suggested change
Then the format of |
||||||||||||
#endif | ||||||||||||
|
||||||||||||
- All the Checked-C-specific declarations (that are currently present in | ||||||||||||
`bar_checked.h`) will be moved to `bar_checked_internal.h`. The file | ||||||||||||
`bar_checked.h` will be modified to contain just the following: | ||||||||||||
|
||||||||||||
// Force the inclusion of Checked-C-specific declarations | ||||||||||||
#undef NO_IMPLICIT_INCLUDE_CHECKED_HDRS | ||||||||||||
#include <bar.h> | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do keep this approach rather than taking my suggestion above, might the following be safer?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattmccutchen-cci Thank you for your suggestion - you are right! I have incorporated it in the latest commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This approach of a slight alteration to the clang-specific header file looks good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't t his be classified as another possible solution? It is a little confusing for the proposed solution to be described as a hybrid of other solutions.