[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 3 10:56:28 PST 2020


MaskRay added inline comments.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst:16-20
+This check is necesary because accidentally including sytem libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose `FILE *` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.
----------------
abrachet wrote:
> To be annoyingly pedantic, `FILE` is opaque so it would actually be ok in this situation. It is undefined to allocate your own `FILE` I believe. Something like `jmp_buf` or `thrd_t` might be better examples? Or macros like `assert` or `errno`.
`FILE` is a problem of glibc. Other libcs don't necessarily have the problem.

glibc exposes the internals of `FILE`: `typedef struct _IO_FILE FILE;` and `struct _IO_FILE { ... }` is exposed. musl does not expose the underlying structure of `FILE` (POSIX intentionally does not require that to allow a flexible implementation).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75332/new/

https://reviews.llvm.org/D75332





More information about the cfe-commits mailing list