@@ -2040,6 +2040,7 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
2040
2040
opstack_push (compound_var );
2041
2041
add_insn (parent , * bb , OP_load_constant , compound_var , NULL ,
2042
2042
NULL , 0 , NULL );
2043
+ return ;
2043
2044
} else if (cast_or_literal_type -> base_type == TYPE_struct ||
2044
2045
cast_or_literal_type -> base_type == TYPE_typedef ) {
2045
2046
/* Struct compound literal support (following proposed solution
@@ -2154,21 +2155,14 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
2154
2155
/* Store first element value for array-to-scalar */
2155
2156
compound_var -> init_val = first_element -> init_val ;
2156
2157
2157
- /* Create result that provides first element access .
2158
- * This enables array compound literals in scalar
2159
- * contexts: int x = (int[]){1,2,3}; // x gets 1 int y
2160
- * = 5 + (int[]){10 }; // adds 5 + 10
2158
+ /* Return the array itself, let normal array decay handle conversion .
2159
+ * This enables both scalar and pointer contexts:
2160
+ * int x = (int[]){1,2,3}; // array decays to first element
2161
+ * int *p = (int[]){1,2,3 }; // array decays to pointer
2161
2162
*/
2162
- var_t * result_var = require_var (parent );
2163
- gen_name_to (result_var -> var_name );
2164
- result_var -> type = compound_var -> type ;
2165
- result_var -> ptr_level = 0 ;
2166
- result_var -> array_size = 0 ;
2167
-
2168
- /* Read first element from the array */
2169
- add_insn (parent , * bb , OP_read , result_var , compound_var ,
2170
- NULL , compound_var -> type -> size , NULL );
2171
- opstack_push (result_var );
2163
+ compound_var -> array_size = element_count ;
2164
+ compound_var -> ptr_level = 0 ;
2165
+ opstack_push (compound_var );
2172
2166
} else {
2173
2167
/* Single value: (int){42} - scalar compound literal */
2174
2168
compound_var = opstack_pop ();
0 commit comments