[llvm] r264470 - SelectionDAG: Remove arbitrary and bug-prone complexity from SDLoc

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 25 15:12:41 PDT 2016


Author: bogner
Date: Fri Mar 25 17:12:41 2016
New Revision: 264470

URL: http://llvm.org/viewvc/llvm-project?rev=264470&view=rev
Log:
SelectionDAG: Remove arbitrary and bug-prone complexity from SDLoc

The implementation of SDLoc has an extra layer of indirection here for
no particular reason, and was leading to problems where we were
dereferencing pointers to SDNodes that had already been deleted so
that we could get at the DebugLoc for a new SDNode. This is one of the
errors that came up often in PR26808.

Instead, we can just track the DebugLoc and IROrder directly. This
makes the code both easier to understand and more correct. It's also
basically NFC other than fixing a large number of places where we were
reading the memory of deleted SDNodes.

Modified:
    llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h

Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h?rev=264470&r1=264469&r2=264470&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h Fri Mar 25 17:12:41 2016
@@ -835,40 +835,20 @@ protected:
 /// be used by the DAGBuilder, the other to be used by others.
 class SDLoc {
 private:
-  // Ptr could be used for either Instruction* or SDNode*. It is used for
-  // Instruction* if IROrder is not -1.
-  const void *Ptr;
-  int IROrder;
+  DebugLoc DL;
+  int IROrder = 0;
 
 public:
-  SDLoc() : Ptr(nullptr), IROrder(0) {}
-  SDLoc(const SDNode *N) : Ptr(N), IROrder(-1) {
-    assert(N && "null SDNode");
-  }
-  SDLoc(const SDValue V) : Ptr(V.getNode()), IROrder(-1) {
-    assert(Ptr && "null SDNode");
-  }
-  SDLoc(const Instruction *I, int Order) : Ptr(I), IROrder(Order) {
+  SDLoc() = default;
+  SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
+  SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
+  SDLoc(const Instruction *I, int Order) : IROrder(Order) {
     assert(Order >= 0 && "bad IROrder");
+    if (I)
+      DL = I->getDebugLoc();
   }
-  unsigned getIROrder() {
-    if (IROrder >= 0 || Ptr == nullptr) {
-      return (unsigned)IROrder;
-    }
-    const SDNode *N = (const SDNode*)(Ptr);
-    return N->getIROrder();
-  }
-  DebugLoc getDebugLoc() {
-    if (!Ptr) {
-      return DebugLoc();
-    }
-    if (IROrder >= 0) {
-      const Instruction *I = (const Instruction*)(Ptr);
-      return I->getDebugLoc();
-    }
-    const SDNode *N = (const SDNode*)(Ptr);
-    return N->getDebugLoc();
-  }
+  unsigned getIROrder() { return IROrder; }
+  DebugLoc getDebugLoc() { return DL; }
 };
 
 




More information about the llvm-commits mailing list