https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114492
Bug ID: 114492
Summary: Invalid use of gcc_assert (notably in
gcc/config/aarch64/aarch64-ldp-fusion.cc)
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: hp at gcc dot gnu.org
CC: acoplan at gcc dot gnu.org
Target Milestone: ---
Target: aarch64
I've noticed invalid uses of gcc_assert in
gcc/config/aarch64/aarch64-ldp-fusion.cc. Please be advised that the argument
is *not* evaluated with release checking; I believe most uses can be cured by
breaking out the call; i.e. replacing an invalid call:
gcc_assert (function_that_needs_to_be_called_but_most_certainly_returns_true())
with:
bool x = function_that_needs_to_be_called_but_most_certainly_returns_true ();
gcc_assert (x).
(Probably not the only file, just the one I've been looking at, for reasons,
and I thought better enter a bug report, just not going to fix it myself.)
Incidentally, I think "we" ought to add something to gcc that automatically
checks and warns for such invalid use. There may be a need to implement a
builtin to check that an expression X does not have side-effects, for use both
within gcc in gcc_assert and user-visible, for implementations of assert; say
__builtin_pure_p (X). (The name is ripe to bike-shedding, just choosing a mix
of __builtin_constant_p and the "pure" attribute.)