Summary: | bogus buffer overflow warning and abort on static flexible array member | ||
---|---|---|---|
Product: | gcc | Reporter: | Martin Sebor <msebor> |
Component: | c | Assignee: | Richard Biener <rguenth> |
Status: | RESOLVED FIXED | ||
Severity: | normal | Keywords: | wrong-code |
Priority: | P3 | ||
Version: | 4.6.0 | ||
Target Milestone: | 4.6.1 | ||
Host: | Target: | ||
Build: | Known to work: | 4.6.1, 4.7.0 | |
Known to fail: | 4.3.0, 4.6.0 | Last reconfirmed: | 2011-05-13 09:27:38 |
Bug Depends on: | 49063 | ||
Bug Blocks: |
Description
Martin Sebor
2011-05-12 23:02:28 UTC
The issue is that the type of the static declaration is never adjusted and we take the total size from the type instead of from the decl. Instead doing sth like Index: gcc/tree-object-size.c =================================================================== --- gcc/tree-object-size.c (revision 173724) +++ gcc/tree-object-size.c (working copy) @@ -205,6 +205,12 @@ addr_object_size (struct object_size_inf pt_var_size = size_int (sz); } else if (pt_var + && DECL_P (pt_var) + && host_integerp (DECL_SIZE_UNIT (pt_var), 1) + && (unsigned HOST_WIDE_INT) + tree_low_cst (DECL_SIZE_UNIT (pt_var), 1) < offset_limit) + pt_var_size = DECL_SIZE_UNIT (pt_var); + else if (pt_var && (SSA_VAR_P (pt_var) || TREE_CODE (pt_var) == STRING_CST) && TYPE_SIZE_UNIT (TREE_TYPE (pt_var)) && host_integerp (TYPE_SIZE_UNIT (TREE_TYPE (pt_var)), 1) fixes it for me (returns 6). I suppose returning zero for a field that has incomplete type is wrong-code. We should return -1 instead. Author: rguenth Date: Thu May 19 10:45:26 2011 New Revision: 173901 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173901 Log: 2011-05-19 Richard Guenther <rguenther@suse.de> PR middle-end/48985 * tree-object-size.c (addr_object_size): If the pointed-to variable is a decl use DECL_SIZE_UNIT instead of TYPE_SIZE_UNIT. * gcc.dg/builtin-object-size-11.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/builtin-object-size-11.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-object-size.c Author: rguenth Date: Tue May 31 12:25:52 2011 New Revision: 174476 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174476 Log: 2011-05-31 Richard Guenther <rguenther@suse.de> Backport from mainline 2011-05-19 Richard Guenther <rguenther@suse.de> PR middle-end/48985 * tree-object-size.c (addr_object_size): If the pointed-to variable is a decl use DECL_SIZE_UNIT instead of TYPE_SIZE_UNIT. * gcc.dg/builtin-object-size-11.c: New testcase. Added: branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/builtin-object-size-11.c Modified: branches/gcc-4_6-branch/gcc/ChangeLog branches/gcc-4_6-branch/gcc/testsuite/ChangeLog branches/gcc-4_6-branch/gcc/tree-object-size.c Fixed for 4.6.1. |