[llvm-commits] CVS: llvm/lib/Analysis/DataStructure/DataStructure.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Mar 15 13:37:07 PST 2005



Changes in directory llvm/lib/Analysis/DataStructure:

DataStructure.cpp updated: 1.205 -> 1.206
---
Log message:

Fix a crash that happens when mapping something like this:

 { short, short }

to
  short

where the second short maps onto the second field of the first struct.  In
this case, the struct index is not aligned, so we should avoid calling 
getLink(2), which asserts out.



---
Diffs of the changes:  (+12 -6)

 DataStructure.cpp |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)


Index: llvm/lib/Analysis/DataStructure/DataStructure.cpp
diff -u llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.205 llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.206
--- llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.205	Tue Mar 15 11:52:18 2005
+++ llvm/lib/Analysis/DataStructure/DataStructure.cpp	Tue Mar 15 15:36:50 2005
@@ -2077,12 +2077,18 @@
   unsigned N2Size = N2->getSize();
   if (N2Size == 0) return;   // No edges to map to.
 
-  for (unsigned i = 0, e = N1->getSize(); i < e; i += DS::PointerSize)
-    if (unsigned(N2Idx)+i < N2Size)
-      computeNodeMapping(N1->getLink(i), N2->getLink(N2Idx+i), NodeMap);
-    else
-      computeNodeMapping(N1->getLink(i),
-                         N2->getLink(unsigned(N2Idx+i) % N2Size), NodeMap);
+  for (unsigned i = 0, e = N1->getSize(); i < e; i += DS::PointerSize) {
+    const DSNodeHandle &N1NH = N1->getLink(i);
+    // Don't call N2->getLink if not needed (avoiding crash if N2Idx is not
+    // aligned right).
+    if (!N1NH.isNull()) {
+      if (unsigned(N2Idx)+i < N2Size)
+        computeNodeMapping(N1NH, N2->getLink(N2Idx+i), NodeMap);
+      else
+        computeNodeMapping(N1NH,
+                           N2->getLink(unsigned(N2Idx+i) % N2Size), NodeMap);
+    }
+  }
 }
 
 






More information about the llvm-commits mailing list