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.2% 678 / 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 284213 std::any IRGenerator::visitAssignExpr(const AssignExprNode *node) {
15 // Visit ternary expression
16
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 284213 times.
284213 if (node->ternaryExpr)
17 ✗ return visit(node->ternaryExpr);
18
19 284213 diGenerator.setSourceLocation(node);
20
21 // Assign or compound assign operation
22
1/2
✓ Branch 5 → 6 taken 284213 times.
✗ Branch 5 → 60 not taken.
284213 if (node->op != AssignExprNode::AssignOp::OP_NONE) {
23 284213 const ExprNode *lhsNode = node->lhs;
24 284213 const ExprNode *rhsNode = node->rhs;
25
26 // Normal assignment
27
2/2
✓ Branch 6 → 7 taken 259888 times.
✓ Branch 6 → 11 taken 24325 times.
284213 if (node->op == AssignExprNode::AssignOp::OP_ASSIGN)
28
2/4
✓ Branch 7 → 8 taken 259888 times.
✗ Branch 7 → 69 not taken.
✓ Branch 8 → 9 taken 259888 times.
✗ Branch 8 → 69 not taken.
519776 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 24325 times.
✗ Branch 11 → 85 not taken.
24325 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
33
1/2
✓ Branch 12 → 13 taken 24325 times.
✗ Branch 12 → 85 not taken.
24325 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
34
35 // Retrieve rhs
36
2/4
✓ Branch 13 → 14 taken 24325 times.
✗ Branch 13 → 72 not taken.
✓ Branch 14 → 15 taken 24325 times.
✗ Branch 14 → 70 not taken.
24325 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
37 // Retrieve lhs
38
2/4
✓ Branch 16 → 17 taken 24325 times.
✗ Branch 16 → 75 not taken.
✓ Branch 17 → 18 taken 24325 times.
✗ Branch 17 → 73 not taken.
24325 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
39
40 24325 LLVMExprResult result;
41
10/11
✓ Branch 19 → 20 taken 17545 times.
✓ Branch 19 → 22 taken 549 times.
✓ Branch 19 → 24 taken 1920 times.
✓ Branch 19 → 26 taken 788 times.
✓ Branch 19 → 28 taken 446 times.
✓ Branch 19 → 30 taken 72 times.
✓ Branch 19 → 32 taken 84 times.
✓ Branch 19 → 34 taken 106 times.
✓ Branch 19 → 36 taken 156 times.
✓ Branch 19 → 38 taken 2659 times.
✗ Branch 19 → 40 not taken.
24325 switch (node->op) {
42 17545 case AssignExprNode::AssignOp::OP_PLUS_EQUAL:
43
1/2
✓ Branch 20 → 21 taken 17545 times.
✗ Branch 20 → 85 not taken.
17545 result = conversionManager.getPlusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
44 17545 break;
45 549 case AssignExprNode::AssignOp::OP_MINUS_EQUAL:
46
1/2
✓ Branch 22 → 23 taken 549 times.
✗ Branch 22 → 85 not taken.
549 result = conversionManager.getMinusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
47 549 break;
48 1920 case AssignExprNode::AssignOp::OP_MUL_EQUAL:
49
1/2
✓ Branch 24 → 25 taken 1920 times.
✗ Branch 24 → 85 not taken.
1920 result = conversionManager.getMulEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
50 1920 break;
51 788 case AssignExprNode::AssignOp::OP_DIV_EQUAL:
52
1/2
✓ Branch 26 → 27 taken 788 times.
✗ Branch 26 → 85 not taken.
788 result = conversionManager.getDivEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
53 788 break;
54 446 case AssignExprNode::AssignOp::OP_REM_EQUAL:
55
1/2
✓ Branch 28 → 29 taken 446 times.
✗ Branch 28 → 85 not taken.
446 result = conversionManager.getRemEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
56 446 break;
57 72 case AssignExprNode::AssignOp::OP_SHL_EQUAL:
58
1/2
✓ Branch 30 → 31 taken 72 times.
✗ Branch 30 → 85 not taken.
72 result = conversionManager.getSHLEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
59 72 break;
60 84 case AssignExprNode::AssignOp::OP_SHR_EQUAL:
61
1/2
✓ Branch 32 → 33 taken 84 times.
✗ Branch 32 → 85 not taken.
84 result = conversionManager.getSHREqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
62 84 break;
63 106 case AssignExprNode::AssignOp::OP_AND_EQUAL:
64
1/2
✓ Branch 34 → 35 taken 106 times.
✗ Branch 34 → 85 not taken.
106 result = conversionManager.getAndEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
65 106 break;
66 156 case AssignExprNode::AssignOp::OP_OR_EQUAL:
67
1/2
✓ Branch 36 → 37 taken 156 times.
✗ Branch 36 → 85 not taken.
156 result = conversionManager.getOrEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
68 156 break;
69 2659 case AssignExprNode::AssignOp::OP_XOR_EQUAL:
70
1/2
✓ Branch 38 → 39 taken 2659 times.
✗ Branch 38 → 85 not taken.
2659 result = conversionManager.getXorEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
71 2659 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 24325 times.
24325 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 18469 times.
✓ Branch 51 → 57 taken 5856 times.
24325 } else if (result.value) { // The operation only updated the value
80 // Store the result
81 18469 lhs.value = result.value;
82
5/6
✓ Branch 52 → 53 taken 18317 times.
✓ Branch 52 → 55 taken 152 times.
✓ Branch 53 → 54 taken 2 times.
✓ Branch 53 → 55 taken 18315 times.
✓ Branch 56 → 57 taken 18469 times.
✗ Branch 56 → 85 not taken.
18469 insertStore(lhs.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
83 }
84
1/2
✓ Branch 57 → 58 taken 24325 times.
✗ Branch 57 → 85 not taken.
24325 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 12553 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 12553 times.
12553 if (!node->falseExpr)
94 ✗ return visit(node->condition);
95
96
1/2
✓ Branch 5 → 6 taken 12553 times.
✗ Branch 5 → 269 not taken.
12553 diGenerator.setSourceLocation(node);
97
98 // It is a ternary
99 // Retrieve the condition value
100
1/2
✓ Branch 6 → 7 taken 12553 times.
✗ Branch 6 → 269 not taken.
12553 llvm::Value *condValue = resolveValue(node->condition);
101
2/2
✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 9 taken 12551 times.
12553 const ExprNode *trueNode = node->isShortened ? node->condition : node->trueExpr;
102 12553 const ExprNode *falseNode = node->falseExpr;
103
104 12553 llvm::Value *resultValue = nullptr;
105 12553 llvm::Value *resultPtr = nullptr;
106 12553 const SymbolTableEntry *anonymousSymbol = nullptr;
107
8/10
✓ Branch 10 → 11 taken 12553 times.
✗ Branch 10 → 269 not taken.
✓ Branch 11 → 12 taken 2330 times.
✓ Branch 11 → 15 taken 10223 times.
✓ Branch 12 → 13 taken 2330 times.
✗ Branch 12 → 269 not taken.
✓ Branch 13 → 14 taken 1924 times.
✓ Branch 13 → 15 taken 406 times.
✓ Branch 16 → 17 taken 1924 times.
✓ Branch 16 → 22 taken 10629 times.
12553 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 1924 times.
✗ Branch 17 → 269 not taken.
1924 llvm::Value *trueValue = resolveValue(trueNode);
110
1/2
✓ Branch 18 → 19 taken 1924 times.
✗ Branch 18 → 269 not taken.
1924 llvm::Value *falseValue = resolveValue(falseNode);
111
2/4
✓ Branch 19 → 20 taken 1924 times.
✗ Branch 19 → 193 not taken.
✓ Branch 20 → 21 taken 1924 times.
✗ Branch 20 → 193 not taken.
1924 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 10629 times.
✗ Branch 22 → 267 not taken.
10629 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
115
2/4
✓ Branch 23 → 24 taken 10629 times.
✗ Branch 23 → 196 not taken.
✓ Branch 24 → 25 taken 10629 times.
✗ Branch 24 → 194 not taken.
10629 llvm::BasicBlock *condTrue = createBlock("cond.true." + codeLoc);
116
2/4
✓ Branch 26 → 27 taken 10629 times.
✗ Branch 26 → 199 not taken.
✓ Branch 27 → 28 taken 10629 times.
✗ Branch 27 → 197 not taken.
10629 llvm::BasicBlock *condFalse = createBlock("cond.false." + codeLoc);
117
2/4
✓ Branch 29 → 30 taken 10629 times.
✗ Branch 29 → 202 not taken.
✓ Branch 30 → 31 taken 10629 times.
✗ Branch 30 → 200 not taken.
10629 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 10629 times.
✗ Branch 32 → 265 not taken.
10629 insertCondJump(condValue, condTrue, condFalse);
121
122 // Fill true block
123
1/2
✓ Branch 33 → 34 taken 10629 times.
✗ Branch 33 → 265 not taken.
10629 switchToBlock(condTrue);
124
1/2
✓ Branch 34 → 35 taken 10629 times.
✗ Branch 34 → 265 not taken.
10629 const QualType &resultType = node->getEvaluatedSymbolType(manIdx);
125 10629 llvm::Value *trueValue = nullptr;
126 10629 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 10629 std::optional<ExprScopeHandle> trueScopeHandle;
129
2/2
✓ Branch 35 → 36 taken 10627 times.
✓ Branch 35 → 38 taken 2 times.
10629 if (!node->isShortened)
130
1/2
✓ Branch 36 → 37 taken 10627 times.
✗ Branch 36 → 203 not taken.
10627 trueScopeHandle.emplace(static_cast<CompilerPass *>(this), trueNode);
131
2/2
✓ Branch 39 → 40 taken 10627 times.
✓ Branch 39 → 42 taken 2 times.
10629 const Scope *trueScope = trueScopeHandle ? trueScopeHandle->getExprScope() : nullptr;
132
7/8
✓ Branch 43 → 44 taken 10365 times.
✓ Branch 43 → 46 taken 264 times.
✓ Branch 44 → 45 taken 10365 times.
✗ Branch 44 → 263 not taken.
✓ Branch 45 → 46 taken 1643 times.
✓ Branch 45 → 47 taken 8722 times.
✓ Branch 48 → 49 taken 1907 times.
✓ Branch 48 → 51 taken 8722 times.
10629 if (node->falseSideCallsCopyCtor || resultType.isRef()) { // both sides or only the false side needs copy ctor call
133
1/2
✓ Branch 49 → 50 taken 1907 times.
✗ Branch 49 → 263 not taken.
1907 truePtr = resolveAddress(trueNode);
134
2/2
✓ Branch 51 → 52 taken 8 times.
✓ Branch 51 → 66 taken 8714 times.
8722 } 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 8714 times.
✗ Branch 66 → 263 not taken.
8714 trueValue = resolveValue(trueNode);
143 }
144 10629 trueScopeHandle.reset();
145 // Set the true block to the current insert point, since it could have changed in the meantime
146 10629 condTrue = builder.GetInsertBlock();
147
1/2
✓ Branch 70 → 71 taken 10629 times.
✗ Branch 70 → 263 not taken.
10629 insertJump(condExit);
148
149 // Fill false block
150
1/2
✓ Branch 71 → 72 taken 10629 times.
✗ Branch 71 → 263 not taken.
10629 switchToBlock(condFalse);
151 10629 llvm::Value *falseValue = nullptr;
152 10629 llvm::Value *falsePtr = nullptr;
153 // The false branch has an expression scope for its temporaries
154 10629 std::optional<ExprScopeHandle> falseScopeHandle;
155
1/2
✓ Branch 72 → 73 taken 10629 times.
✗ Branch 72 → 217 not taken.
10629 falseScopeHandle.emplace(static_cast<CompilerPass *>(this), falseNode);
156 10629 const Scope *falseScope = falseScopeHandle->getExprScope();
157
7/8
✓ Branch 75 → 76 taken 10621 times.
✓ Branch 75 → 78 taken 8 times.
✓ Branch 76 → 77 taken 10621 times.
✗ Branch 76 → 261 not taken.
✓ Branch 77 → 78 taken 1643 times.
✓ Branch 77 → 79 taken 8978 times.
✓ Branch 80 → 81 taken 1651 times.
✓ Branch 80 → 83 taken 8978 times.
10629 if (node->trueSideCallsCopyCtor || resultType.isRef()) { // both sides or only the true side needs copy ctor call
158
1/2
✓ Branch 81 → 82 taken 1651 times.
✗ Branch 81 → 261 not taken.
1651 falsePtr = resolveAddress(falseNode);
159
2/2
✓ Branch 83 → 84 taken 264 times.
✓ Branch 83 → 98 taken 8714 times.
8978 } else if (node->falseSideCallsCopyCtor) { // only false side needs copy ctor call
160
1/2
✓ Branch 84 → 85 taken 264 times.
✗ Branch 84 → 261 not taken.
264 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 264 times.
✗ Branch 88 → 218 not taken.
264 falsePtr = insertAlloca(resultType);
164
2/4
✓ Branch 93 → 94 taken 264 times.
✗ Branch 93 → 226 not taken.
✓ Branch 94 → 95 taken 264 times.
✗ Branch 94 → 224 not taken.
792 generateCtorOrDtorCall(falsePtr, node->calledCopyCtor, {originalPtr});
165 } else { // neither true nor false side need copy ctor call
166
1/2
✓ Branch 98 → 99 taken 8714 times.
✗ Branch 98 → 261 not taken.
8714 falseValue = resolveValue(falseNode);
167 }
168 10629 falseScopeHandle.reset();
169 // Set the true block to the current insert point, since it could have changed in the meantime
170 10629 condFalse = builder.GetInsertBlock();
171
1/2
✓ Branch 102 → 103 taken 10629 times.
✗ Branch 102 → 261 not taken.
10629 insertJump(condExit);
172
173 // Fill the exit block
174
1/2
✓ Branch 103 → 104 taken 10629 times.
✗ Branch 103 → 261 not taken.
10629 switchToBlock(condExit);
175
9/10
✓ Branch 104 → 105 taken 10621 times.
✓ Branch 104 → 108 taken 8 times.
✓ Branch 105 → 106 taken 10357 times.
✓ Branch 105 → 108 taken 264 times.
✓ Branch 106 → 107 taken 10357 times.
✗ Branch 106 → 261 not taken.
✓ Branch 107 → 108 taken 1643 times.
✓ Branch 107 → 109 taken 8714 times.
✓ Branch 110 → 111 taken 1915 times.
✓ Branch 110 → 133 taken 8714 times.
10629 if (node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor || resultType.isRef()) { // one side calls copy ctor
176
3/6
✓ Branch 111 → 112 taken 1915 times.
✗ Branch 111 → 231 not taken.
✓ Branch 112 → 113 taken 1915 times.
✗ Branch 112 → 231 not taken.
✓ Branch 113 → 114 taken 1915 times.
✗ Branch 113 → 231 not taken.
1915 llvm::PHINode *phiInst = builder.CreatePHI(builder.getPtrTy(), 2, "cond.result");
177
1/2
✓ Branch 114 → 115 taken 1915 times.
✗ Branch 114 → 261 not taken.
1915 phiInst->addIncoming(truePtr, condTrue);
178
1/2
✓ Branch 115 → 116 taken 1915 times.
✗ Branch 115 → 261 not taken.
1915 phiInst->addIncoming(falsePtr, condFalse);
179
3/4
✓ Branch 116 → 117 taken 8 times.
✓ Branch 116 → 131 taken 1907 times.
✗ Branch 117 → 118 not taken.
✓ Branch 117 → 131 taken 8 times.
1915 if (node->trueSideCallsCopyCtor && node->falseSideCallsCopyCtor) { // both sides need copy ctor call
180 ✗ resultPtr = insertAlloca(resultType);
181 ✗ generateCtorOrDtorCall(resultPtr, node->calledCopyCtor, {phiInst});
182 } else {
183 1915 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 8714 times.
8714 assert(trueValue != nullptr);
187
3/6
✓ Branch 135 → 136 taken 8714 times.
✗ Branch 135 → 245 not taken.
✓ Branch 136 → 137 taken 8714 times.
✗ Branch 136 → 245 not taken.
✓ Branch 137 → 138 taken 8714 times.
✗ Branch 137 → 245 not taken.
8714 llvm::PHINode *phiInst = builder.CreatePHI(resultType.toLLVMType(sourceFile), 2, "cond.result");
188
1/2
✓ Branch 138 → 139 taken 8714 times.
✗ Branch 138 → 261 not taken.
8714 phiInst->addIncoming(trueValue, condTrue);
189
1/2
✓ Branch 139 → 140 taken 8714 times.
✗ Branch 139 → 261 not taken.
8714 phiInst->addIncoming(falseValue, condFalse);
190 8714 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 10629 times.
✗ Branch 141 → 261 not taken.
10629 anonymousSymbol = currentScope->symbolTable.lookupAnonymous(node);
195
2/2
✓ Branch 142 → 143 taken 885 times.
✓ Branch 142 → 153 taken 9744 times.
10629 if (anonymousSymbol != nullptr) {
196
2/2
✓ Branch 143 → 144 taken 104 times.
✓ Branch 143 → 152 taken 781 times.
885 if (!resultPtr) {
197
2/4
✓ Branch 147 → 148 taken 104 times.
✗ Branch 147 → 246 not taken.
✓ Branch 148 → 149 taken 104 times.
✗ Branch 148 → 246 not taken.
104 resultPtr = insertAlloca(anonymousSymbol->getQualType());
198
1/2
✓ Branch 151 → 152 taken 104 times.
✗ Branch 151 → 261 not taken.
104 insertStore(resultValue, resultPtr);
199 }
200
1/2
✓ Branch 152 → 153 taken 885 times.
✗ Branch 152 → 261 not taken.
885 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 10627 times.
✓ Branch 153 → 157 taken 2 times.
✓ Branch 155 → 156 taken 4 times.
✓ Branch 155 → 157 taken 10623 times.
10629 const bool trueNeedsCleanup = trueScope != nullptr && !trueScope->temporaryDtorsToCall.empty();
206
3/4
✓ Branch 158 → 159 taken 10629 times.
✗ Branch 158 → 162 not taken.
✓ Branch 160 → 161 taken 2 times.
✓ Branch 160 → 162 taken 10627 times.
10629 const bool falseNeedsCleanup = falseScope != nullptr && !falseScope->temporaryDtorsToCall.empty();
207
4/4
✓ Branch 163 → 164 taken 10625 times.
✓ Branch 163 → 165 taken 4 times.
✓ Branch 164 → 165 taken 2 times.
✓ Branch 164 → 184 taken 10623 times.
10629 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 10629 }
226
227
1/2
✓ Branch 188 → 189 taken 12553 times.
✗ Branch 188 → 268 not taken.
25106 return LLVMExprResult{.value = resultValue, .ptr = resultPtr, .entry = anonymousSymbol};
228 }
229
230 14950 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 14950 times.
14950 if (node->operands.size() == 1)
233 ✗ return visit(node->operands.front());
234
235
1/2
✓ Branch 7 → 8 taken 14950 times.
✗ Branch 7 → 104 not taken.
14950 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 14950 times.
✗ Branch 8 → 104 not taken.
14950 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
240
2/4
✓ Branch 9 → 10 taken 14950 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 14950 times.
✗ Branch 10 → 79 not taken.
14950 llvm::BasicBlock *bExit = createBlock("lor.exit." + codeLoc);
241
242 // Visit the first operand
243
1/2
✓ Branch 13 → 14 taken 14950 times.
✗ Branch 13 → 102 not taken.
14950 llvm::Value *firstOperandValue = resolveValue(node->operands.front());
244
245 // Prepare an array for value-to-block-mapping
246 14950 std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks;
247
1/2
✓ Branch 15 → 16 taken 14950 times.
✗ Branch 15 → 100 not taken.
14950 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 14950 times.
✗ Branch 17 → 82 not taken.
14950 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 21572 times.
✓ Branch 31 → 32 taken 14950 times.
36522 for (size_t i = 1; i < node->operands.size(); i++)
252
6/12
✓ Branch 19 → 20 taken 21572 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 21572 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 21572 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 21572 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 21572 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 21572 times.
✗ Branch 24 → 83 not taken.
21572 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 14950 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 14950 times.
✗ Branch 33 → 100 not taken.
14950 insertCondJump(firstOperandValue, bExit, shortCircuitBlocks.at(1).first);
255
256 // Create block for each operand
257
2/2
✓ Branch 50 → 35 taken 21572 times.
✓ Branch 50 → 51 taken 14950 times.
36522 for (size_t i = 1; i < node->operands.size(); i++) {
258 // Switch to the next block
259
2/4
✓ Branch 35 → 36 taken 21572 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 21572 times.
✗ Branch 36 → 100 not taken.
21572 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 21572 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 21572 times.
✗ Branch 39 → 100 not taken.
21572 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 21572 times.
✗ Branch 41 → 100 not taken.
21572 shortCircuitBlocks.at(i).first = builder.GetInsertBlock();
265 // Check if there are more blocks to process
266
2/2
✓ Branch 43 → 44 taken 14950 times.
✓ Branch 43 → 45 taken 6622 times.
21572 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 14950 times.
✗ Branch 44 → 100 not taken.
14950 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 6622 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 6622 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 6622 times.
✗ Branch 47 → 100 not taken.
6622 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 14950 times.
✗ Branch 51 → 100 not taken.
14950 switchToBlock(bExit);
277
2/4
✓ Branch 52 → 53 taken 14950 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 14950 times.
✗ Branch 55 → 97 not taken.
14950 llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "lor_phi");
278
2/2
✓ Branch 72 → 58 taken 36522 times.
✓ Branch 72 → 73 taken 14950 times.
102944 for (const auto &[incomingBlock, value] : shortCircuitBlocks)
279
1/2
✓ Branch 62 → 63 taken 36522 times.
✗ Branch 62 → 98 not taken.
36522 result->addIncoming(value, incomingBlock);
280
281 // Return the result
282
1/2
✓ Branch 73 → 74 taken 14950 times.
✗ Branch 73 → 99 not taken.
14950 return LLVMExprResult{.value = result};
283 14950 }
284
285 25898 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 25898 times.
25898 if (node->operands.size() == 1)
288 ✗ return visit(node->operands.front());
289
290
1/2
✓ Branch 7 → 8 taken 25898 times.
✗ Branch 7 → 104 not taken.
25898 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 25898 times.
✗ Branch 8 → 104 not taken.
25898 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
295
2/4
✓ Branch 9 → 10 taken 25898 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 25898 times.
✗ Branch 10 → 79 not taken.
25898 llvm::BasicBlock *bExit = createBlock("land.exit." + codeLoc);
296
297 // Visit the first operand
298
1/2
✓ Branch 13 → 14 taken 25898 times.
✗ Branch 13 → 102 not taken.
25898 llvm::Value *firstOperandValue = resolveValue(node->operands.front());
299
300 // Prepare an array for value-to-block-mapping
301 25898 std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks;
302
1/2
✓ Branch 15 → 16 taken 25898 times.
✗ Branch 15 → 100 not taken.
25898 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 25898 times.
✗ Branch 17 → 82 not taken.
25898 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 32332 times.
✓ Branch 31 → 32 taken 25898 times.
58230 for (size_t i = 1; i < node->operands.size(); i++)
307
6/12
✓ Branch 19 → 20 taken 32332 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 32332 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 32332 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 32332 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 32332 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 32332 times.
✗ Branch 24 → 83 not taken.
32332 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 25898 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 25898 times.
✗ Branch 33 → 100 not taken.
25898 insertCondJump(firstOperandValue, shortCircuitBlocks.at(1).first, bExit);
310
311 // Create block for each operand
312
2/2
✓ Branch 50 → 35 taken 32332 times.
✓ Branch 50 → 51 taken 25898 times.
58230 for (size_t i = 1; i < node->operands.size(); i++) {
313 // Switch to the next block
314
2/4
✓ Branch 35 → 36 taken 32332 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 32332 times.
✗ Branch 36 → 100 not taken.
32332 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 32332 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 32332 times.
✗ Branch 39 → 100 not taken.
32332 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 32332 times.
✗ Branch 41 → 100 not taken.
32332 shortCircuitBlocks.at(i).first = builder.GetInsertBlock();
320 // Check if there are more blocks to process
321
2/2
✓ Branch 43 → 44 taken 25898 times.
✓ Branch 43 → 45 taken 6434 times.
32332 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 25898 times.
✗ Branch 44 → 100 not taken.
25898 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 6434 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 6434 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 6434 times.
✗ Branch 47 → 100 not taken.
6434 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 25898 times.
✗ Branch 51 → 100 not taken.
25898 switchToBlock(bExit);
332
2/4
✓ Branch 52 → 53 taken 25898 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 25898 times.
✗ Branch 55 → 97 not taken.
25898 llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "land_phi");
333
2/2
✓ Branch 72 → 58 taken 58230 times.
✓ Branch 72 → 73 taken 25898 times.
168256 for (const auto &[incomingBlock, value] : shortCircuitBlocks)
334
1/2
✓ Branch 62 → 63 taken 58230 times.
✗ Branch 62 → 98 not taken.
58230 result->addIncoming(value, incomingBlock);
335
336 // Return the result
337
1/2
✓ Branch 73 → 74 taken 25898 times.
✗ Branch 73 → 99 not taken.
25898 return LLVMExprResult{.value = result};
338 25898 }
339
340 1434 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 1434 times.
1434 if (node->operands.size() == 1)
343 ✗ return visit(node->operands.front());
344
345
1/2
✓ Branch 7 → 8 taken 1434 times.
✗ Branch 7 → 34 not taken.
1434 diGenerator.setSourceLocation(node);
346
347 // It is a bitwise or expression
348 // Evaluate first operand
349 1434 const ExprNode *lhsNode = node->operands.front();
350
1/2
✓ Branch 9 → 10 taken 1434 times.
✗ Branch 9 → 34 not taken.
1434 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
351
2/4
✓ Branch 10 → 11 taken 1434 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 1434 times.
✗ Branch 11 → 27 not taken.
1434 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
352
353 // Evaluate all additional operands
354
2/2
✓ Branch 22 → 14 taken 1536 times.
✓ Branch 22 → 23 taken 1434 times.
2970 for (size_t i = 1; i < node->operands.size(); i++) {
355 // Evaluate the operand
356 1536 const ExprNode *rhsNode = node->operands[i];
357
1/2
✓ Branch 15 → 16 taken 1536 times.
✗ Branch 15 → 33 not taken.
1536 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
358
2/4
✓ Branch 16 → 17 taken 1536 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 1536 times.
✗ Branch 17 → 30 not taken.
1536 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
359
1/2
✓ Branch 19 → 20 taken 1536 times.
✗ Branch 19 → 33 not taken.
1536 result = conversionManager.getBitwiseOrInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
360 }
361
362 // Return result
363
1/2
✓ Branch 23 → 24 taken 1434 times.
✗ Branch 23 → 34 not taken.
1434 return result;
364 }
365
366 179 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 179 times.
179 if (node->operands.size() == 1)
369 ✗ return visit(node->operands.front());
370
371
1/2
✓ Branch 7 → 8 taken 179 times.
✗ Branch 7 → 34 not taken.
179 diGenerator.setSourceLocation(node);
372
373 // It is a bitwise xor expression
374 // Evaluate first operand
375 179 const ExprNode *lhsNode = node->operands.front();
376
1/2
✓ Branch 9 → 10 taken 179 times.
✗ Branch 9 → 34 not taken.
179 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
377
2/4
✓ Branch 10 → 11 taken 179 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 179 times.
✗ Branch 11 → 27 not taken.
179 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
378
379 // Evaluate all additional operands
380
2/2
✓ Branch 22 → 14 taken 181 times.
✓ Branch 22 → 23 taken 179 times.
360 for (size_t i = 1; i < node->operands.size(); i++) {
381 // Evaluate the operand
382 181 const ExprNode *rhsNode = node->operands[i];
383
1/2
✓ Branch 15 → 16 taken 181 times.
✗ Branch 15 → 33 not taken.
181 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
384
2/4
✓ Branch 16 → 17 taken 181 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 181 times.
✗ Branch 17 → 30 not taken.
181 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
385
1/2
✓ Branch 19 → 20 taken 181 times.
✗ Branch 19 → 33 not taken.
181 result = conversionManager.getBitwiseXorInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
386 }
387
388 // Return result
389
1/2
✓ Branch 23 → 24 taken 179 times.
✗ Branch 23 → 34 not taken.
179 return result;
390 }
391
392 4498 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 4498 times.
4498 if (node->operands.size() == 1)
395 ✗ return visit(node->operands.front());
396
397
1/2
✓ Branch 7 → 8 taken 4498 times.
✗ Branch 7 → 34 not taken.
4498 diGenerator.setSourceLocation(node);
398
399 // It is a bitwise and expression
400 // Evaluate first operand
401 4498 const ExprNode *lhsNode = node->operands.front();
402
1/2
✓ Branch 9 → 10 taken 4498 times.
✗ Branch 9 → 34 not taken.
4498 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
403
2/4
✓ Branch 10 → 11 taken 4498 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 4498 times.
✗ Branch 11 → 27 not taken.
4498 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
404
405 // Evaluate all additional operands
406
2/2
✓ Branch 22 → 14 taken 4500 times.
✓ Branch 22 → 23 taken 4498 times.
8998 for (size_t i = 1; i < node->operands.size(); i++) {
407 // Evaluate the operand
408 4500 const ExprNode *rhsNode = node->operands[i];
409
1/2
✓ Branch 15 → 16 taken 4500 times.
✗ Branch 15 → 33 not taken.
4500 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
410
2/4
✓ Branch 16 → 17 taken 4500 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 4500 times.
✗ Branch 17 → 30 not taken.
4500 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
411
1/2
✓ Branch 19 → 20 taken 4500 times.
✗ Branch 19 → 33 not taken.
4500 result = conversionManager.getBitwiseAndInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
412 }
413
414 // Return result
415
1/2
✓ Branch 23 → 24 taken 4498 times.
✗ Branch 23 → 34 not taken.
4498 return result;
416 }
417
418 181602 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 181602 times.
181602 if (node->operands.size() == 1)
421 ✗ return visit(node->operands.front());
422
423
1/2
✓ Branch 7 → 8 taken 181602 times.
✗ Branch 7 → 50 not taken.
181602 diGenerator.setSourceLocation(node);
424
425 // It is an equality expression
426 // Evaluate lhs
427 181602 const ExprNode *lhsNode = node->operands[0];
428
1/2
✓ Branch 9 → 10 taken 181602 times.
✗ Branch 9 → 50 not taken.
181602 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
429
2/4
✓ Branch 10 → 11 taken 181602 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 181602 times.
✗ Branch 11 → 35 not taken.
181602 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
430
431 // Evaluate rhs
432 181602 const ExprNode *rhsNode = node->operands[1];
433
1/2
✓ Branch 14 → 15 taken 181602 times.
✗ Branch 14 → 50 not taken.
181602 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
434
2/4
✓ Branch 15 → 16 taken 181602 times.
✗ Branch 15 → 40 not taken.
✓ Branch 16 → 17 taken 181602 times.
✗ Branch 16 → 38 not taken.
181602 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 139549 times.
✓ Branch 18 → 21 taken 42053 times.
✗ Branch 18 → 23 not taken.
181602 switch (node->op) {
438 139549 case EqualityExprNode::EqualityOp::OP_EQUAL:
439
1/2
✓ Branch 19 → 20 taken 139549 times.
✗ Branch 19 → 50 not taken.
139549 result = conversionManager.getEqualInst(node, result, lhsSTy, rhs, rhsSTy);
440 139549 break;
441 42053 case EqualityExprNode::EqualityOp::OP_NOT_EQUAL:
442
1/2
✓ Branch 21 → 22 taken 42053 times.
✗ Branch 21 → 50 not taken.
42053 result = conversionManager.getNotEqualInst(node, result, lhsSTy, rhs, rhsSTy);
443 42053 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 181602 times.
✗ Branch 31 → 50 not taken.
181602 return result;
450 }
451
452 84999 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 84999 times.
84999 if (node->operands.size() == 1)
455 ✗ return visit(node->operands.front());
456
457
1/2
✓ Branch 7 → 8 taken 84999 times.
✗ Branch 7 → 54 not taken.
84999 diGenerator.setSourceLocation(node);
458
459 // It is a relational expression
460 // Evaluate lhs
461 84999 const ExprNode *lhsNode = node->operands[0];
462
1/2
✓ Branch 9 → 10 taken 84999 times.
✗ Branch 9 → 54 not taken.
84999 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
463
2/4
✓ Branch 10 → 11 taken 84999 times.
✗ Branch 10 → 41 not taken.
✓ Branch 11 → 12 taken 84999 times.
✗ Branch 11 → 39 not taken.
84999 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
464
465 // Evaluate rhs
466 84999 const ExprNode *rhsNode = node->operands[1];
467
1/2
✓ Branch 14 → 15 taken 84999 times.
✗ Branch 14 → 54 not taken.
84999 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
468
2/4
✓ Branch 15 → 16 taken 84999 times.
✗ Branch 15 → 44 not taken.
✓ Branch 16 → 17 taken 84999 times.
✗ Branch 16 → 42 not taken.
84999 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 36948 times.
✓ Branch 18 → 21 taken 23272 times.
✓ Branch 18 → 23 taken 9620 times.
✓ Branch 18 → 25 taken 15159 times.
✗ Branch 18 → 27 not taken.
84999 switch (node->op) {
472 36948 case RelationalExprNode::RelationalOp::OP_LESS:
473
1/2
✓ Branch 19 → 20 taken 36948 times.
✗ Branch 19 → 54 not taken.
36948 result = conversionManager.getLessInst(node, result, lhsSTy, rhs, rhsSTy);
474 36948 break;
475 23272 case RelationalExprNode::RelationalOp::OP_GREATER:
476
1/2
✓ Branch 21 → 22 taken 23272 times.
✗ Branch 21 → 54 not taken.
23272 result = conversionManager.getGreaterInst(node, result, lhsSTy, rhs, rhsSTy);
477 23272 break;
478 9620 case RelationalExprNode::RelationalOp::OP_LESS_EQUAL:
479
1/2
✓ Branch 23 → 24 taken 9620 times.
✗ Branch 23 → 54 not taken.
9620 result = conversionManager.getLessEqualInst(node, result, lhsSTy, rhs, rhsSTy);
480 9620 break;
481 15159 case RelationalExprNode::RelationalOp::OP_GREATER_EQUAL:
482
1/2
✓ Branch 25 → 26 taken 15159 times.
✗ Branch 25 → 54 not taken.
15159 result = conversionManager.getGreaterEqualInst(node, result, lhsSTy, rhs, rhsSTy);
483 15159 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 84999 times.
✗ Branch 35 → 54 not taken.
84999 return result;
490 }
491
492 24792 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 24792 times.
24792 if (node->operands.size() == 1)
495 ✗ return visit(node->operands.front());
496
497
1/2
✓ Branch 7 → 8 taken 24792 times.
✗ Branch 7 → 64 not taken.
24792 diGenerator.setSourceLocation(node);
498
499 // It is a shift expression
500 // Evaluate first operand
501 24792 const ExprNode *lhsNode = node->operands.front();
502
1/2
✓ Branch 9 → 10 taken 24792 times.
✗ Branch 9 → 64 not taken.
24792 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
503
2/4
✓ Branch 10 → 11 taken 24792 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 24792 times.
✗ Branch 11 → 46 not taken.
24792 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
504
505
1/2
✓ Branch 13 → 14 taken 24792 times.
✗ Branch 13 → 64 not taken.
24792 auto opQueue = node->opQueue;
506 24792 size_t operandIndex = 1;
507
2/2
✓ Branch 40 → 15 taken 58412 times.
✓ Branch 40 → 41 taken 24792 times.
83204 while (!opQueue.empty()) {
508 58412 const size_t operatorIndex = operandIndex - 1;
509 // Evaluate next operand
510 58412 const ExprNode *rhsNode = node->operands[operandIndex++];
511
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 58412 times.
58412 assert(rhsNode != nullptr);
512
1/2
✓ Branch 18 → 19 taken 58412 times.
✗ Branch 18 → 61 not taken.
58412 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
513
2/4
✓ Branch 19 → 20 taken 58412 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 58412 times.
✗ Branch 20 → 49 not taken.
58412 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 55751 times.
✓ Branch 23 → 26 taken 2661 times.
✗ Branch 23 → 28 not taken.
58412 switch (opQueue.front().first) {
517 55751 case ShiftExprNode::ShiftOp::OP_SHIFT_LEFT:
518
1/2
✓ Branch 24 → 25 taken 55751 times.
✗ Branch 24 → 61 not taken.
55751 lhs = conversionManager.getShiftLeftInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
519 55751 break;
520 2661 case ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT:
521
1/2
✓ Branch 26 → 27 taken 2661 times.
✗ Branch 26 → 61 not taken.
2661 lhs = conversionManager.getShiftRightInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
522 2661 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 58412 lhsSTy = opQueue.front().second;
529
530 58412 opQueue.pop();
531 }
532
533 // Return the result
534
1/2
✓ Branch 41 → 42 taken 24792 times.
✗ Branch 41 → 62 not taken.
24792 return lhs;
535 24792 }
536
537 62205 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 62205 times.
62205 if (node->operands.size() == 1)
540 ✗ return visit(node->operands.front());
541
542
1/2
✓ Branch 7 → 8 taken 62205 times.
✗ Branch 7 → 64 not taken.
62205 diGenerator.setSourceLocation(node);
543
544 // It is an additive expression
545 // Evaluate first operand
546 62205 const ExprNode *lhsNode = node->operands[0];
547
1/2
✓ Branch 9 → 10 taken 62205 times.
✗ Branch 9 → 64 not taken.
62205 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
548
2/4
✓ Branch 10 → 11 taken 62205 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 62205 times.
✗ Branch 11 → 46 not taken.
62205 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
549
550
1/2
✓ Branch 13 → 14 taken 62205 times.
✗ Branch 13 → 64 not taken.
62205 auto opQueue = node->opQueue;
551 62205 size_t operandIndex = 1;
552
2/2
✓ Branch 40 → 15 taken 79538 times.
✓ Branch 40 → 41 taken 62205 times.
141743 while (!opQueue.empty()) {
553 79538 const size_t operatorIndex = operandIndex - 1;
554 // Evaluate next operand
555 79538 const ExprNode *rhsNode = node->operands[operandIndex++];
556
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 79538 times.
79538 assert(rhsNode != nullptr);
557
1/2
✓ Branch 18 → 19 taken 79538 times.
✗ Branch 18 → 61 not taken.
79538 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
558
2/4
✓ Branch 19 → 20 taken 79538 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 79538 times.
✗ Branch 20 → 49 not taken.
79538 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 62472 times.
✓ Branch 23 → 26 taken 17066 times.
✗ Branch 23 → 28 not taken.
79538 switch (opQueue.front().first) {
562 62472 case AdditiveExprNode::AdditiveOp::OP_PLUS:
563
1/2
✓ Branch 24 → 25 taken 62472 times.
✗ Branch 24 → 61 not taken.
62472 lhs = conversionManager.getPlusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
564 62472 break;
565 17066 case AdditiveExprNode::AdditiveOp::OP_MINUS:
566
1/2
✓ Branch 26 → 27 taken 17066 times.
✗ Branch 26 → 61 not taken.
17066 lhs = conversionManager.getMinusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
567 17066 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 79538 lhsSTy = opQueue.front().second;
574
575 79538 opQueue.pop();
576 }
577
578 // Return the result
579
1/2
✓ Branch 41 → 42 taken 62205 times.
✗ Branch 41 → 62 not taken.
62205 return lhs;
580 62205 }
581
582 28027 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 28027 times.
28027 if (node->operands.size() == 1)
585 ✗ return visit(node->operands.front());
586
587
1/2
✓ Branch 7 → 8 taken 28027 times.
✗ Branch 7 → 66 not taken.
28027 diGenerator.setSourceLocation(node);
588
589 // It is an additive expression
590 // Evaluate first operand
591 28027 const ExprNode *lhsNode = node->operands[0];
592
1/2
✓ Branch 9 → 10 taken 28027 times.
✗ Branch 9 → 66 not taken.
28027 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
593
2/4
✓ Branch 10 → 11 taken 28027 times.
✗ Branch 10 → 50 not taken.
✓ Branch 11 → 12 taken 28027 times.
✗ Branch 11 → 48 not taken.
28027 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
594
595
1/2
✓ Branch 13 → 14 taken 28027 times.
✗ Branch 13 → 66 not taken.
28027 auto opQueue = node->opQueue;
596 28027 size_t operandIndex = 1;
597
2/2
✓ Branch 42 → 15 taken 30291 times.
✓ Branch 42 → 43 taken 28027 times.
58318 while (!opQueue.empty()) {
598 30291 const size_t operatorIndex = operandIndex - 1;
599 // Evaluate next operand
600 30291 const ExprNode *rhsNode = node->operands[operandIndex++];
601
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 30291 times.
30291 assert(rhsNode != nullptr);
602
1/2
✓ Branch 18 → 19 taken 30291 times.
✗ Branch 18 → 63 not taken.
30291 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
603
2/4
✓ Branch 19 → 20 taken 30291 times.
✗ Branch 19 → 53 not taken.
✓ Branch 20 → 21 taken 30291 times.
✗ Branch 20 → 51 not taken.
30291 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 24067 times.
✓ Branch 23 → 26 taken 5470 times.
✓ Branch 23 → 28 taken 754 times.
✗ Branch 23 → 30 not taken.
30291 switch (opQueue.front().first) {
607 24067 case MultiplicativeExprNode::MultiplicativeOp::OP_MUL:
608
1/2
✓ Branch 24 → 25 taken 24067 times.
✗ Branch 24 → 63 not taken.
24067 result = conversionManager.getMulInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex);
609 24067 break;
610 5470 case MultiplicativeExprNode::MultiplicativeOp::OP_DIV:
611
1/2
✓ Branch 26 → 27 taken 5470 times.
✗ Branch 26 → 63 not taken.
5470 result = conversionManager.getDivInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex);
612 5470 break;
613 754 case MultiplicativeExprNode::MultiplicativeOp::OP_REM:
614
1/2
✓ Branch 28 → 29 taken 754 times.
✗ Branch 28 → 63 not taken.
754 result = conversionManager.getRemInst(node, result, lhsSTy, rhs, rhsSTy);
615 754 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 30291 lhsSTy = opQueue.front().second;
622 30291 opQueue.pop();
623 }
624
625 // Return the result
626
1/2
✓ Branch 43 → 44 taken 28027 times.
✗ Branch 43 → 64 not taken.
28027 return result;
627 28027 }
628
629 117251 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 117251 times.
117251 if (!node->isCast)
632 ✗ return visit(node->prefixUnaryExpr);
633
634
1/2
✓ Branch 5 → 6 taken 117251 times.
✗ Branch 5 → 19 not taken.
117251 diGenerator.setSourceLocation(node);
635
636 // It is a cast expression
637 // Retrieve target symbol type
638
1/2
✓ Branch 6 → 7 taken 117251 times.
✗ Branch 6 → 19 not taken.
117251 const QualType targetSTy = node->getEvaluatedSymbolType(manIdx);
639
640 // Evaluate rhs
641 117251 const ExprNode *rhsNode = node->assignExpr;
642
1/2
✓ Branch 7 → 8 taken 117251 times.
✗ Branch 7 → 19 not taken.
117251 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
643
2/4
✓ Branch 8 → 9 taken 117251 times.
✗ Branch 8 → 18 not taken.
✓ Branch 9 → 10 taken 117251 times.
✗ Branch 9 → 16 not taken.
117251 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
644
645 // Retrieve the result value
646
1/2
✓ Branch 11 → 12 taken 117251 times.
✗ Branch 11 → 19 not taken.
117251 const LLVMExprResult result = conversionManager.getCastInst(node, targetSTy, rhs, rhsSTy);
647
648 // Return the result
649
1/2
✓ Branch 12 → 13 taken 117251 times.
✗ Branch 12 → 19 not taken.
117251 return result;
650 }
651
652 105171 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 105171 times.
105171 if (node->op == PrefixUnaryExprNode::PrefixUnaryOp::OP_NONE)
655 ✗ return visit(node->postfixUnaryExpr);
656
657
1/2
✓ Branch 5 → 6 taken 105171 times.
✗ Branch 5 → 117 not taken.
105171 diGenerator.setSourceLocation(node);
658
659 // Evaluate lhs
660 105171 const ExprNode *lhsNode = node->prefixUnaryExpr;
661
1/2
✓ Branch 6 → 7 taken 105171 times.
✗ Branch 6 → 117 not taken.
105171 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
662
2/4
✓ Branch 7 → 8 taken 105171 times.
✗ Branch 7 → 87 not taken.
✓ Branch 8 → 9 taken 105171 times.
✗ Branch 8 → 85 not taken.
105171 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
663
664
7/8
✓ Branch 10 → 11 taken 2921 times.
✓ Branch 10 → 21 taken 22 times.
✓ Branch 10 → 36 taken 234 times.
✓ Branch 10 → 51 taken 64709 times.
✓ Branch 10 → 53 taken 110 times.
✓ Branch 10 → 55 taken 14166 times.
✓ Branch 10 → 64 taken 23009 times.
✗ Branch 10 → 73 not taken.
105171 switch (node->op) {
665 2921 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS: {
666 // Execute operation
667
1/2
✓ Branch 11 → 12 taken 2921 times.
✗ Branch 11 → 117 not taken.
2921 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 2921 times.
✗ Branch 16 → 88 not taken.
2921 lhs.ptr = insertAlloca(lhs.value->getType());
671
672 // Store the new value
673
1/2
✓ Branch 19 → 20 taken 2921 times.
✗ Branch 19 → 117 not taken.
2921 insertStore(lhs.value, lhs.ptr);
674
675 2921 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 234 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS: {
695 // Execute operation
696
1/2
✓ Branch 36 → 37 taken 234 times.
✗ Branch 36 → 101 not taken.
234 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 232 times.
✓ Branch 37 → 40 taken 2 times.
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 232 times.
234 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 232 times.
234 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 234 times.
✗ Branch 49 → 117 not taken.
234 insertStore(lhs.value, lhs.ptr);
708
709 234 break;
710 }
711 64709 case PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT: {
712 // Execute operation
713
1/2
✓ Branch 51 → 52 taken 64709 times.
✗ Branch 51 → 117 not taken.
64709 lhs = conversionManager.getPrefixNotInst(node, lhs, lhsSTy);
714 64709 break;
715 }
716 110 case PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT: {
717 // Execute operation
718
1/2
✓ Branch 53 → 54 taken 110 times.
✗ Branch 53 → 117 not taken.
110 lhs = conversionManager.getPrefixBitwiseNotInst(node, lhs, lhsSTy);
719 110 break;
720 }
721 14166 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 14029 times.
✓ Branch 55 → 58 taken 137 times.
✓ Branch 56 → 57 taken 546 times.
✓ Branch 56 → 58 taken 13483 times.
14166 const bool onlyRefPtrIsFilled = lhs.value == nullptr && lhs.ptr == nullptr;
725 // Rewire the fields
726
3/4
✓ Branch 59 → 60 taken 546 times.
✓ Branch 59 → 62 taken 13620 times.
✓ Branch 60 → 61 taken 546 times.
✗ Branch 60 → 117 not taken.
14166 llvm::Value *newRefPtr = onlyRefPtrIsFilled ? resolveValue(lhsNode, lhs) : lhs.ptr;
727 14166 llvm::Value *newPtr = lhs.value;
728 14166 lhs = {.ptr = newPtr, .refPtr = newRefPtr};
729 14166 break;
730 }
731 23009 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 1666 times.
✓ Branch 64 → 67 taken 21343 times.
✓ Branch 65 → 66 taken 4 times.
✓ Branch 65 → 67 taken 1662 times.
23009 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 23005 times.
✓ Branch 69 → 70 taken 4 times.
✗ Branch 69 → 117 not taken.
23009 llvm::Value *newValue = onlyValueIsFilled ? resolveAddress(lhs) : lhs.ptr;
737 23009 llvm::Value *newPtr = lhs.refPtr;
738 23009 lhs = {.value = newValue, .ptr = newPtr};
739 23009 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 105171 times.
✗ Branch 81 → 117 not taken.
105171 return lhs;
746 }
747
748 846811 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 846811 times.
846811 if (node->op == PostfixUnaryExprNode::PostfixUnaryOp::OP_NONE)
751 ✗ return visit(node->atomicExpr);
752
753
1/2
✓ Branch 5 → 6 taken 846811 times.
✗ Branch 5 → 524 not taken.
846811 diGenerator.setSourceLocation(node);
754
755 // Evaluate lhs
756 846811 const ExprNode *lhsNode = node->postfixUnaryExpr;
757
1/2
✓ Branch 6 → 7 taken 846811 times.
✗ Branch 6 → 524 not taken.
846811 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
758
2/4
✓ Branch 7 → 8 taken 846811 times.
✗ Branch 7 → 342 not taken.
✓ Branch 8 → 9 taken 846811 times.
✗ Branch 8 → 340 not taken.
846811 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
759
760
5/6
✓ Branch 10 → 11 taken 52066 times.
✓ Branch 10 → 62 taken 744988 times.
✓ Branch 10 → 210 taken 46482 times.
✓ Branch 10 → 234 taken 2975 times.
✓ Branch 10 → 258 taken 300 times.
✗ Branch 10 → 328 not taken.
846811 switch (node->op) {
761 52066 case PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT: {
762 52066 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 52066 times.
✗ Branch 11 → 378 not taken.
✓ Branch 12 → 13 taken 2628 times.
✓ Branch 12 → 29 taken 49438 times.
52066 if (conversionManager.callsOverloadedOpFct(node, 0)) {
766
1/2
✓ Branch 13 → 14 taken 2628 times.
✗ Branch 13 → 343 not taken.
2628 ResolverFct lhsV = [&] { return resolveValue(lhsSTy, lhs); };
767 5256 ResolverFct lhsP = [&] { return resolveAddress(lhs); };
768 5208 ResolverFct idxV = [&] { return resolveValue(indexExpr); };
769 2676 ResolverFct idxP = [&] { return resolveAddress(indexExpr); };
770 2628 lhs = conversionManager.callOperatorOverloadFct<2>(node, {lhsV, lhsP, idxV, idxP}, 0);
771 2628 break;
772 2628 }
773
774
1/2
✓ Branch 29 → 30 taken 49438 times.
✗ Branch 29 → 361 not taken.
49438 lhsSTy = lhsSTy.removeReferenceWrapper();
775
776 // Get the index value
777
1/2
✓ Branch 30 → 31 taken 49438 times.
✗ Branch 30 → 378 not taken.
49438 llvm::Value *indexValue = resolveValue(indexExpr);
778 // Come up with the address
779
8/10
✓ Branch 31 → 32 taken 49438 times.
✗ Branch 31 → 378 not taken.
✓ Branch 32 → 33 taken 4279 times.
✓ Branch 32 → 36 taken 45159 times.
✓ Branch 33 → 34 taken 4279 times.
✗ Branch 33 → 378 not taken.
✓ Branch 34 → 35 taken 3335 times.
✓ Branch 34 → 36 taken 944 times.
✓ Branch 37 → 38 taken 3335 times.
✓ Branch 37 → 49 taken 46103 times.
49438 if (lhsSTy.isArray() && lhsSTy.getArraySize() != ARRAY_SIZE_UNKNOWN) { // Array
780 // Make sure the address is present
781
1/2
✓ Branch 38 → 39 taken 3335 times.
✗ Branch 38 → 369 not taken.
3335 resolveAddress(lhs);
782
783 // Calculate address of array item
784
1/2
✓ Branch 39 → 40 taken 3335 times.
✗ Branch 39 → 369 not taken.
3335 llvm::Type *lhsTy = lhsSTy.toLLVMType(sourceFile);
785
1/2
✓ Branch 40 → 41 taken 3335 times.
✗ Branch 40 → 369 not taken.
3335 llvm::Value *indices[2] = {builder.getInt64(0), indexValue};
786
1/2
✓ Branch 45 → 46 taken 3335 times.
✗ Branch 45 → 362 not taken.
3335 lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indices);
787 } else { // Pointer
788 // Now the pointer is the value
789
1/2
✓ Branch 49 → 50 taken 46103 times.
✗ Branch 49 → 378 not taken.
46103 lhs.ptr = resolveValue(lhsNode, lhs);
790
791
2/4
✓ Branch 50 → 51 taken 46103 times.
✗ Branch 50 → 370 not taken.
✓ Branch 51 → 52 taken 46103 times.
✗ Branch 51 → 370 not taken.
46103 llvm::Type *lhsTy = lhsSTy.getContained().toLLVMType(sourceFile);
792 // Calculate address of pointer item
793
1/2
✓ Branch 56 → 57 taken 46103 times.
✗ Branch 56 → 371 not taken.
46103 lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indexValue);
794 }
795
796 // Reset value and entry
797 49438 lhs.value = nullptr;
798 49438 lhs.entry = nullptr;
799 49438 break;
800 }
801 744988 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS: {
802 // Get the address of the struct/union instance
803
1/2
✓ Branch 62 → 63 taken 744988 times.
✗ Branch 62 → 457 not taken.
744988 resolveAddress(lhs);
804
1/2
✓ Branch 63 → 64 taken 744988 times.
✗ Branch 63 → 379 not taken.
744988 lhsSTy = lhsSTy.removeReferenceWrapper();
805
806 // Auto de-reference pointer
807
1/2
✓ Branch 64 → 65 taken 744988 times.
✗ Branch 64 → 457 not taken.
744988 autoDeReferencePtr(lhs.ptr, lhsSTy);
808
809 744988 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 744988 times.
✗ Branch 65 → 457 not taken.
✓ Branch 66 → 67 taken 6012 times.
✓ Branch 66 → 168 taken 738976 times.
744988 if (lhsSTy.is(TY_UNION)) {
815
1/2
✓ Branch 67 → 68 taken 6012 times.
✗ Branch 67 → 443 not taken.
6012 Scope *unionScope = lhsSTy.getBodyScope();
816
1/2
✓ Branch 68 → 69 taken 6012 times.
✗ Branch 68 → 443 not taken.
6012 const SymbolTableEntry *fieldEntry = unionScope->symbolTable.lookupStrict(fieldName);
817
1/2
✗ Branch 69 → 70 not taken.
✓ Branch 69 → 71 taken 6012 times.
6012 assert(fieldEntry != nullptr);
818
1/2
✓ Branch 71 → 72 taken 6012 times.
✗ Branch 71 → 443 not taken.
6012 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 6012 const auto fieldTagIndex = static_cast<uint32_t>(fieldEntry->orderIndex) + 1;
823
824
1/2
✓ Branch 72 → 73 taken 6012 times.
✗ Branch 72 → 443 not taken.
6012 llvm::Type *unionLLVMTy = lhsSTy.toLLVMType(sourceFile);
825 6012 llvm::Value *unionBasePtr = lhs.ptr;
826
2/4
✓ Branch 75 → 76 taken 6012 times.
✗ Branch 75 → 382 not taken.
✓ Branch 76 → 77 taken 6012 times.
✗ Branch 76 → 380 not taken.
6012 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 6012 times.
✗ Branch 79 → 81 not taken.
6012 const auto *assignParent = dynamic_cast<const AssignExprNode *>(node->parent);
833 6012 const bool isDirectAssignTarget =
834
6/6
✓ Branch 82 → 83 taken 3872 times.
✓ Branch 82 → 86 taken 2140 times.
✓ Branch 83 → 84 taken 3072 times.
✓ Branch 83 → 86 taken 800 times.
✓ Branch 84 → 85 taken 2570 times.
✓ Branch 84 → 86 taken 502 times.
6012 assignParent != nullptr && assignParent->lhs == node && assignParent->op == AssignExprNode::AssignOp::OP_ASSIGN;
835
836
2/2
✓ Branch 87 → 88 taken 2570 times.
✓ Branch 87 → 90 taken 3442 times.
6012 if (isDirectAssignTarget) {
837
2/4
✓ Branch 88 → 89 taken 2570 times.
✗ Branch 88 → 443 not taken.
✓ Branch 89 → 159 taken 2570 times.
✗ Branch 89 → 443 not taken.
2570 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 3442 times.
✗ Branch 93 → 386 not taken.
✓ Branch 94 → 95 taken 3442 times.
✗ Branch 94 → 386 not taken.
3442 llvm::Value *tagValue = insertLoad(builder.getInt32Ty(), tagAddr);
843
4/8
✓ Branch 97 → 98 taken 3442 times.
✗ Branch 97 → 392 not taken.
✓ Branch 98 → 99 taken 3442 times.
✗ Branch 98 → 392 not taken.
✓ Branch 99 → 100 taken 3442 times.
✗ Branch 99 → 392 not taken.
✓ Branch 100 → 101 taken 3442 times.
✗ Branch 100 → 439 not taken.
3442 llvm::Value *tagMatches = builder.CreateICmpEQ(tagValue, builder.getInt32(fieldTagIndex));
844
845
1/2
✓ Branch 100 → 101 taken 3442 times.
✗ Branch 100 → 439 not taken.
3442 const std::string &codeLine = node->codeLoc.toPrettyLine();
846
2/4
✓ Branch 101 → 102 taken 3442 times.
✗ Branch 101 → 395 not taken.
✓ Branch 102 → 103 taken 3442 times.
✗ Branch 102 → 393 not taken.
3442 llvm::BasicBlock *bOk = createBlock("union.tag.ok." + codeLine);
847
2/4
✓ Branch 104 → 105 taken 3442 times.
✗ Branch 104 → 398 not taken.
✓ Branch 105 → 106 taken 3442 times.
✗ Branch 105 → 396 not taken.
3442 llvm::BasicBlock *bPanic = createBlock("union.tag.panic." + codeLine);
848
1/2
✓ Branch 107 → 108 taken 3442 times.
✗ Branch 107 → 437 not taken.
3442 insertCondJump(tagMatches, bOk, bPanic, Likelihood::LIKELY);
849
850
1/2
✓ Branch 108 → 109 taken 3442 times.
✗ Branch 108 → 437 not taken.
3442 switchToBlock(bPanic);
851
1/2
✓ Branch 109 → 110 taken 3442 times.
✗ Branch 109 → 437 not taken.
3442 llvm::Value *stdErrValue = getStdErrValue();
852
2/4
✓ Branch 110 → 111 taken 3442 times.
✗ Branch 110 → 407 not taken.
✓ Branch 111 → 112 taken 3442 times.
✗ Branch 111 → 405 not taken.
6884 const std::string errorMsg = "Program panicked at " + node->codeLoc.toPrettyString() +
853
3/6
✓ Branch 112 → 113 taken 3442 times.
✗ Branch 112 → 403 not taken.
✓ Branch 113 → 114 taken 3442 times.
✗ Branch 113 → 401 not taken.
✓ Branch 114 → 115 taken 3442 times.
✗ Branch 114 → 399 not taken.
3442 ": active field mismatch on union field access '" + fieldName + "'\n";
854
4/8
✓ Branch 121 → 122 taken 3442 times.
✗ Branch 121 → 416 not taken.
✓ Branch 122 → 123 taken 3442 times.
✗ Branch 122 → 414 not taken.
✓ Branch 123 → 124 taken 3442 times.
✗ Branch 123 → 412 not taken.
✓ Branch 125 → 126 taken 3442 times.
✗ Branch 125 → 411 not taken.
6884 llvm::GlobalVariable *globalString = builder.CreateGlobalString(errorMsg, getUnusedGlobalName(ANON_GLOBAL_STRING_NAME));
855
1/2
✓ Branch 129 → 130 taken 3442 times.
✗ Branch 129 → 133 not taken.
3442 if (cliOptions.comparableOutput)
856
2/4
✓ Branch 130 → 131 taken 3442 times.
✗ Branch 130 → 422 not taken.
✓ Branch 131 → 132 taken 3442 times.
✗ Branch 131 → 422 not taken.
3442 globalString->setAlignment(llvm::Align(4));
857
4/8
✓ Branch 133 → 134 taken 3442 times.
✗ Branch 133 → 426 not taken.
✓ Branch 135 → 136 taken 3442 times.
✗ Branch 135 → 423 not taken.
✓ Branch 136 → 137 taken 3442 times.
✗ Branch 136 → 423 not taken.
✓ Branch 137 → 138 taken 3442 times.
✗ Branch 137 → 423 not taken.
3442 builder.CreateCall(stdFunctionManager.getFPrintfFct(), {stdErrValue, globalString});
858
1/2
✗ Branch 139 → 140 not taken.
✓ Branch 139 → 148 taken 3442 times.
3442 if (cliOptions.printsStackTraceOnAbort())
859 ✗ builder.CreateCall(stdFunctionManager.getDumpStacktraceFct(), {builder.getTrue(), builder.getFalse()});
860
6/12
✓ Branch 148 → 149 taken 3442 times.
✗ Branch 148 → 434 not taken.
✓ Branch 149 → 150 taken 3442 times.
✗ Branch 149 → 432 not taken.
✓ Branch 151 → 152 taken 3442 times.
✗ Branch 151 → 431 not taken.
✓ Branch 152 → 153 taken 3442 times.
✗ Branch 152 → 431 not taken.
✓ Branch 153 → 154 taken 3442 times.
✗ Branch 153 → 431 not taken.
✓ Branch 154 → 155 taken 3442 times.
✗ Branch 154 → 435 not taken.
3442 builder.CreateCall(stdFunctionManager.getExitFct(), builder.getInt32(EXIT_FAILURE));
861
1/2
✓ Branch 154 → 155 taken 3442 times.
✗ Branch 154 → 435 not taken.
3442 builder.CreateUnreachable();
862
863
1/2
✓ Branch 155 → 156 taken 3442 times.
✗ Branch 155 → 435 not taken.
3442 switchToBlock(bOk);
864 3442 }
865
866 // Get address of the payload (index 2: { tag, alignPad, payload })
867
2/4
✓ Branch 159 → 160 taken 6012 times.
✗ Branch 159 → 442 not taken.
✓ Branch 160 → 161 taken 6012 times.
✗ Branch 160 → 440 not taken.
6012 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 6012 times.
✗ Branch 162 → 443 not taken.
✗ Branch 163 → 164 not taken.
✓ Branch 163 → 165 taken 6012 times.
6012 if (fieldSymbolType.isRef()) {
871 ✗ lhs.ptr = nullptr;
872 ✗ lhs.refPtr = memberAddr;
873 } else {
874 6012 lhs.ptr = memberAddr;
875 6012 lhs.refPtr = nullptr;
876 }
877
878 6012 lhs.entry = fieldEntry;
879 6012 lhs.value = nullptr;
880 6012 break;
881 }
882
883
2/4
✓ Branch 168 → 169 taken 738976 times.
✗ Branch 168 → 457 not taken.
✗ Branch 169 → 170 not taken.
✓ Branch 169 → 171 taken 738976 times.
738976 assert(lhsSTy.is(TY_STRUCT));
884
885 // Retrieve struct scope
886
1/2
✓ Branch 171 → 172 taken 738976 times.
✗ Branch 171 → 457 not taken.
738976 Scope *structScope = lhsSTy.getBodyScope();
887
888 // Retrieve field entry
889 738976 std::vector<size_t> indexPath;
890
1/2
✓ Branch 172 → 173 taken 738976 times.
✗ Branch 172 → 455 not taken.
738976 lhs.entry = structScope->symbolTable.lookupInComposedFields(fieldName, indexPath);
891
1/2
✗ Branch 173 → 174 not taken.
✓ Branch 173 → 175 taken 738976 times.
738976 assert(lhs.entry != nullptr);
892
1/2
✓ Branch 175 → 176 taken 738976 times.
✗ Branch 175 → 455 not taken.
738976 const QualType fieldSymbolType = lhs.entry->getQualType();
893
894 // Get address of the field in the struct instance
895
2/4
✓ Branch 176 → 177 taken 738976 times.
✗ Branch 176 → 447 not taken.
✓ Branch 179 → 180 taken 738976 times.
✗ Branch 179 → 444 not taken.
1477952 std::vector<llvm::Value *> indices = {builder.getInt64(0)};
896
2/2
✓ Branch 196 → 183 taken 776620 times.
✓ Branch 196 → 197 taken 738976 times.
2254572 for (const size_t index : indexPath)
897
2/4
✓ Branch 185 → 186 taken 776620 times.
✗ Branch 185 → 448 not taken.
✓ Branch 186 → 187 taken 776620 times.
✗ Branch 186 → 448 not taken.
776620 indices.push_back(builder.getInt32(index));
898
1/2
✓ Branch 197 → 198 taken 738976 times.
✗ Branch 197 → 453 not taken.
738976 const std::string name = fieldName + ".addr";
899
2/4
✓ Branch 199 → 200 taken 738976 times.
✗ Branch 199 → 450 not taken.
✓ Branch 200 → 201 taken 738976 times.
✗ Branch 200 → 450 not taken.
738976 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 738976 times.
✗ Branch 201 → 451 not taken.
✓ Branch 202 → 203 taken 22191 times.
✓ Branch 202 → 204 taken 716785 times.
738976 if (fieldSymbolType.isRef()) {
903 22191 lhs.ptr = nullptr;
904 22191 lhs.refPtr = memberAddr;
905 } else {
906 716785 lhs.ptr = memberAddr;
907 716785 lhs.refPtr = nullptr;
908 }
909
910 // Reset the value
911 738976 lhs.value = nullptr;
912 738976 break;
913 738976 }
914 46482 case PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS: {
915 // Make sure a value is present
916
1/2
✓ Branch 210 → 211 taken 46482 times.
✗ Branch 210 → 464 not taken.
46482 resolveValue(lhsNode, lhs);
917
918 // Allocate new local variable if required
919
2/2
✓ Branch 211 → 212 taken 4 times.
✓ Branch 211 → 222 taken 46478 times.
46482 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 46482 times.
✗ Branch 222 → 464 not taken.
46482 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 46482 times.
✗ Branch 223 → 464 not taken.
✓ Branch 224 → 225 taken 20 times.
✓ Branch 224 → 226 taken 46462 times.
46482 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 46456 times.
✓ Branch 226 → 229 taken 6 times.
✓ Branch 227 → 228 taken 6 times.
✓ Branch 227 → 229 taken 46450 times.
✓ Branch 230 → 231 taken 46462 times.
✗ Branch 230 → 464 not taken.
46462 insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
933 46462 lhs.ptr = nullptr;
934 }
935 46482 break;
936 }
937 2975 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS: {
938 // Make sure a value is present
939
1/2
✓ Branch 234 → 235 taken 2975 times.
✗ Branch 234 → 471 not taken.
2975 resolveValue(lhsNode, lhs);
940
941 // Allocate new local variable if required
942
2/2
✓ Branch 235 → 236 taken 4 times.
✓ Branch 235 → 246 taken 2971 times.
2975 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 2975 times.
✗ Branch 246 → 471 not taken.
2975 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 2975 times.
✗ Branch 247 → 471 not taken.
✓ Branch 248 → 249 taken 16 times.
✓ Branch 248 → 250 taken 2959 times.
2975 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 2955 times.
✓ Branch 250 → 253 taken 4 times.
✗ Branch 251 → 252 not taken.
✓ Branch 251 → 253 taken 2955 times.
✓ Branch 254 → 255 taken 2959 times.
✗ Branch 254 → 471 not taken.
2959 insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
956 2959 lhs.ptr = nullptr;
957 }
958 2975 break;
959 }
960 300 case PostfixUnaryExprNode::PostfixUnaryOp::OP_ERR_PROPAGATION: {
961 // Get the address of the Result<T> operand
962
1/2
✓ Branch 258 → 259 taken 300 times.
✗ Branch 258 → 514 not taken.
300 llvm::Value *operandPtr = resolveAddress(lhs);
963
964 // Call isErr() on the operand
965
1/2
✗ Branch 259 → 260 not taken.
✓ Branch 259 → 261 taken 300 times.
300 assert(node->errPropIsErrFct != nullptr);
966
1/2
✓ Branch 261 → 262 taken 300 times.
✗ Branch 261 → 514 not taken.
300 llvm::Function *isErrFct = stdFunctionManager.getResultIsErrFct(node->errPropIsErrFct);
967
4/8
✓ Branch 262 → 263 taken 300 times.
✗ Branch 262 → 474 not taken.
✓ Branch 264 → 265 taken 300 times.
✗ Branch 264 → 472 not taken.
✓ Branch 265 → 266 taken 300 times.
✗ Branch 265 → 472 not taken.
✓ Branch 266 → 267 taken 300 times.
✗ Branch 266 → 514 not taken.
300 llvm::Value *isErr = builder.CreateCall(isErrFct, operandPtr);
968
969 // Create blocks
970
1/2
✓ Branch 266 → 267 taken 300 times.
✗ Branch 266 → 514 not taken.
300 const std::string codeLine = node->codeLoc.toPrettyLine();
971
2/4
✓ Branch 267 → 268 taken 300 times.
✗ Branch 267 → 477 not taken.
✓ Branch 268 → 269 taken 300 times.
✗ Branch 268 → 475 not taken.
300 llvm::BasicBlock *bThen = createBlock("err.prop.then." + codeLine);
972
2/4
✓ Branch 270 → 271 taken 300 times.
✗ Branch 270 → 480 not taken.
✓ Branch 271 → 272 taken 300 times.
✗ Branch 271 → 478 not taken.
300 llvm::BasicBlock *bExit = createBlock("err.prop.exit." + codeLine);
973
1/2
✓ Branch 273 → 274 taken 300 times.
✗ Branch 273 → 512 not taken.
300 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 300 times.
✗ Branch 274 → 512 not taken.
300 switchToBlock(bThen);
977
2/4
✓ Branch 275 → 276 taken 300 times.
✗ Branch 275 → 278 not taken.
✓ Branch 276 → 277 taken 300 times.
✗ Branch 276 → 278 not taken.
300 assert(node->errPropGetErrFct != nullptr && node->errPropCtorFct != nullptr);
978
1/2
✓ Branch 279 → 280 taken 300 times.
✗ Branch 279 → 512 not taken.
300 llvm::Function *getErrFct = stdFunctionManager.getResultGetErrFct(node->errPropGetErrFct);
979
4/8
✓ Branch 280 → 281 taken 300 times.
✗ Branch 280 → 483 not taken.
✓ Branch 282 → 283 taken 300 times.
✗ Branch 282 → 481 not taken.
✓ Branch 283 → 284 taken 300 times.
✗ Branch 283 → 481 not taken.
✓ Branch 284 → 285 taken 300 times.
✗ Branch 284 → 512 not taken.
300 llvm::Value *errorPtr = builder.CreateCall(getErrFct, operandPtr);
980
1/2
✓ Branch 284 → 285 taken 300 times.
✗ Branch 284 → 512 not taken.
300 llvm::Function *errCtorFct = stdFunctionManager.getResultErrCtorFct(node->errPropCtorFct);
981
5/8
✓ Branch 285 → 286 taken 300 times.
✗ Branch 285 → 486 not taken.
✓ Branch 287 → 288 taken 300 times.
✗ Branch 287 → 484 not taken.
✓ Branch 288 → 289 taken 300 times.
✗ Branch 288 → 484 not taken.
✓ Branch 289 → 290 taken 6 times.
✓ Branch 289 → 314 taken 294 times.
300 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 294 times.
300 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 300 times.
✗ Branch 314 → 512 not taken.
✓ Branch 315 → 316 taken 300 times.
✗ Branch 315 → 512 not taken.
300 generateScopeCleanupUpTo(node, currentScope->getFunctionScope());
996 300 blockAlreadyTerminated = true;
997
1/2
✓ Branch 316 → 317 taken 300 times.
✗ Branch 316 → 512 not taken.
300 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 300 times.
✗ Branch 317 → 512 not taken.
300 switchToBlock(bExit);
1001
1/2
✗ Branch 318 → 319 not taken.
✓ Branch 318 → 320 taken 300 times.
300 assert(node->errPropUnwrapFct != nullptr);
1002
1/2
✓ Branch 320 → 321 taken 300 times.
✗ Branch 320 → 512 not taken.
300 llvm::Function *unwrapFct = stdFunctionManager.getResultUnwrapFct(node->errPropUnwrapFct);
1003
3/6
✓ Branch 321 → 322 taken 300 times.
✗ Branch 321 → 511 not taken.
✓ Branch 323 → 324 taken 300 times.
✗ Branch 323 → 509 not taken.
✓ Branch 324 → 325 taken 300 times.
✗ Branch 324 → 509 not taken.
300 llvm::Value *unwrapped = builder.CreateCall(unwrapFct, operandPtr);
1004 300 lhs = {.ptr = unwrapped};
1005 300 break;
1006 300 }
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 846811 times.
✗ Branch 336 → 524 not taken.
846811 return lhs;
1012
5/14
✓ Branch 17 → 18 taken 2628 times.
✗ Branch 17 → 346 not taken.
✓ Branch 18 → 19 taken 2628 times.
✗ Branch 18 → 346 not taken.
✓ Branch 19 → 20 taken 2628 times.
✗ Branch 19 → 346 not taken.
✓ Branch 20 → 21 taken 2628 times.
✗ Branch 20 → 346 not taken.
✓ Branch 21 → 22 taken 2628 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.
2628 }
1013
1014 3618144 std::any IRGenerator::visitAtomicExpr(const AtomicExprNode *node) {
1015 // If constant
1016
2/2
✓ Branch 2 → 3 taken 533270 times.
✓ Branch 2 → 9 taken 3084874 times.
3618144 if (node->constant) {
1017
2/4
✓ Branch 3 → 4 taken 533270 times.
✗ Branch 3 → 82 not taken.
✓ Branch 4 → 5 taken 533270 times.
✗ Branch 4 → 80 not taken.
533270 const auto constantValue = std::any_cast<llvm::Constant *>(visit(node->constant));
1018
1/2
✓ Branch 6 → 7 taken 533270 times.
✗ Branch 6 → 83 not taken.
1066540 return LLVMExprResult{.constant = constantValue};
1019 }
1020
1021 // If value
1022
2/2
✓ Branch 9 → 10 taken 1084564 times.
✓ Branch 9 → 12 taken 2000310 times.
3084874 if (node->value)
1023
1/2
✓ Branch 10 → 11 taken 1084564 times.
✗ Branch 10 → 90 not taken.
1084564 return visit(node->value);
1024
1025 // Is assign expression
1026
2/2
✓ Branch 12 → 13 taken 10231 times.
✓ Branch 12 → 15 taken 1990079 times.
2000310 if (node->assignExpr)
1027
1/2
✓ Branch 13 → 14 taken 10231 times.
✗ Branch 13 → 90 not taken.
10231 return visit(node->assignExpr);
1028
1029
1/2
✓ Branch 15 → 16 taken 1990079 times.
✗ Branch 15 → 90 not taken.
1990079 diGenerator.setSourceLocation(node);
1030
1031 // Identifier (local or global variable access)
1032
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 1990079 times.
1990079 assert(!node->identifierFragments.empty());
1033
1034 // Get symbol table entry
1035
1/2
✓ Branch 19 → 20 taken 1990079 times.
✗ Branch 19 → 90 not taken.
1990079 const auto &[entry, accessScope, capture] = node->data.at(manIdx);
1036
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 1990079 times.
1990079 assert(entry != nullptr);
1037
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 1990079 times.
1990079 assert(accessScope != nullptr);
1038
1/2
✓ Branch 24 → 25 taken 1990079 times.
✗ Branch 24 → 90 not taken.
1990079 const QualType varSymbolType = entry->getQualType();
1039
1/2
✓ Branch 25 → 26 taken 1990079 times.
✗ Branch 25 → 90 not taken.
1990079 llvm::Type *varType = varSymbolType.toLLVMType(sourceFile);
1040
1041 // Check if external global variable
1042
7/8
✓ Branch 26 → 27 taken 56634 times.
✓ Branch 26 → 30 taken 1933445 times.
✓ Branch 27 → 28 taken 56634 times.
✗ Branch 27 → 90 not taken.
✓ Branch 28 → 29 taken 14968 times.
✓ Branch 28 → 30 taken 41666 times.
✓ Branch 31 → 32 taken 14968 times.
✓ Branch 31 → 35 taken 1975111 times.
1990079 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 14968 times.
✗ Branch 33 → 84 not taken.
14968 llvm::Value *varAddress = module->getOrInsertGlobal(entry->name, varType);
1045
1/2
✓ Branch 34 → 35 taken 14968 times.
✗ Branch 34 → 90 not taken.
14968 updateAddress(entry, varAddress);
1046 }
1047
1048 // Check if enum item
1049
2/2
✓ Branch 35 → 36 taken 198817 times.
✓ Branch 35 → 49 taken 1791262 times.
1990079 if (accessScope->type == ScopeType::ENUM) {
1050
1/2
✓ Branch 36 → 37 taken 198817 times.
✗ Branch 36 → 38 not taken.
198817 const auto itemNode = spice_pointer_cast<const EnumItemNode *>(entry->declNode);
1051
1/2
✓ Branch 45 → 46 taken 198817 times.
✗ Branch 45 → 90 not taken.
198817 llvm::Constant *constantItemValue = llvm::ConstantInt::get(varType, itemNode->itemValue);
1052
1/2
✓ Branch 46 → 47 taken 198817 times.
✗ Branch 46 → 85 not taken.
397634 return LLVMExprResult{.constant = constantItemValue, .entry = entry};
1053 }
1054
1055
1/2
✓ Branch 49 → 50 taken 1791262 times.
✗ Branch 49 → 90 not taken.
1791262 llvm::Value *address = getAddress(entry);
1056
1/2
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 1791262 times.
1791262 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 56634 times.
✓ Branch 52 → 56 taken 1734628 times.
✓ Branch 53 → 54 taken 56634 times.
✗ Branch 53 → 86 not taken.
✓ Branch 54 → 55 taken 92 times.
✓ Branch 54 → 56 taken 56542 times.
✓ Branch 57 → 58 taken 92 times.
✓ Branch 57 → 64 taken 1791170 times.
1791262 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 1791170 times.
✗ Branch 64 → 90 not taken.
✓ Branch 65 → 66 taken 1570093 times.
✓ Branch 65 → 69 taken 221077 times.
✓ Branch 66 → 67 taken 2734 times.
✓ Branch 66 → 70 taken 1567359 times.
✓ Branch 67 → 68 taken 2734 times.
✗ Branch 67 → 90 not taken.
✓ Branch 68 → 69 taken 38 times.
✓ Branch 68 → 70 taken 2696 times.
✓ Branch 71 → 72 taken 221115 times.
✓ Branch 71 → 75 taken 1570055 times.
1791170 if (varSymbolType.isRef() || (capture && capture->getMode() == BY_REFERENCE))
1068
1/2
✓ Branch 72 → 73 taken 221115 times.
✗ Branch 72 → 88 not taken.
442230 return LLVMExprResult{.refPtr = address, .entry = entry};
1069
1070
1/2
✓ Branch 75 → 76 taken 1570055 times.
✗ Branch 75 → 89 not taken.
3140110 return LLVMExprResult{.ptr = address, .entry = entry};
1071 }
1072
1073 } // namespace spice::compiler
1074