public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-107] genconditions: Add support for targets without non-trivial insn conditions
Date: Wed,  4 May 2022 10:03:03 +0000 (GMT)	[thread overview]
Message-ID: <20220504100303.B41BE3858010@sourceware.org> (raw)

https://gcc.gnu.org/g:8afcd148103b0467126483151b6fb5ac68920e72

commit r13-107-g8afcd148103b0467126483151b6fb5ac68920e72
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed May 4 12:01:56 2022 +0200

    genconditions: Add support for targets without non-trivial insn conditions
    
    Somebody complained on IRC that when writing a new backend one can get
    an error while compiling build/gencondmd.cc.
    The problem is that when host compiler is g++ 3 or later (or when
    bootstrapping), we compile it with g++ -std=c++11 -pedantic and
    the generated insn_conditions array contains pairs
    { "cond", __builtin_constant_p (cond) ? (int) (cond) : -1 },
    where cond is some non-trivial instruction condition.  Now if a target
    uses "" for all the conditions (admittedly unlikely for non-trivial
    target), the initializer for insn_conditions[] is {} and that is
    pedantically rejected because C++ doesn't support zero-sized arrays.
    
    The following patch fixes that by adding an artificial termination
    element and skips that during the walk.
    
    2022-05-04  Jakub Jelinek  <jakub@redhat.com>
    
            * genconditions.cc (write_conditions): Append a { nullptr, -1 }
            element at the end of insn_conditions.
            (write_writer): Use ARRAY_SIZE (insn_conditions) - 1 instead of
            ARRAY_SIZE (insn_conditions).

Diff:
---
 gcc/genconditions.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/genconditions.cc b/gcc/genconditions.cc
index 202813dac8c..f63a3f495c5 100644
--- a/gcc/genconditions.cc
+++ b/gcc/genconditions.cc
@@ -175,7 +175,7 @@ static const struct c_test insn_conditions[] = {\n");
 
   traverse_c_tests (write_one_condition, 0);
 
-  puts ("\n};\n#endif /* gcc >= 3.0.1 */\n");
+  puts ("  { nullptr, -1 }\n};\n#endif /* gcc >= 3.0.1 */\n");
 }
 
 /* Emit code which will convert the C-format table to a
@@ -192,7 +192,7 @@ write_writer (void)
         "  const char *p;\n"
         "  puts (\"(define_conditions [\");\n"
 	"#if GCC_VERSION >= 3001\n"
-	"  for (i = 0; i < ARRAY_SIZE (insn_conditions); i++)\n"
+	"  for (i = 0; i < ARRAY_SIZE (insn_conditions) - 1; i++)\n"
 	"    {\n"
 	"      printf (\"  (%d \\\"\", insn_conditions[i].value);\n"
 	"      for (p = insn_conditions[i].expr; *p; p++)\n"


                 reply	other threads:[~2022-05-04 10:03 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=20220504100303.B41BE3858010@sourceware.org \
    --to=jakub@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).