Skip to content

Commit

Permalink
Add error for invalid arguments to GetDimension
Browse files Browse the repository at this point in the history
When processing the GetDimension member function for textures, we do not
emit an error if the output variable is not an l-value. This change will
add this error.

Fixes microsoft#6689
  • Loading branch information
s-perron committed Jun 17, 2024
1 parent 8c3f40c commit 5897a44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4014,6 +4014,15 @@ SpirvEmitter::processBufferTextureGetDimensions(const CXXMemberCallExpr *expr) {
numSamples = expr->getArg(numArgs - 1);
}

// Make sure that all output args are an l-value.
for (uint32_t argIdx = (mipLevel ? 1 : 0); argIdx < numArgs; ++argIdx) {
if (!expr->getArg(argIdx)->isLValue()) {
emitError("Output argument must be an l-value",
expr->getArg(argIdx)->getExprLoc());
return nullptr;
}
}

uint32_t querySize = numArgs;
// If numLevels arg is present, mipLevel must also be present. These are not
// queried via ImageQuerySizeLod.
Expand Down
9 changes: 9 additions & 0 deletions tools/clang/test/CodeGenSPIRV/texture.get-dimensions.hlsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %dxc -T ps_6_0 -E main -fcgl %s -spirv | FileCheck %s
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv -DERROR 2>&1 | FileCheck %s --check-prefix=ERROR

// CHECK: OpCapability ImageQuery

Expand Down Expand Up @@ -360,4 +361,12 @@ void main() {
// CHECK-NEXT: [[query_levels_int:%[0-9]+]] = OpBitcast %int [[query_levels_uint]]
// CHECK-NEXT: OpStore %signedNumLevels [[query_levels_int]]
t3.GetDimensions(signedMipLevel, signedWidth, signedHeight, signedNumLevels);

#ifdef ERROR
// ERROR: 367:30: error: Output argument must be an l-value
t9.GetDimensions(mipLevel, 0, height, elements, numLevels);

// ERROR: 370:35: error: Output argument must be an l-value
t9.GetDimensions(width, height, 20);
#endif
}

0 comments on commit 5897a44

Please sign in to comment.