[PATCH] D58797: [Sema] Add some compile time _FORTIFY_SOURCE diagnostics

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 28 15:04:53 PST 2019


erik.pilkington created this revision.
erik.pilkington added reviewers: george.burgess.iv, rsmith, aaron.ballman.
Herald added subscribers: jdoerfert, dexonsmith, jkorous.
Herald added a project: clang.

These diagnose overflowing calls to subset of fortifiable functions. Some functions, like `sprintf` or `strcpy` aren't supported right not, but we should probably support these in the future. We previously supported this kind of functionality with `-Wbuiltin-memcpy-chk-size`, but that diagnose doesn't work with `_FORTIFY` implementations that use wrapper functions. Also unlike that diagnostic, we emit these warnings regardless of whether `_FORTIFY_SOURCE` is actually enabled, which is nice for programs that don't enable the runtime checks.

Why not just use diagnose_if, like Bionic does? We can get better diagnostics in the compiler (i.e. mention the sizes), and we have the potential to diagnose `sprintf` and `strcpy` which is impossible with diagnose_if (at least, in languages that don't support C++14 constexpr). This approach also saves standard libraries from having to add diagnose_if.

rdar://48006655

Thanks for taking a look!
Erik


Repository:
  rC Clang

https://reviews.llvm.org/D58797

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/bstring.c
  clang/test/Analysis/null-deref-ps-region.c
  clang/test/Analysis/pr22954.c
  clang/test/Analysis/string.c
  clang/test/Sema/builtin-object-size.c
  clang/test/Sema/builtins.c
  clang/test/Sema/transpose-memset.c
  clang/test/Sema/warn-fortify-source.c
  clang/test/Sema/warn-strncat-size.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58797.188793.patch
Type: text/x-patch
Size: 29962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190228/c572a834/attachment-0001.bin>


More information about the cfe-commits mailing list