Skip to content

Commit

Permalink
default init a default ctor, fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ArielG-NV committed Aug 15, 2024
1 parent addb635 commit 1c8aeab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
3 changes: 2 additions & 1 deletion source/slang/slang-check-conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,15 @@ namespace Slang
// if something makes zero sense.
if (auto toGenericType = _getGenericAppDeclRefType(toType))
{
auto arg = fromInitializerListExpr->args[ioArgIndex];
auto arg = fromInitializerListExpr->args[ioArgIndexMirror];
if (auto fromGenericType = _getGenericAppDeclRefType(getType(m_astBuilder, arg)))
{
for (;;)
{
if (toGenericType->getBase() != fromGenericType->getBase())
break;

ioArgIndex = ioArgIndexMirror;
*outToExpr = arg;
ioArgIndex++;
return true;
Expand Down
29 changes: 15 additions & 14 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,7 @@ namespace Slang
ctor->addOption(ConstructorTags::Synthesized);

// kIROp_TorchTensorType must only refer to its own type through Host functions
// TODO: figure-out how to pass CudaHost for when we have a nested TorchTensor.
if(auto intrinsicType = decl->findModifier<IntrinsicTypeModifier>())
if(intrinsicType->irOp == kIROp_TorchTensorType)
addModifier(ctor, m_astBuilder->create<CudaHostAttribute>());
Expand Down Expand Up @@ -7716,10 +7717,22 @@ namespace Slang

// Static variables are initialized at start of runtime, not inside a constructor
if (!varDeclBase
|| !varDeclBase->initExpr
|| varDeclBase->hasModifier<HLSLStaticModifier>())
continue;

// Default initializer initializes/zero's out all values,
// do this here.
auto intendedInitExpr = varDeclBase->initExpr;
if(structDeclInfo.defaultCtor == ctor && !intendedInitExpr)
{
auto defaultExpr = m_astBuilder->create<DefaultConstructExpr>();
defaultExpr->type = varDeclBase->type.type;
intendedInitExpr = defaultExpr;
}

if (!intendedInitExpr)
continue;

MemberExpr* memberExpr = m_astBuilder->create<MemberExpr>();
memberExpr->baseExpression = thisExpr;
memberExpr->declRef = m->getDefaultDeclRef();
Expand All @@ -7730,7 +7743,7 @@ namespace Slang

auto assign = m_astBuilder->create<AssignExpr>();
assign->left = memberExpr;
assign->right = varDeclBase->initExpr;
assign->right = intendedInitExpr;
assign->loc = m->loc;

auto stmt = m_astBuilder->create<ExpressionStmt>();
Expand Down Expand Up @@ -7884,18 +7897,6 @@ namespace Slang
}
seqStmt->stmts.insert(ctorInfo.insertOffset++, seqStmtChild);
}

if (structDeclInfo.defaultCtor)
{
if (auto block = as<BlockStmt>(structDeclInfo.defaultCtor->body))
{
auto seqStmt = as<SeqStmt>(block->body);
if (seqStmt && seqStmt->stmts.getCount() == 0)
{
seqStmt->stmts.add(m_astBuilder->create<EmptyStmt>());
}
}
}
}

void SemanticsDeclHeaderVisitor::cloneModifiers(Decl* dest, Decl* src)
Expand Down

0 comments on commit 1c8aeab

Please sign in to comment.