Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of CD3DX12_CPU_DESCRIPTOR_HANDLE in an array can result in static analysis warning #6

Open
EpicChrisWaters opened this issue Mar 19, 2021 · 6 comments
Labels
d3dx12 Impacts d3dx12.h not our bug Tracking an issue in an external component like a C/C++ compiler

Comments

@EpicChrisWaters
Copy link

EpicChrisWaters commented Mar 19, 2021

Please see this godbolt output https://godbolt.org/z/ozYG6e

If you create an uninitialized array of CD3DX12_CPU_DESCRIPTOR_HANDLE and then initializing the array in a loop with objects of type D3D12_CPU_DESCRIPTOR_HANDLE, it results in a static analysis error on the usage of the uninitialized array. This does not happen with a non-array.

It actually looks like changing just the custom assignment operator can fix this, if you "= default" the "=" operator, the warning goes away. For context, this warning looks like it was introduced when all the constructors were changed from "{}" (empty implementations) to "= default".

@jenatali
Copy link
Member

Since these assignment operators take D3D12_CPU_DESCRIPTOR_HANDLE instead of the class type (CD3DX12_CPU_DESCRIPTOR_HANDLE) they can't simply be defaulted.

I don't know if there's a good way to indicate to analysis that the operator= method doesn't require *this to be initialized. Maybe the solution is to delete these operator= methods and remove explicit from the conversion constructor - then this assignment would construct a CD3DX12_CPU_DESCRIPTOR_HANDLE and use the defaulted operator=, which doesn't cause analysis to complain: https://godbolt.org/z/3Y49E5

@jenatali
Copy link
Member

Paging @walbourn for an opinion on this.

@walbourn
Copy link
Member

walbourn commented Mar 22, 2021

The =default instead of {} implementation of ctors/operators is important for other reasons, but it does mean that the static code analyzer 'notices' it is uninitialized.

If you choose to use an array of D3D12_CPU_DESCRIPTOR_HANDLE instead, it doesn't produce the warning.

It also doesn't happen if you use CD3DX12_CPU_DESCRIPTOR_HANDLE Handles[32] = {};

Frankly this looks more like a bug in /anazlye than anything else...

You should submit this repro as a bug to the VS team since I don't see any reason it should emit the warning.

@jenatali jenatali added the bug Something isn't working label May 26, 2021
@walbourn
Copy link
Member

Does this warning still happen with the latest VS 2019?

@walbourn
Copy link
Member

I see it still happens. This is definitely a compiler bug. Please report it to VS and then close this issue with the link.

@walbourn
Copy link
Member

@EpicChrisWaters Did this get reported to the VS site yet?

@walbourn walbourn added d3dx12 Impacts d3dx12.h not our bug Tracking an issue in an external component like a C/C++ compiler and removed bug Something isn't working labels Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
d3dx12 Impacts d3dx12.h not our bug Tracking an issue in an external component like a C/C++ compiler
Projects
None yet
Development

No branches or pull requests

3 participants