diff options
author | Omar Sandoval <osandov@osandov.com> | 2021-11-09 15:38:14 -0800 |
---|---|---|
committer | Kim Gräsman <kim.grasman@gmail.com> | 2021-12-04 20:25:50 +0100 |
commit | 44480a2de0d8ef039b13391997f274ea33750be9 (patch) | |
tree | 20f7921f0eac6c28fb2738aa377f5159d712d730 | |
parent | a73561e3eb51565c0fb5b9bc68afcced7c357161 (diff) |
Add export from <stdint.h> to <inttypes.h>
IWYU currently warns for this example:
$ cat test.c
#include <inttypes.h>
#include <stdio.h>
int main(void)
{
uint64_t x = UINT64_C(1234);
printf("%" PRIu64 "\n", x);
return 0;
}
$ include-what-you-use test.c
test.c should add these lines:
#include <stdint.h> // for UINT64_C, uint64_t
test.c should remove these lines:
The full include-list for test.c:
#include <inttypes.h> // for PRIu64
#include <stdint.h> // for UINT64_C, uint64_t
#include <stdio.h> // for printf
---
However, the C standard states that "the header <inttypes.h> includes
the header <stdint.h>". So, this program shouldn't need to include
<stdint.h>.
Some mappings were previously added for individual symbols from
<stdint.h> (e.g., commit 24f9fdf0af94 ("Add more mappings for
[u]intptr_t"), but it's more accurate to export everything. Get rid of
the symbol mappings and add an include mapping.
-rw-r--r-- | gcc.libc.imp | 2 | ||||
-rw-r--r-- | gcc.symbols.imp | 12 | ||||
-rw-r--r-- | iwyu_include_picker.cc | 16 |
3 files changed, 5 insertions, 25 deletions
diff --git a/gcc.libc.imp b/gcc.libc.imp index 1d436f5..a6493f6 100644 --- a/gcc.libc.imp +++ b/gcc.libc.imp @@ -203,4 +203,6 @@ { include: [ "<linux/limits.h>", private, "<limits.h>", public ] }, # PATH_MAX { include: [ "<linux/prctl.h>", private, "<sys/prctl.h>", public ] }, { include: [ "<sys/ucontext.h>", private, "<ucontext.h>", public ] }, + # Exports guaranteed by the C standard + { include: [ "<stdint.h>", public, "<inttypes.h>", public ] }, ] diff --git a/gcc.symbols.imp b/gcc.symbols.imp index de38147..a3f8dc8 100644 --- a/gcc.symbols.imp +++ b/gcc.symbols.imp @@ -55,34 +55,22 @@ { symbol: [ "id_t", private, "<sys/resource.h>", public ] }, { symbol: [ "imaxdiv_t", private, "<inttypes.h>", public ] }, { symbol: [ "intmax_t", private, "<stdint.h>", public ] }, - { symbol: [ "intmax_t", private, "<inttypes.h>", public ] }, { symbol: [ "uintmax_t", private, "<stdint.h>", public ] }, - { symbol: [ "uintmax_t", private, "<inttypes.h>", public ] }, { symbol: [ "ino64_t", private, "<sys/types.h>", public ] }, { symbol: [ "ino64_t", private, "<dirent.h>", public ] }, { symbol: [ "ino_t", private, "<sys/types.h>", public ] }, { symbol: [ "ino_t", private, "<dirent.h>", public ] }, { symbol: [ "ino_t", private, "<sys/stat.h>", public ] }, { symbol: [ "int8_t", private, "<stdint.h>", public ] }, - { symbol: [ "int8_t", private, "<inttypes.h>", public ] }, { symbol: [ "int16_t", private, "<stdint.h>", public ] }, - { symbol: [ "int16_t", private, "<inttypes.h>", public ] }, { symbol: [ "int32_t", private, "<stdint.h>", public ] }, - { symbol: [ "int32_t", private, "<inttypes.h>", public ] }, { symbol: [ "int64_t", private, "<stdint.h>", public ] }, - { symbol: [ "int64_t", private, "<inttypes.h>", public ] }, { symbol: [ "uint8_t", private, "<stdint.h>", public ] }, - { symbol: [ "uint8_t", private, "<inttypes.h>", public ] }, { symbol: [ "uint16_t", private, "<stdint.h>", public ] }, - { symbol: [ "uint16_t", private, "<inttypes.h>", public ] }, { symbol: [ "uint32_t", private, "<stdint.h>", public ] }, - { symbol: [ "uint32_t", private, "<inttypes.h>", public ] }, { symbol: [ "uint64_t", private, "<stdint.h>", public ] }, - { symbol: [ "uint64_t", private, "<inttypes.h>", public ] }, { symbol: [ "intptr_t", private, "<stdint.h>", public ] }, - { symbol: [ "intptr_t", private, "<inttypes.h>", public ] }, { symbol: [ "uintptr_t", private, "<stdint.h>", public ] }, - { symbol: [ "uintptr_t", private, "<inttypes.h>", public ] }, { symbol: [ "key_t", private, "<sys/types.h>", public ] }, { symbol: [ "key_t", private, "<sys/ipc.h>", public ] }, { symbol: [ "lconv", private, "<locale.h>", public ] }, diff --git a/iwyu_include_picker.cc b/iwyu_include_picker.cc index 77928fa..9518bc3 100644 --- a/iwyu_include_picker.cc +++ b/iwyu_include_picker.cc @@ -132,34 +132,22 @@ const IncludeMapEntry libc_symbol_map[] = { { "id_t", kPrivate, "<sys/resource.h>", kPublic }, { "imaxdiv_t", kPrivate, "<inttypes.h>", kPublic }, { "intmax_t", kPrivate, "<stdint.h>", kPublic }, - { "intmax_t", kPrivate, "<inttypes.h>", kPublic }, { "uintmax_t", kPrivate, "<stdint.h>", kPublic }, - { "uintmax_t", kPrivate, "<inttypes.h>", kPublic }, { "ino64_t", kPrivate, "<sys/types.h>", kPublic }, { "ino64_t", kPrivate, "<dirent.h>", kPublic }, { "ino_t", kPrivate, "<sys/types.h>", kPublic }, { "ino_t", kPrivate, "<dirent.h>", kPublic }, { "ino_t", kPrivate, "<sys/stat.h>", kPublic }, { "int8_t", kPrivate, "<stdint.h>", kPublic }, - { "int8_t", kPrivate, "<inttypes.h>", kPublic }, { "int16_t", kPrivate, "<stdint.h>", kPublic }, - { "int16_t", kPrivate, "<inttypes.h>", kPublic }, { "int32_t", kPrivate, "<stdint.h>", kPublic }, - { "int32_t", kPrivate, "<inttypes.h>", kPublic }, { "int64_t", kPrivate, "<stdint.h>", kPublic }, - { "int64_t", kPrivate, "<inttypes.h>", kPublic }, { "uint8_t", kPrivate, "<stdint.h>", kPublic }, - { "uint8_t", kPrivate, "<inttypes.h>", kPublic }, { "uint16_t", kPrivate, "<stdint.h>", kPublic }, - { "uint16_t", kPrivate, "<inttypes.h>", kPublic }, { "uint32_t", kPrivate, "<stdint.h>", kPublic }, - { "uint32_t", kPrivate, "<inttypes.h>", kPublic }, { "uint64_t", kPrivate, "<stdint.h>", kPublic }, - { "uint64_t", kPrivate, "<inttypes.h>", kPublic }, { "intptr_t", kPrivate, "<stdint.h>", kPublic }, - { "intptr_t", kPrivate, "<inttypes.h>", kPublic }, { "uintptr_t", kPrivate, "<stdint.h>", kPublic }, - { "uintptr_t", kPrivate, "<inttypes.h>", kPublic }, { "key_t", kPrivate, "<sys/types.h>", kPublic }, { "key_t", kPrivate, "<sys/ipc.h>", kPublic }, { "lconv", kPrivate, "<locale.h>", kPublic }, @@ -360,8 +348,8 @@ const IncludeMapEntry libstdcpp_symbol_map[] = { { "std::size_t", kPrivate, "<cwchar>", kPublic }, }; -// Private -> public include mappings for GNU libc const IncludeMapEntry libc_include_map[] = { + // Private -> public include mappings for GNU libc // ( cd /usr/include && grep '^ *# *include' {sys/,net/,}* | perl -nle 'm/^([^:]+).*<([^>]+)>/ && print qq@ { "<$2>", kPrivate, "<$1>", kPublic },@' | grep bits/ | sort ) // When I saw more than one mapping for these, I typically picked // what I thought was the "best" one. @@ -565,6 +553,8 @@ const IncludeMapEntry libc_include_map[] = { { "<linux/limits.h>", kPrivate, "<limits.h>", kPublic }, // PATH_MAX { "<linux/prctl.h>", kPrivate, "<sys/prctl.h>", kPublic }, { "<sys/ucontext.h>", kPrivate, "<ucontext.h>", kPublic }, + // Exports guaranteed by the C standard + { "<stdint.h>", kPublic, "<inttypes.h>", kPublic }, }; const IncludeMapEntry stdlib_c_include_map[] = { |