Skip to content

Commit 4295b25

Browse files
authored
Add error for invalid arguments to GetDimension (microsoft#6698)
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
1 parent 129c9f8 commit 4295b25

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,6 +4032,15 @@ SpirvEmitter::processBufferTextureGetDimensions(const CXXMemberCallExpr *expr) {
40324032
numSamples = expr->getArg(numArgs - 1);
40334033
}
40344034

4035+
// Make sure that all output args are an l-value.
4036+
for (uint32_t argIdx = (mipLevel ? 1 : 0); argIdx < numArgs; ++argIdx) {
4037+
if (!expr->getArg(argIdx)->isLValue()) {
4038+
emitError("Output argument must be an l-value",
4039+
expr->getArg(argIdx)->getExprLoc());
4040+
return nullptr;
4041+
}
4042+
}
4043+
40354044
uint32_t querySize = numArgs;
40364045
// If numLevels arg is present, mipLevel must also be present. These are not
40374046
// queried via ImageQuerySizeLod.

tools/clang/test/CodeGenSPIRV/texture.get-dimensions.hlsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %dxc -T ps_6_0 -E main -fcgl %s -spirv | FileCheck %s
2+
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv -DERROR 2>&1 | FileCheck %s --check-prefix=ERROR
23

34
// CHECK: OpCapability ImageQuery
45

@@ -360,4 +361,12 @@ void main() {
360361
// CHECK-NEXT: [[query_levels_int:%[0-9]+]] = OpBitcast %int [[query_levels_uint]]
361362
// CHECK-NEXT: OpStore %signedNumLevels [[query_levels_int]]
362363
t3.GetDimensions(signedMipLevel, signedWidth, signedHeight, signedNumLevels);
364+
365+
#ifdef ERROR
366+
// ERROR: 367:30: error: Output argument must be an l-value
367+
t9.GetDimensions(mipLevel, 0, height, elements, numLevels);
368+
369+
// ERROR: 370:35: error: Output argument must be an l-value
370+
t9.GetDimensions(width, height, 20);
371+
#endif
363372
}

0 commit comments

Comments
 (0)