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 55234 std::any IRGenerator::visitAssignExpr(const AssignExprNode *node) {
15 // Visit ternary expression
16
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 55234 times.
55234 if (node->ternaryExpr)
17 return visit(node->ternaryExpr);
18
19 55234 diGenerator.setSourceLocation(node);
20
21 // Assign or compound assign operation
22
1/2
✓ Branch 5 → 6 taken 55234 times.
✗ Branch 5 → 60 not taken.
55234 if (node->op != AssignExprNode::AssignOp::OP_NONE) {
23 55234 const ExprNode *lhsNode = node->lhs;
24 55234 const ExprNode *rhsNode = node->rhs;
25
26 // Normal assignment
27
2/2
✓ Branch 6 → 7 taken 49179 times.
✓ Branch 6 → 11 taken 6055 times.
55234 if (node->op == AssignExprNode::AssignOp::OP_ASSIGN)
28
2/4
✓ Branch 7 → 8 taken 49179 times.
✗ Branch 7 → 69 not taken.
✓ Branch 8 → 9 taken 49179 times.
✗ Branch 8 → 69 not taken.
98358 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 6055 times.
✗ Branch 11 → 85 not taken.
6055 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
33
1/2
✓ Branch 12 → 13 taken 6055 times.
✗ Branch 12 → 85 not taken.
6055 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
34
35 // Retrieve rhs
36
2/4
✓ Branch 13 → 14 taken 6055 times.
✗ Branch 13 → 72 not taken.
✓ Branch 14 → 15 taken 6055 times.
✗ Branch 14 → 70 not taken.
6055 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
37 // Retrieve lhs
38
2/4
✓ Branch 16 → 17 taken 6055 times.
✗ Branch 16 → 75 not taken.
✓ Branch 17 → 18 taken 6055 times.
✗ Branch 17 → 73 not taken.
6055 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
39
40 6055 LLVMExprResult result;
41
10/11
✓ Branch 19 → 20 taken 4187 times.
✓ Branch 19 → 22 taken 191 times.
✓ Branch 19 → 24 taken 506 times.
✓ Branch 19 → 26 taken 224 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 683 times.
✗ Branch 19 → 40 not taken.
6055 switch (node->op) {
42 4187 case AssignExprNode::AssignOp::OP_PLUS_EQUAL:
43
1/2
✓ Branch 20 → 21 taken 4187 times.
✗ Branch 20 → 85 not taken.
4187 result = conversionManager.getPlusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
44 4187 break;
45 191 case AssignExprNode::AssignOp::OP_MINUS_EQUAL:
46
1/2
✓ Branch 22 → 23 taken 191 times.
✗ Branch 22 → 85 not taken.
191 result = conversionManager.getMinusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
47 191 break;
48 506 case AssignExprNode::AssignOp::OP_MUL_EQUAL:
49
1/2
✓ Branch 24 → 25 taken 506 times.
✗ Branch 24 → 85 not taken.
506 result = conversionManager.getMulEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
50 506 break;
51 224 case AssignExprNode::AssignOp::OP_DIV_EQUAL:
52
1/2
✓ Branch 26 → 27 taken 224 times.
✗ Branch 26 → 85 not taken.
224 result = conversionManager.getDivEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
53 224 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 683 case AssignExprNode::AssignOp::OP_XOR_EQUAL:
70
1/2
✓ Branch 38 → 39 taken 683 times.
✗ Branch 38 → 85 not taken.
683 result = conversionManager.getXorEqualInst(node, lhs, lhsSTy, rhs, rhsSTy);
71 683 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 6055 times.
6055 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 4289 times.
✓ Branch 51 → 57 taken 1766 times.
6055 } else if (result.value) { // The operation only updated the value
80 // Store the result
81 4289 lhs.value = result.value;
82
5/6
✓ Branch 52 → 53 taken 4187 times.
✓ Branch 52 → 55 taken 102 times.
✓ Branch 53 → 54 taken 2 times.
✓ Branch 53 → 55 taken 4185 times.
✓ Branch 56 → 57 taken 4289 times.
✗ Branch 56 → 85 not taken.
4289 insertStore(lhs.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
83 }
84
1/2
✓ Branch 57 → 58 taken 6055 times.
✗ Branch 57 → 85 not taken.
6055 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 3804 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 3804 times.
3804 if (!node->falseExpr)
94 return visit(node->condition);
95
96
1/2
✓ Branch 5 → 6 taken 3804 times.
✗ Branch 5 → 269 not taken.
3804 diGenerator.setSourceLocation(node);
97
98 // It is a ternary
99 // Retrieve the condition value
100
1/2
✓ Branch 6 → 7 taken 3804 times.
✗ Branch 6 → 269 not taken.
3804 llvm::Value *condValue = resolveValue(node->condition);
101
2/2
✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 9 taken 3802 times.
3804 const ExprNode *trueNode = node->isShortened ? node->condition : node->trueExpr;
102 3804 const ExprNode *falseNode = node->falseExpr;
103
104 3804 llvm::Value *resultValue = nullptr;
105 3804 llvm::Value *resultPtr = nullptr;
106 3804 const SymbolTableEntry *anonymousSymbol = nullptr;
107
8/10
✓ Branch 10 → 11 taken 3804 times.
✗ Branch 10 → 269 not taken.
✓ Branch 11 → 12 taken 978 times.
✓ Branch 11 → 15 taken 2826 times.
✓ Branch 12 → 13 taken 978 times.
✗ Branch 12 → 269 not taken.
✓ Branch 13 → 14 taken 920 times.
✓ Branch 13 → 15 taken 58 times.
✓ Branch 16 → 17 taken 920 times.
✓ Branch 16 → 22 taken 2884 times.
3804 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 920 times.
✗ Branch 17 → 269 not taken.
920 llvm::Value *trueValue = resolveValue(trueNode);
110
1/2
✓ Branch 18 → 19 taken 920 times.
✗ Branch 18 → 269 not taken.
920 llvm::Value *falseValue = resolveValue(falseNode);
111
2/4
✓ Branch 19 → 20 taken 920 times.
✗ Branch 19 → 193 not taken.
✓ Branch 20 → 21 taken 920 times.
✗ Branch 20 → 193 not taken.
920 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 2884 times.
✗ Branch 22 → 267 not taken.
2884 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
115
2/4
✓ Branch 23 → 24 taken 2884 times.
✗ Branch 23 → 196 not taken.
✓ Branch 24 → 25 taken 2884 times.
✗ Branch 24 → 194 not taken.
2884 llvm::BasicBlock *condTrue = createBlock("cond.true." + codeLoc);
116
2/4
✓ Branch 26 → 27 taken 2884 times.
✗ Branch 26 → 199 not taken.
✓ Branch 27 → 28 taken 2884 times.
✗ Branch 27 → 197 not taken.
2884 llvm::BasicBlock *condFalse = createBlock("cond.false." + codeLoc);
117
2/4
✓ Branch 29 → 30 taken 2884 times.
✗ Branch 29 → 202 not taken.
✓ Branch 30 → 31 taken 2884 times.
✗ Branch 30 → 200 not taken.
2884 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 2884 times.
✗ Branch 32 → 265 not taken.
2884 insertCondJump(condValue, condTrue, condFalse);
121
122 // Fill true block
123
1/2
✓ Branch 33 → 34 taken 2884 times.
✗ Branch 33 → 265 not taken.
2884 switchToBlock(condTrue);
124
1/2
✓ Branch 34 → 35 taken 2884 times.
✗ Branch 34 → 265 not taken.
2884 const QualType &resultType = node->getEvaluatedSymbolType(manIdx);
125 2884 llvm::Value *trueValue = nullptr;
126 2884 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 2884 std::optional<ExprScopeHandle> trueScopeHandle;
129
2/2
✓ Branch 35 → 36 taken 2882 times.
✓ Branch 35 → 38 taken 2 times.
2884 if (!node->isShortened)
130
1/2
✓ Branch 36 → 37 taken 2882 times.
✗ Branch 36 → 203 not taken.
2882 trueScopeHandle.emplace(static_cast<CompilerPass *>(this), trueNode);
131
2/2
✓ Branch 39 → 40 taken 2882 times.
✓ Branch 39 → 42 taken 2 times.
2884 const Scope *trueScope = trueScopeHandle ? trueScopeHandle->getExprScope() : nullptr;
132
7/8
✓ Branch 43 → 44 taken 2830 times.
✓ Branch 43 → 46 taken 54 times.
✓ Branch 44 → 45 taken 2830 times.
✗ Branch 44 → 263 not taken.
✓ Branch 45 → 46 taken 32 times.
✓ Branch 45 → 47 taken 2798 times.
✓ Branch 48 → 49 taken 86 times.
✓ Branch 48 → 51 taken 2798 times.
2884 if (node->falseSideCallsCopyCtor || resultType.isRef()) { // both sides or only the false side needs copy ctor call
133
1/2
✓ Branch 49 → 50 taken 86 times.
✗ Branch 49 → 263 not taken.
86 truePtr = resolveAddress(trueNode);
134
2/2
✓ Branch 51 → 52 taken 8 times.
✓ Branch 51 → 66 taken 2790 times.
2798 } 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 2790 times.
✗ Branch 66 → 263 not taken.
2790 trueValue = resolveValue(trueNode);
143 }
144 2884 trueScopeHandle.reset();
145 // Set the true block to the current insert point, since it could have changed in the meantime
146 2884 condTrue = builder.GetInsertBlock();
147
1/2
✓ Branch 70 → 71 taken 2884 times.
✗ Branch 70 → 263 not taken.
2884 insertJump(condExit);
148
149 // Fill false block
150
1/2
✓ Branch 71 → 72 taken 2884 times.
✗ Branch 71 → 263 not taken.
2884 switchToBlock(condFalse);
151 2884 llvm::Value *falseValue = nullptr;
152 2884 llvm::Value *falsePtr = nullptr;
153 // The false branch has an expression scope for its temporaries
154 2884 std::optional<ExprScopeHandle> falseScopeHandle;
155
1/2
✓ Branch 72 → 73 taken 2884 times.
✗ Branch 72 → 217 not taken.
2884 falseScopeHandle.emplace(static_cast<CompilerPass *>(this), falseNode);
156 2884 const Scope *falseScope = falseScopeHandle->getExprScope();
157
7/8
✓ Branch 75 → 76 taken 2864 times.
✓ Branch 75 → 78 taken 20 times.
✓ Branch 76 → 77 taken 2864 times.
✗ Branch 76 → 261 not taken.
✓ Branch 77 → 78 taken 32 times.
✓ Branch 77 → 79 taken 2832 times.
✓ Branch 80 → 81 taken 52 times.
✓ Branch 80 → 83 taken 2832 times.
2884 if (node->trueSideCallsCopyCtor || resultType.isRef()) { // both sides or only the true side needs copy ctor call
158
1/2
✓ Branch 81 → 82 taken 52 times.
✗ Branch 81 → 261 not taken.
52 falsePtr = resolveAddress(falseNode);
159
2/2
✓ Branch 83 → 84 taken 42 times.
✓ Branch 83 → 98 taken 2790 times.
2832 } else if (node->falseSideCallsCopyCtor) { // only false side needs copy ctor call
160
1/2
✓ Branch 84 → 85 taken 42 times.
✗ Branch 84 → 261 not taken.
42 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 42 times.
✗ Branch 88 → 218 not taken.
42 falsePtr = insertAlloca(resultType);
164
2/4
✓ Branch 93 → 94 taken 42 times.
✗ Branch 93 → 226 not taken.
✓ Branch 94 → 95 taken 42 times.
✗ Branch 94 → 224 not taken.
126 generateCtorOrDtorCall(falsePtr, node->calledCopyCtor, {originalPtr});
165 } else { // neither true nor false side need copy ctor call
166
1/2
✓ Branch 98 → 99 taken 2790 times.
✗ Branch 98 → 261 not taken.
2790 falseValue = resolveValue(falseNode);
167 }
168 2884 falseScopeHandle.reset();
169 // Set the true block to the current insert point, since it could have changed in the meantime
170 2884 condFalse = builder.GetInsertBlock();
171
1/2
✓ Branch 102 → 103 taken 2884 times.
✗ Branch 102 → 261 not taken.
2884 insertJump(condExit);
172
173 // Fill the exit block
174
1/2
✓ Branch 103 → 104 taken 2884 times.
✗ Branch 103 → 261 not taken.
2884 switchToBlock(condExit);
175
9/10
✓ Branch 104 → 105 taken 2864 times.
✓ Branch 104 → 108 taken 20 times.
✓ Branch 105 → 106 taken 2822 times.
✓ Branch 105 → 108 taken 42 times.
✓ Branch 106 → 107 taken 2822 times.
✗ Branch 106 → 261 not taken.
✓ Branch 107 → 108 taken 32 times.
✓ Branch 107 → 109 taken 2790 times.
✓ Branch 110 → 111 taken 94 times.
✓ Branch 110 → 133 taken 2790 times.
2884 if (node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor || resultType.isRef()) { // one side calls copy ctor
176
3/6
✓ Branch 111 → 112 taken 94 times.
✗ Branch 111 → 231 not taken.
✓ Branch 112 → 113 taken 94 times.
✗ Branch 112 → 231 not taken.
✓ Branch 113 → 114 taken 94 times.
✗ Branch 113 → 231 not taken.
94 llvm::PHINode *phiInst = builder.CreatePHI(builder.getPtrTy(), 2, "cond.result");
177
1/2
✓ Branch 114 → 115 taken 94 times.
✗ Branch 114 → 261 not taken.
94 phiInst->addIncoming(truePtr, condTrue);
178
1/2
✓ Branch 115 → 116 taken 94 times.
✗ Branch 115 → 261 not taken.
94 phiInst->addIncoming(falsePtr, condFalse);
179
4/4
✓ Branch 116 → 117 taken 20 times.
✓ Branch 116 → 131 taken 74 times.
✓ Branch 117 → 118 taken 12 times.
✓ Branch 117 → 131 taken 8 times.
94 if (node->trueSideCallsCopyCtor && node->falseSideCallsCopyCtor) { // both sides need copy ctor call
180
1/2
✓ Branch 121 → 122 taken 12 times.
✗ Branch 121 → 232 not taken.
12 resultPtr = insertAlloca(resultType);
181
2/4
✓ Branch 126 → 127 taken 12 times.
✗ Branch 126 → 240 not taken.
✓ Branch 127 → 128 taken 12 times.
✗ Branch 127 → 238 not taken.
36 generateCtorOrDtorCall(resultPtr, node->calledCopyCtor, {phiInst});
182 } else {
183 82 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 2790 times.
2790 assert(trueValue != nullptr);
187
3/6
✓ Branch 135 → 136 taken 2790 times.
✗ Branch 135 → 245 not taken.
✓ Branch 136 → 137 taken 2790 times.
✗ Branch 136 → 245 not taken.
✓ Branch 137 → 138 taken 2790 times.
✗ Branch 137 → 245 not taken.
2790 llvm::PHINode *phiInst = builder.CreatePHI(resultType.toLLVMType(sourceFile), 2, "cond.result");
188
1/2
✓ Branch 138 → 139 taken 2790 times.
✗ Branch 138 → 261 not taken.
2790 phiInst->addIncoming(trueValue, condTrue);
189
1/2
✓ Branch 139 → 140 taken 2790 times.
✗ Branch 139 → 261 not taken.
2790 phiInst->addIncoming(falseValue, condFalse);
190 2790 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 2884 times.
✗ Branch 141 → 261 not taken.
2884 anonymousSymbol = currentScope->symbolTable.lookupAnonymous(node);
195
2/2
✓ Branch 142 → 143 taken 20 times.
✓ Branch 142 → 153 taken 2864 times.
2884 if (anonymousSymbol != nullptr) {
196
1/2
✗ Branch 143 → 144 not taken.
✓ Branch 143 → 152 taken 20 times.
20 if (!resultPtr) {
197 resultPtr = insertAlloca(anonymousSymbol->getQualType());
198 insertStore(resultValue, resultPtr);
199 }
200
1/2
✓ Branch 152 → 153 taken 20 times.
✗ Branch 152 → 261 not taken.
20 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 2882 times.
✓ Branch 153 → 157 taken 2 times.
✓ Branch 155 → 156 taken 4 times.
✓ Branch 155 → 157 taken 2878 times.
2884 const bool trueNeedsCleanup = trueScope != nullptr && !trueScope->temporaryDtorsToCall.empty();
206
3/4
✓ Branch 158 → 159 taken 2884 times.
✗ Branch 158 → 162 not taken.
✓ Branch 160 → 161 taken 2 times.
✓ Branch 160 → 162 taken 2882 times.
2884 const bool falseNeedsCleanup = falseScope != nullptr && !falseScope->temporaryDtorsToCall.empty();
207
4/4
✓ Branch 163 → 164 taken 2880 times.
✓ Branch 163 → 165 taken 4 times.
✓ Branch 164 → 165 taken 2 times.
✓ Branch 164 → 184 taken 2878 times.
2884 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 2884 }
226
227
1/2
✓ Branch 188 → 189 taken 3804 times.
✗ Branch 188 → 268 not taken.
7608 return LLVMExprResult{.value = resultValue, .ptr = resultPtr, .entry = anonymousSymbol};
228 }
229
230 5190 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 5190 times.
5190 if (node->operands.size() == 1)
233 return visit(node->operands.front());
234
235
1/2
✓ Branch 7 → 8 taken 5190 times.
✗ Branch 7 → 104 not taken.
5190 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 5190 times.
✗ Branch 8 → 104 not taken.
5190 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
240
2/4
✓ Branch 9 → 10 taken 5190 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 5190 times.
✗ Branch 10 → 79 not taken.
5190 llvm::BasicBlock *bExit = createBlock("lor.exit." + codeLoc);
241
242 // Visit the first operand
243
1/2
✓ Branch 13 → 14 taken 5190 times.
✗ Branch 13 → 102 not taken.
5190 llvm::Value *firstOperandValue = resolveValue(node->operands.front());
244
245 // Prepare an array for value-to-block-mapping
246 5190 std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks;
247
1/2
✓ Branch 15 → 16 taken 5190 times.
✗ Branch 15 → 100 not taken.
5190 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 5190 times.
✗ Branch 17 → 82 not taken.
5190 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 6908 times.
✓ Branch 31 → 32 taken 5190 times.
12098 for (size_t i = 1; i < node->operands.size(); i++)
252
6/12
✓ Branch 19 → 20 taken 6908 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 6908 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 6908 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 6908 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 6908 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 6908 times.
✗ Branch 24 → 83 not taken.
6908 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 5190 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 5190 times.
✗ Branch 33 → 100 not taken.
5190 insertCondJump(firstOperandValue, bExit, shortCircuitBlocks.at(1).first);
255
256 // Create block for each operand
257
2/2
✓ Branch 50 → 35 taken 6908 times.
✓ Branch 50 → 51 taken 5190 times.
12098 for (size_t i = 1; i < node->operands.size(); i++) {
258 // Switch to the next block
259
2/4
✓ Branch 35 → 36 taken 6908 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 6908 times.
✗ Branch 36 → 100 not taken.
6908 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 6908 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 6908 times.
✗ Branch 39 → 100 not taken.
6908 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 6908 times.
✗ Branch 41 → 100 not taken.
6908 shortCircuitBlocks.at(i).first = builder.GetInsertBlock();
265 // Check if there are more blocks to process
266
2/2
✓ Branch 43 → 44 taken 5190 times.
✓ Branch 43 → 45 taken 1718 times.
6908 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 5190 times.
✗ Branch 44 → 100 not taken.
5190 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 1718 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 1718 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 1718 times.
✗ Branch 47 → 100 not taken.
1718 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 5190 times.
✗ Branch 51 → 100 not taken.
5190 switchToBlock(bExit);
277
2/4
✓ Branch 52 → 53 taken 5190 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 5190 times.
✗ Branch 55 → 97 not taken.
5190 llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "lor_phi");
278
2/2
✓ Branch 72 → 58 taken 12098 times.
✓ Branch 72 → 73 taken 5190 times.
34576 for (const auto &[incomingBlock, value] : shortCircuitBlocks)
279
1/2
✓ Branch 62 → 63 taken 12098 times.
✗ Branch 62 → 98 not taken.
12098 result->addIncoming(value, incomingBlock);
280
281 // Return the result
282
1/2
✓ Branch 73 → 74 taken 5190 times.
✗ Branch 73 → 99 not taken.
5190 return LLVMExprResult{.value = result};
283 5190 }
284
285 3652 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 3652 times.
3652 if (node->operands.size() == 1)
288 return visit(node->operands.front());
289
290
1/2
✓ Branch 7 → 8 taken 3652 times.
✗ Branch 7 → 104 not taken.
3652 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 3652 times.
✗ Branch 8 → 104 not taken.
3652 const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn();
295
2/4
✓ Branch 9 → 10 taken 3652 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 3652 times.
✗ Branch 10 → 79 not taken.
3652 llvm::BasicBlock *bExit = createBlock("land.exit." + codeLoc);
296
297 // Visit the first operand
298
1/2
✓ Branch 13 → 14 taken 3652 times.
✗ Branch 13 → 102 not taken.
3652 llvm::Value *firstOperandValue = resolveValue(node->operands.front());
299
300 // Prepare an array for value-to-block-mapping
301 3652 std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks;
302
1/2
✓ Branch 15 → 16 taken 3652 times.
✗ Branch 15 → 100 not taken.
3652 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 3652 times.
✗ Branch 17 → 82 not taken.
3652 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 4716 times.
✓ Branch 31 → 32 taken 3652 times.
8368 for (size_t i = 1; i < node->operands.size(); i++)
307
6/12
✓ Branch 19 → 20 taken 4716 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 4716 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 4716 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 4716 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 4716 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 4716 times.
✗ Branch 24 → 83 not taken.
4716 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 3652 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 3652 times.
✗ Branch 33 → 100 not taken.
3652 insertCondJump(firstOperandValue, shortCircuitBlocks.at(1).first, bExit);
310
311 // Create block for each operand
312
2/2
✓ Branch 50 → 35 taken 4716 times.
✓ Branch 50 → 51 taken 3652 times.
8368 for (size_t i = 1; i < node->operands.size(); i++) {
313 // Switch to the next block
314
2/4
✓ Branch 35 → 36 taken 4716 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 4716 times.
✗ Branch 36 → 100 not taken.
4716 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 4716 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 4716 times.
✗ Branch 39 → 100 not taken.
4716 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 4716 times.
✗ Branch 41 → 100 not taken.
4716 shortCircuitBlocks.at(i).first = builder.GetInsertBlock();
320 // Check if there are more blocks to process
321
2/2
✓ Branch 43 → 44 taken 3652 times.
✓ Branch 43 → 45 taken 1064 times.
4716 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 3652 times.
✗ Branch 44 → 100 not taken.
3652 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 1064 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 1064 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 1064 times.
✗ Branch 47 → 100 not taken.
1064 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 3652 times.
✗ Branch 51 → 100 not taken.
3652 switchToBlock(bExit);
332
2/4
✓ Branch 52 → 53 taken 3652 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 3652 times.
✗ Branch 55 → 97 not taken.
3652 llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "land_phi");
333
2/2
✓ Branch 72 → 58 taken 8368 times.
✓ Branch 72 → 73 taken 3652 times.
24040 for (const auto &[incomingBlock, value] : shortCircuitBlocks)
334
1/2
✓ Branch 62 → 63 taken 8368 times.
✗ Branch 62 → 98 not taken.
8368 result->addIncoming(value, incomingBlock);
335
336 // Return the result
337
1/2
✓ Branch 73 → 74 taken 3652 times.
✗ Branch 73 → 99 not taken.
3652 return LLVMExprResult{.value = result};
338 3652 }
339
340 778 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 778 times.
778 if (node->operands.size() == 1)
343 return visit(node->operands.front());
344
345
1/2
✓ Branch 7 → 8 taken 778 times.
✗ Branch 7 → 34 not taken.
778 diGenerator.setSourceLocation(node);
346
347 // It is a bitwise or expression
348 // Evaluate first operand
349 778 const ExprNode *lhsNode = node->operands.front();
350
1/2
✓ Branch 9 → 10 taken 778 times.
✗ Branch 9 → 34 not taken.
778 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
351
2/4
✓ Branch 10 → 11 taken 778 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 778 times.
✗ Branch 11 → 27 not taken.
778 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
352
353 // Evaluate all additional operands
354
2/2
✓ Branch 22 → 14 taken 780 times.
✓ Branch 22 → 23 taken 778 times.
1558 for (size_t i = 1; i < node->operands.size(); i++) {
355 // Evaluate the operand
356 780 const ExprNode *rhsNode = node->operands[i];
357
1/2
✓ Branch 15 → 16 taken 780 times.
✗ Branch 15 → 33 not taken.
780 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
358
2/4
✓ Branch 16 → 17 taken 780 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 780 times.
✗ Branch 17 → 30 not taken.
780 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
359
1/2
✓ Branch 19 → 20 taken 780 times.
✗ Branch 19 → 33 not taken.
780 result = conversionManager.getBitwiseOrInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
360 }
361
362 // Return result
363
1/2
✓ Branch 23 → 24 taken 778 times.
✗ Branch 23 → 34 not taken.
778 return result;
364 }
365
366 145 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 145 times.
145 if (node->operands.size() == 1)
369 return visit(node->operands.front());
370
371
1/2
✓ Branch 7 → 8 taken 145 times.
✗ Branch 7 → 34 not taken.
145 diGenerator.setSourceLocation(node);
372
373 // It is a bitwise xor expression
374 // Evaluate first operand
375 145 const ExprNode *lhsNode = node->operands.front();
376
1/2
✓ Branch 9 → 10 taken 145 times.
✗ Branch 9 → 34 not taken.
145 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
377
2/4
✓ Branch 10 → 11 taken 145 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 145 times.
✗ Branch 11 → 27 not taken.
145 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
378
379 // Evaluate all additional operands
380
2/2
✓ Branch 22 → 14 taken 147 times.
✓ Branch 22 → 23 taken 145 times.
292 for (size_t i = 1; i < node->operands.size(); i++) {
381 // Evaluate the operand
382 147 const ExprNode *rhsNode = node->operands[i];
383
1/2
✓ Branch 15 → 16 taken 147 times.
✗ Branch 15 → 33 not taken.
147 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
384
2/4
✓ Branch 16 → 17 taken 147 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 147 times.
✗ Branch 17 → 30 not taken.
147 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
385
1/2
✓ Branch 19 → 20 taken 147 times.
✗ Branch 19 → 33 not taken.
147 result = conversionManager.getBitwiseXorInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
386 }
387
388 // Return result
389
1/2
✓ Branch 23 → 24 taken 145 times.
✗ Branch 23 → 34 not taken.
145 return result;
390 }
391
392 668 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 668 times.
668 if (node->operands.size() == 1)
395 return visit(node->operands.front());
396
397
1/2
✓ Branch 7 → 8 taken 668 times.
✗ Branch 7 → 34 not taken.
668 diGenerator.setSourceLocation(node);
398
399 // It is a bitwise and expression
400 // Evaluate first operand
401 668 const ExprNode *lhsNode = node->operands.front();
402
1/2
✓ Branch 9 → 10 taken 668 times.
✗ Branch 9 → 34 not taken.
668 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
403
2/4
✓ Branch 10 → 11 taken 668 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 668 times.
✗ Branch 11 → 27 not taken.
668 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
404
405 // Evaluate all additional operands
406
2/2
✓ Branch 22 → 14 taken 670 times.
✓ Branch 22 → 23 taken 668 times.
1338 for (size_t i = 1; i < node->operands.size(); i++) {
407 // Evaluate the operand
408 670 const ExprNode *rhsNode = node->operands[i];
409
1/2
✓ Branch 15 → 16 taken 670 times.
✗ Branch 15 → 33 not taken.
670 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
410
2/4
✓ Branch 16 → 17 taken 670 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 670 times.
✗ Branch 17 → 30 not taken.
670 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
411
1/2
✓ Branch 19 → 20 taken 670 times.
✗ Branch 19 → 33 not taken.
670 result = conversionManager.getBitwiseAndInst(node, result, lhsSTy, rhs, rhsSTy, i - 1);
412 }
413
414 // Return result
415
1/2
✓ Branch 23 → 24 taken 668 times.
✗ Branch 23 → 34 not taken.
668 return result;
416 }
417
418 46908 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 46908 times.
46908 if (node->operands.size() == 1)
421 return visit(node->operands.front());
422
423
1/2
✓ Branch 7 → 8 taken 46908 times.
✗ Branch 7 → 50 not taken.
46908 diGenerator.setSourceLocation(node);
424
425 // It is an equality expression
426 // Evaluate lhs
427 46908 const ExprNode *lhsNode = node->operands[0];
428
1/2
✓ Branch 9 → 10 taken 46908 times.
✗ Branch 9 → 50 not taken.
46908 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
429
2/4
✓ Branch 10 → 11 taken 46908 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 46908 times.
✗ Branch 11 → 35 not taken.
46908 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
430
431 // Evaluate rhs
432 46908 const ExprNode *rhsNode = node->operands[1];
433
1/2
✓ Branch 14 → 15 taken 46908 times.
✗ Branch 14 → 50 not taken.
46908 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
434
2/4
✓ Branch 15 → 16 taken 46908 times.
✗ Branch 15 → 40 not taken.
✓ Branch 16 → 17 taken 46908 times.
✗ Branch 16 → 38 not taken.
46908 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 39147 times.
✓ Branch 18 → 21 taken 7761 times.
✗ Branch 18 → 23 not taken.
46908 switch (node->op) {
438 39147 case EqualityExprNode::EqualityOp::OP_EQUAL:
439
1/2
✓ Branch 19 → 20 taken 39147 times.
✗ Branch 19 → 50 not taken.
39147 result = conversionManager.getEqualInst(node, result, lhsSTy, rhs, rhsSTy);
440 39147 break;
441 7761 case EqualityExprNode::EqualityOp::OP_NOT_EQUAL:
442
1/2
✓ Branch 21 → 22 taken 7761 times.
✗ Branch 21 → 50 not taken.
7761 result = conversionManager.getNotEqualInst(node, result, lhsSTy, rhs, rhsSTy);
443 7761 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 46908 times.
✗ Branch 31 → 50 not taken.
46908 return result;
450 }
451
452 28200 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 28200 times.
28200 if (node->operands.size() == 1)
455 return visit(node->operands.front());
456
457
1/2
✓ Branch 7 → 8 taken 28200 times.
✗ Branch 7 → 54 not taken.
28200 diGenerator.setSourceLocation(node);
458
459 // It is a relational expression
460 // Evaluate lhs
461 28200 const ExprNode *lhsNode = node->operands[0];
462
1/2
✓ Branch 9 → 10 taken 28200 times.
✗ Branch 9 → 54 not taken.
28200 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
463
2/4
✓ Branch 10 → 11 taken 28200 times.
✗ Branch 10 → 41 not taken.
✓ Branch 11 → 12 taken 28200 times.
✗ Branch 11 → 39 not taken.
28200 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
464
465 // Evaluate rhs
466 28200 const ExprNode *rhsNode = node->operands[1];
467
1/2
✓ Branch 14 → 15 taken 28200 times.
✗ Branch 14 → 54 not taken.
28200 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
468
2/4
✓ Branch 15 → 16 taken 28200 times.
✗ Branch 15 → 44 not taken.
✓ Branch 16 → 17 taken 28200 times.
✗ Branch 16 → 42 not taken.
28200 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 11475 times.
✓ Branch 18 → 21 taken 6460 times.
✓ Branch 18 → 23 taken 3648 times.
✓ Branch 18 → 25 taken 6617 times.
✗ Branch 18 → 27 not taken.
28200 switch (node->op) {
472 11475 case RelationalExprNode::RelationalOp::OP_LESS:
473
1/2
✓ Branch 19 → 20 taken 11475 times.
✗ Branch 19 → 54 not taken.
11475 result = conversionManager.getLessInst(node, result, lhsSTy, rhs, rhsSTy);
474 11475 break;
475 6460 case RelationalExprNode::RelationalOp::OP_GREATER:
476
1/2
✓ Branch 21 → 22 taken 6460 times.
✗ Branch 21 → 54 not taken.
6460 result = conversionManager.getGreaterInst(node, result, lhsSTy, rhs, rhsSTy);
477 6460 break;
478 3648 case RelationalExprNode::RelationalOp::OP_LESS_EQUAL:
479
1/2
✓ Branch 23 → 24 taken 3648 times.
✗ Branch 23 → 54 not taken.
3648 result = conversionManager.getLessEqualInst(node, result, lhsSTy, rhs, rhsSTy);
480 3648 break;
481 6617 case RelationalExprNode::RelationalOp::OP_GREATER_EQUAL:
482
1/2
✓ Branch 25 → 26 taken 6617 times.
✗ Branch 25 → 54 not taken.
6617 result = conversionManager.getGreaterEqualInst(node, result, lhsSTy, rhs, rhsSTy);
483 6617 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 28200 times.
✗ Branch 35 → 54 not taken.
28200 return result;
490 }
491
492 3640 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 3640 times.
3640 if (node->operands.size() == 1)
495 return visit(node->operands.front());
496
497
1/2
✓ Branch 7 → 8 taken 3640 times.
✗ Branch 7 → 64 not taken.
3640 diGenerator.setSourceLocation(node);
498
499 // It is a shift expression
500 // Evaluate first operand
501 3640 const ExprNode *lhsNode = node->operands.front();
502
1/2
✓ Branch 9 → 10 taken 3640 times.
✗ Branch 9 → 64 not taken.
3640 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
503
2/4
✓ Branch 10 → 11 taken 3640 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 3640 times.
✗ Branch 11 → 46 not taken.
3640 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
504
505
1/2
✓ Branch 13 → 14 taken 3640 times.
✗ Branch 13 → 64 not taken.
3640 auto opQueue = node->opQueue;
506 3640 size_t operandIndex = 1;
507
2/2
✓ Branch 40 → 15 taken 5316 times.
✓ Branch 40 → 41 taken 3640 times.
8956 while (!opQueue.empty()) {
508 5316 const size_t operatorIndex = operandIndex - 1;
509 // Evaluate next operand
510 5316 const ExprNode *rhsNode = node->operands[operandIndex++];
511
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 5316 times.
5316 assert(rhsNode != nullptr);
512
1/2
✓ Branch 18 → 19 taken 5316 times.
✗ Branch 18 → 61 not taken.
5316 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
513
2/4
✓ Branch 19 → 20 taken 5316 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 5316 times.
✗ Branch 20 → 49 not taken.
5316 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 4565 times.
✓ Branch 23 → 26 taken 751 times.
✗ Branch 23 → 28 not taken.
5316 switch (opQueue.front().first) {
517 4565 case ShiftExprNode::ShiftOp::OP_SHIFT_LEFT:
518
1/2
✓ Branch 24 → 25 taken 4565 times.
✗ Branch 24 → 61 not taken.
4565 lhs = conversionManager.getShiftLeftInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
519 4565 break;
520 751 case ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT:
521
1/2
✓ Branch 26 → 27 taken 751 times.
✗ Branch 26 → 61 not taken.
751 lhs = conversionManager.getShiftRightInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
522 751 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 5316 lhsSTy = opQueue.front().second;
529
530 5316 opQueue.pop();
531 }
532
533 // Return the result
534
1/2
✓ Branch 41 → 42 taken 3640 times.
✗ Branch 41 → 62 not taken.
3640 return lhs;
535 3640 }
536
537 24495 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 24495 times.
24495 if (node->operands.size() == 1)
540 return visit(node->operands.front());
541
542
1/2
✓ Branch 7 → 8 taken 24495 times.
✗ Branch 7 → 64 not taken.
24495 diGenerator.setSourceLocation(node);
543
544 // It is an additive expression
545 // Evaluate first operand
546 24495 const ExprNode *lhsNode = node->operands[0];
547
1/2
✓ Branch 9 → 10 taken 24495 times.
✗ Branch 9 → 64 not taken.
24495 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
548
2/4
✓ Branch 10 → 11 taken 24495 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 24495 times.
✗ Branch 11 → 46 not taken.
24495 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
549
550
1/2
✓ Branch 13 → 14 taken 24495 times.
✗ Branch 13 → 64 not taken.
24495 auto opQueue = node->opQueue;
551 24495 size_t operandIndex = 1;
552
2/2
✓ Branch 40 → 15 taken 27646 times.
✓ Branch 40 → 41 taken 24495 times.
52141 while (!opQueue.empty()) {
553 27646 const size_t operatorIndex = operandIndex - 1;
554 // Evaluate next operand
555 27646 const ExprNode *rhsNode = node->operands[operandIndex++];
556
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 27646 times.
27646 assert(rhsNode != nullptr);
557
1/2
✓ Branch 18 → 19 taken 27646 times.
✗ Branch 18 → 61 not taken.
27646 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
558
2/4
✓ Branch 19 → 20 taken 27646 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 27646 times.
✗ Branch 20 → 49 not taken.
27646 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 17544 times.
✓ Branch 23 → 26 taken 10102 times.
✗ Branch 23 → 28 not taken.
27646 switch (opQueue.front().first) {
562 17544 case AdditiveExprNode::AdditiveOp::OP_PLUS:
563
1/2
✓ Branch 24 → 25 taken 17544 times.
✗ Branch 24 → 61 not taken.
17544 lhs = conversionManager.getPlusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
564 17544 break;
565 10102 case AdditiveExprNode::AdditiveOp::OP_MINUS:
566
1/2
✓ Branch 26 → 27 taken 10102 times.
✗ Branch 26 → 61 not taken.
10102 lhs = conversionManager.getMinusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex);
567 10102 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 27646 lhsSTy = opQueue.front().second;
574
575 27646 opQueue.pop();
576 }
577
578 // Return the result
579
1/2
✓ Branch 41 → 42 taken 24495 times.
✗ Branch 41 → 62 not taken.
24495 return lhs;
580 24495 }
581
582 5739 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 5739 times.
5739 if (node->operands.size() == 1)
585 return visit(node->operands.front());
586
587
1/2
✓ Branch 7 → 8 taken 5739 times.
✗ Branch 7 → 66 not taken.
5739 diGenerator.setSourceLocation(node);
588
589 // It is an additive expression
590 // Evaluate first operand
591 5739 const ExprNode *lhsNode = node->operands[0];
592
1/2
✓ Branch 9 → 10 taken 5739 times.
✗ Branch 9 → 66 not taken.
5739 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
593
2/4
✓ Branch 10 → 11 taken 5739 times.
✗ Branch 10 → 50 not taken.
✓ Branch 11 → 12 taken 5739 times.
✗ Branch 11 → 48 not taken.
5739 auto result = std::any_cast<LLVMExprResult>(visit(lhsNode));
594
595
1/2
✓ Branch 13 → 14 taken 5739 times.
✗ Branch 13 → 66 not taken.
5739 auto opQueue = node->opQueue;
596 5739 size_t operandIndex = 1;
597
2/2
✓ Branch 42 → 15 taken 6009 times.
✓ Branch 42 → 43 taken 5739 times.
11748 while (!opQueue.empty()) {
598 6009 const size_t operatorIndex = operandIndex - 1;
599 // Evaluate next operand
600 6009 const ExprNode *rhsNode = node->operands[operandIndex++];
601
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 6009 times.
6009 assert(rhsNode != nullptr);
602
1/2
✓ Branch 18 → 19 taken 6009 times.
✗ Branch 18 → 63 not taken.
6009 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
603
2/4
✓ Branch 19 → 20 taken 6009 times.
✗ Branch 19 → 53 not taken.
✓ Branch 20 → 21 taken 6009 times.
✗ Branch 20 → 51 not taken.
6009 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 4793 times.
✓ Branch 23 → 26 taken 980 times.
✓ Branch 23 → 28 taken 236 times.
✗ Branch 23 → 30 not taken.
6009 switch (opQueue.front().first) {
607 4793 case MultiplicativeExprNode::MultiplicativeOp::OP_MUL:
608
1/2
✓ Branch 24 → 25 taken 4793 times.
✗ Branch 24 → 63 not taken.
4793 result = conversionManager.getMulInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex);
609 4793 break;
610 980 case MultiplicativeExprNode::MultiplicativeOp::OP_DIV:
611
1/2
✓ Branch 26 → 27 taken 980 times.
✗ Branch 26 → 63 not taken.
980 result = conversionManager.getDivInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex);
612 980 break;
613 236 case MultiplicativeExprNode::MultiplicativeOp::OP_REM:
614
1/2
✓ Branch 28 → 29 taken 236 times.
✗ Branch 28 → 63 not taken.
236 result = conversionManager.getRemInst(node, result, lhsSTy, rhs, rhsSTy);
615 236 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 6009 lhsSTy = opQueue.front().second;
622 6009 opQueue.pop();
623 }
624
625 // Return the result
626
1/2
✓ Branch 43 → 44 taken 5739 times.
✗ Branch 43 → 64 not taken.
5739 return result;
627 5739 }
628
629 21831 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 21831 times.
21831 if (!node->isCast)
632 return visit(node->prefixUnaryExpr);
633
634
1/2
✓ Branch 5 → 6 taken 21831 times.
✗ Branch 5 → 19 not taken.
21831 diGenerator.setSourceLocation(node);
635
636 // It is a cast expression
637 // Retrieve target symbol type
638
1/2
✓ Branch 6 → 7 taken 21831 times.
✗ Branch 6 → 19 not taken.
21831 const QualType targetSTy = node->getEvaluatedSymbolType(manIdx);
639
640 // Evaluate rhs
641 21831 const ExprNode *rhsNode = node->assignExpr;
642
1/2
✓ Branch 7 → 8 taken 21831 times.
✗ Branch 7 → 19 not taken.
21831 const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx);
643
2/4
✓ Branch 8 → 9 taken 21831 times.
✗ Branch 8 → 18 not taken.
✓ Branch 9 → 10 taken 21831 times.
✗ Branch 9 → 16 not taken.
21831 auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode));
644
645 // Retrieve the result value
646
1/2
✓ Branch 11 → 12 taken 21831 times.
✗ Branch 11 → 19 not taken.
21831 const LLVMExprResult result = conversionManager.getCastInst(node, targetSTy, rhs, rhsSTy);
647
648 // Return the result
649
1/2
✓ Branch 12 → 13 taken 21831 times.
✗ Branch 12 → 19 not taken.
21831 return result;
650 }
651
652 15479 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 15479 times.
15479 if (node->op == PrefixUnaryExprNode::PrefixUnaryOp::OP_NONE)
655 return visit(node->postfixUnaryExpr);
656
657
1/2
✓ Branch 5 → 6 taken 15479 times.
✗ Branch 5 → 117 not taken.
15479 diGenerator.setSourceLocation(node);
658
659 // Evaluate lhs
660 15479 const ExprNode *lhsNode = node->prefixUnaryExpr;
661
1/2
✓ Branch 6 → 7 taken 15479 times.
✗ Branch 6 → 117 not taken.
15479 const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
662
2/4
✓ Branch 7 → 8 taken 15479 times.
✗ Branch 7 → 87 not taken.
✓ Branch 8 → 9 taken 15479 times.
✗ Branch 8 → 85 not taken.
15479 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
663
664
7/8
✓ Branch 10 → 11 taken 2049 times.
✓ Branch 10 → 21 taken 22 times.
✓ Branch 10 → 36 taken 30 times.
✓ Branch 10 → 51 taken 8849 times.
✓ Branch 10 → 53 taken 60 times.
✓ Branch 10 → 55 taken 2054 times.
✓ Branch 10 → 64 taken 2415 times.
✗ Branch 10 → 73 not taken.
15479 switch (node->op) {
665 2049 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS: {
666 // Execute operation
667
1/2
✓ Branch 11 → 12 taken 2049 times.
✗ Branch 11 → 117 not taken.
2049 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 2049 times.
✗ Branch 16 → 88 not taken.
2049 lhs.ptr = insertAlloca(lhs.value->getType());
671
672 // Store the new value
673
1/2
✓ Branch 19 → 20 taken 2049 times.
✗ Branch 19 → 117 not taken.
2049 insertStore(lhs.value, lhs.ptr);
674
675 2049 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 30 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS: {
695 // Execute operation
696
1/2
✓ Branch 36 → 37 taken 30 times.
✗ Branch 36 → 101 not taken.
30 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 28 times.
✓ Branch 37 → 40 taken 2 times.
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 28 times.
30 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 28 times.
30 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 30 times.
✗ Branch 49 → 117 not taken.
30 insertStore(lhs.value, lhs.ptr);
708
709 30 break;
710 }
711 8849 case PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT: {
712 // Execute operation
713
1/2
✓ Branch 51 → 52 taken 8849 times.
✗ Branch 51 → 117 not taken.
8849 lhs = conversionManager.getPrefixNotInst(node, lhs, lhsSTy);
714 8849 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 2054 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 2001 times.
✓ Branch 55 → 58 taken 53 times.
✓ Branch 56 → 57 taken 72 times.
✓ Branch 56 → 58 taken 1929 times.
2054 const bool onlyRefPtrIsFilled = lhs.value == nullptr && lhs.ptr == nullptr;
725 // Rewire the fields
726
3/4
✓ Branch 59 → 60 taken 72 times.
✓ Branch 59 → 62 taken 1982 times.
✓ Branch 60 → 61 taken 72 times.
✗ Branch 60 → 117 not taken.
2054 llvm::Value *newRefPtr = onlyRefPtrIsFilled ? resolveValue(lhsNode, lhs) : lhs.ptr;
727 2054 llvm::Value *newPtr = lhs.value;
728 2054 lhs = {.ptr = newPtr, .refPtr = newRefPtr};
729 2054 break;
730 }
731 2415 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 176 times.
✓ Branch 64 → 67 taken 2239 times.
✓ Branch 65 → 66 taken 4 times.
✓ Branch 65 → 67 taken 172 times.
2415 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 2411 times.
✓ Branch 69 → 70 taken 4 times.
✗ Branch 69 → 117 not taken.
2415 llvm::Value *newValue = onlyValueIsFilled ? resolveAddress(lhs) : lhs.ptr;
737 2415 llvm::Value *newPtr = lhs.refPtr;
738 2415 lhs = {.value = newValue, .ptr = newPtr};
739 2415 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 15479 times.
✗ Branch 81 → 117 not taken.
15479 return lhs;
746 }
747
748 181500 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 181500 times.
181500 if (node->op == PostfixUnaryExprNode::PostfixUnaryOp::OP_NONE)
751 return visit(node->atomicExpr);
752
753
1/2
✓ Branch 5 → 6 taken 181500 times.
✗ Branch 5 → 524 not taken.
181500 diGenerator.setSourceLocation(node);
754
755 // Evaluate lhs
756 181500 const ExprNode *lhsNode = node->postfixUnaryExpr;
757
1/2
✓ Branch 6 → 7 taken 181500 times.
✗ Branch 6 → 524 not taken.
181500 QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx);
758
2/4
✓ Branch 7 → 8 taken 181500 times.
✗ Branch 7 → 342 not taken.
✓ Branch 8 → 9 taken 181500 times.
✗ Branch 8 → 340 not taken.
181500 auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode));
759
760
5/6
✓ Branch 10 → 11 taken 19018 times.
✓ Branch 10 → 62 taken 147589 times.
✓ Branch 10 → 210 taken 13578 times.
✓ Branch 10 → 234 taken 1165 times.
✓ Branch 10 → 258 taken 150 times.
✗ Branch 10 → 328 not taken.
181500 switch (node->op) {
761 19018 case PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT: {
762 19018 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 19018 times.
✗ Branch 11 → 378 not taken.
✓ Branch 12 → 13 taken 1094 times.
✓ Branch 12 → 29 taken 17924 times.
19018 if (conversionManager.callsOverloadedOpFct(node, 0)) {
766
1/2
✓ Branch 13 → 14 taken 1094 times.
✗ Branch 13 → 343 not taken.
1094 ResolverFct lhsV = [&] { return resolveValue(lhsSTy, lhs); };
767 2188 ResolverFct lhsP = [&] { return resolveAddress(lhs); };
768 2142 ResolverFct idxV = [&] { return resolveValue(indexExpr); };
769 1140 ResolverFct idxP = [&] { return resolveAddress(indexExpr); };
770 1094 lhs = conversionManager.callOperatorOverloadFct<2>(node, {lhsV, lhsP, idxV, idxP}, 0);
771 1094 break;
772 1094 }
773
774
1/2
✓ Branch 29 → 30 taken 17924 times.
✗ Branch 29 → 361 not taken.
17924 lhsSTy = lhsSTy.removeReferenceWrapper();
775
776 // Get the index value
777
1/2
✓ Branch 30 → 31 taken 17924 times.
✗ Branch 30 → 378 not taken.
17924 llvm::Value *indexValue = resolveValue(indexExpr);
778 // Come up with the address
779
8/10
✓ Branch 31 → 32 taken 17924 times.
✗ Branch 31 → 378 not taken.
✓ Branch 32 → 33 taken 2561 times.
✓ Branch 32 → 36 taken 15363 times.
✓ Branch 33 → 34 taken 2561 times.
✗ Branch 33 → 378 not taken.
✓ Branch 34 → 35 taken 2369 times.
✓ Branch 34 → 36 taken 192 times.
✓ Branch 37 → 38 taken 2369 times.
✓ Branch 37 → 49 taken 15555 times.
17924 if (lhsSTy.isArray() && lhsSTy.getArraySize() != ARRAY_SIZE_UNKNOWN) { // Array
780 // Make sure the address is present
781
1/2
✓ Branch 38 → 39 taken 2369 times.
✗ Branch 38 → 369 not taken.
2369 resolveAddress(lhs);
782
783 // Calculate address of array item
784
1/2
✓ Branch 39 → 40 taken 2369 times.
✗ Branch 39 → 369 not taken.
2369 llvm::Type *lhsTy = lhsSTy.toLLVMType(sourceFile);
785
1/2
✓ Branch 40 → 41 taken 2369 times.
✗ Branch 40 → 369 not taken.
2369 llvm::Value *indices[2] = {builder.getInt64(0), indexValue};
786
1/2
✓ Branch 45 → 46 taken 2369 times.
✗ Branch 45 → 362 not taken.
2369 lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indices);
787 } else { // Pointer
788 // Now the pointer is the value
789
1/2
✓ Branch 49 → 50 taken 15555 times.
✗ Branch 49 → 378 not taken.
15555 lhs.ptr = resolveValue(lhsNode, lhs);
790
791
2/4
✓ Branch 50 → 51 taken 15555 times.
✗ Branch 50 → 370 not taken.
✓ Branch 51 → 52 taken 15555 times.
✗ Branch 51 → 370 not taken.
15555 llvm::Type *lhsTy = lhsSTy.getContained().toLLVMType(sourceFile);
792 // Calculate address of pointer item
793
1/2
✓ Branch 56 → 57 taken 15555 times.
✗ Branch 56 → 371 not taken.
15555 lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indexValue);
794 }
795
796 // Reset value and entry
797 17924 lhs.value = nullptr;
798 17924 lhs.entry = nullptr;
799 17924 break;
800 }
801 147589 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS: {
802 // Get the address of the struct/union instance
803
1/2
✓ Branch 62 → 63 taken 147589 times.
✗ Branch 62 → 457 not taken.
147589 resolveAddress(lhs);
804
1/2
✓ Branch 63 → 64 taken 147589 times.
✗ Branch 63 → 379 not taken.
147589 lhsSTy = lhsSTy.removeReferenceWrapper();
805
806 // Auto de-reference pointer
807
1/2
✓ Branch 64 → 65 taken 147589 times.
✗ Branch 64 → 457 not taken.
147589 autoDeReferencePtr(lhs.ptr, lhsSTy);
808
809 147589 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 147589 times.
✗ Branch 65 → 457 not taken.
✓ Branch 66 → 67 taken 50 times.
✓ Branch 66 → 168 taken 147539 times.
147589 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 147539 times.
✗ Branch 168 → 457 not taken.
✗ Branch 169 → 170 not taken.
✓ Branch 169 → 171 taken 147539 times.
147539 assert(lhsSTy.is(TY_STRUCT));
884
885 // Retrieve struct scope
886
1/2
✓ Branch 171 → 172 taken 147539 times.
✗ Branch 171 → 457 not taken.
147539 Scope *structScope = lhsSTy.getBodyScope();
887
888 // Retrieve field entry
889 147539 std::vector<size_t> indexPath;
890
1/2
✓ Branch 172 → 173 taken 147539 times.
✗ Branch 172 → 455 not taken.
147539 lhs.entry = structScope->symbolTable.lookupInComposedFields(fieldName, indexPath);
891
1/2
✗ Branch 173 → 174 not taken.
✓ Branch 173 → 175 taken 147539 times.
147539 assert(lhs.entry != nullptr);
892
1/2
✓ Branch 175 → 176 taken 147539 times.
✗ Branch 175 → 455 not taken.
147539 const QualType fieldSymbolType = lhs.entry->getQualType();
893
894 // Get address of the field in the struct instance
895
2/4
✓ Branch 176 → 177 taken 147539 times.
✗ Branch 176 → 447 not taken.
✓ Branch 179 → 180 taken 147539 times.
✗ Branch 179 → 444 not taken.
295078 std::vector<llvm::Value *> indices = {builder.getInt64(0)};
896
2/2
✓ Branch 196 → 183 taken 147631 times.
✓ Branch 196 → 197 taken 147539 times.
442709 for (const size_t index : indexPath)
897
2/4
✓ Branch 185 → 186 taken 147631 times.
✗ Branch 185 → 448 not taken.
✓ Branch 186 → 187 taken 147631 times.
✗ Branch 186 → 448 not taken.
147631 indices.push_back(builder.getInt32(index));
898
1/2
✓ Branch 197 → 198 taken 147539 times.
✗ Branch 197 → 453 not taken.
147539 const std::string name = fieldName + ".addr";
899
2/4
✓ Branch 199 → 200 taken 147539 times.
✗ Branch 199 → 450 not taken.
✓ Branch 200 → 201 taken 147539 times.
✗ Branch 200 → 450 not taken.
147539 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 147539 times.
✗ Branch 201 → 451 not taken.
✓ Branch 202 → 203 taken 2547 times.
✓ Branch 202 → 204 taken 144992 times.
147539 if (fieldSymbolType.isRef()) {
903 2547 lhs.ptr = nullptr;
904 2547 lhs.refPtr = memberAddr;
905 } else {
906 144992 lhs.ptr = memberAddr;
907 144992 lhs.refPtr = nullptr;
908 }
909
910 // Reset the value
911 147539 lhs.value = nullptr;
912 147539 break;
913 147539 }
914 13578 case PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS: {
915 // Make sure a value is present
916
1/2
✓ Branch 210 → 211 taken 13578 times.
✗ Branch 210 → 464 not taken.
13578 resolveValue(lhsNode, lhs);
917
918 // Allocate new local variable if required
919
2/2
✓ Branch 211 → 212 taken 4 times.
✓ Branch 211 → 222 taken 13574 times.
13578 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 13578 times.
✗ Branch 222 → 464 not taken.
13578 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 13578 times.
✗ Branch 223 → 464 not taken.
✓ Branch 224 → 225 taken 20 times.
✓ Branch 224 → 226 taken 13558 times.
13578 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 13552 times.
✓ Branch 226 → 229 taken 6 times.
✓ Branch 227 → 228 taken 6 times.
✓ Branch 227 → 229 taken 13546 times.
✓ Branch 230 → 231 taken 13558 times.
✗ Branch 230 → 464 not taken.
13558 insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
933 13558 lhs.ptr = nullptr;
934 }
935 13578 break;
936 }
937 1165 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS: {
938 // Make sure a value is present
939
1/2
✓ Branch 234 → 235 taken 1165 times.
✗ Branch 234 → 471 not taken.
1165 resolveValue(lhsNode, lhs);
940
941 // Allocate new local variable if required
942
2/2
✓ Branch 235 → 236 taken 4 times.
✓ Branch 235 → 246 taken 1161 times.
1165 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 1165 times.
✗ Branch 246 → 471 not taken.
1165 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 1165 times.
✗ Branch 247 → 471 not taken.
✓ Branch 248 → 249 taken 16 times.
✓ Branch 248 → 250 taken 1149 times.
1165 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 1145 times.
✓ Branch 250 → 253 taken 4 times.
✗ Branch 251 → 252 not taken.
✓ Branch 251 → 253 taken 1145 times.
✓ Branch 254 → 255 taken 1149 times.
✗ Branch 254 → 471 not taken.
1149 insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile);
956 1149 lhs.ptr = nullptr;
957 }
958 1165 break;
959 }
960 150 case PostfixUnaryExprNode::PostfixUnaryOp::OP_ERR_PROPAGATION: {
961 // Get the address of the Result<T> operand
962
1/2
✓ Branch 258 → 259 taken 150 times.
✗ Branch 258 → 514 not taken.
150 llvm::Value *operandPtr = resolveAddress(lhs);
963
964 // Call isErr() on the operand
965
1/2
✗ Branch 259 → 260 not taken.
✓ Branch 259 → 261 taken 150 times.
150 assert(node->errPropIsErrFct != nullptr);
966
1/2
✓ Branch 261 → 262 taken 150 times.
✗ Branch 261 → 514 not taken.
150 llvm::Function *isErrFct = stdFunctionManager.getResultIsErrFct(node->errPropIsErrFct);
967
4/8
✓ Branch 262 → 263 taken 150 times.
✗ Branch 262 → 474 not taken.
✓ Branch 264 → 265 taken 150 times.
✗ Branch 264 → 472 not taken.
✓ Branch 265 → 266 taken 150 times.
✗ Branch 265 → 472 not taken.
✓ Branch 266 → 267 taken 150 times.
✗ Branch 266 → 514 not taken.
150 llvm::Value *isErr = builder.CreateCall(isErrFct, operandPtr);
968
969 // Create blocks
970
1/2
✓ Branch 266 → 267 taken 150 times.
✗ Branch 266 → 514 not taken.
150 const std::string codeLine = node->codeLoc.toPrettyLine();
971
2/4
✓ Branch 267 → 268 taken 150 times.
✗ Branch 267 → 477 not taken.
✓ Branch 268 → 269 taken 150 times.
✗ Branch 268 → 475 not taken.
150 llvm::BasicBlock *bThen = createBlock("err.prop.then." + codeLine);
972
2/4
✓ Branch 270 → 271 taken 150 times.
✗ Branch 270 → 480 not taken.
✓ Branch 271 → 272 taken 150 times.
✗ Branch 271 → 478 not taken.
150 llvm::BasicBlock *bExit = createBlock("err.prop.exit." + codeLine);
973
1/2
✓ Branch 273 → 274 taken 150 times.
✗ Branch 273 → 512 not taken.
150 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 150 times.
✗ Branch 274 → 512 not taken.
150 switchToBlock(bThen);
977
2/4
✓ Branch 275 → 276 taken 150 times.
✗ Branch 275 → 278 not taken.
✓ Branch 276 → 277 taken 150 times.
✗ Branch 276 → 278 not taken.
150 assert(node->errPropGetErrFct != nullptr && node->errPropCtorFct != nullptr);
978
1/2
✓ Branch 279 → 280 taken 150 times.
✗ Branch 279 → 512 not taken.
150 llvm::Function *getErrFct = stdFunctionManager.getResultGetErrFct(node->errPropGetErrFct);
979
4/8
✓ Branch 280 → 281 taken 150 times.
✗ Branch 280 → 483 not taken.
✓ Branch 282 → 283 taken 150 times.
✗ Branch 282 → 481 not taken.
✓ Branch 283 → 284 taken 150 times.
✗ Branch 283 → 481 not taken.
✓ Branch 284 → 285 taken 150 times.
✗ Branch 284 → 512 not taken.
150 llvm::Value *errorPtr = builder.CreateCall(getErrFct, operandPtr);
980
1/2
✓ Branch 284 → 285 taken 150 times.
✗ Branch 284 → 512 not taken.
150 llvm::Function *errCtorFct = stdFunctionManager.getResultErrCtorFct(node->errPropCtorFct);
981
5/8
✓ Branch 285 → 286 taken 150 times.
✗ Branch 285 → 486 not taken.
✓ Branch 287 → 288 taken 150 times.
✗ Branch 287 → 484 not taken.
✓ Branch 288 → 289 taken 150 times.
✗ Branch 288 → 484 not taken.
✓ Branch 289 → 290 taken 6 times.
✓ Branch 289 → 314 taken 144 times.
150 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 144 times.
150 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 150 times.
✗ Branch 314 → 512 not taken.
✓ Branch 315 → 316 taken 150 times.
✗ Branch 315 → 512 not taken.
150 generateScopeCleanupUpTo(node, currentScope->getFunctionScope());
996 150 blockAlreadyTerminated = true;
997
1/2
✓ Branch 316 → 317 taken 150 times.
✗ Branch 316 → 512 not taken.
150 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 150 times.
✗ Branch 317 → 512 not taken.
150 switchToBlock(bExit);
1001
1/2
✗ Branch 318 → 319 not taken.
✓ Branch 318 → 320 taken 150 times.
150 assert(node->errPropUnwrapFct != nullptr);
1002
1/2
✓ Branch 320 → 321 taken 150 times.
✗ Branch 320 → 512 not taken.
150 llvm::Function *unwrapFct = stdFunctionManager.getResultUnwrapFct(node->errPropUnwrapFct);
1003
3/6
✓ Branch 321 → 322 taken 150 times.
✗ Branch 321 → 511 not taken.
✓ Branch 323 → 324 taken 150 times.
✗ Branch 323 → 509 not taken.
✓ Branch 324 → 325 taken 150 times.
✗ Branch 324 → 509 not taken.
150 llvm::Value *unwrapped = builder.CreateCall(unwrapFct, operandPtr);
1004 150 lhs = {.ptr = unwrapped};
1005 150 break;
1006 150 }
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 181500 times.
✗ Branch 336 → 524 not taken.
181500 return lhs;
1012
5/14
✓ Branch 17 → 18 taken 1094 times.
✗ Branch 17 → 346 not taken.
✓ Branch 18 → 19 taken 1094 times.
✗ Branch 18 → 346 not taken.
✓ Branch 19 → 20 taken 1094 times.
✗ Branch 19 → 346 not taken.
✓ Branch 20 → 21 taken 1094 times.
✗ Branch 20 → 346 not taken.
✓ Branch 21 → 22 taken 1094 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.
1094 }
1013
1014 730639 std::any IRGenerator::visitAtomicExpr(const AtomicExprNode *node) {
1015 // If constant
1016
2/2
✓ Branch 2 → 3 taken 130004 times.
✓ Branch 2 → 9 taken 600635 times.
730639 if (node->constant) {
1017
2/4
✓ Branch 3 → 4 taken 130004 times.
✗ Branch 3 → 82 not taken.
✓ Branch 4 → 5 taken 130004 times.
✗ Branch 4 → 80 not taken.
130004 const auto constantValue = std::any_cast<llvm::Constant *>(visit(node->constant));
1018
1/2
✓ Branch 6 → 7 taken 130004 times.
✗ Branch 6 → 83 not taken.
260008 return LLVMExprResult{.constant = constantValue};
1019 }
1020
1021 // If value
1022
2/2
✓ Branch 9 → 10 taken 172550 times.
✓ Branch 9 → 12 taken 428085 times.
600635 if (node->value)
1023
1/2
✓ Branch 10 → 11 taken 172550 times.
✗ Branch 10 → 90 not taken.
172550 return visit(node->value);
1024
1025 // Is assign expression
1026
2/2
✓ Branch 12 → 13 taken 3458 times.
✓ Branch 12 → 15 taken 424627 times.
428085 if (node->assignExpr)
1027
1/2
✓ Branch 13 → 14 taken 3458 times.
✗ Branch 13 → 90 not taken.
3458 return visit(node->assignExpr);
1028
1029
1/2
✓ Branch 15 → 16 taken 424627 times.
✗ Branch 15 → 90 not taken.
424627 diGenerator.setSourceLocation(node);
1030
1031 // Identifier (local or global variable access)
1032
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 424627 times.
424627 assert(!node->identifierFragments.empty());
1033
1034 // Get symbol table entry
1035
1/2
✓ Branch 19 → 20 taken 424627 times.
✗ Branch 19 → 90 not taken.
424627 const auto &[entry, accessScope, capture] = node->data.at(manIdx);
1036
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 424627 times.
424627 assert(entry != nullptr);
1037
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 424627 times.
424627 assert(accessScope != nullptr);
1038
1/2
✓ Branch 24 → 25 taken 424627 times.
✗ Branch 24 → 90 not taken.
424627 const QualType varSymbolType = entry->getQualType();
1039
1/2
✓ Branch 25 → 26 taken 424627 times.
✗ Branch 25 → 90 not taken.
424627 llvm::Type *varType = varSymbolType.toLLVMType(sourceFile);
1040
1041 // Check if external global variable
1042
7/8
✓ Branch 26 → 27 taken 9744 times.
✓ Branch 26 → 30 taken 414883 times.
✓ Branch 27 → 28 taken 9744 times.
✗ Branch 27 → 90 not taken.
✓ Branch 28 → 29 taken 584 times.
✓ Branch 28 → 30 taken 9160 times.
✓ Branch 31 → 32 taken 584 times.
✓ Branch 31 → 35 taken 424043 times.
424627 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 584 times.
✗ Branch 33 → 84 not taken.
584 llvm::Value *varAddress = module->getOrInsertGlobal(entry->name, varType);
1045
1/2
✓ Branch 34 → 35 taken 584 times.
✗ Branch 34 → 90 not taken.
584 updateAddress(entry, varAddress);
1046 }
1047
1048 // Check if enum item
1049
2/2
✓ Branch 35 → 36 taken 10085 times.
✓ Branch 35 → 49 taken 414542 times.
424627 if (accessScope->type == ScopeType::ENUM) {
1050
1/2
✓ Branch 36 → 37 taken 10085 times.
✗ Branch 36 → 38 not taken.
10085 const auto itemNode = spice_pointer_cast<const EnumItemNode *>(entry->declNode);
1051
1/2
✓ Branch 45 → 46 taken 10085 times.
✗ Branch 45 → 90 not taken.
10085 llvm::Constant *constantItemValue = llvm::ConstantInt::get(varType, itemNode->itemValue);
1052
1/2
✓ Branch 46 → 47 taken 10085 times.
✗ Branch 46 → 85 not taken.
20170 return LLVMExprResult{.constant = constantItemValue, .entry = entry};
1053 }
1054
1055
1/2
✓ Branch 49 → 50 taken 414542 times.
✗ Branch 49 → 90 not taken.
414542 llvm::Value *address = getAddress(entry);
1056
1/2
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 414542 times.
414542 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 9744 times.
✓ Branch 52 → 56 taken 404798 times.
✓ Branch 53 → 54 taken 9744 times.
✗ Branch 53 → 86 not taken.
✓ Branch 54 → 55 taken 92 times.
✓ Branch 54 → 56 taken 9652 times.
✓ Branch 57 → 58 taken 92 times.
✓ Branch 57 → 64 taken 414450 times.
414542 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 414450 times.
✗ Branch 64 → 90 not taken.
✓ Branch 65 → 66 taken 370921 times.
✓ Branch 65 → 69 taken 43529 times.
✓ Branch 66 → 67 taken 170 times.
✓ Branch 66 → 70 taken 370751 times.
✓ Branch 67 → 68 taken 170 times.
✗ Branch 67 → 90 not taken.
✓ Branch 68 → 69 taken 38 times.
✓ Branch 68 → 70 taken 132 times.
✓ Branch 71 → 72 taken 43567 times.
✓ Branch 71 → 75 taken 370883 times.
414450 if (varSymbolType.isRef() || (capture && capture->getMode() == BY_REFERENCE))
1068
1/2
✓ Branch 72 → 73 taken 43567 times.
✗ Branch 72 → 88 not taken.
87134 return LLVMExprResult{.refPtr = address, .entry = entry};
1069
1070
1/2
✓ Branch 75 → 76 taken 370883 times.
✗ Branch 75 → 89 not taken.
741766 return LLVMExprResult{.ptr = address, .entry = entry};
1071 }
1072
1073 } // namespace spice::compiler
1074