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

[spirv] Fix null pointer dereference #3861

Merged
merged 1 commit into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4962,8 +4962,9 @@ SpirvEmitter::doCXXOperatorCallExpr(const CXXOperatorCallExpr *expr) {

auto base = loadIfAliasVarRef(baseExpr);

if (indices.empty())
return base; // For indexing into size-1 vectors and 1xN matrices
if (base == nullptr ||
indices.empty()) // For indexing into size-1 vectors and 1xN matrices
return base;

// If we are indexing into a rvalue, to use OpAccessChain, we first need
// to create a local variable to hold the rvalue.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Run: %dxc -T ps_6_1 -E main

struct PSInput {
float4 position : SV_POSITION;
nointerpolation float3 color : COLOR;
};

cbuffer constants : register(b0) {
float4 g_constants;
}

float4 main(PSInput input) : SV_TARGET {
uint cmp = (uint)(g_constants[0]);

// CHECK: 16:21: error: GetAttributeAtVertex intrinsic function unimplemented
float colorAtV0 = GetAttributeAtVertex(input.color, 0)[cmp];

// CHECK: 19:21: error: GetAttributeAtVertex intrinsic function unimplemented
float colorAtV1 = GetAttributeAtVertex(input.color, 1)[cmp];

// CHECK: 22:21: error: GetAttributeAtVertex intrinsic function unimplemented
float colorAtV2 = GetAttributeAtVertex(input.color, 2)[cmp];

return float4(colorAtV0, colorAtV1, colorAtV2, 0);
}
3 changes: 3 additions & 0 deletions tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,9 @@ TEST_F(FileTest, IntrinsicsNonUniformResourceIndex) {
TEST_F(FileTest, IntrinsicsMultiPrefix) {
runFileTest("intrinsics.multiprefix.hlsl", Expect::Failure);
}
TEST_F(FileTest, IntrinsicsGetAttributeAtVertex) {
runFileTest("intrinsics.get-attribute-at-vertex.hlsl", Expect::Failure);
}

// Vulkan-specific intrinsic functions
TEST_F(FileTest, IntrinsicsVkCrossDeviceScope) {
Expand Down