[PATCH] PR 7776: Warn about if ("abc" < "xyz") ...

Paul Schlie schlie@comcast.net
Sun Jun 5 18:05:00 GMT 2005


> From: Paul Schlie <schlie@comcast.net>
>> Roger Sayle wrote:
>> The following patch is my proposed solution to PR middle-end/7776
>> which is an enhancement request that gcc warn about comparisons to
>> constant string literals. ...
> 
> By analogy, this should likely apply to all literal value addresses, including
> arbitrary complex literals, i.e.:
> 
> - "abc"
> - (char []){'a','b','c', 0} // which is equivelent to a string literal.
> - &'a' or &(<sometype>)some_literal_value
> - (some_struct_or_array){some_literal, ...}
> 
> As all are subject to the same root problem, being that the standard does not
> define if lexically distinct instances of otherwise equivalently valued
> literals are required to be logically identical or unique objects; therefore
> not a unique issue relating to string-literals.
> 
> Unfortunately however as there is no present facility to qualify pointers to
> literal values; there is no ability to differentiate between literal vs.
> variable object references once a literal address is assigned to a variable,
> or passed as an argument to, or a return from a function.
> 
> (Maybe it's worth while to add a 'literal' qualifier extension to GCC to
> enable such indirect references to READONLY literal objects to be ideally
> differentiated from variable objects; possibly setting a precedent for future
> standard incorporation. As otherwise the proper handling of literal
> references which can not be reliably presently satisfied.)

As a generalization, as READONLY objects are uniquely 'literal' values which
have been determined may be referenced directly or indirectly through a
READONLY memory reference, it would seem that it may be simplest to warn not
for just STRING_CST (or some more complex variation) but more simply for all
READONLY object references (either via TREE_READONLY or MEM_READONLY_P which
should generally reliably identify all such references).




More information about the Gcc-patches mailing list