Skip to content

Built-in analysis fails to converge on simple loops #67834

@ymand

Description

@ymand

A number of (likely-related) simple loops cause the analysis to fail to converge. Below are a series of examples reduced from real code. I suspect they are all the same problem:

TEST(PointerNullabilityTest, NonConvergeBools1) {
  EXPECT_TRUE(checkDiagnostics(R"cc(
    bool cond();
    void target() {
      bool a = false;
      bool b = cond();
      while (!a || !b) {
        if (!cond()) return;
        if (cond()) {
          if (a) return;
          a = cond();
        } else {
          if (b) return;
          b = true;
        }
      }
    }
  )cc"));
}

TEST(PointerNullabilityTest, NonConvergeBools2) {
  EXPECT_TRUE(checkDiagnostics(R"cc(
    bool cond();
    void target() {
      bool c = false;
      while (cond() || cond()) {
        c = (3 == 4);
      }
    }
  )cc"));
}

TEST(PointerNullabilityTest, NonConvergeBools3) {
  EXPECT_TRUE(checkDiagnostics(R"cc(
    bool cond();
    void target() {
      if (cond())
        ;
      while (cond() || cond())
        ;
    }
  )cc"));
}

TEST(PointerNullabilityTest, NonConvergeBools4) {
  EXPECT_TRUE(checkDiagnostics(R"cc(
    bool cond();

    void target(int m, int n, bool b) {
      bool g = m == 0 ;
      while (cond() || cond() || g) {
        bool c = m == 0 ;
        g = false;
      }
    }
  )cc"));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:dataflowClang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions