[llvm] r220303 - [PBQP] Check for out of bound access in DEBUG builds

Arnaud A. de Grandmaison arnaud.degrandmaison at arm.com
Tue Oct 21 09:24:21 PDT 2014


Author: aadg
Date: Tue Oct 21 11:24:21 2014
New Revision: 220303

URL: http://llvm.org/viewvc/llvm-project?rev=220303&view=rev
Log:
[PBQP] Check for out of bound access in DEBUG builds

It is just too easy to use a virtual register intead of a NodeId without a
compiler warning. This does not fix the fundamental problem, i.e. both
have the same underlying types, but increases the likelyhood to detect it.

Modified:
    llvm/trunk/include/llvm/CodeGen/PBQP/Graph.h

Modified: llvm/trunk/include/llvm/CodeGen/PBQP/Graph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/PBQP/Graph.h?rev=220303&r1=220302&r2=220303&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/PBQP/Graph.h (original)
+++ llvm/trunk/include/llvm/CodeGen/PBQP/Graph.h Tue Oct 21 11:24:21 2014
@@ -190,8 +190,14 @@ namespace PBQP {
 
     // ----- INTERNAL METHODS -----
 
-    NodeEntry& getNode(NodeId NId) { return Nodes[NId]; }
-    const NodeEntry& getNode(NodeId NId) const { return Nodes[NId]; }
+    NodeEntry &getNode(NodeId NId) {
+      assert(NId < Nodes.size() && "Out of bound NodeId");
+      return Nodes[NId];
+    }
+    const NodeEntry &getNode(NodeId NId) const {
+      assert(NId < Nodes.size() && "Out of bound NodeId");
+      return Nodes[NId];
+    }
 
     EdgeEntry& getEdge(EdgeId EId) { return Edges[EId]; }
     const EdgeEntry& getEdge(EdgeId EId) const { return Edges[EId]; }





More information about the llvm-commits mailing list