https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123887
Bug ID: 123887
Summary: [14/15/16 Regression] wrong-code with COND_EXPR
folding on GENERIC
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
Target Milestone: ---
#include <stdbool.h>
typedef struct {
unsigned s;
} struct_t;
struct_t *p;
bool cond;
int main()
{
int u = 1 + (cond ? p->s : 0);
return u;
}
crashes since GCC 14, where we start folding it to
int u = (int) ((unsigned int) cond * p->s + 1);
via
/* (zero_one != 0) ? z <op> y : y -> ((typeof(y))zero_one * z) <op> y */
(for op (bit_xor bit_ior plus)
(simplify
(cond (ne zero_one_valued_p@0
integer_zerop)
(op:c @2 @1)
@1)
(if (INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (type) > 1
&& (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
(op (mult (convert:type @0) @2) @1))))
usually GENERIC folding guards this with TREE_SIDE_EFFECTS, but the
p->s tree does not have this flag set. It's folded via c_fully_fold_internal
called from digest_init. The C++ frontend does not have this issue.
Splitting declaration of u from init doesn't make a difference, c_fully_fold
is then called via build_modify_expr.