Skip to content

[DebugInfo] Fix infinite recursion when opaque return type is defined inside function returning it #81794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

augusto2112
Copy link
Contributor

@augusto2112 augusto2112 commented May 28, 2025

A stack overflow would happen when the compiler tried emitting debug info for a function whose opaque return type was declared inside the function itself. This fixes the issue by emitting a forward declaration for the function before emitting it.

rdar://150313956

inside function returning it

A stack overflow would happen when the compiler tried emitting debug
info for a function whose opaque return type was declared inside the
function itself. This fixes the issue by emitting a forward declaration
for the function before emitting it.

rdar://150313956
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112 augusto2112 changed the title [DebugInfo] Fix infinite recursion when opaque return type is defined [DebugInfo] Fix infinite recursion when opaque return type is defined inside function returning it May 28, 2025
@@ -3201,6 +3204,11 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
Name = getName(DS->Loc);
}

llvm::DISubprogram *ReplaceableType = DBuilder.createTempFunctionFwdDecl(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: as someone unfamiliar with this API, parameter comments could help contextualize the various constants that are being passed through. although i see that isn't universally done in this file.

Copy link
Contributor

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks safe & correct, thanks!

@@ -3201,6 +3204,11 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
Name = getName(DS->Loc);
}

llvm::DISubprogram *ReplaceableType = DBuilder.createTempFunctionFwdDecl(
nullptr, Name, LinkageName, 0, 0, nullptr, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if you passed in the correct scope here instead of nullptr — does that make the other change unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? This is creating the temporary forward declaration so if we recurse back here we return it instead. If I passed the scope of the function when creating the temporary? What other change are you referring to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 976 you are guarding against a DIScope with a null DIFile. I was wondering if that is because your temporary Subprogram (which is a DIScope) has a null DIFile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants