Implement -Wduplicated-branches (PR c/64279)

Jeff Law
Thu Oct 20 18:56:00 GMT 2016

On 10/20/2016 08:37 AM, David Malcolm wrote:
> On Thu, 2016-10-20 at 16:24 +0200, Marek Polacek wrote:
>> On Thu, Oct 20, 2016 at 10:11:55AM -0400, Jason Merrill wrote:
>>> On Wed, Oct 19, 2016 at 7:07 AM, Marek Polacek <>
>>> wrote:
>>>> But since integer csts and various decls
>>>> don't carry location info, this works only partially, so the
>>>> warning
>>>> warns even for e.g.
>>>>   if (TREE_STATIC (node) || DECL_EXTERNAL (node))
>>>>     max_align = MAX_OFILE_ALIGNMENT;
>>>>   else
>>>>     max_align = MAX_STACK_ALIGNMENT;
>>>> same number.
>>>> There's no way to get around this, so the warning isn't enabled
>>>> by nor
>>>> -Wall neither -Wextra, and can't be until we solve the pesky
>>>> location
>>>> horror.  (-Wduplicated-cond is off for the very same reason.)
>>> Is someone working on this?
>> Not me, but I think David has been experimenting with this.  David,
>> is that
>> correct?
> I started looking at this, but it's unlikely that I'll have something
> ready for gcc 7 (have been focusing on the RTL frontend).
Right.  David and I have kicked around some ideas on how we might get to 
a point where constants and decls can carry location information, but we 
agreed that it wasn't likely gcc-7 material.

So the question in my mind is does the warning make sense given we can't 
current disambiguate constants and thus are likely generating a goodly 
number of false positives.

[ Presumably it was good enough to catch the duplicated branch code Jon 
pointed out in tree-ssa-threadupdate.c recently?  Any other real bugs
flagged? ]


More information about the Gcc-patches mailing list