]> granicus.if.org Git - clang/commit
[Sema] Add some compile time _FORTIFY_SOURCE diagnostics
authorErik Pilkington <erik.pilkington@gmail.com>
Mon, 18 Mar 2019 19:23:45 +0000 (19:23 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Mon, 18 Mar 2019 19:23:45 +0000 (19:23 +0000)
commit25d062ee4f1b683ccfeefb177d289eac901851cc
treec615a23ae85936a1088992c6024f524b8e270665
parent2bc6178db36348e53054ce2f5b7816da1bae580e
[Sema] Add some compile time _FORTIFY_SOURCE diagnostics

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 diagnostic 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

Differential revision: https://reviews.llvm.org/D58797

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356397 91177308-0d34-0410-b5e6-96231b3b80d8
16 files changed:
include/clang/AST/Decl.h
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/AST/Decl.cpp
lib/Sema/SemaChecking.cpp
lib/Sema/SemaExpr.cpp
test/Analysis/bstring.c
test/Analysis/null-deref-ps-region.c
test/Analysis/pr22954.c
test/Analysis/string.c
test/Sema/builtin-object-size.c
test/Sema/builtins.c
test/Sema/transpose-memset.c
test/Sema/warn-fortify-source.c [new file with mode: 0644]
test/Sema/warn-strncat-size.c