GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.8% 481 / 17 / 519
Functions: 95.0% 19 / 0 / 20
Branches: 57.1% 522 / 36 / 950

src/irgenerator/GenExpressions.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "IRGenerator.h"
4
5 #include <ast/ASTNodes.h>
6
7 #include <llvm/IR/Module.h>
8
9 namespace spice::compiler {
10
11 25965 std::any IRGenerator::visitAssignExpr(const AssignExprNode *node) {
12 // Visit ternary expression
13
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 25965 times.
25965 if (node->ternaryExpr)
14 return visit(node->ternaryExpr);
15
16 25965 diGenerator.setSourceLocation(node);
17
18 // Assign or compound assign operation
19
1/2
✓ Branch 5 → 6 taken 25965 times.
✗ Branch 5 → 60 not taken.
25965 if (node->op != AssignExprNode::AssignOp::OP_NONE) {
20 25965 const ExprNode *lhsNode = node->lhs;
21 25965 const ExprNode *rhsNode = node->rhs;
22
23 // Normal assignment
24
2/2
✓ Branch 6 → 7 taken 23065 times.
✓ Branch 6 → 11 taken 2900 times.
25965 if (node->op == AssignExprNode::AssignOp::OP_ASSIGN)
25
2/4
✓ Branch 7 → 8 taken 23065 times.
✗ Branch 7 → 69 not taken.
✓ Branch 8 → 9 taken 23065 times.
✗ Branch 8 → 69 not taken.
46130 return doAssignment(lhsNode, rhsNode, node);
26
27 // Compound assignment
28 // Get symbol types of left and right side
29
1/2
✓ Branch 11 → 12 taken 2900 times.
✗ Branch 11 → 85 not taken.
2900 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
30
1/2
✓ Branch 12 → 13 taken 2900 times.
✗ Branch 12 → 85 not taken.
2900 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
31
32 // Retrieve rhs
33
2/4
✓ Branch 13 → 14 taken 2900 times.
✗ Branch 13 → 72 not taken.
✓ Branch 14 → 15 taken 2900 times.
✗ Branch 14 → 70 not taken.
2900 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
34 // Retrieve lhs
35
2/4
✓ Branch 16 → 17 taken 2900 times.
✗ Branch 16 → 75 not taken.
✓ Branch 17 → 18 taken 2900 times.
✗ Branch 17 → 73 not taken.
2900 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
36
37 2900 LLVMExprResult result;
38
10/11
✓ Branch 19 → 20 taken 1971 times.
✓ Branch 19 → 22 taken 89 times.
✓ Branch 19 → 24 taken 256 times.
✓ Branch 19 → 26 taken 107 times.
✓ Branch 19 → 28 taken 45 times.
✓ Branch 19 → 30 taken 11 times.
✓ Branch 19 → 32 taken 17 times.
✓ Branch 19 → 34 taken 28 times.
✓ Branch 19 → 36 taken 28 times.
✓ Branch 19 → 38 taken 348 times.
✗ Branch 19 → 40 not taken.
2900 switch (node->op) {
39 1971 case AssignExprNode::AssignOp::OP_PLUS_EQUAL:
40
1/2
✓ Branch 20 → 21 taken 1971 times.
✗ Branch 20 → 85 not taken.
1971 result = conversionManager.getPlusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
41 1971 break;
42 89 case AssignExprNode::AssignOp::OP_MINUS_EQUAL:
43
1/2
✓ Branch 22 → 23 taken 89 times.
✗ Branch 22 → 85 not taken.
89 result = conversionManager.getMinusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
44 89 break;
45 256 case AssignExprNode::AssignOp::OP_MUL_EQUAL:
46
1/2
✓ Branch 24 → 25 taken 256 times.
✗ Branch 24 → 85 not taken.
256 result = conversionManager.getMulEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
47 256 break;
48 107 case AssignExprNode::AssignOp::OP_DIV_EQUAL:
49
1/2
✓ Branch 26 → 27 taken 107 times.
✗ Branch 26 → 85 not taken.
107 result = conversionManager.getDivEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
50 107 break;
51 45 case AssignExprNode::AssignOp::OP_REM_EQUAL:
52
1/2
✓ Branch 28 → 29 taken 45 times.
✗ Branch 28 → 85 not taken.
45 result = conversionManager.getRemEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
53 45 break;
54 11 case AssignExprNode::AssignOp::OP_SHL_EQUAL:
55
1/2
✓ Branch 30 → 31 taken 11 times.
✗ Branch 30 → 85 not taken.
11 result = conversionManager.getSHLEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
56 11 break;
57 17 case AssignExprNode::AssignOp::OP_SHR_EQUAL:
58
1/2
✓ Branch 32 → 33 taken 17 times.
✗ Branch 32 → 85 not taken.
17 result = conversionManager.getSHREqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
59 17 break;
60 28 case AssignExprNode::AssignOp::OP_AND_EQUAL:
61
1/2
✓ Branch 34 → 35 taken 28 times.
✗ Branch 34 → 85 not taken.
28 result = conversionManager.getAndEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
62 28 break;
63 28 case AssignExprNode::AssignOp::OP_OR_EQUAL:
64
1/2
✓ Branch 36 → 37 taken 28 times.
✗ Branch 36 → 85 not taken.
28 result = conversionManager.getOrEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
65 28 break;
66 348 case AssignExprNode::AssignOp::OP_XOR_EQUAL:
67
1/2
✓ Branch 38 → 39 taken 348 times.
✗ Branch 38 → 85 not taken.
348 result = conversionManager.getXorEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
68 348 break;
69 default: // GCOV_EXCL_LINE
70 throw CompilerError(UNHANDLED_BRANCH, "Assign op fall-through"); // GCOV_EXCL_LINE
71 }
72
73
1/2
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 51 taken 2900 times.
2900 if (result.ptr) { // The operation allocated more memory
74 if (lhs.entry)
75 updateAddress(lhs.entry, result.ptr);
76
2/2
✓ Branch 51 → 52 taken 2113 times.
✓ Branch 51 → 57 taken 787 times.
2900 } else if (result.value) { // The operation only updated the value
77 // Store the result
78 2113 lhs.value = result.value;
79
5/6
✓ Branch 52 → 53 taken 2061 times.
✓ Branch 52 → 55 taken 52 times.
✓ Branch 53 → 54 taken 1 time.
✓ Branch 53 → 55 taken 2060 times.
✓ Branch 56 → 57 taken 2113 times.
✗ Branch 56 → 85 not taken.
2113 insertStore(lhs.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
80 }
81
1/2
✓ Branch 57 → 58 taken 2900 times.
✗ Branch 57 → 85 not taken.
2900 return lhs;
82 }
83
84 // This is a fallthrough case -> throw an error
85 throw CompilerError(UNHANDLED_BRANCH, "AssignStmt fall-through"); // GCOV_EXCL_LINE
86 }
87
88 1825 std::any IRGenerator::visitTernaryExpr(const TernaryExprNode *node) {
89 // Check if only one operand is present -> loop through
90
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 1825 times.
1825 if (!node->falseExpr)
91 return visit(node->condition);
92
93 1825 diGenerator.setSourceLocation(node);
94
95 // It is a ternary
96 // Retrieve the condition value
97 1825 llvm::Value *condValue = resolveValue(node->condition);
98
2/2
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 1824 times.
1825 const ExprNode *trueNode = node->isShortened ? node->condition : node->trueExpr;
99 1825 const ExprNode *falseNode = node->falseExpr;
100
101 1825 llvm::Value *resultValue = nullptr;
102 1825 llvm::Value *resultPtr = nullptr;
103 1825 const SymbolTableEntry *anonymousSymbol = nullptr;
104
6/6
✓ Branch 10 → 11 taken 476 times.
✓ Branch 10 → 14 taken 1349 times.
✓ Branch 12 → 13 taken 450 times.
✓ Branch 12 → 14 taken 26 times.
✓ Branch 15 → 16 taken 450 times.
✓ Branch 15 → 21 taken 1375 times.
1825 if (trueNode->hasCompileTimeValue(manIdx) && falseNode->hasCompileTimeValue(manIdx)) {
105 // If both are constants, we can simply emit a selection instruction
106 450 llvm::Value *trueValue = resolveValue(trueNode);
107 450 llvm::Value *falseValue = resolveValue(falseNode);
108
2/4
✓ Branch 18 → 19 taken 450 times.
✗ Branch 18 → 145 not taken.
✓ Branch 19 → 20 taken 450 times.
✗ Branch 19 → 145 not taken.
450 resultValue = builder.CreateSelect(condValue, trueValue, falseValue);
109 } else {
110 // We have at least one non-constant value, use branching to not perform both sides
111
1/2
✓ Branch 21 → 22 taken 1375 times.
✗ Branch 21 → 204 not taken.
1375 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
112
2/4
✓ Branch 22 → 23 taken 1375 times.
✗ Branch 22 → 148 not taken.
✓ Branch 23 → 24 taken 1375 times.
✗ Branch 23 → 146 not taken.
1375 llvm::BasicBlock *condTrue = createBlock("cond.true." + codeLoc);
113
2/4
✓ Branch 25 → 26 taken 1375 times.
✗ Branch 25 → 151 not taken.
✓ Branch 26 → 27 taken 1375 times.
✗ Branch 26 → 149 not taken.
1375 llvm::BasicBlock *condFalse = createBlock("cond.false." + codeLoc);
114
2/4
✓ Branch 28 → 29 taken 1375 times.
✗ Branch 28 → 154 not taken.
✓ Branch 29 → 30 taken 1375 times.
✗ Branch 29 → 152 not taken.
1375 llvm::BasicBlock *condExit = createBlock("cond.exit." + codeLoc);
115
116 // Jump from original block to true or false block, depending on condition
117
1/2
✓ Branch 31 → 32 taken 1375 times.
✗ Branch 31 → 202 not taken.
1375 insertCondJump(condValue, condTrue, condFalse);
118
119 // Fill true block
120
1/2
✓ Branch 32 → 33 taken 1375 times.
✗ Branch 32 → 202 not taken.
1375 switchToBlock(condTrue);
121
1/2
✓ Branch 33 → 34 taken 1375 times.
✗ Branch 33 → 202 not taken.
1375 const QualType &resultType = node->getEvaluatedSymbolType(manIdx);
122 1375 llvm::Value *trueValue = nullptr;
123 1375 llvm::Value *truePtr = nullptr;
124
7/8
✓ Branch 34 → 35 taken 1348 times.
✓ Branch 34 → 37 taken 27 times.
✓ Branch 35 → 36 taken 1348 times.
✗ Branch 35 → 202 not taken.
✓ Branch 36 → 37 taken 13 times.
✓ Branch 36 → 38 taken 1335 times.
✓ Branch 39 → 40 taken 40 times.
✓ Branch 39 → 42 taken 1335 times.
1375 if (node->falseSideCallsCopyCtor || resultType.isRef()) { // both sides or only the false side needs copy ctor call
125
1/2
✓ Branch 40 → 41 taken 40 times.
✗ Branch 40 → 202 not taken.
40 truePtr = resolveAddress(trueNode);
126
2/2
✓ Branch 42 → 43 taken 4 times.
✓ Branch 42 → 57 taken 1331 times.
1335 } else if (node->trueSideCallsCopyCtor) { // only true side needs copy ctor call
127
1/2
✓ Branch 43 → 44 taken 4 times.
✗ Branch 43 → 202 not taken.
4 llvm::Value *originalPtr = resolveAddress(trueNode);
128 // Allocate storage for the copy using the ternary's own result type, not trueNode's own evaluated type:
129 // trueNode may be a reference (e.g. a 'const T&' parameter), whose LLVM type is just a pointer and would
130 // undersize this alloca for the struct value the copy ctor is about to write into it.
131
1/2
✓ Branch 47 → 48 taken 4 times.
✗ Branch 47 → 155 not taken.
4 truePtr = insertAlloca(resultType);
132
2/4
✓ Branch 52 → 53 taken 4 times.
✗ Branch 52 → 163 not taken.
✓ Branch 53 → 54 taken 4 times.
✗ Branch 53 → 161 not taken.
12 generateCtorOrDtorCall(truePtr, node->calledCopyCtor, {originalPtr});
133 } else { // neither true nor false side need copy ctor call
134
1/2
✓ Branch 57 → 58 taken 1331 times.
✗ Branch 57 → 202 not taken.
1331 trueValue = resolveValue(trueNode);
135 }
136 // Set the true block to the current insert point, since it could have changed in the meantime
137 1375 condTrue = builder.GetInsertBlock();
138
1/2
✓ Branch 60 → 61 taken 1375 times.
✗ Branch 60 → 202 not taken.
1375 insertJump(condExit);
139
140 // Fill false block
141
1/2
✓ Branch 61 → 62 taken 1375 times.
✗ Branch 61 → 202 not taken.
1375 switchToBlock(condFalse);
142 1375 llvm::Value *falseValue = nullptr;
143 1375 llvm::Value *falsePtr = nullptr;
144
7/8
✓ Branch 62 → 63 taken 1365 times.
✓ Branch 62 → 65 taken 10 times.
✓ Branch 63 → 64 taken 1365 times.
✗ Branch 63 → 202 not taken.
✓ Branch 64 → 65 taken 13 times.
✓ Branch 64 → 66 taken 1352 times.
✓ Branch 67 → 68 taken 23 times.
✓ Branch 67 → 70 taken 1352 times.
1375 if (node->trueSideCallsCopyCtor || resultType.isRef()) { // both sides or only the true side needs copy ctor call
145
1/2
✓ Branch 68 → 69 taken 23 times.
✗ Branch 68 → 202 not taken.
23 falsePtr = resolveAddress(falseNode);
146
2/2
✓ Branch 70 → 71 taken 21 times.
✓ Branch 70 → 85 taken 1331 times.
1352 } else if (node->falseSideCallsCopyCtor) { // only false side needs copy ctor call
147
1/2
✓ Branch 71 → 72 taken 21 times.
✗ Branch 71 → 202 not taken.
21 llvm::Value *originalPtr = resolveAddress(falseNode);
148 // See the analogous truePtr allocation above: use the ternary's result type, not falseNode's own
149 // (possibly reference-qualified) evaluated type.
150
1/2
✓ Branch 75 → 76 taken 21 times.
✗ Branch 75 → 168 not taken.
21 falsePtr = insertAlloca(resultType);
151
2/4
✓ Branch 80 → 81 taken 21 times.
✗ Branch 80 → 176 not taken.
✓ Branch 81 → 82 taken 21 times.
✗ Branch 81 → 174 not taken.
63 generateCtorOrDtorCall(falsePtr, node->calledCopyCtor, {originalPtr});
152 } else { // neither true nor false side need copy ctor call
153
1/2
✓ Branch 85 → 86 taken 1331 times.
✗ Branch 85 → 202 not taken.
1331 falseValue = resolveValue(falseNode);
154 }
155 // Set the true block to the current insert point, since it could have changed in the meantime
156 1375 condFalse = builder.GetInsertBlock();
157
1/2
✓ Branch 88 → 89 taken 1375 times.
✗ Branch 88 → 202 not taken.
1375 insertJump(condExit);
158
159 // Fill the exit block
160
1/2
✓ Branch 89 → 90 taken 1375 times.
✗ Branch 89 → 202 not taken.
1375 switchToBlock(condExit);
161
9/10
✓ Branch 90 → 91 taken 1365 times.
✓ Branch 90 → 94 taken 10 times.
✓ Branch 91 → 92 taken 1344 times.
✓ Branch 91 → 94 taken 21 times.
✓ Branch 92 → 93 taken 1344 times.
✗ Branch 92 → 202 not taken.
✓ Branch 93 → 94 taken 13 times.
✓ Branch 93 → 95 taken 1331 times.
✓ Branch 96 → 97 taken 44 times.
✓ Branch 96 → 119 taken 1331 times.
1375 if (node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor || resultType.isRef()) { // one side calls copy ctor
162
3/6
✓ Branch 97 → 98 taken 44 times.
✗ Branch 97 → 181 not taken.
✓ Branch 98 → 99 taken 44 times.
✗ Branch 98 → 181 not taken.
✓ Branch 99 → 100 taken 44 times.
✗ Branch 99 → 181 not taken.
44 llvm::PHINode *phiInst = builder.CreatePHI(builder.getPtrTy(), 2, "cond.result");
163
1/2
✓ Branch 100 → 101 taken 44 times.
✗ Branch 100 → 202 not taken.
44 phiInst->addIncoming(truePtr, condTrue);
164
1/2
✓ Branch 101 → 102 taken 44 times.
✗ Branch 101 → 202 not taken.
44 phiInst->addIncoming(falsePtr, condFalse);
165
4/4
✓ Branch 102 → 103 taken 10 times.
✓ Branch 102 → 117 taken 34 times.
✓ Branch 103 → 104 taken 6 times.
✓ Branch 103 → 117 taken 4 times.
44 if (node->trueSideCallsCopyCtor && node->falseSideCallsCopyCtor) { // both sides need copy ctor call
166
1/2
✓ Branch 107 → 108 taken 6 times.
✗ Branch 107 → 182 not taken.
6 resultPtr = insertAlloca(resultType);
167
2/4
✓ Branch 112 → 113 taken 6 times.
✗ Branch 112 → 190 not taken.
✓ Branch 113 → 114 taken 6 times.
✗ Branch 113 → 188 not taken.
18 generateCtorOrDtorCall(resultPtr, node->calledCopyCtor, {phiInst});
168 } else {
169 38 resultPtr = phiInst;
170 }
171 } else { // neither true nor false side calls copy ctor
172
1/2
✗ Branch 119 → 120 not taken.
✓ Branch 119 → 121 taken 1331 times.
1331 assert(trueValue != nullptr);
173
3/6
✓ Branch 121 → 122 taken 1331 times.
✗ Branch 121 → 195 not taken.
✓ Branch 122 → 123 taken 1331 times.
✗ Branch 122 → 195 not taken.
✓ Branch 123 → 124 taken 1331 times.
✗ Branch 123 → 195 not taken.
1331 llvm::PHINode *phiInst = builder.CreatePHI(resultType.toLLVMType(sourceFile), 2, "cond.result");
174
1/2
✓ Branch 124 → 125 taken 1331 times.
✗ Branch 124 → 202 not taken.
1331 phiInst->addIncoming(trueValue, condTrue);
175
1/2
✓ Branch 125 → 126 taken 1331 times.
✗ Branch 125 → 202 not taken.
1331 phiInst->addIncoming(falseValue, condFalse);
176 1331 resultValue = phiInst;
177 }
178
179 // If we have an anonymous symbol for this ternary expr, make sure that it has an address to reference.
180
1/2
✓ Branch 127 → 128 taken 1375 times.
✗ Branch 127 → 202 not taken.
1375 anonymousSymbol = currentScope->symbolTable.lookupAnonymous(node);
181
2/2
✓ Branch 128 → 129 taken 10 times.
✓ Branch 128 → 139 taken 1365 times.
1375 if (anonymousSymbol != nullptr) {
182
1/2
✗ Branch 129 → 130 not taken.
✓ Branch 129 → 138 taken 10 times.
10 if (!resultPtr) {
183 resultPtr = insertAlloca(anonymousSymbol->getQualType());
184 insertStore(resultValue, resultPtr);
185 }
186
1/2
✓ Branch 138 → 139 taken 10 times.
✗ Branch 138 → 202 not taken.
10 updateAddress(anonymousSymbol, resultPtr);
187 }
188 1375 }
189
190
1/2
✓ Branch 141 → 142 taken 1825 times.
✗ Branch 141 → 205 not taken.
3650 return LLVMExprResult{.value = resultValue, .ptr = resultPtr, .entry = anonymousSymbol};
191 }
192
193 2458 std::any IRGenerator::visitLogicalOrExpr(const LogicalOrExprNode *node) {
194 // Check if only one operand is present -> loop through
195
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 2458 times.
2458 if (node->operands.size() == 1)
196 return visit(node->operands.front());
197
198
1/2
✓ Branch 7 → 8 taken 2458 times.
✗ Branch 7 → 104 not taken.
2458 diGenerator.setSourceLocation(node);
199
200 // It is a logical or expression
201 // Create exit block for short-circuiting
202
1/2
✓ Branch 8 → 9 taken 2458 times.
✗ Branch 8 → 104 not taken.
2458 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
203
2/4
✓ Branch 9 → 10 taken 2458 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 2458 times.
✗ Branch 10 → 79 not taken.
2458 llvm::BasicBlock *bExit = createBlock("lor.exit." + codeLoc);
204
205 // Visit the first operand
206
1/2
✓ Branch 13 → 14 taken 2458 times.
✗ Branch 13 → 102 not taken.
2458 llvm::Value *firstOperandValue = resolveValue(node->operands.front());
207
208 // Prepare an array for value-to-block-mapping
209 2458 std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks;
210
1/2
✓ Branch 15 → 16 taken 2458 times.
✗ Branch 15 → 100 not taken.
2458 shortCircuitBlocks.reserve(node->operands.size());
211 // The first element is the first operand value with the original block
212
1/2
✓ Branch 17 → 18 taken 2458 times.
✗ Branch 17 → 82 not taken.
2458 shortCircuitBlocks.emplace_back(builder.GetInsertBlock(), firstOperandValue);
213 // Create a block for each additional operand and save it to the mapping
214
2/2
✓ Branch 31 → 19 taken 3296 times.
✓ Branch 31 → 32 taken 2458 times.
5754 for (size_t i = 1; i < node->operands.size(); i++)
215
6/12
✓ Branch 19 → 20 taken 3296 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 3296 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 3296 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 3296 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 3296 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 3296 times.
✗ Branch 24 → 83 not taken.
3296 shortCircuitBlocks.emplace_back(createBlock("lor." + std::to_string(i) + "." + codeLoc), nullptr);
216 // Create conditional jump to the exit block if the first operand was true, otherwise to the next block
217
2/4
✓ Branch 32 → 33 taken 2458 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 2458 times.
✗ Branch 33 → 100 not taken.
2458 insertCondJump(firstOperandValue, bExit, shortCircuitBlocks.at(1).first);
218
219 // Create block for each operand
220
2/2
✓ Branch 50 → 35 taken 3296 times.
✓ Branch 50 → 51 taken 2458 times.
5754 for (size_t i = 1; i < node->operands.size(); i++) {
221 // Switch to the next block
222
2/4
✓ Branch 35 → 36 taken 3296 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 3296 times.
✗ Branch 36 → 100 not taken.
3296 switchToBlock(shortCircuitBlocks.at(i).first);
223 // Evaluate operand and save the result in the mapping
224
2/4
✓ Branch 38 → 39 taken 3296 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 3296 times.
✗ Branch 39 → 100 not taken.
3296 shortCircuitBlocks.at(i).second = resolveValue(node->operands[i]);
225 // Replace the array entry with the current insert block, since the insert block could have changed in the meantime
226
1/2
✓ Branch 41 → 42 taken 3296 times.
✗ Branch 41 → 100 not taken.
3296 shortCircuitBlocks.at(i).first = builder.GetInsertBlock();
227 // Check if there are more blocks to process
228
2/2
✓ Branch 43 → 44 taken 2458 times.
✓ Branch 43 → 45 taken 838 times.
3296 if (i == node->operands.size() - 1) {
229 // Insert a simple jump to the exit block for the last block
230
1/2
✓ Branch 44 → 48 taken 2458 times.
✗ Branch 44 → 100 not taken.
2458 insertJump(bExit);
231 } else {
232 // Create conditional jump to the exit block if the first operand was true, otherwise to the next block
233
3/6
✓ Branch 45 → 46 taken 838 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 838 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 838 times.
✗ Branch 47 → 100 not taken.
838 insertCondJump(shortCircuitBlocks.at(i).second, bExit, shortCircuitBlocks.at(i + 1).first);
234 }
235 }
236
237 // Get the result with the phi node
238
1/2
✓ Branch 51 → 52 taken 2458 times.
✗ Branch 51 → 100 not taken.
2458 switchToBlock(bExit);
239
2/4
✓ Branch 52 → 53 taken 2458 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 2458 times.
✗ Branch 55 → 97 not taken.
2458 llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "lor_phi");
240
2/2
✓ Branch 72 → 58 taken 5754 times.
✓ Branch 72 → 73 taken 2458 times.
16424 for (const auto &[incomingBlock, value] : shortCircuitBlocks)
241
1/2
✓ Branch 62 → 63 taken 5754 times.
✗ Branch 62 → 98 not taken.
5754 result->addIncoming(value, incomingBlock);
242
243 // Return the result
244
1/2
✓ Branch 73 → 74 taken 2458 times.
✗ Branch 73 → 99 not taken.
2458 return LLVMExprResult{.value = result};
245 2458 }
246
247 1521 std::any IRGenerator::visitLogicalAndExpr(const LogicalAndExprNode *node) {
248 // Check if only one operand is present -> loop through
249
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 1521 times.
1521 if (node->operands.size() == 1)
250 return visit(node->operands.front());
251
252
1/2
✓ Branch 7 → 8 taken 1521 times.
✗ Branch 7 → 104 not taken.
1521 diGenerator.setSourceLocation(node);
253
254 // It is a logical and expression
255 // Create exit block for short-circuiting
256
1/2
✓ Branch 8 → 9 taken 1521 times.
✗ Branch 8 → 104 not taken.
1521 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
257
2/4
✓ Branch 9 → 10 taken 1521 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 1521 times.
✗ Branch 10 → 79 not taken.
1521 llvm::BasicBlock *bExit = createBlock("land.exit." + codeLoc);
258
259 // Visit the first operand
260
1/2
✓ Branch 13 → 14 taken 1521 times.
✗ Branch 13 → 102 not taken.
1521 llvm::Value *firstOperandValue = resolveValue(node->operands.front());
261
262 // Prepare an array for value-to-block-mapping
263 1521 std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks;
264
1/2
✓ Branch 15 → 16 taken 1521 times.
✗ Branch 15 → 100 not taken.
1521 shortCircuitBlocks.reserve(node->operands.size());
265 // The first element is the first operand value with the original block
266
1/2
✓ Branch 17 → 18 taken 1521 times.
✗ Branch 17 → 82 not taken.
1521 shortCircuitBlocks.emplace_back(builder.GetInsertBlock(), firstOperandValue);
267 // Create a block for each additional operand and save it to the mapping
268
2/2
✓ Branch 31 → 19 taken 2021 times.
✓ Branch 31 → 32 taken 1521 times.
3542 for (size_t i = 1; i < node->operands.size(); i++)
269
6/12
✓ Branch 19 → 20 taken 2021 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 2021 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 2021 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 2021 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 2021 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 2021 times.
✗ Branch 24 → 83 not taken.
2021 shortCircuitBlocks.emplace_back(createBlock("land." + std::to_string(i) + "." + codeLoc), nullptr);
270 // Create conditional jump to the exit block if the first operand was true, otherwise to the next block
271
2/4
✓ Branch 32 → 33 taken 1521 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 1521 times.
✗ Branch 33 → 100 not taken.
1521 insertCondJump(firstOperandValue, shortCircuitBlocks.at(1).first, bExit);
272
273 // Create block for each operand
274
2/2
✓ Branch 50 → 35 taken 2021 times.
✓ Branch 50 → 51 taken 1521 times.
3542 for (size_t i = 1; i < node->operands.size(); i++) {
275 // Switch to the next block
276
2/4
✓ Branch 35 → 36 taken 2021 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 2021 times.
✗ Branch 36 → 100 not taken.
2021 switchToBlock(shortCircuitBlocks.at(i).first);
277 // Evaluate operand and save the result in the mapping
278
2/4
✓ Branch 38 → 39 taken 2021 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 2021 times.
✗ Branch 39 → 100 not taken.
2021 shortCircuitBlocks.at(i).second = resolveValue(node->operands[i]);
279 // Replace the array entry with the current insert block, since the insert block could have changed in the meantime
280
1/2
✓ Branch 41 → 42 taken 2021 times.
✗ Branch 41 → 100 not taken.
2021 shortCircuitBlocks.at(i).first = builder.GetInsertBlock();
281 // Check if there are more blocks to process
282
2/2
✓ Branch 43 → 44 taken 1521 times.
✓ Branch 43 → 45 taken 500 times.
2021 if (i == node->operands.size() - 1) {
283 // Insert a simple jump to the exit block for the last block
284
1/2
✓ Branch 44 → 48 taken 1521 times.
✗ Branch 44 → 100 not taken.
1521 insertJump(bExit);
285 } else {
286 // Create conditional jump to the exit block if the operand was true, otherwise to the next block
287
3/6
✓ Branch 45 → 46 taken 500 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 500 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 500 times.
✗ Branch 47 → 100 not taken.
500 insertCondJump(shortCircuitBlocks.at(i).second, shortCircuitBlocks.at(i + 1).first, bExit);
288 }
289 }
290
291 // Get the result with the phi node
292
1/2
✓ Branch 51 → 52 taken 1521 times.
✗ Branch 51 → 100 not taken.
1521 switchToBlock(bExit);
293
2/4
✓ Branch 52 → 53 taken 1521 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 1521 times.
✗ Branch 55 → 97 not taken.
1521 llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "land_phi");
294
2/2
✓ Branch 72 → 58 taken 3542 times.
✓ Branch 72 → 73 taken 1521 times.
10126 for (const auto &[incomingBlock, value] : shortCircuitBlocks)
295
1/2
✓ Branch 62 → 63 taken 3542 times.
✗ Branch 62 → 98 not taken.
3542 result->addIncoming(value, incomingBlock);
296
297 // Return the result
298
1/2
✓ Branch 73 → 74 taken 1521 times.
✗ Branch 73 → 99 not taken.
1521 return LLVMExprResult{.value = result};
299 1521 }
300
301 380 std::any IRGenerator::visitBitwiseOrExpr(const BitwiseOrExprNode *node) {
302 // Check if only one operand is present -> loop through
303
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 380 times.
380 if (node->operands.size() == 1)
304 return visit(node->operands.front());
305
306
1/2
✓ Branch 7 → 8 taken 380 times.
✗ Branch 7 → 34 not taken.
380 diGenerator.setSourceLocation(node);
307
308 // It is a bitwise or expression
309 // Evaluate first operand
310 380 const ExprNode *lhsNode = node->operands.front();
311
1/2
✓ Branch 9 → 10 taken 380 times.
✗ Branch 9 → 34 not taken.
380 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
312
2/4
✓ Branch 10 → 11 taken 380 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 380 times.
✗ Branch 11 → 27 not taken.
380 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
313
314 // Evaluate all additional operands
315
2/2
✓ Branch 22 → 14 taken 381 times.
✓ Branch 22 → 23 taken 380 times.
761 for (size_t i = 1; i < node->operands.size(); i++) {
316 // Evaluate the operand
317 381 const ExprNode *rhsNode = node->operands[i];
318
1/2
✓ Branch 15 → 16 taken 381 times.
✗ Branch 15 → 33 not taken.
381 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
319
2/4
✓ Branch 16 → 17 taken 381 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 381 times.
✗ Branch 17 → 30 not taken.
381 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
320
1/2
✓ Branch 19 → 20 taken 381 times.
✗ Branch 19 → 33 not taken.
381 result = conversionManager.getBitwiseOrInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
321 }
322
323 // Return result
324
1/2
✓ Branch 23 → 24 taken 380 times.
✗ Branch 23 → 34 not taken.
380 return result;
325 }
326
327 73 std::any IRGenerator::visitBitwiseXorExpr(const BitwiseXorExprNode *node) {
328 // Check if only one operand is present -> loop through
329
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 73 times.
73 if (node->operands.size() == 1)
330 return visit(node->operands.front());
331
332
1/2
✓ Branch 7 → 8 taken 73 times.
✗ Branch 7 → 34 not taken.
73 diGenerator.setSourceLocation(node);
333
334 // It is a bitwise xor expression
335 // Evaluate first operand
336 73 const ExprNode *lhsNode = node->operands.front();
337
1/2
✓ Branch 9 → 10 taken 73 times.
✗ Branch 9 → 34 not taken.
73 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
338
2/4
✓ Branch 10 → 11 taken 73 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 73 times.
✗ Branch 11 → 27 not taken.
73 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
339
340 // Evaluate all additional operands
341
2/2
✓ Branch 22 → 14 taken 74 times.
✓ Branch 22 → 23 taken 73 times.
147 for (size_t i = 1; i < node->operands.size(); i++) {
342 // Evaluate the operand
343 74 const ExprNode *rhsNode = node->operands[i];
344
1/2
✓ Branch 15 → 16 taken 74 times.
✗ Branch 15 → 33 not taken.
74 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
345
2/4
✓ Branch 16 → 17 taken 74 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 74 times.
✗ Branch 17 → 30 not taken.
74 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
346
1/2
✓ Branch 19 → 20 taken 74 times.
✗ Branch 19 → 33 not taken.
74 result = conversionManager.getBitwiseXorInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
347 }
348
349 // Return result
350
1/2
✓ Branch 23 → 24 taken 73 times.
✗ Branch 23 → 34 not taken.
73 return result;
351 }
352
353 337 std::any IRGenerator::visitBitwiseAndExpr(const BitwiseAndExprNode *node) {
354 // Check if only one operand is present -> loop through
355
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 337 times.
337 if (node->operands.size() == 1)
356 return visit(node->operands.front());
357
358
1/2
✓ Branch 7 → 8 taken 337 times.
✗ Branch 7 → 34 not taken.
337 diGenerator.setSourceLocation(node);
359
360 // It is a bitwise and expression
361 // Evaluate first operand
362 337 const ExprNode *lhsNode = node->operands.front();
363
1/2
✓ Branch 9 → 10 taken 337 times.
✗ Branch 9 → 34 not taken.
337 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
364
2/4
✓ Branch 10 → 11 taken 337 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 337 times.
✗ Branch 11 → 27 not taken.
337 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
365
366 // Evaluate all additional operands
367
2/2
✓ Branch 22 → 14 taken 338 times.
✓ Branch 22 → 23 taken 337 times.
675 for (size_t i = 1; i < node->operands.size(); i++) {
368 // Evaluate the operand
369 338 const ExprNode *rhsNode = node->operands[i];
370
1/2
✓ Branch 15 → 16 taken 338 times.
✗ Branch 15 → 33 not taken.
338 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
371
2/4
✓ Branch 16 → 17 taken 338 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 338 times.
✗ Branch 17 → 30 not taken.
338 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
372
1/2
✓ Branch 19 → 20 taken 338 times.
✗ Branch 19 → 33 not taken.
338 result = conversionManager.getBitwiseAndInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
373 }
374
375 // Return result
376
1/2
✓ Branch 23 → 24 taken 337 times.
✗ Branch 23 → 34 not taken.
337 return result;
377 }
378
379 22247 std::any IRGenerator::visitEqualityExpr(const EqualityExprNode *node) {
380 // Check if only one operand is present -> loop through
381
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 22247 times.
22247 if (node->operands.size() == 1)
382 return visit(node->operands.front());
383
384
1/2
✓ Branch 7 → 8 taken 22247 times.
✗ Branch 7 → 50 not taken.
22247 diGenerator.setSourceLocation(node);
385
386 // It is an equality expression
387 // Evaluate lhs
388 22247 const ExprNode *lhsNode = node->operands[0];
389
1/2
✓ Branch 9 → 10 taken 22247 times.
✗ Branch 9 → 50 not taken.
22247 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
390
2/4
✓ Branch 10 → 11 taken 22247 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 22247 times.
✗ Branch 11 → 35 not taken.
22247 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
391
392 // Evaluate rhs
393 22247 const ExprNode *rhsNode = node->operands[1];
394
1/2
✓ Branch 14 → 15 taken 22247 times.
✗ Branch 14 → 50 not taken.
22247 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
395
2/4
✓ Branch 15 → 16 taken 22247 times.
✗ Branch 15 → 40 not taken.
✓ Branch 16 → 17 taken 22247 times.
✗ Branch 16 → 38 not taken.
22247 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
396
397 // Retrieve the result value, based on the exact operator
398
2/3
✓ Branch 18 → 19 taken 18629 times.
✓ Branch 18 → 21 taken 3618 times.
✗ Branch 18 → 23 not taken.
22247 switch (node->op) {
399 18629 case EqualityExprNode::EqualityOp::OP_EQUAL:
400
1/2
✓ Branch 19 → 20 taken 18629 times.
✗ Branch 19 → 50 not taken.
18629 result = conversionManager.getEqualInst(node, result, lhsSTy, rhs, rhsSTy);
401 18629 break;
402 3618 case EqualityExprNode::EqualityOp::OP_NOT_EQUAL:
403
1/2
✓ Branch 21 → 22 taken 3618 times.
✗ Branch 21 → 50 not taken.
3618 result = conversionManager.getNotEqualInst(node, result, lhsSTy, rhs, rhsSTy);
404 3618 break;
405 default: // GCOV_EXCL_LINE
406 throw CompilerError(UNHANDLED_BRANCH, "EqualityExpr fall-through"); // GCOV_EXCL_LINE
407 }
408
409 // Return the result
410
1/2
✓ Branch 31 → 32 taken 22247 times.
✗ Branch 31 → 50 not taken.
22247 return result;
411 }
412
413 12751 std::any IRGenerator::visitRelationalExpr(const RelationalExprNode *node) {
414 // Check if only one operand is present -> loop through
415
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 12751 times.
12751 if (node->operands.size() == 1)
416 return visit(node->operands.front());
417
418
1/2
✓ Branch 7 → 8 taken 12751 times.
✗ Branch 7 → 54 not taken.
12751 diGenerator.setSourceLocation(node);
419
420 // It is a relational expression
421 // Evaluate lhs
422 12751 const ExprNode *lhsNode = node->operands[0];
423
1/2
✓ Branch 9 → 10 taken 12751 times.
✗ Branch 9 → 54 not taken.
12751 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
424
2/4
✓ Branch 10 → 11 taken 12751 times.
✗ Branch 10 → 41 not taken.
✓ Branch 11 → 12 taken 12751 times.
✗ Branch 11 → 39 not taken.
12751 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
425
426 // Evaluate rhs
427 12751 const ExprNode *rhsNode = node->operands[1];
428
1/2
✓ Branch 14 → 15 taken 12751 times.
✗ Branch 14 → 54 not taken.
12751 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
429
2/4
✓ Branch 15 → 16 taken 12751 times.
✗ Branch 15 → 44 not taken.
✓ Branch 16 → 17 taken 12751 times.
✗ Branch 16 → 42 not taken.
12751 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
430
431 // Retrieve the result value, based on the exact operator
432
4/5
✓ Branch 18 → 19 taken 5136 times.
✓ Branch 18 → 21 taken 2683 times.
✓ Branch 18 → 23 taken 1761 times.
✓ Branch 18 → 25 taken 3171 times.
✗ Branch 18 → 27 not taken.
12751 switch (node->op) {
433 5136 case RelationalExprNode::RelationalOp::OP_LESS:
434
1/2
✓ Branch 19 → 20 taken 5136 times.
✗ Branch 19 → 54 not taken.
5136 result = conversionManager.getLessInst(node, result, lhsSTy, rhs, rhsSTy);
435 5136 break;
436 2683 case RelationalExprNode::RelationalOp::OP_GREATER:
437
1/2
✓ Branch 21 → 22 taken 2683 times.
✗ Branch 21 → 54 not taken.
2683 result = conversionManager.getGreaterInst(node, result, lhsSTy, rhs, rhsSTy);
438 2683 break;
439 1761 case RelationalExprNode::RelationalOp::OP_LESS_EQUAL:
440
1/2
✓ Branch 23 → 24 taken 1761 times.
✗ Branch 23 → 54 not taken.
1761 result = conversionManager.getLessEqualInst(node, result, lhsSTy, rhs, rhsSTy);
441 1761 break;
442 3171 case RelationalExprNode::RelationalOp::OP_GREATER_EQUAL:
443
1/2
✓ Branch 25 → 26 taken 3171 times.
✗ Branch 25 → 54 not taken.
3171 result = conversionManager.getGreaterEqualInst(node, result, lhsSTy, rhs, rhsSTy);
444 3171 break;
445 default: // GCOV_EXCL_LINE
446 throw CompilerError(UNHANDLED_BRANCH, "EqualityExpr fall-through"); // GCOV_EXCL_LINE
447 }
448
449 // Return the result
450
1/2
✓ Branch 35 → 36 taken 12751 times.
✗ Branch 35 → 54 not taken.
12751 return result;
451 }
452
453 1715 std::any IRGenerator::visitShiftExpr(const ShiftExprNode *node) {
454 // Check if only one operand is present -> loop through
455
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 1715 times.
1715 if (node->operands.size() == 1)
456 return visit(node->operands.front());
457
458
1/2
✓ Branch 7 → 8 taken 1715 times.
✗ Branch 7 → 64 not taken.
1715 diGenerator.setSourceLocation(node);
459
460 // It is a shift expression
461 // Evaluate first operand
462 1715 const ExprNode *lhsNode = node->operands.front();
463
1/2
✓ Branch 9 → 10 taken 1715 times.
✗ Branch 9 → 64 not taken.
1715 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
464
2/4
✓ Branch 10 → 11 taken 1715 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 1715 times.
✗ Branch 11 → 46 not taken.
1715 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
465
466
1/2
✓ Branch 13 → 14 taken 1715 times.
✗ Branch 13 → 64 not taken.
1715 auto opQueue = node->opQueue;
467 1715 size_t operandIndex = 1;
468
2/2
✓ Branch 40 → 15 taken 2543 times.
✓ Branch 40 → 41 taken 1715 times.
4258 while (!opQueue.empty()) {
469 2543 const size_t operatorIndex = operandIndex - 1;
470 // Evaluate next operand
471 2543 const ExprNode *rhsNode = node->operands[operandIndex++];
472
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 2543 times.
2543 assert(rhsNode != nullptr);
473
1/2
✓ Branch 18 → 19 taken 2543 times.
✗ Branch 18 → 61 not taken.
2543 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
474
2/4
✓ Branch 19 → 20 taken 2543 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 2543 times.
✗ Branch 20 → 49 not taken.
2543 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
475
476 // Retrieve the result, based on the exact operator
477
2/3
✓ Branch 23 → 24 taken 2162 times.
✓ Branch 23 → 26 taken 381 times.
✗ Branch 23 → 28 not taken.
2543 switch (opQueue.front().first) {
478 2162 case ShiftExprNode::ShiftOp::OP_SHIFT_LEFT:
479
1/2
✓ Branch 24 → 25 taken 2162 times.
✗ Branch 24 → 61 not taken.
2162 lhs = conversionManager.getShiftLeftInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
480 2162 break;
481 381 case ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT:
482
1/2
✓ Branch 26 → 27 taken 381 times.
✗ Branch 26 → 61 not taken.
381 lhs = conversionManager.getShiftRightInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
483 381 break;
484 default: // GCOV_EXCL_LINE
485 throw CompilerError(UNHANDLED_BRANCH, "AdditiveExpr fall-through"); // GCOV_EXCL_LINE
486 }
487
488 // Retrieve the new lhs symbol type
489 2543 lhsSTy = opQueue.front().second;
490
491 2543 opQueue.pop();
492 }
493
494 // Return the result
495
1/2
✓ Branch 41 → 42 taken 1715 times.
✗ Branch 41 → 62 not taken.
1715 return lhs;
496 1715 }
497
498 11730 std::any IRGenerator::visitAdditiveExpr(const AdditiveExprNode *node) {
499 // Check if only one operand is present -> loop through
500
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 11730 times.
11730 if (node->operands.size() == 1)
501 return visit(node->operands.front());
502
503
1/2
✓ Branch 7 → 8 taken 11730 times.
✗ Branch 7 → 64 not taken.
11730 diGenerator.setSourceLocation(node);
504
505 // It is an additive expression
506 // Evaluate first operand
507 11730 const ExprNode *lhsNode = node->operands[0];
508
1/2
✓ Branch 9 → 10 taken 11730 times.
✗ Branch 9 → 64 not taken.
11730 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
509
2/4
✓ Branch 10 → 11 taken 11730 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 11730 times.
✗ Branch 11 → 46 not taken.
11730 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
510
511
1/2
✓ Branch 13 → 14 taken 11730 times.
✗ Branch 13 → 64 not taken.
11730 auto opQueue = node->opQueue;
512 11730 size_t operandIndex = 1;
513
2/2
✓ Branch 40 → 15 taken 13255 times.
✓ Branch 40 → 41 taken 11730 times.
24985 while (!opQueue.empty()) {
514 13255 const size_t operatorIndex = operandIndex - 1;
515 // Evaluate next operand
516 13255 const ExprNode *rhsNode = node->operands[operandIndex++];
517
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 13255 times.
13255 assert(rhsNode != nullptr);
518
1/2
✓ Branch 18 → 19 taken 13255 times.
✗ Branch 18 → 61 not taken.
13255 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
519
2/4
✓ Branch 19 → 20 taken 13255 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 13255 times.
✗ Branch 20 → 49 not taken.
13255 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
520
521 // Retrieve the result, based on the exact operator
522
2/3
✓ Branch 23 → 24 taken 8434 times.
✓ Branch 23 → 26 taken 4821 times.
✗ Branch 23 → 28 not taken.
13255 switch (opQueue.front().first) {
523 8434 case AdditiveExprNode::AdditiveOp::OP_PLUS:
524
1/2
✓ Branch 24 → 25 taken 8434 times.
✗ Branch 24 → 61 not taken.
8434 lhs = conversionManager.getPlusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
525 8434 break;
526 4821 case AdditiveExprNode::AdditiveOp::OP_MINUS:
527
1/2
✓ Branch 26 → 27 taken 4821 times.
✗ Branch 26 → 61 not taken.
4821 lhs = conversionManager.getMinusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
528 4821 break;
529 default: // GCOV_EXCL_LINE
530 throw CompilerError(UNHANDLED_BRANCH, "AdditiveExpr fall-through"); // GCOV_EXCL_LINE
531 }
532
533 // Retrieve the new lhs symbol type
534 13255 lhsSTy = opQueue.front().second;
535
536 13255 opQueue.pop();
537 }
538
539 // Return the result
540
1/2
✓ Branch 41 → 42 taken 11730 times.
✗ Branch 41 → 62 not taken.
11730 return lhs;
541 11730 }
542
543 2795 std::any IRGenerator::visitMultiplicativeExpr(const MultiplicativeExprNode *node) {
544 // Check if only one operand is present -> loop through
545
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 2795 times.
2795 if (node->operands.size() == 1)
546 return visit(node->operands.front());
547
548
1/2
✓ Branch 7 → 8 taken 2795 times.
✗ Branch 7 → 66 not taken.
2795 diGenerator.setSourceLocation(node);
549
550 // It is an additive expression
551 // Evaluate first operand
552 2795 const ExprNode *lhsNode = node->operands[0];
553
1/2
✓ Branch 9 → 10 taken 2795 times.
✗ Branch 9 → 66 not taken.
2795 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
554
2/4
✓ Branch 10 → 11 taken 2795 times.
✗ Branch 10 → 50 not taken.
✓ Branch 11 → 12 taken 2795 times.
✗ Branch 11 → 48 not taken.
2795 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
555
556
1/2
✓ Branch 13 → 14 taken 2795 times.
✗ Branch 13 → 66 not taken.
2795 auto opQueue = node->opQueue;
557 2795 size_t operandIndex = 1;
558
2/2
✓ Branch 42 → 15 taken 2914 times.
✓ Branch 42 → 43 taken 2795 times.
5709 while (!opQueue.empty()) {
559 2914 const size_t operatorIndex = operandIndex - 1;
560 // Evaluate next operand
561 2914 const ExprNode *rhsNode = node->operands[operandIndex++];
562
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 2914 times.
2914 assert(rhsNode != nullptr);
563
1/2
✓ Branch 18 → 19 taken 2914 times.
✗ Branch 18 → 63 not taken.
2914 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
564
2/4
✓ Branch 19 → 20 taken 2914 times.
✗ Branch 19 → 53 not taken.
✓ Branch 20 → 21 taken 2914 times.
✗ Branch 20 → 51 not taken.
2914 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
565
566 // Retrieve the result, based on the exact operator
567
3/4
✓ Branch 23 → 24 taken 2328 times.
✓ Branch 23 → 26 taken 474 times.
✓ Branch 23 → 28 taken 112 times.
✗ Branch 23 → 30 not taken.
2914 switch (opQueue.front().first) {
568 2328 case MultiplicativeExprNode::MultiplicativeOp::OP_MUL:
569
1/2
✓ Branch 24 → 25 taken 2328 times.
✗ Branch 24 → 63 not taken.
2328 result = conversionManager.getMulInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex);
570 2328 break;
571 474 case MultiplicativeExprNode::MultiplicativeOp::OP_DIV:
572
1/2
✓ Branch 26 → 27 taken 474 times.
✗ Branch 26 → 63 not taken.
474 result = conversionManager.getDivInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex);
573 474 break;
574 112 case MultiplicativeExprNode::MultiplicativeOp::OP_REM:
575
1/2
✓ Branch 28 → 29 taken 112 times.
✗ Branch 28 → 63 not taken.
112 result = conversionManager.getRemInst(node, result, lhsSTy, rhs, rhsSTy);
576 112 break;
577 default: // GCOV_EXCL_LINE
578 throw CompilerError(UNHANDLED_BRANCH, "MultiplicativeExpr fall-through"); // GCOV_EXCL_LINE
579 }
580
581 // Retrieve the new lhs symbol type
582 2914 lhsSTy = opQueue.front().second;
583 2914 opQueue.pop();
584 }
585
586 // Return the result
587
1/2
✓ Branch 43 → 44 taken 2795 times.
✗ Branch 43 → 64 not taken.
2795 return result;
588 2795 }
589
590 10595 std::any IRGenerator::visitCastExpr(const CastExprNode *node) {
591 // Check if only one operand is present -> loop through
592
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 10595 times.
10595 if (!node->isCast)
593 return visit(node->prefixUnaryExpr);
594
595
1/2
✓ Branch 5 → 6 taken 10595 times.
✗ Branch 5 → 19 not taken.
10595 diGenerator.setSourceLocation(node);
596
597 // It is a cast expression
598 // Retrieve target symbol type
599
1/2
✓ Branch 6 → 7 taken 10595 times.
✗ Branch 6 → 19 not taken.
10595 const QualType targetSTy = node->getEvaluatedSymbolType(manIdx);
600
601 // Evaluate rhs
602 10595 const ExprNode *rhsNode = node->assignExpr;
603
1/2
✓ Branch 7 → 8 taken 10595 times.
✗ Branch 7 → 19 not taken.
10595 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
604
2/4
✓ Branch 8 → 9 taken 10595 times.
✗ Branch 8 → 18 not taken.
✓ Branch 9 → 10 taken 10595 times.
✗ Branch 9 → 16 not taken.
10595 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
605
606 // Retrieve the result value
607
1/2
✓ Branch 11 → 12 taken 10595 times.
✗ Branch 11 → 19 not taken.
10595 const LLVMExprResult result = conversionManager.getCastInst(node, targetSTy, rhs, rhsSTy);
608
609 // Return the result
610
1/2
✓ Branch 12 → 13 taken 10595 times.
✗ Branch 12 → 19 not taken.
10595 return result;
611 }
612
613 7314 std::any IRGenerator::visitPrefixUnaryExpr(const PrefixUnaryExprNode *node) {
614 // If no operator is applied, simply visit the atomic expression
615
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 7314 times.
7314 if (node->op == PrefixUnaryExprNode::PrefixUnaryOp::OP_NONE)
616 return visit(node->postfixUnaryExpr);
617
618
1/2
✓ Branch 5 → 6 taken 7314 times.
✗ Branch 5 → 117 not taken.
7314 diGenerator.setSourceLocation(node);
619
620 // Evaluate lhs
621 7314 const ExprNode *lhsNode = node->prefixUnaryExpr;
622
1/2
✓ Branch 6 → 7 taken 7314 times.
✗ Branch 6 → 117 not taken.
7314 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
623
2/4
✓ Branch 7 → 8 taken 7314 times.
✗ Branch 7 → 87 not taken.
✓ Branch 8 → 9 taken 7314 times.
✗ Branch 8 → 85 not taken.
7314 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
624
625
7/8
✓ Branch 10 → 11 taken 1025 times.
✓ Branch 10 → 21 taken 11 times.
✓ Branch 10 → 36 taken 15 times.
✓ Branch 10 → 51 taken 4087 times.
✓ Branch 10 → 53 taken 30 times.
✓ Branch 10 → 55 taken 1000 times.
✓ Branch 10 → 64 taken 1146 times.
✗ Branch 10 → 73 not taken.
7314 switch (node->op) {
626 1025 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS: {
627 // Execute operation
628
1/2
✓ Branch 11 → 12 taken 1025 times.
✗ Branch 11 → 117 not taken.
1025 lhs = conversionManager.getPrefixMinusInst(node, lhs, lhsSTy);
629
630 // This operator can not work in-place, so we need additional memory
631
1/2
✓ Branch 16 → 17 taken 1025 times.
✗ Branch 16 → 88 not taken.
1025 lhs.ptr = insertAlloca(lhs.value->getType());
632
633 // Store the new value
634
1/2
✓ Branch 19 → 20 taken 1025 times.
✗ Branch 19 → 117 not taken.
1025 insertStore(lhs.value, lhs.ptr);
635
636 1025 break;
637 }
638 11 case PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS: {
639 // Execute operation
640
1/2
✓ Branch 21 → 22 taken 11 times.
✗ Branch 21 → 94 not taken.
11 lhs.value = conversionManager.getPrefixPlusPlusInst(node, lhs, lhsSTy).value;
641
642 // If this operation happens on a volatile variable, store the value directly
643
3/4
✓ Branch 22 → 23 taken 10 times.
✓ Branch 22 → 25 taken 1 time.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 10 times.
11 if (lhs.entry && lhs.entry->isVolatile)
644 insertStore(lhs.value, lhs.ptr, true);
645
646 // Save to the existing address if possible, otherwise (e.g. for literals) allocate new space
647
2/2
✓ Branch 25 → 26 taken 1 time.
✓ Branch 25 → 34 taken 10 times.
11 if (!lhs.ptr)
648
1/2
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 95 not taken.
1 lhs.ptr = insertAlloca(lhs.value->getType());
649
650 // Store the new value
651
1/2
✓ Branch 34 → 35 taken 11 times.
✗ Branch 34 → 117 not taken.
11 insertStore(lhs.value, lhs.ptr);
652
653 11 break;
654 }
655 15 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS: {
656 // Execute operation
657
1/2
✓ Branch 36 → 37 taken 15 times.
✗ Branch 36 → 101 not taken.
15 lhs.value = conversionManager.getPrefixMinusMinusInst(node, lhs, lhsSTy).value;
658
659 // If this operation happens on a volatile variable, store the value directly
660
3/4
✓ Branch 37 → 38 taken 14 times.
✓ Branch 37 → 40 taken 1 time.
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 14 times.
15 if (lhs.entry && lhs.entry->isVolatile)
661 insertStore(lhs.value, lhs.ptr, true);
662
663 // Save to the existing address if possible, otherwise (e.g. for literals) allocate new space
664
2/2
✓ Branch 40 → 41 taken 1 time.
✓ Branch 40 → 49 taken 14 times.
15 if (!lhs.ptr)
665
1/2
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 102 not taken.
1 lhs.ptr = insertAlloca(lhs.value->getType());
666
667 // Store the new value
668
1/2
✓ Branch 49 → 50 taken 15 times.
✗ Branch 49 → 117 not taken.
15 insertStore(lhs.value, lhs.ptr);
669
670 15 break;
671 }
672 4087 case PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT: {
673 // Execute operation
674
1/2
✓ Branch 51 → 52 taken 4087 times.
✗ Branch 51 → 117 not taken.
4087 lhs = conversionManager.getPrefixNotInst(node, lhs, lhsSTy);
675 4087 break;
676 }
677 30 case PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT: {
678 // Execute operation
679
1/2
✓ Branch 53 → 54 taken 30 times.
✗ Branch 53 → 117 not taken.
30 lhs = conversionManager.getPrefixBitwiseNotInst(node, lhs, lhsSTy);
680 30 break;
681 }
682 1000 case PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE: {
683 // If only .refPtr is filled, we can't simply rewire the fields, but need to actually perform a load.
684 // For that we can use resolveValue().
685
4/4
✓ Branch 55 → 56 taken 973 times.
✓ Branch 55 → 58 taken 27 times.
✓ Branch 56 → 57 taken 38 times.
✓ Branch 56 → 58 taken 935 times.
1000 const bool onlyRefPtrIsFilled = lhs.value == nullptr && lhs.ptr == nullptr;
686 // Rewire the fields
687
3/4
✓ Branch 59 → 60 taken 38 times.
✓ Branch 59 → 62 taken 962 times.
✓ Branch 60 → 61 taken 38 times.
✗ Branch 60 → 117 not taken.
1000 llvm::Value *newRefPtr = onlyRefPtrIsFilled ? resolveValue(lhsNode, lhs) : lhs.ptr;
688 1000 llvm::Value *newPtr = lhs.value;
689 1000 lhs = {.ptr = newPtr, .refPtr = newRefPtr};
690 1000 break;
691 }
692 1146 case PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF: {
693 // If only .value is filled, we can't simply rewire the fields, but need to actually perform alloca + store.
694 // For that we can use resolveAddress().
695
4/4
✓ Branch 64 → 65 taken 66 times.
✓ Branch 64 → 67 taken 1080 times.
✓ Branch 65 → 66 taken 2 times.
✓ Branch 65 → 67 taken 64 times.
1146 const bool onlyValueIsFilled = lhs.ptr == nullptr && lhs.refPtr == nullptr;
696 // Rewire the fields
697
3/4
✓ Branch 68 → 69 taken 2 times.
✓ Branch 68 → 71 taken 1144 times.
✓ Branch 69 → 70 taken 2 times.
✗ Branch 69 → 117 not taken.
1146 llvm::Value *newValue = onlyValueIsFilled ? resolveAddress(lhs) : lhs.ptr;
698 1146 llvm::Value *newPtr = lhs.refPtr;
699 1146 lhs = {.value = newValue, .ptr = newPtr};
700 1146 break;
701 }
702 default: // GCOV_EXCL_LINE
703 throw CompilerError(UNHANDLED_BRANCH, "PrefixUnaryExpr fall-through"); // GCOV_EXCL_LINE
704 }
705
706
1/2
✓ Branch 81 → 82 taken 7314 times.
✗ Branch 81 → 117 not taken.
7314 return lhs;
707 }
708
709 82621 std::any IRGenerator::visitPostfixUnaryExpr(const PostfixUnaryExprNode *node) {
710 // If no operator is applied, simply visit the atomic expression
711
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 82621 times.
82621 if (node->op == PostfixUnaryExprNode::PostfixUnaryOp::OP_NONE)
712 return visit(node->atomicExpr);
713
714
1/2
✓ Branch 5 → 6 taken 82621 times.
✗ Branch 5 → 244 not taken.
82621 diGenerator.setSourceLocation(node);
715
716 // Evaluate lhs
717 82621 const ExprNode *lhsNode = node->postfixUnaryExpr;
718
1/2
✓ Branch 6 → 7 taken 82621 times.
✗ Branch 6 → 244 not taken.
82621 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
719
2/4
✓ Branch 7 → 8 taken 82621 times.
✗ Branch 7 → 169 not taken.
✓ Branch 8 → 9 taken 82621 times.
✗ Branch 8 → 167 not taken.
82621 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
720
721
4/5
✓ Branch 10 → 11 taken 8437 times.
✓ Branch 10 → 62 taken 67579 times.
✓ Branch 10 → 107 taken 6055 times.
✓ Branch 10 → 131 taken 550 times.
✗ Branch 10 → 155 not taken.
82621 switch (node->op) {
722 8437 case PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT: {
723 8437 const ExprNode *indexExpr = node->subscriptIndexExpr;
724
725 // Check if we need to generate a call to an overloaded operator function
726
3/4
✓ Branch 11 → 12 taken 8437 times.
✗ Branch 11 → 205 not taken.
✓ Branch 12 → 13 taken 540 times.
✓ Branch 12 → 29 taken 7897 times.
8437 if (conversionManager.callsOverloadedOpFct(node, 0)) {
727
1/2
✓ Branch 13 → 14 taken 540 times.
✗ Branch 13 → 170 not taken.
540 ResolverFct lhsV = [&] { return resolveValue(lhsSTy, lhs); };
728 1080 ResolverFct lhsP = [&] { return resolveAddress(lhs); };
729 1057 ResolverFct idxV = [&] { return resolveValue(indexExpr); };
730 563 ResolverFct idxP = [&] { return resolveAddress(indexExpr); };
731 540 lhs = conversionManager.callOperatorOverloadFct<2>(node, {lhsV, lhsP, idxV, idxP}, 0);
732 540 break;
733 540 }
734
735
1/2
✓ Branch 29 → 30 taken 7897 times.
✗ Branch 29 → 188 not taken.
7897 lhsSTy = lhsSTy.removeReferenceWrapper();
736
737 // Get the index value
738
1/2
✓ Branch 30 → 31 taken 7897 times.
✗ Branch 30 → 205 not taken.
7897 llvm::Value *indexValue = resolveValue(indexExpr);
739 // Come up with the address
740
8/10
✓ Branch 31 → 32 taken 7897 times.
✗ Branch 31 → 205 not taken.
✓ Branch 32 → 33 taken 489 times.
✓ Branch 32 → 36 taken 7408 times.
✓ Branch 33 → 34 taken 489 times.
✗ Branch 33 → 205 not taken.
✓ Branch 34 → 35 taken 393 times.
✓ Branch 34 → 36 taken 96 times.
✓ Branch 37 → 38 taken 393 times.
✓ Branch 37 → 49 taken 7504 times.
7897 if (lhsSTy.isArray() && lhsSTy.getArraySize() != ARRAY_SIZE_UNKNOWN) { // Array
741 // Make sure the address is present
742
1/2
✓ Branch 38 → 39 taken 393 times.
✗ Branch 38 → 196 not taken.
393 resolveAddress(lhs);
743
744 // Calculate address of array item
745
1/2
✓ Branch 39 → 40 taken 393 times.
✗ Branch 39 → 196 not taken.
393 llvm::Type *lhsTy = lhsSTy.toLLVMType(sourceFile);
746
1/2
✓ Branch 40 → 41 taken 393 times.
✗ Branch 40 → 196 not taken.
393 llvm::Value *indices[2] = {builder.getInt64(0), indexValue};
747
1/2
✓ Branch 45 → 46 taken 393 times.
✗ Branch 45 → 189 not taken.
393 lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indices);
748 } else { // Pointer
749 // Now the pointer is the value
750
1/2
✓ Branch 49 → 50 taken 7504 times.
✗ Branch 49 → 205 not taken.
7504 lhs.ptr = resolveValue(lhsNode, lhs);
751
752
2/4
✓ Branch 50 → 51 taken 7504 times.
✗ Branch 50 → 197 not taken.
✓ Branch 51 → 52 taken 7504 times.
✗ Branch 51 → 197 not taken.
7504 llvm::Type *lhsTy = lhsSTy.getContained().toLLVMType(sourceFile);
753 // Calculate address of pointer item
754
1/2
✓ Branch 56 → 57 taken 7504 times.
✗ Branch 56 → 198 not taken.
7504 lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indexValue);
755 }
756
757 // Reset value and entry
758 7897 lhs.value = nullptr;
759 7897 lhs.entry = nullptr;
760 7897 break;
761 }
762 67579 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS: {
763 // Get the address of the struct instance
764
1/2
✓ Branch 62 → 63 taken 67579 times.
✗ Branch 62 → 220 not taken.
67579 resolveAddress(lhs);
765
1/2
✓ Branch 63 → 64 taken 67579 times.
✗ Branch 63 → 206 not taken.
67579 lhsSTy = lhsSTy.removeReferenceWrapper();
766
767 // Auto de-reference pointer
768
1/2
✓ Branch 64 → 65 taken 67579 times.
✗ Branch 64 → 220 not taken.
67579 autoDeReferencePtr(lhs.ptr, lhsSTy);
769
2/4
✓ Branch 65 → 66 taken 67579 times.
✗ Branch 65 → 220 not taken.
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 68 taken 67579 times.
67579 assert(lhsSTy.is(TY_STRUCT));
770
771 // Retrieve struct scope
772 67579 const std::string &fieldName = node->identifier;
773
1/2
✓ Branch 68 → 69 taken 67579 times.
✗ Branch 68 → 220 not taken.
67579 Scope *structScope = lhsSTy.getBodyScope();
774
775 // Retrieve field entry
776 67579 std::vector<size_t> indexPath;
777
1/2
✓ Branch 69 → 70 taken 67579 times.
✗ Branch 69 → 218 not taken.
67579 lhs.entry = structScope->symbolTable.lookupInComposedFields(fieldName, indexPath);
778
1/2
✗ Branch 70 → 71 not taken.
✓ Branch 70 → 72 taken 67579 times.
67579 assert(lhs.entry != nullptr);
779
1/2
✓ Branch 72 → 73 taken 67579 times.
✗ Branch 72 → 218 not taken.
67579 const QualType fieldSymbolType = lhs.entry->getQualType();
780
781 // Get address of the field in the struct instance
782
2/4
✓ Branch 73 → 74 taken 67579 times.
✗ Branch 73 → 210 not taken.
✓ Branch 76 → 77 taken 67579 times.
✗ Branch 76 → 207 not taken.
135158 std::vector<llvm::Value *> indices = {builder.getInt64(0)};
783
2/2
✓ Branch 93 → 80 taken 67625 times.
✓ Branch 93 → 94 taken 67579 times.
202783 for (const size_t index : indexPath)
784
2/4
✓ Branch 82 → 83 taken 67625 times.
✗ Branch 82 → 211 not taken.
✓ Branch 83 → 84 taken 67625 times.
✗ Branch 83 → 211 not taken.
67625 indices.push_back(builder.getInt32(index));
785
1/2
✓ Branch 94 → 95 taken 67579 times.
✗ Branch 94 → 216 not taken.
67579 const std::string name = fieldName + ".addr";
786
2/4
✓ Branch 96 → 97 taken 67579 times.
✗ Branch 96 → 213 not taken.
✓ Branch 97 → 98 taken 67579 times.
✗ Branch 97 → 213 not taken.
67579 llvm::Value *memberAddr = insertInBoundsGEP(lhsSTy.toLLVMType(sourceFile), lhs.ptr, indices, name);
787
788 // Set as ptr or refPtr, depending on the type
789
3/4
✓ Branch 98 → 99 taken 67579 times.
✗ Branch 98 → 214 not taken.
✓ Branch 99 → 100 taken 1267 times.
✓ Branch 99 → 101 taken 66312 times.
67579 if (fieldSymbolType.isRef()) {
790 1267 lhs.ptr = nullptr;
791 1267 lhs.refPtr = memberAddr;
792 } else {
793 66312 lhs.ptr = memberAddr;
794 66312 lhs.refPtr = nullptr;
795 }
796
797 // Reset the value
798 67579 lhs.value = nullptr;
799 67579 break;
800 67579 }
801 6055 case PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS: {
802 // Make sure a value is present
803
1/2
✓ Branch 107 → 108 taken 6055 times.
✗ Branch 107 → 227 not taken.
6055 resolveValue(lhsNode, lhs);
804
805 // Allocate new local variable if required
806
2/2
✓ Branch 108 → 109 taken 2 times.
✓ Branch 108 → 119 taken 6053 times.
6055 if (!lhs.ptr) {
807
1/2
✗ Branch 109 → 110 not taken.
✓ Branch 109 → 111 taken 2 times.
2 assert(lhs.value != nullptr);
808
1/2
✓ Branch 115 → 116 taken 2 times.
✗ Branch 115 → 221 not taken.
2 lhs.ptr = insertAlloca(lhs.value->getType());
809 }
810
811 // Execute operation
812
1/2
✓ Branch 119 → 120 taken 6055 times.
✗ Branch 119 → 227 not taken.
6055 const LLVMExprResult result = conversionManager.getPostfixPlusPlusInst(node, lhs, lhsSTy);
813
814 // Save the new value to the old address
815
3/4
✓ Branch 120 → 121 taken 6055 times.
✗ Branch 120 → 227 not taken.
✓ Branch 121 → 122 taken 9 times.
✓ Branch 121 → 123 taken 6046 times.
6055 if (conversionManager.callsOverloadedOpFct(node, 0)) {
816 9 lhs.value = result.value;
817 9 lhs.ptr = result.ptr;
818 } else {
819
5/6
✓ Branch 123 → 124 taken 6043 times.
✓ Branch 123 → 126 taken 3 times.
✓ Branch 124 → 125 taken 3 times.
✓ Branch 124 → 126 taken 6040 times.
✓ Branch 127 → 128 taken 6046 times.
✗ Branch 127 → 227 not taken.
6046 insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
820 6046 lhs.ptr = nullptr;
821 }
822 6055 break;
823 }
824 550 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS: {
825 // Make sure a value is present
826
1/2
✓ Branch 131 → 132 taken 550 times.
✗ Branch 131 → 234 not taken.
550 resolveValue(lhsNode, lhs);
827
828 // Allocate new local variable if required
829
2/2
✓ Branch 132 → 133 taken 2 times.
✓ Branch 132 → 143 taken 548 times.
550 if (!lhs.ptr) {
830
1/2
✗ Branch 133 → 134 not taken.
✓ Branch 133 → 135 taken 2 times.
2 assert(lhs.value != nullptr);
831
1/2
✓ Branch 139 → 140 taken 2 times.
✗ Branch 139 → 228 not taken.
2 lhs.ptr = insertAlloca(lhs.value->getType());
832 }
833
834 // Execute operation
835
1/2
✓ Branch 143 → 144 taken 550 times.
✗ Branch 143 → 234 not taken.
550 const LLVMExprResult result = conversionManager.getPostfixMinusMinusInst(node, lhs, lhsSTy);
836
837 // Save the new value to the old address
838
3/4
✓ Branch 144 → 145 taken 550 times.
✗ Branch 144 → 234 not taken.
✓ Branch 145 → 146 taken 7 times.
✓ Branch 145 → 147 taken 543 times.
550 if (conversionManager.callsOverloadedOpFct(node, 0)) {
839 7 lhs.value = result.value;
840 7 lhs.ptr = result.ptr;
841 } else {
842
4/6
✓ Branch 147 → 148 taken 541 times.
✓ Branch 147 → 150 taken 2 times.
✗ Branch 148 → 149 not taken.
✓ Branch 148 → 150 taken 541 times.
✓ Branch 151 → 152 taken 543 times.
✗ Branch 151 → 234 not taken.
543 insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
843 543 lhs.ptr = nullptr;
844 }
845 550 break;
846 }
847 default: // GCOV_EXCL_LINE
848 throw CompilerError(UNHANDLED_BRANCH, "PostfixUnaryExpr fall-through"); // GCOV_EXCL_LINE
849 }
850
851
1/2
✓ Branch 163 → 164 taken 82621 times.
✗ Branch 163 → 244 not taken.
82621 return lhs;
852
5/14
✓ Branch 17 → 18 taken 540 times.
✗ Branch 17 → 173 not taken.
✓ Branch 18 → 19 taken 540 times.
✗ Branch 18 → 173 not taken.
✓ Branch 19 → 20 taken 540 times.
✗ Branch 19 → 173 not taken.
✓ Branch 20 → 21 taken 540 times.
✗ Branch 20 → 173 not taken.
✓ Branch 21 → 22 taken 540 times.
✗ Branch 21 → 171 not taken.
✗ Branch 173 → 174 not taken.
✗ Branch 173 → 177 not taken.
✗ Branch 175 → 176 not taken.
✗ Branch 175 → 177 not taken.
540 }
853
854 338743 std::any IRGenerator::visitAtomicExpr(const AtomicExprNode *node) {
855 // If constant
856
2/2
✓ Branch 2 → 3 taken 61187 times.
✓ Branch 2 → 9 taken 277556 times.
338743 if (node->constant) {
857
2/4
✓ Branch 3 → 4 taken 61187 times.
✗ Branch 3 → 82 not taken.
✓ Branch 4 → 5 taken 61187 times.
✗ Branch 4 → 80 not taken.
61187 const auto constantValue = std::any_cast<llvm::Constant *>(visit(node->constant));
858
1/2
✓ Branch 6 → 7 taken 61187 times.
✗ Branch 6 → 83 not taken.
122374 return LLVMExprResult{.constant = constantValue};
859 }
860
861 // If value
862
2/2
✓ Branch 9 → 10 taken 80542 times.
✓ Branch 9 → 12 taken 197014 times.
277556 if (node->value)
863
1/2
✓ Branch 10 → 11 taken 80542 times.
✗ Branch 10 → 90 not taken.
80542 return visit(node->value);
864
865 // Is assign expression
866
2/2
✓ Branch 12 → 13 taken 1699 times.
✓ Branch 12 → 15 taken 195315 times.
197014 if (node->assignExpr)
867
1/2
✓ Branch 13 → 14 taken 1699 times.
✗ Branch 13 → 90 not taken.
1699 return visit(node->assignExpr);
868
869
1/2
✓ Branch 15 → 16 taken 195315 times.
✗ Branch 15 → 90 not taken.
195315 diGenerator.setSourceLocation(node);
870
871 // Identifier (local or global variable access)
872
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 195315 times.
195315 assert(!node->identifierFragments.empty());
873
874 // Get symbol table entry
875
1/2
✓ Branch 19 → 20 taken 195315 times.
✗ Branch 19 → 90 not taken.
195315 const auto &[entry, accessScope, capture] = node->data.at(manIdx);
876
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 195315 times.
195315 assert(entry != nullptr);
877
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 195315 times.
195315 assert(accessScope != nullptr);
878
1/2
✓ Branch 24 → 25 taken 195315 times.
✗ Branch 24 → 90 not taken.
195315 const QualType varSymbolType = entry->getQualType();
879
1/2
✓ Branch 25 → 26 taken 195315 times.
✗ Branch 25 → 90 not taken.
195315 llvm::Type *varType = varSymbolType.toLLVMType(sourceFile);
880
881 // Check if external global variable
882
7/8
✓ Branch 26 → 27 taken 4330 times.
✓ Branch 26 → 30 taken 190985 times.
✓ Branch 27 → 28 taken 4330 times.
✗ Branch 27 → 90 not taken.
✓ Branch 28 → 29 taken 286 times.
✓ Branch 28 → 30 taken 4044 times.
✓ Branch 31 → 32 taken 286 times.
✓ Branch 31 → 35 taken 195029 times.
195315 if (entry->global && accessScope->isImportedBy(rootScope)) {
883 // External global variables need to be declared and allocated in the current module
884
1/2
✓ Branch 33 → 34 taken 286 times.
✗ Branch 33 → 84 not taken.
286 llvm::Value *varAddress = module->getOrInsertGlobal(entry->name, varType);
885
1/2
✓ Branch 34 → 35 taken 286 times.
✗ Branch 34 → 90 not taken.
286 updateAddress(entry, varAddress);
886 }
887
888 // Check if enum item
889
2/2
✓ Branch 35 → 36 taken 4146 times.
✓ Branch 35 → 49 taken 191169 times.
195315 if (accessScope->type == ScopeType::ENUM) {
890
1/2
✓ Branch 36 → 37 taken 4146 times.
✗ Branch 36 → 38 not taken.
4146 const auto itemNode = spice_pointer_cast<const EnumItemNode *>(entry->declNode);
891
1/2
✓ Branch 45 → 46 taken 4146 times.
✗ Branch 45 → 90 not taken.
4146 llvm::Constant *constantItemValue = llvm::ConstantInt::get(varType, itemNode->itemValue);
892
1/2
✓ Branch 46 → 47 taken 4146 times.
✗ Branch 46 → 85 not taken.
8292 return LLVMExprResult{.constant = constantItemValue, .entry = entry};
893 }
894
895
1/2
✓ Branch 49 → 50 taken 191169 times.
✗ Branch 49 → 90 not taken.
191169 llvm::Value *address = getAddress(entry);
896
1/2
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 191169 times.
191169 assert(address != nullptr);
897
898 // If this is a function/procedure reference, return it as value. The fat pointer must point at a thunk that
899 // carries the (ignored) leading capture-struct pointer, so it can be called through the uniform lambda ABI.
900
7/8
✓ Branch 52 → 53 taken 4330 times.
✓ Branch 52 → 56 taken 186839 times.
✓ Branch 53 → 54 taken 4330 times.
✗ Branch 53 → 86 not taken.
✓ Branch 54 → 55 taken 16 times.
✓ Branch 54 → 56 taken 4314 times.
✓ Branch 57 → 58 taken 16 times.
✓ Branch 57 → 64 taken 191153 times.
191169 if (entry->global && varSymbolType.isOneOf({TY_FUNCTION, TY_PROCEDURE})) {
901
2/4
✓ Branch 58 → 59 taken 16 times.
✗ Branch 58 → 90 not taken.
✓ Branch 59 → 60 taken 16 times.
✗ Branch 59 → 90 not taken.
16 llvm::Function *thunk = getOrCreateFatFctPtrThunk(llvm::cast<llvm::Function>(address));
902
1/2
✓ Branch 60 → 61 taken 16 times.
✗ Branch 60 → 90 not taken.
16 llvm::Value *fatPtr = buildFatFctPtr(nullptr, nullptr, thunk);
903
1/2
✓ Branch 61 → 62 taken 16 times.
✗ Branch 61 → 87 not taken.
32 return LLVMExprResult{.ptr = fatPtr, .entry = entry};
904 }
905
906 // Load the address of the referenced variable
907
10/12
✓ Branch 64 → 65 taken 191153 times.
✗ Branch 64 → 90 not taken.
✓ Branch 65 → 66 taken 170959 times.
✓ Branch 65 → 69 taken 20194 times.
✓ Branch 66 → 67 taken 81 times.
✓ Branch 66 → 70 taken 170878 times.
✓ Branch 67 → 68 taken 81 times.
✗ Branch 67 → 90 not taken.
✓ Branch 68 → 69 taken 19 times.
✓ Branch 68 → 70 taken 62 times.
✓ Branch 71 → 72 taken 20213 times.
✓ Branch 71 → 75 taken 170940 times.
191153 if (varSymbolType.isRef() || (capture && capture->getMode() == BY_REFERENCE))
908
1/2
✓ Branch 72 → 73 taken 20213 times.
✗ Branch 72 → 88 not taken.
40426 return LLVMExprResult{.refPtr = address, .entry = entry};
909
910
1/2
✓ Branch 75 → 76 taken 170940 times.
✗ Branch 75 → 89 not taken.
341880 return LLVMExprResult{.ptr = address, .entry = entry};
911 }
912
913 } // namespace spice::compiler
914