On 06/09/2016 12:34 PM, Martin Sebor wrote:
Attached is an updated version of the original patch described
below to annotate with the nonnull attribute the Built-In Functions
to Perform Arithmetic with Overflow Checking.

Since the machinery that's in place doesn't handle the attribute
on type-generic built-ins changes to the (handle_nonnull_attribute
function in Ada and LTO besides C were required so I CC the
maintainers for these areas.

Thanks
Martin

On 06/02/2016 05:22 PM, Martin Sebor wrote:
In a discussion of a patch in a this area (c/68120 and c++/70507)
Jakub noticed that the integer arithmetic built-ins with overflow
checking that expect a pointer to an integer as the last argument
silently (i.e., without a warning) accept a null pointer.  As the
test case in the bug referenced in in subject shows, such calls
then crash at runtime.

The attached patch follows the same approach used by other built
ins that take a pointer to an object (such as __built_strlen) to
issue a -Wnonnull warning for such invalid calls.

Martin


gcc-71392.diff


PR c/71392 - SEGV calling integer overflow built-ins with a null pointer

gcc/ChangeLog:

        PR c/71392
        * builtin-attrs.def (ATTR_NOTHROW_NONNULL_LEAF_LIST): New macro.
        (ATTR_NOTHROW_NONNULL_TYPEGENERIC_LEAF): Same.
        * builtins.def (BUILT_IN_SADD_OVERFLOW, BUILT_IN_SADDL_OVERFLOW): Use
        them.
        (BUILT_IN_SADDLL_OVERFLOW, BUILT_IN_SSUB_OVERFLOW): Same.
        (BUILT_IN_SSUBL_OVERFLOW, BUILT_IN_SSUBLL_OVERFLOW): Same.
        (BUILT_IN_SMUL_OVERFLOW, BUILT_IN_SMULL_OVERFLOW): Same.
        (BUILT_IN_SMULLL_OVERFLOW, BUILT_IN_UADD_OVERFLOW): Same.
        (BUILT_IN_UADDL_OVERFLOW, BUILT_IN_UADDLL_OVERFLOW): Same.
        (BUILT_IN_USUB_OVERFLOW, BUILT_IN_USUBL_OVERFLOW): Same.
        (BUILT_IN_USUBLL_OVERFLOW, BUILT_IN_UMUL_OVERFLOW): Same.
        (BUILT_IN_UMULL_OVERFLOW, BUILT_IN_UMULLL_OVERFLOW):

gcc/ada/ChangeLog:

        PR c/71392
        * gcc/ada/gcc-interface/utils.c (handle_nonnull_attribute): Accept
        the nonnull attribute in type-generic builtins.

gcc/c-family/ChangeLog:

        PR c/71392
        * gcc/c-family/c-common.c (handle_nonnull_attribute): Accept
        the nonnull attribute in type-generic builtins.

gcc/lto/ChangeLog:

        PR c/71392
        * gcc/lto/lto-lang.c (handle_nonnull_attribute): Accept the nonnull
        attribute in type-generic builtins.

gcc/testsuite/ChangeLog:

        PR c/71392
        * c-c++-common/builtin-arith-overflow-1.c: Add test cases.
OK for the trunk.

THanks,
Jeff

Reply via email to