Skip to content

Commit 50dc5e2

Browse files
author
Dave Bartolomeo
authored
Merge pull request #2438 from rdmarsh2/rdmarsh/ir-line-number-ids
C++/C#: use line numbers for instruction IDs
2 parents 57917be + 722cc91 commit 50dc5e2

File tree

10 files changed

+8853
-8853
lines changed

10 files changed

+8853
-8853
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -359,24 +359,25 @@ class Instruction extends Construction::TInstruction {
359359
*/
360360
int getDisplayIndexInBlock() {
361361
exists(IRBlock block |
362-
block = getBlock() and
363-
(
364-
exists(int index, int phiCount |
365-
phiCount = count(block.getAPhiInstruction()) and
366-
this = block.getInstruction(index) and
367-
result = index + phiCount
362+
this = block.getInstruction(result)
363+
or
364+
this = rank[-result - 1](PhiInstruction phiInstr |
365+
phiInstr = block.getAPhiInstruction()
366+
|
367+
phiInstr order by phiInstr.getUniqueId()
368368
)
369-
or
370-
this instanceof PhiInstruction and
371-
this = rank[result + 1](PhiInstruction phiInstr |
372-
phiInstr = block.getAPhiInstruction()
373-
|
374-
phiInstr order by phiInstr.getUniqueId()
375-
)
376-
)
377369
)
378370
}
379371

372+
private int getLineRank() {
373+
this = rank[result](Instruction instr |
374+
instr.getAST().getFile() = getAST().getFile() and
375+
instr.getAST().getLocation().getStartLine() = getAST().getLocation().getStartLine()
376+
|
377+
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
378+
)
379+
}
380+
380381
/**
381382
* Gets a human-readable string that uniquely identifies this instruction
382383
* within the function. This string is used to refer to this instruction when
@@ -385,8 +386,7 @@ class Instruction extends Construction::TInstruction {
385386
* Example: `r1_1`
386387
*/
387388
string getResultId() {
388-
result = getResultPrefix() + getBlock().getDisplayIndex().toString() + "_" +
389-
getDisplayIndexInBlock().toString()
389+
result = getResultPrefix() + getAST().getLocation().getStartLine() + "_" + getLineRank()
390390
}
391391

392392
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -359,24 +359,25 @@ class Instruction extends Construction::TInstruction {
359359
*/
360360
int getDisplayIndexInBlock() {
361361
exists(IRBlock block |
362-
block = getBlock() and
363-
(
364-
exists(int index, int phiCount |
365-
phiCount = count(block.getAPhiInstruction()) and
366-
this = block.getInstruction(index) and
367-
result = index + phiCount
362+
this = block.getInstruction(result)
363+
or
364+
this = rank[-result - 1](PhiInstruction phiInstr |
365+
phiInstr = block.getAPhiInstruction()
366+
|
367+
phiInstr order by phiInstr.getUniqueId()
368368
)
369-
or
370-
this instanceof PhiInstruction and
371-
this = rank[result + 1](PhiInstruction phiInstr |
372-
phiInstr = block.getAPhiInstruction()
373-
|
374-
phiInstr order by phiInstr.getUniqueId()
375-
)
376-
)
377369
)
378370
}
379371

372+
private int getLineRank() {
373+
this = rank[result](Instruction instr |
374+
instr.getAST().getFile() = getAST().getFile() and
375+
instr.getAST().getLocation().getStartLine() = getAST().getLocation().getStartLine()
376+
|
377+
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
378+
)
379+
}
380+
380381
/**
381382
* Gets a human-readable string that uniquely identifies this instruction
382383
* within the function. This string is used to refer to this instruction when
@@ -385,8 +386,7 @@ class Instruction extends Construction::TInstruction {
385386
* Example: `r1_1`
386387
*/
387388
string getResultId() {
388-
result = getResultPrefix() + getBlock().getDisplayIndex().toString() + "_" +
389-
getDisplayIndexInBlock().toString()
389+
result = getResultPrefix() + getAST().getLocation().getStartLine() + "_" + getLineRank()
390390
}
391391

392392
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -359,24 +359,25 @@ class Instruction extends Construction::TInstruction {
359359
*/
360360
int getDisplayIndexInBlock() {
361361
exists(IRBlock block |
362-
block = getBlock() and
363-
(
364-
exists(int index, int phiCount |
365-
phiCount = count(block.getAPhiInstruction()) and
366-
this = block.getInstruction(index) and
367-
result = index + phiCount
362+
this = block.getInstruction(result)
363+
or
364+
this = rank[-result - 1](PhiInstruction phiInstr |
365+
phiInstr = block.getAPhiInstruction()
366+
|
367+
phiInstr order by phiInstr.getUniqueId()
368368
)
369-
or
370-
this instanceof PhiInstruction and
371-
this = rank[result + 1](PhiInstruction phiInstr |
372-
phiInstr = block.getAPhiInstruction()
373-
|
374-
phiInstr order by phiInstr.getUniqueId()
375-
)
376-
)
377369
)
378370
}
379371

372+
private int getLineRank() {
373+
this = rank[result](Instruction instr |
374+
instr.getAST().getFile() = getAST().getFile() and
375+
instr.getAST().getLocation().getStartLine() = getAST().getLocation().getStartLine()
376+
|
377+
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
378+
)
379+
}
380+
380381
/**
381382
* Gets a human-readable string that uniquely identifies this instruction
382383
* within the function. This string is used to refer to this instruction when
@@ -385,8 +386,7 @@ class Instruction extends Construction::TInstruction {
385386
* Example: `r1_1`
386387
*/
387388
string getResultId() {
388-
result = getResultPrefix() + getBlock().getDisplayIndex().toString() + "_" +
389-
getDisplayIndexInBlock().toString()
389+
result = getResultPrefix() + getAST().getLocation().getStartLine() + "_" + getLineRank()
390390
}
391391

392392
/**

0 commit comments

Comments
 (0)