[cfe-dev] [RFC] new checker: function pointer parameter can be const
Daniel Marjamäki
Daniel.Marjamaki at evidente.se
Wed Aug 5 05:47:34 PDT 2015
Hello!
I am working on a new checker; function parameter can be const.
I plan to warn when:
* a function parameter is not const
* the function parameter is a pointer
* it is dereferenced in the function (otherwise there will be -Wunused-parameter warnings)
* the pointer address is not taken
* the data is not written
Example code:
int x;
void warn(int *p) { x = *p; } // <- Warning
void dontwarn(int *p) { *p = 0; } // <- No warning, data is written
My checker works a bit like the -Wunused-parameter warning. I add a flag to Decl that says if there is non-const usage.
I attach a proof-of-concept patch. It does not work well yet but shows how I intend to implement this.
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: 150805-constpar.diff
Type: text/x-patch
Size: 4587 bytes
Desc: 150805-constpar.diff
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150805/1b1bb16c/attachment.bin>
More information about the cfe-dev
mailing list