public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* don't consider 'main' inlinable
@ 2015-12-18 14:36 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2015-12-18 14:36 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 486 bytes --]

When looking at ipa's creation of calls to main 
(https://gcc.gnu.org/ml/gcc-patches/2015-12/msg01812.html), I discovered this 
piece of code in tree-inline.c.

Explicitly calling main is a strange thing to do from anywhere but crt0 (and 
ill-formed c++).  However, we should probably not consider main as an inlinable 
function without some user annotation.  I guess we might encounter something 
like the testcase with whole-program optimization.

tested on x86_64-linux, ok?

nathan

[-- Attachment #2: trunk-main.patch --]
[-- Type: text/x-patch, Size: 1546 bytes --]

2015-12-18  Nathan Sidwell  <nathan@acm.org>

	gcc/
	* tree-inline.c (tree_inlinable_function_p): Don't consider main
	inlinable, unless told so.

	gcc/testsuite/
	* gcc.dg/ipa/inline-9.c: New.

Index: tree-inline.c
===================================================================
--- tree-inline.c	(revision 231815)
+++ tree-inline.c	(working copy)
@@ -3793,6 +3793,16 @@ tree_inlinable_function_p (tree fn)
       inlinable = false;
     }
 
+  else if (!DECL_DECLARED_INLINE_P (fn)
+	   && !always_inline
+	   && TREE_PUBLIC (fn)
+	   && DECL_FILE_SCOPE_P (fn)
+	   && MAIN_NAME_P (DECL_NAME (fn)))
+    /* Inlining main is usually a bad idea, but not forbidden.  So
+       only inibit inlining it, if the user's not explicitly asked for
+       it to be inlinable.  */
+    inlinable = false;
+
   /* Squirrel away the result so that we don't have to check again.  */
   DECL_UNINLINABLE (fn) = !inlinable;
 
Index: testsuite/gcc.dg/ipa/inline-9.c
===================================================================
--- testsuite/gcc.dg/ipa/inline-9.c	(revision 0)
+++ testsuite/gcc.dg/ipa/inline-9.c	(working copy)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O2 -fdump-tree-inline_param1 -fdump-tree-einline" } */
+
+/* Make sure we don't inline 'main'.  */
+
+int main (int argc, char **argv)
+{
+  return argc;
+}
+
+int x ()
+{
+  return main (1, 0);
+}
+
+/* { dg-final { scan-tree-dump-not "for main/1 inlinable" "inline_param1" } } */
+/* { df-final { scan-tree-dump "main \\(1, 0B\\)" "einline" } } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-12-18 14:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-18 14:36 don't consider 'main' inlinable Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).