- if (TREE_CODE (exp) == VAR_DECL)
- {
- /* We are making an ADDR_EXPR of ptrtype. This is a valid
- ADDR_EXPR because it's the best way of representing what
- happens in C when we take the address of an array and place
- it in a pointer to the element type. */
- adr = build1 (ADDR_EXPR, ptrtype, exp);
- if (!c_mark_addressable (exp))
- return error_mark_node;
- TREE_SIDE_EFFECTS (adr) = 0; /* Default would be, same as EXP. */
- return adr;
- }
- /* This way is better for a COMPONENT_REF since it can
- simplify the offset for a component. */
- adr = build_unary_op (ADDR_EXPR, exp, 1);
- return convert (ptrtype, adr);
+/* Perform the default conversion of arrays and functions to pointers.
+ Return the result of converting EXP. For any other expression, just
+ return EXP after removing NOPs. */
+
+struct c_expr
+default_function_array_conversion (struct c_expr exp)
+{
+ tree orig_exp = exp.value;
+ tree type = TREE_TYPE (exp.value);
+ enum tree_code code = TREE_CODE (type);
+
+ switch (code)
+ {
+ case ARRAY_TYPE:
+ {
+ bool not_lvalue = false;
+ bool lvalue_array_p;
+
+ while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
+ || TREE_CODE (exp.value) == NOP_EXPR
+ || TREE_CODE (exp.value) == CONVERT_EXPR)
+ && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
+ {
+ if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
+ not_lvalue = true;
+ exp.value = TREE_OPERAND (exp.value, 0);
+ }
+
+ if (TREE_NO_WARNING (orig_exp))
+ TREE_NO_WARNING (exp.value) = 1;
+
+ lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
+ if (!flag_isoc99 && !lvalue_array_p)
+ {
+ /* Before C99, non-lvalue arrays do not decay to pointers.
+ Normally, using such an array would be invalid; but it can
+ be used correctly inside sizeof or as a statement expression.
+ Thus, do not give an error here; an error will result later. */
+ return exp;
+ }
+
+ exp.value = array_to_pointer_conversion (exp.value);
+ }
+ break;
+ case FUNCTION_TYPE:
+ exp.value = function_to_pointer_conversion (exp.value);
+ break;
+ default:
+ STRIP_TYPE_NOPS (exp.value);
+ if (TREE_NO_WARNING (orig_exp))
+ TREE_NO_WARNING (exp.value) = 1;
+ break;