r210372 - Add -Wtautological-undefined-compare and -Wundefined-bool-conversion warnings

Arthur O'Dwyer arthur.j.odwyer at gmail.com
Thu Jun 12 12:21:44 PDT 2014


FYI, I've worked on at least two commercial products which contained
constructs similar to

    void Crash() { *(volatile int*)0 = 42; }

in order to simulate an accidental null-pointer dereference in a
"portable" way (to be used in end-to-end testing of the code that was
supposed to gracefully handle that kind of accidental bug).  I'm not
saying this shouldn't generate a warning — of course it should — but
please make sure that there are very specific and targeted -W options
available to turn off any new diagnostics you're adding. Ideally, one
-W mnemonic per diagnostic.

–Arthur




On Thu, Jun 12, 2014 at 3:49 AM, Chandler Carruth <chandlerc at google.com> wrote:
>
> On Thu, Jun 12, 2014 at 11:40 AM, Stephan Bergmann <sbergman at redhat.com>
> wrote:
>>
>> On 06/06/2014 11:39 PM, Richard Trieu wrote:
>>>
>>> Author: rtrieu
>>> Date: Fri Jun  6 16:39:26 2014
>>> New Revision: 210372
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=210372&view=rev
>>> Log:
>>> Add -Wtautological-undefined-compare and -Wundefined-bool-conversion
>>> warnings
>>> to detect underfined behavior involving pointers.
>>
>>
>> Given that code that offends -Wtautological-undefined-compare (by checking
>> a reference for null) often also deliberately creates such null references,
>> a la
>>
>>   int & r = *(int*)0;
>>
>> is there any fundamental reason to not also add a warning for such
>> constructs?
>
>
> Makes sense to me. We should warn for anything which the full power of the
> Clang-side constant folding can see a null pointer being bound to a
> reference, provided it isn't in dead code (which we already have a mechanism
> for).
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list