@@ -4183,6 +4183,24 @@ static CodegenContext *setUpSimpleContext(CodegenContext *ctx,
41834183
41844184 ctx->llvmFunc = initGlobals;
41854185
4186+ // synthetic functions need their own DI scope so global-var initializers
4187+ // codegenned into this context emit DILocations with a non-null scope
4188+ if (llvmDIBuilder != nullptr ) {
4189+ llvm::DIFile *file = llvmDICompileUnit->getFile ();
4190+
4191+ llvm::DISubroutineType *spType = llvmDIBuilder->createSubroutineType (
4192+ llvmDIBuilder->getOrCreateTypeArray ({}));
4193+
4194+ llvm::DISubprogram *sp = llvmDIBuilder->createFunction (
4195+ file, name, name, file, 0 , spType, 0 , llvm::DINode::FlagArtificial,
4196+ llvm::DISubprogram::SPFlagLocalToUnit |
4197+ llvm::DISubprogram::SPFlagDefinition);
4198+
4199+ initGlobals->setSubprogram (sp);
4200+
4201+ ctx->pushDebugScope (llvmDIBuilder->createLexicalBlock (sp, file, 0 , 0 ));
4202+ }
4203+
41864204 llvm::BasicBlock *initBlock = newBasicBlock (" init" , ctx);
41874205 llvm::BasicBlock *codeBlock = newBasicBlock (" code" , ctx);
41884206 llvm::BasicBlock *returnBlock = newBasicBlock (" return" , ctx);
@@ -4191,6 +4209,13 @@ static CodegenContext *setUpSimpleContext(CodegenContext *ctx,
41914209 ctx->initBuilder .reset (new llvm::IRBuilder<>(initBlock));
41924210 ctx->builder .reset (new llvm::IRBuilder<>(codeBlock));
41934211
4212+ if (llvmDIBuilder != nullptr ) {
4213+ llvm::DebugLoc debugLoc =
4214+ llvm::DILocation::get (llvmContext, 0 , 0 , ctx->getDebugScope ());
4215+ ctx->initBuilder ->SetCurrentDebugLocation (debugLoc);
4216+ ctx->builder ->SetCurrentDebugLocation (debugLoc);
4217+ }
4218+
41944219 ctx->exceptionValue = ctx->initBuilder ->CreateAlloca (exceptionReturnType (),
41954220 nullptr , " exception" );
41964221
0 commit comments