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