GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 90.8% 465 / 0 / 512
Functions: 96.3% 26 / 0 / 27
Branches: 49.7% 587 / 0 / 1182

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