<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [NewGVN] Crash while looking up domtree node"
   href="https://llvm.org/bugs/show_bug.cgi?id=31758">31758</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[NewGVN] Crash while looking up domtree node
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>davide@freebsd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dberlin@dberlin.org, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>30995
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We mark a block unreachable so DT->getNode() returns nullptr. Maybe there's a
different/more correct way to fix this. Tried to bootstrap/test suite.

Testcase reduced from one of our internal codebases (game7).

%struct.dipsy = type {}
%struct.fluttershy = type { %struct.dipsy* }
%struct.patatino = type {}

define void @tinkywinky() {
bb:
  br label %bb90

bb90:                                             ; preds = %bb90, %bb
  %tmp = getelementptr inbounds %struct.fluttershy, %struct.fluttershy* undef,
i64 0, i32 0
  %tmp91 = bitcast %struct.dipsy** %tmp to %struct.patatino**
  %tmp92 = load %struct.patatino*, %struct.patatino** %tmp91, align 8
  %tmp99 = getelementptr inbounds %struct.patatino, %struct.patatino* %tmp92
  %tmp134 = getelementptr inbounds %struct.fluttershy, %struct.fluttershy*
undef, i64 0, i32 0
  %tmp135 = bitcast %struct.dipsy** %tmp134 to %struct.patatino**
  %tmp136 = load %struct.patatino*, %struct.patatino** %tmp135, align 8
  br label %bb90

bb138:                                            ; preds = %bb138
  %tmp139 = getelementptr inbounds %struct.patatino, %struct.patatino* %tmp136
  br label %bb138
}

Proposed patch:

fluttershy@SONY-PC C:\Users\fluttershy\work\llvm
<span class="quote">> git diff</span >
diff --git a/lib/Transforms/Scalar/NewGVN.cpp
b/lib/Transforms/Scalar/NewGVN.cpp
index d4e41e1..cc87c79 100644
--- a/lib/Transforms/Scalar/NewGVN.cpp
+++ b/lib/Transforms/Scalar/NewGVN.cpp
@@ -1939,8 +1939,14 @@ void NewGVN::convertDenseToDFSOrdered(
           VD.LocalNum = InstrDFS.lookup(I);
         }
         DomTreeNode *DomNode = DT->getNode(IBlock);
-        VD.DFSIn = DomNode->getDFSNumIn();
-        VD.DFSOut = DomNode->getDFSNumOut();
+        if (DomNode) {
+          VD.DFSIn = DomNode->getDFSNumIn();
+          VD.DFSOut = DomNode->getDFSNumOut();
+        }
+        else {
+          VD.DFSIn = 0;
+          VD.DFSOut = 0;
+        }
         VD.U = &U;
         DFSOrderedSet.emplace_back(VD);
       }</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>