Skip to content

Commit 8c056be

Browse files
authored
Reject string operands in binary and select ops (KhronosGroup#4077) (KhronosGroup#4079)
Reject string operands in binary and select ops (KhronosGroup#4077). This would previously cause a segfault during SPIR-V codegen
1 parent e2ab21f commit 8c056be

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
stringInvalidOps.frag
2+
ERROR: 0:5: ':' : wrong operand types: no operation ':' exists that takes a left-hand operand of type ' const string' and a right operand of type ' const string' (or there is no acceptable conversion)
3+
ERROR: 0:6: '+' : wrong operand types: no operation '+' exists that takes a left-hand operand of type ' const string' and a right operand of type ' const string' (or there is no acceptable conversion)
4+
ERROR: 0:7: '*' : wrong operand types: no operation '*' exists that takes a left-hand operand of type ' const string' and a right operand of type ' const string' (or there is no acceptable conversion)
5+
ERROR: 0:7: '+' : wrong operand types: no operation '+' exists that takes a left-hand operand of type ' const string' and a right operand of type ' const string' (or there is no acceptable conversion)
6+
ERROR: 4 compilation errors. No code generated.
7+
8+
9+
Shader version: 450
10+
Requested GL_EXT_debug_printf
11+
ERROR: node is still EOpNull!
12+
0:4 Function Definition: main( ( global void)
13+
0:4 Function Parameters:
14+
0:5 Sequence
15+
0:5 Constant:
16+
0:5 "def"
17+
0:6 Constant:
18+
0:6 "o"
19+
0:7 Constant:
20+
0:7 "o"
21+
0:? Linker Objects
22+
23+
24+
Linked fragment stage:
25+
26+
27+
Shader version: 450
28+
Requested GL_EXT_debug_printf
29+
ERROR: node is still EOpNull!
30+
0:4 Function Definition: main( ( global void)
31+
0:4 Function Parameters:
32+
0:5 Sequence
33+
0:5 Constant:
34+
0:5 "def"
35+
0:6 Constant:
36+
0:6 "o"
37+
0:7 Constant:
38+
0:7 "o"
39+
0:? Linker Objects
40+

Test/stringInvalidOps.frag

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#version 450
2+
#extension GL_EXT_debug_printf : require
3+
4+
void main() {
5+
true ? "abd" : "def";
6+
"o" + "k";
7+
"o" + "k" * "l";
8+
}

glslang/MachineIndependent/Intermediate.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ TIntermSymbol* TIntermediate::addSymbol(const TType& type, const TSourceLoc& loc
118118
TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc& loc)
119119
{
120120
// No operations work on blocks
121-
if (left->getType().getBasicType() == EbtBlock || right->getType().getBasicType() == EbtBlock)
121+
if (left->getType().getBasicType() == EbtBlock || right->getType().getBasicType() == EbtBlock ||
122+
left->getType().getBasicType() == EbtString || right->getType().getBasicType() == EbtString)
122123
return nullptr;
123124

124125
// Convert "reference +/- int" and "reference - reference" to integer math
@@ -2382,7 +2383,8 @@ TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* true
23822383
trueBlock = std::get<0>(children);
23832384
falseBlock = std::get<1>(children);
23842385

2385-
if (trueBlock == nullptr || falseBlock == nullptr)
2386+
if (trueBlock == nullptr || falseBlock == nullptr ||
2387+
trueBlock->getBasicType() == EbtString || falseBlock->getBasicType() == EbtString)
23862388
return nullptr;
23872389

23882390
// Handle a vector condition as a mix

gtests/AST.FromFile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ INSTANTIATE_TEST_SUITE_P(
215215
"runtimeArray.vert",
216216
"simpleFunctionCall.frag",
217217
"stringToDouble.vert",
218+
"stringInvalidOps.frag",
218219
"struct.error.frag",
219220
"structAssignment.frag",
220221
"structDeref.frag",

0 commit comments

Comments
 (0)