public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <tobias@codesourcery.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>, Jakub Jelinek <jakub@redhat.com>
Subject: [Patch] OpenMP requires: Fix diagnostic filename corner case
Date: Fri, 22 Jul 2022 12:38:31 +0200	[thread overview]
Message-ID: <e63fb3d3-50a2-8c31-9648-506fad70499e@codesourcery.com> (raw)

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

This patch addresses a corner case which causes a filename
confusion:
   lto1: error: OpenMP 'requires' directive with 'unified_address' specified only in some compilation units
   lto1: note: '1.c' has 'unified_address'
   lto1: note: but '1.c' has not
   lto1: fatal error: errors during merging of translation units

This happens, e.g., for a source code like the following, where two files
are identical except that only one has an additional '#pragma omp requires':

----------------
int
main ()
{
   int i;
   #pragma omp target map(from:i)
     i = 1;
   return i;
}
----------------

Both have 'main._omp_fn.0' - which gets merged to the same decl such
that the source file will be identical.

Without the fatal error shown for requires, it would fail later during
liking due to having the same symbol ('main') multiple times - but that
additional diagnostic is not reached, leaving one puzzled.

I did run into this with 'gcc -fopenmp test_*.c' missing that I had a
second file in that dir which also started with test_...

OK for mainline? Or do you think adding a testcase makes sense?

Tobias

PS: It might also be possible to generate this with class instantiations
for valid code - other than the requires mismatch.

PPS: If compiles as 'gcc -fopenmp .c' / in the testsuite, the new inform
will be:
   lto1: note: '/tmp/ccAs0w67.o' has 'unified_address'
   lto1: note: but '/tmp/ccv6XCfc.o' has not
That avoids the issue with showing the sane name but is not perfect, either.
But that's a known issue and splittitng compiling from linking will improve
the diagnostic!
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Attachment #2: requires-loc-fix.diff --]
[-- Type: text/x-patch, Size: 1153 bytes --]

OpenMP requires: Fix diagnostic filename corner case

The issue occurs when there is, e.g., main._omp_fn.0 in two files with
different OpenMP requires clauses.  The function entries in the offload
table ends up having the same decl tree and, hence, the diagnostic showed
the same filename for both.  Solution: Use the .o filename in this case.

Note that the issue does not occur with same-named 'static' functions and
without the fatal error from the requires diagnostic, there would be
later a linker error due to having two 'main'.

gcc/
	* lto-cgraph.cc (input_offload_tables): Improve requires diagnostic
	when filenames come out identically.

diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index 062677a32eb..350195d86db 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -1893,6 +1893,11 @@ input_offload_tables (bool do_force_output)
 		      if (tmp_decl != NULL_TREE)
 			fn2 = IDENTIFIER_POINTER (DECL_NAME (tmp_decl));
 		    }
+		  if (fn1 == fn2)
+		    {
+		      fn1 = requires_fn;
+		      fn2 = file_data->file_name;
+		    }
 
 		  char buf1[sizeof ("unified_address, unified_shared_memory, "
 				    "reverse_offload")];

             reply	other threads:[~2022-07-22 10:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22 10:38 Tobias Burnus [this message]
2022-08-17 13:43 ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e63fb3d3-50a2-8c31-9648-506fad70499e@codesourcery.com \
    --to=tobias@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).