Skip to content

Fix #5027: segfault in DComputeSemanticAnalyser::visit(VarDeclaration)#5099

Open
Codingisinmyblud wants to merge 1 commit intoldc-developers:masterfrom
Codingisinmyblud:fix-dcompute-null-type-crash
Open

Fix #5027: segfault in DComputeSemanticAnalyser::visit(VarDeclaration)#5099
Codingisinmyblud wants to merge 1 commit intoldc-developers:masterfrom
Codingisinmyblud:fix-dcompute-null-type-crash

Conversation

@Codingisinmyblud
Copy link

While looking into this issue I noticed that decl->type can sometimes be null when semantic analysis visits VarDeclarations coming from failed template instantiations in imported modules.

This showed up when a @compute module imports a template via -I and checks it with __traits(compiles, ...). In that case the recursive walker can reach a VarDeclaration whose type was never set, and the code was dereferencing decl->type unconditionally when checking for Taarray/Tclass, which leads to a segfault.

I added a small guard for this case. Let me know if this looks reasonable or if there’s a better way to handle it.

Thank you so much

Fixes #5027.

Guard against decl->type being null when semantic analysis
encounters VarDeclarations from failed template instantiations
in imported modules.

When a @compute module imports a template via -I and uses
__traits(compiles, ...) to test it, the recursive walker may
visit VarDeclaration nodes whose type field is null. The
unconditional dereference of decl->type on the check for
Taarray/Tclass causes a segmentation fault.

Fixes ldc-developers#5027.
@Codingisinmyblud Codingisinmyblud changed the title Fixe #5027: segfault in DComputeSemanticAnalyser::visit(VarDeclaration) Fix #5027: segfault in DComputeSemanticAnalyser::visit(VarDeclaration) Mar 15, 2026
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.

LDC segfaults in gen/semantic-dcompute.cpp at DComputeSemanticAnalyser::visit(VarDeclaration*)

1 participant