GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 91.4% 458 / 0 / 501
Functions: 96.3% 26 / 0 / 27
Branches: 50.0% 576 / 0 / 1152

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