Skip to content

Commit c216176

Browse files
committed
C++: sync and accept new consistency test
1 parent f063414 commit c216176

21 files changed

+169
-126
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,4 +524,23 @@ module InstructionConsistency {
524524
"' has a `this` argument operand that is not an address, in function '$@'." and
525525
irFunc = getInstructionIRFunction(instr, irFuncText)
526526
}
527+
528+
query predicate nonUniqueIRVariable(
529+
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
530+
) {
531+
exists(VariableInstruction vi, IRVariable v1, IRVariable v2 |
532+
instr = vi and vi.getIRVariable() = v1 and vi.getIRVariable() = v2 and v1 != v2
533+
) and
534+
message =
535+
"Variable instruction '" + instr.toString() +
536+
"' has multiple associated variables, in function '$@'." and
537+
irFunc = getInstructionIRFunction(instr, irFuncText)
538+
or
539+
instr.getOpcode() instanceof Opcode::VariableAddress and
540+
not instr instanceof VariableInstruction and
541+
message =
542+
"Variable address instruction '" + instr.toString() +
543+
"' has no associated variable, in function '$@'." and
544+
irFunc = getInstructionIRFunction(instr, irFuncText)
545+
}
527546
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,4 +524,23 @@ module InstructionConsistency {
524524
"' has a `this` argument operand that is not an address, in function '$@'." and
525525
irFunc = getInstructionIRFunction(instr, irFuncText)
526526
}
527+
528+
query predicate nonUniqueIRVariable(
529+
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
530+
) {
531+
exists(VariableInstruction vi, IRVariable v1, IRVariable v2 |
532+
instr = vi and vi.getIRVariable() = v1 and vi.getIRVariable() = v2 and v1 != v2
533+
) and
534+
message =
535+
"Variable instruction '" + instr.toString() +
536+
"' has multiple associated variables, in function '$@'." and
537+
irFunc = getInstructionIRFunction(instr, irFuncText)
538+
or
539+
instr.getOpcode() instanceof Opcode::VariableAddress and
540+
not instr instanceof VariableInstruction and
541+
message =
542+
"Variable address instruction '" + instr.toString() +
543+
"' has no associated variable, in function '$@'." and
544+
irFunc = getInstructionIRFunction(instr, irFuncText)
545+
}
527546
}

cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ invalidOverlap
2323
nonUniqueEnclosingIRFunction
2424
fieldAddressOnNonPointer
2525
thisArgumentIsNonPointer
26+
nonUniqueIRVariable
2627
missingCanonicalLanguageType
2728
multipleCanonicalLanguageTypes
2829
missingIRType

cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency_unsound.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ invalidOverlap
2323
nonUniqueEnclosingIRFunction
2424
fieldAddressOnNonPointer
2525
thisArgumentIsNonPointer
26+
nonUniqueIRVariable
2627
missingCanonicalLanguageType
2728
multipleCanonicalLanguageTypes
2829
missingIRType

cpp/ql/test/library-tests/ir/ir/raw_consistency.expected

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ nonUniqueEnclosingIRFunction
2828
fieldAddressOnNonPointer
2929
thisArgumentIsNonPointer
3030
nonUniqueIRVariable
31-
| ir.cpp:1038:6:1038:8 | VariableAddress: lam | Variable address instruction 'VariableAddress: lam' has no associated variable, in function '$@'. | ir.cpp:1038:6:1038:8 | (lambda [] type at line 1038, col. 12) lam | (lambda [] type at line 1038, col. 12) lam |
32-
| ir.cpp:1759:5:1759:12 | VariableAddress: global_2 | Variable address instruction 'VariableAddress: global_2' has no associated variable, in function '$@'. | ir.cpp:1759:5:1759:12 | int global_2 | int global_2 |
33-
| ir.cpp:1761:11:1761:18 | VariableAddress: global_3 | Variable address instruction 'VariableAddress: global_3' has no associated variable, in function '$@'. | ir.cpp:1761:11:1761:18 | int const global_3 | int const global_3 |
34-
| ir.cpp:1763:18:1763:25 | VariableAddress: global_4 | Variable address instruction 'VariableAddress: global_4' has no associated variable, in function '$@'. | ir.cpp:1763:18:1763:25 | constructor_only global_4 | constructor_only global_4 |
35-
| ir.cpp:1765:18:1765:25 | VariableAddress: global_5 | Variable address instruction 'VariableAddress: global_5' has no associated variable, in function '$@'. | ir.cpp:1765:18:1765:25 | constructor_only global_5 | constructor_only global_5 |
36-
| ir.cpp:1767:7:1767:19 | VariableAddress: global_string | Variable address instruction 'VariableAddress: global_string' has no associated variable, in function '$@'. | ir.cpp:1767:7:1767:19 | char* global_string | char* global_string |
37-
| struct_init.cpp:9:13:9:25 | VariableAddress: infos_in_file | Variable address instruction 'VariableAddress: infos_in_file' has no associated variable, in function '$@'. | struct_init.cpp:9:13:9:25 | Info infos_in_file[] | Info infos_in_file[] |
3831
missingCanonicalLanguageType
3932
multipleCanonicalLanguageTypes
4033
missingIRType

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5654,11 +5654,11 @@ ir.cpp:
56545654
# 1038| Block 0
56555655
# 1038| v1038_1(void) = EnterFunction :
56565656
# 1038| mu1038_2(unknown) = AliasedDefinition :
5657-
# 1038| r1038_3(glval<decltype([...](...){...})>) = VariableAddress :
5657+
# 1038| r1038_3(glval<decltype([...](...){...})>) = VariableAddress[lam] :
56585658
# 1038| r1038_4(glval<decltype([...](...){...})>) = VariableAddress[#temp1038:12] :
56595659
# 1038| mu1038_5(decltype([...](...){...})) = Uninitialized[#temp1038:12] : &:r1038_4
56605660
# 1038| r1038_6(decltype([...](...){...})) = Load[#temp1038:12] : &:r1038_4, ~m?
5661-
# 1038| mu1038_7(decltype([...](...){...})) = Store[?] : &:r1038_3, r1038_6
5661+
# 1038| mu1038_7(decltype([...](...){...})) = Store[lam] : &:r1038_3, r1038_6
56625662
# 1038| v1038_8(void) = ReturnVoid :
56635663
# 1038| v1038_9(void) = AliasedUse : ~m?
56645664
# 1038| v1038_10(void) = ExitFunction :
@@ -9735,31 +9735,31 @@ ir.cpp:
97359735

97369736
# 1821| int global_2
97379737
# 1821| Block 0
9738-
# 1821| v1821_1(void) = EnterFunction :
9739-
# 1821| mu1821_2(unknown) = AliasedDefinition :
9740-
# 1821| r1821_3(glval<int>) = VariableAddress :
9741-
# 1821| r1821_4(int) = Constant[1] :
9742-
# 1821| mu1821_5(int) = Store[?] : &:r1821_3, r1821_4
9743-
# 1821| v1821_6(void) = ReturnVoid :
9744-
# 1821| v1821_7(void) = AliasedUse : ~m?
9745-
# 1821| v1821_8(void) = ExitFunction :
9738+
# 1821| v1821_1(void) = EnterFunction :
9739+
# 1821| mu1821_2(unknown) = AliasedDefinition :
9740+
# 1821| r1821_3(glval<int>) = VariableAddress[global_2] :
9741+
# 1821| r1821_4(int) = Constant[1] :
9742+
# 1821| mu1821_5(int) = Store[global_2] : &:r1821_3, r1821_4
9743+
# 1821| v1821_6(void) = ReturnVoid :
9744+
# 1821| v1821_7(void) = AliasedUse : ~m?
9745+
# 1821| v1821_8(void) = ExitFunction :
97469746

97479747
# 1823| int const global_3
97489748
# 1823| Block 0
9749-
# 1823| v1823_1(void) = EnterFunction :
9750-
# 1823| mu1823_2(unknown) = AliasedDefinition :
9751-
# 1823| r1823_3(glval<int>) = VariableAddress :
9752-
# 1823| r1823_4(int) = Constant[2] :
9753-
# 1823| mu1823_5(int) = Store[?] : &:r1823_3, r1823_4
9754-
# 1823| v1823_6(void) = ReturnVoid :
9755-
# 1823| v1823_7(void) = AliasedUse : ~m?
9756-
# 1823| v1823_8(void) = ExitFunction :
9749+
# 1823| v1823_1(void) = EnterFunction :
9750+
# 1823| mu1823_2(unknown) = AliasedDefinition :
9751+
# 1823| r1823_3(glval<int>) = VariableAddress[global_3] :
9752+
# 1823| r1823_4(int) = Constant[2] :
9753+
# 1823| mu1823_5(int) = Store[global_3] : &:r1823_3, r1823_4
9754+
# 1823| v1823_6(void) = ReturnVoid :
9755+
# 1823| v1823_7(void) = AliasedUse : ~m?
9756+
# 1823| v1823_8(void) = ExitFunction :
97579757

97589758
# 1825| constructor_only global_4
97599759
# 1825| Block 0
97609760
# 1825| v1825_1(void) = EnterFunction :
97619761
# 1825| mu1825_2(unknown) = AliasedDefinition :
9762-
# 1825| r1825_3(glval<constructor_only>) = VariableAddress :
9762+
# 1825| r1825_3(glval<constructor_only>) = VariableAddress[global_4] :
97639763
# 1825| r1825_4(glval<unknown>) = FunctionAddress[constructor_only] :
97649764
# 1825| r1825_5(int) = Constant[1] :
97659765
# 1825| v1825_6(void) = Call[constructor_only] : func:r1825_4, this:r1825_3, 0:r1825_5
@@ -9773,7 +9773,7 @@ ir.cpp:
97739773
# 1827| Block 0
97749774
# 1827| v1827_1(void) = EnterFunction :
97759775
# 1827| mu1827_2(unknown) = AliasedDefinition :
9776-
# 1827| r1827_3(glval<constructor_only>) = VariableAddress :
9776+
# 1827| r1827_3(glval<constructor_only>) = VariableAddress[global_5] :
97779777
# 1827| r1827_4(glval<unknown>) = FunctionAddress[constructor_only] :
97789778
# 1827| r1827_5(int) = Constant[2] :
97799779
# 1827| v1827_6(void) = Call[constructor_only] : func:r1827_4, this:r1827_3, 0:r1827_5
@@ -9787,11 +9787,11 @@ ir.cpp:
97879787
# 1829| Block 0
97889788
# 1829| v1829_1(void) = EnterFunction :
97899789
# 1829| mu1829_2(unknown) = AliasedDefinition :
9790-
# 1829| r1829_3(glval<char *>) = VariableAddress :
9790+
# 1829| r1829_3(glval<char *>) = VariableAddress[global_string] :
97919791
# 1829| r1829_4(glval<char[14]>) = StringConstant["global string"] :
97929792
# 1829| r1829_5(char *) = Convert : r1829_4
97939793
# 1829| r1829_6(char *) = Convert : r1829_5
9794-
# 1829| mu1829_7(char *) = Store[?] : &:r1829_3, r1829_6
9794+
# 1829| mu1829_7(char *) = Store[global_string] : &:r1829_3, r1829_6
97959795
# 1829| v1829_8(void) = ReturnVoid :
97969796
# 1829| v1829_9(void) = AliasedUse : ~m?
97979797
# 1829| v1829_10(void) = ExitFunction :
@@ -10019,31 +10019,31 @@ smart_ptr.cpp:
1001910019
struct_init.cpp:
1002010020
# 9| Info infos_in_file[]
1002110021
# 9| Block 0
10022-
# 9| v9_1(void) = EnterFunction :
10023-
# 9| mu9_2(unknown) = AliasedDefinition :
10024-
# 9| r9_3(glval<Info[]>) = VariableAddress :
10025-
# 9| r9_4(int) = Constant[0] :
10026-
# 9| r9_5(glval<Info>) = PointerAdd[16] : r9_3, r9_4
10027-
# 10| r10_1(glval<char *>) = FieldAddress[name] : r9_5
10028-
# 10| r10_2(glval<char[2]>) = StringConstant["1"] :
10029-
# 10| r10_3(char *) = Convert : r10_2
10030-
# 10| mu10_4(char *) = Store[?] : &:r10_1, r10_3
10031-
# 10| r10_5(glval<..(*)(..)>) = FieldAddress[handler] : r9_5
10032-
# 10| r10_6(..(*)(..)) = FunctionAddress[handler1] :
10033-
# 10| mu10_7(..(*)(..)) = Store[?] : &:r10_5, r10_6
10034-
# 9| r9_6(int) = Constant[1] :
10035-
# 9| r9_7(glval<Info>) = PointerAdd[16] : r9_3, r9_6
10036-
# 11| r11_1(glval<char *>) = FieldAddress[name] : r9_7
10037-
# 11| r11_2(glval<char[2]>) = StringConstant["3"] :
10038-
# 11| r11_3(char *) = Convert : r11_2
10039-
# 11| mu11_4(char *) = Store[?] : &:r11_1, r11_3
10040-
# 11| r11_5(glval<..(*)(..)>) = FieldAddress[handler] : r9_7
10041-
# 11| r11_6(glval<..()(..)>) = FunctionAddress[handler2] :
10042-
# 11| r11_7(..(*)(..)) = CopyValue : r11_6
10043-
# 11| mu11_8(..(*)(..)) = Store[?] : &:r11_5, r11_7
10044-
# 9| v9_8(void) = ReturnVoid :
10045-
# 9| v9_9(void) = AliasedUse : ~m?
10046-
# 9| v9_10(void) = ExitFunction :
10022+
# 9| v9_1(void) = EnterFunction :
10023+
# 9| mu9_2(unknown) = AliasedDefinition :
10024+
# 9| r9_3(glval<Info[]>) = VariableAddress[infos_in_file] :
10025+
# 9| r9_4(int) = Constant[0] :
10026+
# 9| r9_5(glval<Info>) = PointerAdd[16] : r9_3, r9_4
10027+
# 10| r10_1(glval<char *>) = FieldAddress[name] : r9_5
10028+
# 10| r10_2(glval<char[2]>) = StringConstant["1"] :
10029+
# 10| r10_3(char *) = Convert : r10_2
10030+
# 10| mu10_4(char *) = Store[?] : &:r10_1, r10_3
10031+
# 10| r10_5(glval<..(*)(..)>) = FieldAddress[handler] : r9_5
10032+
# 10| r10_6(..(*)(..)) = FunctionAddress[handler1] :
10033+
# 10| mu10_7(..(*)(..)) = Store[?] : &:r10_5, r10_6
10034+
# 9| r9_6(int) = Constant[1] :
10035+
# 9| r9_7(glval<Info>) = PointerAdd[16] : r9_3, r9_6
10036+
# 11| r11_1(glval<char *>) = FieldAddress[name] : r9_7
10037+
# 11| r11_2(glval<char[2]>) = StringConstant["3"] :
10038+
# 11| r11_3(char *) = Convert : r11_2
10039+
# 11| mu11_4(char *) = Store[?] : &:r11_1, r11_3
10040+
# 11| r11_5(glval<..(*)(..)>) = FieldAddress[handler] : r9_7
10041+
# 11| r11_6(glval<..()(..)>) = FunctionAddress[handler2] :
10042+
# 11| r11_7(..(*)(..)) = CopyValue : r11_6
10043+
# 11| mu11_8(..(*)(..)) = Store[?] : &:r11_5, r11_7
10044+
# 9| v9_8(void) = ReturnVoid :
10045+
# 9| v9_9(void) = AliasedUse : ~m?
10046+
# 9| v9_10(void) = ExitFunction :
1004710047

1004810048
# 16| void let_info_escape(Info*)
1004910049
# 16| Block 0

cpp/ql/test/library-tests/ir/ir/unaliased_ssa_consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ invalidOverlap
2323
nonUniqueEnclosingIRFunction
2424
fieldAddressOnNonPointer
2525
thisArgumentIsNonPointer
26+
nonUniqueIRVariable
2627
missingCanonicalLanguageType
2728
multipleCanonicalLanguageTypes
2829
missingIRType

cpp/ql/test/library-tests/ir/ir/unaliased_ssa_consistency_unsound.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ invalidOverlap
2323
nonUniqueEnclosingIRFunction
2424
fieldAddressOnNonPointer
2525
thisArgumentIsNonPointer
26+
nonUniqueIRVariable
2627
missingCanonicalLanguageType
2728
multipleCanonicalLanguageTypes
2829
missingIRType

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ invalidOverlap
2323
nonUniqueEnclosingIRFunction
2424
fieldAddressOnNonPointer
2525
thisArgumentIsNonPointer
26+
nonUniqueIRVariable
2627
missingCanonicalLanguageType
2728
multipleCanonicalLanguageTypes
2829
missingIRType

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_consistency_unsound.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ invalidOverlap
2323
nonUniqueEnclosingIRFunction
2424
fieldAddressOnNonPointer
2525
thisArgumentIsNonPointer
26+
nonUniqueIRVariable
2627
missingCanonicalLanguageType
2728
multipleCanonicalLanguageTypes
2829
missingIRType

0 commit comments

Comments
 (0)