These builtins requires a constant integer for the third argument but currently
there is assert rather than error. This fixes that and updates the documentation too.
Uses the same terms as was being used for the __builtin_prefetch arguments.
Bootstrapped and tested on x86_64-linux-gnu.
PR middle-end/120709
gcc/ChangeLog:
* builtins.cc (expand_builtin_crc_table_based): Error out
instead of asserting the 3rd argument is an integer constant.
* internal-fn.cc (expand_crc_optab_fn): Likewise.
* doc/extend.texi (crc): Document requirement of the poly argument
being a constant.
gcc/testsuite/ChangeLog:
* gcc.dg/crc-non-cst-poly-1.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
(cherry picked from commit
be07dd9a96a7a6f8fb59c939eda84d74b54f8182)
rtx op1 = expand_normal (rhs1);
rtx op2 = expand_normal (rhs2);
- gcc_assert (TREE_CODE (rhs3) == INTEGER_CST);
- rtx op3 = gen_int_mode (TREE_INT_CST_LOW (rhs3), crc_mode);
+ rtx op3;
+ if (TREE_CODE (rhs3) != INTEGER_CST)
+ {
+ error ("third argument to %<crc%> builtins must be a constant");
+ op3 = const0_rtx;
+ }
+ else
+ op3 = convert_to_mode (crc_mode, expand_normal (rhs3), 0);
if (CONST_INT_P (op2))
- op2 = gen_int_mode (INTVAL (op2), crc_mode);
+ op2 = convert_to_mode (crc_mode, op2, 0);
if (fn == IFN_CRC)
expand_crc_table_based (target, op1, op2, op3, data_mode);
Returns the calculated 8-bit bit-reversed CRC using the initial CRC (8-bit),
data (8-bit) and the polynomial (8-bit).
@var{crc} is the initial CRC, @var{data} is the data and
-@var{poly} is the polynomial without leading 1.
+@var{poly} is the polynomial without leading 1. @var{poly} is required to be a compile-time constant.
Table-based or clmul-based CRC may be used for the
calculation, depending on the target architecture.
@enddefbuiltin
Returns the calculated 8-bit bit-forward CRC using the initial CRC (8-bit),
data (8-bit) and the polynomial (8-bit).
@var{crc} is the initial CRC, @var{data} is the data and
-@var{poly} is the polynomial without leading 1.
+@var{poly} is the polynomial without leading 1. @var{poly} is required to be a compile-time constant.
Table-based or clmul-based CRC may be used for the
calculation, depending on the target architecture.
@enddefbuiltin
rtx dest = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
rtx crc = expand_normal (rhs1);
rtx data = expand_normal (rhs2);
- gcc_assert (TREE_CODE (rhs3) == INTEGER_CST);
- rtx polynomial = gen_rtx_CONST_INT (TYPE_MODE (result_type),
- TREE_INT_CST_LOW (rhs3));
+ rtx polynomial;
+ if (TREE_CODE (rhs3) != INTEGER_CST)
+ {
+ error ("third argument to %<crc%> builtins must be a constant");
+ polynomial = const0_rtx;
+ }
+ else
+ polynomial = convert_to_mode (TYPE_MODE (result_type), expand_normal (rhs3), 0);
/* Use target specific expansion if it exists.
Otherwise, generate table-based CRC. */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+/* PR middle-end/120709 */
+/* Make sure we don't ICE on a non-constant poly argument. */
+
+
+typedef unsigned char uint8_t;
+uint8_t crc8_data8(uint8_t crc, uint8_t data, uint8_t polynomial) {
+ return __builtin_rev_crc32_data8 (crc, data, polynomial); /* { dg-error "must be a constant" } */
+}