diff options
author | Jakub Jelinek <jakub@redhat.com> | 2023-09-07 11:17:04 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2023-09-07 11:17:04 +0200 |
commit | 18c90eaa25363d34b5bef444fbbad04f5da2522d (patch) | |
tree | fa7311153f6f81450f473c1192964159979ce75f | |
parent | 5b857e87201335148f23ec7134cf7fbf97c04c72 (diff) | |
download | gcc-18c90eaa25363d34b5bef444fbbad04f5da2522d.zip gcc-18c90eaa25363d34b5bef444fbbad04f5da2522d.tar.gz gcc-18c90eaa25363d34b5bef444fbbad04f5da2522d.tar.bz2 |
middle-end: Avoid calling targetm.c.bitint_type_info inside of gcc_assert [PR102989]
On Thu, Sep 07, 2023 at 10:36:02AM +0200, Thomas Schwinge wrote:
> Minor comment/question: are we doing away with the property that
> 'assert'-like "calls" must not have side effects? Per 'gcc/system.h',
> this is "OK" for 'gcc_assert' for '#if ENABLE_ASSERT_CHECKING' or
> '#elif (GCC_VERSION >= 4005)' -- that is, GCC 4.5, which is always-true,
> thus the "offending" '#else' is never active. However, it's different
> for standard 'assert' and 'gcc_checking_assert', so I'm not sure if
> that's a good property for 'gcc_assert' only? For example, see also
> <https://gcc.gnu.org/PR6906> "warn about asserts with side effects", or
> recent <https://gcc.gnu.org/PR111144>
> "RFE: could -fanalyzer warn about assertions that have side effects?".
You're right, the
#define gcc_assert(EXPR) ((void)(0 && (EXPR)))
fallback definition is incompatible with the way I've used it, so for
--disable-checking built by non-GCC it would not work properly.
2023-09-07 Jakub Jelinek <jakub@redhat.com>
PR c/102989
* expr.cc (expand_expr_real_1): Don't call targetm.c.bitint_type_info
inside gcc_assert, as later code relies on it filling info variable.
* gimple-fold.cc (clear_padding_bitint_needs_padding_p,
clear_padding_type): Likewise.
* varasm.cc (output_constant): Likewise.
* fold-const.cc (native_encode_int, native_interpret_int): Likewise.
* stor-layout.cc (finish_bitfield_representative, layout_type):
Likewise.
* gimple-lower-bitint.cc (bitint_precision_kind): Likewise.
-rw-r--r-- | gcc/expr.cc | 3 | ||||
-rw-r--r-- | gcc/fold-const.cc | 8 | ||||
-rw-r--r-- | gcc/gimple-fold.cc | 6 | ||||
-rw-r--r-- | gcc/gimple-lower-bitint.cc | 3 | ||||
-rw-r--r-- | gcc/stor-layout.cc | 6 | ||||
-rw-r--r-- | gcc/varasm.cc | 4 |
6 files changed, 18 insertions, 12 deletions
diff --git a/gcc/expr.cc b/gcc/expr.cc index d6b5bd0..d5b6494 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -11039,7 +11039,8 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, { unsigned int prec = TYPE_PRECISION (type); struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (prec, &info)); + bool ok = targetm.c.bitint_type_info (prec, &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode); unsigned int limb_prec = GET_MODE_PRECISION (limb_mode); diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 5b481a2..1da498a 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -7731,8 +7731,8 @@ native_encode_int (const_tree expr, unsigned char *ptr, int len, int off) if (TREE_CODE (type) == BITINT_TYPE) { struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), - &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode); if (TYPE_PRECISION (type) > GET_MODE_PRECISION (limb_mode)) { @@ -8661,8 +8661,8 @@ native_interpret_int (tree type, const unsigned char *ptr, int len) if (TREE_CODE (type) == BITINT_TYPE) { struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), - &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode); if (TYPE_PRECISION (type) > GET_MODE_PRECISION (limb_mode)) { diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index a25b2fd..04d9fac 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -4602,7 +4602,8 @@ static bool clear_padding_bitint_needs_padding_p (tree type) { struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); if (info.extended) return false; scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode); @@ -4880,7 +4881,8 @@ clear_padding_type (clear_padding_struct *buf, tree type, case BITINT_TYPE: { struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode); if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode)) { diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc index dceaec7..cf4bcfc 100644 --- a/gcc/gimple-lower-bitint.cc +++ b/gcc/gimple-lower-bitint.cc @@ -92,7 +92,8 @@ bitint_precision_kind (int prec) return bitint_prec_middle; struct bitint_info info; - gcc_assert (targetm.c.bitint_type_info (prec, &info)); + bool ok = targetm.c.bitint_type_info (prec, &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode); if (prec <= GET_MODE_PRECISION (limb_mode)) { diff --git a/gcc/stor-layout.cc b/gcc/stor-layout.cc index 7471127..ba375fa 100644 --- a/gcc/stor-layout.cc +++ b/gcc/stor-layout.cc @@ -2152,7 +2152,8 @@ finish_bitfield_representative (tree repr, tree field) { struct bitint_info info; unsigned prec = TYPE_PRECISION (TREE_TYPE (field)); - gcc_assert (targetm.c.bitint_type_info (prec, &info)); + bool ok = targetm.c.bitint_type_info (prec, &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode); unsigned lprec = GET_MODE_PRECISION (limb_mode); if (prec > lprec) @@ -2413,7 +2414,8 @@ layout_type (tree type) { struct bitint_info info; int cnt; - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode); if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode)) { diff --git a/gcc/varasm.cc b/gcc/varasm.cc index 76064af..b0eff17 100644 --- a/gcc/varasm.cc +++ b/gcc/varasm.cc @@ -5289,8 +5289,8 @@ output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align, { struct bitint_info info; tree type = TREE_TYPE (exp); - gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), - &info)); + bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info); + gcc_assert (ok); scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode); if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode)) { |