GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.0% 506 / 17 / 544
Functions: 95.0% 19 / 0 / 20
Branches: 56.6% 558 / 36 / 1021

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 26133 std::any IRGenerator::visitAssignExpr(const AssignExprNode *node) {
12 // Visit ternary expression
13
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 26133 times.
26133 if (node->ternaryExpr)
14 return visit(node->ternaryExpr);
15
16 26133 diGenerator.setSourceLocation(node);
17
18 // Assign or compound assign operation
19
1/2
✓ Branch 5 → 6 taken 26133 times.
✗ Branch 5 → 60 not taken.
26133 if (node->op != AssignExprNode::AssignOp::OP_NONE) {
20 26133 const ExprNode *lhsNode = node->lhs;
21 26133 const ExprNode *rhsNode = node->rhs;
22
23 // Normal assignment
24
2/2
✓ Branch 6 → 7 taken 23226 times.
✓ Branch 6 → 11 taken 2907 times.
26133 if (node->op == AssignExprNode::AssignOp::OP_ASSIGN)
25
2/4
✓ Branch 7 → 8 taken 23226 times.
✗ Branch 7 → 69 not taken.
✓ Branch 8 → 9 taken 23226 times.
✗ Branch 8 → 69 not taken.
46452 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 2907 times.
✗ Branch 11 → 85 not taken.
2907 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
30
1/2
✓ Branch 12 → 13 taken 2907 times.
✗ Branch 12 → 85 not taken.
2907 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
31
32 // Retrieve rhs
33
2/4
✓ Branch 13 → 14 taken 2907 times.
✗ Branch 13 → 72 not taken.
✓ Branch 14 → 15 taken 2907 times.
✗ Branch 14 → 70 not taken.
2907 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
34 // Retrieve lhs
35
2/4
✓ Branch 16 → 17 taken 2907 times.
✗ Branch 16 → 75 not taken.
✓ Branch 17 → 18 taken 2907 times.
✗ Branch 17 → 73 not taken.
2907 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
36
37 2907 LLVMExprResult result;
38
10/11
✓ Branch 19 → 20 taken 1975 times.
✓ Branch 19 → 22 taken 89 times.
✓ Branch 19 → 24 taken 256 times.
✓ Branch 19 → 26 taken 107 times.
✓ Branch 19 → 28 taken 48 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.
2907 switch (node->op) {
39 1975 case AssignExprNode::AssignOp::OP_PLUS_EQUAL:
40
1/2
✓ Branch 20 → 21 taken 1975 times.
✗ Branch 20 → 85 not taken.
1975 result = conversionManager.getPlusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
41 1975 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 48 case AssignExprNode::AssignOp::OP_REM_EQUAL:
52
1/2
✓ Branch 28 → 29 taken 48 times.
✗ Branch 28 → 85 not taken.
48 result = conversionManager.getRemEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
53 48 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 2907 times.
2907 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 2120 times.
✓ Branch 51 → 57 taken 787 times.
2907 } else if (result.value) { // The operation only updated the value
77 // Store the result
78 2120 lhs.value = result.value;
79
5/6
✓ Branch 52 → 53 taken 2068 times.
✓ Branch 52 → 55 taken 52 times.
✓ Branch 53 → 54 taken 1 time.
✓ Branch 53 → 55 taken 2067 times.
✓ Branch 56 → 57 taken 2120 times.
✗ Branch 56 → 85 not taken.
2120 insertStore(lhs.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
80 }
81
1/2
✓ Branch 57 → 58 taken 2907 times.
✗ Branch 57 → 85 not taken.
2907 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 1837 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 1837 times.
1837 if (!node->falseExpr)
91 return visit(node->condition);
92
93 1837 diGenerator.setSourceLocation(node);
94
95 // It is a ternary
96 // Retrieve the condition value
97 1837 llvm::Value *condValue = resolveValue(node->condition);
98
2/2
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 1836 times.
1837 const ExprNode *trueNode = node->isShortened ? node->condition : node->trueExpr;
99 1837 const ExprNode *falseNode = node->falseExpr;
100
101 1837 llvm::Value *resultValue = nullptr;
102 1837 llvm::Value *resultPtr = nullptr;
103 1837 const SymbolTableEntry *anonymousSymbol = nullptr;
104
6/6
✓ Branch 10 → 11 taken 478 times.
✓ Branch 10 → 14 taken 1359 times.
✓ Branch 12 → 13 taken 450 times.
✓ Branch 12 → 14 taken 28 times.
✓ Branch 15 → 16 taken 450 times.
✓ Branch 15 → 21 taken 1387 times.
1837 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 1387 times.
✗ Branch 21 → 204 not taken.
1387 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
112
2/4
✓ Branch 22 → 23 taken 1387 times.
✗ Branch 22 → 148 not taken.
✓ Branch 23 → 24 taken 1387 times.
✗ Branch 23 → 146 not taken.
1387 llvm::BasicBlock *condTrue = createBlock("cond.true." + codeLoc);
113
2/4
✓ Branch 25 → 26 taken 1387 times.
✗ Branch 25 → 151 not taken.
✓ Branch 26 → 27 taken 1387 times.
✗ Branch 26 → 149 not taken.
1387 llvm::BasicBlock *condFalse = createBlock("cond.false." + codeLoc);
114
2/4
✓ Branch 28 → 29 taken 1387 times.
✗ Branch 28 → 154 not taken.
✓ Branch 29 → 30 taken 1387 times.
✗ Branch 29 → 152 not taken.
1387 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 1387 times.
✗ Branch 31 → 202 not taken.
1387 insertCondJump(condValue, condTrue, condFalse);
118
119 // Fill true block
120
1/2
✓ Branch 32 → 33 taken 1387 times.
✗ Branch 32 → 202 not taken.
1387 switchToBlock(condTrue);
121
1/2
✓ Branch 33 → 34 taken 1387 times.
✗ Branch 33 → 202 not taken.
1387 const QualType &resultType = node->getEvaluatedSymbolType(manIdx);
122 1387 llvm::Value *trueValue = nullptr;
123 1387 llvm::Value *truePtr = nullptr;
124
7/8
✓ Branch 34 → 35 taken 1360 times.
✓ Branch 34 → 37 taken 27 times.
✓ Branch 35 → 36 taken 1360 times.
✗ Branch 35 → 202 not taken.
✓ Branch 36 → 37 taken 14 times.
✓ Branch 36 → 38 taken 1346 times.
✓ Branch 39 → 40 taken 41 times.
✓ Branch 39 → 42 taken 1346 times.
1387 if (node->falseSideCallsCopyCtor || resultType.isRef()) { // both sides or only the false side needs copy ctor call
125
1/2
✓ Branch 40 → 41 taken 41 times.
✗ Branch 40 → 202 not taken.
41 truePtr = resolveAddress(trueNode);
126
2/2
✓ Branch 42 → 43 taken 4 times.
✓ Branch 42 → 57 taken 1342 times.
1346 } 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 1342 times.
✗ Branch 57 → 202 not taken.
1342 trueValue = resolveValue(trueNode);
135 }
136 // Set the true block to the current insert point, since it could have changed in the meantime
137 1387 condTrue = builder.GetInsertBlock();
138
1/2
✓ Branch 60 → 61 taken 1387 times.
✗ Branch 60 → 202 not taken.
1387 insertJump(condExit);
139
140 // Fill false block
141
1/2
✓ Branch 61 → 62 taken 1387 times.
✗ Branch 61 → 202 not taken.
1387 switchToBlock(condFalse);
142 1387 llvm::Value *falseValue = nullptr;
143 1387 llvm::Value *falsePtr = nullptr;
144
7/8
✓ Branch 62 → 63 taken 1377 times.
✓ Branch 62 → 65 taken 10 times.
✓ Branch 63 → 64 taken 1377 times.
✗ Branch 63 → 202 not taken.
✓ Branch 64 → 65 taken 14 times.
✓ Branch 64 → 66 taken 1363 times.
✓ Branch 67 → 68 taken 24 times.
✓ Branch 67 → 70 taken 1363 times.
1387 if (node->trueSideCallsCopyCtor || resultType.isRef()) { // both sides or only the true side needs copy ctor call
145
1/2
✓ Branch 68 → 69 taken 24 times.
✗ Branch 68 → 202 not taken.
24 falsePtr = resolveAddress(falseNode);
146
2/2
✓ Branch 70 → 71 taken 21 times.
✓ Branch 70 → 85 taken 1342 times.
1363 } 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 1342 times.
✗ Branch 85 → 202 not taken.
1342 falseValue = resolveValue(falseNode);
154 }
155 // Set the true block to the current insert point, since it could have changed in the meantime
156 1387 condFalse = builder.GetInsertBlock();
157
1/2
✓ Branch 88 → 89 taken 1387 times.
✗ Branch 88 → 202 not taken.
1387 insertJump(condExit);
158
159 // Fill the exit block
160
1/2
✓ Branch 89 → 90 taken 1387 times.
✗ Branch 89 → 202 not taken.
1387 switchToBlock(condExit);
161
9/10
✓ Branch 90 → 91 taken 1377 times.
✓ Branch 90 → 94 taken 10 times.
✓ Branch 91 → 92 taken 1356 times.
✓ Branch 91 → 94 taken 21 times.
✓ Branch 92 → 93 taken 1356 times.
✗ Branch 92 → 202 not taken.
✓ Branch 93 → 94 taken 14 times.
✓ Branch 93 → 95 taken 1342 times.
✓ Branch 96 → 97 taken 45 times.
✓ Branch 96 → 119 taken 1342 times.
1387 if (node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor || resultType.isRef()) { // one side calls copy ctor
162
3/6
✓ Branch 97 → 98 taken 45 times.
✗ Branch 97 → 181 not taken.
✓ Branch 98 → 99 taken 45 times.
✗ Branch 98 → 181 not taken.
✓ Branch 99 → 100 taken 45 times.
✗ Branch 99 → 181 not taken.
45 llvm::PHINode *phiInst = builder.CreatePHI(builder.getPtrTy(), 2, "cond.result");
163
1/2
✓ Branch 100 → 101 taken 45 times.
✗ Branch 100 → 202 not taken.
45 phiInst->addIncoming(truePtr, condTrue);
164
1/2
✓ Branch 101 → 102 taken 45 times.
✗ Branch 101 → 202 not taken.
45 phiInst->addIncoming(falsePtr, condFalse);
165
4/4
✓ Branch 102 → 103 taken 10 times.
✓ Branch 102 → 117 taken 35 times.
✓ Branch 103 → 104 taken 6 times.
✓ Branch 103 → 117 taken 4 times.
45 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 39 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 1342 times.
1342 assert(trueValue != nullptr);
173
3/6
✓ Branch 121 → 122 taken 1342 times.
✗ Branch 121 → 195 not taken.
✓ Branch 122 → 123 taken 1342 times.
✗ Branch 122 → 195 not taken.
✓ Branch 123 → 124 taken 1342 times.
✗ Branch 123 → 195 not taken.
1342 llvm::PHINode *phiInst = builder.CreatePHI(resultType.toLLVMType(sourceFile), 2, "cond.result");
174
1/2
✓ Branch 124 → 125 taken 1342 times.
✗ Branch 124 → 202 not taken.
1342 phiInst->addIncoming(trueValue, condTrue);
175
1/2
✓ Branch 125 → 126 taken 1342 times.
✗ Branch 125 → 202 not taken.
1342 phiInst->addIncoming(falseValue, condFalse);
176 1342 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 1387 times.
✗ Branch 127 → 202 not taken.
1387 anonymousSymbol = currentScope->symbolTable.lookupAnonymous(node);
181
2/2
✓ Branch 128 → 129 taken 10 times.
✓ Branch 128 → 139 taken 1377 times.
1387 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 1387 }
189
190
1/2
✓ Branch 141 → 142 taken 1837 times.
✗ Branch 141 → 205 not taken.
3674 return LLVMExprResult{.value = resultValue, .ptr = resultPtr, .entry = anonymousSymbol};
191 }
192
193 2470 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 2470 times.
2470 if (node->operands.size() == 1)
196 return visit(node->operands.front());
197
198
1/2
✓ Branch 7 → 8 taken 2470 times.
✗ Branch 7 → 104 not taken.
2470 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 2470 times.
✗ Branch 8 → 104 not taken.
2470 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
203
2/4
✓ Branch 9 → 10 taken 2470 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 2470 times.
✗ Branch 10 → 79 not taken.
2470 llvm::BasicBlock *bExit = createBlock("lor.exit." + codeLoc);
204
205 // Visit the first operand
206
1/2
✓ Branch 13 → 14 taken 2470 times.
✗ Branch 13 → 102 not taken.
2470 llvm::Value *firstOperandValue = resolveValue(node->operands.front());
207
208 // Prepare an array for value-to-block-mapping
209 2470 std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks;
210
1/2
✓ Branch 15 → 16 taken 2470 times.
✗ Branch 15 → 100 not taken.
2470 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 2470 times.
✗ Branch 17 → 82 not taken.
2470 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 3311 times.
✓ Branch 31 → 32 taken 2470 times.
5781 for (size_t i = 1; i < node->operands.size(); i++)
215
6/12
✓ Branch 19 → 20 taken 3311 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 3311 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 3311 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 3311 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 3311 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 3311 times.
✗ Branch 24 → 83 not taken.
3311 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 2470 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 2470 times.
✗ Branch 33 → 100 not taken.
2470 insertCondJump(firstOperandValue, bExit, shortCircuitBlocks.at(1).first);
218
219 // Create block for each operand
220
2/2
✓ Branch 50 → 35 taken 3311 times.
✓ Branch 50 → 51 taken 2470 times.
5781 for (size_t i = 1; i < node->operands.size(); i++) {
221 // Switch to the next block
222
2/4
✓ Branch 35 → 36 taken 3311 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 3311 times.
✗ Branch 36 → 100 not taken.
3311 switchToBlock(shortCircuitBlocks.at(i).first);
223 // Evaluate operand and save the result in the mapping
224
2/4
✓ Branch 38 → 39 taken 3311 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 3311 times.
✗ Branch 39 → 100 not taken.
3311 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 3311 times.
✗ Branch 41 → 100 not taken.
3311 shortCircuitBlocks.at(i).first = builder.GetInsertBlock();
227 // Check if there are more blocks to process
228
2/2
✓ Branch 43 → 44 taken 2470 times.
✓ Branch 43 → 45 taken 841 times.
3311 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 2470 times.
✗ Branch 44 → 100 not taken.
2470 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 841 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 841 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 841 times.
✗ Branch 47 → 100 not taken.
841 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 2470 times.
✗ Branch 51 → 100 not taken.
2470 switchToBlock(bExit);
239
2/4
✓ Branch 52 → 53 taken 2470 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 2470 times.
✗ Branch 55 → 97 not taken.
2470 llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "lor_phi");
240
2/2
✓ Branch 72 → 58 taken 5781 times.
✓ Branch 72 → 73 taken 2470 times.
16502 for (const auto &[incomingBlock, value] : shortCircuitBlocks)
241
1/2
✓ Branch 62 → 63 taken 5781 times.
✗ Branch 62 → 98 not taken.
5781 result->addIncoming(value, incomingBlock);
242
243 // Return the result
244
1/2
✓ Branch 73 → 74 taken 2470 times.
✗ Branch 73 → 99 not taken.
2470 return LLVMExprResult{.value = result};
245 2470 }
246
247 1527 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 1527 times.
1527 if (node->operands.size() == 1)
250 return visit(node->operands.front());
251
252
1/2
✓ Branch 7 → 8 taken 1527 times.
✗ Branch 7 → 104 not taken.
1527 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 1527 times.
✗ Branch 8 → 104 not taken.
1527 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
257
2/4
✓ Branch 9 → 10 taken 1527 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 1527 times.
✗ Branch 10 → 79 not taken.
1527 llvm::BasicBlock *bExit = createBlock("land.exit." + codeLoc);
258
259 // Visit the first operand
260
1/2
✓ Branch 13 → 14 taken 1527 times.
✗ Branch 13 → 102 not taken.
1527 llvm::Value *firstOperandValue = resolveValue(node->operands.front());
261
262 // Prepare an array for value-to-block-mapping
263 1527 std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks;
264
1/2
✓ Branch 15 → 16 taken 1527 times.
✗ Branch 15 → 100 not taken.
1527 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 1527 times.
✗ Branch 17 → 82 not taken.
1527 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 2028 times.
✓ Branch 31 → 32 taken 1527 times.
3555 for (size_t i = 1; i < node->operands.size(); i++)
269
6/12
✓ Branch 19 → 20 taken 2028 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 2028 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 2028 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 2028 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 2028 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 2028 times.
✗ Branch 24 → 83 not taken.
2028 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 1527 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 1527 times.
✗ Branch 33 → 100 not taken.
1527 insertCondJump(firstOperandValue, shortCircuitBlocks.at(1).first, bExit);
272
273 // Create block for each operand
274
2/2
✓ Branch 50 → 35 taken 2028 times.
✓ Branch 50 → 51 taken 1527 times.
3555 for (size_t i = 1; i < node->operands.size(); i++) {
275 // Switch to the next block
276
2/4
✓ Branch 35 → 36 taken 2028 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 2028 times.
✗ Branch 36 → 100 not taken.
2028 switchToBlock(shortCircuitBlocks.at(i).first);
277 // Evaluate operand and save the result in the mapping
278
2/4
✓ Branch 38 → 39 taken 2028 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 2028 times.
✗ Branch 39 → 100 not taken.
2028 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 2028 times.
✗ Branch 41 → 100 not taken.
2028 shortCircuitBlocks.at(i).first = builder.GetInsertBlock();
281 // Check if there are more blocks to process
282
2/2
✓ Branch 43 → 44 taken 1527 times.
✓ Branch 43 → 45 taken 501 times.
2028 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 1527 times.
✗ Branch 44 → 100 not taken.
1527 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 501 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 501 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 501 times.
✗ Branch 47 → 100 not taken.
501 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 1527 times.
✗ Branch 51 → 100 not taken.
1527 switchToBlock(bExit);
293
2/4
✓ Branch 52 → 53 taken 1527 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 1527 times.
✗ Branch 55 → 97 not taken.
1527 llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "land_phi");
294
2/2
✓ Branch 72 → 58 taken 3555 times.
✓ Branch 72 → 73 taken 1527 times.
10164 for (const auto &[incomingBlock, value] : shortCircuitBlocks)
295
1/2
✓ Branch 62 → 63 taken 3555 times.
✗ Branch 62 → 98 not taken.
3555 result->addIncoming(value, incomingBlock);
296
297 // Return the result
298
1/2
✓ Branch 73 → 74 taken 1527 times.
✗ Branch 73 → 99 not taken.
1527 return LLVMExprResult{.value = result};
299 1527 }
300
301 384 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 384 times.
384 if (node->operands.size() == 1)
304 return visit(node->operands.front());
305
306
1/2
✓ Branch 7 → 8 taken 384 times.
✗ Branch 7 → 34 not taken.
384 diGenerator.setSourceLocation(node);
307
308 // It is a bitwise or expression
309 // Evaluate first operand
310 384 const ExprNode *lhsNode = node->operands.front();
311
1/2
✓ Branch 9 → 10 taken 384 times.
✗ Branch 9 → 34 not taken.
384 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
312
2/4
✓ Branch 10 → 11 taken 384 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 384 times.
✗ Branch 11 → 27 not taken.
384 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
313
314 // Evaluate all additional operands
315
2/2
✓ Branch 22 → 14 taken 385 times.
✓ Branch 22 → 23 taken 384 times.
769 for (size_t i = 1; i < node->operands.size(); i++) {
316 // Evaluate the operand
317 385 const ExprNode *rhsNode = node->operands[i];
318
1/2
✓ Branch 15 → 16 taken 385 times.
✗ Branch 15 → 33 not taken.
385 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
319
2/4
✓ Branch 16 → 17 taken 385 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 385 times.
✗ Branch 17 → 30 not taken.
385 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
320
1/2
✓ Branch 19 → 20 taken 385 times.
✗ Branch 19 → 33 not taken.
385 result = conversionManager.getBitwiseOrInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
321 }
322
323 // Return result
324
1/2
✓ Branch 23 → 24 taken 384 times.
✗ Branch 23 → 34 not taken.
384 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 22381 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 22381 times.
22381 if (node->operands.size() == 1)
382 return visit(node->operands.front());
383
384
1/2
✓ Branch 7 → 8 taken 22381 times.
✗ Branch 7 → 50 not taken.
22381 diGenerator.setSourceLocation(node);
385
386 // It is an equality expression
387 // Evaluate lhs
388 22381 const ExprNode *lhsNode = node->operands[0];
389
1/2
✓ Branch 9 → 10 taken 22381 times.
✗ Branch 9 → 50 not taken.
22381 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
390
2/4
✓ Branch 10 → 11 taken 22381 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 22381 times.
✗ Branch 11 → 35 not taken.
22381 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
391
392 // Evaluate rhs
393 22381 const ExprNode *rhsNode = node->operands[1];
394
1/2
✓ Branch 14 → 15 taken 22381 times.
✗ Branch 14 → 50 not taken.
22381 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
395
2/4
✓ Branch 15 → 16 taken 22381 times.
✗ Branch 15 → 40 not taken.
✓ Branch 16 → 17 taken 22381 times.
✗ Branch 16 → 38 not taken.
22381 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 18901 times.
✓ Branch 18 → 21 taken 3480 times.
✗ Branch 18 → 23 not taken.
22381 switch (node->op) {
399 18901 case EqualityExprNode::EqualityOp::OP_EQUAL:
400
1/2
✓ Branch 19 → 20 taken 18901 times.
✗ Branch 19 → 50 not taken.
18901 result = conversionManager.getEqualInst(node, result, lhsSTy, rhs, rhsSTy);
401 18901 break;
402 3480 case EqualityExprNode::EqualityOp::OP_NOT_EQUAL:
403
1/2
✓ Branch 21 → 22 taken 3480 times.
✗ Branch 21 → 50 not taken.
3480 result = conversionManager.getNotEqualInst(node, result, lhsSTy, rhs, rhsSTy);
404 3480 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 22381 times.
✗ Branch 31 → 50 not taken.
22381 return result;
411 }
412
413 12803 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 12803 times.
12803 if (node->operands.size() == 1)
416 return visit(node->operands.front());
417
418
1/2
✓ Branch 7 → 8 taken 12803 times.
✗ Branch 7 → 54 not taken.
12803 diGenerator.setSourceLocation(node);
419
420 // It is a relational expression
421 // Evaluate lhs
422 12803 const ExprNode *lhsNode = node->operands[0];
423
1/2
✓ Branch 9 → 10 taken 12803 times.
✗ Branch 9 → 54 not taken.
12803 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
424
2/4
✓ Branch 10 → 11 taken 12803 times.
✗ Branch 10 → 41 not taken.
✓ Branch 11 → 12 taken 12803 times.
✗ Branch 11 → 39 not taken.
12803 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
425
426 // Evaluate rhs
427 12803 const ExprNode *rhsNode = node->operands[1];
428
1/2
✓ Branch 14 → 15 taken 12803 times.
✗ Branch 14 → 54 not taken.
12803 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
429
2/4
✓ Branch 15 → 16 taken 12803 times.
✗ Branch 15 → 44 not taken.
✓ Branch 16 → 17 taken 12803 times.
✗ Branch 16 → 42 not taken.
12803 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 5158 times.
✓ Branch 18 → 21 taken 2692 times.
✓ Branch 18 → 23 taken 1769 times.
✓ Branch 18 → 25 taken 3184 times.
✗ Branch 18 → 27 not taken.
12803 switch (node->op) {
433 5158 case RelationalExprNode::RelationalOp::OP_LESS:
434
1/2
✓ Branch 19 → 20 taken 5158 times.
✗ Branch 19 → 54 not taken.
5158 result = conversionManager.getLessInst(node, result, lhsSTy, rhs, rhsSTy);
435 5158 break;
436 2692 case RelationalExprNode::RelationalOp::OP_GREATER:
437
1/2
✓ Branch 21 → 22 taken 2692 times.
✗ Branch 21 → 54 not taken.
2692 result = conversionManager.getGreaterInst(node, result, lhsSTy, rhs, rhsSTy);
438 2692 break;
439 1769 case RelationalExprNode::RelationalOp::OP_LESS_EQUAL:
440
1/2
✓ Branch 23 → 24 taken 1769 times.
✗ Branch 23 → 54 not taken.
1769 result = conversionManager.getLessEqualInst(node, result, lhsSTy, rhs, rhsSTy);
441 1769 break;
442 3184 case RelationalExprNode::RelationalOp::OP_GREATER_EQUAL:
443
1/2
✓ Branch 25 → 26 taken 3184 times.
✗ Branch 25 → 54 not taken.
3184 result = conversionManager.getGreaterEqualInst(node, result, lhsSTy, rhs, rhsSTy);
444 3184 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 12803 times.
✗ Branch 35 → 54 not taken.
12803 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 11787 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 11787 times.
11787 if (node->operands.size() == 1)
501 return visit(node->operands.front());
502
503
1/2
✓ Branch 7 → 8 taken 11787 times.
✗ Branch 7 → 64 not taken.
11787 diGenerator.setSourceLocation(node);
504
505 // It is an additive expression
506 // Evaluate first operand
507 11787 const ExprNode *lhsNode = node->operands[0];
508
1/2
✓ Branch 9 → 10 taken 11787 times.
✗ Branch 9 → 64 not taken.
11787 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
509
2/4
✓ Branch 10 → 11 taken 11787 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 11787 times.
✗ Branch 11 → 46 not taken.
11787 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
510
511
1/2
✓ Branch 13 → 14 taken 11787 times.
✗ Branch 13 → 64 not taken.
11787 auto opQueue = node->opQueue;
512 11787 size_t operandIndex = 1;
513
2/2
✓ Branch 40 → 15 taken 13318 times.
✓ Branch 40 → 41 taken 11787 times.
25105 while (!opQueue.empty()) {
514 13318 const size_t operatorIndex = operandIndex - 1;
515 // Evaluate next operand
516 13318 const ExprNode *rhsNode = node->operands[operandIndex++];
517
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 13318 times.
13318 assert(rhsNode != nullptr);
518
1/2
✓ Branch 18 → 19 taken 13318 times.
✗ Branch 18 → 61 not taken.
13318 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
519
2/4
✓ Branch 19 → 20 taken 13318 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 13318 times.
✗ Branch 20 → 49 not taken.
13318 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 8473 times.
✓ Branch 23 → 26 taken 4845 times.
✗ Branch 23 → 28 not taken.
13318 switch (opQueue.front().first) {
523 8473 case AdditiveExprNode::AdditiveOp::OP_PLUS:
524
1/2
✓ Branch 24 → 25 taken 8473 times.
✗ Branch 24 → 61 not taken.
8473 lhs = conversionManager.getPlusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
525 8473 break;
526 4845 case AdditiveExprNode::AdditiveOp::OP_MINUS:
527
1/2
✓ Branch 26 → 27 taken 4845 times.
✗ Branch 26 → 61 not taken.
4845 lhs = conversionManager.getMinusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
528 4845 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 13318 lhsSTy = opQueue.front().second;
535
536 13318 opQueue.pop();
537 }
538
539 // Return the result
540
1/2
✓ Branch 41 → 42 taken 11787 times.
✗ Branch 41 → 62 not taken.
11787 return lhs;
541 11787 }
542
543 2812 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 2812 times.
2812 if (node->operands.size() == 1)
546 return visit(node->operands.front());
547
548
1/2
✓ Branch 7 → 8 taken 2812 times.
✗ Branch 7 → 66 not taken.
2812 diGenerator.setSourceLocation(node);
549
550 // It is an additive expression
551 // Evaluate first operand
552 2812 const ExprNode *lhsNode = node->operands[0];
553
1/2
✓ Branch 9 → 10 taken 2812 times.
✗ Branch 9 → 66 not taken.
2812 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
554
2/4
✓ Branch 10 → 11 taken 2812 times.
✗ Branch 10 → 50 not taken.
✓ Branch 11 → 12 taken 2812 times.
✗ Branch 11 → 48 not taken.
2812 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
555
556
1/2
✓ Branch 13 → 14 taken 2812 times.
✗ Branch 13 → 66 not taken.
2812 auto opQueue = node->opQueue;
557 2812 size_t operandIndex = 1;
558
2/2
✓ Branch 42 → 15 taken 2932 times.
✓ Branch 42 → 43 taken 2812 times.
5744 while (!opQueue.empty()) {
559 2932 const size_t operatorIndex = operandIndex - 1;
560 // Evaluate next operand
561 2932 const ExprNode *rhsNode = node->operands[operandIndex++];
562
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 2932 times.
2932 assert(rhsNode != nullptr);
563
1/2
✓ Branch 18 → 19 taken 2932 times.
✗ Branch 18 → 63 not taken.
2932 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
564
2/4
✓ Branch 19 → 20 taken 2932 times.
✗ Branch 19 → 53 not taken.
✓ Branch 20 → 21 taken 2932 times.
✗ Branch 20 → 51 not taken.
2932 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 2342 times.
✓ Branch 23 → 26 taken 475 times.
✓ Branch 23 → 28 taken 115 times.
✗ Branch 23 → 30 not taken.
2932 switch (opQueue.front().first) {
568 2342 case MultiplicativeExprNode::MultiplicativeOp::OP_MUL:
569
1/2
✓ Branch 24 → 25 taken 2342 times.
✗ Branch 24 → 63 not taken.
2342 result = conversionManager.getMulInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex);
570 2342 break;
571 475 case MultiplicativeExprNode::MultiplicativeOp::OP_DIV:
572
1/2
✓ Branch 26 → 27 taken 475 times.
✗ Branch 26 → 63 not taken.
475 result = conversionManager.getDivInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex);
573 475 break;
574 115 case MultiplicativeExprNode::MultiplicativeOp::OP_REM:
575
1/2
✓ Branch 28 → 29 taken 115 times.
✗ Branch 28 → 63 not taken.
115 result = conversionManager.getRemInst(node, result, lhsSTy, rhs, rhsSTy);
576 115 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 2932 lhsSTy = opQueue.front().second;
583 2932 opQueue.pop();
584 }
585
586 // Return the result
587
1/2
✓ Branch 43 → 44 taken 2812 times.
✗ Branch 43 → 64 not taken.
2812 return result;
588 2812 }
589
590 10642 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 10642 times.
10642 if (!node->isCast)
593 return visit(node->prefixUnaryExpr);
594
595
1/2
✓ Branch 5 → 6 taken 10642 times.
✗ Branch 5 → 19 not taken.
10642 diGenerator.setSourceLocation(node);
596
597 // It is a cast expression
598 // Retrieve target symbol type
599
1/2
✓ Branch 6 → 7 taken 10642 times.
✗ Branch 6 → 19 not taken.
10642 const QualType targetSTy = node->getEvaluatedSymbolType(manIdx);
600
601 // Evaluate rhs
602 10642 const ExprNode *rhsNode = node->assignExpr;
603
1/2
✓ Branch 7 → 8 taken 10642 times.
✗ Branch 7 → 19 not taken.
10642 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
604
2/4
✓ Branch 8 → 9 taken 10642 times.
✗ Branch 8 → 18 not taken.
✓ Branch 9 → 10 taken 10642 times.
✗ Branch 9 → 16 not taken.
10642 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
605
606 // Retrieve the result value
607
1/2
✓ Branch 11 → 12 taken 10642 times.
✗ Branch 11 → 19 not taken.
10642 const LLVMExprResult result = conversionManager.getCastInst(node, targetSTy, rhs, rhsSTy);
608
609 // Return the result
610
1/2
✓ Branch 12 → 13 taken 10642 times.
✗ Branch 12 → 19 not taken.
10642 return result;
611 }
612
613 7490 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 7490 times.
7490 if (node->op == PrefixUnaryExprNode::PrefixUnaryOp::OP_NONE)
616 return visit(node->postfixUnaryExpr);
617
618
1/2
✓ Branch 5 → 6 taken 7490 times.
✗ Branch 5 → 117 not taken.
7490 diGenerator.setSourceLocation(node);
619
620 // Evaluate lhs
621 7490 const ExprNode *lhsNode = node->prefixUnaryExpr;
622
1/2
✓ Branch 6 → 7 taken 7490 times.
✗ Branch 6 → 117 not taken.
7490 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
623
2/4
✓ Branch 7 → 8 taken 7490 times.
✗ Branch 7 → 87 not taken.
✓ Branch 8 → 9 taken 7490 times.
✗ Branch 8 → 85 not taken.
7490 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 4244 times.
✓ Branch 10 → 53 taken 30 times.
✓ Branch 10 → 55 taken 1009 times.
✓ Branch 10 → 64 taken 1156 times.
✗ Branch 10 → 73 not taken.
7490 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 4244 case PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT: {
673 // Execute operation
674
1/2
✓ Branch 51 → 52 taken 4244 times.
✗ Branch 51 → 117 not taken.
4244 lhs = conversionManager.getPrefixNotInst(node, lhs, lhsSTy);
675 4244 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 1009 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 982 times.
✓ Branch 55 → 58 taken 27 times.
✓ Branch 56 → 57 taken 38 times.
✓ Branch 56 → 58 taken 944 times.
1009 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 971 times.
✓ Branch 60 → 61 taken 38 times.
✗ Branch 60 → 117 not taken.
1009 llvm::Value *newRefPtr = onlyRefPtrIsFilled ? resolveValue(lhsNode, lhs) : lhs.ptr;
688 1009 llvm::Value *newPtr = lhs.value;
689 1009 lhs = {.ptr = newPtr, .refPtr = newRefPtr};
690 1009 break;
691 }
692 1156 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 68 times.
✓ Branch 64 → 67 taken 1088 times.
✓ Branch 65 → 66 taken 2 times.
✓ Branch 65 → 67 taken 66 times.
1156 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 1154 times.
✓ Branch 69 → 70 taken 2 times.
✗ Branch 69 → 117 not taken.
1156 llvm::Value *newValue = onlyValueIsFilled ? resolveAddress(lhs) : lhs.ptr;
698 1156 llvm::Value *newPtr = lhs.refPtr;
699 1156 lhs = {.value = newValue, .ptr = newPtr};
700 1156 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 7490 times.
✗ Branch 81 → 117 not taken.
7490 return lhs;
707 }
708
709 83574 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 83574 times.
83574 if (node->op == PostfixUnaryExprNode::PostfixUnaryOp::OP_NONE)
712 return visit(node->atomicExpr);
713
714
1/2
✓ Branch 5 → 6 taken 83574 times.
✗ Branch 5 → 310 not taken.
83574 diGenerator.setSourceLocation(node);
715
716 // Evaluate lhs
717 83574 const ExprNode *lhsNode = node->postfixUnaryExpr;
718
1/2
✓ Branch 6 → 7 taken 83574 times.
✗ Branch 6 → 310 not taken.
83574 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
719
2/4
✓ Branch 7 → 8 taken 83574 times.
✗ Branch 7 → 214 not taken.
✓ Branch 8 → 9 taken 83574 times.
✗ Branch 8 → 212 not taken.
83574 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
720
721
5/6
✓ Branch 10 → 11 taken 8481 times.
✓ Branch 10 → 62 taken 68399 times.
✓ Branch 10 → 107 taken 6085 times.
✓ Branch 10 → 131 taken 553 times.
✓ Branch 10 → 155 taken 56 times.
✗ Branch 10 → 200 not taken.
83574 switch (node->op) {
722 8481 case PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT: {
723 8481 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 8481 times.
✗ Branch 11 → 250 not taken.
✓ Branch 12 → 13 taken 541 times.
✓ Branch 12 → 29 taken 7940 times.
8481 if (conversionManager.callsOverloadedOpFct(node, 0)) {
727
1/2
✓ Branch 13 → 14 taken 541 times.
✗ Branch 13 → 215 not taken.
541 ResolverFct lhsV = [&] { return resolveValue(lhsSTy, lhs); };
728 1082 ResolverFct lhsP = [&] { return resolveAddress(lhs); };
729 1059 ResolverFct idxV = [&] { return resolveValue(indexExpr); };
730 564 ResolverFct idxP = [&] { return resolveAddress(indexExpr); };
731 541 lhs = conversionManager.callOperatorOverloadFct<2>(node, {lhsV, lhsP, idxV, idxP}, 0);
732 541 break;
733 541 }
734
735
1/2
✓ Branch 29 → 30 taken 7940 times.
✗ Branch 29 → 233 not taken.
7940 lhsSTy = lhsSTy.removeReferenceWrapper();
736
737 // Get the index value
738
1/2
✓ Branch 30 → 31 taken 7940 times.
✗ Branch 30 → 250 not taken.
7940 llvm::Value *indexValue = resolveValue(indexExpr);
739 // Come up with the address
740
8/10
✓ Branch 31 → 32 taken 7940 times.
✗ Branch 31 → 250 not taken.
✓ Branch 32 → 33 taken 489 times.
✓ Branch 32 → 36 taken 7451 times.
✓ Branch 33 → 34 taken 489 times.
✗ Branch 33 → 250 not taken.
✓ Branch 34 → 35 taken 393 times.
✓ Branch 34 → 36 taken 96 times.
✓ Branch 37 → 38 taken 393 times.
✓ Branch 37 → 49 taken 7547 times.
7940 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 → 241 not taken.
393 resolveAddress(lhs);
743
744 // Calculate address of array item
745
1/2
✓ Branch 39 → 40 taken 393 times.
✗ Branch 39 → 241 not taken.
393 llvm::Type *lhsTy = lhsSTy.toLLVMType(sourceFile);
746
1/2
✓ Branch 40 → 41 taken 393 times.
✗ Branch 40 → 241 not taken.
393 llvm::Value *indices[2] = {builder.getInt64(0), indexValue};
747
1/2
✓ Branch 45 → 46 taken 393 times.
✗ Branch 45 → 234 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 7547 times.
✗ Branch 49 → 250 not taken.
7547 lhs.ptr = resolveValue(lhsNode, lhs);
751
752
2/4
✓ Branch 50 → 51 taken 7547 times.
✗ Branch 50 → 242 not taken.
✓ Branch 51 → 52 taken 7547 times.
✗ Branch 51 → 242 not taken.
7547 llvm::Type *lhsTy = lhsSTy.getContained().toLLVMType(sourceFile);
753 // Calculate address of pointer item
754
1/2
✓ Branch 56 → 57 taken 7547 times.
✗ Branch 56 → 243 not taken.
7547 lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indexValue);
755 }
756
757 // Reset value and entry
758 7940 lhs.value = nullptr;
759 7940 lhs.entry = nullptr;
760 7940 break;
761 }
762 68399 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS: {
763 // Get the address of the struct instance
764
1/2
✓ Branch 62 → 63 taken 68399 times.
✗ Branch 62 → 265 not taken.
68399 resolveAddress(lhs);
765
1/2
✓ Branch 63 → 64 taken 68399 times.
✗ Branch 63 → 251 not taken.
68399 lhsSTy = lhsSTy.removeReferenceWrapper();
766
767 // Auto de-reference pointer
768
1/2
✓ Branch 64 → 65 taken 68399 times.
✗ Branch 64 → 265 not taken.
68399 autoDeReferencePtr(lhs.ptr, lhsSTy);
769
2/4
✓ Branch 65 → 66 taken 68399 times.
✗ Branch 65 → 265 not taken.
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 68 taken 68399 times.
68399 assert(lhsSTy.is(TY_STRUCT));
770
771 // Retrieve struct scope
772 68399 const std::string &fieldName = node->identifier;
773
1/2
✓ Branch 68 → 69 taken 68399 times.
✗ Branch 68 → 265 not taken.
68399 Scope *structScope = lhsSTy.getBodyScope();
774
775 // Retrieve field entry
776 68399 std::vector<size_t> indexPath;
777
1/2
✓ Branch 69 → 70 taken 68399 times.
✗ Branch 69 → 263 not taken.
68399 lhs.entry = structScope->symbolTable.lookupInComposedFields(fieldName, indexPath);
778
1/2
✗ Branch 70 → 71 not taken.
✓ Branch 70 → 72 taken 68399 times.
68399 assert(lhs.entry != nullptr);
779
1/2
✓ Branch 72 → 73 taken 68399 times.
✗ Branch 72 → 263 not taken.
68399 const QualType fieldSymbolType = lhs.entry->getQualType();
780
781 // Get address of the field in the struct instance
782
2/4
✓ Branch 73 → 74 taken 68399 times.
✗ Branch 73 → 255 not taken.
✓ Branch 76 → 77 taken 68399 times.
✗ Branch 76 → 252 not taken.
136798 std::vector<llvm::Value *> indices = {builder.getInt64(0)};
783
2/2
✓ Branch 93 → 80 taken 68445 times.
✓ Branch 93 → 94 taken 68399 times.
205243 for (const size_t index : indexPath)
784
2/4
✓ Branch 82 → 83 taken 68445 times.
✗ Branch 82 → 256 not taken.
✓ Branch 83 → 84 taken 68445 times.
✗ Branch 83 → 256 not taken.
68445 indices.push_back(builder.getInt32(index));
785
1/2
✓ Branch 94 → 95 taken 68399 times.
✗ Branch 94 → 261 not taken.
68399 const std::string name = fieldName + ".addr";
786
2/4
✓ Branch 96 → 97 taken 68399 times.
✗ Branch 96 → 258 not taken.
✓ Branch 97 → 98 taken 68399 times.
✗ Branch 97 → 258 not taken.
68399 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 68399 times.
✗ Branch 98 → 259 not taken.
✓ Branch 99 → 100 taken 1270 times.
✓ Branch 99 → 101 taken 67129 times.
68399 if (fieldSymbolType.isRef()) {
790 1270 lhs.ptr = nullptr;
791 1270 lhs.refPtr = memberAddr;
792 } else {
793 67129 lhs.ptr = memberAddr;
794 67129 lhs.refPtr = nullptr;
795 }
796
797 // Reset the value
798 68399 lhs.value = nullptr;
799 68399 break;
800 68399 }
801 6085 case PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS: {
802 // Make sure a value is present
803
1/2
✓ Branch 107 → 108 taken 6085 times.
✗ Branch 107 → 272 not taken.
6085 resolveValue(lhsNode, lhs);
804
805 // Allocate new local variable if required
806
2/2
✓ Branch 108 → 109 taken 2 times.
✓ Branch 108 → 119 taken 6083 times.
6085 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 → 266 not taken.
2 lhs.ptr = insertAlloca(lhs.value->getType());
809 }
810
811 // Execute operation
812
1/2
✓ Branch 119 → 120 taken 6085 times.
✗ Branch 119 → 272 not taken.
6085 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 6085 times.
✗ Branch 120 → 272 not taken.
✓ Branch 121 → 122 taken 9 times.
✓ Branch 121 → 123 taken 6076 times.
6085 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 6073 times.
✓ Branch 123 → 126 taken 3 times.
✓ Branch 124 → 125 taken 3 times.
✓ Branch 124 → 126 taken 6070 times.
✓ Branch 127 → 128 taken 6076 times.
✗ Branch 127 → 272 not taken.
6076 insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
820 6076 lhs.ptr = nullptr;
821 }
822 6085 break;
823 }
824 553 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS: {
825 // Make sure a value is present
826
1/2
✓ Branch 131 → 132 taken 553 times.
✗ Branch 131 → 279 not taken.
553 resolveValue(lhsNode, lhs);
827
828 // Allocate new local variable if required
829
2/2
✓ Branch 132 → 133 taken 2 times.
✓ Branch 132 → 143 taken 551 times.
553 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 → 273 not taken.
2 lhs.ptr = insertAlloca(lhs.value->getType());
832 }
833
834 // Execute operation
835
1/2
✓ Branch 143 → 144 taken 553 times.
✗ Branch 143 → 279 not taken.
553 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 553 times.
✗ Branch 144 → 279 not taken.
✓ Branch 145 → 146 taken 7 times.
✓ Branch 145 → 147 taken 546 times.
553 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 544 times.
✓ Branch 147 → 150 taken 2 times.
✗ Branch 148 → 149 not taken.
✓ Branch 148 → 150 taken 544 times.
✓ Branch 151 → 152 taken 546 times.
✗ Branch 151 → 279 not taken.
546 insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
843 546 lhs.ptr = nullptr;
844 }
845 553 break;
846 }
847 56 case PostfixUnaryExprNode::PostfixUnaryOp::OP_ERR_PROPAGATION: {
848 // Get the address of the Result<T> operand
849
1/2
✓ Branch 155 → 156 taken 56 times.
✗ Branch 155 → 300 not taken.
56 llvm::Value *operandPtr = resolveAddress(lhs);
850
851 // Call isErr() on the operand
852
1/2
✗ Branch 156 → 157 not taken.
✓ Branch 156 → 158 taken 56 times.
56 assert(node->errPropIsErrFct != nullptr);
853
1/2
✓ Branch 158 → 159 taken 56 times.
✗ Branch 158 → 300 not taken.
56 llvm::Function *isErrFct = stdFunctionManager.getResultIsErrFct(node->errPropIsErrFct);
854
4/8
✓ Branch 159 → 160 taken 56 times.
✗ Branch 159 → 282 not taken.
✓ Branch 161 → 162 taken 56 times.
✗ Branch 161 → 280 not taken.
✓ Branch 162 → 163 taken 56 times.
✗ Branch 162 → 280 not taken.
✓ Branch 163 → 164 taken 56 times.
✗ Branch 163 → 300 not taken.
56 llvm::Value *isErr = builder.CreateCall(isErrFct, operandPtr);
855
856 // Create blocks
857
1/2
✓ Branch 163 → 164 taken 56 times.
✗ Branch 163 → 300 not taken.
56 const std::string codeLine = node->codeLoc.toPrettyLine();
858
2/4
✓ Branch 164 → 165 taken 56 times.
✗ Branch 164 → 285 not taken.
✓ Branch 165 → 166 taken 56 times.
✗ Branch 165 → 283 not taken.
56 llvm::BasicBlock *bThen = createBlock("err.prop.then." + codeLine);
859
2/4
✓ Branch 167 → 168 taken 56 times.
✗ Branch 167 → 288 not taken.
✓ Branch 168 → 169 taken 56 times.
✗ Branch 168 → 286 not taken.
56 llvm::BasicBlock *bExit = createBlock("err.prop.exit." + codeLine);
860
1/2
✓ Branch 170 → 171 taken 56 times.
✗ Branch 170 → 298 not taken.
56 insertCondJump(isErr, bThen, bExit, Likelihood::UNLIKELY);
861
862 // Switch to then block: propagate the error as the enclosing function's Result<U>
863
1/2
✓ Branch 171 → 172 taken 56 times.
✗ Branch 171 → 298 not taken.
56 switchToBlock(bThen);
864
2/4
✓ Branch 172 → 173 taken 56 times.
✗ Branch 172 → 175 not taken.
✓ Branch 173 → 174 taken 56 times.
✗ Branch 173 → 175 not taken.
56 assert(node->errPropGetErrFct != nullptr && node->errPropCtorFct != nullptr);
865
1/2
✓ Branch 176 → 177 taken 56 times.
✗ Branch 176 → 298 not taken.
56 llvm::Function *getErrFct = stdFunctionManager.getResultGetErrFct(node->errPropGetErrFct);
866
4/8
✓ Branch 177 → 178 taken 56 times.
✗ Branch 177 → 291 not taken.
✓ Branch 179 → 180 taken 56 times.
✗ Branch 179 → 289 not taken.
✓ Branch 180 → 181 taken 56 times.
✗ Branch 180 → 289 not taken.
✓ Branch 181 → 182 taken 56 times.
✗ Branch 181 → 298 not taken.
56 llvm::Value *errorPtr = builder.CreateCall(getErrFct, operandPtr);
867
1/2
✓ Branch 181 → 182 taken 56 times.
✗ Branch 181 → 298 not taken.
56 llvm::Function *errCtorFct = stdFunctionManager.getResultErrCtorFct(node->errPropCtorFct);
868
4/8
✓ Branch 182 → 183 taken 56 times.
✗ Branch 182 → 294 not taken.
✓ Branch 184 → 185 taken 56 times.
✗ Branch 184 → 292 not taken.
✓ Branch 185 → 186 taken 56 times.
✗ Branch 185 → 292 not taken.
✓ Branch 186 → 187 taken 56 times.
✗ Branch 186 → 298 not taken.
56 llvm::Value *propagatedResult = builder.CreateCall(errCtorFct, errorPtr);
869 // Clean up all scopes between here and the enclosing function/procedure/lambda body, then return the error
870
2/4
✓ Branch 186 → 187 taken 56 times.
✗ Branch 186 → 298 not taken.
✓ Branch 187 → 188 taken 56 times.
✗ Branch 187 → 298 not taken.
56 generateScopeCleanupUpTo(node, currentScope->getFunctionScope());
871 56 blockAlreadyTerminated = true;
872
1/2
✓ Branch 188 → 189 taken 56 times.
✗ Branch 188 → 298 not taken.
56 builder.CreateRet(propagatedResult);
873
874 // Switch to exit block: unwrap the payload, which becomes the value of the whole expression
875
1/2
✓ Branch 189 → 190 taken 56 times.
✗ Branch 189 → 298 not taken.
56 switchToBlock(bExit);
876
1/2
✗ Branch 190 → 191 not taken.
✓ Branch 190 → 192 taken 56 times.
56 assert(node->errPropUnwrapFct != nullptr);
877
1/2
✓ Branch 192 → 193 taken 56 times.
✗ Branch 192 → 298 not taken.
56 llvm::Function *unwrapFct = stdFunctionManager.getResultUnwrapFct(node->errPropUnwrapFct);
878
3/6
✓ Branch 193 → 194 taken 56 times.
✗ Branch 193 → 297 not taken.
✓ Branch 195 → 196 taken 56 times.
✗ Branch 195 → 295 not taken.
✓ Branch 196 → 197 taken 56 times.
✗ Branch 196 → 295 not taken.
56 llvm::Value *unwrapped = builder.CreateCall(unwrapFct, operandPtr);
879 56 lhs = {.ptr = unwrapped};
880 56 break;
881 56 }
882 default: // GCOV_EXCL_LINE
883 throw CompilerError(UNHANDLED_BRANCH, "PostfixUnaryExpr fall-through"); // GCOV_EXCL_LINE
884 }
885
886
1/2
✓ Branch 208 → 209 taken 83574 times.
✗ Branch 208 → 310 not taken.
83574 return lhs;
887
5/14
✓ Branch 17 → 18 taken 541 times.
✗ Branch 17 → 218 not taken.
✓ Branch 18 → 19 taken 541 times.
✗ Branch 18 → 218 not taken.
✓ Branch 19 → 20 taken 541 times.
✗ Branch 19 → 218 not taken.
✓ Branch 20 → 21 taken 541 times.
✗ Branch 20 → 218 not taken.
✓ Branch 21 → 22 taken 541 times.
✗ Branch 21 → 216 not taken.
✗ Branch 218 → 219 not taken.
✗ Branch 218 → 222 not taken.
✗ Branch 220 → 221 not taken.
✗ Branch 220 → 222 not taken.
541 }
888
889 341614 std::any IRGenerator::visitAtomicExpr(const AtomicExprNode *node) {
890 // If constant
891
2/2
✓ Branch 2 → 3 taken 61082 times.
✓ Branch 2 → 9 taken 280532 times.
341614 if (node->constant) {
892
2/4
✓ Branch 3 → 4 taken 61082 times.
✗ Branch 3 → 82 not taken.
✓ Branch 4 → 5 taken 61082 times.
✗ Branch 4 → 80 not taken.
61082 const auto constantValue = std::any_cast<llvm::Constant *>(visit(node->constant));
893
1/2
✓ Branch 6 → 7 taken 61082 times.
✗ Branch 6 → 83 not taken.
122164 return LLVMExprResult{.constant = constantValue};
894 }
895
896 // If value
897
2/2
✓ Branch 9 → 10 taken 81252 times.
✓ Branch 9 → 12 taken 199280 times.
280532 if (node->value)
898
1/2
✓ Branch 10 → 11 taken 81252 times.
✗ Branch 10 → 90 not taken.
81252 return visit(node->value);
899
900 // Is assign expression
901
2/2
✓ Branch 12 → 13 taken 1704 times.
✓ Branch 12 → 15 taken 197576 times.
199280 if (node->assignExpr)
902
1/2
✓ Branch 13 → 14 taken 1704 times.
✗ Branch 13 → 90 not taken.
1704 return visit(node->assignExpr);
903
904
1/2
✓ Branch 15 → 16 taken 197576 times.
✗ Branch 15 → 90 not taken.
197576 diGenerator.setSourceLocation(node);
905
906 // Identifier (local or global variable access)
907
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 197576 times.
197576 assert(!node->identifierFragments.empty());
908
909 // Get symbol table entry
910
1/2
✓ Branch 19 → 20 taken 197576 times.
✗ Branch 19 → 90 not taken.
197576 const auto &[entry, accessScope, capture] = node->data.at(manIdx);
911
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 197576 times.
197576 assert(entry != nullptr);
912
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 197576 times.
197576 assert(accessScope != nullptr);
913
1/2
✓ Branch 24 → 25 taken 197576 times.
✗ Branch 24 → 90 not taken.
197576 const QualType varSymbolType = entry->getQualType();
914
1/2
✓ Branch 25 → 26 taken 197576 times.
✗ Branch 25 → 90 not taken.
197576 llvm::Type *varType = varSymbolType.toLLVMType(sourceFile);
915
916 // Check if external global variable
917
7/8
✓ Branch 26 → 27 taken 4352 times.
✓ Branch 26 → 30 taken 193224 times.
✓ Branch 27 → 28 taken 4352 times.
✗ Branch 27 → 90 not taken.
✓ Branch 28 → 29 taken 286 times.
✓ Branch 28 → 30 taken 4066 times.
✓ Branch 31 → 32 taken 286 times.
✓ Branch 31 → 35 taken 197290 times.
197576 if (entry->global && accessScope->isImportedBy(rootScope)) {
918 // External global variables need to be declared and allocated in the current module
919
1/2
✓ Branch 33 → 34 taken 286 times.
✗ Branch 33 → 84 not taken.
286 llvm::Value *varAddress = module->getOrInsertGlobal(entry->name, varType);
920
1/2
✓ Branch 34 → 35 taken 286 times.
✗ Branch 34 → 90 not taken.
286 updateAddress(entry, varAddress);
921 }
922
923 // Check if enum item
924
2/2
✓ Branch 35 → 36 taken 4782 times.
✓ Branch 35 → 49 taken 192794 times.
197576 if (accessScope->type == ScopeType::ENUM) {
925
1/2
✓ Branch 36 → 37 taken 4782 times.
✗ Branch 36 → 38 not taken.
4782 const auto itemNode = spice_pointer_cast<const EnumItemNode *>(entry->declNode);
926
1/2
✓ Branch 45 → 46 taken 4782 times.
✗ Branch 45 → 90 not taken.
4782 llvm::Constant *constantItemValue = llvm::ConstantInt::get(varType, itemNode->itemValue);
927
1/2
✓ Branch 46 → 47 taken 4782 times.
✗ Branch 46 → 85 not taken.
9564 return LLVMExprResult{.constant = constantItemValue, .entry = entry};
928 }
929
930
1/2
✓ Branch 49 → 50 taken 192794 times.
✗ Branch 49 → 90 not taken.
192794 llvm::Value *address = getAddress(entry);
931
1/2
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 192794 times.
192794 assert(address != nullptr);
932
933 // If this is a function/procedure reference, return it as value. The fat pointer must point at a thunk that
934 // carries the (ignored) leading capture-struct pointer, so it can be called through the uniform lambda ABI.
935
7/8
✓ Branch 52 → 53 taken 4352 times.
✓ Branch 52 → 56 taken 188442 times.
✓ Branch 53 → 54 taken 4352 times.
✗ Branch 53 → 86 not taken.
✓ Branch 54 → 55 taken 16 times.
✓ Branch 54 → 56 taken 4336 times.
✓ Branch 57 → 58 taken 16 times.
✓ Branch 57 → 64 taken 192778 times.
192794 if (entry->global && varSymbolType.isOneOf({TY_FUNCTION, TY_PROCEDURE})) {
936
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));
937
1/2
✓ Branch 60 → 61 taken 16 times.
✗ Branch 60 → 90 not taken.
16 llvm::Value *fatPtr = buildFatFctPtr(nullptr, nullptr, thunk);
938
1/2
✓ Branch 61 → 62 taken 16 times.
✗ Branch 61 → 87 not taken.
32 return LLVMExprResult{.ptr = fatPtr, .entry = entry};
939 }
940
941 // Load the address of the referenced variable
942
10/12
✓ Branch 64 → 65 taken 192778 times.
✗ Branch 64 → 90 not taken.
✓ Branch 65 → 66 taken 172472 times.
✓ Branch 65 → 69 taken 20306 times.
✓ Branch 66 → 67 taken 85 times.
✓ Branch 66 → 70 taken 172387 times.
✓ Branch 67 → 68 taken 85 times.
✗ Branch 67 → 90 not taken.
✓ Branch 68 → 69 taken 19 times.
✓ Branch 68 → 70 taken 66 times.
✓ Branch 71 → 72 taken 20325 times.
✓ Branch 71 → 75 taken 172453 times.
192778 if (varSymbolType.isRef() || (capture && capture->getMode() == BY_REFERENCE))
943
1/2
✓ Branch 72 → 73 taken 20325 times.
✗ Branch 72 → 88 not taken.
40650 return LLVMExprResult{.refPtr = address, .entry = entry};
944
945
1/2
✓ Branch 75 → 76 taken 172453 times.
✗ Branch 75 → 89 not taken.
344906 return LLVMExprResult{.ptr = address, .entry = entry};
946 }
947
948 } // namespace spice::compiler
949