microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.07k stars 683 forks source link

Arrays cast compiler error #5338

Open gauss11 opened 1 year ago

gauss11 commented 1 year ago

HLSL compilers 5.1 and lower compiles this test without any type-cast errors. DXC returns error: // Internal Compiler error: llvm::cast() argument of incompatible type!

run dxc -T vs_6_0 test.hlsl

=========== test.hlsl ============

#define MAX_CLIPPINGPLANES_CASCADE_ 8

struct VSOUT
{
    float4 vPos:SV_Position;
    float4 afClipD[MAX_CLIPPINGPLANES_CASCADE_>>2]:SV_ClipDistance;
};

void castFunc(out float4 afClipD[MAX_CLIPPINGPLANES_CASCADE_>>2])
{
    [unroll]
    for (int n=0;n<MAX_CLIPPINGPLANES_CASCADE_;++n)
        ((float[MAX_CLIPPINGPLANES_CASCADE_])afClipD)[n]=float(n*n);
}

VSOUT main(float4 pos:POSITION0)
{
    VSOUT ret;
    ret.vPos=1;
    castFunc(ret.afClipD);  
    return ret;
} 
llvm-beanz commented 1 year ago

The bug is caused by SROA and related passes making unsafe assumptions about bitcasting, which is a gnarly problem and we'll have to look into. With asserts enabled the following error message is produced:

expected struct bitcast to only be used by lifetime intrinsicsAssertion failed: (false && "expected struct bitcast to only be used by lifetime intrinsics"), function RewriteBitCast, file ScalarReplAggregatesHLSL.cpp, line 2548.