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]

Re: [PATCH][C++] Fix PR60761, diagnostics in clones


Hi,

On Tue, Apr 08, 2014 at 01:58:06PM +0200, Richard Biener wrote:
> 
> This fixes PR60761 by dumping decl context of function clones
> as origin with <clone> appended instead of <built-in> that now
> appears after we (compared to 4.8) clear DECL_LANG_SPECIFIC.
> 
> Thus for the testcase in PR60761 we now print
> 
> t.ii: In function 'void foo(int) <clone>':
> t.ii:14:13: warning: iteration 3u invokes undefined behavior 
> [-Waggressive-loop-optimizations]
>      z[i] = i;
>              ^
> t.ii:13:3: note: containing loop
>    for (int i = 0; i < s; i++)
>    ^
> t.ii:14:8: warning: array subscript is above array bounds [-Warray-bounds]
>      z[i] = i;
>         ^
> 
> instead of
> 
> t.ii: In function â<built-in>â:
> t.ii:14:13: warning: iteration 3u invokes undefined behavior 
> [-Waggressive-loop-optimizations]
>      z[i] = i;
>              ^
> t.ii:13:3: note: containing loop
>    for (int i = 0; i < s; i++)
>    ^
> t.ii:14:8: warning: array subscript is above array bounds [-Warray-bounds]
>      z[i] = i;
>         ^
> 
> or with 4.8
> 
> t.ii: In function âvoid _Z3fooi.constprop.0()â:
> t.ii:14:8: warning: array subscript is above array bounds [-Warray-bounds]
>      z[i] = i;
>         ^
> 
> IMHO an improvement over both variants.
> 
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
> 
> Honza - does ->former_clone_of apply recursively or do I have to
> loop to find the "ultimate" clone-of?  Jason, is <clone> good
> or shall I use sth else (do we annotate in-charge vs. not in-charge
> constructors specially for example?).
> 
> Ok?
> 
> Thanks,
> Richard.
> 
> 2014-04-08  Richard Biener  <rguenther@suse.de>
> 
> 	cp/
> 	* error.c: Include cgraph.h
> 	(dump_decl): Print function clones as their origin plus <clone>
> 	appended instead of just <built-in>.
> 
> Index: gcc/cp/error.c
> ===================================================================
> *** gcc/cp/error.c	(revision 209210)
> --- gcc/cp/error.c	(working copy)
> *************** along with GCC; see the file COPYING3.
> *** 34,39 ****
> --- 34,40 ----
>   #include "pointer-set.h"
>   #include "c-family/c-objc.h"
>   #include "ubsan.h"
> + #include "cgraph.h"
>   
>   #include <new>                    // For placement-new.
>   
> *************** dump_decl (cxx_pretty_printer *pp, tree
> *** 1145,1151 ****
>   
>       case FUNCTION_DECL:
>         if (! DECL_LANG_SPECIFIC (t))
> ! 	pp_string (pp, M_("<built-in>"));
>         else if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
>   	dump_global_iord (pp, t);
>         else
> --- 1146,1162 ----
>   
>       case FUNCTION_DECL:
>         if (! DECL_LANG_SPECIFIC (t))
> ! 	{
> ! 	  cgraph_node *node;
> ! 	  if ((node = cgraph_get_node (t))
> ! 	      && node->former_clone_of)
> ! 	    {
> ! 	      dump_decl (pp, node->former_clone_of, flags);
> ! 	      pp_string (pp, M_(" <clone>"));
> ! 	    }
> ! 	  else
> ! 	    pp_string (pp, M_("<built-in>"));
> ! 	}
>         else if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
>   	dump_global_iord (pp, t);
>         else

I think you should use DECL_ABSTRACT_ORIGIN instead of
former_clone_of.  Not only you avoid using cgraph stuff here but
unlike this patch, it also works for IPA-CP clones of IPA-SRA clones
(yeah, I know, but I bet I can cause the same havoc by ipa-split
instead of ipa-sra, just not as easily).

The testcase is simmilar:

extern int sum;

void do_sum (char *p)
{
  for (int i = 0; i < 2; i++)
    sum += p[i];
}

static void
foo (int s, int unused)
{
  char z[3];
  for (int i = 0; i < s; i++)
    z[i] = i;
  do_sum (z);
}

int
bar (int i)
{
  foo (4, 3);
  return 0;
}


Thanks,

Martin


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