https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94421

            Bug ID: 94421
           Summary: [memory free] bug related to predication speculative
                    schedule
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhongyunde at huawei dot com
  Target Milestone: ---

After we enable the schedule DO_PREDICATION, then spec_dependency_cache will be
alloc in function extend_dependency_caches, and it is obvious controlled by
condition '(current_sched_info->flags & DO_SPECULATION)'

4123 extend_dependency_caches (int n, bool create_p)
4124 {
4125   if (create_p || true_dependency_cache)
4126     {
4127       int i, luid = cache_size + n;
4128 
4129       true_dependency_cache = XRESIZEVEC (bitmap_head,
true_dependency_cache, luid);
4131       ...
4137 
4138       if (current_sched_info->flags & DO_SPECULATION)
4139         spec_dependency_cache = XRESIZEVEC (bitmap_head,
spec_dependency_cache,
4140                                             luid);

while in function change_spec_dep_to_hard, when we free the memory of
spec_dependency_cache , it don't have condition '(current_sched_info->flags &
DO_SPECULATION)', so it will bring in compile bug.

should we add the following code to avoid such issue ?

diff --git a/gcc/sched-deps.c b/gcc/sched-deps.c
index dfdf5cc..4f94ef2 100644
--- a/gcc/sched-deps.c
+++ b/gcc/sched-deps.c
@@ -1116,7 +1116,8 @@ change_spec_dep_to_hard (sd_iterator_def sd_it)

   DEP_STATUS (dep) &= ~SPECULATIVE;

-  if (true_dependency_cache != NULL)
+  if (true_dependency_cache
+      && current_sched_info->flags & DO_SPECULATION)
     /* Clear the cache entry.  */

Reply via email to