OSDN Git Service

2011-03-24 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Mar 2011 12:44:58 +0000 (12:44 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Mar 2011 12:44:58 +0000 (12:44 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@171388 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtin-object-size-10.c [new file with mode: 0644]
gcc/tree-object-size.c

index feace51..8e36161 100644 (file)
@@ -1,3 +1,9 @@
+2011-03-24  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/48269
+       * tree-object-size.c (addr_object_size): Do not double-account
+       for MEM_REF offsets.
+
 2011-03-24  Diego Novillo  <dnovillo@google.com>
 
        * lto-opts.c (input_data_block): Move to lto-streamer-in.c.
index 8bda6a4..0d331be 100644 (file)
@@ -1,5 +1,10 @@
 2011-03-24  Richard Guenther  <rguenther@suse.de>
 
+       PR middle-end/48269
+       * gcc.dg/builtin-object-size-10.c: New testcase.
+
+2011-03-24  Richard Guenther  <rguenther@suse.de>
+
        PR tree-optimization/46562
        * c-c++-common/pr46562-2.c: New testcase.
        * c-c++-common/pr46562.c: Likewise.
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 (file)
index 0000000..6c7ed45
--- /dev/null
@@ -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" } } */
index 6a74d19..043b445 100644 (file)
@@ -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;