Skip to content

LLVM assert when using the [unroll] attribute #210

Closed

Description

@TheRealMJP

I'm hitting an LLVM assert when compiling a shader that uses the parameterized version of the unroll attribute, where the loop count comes from a local constant variable. If I go past the assert the compiler crashes shortly after trying to deference a null pointer. Here's a simple example vertex shader that triggers the assert:

float4 VSMain() : SV_Position
{
    float4 position = 0.0f;

    const uint loopCount = 4;

    [unroll(loopCount)]
    for(uint i = 0; i < loopCount; ++i)
        position.x += 1.0f;

    return position;
}

This is the callstack that I get when I hit the assert:

dxcompiler.dll!llvm_assert(const char * _Message, const char * _File, unsigned int _Line) Line 17   C++
dxcompiler.dll!llvm::isa_impl_cl<clang::VarDecl,clang::NamedDecl const * __ptr64>::doit(const clang::NamedDecl * Val) Line 95   C++
dxcompiler.dll!llvm::isa_impl_wrap<clang::VarDecl,clang::NamedDecl const * __ptr64,clang::NamedDecl const * __ptr64>::doit(const clang::NamedDecl * const & Val) Line 123   C++
dxcompiler.dll!llvm::isa_impl_wrap<clang::VarDecl,clang::NamedDecl * __ptr64 const,clang::NamedDecl const * __ptr64>::doit(clang::NamedDecl * const & Val) Line 115 C++
dxcompiler.dll!llvm::isa<clang::VarDecl,clang::NamedDecl * __ptr64>(clang::NamedDecl * const & Val) Line 135    C++
dxcompiler.dll!llvm::dyn_cast<clang::VarDecl,clang::NamedDecl>(clang::NamedDecl * Val) Line 299 C++
dxcompiler.dll!ValidateAttributeIntArg(clang::Sema & S, const clang::AttributeList & Attr, unsigned int index) Line 9398    C++
dxcompiler.dll!HandleUnrollAttribute(clang::Sema & S, const clang::AttributeList & Attr) Line 9636  C++
dxcompiler.dll!hlsl::ProcessStmtAttributeForHLSL(clang::Sema & S, clang::Stmt * St, const clang::AttributeList & A, clang::SourceRange Range, bool & Handled) Line 9969 C++
dxcompiler.dll!ProcessStmtAttribute(clang::Sema & S, clang::Stmt * St, const clang::AttributeList & A, clang::SourceRange Range) Line 212   C++
dxcompiler.dll!clang::Sema::ProcessStmtAttributes(clang::Stmt * S, clang::AttributeList * AttrList, clang::SourceRange Range) Line 229  C++
dxcompiler.dll!clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt *,32> & Stmts, bool OnlyStatement, clang::SourceLocation * TrailingElseLoc) Line 116    C++
dxcompiler.dll!clang::Parser::ParseCompoundStatementBody(bool isStmtExpr) Line 1025 C++
dxcompiler.dll!clang::Parser::ParseFunctionStatementBody(clang::Decl * Decl, clang::Parser::ParseScope & BodyScope) Line 1962   C++
dxcompiler.dll!clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator & D, const clang::Parser::ParsedTemplateInfo & TemplateInfo, clang::Parser::LateParsedAttrList * LateParsedAttrs) Line 1174  C++
dxcompiler.dll!clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec & DS, unsigned int Context, clang::SourceLocation * DeclEnd, clang::Parser::ForRangeInit * FRI) Line 2277   C++
dxcompiler.dll!clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange & attrs, clang::ParsingDeclSpec & DS, clang::AccessSpecifier AS) Line 962 C++
dxcompiler.dll!clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange & attrs, clang::ParsingDeclSpec * DS, clang::AccessSpecifier AS) Line 978   C++
dxcompiler.dll!clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange & attrs, clang::ParsingDeclSpec * DS) Line 836  C++
dxcompiler.dll!clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef> & Result) Line 606    C++
dxcompiler.dll!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 146  C++
dxcompiler.dll!clang::ASTFrontendAction::ExecuteAction() Line 556   C++
dxcompiler.dll!clang::CodeGenAction::ExecuteAction() Line 747   C++
dxcompiler.dll!clang::FrontendAction::Execute() Line 468    C++
dxcompiler.dll!DxcCompiler::Compile(IDxcBlob * pSource, const wchar_t * pSourceName, const wchar_t * pEntryPoint, const wchar_t * pTargetProfile, const wchar_t * * pArguments, unsigned int argCount, const DxcDefine * pDefines, unsigned int defineCount, IDxcIncludeHandler * pIncludeHandler, IDxcOperationResult * * ppResult) Line 2204  C++

It compiles fine if I use the un-parameterized "[unroll]" attribute, or if I remove the unroll entirely.

Activity

  1. python3kgae commented on Apr 12, 2017

    @python3kgae
    Contributor

    Thanks for the feedback.
    Fixed with #214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions