[PATCH] -fsanitize=nonnull-attribute and -fsanitize=returns-nonnull-attribute support

Jeff Law law@redhat.com
Fri Sep 19 18:02:00 GMT 2014


On 09/09/14 11:53, Jakub Jelinek wrote:
> On Fri, Jun 27, 2014 at 09:13:07AM +0200, Jakub Jelinek wrote:
>> The patch adds two new (trivial handlers) to libubsan, as it is maintained
>> in llvm's compiler-rt, will talk to them if they are interested in those
>> and what exact wording and form (AFAIK clang also added the gcc
>> {,returns_}nonnull attributes).  If they wouldn't be interested, guess
>> we could add them in a separate, gcc owned, source file in ubsan (like we
>> own Makefile*).
>
> And here is the actual new version of the patch, including cherry-picked
> libsanitizer changes.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2014-09-09  Jakub Jelinek  <jakub@redhat.com>
>
> gcc/
> 	* flag-types.h (enum sanitize_code): Add SANITIZE_NONNULL_ATTRIBUTE
> 	and SANITIZE_RETURNS_NONNULL_ATTRIBUTE, or them into SANITIZE_UNDEFINED.
> 	* opts.c (common_handle_option): Handle SANITIZE_NONNULL_ATTRIBUTE and
> 	SANITIZE_RETURNS_NONNULL_ATTRIBUTE and disable
> 	flag_delete_null_pointer_checks for them.
> 	* sanitizer.def (BUILT_IN_UBSAN_HANDLE_NONNULL_ARG,
> 	BUILT_IN_UBSAN_HANDLE_NONNULL_ARG_ABORT,
> 	BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
> 	BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): New.
> 	* ubsan.c (instrument_bool_enum_load): Set *gsi back to
> 	stmt's iterator.
> 	(instrument_nonnull_arg, instrument_nonnull_return): New functions.
> 	(pass_ubsan::gate): Return true even for SANITIZE_NONNULL_ATTRIBUTE
> 	or SANITIZE_RETURNS_NONNULL_ATTRIBUTE.
> 	(pass_ubsan::execute): Call instrument_nonnull_{arg,return}.
> 	* doc/invoke.texi (-fsanitize=nonnull-attribute,
> 	-fsanitize=returns-nonnull-attribute): Document.
> gcc/testsuite/
> 	* c-c++-common/ubsan/attrib-3.c: New test.
> 	* c-c++-common/ubsan/nonnull-1.c: New test.
> 	* c-c++-common/ubsan/nonnull-2.c: New test.
> 	* c-c++-common/ubsan/nonnull-3.c: New test.
> 	* c-c++-common/ubsan/nonnull-4.c: New test.
> 	* c-c++-common/ubsan/nonnull-5.c: New test.
> libsanitizer/
> 	* ubsan/ubsan_handlers.cc, ubsan/ubsan_handlers.h: Cherry pick
> 	upstream r215485, r217389, r217391 and r217400.
OK.
jeff



More information about the Gcc-patches mailing list