Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a36c6f2

Browse files
author
Robert Marsh
committed
C++: restrict IR generation to global vars w inits
1 parent c27dfb5 commit a36c6f2

8 files changed

Lines changed: 35 additions & 49 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ newtype TTranslatedElement =
672672
} or
673673
// The side effect that initializes newly-allocated memory.
674674
TTranslatedAllocationSideEffect(AllocationExpr expr) { not ignoreSideEffects(expr) } or
675-
TTranslatedGlobalOrNamespaceVarInit(GlobalOrNamespaceVariable var) { any() }
675+
TTranslatedGlobalOrNamespaceVarInit(GlobalOrNamespaceVariable var) { var.hasInitializer() }
676676

677677
/**
678678
* Gets the index of the first explicitly initialized element in `initList`

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ missingOperandType
1010
duplicateChiOperand
1111
sideEffectWithoutPrimary
1212
instructionWithoutSuccessor
13-
| clang.cpp:3:5:3:13 | VariableAddress: globalInt | Instruction 'VariableAddress: globalInt' has no successors in function '$@'. | clang.cpp:3:5:3:13 | int globalInt | int globalInt |
14-
| ir.cpp:346:5:346:5 | VariableAddress: g | Instruction 'VariableAddress: g' has no successors in function '$@'. | ir.cpp:346:5:346:5 | int g | int g |
15-
| ir.cpp:1672:5:1672:12 | VariableAddress: global_1 | Instruction 'VariableAddress: global_1' has no successors in function '$@'. | ir.cpp:1672:5:1672:12 | int global_1 | int global_1 |
16-
| struct_init.cpp:14:7:14:20 | VariableAddress: global_pointer | Instruction 'VariableAddress: global_pointer' has no successors in function '$@'. | struct_init.cpp:14:7:14:20 | Info* global_pointer | Info* global_pointer |
1713
ambiguousSuccessors
1814
unexplainedLoop
1915
unnecessaryPhiInstruction

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ missingOperandType
1010
duplicateChiOperand
1111
sideEffectWithoutPrimary
1212
instructionWithoutSuccessor
13-
| clang.cpp:3:5:3:13 | VariableAddress: globalInt | Instruction 'VariableAddress: globalInt' has no successors in function '$@'. | clang.cpp:3:5:3:13 | int globalInt | int globalInt |
14-
| ir.cpp:346:5:346:5 | VariableAddress: g | Instruction 'VariableAddress: g' has no successors in function '$@'. | ir.cpp:346:5:346:5 | int g | int g |
15-
| ir.cpp:1672:5:1672:12 | VariableAddress: global_1 | Instruction 'VariableAddress: global_1' has no successors in function '$@'. | ir.cpp:1672:5:1672:12 | int global_1 | int global_1 |
16-
| struct_init.cpp:14:7:14:20 | VariableAddress: global_pointer | Instruction 'VariableAddress: global_pointer' has no successors in function '$@'. | struct_init.cpp:14:7:14:20 | Info* global_pointer | Info* global_pointer |
1713
ambiguousSuccessors
1814
unexplainedLoop
1915
unnecessaryPhiInstruction

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4658,7 +4658,15 @@
46584658
| ir.cpp:1034:6:1034:20 | ChiTotal | total:m1034_2 |
46594659
| ir.cpp:1034:6:1034:20 | SideEffect | m1034_3 |
46604660
| ir.cpp:1035:15:1035:15 | Address | &:r1035_1 |
4661+
| ir.cpp:1038:6:1038:8 | Address | &:r1038_2 |
4662+
| ir.cpp:1038:12:1038:18 | Address | &:r1038_3 |
4663+
| ir.cpp:1038:12:1038:18 | Address | &:r1038_3 |
4664+
| ir.cpp:1038:12:1038:18 | ChiPartial | partial:m1038_4 |
4665+
| ir.cpp:1038:12:1038:18 | ChiPartial | partial:m1038_7 |
4666+
| ir.cpp:1038:12:1038:18 | ChiTotal | total:m1038_5 |
46614667
| ir.cpp:1038:12:1038:18 | ChiTotal | total:~m? |
4668+
| ir.cpp:1038:12:1038:18 | Load | ~m1038_5 |
4669+
| ir.cpp:1038:12:1038:18 | StoreValue | r1038_6 |
46624670
| ir.cpp:1038:14:1038:14 | Address | &:r1038_5 |
46634671
| ir.cpp:1038:14:1038:14 | Address | &:r1038_5 |
46644672
| ir.cpp:1038:14:1038:14 | Address | &:r1038_5 |
@@ -7437,8 +7445,14 @@
74377445
| ir.cpp:1668:17:1668:17 | Load | m1661_14 |
74387446
| ir.cpp:1668:17:1668:17 | Load | ~m1666_6 |
74397447
| ir.cpp:1668:17:1668:17 | StoreValue | r1668_4 |
7448+
| ir.cpp:1674:5:1674:12 | Address | &:r1674_2 |
7449+
| ir.cpp:1674:16:1674:16 | ChiPartial | partial:m1674_4 |
74407450
| ir.cpp:1674:16:1674:16 | ChiTotal | total:~m? |
7451+
| ir.cpp:1674:16:1674:16 | StoreValue | r1674_3 |
7452+
| ir.cpp:1676:11:1676:18 | Address | &:r1676_2 |
7453+
| ir.cpp:1676:22:1676:22 | ChiPartial | partial:m1676_4 |
74417454
| ir.cpp:1676:22:1676:22 | ChiTotal | total:~m? |
7455+
| ir.cpp:1676:22:1676:22 | StoreValue | r1676_3 |
74427456
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
74437457
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
74447458
| perf-regression.cpp:6:3:6:5 | Address | &:r6_7 |
@@ -7682,7 +7696,27 @@
76827696
| smart_ptr.cpp:47:43:47:63 | SideEffect | ~m47_16 |
76837697
| smart_ptr.cpp:47:43:47:63 | Unary | r47_5 |
76847698
| smart_ptr.cpp:47:43:47:63 | Unary | r47_6 |
7699+
| struct_init.cpp:9:13:9:25 | Left | r9_2 |
7700+
| struct_init.cpp:9:13:9:25 | Left | r9_2 |
7701+
| struct_init.cpp:10:5:10:21 | Address | &:r10_1 |
7702+
| struct_init.cpp:10:5:10:21 | Address | &:r10_6 |
7703+
| struct_init.cpp:10:7:10:9 | ChiPartial | partial:m10_4 |
76857704
| struct_init.cpp:10:7:10:9 | ChiTotal | total:~m? |
7705+
| struct_init.cpp:10:7:10:9 | StoreValue | r10_3 |
7706+
| struct_init.cpp:10:7:10:9 | Unary | r10_2 |
7707+
| struct_init.cpp:10:12:10:19 | ChiPartial | partial:m10_8 |
7708+
| struct_init.cpp:10:12:10:19 | ChiTotal | total:m10_5 |
7709+
| struct_init.cpp:10:12:10:19 | StoreValue | r10_7 |
7710+
| struct_init.cpp:11:5:11:22 | Address | &:r11_1 |
7711+
| struct_init.cpp:11:5:11:22 | Address | &:r11_6 |
7712+
| struct_init.cpp:11:7:11:9 | ChiPartial | partial:m11_4 |
7713+
| struct_init.cpp:11:7:11:9 | ChiTotal | total:m10_9 |
7714+
| struct_init.cpp:11:7:11:9 | StoreValue | r11_3 |
7715+
| struct_init.cpp:11:7:11:9 | Unary | r11_2 |
7716+
| struct_init.cpp:11:12:11:20 | ChiPartial | partial:m11_9 |
7717+
| struct_init.cpp:11:12:11:20 | ChiTotal | total:m11_5 |
7718+
| struct_init.cpp:11:12:11:20 | StoreValue | r11_8 |
7719+
| struct_init.cpp:11:13:11:20 | Unary | r11_7 |
76867720
| struct_init.cpp:16:6:16:20 | ChiPartial | partial:m16_3 |
76877721
| struct_init.cpp:16:6:16:20 | ChiTotal | total:m16_2 |
76887722
| struct_init.cpp:16:6:16:20 | SideEffect | ~m17_5 |

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
| ../../../include/memory.h:68:25:68:33 | CopyValue: (reference to) | Instruction 'CopyValue: (reference to)' has no successors in function '$@'. | ../../../include/memory.h:67:5:67:5 | void std::unique_ptr<int, std::default_delete<int>>::~unique_ptr() | void std::unique_ptr<int, std::default_delete<int>>::~unique_ptr() |
10-
| clang.cpp:3:5:3:13 | VariableAddress: globalInt | Instruction 'VariableAddress: globalInt' has no successors in function '$@'. | clang.cpp:3:5:3:13 | int globalInt | int globalInt |
11-
| ir.cpp:346:5:346:5 | VariableAddress: g | Instruction 'VariableAddress: g' has no successors in function '$@'. | ir.cpp:346:5:346:5 | int g | int g |
12-
| ir.cpp:1672:5:1672:12 | VariableAddress: global_1 | Instruction 'VariableAddress: global_1' has no successors in function '$@'. | ir.cpp:1672:5:1672:12 | int global_1 | int global_1 |
13-
| struct_init.cpp:14:7:14:20 | VariableAddress: global_pointer | Instruction 'VariableAddress: global_pointer' has no successors in function '$@'. | struct_init.cpp:14:7:14:20 | Info* global_pointer | Info* global_pointer |
1410
ambiguousSuccessors
1511
unexplainedLoop
1612
unnecessaryPhiInstruction

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ bad_asts.cpp:
108108

109109
clang.cpp:
110110
# 3| int globalInt
111-
# 3| Block 0
112-
# 3| v3_1(void) = EnterFunction :
113-
# 3| r3_2(glval<int>) = VariableAddress[globalInt] :
114-
115-
# 3| Block 1
116-
# 3| v3_3(void) = ReturnVoid :
117-
# 3| v3_4(void) = ExitFunction :
118111

119112
# 5| int* globalIntAddress()
120113
# 5| Block 0
@@ -2202,13 +2195,6 @@ ir.cpp:
22022195
# 341| v341_12(void) = ExitFunction :
22032196

22042197
# 346| int g
2205-
# 346| Block 0
2206-
# 346| v346_1(void) = EnterFunction :
2207-
# 346| r346_2(glval<int>) = VariableAddress[g] :
2208-
2209-
# 346| Block 1
2210-
# 346| v346_3(void) = ReturnVoid :
2211-
# 346| v346_4(void) = ExitFunction :
22122198

22132199
# 348| int* AddressOf()
22142200
# 348| Block 0
@@ -8694,13 +8680,6 @@ ir.cpp:
86948680
# 1645| v1645_6(void) = ExitFunction :
86958681

86968682
# 1672| int global_1
8697-
# 1672| Block 0
8698-
# 1672| v1672_1(void) = EnterFunction :
8699-
# 1672| r1672_2(glval<int>) = VariableAddress :
8700-
8701-
# 1672| Block 1
8702-
# 1672| v1672_3(void) = ReturnVoid :
8703-
# 1672| v1672_4(void) = ExitFunction :
87048683

87058684
# 1674| int global_2
87068685
# 1674| Block 0
@@ -8964,13 +8943,6 @@ struct_init.cpp:
89648943
# 9| v9_4(void) = ExitFunction :
89658944

89668945
# 14| Info* global_pointer
8967-
# 14| Block 0
8968-
# 14| v14_1(void) = EnterFunction :
8969-
# 14| r14_2(glval<Info *>) = VariableAddress[global_pointer] :
8970-
8971-
# 14| Block 1
8972-
# 14| v14_3(void) = ReturnVoid :
8973-
# 14| v14_4(void) = ExitFunction :
89748946

89758947
# 16| void let_info_escape(Info*)
89768948
# 16| Block 0

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9-
| clang.cpp:3:5:3:13 | VariableAddress: globalInt | Instruction 'VariableAddress: globalInt' has no successors in function '$@'. | clang.cpp:3:5:3:13 | int globalInt | int globalInt |
10-
| ir.cpp:346:5:346:5 | VariableAddress: g | Instruction 'VariableAddress: g' has no successors in function '$@'. | ir.cpp:346:5:346:5 | int g | int g |
11-
| ir.cpp:1672:5:1672:12 | VariableAddress: global_1 | Instruction 'VariableAddress: global_1' has no successors in function '$@'. | ir.cpp:1672:5:1672:12 | int global_1 | int global_1 |
12-
| struct_init.cpp:14:7:14:20 | VariableAddress: global_pointer | Instruction 'VariableAddress: global_pointer' has no successors in function '$@'. | struct_init.cpp:14:7:14:20 | Info* global_pointer | Info* global_pointer |
139
ambiguousSuccessors
1410
unexplainedLoop
1511
unnecessaryPhiInstruction

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9-
| clang.cpp:3:5:3:13 | VariableAddress: globalInt | Instruction 'VariableAddress: globalInt' has no successors in function '$@'. | clang.cpp:3:5:3:13 | int globalInt | int globalInt |
10-
| ir.cpp:346:5:346:5 | VariableAddress: g | Instruction 'VariableAddress: g' has no successors in function '$@'. | ir.cpp:346:5:346:5 | int g | int g |
11-
| ir.cpp:1672:5:1672:12 | VariableAddress: global_1 | Instruction 'VariableAddress: global_1' has no successors in function '$@'. | ir.cpp:1672:5:1672:12 | int global_1 | int global_1 |
12-
| struct_init.cpp:14:7:14:20 | VariableAddress: global_pointer | Instruction 'VariableAddress: global_pointer' has no successors in function '$@'. | struct_init.cpp:14:7:14:20 | Info* global_pointer | Info* global_pointer |
139
ambiguousSuccessors
1410
unexplainedLoop
1511
unnecessaryPhiInstruction

0 commit comments

Comments
 (0)