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