https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119222
--- Comment #16 from Gwen Fu <gwen3293940943 at gmail dot com> ---
I am void under the gcc/c-family/c-warn.cc file
warnings_for_convert_and_check (location_t loc, tree type, tree expr, tree
result) function performs the following judgment and processing:
/*"inifity to int" this operation belongs to FIX_TRUNC_EXPR*/
else if (TREE_CODE(result) == FIX_TRUNC_EXPR
&& TREE_CODE(exprtype) == REAL_TYPE)
{
bool warn_flag = false;
tree dst = expr;
/*Considering that it may be an assignment expression,
expr may be a variable declaration.*/
if(TREE_CODE(dst) == VAR_DECL)
dst = DECL_INITIAL(dst);
/*This situation has not been found during the debugging process,
but just in case, the judgment of this situation is still added*/
if (TREE_CODE(dst) == REAL_CST)
{
REAL_VALUE_TYPE value = TREE_REAL_CST(expr);
bool is_inf = REAL_VALUE_ISINF(value);
if (is_inf)
warn_flag = true;
}
else if (TREE_CODE(dst) == RDIV_EXPR
&& TREE_CODE (TREE_OPERAND(dst, 1)) == REAL_CST
&& real_zerop (TREE_OPERAND(dst, 1)))
warn_flag = true;
/*After getting the initial value of the variable,
the node type is FLOAT_EXPR*/
else if (TREE_CODE(dst) == FLOAT_EXPR)
{
tree op = dst; if(EXPR_P(TREE_OPERAND(op, 0)))
op = TREE_OPERAND(op, 0) ;
tree denominator = TREE_OPERAND(op, 1) ;
if ((TREE_CODE(denominator) == INTEGER_CST
&& integer_zerop(denominator)))
warn_flag = true;
}
if(warn_flag)
warning_at (loc, 0, "Undefined behavior : conversion "
"from %qT to %qT", expr, type);
conversion_warning(loc , type , expr , result);
}
When performing "make -check-gcc", a series of Fail messages are displayed in
the file gcc.dg/analyzer/data-model-1.c, but these messages did not appear
before the source code was modified:
FAIL: gcc.dg/analyzer/data-model-1.c (internal compiler error: Segmentation
fault)
FAIL: gcc.dg/analyzer/data-model-1.c (test for warnings, line 19)
.......
FAIL: gcc.dg/analyzer/data-model-1.c (test for warnings, line 1015)
FAIL: gcc.dg/analyzer/data-model-1.c (test for warnings, line 1016)
FAIL: gcc.dg/analyzer/data-model-1.c (test for warnings, line 1028)
FAIL: gcc.dg/analyzer/data-model-1.c (test for warnings, line 1029)
FAIL: gcc.dg/analyzer/data-model-1.c (test for excess errors)