From 190b2187b62863306378ea0940a6ddd2eb3629d5 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Thu, 24 Mar 2011 12:44:58 +0000 Subject: [PATCH] re PR middle-end/48269 (Incorrect fortify warning for a packed struct member) 2011-03-24 Richard Guenther PR middle-end/48269 * tree-object-size.c (addr_object_size): Do not double-account for MEM_REF offsets. * gcc.dg/builtin-object-size-10.c: New testcase. From-SVN: r171388 --- gcc/ChangeLog | 6 +++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/builtin-object-size-10.c | 26 +++++++++++++++++++ gcc/tree-object-size.c | 2 -- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-10.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index feace5129f0..8e361612595 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2011-03-24 Richard Guenther + + PR middle-end/48269 + * tree-object-size.c (addr_object_size): Do not double-account + for MEM_REF offsets. + 2011-03-24 Diego Novillo * lto-opts.c (input_data_block): Move to lto-streamer-in.c. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8bda6a47eec..0d331be99f7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-03-24 Richard Guenther + + PR middle-end/48269 + * gcc.dg/builtin-object-size-10.c: New testcase. + 2011-03-24 Richard Guenther PR tree-optimization/46562 diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-10.c b/gcc/testsuite/gcc.dg/builtin-object-size-10.c new file mode 100644 index 00000000000..6c7ed45b6e0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtin-object-size-10.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-objsz-details" } */ + +typedef struct { + char sentinel[4]; + char data[0]; +} drone_packet; +typedef struct { + char type_str[16]; + char channel_hop; +} drone_source_packet; +drone_packet * +foo(char *x) +{ + drone_packet *dpkt = __builtin_malloc(sizeof(drone_packet) + + sizeof(drone_source_packet)); + drone_source_packet *spkt = (drone_source_packet *) dpkt->data; + __builtin___snprintf_chk (spkt->type_str, 16, + 1, __builtin_object_size (spkt->type_str, 1), + "%s", x); + return dpkt; +} + +/* { dg-final { scan-tree-dump "maximum object size 21" "objsz" } } */ +/* { dg-final { scan-tree-dump "maximum subobject size 16" "objsz" } } */ +/* { dg-final { cleanup-tree-dump "objsz" } } */ diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c index 6a74d19edc0..043b445bf2e 100644 --- a/gcc/tree-object-size.c +++ b/gcc/tree-object-size.c @@ -348,8 +348,6 @@ addr_object_size (struct object_size_info *osi, const_tree ptr, tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0), pt_var); if (bytes2 != error_mark_node) { - bytes2 = size_binop (PLUS_EXPR, bytes2, - TREE_OPERAND (pt_var, 1)); if (TREE_CODE (bytes2) == INTEGER_CST && tree_int_cst_lt (pt_var_size, bytes2)) bytes2 = size_zero_node; -- 2.30.2