https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119222
--- Comment #5 from Gwen Fu <gwen3293940943 at gmail dot com> ---
Maybe the bug is related to the code below:
(in gcc/fold-const.cc :fold_binary_loc)
case RDIV_EXPR:
/* Don't touch a floating-point divide by zero unless the mode
of the constant can represent infinity. */
if (TREE_CODE (arg1) == REAL_CST
&& !MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg1)))
&& real_zerop (arg1))
return NULL_TREE;
/* (-A) / (-B) -> A / B */
if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
return fold_build2_loc (loc, RDIV_EXPR, type,
TREE_OPERAND (arg0, 0),
negate_expr (arg1));
if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0))
return fold_build2_loc (loc, RDIV_EXPR, type,
negate_expr (arg0),
TREE_OPERAND (arg1, 0));
These code uncovered that : There are two types of floating point numbers:
support infinity and do not support infinity.
And I tried to compile the testing code :
int foo() {
return 1/static_cast<double>(0) ;
}
int main()
{
double a = 1/static_cast<double>(0);
return 0 ;
}
Howerver , there is no warning .
SO is it feasible that these two situations can support infinity ?