[cfe-dev] RFC redundant assignment in switch

Ted Kremenek kremenek at apple.com
Mon Mar 31 09:21:56 PDT 2014


On Mar 31, 2014, at 9:08 AM, Jordan Rose <jordan_rose at apple.com> wrote:

> 
> On Mar 30, 2014, at 19:47 , Kyle Sluder <kyle at ksluder.com> wrote:
> 
>> On Mar 28, 2014, at 1:52 PM, Jordan Rose <jordan_rose at apple.com> wrote:
>>> 
>>> Hi, Daniel. We already have this in Clang itself as -Wimplicit-fallthrough,
>> 
>> That warning triggers for every fallthrough. Daniel’s checker only triggers for assignments that are redundant with assignments made in cases that are fallen into.
>> 
>> These are philosophically different approaches, and they are mutually compatible. Even if -Wimplicit-fallthrough becomes useful to C/ObjC programmers via the __fallthrough macro, Daniel’s checker is still useful because it will catch logic bugs in code that redundantly assigns to the same variable in two different cases.
> 
> Ah, interesting. Isn't this already caught with the dead stores checker, though?
> 
> <stdin>:5:5: warning: Value stored to 'y' is never read
>     y = 1;
>     ^   ~
> 
> We could probably stand to improve that checker to say why something's a dead store, but I don't think we need a separate pass.
> 
> Jordan

Agreed.  I’d rather we have the general dead stores checker (and make it better) then have something more specialized like this.  The dead stores checker has also been hardened over several years to handle many common idioms of defensive code that are “dead” but not interesting.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140331/6209c4c0/attachment.html>


More information about the cfe-dev mailing list