public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom de Vries <vries@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7094] [nvptx] Fix 'main (int argc)' compilation
Date: Tue,  8 Feb 2022 09:02:01 +0000 (GMT)	[thread overview]
Message-ID: <20220208090201.B0ECC385841F@sourceware.org> (raw)

https://gcc.gnu.org/g:73f4a989b7f8aeaf8bff37e7f33b65d26b8f179f

commit r12-7094-g73f4a989b7f8aeaf8bff37e7f33b65d26b8f179f
Author: Tom de Vries <tdevries@suse.de>
Date:   Mon Feb 7 14:50:13 2022 +0100

    [nvptx] Fix 'main (int argc)' compilation
    
    On nvptx, with test-case sso-12.c I run into:
    ...
    spawn nvptx-none-run ./sso-12.exe^M
    error: Prototype doesn't match for 'main' in 'input file 1 at offset 1796', \
      first defined in 'input file 1 at offset 1796'^M
    nvptx-run: cuLinkAddData failed: device kernel image is invalid \
      (CUDA_ERROR_INVALID_SOURCE, 300)^M
    FAIL: gcc.dg/sso-12.c execution test
    ...
    
    The problem is that the test case uses 'main (int)' prototype, while __main
    uses:
    ...
    extern int main (int, void **);
    ...
    
    There's code in write_fn_proto_1 to handle 'main (void)' as if
    'main (int, void **)' was specified, but that's not active for 'main (int)'.
    
    Fix this in write_fn_proto_1 by handling 'main (int)' as if
    'main (int, void **)' was specified.
    
    Tested on nvptx.
    
    gcc/ChangeLog:
    
    2022-02-07  Tom de Vries  <tdevries@suse.de>
    
            * config/nvptx/nvptx.cc (write_fn_proto_1): Handle 'main (int)'.

Diff:
---
 gcc/config/nvptx/nvptx.cc | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index 2a694926b7a..006fac8c839 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -938,10 +938,13 @@ write_fn_proto_1 (std::stringstream &s, bool is_defn,
   if (DECL_STATIC_CHAIN (decl))
     argno = write_arg_type (s, -1, argno, ptr_type_node, true);
 
-  if (!argno && strcmp (name, "main") == 0)
+  if (argno < 2 && strcmp (name, "main") == 0)
     {
-      argno = write_arg_type (s, -1, argno, integer_type_node, true);
-      argno = write_arg_type (s, -1, argno, ptr_type_node, true);
+      if (argno == 0)
+	argno = write_arg_type (s, -1, argno, integer_type_node, true);
+
+      if (argno == 1)
+	argno = write_arg_type (s, -1, argno, ptr_type_node, true);
     }
 
   if (argno)


                 reply	other threads:[~2022-02-08  9:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220208090201.B0ECC385841F@sourceware.org \
    --to=vries@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).