[cfe-dev] -Warray-bounds seems over-zealous on Clang

Nicola Gigante nicola.gigante at gmail.com
Fri Jul 15 03:24:53 PDT 2011


Il giorno 13/lug/2011, alle ore 22.21, John McCall ha scritto:

> On Jul 13, 2011, at 1:10 PM, Nicola Gigante wrote:
>> Il giorno 13/lug/2011, alle ore 17.49, Ted Kremenek ha scritto:
>>> On Jul 13, 2011, at 8:05 AM, David Blaikie wrote:
>>> 
>>>> So, options that seem to be being discussed include:
>>>> 
>>>> 1) suppress this warning in all cases where the array is of length 1 and the last element in a struct
>>>>   1.1) refinement: only when the length is specified explicitly and not via macro expansion, etc. (as John suggested)
>>>>   1.2) refinement: under c99 recommend a fixup to use flexible arrays
>>>> 2) split the warning in two, the second being the cases suppressed by the above option (probably less interesting if 1.1 is implemented)
>>>>  
>>> 
>>> (1) and (2) aren't mutually exclusive.  (2) is still useful when the heuristics implied by 1.1 and 1.2 aren't good enough.
>> 
>> I've tried to write such a patch, as it seemed simple, but I'm stuck because I don't know enough
>> about internal clang's APIs yet.
>> Until now, I've come up with the simple patch attached, that disables the warning if
>> the array is declared inside a record type and the size is one.
>> Questions:
>> - From the NamedDecl* object representing the array declaration, how do I know if it's declared last in the struct?
> 
> It should be a FieldDecl, and its parent should be a RecordDecl.  I don't think there's a cleaner solution than just iterating through the fields of the record and complaining if it's not the last one.
> 
>> - From the NamedDecl*, how do I know if the size of the member declaration comes from a macro expansion?
> 
> The exception should apply to:
>   - a field of a struct, where
>   - the field's TypeLoc is a (possibly parenthesized) ConstantArrayTypeLoc and
>   - the size expression in that TypeLoc is a (possibly parenthesized) IntegerLiteral and
>   - the source location of that literal is not a macro ID.
> 

Hello.

I've attached the patch. It seems to work as intended. The only thing missing is to split up
the warning. How to do it?

Also what do you mean by "possibly parenthesized" ConstantArrayTypeLoc and IntegerLiteral?

> John.

Nicola

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110715/e603d3f6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgsql_warning.patch
Type: application/octet-stream
Size: 3741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110715/e603d3f6/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110715/e603d3f6/attachment-0001.html>


More information about the cfe-dev mailing list