Skip to content

Commit 687d6d2

Browse files
author
Dave Bartolomeo
committed
C++: Replace TRawInstruction() calls
Replace most direct calls to `TRawInstruction()` with calls to `getInstructionTranslatedElement()` and `getInstructionTag()`, matching existing practice. One tiny RA diff in an inconsequential join order in `getInstructionVariable`.
1 parent c101674 commit 687d6d2

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/IRConstruction.qll

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ module Raw {
7171
cached
7272
TIRVariable getInstructionVariable(Instruction instruction) {
7373
exists(TranslatedElement element, InstructionTag tag |
74-
instruction = TRawInstruction(element, tag) and
74+
element = getInstructionTranslatedElement(instruction) and
75+
tag = getInstructionTag(instruction) and
7576
(
7677
result = element.getInstructionVariable(tag) or
7778
result.(IRStringLiteral).getAST() = element.getInstructionStringLiteral(tag)
@@ -81,10 +82,9 @@ module Raw {
8182

8283
cached
8384
Field getInstructionField(Instruction instruction) {
84-
exists(TranslatedElement element, InstructionTag tag |
85-
instruction = TRawInstruction(element, tag) and
86-
result = element.getInstructionField(tag)
87-
)
85+
result =
86+
getInstructionTranslatedElement(instruction)
87+
.getInstructionField(getInstructionTag(instruction))
8888
}
8989

9090
cached
@@ -103,10 +103,9 @@ module Raw {
103103

104104
cached
105105
int getInstructionIndex(Instruction instruction) {
106-
exists(TranslatedElement element, InstructionTag tag |
107-
instruction = TRawInstruction(element, tag) and
108-
result = element.getInstructionIndex(tag)
109-
)
106+
result =
107+
getInstructionTranslatedElement(instruction)
108+
.getInstructionIndex(getInstructionTag(instruction))
110109
}
111110

112111
cached
@@ -131,10 +130,9 @@ module Raw {
131130

132131
cached
133132
int getInstructionElementSize(Instruction instruction) {
134-
exists(TranslatedElement element, InstructionTag tag |
135-
instruction = TRawInstruction(element, tag) and
136-
result = element.getInstructionElementSize(tag)
137-
)
133+
result =
134+
getInstructionTranslatedElement(instruction)
135+
.getInstructionElementSize(getInstructionTag(instruction))
138136
}
139137

140138
cached
@@ -345,28 +343,21 @@ Locatable getInstructionAST(TStageInstruction instr) {
345343
}
346344

347345
CppType getInstructionResultType(TStageInstruction instr) {
348-
exists(TranslatedElement element, InstructionTag tag |
349-
instr = TRawInstruction(element, tag) and
350-
element.hasInstruction(_, tag, result)
351-
)
346+
getInstructionTranslatedElement(instr).hasInstruction(_, getInstructionTag(instr), result)
352347
}
353348

354349
Opcode getInstructionOpcode(TStageInstruction instr) {
355-
exists(TranslatedElement element, InstructionTag tag |
356-
instr = TRawInstruction(element, tag) and
357-
element.hasInstruction(result, tag, _)
358-
)
350+
getInstructionTranslatedElement(instr).hasInstruction(result, getInstructionTag(instr), _)
359351
}
360352

361353
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
362354
result.getFunction() = getInstructionTranslatedElement(instr).getFunction()
363355
}
364356

365357
Instruction getPrimaryInstructionForSideEffect(SideEffectInstruction instruction) {
366-
exists(TranslatedElement element, InstructionTag tag |
367-
instruction = TRawInstruction(element, tag) and
368-
result = element.getPrimaryInstructionForSideEffect(tag)
369-
)
358+
result =
359+
getInstructionTranslatedElement(instruction)
360+
.getPrimaryInstructionForSideEffect(getInstructionTag(instruction))
370361
}
371362

372363
import CachedForDebugging

0 commit comments

Comments
 (0)