Patchwork Add new warning -Wtrampolines

login
register
mail settings
Submitter Magnus Granberg
Date July 13, 2010, 12:30 a.m.
Message ID <201007130230.40175.zorry@gentoo.org>
Download mbox | patch
Permalink /patch/58695/
State New
Headers show

Comments

Magnus Granberg - July 13, 2010, 12:30 a.m.
On Monday 12 July 2010 16.22.30 you wrote:
> On 12 July 2010 13:53, Magnus Granberg <zorry@gentoo.org> wrote:
> > On Friday 02 July 2010 13.07.49 you wrote:
> >> Magnus,
> >> 
> >> Was this reviewed? If nobody offers to commit it, I will try to find
> >> some time to do it.
> >> 
> >> Cheers,
> >> 
> >> Manuel.
> > 
> > it was reviewed in irc and i need to change the location of the warning
> > msg in the testcase so i need to use warnings_at instead of warnings
> 
> Did you commit it? If you need someone to commit it, please send the
> updated patch and a changelog.
> 
> Cheers,
> 
> Manuel.
Updated patch with changelog for new review
gcc/
2010-07-13	Magnus Granberg <zorry@gentoo.org>, Kevin F. Quinn <kevquinn@gentoo.org>

		* builtins.c:  (expand_builtin_init_trampoline):	if -Wtrampolines make a warning.
		* common.opt:	Add -Wtrampolines.
		* doc/invoke.texi:	Add -Wtrampolines.
		* testsuite/gcc.dg/Wtrampolines.c:	New.
---
Manuel López-Ibáñez - July 13, 2010, 12:36 a.m.
I understood that it was oked in IRC subject to changes. If you just
did the changes you do not need a new review. If that is the case, I
will commit it if no one gets to it faster than me.

Thanks,

Manuel.

On 13 July 2010 02:30, Magnus Granberg <zorry@gentoo.org> wrote:
> On Monday 12 July 2010 16.22.30 you wrote:
>> On 12 July 2010 13:53, Magnus Granberg <zorry@gentoo.org> wrote:
>> > On Friday 02 July 2010 13.07.49 you wrote:
>> >> Magnus,
>> >>
>> >> Was this reviewed? If nobody offers to commit it, I will try to find
>> >> some time to do it.
>> >>
>> >> Cheers,
>> >>
>> >> Manuel.
>> >
>> > it was reviewed in irc and i need to change the location of the warning
>> > msg in the testcase so i need to use warnings_at instead of warnings
>>
>> Did you commit it? If you need someone to commit it, please send the
>> updated patch and a changelog.
>>
>> Cheers,
>>
>> Manuel.
> Updated patch with changelog for new review
> gcc/
> 2010-07-13      Magnus Granberg <zorry@gentoo.org>, Kevin F. Quinn <kevquinn@gentoo.org>
>
>                * builtins.c:  (expand_builtin_init_trampoline):        if -Wtrampolines make a warning.
>                * common.opt:   Add -Wtrampolines.
>                * doc/invoke.texi:      Add -Wtrampolines.
>                * testsuite/gcc.dg/Wtrampolines.c:      New.
> ---
>
Magnus Granberg - July 13, 2010, 12:31 p.m.
On Tuesday 13 July 2010 02.36.27 Manuel López-Ibáñez wrote:
> I understood that it was oked in IRC subject to changes. If you just
> did the changes you do not need a new review. If that is the case, I
> will commit it if no one gets to it faster than me.
> 
> Thanks,
> 
> Manuel.
> 
[14:16:21] <iant> Zorry: pong
[14:16:53] <Zorry> iant: havetime for some more review of the wtrampolin patch have move the location now http://gcc.gnu.org/ml/gcc-patches/2010-07/msg01019.html
[14:18:20] <iant> Zorry: that is OK
So fill free to commit the patch.
/Magnus
Manuel López-Ibáñez - July 15, 2010, 5:48 a.m.
Committed revision 162205.

Sorry for the dealy, I am on the road and it is difficult to find some
internet sometimes.

I fixed some errors in the patch, like using Warnings instead of
Warning in the opt file. Thanks for the patch, I hope to see more
patches from you guys in the future.

Cheers,

Manuel.

On 13 July 2010 14:31, Magnus Granberg <zorry@gentoo.org> wrote:
> On Tuesday 13 July 2010 02.36.27 Manuel López-Ibáñez wrote:
>> I understood that it was oked in IRC subject to changes. If you just
>> did the changes you do not need a new review. If that is the case, I
>> will commit it if no one gets to it faster than me.
>>
>> Thanks,
>>
>> Manuel.
>>
> [14:16:21] <iant> Zorry: pong
> [14:16:53] <Zorry> iant: havetime for some more review of the wtrampolin patch have move the location now http://gcc.gnu.org/ml/gcc-patches/2010-07/msg01019.html
> [14:18:20] <iant> Zorry: that is OK
> So fill free to commit the patch.
> /Magnus
>
Magnus Granberg - July 16, 2010, 12:45 a.m.
On Thursday 15 July 2010 07.48.07 you wrote:
> Committed revision 162205.
> 
> Sorry for the dealy, I am on the road and it is difficult to find some
> internet sometimes.
> 
> I fixed some errors in the patch, like using Warnings instead of
> Warning in the opt file. Thanks for the patch, I hope to see more
> patches from you guys in the future.
> 
> Cheers,
> 
> Manuel.
> 
Thank you all for the commit and help.

/Magnus

Patch

--- gcc/builtins.c.zorry	2010-04-13 15:47:11.000000000 +0200
+++ gcc/builtins.c			2010-06-16 12:33:54.000000000 +0200
@@ -5150,6 +5150,11 @@ 
   targetm.calls.trampoline_init (m_tramp, t_func, r_chain);
 
   trampolines_created = 1;
+
+  if (warn_trampolines)
+    warning_at (DECL_SOURCE_LOCATION (t_func), OPT_Wtrampolines,
+                       "trampoline generated for nested function %qD", t_func);
+
   return const0_rtx;
 }
 
--- gcc/common.opt.zorry	2010-03-18 04:01:09.000000000 +0100
+++ gcc/common.opt			2010-05-06 00:44:18.000000000 +0200
@@ -192,6 +192,10 @@ 
 Common Var(warn_system_headers) Warning
 Do not suppress warnings from system headers
 
+Wtrampolines
+Common Var(warn_trampolines) Warnings
+Warn whenever a trampoline is generated
+
 Wtype-limits
 Common Var(warn_type_limits) Init(-1) Warning
 Warn if a comparison is always true or always false due to the limited range of the data type
--- gcc/doc/invoke.texi.zorry	2010-04-06 16:02:22.000000000 +0200
+++ gcc/doc/invoke.texi			2010-05-06 00:20:25.000000000 +0200
@@ -258,8 +258,8 @@ 
 -Wstrict-aliasing -Wstrict-aliasing=n @gol
 -Wstrict-overflow -Wstrict-overflow=@var{n} @gol
 -Wswitch  -Wswitch-default  -Wswitch-enum -Wsync-nand @gol
--Wsystem-headers  -Wtrigraphs  -Wtype-limits  -Wundef  -Wuninitialized @gol
--Wunknown-pragmas  -Wno-pragmas @gol
+-Wsystem-headers  -Wtrampolines  -Wtrigraphs  -Wtype-limits  -Wundef @gol
+-Wuninitialized  -Wunknown-pragmas  -Wno-pragmas @gol
 -Wunsuffixed-float-constants  -Wunused  -Wunused-function @gol
 -Wunused-label  -Wunused-parameter -Wno-unused-result -Wunused-value  -Wunused-variable @gol
 -Wvariadic-macros -Wvla @gol
@@ -3603,6 +3603,18 @@ 
 option will @emph{not} warn about unknown pragmas in system
 headers---for that, @option{-Wunknown-pragmas} must also be used.
 
+@item -Wtrampolines
+@opindex Wtrampolines
+@opindex Wno-trampolines
+ Warn about trampolines generated for pointers to nested functions.
+ 
+ A trampoline is a small piece of data or code that is created at run
+ time on the stack when the address of a nested function is taken, and
+ is used to call the nested function indirectly.  For some targets, it
+ is made up of data only and thus requires no special treatment.  But,
+ for most targets, it is made up of code and thus requires the stack
+ to be made executable in order for the program to work properly.
+
 @item -Wfloat-equal
 @opindex Wfloat-equal
 @opindex Wno-float-equal
--- gcc/testsuite/gcc.dg/Wtrampolines.c.zorry	2010-05-05 12:53:11.000000000 +0200
+++ gcc/testsuite/gcc.dg/Wtrampolines.c			2010-05-06 00:26:05.000000000 +0200
@@ -0,0 +1,57 @@ 
+/* Origin: trampoline-1.c Waldek Hebisch <hebisch@math.uni.wroc.pl> */
+/* Ported to test -Wtrampolines Magnus Granberg <zorry@gentoo.org> */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target trampolines } */
+/* { dg-options "-O2 -Wtrampolines" } */
+
+#ifndef NO_TRAMPOLINES
+
+/* This used to fail on various versions of Solaris 2 because the
+   trampoline couldn't be made executable.  */
+
+extern void abort(void);
+extern double fabs(double);
+
+void foo (void)
+{
+  const int correct[1100] = {1, 0, -2, 0, 1, 0, 1, -1, -10, -30, -67};
+  int i;
+
+  double x1 (void) {return 1; }
+  double x2 (void) {return -1;}
+  double x3 (void) {return -1;}
+  double x4 (void) {return 1; }
+  double x5 (void) {return 0; }
+
+  typedef double pfun(void);
+
+  double a (int k, pfun x1, pfun x2, pfun x3, pfun x4, pfun x5)
+  {
+    double b (void)  /* { dg-warning "trampoline generated for nested function 'b'" } */
+    { 
+      k = k - 1;
+      return a (k, b, x1, x2, x3, x4 );
+    }
+
+    if (k <= 0)
+      return x4 () + x5 ();
+    else
+      return b ();
+  }
+
+  for (i=0; i<=10; i++)
+  {
+    if (fabs(a( i, x1, x2, x3, x4, x5 ) - correct [i]) > 0.1)
+      abort();
+  }
+}
+#endif
+
+int main (void)
+{
+#ifndef NO_TRAMPOLINES
+  foo ();
+#endif
+  return 0;
+}