@@ -720,16 +720,52 @@ DIType DIBuilder::CreateAArrayType(TypeAArray *type) {
720
720
721
721
// //////////////////////////////////////////////////////////////////////////////
722
722
723
- DISubroutineType DIBuilder::CreateFunctionType (Type *type) {
723
+ DISubroutineType DIBuilder::CreateFunctionType (Type *type,
724
+ FuncDeclaration *fd) {
724
725
TypeFunction *t = type->isTypeFunction ();
725
726
assert (t);
726
727
727
- Type *retType = t->next ;
728
+ llvm::SmallVector<LLMetadata *, 8 > params;
729
+ auto pushParam = [&](Type *type, bool isRef) {
730
+ auto ditype = CreateTypeDescription (type);
731
+ if (isRef) {
732
+ if (!ditype) { // void or noreturn
733
+ ditype = CreateTypeDescription (Type::tuns8);
734
+ }
735
+ ditype = DBuilder.createReferenceType (llvm::dwarf::DW_TAG_reference_type,
736
+ ditype, target.ptrsize * 8 );
737
+ }
738
+ params.emplace_back (ditype);
739
+ };
728
740
729
- // Create "dummy" subroutine type for the return type
730
- LLMetadata *params = {CreateTypeDescription (retType)};
731
- auto paramsArray = DBuilder.getOrCreateTypeArray (params);
741
+ // the first 'param' is the return value
742
+ pushParam (t->next , t->isref ());
743
+
744
+ // then the implicit 'this'/context pointer
745
+ if (fd) {
746
+ DIType pointeeType = nullptr ;
747
+ if (auto parentAggregate = fd->isThis ()) {
748
+ pointeeType = CreateCompositeType (parentAggregate->type );
749
+ } else if (fd->isNested ()) {
750
+ pointeeType = CreateTypeDescription (Type::tuns8); // cannot use void
751
+ }
732
752
753
+ if (pointeeType) {
754
+ DIType ditype = DBuilder.createReferenceType (
755
+ llvm::dwarf::DW_TAG_pointer_type, pointeeType, target.ptrsize * 8 );
756
+ ditype = DBuilder.createObjectPointerType (ditype);
757
+ params.emplace_back (ditype);
758
+ }
759
+ }
760
+
761
+ // and finally the formal parameters
762
+ const auto len = t->parameterList .length ();
763
+ for (size_t i = 0 ; i < len; i++) {
764
+ const auto param = t->parameterList [i];
765
+ pushParam (param->type , param->isReference ());
766
+ }
767
+
768
+ auto paramsArray = DBuilder.getOrCreateTypeArray (params);
733
769
return DBuilder.createSubroutineType (paramsArray, DIFlags::FlagZero, 0 );
734
770
}
735
771
@@ -971,7 +1007,7 @@ DISubprogram DIBuilder::EmitSubProgram(FuncDeclaration *fd) {
971
1007
flags, dispFlags);
972
1008
973
1009
// Now create subroutine type.
974
- diFnType = CreateFunctionType (fd->type );
1010
+ diFnType = CreateFunctionType (fd->type , fd );
975
1011
}
976
1012
977
1013
// FIXME: duplicates?
@@ -1010,7 +1046,7 @@ DISubprogram DIBuilder::EmitThunk(llvm::Function *Thunk, FuncDeclaration *fd) {
1010
1046
" Compilation unit missing or corrupted in DIBuilder::EmitThunk" );
1011
1047
1012
1048
// Create subroutine type (thunk has same type as wrapped function)
1013
- DISubroutineType DIFnType = CreateFunctionType (fd->type );
1049
+ DISubroutineType DIFnType = CreateFunctionType (fd->type , fd );
1014
1050
1015
1051
const auto scope = GetSymbolScope (fd);
1016
1052
const auto name = (llvm::Twine (fd->toChars ()) + " .__thunk" ).str ();
0 commit comments