GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.0% 578 / 17 / 619
Functions: 95.0% 19 / 0 / 20
Branches: 56.1% 677 / 36 / 1243

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 <SourceFile.h>
6 #include <ast/ASTNodes.h>
7 #include <driver/Driver.h>
8 #include <symboltablebuilder/ScopeHandle.h>
9
10 #include <llvm/IR/Module.h>
11
12 namespace spice::compiler {
13
14 40222 std::any IRGenerator::visitAssignExpr(const AssignExprNode *node) {
15 // Visit ternary expression
16
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 40222 times.
40222 if (node->ternaryExpr)
17 ✗ return visit(node->ternaryExpr);
18
19 40222 diGenerator.setSourceLocation(node);
20
21 // Assign or compound assign operation
22
1/2
✓ Branch 5 → 6 taken 40222 times.
✗ Branch 5 → 60 not taken.
40222 if (node->op != AssignExprNode::AssignOp::OP_NONE) {
23 40222 const ExprNode *lhsNode = node->lhs;
24 40222 const ExprNode *rhsNode = node->rhs;
25
26 // Normal assignment
27
2/2
✓ Branch 6 → 7 taken 35917 times.
✓ Branch 6 → 11 taken 4305 times.
40222 if (node->op == AssignExprNode::AssignOp::OP_ASSIGN)
28
2/4
✓ Branch 7 → 8 taken 35917 times.
✗ Branch 7 → 69 not taken.
✓ Branch 8 → 9 taken 35917 times.
✗ Branch 8 → 69 not taken.
71834 return doAssignment(lhsNode, rhsNode, node);
29
30 // Compound assignment
31 // Get symbol types of left and right side
32
1/2
✓ Branch 11 → 12 taken 4305 times.
✗ Branch 11 → 85 not taken.
4305 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
33
1/2
✓ Branch 12 → 13 taken 4305 times.
✗ Branch 12 → 85 not taken.
4305 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
34
35 // Retrieve rhs
36
2/4
✓ Branch 13 → 14 taken 4305 times.
✗ Branch 13 → 72 not taken.
✓ Branch 14 → 15 taken 4305 times.
✗ Branch 14 → 70 not taken.
4305 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
37 // Retrieve lhs
38
2/4
✓ Branch 16 → 17 taken 4305 times.
✗ Branch 16 → 75 not taken.
✓ Branch 17 → 18 taken 4305 times.
✗ Branch 17 → 73 not taken.
4305 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
39
40 4305 LLVMExprResult result;
41
10/11
✓ Branch 19 → 20 taken 2967 times.
✓ Branch 19 → 22 taken 155 times.
✓ Branch 19 → 24 taken 330 times.
✓ Branch 19 → 26 taken 152 times.
✓ Branch 19 → 28 taken 96 times.
✓ Branch 19 → 30 taken 22 times.
✓ Branch 19 → 32 taken 34 times.
✓ Branch 19 → 34 taken 56 times.
✓ Branch 19 → 36 taken 56 times.
✓ Branch 19 → 38 taken 437 times.
✗ Branch 19 → 40 not taken.
4305 switch (node->op) {
42 2967 case AssignExprNode::AssignOp::OP_PLUS_EQUAL:
43
1/2
✓ Branch 20 → 21 taken 2967 times.
✗ Branch 20 → 85 not taken.
2967 result = conversionManager.getPlusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
44 2967 break;
45 155 case AssignExprNode::AssignOp::OP_MINUS_EQUAL:
46
1/2
✓ Branch 22 → 23 taken 155 times.
✗ Branch 22 → 85 not taken.
155 result = conversionManager.getMinusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
47 155 break;
48 330 case AssignExprNode::AssignOp::OP_MUL_EQUAL:
49
1/2
✓ Branch 24 → 25 taken 330 times.
✗ Branch 24 → 85 not taken.
330 result = conversionManager.getMulEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
50 330 break;
51 152 case AssignExprNode::AssignOp::OP_DIV_EQUAL:
52
1/2
✓ Branch 26 → 27 taken 152 times.
✗ Branch 26 → 85 not taken.
152 result = conversionManager.getDivEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
53 152 break;
54 96 case AssignExprNode::AssignOp::OP_REM_EQUAL:
55
1/2
✓ Branch 28 → 29 taken 96 times.
✗ Branch 28 → 85 not taken.
96 result = conversionManager.getRemEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
56 96 break;
57 22 case AssignExprNode::AssignOp::OP_SHL_EQUAL:
58
1/2
✓ Branch 30 → 31 taken 22 times.
✗ Branch 30 → 85 not taken.
22 result = conversionManager.getSHLEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
59 22 break;
60 34 case AssignExprNode::AssignOp::OP_SHR_EQUAL:
61
1/2
✓ Branch 32 → 33 taken 34 times.
✗ Branch 32 → 85 not taken.
34 result = conversionManager.getSHREqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
62 34 break;
63 56 case AssignExprNode::AssignOp::OP_AND_EQUAL:
64
1/2
✓ Branch 34 → 35 taken 56 times.
✗ Branch 34 → 85 not taken.
56 result = conversionManager.getAndEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
65 56 break;
66 56 case AssignExprNode::AssignOp::OP_OR_EQUAL:
67
1/2
✓ Branch 36 → 37 taken 56 times.
✗ Branch 36 → 85 not taken.
56 result = conversionManager.getOrEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
68 56 break;
69 437 case AssignExprNode::AssignOp::OP_XOR_EQUAL:
70
1/2
✓ Branch 38 → 39 taken 437 times.
✗ Branch 38 → 85 not taken.
437 result = conversionManager.getXorEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
71 437 break;
72 − default: // GCOV_EXCL_LINE
73 − throw CompilerError(UNHANDLED_BRANCH, "Assign op fall-through"); // GCOV_EXCL_LINE
74 }
75
76
1/2
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 51 taken 4305 times.
4305 if (result.ptr) { // The operation allocated more memory
77 ✗ if (lhs.entry)
78 ✗ updateAddress(lhs.entry, result.ptr);
79
2/2
✓ Branch 51 → 52 taken 2903 times.
✓ Branch 51 → 57 taken 1402 times.
4305 } else if (result.value) { // The operation only updated the value
80 // Store the result
81 2903 lhs.value = result.value;
82
5/6
✓ Branch 52 → 53 taken 2801 times.
✓ Branch 52 → 55 taken 102 times.
✓ Branch 53 → 54 taken 2 times.
✓ Branch 53 → 55 taken 2799 times.
✓ Branch 56 → 57 taken 2903 times.
✗ Branch 56 → 85 not taken.
2903 insertStore(lhs.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
83 }
84
1/2
✓ Branch 57 → 58 taken 4305 times.
✗ Branch 57 → 85 not taken.
4305 return lhs;
85 }
86
87 // This is a fallthrough case -> throw an error
88 − throw CompilerError(UNHANDLED_BRANCH, "AssignStmt fall-through"); // GCOV_EXCL_LINE
89 }
90
91 2961 std::any IRGenerator::visitTernaryExpr(const TernaryExprNode *node) {
92 // Check if only one operand is present -> loop through
93
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 2961 times.
2961 if (!node->falseExpr)
94 ✗ return visit(node->condition);
95
96
1/2
✓ Branch 5 → 6 taken 2961 times.
✗ Branch 5 → 269 not taken.
2961 diGenerator.setSourceLocation(node);
97
98 // It is a ternary
99 // Retrieve the condition value
100
1/2
✓ Branch 6 → 7 taken 2961 times.
✗ Branch 6 → 269 not taken.
2961 llvm::Value *condValue = resolveValue(node->condition);
101
2/2
✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 9 taken 2959 times.
2961 const ExprNode *trueNode = node->isShortened ? node->condition : node->trueExpr;
102 2961 const ExprNode *falseNode = node->falseExpr;
103
104 2961 llvm::Value *resultValue = nullptr;
105 2961 llvm::Value *resultPtr = nullptr;
106 2961 const SymbolTableEntry *anonymousSymbol = nullptr;
107
8/10
✓ Branch 10 → 11 taken 2961 times.
✗ Branch 10 → 269 not taken.
✓ Branch 11 → 12 taken 654 times.
✓ Branch 11 → 15 taken 2307 times.
✓ Branch 12 → 13 taken 654 times.
✗ Branch 12 → 269 not taken.
✓ Branch 13 → 14 taken 574 times.
✓ Branch 13 → 15 taken 80 times.
✓ Branch 16 → 17 taken 574 times.
✓ Branch 16 → 22 taken 2387 times.
2961 if (trueNode->hasCompileTimeValue(manIdx) && falseNode->hasCompileTimeValue(manIdx)) {
108 // If both are constants, we can simply emit a selection instruction
109
1/2
✓ Branch 17 → 18 taken 574 times.
✗ Branch 17 → 269 not taken.
574 llvm::Value *trueValue = resolveValue(trueNode);
110
1/2
✓ Branch 18 → 19 taken 574 times.
✗ Branch 18 → 269 not taken.
574 llvm::Value *falseValue = resolveValue(falseNode);
111
2/4
✓ Branch 19 → 20 taken 574 times.
✗ Branch 19 → 193 not taken.
✓ Branch 20 → 21 taken 574 times.
✗ Branch 20 → 193 not taken.
574 resultValue = builder.CreateSelect(condValue, trueValue, falseValue);
112 } else {
113 // We have at least one non-constant value, use branching to not perform both sides
114
1/2
✓ Branch 22 → 23 taken 2387 times.
✗ Branch 22 → 267 not taken.
2387 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
115
2/4
✓ Branch 23 → 24 taken 2387 times.
✗ Branch 23 → 196 not taken.
✓ Branch 24 → 25 taken 2387 times.
✗ Branch 24 → 194 not taken.
2387 llvm::BasicBlock *condTrue = createBlock("cond.true." + codeLoc);
116
2/4
✓ Branch 26 → 27 taken 2387 times.
✗ Branch 26 → 199 not taken.
✓ Branch 27 → 28 taken 2387 times.
✗ Branch 27 → 197 not taken.
2387 llvm::BasicBlock *condFalse = createBlock("cond.false." + codeLoc);
117
2/4
✓ Branch 29 → 30 taken 2387 times.
✗ Branch 29 → 202 not taken.
✓ Branch 30 → 31 taken 2387 times.
✗ Branch 30 → 200 not taken.
2387 llvm::BasicBlock *condExit = createBlock("cond.exit." + codeLoc);
118
119 // Jump from original block to true or false block, depending on condition
120
1/2
✓ Branch 32 → 33 taken 2387 times.
✗ Branch 32 → 265 not taken.
2387 insertCondJump(condValue, condTrue, condFalse);
121
122 // Fill true block
123
1/2
✓ Branch 33 → 34 taken 2387 times.
✗ Branch 33 → 265 not taken.
2387 switchToBlock(condTrue);
124
1/2
✓ Branch 34 → 35 taken 2387 times.
✗ Branch 34 → 265 not taken.
2387 const QualType &resultType = node->getEvaluatedSymbolType(manIdx);
125 2387 llvm::Value *trueValue = nullptr;
126 2387 llvm::Value *truePtr = nullptr;
127 // The true branch has an expression scope for its temporaries, except for shortened ternaries (the condition is the branch)
128 2387 std::optional<ExprScopeHandle> trueScopeHandle;
129
2/2
✓ Branch 35 → 36 taken 2385 times.
✓ Branch 35 → 38 taken 2 times.
2387 if (!node->isShortened)
130
1/2
✓ Branch 36 → 37 taken 2385 times.
✗ Branch 36 → 203 not taken.
2385 trueScopeHandle.emplace(static_cast<CompilerPass *>(this), trueNode);
131
2/2
✓ Branch 39 → 40 taken 2385 times.
✓ Branch 39 → 42 taken 2 times.
2387 const Scope *trueScope = trueScopeHandle ? trueScopeHandle->getExprScope() : nullptr;
132
7/8
✓ Branch 43 → 44 taken 2381 times.
✓ Branch 43 → 46 taken 6 times.
✓ Branch 44 → 45 taken 2381 times.
✗ Branch 44 → 263 not taken.
✓ Branch 45 → 46 taken 169 times.
✓ Branch 45 → 47 taken 2212 times.
✓ Branch 48 → 49 taken 175 times.
✓ Branch 48 → 51 taken 2212 times.
2387 if (node->falseSideCallsCopyCtor || resultType.isRef()) { // both sides or only the false side needs copy ctor call
133
1/2
✓ Branch 49 → 50 taken 175 times.
✗ Branch 49 → 263 not taken.
175 truePtr = resolveAddress(trueNode);
134
2/2
✓ Branch 51 → 52 taken 8 times.
✓ Branch 51 → 66 taken 2204 times.
2212 } else if (node->trueSideCallsCopyCtor) { // only true side needs copy ctor call
135
1/2
✓ Branch 52 → 53 taken 8 times.
✗ Branch 52 → 263 not taken.
8 llvm::Value *originalPtr = resolveAddress(trueNode);
136 // Allocate storage for the copy using the ternary's own result type, not trueNode's own evaluated type:
137 // trueNode may be a reference (e.g. a 'const T&' parameter), whose LLVM type is just a pointer and would
138 // undersize this alloca for the struct value the copy ctor is about to write into it.
139
1/2
✓ Branch 56 → 57 taken 8 times.
✗ Branch 56 → 204 not taken.
8 truePtr = insertAlloca(resultType);
140
2/4
✓ Branch 61 → 62 taken 8 times.
✗ Branch 61 → 212 not taken.
✓ Branch 62 → 63 taken 8 times.
✗ Branch 62 → 210 not taken.
24 generateCtorOrDtorCall(truePtr, node->calledCopyCtor, {originalPtr});
141 } else { // neither true nor false side need copy ctor call
142
1/2
✓ Branch 66 → 67 taken 2204 times.
✗ Branch 66 → 263 not taken.
2204 trueValue = resolveValue(trueNode);
143 }
144 2387 trueScopeHandle.reset();
145 // Set the true block to the current insert point, since it could have changed in the meantime
146 2387 condTrue = builder.GetInsertBlock();
147
1/2
✓ Branch 70 → 71 taken 2387 times.
✗ Branch 70 → 263 not taken.
2387 insertJump(condExit);
148
149 // Fill false block
150
1/2
✓ Branch 71 → 72 taken 2387 times.
✗ Branch 71 → 263 not taken.
2387 switchToBlock(condFalse);
151 2387 llvm::Value *falseValue = nullptr;
152 2387 llvm::Value *falsePtr = nullptr;
153 // The false branch has an expression scope for its temporaries
154 2387 std::optional<ExprScopeHandle> falseScopeHandle;
155
1/2
✓ Branch 72 → 73 taken 2387 times.
✗ Branch 72 → 217 not taken.
2387 falseScopeHandle.emplace(static_cast<CompilerPass *>(this), falseNode);
156 2387 const Scope *falseScope = falseScopeHandle->getExprScope();
157
7/8
✓ Branch 75 → 76 taken 2379 times.
✓ Branch 75 → 78 taken 8 times.
✓ Branch 76 → 77 taken 2379 times.
✗ Branch 76 → 261 not taken.
✓ Branch 77 → 78 taken 169 times.
✓ Branch 77 → 79 taken 2210 times.
✓ Branch 80 → 81 taken 177 times.
✓ Branch 80 → 83 taken 2210 times.
2387 if (node->trueSideCallsCopyCtor || resultType.isRef()) { // both sides or only the true side needs copy ctor call
158
1/2
✓ Branch 81 → 82 taken 177 times.
✗ Branch 81 → 261 not taken.
177 falsePtr = resolveAddress(falseNode);
159
2/2
✓ Branch 83 → 84 taken 6 times.
✓ Branch 83 → 98 taken 2204 times.
2210 } else if (node->falseSideCallsCopyCtor) { // only false side needs copy ctor call
160
1/2
✓ Branch 84 → 85 taken 6 times.
✗ Branch 84 → 261 not taken.
6 llvm::Value *originalPtr = resolveAddress(falseNode);
161 // See the analogous truePtr allocation above: use the ternary's result type, not falseNode's own
162 // (possibly reference-qualified) evaluated type.
163
1/2
✓ Branch 88 → 89 taken 6 times.
✗ Branch 88 → 218 not taken.
6 falsePtr = insertAlloca(resultType);
164
2/4
✓ Branch 93 → 94 taken 6 times.
✗ Branch 93 → 226 not taken.
✓ Branch 94 → 95 taken 6 times.
✗ Branch 94 → 224 not taken.
18 generateCtorOrDtorCall(falsePtr, node->calledCopyCtor, {originalPtr});
165 } else { // neither true nor false side need copy ctor call
166
1/2
✓ Branch 98 → 99 taken 2204 times.
✗ Branch 98 → 261 not taken.
2204 falseValue = resolveValue(falseNode);
167 }
168 2387 falseScopeHandle.reset();
169 // Set the true block to the current insert point, since it could have changed in the meantime
170 2387 condFalse = builder.GetInsertBlock();
171
1/2
✓ Branch 102 → 103 taken 2387 times.
✗ Branch 102 → 261 not taken.
2387 insertJump(condExit);
172
173 // Fill the exit block
174
1/2
✓ Branch 103 → 104 taken 2387 times.
✗ Branch 103 → 261 not taken.
2387 switchToBlock(condExit);
175
9/10
✓ Branch 104 → 105 taken 2379 times.
✓ Branch 104 → 108 taken 8 times.
✓ Branch 105 → 106 taken 2373 times.
✓ Branch 105 → 108 taken 6 times.
✓ Branch 106 → 107 taken 2373 times.
✗ Branch 106 → 261 not taken.
✓ Branch 107 → 108 taken 169 times.
✓ Branch 107 → 109 taken 2204 times.
✓ Branch 110 → 111 taken 183 times.
✓ Branch 110 → 133 taken 2204 times.
2387 if (node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor || resultType.isRef()) { // one side calls copy ctor
176
3/6
✓ Branch 111 → 112 taken 183 times.
✗ Branch 111 → 231 not taken.
✓ Branch 112 → 113 taken 183 times.
✗ Branch 112 → 231 not taken.
✓ Branch 113 → 114 taken 183 times.
✗ Branch 113 → 231 not taken.
183 llvm::PHINode *phiInst = builder.CreatePHI(builder.getPtrTy(), 2, "cond.result");
177
1/2
✓ Branch 114 → 115 taken 183 times.
✗ Branch 114 → 261 not taken.
183 phiInst->addIncoming(truePtr, condTrue);
178
1/2
✓ Branch 115 → 116 taken 183 times.
✗ Branch 115 → 261 not taken.
183 phiInst->addIncoming(falsePtr, condFalse);
179
3/4
✓ Branch 116 → 117 taken 8 times.
✓ Branch 116 → 131 taken 175 times.
✗ Branch 117 → 118 not taken.
✓ Branch 117 → 131 taken 8 times.
183 if (node->trueSideCallsCopyCtor && node->falseSideCallsCopyCtor) { // both sides need copy ctor call
180 ✗ resultPtr = insertAlloca(resultType);
181 ✗ generateCtorOrDtorCall(resultPtr, node->calledCopyCtor, {phiInst});
182 } else {
183 183 resultPtr = phiInst;
184 }
185 } else { // neither true nor false side calls copy ctor
186
1/2
✗ Branch 133 → 134 not taken.
✓ Branch 133 → 135 taken 2204 times.
2204 assert(trueValue != nullptr);
187
3/6
✓ Branch 135 → 136 taken 2204 times.
✗ Branch 135 → 245 not taken.
✓ Branch 136 → 137 taken 2204 times.
✗ Branch 136 → 245 not taken.
✓ Branch 137 → 138 taken 2204 times.
✗ Branch 137 → 245 not taken.
2204 llvm::PHINode *phiInst = builder.CreatePHI(resultType.toLLVMType(sourceFile), 2, "cond.result");
188
1/2
✓ Branch 138 → 139 taken 2204 times.
✗ Branch 138 → 261 not taken.
2204 phiInst->addIncoming(trueValue, condTrue);
189
1/2
✓ Branch 139 → 140 taken 2204 times.
✗ Branch 139 → 261 not taken.
2204 phiInst->addIncoming(falseValue, condFalse);
190 2204 resultValue = phiInst;
191 }
192
193 // If we have an anonymous symbol for this ternary expr, make sure that it has an address to reference.
194
1/2
✓ Branch 141 → 142 taken 2387 times.
✗ Branch 141 → 261 not taken.
2387 anonymousSymbol = currentScope->symbolTable.lookupAnonymous(node);
195
2/2
✓ Branch 142 → 143 taken 53 times.
✓ Branch 142 → 153 taken 2334 times.
2387 if (anonymousSymbol != nullptr) {
196
2/2
✓ Branch 143 → 144 taken 4 times.
✓ Branch 143 → 152 taken 49 times.
53 if (!resultPtr) {
197
2/4
✓ Branch 147 → 148 taken 4 times.
✗ Branch 147 → 246 not taken.
✓ Branch 148 → 149 taken 4 times.
✗ Branch 148 → 246 not taken.
4 resultPtr = insertAlloca(anonymousSymbol->getQualType());
198
1/2
✓ Branch 151 → 152 taken 4 times.
✗ Branch 151 → 261 not taken.
4 insertStore(resultValue, resultPtr);
199 }
200
1/2
✓ Branch 152 → 153 taken 53 times.
✗ Branch 152 → 261 not taken.
53 updateAddress(anonymousSymbol, resultPtr);
201 }
202
203 // Destruct the temporaries of the branch that was evaluated. This must happen here, after the result was copied out of the
204 // branch and only for the branch that was taken, since the temporaries of the other one were never constructed.
205
4/4
✓ Branch 153 → 154 taken 2385 times.
✓ Branch 153 → 157 taken 2 times.
✓ Branch 155 → 156 taken 4 times.
✓ Branch 155 → 157 taken 2381 times.
2387 const bool trueNeedsCleanup = trueScope != nullptr && !trueScope->temporaryDtorsToCall.empty();
206
3/4
✓ Branch 158 → 159 taken 2387 times.
✗ Branch 158 → 162 not taken.
✓ Branch 160 → 161 taken 2 times.
✓ Branch 160 → 162 taken 2385 times.
2387 const bool falseNeedsCleanup = falseScope != nullptr && !falseScope->temporaryDtorsToCall.empty();
207
4/4
✓ Branch 163 → 164 taken 2383 times.
✓ Branch 163 → 165 taken 4 times.
✓ Branch 164 → 165 taken 2 times.
✓ Branch 164 → 184 taken 2381 times.
2387 if (trueNeedsCleanup || falseNeedsCleanup) {
208
2/4
✓ Branch 165 → 166 taken 6 times.
✗ Branch 165 → 254 not taken.
✓ Branch 166 → 167 taken 6 times.
✗ Branch 166 → 252 not taken.
6 llvm::BasicBlock *bCleanTrue = createBlock("cond.cleanup.true." + codeLoc);
209
2/4
✓ Branch 168 → 169 taken 6 times.
✗ Branch 168 → 257 not taken.
✓ Branch 169 → 170 taken 6 times.
✗ Branch 169 → 255 not taken.
6 llvm::BasicBlock *bCleanFalse = createBlock("cond.cleanup.false." + codeLoc);
210
2/4
✓ Branch 171 → 172 taken 6 times.
✗ Branch 171 → 260 not taken.
✓ Branch 172 → 173 taken 6 times.
✗ Branch 172 → 258 not taken.
6 llvm::BasicBlock *bCleanExit = createBlock("cond.cleanup.exit." + codeLoc);
211
1/2
✓ Branch 174 → 175 taken 6 times.
✗ Branch 174 → 261 not taken.
6 insertCondJump(condValue, bCleanTrue, bCleanFalse);
212
213
1/2
✓ Branch 175 → 176 taken 6 times.
✗ Branch 175 → 261 not taken.
6 switchToBlock(bCleanTrue);
214
2/2
✓ Branch 176 → 177 taken 4 times.
✓ Branch 176 → 178 taken 2 times.
6 if (trueNeedsCleanup)
215
1/2
✓ Branch 177 → 178 taken 4 times.
✗ Branch 177 → 261 not taken.
4 generateTemporariesCleanup(trueScope, trueNode);
216
1/2
✓ Branch 178 → 179 taken 6 times.
✗ Branch 178 → 261 not taken.
6 insertJump(bCleanExit);
217
218
1/2
✓ Branch 179 → 180 taken 6 times.
✗ Branch 179 → 261 not taken.
6 switchToBlock(bCleanFalse);
219
2/2
✓ Branch 180 → 181 taken 2 times.
✓ Branch 180 → 182 taken 4 times.
6 if (falseNeedsCleanup)
220
1/2
✓ Branch 181 → 182 taken 2 times.
✗ Branch 181 → 261 not taken.
2 generateTemporariesCleanup(falseScope, falseNode);
221
1/2
✓ Branch 182 → 183 taken 6 times.
✗ Branch 182 → 261 not taken.
6 insertJump(bCleanExit);
222
223
1/2
✓ Branch 183 → 184 taken 6 times.
✗ Branch 183 → 261 not taken.
6 switchToBlock(bCleanExit);
224 }
225 2387 }
226
227
1/2
✓ Branch 188 → 189 taken 2961 times.
✗ Branch 188 → 268 not taken.
5922 return LLVMExprResult{.value = resultValue, .ptr = resultPtr, .entry = anonymousSymbol};
228 }
229
230 4536 std::any IRGenerator::visitLogicalOrExpr(const LogicalOrExprNode *node) {
231 // Check if only one operand is present -> loop through
232
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 4536 times.
4536 if (node->operands.size() == 1)
233 ✗ return visit(node->operands.front());
234
235
1/2
✓ Branch 7 → 8 taken 4536 times.
✗ Branch 7 → 104 not taken.
4536 diGenerator.setSourceLocation(node);
236
237 // It is a logical or expression
238 // Create exit block for short-circuiting
239
1/2
✓ Branch 8 → 9 taken 4536 times.
✗ Branch 8 → 104 not taken.
4536 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
240
2/4
✓ Branch 9 → 10 taken 4536 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 4536 times.
✗ Branch 10 → 79 not taken.
4536 llvm::BasicBlock *bExit = createBlock("lor.exit." + codeLoc);
241
242 // Visit the first operand
243
1/2
✓ Branch 13 → 14 taken 4536 times.
✗ Branch 13 → 102 not taken.
4536 llvm::Value *firstOperandValue = resolveValue(node->operands.front());
244
245 // Prepare an array for value-to-block-mapping
246 4536 std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks;
247
1/2
✓ Branch 15 → 16 taken 4536 times.
✗ Branch 15 → 100 not taken.
4536 shortCircuitBlocks.reserve(node->operands.size());
248 // The first element is the first operand value with the original block
249
1/2
✓ Branch 17 → 18 taken 4536 times.
✗ Branch 17 → 82 not taken.
4536 shortCircuitBlocks.emplace_back(builder.GetInsertBlock(), firstOperandValue);
250 // Create a block for each additional operand and save it to the mapping
251
2/2
✓ Branch 31 → 19 taken 5900 times.
✓ Branch 31 → 32 taken 4536 times.
10436 for (size_t i = 1; i < node->operands.size(); i++)
252
6/12
✓ Branch 19 → 20 taken 5900 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 5900 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 5900 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 5900 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 5900 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 5900 times.
✗ Branch 24 → 83 not taken.
5900 shortCircuitBlocks.emplace_back(createBlock("lor." + std::to_string(i) + "." + codeLoc), nullptr);
253 // Create conditional jump to the exit block if the first operand was true, otherwise to the next block
254
2/4
✓ Branch 32 → 33 taken 4536 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 4536 times.
✗ Branch 33 → 100 not taken.
4536 insertCondJump(firstOperandValue, bExit, shortCircuitBlocks.at(1).first);
255
256 // Create block for each operand
257
2/2
✓ Branch 50 → 35 taken 5900 times.
✓ Branch 50 → 51 taken 4536 times.
10436 for (size_t i = 1; i < node->operands.size(); i++) {
258 // Switch to the next block
259
2/4
✓ Branch 35 → 36 taken 5900 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 5900 times.
✗ Branch 36 → 100 not taken.
5900 switchToBlock(shortCircuitBlocks.at(i).first);
260 // Evaluate operand and save the result in the mapping. The temporaries of the operand are destructed within its block, since
261 // they only exist if the operand was evaluated
262
2/4
✓ Branch 38 → 39 taken 5900 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 5900 times.
✗ Branch 39 → 100 not taken.
5900 shortCircuitBlocks.at(i).second = resolveValueInExprScope(node->operands[i]);
263 // Replace the array entry with the current insert block, since the insert block could have changed in the meantime
264
1/2
✓ Branch 41 → 42 taken 5900 times.
✗ Branch 41 → 100 not taken.
5900 shortCircuitBlocks.at(i).first = builder.GetInsertBlock();
265 // Check if there are more blocks to process
266
2/2
✓ Branch 43 → 44 taken 4536 times.
✓ Branch 43 → 45 taken 1364 times.
5900 if (i == node->operands.size() - 1) {
267 // Insert a simple jump to the exit block for the last block
268
1/2
✓ Branch 44 → 48 taken 4536 times.
✗ Branch 44 → 100 not taken.
4536 insertJump(bExit);
269 } else {
270 // Create conditional jump to the exit block if the first operand was true, otherwise to the next block
271
3/6
✓ Branch 45 → 46 taken 1364 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 1364 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 1364 times.
✗ Branch 47 → 100 not taken.
1364 insertCondJump(shortCircuitBlocks.at(i).second, bExit, shortCircuitBlocks.at(i + 1).first);
272 }
273 }
274
275 // Get the result with the phi node
276
1/2
✓ Branch 51 → 52 taken 4536 times.
✗ Branch 51 → 100 not taken.
4536 switchToBlock(bExit);
277
2/4
✓ Branch 52 → 53 taken 4536 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 4536 times.
✗ Branch 55 → 97 not taken.
4536 llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "lor_phi");
278
2/2
✓ Branch 72 → 58 taken 10436 times.
✓ Branch 72 → 73 taken 4536 times.
29944 for (const auto &[incomingBlock, value] : shortCircuitBlocks)
279
1/2
✓ Branch 62 → 63 taken 10436 times.
✗ Branch 62 → 98 not taken.
10436 result->addIncoming(value, incomingBlock);
280
281 // Return the result
282
1/2
✓ Branch 73 → 74 taken 4536 times.
✗ Branch 73 → 99 not taken.
4536 return LLVMExprResult{.value = result};
283 4536 }
284
285 2612 std::any IRGenerator::visitLogicalAndExpr(const LogicalAndExprNode *node) {
286 // Check if only one operand is present -> loop through
287
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 2612 times.
2612 if (node->operands.size() == 1)
288 ✗ return visit(node->operands.front());
289
290
1/2
✓ Branch 7 → 8 taken 2612 times.
✗ Branch 7 → 104 not taken.
2612 diGenerator.setSourceLocation(node);
291
292 // It is a logical and expression
293 // Create exit block for short-circuiting
294
1/2
✓ Branch 8 → 9 taken 2612 times.
✗ Branch 8 → 104 not taken.
2612 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
295
2/4
✓ Branch 9 → 10 taken 2612 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 2612 times.
✗ Branch 10 → 79 not taken.
2612 llvm::BasicBlock *bExit = createBlock("land.exit." + codeLoc);
296
297 // Visit the first operand
298
1/2
✓ Branch 13 → 14 taken 2612 times.
✗ Branch 13 → 102 not taken.
2612 llvm::Value *firstOperandValue = resolveValue(node->operands.front());
299
300 // Prepare an array for value-to-block-mapping
301 2612 std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks;
302
1/2
✓ Branch 15 → 16 taken 2612 times.
✗ Branch 15 → 100 not taken.
2612 shortCircuitBlocks.reserve(node->operands.size());
303 // The first element is the first operand value with the original block
304
1/2
✓ Branch 17 → 18 taken 2612 times.
✗ Branch 17 → 82 not taken.
2612 shortCircuitBlocks.emplace_back(builder.GetInsertBlock(), firstOperandValue);
305 // Create a block for each additional operand and save it to the mapping
306
2/2
✓ Branch 31 → 19 taken 2906 times.
✓ Branch 31 → 32 taken 2612 times.
5518 for (size_t i = 1; i < node->operands.size(); i++)
307
6/12
✓ Branch 19 → 20 taken 2906 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 2906 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 2906 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 2906 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 2906 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 2906 times.
✗ Branch 24 → 83 not taken.
2906 shortCircuitBlocks.emplace_back(createBlock("land." + std::to_string(i) + "." + codeLoc), nullptr);
308 // Create conditional jump to the exit block if the first operand was true, otherwise to the next block
309
2/4
✓ Branch 32 → 33 taken 2612 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 2612 times.
✗ Branch 33 → 100 not taken.
2612 insertCondJump(firstOperandValue, shortCircuitBlocks.at(1).first, bExit);
310
311 // Create block for each operand
312
2/2
✓ Branch 50 → 35 taken 2906 times.
✓ Branch 50 → 51 taken 2612 times.
5518 for (size_t i = 1; i < node->operands.size(); i++) {
313 // Switch to the next block
314
2/4
✓ Branch 35 → 36 taken 2906 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 2906 times.
✗ Branch 36 → 100 not taken.
2906 switchToBlock(shortCircuitBlocks.at(i).first);
315 // Evaluate operand and save the result in the mapping. The temporaries of the operand are destructed within its block, since
316 // they only exist if the operand was evaluated
317
2/4
✓ Branch 38 → 39 taken 2906 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 2906 times.
✗ Branch 39 → 100 not taken.
2906 shortCircuitBlocks.at(i).second = resolveValueInExprScope(node->operands[i]);
318 // Replace the array entry with the current insert block, since the insert block could have changed in the meantime
319
1/2
✓ Branch 41 → 42 taken 2906 times.
✗ Branch 41 → 100 not taken.
2906 shortCircuitBlocks.at(i).first = builder.GetInsertBlock();
320 // Check if there are more blocks to process
321
2/2
✓ Branch 43 → 44 taken 2612 times.
✓ Branch 43 → 45 taken 294 times.
2906 if (i == node->operands.size() - 1) {
322 // Insert a simple jump to the exit block for the last block
323
1/2
✓ Branch 44 → 48 taken 2612 times.
✗ Branch 44 → 100 not taken.
2612 insertJump(bExit);
324 } else {
325 // Create conditional jump to the exit block if the operand was true, otherwise to the next block
326
3/6
✓ Branch 45 → 46 taken 294 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 294 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 294 times.
✗ Branch 47 → 100 not taken.
294 insertCondJump(shortCircuitBlocks.at(i).second, shortCircuitBlocks.at(i + 1).first, bExit);
327 }
328 }
329
330 // Get the result with the phi node
331
1/2
✓ Branch 51 → 52 taken 2612 times.
✗ Branch 51 → 100 not taken.
2612 switchToBlock(bExit);
332
2/4
✓ Branch 52 → 53 taken 2612 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 2612 times.
✗ Branch 55 → 97 not taken.
2612 llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "land_phi");
333
2/2
✓ Branch 72 → 58 taken 5518 times.
✓ Branch 72 → 73 taken 2612 times.
16260 for (const auto &[incomingBlock, value] : shortCircuitBlocks)
334
1/2
✓ Branch 62 → 63 taken 5518 times.
✗ Branch 62 → 98 not taken.
5518 result->addIncoming(value, incomingBlock);
335
336 // Return the result
337
1/2
✓ Branch 73 → 74 taken 2612 times.
✗ Branch 73 → 99 not taken.
2612 return LLVMExprResult{.value = result};
338 2612 }
339
340 614 std::any IRGenerator::visitBitwiseOrExpr(const BitwiseOrExprNode *node) {
341 // Check if only one operand is present -> loop through
342
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 614 times.
614 if (node->operands.size() == 1)
343 ✗ return visit(node->operands.front());
344
345
1/2
✓ Branch 7 → 8 taken 614 times.
✗ Branch 7 → 34 not taken.
614 diGenerator.setSourceLocation(node);
346
347 // It is a bitwise or expression
348 // Evaluate first operand
349 614 const ExprNode *lhsNode = node->operands.front();
350
1/2
✓ Branch 9 → 10 taken 614 times.
✗ Branch 9 → 34 not taken.
614 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
351
2/4
✓ Branch 10 → 11 taken 614 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 614 times.
✗ Branch 11 → 27 not taken.
614 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
352
353 // Evaluate all additional operands
354
2/2
✓ Branch 22 → 14 taken 616 times.
✓ Branch 22 → 23 taken 614 times.
1230 for (size_t i = 1; i < node->operands.size(); i++) {
355 // Evaluate the operand
356 616 const ExprNode *rhsNode = node->operands[i];
357
1/2
✓ Branch 15 → 16 taken 616 times.
✗ Branch 15 → 33 not taken.
616 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
358
2/4
✓ Branch 16 → 17 taken 616 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 616 times.
✗ Branch 17 → 30 not taken.
616 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
359
1/2
✓ Branch 19 → 20 taken 616 times.
✗ Branch 19 → 33 not taken.
616 result = conversionManager.getBitwiseOrInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
360 }
361
362 // Return result
363
1/2
✓ Branch 23 → 24 taken 614 times.
✗ Branch 23 → 34 not taken.
614 return result;
364 }
365
366 127 std::any IRGenerator::visitBitwiseXorExpr(const BitwiseXorExprNode *node) {
367 // Check if only one operand is present -> loop through
368
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 127 times.
127 if (node->operands.size() == 1)
369 ✗ return visit(node->operands.front());
370
371
1/2
✓ Branch 7 → 8 taken 127 times.
✗ Branch 7 → 34 not taken.
127 diGenerator.setSourceLocation(node);
372
373 // It is a bitwise xor expression
374 // Evaluate first operand
375 127 const ExprNode *lhsNode = node->operands.front();
376
1/2
✓ Branch 9 → 10 taken 127 times.
✗ Branch 9 → 34 not taken.
127 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
377
2/4
✓ Branch 10 → 11 taken 127 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 127 times.
✗ Branch 11 → 27 not taken.
127 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
378
379 // Evaluate all additional operands
380
2/2
✓ Branch 22 → 14 taken 129 times.
✓ Branch 22 → 23 taken 127 times.
256 for (size_t i = 1; i < node->operands.size(); i++) {
381 // Evaluate the operand
382 129 const ExprNode *rhsNode = node->operands[i];
383
1/2
✓ Branch 15 → 16 taken 129 times.
✗ Branch 15 → 33 not taken.
129 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
384
2/4
✓ Branch 16 → 17 taken 129 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 129 times.
✗ Branch 17 → 30 not taken.
129 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
385
1/2
✓ Branch 19 → 20 taken 129 times.
✗ Branch 19 → 33 not taken.
129 result = conversionManager.getBitwiseXorInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
386 }
387
388 // Return result
389
1/2
✓ Branch 23 → 24 taken 127 times.
✗ Branch 23 → 34 not taken.
127 return result;
390 }
391
392 508 std::any IRGenerator::visitBitwiseAndExpr(const BitwiseAndExprNode *node) {
393 // Check if only one operand is present -> loop through
394
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 508 times.
508 if (node->operands.size() == 1)
395 ✗ return visit(node->operands.front());
396
397
1/2
✓ Branch 7 → 8 taken 508 times.
✗ Branch 7 → 34 not taken.
508 diGenerator.setSourceLocation(node);
398
399 // It is a bitwise and expression
400 // Evaluate first operand
401 508 const ExprNode *lhsNode = node->operands.front();
402
1/2
✓ Branch 9 → 10 taken 508 times.
✗ Branch 9 → 34 not taken.
508 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
403
2/4
✓ Branch 10 → 11 taken 508 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 508 times.
✗ Branch 11 → 27 not taken.
508 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
404
405 // Evaluate all additional operands
406
2/2
✓ Branch 22 → 14 taken 510 times.
✓ Branch 22 → 23 taken 508 times.
1018 for (size_t i = 1; i < node->operands.size(); i++) {
407 // Evaluate the operand
408 510 const ExprNode *rhsNode = node->operands[i];
409
1/2
✓ Branch 15 → 16 taken 510 times.
✗ Branch 15 → 33 not taken.
510 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
410
2/4
✓ Branch 16 → 17 taken 510 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 510 times.
✗ Branch 17 → 30 not taken.
510 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
411
1/2
✓ Branch 19 → 20 taken 510 times.
✗ Branch 19 → 33 not taken.
510 result = conversionManager.getBitwiseAndInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
412 }
413
414 // Return result
415
1/2
✓ Branch 23 → 24 taken 508 times.
✗ Branch 23 → 34 not taken.
508 return result;
416 }
417
418 37864 std::any IRGenerator::visitEqualityExpr(const EqualityExprNode *node) {
419 // Check if only one operand is present -> loop through
420
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 37864 times.
37864 if (node->operands.size() == 1)
421 ✗ return visit(node->operands.front());
422
423
1/2
✓ Branch 7 → 8 taken 37864 times.
✗ Branch 7 → 50 not taken.
37864 diGenerator.setSourceLocation(node);
424
425 // It is an equality expression
426 // Evaluate lhs
427 37864 const ExprNode *lhsNode = node->operands[0];
428
1/2
✓ Branch 9 → 10 taken 37864 times.
✗ Branch 9 → 50 not taken.
37864 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
429
2/4
✓ Branch 10 → 11 taken 37864 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 37864 times.
✗ Branch 11 → 35 not taken.
37864 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
430
431 // Evaluate rhs
432 37864 const ExprNode *rhsNode = node->operands[1];
433
1/2
✓ Branch 14 → 15 taken 37864 times.
✗ Branch 14 → 50 not taken.
37864 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
434
2/4
✓ Branch 15 → 16 taken 37864 times.
✗ Branch 15 → 40 not taken.
✓ Branch 16 → 17 taken 37864 times.
✗ Branch 16 → 38 not taken.
37864 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
435
436 // Retrieve the result value, based on the exact operator
437
2/3
✓ Branch 18 → 19 taken 31541 times.
✓ Branch 18 → 21 taken 6323 times.
✗ Branch 18 → 23 not taken.
37864 switch (node->op) {
438 31541 case EqualityExprNode::EqualityOp::OP_EQUAL:
439
1/2
✓ Branch 19 → 20 taken 31541 times.
✗ Branch 19 → 50 not taken.
31541 result = conversionManager.getEqualInst(node, result, lhsSTy, rhs, rhsSTy);
440 31541 break;
441 6323 case EqualityExprNode::EqualityOp::OP_NOT_EQUAL:
442
1/2
✓ Branch 21 → 22 taken 6323 times.
✗ Branch 21 → 50 not taken.
6323 result = conversionManager.getNotEqualInst(node, result, lhsSTy, rhs, rhsSTy);
443 6323 break;
444 − default: // GCOV_EXCL_LINE
445 − throw CompilerError(UNHANDLED_BRANCH, "EqualityExpr fall-through"); // GCOV_EXCL_LINE
446 }
447
448 // Return the result
449
1/2
✓ Branch 31 → 32 taken 37864 times.
✗ Branch 31 → 50 not taken.
37864 return result;
450 }
451
452 22601 std::any IRGenerator::visitRelationalExpr(const RelationalExprNode *node) {
453 // Check if only one operand is present -> loop through
454
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 22601 times.
22601 if (node->operands.size() == 1)
455 ✗ return visit(node->operands.front());
456
457
1/2
✓ Branch 7 → 8 taken 22601 times.
✗ Branch 7 → 54 not taken.
22601 diGenerator.setSourceLocation(node);
458
459 // It is a relational expression
460 // Evaluate lhs
461 22601 const ExprNode *lhsNode = node->operands[0];
462
1/2
✓ Branch 9 → 10 taken 22601 times.
✗ Branch 9 → 54 not taken.
22601 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
463
2/4
✓ Branch 10 → 11 taken 22601 times.
✗ Branch 10 → 41 not taken.
✓ Branch 11 → 12 taken 22601 times.
✗ Branch 11 → 39 not taken.
22601 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
464
465 // Evaluate rhs
466 22601 const ExprNode *rhsNode = node->operands[1];
467
1/2
✓ Branch 14 → 15 taken 22601 times.
✗ Branch 14 → 54 not taken.
22601 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
468
2/4
✓ Branch 15 → 16 taken 22601 times.
✗ Branch 15 → 44 not taken.
✓ Branch 16 → 17 taken 22601 times.
✗ Branch 16 → 42 not taken.
22601 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
469
470 // Retrieve the result value, based on the exact operator
471
4/5
✓ Branch 18 → 19 taken 9400 times.
✓ Branch 18 → 21 taken 4970 times.
✓ Branch 18 → 23 taken 2904 times.
✓ Branch 18 → 25 taken 5327 times.
✗ Branch 18 → 27 not taken.
22601 switch (node->op) {
472 9400 case RelationalExprNode::RelationalOp::OP_LESS:
473
1/2
✓ Branch 19 → 20 taken 9400 times.
✗ Branch 19 → 54 not taken.
9400 result = conversionManager.getLessInst(node, result, lhsSTy, rhs, rhsSTy);
474 9400 break;
475 4970 case RelationalExprNode::RelationalOp::OP_GREATER:
476
1/2
✓ Branch 21 → 22 taken 4970 times.
✗ Branch 21 → 54 not taken.
4970 result = conversionManager.getGreaterInst(node, result, lhsSTy, rhs, rhsSTy);
477 4970 break;
478 2904 case RelationalExprNode::RelationalOp::OP_LESS_EQUAL:
479
1/2
✓ Branch 23 → 24 taken 2904 times.
✗ Branch 23 → 54 not taken.
2904 result = conversionManager.getLessEqualInst(node, result, lhsSTy, rhs, rhsSTy);
480 2904 break;
481 5327 case RelationalExprNode::RelationalOp::OP_GREATER_EQUAL:
482
1/2
✓ Branch 25 → 26 taken 5327 times.
✗ Branch 25 → 54 not taken.
5327 result = conversionManager.getGreaterEqualInst(node, result, lhsSTy, rhs, rhsSTy);
483 5327 break;
484 − default: // GCOV_EXCL_LINE
485 − throw CompilerError(UNHANDLED_BRANCH, "EqualityExpr fall-through"); // GCOV_EXCL_LINE
486 }
487
488 // Return the result
489
1/2
✓ Branch 35 → 36 taken 22601 times.
✗ Branch 35 → 54 not taken.
22601 return result;
490 }
491
492 1274 std::any IRGenerator::visitShiftExpr(const ShiftExprNode *node) {
493 // Check if only one operand is present -> loop through
494
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 1274 times.
1274 if (node->operands.size() == 1)
495 ✗ return visit(node->operands.front());
496
497
1/2
✓ Branch 7 → 8 taken 1274 times.
✗ Branch 7 → 64 not taken.
1274 diGenerator.setSourceLocation(node);
498
499 // It is a shift expression
500 // Evaluate first operand
501 1274 const ExprNode *lhsNode = node->operands.front();
502
1/2
✓ Branch 9 → 10 taken 1274 times.
✗ Branch 9 → 64 not taken.
1274 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
503
2/4
✓ Branch 10 → 11 taken 1274 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 1274 times.
✗ Branch 11 → 46 not taken.
1274 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
504
505
1/2
✓ Branch 13 → 14 taken 1274 times.
✗ Branch 13 → 64 not taken.
1274 auto opQueue = node->opQueue;
506 1274 size_t operandIndex = 1;
507
2/2
✓ Branch 40 → 15 taken 1636 times.
✓ Branch 40 → 41 taken 1274 times.
2910 while (!opQueue.empty()) {
508 1636 const size_t operatorIndex = operandIndex - 1;
509 // Evaluate next operand
510 1636 const ExprNode *rhsNode = node->operands[operandIndex++];
511
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 1636 times.
1636 assert(rhsNode != nullptr);
512
1/2
✓ Branch 18 → 19 taken 1636 times.
✗ Branch 18 → 61 not taken.
1636 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
513
2/4
✓ Branch 19 → 20 taken 1636 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 1636 times.
✗ Branch 20 → 49 not taken.
1636 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
514
515 // Retrieve the result, based on the exact operator
516
2/3
✓ Branch 23 → 24 taken 1099 times.
✓ Branch 23 → 26 taken 537 times.
✗ Branch 23 → 28 not taken.
1636 switch (opQueue.front().first) {
517 1099 case ShiftExprNode::ShiftOp::OP_SHIFT_LEFT:
518
1/2
✓ Branch 24 → 25 taken 1099 times.
✗ Branch 24 → 61 not taken.
1099 lhs = conversionManager.getShiftLeftInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
519 1099 break;
520 537 case ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT:
521
1/2
✓ Branch 26 → 27 taken 537 times.
✗ Branch 26 → 61 not taken.
537 lhs = conversionManager.getShiftRightInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
522 537 break;
523 − default: // GCOV_EXCL_LINE
524 − throw CompilerError(UNHANDLED_BRANCH, "AdditiveExpr fall-through"); // GCOV_EXCL_LINE
525 }
526
527 // Retrieve the new lhs symbol type
528 1636 lhsSTy = opQueue.front().second;
529
530 1636 opQueue.pop();
531 }
532
533 // Return the result
534
1/2
✓ Branch 41 → 42 taken 1274 times.
✗ Branch 41 → 62 not taken.
1274 return lhs;
535 1274 }
536
537 20542 std::any IRGenerator::visitAdditiveExpr(const AdditiveExprNode *node) {
538 // Check if only one operand is present -> loop through
539
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 20542 times.
20542 if (node->operands.size() == 1)
540 ✗ return visit(node->operands.front());
541
542
1/2
✓ Branch 7 → 8 taken 20542 times.
✗ Branch 7 → 64 not taken.
20542 diGenerator.setSourceLocation(node);
543
544 // It is an additive expression
545 // Evaluate first operand
546 20542 const ExprNode *lhsNode = node->operands[0];
547
1/2
✓ Branch 9 → 10 taken 20542 times.
✗ Branch 9 → 64 not taken.
20542 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
548
2/4
✓ Branch 10 → 11 taken 20542 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 20542 times.
✗ Branch 11 → 46 not taken.
20542 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
549
550
1/2
✓ Branch 13 → 14 taken 20542 times.
✗ Branch 13 → 64 not taken.
20542 auto opQueue = node->opQueue;
551 20542 size_t operandIndex = 1;
552
2/2
✓ Branch 40 → 15 taken 22803 times.
✓ Branch 40 → 41 taken 20542 times.
43345 while (!opQueue.empty()) {
553 22803 const size_t operatorIndex = operandIndex - 1;
554 // Evaluate next operand
555 22803 const ExprNode *rhsNode = node->operands[operandIndex++];
556
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 22803 times.
22803 assert(rhsNode != nullptr);
557
1/2
✓ Branch 18 → 19 taken 22803 times.
✗ Branch 18 → 61 not taken.
22803 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
558
2/4
✓ Branch 19 → 20 taken 22803 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 22803 times.
✗ Branch 20 → 49 not taken.
22803 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
559
560 // Retrieve the result, based on the exact operator
561
2/3
✓ Branch 23 → 24 taken 13874 times.
✓ Branch 23 → 26 taken 8929 times.
✗ Branch 23 → 28 not taken.
22803 switch (opQueue.front().first) {
562 13874 case AdditiveExprNode::AdditiveOp::OP_PLUS:
563
1/2
✓ Branch 24 → 25 taken 13874 times.
✗ Branch 24 → 61 not taken.
13874 lhs = conversionManager.getPlusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
564 13874 break;
565 8929 case AdditiveExprNode::AdditiveOp::OP_MINUS:
566
1/2
✓ Branch 26 → 27 taken 8929 times.
✗ Branch 26 → 61 not taken.
8929 lhs = conversionManager.getMinusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
567 8929 break;
568 − default: // GCOV_EXCL_LINE
569 − throw CompilerError(UNHANDLED_BRANCH, "AdditiveExpr fall-through"); // GCOV_EXCL_LINE
570 }
571
572 // Retrieve the new lhs symbol type
573 22803 lhsSTy = opQueue.front().second;
574
575 22803 opQueue.pop();
576 }
577
578 // Return the result
579
1/2
✓ Branch 41 → 42 taken 20542 times.
✗ Branch 41 → 62 not taken.
20542 return lhs;
580 20542 }
581
582 4237 std::any IRGenerator::visitMultiplicativeExpr(const MultiplicativeExprNode *node) {
583 // Check if only one operand is present -> loop through
584
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 4237 times.
4237 if (node->operands.size() == 1)
585 ✗ return visit(node->operands.front());
586
587
1/2
✓ Branch 7 → 8 taken 4237 times.
✗ Branch 7 → 66 not taken.
4237 diGenerator.setSourceLocation(node);
588
589 // It is an additive expression
590 // Evaluate first operand
591 4237 const ExprNode *lhsNode = node->operands[0];
592
1/2
✓ Branch 9 → 10 taken 4237 times.
✗ Branch 9 → 66 not taken.
4237 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
593
2/4
✓ Branch 10 → 11 taken 4237 times.
✗ Branch 10 → 50 not taken.
✓ Branch 11 → 12 taken 4237 times.
✗ Branch 11 → 48 not taken.
4237 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
594
595
1/2
✓ Branch 13 → 14 taken 4237 times.
✗ Branch 13 → 66 not taken.
4237 auto opQueue = node->opQueue;
596 4237 size_t operandIndex = 1;
597
2/2
✓ Branch 42 → 15 taken 4403 times.
✓ Branch 42 → 43 taken 4237 times.
8640 while (!opQueue.empty()) {
598 4403 const size_t operatorIndex = operandIndex - 1;
599 // Evaluate next operand
600 4403 const ExprNode *rhsNode = node->operands[operandIndex++];
601
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 4403 times.
4403 assert(rhsNode != nullptr);
602
1/2
✓ Branch 18 → 19 taken 4403 times.
✗ Branch 18 → 63 not taken.
4403 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
603
2/4
✓ Branch 19 → 20 taken 4403 times.
✗ Branch 19 → 53 not taken.
✓ Branch 20 → 21 taken 4403 times.
✗ Branch 20 → 51 not taken.
4403 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
604
605 // Retrieve the result, based on the exact operator
606
3/4
✓ Branch 23 → 24 taken 3507 times.
✓ Branch 23 → 26 taken 670 times.
✓ Branch 23 → 28 taken 226 times.
✗ Branch 23 → 30 not taken.
4403 switch (opQueue.front().first) {
607 3507 case MultiplicativeExprNode::MultiplicativeOp::OP_MUL:
608
1/2
✓ Branch 24 → 25 taken 3507 times.
✗ Branch 24 → 63 not taken.
3507 result = conversionManager.getMulInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex);
609 3507 break;
610 670 case MultiplicativeExprNode::MultiplicativeOp::OP_DIV:
611
1/2
✓ Branch 26 → 27 taken 670 times.
✗ Branch 26 → 63 not taken.
670 result = conversionManager.getDivInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex);
612 670 break;
613 226 case MultiplicativeExprNode::MultiplicativeOp::OP_REM:
614
1/2
✓ Branch 28 → 29 taken 226 times.
✗ Branch 28 → 63 not taken.
226 result = conversionManager.getRemInst(node, result, lhsSTy, rhs, rhsSTy);
615 226 break;
616 − default: // GCOV_EXCL_LINE
617 − throw CompilerError(UNHANDLED_BRANCH, "MultiplicativeExpr fall-through"); // GCOV_EXCL_LINE
618 }
619
620 // Retrieve the new lhs symbol type
621 4403 lhsSTy = opQueue.front().second;
622 4403 opQueue.pop();
623 }
624
625 // Return the result
626
1/2
✓ Branch 43 → 44 taken 4237 times.
✗ Branch 43 → 64 not taken.
4237 return result;
627 4237 }
628
629 15392 std::any IRGenerator::visitCastExpr(const CastExprNode *node) {
630 // Check if only one operand is present -> loop through
631
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 15392 times.
15392 if (!node->isCast)
632 ✗ return visit(node->prefixUnaryExpr);
633
634
1/2
✓ Branch 5 → 6 taken 15392 times.
✗ Branch 5 → 19 not taken.
15392 diGenerator.setSourceLocation(node);
635
636 // It is a cast expression
637 // Retrieve target symbol type
638
1/2
✓ Branch 6 → 7 taken 15392 times.
✗ Branch 6 → 19 not taken.
15392 const QualType targetSTy = node->getEvaluatedSymbolType(manIdx);
639
640 // Evaluate rhs
641 15392 const ExprNode *rhsNode = node->assignExpr;
642
1/2
✓ Branch 7 → 8 taken 15392 times.
✗ Branch 7 → 19 not taken.
15392 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
643
2/4
✓ Branch 8 → 9 taken 15392 times.
✗ Branch 8 → 18 not taken.
✓ Branch 9 → 10 taken 15392 times.
✗ Branch 9 → 16 not taken.
15392 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
644
645 // Retrieve the result value
646
1/2
✓ Branch 11 → 12 taken 15392 times.
✗ Branch 11 → 19 not taken.
15392 const LLVMExprResult result = conversionManager.getCastInst(node, targetSTy, rhs, rhsSTy);
647
648 // Return the result
649
1/2
✓ Branch 12 → 13 taken 15392 times.
✗ Branch 12 → 19 not taken.
15392 return result;
650 }
651
652 10084 std::any IRGenerator::visitPrefixUnaryExpr(const PrefixUnaryExprNode *node) {
653 // If no operator is applied, simply visit the atomic expression
654
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 10084 times.
10084 if (node->op == PrefixUnaryExprNode::PrefixUnaryOp::OP_NONE)
655 ✗ return visit(node->postfixUnaryExpr);
656
657
1/2
✓ Branch 5 → 6 taken 10084 times.
✗ Branch 5 → 117 not taken.
10084 diGenerator.setSourceLocation(node);
658
659 // Evaluate lhs
660 10084 const ExprNode *lhsNode = node->prefixUnaryExpr;
661
1/2
✓ Branch 6 → 7 taken 10084 times.
✗ Branch 6 → 117 not taken.
10084 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
662
2/4
✓ Branch 7 → 8 taken 10084 times.
✗ Branch 7 → 87 not taken.
✓ Branch 8 → 9 taken 10084 times.
✗ Branch 8 → 85 not taken.
10084 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
663
664
7/8
✓ Branch 10 → 11 taken 1961 times.
✓ Branch 10 → 21 taken 22 times.
✓ Branch 10 → 36 taken 34 times.
✓ Branch 10 → 51 taken 4989 times.
✓ Branch 10 → 53 taken 60 times.
✓ Branch 10 → 55 taken 1300 times.
✓ Branch 10 → 64 taken 1718 times.
✗ Branch 10 → 73 not taken.
10084 switch (node->op) {
665 1961 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS: {
666 // Execute operation
667
1/2
✓ Branch 11 → 12 taken 1961 times.
✗ Branch 11 → 117 not taken.
1961 lhs = conversionManager.getPrefixMinusInst(node, lhs, lhsSTy);
668
669 // This operator can not work in-place, so we need additional memory
670
1/2
✓ Branch 16 → 17 taken 1961 times.
✗ Branch 16 → 88 not taken.
1961 lhs.ptr = insertAlloca(lhs.value->getType());
671
672 // Store the new value
673
1/2
✓ Branch 19 → 20 taken 1961 times.
✗ Branch 19 → 117 not taken.
1961 insertStore(lhs.value, lhs.ptr);
674
675 1961 break;
676 }
677 22 case PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS: {
678 // Execute operation
679
1/2
✓ Branch 21 → 22 taken 22 times.
✗ Branch 21 → 94 not taken.
22 lhs.value = conversionManager.getPrefixPlusPlusInst(node, lhs, lhsSTy).value;
680
681 // If this operation happens on a volatile variable, store the value directly
682
3/4
✓ Branch 22 → 23 taken 20 times.
✓ Branch 22 → 25 taken 2 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 20 times.
22 if (lhs.entry && lhs.entry->isVolatile)
683 ✗ insertStore(lhs.value, lhs.ptr, true);
684
685 // Save to the existing address if possible, otherwise (e.g. for literals) allocate new space
686
2/2
✓ Branch 25 → 26 taken 2 times.
✓ Branch 25 → 34 taken 20 times.
22 if (!lhs.ptr)
687
1/2
✓ Branch 30 → 31 taken 2 times.
✗ Branch 30 → 95 not taken.
2 lhs.ptr = insertAlloca(lhs.value->getType());
688
689 // Store the new value
690
1/2
✓ Branch 34 → 35 taken 22 times.
✗ Branch 34 → 117 not taken.
22 insertStore(lhs.value, lhs.ptr);
691
692 22 break;
693 }
694 34 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS: {
695 // Execute operation
696
1/2
✓ Branch 36 → 37 taken 34 times.
✗ Branch 36 → 101 not taken.
34 lhs.value = conversionManager.getPrefixMinusMinusInst(node, lhs, lhsSTy).value;
697
698 // If this operation happens on a volatile variable, store the value directly
699
3/4
✓ Branch 37 → 38 taken 32 times.
✓ Branch 37 → 40 taken 2 times.
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 32 times.
34 if (lhs.entry && lhs.entry->isVolatile)
700 ✗ insertStore(lhs.value, lhs.ptr, true);
701
702 // Save to the existing address if possible, otherwise (e.g. for literals) allocate new space
703
2/2
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 49 taken 32 times.
34 if (!lhs.ptr)
704
1/2
✓ Branch 45 → 46 taken 2 times.
✗ Branch 45 → 102 not taken.
2 lhs.ptr = insertAlloca(lhs.value->getType());
705
706 // Store the new value
707
1/2
✓ Branch 49 → 50 taken 34 times.
✗ Branch 49 → 117 not taken.
34 insertStore(lhs.value, lhs.ptr);
708
709 34 break;
710 }
711 4989 case PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT: {
712 // Execute operation
713
1/2
✓ Branch 51 → 52 taken 4989 times.
✗ Branch 51 → 117 not taken.
4989 lhs = conversionManager.getPrefixNotInst(node, lhs, lhsSTy);
714 4989 break;
715 }
716 60 case PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT: {
717 // Execute operation
718
1/2
✓ Branch 53 → 54 taken 60 times.
✗ Branch 53 → 117 not taken.
60 lhs = conversionManager.getPrefixBitwiseNotInst(node, lhs, lhsSTy);
719 60 break;
720 }
721 1300 case PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE: {
722 // If only .refPtr is filled, we can't simply rewire the fields, but need to actually perform a load.
723 // For that we can use resolveValue().
724
4/4
✓ Branch 55 → 56 taken 1265 times.
✓ Branch 55 → 58 taken 35 times.
✓ Branch 56 → 57 taken 84 times.
✓ Branch 56 → 58 taken 1181 times.
1300 const bool onlyRefPtrIsFilled = lhs.value == nullptr && lhs.ptr == nullptr;
725 // Rewire the fields
726
3/4
✓ Branch 59 → 60 taken 84 times.
✓ Branch 59 → 62 taken 1216 times.
✓ Branch 60 → 61 taken 84 times.
✗ Branch 60 → 117 not taken.
1300 llvm::Value *newRefPtr = onlyRefPtrIsFilled ? resolveValue(lhsNode, lhs) : lhs.ptr;
727 1300 llvm::Value *newPtr = lhs.value;
728 1300 lhs = {.ptr = newPtr, .refPtr = newRefPtr};
729 1300 break;
730 }
731 1718 case PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF: {
732 // If only .value is filled, we can't simply rewire the fields, but need to actually perform alloca + store.
733 // For that we can use resolveAddress().
734
4/4
✓ Branch 64 → 65 taken 248 times.
✓ Branch 64 → 67 taken 1470 times.
✓ Branch 65 → 66 taken 4 times.
✓ Branch 65 → 67 taken 244 times.
1718 const bool onlyValueIsFilled = lhs.ptr == nullptr && lhs.refPtr == nullptr;
735 // Rewire the fields
736
3/4
✓ Branch 68 → 69 taken 4 times.
✓ Branch 68 → 71 taken 1714 times.
✓ Branch 69 → 70 taken 4 times.
✗ Branch 69 → 117 not taken.
1718 llvm::Value *newValue = onlyValueIsFilled ? resolveAddress(lhs) : lhs.ptr;
737 1718 llvm::Value *newPtr = lhs.refPtr;
738 1718 lhs = {.value = newValue, .ptr = newPtr};
739 1718 break;
740 }
741 − default: // GCOV_EXCL_LINE
742 − throw CompilerError(UNHANDLED_BRANCH, "PrefixUnaryExpr fall-through"); // GCOV_EXCL_LINE
743 }
744
745
1/2
✓ Branch 81 → 82 taken 10084 times.
✗ Branch 81 → 117 not taken.
10084 return lhs;
746 }
747
748 135534 std::any IRGenerator::visitPostfixUnaryExpr(const PostfixUnaryExprNode *node) {
749 // If no operator is applied, simply visit the atomic expression
750
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 135534 times.
135534 if (node->op == PostfixUnaryExprNode::PostfixUnaryOp::OP_NONE)
751 ✗ return visit(node->atomicExpr);
752
753
1/2
✓ Branch 5 → 6 taken 135534 times.
✗ Branch 5 → 524 not taken.
135534 diGenerator.setSourceLocation(node);
754
755 // Evaluate lhs
756 135534 const ExprNode *lhsNode = node->postfixUnaryExpr;
757
1/2
✓ Branch 6 → 7 taken 135534 times.
✗ Branch 6 → 524 not taken.
135534 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
758
2/4
✓ Branch 7 → 8 taken 135534 times.
✗ Branch 7 → 342 not taken.
✓ Branch 8 → 9 taken 135534 times.
✗ Branch 8 → 340 not taken.
135534 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
759
760
5/6
✓ Branch 10 → 11 taken 16033 times.
✓ Branch 10 → 62 taken 107046 times.
✓ Branch 10 → 210 taken 11314 times.
✓ Branch 10 → 234 taken 1009 times.
✓ Branch 10 → 258 taken 132 times.
✗ Branch 10 → 328 not taken.
135534 switch (node->op) {
761 16033 case PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT: {
762 16033 const ExprNode *indexExpr = node->subscriptIndexExpr;
763
764 // Check if we need to generate a call to an overloaded operator function
765
3/4
✓ Branch 11 → 12 taken 16033 times.
✗ Branch 11 → 378 not taken.
✓ Branch 12 → 13 taken 1004 times.
✓ Branch 12 → 29 taken 15029 times.
16033 if (conversionManager.callsOverloadedOpFct(node, 0)) {
766
1/2
✓ Branch 13 → 14 taken 1004 times.
✗ Branch 13 → 343 not taken.
1004 ResolverFct lhsV = [&] { return resolveValue(lhsSTy, lhs); };
767 2008 ResolverFct lhsP = [&] { return resolveAddress(lhs); };
768 1960 ResolverFct idxV = [&] { return resolveValue(indexExpr); };
769 1052 ResolverFct idxP = [&] { return resolveAddress(indexExpr); };
770 1004 lhs = conversionManager.callOperatorOverloadFct<2>(node, {lhsV, lhsP, idxV, idxP}, 0);
771 1004 break;
772 1004 }
773
774
1/2
✓ Branch 29 → 30 taken 15029 times.
✗ Branch 29 → 361 not taken.
15029 lhsSTy = lhsSTy.removeReferenceWrapper();
775
776 // Get the index value
777
1/2
✓ Branch 30 → 31 taken 15029 times.
✗ Branch 30 → 378 not taken.
15029 llvm::Value *indexValue = resolveValue(indexExpr);
778 // Come up with the address
779
8/10
✓ Branch 31 → 32 taken 15029 times.
✗ Branch 31 → 378 not taken.
✓ Branch 32 → 33 taken 2605 times.
✓ Branch 32 → 36 taken 12424 times.
✓ Branch 33 → 34 taken 2605 times.
✗ Branch 33 → 378 not taken.
✓ Branch 34 → 35 taken 2265 times.
✓ Branch 34 → 36 taken 340 times.
✓ Branch 37 → 38 taken 2265 times.
✓ Branch 37 → 49 taken 12764 times.
15029 if (lhsSTy.isArray() && lhsSTy.getArraySize() != ARRAY_SIZE_UNKNOWN) { // Array
780 // Make sure the address is present
781
1/2
✓ Branch 38 → 39 taken 2265 times.
✗ Branch 38 → 369 not taken.
2265 resolveAddress(lhs);
782
783 // Calculate address of array item
784
1/2
✓ Branch 39 → 40 taken 2265 times.
✗ Branch 39 → 369 not taken.
2265 llvm::Type *lhsTy = lhsSTy.toLLVMType(sourceFile);
785
1/2
✓ Branch 40 → 41 taken 2265 times.
✗ Branch 40 → 369 not taken.
2265 llvm::Value *indices[2] = {builder.getInt64(0), indexValue};
786
1/2
✓ Branch 45 → 46 taken 2265 times.
✗ Branch 45 → 362 not taken.
2265 lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indices);
787 } else { // Pointer
788 // Now the pointer is the value
789
1/2
✓ Branch 49 → 50 taken 12764 times.
✗ Branch 49 → 378 not taken.
12764 lhs.ptr = resolveValue(lhsNode, lhs);
790
791
2/4
✓ Branch 50 → 51 taken 12764 times.
✗ Branch 50 → 370 not taken.
✓ Branch 51 → 52 taken 12764 times.
✗ Branch 51 → 370 not taken.
12764 llvm::Type *lhsTy = lhsSTy.getContained().toLLVMType(sourceFile);
792 // Calculate address of pointer item
793
1/2
✓ Branch 56 → 57 taken 12764 times.
✗ Branch 56 → 371 not taken.
12764 lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indexValue);
794 }
795
796 // Reset value and entry
797 15029 lhs.value = nullptr;
798 15029 lhs.entry = nullptr;
799 15029 break;
800 }
801 107046 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS: {
802 // Get the address of the struct/union instance
803
1/2
✓ Branch 62 → 63 taken 107046 times.
✗ Branch 62 → 457 not taken.
107046 resolveAddress(lhs);
804
1/2
✓ Branch 63 → 64 taken 107046 times.
✗ Branch 63 → 379 not taken.
107046 lhsSTy = lhsSTy.removeReferenceWrapper();
805
806 // Auto de-reference pointer
807
1/2
✓ Branch 64 → 65 taken 107046 times.
✗ Branch 64 → 457 not taken.
107046 autoDeReferencePtr(lhs.ptr, lhsSTy);
808
809 107046 const std::string &fieldName = node->identifier;
810
811 // Union field access is handled separately, since it is backed by a tagged { i32 tag, ..., payload } layout
812 // instead of one LLVM struct member per Spice field (see Type::toLLVMType's TY_UNION branch), and needs a
813 // runtime tag read-guard/write-update around the payload access.
814
3/4
✓ Branch 65 → 66 taken 107046 times.
✗ Branch 65 → 457 not taken.
✓ Branch 66 → 67 taken 50 times.
✓ Branch 66 → 168 taken 106996 times.
107046 if (lhsSTy.is(TY_UNION)) {
815
1/2
✓ Branch 67 → 68 taken 50 times.
✗ Branch 67 → 443 not taken.
50 Scope *unionScope = lhsSTy.getBodyScope();
816
1/2
✓ Branch 68 → 69 taken 50 times.
✗ Branch 68 → 443 not taken.
50 const SymbolTableEntry *fieldEntry = unionScope->symbolTable.lookupStrict(fieldName);
817
1/2
✗ Branch 69 → 70 not taken.
✓ Branch 69 → 71 taken 50 times.
50 assert(fieldEntry != nullptr);
818
1/2
✓ Branch 71 → 72 taken 50 times.
✗ Branch 71 → 443 not taken.
50 const QualType fieldSymbolType = fieldEntry->getQualType();
819 // Tag 0 is reserved for the "unset" state, so a field's tag is its order index shifted up by one. This makes
820 // an all-zero union (e.g. from .bss, a generic memset, or a nested aggregate's zero default) correctly unset
821 // rather than aliasing field 0, so the tag-mismatch guard below also catches accidental zero-initialization.
822 50 const auto fieldTagIndex = static_cast<uint32_t>(fieldEntry->orderIndex) + 1;
823
824
1/2
✓ Branch 72 → 73 taken 50 times.
✗ Branch 72 → 443 not taken.
50 llvm::Type *unionLLVMTy = lhsSTy.toLLVMType(sourceFile);
825 50 llvm::Value *unionBasePtr = lhs.ptr;
826
2/4
✓ Branch 75 → 76 taken 50 times.
✗ Branch 75 → 382 not taken.
✓ Branch 76 → 77 taken 50 times.
✗ Branch 76 → 380 not taken.
50 llvm::Value *tagAddr = insertStructGEP(unionLLVMTy, unionBasePtr, 0, "tag.addr");
827
828 // A plain `u.field = value` assignment is the only access that should update the tag instead of checking it:
829 // it is the sole case where this exact node is the direct, unwrapped left-hand side of a plain '=' assignment.
830 // Every other use (reads, compound-assign's read-then-store-back, address-of, pass-by-ref, or descending
831 // further into a by-value struct/union field) must first prove the field is currently active.
832
1/2
✓ Branch 79 → 80 taken 50 times.
✗ Branch 79 → 81 not taken.
50 const auto *assignParent = dynamic_cast<const AssignExprNode *>(node->parent);
833 50 const bool isDirectAssignTarget =
834
5/6
✓ Branch 82 → 83 taken 22 times.
✓ Branch 82 → 86 taken 28 times.
✓ Branch 83 → 84 taken 22 times.
✗ Branch 83 → 86 not taken.
✓ Branch 84 → 85 taken 20 times.
✓ Branch 84 → 86 taken 2 times.
50 assignParent != nullptr && assignParent->lhs == node && assignParent->op == AssignExprNode::AssignOp::OP_ASSIGN;
835
836
2/2
✓ Branch 87 → 88 taken 20 times.
✓ Branch 87 → 90 taken 30 times.
50 if (isDirectAssignTarget) {
837
2/4
✓ Branch 88 → 89 taken 20 times.
✗ Branch 88 → 443 not taken.
✓ Branch 89 → 159 taken 20 times.
✗ Branch 89 → 443 not taken.
20 insertStore(builder.getInt32(fieldTagIndex), tagAddr);
838 } else {
839 // Guard the read with a runtime tag check. This is an always-on safety check (unlike e.g. the assert
840 // statement, which is skipped in release builds), since it protects a core invariant of the union type
841 // itself, not an optional user-level debug assertion.
842
2/4
✓ Branch 93 → 94 taken 30 times.
✗ Branch 93 → 386 not taken.
✓ Branch 94 → 95 taken 30 times.
✗ Branch 94 → 386 not taken.
30 llvm::Value *tagValue = insertLoad(builder.getInt32Ty(), tagAddr);
843
4/8
✓ Branch 97 → 98 taken 30 times.
✗ Branch 97 → 392 not taken.
✓ Branch 98 → 99 taken 30 times.
✗ Branch 98 → 392 not taken.
✓ Branch 99 → 100 taken 30 times.
✗ Branch 99 → 392 not taken.
✓ Branch 100 → 101 taken 30 times.
✗ Branch 100 → 439 not taken.
30 llvm::Value *tagMatches = builder.CreateICmpEQ(tagValue, builder.getInt32(fieldTagIndex));
844
845
1/2
✓ Branch 100 → 101 taken 30 times.
✗ Branch 100 → 439 not taken.
30 const std::string &codeLine = node->codeLoc.toPrettyLine();
846
2/4
✓ Branch 101 → 102 taken 30 times.
✗ Branch 101 → 395 not taken.
✓ Branch 102 → 103 taken 30 times.
✗ Branch 102 → 393 not taken.
30 llvm::BasicBlock *bOk = createBlock("union.tag.ok." + codeLine);
847
2/4
✓ Branch 104 → 105 taken 30 times.
✗ Branch 104 → 398 not taken.
✓ Branch 105 → 106 taken 30 times.
✗ Branch 105 → 396 not taken.
30 llvm::BasicBlock *bPanic = createBlock("union.tag.panic." + codeLine);
848
1/2
✓ Branch 107 → 108 taken 30 times.
✗ Branch 107 → 437 not taken.
30 insertCondJump(tagMatches, bOk, bPanic, Likelihood::LIKELY);
849
850
1/2
✓ Branch 108 → 109 taken 30 times.
✗ Branch 108 → 437 not taken.
30 switchToBlock(bPanic);
851
1/2
✓ Branch 109 → 110 taken 30 times.
✗ Branch 109 → 437 not taken.
30 llvm::Value *stdErrValue = getStdErrValue();
852
2/4
✓ Branch 110 → 111 taken 30 times.
✗ Branch 110 → 407 not taken.
✓ Branch 111 → 112 taken 30 times.
✗ Branch 111 → 405 not taken.
60 const std::string errorMsg = "Program panicked at " + node->codeLoc.toPrettyString() +
853
3/6
✓ Branch 112 → 113 taken 30 times.
✗ Branch 112 → 403 not taken.
✓ Branch 113 → 114 taken 30 times.
✗ Branch 113 → 401 not taken.
✓ Branch 114 → 115 taken 30 times.
✗ Branch 114 → 399 not taken.
30 ": active field mismatch on union field access '" + fieldName + "'\n";
854
4/8
✓ Branch 121 → 122 taken 30 times.
✗ Branch 121 → 416 not taken.
✓ Branch 122 → 123 taken 30 times.
✗ Branch 122 → 414 not taken.
✓ Branch 123 → 124 taken 30 times.
✗ Branch 123 → 412 not taken.
✓ Branch 125 → 126 taken 30 times.
✗ Branch 125 → 411 not taken.
60 llvm::GlobalVariable *globalString = builder.CreateGlobalString(errorMsg, getUnusedGlobalName(ANON_GLOBAL_STRING_NAME));
855
1/2
✓ Branch 129 → 130 taken 30 times.
✗ Branch 129 → 133 not taken.
30 if (cliOptions.comparableOutput)
856
2/4
✓ Branch 130 → 131 taken 30 times.
✗ Branch 130 → 422 not taken.
✓ Branch 131 → 132 taken 30 times.
✗ Branch 131 → 422 not taken.
30 globalString->setAlignment(llvm::Align(4));
857
4/8
✓ Branch 133 → 134 taken 30 times.
✗ Branch 133 → 426 not taken.
✓ Branch 135 → 136 taken 30 times.
✗ Branch 135 → 423 not taken.
✓ Branch 136 → 137 taken 30 times.
✗ Branch 136 → 423 not taken.
✓ Branch 137 → 138 taken 30 times.
✗ Branch 137 → 423 not taken.
30 builder.CreateCall(stdFunctionManager.getFPrintfFct(), {stdErrValue, globalString});
858
1/2
✗ Branch 139 → 140 not taken.
✓ Branch 139 → 148 taken 30 times.
30 if (cliOptions.printsStackTraceOnAbort())
859 ✗ builder.CreateCall(stdFunctionManager.getDumpStacktraceFct(), {builder.getTrue(), builder.getFalse()});
860
6/12
✓ Branch 148 → 149 taken 30 times.
✗ Branch 148 → 434 not taken.
✓ Branch 149 → 150 taken 30 times.
✗ Branch 149 → 432 not taken.
✓ Branch 151 → 152 taken 30 times.
✗ Branch 151 → 431 not taken.
✓ Branch 152 → 153 taken 30 times.
✗ Branch 152 → 431 not taken.
✓ Branch 153 → 154 taken 30 times.
✗ Branch 153 → 431 not taken.
✓ Branch 154 → 155 taken 30 times.
✗ Branch 154 → 435 not taken.
30 builder.CreateCall(stdFunctionManager.getExitFct(), builder.getInt32(EXIT_FAILURE));
861
1/2
✓ Branch 154 → 155 taken 30 times.
✗ Branch 154 → 435 not taken.
30 builder.CreateUnreachable();
862
863
1/2
✓ Branch 155 → 156 taken 30 times.
✗ Branch 155 → 435 not taken.
30 switchToBlock(bOk);
864 30 }
865
866 // Get address of the payload (index 2: { tag, alignPad, payload })
867
2/4
✓ Branch 159 → 160 taken 50 times.
✗ Branch 159 → 442 not taken.
✓ Branch 160 → 161 taken 50 times.
✗ Branch 160 → 440 not taken.
50 llvm::Value *memberAddr = insertStructGEP(unionLLVMTy, unionBasePtr, 2, fieldName + ".addr");
868
869 // Set as ptr or refPtr, depending on the type
870
2/4
✓ Branch 162 → 163 taken 50 times.
✗ Branch 162 → 443 not taken.
✗ Branch 163 → 164 not taken.
✓ Branch 163 → 165 taken 50 times.
50 if (fieldSymbolType.isRef()) {
871 ✗ lhs.ptr = nullptr;
872 ✗ lhs.refPtr = memberAddr;
873 } else {
874 50 lhs.ptr = memberAddr;
875 50 lhs.refPtr = nullptr;
876 }
877
878 50 lhs.entry = fieldEntry;
879 50 lhs.value = nullptr;
880 50 break;
881 }
882
883
2/4
✓ Branch 168 → 169 taken 106996 times.
✗ Branch 168 → 457 not taken.
✗ Branch 169 → 170 not taken.
✓ Branch 169 → 171 taken 106996 times.
106996 assert(lhsSTy.is(TY_STRUCT));
884
885 // Retrieve struct scope
886
1/2
✓ Branch 171 → 172 taken 106996 times.
✗ Branch 171 → 457 not taken.
106996 Scope *structScope = lhsSTy.getBodyScope();
887
888 // Retrieve field entry
889 106996 std::vector<size_t> indexPath;
890
1/2
✓ Branch 172 → 173 taken 106996 times.
✗ Branch 172 → 455 not taken.
106996 lhs.entry = structScope->symbolTable.lookupInComposedFields(fieldName, indexPath);
891
1/2
✗ Branch 173 → 174 not taken.
✓ Branch 173 → 175 taken 106996 times.
106996 assert(lhs.entry != nullptr);
892
1/2
✓ Branch 175 → 176 taken 106996 times.
✗ Branch 175 → 455 not taken.
106996 const QualType fieldSymbolType = lhs.entry->getQualType();
893
894 // Get address of the field in the struct instance
895
2/4
✓ Branch 176 → 177 taken 106996 times.
✗ Branch 176 → 447 not taken.
✓ Branch 179 → 180 taken 106996 times.
✗ Branch 179 → 444 not taken.
213992 std::vector<llvm::Value *> indices = {builder.getInt64(0)};
896
2/2
✓ Branch 196 → 183 taken 107072 times.
✓ Branch 196 → 197 taken 106996 times.
321064 for (const size_t index : indexPath)
897
2/4
✓ Branch 185 → 186 taken 107072 times.
✗ Branch 185 → 448 not taken.
✓ Branch 186 → 187 taken 107072 times.
✗ Branch 186 → 448 not taken.
107072 indices.push_back(builder.getInt32(index));
898
1/2
✓ Branch 197 → 198 taken 106996 times.
✗ Branch 197 → 453 not taken.
106996 const std::string name = fieldName + ".addr";
899
2/4
✓ Branch 199 → 200 taken 106996 times.
✗ Branch 199 → 450 not taken.
✓ Branch 200 → 201 taken 106996 times.
✗ Branch 200 → 450 not taken.
106996 llvm::Value *memberAddr = insertInBoundsGEP(lhsSTy.toLLVMType(sourceFile), lhs.ptr, indices, name);
900
901 // Set as ptr or refPtr, depending on the type
902
3/4
✓ Branch 201 → 202 taken 106996 times.
✗ Branch 201 → 451 not taken.
✓ Branch 202 → 203 taken 1355 times.
✓ Branch 202 → 204 taken 105641 times.
106996 if (fieldSymbolType.isRef()) {
903 1355 lhs.ptr = nullptr;
904 1355 lhs.refPtr = memberAddr;
905 } else {
906 105641 lhs.ptr = memberAddr;
907 105641 lhs.refPtr = nullptr;
908 }
909
910 // Reset the value
911 106996 lhs.value = nullptr;
912 106996 break;
913 106996 }
914 11314 case PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS: {
915 // Make sure a value is present
916
1/2
✓ Branch 210 → 211 taken 11314 times.
✗ Branch 210 → 464 not taken.
11314 resolveValue(lhsNode, lhs);
917
918 // Allocate new local variable if required
919
2/2
✓ Branch 211 → 212 taken 4 times.
✓ Branch 211 → 222 taken 11310 times.
11314 if (!lhs.ptr) {
920
1/2
✗ Branch 212 → 213 not taken.
✓ Branch 212 → 214 taken 4 times.
4 assert(lhs.value != nullptr);
921
1/2
✓ Branch 218 → 219 taken 4 times.
✗ Branch 218 → 458 not taken.
4 lhs.ptr = insertAlloca(lhs.value->getType());
922 }
923
924 // Execute operation
925
1/2
✓ Branch 222 → 223 taken 11314 times.
✗ Branch 222 → 464 not taken.
11314 const LLVMExprResult result = conversionManager.getPostfixPlusPlusInst(node, lhs, lhsSTy);
926
927 // Save the new value to the old address
928
3/4
✓ Branch 223 → 224 taken 11314 times.
✗ Branch 223 → 464 not taken.
✓ Branch 224 → 225 taken 20 times.
✓ Branch 224 → 226 taken 11294 times.
11314 if (conversionManager.callsOverloadedOpFct(node, 0)) {
929 20 lhs.value = result.value;
930 20 lhs.ptr = result.ptr;
931 } else {
932
5/6
✓ Branch 226 → 227 taken 11288 times.
✓ Branch 226 → 229 taken 6 times.
✓ Branch 227 → 228 taken 6 times.
✓ Branch 227 → 229 taken 11282 times.
✓ Branch 230 → 231 taken 11294 times.
✗ Branch 230 → 464 not taken.
11294 insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
933 11294 lhs.ptr = nullptr;
934 }
935 11314 break;
936 }
937 1009 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS: {
938 // Make sure a value is present
939
1/2
✓ Branch 234 → 235 taken 1009 times.
✗ Branch 234 → 471 not taken.
1009 resolveValue(lhsNode, lhs);
940
941 // Allocate new local variable if required
942
2/2
✓ Branch 235 → 236 taken 4 times.
✓ Branch 235 → 246 taken 1005 times.
1009 if (!lhs.ptr) {
943
1/2
✗ Branch 236 → 237 not taken.
✓ Branch 236 → 238 taken 4 times.
4 assert(lhs.value != nullptr);
944
1/2
✓ Branch 242 → 243 taken 4 times.
✗ Branch 242 → 465 not taken.
4 lhs.ptr = insertAlloca(lhs.value->getType());
945 }
946
947 // Execute operation
948
1/2
✓ Branch 246 → 247 taken 1009 times.
✗ Branch 246 → 471 not taken.
1009 const LLVMExprResult result = conversionManager.getPostfixMinusMinusInst(node, lhs, lhsSTy);
949
950 // Save the new value to the old address
951
3/4
✓ Branch 247 → 248 taken 1009 times.
✗ Branch 247 → 471 not taken.
✓ Branch 248 → 249 taken 16 times.
✓ Branch 248 → 250 taken 993 times.
1009 if (conversionManager.callsOverloadedOpFct(node, 0)) {
952 16 lhs.value = result.value;
953 16 lhs.ptr = result.ptr;
954 } else {
955
4/6
✓ Branch 250 → 251 taken 989 times.
✓ Branch 250 → 253 taken 4 times.
✗ Branch 251 → 252 not taken.
✓ Branch 251 → 253 taken 989 times.
✓ Branch 254 → 255 taken 993 times.
✗ Branch 254 → 471 not taken.
993 insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
956 993 lhs.ptr = nullptr;
957 }
958 1009 break;
959 }
960 132 case PostfixUnaryExprNode::PostfixUnaryOp::OP_ERR_PROPAGATION: {
961 // Get the address of the Result<T> operand
962
1/2
✓ Branch 258 → 259 taken 132 times.
✗ Branch 258 → 514 not taken.
132 llvm::Value *operandPtr = resolveAddress(lhs);
963
964 // Call isErr() on the operand
965
1/2
✗ Branch 259 → 260 not taken.
✓ Branch 259 → 261 taken 132 times.
132 assert(node->errPropIsErrFct != nullptr);
966
1/2
✓ Branch 261 → 262 taken 132 times.
✗ Branch 261 → 514 not taken.
132 llvm::Function *isErrFct = stdFunctionManager.getResultIsErrFct(node->errPropIsErrFct);
967
4/8
✓ Branch 262 → 263 taken 132 times.
✗ Branch 262 → 474 not taken.
✓ Branch 264 → 265 taken 132 times.
✗ Branch 264 → 472 not taken.
✓ Branch 265 → 266 taken 132 times.
✗ Branch 265 → 472 not taken.
✓ Branch 266 → 267 taken 132 times.
✗ Branch 266 → 514 not taken.
132 llvm::Value *isErr = builder.CreateCall(isErrFct, operandPtr);
968
969 // Create blocks
970
1/2
✓ Branch 266 → 267 taken 132 times.
✗ Branch 266 → 514 not taken.
132 const std::string codeLine = node->codeLoc.toPrettyLine();
971
2/4
✓ Branch 267 → 268 taken 132 times.
✗ Branch 267 → 477 not taken.
✓ Branch 268 → 269 taken 132 times.
✗ Branch 268 → 475 not taken.
132 llvm::BasicBlock *bThen = createBlock("err.prop.then." + codeLine);
972
2/4
✓ Branch 270 → 271 taken 132 times.
✗ Branch 270 → 480 not taken.
✓ Branch 271 → 272 taken 132 times.
✗ Branch 271 → 478 not taken.
132 llvm::BasicBlock *bExit = createBlock("err.prop.exit." + codeLine);
973
1/2
✓ Branch 273 → 274 taken 132 times.
✗ Branch 273 → 512 not taken.
132 insertCondJump(isErr, bThen, bExit, Likelihood::UNLIKELY);
974
975 // Switch to then block: propagate the error as the enclosing function's Result<U>
976
1/2
✓ Branch 274 → 275 taken 132 times.
✗ Branch 274 → 512 not taken.
132 switchToBlock(bThen);
977
2/4
✓ Branch 275 → 276 taken 132 times.
✗ Branch 275 → 278 not taken.
✓ Branch 276 → 277 taken 132 times.
✗ Branch 276 → 278 not taken.
132 assert(node->errPropGetErrFct != nullptr && node->errPropCtorFct != nullptr);
978
1/2
✓ Branch 279 → 280 taken 132 times.
✗ Branch 279 → 512 not taken.
132 llvm::Function *getErrFct = stdFunctionManager.getResultGetErrFct(node->errPropGetErrFct);
979
4/8
✓ Branch 280 → 281 taken 132 times.
✗ Branch 280 → 483 not taken.
✓ Branch 282 → 283 taken 132 times.
✗ Branch 282 → 481 not taken.
✓ Branch 283 → 284 taken 132 times.
✗ Branch 283 → 481 not taken.
✓ Branch 284 → 285 taken 132 times.
✗ Branch 284 → 512 not taken.
132 llvm::Value *errorPtr = builder.CreateCall(getErrFct, operandPtr);
980
1/2
✓ Branch 284 → 285 taken 132 times.
✗ Branch 284 → 512 not taken.
132 llvm::Function *errCtorFct = stdFunctionManager.getResultErrCtorFct(node->errPropCtorFct);
981
5/8
✓ Branch 285 → 286 taken 132 times.
✗ Branch 285 → 486 not taken.
✓ Branch 287 → 288 taken 132 times.
✗ Branch 287 → 484 not taken.
✓ Branch 288 → 289 taken 132 times.
✗ Branch 288 → 484 not taken.
✓ Branch 289 → 290 taken 6 times.
✓ Branch 289 → 314 taken 126 times.
132 llvm::Value *propagatedResult = builder.CreateCall(errCtorFct, errorPtr);
982
983 // Record this propagation hop in the error return trace, if tracing is enabled for this file
984
2/2
✓ Branch 289 → 290 taken 6 times.
✓ Branch 289 → 314 taken 126 times.
132 if (sourceFile->errorReturnTracing) {
985
1/2
✓ Branch 290 → 291 taken 6 times.
✗ Branch 290 → 512 not taken.
6 llvm::Function *pushFct = stdFunctionManager.getErrTracePushFct();
986 llvm::Constant *signature =
987
3/6
✓ Branch 291 → 292 taken 6 times.
✗ Branch 291 → 495 not taken.
✓ Branch 294 → 295 taken 6 times.
✗ Branch 294 → 489 not taken.
✓ Branch 295 → 296 taken 6 times.
✗ Branch 295 → 487 not taken.
18 createGlobalStringConst("errtrace.hop.sig.", node->getEnclosingFunctionSignature(manIdx), node->codeLoc);
988
3/6
✓ Branch 299 → 300 taken 6 times.
✗ Branch 299 → 504 not taken.
✓ Branch 302 → 303 taken 6 times.
✗ Branch 302 → 498 not taken.
✓ Branch 303 → 304 taken 6 times.
✗ Branch 303 → 496 not taken.
18 llvm::Constant *fileName = createGlobalStringConst("errtrace.hop.file.", node->codeLoc.toPrettyFilePath(), node->codeLoc);
989
1/2
✓ Branch 307 → 308 taken 6 times.
✗ Branch 307 → 512 not taken.
6 llvm::Value *line = builder.getInt32(node->codeLoc.line);
990
1/2
✓ Branch 308 → 309 taken 6 times.
✗ Branch 308 → 512 not taken.
6 llvm::Value *column = builder.getInt32(node->codeLoc.col);
991
3/6
✓ Branch 309 → 310 taken 6 times.
✗ Branch 309 → 508 not taken.
✓ Branch 311 → 312 taken 6 times.
✗ Branch 311 → 505 not taken.
✓ Branch 312 → 313 taken 6 times.
✗ Branch 312 → 505 not taken.
6 builder.CreateCall(pushFct, {signature, fileName, line, column});
992 }
993
994 // Clean up all scopes between here and the enclosing function/procedure/lambda body, then return the error
995
2/4
✓ Branch 314 → 315 taken 132 times.
✗ Branch 314 → 512 not taken.
✓ Branch 315 → 316 taken 132 times.
✗ Branch 315 → 512 not taken.
132 generateScopeCleanupUpTo(node, currentScope->getFunctionScope());
996 132 blockAlreadyTerminated = true;
997
1/2
✓ Branch 316 → 317 taken 132 times.
✗ Branch 316 → 512 not taken.
132 builder.CreateRet(propagatedResult);
998
999 // Switch to exit block: unwrap the payload, which becomes the value of the whole expression
1000
1/2
✓ Branch 317 → 318 taken 132 times.
✗ Branch 317 → 512 not taken.
132 switchToBlock(bExit);
1001
1/2
✗ Branch 318 → 319 not taken.
✓ Branch 318 → 320 taken 132 times.
132 assert(node->errPropUnwrapFct != nullptr);
1002
1/2
✓ Branch 320 → 321 taken 132 times.
✗ Branch 320 → 512 not taken.
132 llvm::Function *unwrapFct = stdFunctionManager.getResultUnwrapFct(node->errPropUnwrapFct);
1003
3/6
✓ Branch 321 → 322 taken 132 times.
✗ Branch 321 → 511 not taken.
✓ Branch 323 → 324 taken 132 times.
✗ Branch 323 → 509 not taken.
✓ Branch 324 → 325 taken 132 times.
✗ Branch 324 → 509 not taken.
132 llvm::Value *unwrapped = builder.CreateCall(unwrapFct, operandPtr);
1004 132 lhs = {.ptr = unwrapped};
1005 132 break;
1006 132 }
1007 − default: // GCOV_EXCL_LINE
1008 − throw CompilerError(UNHANDLED_BRANCH, "PostfixUnaryExpr fall-through"); // GCOV_EXCL_LINE
1009 }
1010
1011
1/2
✓ Branch 336 → 337 taken 135534 times.
✗ Branch 336 → 524 not taken.
135534 return lhs;
1012
5/14
✓ Branch 17 → 18 taken 1004 times.
✗ Branch 17 → 346 not taken.
✓ Branch 18 → 19 taken 1004 times.
✗ Branch 18 → 346 not taken.
✓ Branch 19 → 20 taken 1004 times.
✗ Branch 19 → 346 not taken.
✓ Branch 20 → 21 taken 1004 times.
✗ Branch 20 → 346 not taken.
✓ Branch 21 → 22 taken 1004 times.
✗ Branch 21 → 344 not taken.
✗ Branch 346 → 347 not taken.
✗ Branch 346 → 350 not taken.
✗ Branch 348 → 349 not taken.
✗ Branch 348 → 350 not taken.
1004 }
1013
1014 542214 std::any IRGenerator::visitAtomicExpr(const AtomicExprNode *node) {
1015 // If constant
1016
2/2
✓ Branch 2 → 3 taken 102452 times.
✓ Branch 2 → 9 taken 439762 times.
542214 if (node->constant) {
1017
2/4
✓ Branch 3 → 4 taken 102452 times.
✗ Branch 3 → 82 not taken.
✓ Branch 4 → 5 taken 102452 times.
✗ Branch 4 → 80 not taken.
102452 const auto constantValue = std::any_cast<llvm::Constant *>(visit(node->constant));
1018
1/2
✓ Branch 6 → 7 taken 102452 times.
✗ Branch 6 → 83 not taken.
204904 return LLVMExprResult{.constant = constantValue};
1019 }
1020
1021 // If value
1022
2/2
✓ Branch 9 → 10 taken 120319 times.
✓ Branch 9 → 12 taken 319443 times.
439762 if (node->value)
1023
1/2
✓ Branch 10 → 11 taken 120319 times.
✗ Branch 10 → 90 not taken.
120319 return visit(node->value);
1024
1025 // Is assign expression
1026
2/2
✓ Branch 12 → 13 taken 2860 times.
✓ Branch 12 → 15 taken 316583 times.
319443 if (node->assignExpr)
1027
1/2
✓ Branch 13 → 14 taken 2860 times.
✗ Branch 13 → 90 not taken.
2860 return visit(node->assignExpr);
1028
1029
1/2
✓ Branch 15 → 16 taken 316583 times.
✗ Branch 15 → 90 not taken.
316583 diGenerator.setSourceLocation(node);
1030
1031 // Identifier (local or global variable access)
1032
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 316583 times.
316583 assert(!node->identifierFragments.empty());
1033
1034 // Get symbol table entry
1035
1/2
✓ Branch 19 → 20 taken 316583 times.
✗ Branch 19 → 90 not taken.
316583 const auto &[entry, accessScope, capture] = node->data.at(manIdx);
1036
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 316583 times.
316583 assert(entry != nullptr);
1037
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 316583 times.
316583 assert(accessScope != nullptr);
1038
1/2
✓ Branch 24 → 25 taken 316583 times.
✗ Branch 24 → 90 not taken.
316583 const QualType varSymbolType = entry->getQualType();
1039
1/2
✓ Branch 25 → 26 taken 316583 times.
✗ Branch 25 → 90 not taken.
316583 llvm::Type *varType = varSymbolType.toLLVMType(sourceFile);
1040
1041 // Check if external global variable
1042
7/8
✓ Branch 26 → 27 taken 7600 times.
✓ Branch 26 → 30 taken 308983 times.
✓ Branch 27 → 28 taken 7600 times.
✗ Branch 27 → 90 not taken.
✓ Branch 28 → 29 taken 528 times.
✓ Branch 28 → 30 taken 7072 times.
✓ Branch 31 → 32 taken 528 times.
✓ Branch 31 → 35 taken 316055 times.
316583 if (entry->global && accessScope->isImportedBy(rootScope)) {
1043 // External global variables need to be declared and allocated in the current module
1044
1/2
✓ Branch 33 → 34 taken 528 times.
✗ Branch 33 → 84 not taken.
528 llvm::Value *varAddress = module->getOrInsertGlobal(entry->name, varType);
1045
1/2
✓ Branch 34 → 35 taken 528 times.
✗ Branch 34 → 90 not taken.
528 updateAddress(entry, varAddress);
1046 }
1047
1048 // Check if enum item
1049
2/2
✓ Branch 35 → 36 taken 3385 times.
✓ Branch 35 → 49 taken 313198 times.
316583 if (accessScope->type == ScopeType::ENUM) {
1050
1/2
✓ Branch 36 → 37 taken 3385 times.
✗ Branch 36 → 38 not taken.
3385 const auto itemNode = spice_pointer_cast<const EnumItemNode *>(entry->declNode);
1051
1/2
✓ Branch 45 → 46 taken 3385 times.
✗ Branch 45 → 90 not taken.
3385 llvm::Constant *constantItemValue = llvm::ConstantInt::get(varType, itemNode->itemValue);
1052
1/2
✓ Branch 46 → 47 taken 3385 times.
✗ Branch 46 → 85 not taken.
6770 return LLVMExprResult{.constant = constantItemValue, .entry = entry};
1053 }
1054
1055
1/2
✓ Branch 49 → 50 taken 313198 times.
✗ Branch 49 → 90 not taken.
313198 llvm::Value *address = getAddress(entry);
1056
1/2
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 313198 times.
313198 assert(address != nullptr);
1057
1058 // If this is a function/procedure reference, return it as value. The fat pointer must point at a thunk that
1059 // carries the (ignored) leading capture-struct pointer, so it can be called through the uniform lambda ABI.
1060
7/8
✓ Branch 52 → 53 taken 7600 times.
✓ Branch 52 → 56 taken 305598 times.
✓ Branch 53 → 54 taken 7600 times.
✗ Branch 53 → 86 not taken.
✓ Branch 54 → 55 taken 92 times.
✓ Branch 54 → 56 taken 7508 times.
✓ Branch 57 → 58 taken 92 times.
✓ Branch 57 → 64 taken 313106 times.
313198 if (entry->global && varSymbolType.isOneOf({TY_FUNCTION, TY_PROCEDURE})) {
1061
2/4
✓ Branch 58 → 59 taken 92 times.
✗ Branch 58 → 90 not taken.
✓ Branch 59 → 60 taken 92 times.
✗ Branch 59 → 90 not taken.
92 llvm::Function *thunk = getOrCreateFatFctPtrThunk(llvm::cast<llvm::Function>(address));
1062
1/2
✓ Branch 60 → 61 taken 92 times.
✗ Branch 60 → 90 not taken.
92 llvm::Value *fatPtr = buildFatFctPtr(nullptr, nullptr, thunk);
1063
1/2
✓ Branch 61 → 62 taken 92 times.
✗ Branch 61 → 87 not taken.
184 return LLVMExprResult{.ptr = fatPtr, .entry = entry};
1064 }
1065
1066 // Load the address of the referenced variable
1067
10/12
✓ Branch 64 → 65 taken 313106 times.
✗ Branch 64 → 90 not taken.
✓ Branch 65 → 66 taken 283235 times.
✓ Branch 65 → 69 taken 29871 times.
✓ Branch 66 → 67 taken 105 times.
✓ Branch 66 → 70 taken 283130 times.
✓ Branch 67 → 68 taken 105 times.
✗ Branch 67 → 90 not taken.
✓ Branch 68 → 69 taken 39 times.
✓ Branch 68 → 70 taken 66 times.
✓ Branch 71 → 72 taken 29910 times.
✓ Branch 71 → 75 taken 283196 times.
313106 if (varSymbolType.isRef() || (capture && capture->getMode() == BY_REFERENCE))
1068
1/2
✓ Branch 72 → 73 taken 29910 times.
✗ Branch 72 → 88 not taken.
59820 return LLVMExprResult{.refPtr = address, .entry = entry};
1069
1070
1/2
✓ Branch 75 → 76 taken 283196 times.
✗ Branch 75 → 89 not taken.
566392 return LLVMExprResult{.ptr = address, .entry = entry};
1071 }
1072
1073 } // namespace spice::compiler
1074