File tree Expand file tree Collapse file tree 5 files changed +90
-20
lines changed
cpp/ql/lib/semmle/code/cpp/ir/implementation
csharp/ql/src/experimental/ir/implementation Expand file tree Collapse file tree 5 files changed +90
-20
lines changed Original file line number Diff line number Diff line change @@ -255,14 +255,28 @@ private module Cached {
255
255
cached
256
256
newtype TIRBlock = MkIRBlock ( Instruction firstInstr ) { startsBasicBlock ( firstInstr ) }
257
257
258
- /** Holds if `i` is the `index`th instruction the block starting with `first`. */
259
- private Instruction getInstructionFromFirst ( Instruction first , int index ) =
260
- shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
258
+ /** Gets the index of `i` in its `IRBlock`. */
259
+ private int getMemberIndex ( Instruction i ) {
260
+ startsBasicBlock ( i ) and
261
+ result = 0
262
+ or
263
+ exists ( Instruction iPrev |
264
+ adjacentInBlock ( iPrev , i ) and
265
+ result = getMemberIndex ( iPrev ) + 1
266
+ )
267
+ }
268
+
269
+ private module BlockAdjacency = QlBuiltins:: EquivalenceRelation< Instruction , adjacentInBlock / 2 > ;
261
270
262
271
/** Holds if `i` is the `index`th instruction in `block`. */
263
272
cached
264
273
Instruction getInstruction ( TIRBlock block , int index ) {
265
- result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
274
+ exists ( Instruction first | block = MkIRBlock ( first ) |
275
+ first = result and index = 0
276
+ or
277
+ index = getMemberIndex ( result ) and
278
+ BlockAdjacency:: getEquivalenceClass ( first ) = BlockAdjacency:: getEquivalenceClass ( result )
279
+ )
266
280
}
267
281
268
282
cached
Original file line number Diff line number Diff line change @@ -255,14 +255,28 @@ private module Cached {
255
255
cached
256
256
newtype TIRBlock = MkIRBlock ( Instruction firstInstr ) { startsBasicBlock ( firstInstr ) }
257
257
258
- /** Holds if `i` is the `index`th instruction the block starting with `first`. */
259
- private Instruction getInstructionFromFirst ( Instruction first , int index ) =
260
- shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
258
+ /** Gets the index of `i` in its `IRBlock`. */
259
+ private int getMemberIndex ( Instruction i ) {
260
+ startsBasicBlock ( i ) and
261
+ result = 0
262
+ or
263
+ exists ( Instruction iPrev |
264
+ adjacentInBlock ( iPrev , i ) and
265
+ result = getMemberIndex ( iPrev ) + 1
266
+ )
267
+ }
268
+
269
+ private module BlockAdjacency = QlBuiltins:: EquivalenceRelation< Instruction , adjacentInBlock / 2 > ;
261
270
262
271
/** Holds if `i` is the `index`th instruction in `block`. */
263
272
cached
264
273
Instruction getInstruction ( TIRBlock block , int index ) {
265
- result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
274
+ exists ( Instruction first | block = MkIRBlock ( first ) |
275
+ first = result and index = 0
276
+ or
277
+ index = getMemberIndex ( result ) and
278
+ BlockAdjacency:: getEquivalenceClass ( first ) = BlockAdjacency:: getEquivalenceClass ( result )
279
+ )
266
280
}
267
281
268
282
cached
Original file line number Diff line number Diff line change @@ -255,14 +255,28 @@ private module Cached {
255
255
cached
256
256
newtype TIRBlock = MkIRBlock ( Instruction firstInstr ) { startsBasicBlock ( firstInstr ) }
257
257
258
- /** Holds if `i` is the `index`th instruction the block starting with `first`. */
259
- private Instruction getInstructionFromFirst ( Instruction first , int index ) =
260
- shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
258
+ /** Gets the index of `i` in its `IRBlock`. */
259
+ private int getMemberIndex ( Instruction i ) {
260
+ startsBasicBlock ( i ) and
261
+ result = 0
262
+ or
263
+ exists ( Instruction iPrev |
264
+ adjacentInBlock ( iPrev , i ) and
265
+ result = getMemberIndex ( iPrev ) + 1
266
+ )
267
+ }
268
+
269
+ private module BlockAdjacency = QlBuiltins:: EquivalenceRelation< Instruction , adjacentInBlock / 2 > ;
261
270
262
271
/** Holds if `i` is the `index`th instruction in `block`. */
263
272
cached
264
273
Instruction getInstruction ( TIRBlock block , int index ) {
265
- result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
274
+ exists ( Instruction first | block = MkIRBlock ( first ) |
275
+ first = result and index = 0
276
+ or
277
+ index = getMemberIndex ( result ) and
278
+ BlockAdjacency:: getEquivalenceClass ( first ) = BlockAdjacency:: getEquivalenceClass ( result )
279
+ )
266
280
}
267
281
268
282
cached
Original file line number Diff line number Diff line change @@ -255,14 +255,28 @@ private module Cached {
255
255
cached
256
256
newtype TIRBlock = MkIRBlock ( Instruction firstInstr ) { startsBasicBlock ( firstInstr ) }
257
257
258
- /** Holds if `i` is the `index`th instruction the block starting with `first`. */
259
- private Instruction getInstructionFromFirst ( Instruction first , int index ) =
260
- shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
258
+ /** Gets the index of `i` in its `IRBlock`. */
259
+ private int getMemberIndex ( Instruction i ) {
260
+ startsBasicBlock ( i ) and
261
+ result = 0
262
+ or
263
+ exists ( Instruction iPrev |
264
+ adjacentInBlock ( iPrev , i ) and
265
+ result = getMemberIndex ( iPrev ) + 1
266
+ )
267
+ }
268
+
269
+ private module BlockAdjacency = QlBuiltins:: EquivalenceRelation< Instruction , adjacentInBlock / 2 > ;
261
270
262
271
/** Holds if `i` is the `index`th instruction in `block`. */
263
272
cached
264
273
Instruction getInstruction ( TIRBlock block , int index ) {
265
- result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
274
+ exists ( Instruction first | block = MkIRBlock ( first ) |
275
+ first = result and index = 0
276
+ or
277
+ index = getMemberIndex ( result ) and
278
+ BlockAdjacency:: getEquivalenceClass ( first ) = BlockAdjacency:: getEquivalenceClass ( result )
279
+ )
266
280
}
267
281
268
282
cached
Original file line number Diff line number Diff line change @@ -255,14 +255,28 @@ private module Cached {
255
255
cached
256
256
newtype TIRBlock = MkIRBlock ( Instruction firstInstr ) { startsBasicBlock ( firstInstr ) }
257
257
258
- /** Holds if `i` is the `index`th instruction the block starting with `first`. */
259
- private Instruction getInstructionFromFirst ( Instruction first , int index ) =
260
- shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
258
+ /** Gets the index of `i` in its `IRBlock`. */
259
+ private int getMemberIndex ( Instruction i ) {
260
+ startsBasicBlock ( i ) and
261
+ result = 0
262
+ or
263
+ exists ( Instruction iPrev |
264
+ adjacentInBlock ( iPrev , i ) and
265
+ result = getMemberIndex ( iPrev ) + 1
266
+ )
267
+ }
268
+
269
+ private module BlockAdjacency = QlBuiltins:: EquivalenceRelation< Instruction , adjacentInBlock / 2 > ;
261
270
262
271
/** Holds if `i` is the `index`th instruction in `block`. */
263
272
cached
264
273
Instruction getInstruction ( TIRBlock block , int index ) {
265
- result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
274
+ exists ( Instruction first | block = MkIRBlock ( first ) |
275
+ first = result and index = 0
276
+ or
277
+ index = getMemberIndex ( result ) and
278
+ BlockAdjacency:: getEquivalenceClass ( first ) = BlockAdjacency:: getEquivalenceClass ( result )
279
+ )
266
280
}
267
281
268
282
cached
You can’t perform that action at this time.
0 commit comments