This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/31236] incorrect output on external symbol address cast as integer used in conditional statement
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Mar 2007 03:59:53 -0000
- Subject: [Bug c/31236] incorrect output on external symbol address cast as integer used in conditional statement
- References: <bug-31236-14260@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #6 from bangerth at dealii dot org 2007-03-21 03:59 -------
(In reply to comment #4)
> so in other words you're saying the solution to this is
> "if you want it to work with GCC, make your code non-portable"
>
> afaik "__attribute__ (( weak ))" is not part of the standard, its not a
> portable solution.
>
> the fact that
> #define SOMEVALUE ((int)&SomeLinkerScriptDefinedSymbol)
> int i = SOMEVALUE;
> if(i == 0){
> and
> if(SOMEVALUE == 0){
>
> give a different result makes gcc act inconsistently on code that should be
> equivalent.
I would argue that it is a missed optimization that it doesn't optimize
away both cases.
That said, a compiler is entirely within the standard to assume that the
address of a symbol is non-null. That's simply the case in a well-formed
program. If you specifically want something different, then you need to
let the compiler know this.
As a second point, you are surely aware of the fact that casting a
pointer (in general) to int is not portable, and a function pointer in
particular (since function pointers may not be represented as pointers,
but potentially as structures). The latter is where the difference in
optimization comes from.
W.
--
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bangerth at dealii dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31236