microsoft / microsoft/DirectXShaderCompiler
SemaHLSL's FlattenedTypeIterator does not handle bit fields properly.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
There are a variety of repros possible, such as: casting from one struct to another where one has bitfields and the other has a series of uints equivalent to the size of the bitfield storage, or from a literal int 0 to a struct with a starting bitfield of enum type.
Example 1:
// RUN: %dxc -T lib_6_6 -HV 2021 %s
struct SomeStructWithBitfields {
uint32_t m1 : 8;
uint32_t m2 : 16;
uint32_t m3 : 6;
};
struct StructWithUint {
uint32_t u;
};
StructWithUint cStructWithUint;
export uint32_t SomeFuncCastingStructs()
{
// error: cannot convert from 'const StructWithUint' to 'SomeStructWithBitfields'
SomeStructWithBitfields bf = (SomeStructWithBitfields)cStructWithUint;
return bf.m2;
}
Example 2:
This one may have a different root cause, or involve an additional bug, which should be broken out into another issue during investigation if so.
// RUN: %dxc -T lib_6_6 -HV 2021 %s
enum SomeEnum { Val1 };
struct SomeStructWithEnum
{
// Uncommenting the uint32_t field makes the cast ok somehow...
//uint32_t m1 : 16;
SomeEnum m3 : 3;
};
export int SomeFuncUsingEnum()
{
// This cast only succeeds when the first bitfield is not an enum.
// Uncommenting the uint32_t field gets past taht, but then there's a
// crash due to issue #5257
SomeStructWithEnums = (SomeStructWithEnum)0;
s.m3 = Val1;
return (int)s.m3;
}
Example 3 (expect some diagnostics casting to uint here):
// RUN: %dxc -T lib_6_6 -HV 2021 %s
struct SomeStruct2
{
uint32_t m1 : 16;
uint32_t m2 : 19;
uint32_t m3 : 3;
};
export uint SomeFunc2()
{
SomeStruct2 s = (SomeStruct2)0;
// Expect some error or warning when casting to uint, since SomeStruct2 is larger than one uint:
return (uint)s;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the three HLSL cases with the shown dxc -T lib_6_6 -HV 2021 commands and inspect SemaHLSL's FlattenedTypeIterator while comparing bitfield and enum handling. Determine whether the enum case is separate from issue #5257, then add regression coverage for the confirmed casts and expected diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100