[C/C++ PATCH] Call make_decl_rtl in {,c_}determine_visibility if DECL_RTL is set and visibility changed (PR target/39175)

Jakub Jelinek jakub@redhat.com
Fri Feb 13 21:22:00 GMT 2009


Hi!

The following testcase ICEs on powerpc-linux with -fpic -msecure-plt -O2.
The problem is in the redundant prototype after function.
First the foo FUNCTION_DECL is created, afterwards finish_function calls
c_determine_visibility on it which changes its visibility from default to hidden.
After this make_decl_rtl is called, determines the function binds locally and
sets SYMBOL_FLAG_LOCAL|SYMBOL_FLAG_FUNCTION.  Then merge_decls is called, which
in turn clears visibility (sets it back to default) and calls make_decl_rtl to
update the flags.  At this point targetm.binds_local_p returns false, as it at
that point has default visibility, so changes DECL_RTL's flags to
SYMBOL_FLAG_FUNCTION alone.  Then finish_decl calls c_determine_visibility
again and sets it back to hidden visibility.  But nothing afterwards calls
make_decl_rtl again to update the symbol flags again.  This means that
during expand_call we decide to use a tail call (targetm.binds_local_p is
true), but the right insn pattern isn't used (as that uses the
SYMBOL_FLAG_* bits and those are incorrect).

The following patch fixes this by teaching {,c_}determine_visibility to
update symbol flags if DECL_RTL is set already and the visibility changes.

Bootstrapped/regtested on i686-linux, x86_64-linux, powerpc64-linux
--with-cpu=default32 as well as powerpc64-linux defaulting to -m64.
Ok for trunk?

2009-02-13  Jakub Jelinek  <jakub@redhat.com>

	PR target/39175
	* c-common.c (c_determine_visibility): If visibility changed and
	DECL_RTL has been already set, call make_decl_rtl to update symbol
	flags.

	* decl2.c (determine_visibility): If visibility changed and
	DECL_RTL has been already set, call make_decl_rtl to update symbol
	flags.

	* gcc.dg/visibility-20.c: New test.
	* g++.dg/ext/visibility/visibility-11.C: New test.

--- gcc/c-common.c.jj	2009-02-09 23:07:06.000000000 +0100
+++ gcc/c-common.c	2009-02-13 12:05:41.000000000 +0100
@@ -1,6 +1,7 @@
 /* Subroutines shared by all languages that are variants of C.
    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -6249,8 +6250,18 @@ c_determine_visibility (tree decl)
      visibility_specified depending on #pragma GCC visibility.  */
   if (!DECL_VISIBILITY_SPECIFIED (decl))
     {
-      DECL_VISIBILITY (decl) = default_visibility;
-      DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
+      if (visibility_options.inpragma
+	  || DECL_VISIBILITY (decl) != default_visibility)
+	{
+	  DECL_VISIBILITY (decl) = default_visibility;
+	  DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
+	  /* If visibility changed and DECL already has DECL_RTL, ensure
+	     symbol flags are updated.  */
+	  if (((TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
+	       || TREE_CODE (decl) == FUNCTION_DECL)
+	      && DECL_RTL_SET_P (decl))
+	    make_decl_rtl (decl);
+	}
     }
   return false;
 }
--- gcc/cp/decl2.c.jj	2009-01-26 15:24:39.000000000 +0100
+++ gcc/cp/decl2.c	2009-02-13 12:10:53.000000000 +0100
@@ -1,6 +1,6 @@
 /* Process declarations and variables for C++ compiler.
    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Hacked by Michael Tiemann (tiemann@cygnus.com)
 
@@ -1921,6 +1921,8 @@ determine_visibility (tree decl)
 {
   tree class_type = NULL_TREE;
   bool use_template;
+  bool orig_visibility_specified;
+  enum symbol_visibility orig_visibility;
 
   /* Remember that all decls get VISIBILITY_DEFAULT when built.  */
 
@@ -1933,6 +1935,9 @@ determine_visibility (tree decl)
      maybe_clone_body.  */
   gcc_assert (!DECL_CLONED_FUNCTION_P (decl));
 
+  orig_visibility_specified = DECL_VISIBILITY_SPECIFIED (decl);
+  orig_visibility = DECL_VISIBILITY (decl);
+
   if (TREE_CODE (decl) == TYPE_DECL)
     {
       if (CLASS_TYPE_P (TREE_TYPE (decl)))
@@ -2061,6 +2066,15 @@ determine_visibility (tree decl)
 	  || ! DECL_VISIBILITY_SPECIFIED (decl))
 	constrain_visibility (decl, tvis);
     }
+
+  /* If visibility changed and DECL already has DECL_RTL, ensure
+     symbol flags are updated.  */
+  if ((DECL_VISIBILITY (decl) != orig_visibility
+       || DECL_VISIBILITY_SPECIFIED (decl) != orig_visibility_specified)
+      && ((TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
+	  || TREE_CODE (decl) == FUNCTION_DECL)
+      && DECL_RTL_SET_P (decl))
+    make_decl_rtl (decl);
 }
 
 /* By default, static data members and function members receive
--- gcc/testsuite/gcc.dg/visibility-20.c.jj	2009-02-13 12:24:42.000000000 +0100
+++ gcc/testsuite/gcc.dg/visibility-20.c	2009-02-13 12:27:00.000000000 +0100
@@ -0,0 +1,18 @@
+/* PR target/39175 */
+/* { dg-do compile } */
+/* { dg-require-visibility "" } */
+/* { dg-options "-O2 -fvisibility=hidden -fpic" { target fpic } } */
+
+__attribute__((noinline)) int
+foo (int x)
+{
+  return x;
+}
+
+int foo (int x);
+
+int
+bar (int x)
+{
+  return foo (x);
+}
--- gcc/testsuite/g++.dg/ext/visibility/visibility-11.C.jj	2009-02-13 12:25:19.000000000 +0100
+++ gcc/testsuite/g++.dg/ext/visibility/visibility-11.C	2009-02-13 12:27:09.000000000 +0100
@@ -0,0 +1,18 @@
+// PR target/39175
+// { dg-do compile }
+// { dg-require-visibility "" }
+// { dg-options "-O2 -fvisibility=hidden -fpic" { target fpic } }
+
+__attribute__((noinline)) int
+foo (int x)
+{
+  return x;
+}
+
+int foo (int x);
+
+int
+bar (int x)
+{
+  return foo (x);
+}

	Jakub



More information about the Gcc-patches mailing list