src/irgenerator/DebugInfoGenerator.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "DebugInfoGenerator.h" | ||
| 4 | |||
| 5 | #include <driver/Driver.h> | ||
| 6 | #include <irgenerator/IRGenerator.h> | ||
| 7 | #include <irgenerator/NameMangling.h> | ||
| 8 | #include <model/Function.h> | ||
| 9 | #include <model/Struct.h> | ||
| 10 | #include <util/CustomHashFunctions.h> | ||
| 11 | #include <util/FileUtil.h> | ||
| 12 | |||
| 13 | #include <llvm/BinaryFormat/Dwarf.h> | ||
| 14 | #include <llvm/IR/Module.h> | ||
| 15 | |||
| 16 | namespace spice::compiler { | ||
| 17 | |||
| 18 |
1/2✓ Branch 3 → 4 taken 2562 times.
✗ Branch 3 → 6 not taken.
|
2562 | DebugInfoGenerator::DebugInfoGenerator(IRGenerator *irGenerator) : irGenerator(irGenerator) {} |
| 19 | |||
| 20 | 59 | void DebugInfoGenerator::initialize(const std::string &sourceFileName, std::filesystem::path sourceFileDir) { | |
| 21 | 59 | llvm::Module *module = irGenerator->module; | |
| 22 | 59 | llvm::LLVMContext &context = irGenerator->context; | |
| 23 | |||
| 24 | // Create DIBuilder | ||
| 25 |
1/2✓ Branch 2 → 3 taken 59 times.
✗ Branch 2 → 132 not taken.
|
59 | diBuilder = std::make_unique<llvm::DIBuilder>(*module); |
| 26 | |||
| 27 | // Create compilation unit | ||
| 28 |
3/6✓ Branch 5 → 6 taken 59 times.
✗ Branch 5 → 137 not taken.
✓ Branch 6 → 7 taken 59 times.
✗ Branch 6 → 135 not taken.
✓ Branch 7 → 8 taken 59 times.
✗ Branch 7 → 133 not taken.
|
59 | std::filesystem::path absolutePath = absolute(sourceFileDir / sourceFileName); |
| 29 | 59 | absolutePath.make_preferred(); | |
| 30 | 59 | sourceFileDir.make_preferred(); | |
| 31 |
3/6✓ Branch 15 → 16 taken 59 times.
✗ Branch 15 → 145 not taken.
✓ Branch 17 → 18 taken 59 times.
✗ Branch 17 → 141 not taken.
✓ Branch 19 → 20 taken 59 times.
✗ Branch 19 → 139 not taken.
|
118 | llvm::DIFile *cuDiFile = diBuilder->createFile(absolutePath.string(), sourceFileDir.string()); |
| 32 |
1/2✓ Branch 29 → 30 taken 59 times.
✗ Branch 29 → 149 not taken.
|
118 | compileUnit = diBuilder->createCompileUnit( |
| 33 |
2/4✓ Branch 25 → 26 taken 59 times.
✗ Branch 25 → 152 not taken.
✓ Branch 26 → 27 taken 59 times.
✗ Branch 26 → 151 not taken.
|
59 | llvm::dwarf::DW_LANG_C_plus_plus_14, cuDiFile, PRODUCER_STRING, irGenerator->cliOptions.optLevel > OptLevel::O0, "", 0, "", |
| 34 | llvm::DICompileUnit::FullDebug, 0, false, false, llvm::DICompileUnit::DebugNameTableKind::None); | ||
| 35 | |||
| 36 |
2/4✓ Branch 30 → 31 taken 59 times.
✗ Branch 30 → 155 not taken.
✓ Branch 31 → 32 taken 59 times.
✗ Branch 31 → 155 not taken.
|
59 | module->addModuleFlag(llvm::Module::Max, "Dwarf Version", 5); |
| 37 |
2/4✓ Branch 32 → 33 taken 59 times.
✗ Branch 32 → 156 not taken.
✓ Branch 33 → 34 taken 59 times.
✗ Branch 33 → 156 not taken.
|
59 | module->addModuleFlag(llvm::Module::Warning, "Debug Info Version", llvm::DEBUG_METADATA_VERSION); |
| 38 | |||
| 39 | // Create another DIFile as scope for subprograms | ||
| 40 |
2/4✓ Branch 37 → 38 taken 59 times.
✗ Branch 37 → 160 not taken.
✓ Branch 40 → 41 taken 59 times.
✗ Branch 40 → 157 not taken.
|
118 | diFile = diBuilder->createFile(sourceFileName, sourceFileDir.string()); |
| 41 | |||
| 42 |
1/2✓ Branch 43 → 44 taken 59 times.
✗ Branch 43 → 202 not taken.
|
59 | pointerWidth = irGenerator->module->getDataLayout().getPointerSizeInBits(); |
| 43 | |||
| 44 | // Initialize primitive debug types | ||
| 45 |
2/4✓ Branch 45 → 46 taken 59 times.
✗ Branch 45 → 164 not taken.
✓ Branch 46 → 47 taken 59 times.
✗ Branch 46 → 164 not taken.
|
59 | doubleTy = diBuilder->createBasicType("double", 64, llvm::dwarf::DW_ATE_float); |
| 46 |
2/4✓ Branch 48 → 49 taken 59 times.
✗ Branch 48 → 165 not taken.
✓ Branch 49 → 50 taken 59 times.
✗ Branch 49 → 165 not taken.
|
59 | intTy = diBuilder->createBasicType("int", 32, llvm::dwarf::DW_ATE_signed); |
| 47 |
2/4✓ Branch 51 → 52 taken 59 times.
✗ Branch 51 → 166 not taken.
✓ Branch 52 → 53 taken 59 times.
✗ Branch 52 → 166 not taken.
|
59 | uIntTy = diBuilder->createBasicType("unsigned int", 32, llvm::dwarf::DW_ATE_unsigned); |
| 48 |
2/4✓ Branch 54 → 55 taken 59 times.
✗ Branch 54 → 167 not taken.
✓ Branch 55 → 56 taken 59 times.
✗ Branch 55 → 167 not taken.
|
59 | shortTy = diBuilder->createBasicType("short", 16, llvm::dwarf::DW_ATE_signed); |
| 49 |
2/4✓ Branch 57 → 58 taken 59 times.
✗ Branch 57 → 168 not taken.
✓ Branch 58 → 59 taken 59 times.
✗ Branch 58 → 168 not taken.
|
59 | uShortTy = diBuilder->createBasicType("unsigned short", 16, llvm::dwarf::DW_ATE_unsigned); |
| 50 |
2/4✓ Branch 60 → 61 taken 59 times.
✗ Branch 60 → 169 not taken.
✓ Branch 61 → 62 taken 59 times.
✗ Branch 61 → 169 not taken.
|
59 | longTy = diBuilder->createBasicType("long", 64, llvm::dwarf::DW_ATE_signed); |
| 51 |
2/4✓ Branch 63 → 64 taken 59 times.
✗ Branch 63 → 170 not taken.
✓ Branch 64 → 65 taken 59 times.
✗ Branch 64 → 170 not taken.
|
59 | uLongTy = diBuilder->createBasicType("unsigned long", 64, llvm::dwarf::DW_ATE_unsigned); |
| 52 |
2/4✓ Branch 66 → 67 taken 59 times.
✗ Branch 66 → 171 not taken.
✓ Branch 67 → 68 taken 59 times.
✗ Branch 67 → 171 not taken.
|
59 | byteTy = diBuilder->createBasicType("byte", 8, llvm::dwarf::DW_ATE_unsigned); |
| 53 |
2/4✓ Branch 69 → 70 taken 59 times.
✗ Branch 69 → 172 not taken.
✓ Branch 70 → 71 taken 59 times.
✗ Branch 70 → 172 not taken.
|
59 | charTy = diBuilder->createBasicType("char", 8, llvm::dwarf::DW_ATE_unsigned_char); |
| 54 |
1/2✓ Branch 75 → 76 taken 59 times.
✗ Branch 75 → 173 not taken.
|
118 | stringTy = diBuilder->createPointerType(charTy, pointerWidth); |
| 55 |
2/4✓ Branch 77 → 78 taken 59 times.
✗ Branch 77 → 176 not taken.
✓ Branch 78 → 79 taken 59 times.
✗ Branch 78 → 176 not taken.
|
59 | boolTy = diBuilder->createBasicType("bool", 8, llvm::dwarf::DW_ATE_boolean); |
| 56 |
2/4✓ Branch 80 → 81 taken 59 times.
✗ Branch 80 → 177 not taken.
✓ Branch 81 → 82 taken 59 times.
✗ Branch 81 → 177 not taken.
|
59 | voidTy = diBuilder->createBasicType("void", 0, llvm::dwarf::DW_ATE_unsigned); |
| 57 | |||
| 58 | // Initialize lambda fat ptr type | ||
| 59 |
1/2✓ Branch 82 → 83 taken 59 times.
✗ Branch 82 → 202 not taken.
|
59 | llvm::PointerType *ptrTy = irGenerator->builder.getPtrTy(); |
| 60 |
1/2✓ Branch 83 → 84 taken 59 times.
✗ Branch 83 → 202 not taken.
|
59 | llvm::IntegerType *int64Ty = irGenerator->builder.getInt64Ty(); |
| 61 | 59 | const llvm::DataLayout &dataLayout = module->getDataLayout(); | |
| 62 |
1/2✓ Branch 85 → 86 taken 59 times.
✗ Branch 85 → 202 not taken.
|
59 | const llvm::StructLayout *structLayout = dataLayout.getStructLayout(irGenerator->llvmTypes.lambdaFatPtrType); |
| 63 |
1/2✓ Branch 86 → 87 taken 59 times.
✗ Branch 86 → 178 not taken.
|
59 | const uint32_t alignInBits = dataLayout.getABITypeAlign(irGenerator->llvmTypes.lambdaFatPtrType).value(); |
| 64 |
1/2✓ Branch 88 → 89 taken 59 times.
✗ Branch 88 → 179 not taken.
|
59 | const uint32_t ptrAlignInBits = dataLayout.getABITypeAlign(ptrTy).value(); |
| 65 |
2/4✓ Branch 90 → 91 taken 59 times.
✗ Branch 90 → 180 not taken.
✓ Branch 91 → 92 taken 59 times.
✗ Branch 91 → 180 not taken.
|
59 | const uint32_t int64Width = dataLayout.getTypeSizeInBits(int64Ty); |
| 66 |
1/2✓ Branch 92 → 93 taken 59 times.
✗ Branch 92 → 181 not taken.
|
59 | const uint32_t int64AlignInBits = dataLayout.getABITypeAlign(int64Ty).value(); |
| 67 |
2/4✓ Branch 94 → 95 taken 59 times.
✗ Branch 94 → 182 not taken.
✓ Branch 95 → 96 taken 59 times.
✗ Branch 95 → 182 not taken.
|
59 | const uint64_t fctPtrOffset = structLayout->getElementOffsetInBits(0); |
| 68 |
2/4✓ Branch 96 → 97 taken 59 times.
✗ Branch 96 → 183 not taken.
✓ Branch 97 → 98 taken 59 times.
✗ Branch 97 → 183 not taken.
|
59 | const uint64_t capturesOffset = structLayout->getElementOffsetInBits(1); |
| 69 |
2/4✓ Branch 98 → 99 taken 59 times.
✗ Branch 98 → 184 not taken.
✓ Branch 99 → 100 taken 59 times.
✗ Branch 99 → 184 not taken.
|
59 | const uint64_t captureSizeOffset = structLayout->getElementOffsetInBits(2); |
| 70 | |||
| 71 |
1/2✓ Branch 104 → 105 taken 59 times.
✗ Branch 104 → 185 not taken.
|
118 | llvm::DIType *voidPtrDIType = diBuilder->createPointerType(voidTy, pointerWidth, ptrAlignInBits); |
| 72 |
5/10✓ Branch 109 → 110 taken 59 times.
✗ Branch 109 → 190 not taken.
✓ Branch 110 → 111 taken 59 times.
✗ Branch 110 → 189 not taken.
✓ Branch 111 → 112 taken 59 times.
✗ Branch 111 → 189 not taken.
✓ Branch 112 → 113 taken 59 times.
✗ Branch 112 → 188 not taken.
✓ Branch 113 → 114 taken 59 times.
✗ Branch 113 → 188 not taken.
|
118 | fatPtrTy = diBuilder->createStructType(diFile, "_lambda", diFile, 0, structLayout->getSizeInBits(), alignInBits, |
| 73 | llvm::DINode::FlagTypePassByValue | llvm::DINode::FlagNonTrivial, nullptr, {}, 0, | ||
| 74 |
1/2✓ Branch 107 → 108 taken 59 times.
✗ Branch 107 → 191 not taken.
|
59 | nullptr, "_lambda"); |
| 75 |
2/4✓ Branch 116 → 117 taken 59 times.
✗ Branch 116 → 193 not taken.
✓ Branch 117 → 118 taken 59 times.
✗ Branch 117 → 193 not taken.
|
59 | const auto firstType = diBuilder->createMemberType(fatPtrTy, "fct", diFile, 0, pointerWidth, ptrAlignInBits, fctPtrOffset, |
| 76 | llvm::DINode::FlagZero, voidPtrDIType); | ||
| 77 |
2/4✓ Branch 120 → 121 taken 59 times.
✗ Branch 120 → 195 not taken.
✓ Branch 121 → 122 taken 59 times.
✗ Branch 121 → 195 not taken.
|
59 | const auto secondType = diBuilder->createMemberType(fatPtrTy, "captures", diFile, 0, pointerWidth, ptrAlignInBits, |
| 78 | capturesOffset, llvm::DINode::FlagZero, voidPtrDIType); | ||
| 79 |
2/4✓ Branch 124 → 125 taken 59 times.
✗ Branch 124 → 197 not taken.
✓ Branch 125 → 126 taken 59 times.
✗ Branch 125 → 197 not taken.
|
59 | const auto thirdType = diBuilder->createMemberType(fatPtrTy, "captureSize", diFile, 0, int64Width, int64AlignInBits, |
| 80 | captureSizeOffset, llvm::DINode::FlagZero, uLongTy); | ||
| 81 |
2/4✓ Branch 127 → 128 taken 59 times.
✗ Branch 127 → 199 not taken.
✓ Branch 129 → 130 taken 59 times.
✗ Branch 129 → 199 not taken.
|
59 | fatPtrTy->replaceElements(llvm::MDTuple::get(context, {firstType, secondType, thirdType})); |
| 82 | 59 | } | |
| 83 | |||
| 84 | 40974 | void DebugInfoGenerator::generateFunctionDebugInfo(llvm::Function *llvmFunction, const Function *spiceFunc, bool isLambda) { | |
| 85 |
2/2✓ Branch 2 → 3 taken 40091 times.
✓ Branch 2 → 4 taken 883 times.
|
40974 | if (!irGenerator->cliOptions.instrumentation.generateDebugInfo) |
| 86 | 40091 | return; | |
| 87 | |||
| 88 | 883 | const ASTNode *node = spiceFunc->declNode; | |
| 89 |
1/2✓ Branch 4 → 5 taken 883 times.
✗ Branch 4 → 125 not taken.
|
883 | const uint32_t lineNo = spiceFunc->getDeclCodeLoc().line; |
| 90 | |||
| 91 | // Prepare flags | ||
| 92 | 883 | llvm::DIScope *scope = diFile; | |
| 93 | 883 | llvm::DINode::DIFlags flags = llvm::DINode::FlagPrototyped; | |
| 94 |
8/10✓ Branch 5 → 6 taken 876 times.
✓ Branch 5 → 10 taken 7 times.
✓ Branch 6 → 7 taken 876 times.
✗ Branch 6 → 125 not taken.
✓ Branch 7 → 8 taken 876 times.
✗ Branch 7 → 125 not taken.
✓ Branch 8 → 9 taken 773 times.
✓ Branch 8 → 10 taken 103 times.
✓ Branch 11 → 12 taken 773 times.
✓ Branch 11 → 13 taken 110 times.
|
883 | if (spiceFunc->entry && spiceFunc->entry->getQualType().isPublic()) |
| 95 |
1/2✓ Branch 12 → 13 taken 773 times.
✗ Branch 12 → 125 not taken.
|
773 | flags |= llvm::DINode::FlagPublic; |
| 96 | |||
| 97 | // Prepare spFlags | ||
| 98 | 883 | llvm::DISubprogram::DISPFlags spFlags = llvm::DISubprogram::SPFlagDefinition; | |
| 99 |
1/2✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 883 times.
|
883 | if (isLambda) |
| 100 | ✗ | spFlags |= llvm::DISubprogram::SPFlagLocalToUnit; | |
| 101 |
2/2✓ Branch 15 → 16 taken 106 times.
✓ Branch 15 → 20 taken 777 times.
|
883 | if (spiceFunc->isVirtual) { |
| 102 |
2/4✓ Branch 16 → 17 taken 106 times.
✗ Branch 16 → 125 not taken.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 106 times.
|
106 | if (spiceFunc->thisType.is(TY_INTERFACE)) |
| 103 | ✗ | spFlags |= llvm::DISubprogram::SPFlagPureVirtual; | |
| 104 | else | ||
| 105 |
1/2✓ Branch 19 → 20 taken 106 times.
✗ Branch 19 → 125 not taken.
|
106 | spFlags |= llvm::DISubprogram::SPFlagVirtual; |
| 106 | } | ||
| 107 | |||
| 108 | // Collect arguments | ||
| 109 |
1/2✓ Branch 20 → 21 taken 883 times.
✗ Branch 20 → 123 not taken.
|
883 | std::vector<llvm::Metadata *> argTypes; |
| 110 |
2/2✓ Branch 23 → 24 taken 398 times.
✓ Branch 23 → 26 taken 485 times.
|
883 | if (spiceFunc->isProcedure()) |
| 111 |
1/2✓ Branch 24 → 25 taken 398 times.
✗ Branch 24 → 97 not taken.
|
398 | argTypes.push_back(voidTy); |
| 112 | else | ||
| 113 |
2/4✓ Branch 26 → 27 taken 485 times.
✗ Branch 26 → 98 not taken.
✓ Branch 27 → 28 taken 485 times.
✗ Branch 27 → 98 not taken.
|
485 | argTypes.push_back(getDITypeForQualType(node, spiceFunc->returnType)); // Add result type |
| 114 |
2/2✓ Branch 32 → 33 taken 627 times.
✓ Branch 32 → 36 taken 256 times.
|
883 | if (spiceFunc->isMethod()) |
| 115 |
2/4✓ Branch 33 → 34 taken 627 times.
✗ Branch 33 → 99 not taken.
✓ Branch 34 → 35 taken 627 times.
✗ Branch 34 → 99 not taken.
|
627 | argTypes.push_back(getDITypeForQualType(node, spiceFunc->thisType)); // Add this type |
| 116 |
1/2✗ Branch 36 → 37 not taken.
✓ Branch 36 → 45 taken 883 times.
|
883 | if (isLambda) { |
| 117 | ✗ | llvm::DICompositeType *captureStructType = generateCaptureStructDebugInfo(spiceFunc); | |
| 118 | ✗ | scope = captureStructType; | |
| 119 | ✗ | llvm::DIType *captureStructPtr = diBuilder->createPointerType(captureStructType, pointerWidth); | |
| 120 | ✗ | argTypes.push_back(captureStructPtr); // Add this type | |
| 121 | } | ||
| 122 |
3/4✓ Branch 45 → 46 taken 883 times.
✗ Branch 45 → 107 not taken.
✓ Branch 61 → 48 taken 745 times.
✓ Branch 61 → 62 taken 883 times.
|
2511 | for (const QualType &argType : spiceFunc->getParamTypes()) // Add arg types |
| 123 |
2/4✓ Branch 50 → 51 taken 745 times.
✗ Branch 50 → 104 not taken.
✓ Branch 51 → 52 taken 745 times.
✗ Branch 51 → 104 not taken.
|
1628 | argTypes.push_back(getDITypeForQualType(node, argType)); |
| 124 | |||
| 125 | // Create function type | ||
| 126 |
2/4✓ Branch 66 → 67 taken 883 times.
✗ Branch 66 → 108 not taken.
✓ Branch 67 → 68 taken 883 times.
✗ Branch 67 → 108 not taken.
|
883 | llvm::DISubroutineType *functionTy = diBuilder->createSubroutineType(diBuilder->getOrCreateTypeArray(argTypes)); |
| 127 | |||
| 128 |
1/2✓ Branch 68 → 69 taken 883 times.
✗ Branch 68 → 123 not taken.
|
883 | const std::string mangledName = spiceFunc->getMangledName(); |
| 129 | llvm::DISubprogram *subprogram; | ||
| 130 |
1/2✓ Branch 69 → 70 taken 883 times.
✗ Branch 69 → 121 not taken.
|
883 | const std::string &name = spiceFunc->name; |
| 131 |
2/2✓ Branch 72 → 73 taken 627 times.
✓ Branch 72 → 80 taken 256 times.
|
883 | if (spiceFunc->isMethod()) { |
| 132 |
1/2✓ Branch 78 → 79 taken 627 times.
✗ Branch 78 → 109 not taken.
|
627 | subprogram = diBuilder->createMethod(scope, name, mangledName, diFile, lineNo, functionTy, 0, 0, nullptr, flags, spFlags); |
| 133 | } else { | ||
| 134 |
1/2✓ Branch 87 → 88 taken 256 times.
✗ Branch 87 → 113 not taken.
|
512 | subprogram = diBuilder->createFunction(scope, name, mangledName, diFile, lineNo, functionTy, lineNo, flags, spFlags); |
| 135 | } | ||
| 136 |
1/2✓ Branch 90 → 91 taken 883 times.
✗ Branch 90 → 119 not taken.
|
883 | subprogram->replaceRetainedNodes({}); |
| 137 | |||
| 138 | // Add debug info to LLVM function | ||
| 139 |
1/2✓ Branch 91 → 92 taken 883 times.
✗ Branch 91 → 121 not taken.
|
883 | llvmFunction->setSubprogram(subprogram); |
| 140 | // Add scope to lexicalBlocks | ||
| 141 |
1/2✓ Branch 92 → 93 taken 883 times.
✗ Branch 92 → 120 not taken.
|
883 | lexicalBlocks.push(subprogram); |
| 142 | 883 | } | |
| 143 | |||
| 144 | 41417 | void DebugInfoGenerator::concludeFunctionDebugInfo() { | |
| 145 |
2/2✓ Branch 2 → 3 taken 40534 times.
✓ Branch 2 → 4 taken 883 times.
|
41417 | if (!irGenerator->cliOptions.instrumentation.generateDebugInfo) |
| 146 | 40534 | return; | |
| 147 | |||
| 148 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 883 times.
|
883 | assert(!lexicalBlocks.empty()); |
| 149 | 883 | lexicalBlocks.pop(); | |
| 150 | } | ||
| 151 | |||
| 152 | 37781 | void DebugInfoGenerator::pushLexicalBlock(const ASTNode *node) { | |
| 153 |
2/2✓ Branch 2 → 3 taken 36885 times.
✓ Branch 2 → 4 taken 896 times.
|
37781 | if (!irGenerator->cliOptions.instrumentation.generateDebugInfo) |
| 154 | 36885 | return; | |
| 155 | |||
| 156 | 896 | const uint32_t line = node->codeLoc.line; | |
| 157 | 896 | const uint32_t col = node->codeLoc.col; | |
| 158 | 896 | llvm::DILexicalBlock *lexicalBlock = diBuilder->createLexicalBlock(lexicalBlocks.top(), diFile, line, col); | |
| 159 |
1/2✓ Branch 7 → 8 taken 896 times.
✗ Branch 7 → 10 not taken.
|
896 | lexicalBlocks.push(lexicalBlock); |
| 160 | } | ||
| 161 | |||
| 162 | 37781 | void DebugInfoGenerator::popLexicalBlock() { | |
| 163 |
2/2✓ Branch 2 → 3 taken 36885 times.
✓ Branch 2 → 4 taken 896 times.
|
37781 | if (!irGenerator->cliOptions.instrumentation.generateDebugInfo) |
| 164 | 36885 | return; | |
| 165 | |||
| 166 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 896 times.
|
896 | assert(!lexicalBlocks.empty()); |
| 167 | 896 | lexicalBlocks.pop(); | |
| 168 | } | ||
| 169 | |||
| 170 | ✗ | llvm::DICompositeType *DebugInfoGenerator::generateCaptureStructDebugInfo(const Function *spiceFunc) { | |
| 171 | ✗ | const CaptureMap &captures = spiceFunc->bodyScope->symbolTable.captures; | |
| 172 | ✗ | const ASTNode *node = spiceFunc->declNode; | |
| 173 | ✗ | const uint32_t lineNo = node->codeLoc.line; | |
| 174 | |||
| 175 | // Get LLVM type for struct | ||
| 176 | ✗ | std::vector<llvm::Type *> fieldTypes; | |
| 177 | ✗ | std::vector<const SymbolTableEntry *> fieldEntries; | |
| 178 | ✗ | QualTypeList fieldSymbolTypes; | |
| 179 | ✗ | for (const auto &capture : captures | std::views::values) { | |
| 180 | ✗ | QualType captureType = capture.capturedSymbol->getQualType(); | |
| 181 | |||
| 182 | // Capture by reference | ||
| 183 | ✗ | if (capture.getMode() == BY_REFERENCE) | |
| 184 | ✗ | captureType = captureType.toRef(node); | |
| 185 | |||
| 186 | ✗ | fieldEntries.push_back(capture.capturedSymbol); | |
| 187 | ✗ | fieldSymbolTypes.push_back(captureType); | |
| 188 | ✗ | fieldTypes.push_back(captureType.toLLVMType(irGenerator->sourceFile)); | |
| 189 | } | ||
| 190 | ✗ | llvm::StructType *structType = llvm::StructType::get(irGenerator->context, fieldTypes); | |
| 191 | ✗ | const llvm::StructLayout *structLayout = irGenerator->module->getDataLayout().getStructLayout(structType); | |
| 192 | ✗ | const size_t alignInBits = irGenerator->module->getDataLayout().getABITypeAlign(structType).value(); | |
| 193 | |||
| 194 | ✗ | llvm::DIScope *scope = lexicalBlocks.top(); | |
| 195 | llvm::DICompositeType *structDiType = | ||
| 196 | ✗ | diBuilder->createClassType(scope, "", diFile, lineNo, structLayout->getSizeInBits(), alignInBits, 0, | |
| 197 | llvm::DINode::FlagTypePassByValue | llvm::DINode::FlagNonTrivial, nullptr, {}); | ||
| 198 | |||
| 199 | ✗ | std::vector<llvm::Metadata *> fieldDITypes; | |
| 200 | ✗ | for (size_t i = 0; i < fieldEntries.size(); i++) { | |
| 201 | ✗ | llvm::DIType *fieldDiType = getDITypeForQualType(node, fieldSymbolTypes.at(i)); | |
| 202 | ✗ | const std::string &fieldName = fieldEntries.at(i)->name; | |
| 203 | ✗ | const size_t offsetInBits = structLayout->getElementOffsetInBits(i); | |
| 204 | ✗ | const size_t fieldSize = fieldDiType->getSizeInBits(); | |
| 205 | ✗ | const size_t fieldAlign = fieldDiType->getAlignInBits(); | |
| 206 | ✗ | llvm::DIDerivedType *fieldDiDerivedType = diBuilder->createMemberType( | |
| 207 | ✗ | structDiType, fieldName, diFile, lineNo, fieldSize, fieldAlign, offsetInBits, llvm::DINode::FlagZero, fieldDiType); | |
| 208 | ✗ | fieldDITypes.push_back(fieldDiDerivedType); | |
| 209 | } | ||
| 210 | ✗ | structDiType->replaceElements(llvm::MDTuple::get(irGenerator->context, fieldDITypes)); | |
| 211 | |||
| 212 | ✗ | return structDiType; | |
| 213 | ✗ | } | |
| 214 | |||
| 215 | 2711 | void DebugInfoGenerator::generateGlobalVarDebugInfo(llvm::GlobalVariable *global, const SymbolTableEntry *globalEntry) { | |
| 216 |
2/2✓ Branch 2 → 3 taken 2684 times.
✓ Branch 2 → 4 taken 27 times.
|
2711 | if (!irGenerator->cliOptions.instrumentation.generateDebugInfo) |
| 217 | 2684 | return; | |
| 218 | |||
| 219 |
1/2✓ Branch 4 → 5 taken 27 times.
✗ Branch 4 → 17 not taken.
|
27 | const uint32_t lineNo = globalEntry->getDeclCodeLoc().line; |
| 220 |
1/2✓ Branch 5 → 6 taken 27 times.
✗ Branch 5 → 17 not taken.
|
27 | const llvm::StringRef name = global->getName(); |
| 221 |
2/4✓ Branch 6 → 7 taken 27 times.
✗ Branch 6 → 17 not taken.
✓ Branch 7 → 8 taken 27 times.
✗ Branch 7 → 17 not taken.
|
27 | llvm::DIType *type = getDITypeForQualType(globalEntry->declNode, globalEntry->getQualType()); |
| 222 |
2/4✓ Branch 8 → 9 taken 27 times.
✗ Branch 8 → 17 not taken.
✓ Branch 9 → 10 taken 27 times.
✗ Branch 9 → 17 not taken.
|
27 | const bool isLocal = globalEntry->getQualType().isPublic(); |
| 223 | |||
| 224 |
2/4✓ Branch 12 → 13 taken 27 times.
✗ Branch 12 → 16 not taken.
✓ Branch 13 → 14 taken 27 times.
✗ Branch 13 → 16 not taken.
|
27 | global->addDebugInfo(diBuilder->createGlobalVariableExpression(compileUnit, name, name, diFile, lineNo, type, isLocal)); |
| 225 | } | ||
| 226 | |||
| 227 | 135 | void DebugInfoGenerator::generateGlobalStringDebugInfo(llvm::GlobalVariable *global, const std::string &name, size_t length, | |
| 228 | const CodeLoc &codeLoc) const { | ||
| 229 | 135 | const uint32_t lineNo = codeLoc.line; | |
| 230 | 135 | const size_t sizeInBits = (length + 1) * 8; // +1 because of null-terminator | |
| 231 | |||
| 232 |
1/2✓ Branch 4 → 5 taken 135 times.
✗ Branch 4 → 12 not taken.
|
135 | llvm::DIStringType *stringType = diBuilder->createStringType(name, sizeInBits); |
| 233 |
2/4✓ Branch 9 → 10 taken 135 times.
✗ Branch 9 → 13 not taken.
✓ Branch 10 → 11 taken 135 times.
✗ Branch 10 → 13 not taken.
|
135 | global->addDebugInfo(diBuilder->createGlobalVariableExpression(compileUnit, name, name, diFile, lineNo, stringType, true)); |
| 234 | 135 | } | |
| 235 | |||
| 236 | 126762 | void DebugInfoGenerator::generateLocalVarDebugInfo(const std::string &varName, llvm::Value *address, size_t argNumber) { | |
| 237 |
2/2✓ Branch 2 → 3 taken 124267 times.
✓ Branch 2 → 4 taken 2495 times.
|
126762 | if (!irGenerator->cliOptions.instrumentation.generateDebugInfo) |
| 238 | 124267 | return; | |
| 239 | |||
| 240 | // Get symbol table entry | ||
| 241 | 2495 | const SymbolTableEntry *variableEntry = irGenerator->currentScope->lookupStrict(varName); | |
| 242 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 2495 times.
|
2495 | assert(variableEntry != nullptr); |
| 243 | // Build debug info | ||
| 244 | 2495 | llvm::DIScope *scope = lexicalBlocks.top(); | |
| 245 | 2495 | llvm::DIType *diType = getDITypeForQualType(variableEntry->declNode, variableEntry->getQualType()); | |
| 246 | 2495 | const uint32_t lineNo = variableEntry->declNode->codeLoc.line; | |
| 247 | |||
| 248 | llvm::DILocalVariable *varInfo; | ||
| 249 |
2/2✓ Branch 12 → 13 taken 1371 times.
✓ Branch 12 → 18 taken 1124 times.
|
2495 | if (argNumber != SIZE_MAX) |
| 250 |
1/2✓ Branch 16 → 17 taken 1371 times.
✗ Branch 16 → 35 not taken.
|
1371 | varInfo = diBuilder->createParameterVariable(scope, varName, argNumber, diFile, lineNo, diType); |
| 251 | else | ||
| 252 |
1/2✓ Branch 20 → 21 taken 1124 times.
✗ Branch 20 → 37 not taken.
|
1124 | varInfo = diBuilder->createAutoVariable(scope, varName, diFile, lineNo, diType); |
| 253 |
1/2✓ Branch 24 → 25 taken 2495 times.
✗ Branch 24 → 38 not taken.
|
2495 | llvm::DIExpression *expr = diBuilder->createExpression(); |
| 254 |
1/2✓ Branch 25 → 26 taken 2495 times.
✗ Branch 25 → 39 not taken.
|
2495 | const llvm::DILocation *debugLocation = irGenerator->builder.getCurrentDebugLocation(); |
| 255 |
1/2✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 2495 times.
|
2495 | assert(debugLocation != nullptr); |
| 256 |
1/2✓ Branch 32 → 33 taken 2495 times.
✗ Branch 32 → 40 not taken.
|
2495 | diBuilder->insertDeclare(address, varInfo, expr, debugLocation, irGenerator->builder.GetInsertPoint()); |
| 257 | } | ||
| 258 | |||
| 259 | 932954 | void DebugInfoGenerator::setSourceLocation(const CodeLoc &codeLoc) { | |
| 260 |
2/2✓ Branch 2 → 3 taken 912672 times.
✓ Branch 2 → 4 taken 20282 times.
|
932954 | if (!irGenerator->cliOptions.instrumentation.generateDebugInfo) |
| 261 | 912672 | return; | |
| 262 | |||
| 263 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 20282 times.
|
20282 | assert(!lexicalBlocks.empty()); |
| 264 | 20282 | llvm::DIScope *scope = lexicalBlocks.top(); | |
| 265 | 20282 | const llvm::DILocation *diCodeLoc = llvm::DILocation::get(scope->getContext(), codeLoc.line, codeLoc.col, scope); | |
| 266 | 20282 | irGenerator->builder.SetCurrentDebugLocation(diCodeLoc); | |
| 267 | } | ||
| 268 | |||
| 269 | 2562 | void DebugInfoGenerator::finalize() const { | |
| 270 |
2/2✓ Branch 2 → 3 taken 59 times.
✓ Branch 2 → 5 taken 2503 times.
|
2562 | if (irGenerator->cliOptions.instrumentation.generateDebugInfo) |
| 271 | 59 | diBuilder->finalize(); | |
| 272 | 2562 | } | |
| 273 | |||
| 274 | 8159 | llvm::DIType *DebugInfoGenerator::getDITypeForQualType(const ASTNode *node, const QualType &ty) { // NOLINT(*-no-recursion) | |
| 275 | // Pointer type | ||
| 276 |
2/2✓ Branch 3 → 4 taken 1385 times.
✓ Branch 3 → 13 taken 6774 times.
|
8159 | if (ty.isPtr()) { |
| 277 |
2/4✓ Branch 4 → 5 taken 1385 times.
✗ Branch 4 → 227 not taken.
✓ Branch 5 → 6 taken 1385 times.
✗ Branch 5 → 227 not taken.
|
1385 | llvm::DIType *pointeeTy = getDITypeForQualType(node, ty.getContained()); |
| 278 |
1/2✓ Branch 10 → 11 taken 1385 times.
✗ Branch 10 → 228 not taken.
|
2770 | return diBuilder->createPointerType(pointeeTy, pointerWidth); |
| 279 | } | ||
| 280 | |||
| 281 | // Reference type | ||
| 282 |
2/2✓ Branch 14 → 15 taken 913 times.
✓ Branch 14 → 22 taken 5861 times.
|
6774 | if (ty.isRef()) { |
| 283 |
2/4✓ Branch 15 → 16 taken 913 times.
✗ Branch 15 → 231 not taken.
✓ Branch 16 → 17 taken 913 times.
✗ Branch 16 → 231 not taken.
|
913 | llvm::DIType *referencedType = getDITypeForQualType(node, ty.getContained()); |
| 284 |
1/2✓ Branch 19 → 20 taken 913 times.
✗ Branch 19 → 232 not taken.
|
1826 | return diBuilder->createReferenceType(llvm::dwarf::DW_TAG_reference_type, referencedType, pointerWidth); |
| 285 | } | ||
| 286 | |||
| 287 | // Array type | ||
| 288 |
2/2✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 38 taken 5859 times.
|
5861 | if (ty.isArray()) { |
| 289 |
2/4✓ Branch 24 → 25 taken 2 times.
✗ Branch 24 → 233 not taken.
✓ Branch 25 → 26 taken 2 times.
✗ Branch 25 → 233 not taken.
|
2 | llvm::DIType *itemTy = getDITypeForQualType(node, ty.getContained()); |
| 290 |
1/2✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 239 not taken.
|
2 | const size_t size = ty.getArraySize(); |
| 291 |
1/2✓ Branch 29 → 30 taken 2 times.
✗ Branch 29 → 234 not taken.
|
2 | const llvm::DINodeArray subscripts = diBuilder->getOrCreateArray({}); |
| 292 |
5/10✓ Branch 31 → 32 taken 2 times.
✗ Branch 31 → 238 not taken.
✓ Branch 32 → 33 taken 2 times.
✗ Branch 32 → 237 not taken.
✓ Branch 33 → 34 taken 2 times.
✗ Branch 33 → 236 not taken.
✓ Branch 34 → 35 taken 2 times.
✗ Branch 34 → 235 not taken.
✓ Branch 35 → 36 taken 2 times.
✗ Branch 35 → 235 not taken.
|
2 | return diBuilder->createArrayType(size, 0, itemTy, subscripts); |
| 293 | } | ||
| 294 | |||
| 295 | // Primitive types | ||
| 296 | llvm::DIType *baseDiType; | ||
| 297 |
11/12✓ Branch 39 → 40 taken 27 times.
✓ Branch 39 → 41 taken 641 times.
✓ Branch 39 → 46 taken 30 times.
✓ Branch 39 → 51 taken 1167 times.
✓ Branch 39 → 56 taken 269 times.
✓ Branch 39 → 57 taken 280 times.
✓ Branch 39 → 58 taken 295 times.
✓ Branch 39 → 59 taken 454 times.
✓ Branch 39 → 60 taken 2678 times.
✓ Branch 39 → 174 taken 2 times.
✓ Branch 39 → 211 taken 16 times.
✗ Branch 39 → 212 not taken.
|
5859 | switch (ty.getSuperType()) { |
| 298 | 27 | case TY_DOUBLE: | |
| 299 | 27 | baseDiType = doubleTy; | |
| 300 | 27 | break; | |
| 301 | 641 | case TY_INT: | |
| 302 |
2/2✓ Branch 42 → 43 taken 610 times.
✓ Branch 42 → 44 taken 31 times.
|
641 | baseDiType = ty.isSigned() ? intTy : uIntTy; |
| 303 | 641 | break; | |
| 304 | 30 | case TY_SHORT: | |
| 305 |
1/2✓ Branch 47 → 48 taken 30 times.
✗ Branch 47 → 49 not taken.
|
30 | baseDiType = ty.isSigned() ? shortTy : uShortTy; |
| 306 | 30 | break; | |
| 307 | 1167 | case TY_LONG: | |
| 308 |
2/2✓ Branch 52 → 53 taken 138 times.
✓ Branch 52 → 54 taken 1029 times.
|
1167 | baseDiType = ty.isSigned() ? longTy : uLongTy; |
| 309 | 1167 | break; | |
| 310 | 269 | case TY_BYTE: | |
| 311 | 269 | baseDiType = byteTy; | |
| 312 | 269 | break; | |
| 313 | 280 | case TY_CHAR: | |
| 314 | 280 | baseDiType = charTy; | |
| 315 | 280 | break; | |
| 316 | 295 | case TY_STRING: | |
| 317 | 295 | baseDiType = stringTy; | |
| 318 | 295 | break; | |
| 319 | 454 | case TY_BOOL: | |
| 320 | 454 | baseDiType = boolTy; | |
| 321 | 454 | break; | |
| 322 | 2678 | case TY_STRUCT: { | |
| 323 | // Do cache lookup | ||
| 324 | 2678 | const size_t hashKey = std::hash<QualType>{}(ty); | |
| 325 |
1/2✓ Branch 61 → 62 taken 2678 times.
✗ Branch 61 → 265 not taken.
|
2678 | const auto it = structTypeCache.find(hashKey); |
| 326 |
2/2✓ Branch 64 → 65 taken 2291 times.
✓ Branch 64 → 67 taken 387 times.
|
2678 | if (it != structTypeCache.end()) |
| 327 | 2291 | return it->second; | |
| 328 | |||
| 329 | // Cache miss, generate struct type | ||
| 330 |
1/2✓ Branch 67 → 68 taken 387 times.
✗ Branch 67 → 265 not taken.
|
387 | const Struct *spiceStruct = ty.getStruct(node); |
| 331 |
1/2✗ Branch 68 → 69 not taken.
✓ Branch 68 → 70 taken 387 times.
|
387 | assert(spiceStruct != nullptr); |
| 332 | |||
| 333 | // Retrieve information about the struct | ||
| 334 |
1/2✓ Branch 70 → 71 taken 387 times.
✗ Branch 70 → 265 not taken.
|
387 | const uint32_t lineNo = spiceStruct->getDeclCodeLoc().line; |
| 335 |
2/4✓ Branch 71 → 72 taken 387 times.
✗ Branch 71 → 265 not taken.
✓ Branch 72 → 73 taken 387 times.
✗ Branch 72 → 265 not taken.
|
387 | llvm::Type *structType = spiceStruct->entry->getQualType().toLLVMType(irGenerator->sourceFile); |
| 336 |
1/2✗ Branch 73 → 74 not taken.
✓ Branch 73 → 75 taken 387 times.
|
387 | assert(structType != nullptr); |
| 337 | 387 | const llvm::DataLayout &dataLayout = irGenerator->module->getDataLayout(); | |
| 338 |
2/4✓ Branch 76 → 77 taken 387 times.
✗ Branch 76 → 265 not taken.
✓ Branch 77 → 78 taken 387 times.
✗ Branch 77 → 265 not taken.
|
387 | const llvm::StructLayout *structLayout = dataLayout.getStructLayout(llvm::cast<llvm::StructType>(structType)); |
| 339 |
1/2✓ Branch 78 → 79 taken 387 times.
✗ Branch 78 → 240 not taken.
|
387 | const uint32_t alignInBits = dataLayout.getABITypeAlign(structType).value(); |
| 340 | |||
| 341 | // Create struct ty. Generic substantiations are named by their signature (e.g. Vector<int>), so that debuggers can | ||
| 342 | // tell the manifestations of a generic struct apart | ||
| 343 |
1/2✓ Branch 80 → 81 taken 387 times.
✗ Branch 80 → 265 not taken.
|
387 | const std::string structName = spiceStruct->getSignature(); |
| 344 |
1/2✓ Branch 81 → 82 taken 387 times.
✗ Branch 81 → 263 not taken.
|
387 | const std::string mangledName = NameMangling::mangleStruct(*spiceStruct); |
| 345 |
2/4✓ Branch 86 → 87 taken 387 times.
✗ Branch 86 → 243 not taken.
✓ Branch 88 → 89 taken 387 times.
✗ Branch 88 → 242 not taken.
|
1161 | llvm::DICompositeType *structDiType = diBuilder->createStructType( |
| 346 |
2/4✓ Branch 87 → 88 taken 387 times.
✗ Branch 87 → 242 not taken.
✓ Branch 90 → 91 taken 387 times.
✗ Branch 90 → 241 not taken.
|
774 | diFile, structName, diFile, lineNo, structLayout->getSizeInBits(), alignInBits, |
| 347 | 387 | llvm::DINode::FlagTypePassByReference | llvm::DINode::FlagNonTrivial, nullptr, {}, 0, nullptr, mangledName); | |
| 348 | |||
| 349 | // Insert into cache | ||
| 350 |
1/2✓ Branch 91 → 92 taken 387 times.
✗ Branch 91 → 261 not taken.
|
387 | structTypeCache.emplace(hashKey, structDiType); |
| 351 | |||
| 352 | // A synthesized vtable pointer takes up the first element of the LLVM struct type, which shifts all fields | ||
| 353 | // by one element | ||
| 354 |
3/4✓ Branch 92 → 93 taken 387 times.
✗ Branch 92 → 261 not taken.
✓ Branch 93 → 94 taken 4 times.
✓ Branch 93 → 95 taken 383 times.
|
387 | const size_t fieldElementOffset = spiceStruct->hasSynthesizedVTablePtr() ? 1 : 0; |
| 355 | |||
| 356 | // Collect DI types for fields | ||
| 357 | 387 | std::vector<llvm::Metadata *> fieldTypes; | |
| 358 |
3/4✓ Branch 122 → 123 taken 1509 times.
✗ Branch 122 → 259 not taken.
✓ Branch 123 → 97 taken 1122 times.
✓ Branch 123 → 124 taken 387 times.
|
1509 | for (size_t i = 0; i < spiceStruct->scope->getFieldCount(); i++) { |
| 359 | // Get field entry | ||
| 360 |
1/2✗ Branch 97 → 98 not taken.
✓ Branch 97 → 99 taken 1122 times.
|
1122 | const SymbolTableEntry *fieldEntry = spiceStruct->scope->lookupField(i); |
| 361 |
3/6✓ Branch 102 → 103 taken 1122 times.
✗ Branch 102 → 106 not taken.
✓ Branch 103 → 104 taken 1122 times.
✗ Branch 103 → 259 not taken.
✓ Branch 104 → 105 taken 1122 times.
✗ Branch 104 → 106 not taken.
|
1122 | assert(fieldEntry != nullptr && fieldEntry->isField()); |
| 362 |
2/2✓ Branch 107 → 108 taken 117 times.
✓ Branch 107 → 109 taken 1005 times.
|
1122 | if (fieldEntry->isImplicitField) |
| 363 | 117 | continue; | |
| 364 | |||
| 365 |
1/2✓ Branch 109 → 110 taken 1005 times.
✗ Branch 109 → 259 not taken.
|
1005 | const QualType &fieldType = fieldEntry->getQualType(); |
| 366 | 1005 | const uint32_t fieldLineNo = fieldEntry->declNode->codeLoc.line; | |
| 367 |
2/4✓ Branch 110 → 111 taken 1005 times.
✗ Branch 110 → 246 not taken.
✓ Branch 111 → 112 taken 1005 times.
✗ Branch 111 → 246 not taken.
|
1005 | const size_t offsetInBits = structLayout->getElementOffsetInBits(i + fieldElementOffset); |
| 368 | |||
| 369 |
1/2✓ Branch 112 → 113 taken 1005 times.
✗ Branch 112 → 259 not taken.
|
1005 | llvm::DIType *fieldDiType = getDITypeForQualType(node, fieldType); |
| 370 | llvm::DIDerivedType *fieldDiDerivedType = | ||
| 371 |
3/6✓ Branch 115 → 116 taken 1005 times.
✗ Branch 115 → 248 not taken.
✓ Branch 116 → 117 taken 1005 times.
✗ Branch 116 → 248 not taken.
✓ Branch 118 → 119 taken 1005 times.
✗ Branch 118 → 247 not taken.
|
1005 | diBuilder->createMemberType(structDiType, fieldEntry->name, diFile, fieldLineNo, fieldDiType->getSizeInBits(), |
| 372 | fieldDiType->getAlignInBits(), offsetInBits, llvm::DINode::FlagZero, fieldDiType); | ||
| 373 | |||
| 374 |
1/2✓ Branch 119 → 120 taken 1005 times.
✗ Branch 119 → 249 not taken.
|
1005 | fieldTypes.push_back(fieldDiDerivedType); |
| 375 | } | ||
| 376 | |||
| 377 | // Collect DI nodes for the template parameters of generic substantiations | ||
| 378 | 387 | std::vector<llvm::Metadata *> templateParams; | |
| 379 |
6/8✓ Branch 125 → 126 taken 310 times.
✓ Branch 125 → 129 taken 77 times.
✓ Branch 126 → 127 taken 310 times.
✗ Branch 126 → 257 not taken.
✓ Branch 127 → 128 taken 310 times.
✗ Branch 127 → 129 not taken.
✓ Branch 130 → 131 taken 310 times.
✓ Branch 130 → 156 taken 77 times.
|
387 | if (!spiceStruct->templateTypes.empty() && spiceStruct->isFullySubstantiated()) { |
| 380 | // The template parameters of a substantiation carry the concrete types, so the declared parameter names | ||
| 381 | // (e.g. 'T') have to be taken from the generic preset | ||
| 382 |
2/4✓ Branch 131 → 132 taken 310 times.
✗ Branch 131 → 254 not taken.
✓ Branch 132 → 133 taken 310 times.
✗ Branch 132 → 134 not taken.
|
310 | const StructBase *nameSource = spiceStruct->isGenericSubstantiation() ? spiceStruct->genericPreset : spiceStruct; |
| 383 |
1/2✓ Branch 135 → 136 taken 310 times.
✗ Branch 135 → 254 not taken.
|
310 | const QualTypeList concreteTemplateTypes = spiceStruct->getConcreteTemplateTypes(); |
| 384 |
1/2✗ Branch 138 → 139 not taken.
✓ Branch 138 → 140 taken 310 times.
|
310 | assert(nameSource->templateTypes.size() == concreteTemplateTypes.size()); |
| 385 |
1/2✓ Branch 141 → 142 taken 310 times.
✗ Branch 141 → 252 not taken.
|
310 | templateParams.reserve(concreteTemplateTypes.size()); |
| 386 |
2/2✓ Branch 153 → 143 taken 475 times.
✓ Branch 153 → 154 taken 310 times.
|
785 | for (size_t i = 0; i < concreteTemplateTypes.size(); i++) { |
| 387 |
2/4✓ Branch 143 → 144 taken 475 times.
✗ Branch 143 → 252 not taken.
✓ Branch 144 → 145 taken 475 times.
✗ Branch 144 → 252 not taken.
|
475 | const std::string ¶mName = nameSource->templateTypes.at(i).getSubType(); |
| 388 |
2/4✓ Branch 145 → 146 taken 475 times.
✗ Branch 145 → 252 not taken.
✓ Branch 146 → 147 taken 475 times.
✗ Branch 146 → 252 not taken.
|
475 | llvm::DIType *paramDiType = getDITypeForQualType(node, concreteTemplateTypes.at(i)); |
| 389 |
2/4✓ Branch 149 → 150 taken 475 times.
✗ Branch 149 → 250 not taken.
✓ Branch 150 → 151 taken 475 times.
✗ Branch 150 → 250 not taken.
|
475 | templateParams.push_back(diBuilder->createTemplateTypeParameter(compileUnit, paramName, paramDiType, false)); |
| 390 | } | ||
| 391 | 310 | } | |
| 392 | |||
| 393 | // Attach fields and template parameters. This may re-unique the struct type, so refresh all references to it | ||
| 394 | 387 | const llvm::DINodeArray templateParamArray = | |
| 395 |
3/4✓ Branch 157 → 158 taken 77 times.
✓ Branch 157 → 159 taken 310 times.
✓ Branch 161 → 162 taken 310 times.
✗ Branch 161 → 255 not taken.
|
387 | templateParams.empty() ? llvm::DINodeArray() : diBuilder->getOrCreateArray(templateParams); |
| 396 |
2/4✓ Branch 165 → 166 taken 387 times.
✗ Branch 165 → 256 not taken.
✓ Branch 166 → 167 taken 387 times.
✗ Branch 166 → 256 not taken.
|
387 | diBuilder->replaceArrays(structDiType, diBuilder->getOrCreateArray(fieldTypes), templateParamArray); |
| 397 |
1/2✓ Branch 167 → 168 taken 387 times.
✗ Branch 167 → 257 not taken.
|
387 | structTypeCache.at(hashKey) = structDiType; |
| 398 | 387 | baseDiType = structDiType; | |
| 399 | 387 | break; | |
| 400 | 387 | } | |
| 401 | 2 | case TY_INTERFACE: { | |
| 402 | // Do cache lookup | ||
| 403 | 2 | const size_t hashKey = std::hash<QualType>{}(ty); | |
| 404 |
1/2✓ Branch 175 → 176 taken 2 times.
✗ Branch 175 → 276 not taken.
|
2 | const auto it = structTypeCache.find(hashKey); |
| 405 |
2/2✓ Branch 178 → 179 taken 1 time.
✓ Branch 178 → 181 taken 1 time.
|
2 | if (it != structTypeCache.end()) |
| 406 | 1 | return it->second; | |
| 407 | |||
| 408 | // Cache miss, generate interface type | ||
| 409 |
1/2✓ Branch 181 → 182 taken 1 time.
✗ Branch 181 → 276 not taken.
|
1 | const Interface *spiceInterface = ty.getInterface(node); |
| 410 |
1/2✗ Branch 182 → 183 not taken.
✓ Branch 182 → 184 taken 1 time.
|
1 | assert(spiceInterface != nullptr); |
| 411 | |||
| 412 | // Retrieve information about the interface | ||
| 413 |
1/2✓ Branch 184 → 185 taken 1 time.
✗ Branch 184 → 276 not taken.
|
1 | const uint32_t lineNo = spiceInterface->getDeclCodeLoc().line; |
| 414 |
2/4✓ Branch 185 → 186 taken 1 time.
✗ Branch 185 → 276 not taken.
✓ Branch 186 → 187 taken 1 time.
✗ Branch 186 → 276 not taken.
|
1 | llvm::Type *interfaceType = spiceInterface->entry->getQualType().toLLVMType(irGenerator->sourceFile); |
| 415 |
1/2✗ Branch 187 → 188 not taken.
✓ Branch 187 → 189 taken 1 time.
|
1 | assert(interfaceType != nullptr); |
| 416 |
1/2✓ Branch 190 → 191 taken 1 time.
✗ Branch 190 → 276 not taken.
|
1 | const llvm::DataLayout dataLayout = irGenerator->module->getDataLayout(); |
| 417 |
2/4✓ Branch 191 → 192 taken 1 time.
✗ Branch 191 → 274 not taken.
✓ Branch 192 → 193 taken 1 time.
✗ Branch 192 → 274 not taken.
|
1 | const llvm::StructLayout *structLayout = dataLayout.getStructLayout(llvm::cast<llvm::StructType>(interfaceType)); |
| 418 |
1/2✓ Branch 193 → 194 taken 1 time.
✗ Branch 193 → 266 not taken.
|
1 | const uint32_t alignInBits = dataLayout.getABITypeAlign(interfaceType).value(); |
| 419 | |||
| 420 | // Create interface ty | ||
| 421 |
1/2✓ Branch 195 → 196 taken 1 time.
✗ Branch 195 → 274 not taken.
|
1 | const std::string mangledName = NameMangling::mangleInterface(*spiceInterface); |
| 422 |
2/4✓ Branch 200 → 201 taken 1 time.
✗ Branch 200 → 269 not taken.
✓ Branch 202 → 203 taken 1 time.
✗ Branch 202 → 268 not taken.
|
3 | llvm::DICompositeType *interfaceDiType = diBuilder->createStructType( |
| 423 |
2/4✓ Branch 201 → 202 taken 1 time.
✗ Branch 201 → 268 not taken.
✓ Branch 204 → 205 taken 1 time.
✗ Branch 204 → 267 not taken.
|
2 | diFile, spiceInterface->name, diFile, lineNo, structLayout->getSizeInBits(), alignInBits, |
| 424 | 1 | llvm::DINode::FlagTypePassByReference | llvm::DINode::FlagNonTrivial, nullptr, {}, 0, nullptr, mangledName); | |
| 425 | |||
| 426 | // Set vtable holder to itself for interfaces | ||
| 427 |
1/2✓ Branch 205 → 206 taken 1 time.
✗ Branch 205 → 272 not taken.
|
1 | interfaceDiType->replaceVTableHolder(interfaceDiType); |
| 428 | 1 | baseDiType = interfaceDiType; | |
| 429 | |||
| 430 | // Insert into cache | ||
| 431 |
1/2✓ Branch 206 → 207 taken 1 time.
✗ Branch 206 → 272 not taken.
|
1 | structTypeCache.emplace(hashKey, interfaceDiType); |
| 432 | |||
| 433 | 1 | break; | |
| 434 | 1 | } | |
| 435 | 16 | case TY_FUNCTION: // fall-through | |
| 436 | case TY_PROCEDURE: | ||
| 437 | 16 | baseDiType = fatPtrTy; | |
| 438 | 16 | break; | |
| 439 | ✗ | default: | |
| 440 | − | throw CompilerError(UNHANDLED_BRANCH, "Debug Info Type fallthrough"); // GCOV_EXCL_LINE | |
| 441 | } | ||
| 442 | |||
| 443 |
2/2✓ Branch 221 → 222 taken 432 times.
✓ Branch 221 → 225 taken 3135 times.
|
3567 | if (ty.isConst()) |
| 444 | 432 | baseDiType = diBuilder->createQualifiedType(llvm::dwarf::DW_TAG_const_type, baseDiType); | |
| 445 | |||
| 446 | 3567 | return baseDiType; | |
| 447 | } | ||
| 448 | |||
| 449 | } // namespace spice::compiler | ||
| 450 |