Skip to content

Commit

Permalink
fix smoke-gfx
Browse files Browse the repository at this point in the history
We need to ensure the definite checked for a struct before trying to
use its constructor in the initialize list coerce.
  • Loading branch information
kaizhangNV committed Oct 13, 2024
1 parent f9b905e commit a548615
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions source/slang/slang-check-conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,19 @@ namespace Slang

bool isCStyle = isCStyleStruct(structDecl);

DiagnosticSink tempSink(getSourceManager(), nullptr);
SemanticsVisitor subVisitor(withSink(&tempSink));

// First make sure the struct is fully checked, otherwise the synthesized constructor may not be created yet.
subVisitor.ensureDecl(structDecl, DeclCheckState::DefinitionChecked);

if (structDecl->m_synthesizedCtorMap.getCount() == 0)
{
return false;
}

List<Expr*> coercedArgs;
auto ctorInvokeExpr = _createCtorInvokeExpr(toType, fromInitializerListExpr->loc, fromInitializerListExpr->args);

DiagnosticSink tempSink(getSourceManager(), nullptr);
SemanticsVisitor subVisitor(withSink(&tempSink));
ctorInvokeExpr = subVisitor.CheckExpr(ctorInvokeExpr);

if (ctorInvokeExpr)
Expand Down
12 changes: 6 additions & 6 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Slang
static ConstructorDecl* _getDefaultCtor(StructDecl* structDecl);
static List<ConstructorDecl*> _getCtorList(ASTBuilder* m_astBuilder, SemanticsVisitor* visitor, StructDecl* structDecl, ConstructorDecl** defaultCtorOut);
static Expr* constructDefaultInitExprForType(SemanticsVisitor* visitor, VarDeclBase* varDecl);
void addVisibilityModifier(ASTBuilder* builder, Decl* decl, DeclVisibility vis);

/// Visitor to transition declarations to `DeclCheckState::CheckedModifiers`
struct SemanticsDeclModifiersVisitor
Expand Down Expand Up @@ -1997,7 +1998,7 @@ namespace Slang
addModifier(func, m_astBuilder->create<TreatAsDifferentiableAttribute>());
}

static ConstructorDecl* _createCtor(SemanticsDeclVisitorBase* visitor, ASTBuilder* m_astBuilder, AggTypeDecl* decl)
static ConstructorDecl* _createCtor(SemanticsDeclVisitorBase* visitor, ASTBuilder* m_astBuilder, AggTypeDecl* decl, DeclVisibility ctorVisibility)
{
auto ctor = m_astBuilder->create<ConstructorDecl>();
addModifier(ctor, m_astBuilder->create<SynthesizedModifier>());
Expand All @@ -2024,6 +2025,7 @@ namespace Slang
ctor->addTag(ConstructorDecl::ConstructorTags::Synthesized);
decl->addMember(ctor);
addAutoDiffModifiersToFunc(visitor, m_astBuilder, ctor);
addVisibilityModifier(m_astBuilder, ctor, ctorVisibility);
return ctor;
}

Expand Down Expand Up @@ -11438,7 +11440,7 @@ namespace Slang

// synthesize the constructor signature:
// 1. The constructor's name is always `$init`, we create one without parameters now.
ConstructorDecl* ctor = _createCtor(this, getASTBuilder(), structDecl);
ConstructorDecl* ctor = _createCtor(this, getASTBuilder(), structDecl, ctorVisibility);
ctor->addTag(ConstructorDecl::ConstructorTags::MemberInitCtor);
structDecl->m_synthesizedCtorMap.addIfNotExists((int)ConstructorDecl::ConstructorTags::MemberInitCtor, ctor);

Expand Down Expand Up @@ -11473,9 +11475,6 @@ namespace Slang
}
}
ctor->members.reverse();

// 3. Add the necessary modifiers
addVisibilityModifier(getASTBuilder(), ctor, ctorVisibility);
}

void SemanticsDeclAttributesVisitor::visitStructDecl(StructDecl* structDecl)
Expand All @@ -11489,7 +11488,8 @@ namespace Slang
auto defaultCtor = _getDefaultCtor(structDecl);
if (!defaultCtor)
{
auto ctor = _createCtor(this, m_astBuilder, structDecl);
DeclVisibility ctorVisibility = getDeclVisibility(structDecl);
auto ctor = _createCtor(this, m_astBuilder, structDecl, ctorVisibility);
structDecl->m_synthesizedCtorMap.addIfNotExists((int)ConstructorDecl::ConstructorTags::Synthesized, ctor);
}

Expand Down

0 comments on commit a548615

Please sign in to comment.