GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 90.8% 466 / 0 / 513
Functions: 96.3% 26 / 0 / 27
Branches: 49.7% 586 / 0 / 1180

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