[cfe-dev] RFC redundant assignment in switch
Daniel Marjamäki
Daniel.Marjamaki at evidente.se
Fri Mar 28 06:33:31 PDT 2014
Hello!
I am working on a new checker for the StaticAnalyser.
The purpose is to detect unintentional switch case fall through. The checker will warn when there is redundant assignment. Example code:
switch (x) {
case 1:
y = 1; // <- redundant assignment
case 2:
y = 2;
break;
}
For your info, Cppcheck has this check. It has detected real bugs in real code. There are such cppcheck warnings in emacs,fvwm,etc. here is for example the code cppcheck warns about in fvwm:
case TEXTURE_BUILTIN:
Builtin:
TextureType=TEXTURE_BUILTIN;
default:
Solid:
TextureType=TEXTURE_SOLID;
I would like to discuss the design.
I attach a proof-of-concept checker.
In the proof-of-concept code, variables that are assigned are tracked using a DenseMap. If there is no break and a variable is reassigned in the next case there will be a warning.
I would like to know if I use the proper visitors and good approach for tracking assigned variables, etc.
Best regards,
Daniel Marjamäki
..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden
Mobile: +46 (0)709 12 42 62
E-mail: Daniel.Marjamaki at evidente.se
www.evidente.se
-------------- next part --------------
A non-text attachment was scrubbed...
Name: redundantassignment1.patch
Type: text/x-patch
Size: 13692 bytes
Desc: redundantassignment1.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140328/b251339e/attachment.bin>
More information about the cfe-dev
mailing list