This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR 7776: Warn about if ("abc" < "xyz") ...
- From: Paul Schlie <schlie at comcast dot net>
- To: Roger Sayle <roger at eyesopen dot com>,<gcc-patches at gcc dot gnu dot org>
- Date: Sun, 05 Jun 2005 14:05:33 -0400
- Subject: Re: [PATCH] PR 7776: Warn about if ("abc" < "xyz") ...
> 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).