Bug 36513 - -Wlogical-op warns about strchr
Summary: -Wlogical-op warns about strchr
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Manuel López-Ibáñez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-12 19:00 UTC by Benjamin Otte
Modified: 2010-02-23 13:58 UTC (History)
2 users (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-11-25 13:43:34


Attachments
Preprocessed source file (2.46 KB, text/plain)
2009-11-25 10:26 UTC, Johan Gill
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Otte 2008-06-12 19:00:41 UTC
Compiling the following code with gcc-4.3 -Wlogical-op -O1

int main ()
{
  char *s, t;
  strchr (s, t);
}

leads to this warning:
test2.c: In function ‘main’:
test2.c:7: warning: logical ‘&&’ with non-zero constant will always evaluate as true

This is because libc defines strchr to a macro in bits/string.h. It looks to me like gcc should not warn about optimizations like __builtin_constant_p optimizations as those are diectly targeted at being optimized out.
Comment 1 Andrew Pinski 2008-06-12 19:08:53 UTC
Well also I think glibc should not need to optimise strchr really and let the compiler do it.
Comment 2 Manuel López-Ibáñez 2009-02-11 22:13:37 UTC
We need a reproducible preprocessed testcase. 
See http://gcc.gnu.org/bugs.html#detailed
Comment 3 Manuel López-Ibáñez 2009-05-15 20:13:44 UTC
Benjamin, note that -Wlogical-op will be enabled by -Wextra in GCC 4.5. 

I am willing to give it a try to fix this before 4.5 is released. However, I cannot reproduce this problem, so please, provide a preprocessed testcase.
Comment 4 Benjamin Otte 2009-05-17 09:05:45 UTC
I cannot reproduce this anymore with gcc 4.3.3 from Ubuntu 9.04, so I consider this fixed.
Comment 5 Manuel López-Ibáñez 2009-05-17 16:39:51 UTC
FIXED per previous comment.
Comment 6 Johan Gill 2009-11-25 10:02:56 UTC
I get this error when building swfdec with gcc 4.4.2 on Fedora 12.
Comment 7 Johan Gill 2009-11-25 10:06:12 UTC
Also tried the simple test case described in the bug description, although it needs to add #include <string.h> at the top.

The warning is still there.
Comment 8 Johan Gill 2009-11-25 10:26:42 UTC
Created attachment 19148 [details]
Preprocessed source file

Created a preprocessed source file producing the warning.
Comment 9 Manuel López-Ibáñez 2009-11-25 13:42:54 UTC
(In reply to comment #6)
> I get this error when building swfdec with gcc 4.4.2 on Fedora 12.

It is a warning that you need to enable with -Wlogical-op explicitly.

I cannot reproduce the preprocessed testcase with GCC 4.5 rev 150311. If you can reproduce it with a more recent revision, please let us know. Since this is not a regression (it was a new warning in GCC 4.3), I don't think anyone will try to fix it in GCC 4.3.x or GCC 4.4.x.

Now that we have a preprocessed testcase, I will try to reduce it and add it to the testsuite to avoid regressing here.

Comment 10 Manuel López-Ibáñez 2009-11-25 13:43:34 UTC
Now that we have a preprocessed testcase, I will try to reduce it and add it to
the testsuite to avoid regressing here.
Comment 11 Manuel López-Ibáñez 2010-02-19 21:21:54 UTC
Subject: Bug 36513

Author: manu
Date: Fri Feb 19 21:21:34 2010
New Revision: 156912

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156912
Log:
2010-02-19  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR 36513
testsuite/
	* c-c++-common/pr36513.c: New testcase.
	* c-c++-common/pr36513-2.c: New testcase.

Added:
    trunk/gcc/testsuite/c-c++-common/pr36513-2.c
    trunk/gcc/testsuite/c-c++-common/pr36513.c
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 12 Manuel López-Ibáñez 2010-02-19 21:25:34 UTC
FIXED in GCC 4.5