Re: [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2)

2016-01-07 Thread Bernd Schmidt

On 01/07/2016 10:36 PM, Jakub Jelinek wrote:


I've also bootstrapped/regtested on x86_64-linux and i686-linux
following version:

2016-01-07  Jakub Jelinek  

PR c++/69145
* files.c (cpp_included_before): If IS_ADHOC_LOC (location), lookup
real location from the line_table.

* g++.dg/ext/pr69145-1.C: New test.
* g++.dg/ext/pr69145-2-very-long-filename.cc: New file.
* g++.dg/ext/pr69145-2.h: New file.


I think this is OK.


Bernd


Re: [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2)

2016-01-07 Thread Jakub Jelinek
On Thu, Jan 07, 2016 at 01:49:12PM +0100, Bernd Schmidt wrote:
> On 01/07/2016 10:05 AM, Jakub Jelinek wrote:
> >+  if (IS_ADHOC_LOC (location))
> >+{
> >+  location &= MAX_SOURCE_LOCATION;
> >+  location
> >+= pfile->line_table->location_adhoc_data_map.data[location].locus;
> >+}
> 
> This looks like it is get_location_from_adhoc_loc.

I've also bootstrapped/regtested on x86_64-linux and i686-linux
following version:

2016-01-07  Jakub Jelinek  

PR c++/69145
* files.c (cpp_included_before): If IS_ADHOC_LOC (location), lookup
real location from the line_table.

* g++.dg/ext/pr69145-1.C: New test.
* g++.dg/ext/pr69145-2-very-long-filename.cc: New file.
* g++.dg/ext/pr69145-2.h: New file.

--- libcpp/files.c.jj   2016-01-05 12:26:58.0 +0100
+++ libcpp/files.c  2016-01-07 19:41:11.841870958 +0100
@@ -1224,10 +1224,12 @@ bool
 cpp_included_before (cpp_reader *pfile, const char *fname,
 source_location location)
 {
-  struct cpp_file_hash_entry *entry;
+  struct cpp_file_hash_entry *entry
+= (struct cpp_file_hash_entry *)
+  htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname));
 
-  entry = (struct cpp_file_hash_entry *)
- htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname));
+  if (IS_ADHOC_LOC (location))
+location = get_location_from_adhoc_loc (pfile->line_table, location);
 
   while (entry && (entry->start_dir == NULL || entry->u.file->err_no
   || entry->location > location))
--- gcc/testsuite/g++.dg/ext/pr69145-1.C.jj 2016-01-05 12:22:58.206729760 
+0100
+++ gcc/testsuite/g++.dg/ext/pr69145-1.C2016-01-05 12:22:52.017818392 
+0100
@@ -0,0 +1,4 @@
+// PR c++/69145
+// { dg-do compile }
+#pragma implementation "pr69145-2-very-long-filename.cc" // { dg-bogus 
"appears after file is included" }
+#include "pr69145-2-very-long-filename.cc"
--- gcc/testsuite/g++.dg/ext/pr69145-2-very-long-filename.cc.jj 2016-01-05 
12:23:47.151028824 +0100
+++ gcc/testsuite/g++.dg/ext/pr69145-2-very-long-filename.cc2016-01-05 
12:23:42.629093583 +0100
@@ -0,0 +1,3 @@
+// PR c++/69145
+// { dg-do compile } */
+#include "pr69145-2.h"
--- gcc/testsuite/g++.dg/ext/pr69145-2.h.jj 2016-01-05 12:23:49.963988539 
+0100
+++ gcc/testsuite/g++.dg/ext/pr69145-2.h2016-01-05 12:06:42.0 
+0100
@@ -0,0 +1,3 @@
+#ifndef PR69145_2_H
+# define PR69145_2_H
+#endif


Jakub


Re: [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2)

2016-01-07 Thread Bernd Schmidt

On 01/07/2016 10:05 AM, Jakub Jelinek wrote:

+  if (IS_ADHOC_LOC (location))
+{
+  location &= MAX_SOURCE_LOCATION;
+  location
+   = pfile->line_table->location_adhoc_data_map.data[location].locus;
+}


This looks like it is get_location_from_adhoc_loc.


Bernd


[PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2)

2016-01-07 Thread Jakub Jelinek
Hi!

On Tue, Jan 05, 2016 at 03:19:04PM -0500, David Malcolm wrote:
> Isn't the line_table available from the cpp_reader as a field, though?
> cpp_included_before could in theory access pfile->line_table.

You are right, that works too.
So I'm offering an alternate patch too:

2016-01-07  Jakub Jelinek  

PR c++/69145
* files.c (cpp_included_before): If IS_ADHOC_LOC (location), lookup
real location from the line_table.

* g++.dg/ext/pr69145-1.C: New test.
* g++.dg/ext/pr69145-2-very-long-filename.cc: New file.
* g++.dg/ext/pr69145-2.h: New file.

--- libcpp/files.c.jj   2016-01-05 12:26:58.0 +0100
+++ libcpp/files.c  2016-01-07 10:01:35.958676922 +0100
@@ -1224,10 +1224,16 @@ bool
 cpp_included_before (cpp_reader *pfile, const char *fname,
 source_location location)
 {
-  struct cpp_file_hash_entry *entry;
+  struct cpp_file_hash_entry *entry
+= (struct cpp_file_hash_entry *)
+  htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname));
 
-  entry = (struct cpp_file_hash_entry *)
- htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname));
+  if (IS_ADHOC_LOC (location))
+{
+  location &= MAX_SOURCE_LOCATION;
+  location
+   = pfile->line_table->location_adhoc_data_map.data[location].locus;
+}
 
   while (entry && (entry->start_dir == NULL || entry->u.file->err_no
   || entry->location > location))
--- gcc/testsuite/g++.dg/ext/pr69145-1.C.jj 2016-01-05 12:22:58.206729760 
+0100
+++ gcc/testsuite/g++.dg/ext/pr69145-1.C2016-01-05 12:22:52.017818392 
+0100
@@ -0,0 +1,4 @@
+// PR c++/69145
+// { dg-do compile }
+#pragma implementation "pr69145-2-very-long-filename.cc" // { dg-bogus 
"appears after file is included" }
+#include "pr69145-2-very-long-filename.cc"
--- gcc/testsuite/g++.dg/ext/pr69145-2-very-long-filename.cc.jj 2016-01-05 
12:23:47.151028824 +0100
+++ gcc/testsuite/g++.dg/ext/pr69145-2-very-long-filename.cc2016-01-05 
12:23:42.629093583 +0100
@@ -0,0 +1,3 @@
+// PR c++/69145
+// { dg-do compile } */
+#include "pr69145-2.h"
--- gcc/testsuite/g++.dg/ext/pr69145-2.h.jj 2016-01-05 12:23:49.963988539 
+0100
+++ gcc/testsuite/g++.dg/ext/pr69145-2.h2016-01-05 12:06:42.0 
+0100
@@ -0,0 +1,3 @@
+#ifndef PR69145_2_H
+# define PR69145_2_H
+#endif

Jakub