diff mbox

Remove line 0 hack in cp/decl.c (issue4835047)

Message ID 20110802031540.DB6B81C13F2@gchare.mtv.corp.google.com
State New
Headers show

Commit Message

Gab Charette Aug. 2, 2011, 3:15 a.m. UTC
This hack, has described in more details in the email labeled "Line 0 Hack??", was now causing problem when serializing the line_table in pph.

According to the revision history: this was introduced by steven in 2005:
    commit ba821eb102fc1a654c0542fcba73898340a9a02d
    Author: steven <steven@138bc75d-0d04-0410-961f-82ee72b054a4>
    Date:   Sat Jan 1 16:15:23 2005 +0000

	    * emit-rtl.c (add_insn_before): Fix comment typo.
	
	    PR middle-end/17544
	    * c-decl.c (finish_function): If compiling C99, annotate the
	    compiler generated return with the current file name and line 0.
	    * tree-cfg.c (remove_useless_stmts_warn_notreached): Only warn if
	    the source line is greater than 0.

	    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@92784 138bc75d-0d04-0410-961f-82ee72b054a4

The function remove_useless_stmts_warn_notreached refered to by steven in his 2005 commit has been removed on 2009-10-08 by matz@suse.de according to ChangeLog-2009.

This patch removes this hack which appears to be no longer necessary.

Tested with a full bootstrap build and regression testing on x64.

Gabriel

2011-08-01  Gabriel Charette  <gchare@google.com>

	* decl.c (finish_function): Remove unecessary line 0 hack.


--
This patch is available for review at http://codereview.appspot.com/4835047

Comments

Tom Tromey Aug. 5, 2011, 5:37 p.m. UTC | #1
>>>>> "Gabriel" == Gabriel Charette <gchare@google.com> writes:

Gabriel> This hack, has described in more details in the email labeled
Gabriel> "Line 0 Hack??", was now causing problem when serializing the
Gabriel> line_table in pph.

I think you do have to handle location 0 somehow.
This is UNKNOWN_LOCATION, referred to widely in the sources.

Gabriel> 2011-08-01  Gabriel Charette  <gchare@google.com>
Gabriel> 	* decl.c (finish_function): Remove unecessary line 0 hack.

Now that -Wunreachable-code is gone, I doubt this code is even
theoretically relevant.  So, while I can't approve or reject this patch,
it seems reasonable to me.

Tom
Diego Novillo Aug. 5, 2011, 5:39 p.m. UTC | #2
On Fri, Aug 5, 2011 at 13:37, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Gabriel" == Gabriel Charette <gchare@google.com> writes:
>
> Gabriel> This hack, has described in more details in the email labeled
> Gabriel> "Line 0 Hack??", was now causing problem when serializing the
> Gabriel> line_table in pph.
>
> I think you do have to handle location 0 somehow.
> This is UNKNOWN_LOCATION, referred to widely in the sources.
>
> Gabriel> 2011-08-01  Gabriel Charette  <gchare@google.com>
> Gabriel>        * decl.c (finish_function): Remove unecessary line 0 hack.
>
> Now that -Wunreachable-code is gone, I doubt this code is even
> theoretically relevant.  So, while I can't approve or reject this patch,
> it seems reasonable to me.

In that case, this is OK for trunk.  Thanks Tom.


Diego.
Gab Charette Aug. 5, 2011, 6:18 p.m. UTC | #3
On Fri, Aug 5, 2011 at 10:37 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Gabriel" == Gabriel Charette <gchare@google.com> writes:
>
> Gabriel> This hack, has described in more details in the email labeled
> Gabriel> "Line 0 Hack??", was now causing problem when serializing the
> Gabriel> line_table in pph.
>
> I think you do have to handle location 0 somehow.
> This is UNKNOWN_LOCATION, referred to widely in the sources.
>

I do handle location 0, the problem is that this specific call to
linemap_line_start was made late, after all linemap entries had exited
(LC_LEAVE), and thus this would create a new LC_ENTER in the table and
the parsing would finish with line_table->depth == 1 (instead of 0 as
expected)... This bug never really showed up because at that point no
one is trying to add new entries to the line_table, it only shows up
now that we're trying to serialize the line_table.

> Gabriel> 2011-08-01  Gabriel Charette  <gchare@google.com>
> Gabriel>        * decl.c (finish_function): Remove unecessary line 0 hack.
>
> Now that -Wunreachable-code is gone, I doubt this code is even
> theoretically relevant.  So, while I can't approve or reject this patch,
> it seems reasonable to me.
>

Ok Thanks,
Gabriel
diff mbox

Patch

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 2000bd4..9ee3c6d 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13220,22 +13220,13 @@  finish_function (int flags)
     {
       if (DECL_MAIN_P (current_function_decl))
 	{
-	  tree stmt;
-
 	  /* Make it so that `main' always returns 0 by default (or
 	     1 for VMS).  */
 #if VMS_TARGET
-	  stmt = finish_return_stmt (integer_one_node);
+	  finish_return_stmt (integer_one_node);
 #else
-	  stmt = finish_return_stmt (integer_zero_node);
+	  finish_return_stmt (integer_zero_node);
 #endif
-	  /* Hack.  We don't want the middle-end to warn that this
-	     return is unreachable, so put the statement on the
-	     special line 0.  */
-	  {
-	    location_t linezero = linemap_line_start (line_table, 0, 1);
-	    SET_EXPR_LOCATION (stmt, linezero);
-	  }
 	}
 
       if (use_eh_spec_block (current_function_decl))