GCC Code Coverage Report


Directory: ../
File: src/irgenerator/GenExpressions.cpp
Date: 2025-11-05 11:52:30
Coverage Exec Excl Total
Lines: 98.8% 501 17 524
Functions: 95.0% 19 0 20
Branches: 59.4% 550 36 962

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