[PATCH v2 2/3] gimple-fold: Use ranges to simplify _chk calls

Jeff Law jeffreyalaw@gmail.com
Mon Nov 15 20:25:28 GMT 2021



On 11/15/2021 10:33 AM, Siddhesh Poyarekar wrote:
> Instead of comparing LEN and SIZE only if they are constants, use their
> ranges to decide if LEN will always be lower than or same as SIZE.
>
> This change ends up putting the stringop-overflow warning line number
> against the strcpy implementation, so adjust the warning check to be
> line number agnostic.
>
> gcc/ChangeLog:
>
> 	* gimple-fold.c (known_lower): New function.
> 	(gimple_fold_builtin_strncat_chk,
> 	gimple_fold_builtin_memory_chk, gimple_fold_builtin_stxcpy_chk,
> 	gimple_fold_builtin_stxncpy_chk,
> 	gimple_fold_builtin_snprintf_chk,
> 	gimple_fold_builtin_sprintf_chk): Use it.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.dg/Wobjsize-1.c: Make warning change line agnostic.
> 	* gcc.dg/builtin-chk-fold.c: New test.
>
>

> @@ -3024,39 +3040,24 @@ gimple_fold_builtin_memory_chk (gimple_stmt_iterator *gsi,
>   	}
>       }
>   
> -  if (! tree_fits_uhwi_p (size))
> -    return false;
> -
>     tree maxlen = get_maxval_strlen (len, SRK_INT_VALUE);
> -  if (! integer_all_onesp (size))
> +  if (! integer_all_onesp (size)
> +      && !known_lower (stmt, len, size) && !known_lower (stmt, maxlen, size))
Formatting it.  Move the trailing && !known_lower (...) to its own line.

OK with the formatting nit fixed.

jeff



More information about the Gcc-patches mailing list