https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123370
Bug ID: 123370
Summary: ICE: in build_conditional_expr, at c/c-typeck.cc with
_Float16 and ternary operator
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: 522024330006 at smail dot nju.edu.cn
Target Milestone: ---
Reproducer: https://godbolt.org/z/ndffP591n
An Internal Compiler Error occurs during the semantic analysis of a ternary
operator when one results in a _Float16 calculation and the other results in a
logical int. This happens specifically when the compiler cannot resolve a
common type between the two operands of the conditional expression.
Code:
```c
typedef _Float16 TFtype;
int main() {
TFtype x = (TFtype)3.14;
TFtype y = (TFtype)1.0;
int n = 0;
return (y == x) ? (y + n) : !(x - y);
}
```
Traceback:
```
internal compiler error: in build_conditional_expr, at c/c-typeck.cc:6107
25 | return y == x ? y + n : !(x - y);
| ^~~~~~
0x569ce3c internal_error(char const*, ...)
/workspace/install/gcc/src/gcc/gcc/diagnostic-global-context.cc:517
0x563a4de fancy_abort(char const*, int, char const*)
/workspace/install/gcc/src/gcc/gcc/diagnostic.cc:1749
0xeaf93c build_conditional_expr(unsigned long, tree_node*, bool, tree_node*,
tree_node*, unsigned long, tree_node*, tree_node*, unsigned long)
/workspace/install/gcc/src/gcc/gcc/c/c-typeck.cc:6107
0xf516e9 c_parser_conditional_expression
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:10030
0xf5039d c_parser_expr_no_commas
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:9864
0xf6b9d7 c_parser_expression
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:13918
0xf6c12a c_parser_expression_conv
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:13977
0xf478c7 c_parser_statement_after_labels
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:8269
0xf4598a c_parser_compound_statement_nostart
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:7800
0xf414a3 c_parser_compound_statement
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:7018
0xf2ead7 c_parser_declaration_or_fndef
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:3218
0xf29809 c_parser_external_declaration
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:2150
0xf28c9b c_parser_translation_unit
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:2004
0xfd4dac c_parse_file()
/workspace/install/gcc/src/gcc/gcc/c/c-parser.cc:29833
0x1106e32 c_common_parse_file()
/workspace/install/gcc/src/gcc/gcc/c-family/c-opts.cc:1381
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
```