OSDN Git Service

2011-05-19 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 19 May 2011 10:45:26 +0000 (10:45 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 19 May 2011 10:45:26 +0000 (10:45 +0000)
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.

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

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

index a653ae8..b03cc9b 100644 (file)
@@ -1,5 +1,11 @@
 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.
+
+2011-05-19  Richard Guenther  <rguenther@suse.de>
+
        * gimple.c (gimple_types_compatible_p_1): Compare names of
        the types themselves.
        (iterative_hash_gimple_type): And hash them that way.
index f9defe5..242a33b 100644 (file)
@@ -1,3 +1,8 @@
+2011-05-19  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/48985
+       * gcc.dg/builtin-object-size-11.c: New testcase.
+
 2011-05-19  Tom de Vries  <tom@codesourcery.com>
 
        PR target/45098
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-11.c b/gcc/testsuite/gcc.dg/builtin-object-size-11.c
new file mode 100644 (file)
index 0000000..427b94d
--- /dev/null
@@ -0,0 +1,20 @@
+/* PR48985 */
+/* { dg-do run } */
+
+extern void abort (void);
+
+struct s {
+    int i;
+    char c[];
+} s = { 1, "01234" };
+
+__SIZE_TYPE__ f (void) { return __builtin_object_size (&s.c, 0); }
+
+int
+main()
+{
+  if (f() != sizeof ("01234"))
+    abort ();
+
+  return 0;
+}
index 043b445..41118d2 100644 (file)
@@ -205,6 +205,12 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
        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)