GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.1% 513 / 17 / 551
Functions: 95.0% 19 / 0 / 20
Branches: 56.7% 573 / 36 / 1047

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