public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Fix #pragma implementation diagnostics (PR c++/69145)
@ 2016-01-05 18:23 Jakub Jelinek
  2016-01-05 20:19 ` David Malcolm
  0 siblings, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2016-01-05 18:23 UTC (permalink / raw)
  To: Jason Merrill, David Malcolm; +Cc: gcc-patches

Hi!

Now that input_location can be adhoc location (if it represents a location
range rather than a single loc and it is long enough), we need to avoid
passing it to cpp_included_before which compares locations as numbers.
This can't be done on the libcpp side, because cpp_included_before
isn't called with the line_table parameter.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-01-05  Jakub Jelinek  <jakub@redhat.com>

	PR c++/69145
	* lex.c (handle_pragma_implementation): Pass LOCATION_LOCUS
	of input_location instead of input_location itself to
	cpp_included_before.

	* 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.

--- gcc/cp/lex.c.jj	2016-01-04 14:55:57.000000000 +0100
+++ gcc/cp/lex.c	2016-01-05 12:27:36.056749882 +0100
@@ -408,7 +408,8 @@ handle_pragma_implementation (cpp_reader
   else
     {
       filename = TREE_STRING_POINTER (fname);
-      if (cpp_included_before (parse_in, filename, input_location))
+      if (cpp_included_before (parse_in, filename,
+			       LOCATION_LOCUS (input_location)))
 	warning (0, "#pragma implementation for %qs appears after "
 		 "file is included", filename);
     }
--- gcc/testsuite/g++.dg/ext/pr69145-1.C.jj	2016-01-05 12:22:58.206729760 +0100
+++ gcc/testsuite/g++.dg/ext/pr69145-1.C	2016-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.cc	2016-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.h	2016-01-05 12:06:42.000000000 +0100
@@ -0,0 +1,3 @@
+#ifndef PR69145_2_H
+# define PR69145_2_H
+#endif

	Jakub

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [C++ PATCH] Fix #pragma implementation diagnostics (PR c++/69145)
  2016-01-05 18:23 [C++ PATCH] Fix #pragma implementation diagnostics (PR c++/69145) Jakub Jelinek
@ 2016-01-05 20:19 ` David Malcolm
  2016-01-07  9:05   ` [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2) Jakub Jelinek
  0 siblings, 1 reply; 7+ messages in thread
From: David Malcolm @ 2016-01-05 20:19 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jason Merrill, gcc-patches

On Tue, 2016-01-05 at 19:23 +0100, Jakub Jelinek wrote:
> Hi!
> 
> Now that input_location can be adhoc location (if it represents a location
> range rather than a single loc and it is long enough), we need to avoid
> passing it to cpp_included_before which compares locations as numbers.
> This can't be done on the libcpp side, because cpp_included_before
> isn't called with the line_table parameter.
Isn't the line_table available from the cpp_reader as a field, though?
cpp_included_before could in theory access pfile->line_table.

That said, cp/lex.c seems to have the only usage of cpp_included_before.

> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2016-01-05  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/69145
> 	* lex.c (handle_pragma_implementation): Pass LOCATION_LOCUS
> 	of input_location instead of input_location itself to
> 	cpp_included_before.
> 
> 	* 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.
> 
> --- gcc/cp/lex.c.jj	2016-01-04 14:55:57.000000000 +0100
> +++ gcc/cp/lex.c	2016-01-05 12:27:36.056749882 +0100
> @@ -408,7 +408,8 @@ handle_pragma_implementation (cpp_reader
>    else
>      {
>        filename = TREE_STRING_POINTER (fname);
> -      if (cpp_included_before (parse_in, filename, input_location))
> +      if (cpp_included_before (parse_in, filename,
> +			       LOCATION_LOCUS (input_location)))
>  	warning (0, "#pragma implementation for %qs appears after "
>  		 "file is included", filename);
>      }
> --- gcc/testsuite/g++.dg/ext/pr69145-1.C.jj	2016-01-05 12:22:58.206729760 +0100
> +++ gcc/testsuite/g++.dg/ext/pr69145-1.C	2016-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.cc	2016-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.h	2016-01-05 12:06:42.000000000 +0100
> @@ -0,0 +1,3 @@
> +#ifndef PR69145_2_H
> +# define PR69145_2_H
> +#endif
> 
> 	Jakub


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2)
  2016-01-05 20:19 ` David Malcolm
@ 2016-01-07  9:05   ` Jakub Jelinek
  2016-01-07 12:49     ` Bernd Schmidt
  0 siblings, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2016-01-07  9:05 UTC (permalink / raw)
  To: David Malcolm, Dodji Seketeli; +Cc: Jason Merrill, gcc-patches

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  <jakub@redhat.com>

	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.000000000 +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.C	2016-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.cc	2016-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.h	2016-01-05 12:06:42.000000000 +0100
@@ -0,0 +1,3 @@
+#ifndef PR69145_2_H
+# define PR69145_2_H
+#endif

	Jakub

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2)
  2016-01-07  9:05   ` [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2) Jakub Jelinek
@ 2016-01-07 12:49     ` Bernd Schmidt
  2016-01-07 13:05       ` Jakub Jelinek
  2016-01-07 21:36       ` Jakub Jelinek
  0 siblings, 2 replies; 7+ messages in thread
From: Bernd Schmidt @ 2016-01-07 12:49 UTC (permalink / raw)
  To: Jakub Jelinek, David Malcolm, Dodji Seketeli; +Cc: Jason Merrill, gcc-patches

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2)
  2016-01-07 12:49     ` Bernd Schmidt
@ 2016-01-07 13:05       ` Jakub Jelinek
  2016-01-07 21:36       ` Jakub Jelinek
  1 sibling, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2016-01-07 13:05 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: David Malcolm, Dodji Seketeli, Jason Merrill, gcc-patches

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.

That is true, but all of libcpp (except for one spot) inlines that by hand,
don't know if for performance reasons or some other reason.
Though, cpp_included_before isn't performance critical, so I could use it.

	Jakub

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2)
  2016-01-07 12:49     ` Bernd Schmidt
  2016-01-07 13:05       ` Jakub Jelinek
@ 2016-01-07 21:36       ` Jakub Jelinek
  2016-01-08  3:01         ` Bernd Schmidt
  1 sibling, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2016-01-07 21:36 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: David Malcolm, Dodji Seketeli, Jason Merrill, gcc-patches

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  <jakub@redhat.com>

	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.000000000 +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.C	2016-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.cc	2016-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.h	2016-01-05 12:06:42.000000000 +0100
@@ -0,0 +1,3 @@
+#ifndef PR69145_2_H
+# define PR69145_2_H
+#endif


	Jakub

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2)
  2016-01-07 21:36       ` Jakub Jelinek
@ 2016-01-08  3:01         ` Bernd Schmidt
  0 siblings, 0 replies; 7+ messages in thread
From: Bernd Schmidt @ 2016-01-08  3:01 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: David Malcolm, Dodji Seketeli, Jason Merrill, gcc-patches

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  <jakub@redhat.com>
>
> 	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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-01-08  3:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-05 18:23 [C++ PATCH] Fix #pragma implementation diagnostics (PR c++/69145) Jakub Jelinek
2016-01-05 20:19 ` David Malcolm
2016-01-07  9:05   ` [PATCH] Fix #pragma implementation diagnostics (PR c++/69145, take 2) Jakub Jelinek
2016-01-07 12:49     ` Bernd Schmidt
2016-01-07 13:05       ` Jakub Jelinek
2016-01-07 21:36       ` Jakub Jelinek
2016-01-08  3:01         ` Bernd Schmidt

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).