From bc17b0a96ae2b6071f673258af45ef4c2ebdc3ea Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Tue, 28 Jun 2016 23:56:31 -0600 Subject: [PATCH] Front-end: Add missing rule for function-return implicit type conversion check. Basic (component) type conversion was done, but checking that the composite was correct was not being done. Fixes issue #353. --- Test/baseResults/functionSemantics.frag.out | 18 ++++++++++++++++-- Test/functionSemantics.frag | 5 +++++ glslang/MachineIndependent/ParseHelper.cpp | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Test/baseResults/functionSemantics.frag.out b/Test/baseResults/functionSemantics.frag.out index a9dfb91c5..1ea7dbd68 100644 --- a/Test/baseResults/functionSemantics.frag.out +++ b/Test/baseResults/functionSemantics.frag.out @@ -1,8 +1,12 @@ functionSemantics.frag Warning, version 400 is not yet complete; most version-specific features are present, but some are missing. +ERROR: 0:74: 'return' : cannot convert return value to function return type +WARNING: 0:74: 'return' : type conversion on return values was not explicitly allowed until version 420 +ERROR: 1 compilation errors. No code generated. + Shader version: 400 -0:? Sequence +ERROR: node is still EOpNull! 0:5 Function Definition: foo(i1;i1;i1;i1;i1;i1; (global int) 0:5 Function Parameters: 0:5 'a' (in int) @@ -195,6 +199,11 @@ Shader version: 400 0:69 Construct ivec2 (temp 2-component vector of int) 0:69 Convert float to int (temp int) 0:69 'F' (temp float) +0:72 Function Definition: badConv( (global 4-component vector of float) +0:72 Function Parameters: +0:74 Sequence +0:74 Branch: Return with expression +0:74 'u' (uniform float) 0:? Linker Objects 0:? 'u' (uniform float) @@ -203,7 +212,7 @@ Linked fragment stage: Shader version: 400 -0:? Sequence +ERROR: node is still EOpNull! 0:5 Function Definition: foo(i1;i1;i1;i1;i1;i1; (global int) 0:5 Function Parameters: 0:5 'a' (in int) @@ -396,6 +405,11 @@ Shader version: 400 0:69 Construct ivec2 (temp 2-component vector of int) 0:69 Convert float to int (temp int) 0:69 'F' (temp float) +0:72 Function Definition: badConv( (global 4-component vector of float) +0:72 Function Parameters: +0:74 Sequence +0:74 Branch: Return with expression +0:74 'u' (uniform float) 0:? Linker Objects 0:? 'u' (uniform float) diff --git a/Test/functionSemantics.frag b/Test/functionSemantics.frag index 15ebc604c..e5c3ed00e 100644 --- a/Test/functionSemantics.frag +++ b/Test/functionSemantics.frag @@ -68,3 +68,8 @@ void aggCall() float F; m(ivec2(F)); // test input conversion of single argument that's an aggregate; other function tests in 120.vert } + +vec4 badConv() +{ + return u; // ERROR, can change scalar to vector +} \ No newline at end of file diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 49ac1c9bf..fe22ff80b 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -1208,6 +1208,8 @@ TIntermNode* TParseContext::handleReturnValue(const TSourceLoc& loc, TIntermType } else if (*currentFunctionType != value->getType()) { TIntermTyped* converted = intermediate.addConversion(EOpReturn, *currentFunctionType, value); if (converted) { + if (*currentFunctionType != converted->getType()) + error(loc, "cannot convert return value to function return type", "return", ""); if (version < 420) warn(loc, "type conversion on return values was not explicitly allowed until version 420", "return", ""); return intermediate.addBranch(EOpReturn, converted, loc);