Re: [PATCH] Fix Linux/sparc build after generic asm output optimizations.

2011-11-12 Thread Eric Botcazou
 Any ELF target that overrides ASM_GENERATE_INTERNAL_LABEL is at risk
 of not building any more due to the recent elfos.h changes.

 Those changes require that the label format generated by
 ASM_GENERATE_INTERNAL_LABEL and TARGET_ASM_INTERNAL_LABEL are in sync,
 but that is only being ensured for targets that use elfos.h as-is.

And ASM_GENERATE_INTERNAL_LABEL uses stpcpy, which isn't portable.

 Eric, it seems that most if not all of the other ELF sparc targets
 will need something like this as well but I was only able to validate
 Linux at the moment.

Aren't all ELF targets of all architectures potentially affected?

-- 
Eric Botcazou


Re: [patch tree-optimization 1/2]: Branch-cost optimizations

2011-11-12 Thread Kai Tietz
2011/11/10 Jeff Law l...@redhat.com:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 11/09/11 14:09, Kai Tietz wrote:

 Well, such a comparison-logic-folder helper - like affine-tree for
 add/subtract/scale) - is for sure something good for inner gimple
 passes building up new logic-truth expressions, but such a pass
 doesn't meet requirements need to fold for BC optimization AFAICS.
 Perhaps.  I think the thing to do would be to see what additional
 needs we have and evaluate if they make sense in that kind of framework.


 The difference is that for BC we don't want to fold at all. Also
 it isn't necessarily simplified statement we want. For example
 'if ((a | b) == 0  ...) ...'.  If the costs of such pattern '(a |
 b) == 0' are too high, we want to representation it instead as 'if
 (a == 0) if (b == 0) ...'.
 We don't have to fold.  Think of this as an easy to use on-the-side
 representation of some operation(s).
Well, this is clear, but I see here not much re-use between
BC-optimization and general truth-logic folding.

The requirement that we need to handle comparisons for conditional
folding is mainly caused by the cond_expr itself.  As here we have no
ssa-comparison statement itself.  We have here left and right operand
plus a comparison-code.  So this kind of statement requires that we
handle it in tree.  Additional it might be a floating-point
comparison, where logical-invert can't be done on comparison's code
itself.  So we need here to introduce a dummy expression for such
cases (eg making a AST tree out of it).
One of the major difference I see between expanding for general
optimization vs. BC-optimization is the cost-analysis itself and the
decision, if we want to exloide a statment into its sub-parts, or
not.. For non-conditions, we don't want to look into multiple used
statements at all, but for BC we might want that, as long as statement
wasn't used before (in statement and dominators)  Also costs of a
statements operand depends on its use.  Means an operand with
multiple-use, which was prior to this statement evaluated, can be
considered as simple-statments with costs of 1, but a statement with
multiple use, which wasn't already evaluated has the costs of its
operations.

 What I would roughly expect to see is the set of operations feeding
 the comparison shoved into this structure.  With the full set of ops
 exposed into this structure we could look at the cost,
 canonicalize/simplify if appropriate, then select the best codegen
 strategy, modifying the on-the-side structure as needed.  We then
 reflect the final result back into the IL.

Well, the set of operations would be pretty limited IMHO.  It would be
logical and/or/not. May logical-xor could be interesting in some
cases, but not really sure if it is worth to handle it all, as a
logical-xor is normally a simple equal-compare in a condition.
Additionally we need function to read in a conditional-expression from
SSA-gimple form and built by it this representation and doing the
comparison-expansion (means eliminating logical-not expressions and
exploding some folded-patterns to their pure-logical expanded form -
like (A | B) ==/!= 0, (A  B) ==/!= ~0 for integral-typed A,B, .And
for boolean-typed A,B we might have things like A  B - !A  B,
etc.

 We have an condition 'if ((A | B) == 0  C == 0) ...' where the
 joining of A == 0 and C == 0 would be profitable by
 BC-optimization, but the join of A != 0 and B != 0 isn't. So we do
 - as my patch does - first an expand to element comparison-sequence
 view.

 So we get for it the transformed form 'if (A == 0  B == 0  C ==
 0)'.
 Right, so one of the first steps would be to canonicalize the (A|B) ==
 0  C == 0 form into something like you've shown above within this
 on-the-side structure.

Sure. with considering the simple characteristic of a
gimple-statement and evaluating elements costs.

 Now we can begin to search for valid patterns in the condition for
 joining by searching from left-to-right for a profitable pattern.
 So we end-up with final statement 'if ((A | C) == 0  C)'
 Which would be fairly straighforward using the on-the-side structure.

 I'm not sure what I'm missing since the description you've given fits
 very nicely with the overall approach Richi is suggesting.

The point is here more, that I don't see a share-ability of this
abstraction for BC and general condition-build-up, as the attributes
for them are quite different.  For a simple comparison-chain collector
we need indeed just an inverse, and a helper-mode to represent intial
condition-expression's compare.  For BC we would need to make out of
such a general tree a specialized one with the additional attributes
and expansion logic before we can work on it at all.  As for BC we
have always to operate on already created SSA-gimple form, we don't
need any operations on such a tree.  We just read it in to our
representation with calculating attributes, and then generating out of
it the new representation for BC.  And 

Fix bootstrap with solaris as

2011-11-12 Thread Jan Hubicka
Hi,
my reorg of wekarefs broke solaris bootstrap. The problem is that C++ FE 
produces
aliases for external variables/functions and expect them to be always thrown 
away.
I think this was originally an oversight, since they are completely useless for
rest of compilation but with new alias representation we ought to be able to use
them to prove that the two vars are known to be equivalent. This patch however 
just
prevents cgraphunit from outputting them and thus fixes the bootstrap issue.

Bootstrapped/regtested  comitted.
Honza
Index: ChangeLog
===
--- ChangeLog   (revision 181310)
+++ ChangeLog   (working copy)
@@ -1,3 +1,8 @@
+2011-11-12  Jan Hubicka  j...@suse.cz
+
+   PR bootstrap/50822
+   * cgraphunit.c (output_weakrefs): Output really only weakrefs.
+
 2011-11-12  Nathan Sidwell  nat...@acm.org
 
* gcov.c (struct name_map): New.
Index: cgraphunit.c
===
--- cgraphunit.c(revision 181310)
+++ cgraphunit.c(working copy)
@@ -2101,13 +2101,15 @@ output_weakrefs (void)
   struct varpool_node *vnode;
   for (node = cgraph_nodes; node; node = node-next)
 if (node-alias  DECL_EXTERNAL (node-decl)
- !TREE_ASM_WRITTEN (node-decl))
+ !TREE_ASM_WRITTEN (node-decl)
+lookup_attribute (weakref, DECL_ATTRIBUTES (node-decl)))
   assemble_alias (node-decl,
  node-thunk.alias ? DECL_ASSEMBLER_NAME 
(node-thunk.alias)
  : get_alias_symbol (node-decl));
   for (vnode = varpool_nodes; vnode; vnode = vnode-next)
 if (vnode-alias  DECL_EXTERNAL (vnode-decl)
- !TREE_ASM_WRITTEN (vnode-decl))
+ !TREE_ASM_WRITTEN (vnode-decl)
+lookup_attribute (weakref, DECL_ATTRIBUTES (vnode-decl)))
   assemble_alias (vnode-decl,
  vnode-alias_of ? DECL_ASSEMBLER_NAME (vnode-alias_of)
  : get_alias_symbol (vnode-decl));


Re: [PATCH 0/3] Conversion to __atomic builtins

2011-11-12 Thread David Edelsohn
On Sat, Nov 12, 2011 at 1:46 AM, Richard Henderson r...@redhat.com wrote:

 The first patch removes two avoidable warnings in rs6000.md.
 It seems like we could avoid many more of the remaining, but
 those are harder; this one was obvious.

 The second patch is a build error.  It has appeared on this
 list previously, but not yet applied.

  rs6000: fix*_trunc insns use nonimmediate_operand
  ppc-linux: Fix call to _Unwind_SetGRPtr

The first two patches are good.

The third will take a little more time to review.

Thanks, David


[Patch Powerpc/Darwin, committed] fix PR45233

2011-11-12 Thread Iain Sandoe

OK'd by Mike in the PR thread.
Applied to trunk and 4.6
Iain

gcc:

PR target/45233
* config/rs6000/rs6000.c (rs6000_legitimize_reload_address):
Only expand a symbol ref. into an access when the entity is defined
in the TU.

PR bootstrap/50822
Index: gcc/config/rs6000/rs6000.c
===
--- gcc/config/rs6000/rs6000.c  (revision 181311)
+++ gcc/config/rs6000/rs6000.c  (working copy)
@@ -6169,6 +6169,7 @@ rs6000_legitimize_reload_address (rtx x, enum mach
 #if TARGET_MACHO
DEFAULT_ABI == ABI_DARWIN
(flag_pic || MACHO_DYNAMIC_NO_PIC_P)
+   machopic_symbol_defined_p (x)
 #else
DEFAULT_ABI == ABI_V4
!flag_pic



Re: [PATCH] Fix Linux/sparc build after generic asm output optimizations.

2011-11-12 Thread Jason Merrill

On 11/12/2011 03:57 AM, Eric Botcazou wrote:

And ASM_GENERATE_INTERNAL_LABEL uses stpcpy, which isn't portable.


We just need to declare it in system.h in order to use the definition in 
libiberty.


Jason


[v3] fix libstdc++/51083

2011-11-12 Thread Jonathan Wakely
This allows __promote to be used like enable_if to constrain the TR1
and C++11 maths function overloads so they only work for floating
point and integral types.

PR libstdc++/51083
* include/ext/type_traits.h (__promote): Only define __type member
for integral and floating point types, to prevent math functions
participating in overload resolution for other types.
(__promote_2, __promote_3, __promote_4): Use __promote in default
template argument values, so deduction only succeeds for integral and
floating point types.
* testsuite/26_numerics/cmath/51083.cc: New.
* testsuite/26_numerics/complex/51083.cc: New.
* testsuite/tr1/8_c_compatibility/cmath/51083.cc: New.
* testsuite/tr1/8_c_compatibility/complex/51083.cc: New.

tested x86_64-linux, committed to trunk.

I'm undecided whether this counts as a regression or not and if it
should be applied to the 4.6 branch - the testcases worked before TR1
was added or without -std=c++0x.
Index: include/ext/type_traits.h
===
--- include/ext/type_traits.h   (revision 181320)
+++ include/ext/type_traits.h   (revision 181321)
@@ -161,44 +161,50 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct __promote
 { typedef double __type; };
 
+  // No nested __type member for non-integer non-floating point types,
+  // allows this type to be used for SFINAE to constrain overloads in
+  // cmath and complex to only the intended types.
   templatetypename _Tp
 struct __promote_Tp, false
-{ typedef _Tp __type; };
+{ };
 
-  templatetypename _Tp, typename _Up
+  template
+struct __promotelong double
+{ typedef long double __type; };
+
+  template
+struct __promotedouble
+{ typedef double __type; };
+
+  template
+struct __promotefloat
+{ typedef float __type; };
+
+  templatetypename _Tp, typename _Up,
+   typename _Tp2 = typename __promote_Tp::__type,
+   typename _Up2 = typename __promote_Up::__type
 struct __promote_2
 {
-private:
-  typedef typename __promote_Tp::__type __type1;
-  typedef typename __promote_Up::__type __type2;
-
-public:
-  typedef __typeof__(__type1() + __type2()) __type;
+  typedef __typeof__(_Tp2() + _Up2()) __type;
 };
 
-  templatetypename _Tp, typename _Up, typename _Vp
+  templatetypename _Tp, typename _Up, typename _Vp,
+   typename _Tp2 = typename __promote_Tp::__type,
+   typename _Up2 = typename __promote_Up::__type,
+   typename _Vp2 = typename __promote_Vp::__type
 struct __promote_3
 {
-private:
-  typedef typename __promote_Tp::__type __type1;
-  typedef typename __promote_Up::__type __type2;
-  typedef typename __promote_Vp::__type __type3;
-
-public:
-  typedef __typeof__(__type1() + __type2() + __type3()) __type;
+  typedef __typeof__(_Tp2() + _Up2() + _Vp2()) __type;
 };
 
-  templatetypename _Tp, typename _Up, typename _Vp, typename _Wp
+  templatetypename _Tp, typename _Up, typename _Vp, typename _Wp,
+   typename _Tp2 = typename __promote_Tp::__type,
+   typename _Up2 = typename __promote_Up::__type,
+   typename _Vp2 = typename __promote_Vp::__type,
+   typename _Wp2 = typename __promote_Wp::__type
 struct __promote_4
 {
-private:
-  typedef typename __promote_Tp::__type __type1;
-  typedef typename __promote_Up::__type __type2;
-  typedef typename __promote_Vp::__type __type3;
-  typedef typename __promote_Wp::__type __type4;
-
-public:
-  typedef __typeof__(__type1() + __type2() + __type3() + __type4()) __type;
+  typedef __typeof__(_Tp2() + _Up2() + _Vp2() + _Wp2()) __type;
 };
 
 _GLIBCXX_END_NAMESPACE_VERSION
Index: testsuite/26_numerics/complex/51083.cc
===
--- testsuite/26_numerics/complex/51083.cc  (revision 0)
+++ testsuite/26_numerics/complex/51083.cc  (revision 181321)
@@ -0,0 +1,54 @@
+// { dg-options -std=gnu++0x }
+//
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// http://www.gnu.org/licenses/.
+
+#include complex
+
+namespace a
+{
+  templatetypename class Mat { };
+
+  templatetypename T 

Re: PING 1 [Patch Ada RFA] make sure that multilibs are built with correct s-oscons.ads

2011-11-12 Thread Arnaud Charlet
 May I repeat my question re. 4.6?
 Since this is a wrong-code situation, I would have thought it eligible for
 a back-port?

Well, it's not a wrong-code as in wrong code generated by the back-end,
and it's not a regression.

In any case, backporting to 4.6 is fine with me.

Arno


Re: [v3] fix libstdc++/51083

2011-11-12 Thread Paolo Carlini
Hi

 I'm undecided whether this counts as a regression or not and if it
 should be applied to the 4.6 branch - the testcases worked before TR1
 was added or without -std=c++0x.

Thanks a lot for fixing this! About the branch, the patch seems safe enough to 
me, maybe just wait a couple if weeks?

Paolo


Re: [v3] fix libstdc++/51083

2011-11-12 Thread Jonathan Wakely
On 12 November 2011 16:24, Paolo Carlini wrote:
 Hi

 I'm undecided whether this counts as a regression or not and if it
 should be applied to the 4.6 branch - the testcases worked before TR1
 was added or without -std=c++0x.

 Thanks a lot for fixing this! About the branch, the patch seems safe enough 
 to me, maybe just wait a couple if weeks?

Yeah, that's what I was thinking too - will do, thanks.


Re: [Patch 001] [x86 backend] Define march/mtune for upcoming AMD Bulldozer procesor.

2011-11-12 Thread Uros Bizjak
On Fri, Nov 11, 2011 at 1:47 PM, Venkataramanan Kumar
venkataramanan.kumar@gmail.com wrote:

 Can you please check if these changes as Ok.

 On Thu, Nov 10, 2011 at 7:59 PM, Jan Hubicka hubi...@ucw.cz wrote:

  Hello!
 
   This patch defines -march=bdver1 and -mtune=bdver1 flag for the
   upcoming
   AMD Bulldozer processor.
 Hi,
 it seems that bdver/btver is not mentioned in invoke.texi nor
 changes.html.
 Could you please add documentation?

These are OK.

Thanks,
Uros.


Re: [PATCH 0/4][CFT] Handle legacy __sync libcalls

2011-11-12 Thread Richard Henderson
On 11/12/2011 07:56 AM, Richard Henderson wrote:
 On 11/11/2011 07:39 PM, Kaz Kojima wrote:
 It seems that expand_builtin sets target variable to
 const0_trx when ignore argument is set and this causes
 the above ICE.  I'm trying a patch ...
 
 I think the fix belongs in expand_builtin_compare_and_swap.
 I'm testing the following.

Full test completed on x86_64-linux.  I verified that the test
you mentioned no longer ICEs on sh4-linux.

Committed.


r~


Re: PATCH [1/n] addr32: Properly use Pmode and word_mode

2011-11-12 Thread Uros Bizjak
On Sat, Nov 12, 2011 at 3:19 AM, H.J. Lu hongjiu...@intel.com wrote:

 The current x32 implementation uses LEAs to convert 32bit address to
 64bit.  However, we can use addr32 prefix to use 32bit address directly.
 It improves performance by 5% in SPEC CPU 2K/2006.  All changes are done
 in x86 backend, except for a smaill unwind library assert change:

 http://gcc.gnu.org/ml/gcc-patches/2011-11/msg01555.html

 due to return column size difference.

 For x86-64, Pmode can be 32bit or 64bit, but word_mode is always 64bit.
 push/pop only work on word_mode.  Also string instructions take Pmode
 pointers.

 I will submit a set of patches to use 32bit Pmode for x32.  This is
 the first patch to properly use Pmode and word_mode.  It also adds
 addr32 prefix to string instructions if needed.  OK for trunk?

Not for stage3.

Uros.


Re: [Gcc.amd] [Patch 002] Document bdver1 in changes.html for GCC4.6

2011-11-12 Thread Gerald Pfeifer
On Fri, 11 Nov 2011, venkataramanan.ku...@amd.com wrote:
 Added bdver1 information to changes.html for GCC4.6
 
 is Ok to commit?

Looks good to me, yes.

Thanks,
Gerald


Re: [PATCH 3/4] hppa: Install __sync libfuncs for linux.

2011-11-12 Thread Gerald Pfeifer
On Fri, 11 Nov 2011, Richard Henderson wrote:
 @@ -136,3 +136,6 @@ along with GCC; see the file COPYING3.  If not see
  /* Linux always uses gas.  */
  #undef TARGET_GAS
  #define TARGET_GAS 1
 +
 +#undef TARGET_SYNC_LIBCALL
 +#define TARGET_SYNC_LIBCALL 1

John, Richard, while you are at it, mind making this GNU/Linux per
guidance from RMS?  (That'll save us work later on.)

I assume the ChangeLog entry also should refer to GNU/Linux?

Gerald


Re: [PATCH] Fix Linux/sparc build after generic asm output optimizations.

2011-11-12 Thread David Miller
From: Eric Botcazou ebotca...@adacore.com
Date: Sat, 12 Nov 2011 09:57:04 +0100

 Eric, it seems that most if not all of the other ELF sparc targets
 will need something like this as well but I was only able to validate
 Linux at the moment.
 
 Aren't all ELF targets of all architectures potentially affected?

Again, only those ELF targets which have an override for
ASM_GENERATE_INTERNAL_LABEL, which if you check is almost entirely
Sparc.

The normal thing to do is to use the elfos.h defines as-is.

In the end it was a good thing, as we can now get rid of these spurious
override sparc doesn't even need.


Fix permissions in update_web_docs_svn

2011-11-12 Thread Gerald Pfeifer
Benjamin maintains the libstdc++ manuals under /onlinedocs on
gcc.gnu.org, but we keep running into permissions problems.

The patch below addresses this such that he, and others in the
gcc group with login access, can take care of such changes.

Unless there are any objections, I am planning on checking this
in.  (The script is generally run as gccadmin with group gcc.)
Affirmative notes welcome as well. :-)

Gerald


2011-11-02  Gerald Pfeifer  ger...@pfeifer.com

* update_web_docs_svn: Make $DOCSDIR group writable after
creating it.

Index: update_web_docs_svn
===
--- update_web_docs_svn (revision 181325)
+++ update_web_docs_svn (working copy)
@@ -93,6 +93,7 @@
 
 if [ ! -d $DOCSDIR ]; then
   mkdir $DOCSDIR
+  chmod g+w $DOCSDIR
 fi
 
 if [ -z $RELEASE ]; then


Re: [PATCH] Fix Linux/sparc build after generic asm output optimizations.

2011-11-12 Thread Eric Botcazou
 Again, only those ELF targets which have an override for
 ASM_GENERATE_INTERNAL_LABEL, which if you check is almost entirely
 Sparc.

We probably aren't looking at the same tree then.  Alpha, IA-64, MIPS, HP-PA, 
SPARC and a few others have an override for ASM_GENERATE_INTERNAL_LABEL.

 The normal thing to do is to use the elfos.h defines as-is.

Target macros are meant to be overridden though.  If an implicit dependency has 
been introduced, then it should be documented and the tree should be audited.

-- 
Eric Botcazou


Re: [PATCH] Fix Linux/sparc build after generic asm output optimizations.

2011-11-12 Thread David Miller
From: Eric Botcazou ebotca...@adacore.com
Date: Sun, 13 Nov 2011 00:26:51 +0100

 Again, only those ELF targets which have an override for
 ASM_GENERATE_INTERNAL_LABEL, which if you check is almost entirely
 Sparc.
 
 We probably aren't looking at the same tree then.  Alpha, IA-64, MIPS, HP-PA, 
 SPARC and a few others have an override for ASM_GENERATE_INTERNAL_LABEL.

I am aware of these cases.

And when I took at look at them it seemed to me that these base target
headers where you see those defines either do not get used alongside
elfos.h or will come before elfos.h in the tmake file listing, thus
the elfos.h definition will take precedence.

On the other hand, on Sparc, the overrides occur in OS specific target
headers which appear after elfos.h in the tmake header file list.

 The normal thing to do is to use the elfos.h defines as-is.
 
 Target macros are meant to be overridden though.  If an implicit dependency 
 has 
 been introduced, then it should be documented and the tree should be audited.

Agreed.


Re: [PATCH 0/4][CFT] Handle legacy __sync libcalls

2011-11-12 Thread Kaz Kojima
Richard Henderson r...@redhat.com wrote:
 I think the fix belongs in expand_builtin_compare_and_swap.
 I'm testing the following.
 
 Full test completed on x86_64-linux.  I verified that the test
 you mentioned no longer ICEs on sh4-linux.
 
 Committed.

Thanks!

Regards,
kaz


PATCH for to use tree clobbers for c++/51060 (temporary re-use)

2011-11-12 Thread Jason Merrill
Now that we have a way of explicitly marking a variable as dead, we can 
use that to indicate the end of a temporary's lifetime by adding it as a 
cleanup for that temporary.  Since gimple_push_cleanup still deals in 
trees I needed to tweak a couple of places to avoid trying to treat a 
clobber as a real CONSTRUCTOR, but the changes were small.


One somewhat surprising thing that showed up as a result of this change 
were some failures in the libstdc++ testsuite.  When I investigated, I 
found that the tests were relying on temporaries living longer than they 
should:



 const int x = std::max(1, 2);


Since std::max takes its arguments by const reference and returns one of 
them, x ends up as a dangling reference to the temporary containing 2, 
which dies at the end of the declaration-statement.  This patch breaks 
the testcase because now the temporary stack slots get reused by the 
next statement, so by the time we look at x it no longer points to a 2. 
 I've fixed the tests by removing the references on the variables.


Tested x86_64-pc-linux-gnu, applying to trunk.
commit 007e09c084265ea24ca76db72083d90b3280
Author: Jason Merrill ja...@redhat.com
Date:   Fri Nov 11 17:42:30 2011 -0500

	PR c++/51060
	* gimplify.c (gimplify_target_expr): Add a clobber to the cleanup.
	(gimplify_modify_expr): Don't try to simplify it.
	* cp/cp-gimplify.c (cp_gimplify_expr): Leave clobbers alone.

diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index af45f59..9968c3d 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -569,7 +569,8 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
 
 	else if ((is_gimple_lvalue (op1) || INDIRECT_REF_P (op1)
 		  || (TREE_CODE (op1) == CONSTRUCTOR
-		   CONSTRUCTOR_NELTS (op1) == 0)
+		   CONSTRUCTOR_NELTS (op1) == 0
+		   !TREE_CLOBBER_P (op1))
 		  || (TREE_CODE (op1) == CALL_EXPR
 		   !CALL_EXPR_RETURN_SLOT_OPT (op1)))
 		  is_really_empty_class (TREE_TYPE (op0)))
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 9845b69..cfe6696 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -4554,6 +4554,16 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
   gcc_assert (TREE_CODE (*expr_p) == MODIFY_EXPR
 	  || TREE_CODE (*expr_p) == INIT_EXPR);
 
+  /* Trying to simplify a clobber using normal logic doesn't work,
+ so handle it here.  */
+  if (TREE_CLOBBER_P (*from_p))
+{
+  gcc_assert (!want_value  TREE_CODE (*to_p) == VAR_DECL);
+  gimplify_seq_add_stmt (pre_p, gimple_build_assign (*to_p, *from_p));
+  *expr_p = NULL;
+  return GS_ALL_DONE;
+}
+
   /* Insert pointer conversions required by the middle-end that are not
  required by the frontend.  This fixes middle-end type checking for
  for example gcc.dg/redecl-6.c.  */
@@ -5335,6 +5345,8 @@ gimplify_target_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
 
   if (init)
 {
+  tree cleanup = NULL_TREE;
+
   /* TARGET_EXPR temps aren't part of the enclosing block, so add it
 	 to the temps list.  Handle also variable length TARGET_EXPRs.  */
   if (TREE_CODE (DECL_SIZE (temp)) != INTEGER_CST)
@@ -5369,8 +5381,30 @@ gimplify_target_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
 
   /* If needed, push the cleanup for the temp.  */
   if (TARGET_EXPR_CLEANUP (targ))
-	gimple_push_cleanup (temp, TARGET_EXPR_CLEANUP (targ),
-			 CLEANUP_EH_ONLY (targ), pre_p);
+	{
+	  if (CLEANUP_EH_ONLY (targ))
+	gimple_push_cleanup (temp, TARGET_EXPR_CLEANUP (targ),
+ CLEANUP_EH_ONLY (targ), pre_p);
+	  else
+	cleanup = TARGET_EXPR_CLEANUP (targ);
+	}
+
+  /* Add a clobber for the temporary going out of scope, like
+	 gimplify_bind_expr.  */
+  if (needs_to_live_in_memory (temp))
+	{
+	  tree clobber = build_constructor (TREE_TYPE (temp), NULL);
+	  TREE_THIS_VOLATILE (clobber) = true;
+	  clobber = build2 (MODIFY_EXPR, TREE_TYPE (temp), temp, clobber);
+	  if (cleanup)
+	cleanup = build2 (COMPOUND_EXPR, void_type_node, cleanup,
+			  clobber);
+	  else
+	cleanup = clobber;
+	}
+
+  if (cleanup)
+	gimple_push_cleanup (temp, cleanup, false, pre_p);
 
   /* Only expand this once.  */
   TREE_OPERAND (targ, 3) = init;
diff --git a/gcc/testsuite/g++.dg/opt/stack2.C b/gcc/testsuite/g++.dg/opt/stack2.C
new file mode 100644
index 000..8468e1a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/stack2.C
@@ -0,0 +1,33 @@
+// PR c++/51060
+// { dg-options -Os -Wframe-larger-than=2000 -Werror }
+
+// Shows a problem of not re-using stack space:
+// Compile as: g++ -c test_stack_reuse.cpp -o /dev/null -Wframe-larger-than=2048 -Werror -Os
+// Result: warning: the frame size of 10240 bytes is larger than 2048 bytes [-Wframe-larger-than=]
+//
+
+struct StackObject
+{
+  StackObject();
+  char buffer[1024];
+};
+
+void Test()
+{
+#define TEST_SUB() \
+  StackObject();
+
+#define TEST() \
+	TEST_SUB() \
+	TEST_SUB() \
+	TEST_SUB() \
+	

C++ PATCH for c++/986 (warn about temporary bound to reference in constructor)

2011-11-12 Thread Jason Merrill
My recent work on fixing lifetime extension for temporaries bound to 
references makes it trivial to add this warning.


Tested x86_64-pc-linux-gnu, applied to trunk.
commit 1db25121594ff9405adeb5bd6892d72679bf2ba1
Author: Jason Merrill ja...@redhat.com
Date:   Sat Nov 12 20:42:21 2011 -0500

	PR c++/986
	* call.c (set_up_extended_ref_temp): Warn about references
	bound to non-static reference members.
	* init.c (perform_member_init): Pass in the member.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index dd3026d..181d9e8 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8609,6 +8609,14 @@ set_up_extended_ref_temp (tree decl, tree expr, VEC(tree,gc) **cleanups,
   if (TREE_CODE (expr) != TARGET_EXPR)
 expr = get_target_expr (expr);
 
+  if (TREE_CODE (decl) == FIELD_DECL
+   extra_warnings  !TREE_NO_WARNING (decl))
+{
+  warning (OPT_Wextra, a temporary bound to %qD only persists 
+	   until the constructor exits, decl);
+  TREE_NO_WARNING (decl) = true;
+}
+
   /* Recursively extend temps in this initializer.  */
   TARGET_EXPR_INITIAL (expr)
 = extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups);
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 888c151..73f2b67 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -623,7 +623,7 @@ perform_member_init (tree member, tree init)
   if (init == error_mark_node)
 	return;
   /* Use 'this' as the decl, as it has the lifetime we want.  */
-  init = extend_ref_init_temps (current_class_ptr, init, cleanups);
+  init = extend_ref_init_temps (member, init, cleanups);
   if (TREE_CODE (type) == ARRAY_TYPE
 	   TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (type)))
 	init = build_vec_init_expr (type, init, tf_warning_or_error);
diff --git a/gcc/testsuite/g++.dg/warn/ref-temp1.C b/gcc/testsuite/g++.dg/warn/ref-temp1.C
new file mode 100644
index 000..26f1ca5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/ref-temp1.C
@@ -0,0 +1,11 @@
+// PR c++/986
+// { dg-options -Wall -Wextra }
+
+struct X { X (int); };
+
+struct Y {
+  Y ();
+  const X x;			// note the ampersand
+};
+
+Y::Y () : x(1) {}		// { dg-warning temporary }