summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@gotplt.org>2022-06-21 12:15:07 +0530
committerSiddhesh Poyarekar <siddhesh@gotplt.org>2022-06-23 11:21:29 +0530
commit70deb85b995eed16280ed3a45c3b879b16685bbf (patch)
treec019583878b8f02581c782279f7931566dbbacd2
parentc++: dependence of baselink [PR105964] (diff)
downloadgcc-70deb85b995eed16280ed3a45c3b879b16685bbf.tar.gz
gcc-70deb85b995eed16280ed3a45c3b879b16685bbf.tar.bz2
gcc-70deb85b995eed16280ed3a45c3b879b16685bbf.tar.xz
tree-object-size: Don't let error_mark_node escape for ADDR_EXPR [PR105736]
The addr_expr computation does not check for error_mark_node before returning the size expression. This used to work in the constant case because the conversion to uhwi would end up causing it to return size_unknown, but that won't work for the dynamic case. Modify the control flow to explicitly return size_unknown if the offset computation returns an error_mark_node. gcc/ChangeLog: PR tree-optimization/105736 * tree-object-size.cc (addr_object_size): Return size_unknown when object offset computation returns an error. gcc/testsuite/ChangeLog: PR tree-optimization/105736 * gcc.dg/builtin-dynamic-object-size-0.c (TV4): New struct. (val3): New variable. (test_pr105736): New test. (main): Call it. Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org> (cherry picked from commit 70454c50b4592fe6876ecca13268264e395e058f)
-rw-r--r--gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c18
-rw-r--r--gcc/tree-object-size.cc20
2 files changed, 29 insertions, 9 deletions
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index b5b0b3a677c..01a280b2d7b 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -479,6 +479,20 @@ test_loop (int *obj, size_t sz, size_t start, size_t end, int incr)
479 return __builtin_dynamic_object_size (ptr, 0); 479 return __builtin_dynamic_object_size (ptr, 0);
480} 480}
481 481
482/* Other tests. */
483
484struct TV4
485{
486 __attribute__((vector_size (sizeof (int) * 4))) int v;
487};
488
489struct TV4 val3;
490int *
491test_pr105736 (struct TV4 *a)
492{
493 return &a->v[0];
494}
495
482unsigned nfails = 0; 496unsigned nfails = 0;
483 497
484#define FAIL() ({ \ 498#define FAIL() ({ \
@@ -633,6 +647,10 @@ main (int argc, char **argv)
633 FAIL (); 647 FAIL ();
634 if (test_loop (arr, 42, 20, 52, 1) != 0) 648 if (test_loop (arr, 42, 20, 52, 1) != 0)
635 FAIL (); 649 FAIL ();
650 /* pr105736. */
651 int *t = test_pr105736 (&val3);
652 if (__builtin_dynamic_object_size (t, 0) != -1)
653 FAIL ();
636 654
637 if (nfails > 0) 655 if (nfails > 0)
638 __builtin_abort (); 656 __builtin_abort ();
diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc
index fc062b94d76..41d21bd3bc9 100644
--- a/gcc/tree-object-size.cc
+++ b/gcc/tree-object-size.cc
@@ -695,19 +695,21 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
695 var_size = pt_var_size; 695 var_size = pt_var_size;
696 bytes = compute_object_offset (TREE_OPERAND (ptr, 0), var); 696 bytes = compute_object_offset (TREE_OPERAND (ptr, 0), var);
697 if (bytes != error_mark_node) 697 if (bytes != error_mark_node)
698 bytes = size_for_offset (var_size, bytes);
699 if (var != pt_var
700 && pt_var_size
701 && TREE_CODE (pt_var) == MEM_REF
702 && bytes != error_mark_node)
703 { 698 {
704 tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0), pt_var); 699 bytes = size_for_offset (var_size, bytes);
705 if (bytes2 != error_mark_node) 700 if (var != pt_var && pt_var_size && TREE_CODE (pt_var) == MEM_REF)
706 { 701 {
707 bytes2 = size_for_offset (pt_var_size, bytes2); 702 tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0),
708 bytes = size_binop (MIN_EXPR, bytes, bytes2); 703 pt_var);
704 if (bytes2 != error_mark_node)
705 {
706 bytes2 = size_for_offset (pt_var_size, bytes2);
707 bytes = size_binop (MIN_EXPR, bytes, bytes2);
708 }
709 } 709 }
710 } 710 }
711 else
712 bytes = size_unknown (object_size_type);
711 713
712 wholebytes 714 wholebytes
713 = object_size_type & OST_SUBOBJECT ? var_size : pt_var_wholesize; 715 = object_size_type & OST_SUBOBJECT ? var_size : pt_var_wholesize;