This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Don't optimize function addresses
- From: John David Anglin <dave at hiauly1 dot hia dot nrc dot ca>
- To: gcc-patches at gcc dot gnu dot org
- Cc: rguenth at gcc dot gnu dot org
- Date: Mon, 31 Mar 2008 20:01:58 -0400
- Subject: [PATCH] Don't optimize function addresses
- Reply-to: John David Anglin <dave dot anglin at nrc-cnrc dot gc dot ca>
The enclosed change fixes PR middle-end/35705. The 32-bit PA-RISC
runtimes treat function pointers in a unique manner. Many targets
have function pointers which point to function descriptors. In the
PA case, a function pointer may point to a descriptor or directly
to code. The plabel bit is used to distinguish these two cases.
Various code needs to be able to test this bit. However in 4.3.0,
an optimization of function pointers was introduced based on the
alignment of the actual function code. This is incorrect for targets
that use function descriptors, but it also made it impossible for C
code to test the plabel bit. A similar situation may apply to
arm/thumb function pointers.
The enclosed change disables this optimization.
The patch has been tested on hppa-unknown-linux, hppa2.0w-hp-hpux11.11
and hppa64-hp-hpux11.11 with no observed regressions.
Ok for trunk and 4.3 branch?
Dave
--
J. David Anglin dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6602)
2008-03-31 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
PR middle-end/35705
* fold-const.c (get_pointer_modulus_and_residue): Return modulus 1 if
the expression is a function address.
Index: fold-const.c
===================================================================
--- fold-const.c (revision 133621)
+++ fold-const.c (working copy)
@@ -9065,7 +9065,7 @@
}
}
- if (DECL_P (expr))
+ if (DECL_P (expr) && TREE_CODE (expr) != FUNCTION_DECL)
return DECL_ALIGN_UNIT (expr);
}
else if (code == POINTER_PLUS_EXPR)