Fix missing symbols for template alias arguments during codegen#22849
Fix missing symbols for template alias arguments during codegen#22849oCHIKIo wants to merge 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @oCHIKIo! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
af81842 to
b116364
Compare
|
A function passed as a template parameter doesn't need code gen when it's not used, that is intentional. In the issue's test case, neither function needs code gen. |
b116364 to
a5b0c04
Compare
|
I updated the fix based on @dkorpel's feedback! Instead of forcing the compiler to generate code for unused lambda arguments, I went the other way: if a lambda is never actually used or referenced (tookAddressOf == 0), we now skip code generation for any templates instantiated inside it too. I updated needsCodegen in templatesem.d to catch this specific case and mark those inner template instances as speculative. This way, the compiler correctly drops both the unused lambda and the template instances inside it, completely avoiding the undefined reference errors without generating dead code generation without forcing unnecessary codegen errors without compiling dead/optimized-out code. |
Fixes #22848
i discovered that the compiler was skipping code generation for symbols (like nested functions) when they were passed only as alias arguments to templates. this resulted in "undefined reference" linker errors because the backend never visited those dependencies.
this PR adds a traversal of template arguments (tiargs) to the toObjFile visitor in toobj.d. this ensures that all symbols required by a non-speculative template instantiation are correctly processed for code generation.