This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Correct handling of #pragma redefine_extname for block-scope extern
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 21 Sep 2004 19:26:27 -0700
- Subject: Correct handling of #pragma redefine_extname for block-scope extern
- Reply-to: mark at codesourcery dot com
As previously discussed, #pragma redefine_extname should work with
block-scope extern and implicit declarations -- but it did not. We
need to call maybe_apply_renaming_pragma in these situations as well.
Bootstraped and tested (in a slightly different form) on
i386-pc-solaris2.10, bootstrapped and tested (in this form) on
i686-pc-linux-gnu, applied on the mainline.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2004-09-21 Mark Mitchell <mark@codesourcery.com>
* c-decl.c (implicitly_declare): Call maybe_apply_renaming_pragma.
(finish_decl): Likewise.
2004-09-21 Mark Mitchell <mark@codesourcery.com>
* gcc.dg/pragma-re-3.c: New test.
Index: testsuite/gcc.dg/pragma-re-3.c
===================================================================
RCS file: testsuite/gcc.dg/pragma-re-3.c
diff -N testsuite/gcc.dg/pragma-re-3.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/pragma-re-3.c 21 Sep 2004 22:37:24 -0000
***************
*** 0 ****
--- 1,18 ----
+ /* { dg-do link { target *-*-solaris* } } */
+
+ #pragma redefine_extname f1 f
+ #pragma redefine_extname g1 g
+
+ void f() {
+ extern int f1();
+ f1();
+ }
+
+ void g() {
+ g1();
+ }
+
+ int main () {
+ f();
+ g();
+ }
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.587
diff -c -5 -p -r1.587 c-decl.c
*** c-decl.c 20 Sep 2004 20:41:20 -0000 1.587
--- c-decl.c 22 Sep 2004 02:21:04 -0000
*************** implicit_decl_warning (tree id, tree old
*** 2157,2166 ****
--- 2157,2168 ----
tree
implicitly_declare (tree functionid)
{
struct c_binding *b;
tree decl = 0;
+ tree asmspec_tree;
+
for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
{
if (B_IN_SCOPE (b, external_scope))
{
decl = b->decl;
*************** implicitly_declare (tree functionid)
*** 2228,2237 ****
--- 2230,2242 ----
decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
DECL_EXTERNAL (decl) = 1;
TREE_PUBLIC (decl) = 1;
C_DECL_IMPLICIT (decl) = 1;
implicit_decl_warning (functionid, 0);
+ asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL);
+ if (asmspec_tree)
+ set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
/* C89 says implicit declarations are in the innermost block.
So we record the decl in the standard fashion. */
decl = pushdecl (decl);
*************** finish_decl (tree decl, tree init, tree
*** 3062,3072 ****
tree type = TREE_TYPE (decl);
int was_incomplete = (DECL_SIZE (decl) == 0);
const char *asmspec = 0;
/* If a name was specified, get the string. */
! if (current_scope == file_scope)
asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
if (asmspec_tree)
asmspec = TREE_STRING_POINTER (asmspec_tree);
/* If `start_decl' didn't like having an initialization, ignore it now. */
--- 3067,3078 ----
tree type = TREE_TYPE (decl);
int was_incomplete = (DECL_SIZE (decl) == 0);
const char *asmspec = 0;
/* If a name was specified, get the string. */
! if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
! && DECL_FILE_SCOPE_P (decl))
asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
if (asmspec_tree)
asmspec = TREE_STRING_POINTER (asmspec_tree);
/* If `start_decl' didn't like having an initialization, ignore it now. */