Skip to content

DXC exhibits different behavior than FXC when encountering uninitialized variables #2419

Closed as not planned

Description

Scenario 1: Uninitialized variable
DXC: Below shader compiles fine without any warning.
FXC: Compilation fails with an error message error X4000: variable 'sum' used without having been completely initialized

uint main() : OUT
{
	uint sum;
        sum++;
	return sum;
}

Scenario 2: Uninitialized variable passed to another function.
DXC: Below shader compiles fine without any warning.
FXC: Compilation fails with an error message error X4000: variable 'sum' used without having been completely initialized

uint foo(uint s)
{
	s = s << 4;
	return s;
}

uint main(uint i : IN) : OUT
{
	uint sum;
	return foo(sum);
}

Scenario 3: Uninitialized variable used in its own initialization
DXC: Below shader compiles fine without any warning.
FXC: Compiles fine with a warning message warning X3578: Output value 'main' is not completely initialized

uint main() : OUT
{
	uint sum = sum;
	return sum;
}

Scenario 4: Returning struct with uninitialized fields

DXC: Below shader compiles fine without any warning.
FXC: Compiles fine with a warning message warning X3578: Output value 'main' is not completely initialized

struct MyStruct {
 float a;
 int b;
};


MyStruct main() : OUT
{
	MyStruct val;
	return val;
}

Scenario 5: Conditional initialization
Both DXC and FXC compiles below shader without any warning.

uint main(uint i : IN) : OUT
{
	uint sum;
	if(i > 10) {
		sum = 10;
	}
	return sum;
} 

Activity

  1. vcsharma commented on Apr 29, 2020

    @vcsharma
    ContributorAuthor

    Reopening this issue as the fix for this would be needed along with fix for #2494.

  2. Dredhog commented on May 3, 2021

    @Dredhog

    Vishal Sharma (@vcsharma) We've also noticed this at Unity, do you plan on fixing this anytime soon? Having warnings for uninitialized outputs would be really nice to have.

  3. damyanp commented on Jun 12, 2024

    @damyanp
    Member

    No plans to address this in DXC, but this is something we're aware of in clang.

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

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions