]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/103456 - Record only successes from object_sizes_set
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Wed, 1 Dec 2021 07:28:12 +0000 (12:58 +0530)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Wed, 1 Dec 2021 08:27:50 +0000 (13:57 +0530)
Avoid overwriting osi->changed if object_sizes_set does not update the
size, so that a previous success in the same pass is not overwritten.
This fixes the bootstrap-ubsan build config, which was failing due to
incorrect object size.

gcc/ChangeLog:

PR tree-optimization/103456
* tree-object-size.c (merge_object_sizes): Update osi->changed
only if object_sizes_set succeeded.

gcc/testsuite/ChangeLog:

PR tree-optimization/103456
* gcc.dg/ubsan/pr103456.c: New test.

Co-authored-by: Martin Liška <mliska@suse.cz>
Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
gcc/testsuite/gcc.dg/ubsan/pr103456.c [new file with mode: 0644]
gcc/tree-object-size.c

diff --git a/gcc/testsuite/gcc.dg/ubsan/pr103456.c b/gcc/testsuite/gcc.dg/ubsan/pr103456.c
new file mode 100644 (file)
index 0000000..20322fb
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR tree-optimization/103456 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined -O -fdump-tree-objsz" } */
+
+static char *multilib_options = "m64/m32";
+
+void
+used_arg_t (void)
+{
+  char *q = multilib_options;
+  for (;;)
+    {
+      while (*q)
+       q++;
+      while (__builtin_strchr (q, '_') == 0)
+       while (*q)
+         q++;
+    }
+}
+
+/* { dg-final { scan-tree-dump-not "maximum object size 0" "objsz1" } } */
index 3780437ff910fcd0f3142d51009f0868d8c67002..b4881ef198f9f668fb8cf264f1d37a22edfc8df4 100644 (file)
@@ -854,7 +854,8 @@ merge_object_sizes (struct object_size_info *osi, tree dest, tree orig,
     orig_bytes = (offset > orig_bytes)
                 ? HOST_WIDE_INT_0U : orig_bytes - offset;
 
-  osi->changed = object_sizes_set (osi, varno, orig_bytes);
+  if (object_sizes_set (osi, varno, orig_bytes))
+    osi->changed = true;
 
   return bitmap_bit_p (osi->reexamine, SSA_NAME_VERSION (orig));
 }