https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64137
Bug ID: 64137 Summary: Fortran FE builds invalid GENERIC Product: gcc Version: 5.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org #6 0x000000000085f420 in gfc_conv_intrinsic_minmaxloc (se=0x7fffffffd150, expr=0x235ba70, op=GT_EXPR) at /space/rguenther/tramp3d/trunk/gcc/fortran/trans-intrinsic.c:3734 (gdb) l 3729 possible value is HUGE in both cases. */ 3730 if (op == GT_EXPR) 3731 tmp = fold_build1_loc (input_location, NEGATE_EXPR, TREE_TYPE (tmp), tmp); 3732 if (op == GT_EXPR && expr->ts.type == BT_INTEGER) 3733 tmp = fold_build2_loc (input_location, MINUS_EXPR, TREE_TYPE (tmp), tmp, 3734 build_int_cst (type, 1)); the body of the 2nd if builds REAL_CST - INTEGER_CST for at least gfortran.dg/maxloc_2.f90 at -O1+. Currently it is lucky that fold-const.c 10523 /* A - B -> A + (-B) if B is easily negatable. */ 10524 if (negate_expr_p (arg1) 10525 && !TYPE_OVERFLOW_SANITIZED (type) (gdb) l 10526 && ((FLOAT_TYPE_P (type) 10527 /* Avoid this transformation if B is a positive REAL_CST. */ 10528 && (TREE_CODE (arg1) != REAL_CST 10529 || REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1)))) 10530 || INTEGRAL_TYPE_P (type))) 10531 return fold_build2_loc (loc, PLUS_EXPR, type, 10532 fold_convert_loc (loc, type, arg0), 10533 fold_convert_loc (loc, type, 10534 negate_expr (arg1))); applies as that fold_convert()s to REAL after negating the integer, hiding this bug. When I move that to match.pd patterns that no longer happens, but we simply get -Huge + -1 with bogus types here. Not sure what is intended here (integer Huge or Float 1).