[PATCH] avoid bogus -Wstringop-truncation when inlining (PR 84480)

Martin Sebor msebor@gmail.com
Thu Feb 22 17:49:00 GMT 2018


On 02/21/2018 07:53 PM, Jeff Law wrote:
> On 02/21/2018 02:19 PM, Martin Sebor wrote:
>> The attached patch eliminates -Wstringop-truncation false
>> positives reported in bug 84480 - bogus -Wstringop-truncation
>> despite assignment with an inlined string literal.  It does
>> that by delegating early strncpy checks during folding to
>> the same machinery in tree-ssa-strlen that looks for a NUL
>> assignment to the destination the next statement.
>>
>> The patch also adds inlining context to the warnings via
>> the %G directive.
>>
>> Tested on x86_64-linux with no regressions.
>>
>> Martin
>>
>> gcc-84480.diff
>>
>>
>> PR tree-optimization/84480 - bogus -Wstringop-truncation despite assignment with an inlined string literal
>>
>> gcc/ChangeLog:
>>
>> 	PR tree-optimization/84480
>> 	* gimple-fold.c (gimple_fold_builtin_strcpy): Move warnings
>> 	to maybe_diag_stxncpy_trunc.  Call it.
>> 	* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Integrate warnings
>> 	from gimple_fold_builtin_strcpy.  Print inlining stack.
>> 	(handle_builtin_stxncpy): Print inlining stack.
>> 	* tree-ssa-strlen.h (maybe_diag_stxncpy_trunc): Declare.
>>
>> gcc/testsuite/ChangeLog:
>>
>> 	PR tree-optimization/84480
>> 	* c-c++-common/Wstringop-truncation.c: Adjust text of expected warnings.
>> 	* g++.dg/warn/Wstringop-truncation-1.C: New test.
> In general our guidelines are that the users of a .h file should include
> any dependencies rather than having the .h file itself include other .h
> files (Now that we've detangled the header files we may want to revisit
> that guideline, but that's not a gcc-8 item).
>
> It looks like gimple-fold.c and tree-ssa-strlen.c already have the
> prereqs.  So in theory you should be able to just remove the bogus
> #includes from tree-ssa-strlen.h.

Done.

>
> In general we want to avoid adding more warnings to folding code.  But I
> think the argument here is that we're already trying to warn within the
> folder and just doing a poor job -- so we're removing that
> implementation and delegating the warning to a better implementation.
> Right?

Exactly.

>
> So I think you just need to remove the bogus #includes from
> tree-ssa-strlen and this is OK.

Thanks.  Committed in r257910.

Martin



More information about the Gcc-patches mailing list