static void c_parser_do_statement (c_parser *);
static void c_parser_for_statement (c_parser *);
static tree c_parser_asm_statement (c_parser *);
-static tree c_parser_asm_operands (c_parser *);
+static tree c_parser_asm_operands (c_parser *, bool);
static tree c_parser_asm_clobbers (c_parser *);
static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
static struct c_expr c_parser_conditional_expression (c_parser *,
static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
struct c_expr);
static struct c_expr c_parser_expression (c_parser *);
-static tree c_parser_expr_list (c_parser *);
+static struct c_expr c_parser_expression_conv (c_parser *);
+static tree c_parser_expr_list (c_parser *, bool);
/* These Objective-C parser functions are only ever called when
compiling Objective-C. */
{
c_parser_consume_token (parser);
attr_args = tree_cons (NULL_TREE, arg1,
- c_parser_expr_list (parser));
+ c_parser_expr_list (parser, false));
}
}
else
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
attr_args = NULL_TREE;
else
- attr_args = c_parser_expr_list (parser);
+ attr_args = c_parser_expr_list (parser, false);
}
attr = build_tree_list (attr_name, attr_args);
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
return c_parser_braced_init (parser, NULL_TREE, false);
else
- return c_parser_expr_no_commas (parser, NULL);
+ {
+ struct c_expr ret;
+ ret = c_parser_expr_no_commas (parser, NULL);
+ if (TREE_CODE (ret.value) != STRING_CST
+ && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
+ ret.value = default_function_array_conversion (ret.value);
+ return ret;
+ }
}
/* Parse a braced initializer list. TYPE is the type specified for a
tree next;
c_parser_consume_token (parser);
next = c_parser_expr_no_commas (parser, NULL).value;
+ next = default_function_array_conversion (next);
rec = build_compound_expr (rec, next);
}
parse_message_args:
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
init = c_parser_braced_init (parser, NULL_TREE, true);
else
- init = c_parser_expr_no_commas (parser, after);
+ {
+ init = c_parser_expr_no_commas (parser, after);
+ if (init.value != NULL_TREE
+ && TREE_CODE (init.value) != STRING_CST
+ && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
+ init.value = default_function_array_conversion (init.value);
+ }
process_init_element (init);
}
}
else
{
- stmt = c_finish_return (c_parser_expression (parser).value);
+ stmt = c_finish_return (c_parser_expression_conv (parser).value);
goto expect_semicolon;
}
break;
break;
default:
expr_stmt:
- stmt = c_finish_expr_stmt (c_parser_expression (parser).value);
+ stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
expect_semicolon:
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
break;
return error_mark_node;
loc = c_parser_peek_token (parser)->location;
cond = c_objc_common_truthvalue_conversion
- (c_parser_expression (parser).value);
+ (c_parser_expression_conv (parser).value);
if (EXPR_P (cond))
SET_EXPR_LOCATION (cond, loc);
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
}
else
{
- tree ocond = c_parser_expression (parser).value;
+ tree ocond = c_parser_expression_conv (parser).value;
cond = c_objc_common_truthvalue_conversion (ocond);
if (EXPR_P (cond))
SET_EXPR_LOCATION (cond, loc);
|| c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
outputs = NULL_TREE;
else
- outputs = c_parser_asm_operands (parser);
+ outputs = c_parser_asm_operands (parser, false);
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
{
inputs = NULL_TREE;
|| c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
inputs = NULL_TREE;
else
- inputs = c_parser_asm_operands (parser);
+ inputs = c_parser_asm_operands (parser, true);
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
{
clobbers = NULL_TREE;
return ret;
}
-/* Parse asm operands, a GNU extension.
+/* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
+ not outputs), apply the default conversion of functions and arrays
+ to pointers.
asm-operands:
asm-operand
*/
static tree
-c_parser_asm_operands (c_parser *parser)
+c_parser_asm_operands (c_parser *parser, bool convert_p)
{
tree list = NULL_TREE;
while (true)
return NULL_TREE;
}
expr = c_parser_expression (parser).value;
+ if (convert_p)
+ expr = default_function_array_conversion (expr);
c_lex_string_translate = 0;
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
{
}
c_parser_consume_token (parser);
rhs = c_parser_expr_no_commas (parser, NULL);
+ rhs.value = default_function_array_conversion (rhs.value);
ret.value = build_modify_expr (lhs.value, code, rhs.value);
if (code == NOP_EXPR)
ret.original_code = MODIFY_EXPR;
cond = c_parser_binary_expression (parser, after);
if (c_parser_next_token_is_not (parser, CPP_QUERY))
return cond;
+ cond.value = default_function_array_conversion (cond.value);
c_parser_consume_token (parser);
if (c_parser_next_token_is (parser, CPP_COLON))
{
= c_objc_common_truthvalue_conversion
(default_conversion (cond.value));
skip_evaluation += cond.value == truthvalue_false_node;
- exp1 = c_parser_expression (parser);
+ exp1 = c_parser_expression_conv (parser);
skip_evaluation += ((cond.value == truthvalue_true_node)
- (cond.value == truthvalue_false_node));
}
return ret;
}
exp2 = c_parser_conditional_expression (parser, NULL);
+ exp2.value = default_function_array_conversion (exp2.value);
skip_evaluation -= cond.value == truthvalue_true_node;
ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
ret.original_code = ERROR_MARK;
default: \
break; \
} \
+ stack[sp - 1].expr.value \
+ = default_function_array_conversion (stack[sp - 1].expr.value); \
+ stack[sp].expr.value \
+ = default_function_array_conversion (stack[sp].expr.value); \
stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
stack[sp - 1].expr, \
stack[sp].expr); \
switch (ocode)
{
case TRUTH_ANDIF_EXPR:
+ stack[sp].expr.value
+ = default_function_array_conversion (stack[sp].expr.value);
stack[sp].expr.value = c_objc_common_truthvalue_conversion
(default_conversion (stack[sp].expr.value));
skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
break;
case TRUTH_ORIF_EXPR:
+ stack[sp].expr.value
+ = default_function_array_conversion (stack[sp].expr.value);
stack[sp].expr.value = c_objc_common_truthvalue_conversion
(default_conversion (stack[sp].expr.value));
skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
return c_parser_postfix_expression_after_paren_type (parser,
type_name);
expr = c_parser_cast_expression (parser, NULL).value;
+ expr = default_function_array_conversion (expr);
ret.value = c_cast_expr (type_name, expr);
ret.original_code = ERROR_MARK;
return ret;
c_parser_unary_expression (c_parser *parser)
{
int ext;
- struct c_expr ret;
+ struct c_expr ret, op;
switch (c_parser_peek_token (parser)->type)
{
case CPP_PLUS_PLUS:
c_parser_consume_token (parser);
- return parser_build_unary_op (PREINCREMENT_EXPR,
- c_parser_cast_expression (parser, NULL));
+ op = c_parser_cast_expression (parser, NULL);
+ op.value = default_function_array_conversion (op.value);
+ return parser_build_unary_op (PREINCREMENT_EXPR, op);
case CPP_MINUS_MINUS:
c_parser_consume_token (parser);
- return parser_build_unary_op (PREDECREMENT_EXPR,
- c_parser_cast_expression (parser, NULL));
+ op = c_parser_cast_expression (parser, NULL);
+ op.value = default_function_array_conversion (op.value);
+ return parser_build_unary_op (PREDECREMENT_EXPR, op);
case CPP_AND:
c_parser_consume_token (parser);
return parser_build_unary_op (ADDR_EXPR,
c_parser_cast_expression (parser, NULL));
case CPP_MULT:
c_parser_consume_token (parser);
- ret.value
- = build_indirect_ref (c_parser_cast_expression (parser, NULL).value,
- "unary *");
+ op = c_parser_cast_expression (parser, NULL);
+ op.value = default_function_array_conversion (op.value);
+ ret.value = build_indirect_ref (op.value, "unary *");
ret.original_code = ERROR_MARK;
return ret;
case CPP_PLUS:
if (!c_dialect_objc () && !in_system_header)
warning (OPT_Wtraditional,
"traditional C rejects the unary plus operator");
- return parser_build_unary_op (CONVERT_EXPR,
- c_parser_cast_expression (parser, NULL));
+ op = c_parser_cast_expression (parser, NULL);
+ op.value = default_function_array_conversion (op.value);
+ return parser_build_unary_op (CONVERT_EXPR, op);
case CPP_MINUS:
c_parser_consume_token (parser);
- return parser_build_unary_op (NEGATE_EXPR,
- c_parser_cast_expression (parser, NULL));
+ op = c_parser_cast_expression (parser, NULL);
+ op.value = default_function_array_conversion (op.value);
+ return parser_build_unary_op (NEGATE_EXPR, op);
case CPP_COMPL:
c_parser_consume_token (parser);
- return parser_build_unary_op (BIT_NOT_EXPR,
- c_parser_cast_expression (parser, NULL));
+ op = c_parser_cast_expression (parser, NULL);
+ op.value = default_function_array_conversion (op.value);
+ return parser_build_unary_op (BIT_NOT_EXPR, op);
case CPP_NOT:
c_parser_consume_token (parser);
- return parser_build_unary_op (TRUTH_NOT_EXPR,
- c_parser_cast_expression (parser, NULL));
+ op = c_parser_cast_expression (parser, NULL);
+ op.value = default_function_array_conversion (op.value);
+ return parser_build_unary_op (TRUTH_NOT_EXPR, op);
case CPP_AND_AND:
/* Refer to the address of a label as a pointer. */
c_parser_consume_token (parser);
return ret;
case RID_REALPART:
c_parser_consume_token (parser);
- return parser_build_unary_op (REALPART_EXPR,
- c_parser_cast_expression (parser,
- NULL));
+ op = c_parser_cast_expression (parser, NULL);
+ op.value = default_function_array_conversion (op.value);
+ return parser_build_unary_op (REALPART_EXPR, op);
case RID_IMAGPART:
c_parser_consume_token (parser);
- return parser_build_unary_op (IMAGPART_EXPR,
- c_parser_cast_expression (parser,
- NULL));
+ op = c_parser_cast_expression (parser, NULL);
+ op.value = default_function_array_conversion (op.value);
+ return parser_build_unary_op (IMAGPART_EXPR, op);
default:
return c_parser_postfix_expression (parser);
}
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
exprlist = NULL_TREE;
else
- exprlist = c_parser_expr_list (parser);
+ exprlist = c_parser_expr_list (parser, true);
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
"expected %<)%>");
expr.value = build_function_call (expr.value, exprlist);
case CPP_DOT:
/* Structure element reference. */
c_parser_consume_token (parser);
+ expr.value = default_function_array_conversion (expr.value);
if (c_parser_next_token_is (parser, CPP_NAME))
ident = c_parser_peek_token (parser)->value;
else
case CPP_DEREF:
/* Structure element reference. */
c_parser_consume_token (parser);
+ expr.value = default_function_array_conversion (expr.value);
if (c_parser_next_token_is (parser, CPP_NAME))
ident = c_parser_peek_token (parser)->value;
else
case CPP_PLUS_PLUS:
/* Postincrement. */
c_parser_consume_token (parser);
+ expr.value = default_function_array_conversion (expr.value);
expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
expr.original_code = ERROR_MARK;
break;
case CPP_MINUS_MINUS:
/* Postdecrement. */
c_parser_consume_token (parser);
+ expr.value = default_function_array_conversion (expr.value);
expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
expr.original_code = ERROR_MARK;
break;
struct c_expr next;
c_parser_consume_token (parser);
next = c_parser_expr_no_commas (parser, NULL);
+ next.value = default_function_array_conversion (next.value);
expr.value = build_compound_expr (expr.value, next.value);
expr.original_code = COMPOUND_EXPR;
}
return expr;
}
-/* Parse a non-empty list of expressions.
+/* Parse an expression and convert functions or arrays to
+ pointers. */
+
+static struct c_expr
+c_parser_expression_conv (c_parser *parser)
+{
+ struct c_expr expr;
+ expr = c_parser_expression (parser);
+ expr.value = default_function_array_conversion (expr.value);
+ return expr;
+}
+
+/* Parse a non-empty list of expressions. If CONVERT_P, convert
+ functions and arrays to pointers.
nonempty-expr-list:
assignment-expression
*/
static tree
-c_parser_expr_list (c_parser *parser)
+c_parser_expr_list (c_parser *parser, bool convert_p)
{
struct c_expr expr;
tree ret, cur;
expr = c_parser_expr_no_commas (parser, NULL);
+ if (convert_p)
+ expr.value = default_function_array_conversion (expr.value);
ret = cur = build_tree_list (NULL_TREE, expr.value);
while (c_parser_next_token_is (parser, CPP_COMMA))
{
c_parser_consume_token (parser);
expr = c_parser_expr_no_commas (parser, NULL);
+ if (convert_p)
+ expr.value = default_function_array_conversion (expr.value);
cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
}
return ret;
static tree
c_parser_objc_keywordexpr (c_parser *parser)
{
- tree list = c_parser_expr_list (parser);
+ tree list = c_parser_expr_list (parser, true);
if (TREE_CHAIN (list) == NULL_TREE)
{
/* Just return the expression, remove a level of
static int function_types_compatible_p (tree, tree);
static int type_lists_compatible_p (tree, tree);
static tree decl_constant_value_for_broken_optimization (tree);
-static tree default_function_array_conversion (tree);
static tree lookup_field (tree, tree);
static tree convert_arguments (tree, tree, tree, tree);
static tree pointer_diff (tree, tree);
/* Perform the default conversion of arrays and functions to pointers.
Return the result of converting EXP. For any other expression, just
- return EXP. */
+ return EXP after removing NOPs. */
-static tree
+tree
default_function_array_conversion (tree exp)
{
tree orig_exp;
/* Perform default promotions for C data used in expressions.
- Arrays and functions are converted to pointers;
- enumeral types or short or char, to int.
+ Enumeral types or short or char are converted to int.
In addition, manifest constants symbols are replaced by their values. */
tree
tree type = TREE_TYPE (exp);
enum tree_code code = TREE_CODE (type);
- if (code == FUNCTION_TYPE || code == ARRAY_TYPE)
- return default_function_array_conversion (exp);
+ /* Functions and arrays have been converted during parsing. */
+ gcc_assert (code != FUNCTION_TYPE);
+ if (code == ARRAY_TYPE)
+ return exp;
/* Constants can be used directly unless they're not loadable. */
if (TREE_CODE (exp) == CONST_DECL)
return tem;
name = DECL_NAME (function);
-
- /* Differs from default_conversion by not setting TREE_ADDRESSABLE
- (because calling an inline function does not mean the function
- needs to be separately compiled). */
- fntype = build_type_variant (TREE_TYPE (function),
- TREE_READONLY (function),
- TREE_THIS_VOLATILE (function));
- fundecl = function;
- function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
}
- else
- function = default_conversion (function);
+ function = default_function_array_conversion (function);
/* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
expressions, like those used for ObjC messenger dispatches. */
STRIP_TYPE_NOPS (val);
- val = default_function_array_conversion (val);
-
val = require_complete_type (val);
if (type != 0)
break;
case TRUTH_NOT_EXPR:
- /* ??? Why do most validation here but that for non-lvalue arrays
- in c_objc_common_truthvalue_conversion? */
if (typecode != INTEGER_TYPE
&& typecode != REAL_TYPE && typecode != POINTER_TYPE
- && typecode != COMPLEX_TYPE
- /* These will convert to a pointer. */
- && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
+ && typecode != COMPLEX_TYPE)
{
error ("wrong type argument to unary exclamation mark");
return error_mark_node;
{
if (!c_mark_addressable (TREE_OPERAND (arg, 0)))
return error_mark_node;
- return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
+ return build_binary_op (PLUS_EXPR,
+ default_function_array_conversion
+ (TREE_OPERAND (arg, 0)),
TREE_OPERAND (arg, 1), 1);
}
tree
build_compound_expr (tree expr1, tree expr2)
{
- /* Convert arrays and functions to pointers. */
- expr2 = default_function_array_conversion (expr2);
-
if (!TREE_SIDE_EFFECTS (expr1))
{
/* The left-hand operand of a comma expression is like an expression
else if (TREE_CODE (type) == UNION_TYPE)
{
tree field;
- value = default_function_array_conversion (value);
for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
{
tree otype, ovalue;
- /* If casting to void, avoid the error that would come
- from default_conversion in the case of a non-lvalue array. */
if (type == void_type_node)
return build1 (CONVERT_EXPR, type, value);
- /* Convert functions and arrays to pointers,
- but don't convert any other types. */
- value = default_function_array_conversion (value);
otype = TREE_TYPE (value);
/* Optionally warn about potentially worrisome casts. */
STRIP_TYPE_NOPS (rhs);
- if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
- || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
- rhs = default_conversion (rhs);
- else if (optimize && TREE_CODE (rhs) == VAR_DECL)
+ if (optimize && TREE_CODE (rhs) == VAR_DECL
+ && TREE_CODE (TREE_TYPE (rhs)) != ARRAY_TYPE)
rhs = decl_constant_value_for_broken_optimization (rhs);
rhstype = TREE_TYPE (rhs);
|| (code == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
&& comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
- TREE_TYPE (type)))
- || (code == POINTER_TYPE
- && TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE
- && comptypes (TREE_TYPE (inside_init),
TREE_TYPE (type)))))
{
if (code == POINTER_TYPE)
{
- inside_init = default_function_array_conversion (inside_init);
+ if (TREE_CODE (inside_init) == STRING_CST
+ || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
+ inside_init = default_function_array_conversion (inside_init);
if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
{
|| code == ENUMERAL_TYPE || code == BOOLEAN_TYPE || code == COMPLEX_TYPE
|| code == VECTOR_TYPE)
{
- /* Note that convert_for_assignment calls default_conversion
- for arrays and functions. We must not call it in the
- case where inside_init is a null pointer constant. */
+ if (TREE_CODE (init) == STRING_CST
+ || TREE_CODE (init) == COMPOUND_LITERAL_EXPR)
+ init = default_function_array_conversion (init);
inside_init
= convert_for_assignment (type, init, ic_init,
NULL_TREE, NULL_TREE, 0);
constructor_erroneous = 1;
return;
}
- if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
- || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
- && !(TREE_CODE (value) == STRING_CST
- && TREE_CODE (type) == ARRAY_TYPE
- && INTEGRAL_TYPE_P (TREE_TYPE (type)))
- && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
- TYPE_MAIN_VARIANT (type))))
- value = default_conversion (value);
+ if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
+ && (TREE_CODE (value) == STRING_CST
+ || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
+ && !(TREE_CODE (value) == STRING_CST
+ && TREE_CODE (type) == ARRAY_TYPE
+ && INTEGRAL_TYPE_P (TREE_TYPE (type)))
+ && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
+ TYPE_MAIN_VARIANT (type)))
+ value = default_function_array_conversion (value);
if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
&& require_constant_value && !flag_isoc99 && pending)
TREE_VALUE (tail) = output;
}
- /* Perform default conversions on array and function inputs.
- Don't do this for other types as it would screw up operands
- expected to be in memory. */
for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
{
tree input;
constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
input = TREE_VALUE (tail);
- input = default_function_array_conversion (input);
-
if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
oconstraints, &allows_mem, &allows_reg))
{
if (!expr)
return NULL_TREE;
- /* Do default conversion if safe and possibly important,
- in case within ({...}). */
- if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
- && (flag_isoc99 || lvalue_p (expr)))
- || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
- expr = default_conversion (expr);
-
if (warn_sequence_point)
verify_sequence_points (expr);
/* Convert EXPR to be a truth-value, validating its type for this
- purpose. Passes EXPR to default_function_array_conversion. */
+ purpose. */
tree
c_objc_common_truthvalue_conversion (tree expr)
{
- expr = default_function_array_conversion (expr);
switch (TREE_CODE (TREE_TYPE (expr)))
{
case ARRAY_TYPE:
error ("used union type value where scalar is required");
return error_mark_node;
+ case FUNCTION_TYPE:
+ gcc_unreachable ();
+
default:
break;
}