This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR optimization/13472


Hi,

This is again a problem that shows up only on the 3.3 branch, but is probably 
latent on mainline.  When the testcase is compiled with -O2 -march=i686 
-pedantic, a store to .rodata is emitted, which leads to a segfault at 
runtime.  And, most surprisingly, removing -pedantic makes the problem 
disappear!!

Here's what I wrote in the audit trail:
"The final culprit is the reload pass: it generates the store (although the 
MEM is marked as unchanging) because it thinks the memory location is a 
regular spill slot.  It appears that the reload pass doesn't care about the 
/u flag when recording equivalent memory locations based on the presence of 
REG_EQUIV notes.

But I don't know if this is really a reload problem: maybe reload implicitly
expects full equivalence between objects in pairs that carry REG_EQUIV notes.

In any cases, the dependence upon -pedantic is certainly a bug and is 
actually recognized as such in the code (c-typeck.c:790):

/* Return either DECL or its known constant value (if it has one), but
   return DECL if pedantic or DECL has mode BLKmode.  This is for
   bug-compatibility with the old behavior of decl_constant_value
   (before GCC 3.0); every use of this function is a bug and it should
   be removed before GCC 3.1.  It is not appropriate to use pedantic
   in a way that affects optimization, and BLKmode is probably not the
   right test for avoiding misoptimizations either.  */

static tree
decl_constant_value_for_broken_optimization (decl)
     tree decl;
{
  if (pedantic || DECL_MODE (decl) == BLKmode)
    return decl;
  else
    return decl_constant_value (decl);
}


So I think the fix is to remove decl_constant_value_for_broken_optimization
altogether from the C front-end.  But this is probably not doable on a 
release branch."


I've attached the patch that does this on mainline.  Bootstrapped/regtested
on i586-redhat-linux-gnu (mainline except Ada and libgcj).


2003-12-23  Eric Botcazou  <ebotcazou@libertysurf.fr>

        * c-typeck.c (decl_constant_value_for_broken_optimization): Delete.
	(default_conversion): Call decl_constant_value instead of it.
	(convert_for_assignment): Likewise.
	(digest_init): Likewise.
 

-- 
Eric Botcazou
#define MAX2(a,b) (((a)>(b)) ? (a) : (b))

const int q=0, p=0;

typedef struct {
	float a;
	float b;
} F;

F **E, *D, C = { 2.f, 1.f };

void G(float);
void H(void);
#if 0
int main()
{
	D = &C;
	E = &D;

	H();
}
#endif
void H(void)
{
	int i, l=1;
	float b, o;

	if( l )
	{
		b = 0.3f * MAX2(0.f,E[q][p].a - E[q][p].b);
		o = E[q][p].a;
		if( o > 1.e-36f )
                        G(o);
		E[q][p].a *= b;
	}
	else
		b = 1.f;
	for( i=q; i<2; ++i )
		;
}

void G(float o)
{
}
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.267
diff -u -p -r1.267 c-typeck.c
--- c-typeck.c	23 Dec 2003 05:26:40 -0000	1.267
+++ c-typeck.c	23 Dec 2003 15:57:00 -0000
@@ -55,7 +55,6 @@ static int tagged_types_tu_compatible_p 
 static int comp_target_types (tree, tree, int);
 static int function_types_compatible_p (tree, tree, int);
 static int type_lists_compatible_p (tree, tree, int);
-static tree decl_constant_value_for_broken_optimization (tree);
 static tree default_function_array_conversion (tree);
 static tree lookup_field (tree, tree);
 static tree convert_arguments (tree, tree, tree, tree);
@@ -994,24 +993,6 @@ decl_constant_value (tree decl)
   return decl;
 }
 
-/* Return either DECL or its known constant value (if it has one), but
-   return DECL if pedantic or DECL has mode BLKmode.  This is for
-   bug-compatibility with the old behavior of decl_constant_value
-   (before GCC 3.0); every use of this function is a bug and it should
-   be removed before GCC 3.1.  It is not appropriate to use pedantic
-   in a way that affects optimization, and BLKmode is probably not the
-   right test for avoiding misoptimizations either.  */
-
-static tree
-decl_constant_value_for_broken_optimization (tree decl)
-{
-  if (pedantic || DECL_MODE (decl) == BLKmode)
-    return decl;
-  else
-    return decl_constant_value (decl);
-}
-
-
 /* Perform the default conversion of arrays and functions to pointers.
    Return the result of converting EXP.  For any other expression, just
    return EXP.  */
@@ -1137,7 +1118,7 @@ default_conversion (tree exp)
      address of the array produces consistent results.  */
   else if (optimize && TREE_CODE (exp) == VAR_DECL && code != ARRAY_TYPE)
     {
-      exp = decl_constant_value_for_broken_optimization (exp);
+      exp = decl_constant_value (exp);
       type = TREE_TYPE (exp);
     }
 
@@ -3366,7 +3347,7 @@ convert_for_assignment (tree type, tree 
       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
     rhs = default_conversion (rhs);
   else if (optimize && TREE_CODE (rhs) == VAR_DECL)
-    rhs = decl_constant_value_for_broken_optimization (rhs);
+    rhs = decl_constant_value (rhs);
 
   rhstype = TREE_TYPE (rhs);
   coder = TREE_CODE (rhstype);
@@ -4126,7 +4107,7 @@ digest_init (tree type, tree init, int r
 	}
 
       if (optimize && TREE_CODE (inside_init) == VAR_DECL)
-	inside_init = decl_constant_value_for_broken_optimization (inside_init);
+	inside_init = decl_constant_value (inside_init);
 
       /* Compound expressions can only occur here if -pedantic or
 	 -pedantic-errors is specified.  In the later case, we always want

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]