Skip to content

Commit 3ce7c52

Browse files
committed
C++: fix IR global var init for string constants
1 parent e017998 commit 3ce7c52

File tree

9 files changed

+22
-24
lines changed

9 files changed

+22
-24
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ module Raw {
4949
}
5050

5151
cached
52-
predicate hasTempVariable(Function func, Locatable ast, TempVariableTag tag, CppType type) {
52+
predicate hasTempVariable(Declaration decl, Locatable ast, TempVariableTag tag, CppType type) {
5353
exists(TranslatedElement element |
5454
element.getAst() = ast and
55-
func = element.getFunction() and
55+
decl = element.getFunction() and
5656
element.hasTempVariable(tag, type)
5757
)
5858
}
5959

6060
cached
61-
predicate hasStringLiteral(Function func, Locatable ast, CppType type, StringLiteral literal) {
61+
predicate hasStringLiteral(Declaration decl, Locatable ast, CppType type, StringLiteral literal) {
6262
literal = ast and
63-
literal.getEnclosingFunction() = func and
63+
literal.getEnclosingDeclaration() = decl and
6464
getTypeForPRValue(literal.getType()) = type
6565
}
6666

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TranslatedGlobalOrNamespaceVarInit extends TranslatedRootElement,
2424
override Instruction getFirstInstruction() { result = this.getInstruction(EnterFunctionTag()) }
2525

2626
override TranslatedElement getChild(int n) {
27-
n = 1 and result = getTranslatedInitialization(var.getInitializer().getExpr())
27+
n = 1 and result = getTranslatedInitialization(var.getInitializer().getExpr().getFullyConverted())
2828
}
2929

3030
override predicate hasInstruction(Opcode op, InstructionTag tag, CppType type) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
| ir.cpp:1688:24:1690:5 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1683:6:1683:20 | void captured_lambda(int, int&, int&&) | void captured_lambda(int, int&, int&&) |
1010
| ir.cpp:1689:28:1689:54 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1688:46:1688:46 | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const |
11-
| ir.cpp:1709:7:1709:19 | VariableAddress: global_string | Instruction 'VariableAddress: global_string' has no successors in function '$@'. | ir.cpp:1709:7:1709:19 | char* global_string | char* global_string |
1211
ambiguousSuccessors
1312
unexplainedLoop
1413
unnecessaryPhiInstruction

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
| ir.cpp:1688:24:1690:5 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1683:6:1683:20 | void captured_lambda(int, int&, int&&) | void captured_lambda(int, int&, int&&) |
1010
| ir.cpp:1689:28:1689:54 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1688:46:1688:46 | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const |
11-
| ir.cpp:1709:7:1709:19 | VariableAddress: global_string | Instruction 'VariableAddress: global_string' has no successors in function '$@'. | ir.cpp:1709:7:1709:19 | char* global_string | char* global_string |
1211
ambiguousSuccessors
1312
unexplainedLoop
1413
unnecessaryPhiInstruction

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7753,6 +7753,13 @@
77537753
| ir.cpp:1707:28:1707:47 | ChiTotal | total:m1707_8 |
77547754
| ir.cpp:1707:28:1707:47 | SideEffect | ~m1707_2 |
77557755
| ir.cpp:1707:46:1707:46 | Arg(0) | 0:r1707_5 |
7756+
| ir.cpp:1709:7:1709:19 | Address | &:r1709_3 |
7757+
| ir.cpp:1709:7:1709:19 | SideEffect | ~m1709_8 |
7758+
| ir.cpp:1709:23:1709:37 | ChiPartial | partial:m1709_7 |
7759+
| ir.cpp:1709:23:1709:37 | ChiTotal | total:m1709_2 |
7760+
| ir.cpp:1709:23:1709:37 | StoreValue | r1709_6 |
7761+
| ir.cpp:1709:23:1709:37 | Unary | r1709_4 |
7762+
| ir.cpp:1709:23:1709:37 | Unary | r1709_5 |
77567763
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
77577764
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
77587765
| perf-regression.cpp:6:3:6:5 | Address | &:r6_7 |

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ instructionWithoutSuccessor
1515
| ir.cpp:1688:24:1690:5 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1683:6:1683:20 | void captured_lambda(int, int&, int&&) | void captured_lambda(int, int&, int&&) |
1616
| ir.cpp:1689:28:1689:54 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1688:46:1688:46 | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const |
1717
| ir.cpp:1689:28:1689:54 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1688:46:1688:46 | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const |
18-
| ir.cpp:1709:7:1709:19 | VariableAddress: global_string | Instruction 'VariableAddress: global_string' has no successors in function '$@'. | ir.cpp:1709:7:1709:19 | char* global_string | char* global_string |
19-
| ir.cpp:1709:23:1709:37 | Convert: (char *)... | Instruction 'Convert: (char *)...' has no successors in function '$@'. | ir.cpp:1709:7:1709:19 | char* global_string | char* global_string |
2018
ambiguousSuccessors
2119
unexplainedLoop
2220
unnecessaryPhiInstruction

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9070,19 +9070,16 @@ ir.cpp:
90709070

90719071
# 1709| char* global_string
90729072
# 1709| Block 0
9073-
# 1709| v1709_1(void) = EnterFunction :
9074-
# 1709| mu1709_2(unknown) = AliasedDefinition :
9075-
# 1709| r1709_3(glval<char *>) = VariableAddress :
9076-
9077-
# 1709| Block 1
9078-
# 1709| v1709_4(void) = ReturnVoid :
9079-
# 1709| v1709_5(void) = AliasedUse : ~m?
9080-
# 1709| v1709_6(void) = ExitFunction :
9081-
9082-
# 1709| Block 2
9083-
# 1709| r1709_7(glval<char[14]>) = StringConstant :
9084-
# 1709| r1709_8(char *) = Convert : r1709_7
9085-
# 1709| r1709_9(char *) = Convert : r1709_8
9073+
# 1709| v1709_1(void) = EnterFunction :
9074+
# 1709| mu1709_2(unknown) = AliasedDefinition :
9075+
# 1709| r1709_3(glval<char *>) = VariableAddress :
9076+
# 1709| r1709_4(glval<char[14]>) = StringConstant :
9077+
# 1709| r1709_5(char *) = Convert : r1709_4
9078+
# 1709| r1709_6(char *) = Convert : r1709_5
9079+
# 1709| mu1709_7(char *) = Store[?] : &:r1709_3, r1709_6
9080+
# 1709| v1709_8(void) = ReturnVoid :
9081+
# 1709| v1709_9(void) = AliasedUse : ~m?
9082+
# 1709| v1709_10(void) = ExitFunction :
90869083

90879084
perf-regression.cpp:
90889085
# 6| void Big::Big()

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
| ir.cpp:1688:24:1690:5 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1683:6:1683:20 | void captured_lambda(int, int&, int&&) | void captured_lambda(int, int&, int&&) |
1010
| ir.cpp:1689:28:1689:54 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1688:46:1688:46 | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const |
11-
| ir.cpp:1709:7:1709:19 | VariableAddress: global_string | Instruction 'VariableAddress: global_string' has no successors in function '$@'. | ir.cpp:1709:7:1709:19 | char* global_string | char* global_string |
1211
ambiguousSuccessors
1312
unexplainedLoop
1413
unnecessaryPhiInstruction

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
| ir.cpp:1688:24:1690:5 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1683:6:1683:20 | void captured_lambda(int, int&, int&&) | void captured_lambda(int, int&, int&&) |
1010
| ir.cpp:1689:28:1689:54 | FieldAddress: {...} | Instruction 'FieldAddress: {...}' has no successors in function '$@'. | ir.cpp:1688:46:1688:46 | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const | void (void captured_lambda(int, int&, int&&))::(lambda [] type at line 1688, col. 25)::operator()() const |
11-
| ir.cpp:1709:7:1709:19 | VariableAddress: global_string | Instruction 'VariableAddress: global_string' has no successors in function '$@'. | ir.cpp:1709:7:1709:19 | char* global_string | char* global_string |
1211
ambiguousSuccessors
1312
unexplainedLoop
1413
unnecessaryPhiInstruction

0 commit comments

Comments
 (0)