Commit 1a4049e7 by Jakub Jelinek Committed by Jakub Jelinek

invoke.texi (-Wsizeof-pointer-memaccess): Document.

	* doc/invoke.texi (-Wsizeof-pointer-memaccess): Document.
c/
	* c-tree.h (c_last_sizeof_arg): Declare.
	* c-parser.c (struct c_tree_loc_pair): New type.
	(c_parser_expr_list): Add sizeof_arg argument.  Fill it in if
	non-NULL.
	(c_parser_attributes, c_parser_objc_keywordexpr): Adjust callers.
	(c_parser_postfix_expression_after_primary): Likewise.  Call
	sizeof_pointer_memaccess_warning if needed.
	(sizeof_ptr_memacc_comptypes): New function.
	* c-typeck.c (c_last_sizeof_arg): New global variable.
	(c_expr_sizeof_expr, c_expr_sizeof_type): Initialize it.
cp/
	* cp-tree.def (SIZEOF_EXPR): Move to c-common.def.
c-family/
	* c-common.c (sizeof_pointer_memaccess_warning): New function.
	* c.opt (-Wsizeof-pointer-memaccess): Add new option.
	* c-opts.c (c_common_handle_option): Enable it for -Wall.
	* c-common.h (sizeof_pointer_memaccess_warning): Add prototype.
	* c-common.def (SIZEOF_EXPR): Moved here from cp-tree.def.
fortran/
	* array.c (gfc_match_array_ref): Fix up memset arguments.
testsuite/
	* gcc.dg/torture/Wsizeof-pointer-memaccess1.c: New test.

From-SVN: r190467
parent 138f5acd
2012-08-17 Jakub Jelinek <jakub@redhat.com>
* doc/invoke.texi (-Wsizeof-pointer-memaccess): Document.
2012-08-16 Sandra Loosemore <sandra@codesourcery.com> 2012-08-16 Sandra Loosemore <sandra@codesourcery.com>
* config/mips/mips-dsp.md (mips_dpau_h_qbl, mips_dpau_h_qbr) * config/mips/mips-dsp.md (mips_dpau_h_qbl, mips_dpau_h_qbr)
......
2012-08-17 Jakub Jelinek <jakub@redhat.com>
* c-common.c (sizeof_pointer_memaccess_warning): New function.
* c.opt (-Wsizeof-pointer-memaccess): Add new option.
* c-opts.c (c_common_handle_option): Enable it for -Wall.
* c-common.h (sizeof_pointer_memaccess_warning): Add prototype.
* c-common.def (SIZEOF_EXPR): Moved here from cp-tree.def.
2012-08-10 Richard Guenther <rguenther@suse.de> 2012-08-10 Richard Guenther <rguenther@suse.de>
* c-pretty-print.c (pp_c_expression): Handle anonymous SSA names. * c-pretty-print.c (pp_c_expression): Handle anonymous SSA names.
......
...@@ -1841,6 +1841,149 @@ strict_aliasing_warning (tree otype, tree type, tree expr) ...@@ -1841,6 +1841,149 @@ strict_aliasing_warning (tree otype, tree type, tree expr)
return false; return false;
} }
/* Warn about memset (&a, 0, sizeof (&a)); and similar mistakes with
sizeof as last operand of certain builtins. */
void
sizeof_pointer_memaccess_warning (location_t loc, tree callee,
VEC(tree, gc) *params, tree sizeof_arg,
bool (*comp_types) (tree, tree))
{
tree type, dest = NULL_TREE, src = NULL_TREE, tem;
bool strop = false;
if (TREE_CODE (callee) != FUNCTION_DECL
|| DECL_BUILT_IN_CLASS (callee) != BUILT_IN_NORMAL
|| sizeof_arg == error_mark_node
|| VEC_length (tree, params) <= 1)
return;
type = TYPE_P (sizeof_arg) ? sizeof_arg : TREE_TYPE (sizeof_arg);
if (!POINTER_TYPE_P (type))
return;
switch (DECL_FUNCTION_CODE (callee))
{
case BUILT_IN_STRNCMP:
case BUILT_IN_STRNCASECMP:
case BUILT_IN_STRNCPY:
case BUILT_IN_STRNCAT:
strop = true;
/* FALLTHRU */
case BUILT_IN_MEMCPY:
case BUILT_IN_MEMMOVE:
case BUILT_IN_MEMCMP:
if (VEC_length (tree, params) < 3)
return;
src = VEC_index (tree, params, 1);
dest = VEC_index (tree, params, 0);
break;
case BUILT_IN_MEMSET:
if (VEC_length (tree, params) < 3)
return;
dest = VEC_index (tree, params, 0);
break;
case BUILT_IN_STRNDUP:
src = VEC_index (tree, params, 0);
strop = true;
break;
default:
break;
}
if (dest
&& (tem = tree_strip_nop_conversions (dest))
&& POINTER_TYPE_P (TREE_TYPE (tem))
&& comp_types (TREE_TYPE (TREE_TYPE (tem)), type))
return;
if (src
&& (tem = tree_strip_nop_conversions (src))
&& POINTER_TYPE_P (TREE_TYPE (tem))
&& comp_types (TREE_TYPE (TREE_TYPE (tem)), type))
return;
if (dest)
{
if (!TYPE_P (sizeof_arg)
&& operand_equal_p (dest, sizeof_arg, 0)
&& comp_types (TREE_TYPE (dest), type))
{
if (TREE_CODE (sizeof_arg) == ADDR_EXPR && !strop)
warning_at (loc, OPT_Wsizeof_pointer_memaccess,
"argument to %<sizeof%> in %qD call is the same "
"expression as the destination; did you mean to "
"remove the addressof?", callee);
else if ((TYPE_PRECISION (TREE_TYPE (type))
== TYPE_PRECISION (char_type_node))
|| strop)
warning_at (loc, OPT_Wsizeof_pointer_memaccess,
"argument to %<sizeof%> in %qD call is the same "
"expression as the destination; did you mean to "
"provide an explicit length?", callee);
else
warning_at (loc, OPT_Wsizeof_pointer_memaccess,
"argument to %<sizeof%> in %qD call is the same "
"expression as the destination; did you mean to "
"dereference it?", callee);
return;
}
if (POINTER_TYPE_P (TREE_TYPE (dest))
&& !strop
&& comp_types (TREE_TYPE (dest), type)
&& !VOID_TYPE_P (TREE_TYPE (type)))
{
warning_at (loc, OPT_Wsizeof_pointer_memaccess,
"argument to %<sizeof%> in %qD call is the same "
"pointer type %qT as the destination; expected %qT "
"or an explicit length", callee, TREE_TYPE (dest),
TREE_TYPE (TREE_TYPE (dest)));
return;
}
}
if (src)
{
if (!TYPE_P (sizeof_arg)
&& operand_equal_p (src, sizeof_arg, 0)
&& comp_types (TREE_TYPE (src), type))
{
if (TREE_CODE (sizeof_arg) == ADDR_EXPR && !strop)
warning_at (loc, OPT_Wsizeof_pointer_memaccess,
"argument to %<sizeof%> in %qD call is the same "
"expression as the source; did you mean to "
"remove the addressof?", callee);
else if ((TYPE_PRECISION (TREE_TYPE (type))
== TYPE_PRECISION (char_type_node))
|| strop)
warning_at (loc, OPT_Wsizeof_pointer_memaccess,
"argument to %<sizeof%> in %qD call is the same "
"expression as the source; did you mean to "
"provide an explicit length?", callee);
else
warning_at (loc, OPT_Wsizeof_pointer_memaccess,
"argument to %<sizeof%> in %qD call is the same "
"expression as the source; did you mean to "
"dereference it?", callee);
return;
}
if (POINTER_TYPE_P (TREE_TYPE (src))
&& !strop
&& comp_types (TREE_TYPE (src), type)
&& !VOID_TYPE_P (TREE_TYPE (type)))
{
warning_at (loc, OPT_Wsizeof_pointer_memaccess,
"argument to %<sizeof%> in %qD call is the same "
"pointer type %qT as the source; expected %qT "
"or an explicit length", callee, TREE_TYPE (src),
TREE_TYPE (TREE_TYPE (src)));
return;
}
}
}
/* Warn for unlikely, improbable, or stupid DECL declarations /* Warn for unlikely, improbable, or stupid DECL declarations
of `main'. */ of `main'. */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
additional tree codes used in the GNU C compiler (see tree.def additional tree codes used in the GNU C compiler (see tree.def
for the standard codes). for the standard codes).
Copyright (C) 1987, 1988, 1990, 1993, 1997, 1998, Copyright (C) 1987, 1988, 1990, 1993, 1997, 1998,
1999, 2000, 2001, 2004, 2005, 2007, 2009, 2010 1999, 2000, 2001, 2004, 2005, 2007, 2009, 2010, 2011, 2012
Free Software Foundation, Inc. Free Software Foundation, Inc.
Written by Benjamin Chelf <chelf@codesourcery.com> Written by Benjamin Chelf <chelf@codesourcery.com>
...@@ -53,6 +53,10 @@ DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1) ...@@ -53,6 +53,10 @@ DEFTREECODE (EXCESS_PRECISION_EXPR, "excess_precision_expr", tcc_expression, 1)
number. */ number. */
DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3) DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
/* Represents a 'sizeof' expression during C++ template expansion,
or for the purpose of -Wsizeof-pointer-memaccess warning. */
DEFTREECODE (SIZEOF_EXPR, "sizeof_expr", tcc_expression, 1)
/* /*
Local variables: Local variables:
mode:c mode:c
......
/* Definitions for c-common.c. /* Definitions for c-common.c.
Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998, Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of GCC. This file is part of GCC.
...@@ -768,6 +768,9 @@ extern tree fix_string_type (tree); ...@@ -768,6 +768,9 @@ extern tree fix_string_type (tree);
extern void constant_expression_warning (tree); extern void constant_expression_warning (tree);
extern void constant_expression_error (tree); extern void constant_expression_error (tree);
extern bool strict_aliasing_warning (tree, tree, tree); extern bool strict_aliasing_warning (tree, tree, tree);
extern void sizeof_pointer_memaccess_warning (location_t, tree,
VEC(tree, gc) *, tree,
bool (*) (tree, tree));
extern void warnings_for_convert_and_check (tree, tree, tree); extern void warnings_for_convert_and_check (tree, tree, tree);
extern tree convert_and_check (tree, tree); extern tree convert_and_check (tree, tree);
extern void overflow_warning (location_t, tree); extern void overflow_warning (location_t, tree);
......
/* C/ObjC/C++ command line option handling. /* C/ObjC/C++ command line option handling.
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
Free Software Foundation, Inc. 2012 Free Software Foundation, Inc.
Contributed by Neil Booth. Contributed by Neil Booth.
This file is part of GCC. This file is part of GCC.
...@@ -374,6 +374,7 @@ c_common_handle_option (size_t scode, const char *arg, int value, ...@@ -374,6 +374,7 @@ c_common_handle_option (size_t scode, const char *arg, int value,
warn_return_type = value; warn_return_type = value;
warn_sequence_point = value; /* Was C only. */ warn_sequence_point = value; /* Was C only. */
warn_switch = value; warn_switch = value;
warn_sizeof_pointer_memaccess = value;
if (warn_strict_aliasing == -1) if (warn_strict_aliasing == -1)
set_Wstrict_aliasing (&global_options, value); set_Wstrict_aliasing (&global_options, value);
warn_address = value; warn_address = value;
......
...@@ -474,6 +474,9 @@ Wmissing-field-initializers ...@@ -474,6 +474,9 @@ Wmissing-field-initializers
C ObjC C++ ObjC++ Var(warn_missing_field_initializers) Warning EnabledBy(Wextra) C ObjC C++ ObjC++ Var(warn_missing_field_initializers) Warning EnabledBy(Wextra)
Warn about missing fields in struct initializers Warn about missing fields in struct initializers
Wsizeof-pointer-memaccess
C ObjC C++ ObjC++ Var(warn_sizeof_pointer_memaccess) Warning
Wsuggest-attribute=format Wsuggest-attribute=format
C ObjC C++ ObjC++ Var(warn_suggest_attribute_format) Warning C ObjC C++ ObjC++ Var(warn_suggest_attribute_format) Warning
Warn about functions which might be candidates for format attributes Warn about functions which might be candidates for format attributes
......
2012-08-17 Jakub Jelinek <jakub@redhat.com>
* c-tree.h (c_last_sizeof_arg): Declare.
* c-parser.c (struct c_tree_loc_pair): New type.
(c_parser_expr_list): Add sizeof_arg argument. Fill it in if
non-NULL.
(c_parser_attributes, c_parser_objc_keywordexpr): Adjust callers.
(c_parser_postfix_expression_after_primary): Likewise. Call
sizeof_pointer_memaccess_warning if needed.
(sizeof_ptr_memacc_comptypes): New function.
* c-typeck.c (c_last_sizeof_arg): New global variable.
(c_expr_sizeof_expr, c_expr_sizeof_type): Initialize it.
2012-07-24 Uros Bizjak <ubizjak@gmail.com> 2012-07-24 Uros Bizjak <ubizjak@gmail.com>
* c-lang.h (lang_decl): Add variable_size GTY option. * c-lang.h (lang_decl): Add variable_size GTY option.
......
...@@ -1111,6 +1111,12 @@ enum c_parser_prec { ...@@ -1111,6 +1111,12 @@ enum c_parser_prec {
NUM_PRECS NUM_PRECS
}; };
/* Expression and its location. */
struct c_tree_loc_pair {
tree expr;
location_t loc;
};
static void c_parser_external_declaration (c_parser *); static void c_parser_external_declaration (c_parser *);
static void c_parser_asm_definition (c_parser *); static void c_parser_asm_definition (c_parser *);
static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
...@@ -1179,7 +1185,8 @@ static tree c_parser_transaction_cancel (c_parser *); ...@@ -1179,7 +1185,8 @@ static tree c_parser_transaction_cancel (c_parser *);
static struct c_expr c_parser_expression (c_parser *); static struct c_expr c_parser_expression (c_parser *);
static struct c_expr c_parser_expression_conv (c_parser *); static struct c_expr c_parser_expression_conv (c_parser *);
static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool, static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
VEC(tree,gc) **); VEC(tree,gc) **,
struct c_tree_loc_pair *);
static void c_parser_omp_construct (c_parser *); static void c_parser_omp_construct (c_parser *);
static void c_parser_omp_threadprivate (c_parser *); static void c_parser_omp_threadprivate (c_parser *);
static void c_parser_omp_barrier (c_parser *); static void c_parser_omp_barrier (c_parser *);
...@@ -3578,7 +3585,8 @@ c_parser_attributes (c_parser *parser) ...@@ -3578,7 +3585,8 @@ c_parser_attributes (c_parser *parser)
{ {
tree tree_list; tree tree_list;
c_parser_consume_token (parser); c_parser_consume_token (parser);
expr_list = c_parser_expr_list (parser, false, true, NULL); expr_list = c_parser_expr_list (parser, false, true,
NULL, NULL);
tree_list = build_tree_list_vec (expr_list); tree_list = build_tree_list_vec (expr_list);
attr_args = tree_cons (NULL_TREE, arg1, tree_list); attr_args = tree_cons (NULL_TREE, arg1, tree_list);
release_tree_vector (expr_list); release_tree_vector (expr_list);
...@@ -3590,7 +3598,8 @@ c_parser_attributes (c_parser *parser) ...@@ -3590,7 +3598,8 @@ c_parser_attributes (c_parser *parser)
attr_args = NULL_TREE; attr_args = NULL_TREE;
else else
{ {
expr_list = c_parser_expr_list (parser, false, true, NULL); expr_list = c_parser_expr_list (parser, false, true,
NULL, NULL);
attr_args = build_tree_list_vec (expr_list); attr_args = build_tree_list_vec (expr_list);
release_tree_vector (expr_list); release_tree_vector (expr_list);
} }
...@@ -6845,6 +6854,15 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser, ...@@ -6845,6 +6854,15 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser,
return c_parser_postfix_expression_after_primary (parser, start_loc, expr); return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
} }
/* Callback function for sizeof_pointer_memaccess_warning to compare
types. */
static bool
sizeof_ptr_memacc_comptypes (tree type1, tree type2)
{
return comptypes (type1, type2) == 1;
}
/* Parse a postfix expression after the initial primary or compound /* Parse a postfix expression after the initial primary or compound
literal; that is, parse a series of postfix operators. literal; that is, parse a series of postfix operators.
...@@ -6857,6 +6875,7 @@ c_parser_postfix_expression_after_primary (c_parser *parser, ...@@ -6857,6 +6875,7 @@ c_parser_postfix_expression_after_primary (c_parser *parser,
{ {
struct c_expr orig_expr; struct c_expr orig_expr;
tree ident, idx; tree ident, idx;
struct c_tree_loc_pair sizeof_arg;
VEC(tree,gc) *exprlist; VEC(tree,gc) *exprlist;
VEC(tree,gc) *origtypes; VEC(tree,gc) *origtypes;
while (true) while (true)
...@@ -6877,14 +6896,22 @@ c_parser_postfix_expression_after_primary (c_parser *parser, ...@@ -6877,14 +6896,22 @@ c_parser_postfix_expression_after_primary (c_parser *parser,
case CPP_OPEN_PAREN: case CPP_OPEN_PAREN:
/* Function call. */ /* Function call. */
c_parser_consume_token (parser); c_parser_consume_token (parser);
sizeof_arg.expr = NULL_TREE;
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
exprlist = NULL; exprlist = NULL;
else else
exprlist = c_parser_expr_list (parser, true, false, &origtypes); exprlist = c_parser_expr_list (parser, true, false, &origtypes,
&sizeof_arg);
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
"expected %<)%>"); "expected %<)%>");
orig_expr = expr; orig_expr = expr;
mark_exp_read (expr.value); mark_exp_read (expr.value);
if (warn_sizeof_pointer_memaccess
&& sizeof_arg.expr != NULL_TREE)
sizeof_pointer_memaccess_warning (sizeof_arg.loc,
expr.value, exprlist,
sizeof_arg.expr,
sizeof_ptr_memacc_comptypes);
/* FIXME diagnostics: Ideally we want the FUNCNAME, not the /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
"(" after the FUNCNAME, which is what we have now. */ "(" after the FUNCNAME, which is what we have now. */
expr.value = build_function_call_vec (op_loc, expr.value, exprlist, expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
...@@ -7045,12 +7072,14 @@ c_parser_expression_conv (c_parser *parser) ...@@ -7045,12 +7072,14 @@ c_parser_expression_conv (c_parser *parser)
static VEC(tree,gc) * static VEC(tree,gc) *
c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
VEC(tree,gc) **p_orig_types) VEC(tree,gc) **p_orig_types,
struct c_tree_loc_pair *sizeof_arg)
{ {
VEC(tree,gc) *ret; VEC(tree,gc) *ret;
VEC(tree,gc) *orig_types; VEC(tree,gc) *orig_types;
struct c_expr expr; struct c_expr expr;
location_t loc = c_parser_peek_token (parser)->location; location_t loc = c_parser_peek_token (parser)->location;
location_t sizeof_arg_loc = UNKNOWN_LOCATION;
ret = make_tree_vector (); ret = make_tree_vector ();
if (p_orig_types == NULL) if (p_orig_types == NULL)
...@@ -7058,6 +7087,9 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, ...@@ -7058,6 +7087,9 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
else else
orig_types = make_tree_vector (); orig_types = make_tree_vector ();
if (sizeof_arg != NULL
&& c_parser_next_token_is_keyword (parser, RID_SIZEOF))
sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
expr = c_parser_expr_no_commas (parser, NULL); expr = c_parser_expr_no_commas (parser, NULL);
if (convert_p) if (convert_p)
expr = default_function_array_read_conversion (loc, expr); expr = default_function_array_read_conversion (loc, expr);
...@@ -7070,6 +7102,11 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, ...@@ -7070,6 +7102,11 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
{ {
c_parser_consume_token (parser); c_parser_consume_token (parser);
loc = c_parser_peek_token (parser)->location; loc = c_parser_peek_token (parser)->location;
if (sizeof_arg != NULL
&& c_parser_next_token_is_keyword (parser, RID_SIZEOF))
sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location;
else
sizeof_arg_loc = UNKNOWN_LOCATION;
expr = c_parser_expr_no_commas (parser, NULL); expr = c_parser_expr_no_commas (parser, NULL);
if (convert_p) if (convert_p)
expr = default_function_array_read_conversion (loc, expr); expr = default_function_array_read_conversion (loc, expr);
...@@ -7079,6 +7116,20 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, ...@@ -7079,6 +7116,20 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
if (orig_types != NULL) if (orig_types != NULL)
VEC_safe_push (tree, gc, orig_types, expr.original_type); VEC_safe_push (tree, gc, orig_types, expr.original_type);
} }
if (sizeof_arg != NULL)
{
if (sizeof_arg_loc != UNKNOWN_LOCATION
&& expr.original_code == SIZEOF_EXPR)
{
sizeof_arg->expr = c_last_sizeof_arg;
sizeof_arg->loc = sizeof_arg_loc;
}
else
{
sizeof_arg->expr = NULL_TREE;
sizeof_arg->loc = UNKNOWN_LOCATION;
}
}
if (orig_types != NULL) if (orig_types != NULL)
*p_orig_types = orig_types; *p_orig_types = orig_types;
return ret; return ret;
...@@ -8157,7 +8208,8 @@ static tree ...@@ -8157,7 +8208,8 @@ static tree
c_parser_objc_keywordexpr (c_parser *parser) c_parser_objc_keywordexpr (c_parser *parser)
{ {
tree ret; tree ret;
VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL); VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true,
NULL, NULL);
if (VEC_length (tree, expr_list) == 1) if (VEC_length (tree, expr_list) == 1)
{ {
/* Just return the expression, remove a level of /* Just return the expression, remove a level of
......
/* Definitions for C parsing and type checking. /* Definitions for C parsing and type checking.
Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998, Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011,
Free Software Foundation, Inc. 2012 Free Software Foundation, Inc.
This file is part of GCC. This file is part of GCC.
...@@ -573,6 +573,8 @@ extern int in_alignof; ...@@ -573,6 +573,8 @@ extern int in_alignof;
extern int in_sizeof; extern int in_sizeof;
extern int in_typeof; extern int in_typeof;
extern tree c_last_sizeof_arg;
extern struct c_switch *c_switch_stack; extern struct c_switch *c_switch_stack;
extern tree c_objc_common_truthvalue_conversion (location_t, tree); extern tree c_objc_common_truthvalue_conversion (location_t, tree);
......
/* Build expressions with type checking for C compiler. /* Build expressions with type checking for C compiler.
Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
Free Software Foundation, Inc. 2011, 2012 Free Software Foundation, Inc.
This file is part of GCC. This file is part of GCC.
...@@ -67,6 +67,10 @@ int in_sizeof; ...@@ -67,6 +67,10 @@ int in_sizeof;
/* The level of nesting inside "typeof". */ /* The level of nesting inside "typeof". */
int in_typeof; int in_typeof;
/* The argument of last parsed sizeof expression, only to be tested
if expr.original_code == SIZEOF_EXPR. */
tree c_last_sizeof_arg;
/* Nonzero if we've already printed a "missing braces around initializer" /* Nonzero if we've already printed a "missing braces around initializer"
message within this initializer. */ message within this initializer. */
static int missing_braces_mentioned; static int missing_braces_mentioned;
...@@ -2603,7 +2607,8 @@ c_expr_sizeof_expr (location_t loc, struct c_expr expr) ...@@ -2603,7 +2607,8 @@ c_expr_sizeof_expr (location_t loc, struct c_expr expr)
tree folded_expr = c_fully_fold (expr.value, require_constant_value, tree folded_expr = c_fully_fold (expr.value, require_constant_value,
&expr_const_operands); &expr_const_operands);
ret.value = c_sizeof (loc, TREE_TYPE (folded_expr)); ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
ret.original_code = ERROR_MARK; c_last_sizeof_arg = expr.value;
ret.original_code = SIZEOF_EXPR;
ret.original_type = NULL; ret.original_type = NULL;
if (c_vla_type_p (TREE_TYPE (folded_expr))) if (c_vla_type_p (TREE_TYPE (folded_expr)))
{ {
...@@ -2631,7 +2636,8 @@ c_expr_sizeof_type (location_t loc, struct c_type_name *t) ...@@ -2631,7 +2636,8 @@ c_expr_sizeof_type (location_t loc, struct c_type_name *t)
bool type_expr_const = true; bool type_expr_const = true;
type = groktypename (t, &type_expr, &type_expr_const); type = groktypename (t, &type_expr, &type_expr_const);
ret.value = c_sizeof (loc, type); ret.value = c_sizeof (loc, type);
ret.original_code = ERROR_MARK; c_last_sizeof_arg = type;
ret.original_code = SIZEOF_EXPR;
ret.original_type = NULL; ret.original_type = NULL;
if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST) if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
&& c_vla_type_p (type)) && c_vla_type_p (type))
......
2012-08-17 Jakub Jelinek <jakub@redhat.com>
* cp-tree.def (SIZEOF_EXPR): Move to c-common.def.
2012-08-14 Diego Novillo <dnovillo@google.com> 2012-08-14 Diego Novillo <dnovillo@google.com>
Merge from cxx-conversion branch. Re-write VEC in C++. Merge from cxx-conversion branch. Re-write VEC in C++.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
additional tree codes used in the GNU C++ compiler (see tree.def additional tree codes used in the GNU C++ compiler (see tree.def
for the standard codes). for the standard codes).
Copyright (C) 1987, 1988, 1990, 1993, 1997, 1998, 2003, 2004, 2005, Copyright (C) 1987, 1988, 1990, 1993, 1997, 1998, 2003, 2004, 2005,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2010, 2011 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2010, 2011, 2012
Free Software Foundation, Inc. Free Software Foundation, Inc.
Hacked by Michael Tiemann (tiemann@cygnus.com) Hacked by Michael Tiemann (tiemann@cygnus.com)
...@@ -333,9 +333,6 @@ DEFTREECODE (TAG_DEFN, "tag_defn", tcc_expression, 0) ...@@ -333,9 +333,6 @@ DEFTREECODE (TAG_DEFN, "tag_defn", tcc_expression, 0)
/* Represents an 'offsetof' expression during template expansion. */ /* Represents an 'offsetof' expression during template expansion. */
DEFTREECODE (OFFSETOF_EXPR, "offsetof_expr", tcc_expression, 1) DEFTREECODE (OFFSETOF_EXPR, "offsetof_expr", tcc_expression, 1)
/* Represents a 'sizeof' expression during template expansion. */
DEFTREECODE (SIZEOF_EXPR, "sizeof_expr", tcc_expression, 1)
/* Represents the -> operator during template expansion. */ /* Represents the -> operator during template expansion. */
DEFTREECODE (ARROW_EXPR, "arrow_expr", tcc_expression, 1) DEFTREECODE (ARROW_EXPR, "arrow_expr", tcc_expression, 1)
......
...@@ -263,9 +263,9 @@ Objective-C and Objective-C++ Dialects}. ...@@ -263,9 +263,9 @@ Objective-C and Objective-C++ Dialects}.
-Wpointer-arith -Wno-pointer-to-int-cast @gol -Wpointer-arith -Wno-pointer-to-int-cast @gol
-Wredundant-decls @gol -Wredundant-decls @gol
-Wreturn-type -Wsequence-point -Wshadow @gol -Wreturn-type -Wsequence-point -Wshadow @gol
-Wsign-compare -Wsign-conversion -Wstack-protector @gol -Wsign-compare -Wsign-conversion -Wsizeof-pointer-memaccess @gol
-Wstack-usage=@var{len} -Wstrict-aliasing -Wstrict-aliasing=n @gol -Wstack-protector -Wstack-usage=@var{len} -Wstrict-aliasing @gol
-Wstrict-overflow -Wstrict-overflow=@var{n} @gol -Wstrict-aliasing=n @gol -Wstrict-overflow -Wstrict-overflow=@var{n} @gol
-Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{]} @gol -Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{]} @gol
-Wmissing-format-attribute @gol -Wmissing-format-attribute @gol
-Wswitch -Wswitch-default -Wswitch-enum -Wsync-nand @gol -Wswitch -Wswitch-default -Wswitch-enum -Wsync-nand @gol
...@@ -4327,6 +4327,16 @@ value, like assigning a signed integer expression to an unsigned ...@@ -4327,6 +4327,16 @@ value, like assigning a signed integer expression to an unsigned
integer variable. An explicit cast silences the warning. In C, this integer variable. An explicit cast silences the warning. In C, this
option is enabled also by @option{-Wconversion}. option is enabled also by @option{-Wconversion}.
@item -Wsizeof-pointer-memaccess
@opindex Wsizeof-pointer-memaccess
@opindex Wno-sizeof-pointer-memaccess
Warn for suspicious length parameters to certain string and memory built-in
functions if the argument uses @code{sizeof}. This warning warns e.g.@:
about @code{memset (ptr, 0, sizeof (ptr));} if @code{ptr} is not an array,
but a pointer, and suggests a possible fix, or about
@code{memcpy (&foo, ptr, sizeof (&foo));}. This warning is enabled by
@option{-Wall}.
@item -Waddress @item -Waddress
@opindex Waddress @opindex Waddress
@opindex Wno-address @opindex Wno-address
......
2012-08-17 Jakub Jelinek <jakub@redhat.com>
* array.c (gfc_match_array_ref): Fix up memset arguments.
2012-08-16 Diego Novillo <dnovillo@google.com> 2012-08-16 Diego Novillo <dnovillo@google.com>
Revert Revert
......
/* Array things /* Array things
Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
Free Software Foundation, Inc. 2011, 2012 Free Software Foundation, Inc.
Contributed by Andy Vaught Contributed by Andy Vaught
This file is part of GCC. This file is part of GCC.
...@@ -159,7 +159,7 @@ gfc_match_array_ref (gfc_array_ref *ar, gfc_array_spec *as, int init, ...@@ -159,7 +159,7 @@ gfc_match_array_ref (gfc_array_ref *ar, gfc_array_spec *as, int init,
match m; match m;
bool matched_bracket = false; bool matched_bracket = false;
memset (ar, '\0', sizeof (ar)); memset (ar, '\0', sizeof (*ar));
ar->where = gfc_current_locus; ar->where = gfc_current_locus;
ar->as = as; ar->as = as;
......
2012-08-17 Jakub Jelinek <jakub@redhat.com>
* gcc.dg/torture/Wsizeof-pointer-memaccess1.c: New test.
2012-08-16 Oleg Endo <olegendo@gcc.gnu.org> 2012-08-16 Oleg Endo <olegendo@gcc.gnu.org>
PR target/54236 PR target/54236
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment