GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.8% 481 / 17 / 519
Functions: 95.0% 19 / 0 / 20
Branches: 57.1% 522 / 36 / 950

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