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]

C++ PATCH: PR 5079


This patch fixes PR 5079, in which we failed to simplify arguments to
conditional expressions.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com


2003-08-28  Mark Mitchell  <mark@codesourcery.com>

	PR optimization/5079
	* call.c (build_conditional_expr): Use decl_constant_value to
	simplify the arguments.

2003-08-28  Mark Mitchell  <mark@codesourcery.com>

	PR optimization/5079
	* g++.dg/opt/static3.C: New test.

Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.425
diff -c -5 -p -r1.425 call.c
*** cp/call.c	26 Aug 2003 08:51:33 -0000	1.425
--- cp/call.c	28 Aug 2003 07:12:22 -0000
*************** build_conditional_expr (tree arg1, tree 
*** 3356,3365 ****
--- 3356,3367 ----
        error ("operands to ?: have different types");
        return error_mark_node;
      }
  
   valid_operands:
+   arg2 = decl_constant_value (arg2);
+   arg3 = decl_constant_value (arg3);
    result = fold (build (COND_EXPR, result_type, arg1, arg2, arg3));
    /* We can't use result_type below, as fold might have returned a
       throw_expr.  */
  
    /* Expand both sides into the same slot, hopefully the target of the
Index: testsuite/g++.dg/opt/static3.C
===================================================================
RCS file: testsuite/g++.dg/opt/static3.C
diff -N testsuite/g++.dg/opt/static3.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/opt/static3.C	28 Aug 2003 07:12:22 -0000
***************
*** 0 ****
--- 1,35 ----
+ // { dg-do link }
+ 
+ class Foo {
+ public:
+   // No out-of-class definition is provided for these class members.
+   // That's technically a violation of the standard, but no diagnostic
+   // is required, and, as a QOI issue, we should optimize away all
+   // references.
+   static const int erf = 0;
+   static const int foo = 1;
+ };
+ 
+ int one()
+ {
+   return Foo::foo;
+ }
+ 
+ int two()
+ {
+   return Foo::foo + Foo::erf;
+ }
+ 
+ int three(int x)
+ {
+   return x ? Foo::erf : Foo::foo;
+ }
+ 
+ int i;
+ 
+ int main ()
+ {
+   one ();
+   two ();
+   three (i);
+ }


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