GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 91.6% 469 / 0 / 512
Functions: 96.4% 27 / 0 / 28
Branches: 50.2% 582 / 0 / 1160

src/irgenerator/GenImplicit.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "IRGenerator.h"
4
5 #include <SourceFile.h>
6 #include <ast/ASTNodes.h>
7 #include <ast/Attributes.h>
8 #include <driver/Driver.h>
9 #include <global/GlobalResourceManager.h>
10 #include <model/Function.h>
11 #include <symboltablebuilder/SymbolTableBuilder.h>
12 #include <typechecker/FunctionManager.h>
13
14 #include <llvm/IR/Module.h>
15
16 namespace spice::compiler {
17
18 // String placeholders for builtin testing output
19 static const char *const TEST_ALL_START_MSG = "[==========] Running %d test(s) from %d source file(s)\n";
20 static const char *const TEST_ALL_END_MSG = "[==========] Ran %d test(s) from %d source file(s)\n";
21 static const char *const TEST_FILE_START_MSG = "[----------] Running %d test(s) from %s\n";
22 static const char *const TEST_FILE_END_MSG = "[----------] Ran %d test(s) from %s\n\n";
23 static const char *const TEST_CASE_RUN_MSG = "[ RUN ] %s\n";
24 static const char *const TEST_CASE_SUCCESS_MSG = "\033[1m\033[32m[ PASSED ]\033[0m\033[22m %s\n";
25 static const char *const TEST_CASE_FAILED_MSG = "\033[1m\033[31m[ FAILED ]\033[0m\033[22m %s\n";
26 static const char *const TEST_CASE_SKIPPED_MSG = "\033[1m\033[33m[ SKIPPED ]\033[0m\033[22m %s\n";
27
28 482 llvm::Value *IRGenerator::doImplicitCast(llvm::Value *src, QualType dstSTy, QualType srcSTy) {
29
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 482 times.
482 assert(srcSTy != dstSTy); // We only need to cast implicitly, if the types do not match exactly
30
31 // Unpack the pointers until a pointer of another type is met
32 482 size_t loadCounter = 0;
33
1/2
✗ Branch 16 → 6 not taken.
✓ Branch 16 → 17 taken 482 times.
482 while (srcSTy.isPtr()) {
34 src = insertLoad(srcSTy, src);
35 srcSTy = srcSTy.getContained();
36 dstSTy = dstSTy.getContained();
37 loadCounter++;
38 }
39 // GEP or bit-cast
40
3/6
✓ Branch 18 → 19 taken 482 times.
✗ Branch 18 → 22 not taken.
✓ Branch 20 → 21 taken 482 times.
✗ Branch 20 → 22 not taken.
✓ Branch 23 → 24 taken 482 times.
✗ Branch 23 → 35 not taken.
482 if (dstSTy.isArray() && srcSTy.isArray()) { // Special case that is used for passing arrays as pointer to functions
41
2/4
✓ Branch 24 → 25 taken 482 times.
✗ Branch 24 → 72 not taken.
✓ Branch 25 → 26 taken 482 times.
✗ Branch 25 → 72 not taken.
482 llvm::Value *indices[2] = {builder.getInt64(0), builder.getInt32(0)};
42
2/4
✓ Branch 30 → 31 taken 482 times.
✗ Branch 30 → 65 not taken.
✓ Branch 31 → 32 taken 482 times.
✗ Branch 31 → 65 not taken.
482 src = insertInBoundsGEP(srcSTy.toLLVMType(sourceFile), src, indices);
43 } else {
44 src = insertLoad(srcSTy, src);
45 src = builder.CreateBitCast(src, dstSTy.toLLVMType(sourceFile));
46 }
47 // Pack the pointers together again
48
1/2
✗ Branch 54 → 46 not taken.
✓ Branch 54 → 55 taken 482 times.
482 for (; loadCounter > 0; loadCounter--) {
49 llvm::Value *newActualArg = insertAlloca(srcSTy);
50 insertStore(src, newActualArg);
51 src = newActualArg;
52 }
53 482 return src;
54 }
55
56 938 llvm::Value *IRGenerator::getUpcastedStructPtr(llvm::Value *structPtr, const QualType &dstType, const QualType &srcType) const {
57 // Adjusts a pointer to a struct instance so it points at the embedded subobject the destination type
58 // refers to. This backs the explicit 'cast<Base*>(derived)' / 'cast<Interface*>(struct)' conversions.
59 // When the struct carries a vtable prefix (because it implements interfaces), the composed base no longer
60 // sits at offset 0, so the pointer has to be advanced via a GEP. For subobjects that already sit at offset
61 // 0 (e.g. the leading interface field), insertStructGEP() with index 0 is a no-op and returns the pointer
62 // unchanged, so no superfluous IR is emitted. If the given pair of types is not such an upcast, the
63 // pointer is returned unchanged.
64
1/2
✓ Branch 2 → 3 taken 938 times.
✗ Branch 2 → 99 not taken.
938 QualType dstPointee = dstType.removeReferenceWrapper();
65
1/2
✓ Branch 3 → 4 taken 938 times.
✗ Branch 3 → 99 not taken.
938 QualType srcPointee = srcType.removeReferenceWrapper();
66 // Both sides are pointers ('structPtr' is the pointer value itself), so look one level deeper
67
5/10
✓ Branch 4 → 5 taken 938 times.
✗ Branch 4 → 99 not taken.
✓ Branch 5 → 6 taken 938 times.
✗ Branch 5 → 9 not taken.
✓ Branch 6 → 7 taken 938 times.
✗ Branch 6 → 99 not taken.
✓ Branch 7 → 8 taken 938 times.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 938 times.
✗ Branch 10 → 14 not taken.
938 if (dstPointee.isPtr() && srcPointee.isPtr()) {
68
1/2
✓ Branch 11 → 12 taken 938 times.
✗ Branch 11 → 85 not taken.
938 dstPointee = dstPointee.getContained();
69
1/2
✓ Branch 12 → 13 taken 938 times.
✗ Branch 12 → 86 not taken.
938 srcPointee = srcPointee.getContained();
70 }
71 // Bail out if this is not an interface/composed-base upcast that requires a pointer adjustment
72
2/4
✓ Branch 14 → 15 taken 938 times.
✗ Branch 14 → 99 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 938 times.
938 if (!srcPointee.is(TY_STRUCT))
73 return structPtr;
74
6/10
✓ Branch 17 → 18 taken 938 times.
✗ Branch 17 → 99 not taken.
✓ Branch 18 → 19 taken 924 times.
✓ Branch 18 → 22 taken 14 times.
✓ Branch 19 → 20 taken 924 times.
✗ Branch 19 → 99 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 924 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 938 times.
938 if (!dstPointee.matchesInterfaceImplementedByStruct(srcPointee) && !dstPointee.matchesComposedBaseOfStruct(srcPointee))
75 return structPtr;
76
77 938 QualType walkType = srcPointee;
78
3/4
✓ Branch 80 → 81 taken 2584 times.
✗ Branch 80 → 99 not taken.
✓ Branch 81 → 26 taken 1660 times.
✓ Branch 81 → 82 taken 924 times.
2584 while (!walkType.matches(dstPointee, false, true, true)) {
79
2/4
✓ Branch 26 → 27 taken 1660 times.
✗ Branch 26 → 99 not taken.
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 1660 times.
1660 assert(walkType.is(TY_STRUCT));
80
1/2
✓ Branch 29 → 30 taken 1660 times.
✗ Branch 29 → 99 not taken.
1660 Scope *structScope = walkType.getBodyScope();
81
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 1660 times.
1660 assert(structScope != nullptr);
82
1/2
✓ Branch 32 → 33 taken 1660 times.
✗ Branch 32 → 99 not taken.
1660 const Struct *spiceStruct = walkType.getStruct(nullptr);
83
1/2
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 1660 times.
1660 assert(spiceStruct != nullptr);
84
1/2
✓ Branch 35 → 36 taken 1660 times.
✗ Branch 35 → 99 not taken.
1660 llvm::Type *llvmStructType = walkType.toLLVMType(sourceFile);
85 // Implicit (interface) fields are inserted before the explicit fields, so their count is the difference
86 // between the total field count and the number of explicit fields.
87
1/2
✓ Branch 36 → 37 taken 1660 times.
✗ Branch 36 → 99 not taken.
1660 const size_t implicitFieldCount = structScope->getFieldCount() - spiceStruct->fieldTypes.size();
88
89 // Case 1: the destination is an interface implemented directly by the struct -> step into its implicit field
90
3/4
✓ Branch 38 → 39 taken 1660 times.
✗ Branch 38 → 99 not taken.
✓ Branch 39 → 40 taken 14 times.
✓ Branch 39 → 61 taken 1646 times.
1660 if (dstPointee.is(TY_INTERFACE)) {
91 14 bool found = false;
92
1/2
✓ Branch 57 → 41 taken 14 times.
✗ Branch 57 → 58 not taken.
14 for (size_t i = 0; i < implicitFieldCount; i++) {
93
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 14 times.
14 const SymbolTableEntry *implicitField = structScope->lookupField(i);
94
3/6
✓ Branch 46 → 47 taken 14 times.
✗ Branch 46 → 99 not taken.
✓ Branch 47 → 48 taken 14 times.
✗ Branch 47 → 99 not taken.
✓ Branch 48 → 49 taken 14 times.
✗ Branch 48 → 56 not taken.
14 if (dstPointee.matches(implicitField->getQualType(), false, true, true)) {
95
1/2
✓ Branch 52 → 53 taken 14 times.
✗ Branch 52 → 87 not taken.
14 structPtr = insertStructGEP(llvmStructType, structPtr, implicitField->orderIndex);
96 14 found = true;
97 14 break;
98 }
99 }
100
1/2
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 60 taken 14 times.
14 assert(found);
101 (void)found;
102 14 return structPtr;
103 }
104
105 // Case 2: the destination is a composed base struct -> step into the first explicit (composed) field
106
1/2
✗ Branch 61 → 62 not taken.
✓ Branch 61 → 63 taken 1646 times.
1646 const SymbolTableEntry *baseField = structScope->lookupField(implicitFieldCount);
107
4/8
✓ Branch 66 → 67 taken 1646 times.
✗ Branch 66 → 71 not taken.
✓ Branch 67 → 68 taken 1646 times.
✗ Branch 67 → 99 not taken.
✓ Branch 68 → 69 taken 1646 times.
✗ Branch 68 → 99 not taken.
✓ Branch 69 → 70 taken 1646 times.
✗ Branch 69 → 71 not taken.
1646 assert(baseField != nullptr && baseField->getQualType().isComposition());
108
1/2
✓ Branch 75 → 76 taken 1646 times.
✗ Branch 75 → 93 not taken.
1646 structPtr = insertStructGEP(llvmStructType, structPtr, baseField->orderIndex);
109
1/2
✓ Branch 78 → 79 taken 1646 times.
✗ Branch 78 → 99 not taken.
1646 walkType = baseField->getQualType();
110 }
111 924 return structPtr;
112 }
113
114 284927 void IRGenerator::generateScopeCleanup(const StmtLstNode *node) {
115 284927 diGenerator.setSourceLocation(node->closingBraceCodeLoc);
116
117 // Do not clean up if the block is already terminated
118
2/2
✓ Branch 3 → 4 taken 86111 times.
✓ Branch 3 → 5 taken 198816 times.
284927 if (blockAlreadyTerminated)
119 86111 return;
120
121 // Call all dtor functions
122 198816 const auto &[dtorFunctionsToCall, heapVarsToFree] = node->resourcesToCleanup.at(manIdx);
123
2/2
✓ Branch 24 → 8 taken 12129 times.
✓ Branch 24 → 25 taken 198816 times.
421890 for (auto [entry, dtor] : dtorFunctionsToCall)
124
1/2
✓ Branch 13 → 14 taken 12129 times.
✗ Branch 13 → 63 not taken.
12129 generateCtorOrDtorCall(entry, dtor, {});
125
126 // Deallocate all heap variables that go out of scope and are currently owned
127
2/2
✓ Branch 40 → 27 taken 921 times.
✓ Branch 40 → 41 taken 198816 times.
398553 for (const SymbolTableEntry *entry : heapVarsToFree)
128
2/4
✓ Branch 29 → 30 taken 921 times.
✗ Branch 29 → 67 not taken.
✓ Branch 30 → 31 taken 921 times.
✗ Branch 30 → 67 not taken.
921 generateDeallocCall(getAddress(entry));
129
130 // Generate lifetime end markers
131
2/2
✓ Branch 41 → 42 taken 1658 times.
✓ Branch 41 → 62 taken 197158 times.
198816 if (cliOptions.useLifetimeMarkers) {
132
3/4
✓ Branch 42 → 43 taken 1658 times.
✗ Branch 42 → 70 not taken.
✓ Branch 59 → 45 taken 535 times.
✓ Branch 59 → 60 taken 1658 times.
3851 for (const SymbolTableEntry *var : currentScope->getVarsGoingOutOfScope()) {
133
1/2
✓ Branch 47 → 48 taken 535 times.
✗ Branch 47 → 68 not taken.
535 llvm::Value *address = getAddress(var);
134
2/2
✓ Branch 48 → 49 taken 491 times.
✓ Branch 48 → 50 taken 44 times.
535 if (address != nullptr)
135
1/2
✓ Branch 49 → 50 taken 491 times.
✗ Branch 49 → 68 not taken.
491 builder.CreateLifetimeEnd(address);
136 1658 }
137 }
138 }
139
140 /**
141 * Generate cleanup code (dtor calls, deallocations) for every scope between the given node (exclusive) and the given
142 * target scope (inclusive). This is required for jumps that leave more than one scope at once (e.g. break/continue/return),
143 * since those skip the normal fall-through cleanup that visitStmtLst() generates for each of the enclosing scopes.
144 *
145 * @param node Node the jump originates from
146 * @param targetScope Outermost scope that is left by the jump; cleanup is generated for this scope as well
147 */
148 77151 void IRGenerator::generateScopeCleanupUpTo(const ASTNode *node, const Scope *targetScope) {
149
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 77151 times.
77151 assert(targetScope != nullptr);
150 77151 const StmtLstNode *scope = node->getNextOuterStmtLst();
151 77151 const Scope *scopeLevel = currentScope;
152 while (true) {
153 117107 generateScopeCleanup(scope);
154
2/2
✓ Branch 7 → 8 taken 77151 times.
✓ Branch 7 → 9 taken 39956 times.
117107 if (scopeLevel == targetScope)
155 77151 break;
156
2/4
✓ Branch 9 → 10 taken 39956 times.
✗ Branch 9 → 12 not taken.
✓ Branch 10 → 11 taken 39956 times.
✗ Branch 10 → 12 not taken.
39956 assert(scope->parent != nullptr && scopeLevel->parent != nullptr);
157 39956 scope = scope->parent->getNextOuterStmtLst();
158 39956 scopeLevel = scopeLevel->parent;
159 }
160 77151 }
161
162 22142 void IRGenerator::generateFctDecl(const Function *fct, const std::vector<llvm::Value *> &args) const {
163 // Retrieve metadata for the function
164
1/2
✓ Branch 2 → 3 taken 22142 times.
✗ Branch 2 → 90 not taken.
22142 const std::string mangledName = fct->getMangledName();
165
166 // Function is not defined in the current module -> declare it
167
3/4
✓ Branch 4 → 5 taken 22142 times.
✗ Branch 4 → 71 not taken.
✓ Branch 5 → 6 taken 5538 times.
✓ Branch 5 → 69 taken 16604 times.
22142 if (!module->getFunction(mangledName)) {
168 5538 std::vector<llvm::Type *> paramTypes;
169
2/2
✓ Branch 21 → 8 taken 6971 times.
✓ Branch 21 → 22 taken 5538 times.
18047 for (const llvm::Value *argValue : args)
170
1/2
✓ Branch 11 → 12 taken 6971 times.
✗ Branch 11 → 72 not taken.
6971 paramTypes.push_back(argValue->getType());
171
2/6
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 28 taken 5538 times.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 85 not taken.
✓ Branch 28 → 29 taken 5538 times.
✗ Branch 28 → 85 not taken.
5538 llvm::Type *returnType = fct->isFunction() ? fct->returnType.toLLVMType(sourceFile) : builder.getVoidTy();
172
1/2
✓ Branch 31 → 32 taken 5538 times.
✗ Branch 31 → 74 not taken.
5538 llvm::FunctionType *fctType = llvm::FunctionType::get(returnType, paramTypes, false);
173
2/4
✓ Branch 33 → 34 taken 5538 times.
✗ Branch 33 → 75 not taken.
✓ Branch 34 → 35 taken 5538 times.
✗ Branch 34 → 85 not taken.
5538 module->getOrInsertFunction(mangledName, fctType);
174
175
1/2
✓ Branch 37 → 38 taken 5538 times.
✗ Branch 37 → 67 not taken.
5538 if (fct->isMethod()) {
176 // Get callee function
177
1/2
✓ Branch 39 → 40 taken 5538 times.
✗ Branch 39 → 76 not taken.
5538 llvm::Function *callee = module->getFunction(mangledName);
178
1/2
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 42 taken 5538 times.
5538 assert(callee != nullptr);
179
180 // Set attributes to 'this' param
181 // Get 'this' entry
182
1/2
✓ Branch 44 → 45 taken 5538 times.
✗ Branch 44 → 79 not taken.
16614 const SymbolTableEntry *thisEntry = fct->bodyScope->lookupStrict(THIS_VARIABLE_NAME);
183
1/2
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 5538 times.
5538 assert(thisEntry != nullptr);
184
3/6
✓ Branch 52 → 53 taken 5538 times.
✗ Branch 52 → 83 not taken.
✓ Branch 53 → 54 taken 5538 times.
✗ Branch 53 → 83 not taken.
✓ Branch 54 → 55 taken 5538 times.
✗ Branch 54 → 83 not taken.
5538 llvm::Type *structType = thisEntry->getQualType().getContained().toLLVMType(sourceFile);
185
1/2
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 5538 times.
5538 assert(structType != nullptr);
186
1/2
✓ Branch 57 → 58 taken 5538 times.
✗ Branch 57 → 85 not taken.
5538 callee->addParamAttr(0, llvm::Attribute::NoUndef);
187
1/2
✓ Branch 58 → 59 taken 5538 times.
✗ Branch 58 → 85 not taken.
5538 callee->addParamAttr(0, llvm::Attribute::NonNull);
188
3/6
✓ Branch 60 → 61 taken 5538 times.
✗ Branch 60 → 84 not taken.
✓ Branch 61 → 62 taken 5538 times.
✗ Branch 61 → 84 not taken.
✓ Branch 62 → 63 taken 5538 times.
✗ Branch 62 → 84 not taken.
5538 callee->addDereferenceableParamAttr(0, module->getDataLayout().getTypeStoreSize(structType));
189
3/6
✓ Branch 64 → 65 taken 5538 times.
✗ Branch 64 → 85 not taken.
✓ Branch 65 → 66 taken 5538 times.
✗ Branch 65 → 85 not taken.
✓ Branch 66 → 67 taken 5538 times.
✗ Branch 66 → 85 not taken.
5538 callee->addParamAttr(0, llvm::Attribute::getWithAlignment(context, module->getDataLayout().getABITypeAlign(structType)));
190 }
191 5538 }
192 22142 }
193
194 22142 llvm::CallInst *IRGenerator::generateFctCall(const Function *fct, const std::vector<llvm::Value *> &args) const {
195 // Retrieve metadata for the function
196
1/2
✓ Branch 2 → 3 taken 22142 times.
✗ Branch 2 → 57 not taken.
22142 const std::string mangledName = fct->getMangledName();
197
198 // Get callee function
199
1/2
✓ Branch 4 → 5 taken 22142 times.
✗ Branch 4 → 43 not taken.
22142 llvm::Function *callee = module->getFunction(mangledName);
200
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 22142 times.
22142 assert(callee != nullptr);
201
202 // Generate function call
203
4/8
✓ Branch 7 → 8 taken 22142 times.
✗ Branch 7 → 46 not taken.
✓ Branch 9 → 10 taken 22142 times.
✗ Branch 9 → 44 not taken.
✓ Branch 10 → 11 taken 22142 times.
✗ Branch 10 → 44 not taken.
✓ Branch 11 → 12 taken 22142 times.
✗ Branch 11 → 55 not taken.
22142 llvm::CallInst *callInst = builder.CreateCall(callee, args);
204
205 // Set attributes to 'this' param
206
1/2
✓ Branch 14 → 15 taken 22142 times.
✗ Branch 14 → 40 not taken.
22142 if (fct->isMethod()) {
207 // Get 'this' entry
208
1/2
✓ Branch 17 → 18 taken 22142 times.
✗ Branch 17 → 49 not taken.
66426 const SymbolTableEntry *thisEntry = fct->bodyScope->lookupStrict(THIS_VARIABLE_NAME);
209
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 22142 times.
22142 assert(thisEntry != nullptr);
210
3/6
✓ Branch 25 → 26 taken 22142 times.
✗ Branch 25 → 53 not taken.
✓ Branch 26 → 27 taken 22142 times.
✗ Branch 26 → 53 not taken.
✓ Branch 27 → 28 taken 22142 times.
✗ Branch 27 → 53 not taken.
22142 llvm::Type *structType = thisEntry->getQualType().getContained().toLLVMType(sourceFile);
211
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 22142 times.
22142 assert(structType != nullptr);
212
1/2
✓ Branch 30 → 31 taken 22142 times.
✗ Branch 30 → 55 not taken.
22142 callInst->addParamAttr(0, llvm::Attribute::NoUndef);
213
1/2
✓ Branch 31 → 32 taken 22142 times.
✗ Branch 31 → 55 not taken.
22142 callInst->addParamAttr(0, llvm::Attribute::NonNull);
214
3/6
✓ Branch 33 → 34 taken 22142 times.
✗ Branch 33 → 54 not taken.
✓ Branch 34 → 35 taken 22142 times.
✗ Branch 34 → 54 not taken.
✓ Branch 35 → 36 taken 22142 times.
✗ Branch 35 → 54 not taken.
22142 callInst->addDereferenceableParamAttr(0, module->getDataLayout().getTypeStoreSize(structType));
215
3/6
✓ Branch 37 → 38 taken 22142 times.
✗ Branch 37 → 55 not taken.
✓ Branch 38 → 39 taken 22142 times.
✗ Branch 38 → 55 not taken.
✓ Branch 39 → 40 taken 22142 times.
✗ Branch 39 → 55 not taken.
22142 callInst->addParamAttr(0, llvm::Attribute::getWithAlignment(context, module->getDataLayout().getABITypeAlign(structType)));
216 }
217
218 22142 return callInst;
219 22142 }
220
221 llvm::Value *IRGenerator::generateFctDeclAndCall(const Function *fct, const std::vector<llvm::Value *> &args) const {
222 generateFctDecl(fct, args);
223 return generateFctCall(fct, args);
224 }
225
226 22142 void IRGenerator::generateProcDeclAndCall(const Function *proc, const std::vector<llvm::Value *> &args) const {
227 22142 generateFctDecl(proc, args);
228 22142 (void)generateFctCall(proc, args);
229 22142 }
230
231 16612 void IRGenerator::generateCtorOrDtorCall(const SymbolTableEntry *entry, const Function *ctorOrDtor,
232 const std::vector<llvm::Value *> &args) {
233 // Retrieve address of the struct variable. For fields this is the 'this' variable, otherwise use the normal address
234 llvm::Value *structAddr;
235
2/2
✓ Branch 3 → 4 taken 2342 times.
✓ Branch 3 → 41 taken 14270 times.
16612 if (entry->isField()) {
236 // Take 'this' var as base pointer
237
1/2
✓ Branch 6 → 7 taken 2342 times.
✗ Branch 6 → 50 not taken.
7026 const SymbolTableEntry *thisVar = currentScope->lookupStrict(THIS_VARIABLE_NAME);
238
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 2342 times.
2342 assert(thisVar != nullptr);
239
7/14
✓ Branch 14 → 15 taken 2342 times.
✗ Branch 14 → 54 not taken.
✓ Branch 15 → 16 taken 2342 times.
✗ Branch 15 → 54 not taken.
✓ Branch 16 → 17 taken 2342 times.
✗ Branch 16 → 22 not taken.
✓ Branch 17 → 18 taken 2342 times.
✗ Branch 17 → 54 not taken.
✓ Branch 18 → 19 taken 2342 times.
✗ Branch 18 → 54 not taken.
✓ Branch 19 → 20 taken 2342 times.
✗ Branch 19 → 54 not taken.
✓ Branch 20 → 21 taken 2342 times.
✗ Branch 20 → 22 not taken.
2342 assert(thisVar->getQualType().isPtr() && thisVar->getQualType().getContained().is(TY_STRUCT));
240
3/6
✓ Branch 23 → 24 taken 2342 times.
✗ Branch 23 → 55 not taken.
✓ Branch 24 → 25 taken 2342 times.
✗ Branch 24 → 55 not taken.
✓ Branch 25 → 26 taken 2342 times.
✗ Branch 25 → 55 not taken.
2342 llvm::Type *thisType = thisVar->getQualType().getContained().toLLVMType(sourceFile);
241
3/6
✓ Branch 29 → 30 taken 2342 times.
✗ Branch 29 → 56 not taken.
✓ Branch 30 → 31 taken 2342 times.
✗ Branch 30 → 56 not taken.
✓ Branch 31 → 32 taken 2342 times.
✗ Branch 31 → 56 not taken.
2342 llvm::Value *thisPtr = insertLoad(builder.getPtrTy(), getAddress(thisVar));
242 // Add field offset
243
1/2
✓ Branch 37 → 38 taken 2342 times.
✗ Branch 37 → 62 not taken.
2342 structAddr = insertStructGEP(thisType, thisPtr, entry->orderIndex);
244 } else {
245 14270 structAddr = getAddress(entry);
246 // For optional parameter initializers we need this exception
247
2/2
✓ Branch 42 → 43 taken 530 times.
✓ Branch 42 → 44 taken 13740 times.
14270 if (!structAddr)
248 530 return;
249 }
250
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 16082 times.
16082 assert(structAddr != nullptr);
251 16082 generateCtorOrDtorCall(structAddr, ctorOrDtor, args);
252 }
253
254 22142 void IRGenerator::generateCtorOrDtorCall(llvm::Value *structAddr, const Function *ctorOrDtor,
255 const std::vector<llvm::Value *> &args) const {
256 // Build parameter list
257
1/2
✓ Branch 4 → 5 taken 22142 times.
✗ Branch 4 → 16 not taken.
44284 std::vector argValues = {structAddr};
258
1/2
✓ Branch 12 → 13 taken 22142 times.
✗ Branch 12 → 20 not taken.
44284 argValues.insert(argValues.end(), args.begin(), args.end());
259
260 // Generate function call
261
1/2
✓ Branch 13 → 14 taken 22142 times.
✗ Branch 13 → 22 not taken.
22142 generateProcDeclAndCall(ctorOrDtor, argValues);
262 22142 }
263
264 1267 void IRGenerator::generateDeallocCall(llvm::Value *variableAddress) const {
265 // Abort if the address is not set. This can happen when leaving the scope of a dtor, which already freed the heap memory
266
2/2
✓ Branch 2 → 3 taken 582 times.
✓ Branch 2 → 4 taken 685 times.
1267 if (!variableAddress)
267 582 return;
268
269 // In case of string runtime, call free manually. Otherwise, use the memory_rt implementation of sDealloc()
270
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 14 taken 685 times.
1370 if (sourceFile->isStringRT()) {
271 llvm::Function *freeFct = stdFunctionManager.getFreeFct();
272 builder.CreateCall(freeFct, variableAddress);
273 } else {
274 685 llvm::Function *deallocFct = stdFunctionManager.getDeallocBytePtrRefFct();
275
3/6
✓ Branch 15 → 16 taken 685 times.
✗ Branch 15 → 26 not taken.
✓ Branch 17 → 18 taken 685 times.
✗ Branch 17 → 24 not taken.
✓ Branch 18 → 19 taken 685 times.
✗ Branch 18 → 24 not taken.
685 builder.CreateCall(deallocFct, variableAddress);
276 }
277 }
278
279 10 llvm::Function *IRGenerator::generateImplicitFunction(const std::function<void()> &generateBody, const Function *spiceFunc) {
280 // Only focus on method procedures
281
1/2
✓ Branch 2 → 3 taken 10 times.
✗ Branch 2 → 161 not taken.
10 const ASTNode *node = spiceFunc->entry->declNode;
282
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 10 times.
10 assert(spiceFunc->isFunction());
283
284 // Only generate if used
285
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 10 times.
10 if (!spiceFunc->used)
286 return nullptr;
287
288 // Retrieve return type
289
1/2
✓ Branch 9 → 10 taken 10 times.
✗ Branch 9 → 161 not taken.
10 llvm::Type *returnType = spiceFunc->returnType.toLLVMType(sourceFile);
290
291 // Get 'this' entry
292 10 std::vector<llvm::Type *> paramTypes;
293
1/2
✓ Branch 10 → 11 taken 10 times.
✗ Branch 10 → 159 not taken.
10 const SymbolTableEntry *thisEntry = nullptr;
294
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 27 taken 10 times.
10 if (spiceFunc->isMethod()) {
295 thisEntry = spiceFunc->bodyScope->lookupStrict(THIS_VARIABLE_NAME);
296 assert(thisEntry != nullptr);
297 paramTypes.push_back(builder.getPtrTy());
298 }
299
300 // Get parameter types
301
1/2
✗ Branch 44 → 29 not taken.
✓ Branch 44 → 45 taken 10 times.
20 for (const auto &[qualType, isOptional] : spiceFunc->paramList) {
302 assert(!isOptional);
303 paramTypes.push_back(qualType.toLLVMType(sourceFile));
304 }
305
306 // Get function linkage
307
2/4
✓ Branch 45 → 46 taken 10 times.
✗ Branch 45 → 159 not taken.
✓ Branch 46 → 47 taken 10 times.
✗ Branch 46 → 159 not taken.
10 const bool isPublic = spiceFunc->entry->getQualType().isPublic();
308
309 // Create function
310
1/2
✓ Branch 47 → 48 taken 10 times.
✗ Branch 47 → 159 not taken.
10 const std::string mangledName = spiceFunc->getMangledName();
311
1/2
✓ Branch 49 → 50 taken 10 times.
✗ Branch 49 → 132 not taken.
10 llvm::FunctionType *fctType = llvm::FunctionType::get(returnType, paramTypes, false);
312
1/2
✓ Branch 50 → 51 taken 10 times.
✗ Branch 50 → 157 not taken.
10 const llvm::GlobalObject::LinkageTypes linkage = getSymbolLinkageType(isPublic);
313
2/4
✓ Branch 51 → 52 taken 10 times.
✗ Branch 51 → 133 not taken.
✓ Branch 52 → 53 taken 10 times.
✗ Branch 52 → 133 not taken.
10 llvm::Function *fct = llvm::Function::Create(fctType, linkage, mangledName, module);
314
1/2
✓ Branch 53 → 54 taken 10 times.
✗ Branch 53 → 157 not taken.
10 fct->addFnAttr(llvm::Attribute::MustProgress);
315
1/2
✓ Branch 54 → 55 taken 10 times.
✗ Branch 54 → 157 not taken.
10 addCommonFctAttrs(fct);
316
317 // Set attributes to 'this' param
318
1/2
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 76 taken 10 times.
10 if (spiceFunc->isMethod()) {
319 fct->addParamAttr(0, llvm::Attribute::NoUndef);
320 fct->addParamAttr(0, llvm::Attribute::NonNull);
321 assert(thisEntry != nullptr);
322 llvm::Type *structType = thisEntry->getQualType().getContained().toLLVMType(sourceFile);
323 assert(structType != nullptr);
324 fct->addDereferenceableParamAttr(0, module->getDataLayout().getTypeStoreSize(structType));
325 fct->addParamAttr(0, llvm::Attribute::getWithAlignment(context, module->getDataLayout().getABITypeAlign(structType)));
326 }
327
328 // Add debug info
329
1/2
✓ Branch 76 → 77 taken 10 times.
✗ Branch 76 → 157 not taken.
10 diGenerator.generateFunctionDebugInfo(fct, spiceFunc);
330
1/2
✗ Branch 77 → 78 not taken.
✓ Branch 77 → 80 taken 10 times.
10 if (node != nullptr)
331 diGenerator.setSourceLocation(node);
332
333 // Change to body scope
334
2/4
✓ Branch 80 → 81 taken 10 times.
✗ Branch 80 → 138 not taken.
✓ Branch 81 → 82 taken 10 times.
✗ Branch 81 → 136 not taken.
10 changeToScope(spiceFunc->getScopeName(), ScopeType::FUNC_PROC_BODY);
335
336 // Create entry block
337
1/2
✓ Branch 86 → 87 taken 10 times.
✗ Branch 86 → 139 not taken.
10 llvm::BasicBlock *bEntry = createBlock();
338
1/2
✓ Branch 89 → 90 taken 10 times.
✗ Branch 89 → 157 not taken.
10 switchToBlock(bEntry, fct);
339
340 // Reset alloca insert markers to this block
341 10 allocaInsertBlock = bEntry;
342
1/2
✓ Branch 90 → 91 taken 10 times.
✗ Branch 90 → 157 not taken.
10 allocaInsertInst = nullptr;
343
344 // Store first argument to 'this' symbol
345
1/2
✗ Branch 93 → 94 not taken.
✓ Branch 93 → 112 taken 10 times.
10 if (spiceFunc->isMethod()) {
346 assert(thisEntry != nullptr);
347 // Allocate space for the parameter
348 llvm::Value *thisAddress = insertAlloca(paramTypes.front(), THIS_VARIABLE_NAME);
349 // Update the symbol table entry
350 updateAddress(thisEntry, thisAddress);
351 // Generate debug info
352 diGenerator.generateLocalVarDebugInfo(THIS_VARIABLE_NAME, thisAddress, 1);
353 // Store the value at the new address
354 insertStore(fct->arg_begin(), thisAddress);
355 }
356
357 // Generate body
358
1/2
✓ Branch 112 → 113 taken 10 times.
✗ Branch 112 → 157 not taken.
10 generateBody();
359
360 // Conclude debug info for function
361
1/2
✓ Branch 113 → 114 taken 10 times.
✗ Branch 113 → 157 not taken.
10 diGenerator.concludeFunctionDebugInfo();
362
363 // Verify function
364 // Use the code location of the declaration node if available. Otherwise, (e.g. in case of test main) use an artificial code loc
365
2/4
✗ Branch 114 → 115 not taken.
✓ Branch 114 → 116 taken 10 times.
✓ Branch 116 → 117 taken 10 times.
✗ Branch 116 → 157 not taken.
10 const CodeLoc codeLoc = node != nullptr ? node->codeLoc : CodeLoc(1, 1, sourceFile);
366
1/2
✓ Branch 117 → 118 taken 10 times.
✗ Branch 117 → 157 not taken.
10 verifyFunction(fct, codeLoc);
367
368 // Change to parent scope
369
1/2
✓ Branch 118 → 119 taken 10 times.
✗ Branch 118 → 157 not taken.
10 changeToParentScope(ScopeType::FUNC_PROC_BODY);
370
371 10 return fct;
372 10 }
373
374 7702 llvm::Function *IRGenerator::generateImplicitProcedure(const std::function<void()> &generateBody, const Function *spiceProc) {
375 // Only focus on method procedures
376 7702 const ASTNode *node = spiceProc->entry->declNode;
377
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 7702 times.
7702 assert(node != nullptr);
378
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 7702 times.
7702 assert(spiceProc->isProcedure());
379
380 // Only generate if used
381
2/2
✓ Branch 9 → 10 taken 5802 times.
✓ Branch 9 → 11 taken 1900 times.
7702 if (!spiceProc->used)
382 5802 return nullptr;
383
384 // Get 'this' entry
385 1900 std::vector<llvm::Type *> paramTypes;
386
1/2
✓ Branch 11 → 12 taken 1900 times.
✗ Branch 11 → 157 not taken.
1900 const SymbolTableEntry *thisEntry = nullptr;
387
1/2
✓ Branch 14 → 15 taken 1900 times.
✗ Branch 14 → 28 not taken.
1900 if (spiceProc->isMethod()) {
388
1/2
✓ Branch 17 → 18 taken 1900 times.
✗ Branch 17 → 123 not taken.
5700 thisEntry = spiceProc->bodyScope->lookupStrict(THIS_VARIABLE_NAME);
389
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 1900 times.
1900 assert(thisEntry != nullptr);
390
2/4
✓ Branch 25 → 26 taken 1900 times.
✗ Branch 25 → 127 not taken.
✓ Branch 26 → 27 taken 1900 times.
✗ Branch 26 → 127 not taken.
1900 paramTypes.push_back(builder.getPtrTy());
391 }
392
393 // Get parameter types
394
2/2
✓ Branch 45 → 30 taken 494 times.
✓ Branch 45 → 46 taken 1900 times.
4294 for (const auto &[qualType, isOptional] : spiceProc->paramList) {
395
1/2
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 494 times.
494 assert(!isOptional);
396
2/4
✓ Branch 34 → 35 taken 494 times.
✗ Branch 34 → 128 not taken.
✓ Branch 35 → 36 taken 494 times.
✗ Branch 35 → 128 not taken.
494 paramTypes.push_back(qualType.toLLVMType(sourceFile));
397 }
398
399 // Get function linkage
400
2/4
✓ Branch 46 → 47 taken 1900 times.
✗ Branch 46 → 157 not taken.
✓ Branch 47 → 48 taken 1900 times.
✗ Branch 47 → 157 not taken.
1900 const bool isPublic = spiceProc->entry->getQualType().isPublic();
401
402 // Create function
403
1/2
✓ Branch 48 → 49 taken 1900 times.
✗ Branch 48 → 157 not taken.
1900 const std::string mangledName = spiceProc->getMangledName();
404
2/4
✓ Branch 50 → 51 taken 1900 times.
✗ Branch 50 → 130 not taken.
✓ Branch 51 → 52 taken 1900 times.
✗ Branch 51 → 130 not taken.
1900 llvm::FunctionType *fctType = llvm::FunctionType::get(builder.getVoidTy(), paramTypes, false);
405
1/2
✓ Branch 52 → 53 taken 1900 times.
✗ Branch 52 → 155 not taken.
1900 const llvm::GlobalObject::LinkageTypes linkage = getSymbolLinkageType(isPublic);
406
2/4
✓ Branch 53 → 54 taken 1900 times.
✗ Branch 53 → 131 not taken.
✓ Branch 54 → 55 taken 1900 times.
✗ Branch 54 → 131 not taken.
1900 llvm::Function *fct = llvm::Function::Create(fctType, linkage, mangledName, module);
407
1/2
✓ Branch 55 → 56 taken 1900 times.
✗ Branch 55 → 155 not taken.
1900 fct->addFnAttr(llvm::Attribute::MustProgress);
408
1/2
✓ Branch 56 → 57 taken 1900 times.
✗ Branch 56 → 155 not taken.
1900 addCommonFctAttrs(fct);
409
410 // Set attributes to 'this' param
411
1/2
✓ Branch 60 → 61 taken 1900 times.
✗ Branch 60 → 78 not taken.
1900 if (spiceProc->isMethod()) {
412
1/2
✓ Branch 61 → 62 taken 1900 times.
✗ Branch 61 → 155 not taken.
1900 fct->addParamAttr(0, llvm::Attribute::NoUndef);
413
1/2
✓ Branch 62 → 63 taken 1900 times.
✗ Branch 62 → 155 not taken.
1900 fct->addParamAttr(0, llvm::Attribute::NonNull);
414
1/2
✗ Branch 63 → 64 not taken.
✓ Branch 63 → 65 taken 1900 times.
1900 assert(thisEntry != nullptr);
415
3/6
✓ Branch 65 → 66 taken 1900 times.
✗ Branch 65 → 132 not taken.
✓ Branch 66 → 67 taken 1900 times.
✗ Branch 66 → 132 not taken.
✓ Branch 67 → 68 taken 1900 times.
✗ Branch 67 → 132 not taken.
1900 llvm::Type *structType = thisEntry->getQualType().getContained().toLLVMType(sourceFile);
416
1/2
✗ Branch 68 → 69 not taken.
✓ Branch 68 → 70 taken 1900 times.
1900 assert(structType != nullptr);
417
3/6
✓ Branch 71 → 72 taken 1900 times.
✗ Branch 71 → 133 not taken.
✓ Branch 72 → 73 taken 1900 times.
✗ Branch 72 → 133 not taken.
✓ Branch 73 → 74 taken 1900 times.
✗ Branch 73 → 133 not taken.
1900 fct->addDereferenceableParamAttr(0, module->getDataLayout().getTypeStoreSize(structType));
418
3/6
✓ Branch 75 → 76 taken 1900 times.
✗ Branch 75 → 155 not taken.
✓ Branch 76 → 77 taken 1900 times.
✗ Branch 76 → 155 not taken.
✓ Branch 77 → 78 taken 1900 times.
✗ Branch 77 → 155 not taken.
1900 fct->addParamAttr(0, llvm::Attribute::getWithAlignment(context, module->getDataLayout().getABITypeAlign(structType)));
419 }
420
421 // Add debug info
422
1/2
✓ Branch 78 → 79 taken 1900 times.
✗ Branch 78 → 155 not taken.
1900 diGenerator.generateFunctionDebugInfo(fct, spiceProc);
423
1/2
✓ Branch 79 → 80 taken 1900 times.
✗ Branch 79 → 155 not taken.
1900 diGenerator.setSourceLocation(node);
424
425 // Change to body scope
426
2/4
✓ Branch 80 → 81 taken 1900 times.
✗ Branch 80 → 136 not taken.
✓ Branch 81 → 82 taken 1900 times.
✗ Branch 81 → 134 not taken.
1900 changeToScope(spiceProc->getScopeName(), ScopeType::FUNC_PROC_BODY);
427
428 // Create entry block
429
1/2
✓ Branch 86 → 87 taken 1900 times.
✗ Branch 86 → 137 not taken.
1900 llvm::BasicBlock *bEntry = createBlock();
430
1/2
✓ Branch 89 → 90 taken 1900 times.
✗ Branch 89 → 155 not taken.
1900 switchToBlock(bEntry, fct);
431
432 // Reset alloca insert markers to this block
433 1900 allocaInsertBlock = bEntry;
434
1/2
✓ Branch 90 → 91 taken 1900 times.
✗ Branch 90 → 155 not taken.
1900 allocaInsertInst = nullptr;
435
436 // Store first argument to 'this' symbol
437
1/2
✓ Branch 93 → 94 taken 1900 times.
✗ Branch 93 → 112 not taken.
1900 if (spiceProc->isMethod()) {
438
1/2
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 96 taken 1900 times.
1900 assert(thisEntry != nullptr);
439 // Allocate space for the parameter
440
2/4
✓ Branch 98 → 99 taken 1900 times.
✗ Branch 98 → 145 not taken.
✓ Branch 100 → 101 taken 1900 times.
✗ Branch 100 → 143 not taken.
1900 llvm::Value *thisAddress = insertAlloca(paramTypes.front(), THIS_VARIABLE_NAME);
441 // Update the symbol table entry
442
1/2
✓ Branch 103 → 104 taken 1900 times.
✗ Branch 103 → 155 not taken.
1900 updateAddress(thisEntry, thisAddress);
443 // Generate debug info
444
2/4
✓ Branch 106 → 107 taken 1900 times.
✗ Branch 106 → 151 not taken.
✓ Branch 107 → 108 taken 1900 times.
✗ Branch 107 → 149 not taken.
3800 diGenerator.generateLocalVarDebugInfo(THIS_VARIABLE_NAME, thisAddress, 1);
445 // Store the value at the new address
446
2/4
✓ Branch 110 → 111 taken 1900 times.
✗ Branch 110 → 155 not taken.
✓ Branch 111 → 112 taken 1900 times.
✗ Branch 111 → 155 not taken.
1900 insertStore(fct->arg_begin(), thisAddress);
447 }
448
449 // Generate body
450
1/2
✓ Branch 112 → 113 taken 1900 times.
✗ Branch 112 → 155 not taken.
1900 generateBody();
451
452 // Create return instruction
453
1/2
✓ Branch 113 → 114 taken 1900 times.
✗ Branch 113 → 155 not taken.
1900 builder.CreateRetVoid();
454
455 // Conclude debug info for function
456
1/2
✓ Branch 114 → 115 taken 1900 times.
✗ Branch 114 → 155 not taken.
1900 diGenerator.concludeFunctionDebugInfo();
457
458 // Verify function
459
1/2
✓ Branch 115 → 116 taken 1900 times.
✗ Branch 115 → 155 not taken.
1900 verifyFunction(fct, node->codeLoc);
460
461 // Change to parent scope
462
1/2
✓ Branch 116 → 117 taken 1900 times.
✗ Branch 116 → 155 not taken.
1900 changeToParentScope(ScopeType::FUNC_PROC_BODY);
463
464 1900 return fct;
465 1900 }
466
467 12890 void IRGenerator::generateCtorBodyPreamble(Scope *bodyScope) {
468 // Retrieve struct scope
469 12890 Scope *structScope = bodyScope->parent;
470
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 12890 times.
12890 assert(structScope != nullptr);
471
472 // Get struct address
473
1/2
✓ Branch 6 → 7 taken 12890 times.
✗ Branch 6 → 132 not taken.
38670 const SymbolTableEntry *thisEntry = bodyScope->lookupStrict(THIS_VARIABLE_NAME);
474
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 12890 times.
12890 assert(thisEntry != nullptr);
475
1/2
✓ Branch 14 → 15 taken 12890 times.
✗ Branch 14 → 186 not taken.
12890 llvm::Value *thisPtrPtr = getAddress(thisEntry);
476
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 12890 times.
12890 assert(thisPtrPtr != nullptr);
477 12890 llvm::Value *thisPtr = nullptr;
478
2/4
✓ Branch 17 → 18 taken 12890 times.
✗ Branch 17 → 186 not taken.
✓ Branch 18 → 19 taken 12890 times.
✗ Branch 18 → 186 not taken.
12890 const QualType structSymbolType = thisEntry->getQualType().getBase();
479
1/2
✓ Branch 19 → 20 taken 12890 times.
✗ Branch 19 → 186 not taken.
12890 llvm::Type *structType = structSymbolType.toLLVMType(sourceFile);
480
481 // Store VTable to first struct field if required
482
1/2
✓ Branch 20 → 21 taken 12890 times.
✗ Branch 20 → 186 not taken.
12890 const Struct *spiceStruct = structSymbolType.getStruct(nullptr);
483
1/2
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 12890 times.
12890 assert(spiceStruct != nullptr);
484
2/2
✓ Branch 23 → 24 taken 2872 times.
✓ Branch 23 → 45 taken 10018 times.
12890 if (spiceStruct->vTableData.vtable != nullptr) {
485
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 2872 times.
2872 assert(spiceStruct->vTableData.vtableType != nullptr);
486 // Store VTable to field address at index 0
487
2/4
✓ Branch 29 → 30 taken 2872 times.
✗ Branch 29 → 136 not taken.
✓ Branch 30 → 31 taken 2872 times.
✗ Branch 30 → 136 not taken.
2872 thisPtr = insertLoad(builder.getPtrTy(), thisPtrPtr);
488
3/6
✓ Branch 33 → 34 taken 2872 times.
✗ Branch 33 → 149 not taken.
✓ Branch 34 → 35 taken 2872 times.
✗ Branch 34 → 149 not taken.
✓ Branch 35 → 36 taken 2872 times.
✗ Branch 35 → 149 not taken.
2872 llvm::Value *indices[3] = {builder.getInt64(0), builder.getInt32(0), builder.getInt32(2)};
489
1/2
✓ Branch 40 → 41 taken 2872 times.
✗ Branch 40 → 142 not taken.
2872 llvm::Value *gepResult = insertInBoundsGEP(spiceStruct->vTableData.vtableType, spiceStruct->vTableData.vtable, indices);
490
1/2
✓ Branch 43 → 44 taken 2872 times.
✗ Branch 43 → 149 not taken.
2872 insertStore(gepResult, thisPtr);
491 }
492
493
1/2
✓ Branch 45 → 46 taken 12890 times.
✗ Branch 45 → 186 not taken.
12890 const size_t fieldCount = structScope->getFieldCount();
494
2/2
✓ Branch 128 → 47 taken 31603 times.
✓ Branch 128 → 129 taken 12890 times.
44493 for (size_t fieldIdx = 0; fieldIdx < fieldCount; fieldIdx++) {
495
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 31603 times.
31603 const SymbolTableEntry *fieldSymbol = structScope->lookupField(fieldIdx);
496
3/6
✓ Branch 52 → 53 taken 31603 times.
✗ Branch 52 → 56 not taken.
✓ Branch 53 → 54 taken 31603 times.
✗ Branch 53 → 186 not taken.
✓ Branch 54 → 55 taken 31603 times.
✗ Branch 54 → 56 not taken.
31603 assert(fieldSymbol != nullptr && fieldSymbol->isField());
497
2/2
✓ Branch 57 → 58 taken 2654 times.
✓ Branch 57 → 59 taken 28949 times.
31603 if (fieldSymbol->isImplicitField)
498 2654 continue;
499
500 // Call ctor for struct fields
501
1/2
✓ Branch 59 → 60 taken 28949 times.
✗ Branch 59 → 186 not taken.
28949 const QualType &fieldType = fieldSymbol->getQualType();
502
1/2
✓ Branch 60 → 61 taken 28949 times.
✗ Branch 60 → 62 not taken.
28949 const auto fieldNode = spice_pointer_cast<FieldNode *>(fieldSymbol->declNode);
503
3/4
✓ Branch 69 → 70 taken 28949 times.
✗ Branch 69 → 186 not taken.
✓ Branch 70 → 71 taken 7003 times.
✓ Branch 70 → 101 taken 21946 times.
28949 if (fieldType.is(TY_STRUCT)) {
504 // Lookup ctor function and call if available
505
1/2
✓ Branch 71 → 72 taken 7003 times.
✗ Branch 71 → 186 not taken.
7003 Scope *matchScope = fieldType.getBodyScope();
506
4/6
✓ Branch 75 → 76 taken 7003 times.
✗ Branch 75 → 152 not taken.
✓ Branch 76 → 77 taken 7003 times.
✗ Branch 76 → 150 not taken.
✓ Branch 80 → 81 taken 3964 times.
✓ Branch 80 → 100 taken 3039 times.
21009 if (const Function *ctorFunction = FunctionManager::lookup(matchScope, CTOR_FUNCTION_NAME, fieldType, {}, false)) {
507
2/2
✓ Branch 81 → 82 taken 818 times.
✓ Branch 81 → 90 taken 3146 times.
3964 if (!thisPtr)
508
2/4
✓ Branch 85 → 86 taken 818 times.
✗ Branch 85 → 159 not taken.
✓ Branch 86 → 87 taken 818 times.
✗ Branch 86 → 159 not taken.
818 thisPtr = insertLoad(builder.getPtrTy(), thisPtrPtr);
509
1/2
✓ Branch 93 → 94 taken 3964 times.
✗ Branch 93 → 165 not taken.
3964 llvm::Value *fieldAddress = insertStructGEP(structType, thisPtr, fieldIdx);
510
1/2
✓ Branch 97 → 98 taken 3964 times.
✗ Branch 97 → 171 not taken.
3964 generateCtorOrDtorCall(fieldAddress, ctorFunction, {});
511 }
512 7003 continue;
513 7003 }
514
515 // Store default field values
516
3/4
✓ Branch 101 → 102 taken 9578 times.
✓ Branch 101 → 103 taken 12368 times.
✓ Branch 102 → 103 taken 9578 times.
✗ Branch 102 → 127 not taken.
21946 if (fieldNode->defaultValue != nullptr || cliOptions.buildMode != BuildMode::RELEASE) {
517 // Retrieve field address
518
2/2
✓ Branch 103 → 104 taken 6760 times.
✓ Branch 103 → 112 taken 15186 times.
21946 if (!thisPtr)
519
2/4
✓ Branch 107 → 108 taken 6760 times.
✗ Branch 107 → 174 not taken.
✓ Branch 108 → 109 taken 6760 times.
✗ Branch 108 → 174 not taken.
6760 thisPtr = insertLoad(builder.getPtrTy(), thisPtrPtr);
520
1/2
✓ Branch 115 → 116 taken 21946 times.
✗ Branch 115 → 180 not taken.
21946 llvm::Value *fieldAddress = insertStructGEP(structType, thisPtr, fieldIdx);
521 // Retrieve default value
522 llvm::Value *value;
523
2/2
✓ Branch 118 → 119 taken 12368 times.
✓ Branch 118 → 121 taken 9578 times.
21946 if (fieldNode->defaultValue != nullptr) {
524 // To resolve the default value, we need to temporarily change to the manifestation of the current struct instantiation
525 12368 const size_t oldManIdx = manIdx; // Save manifestation index
526 12368 manIdx = spiceStruct->manifestationIndex;
527
1/2
✓ Branch 119 → 120 taken 12368 times.
✗ Branch 119 → 186 not taken.
12368 value = resolveValue(fieldNode->defaultValue);
528 12368 manIdx = oldManIdx; // Restore manifestation index
529 } else {
530
1/4
✗ Branch 121 → 122 not taken.
✓ Branch 121 → 124 taken 9578 times.
✗ Branch 122 → 123 not taken.
✗ Branch 122 → 124 not taken.
9578 assert(cliOptions.buildMode == BuildMode::DEBUG || cliOptions.buildMode == BuildMode::TEST);
531
1/2
✓ Branch 124 → 125 taken 9578 times.
✗ Branch 124 → 186 not taken.
9578 value = getDefaultValueForSymbolType(fieldType);
532 }
533 // Store default value
534
1/2
✓ Branch 126 → 127 taken 21946 times.
✗ Branch 126 → 186 not taken.
21946 insertStore(value, fieldAddress);
535 }
536 }
537 12890 }
538
539 306 void IRGenerator::generateDefaultCtor(const Function *ctorFunction) {
540
3/6
✓ Branch 2 → 3 taken 306 times.
✗ Branch 2 → 6 not taken.
✓ Branch 3 → 4 taken 306 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 306 times.
✗ Branch 4 → 6 not taken.
306 assert(ctorFunction->implicitDefault && ctorFunction->name == CTOR_FUNCTION_NAME);
541 542 const std::function<void()> generateBody = [&] { generateCtorBodyPreamble(ctorFunction->bodyScope); };
542
1/2
✓ Branch 8 → 9 taken 306 times.
✗ Branch 8 → 11 not taken.
306 generateImplicitProcedure(generateBody, ctorFunction);
543 306 }
544
545 484 void IRGenerator::generateCopyCtorBodyPreamble(const Function *copyCtorFunction) {
546 // Retrieve struct scope
547 484 Scope *structScope = copyCtorFunction->bodyScope->parent;
548
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 484 times.
484 assert(structScope != nullptr);
549
550 // Get struct address
551
1/2
✓ Branch 6 → 7 taken 484 times.
✗ Branch 6 → 141 not taken.
1452 const SymbolTableEntry *thisEntry = copyCtorFunction->bodyScope->lookupStrict(THIS_VARIABLE_NAME);
552
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 484 times.
484 assert(thisEntry != nullptr);
553 484 llvm::Value *thisPtrPtr = getAddress(thisEntry);
554
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 484 times.
484 assert(thisPtrPtr != nullptr);
555 484 llvm::Value *thisPtr = nullptr;
556
3/6
✓ Branch 17 → 18 taken 484 times.
✗ Branch 17 → 145 not taken.
✓ Branch 18 → 19 taken 484 times.
✗ Branch 18 → 145 not taken.
✓ Branch 19 → 20 taken 484 times.
✗ Branch 19 → 145 not taken.
484 llvm::Type *structType = thisEntry->getQualType().getBase().toLLVMType(sourceFile);
557
558 // Retrieve the value of the original struct, which is the only function parameter
559 484 llvm::Value *originalThisPtr = builder.GetInsertBlock()->getParent()->getArg(1);
560
561 484 const size_t fieldCount = structScope->getFieldCount();
562
2/2
✓ Branch 137 → 25 taken 1382 times.
✓ Branch 137 → 138 taken 484 times.
1866 for (size_t fieldIdx = 0; fieldIdx < fieldCount; fieldIdx++) {
563
1/2
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 1382 times.
1382 const SymbolTableEntry *fieldSymbol = structScope->lookupField(fieldIdx);
564
2/4
✓ Branch 30 → 31 taken 1382 times.
✗ Branch 30 → 34 not taken.
✓ Branch 32 → 33 taken 1382 times.
✗ Branch 32 → 34 not taken.
1382 assert(fieldSymbol != nullptr && fieldSymbol->isField());
565
566 // Retrieve the address of the original field (copy source)
567
1/2
✓ Branch 38 → 39 taken 1382 times.
✗ Branch 38 → 146 not taken.
1382 llvm::Value *originalFieldAddress = insertStructGEP(structType, originalThisPtr, fieldIdx);
568
569 1382 const QualType &fieldType = fieldSymbol->getQualType();
570
571 // Call copy ctor for struct fields
572
6/6
✓ Branch 43 → 44 taken 856 times.
✓ Branch 43 → 47 taken 526 times.
✓ Branch 45 → 46 taken 796 times.
✓ Branch 45 → 47 taken 60 times.
✓ Branch 48 → 49 taken 796 times.
✓ Branch 48 → 73 taken 586 times.
1382 if (fieldType.is(TY_STRUCT) && !fieldType.isTriviallyCopyable(nullptr)) {
573 // Lookup copy ctor function and call if available
574
1/2
✓ Branch 49 → 50 taken 796 times.
✗ Branch 49 → 173 not taken.
796 Scope *matchScope = fieldType.getBodyScope();
575
2/4
✓ Branch 50 → 51 taken 796 times.
✗ Branch 50 → 156 not taken.
✓ Branch 54 → 55 taken 796 times.
✗ Branch 54 → 152 not taken.
2388 const ArgList args = {{fieldType.toConstRef(nullptr), false /* we have the field as storage */}};
576
2/4
✓ Branch 58 → 59 taken 796 times.
✗ Branch 58 → 160 not taken.
✓ Branch 59 → 60 taken 796 times.
✗ Branch 59 → 158 not taken.
796 const Function *copyCtor = FunctionManager::lookup(matchScope, CTOR_FUNCTION_NAME, fieldType, args, false);
577
1/2
✗ Branch 62 → 63 not taken.
✓ Branch 62 → 64 taken 796 times.
796 assert(copyCtor != nullptr);
578
2/4
✓ Branch 66 → 67 taken 796 times.
✗ Branch 66 → 166 not taken.
✓ Branch 67 → 68 taken 796 times.
✗ Branch 67 → 164 not taken.
1592 generateCtorOrDtorCall(fieldSymbol, copyCtor, {originalFieldAddress});
579 796 continue;
580 796 }
581
582 // Retrieve the address of the new field (copy dest)
583
2/2
✓ Branch 73 → 74 taken 302 times.
✓ Branch 73 → 82 taken 284 times.
586 if (!thisPtr)
584
2/4
✓ Branch 77 → 78 taken 302 times.
✗ Branch 77 → 174 not taken.
✓ Branch 78 → 79 taken 302 times.
✗ Branch 78 → 174 not taken.
302 thisPtr = insertLoad(builder.getPtrTy(), thisPtrPtr);
585
1/2
✓ Branch 85 → 86 taken 586 times.
✗ Branch 85 → 180 not taken.
586 llvm::Value *fieldAddress = insertStructGEP(structType, thisPtr, fieldIdx);
586
587 // For owning heap fields, copy the underlying heap storage
588
2/2
✓ Branch 89 → 90 taken 6 times.
✓ Branch 89 → 134 taken 580 times.
586 if (fieldType.isHeap()) {
589
1/2
✗ Branch 91 → 92 not taken.
✓ Branch 91 → 93 taken 6 times.
6 assert(fieldType.isPtr());
590
2/4
✓ Branch 93 → 94 taken 6 times.
✗ Branch 93 → 186 not taken.
✓ Branch 94 → 95 taken 6 times.
✗ Branch 94 → 186 not taken.
6 llvm::Type *pointeeType = fieldType.getContained().toLLVMType(sourceFile);
591
592 // Retrieve original heap address
593
2/4
✓ Branch 98 → 99 taken 6 times.
✗ Branch 98 → 187 not taken.
✓ Branch 99 → 100 taken 6 times.
✗ Branch 99 → 187 not taken.
6 llvm::Value *originalHeapAddress = insertLoad(builder.getPtrTy(), originalFieldAddress);
594
595 // Insert check for nullptr
596
2/4
✓ Branch 104 → 105 taken 6 times.
✗ Branch 104 → 195 not taken.
✓ Branch 105 → 106 taken 6 times.
✗ Branch 105 → 193 not taken.
12 llvm::BasicBlock *bThen = createBlock("nullptrcheck.then");
597
2/4
✓ Branch 110 → 111 taken 6 times.
✗ Branch 110 → 201 not taken.
✓ Branch 111 → 112 taken 6 times.
✗ Branch 111 → 199 not taken.
6 llvm::BasicBlock *bExit = createBlock("nullptrcheck.exit");
598
4/8
✓ Branch 114 → 115 taken 6 times.
✗ Branch 114 → 205 not taken.
✓ Branch 115 → 116 taken 6 times.
✗ Branch 115 → 205 not taken.
✓ Branch 116 → 117 taken 6 times.
✗ Branch 116 → 205 not taken.
✓ Branch 117 → 118 taken 6 times.
✗ Branch 117 → 205 not taken.
6 llvm::Value *condValue = builder.CreateICmpNE(originalHeapAddress, llvm::Constant::getNullValue(builder.getPtrTy()));
599 6 insertCondJump(condValue, bThen, bExit);
600
601 // Fill then block
602 6 switchToBlock(bThen);
603
604 // Allocate new space on the heap
605 6 llvm::Function *unsafeAllocFct = stdFunctionManager.getAllocUnsafeLongFct();
606
2/4
✓ Branch 122 → 123 taken 6 times.
✗ Branch 122 → 206 not taken.
✓ Branch 123 → 124 taken 6 times.
✗ Branch 123 → 206 not taken.
6 const size_t typeSizeInBytes = module->getDataLayout().getTypeSizeInBits(pointeeType) / 8;
607 6 llvm::ConstantInt *typeSize = builder.getInt64(typeSizeInBytes);
608
3/6
✓ Branch 125 → 126 taken 6 times.
✗ Branch 125 → 210 not taken.
✓ Branch 127 → 128 taken 6 times.
✗ Branch 127 → 207 not taken.
✓ Branch 128 → 129 taken 6 times.
✗ Branch 128 → 207 not taken.
6 llvm::Value *newHeapAddress = builder.CreateCall(unsafeAllocFct, {typeSize});
609 6 insertStore(newHeapAddress, fieldAddress);
610
611 // Copy data from the old heap storage to the new one
612 6 generateShallowCopy(originalHeapAddress, pointeeType, newHeapAddress, false);
613 6 insertJump(bExit);
614
615 // Switch to exit block
616 6 switchToBlock(bExit);
617
618 6 continue;
619 6 }
620
621 // Shallow copy
622 580 llvm::Type *type = fieldType.toLLVMType(sourceFile);
623 580 generateShallowCopy(originalFieldAddress, type, fieldAddress, false);
624 }
625 484 }
626
627 3783 void IRGenerator::generateDefaultCopyCtor(const Function *copyCtorFunction) {
628
3/6
✓ Branch 2 → 3 taken 3783 times.
✗ Branch 2 → 6 not taken.
✓ Branch 3 → 4 taken 3783 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 3783 times.
✗ Branch 4 → 6 not taken.
3783 assert(copyCtorFunction->implicitDefault && copyCtorFunction->name == CTOR_FUNCTION_NAME);
629 4267 const std::function<void()> generateBody = [&] { generateCopyCtorBodyPreamble(copyCtorFunction); };
630
1/2
✓ Branch 8 → 9 taken 3783 times.
✗ Branch 8 → 11 not taken.
3783 generateImplicitProcedure(generateBody, copyCtorFunction);
631 3783 }
632
633 10 void IRGenerator::generateMoveCtorBodyPreamble(const Function *moveCtorFunction) {
634 // Retrieve struct scope
635 10 Scope *structScope = moveCtorFunction->bodyScope->parent;
636
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 10 times.
10 assert(structScope != nullptr);
637
638 // Get struct address
639
1/2
✓ Branch 6 → 7 taken 10 times.
✗ Branch 6 → 118 not taken.
30 const SymbolTableEntry *thisEntry = moveCtorFunction->bodyScope->lookupStrict(THIS_VARIABLE_NAME);
640
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 10 times.
10 assert(thisEntry != nullptr);
641 10 llvm::Value *thisPtrPtr = getAddress(thisEntry);
642
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 10 times.
10 assert(thisPtrPtr != nullptr);
643 10 llvm::Value *thisPtr = nullptr;
644
3/6
✓ Branch 17 → 18 taken 10 times.
✗ Branch 17 → 122 not taken.
✓ Branch 18 → 19 taken 10 times.
✗ Branch 18 → 122 not taken.
✓ Branch 19 → 20 taken 10 times.
✗ Branch 19 → 122 not taken.
10 llvm::Type *structType = thisEntry->getQualType().getBase().toLLVMType(sourceFile);
645
646 // Retrieve the value of the original (source) struct, which is the only function parameter
647 10 llvm::Value *originalThisPtr = builder.GetInsertBlock()->getParent()->getArg(1);
648
649 10 const size_t fieldCount = structScope->getFieldCount();
650
2/2
✓ Branch 114 → 25 taken 14 times.
✓ Branch 114 → 115 taken 10 times.
24 for (size_t fieldIdx = 0; fieldIdx < fieldCount; fieldIdx++) {
651
1/2
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 14 times.
14 const SymbolTableEntry *fieldSymbol = structScope->lookupField(fieldIdx);
652
2/4
✓ Branch 30 → 31 taken 14 times.
✗ Branch 30 → 34 not taken.
✓ Branch 32 → 33 taken 14 times.
✗ Branch 32 → 34 not taken.
14 assert(fieldSymbol != nullptr && fieldSymbol->isField());
653
654 // Retrieve the address of the original field (move source)
655
1/2
✓ Branch 38 → 39 taken 14 times.
✗ Branch 38 → 123 not taken.
14 llvm::Value *originalFieldAddress = insertStructGEP(structType, originalThisPtr, fieldIdx);
656
657 14 const QualType &fieldType = fieldSymbol->getQualType();
658
659 // Call move ctor for struct fields if available, otherwise fall back to copy or shallow copy
660
2/2
✓ Branch 43 → 44 taken 4 times.
✓ Branch 43 → 79 taken 10 times.
14 if (fieldType.is(TY_STRUCT)) {
661 4 Scope *matchScope = fieldType.getBodyScope();
662 // First try to find a move ctor (non-const ref param). We scan the manifestations directly via
663 // findMoveCtor rather than FunctionManager::lookup with a non-const ref arg, because lookup permits
664 // const-param-to-non-const-arg "constify" matching and may return the copy ctor as a false positive.
665
1/2
✓ Branch 46 → 47 taken 4 times.
✗ Branch 46 → 54 not taken.
4 if (const Function *moveCtor = FunctionManager::findMoveCtor(matchScope)) {
666
2/4
✓ Branch 49 → 50 taken 4 times.
✗ Branch 49 → 131 not taken.
✓ Branch 50 → 51 taken 4 times.
✗ Branch 50 → 129 not taken.
8 generateCtorOrDtorCall(fieldSymbol, moveCtor, {originalFieldAddress});
667 4 continue;
668 }
669 // No move ctor: fall back to copy ctor for non-trivially copyable types
670 if (!fieldType.isTriviallyCopyable(nullptr)) {
671 const ArgList copyArgs = {{fieldType.toConstRef(nullptr), false}};
672 const Function *copyCtor = FunctionManager::lookup(matchScope, CTOR_FUNCTION_NAME, fieldType, copyArgs, false);
673 assert(copyCtor != nullptr);
674 generateCtorOrDtorCall(fieldSymbol, copyCtor, {originalFieldAddress});
675 continue;
676 }
677 }
678
679 // Retrieve the address of the new field (move dest)
680
2/2
✓ Branch 79 → 80 taken 8 times.
✓ Branch 79 → 88 taken 2 times.
10 if (!thisPtr)
681
2/4
✓ Branch 83 → 84 taken 8 times.
✗ Branch 83 → 158 not taken.
✓ Branch 84 → 85 taken 8 times.
✗ Branch 84 → 158 not taken.
8 thisPtr = insertLoad(builder.getPtrTy(), thisPtrPtr);
682
1/2
✓ Branch 91 → 92 taken 10 times.
✗ Branch 91 → 164 not taken.
10 llvm::Value *fieldAddress = insertStructGEP(structType, thisPtr, fieldIdx);
683
684 // For owning heap fields, transfer ownership: copy the pointer to the destination, and null out the source
685
2/2
✓ Branch 95 → 96 taken 6 times.
✓ Branch 95 → 111 taken 4 times.
10 if (fieldType.isHeap()) {
686
1/2
✗ Branch 97 → 98 not taken.
✓ Branch 97 → 99 taken 6 times.
6 assert(fieldType.isPtr());
687
688 // Load original heap address
689
2/4
✓ Branch 102 → 103 taken 6 times.
✗ Branch 102 → 170 not taken.
✓ Branch 103 → 104 taken 6 times.
✗ Branch 103 → 170 not taken.
6 llvm::Value *originalHeapAddress = insertLoad(builder.getPtrTy(), originalFieldAddress);
690 // Store it in the destination field
691 6 insertStore(originalHeapAddress, fieldAddress);
692 // Null out the source field so its dtor does not free the storage
693 6 insertStore(llvm::Constant::getNullValue(builder.getPtrTy()), originalFieldAddress);
694
695 6 continue;
696 6 }
697
698 // Shallow copy non-heap, non-struct (or trivially copyable struct) fields
699 4 llvm::Type *type = fieldType.toLLVMType(sourceFile);
700 4 generateShallowCopy(originalFieldAddress, type, fieldAddress, false);
701 }
702 10 }
703
704 20 void IRGenerator::generateDefaultMoveCtor(const Function *moveCtorFunction) {
705
3/6
✓ Branch 2 → 3 taken 20 times.
✗ Branch 2 → 6 not taken.
✓ Branch 3 → 4 taken 20 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 20 times.
✗ Branch 4 → 6 not taken.
20 assert(moveCtorFunction->implicitDefault && moveCtorFunction->name == CTOR_FUNCTION_NAME);
706 30 const std::function<void()> generateBody = [&] { generateMoveCtorBodyPreamble(moveCtorFunction); };
707
1/2
✓ Branch 8 → 9 taken 20 times.
✗ Branch 8 → 11 not taken.
20 generateImplicitProcedure(generateBody, moveCtorFunction);
708 20 }
709
710 1170 void IRGenerator::generateDtorBodyPreamble(const Function *dtorFunction) {
711 // Retrieve struct scope
712 1170 Scope *structScope = dtorFunction->bodyScope->parent;
713
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 1170 times.
1170 assert(structScope != nullptr);
714
715 // Get struct address
716
1/2
✓ Branch 6 → 7 taken 1170 times.
✗ Branch 6 → 73 not taken.
3510 const SymbolTableEntry *thisEntry = dtorFunction->bodyScope->lookupStrict(THIS_VARIABLE_NAME);
717
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 1170 times.
1170 assert(thisEntry != nullptr);
718 1170 llvm::Value *thisPtrPtr = getAddress(thisEntry);
719
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 1170 times.
1170 assert(thisPtrPtr != nullptr);
720 1170 llvm::Value *thisPtr = nullptr;
721
3/6
✓ Branch 17 → 18 taken 1170 times.
✗ Branch 17 → 77 not taken.
✓ Branch 18 → 19 taken 1170 times.
✗ Branch 18 → 77 not taken.
✓ Branch 19 → 20 taken 1170 times.
✗ Branch 19 → 77 not taken.
1170 llvm::Type *structType = thisEntry->getQualType().getBase().toLLVMType(sourceFile);
722
723 1170 const size_t fieldCount = structScope->getFieldCount();
724
2/2
✓ Branch 69 → 22 taken 3155 times.
✓ Branch 69 → 70 taken 1170 times.
4325 for (size_t i = 0; i < fieldCount; i++) {
725 3155 const size_t fieldIdx = fieldCount - 1 - i; // Destruct fields in reverse order
726
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 3155 times.
3155 const SymbolTableEntry *fieldSymbol = structScope->lookupField(fieldIdx);
727
2/4
✓ Branch 27 → 28 taken 3155 times.
✗ Branch 27 → 31 not taken.
✓ Branch 29 → 30 taken 3155 times.
✗ Branch 29 → 31 not taken.
3155 assert(fieldSymbol != nullptr && fieldSymbol->isField());
728
729 // Call dtor for struct fields
730 3155 const QualType &fieldType = fieldSymbol->getQualType();
731
2/2
✓ Branch 34 → 35 taken 1682 times.
✓ Branch 34 → 50 taken 1473 times.
3155 if (fieldType.is(TY_STRUCT)) {
732 // Lookup dtor function and generate call if found
733
5/8
✓ Branch 38 → 39 taken 1682 times.
✗ Branch 38 → 80 not taken.
✓ Branch 39 → 40 taken 1682 times.
✗ Branch 39 → 78 not taken.
✓ Branch 40 → 41 taken 1682 times.
✗ Branch 40 → 78 not taken.
✓ Branch 44 → 45 taken 1356 times.
✓ Branch 44 → 49 taken 326 times.
5046 if (const Function *dtorFct = FunctionManager::lookup(fieldType.getBodyScope(), DTOR_FUNCTION_NAME, fieldType, {}, false))
734
1/2
✓ Branch 46 → 47 taken 1356 times.
✗ Branch 46 → 87 not taken.
1356 generateCtorOrDtorCall(fieldSymbol, dtorFct, {});
735 1682 continue;
736 1682 }
737
738 // Deallocate fields, that are stored on the heap
739
2/2
✓ Branch 51 → 52 taken 346 times.
✓ Branch 51 → 68 taken 1127 times.
1473 if (fieldType.isHeap()) {
740 // Retrieve field address
741
2/2
✓ Branch 52 → 53 taken 312 times.
✓ Branch 52 → 61 taken 34 times.
346 if (!thisPtr)
742
2/4
✓ Branch 56 → 57 taken 312 times.
✗ Branch 56 → 90 not taken.
✓ Branch 57 → 58 taken 312 times.
✗ Branch 57 → 90 not taken.
312 thisPtr = insertLoad(builder.getPtrTy(), thisPtrPtr);
743
1/2
✓ Branch 64 → 65 taken 346 times.
✗ Branch 64 → 96 not taken.
346 llvm::Value *fieldAddress = insertStructGEP(structType, thisPtr, fieldIdx);
744 // Call dealloc function
745 346 generateDeallocCall(fieldAddress);
746 }
747 }
748 1170 }
749
750 3593 void IRGenerator::generateDefaultDtor(const Function *dtorFunction) {
751
3/6
✓ Branch 2 → 3 taken 3593 times.
✗ Branch 2 → 6 not taken.
✓ Branch 3 → 4 taken 3593 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 3593 times.
✗ Branch 4 → 6 not taken.
3593 assert(dtorFunction->implicitDefault && dtorFunction->name == DTOR_FUNCTION_NAME);
752 4763 const std::function<void()> generateBody = [&] { generateDtorBodyPreamble(dtorFunction); };
753
1/2
✓ Branch 8 → 9 taken 3593 times.
✗ Branch 8 → 11 not taken.
3593 generateImplicitProcedure(generateBody, dtorFunction);
754 3593 }
755
756 10 void IRGenerator::generateTestMain() {
757 // Collect all test functions
758 10 std::vector<const std::vector<const Function *> *> tests;
759
5/8
✓ Branch 2 → 3 taken 10 times.
✗ Branch 2 → 138 not taken.
✓ Branch 3 → 4 taken 10 times.
✗ Branch 3 → 138 not taken.
✓ Branch 4 → 5 taken 10 times.
✗ Branch 4 → 138 not taken.
✓ Branch 15 → 6 taken 12 times.
✓ Branch 15 → 16 taken 10 times.
22 for (const auto &sourceFile : resourceManager.sourceFiles | std::views::values)
760
1/2
✓ Branch 9 → 10 taken 12 times.
✗ Branch 9 → 13 not taken.
12 if (!sourceFile->testFunctions.empty())
761
1/2
✓ Branch 11 → 12 taken 12 times.
✗ Branch 11 → 137 not taken.
12 tests.push_back(&sourceFile->testFunctions);
762
763 // Prepare printf function
764
1/2
✓ Branch 16 → 17 taken 10 times.
✗ Branch 16 → 263 not taken.
10 llvm::Function *printfFct = stdFunctionManager.getPrintfFct();
765
766 // Prepare success and error messages
767
3/6
✓ Branch 19 → 20 taken 10 times.
✗ Branch 19 → 147 not taken.
✓ Branch 22 → 23 taken 10 times.
✗ Branch 22 → 141 not taken.
✓ Branch 23 → 24 taken 10 times.
✗ Branch 23 → 139 not taken.
40 llvm::Constant *allStartMsg = createGlobalStringConst("allStartMsg", TEST_ALL_START_MSG, *rootScope->codeLoc);
768
3/6
✓ Branch 30 → 31 taken 10 times.
✗ Branch 30 → 159 not taken.
✓ Branch 33 → 34 taken 10 times.
✗ Branch 33 → 153 not taken.
✓ Branch 34 → 35 taken 10 times.
✗ Branch 34 → 151 not taken.
40 llvm::Constant *allEndMsg = createGlobalStringConst("allEndMsg", TEST_ALL_END_MSG, *rootScope->codeLoc);
769
3/6
✓ Branch 41 → 42 taken 10 times.
✗ Branch 41 → 171 not taken.
✓ Branch 44 → 45 taken 10 times.
✗ Branch 44 → 165 not taken.
✓ Branch 45 → 46 taken 10 times.
✗ Branch 45 → 163 not taken.
40 llvm::Constant *fileStartMsg = createGlobalStringConst("fileStartMsg", TEST_FILE_START_MSG, *rootScope->codeLoc);
770
3/6
✓ Branch 52 → 53 taken 10 times.
✗ Branch 52 → 183 not taken.
✓ Branch 55 → 56 taken 10 times.
✗ Branch 55 → 177 not taken.
✓ Branch 56 → 57 taken 10 times.
✗ Branch 56 → 175 not taken.
40 llvm::Constant *fileEndMsg = createGlobalStringConst("fileEndMsg", TEST_FILE_END_MSG, *rootScope->codeLoc);
771
3/6
✓ Branch 63 → 64 taken 10 times.
✗ Branch 63 → 195 not taken.
✓ Branch 66 → 67 taken 10 times.
✗ Branch 66 → 189 not taken.
✓ Branch 67 → 68 taken 10 times.
✗ Branch 67 → 187 not taken.
40 llvm::Constant *runMsg = createGlobalStringConst("runMsg", TEST_CASE_RUN_MSG, *rootScope->codeLoc);
772
3/6
✓ Branch 74 → 75 taken 10 times.
✗ Branch 74 → 207 not taken.
✓ Branch 77 → 78 taken 10 times.
✗ Branch 77 → 201 not taken.
✓ Branch 78 → 79 taken 10 times.
✗ Branch 78 → 199 not taken.
40 llvm::Constant *successMsg = createGlobalStringConst("successMsg", TEST_CASE_SUCCESS_MSG, *rootScope->codeLoc);
773
3/6
✓ Branch 85 → 86 taken 10 times.
✗ Branch 85 → 219 not taken.
✓ Branch 88 → 89 taken 10 times.
✗ Branch 88 → 213 not taken.
✓ Branch 89 → 90 taken 10 times.
✗ Branch 89 → 211 not taken.
40 llvm::Constant *errorMsg = createGlobalStringConst("errorMsg", TEST_CASE_FAILED_MSG, *rootScope->codeLoc);
774
3/6
✓ Branch 96 → 97 taken 10 times.
✗ Branch 96 → 231 not taken.
✓ Branch 99 → 100 taken 10 times.
✗ Branch 99 → 225 not taken.
✓ Branch 100 → 101 taken 10 times.
✗ Branch 100 → 223 not taken.
40 llvm::Constant *skippedMsg = createGlobalStringConst("skippedMsg", TEST_CASE_SKIPPED_MSG, *rootScope->codeLoc);
775
776 // Prepare entry for test main
777
1/2
✓ Branch 105 → 106 taken 10 times.
✗ Branch 105 → 263 not taken.
10 QualType functionType(TY_FUNCTION);
778
1/2
✓ Branch 106 → 107 taken 10 times.
✗ Branch 106 → 263 not taken.
10 functionType.setQualifiers(TypeQualifiers::of(TY_FUNCTION));
779
1/2
✓ Branch 108 → 109 taken 10 times.
✗ Branch 108 → 263 not taken.
10 functionType.makePublic();
780
1/2
✓ Branch 111 → 112 taken 10 times.
✗ Branch 111 → 235 not taken.
20 SymbolTableEntry entry(MAIN_FUNCTION_NAME, functionType, rootScope, nullptr, 0, false);
781
782 // Prepare test main function
783
4/8
✓ Branch 117 → 118 taken 10 times.
✗ Branch 117 → 246 not taken.
✓ Branch 118 → 119 taken 10 times.
✗ Branch 118 → 245 not taken.
✓ Branch 121 → 122 taken 10 times.
✗ Branch 121 → 241 not taken.
✓ Branch 122 → 123 taken 10 times.
✗ Branch 122 → 239 not taken.
30 Function testMain(MAIN_FUNCTION_NAME, &entry, QualType(TY_DYN), QualType(TY_INT), {}, {}, nullptr);
784 10 testMain.used = true; // Mark as used to prevent removal
785 10 testMain.implicitDefault = true;
786 10 testMain.mangleFunctionName = false;
787
788 // Prepare scope
789
2/4
✓ Branch 127 → 128 taken 10 times.
✗ Branch 127 → 255 not taken.
✓ Branch 128 → 129 taken 10 times.
✗ Branch 128 → 253 not taken.
10 rootScope->createChildScope(testMain.getScopeName(), ScopeType::FUNC_PROC_BODY, nullptr);
790
791 // Generate
792 const std::function<void()> generateBody = [&] {
793 // Prepare result variable
794 10 std::vector<llvm::Value *> testCaseResults;
795
1/2
✓ Branch 3 → 4 taken 10 times.
✗ Branch 3 → 299 not taken.
10 testCaseResults.reserve(tests.size());
796
797 // Print start message
798 12 const auto accFct = [&](size_t sum, const std::vector<const Function *> *innerVector) { return sum + innerVector->size(); };
799 10 const size_t totalTestCount = std::accumulate(tests.begin(), tests.end(), 0, accFct);
800
5/10
✓ Branch 7 → 8 taken 10 times.
✗ Branch 7 → 219 not taken.
✓ Branch 8 → 9 taken 10 times.
✗ Branch 8 → 217 not taken.
✓ Branch 10 → 11 taken 10 times.
✗ Branch 10 → 217 not taken.
✓ Branch 12 → 13 taken 10 times.
✗ Branch 12 → 216 not taken.
✓ Branch 13 → 14 taken 10 times.
✗ Branch 13 → 216 not taken.
10 builder.CreateCall(printfFct, {allStartMsg, builder.getInt32(totalTestCount), builder.getInt32(tests.size())});
801
802 // Generate a call to each test function
803
2/2
✓ Branch 183 → 16 taken 12 times.
✓ Branch 183 → 184 taken 10 times.
32 for (const std::vector<const Function *> *testSuite : tests) {
804 // Print test suite prologue
805
1/2
✓ Branch 19 → 20 taken 12 times.
✗ Branch 19 → 289 not taken.
12 const std::string fileName = testSuite->front()->bodyScope->sourceFile->fileName;
806
3/6
✓ Branch 21 → 22 taken 12 times.
✗ Branch 21 → 287 not taken.
✓ Branch 24 → 25 taken 12 times.
✗ Branch 24 → 222 not taken.
✓ Branch 25 → 26 taken 12 times.
✗ Branch 25 → 220 not taken.
24 llvm::Constant *fileNameValue = createGlobalStringConst("fileName", fileName, testSuite->front()->getDeclCodeLoc());
807
4/8
✓ Branch 28 → 29 taken 12 times.
✗ Branch 28 → 229 not taken.
✓ Branch 30 → 31 taken 12 times.
✗ Branch 30 → 227 not taken.
✓ Branch 32 → 33 taken 12 times.
✗ Branch 32 → 226 not taken.
✓ Branch 33 → 34 taken 12 times.
✗ Branch 33 → 226 not taken.
12 builder.CreateCall(printfFct, {fileStartMsg, builder.getInt32(testSuite->size()), fileNameValue});
808
809
3/4
✓ Branch 38 → 39 taken 22 times.
✗ Branch 38 → 281 not taken.
✓ Branch 166 → 36 taken 22 times.
✓ Branch 166 → 167 taken 12 times.
68 for (const Function *testFunction : *testSuite) {
810
1/2
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 22 times.
22 assert(testFunction->isNormalFunction());
811
1/2
✗ Branch 53 → 54 not taken.
✓ Branch 53 → 55 taken 22 times.
22 assert(testFunction->paramList.empty());
812
813 // Retrieve attribute list for the test function
814
2/4
✓ Branch 55 → 56 taken 22 times.
✗ Branch 55 → 281 not taken.
✗ Branch 56 → 57 not taken.
✓ Branch 56 → 58 taken 22 times.
22 assert(testFunction->declNode->isFctOrProcDef());
815
1/2
✓ Branch 58 → 59 taken 22 times.
✗ Branch 58 → 60 not taken.
22 const auto fctDefNode = spice_pointer_cast<FctDefBaseNode *>(testFunction->declNode);
816
1/2
✗ Branch 67 → 68 not taken.
✓ Branch 67 → 69 taken 22 times.
22 assert(fctDefNode->attrs != nullptr);
817 22 const AttrLstNode *attrs = fctDefNode->attrs->attrLst;
818
3/6
✓ Branch 71 → 72 taken 22 times.
✗ Branch 71 → 232 not taken.
✓ Branch 72 → 73 taken 22 times.
✗ Branch 72 → 230 not taken.
✗ Branch 73 → 74 not taken.
✓ Branch 73 → 75 taken 22 times.
44 assert(attrs->getAttrValueByName(ATTR_TEST)->boolValue); // The test attribute must be present
819
2/4
✓ Branch 79 → 80 taken 22 times.
✗ Branch 79 → 238 not taken.
✓ Branch 80 → 81 taken 22 times.
✗ Branch 80 → 236 not taken.
44 const CompileTimeValue *testSkipAttr = attrs->getAttrValueByName(ATTR_TEST_SKIP);
820
4/4
✓ Branch 83 → 84 taken 6 times.
✓ Branch 83 → 86 taken 16 times.
✓ Branch 84 → 85 taken 2 times.
✓ Branch 84 → 86 taken 4 times.
22 const bool skipTest = testSkipAttr && testSkipAttr->boolValue;
821
2/4
✓ Branch 89 → 90 taken 22 times.
✗ Branch 89 → 244 not taken.
✓ Branch 90 → 91 taken 22 times.
✗ Branch 90 → 242 not taken.
44 const CompileTimeValue *testNameAttr = attrs->getAttrValueByName(ATTR_TEST_NAME);
822
823 // Prepare test name
824
1/2
✓ Branch 93 → 94 taken 22 times.
✗ Branch 93 → 281 not taken.
22 std::stringstream testName;
825
1/2
✓ Branch 94 → 95 taken 22 times.
✗ Branch 94 → 279 not taken.
22 testName << testFunction->name;
826
2/2
✓ Branch 95 → 96 taken 2 times.
✓ Branch 95 → 100 taken 20 times.
22 if (testNameAttr)
827
4/8
✓ Branch 96 → 97 taken 2 times.
✗ Branch 96 → 279 not taken.
✓ Branch 97 → 98 taken 2 times.
✗ Branch 97 → 279 not taken.
✓ Branch 98 → 99 taken 2 times.
✗ Branch 98 → 279 not taken.
✓ Branch 99 → 100 taken 2 times.
✗ Branch 99 → 279 not taken.
2 testName << " (" << resourceManager.compileTimeStringValues.at(testNameAttr->stringValueOffset) << ")";
828
829 // Print test case run message
830
4/8
✓ Branch 100 → 101 taken 22 times.
✗ Branch 100 → 279 not taken.
✓ Branch 101 → 102 taken 22 times.
✗ Branch 101 → 256 not taken.
✓ Branch 104 → 105 taken 22 times.
✗ Branch 104 → 250 not taken.
✓ Branch 105 → 106 taken 22 times.
✗ Branch 105 → 248 not taken.
66 llvm::Constant *testNameValue = createGlobalStringConst("testName", testName.str(), testFunction->getDeclCodeLoc());
831
5/8
✓ Branch 109 → 110 taken 22 times.
✗ Branch 109 → 260 not taken.
✓ Branch 111 → 112 taken 22 times.
✗ Branch 111 → 257 not taken.
✓ Branch 112 → 113 taken 22 times.
✗ Branch 112 → 257 not taken.
✓ Branch 113 → 114 taken 2 times.
✓ Branch 113 → 119 taken 20 times.
22 builder.CreateCall(printfFct, {runMsg, testNameValue});
832
833
2/2
✓ Branch 113 → 114 taken 2 times.
✓ Branch 113 → 119 taken 20 times.
22 if (skipTest) {
834 // Print test case skip message
835
3/6
✓ Branch 114 → 115 taken 2 times.
✗ Branch 114 → 264 not taken.
✓ Branch 116 → 117 taken 2 times.
✗ Branch 116 → 261 not taken.
✓ Branch 117 → 118 taken 2 times.
✗ Branch 117 → 261 not taken.
2 builder.CreateCall(printfFct, {skippedMsg, testNameValue});
836 2 continue;
837 }
838
839 // Test function is not defined in the current module -> declare it
840
1/2
✓ Branch 119 → 120 taken 20 times.
✗ Branch 119 → 279 not taken.
20 const std::string mangledName = testFunction->getMangledName();
841
3/4
✓ Branch 121 → 122 taken 20 times.
✗ Branch 121 → 265 not taken.
✓ Branch 122 → 123 taken 4 times.
✓ Branch 122 → 135 taken 16 times.
20 if (!module->getFunction(mangledName)) {
842
2/4
✓ Branch 123 → 124 taken 4 times.
✗ Branch 123 → 277 not taken.
✗ Branch 124 → 125 not taken.
✓ Branch 124 → 126 taken 4 times.
4 assert(testFunction->returnType.is(TY_BOOL));
843
1/2
✗ Branch 127 → 128 not taken.
✓ Branch 127 → 129 taken 4 times.
4 assert(testFunction->paramList.empty());
844
2/4
✓ Branch 130 → 131 taken 4 times.
✗ Branch 130 → 266 not taken.
✓ Branch 131 → 132 taken 4 times.
✗ Branch 131 → 266 not taken.
4 llvm::FunctionType *fctType = llvm::FunctionType::get(builder.getInt1Ty(), {}, false);
845
1/2
✓ Branch 133 → 134 taken 4 times.
✗ Branch 133 → 267 not taken.
4 module->getOrInsertFunction(mangledName, fctType);
846 }
847
848 // Call test function
849
1/2
✓ Branch 136 → 137 taken 20 times.
✗ Branch 136 → 268 not taken.
20 llvm::Function *callee = module->getFunction(mangledName);
850
1/2
✗ Branch 137 → 138 not taken.
✓ Branch 137 → 139 taken 20 times.
20 assert(callee != nullptr);
851
4/8
✓ Branch 139 → 140 taken 20 times.
✗ Branch 139 → 271 not taken.
✓ Branch 141 → 142 taken 20 times.
✗ Branch 141 → 269 not taken.
✓ Branch 142 → 143 taken 20 times.
✗ Branch 142 → 269 not taken.
✓ Branch 143 → 144 taken 20 times.
✗ Branch 143 → 277 not taken.
20 llvm::Value *testCaseResult = builder.CreateCall(callee);
852
1/2
✓ Branch 143 → 144 taken 20 times.
✗ Branch 143 → 277 not taken.
20 testCaseResults.push_back(testCaseResult);
853
854 // Print test case result message
855
3/6
✓ Branch 144 → 145 taken 20 times.
✗ Branch 144 → 272 not taken.
✓ Branch 145 → 146 taken 20 times.
✗ Branch 145 → 272 not taken.
✓ Branch 146 → 147 taken 20 times.
✗ Branch 146 → 276 not taken.
20 llvm::Value *message = builder.CreateSelect(testCaseResult, successMsg, errorMsg);
856
3/6
✓ Branch 146 → 147 taken 20 times.
✗ Branch 146 → 276 not taken.
✓ Branch 148 → 149 taken 20 times.
✗ Branch 148 → 273 not taken.
✓ Branch 149 → 150 taken 20 times.
✗ Branch 149 → 273 not taken.
20 builder.CreateCall(printfFct, {message, testNameValue});
857
2/2
✓ Branch 153 → 154 taken 20 times.
✓ Branch 153 → 156 taken 2 times.
22 }
858
859 // Print test suite epilogue
860
4/8
✓ Branch 167 → 168 taken 12 times.
✗ Branch 167 → 286 not taken.
✓ Branch 169 → 170 taken 12 times.
✗ Branch 169 → 284 not taken.
✓ Branch 171 → 172 taken 12 times.
✗ Branch 171 → 283 not taken.
✓ Branch 172 → 173 taken 12 times.
✗ Branch 172 → 283 not taken.
12 builder.CreateCall(printfFct, {fileEndMsg, builder.getInt32(testSuite->size()), fileNameValue});
861 12 }
862
863 // Print end message
864
6/12
✓ Branch 184 → 185 taken 10 times.
✗ Branch 184 → 294 not taken.
✓ Branch 185 → 186 taken 10 times.
✗ Branch 185 → 292 not taken.
✓ Branch 187 → 188 taken 10 times.
✗ Branch 187 → 292 not taken.
✓ Branch 189 → 190 taken 10 times.
✗ Branch 189 → 291 not taken.
✓ Branch 190 → 191 taken 10 times.
✗ Branch 190 → 291 not taken.
✓ Branch 191 → 192 taken 10 times.
✗ Branch 191 → 299 not taken.
10 builder.CreateCall(printfFct, {allEndMsg, builder.getInt32(totalTestCount), builder.getInt32(tests.size())});
865
866 // Compute overall result
867
1/2
✓ Branch 191 → 192 taken 10 times.
✗ Branch 191 → 299 not taken.
10 llvm::Value *overallResult = builder.getTrue();
868
2/2
✓ Branch 207 → 194 taken 20 times.
✓ Branch 207 → 208 taken 10 times.
40 for (llvm::Value *testCaseResult : testCaseResults)
869
2/4
✓ Branch 196 → 197 taken 20 times.
✗ Branch 196 → 295 not taken.
✓ Branch 197 → 198 taken 20 times.
✗ Branch 197 → 295 not taken.
20 overallResult = builder.CreateAnd(overallResult, testCaseResult);
870
871 // Return code must be 0 for success and 1 for failure, so we need to invert the result and zero extend to 32 bit
872
3/6
✓ Branch 208 → 209 taken 10 times.
✗ Branch 208 → 297 not taken.
✓ Branch 209 → 210 taken 10 times.
✗ Branch 209 → 297 not taken.
✓ Branch 210 → 211 taken 10 times.
✗ Branch 210 → 298 not taken.
10 llvm::Value *overallResultNegated = builder.CreateNot(overallResult);
873
4/8
✓ Branch 210 → 211 taken 10 times.
✗ Branch 210 → 298 not taken.
✓ Branch 211 → 212 taken 10 times.
✗ Branch 211 → 298 not taken.
✓ Branch 212 → 213 taken 10 times.
✗ Branch 212 → 298 not taken.
✓ Branch 213 → 214 taken 10 times.
✗ Branch 213 → 299 not taken.
10 llvm::Value *exitCode = builder.CreateZExt(overallResultNegated, builder.getInt32Ty());
874
1/2
✓ Branch 213 → 214 taken 10 times.
✗ Branch 213 → 299 not taken.
10 builder.CreateRet(exitCode);
875
1/2
✓ Branch 130 → 131 taken 10 times.
✗ Branch 130 → 256 not taken.
20 };
876
1/2
✓ Branch 131 → 132 taken 10 times.
✗ Branch 131 → 257 not taken.
10 generateImplicitFunction(generateBody, &testMain);
877 10 }
878
879 } // namespace spice::compiler
880