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

            Bug ID: 115564
           Summary: -Wanalyzer-infinite-loop false negative when there are
                    no source locations
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
  Target Milestone: ---

Consider e.g.:

void test (unsigned b)
{
    for (unsigned i = b; i >= 0; --i) {
    }
}

-Wanalyzer-infinite-loop warns about this at -O1 and below:
  https://godbolt.org/z/axze96331

but at -O2 and above we don't warn. 
  https://godbolt.org/z/xjGMnP3P5

The warning is rejected at:

          if (inf_loop->m_loc == UNKNOWN_LOCATION)
            {
              if (get_logger ())
                get_logger ()->log
                  ("no location available for reporting infinite loop");
              continue;
            }

We have two basic blocks no statements, and location_t == UNKNOWN_LOCATION on
each of the edges connecting them.

Ideas for fixing:
* backtrack through the egraph to find the first useful location_t on a path to
the entry to the infinite loop
* ensure that location_t values are set on the CFG edges

Reply via email to