-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Description
[HLSL] Compiler Crash During Template Instantiation with Internal Resource Helper Types
Description
The compiler crashes with an assertion failure in SemaInit.cpp when an HLSL internal resource helper type (like mips_slice_type from Texture2D::mips) is passed to a template function. Since HLSL is based on C++11, passing a prvalue to a function parameter requires an accessible copy or move constructor. When these constructors are marked protected or private, the compiler should report an access violation error. Instead, it crashes during the template instantiation process.
Note: This issue is currently latent and will only be exposed once PR #186143 (which introduces these internal types) is merged.
Steps to Reproduce
- Create a file named
repro.hlslwith the following content:
Texture2D<float4> t;
template<class T>
float4 foo(T t) {
return t[int2(0, 0)];
}
[shader("pixel")]
float4 test_mips() : SV_Target {
return foo(t.mips[0]);
}- Run the following command (assuming PR [HLSL] Implement Texture2D::mips[][] #186143 is applied):
clang -cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -emit-llvm -disable-llvm-passes -finclude-default-header repro.hlslCrash Backtrace
clang: clang/lib/Sema/SemaInit.cpp:6978: auto clang::InitializationSequence::InitializeFrom(Sema &, const InitializedEntity &, const InitializationKind &, MultiExprArg, bool, bool)::(anonymous class)::operator()() const: Assertion `!SourceType.isNull() && "Source QualType should not be null when arg size is exactly 1"\' failed.
#10 clang::InitializationSequence::InitializeFrom(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool, bool)::$_0::operator()() const clang/lib/Sema/SemaInit.cpp:0:7
#11 clang::InitializationSequence::InitializeFrom(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool, bool) clang/lib/Sema/SemaInit.cpp:6993:7
#12 clang::InitializationSequence::InitializationSequence(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool, bool) clang/lib/Sema/SemaInit.cpp:6595:1
#13 clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) clang/lib/Sema/SemaExprCXX.cpp:1655:60
#14 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::RebuildCXXFunctionalCastExpr(clang::TypeSourceInfo*, clang::SourceLocation, clang::Expr*, clang::SourceLocation, bool) clang/lib/Sema/TreeTransform.h:3406:22
...
Expected Behavior
The compiler should report a diagnostic error stating that the constructor of mips_slice_type is protected/inaccessible in this context, or otherwise fail gracefully during template deduction/instantiation.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status