Skip to content

Commit b834173

Browse files
committed
Merge branch 'main' into redsun82/kotlin
2 parents 450f651 + 607ed2e commit b834173

File tree

46 files changed

+872
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+872
-347
lines changed

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,5 +1156,14 @@ private predicate add_eq(
11561156
)
11571157
}
11581158

1159+
private class IntegerOrPointerConstantInstruction extends ConstantInstruction {
1160+
IntegerOrPointerConstantInstruction() {
1161+
this instanceof IntegerConstantInstruction or
1162+
this instanceof PointerConstantInstruction
1163+
}
1164+
}
1165+
11591166
/** The int value of integer constant expression. */
1160-
private int int_value(Instruction i) { result = i.(IntegerConstantInstruction).getValue().toInt() }
1167+
private int int_value(Instruction i) {
1168+
result = i.(IntegerOrPointerConstantInstruction).getValue().toInt()
1169+
}

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ class Instruction extends Construction::TStageInstruction {
247247
* Gets the type of the result produced by this instruction. If the instruction does not produce
248248
* a result, its result type will be `IRVoidType`.
249249
*/
250-
cached
251-
final IRType getResultIRType() { result = this.getResultLanguageType().getIRType() }
250+
final IRType getResultIRType() { result = Construction::getInstructionResultIRType(this) }
252251

253252
/**
254253
* Gets the type of the result produced by this instruction. If the
@@ -995,9 +994,8 @@ class ConstantInstruction extends ConstantValueInstruction {
995994
*/
996995
class IntegerConstantInstruction extends ConstantInstruction {
997996
IntegerConstantInstruction() {
998-
exists(IRType resultType |
999-
resultType = this.getResultIRType() and
1000-
(resultType instanceof IRIntegerType or resultType instanceof IRBooleanType)
997+
exists(IRType resultType | resultType = this.getResultIRType() |
998+
resultType instanceof IRIntegerType or resultType instanceof IRBooleanType
1001999
)
10021000
}
10031001
}
@@ -1009,6 +1007,17 @@ class FloatConstantInstruction extends ConstantInstruction {
10091007
FloatConstantInstruction() { this.getResultIRType() instanceof IRFloatingPointType }
10101008
}
10111009

1010+
/**
1011+
* An instruction whose result is a constant value of a pointer type.
1012+
*/
1013+
class PointerConstantInstruction extends ConstantInstruction {
1014+
PointerConstantInstruction() {
1015+
exists(IRType resultType | resultType = this.getResultIRType() |
1016+
resultType instanceof IRAddressType or resultType instanceof IRFunctionAddressType
1017+
)
1018+
}
1019+
}
1020+
10121021
/**
10131022
* An instruction whose result is the address of a string literal.
10141023
*/

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ private module Cached {
429429
instr = unreachedInstruction(_) and result = Language::getVoidType()
430430
}
431431

432+
cached
433+
IRType getInstructionResultIRType(Instruction instr) {
434+
result = instr.getResultLanguageType().getIRType()
435+
}
436+
432437
/**
433438
* Holds if `opcode` is the opcode that specifies the operation performed by `instr`.
434439
*

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ class Instruction extends Construction::TStageInstruction {
247247
* Gets the type of the result produced by this instruction. If the instruction does not produce
248248
* a result, its result type will be `IRVoidType`.
249249
*/
250-
cached
251-
final IRType getResultIRType() { result = this.getResultLanguageType().getIRType() }
250+
final IRType getResultIRType() { result = Construction::getInstructionResultIRType(this) }
252251

253252
/**
254253
* Gets the type of the result produced by this instruction. If the
@@ -995,9 +994,8 @@ class ConstantInstruction extends ConstantValueInstruction {
995994
*/
996995
class IntegerConstantInstruction extends ConstantInstruction {
997996
IntegerConstantInstruction() {
998-
exists(IRType resultType |
999-
resultType = this.getResultIRType() and
1000-
(resultType instanceof IRIntegerType or resultType instanceof IRBooleanType)
997+
exists(IRType resultType | resultType = this.getResultIRType() |
998+
resultType instanceof IRIntegerType or resultType instanceof IRBooleanType
1001999
)
10021000
}
10031001
}
@@ -1009,6 +1007,17 @@ class FloatConstantInstruction extends ConstantInstruction {
10091007
FloatConstantInstruction() { this.getResultIRType() instanceof IRFloatingPointType }
10101008
}
10111009

1010+
/**
1011+
* An instruction whose result is a constant value of a pointer type.
1012+
*/
1013+
class PointerConstantInstruction extends ConstantInstruction {
1014+
PointerConstantInstruction() {
1015+
exists(IRType resultType | resultType = this.getResultIRType() |
1016+
resultType instanceof IRAddressType or resultType instanceof IRFunctionAddressType
1017+
)
1018+
}
1019+
}
1020+
10121021
/**
10131022
* An instruction whose result is the address of a string literal.
10141023
*/

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ CppType getInstructionResultType(TStageInstruction instr) {
377377
result = getVoidType()
378378
}
379379

380+
IRType getInstructionResultIRType(Instruction instr) {
381+
result = instr.getResultLanguageType().getIRType()
382+
}
383+
380384
predicate getInstructionOpcode(Opcode opcode, TStageInstruction instr) {
381385
getInstructionTranslatedElement(instr).hasInstruction(opcode, getInstructionTag(instr), _)
382386
or

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,11 @@ class TranslatedResultCopy extends TranslatedExpr, TTranslatedResultCopy {
538538
final override predicate producesExprResult() { any() }
539539

540540
private TranslatedCoreExpr getOperand() { result.getExpr() = expr }
541+
542+
override predicate handlesDestructorsExplicitly() {
543+
// The destructor calls will already have been generated by the translation of `expr`.
544+
any()
545+
}
541546
}
542547

543548
class TranslatedCommaExpr extends TranslatedNonConstantExpr {

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ class Instruction extends Construction::TStageInstruction {
247247
* Gets the type of the result produced by this instruction. If the instruction does not produce
248248
* a result, its result type will be `IRVoidType`.
249249
*/
250-
cached
251-
final IRType getResultIRType() { result = this.getResultLanguageType().getIRType() }
250+
final IRType getResultIRType() { result = Construction::getInstructionResultIRType(this) }
252251

253252
/**
254253
* Gets the type of the result produced by this instruction. If the
@@ -995,9 +994,8 @@ class ConstantInstruction extends ConstantValueInstruction {
995994
*/
996995
class IntegerConstantInstruction extends ConstantInstruction {
997996
IntegerConstantInstruction() {
998-
exists(IRType resultType |
999-
resultType = this.getResultIRType() and
1000-
(resultType instanceof IRIntegerType or resultType instanceof IRBooleanType)
997+
exists(IRType resultType | resultType = this.getResultIRType() |
998+
resultType instanceof IRIntegerType or resultType instanceof IRBooleanType
1001999
)
10021000
}
10031001
}
@@ -1009,6 +1007,17 @@ class FloatConstantInstruction extends ConstantInstruction {
10091007
FloatConstantInstruction() { this.getResultIRType() instanceof IRFloatingPointType }
10101008
}
10111009

1010+
/**
1011+
* An instruction whose result is a constant value of a pointer type.
1012+
*/
1013+
class PointerConstantInstruction extends ConstantInstruction {
1014+
PointerConstantInstruction() {
1015+
exists(IRType resultType | resultType = this.getResultIRType() |
1016+
resultType instanceof IRAddressType or resultType instanceof IRFunctionAddressType
1017+
)
1018+
}
1019+
}
1020+
10121021
/**
10131022
* An instruction whose result is the address of a string literal.
10141023
*/

cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ private module Cached {
429429
instr = unreachedInstruction(_) and result = Language::getVoidType()
430430
}
431431

432+
cached
433+
IRType getInstructionResultIRType(Instruction instr) {
434+
result = instr.getResultLanguageType().getIRType()
435+
}
436+
432437
/**
433438
* Holds if `opcode` is the opcode that specifies the operation performed by `instr`.
434439
*

cpp/ql/test/library-tests/controlflow/guards-ir/tests.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ astGuardsCompare
5656
| 17 | y < 1+1 when ... > ... is false |
5757
| 17 | y >= 1+1 when ... && ... is true |
5858
| 17 | y >= 1+1 when ... > ... is true |
59+
| 18 | call to get != 0 when call to get is true |
60+
| 18 | call to get == 0 when call to get is false |
5961
| 26 | 0 < x+0 when ... > ... is true |
6062
| 26 | 0 >= x+0 when ... > ... is false |
6163
| 26 | x < 0+1 when ... > ... is false |
@@ -487,6 +489,7 @@ astGuardsEnsure_const
487489
| test.c:109:9:109:23 | ... \|\| ... | test.c:109:9:109:9 | x | != | 0 | 113 | 113 |
488490
| test.c:175:13:175:32 | ... == ... | test.c:175:13:175:15 | call to foo | != | 0 | 175 | 175 |
489491
| test.c:175:13:175:32 | ... == ... | test.c:175:13:175:15 | call to foo | == | 0 | 175 | 175 |
492+
| test.cpp:18:8:18:10 | call to get | test.cpp:18:8:18:10 | call to get | != | 0 | 19 | 19 |
490493
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | -1 | 30 | 30 |
491494
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | -1 | 34 | 34 |
492495
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | == | -1 | 30 | 30 |
@@ -545,6 +548,8 @@ irGuardsCompare
545548
| 17 | y < 2 when CompareGT: ... > ... is false |
546549
| 17 | y >= 1+1 when CompareGT: ... > ... is true |
547550
| 17 | y >= 2 when CompareGT: ... > ... is true |
551+
| 18 | call to get != 0 when CompareNE: (bool)... is true |
552+
| 18 | call to get == 0 when CompareNE: (bool)... is false |
548553
| 26 | 0 < x+0 when CompareGT: ... > ... is true |
549554
| 26 | 0 >= x+0 when CompareGT: ... > ... is false |
550555
| 26 | x < 0+1 when CompareGT: ... > ... is false |
@@ -996,6 +1001,7 @@ irGuardsEnsure_const
9961001
| test.c:109:19:109:23 | CompareLT: ... < ... | test.c:109:19:109:19 | Load: y | >= | 0 | 113 | 113 |
9971002
| test.c:175:13:175:32 | CompareEQ: ... == ... | test.c:175:13:175:15 | Call: call to foo | != | 0 | 175 | 175 |
9981003
| test.c:175:13:175:32 | CompareEQ: ... == ... | test.c:175:13:175:15 | Call: call to foo | == | 0 | 175 | 175 |
1004+
| test.cpp:18:8:18:12 | CompareNE: (bool)... | test.cpp:18:8:18:10 | Call: call to get | != | 0 | 19 | 19 |
9991005
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | test.cpp:31:7:31:7 | Load: x | != | -1 | 34 | 34 |
10001006
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | test.cpp:31:7:31:7 | Load: x | == | -1 | 30 | 30 |
10011007
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | test.cpp:31:7:31:7 | Load: x | == | -1 | 32 | 32 |

cpp/ql/test/library-tests/controlflow/guards/Guards.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@
3232
| test.cpp:61:10:61:10 | i |
3333
| test.cpp:74:10:74:10 | i |
3434
| test.cpp:84:10:84:10 | i |
35+
| test.cpp:93:6:93:6 | c |
36+
| test.cpp:99:6:99:6 | f |
37+
| test.cpp:105:6:105:14 | ... != ... |
38+
| test.cpp:111:6:111:14 | ... != ... |

0 commit comments

Comments
 (0)