From c6a19f1d044e4e23d3f0a608aa91da55376512bf Mon Sep 17 00:00:00 2001 From: Ethan Nicholas Date: Thu, 29 Mar 2018 16:46:56 -0400 Subject: [PATCH] fix for frexp dataflow analysis Bug: skia: Change-Id: Ic20bedadfbf37fd78ce03872ece2d9552307cfcd Reviewed-on: https://skia-review.googlesource.com/117243 Commit-Queue: Chris Dalton Reviewed-by: Chris Dalton --- src/sksl/SkSLCompiler.cpp | 13 +++++++++++++ src/sksl/sksl.inc | 2 +- tests/SkSLGLSLTest.cpp | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp index 4650e5c643..7db9440e7f 100644 --- a/src/sksl/SkSLCompiler.cpp +++ b/src/sksl/SkSLCompiler.cpp @@ -17,6 +17,7 @@ #include "ir/SkSLEnum.h" #include "ir/SkSLExpression.h" #include "ir/SkSLExpressionStatement.h" +#include "ir/SkSLFunctionCall.h" #include "ir/SkSLIntLiteral.h" #include "ir/SkSLModifiersDeclaration.h" #include "ir/SkSLNop.h" @@ -291,6 +292,18 @@ void Compiler::addDefinitions(const BasicBlock::Node& node, } break; } + case Expression::kFunctionCall_Kind: { + const FunctionCall& c = (const FunctionCall&) *expr; + for (size_t i = 0; i < c.fFunction.fParameters.size(); ++i) { + if (c.fFunction.fParameters[i]->fModifiers.fFlags & Modifiers::kOut_Flag) { + this->addDefinition( + c.fArguments[i].get(), + (std::unique_ptr*) &fContext->fDefined_Expression, + definitions); + } + } + break; + } case Expression::kPrefix_Kind: { const PrefixExpression* p = (PrefixExpression*) expr; if (p->fOperator == Token::MINUSMINUS || p->fOperator == Token::PLUSPLUS) { diff --git a/src/sksl/sksl.inc b/src/sksl/sksl.inc index 2b433ebd0f..0d38e73af6 100644 --- a/src/sksl/sksl.inc +++ b/src/sksl/sksl.inc @@ -102,7 +102,7 @@ $genType fma($genType a, $genType b, $genType c); $genHType fma($genHType a, $genHType b, $genHType c); $genDType fma($genDType a, $genDType b, $genDType c); //$genDType fma($genDType a, $genDType b, $genDType c); -$genType frexp($genType x, out $genIType exp); +sk_has_side_effects $genType frexp($genType x, out $genIType exp); //$genDType frexp($genDType x, out $genIType exp); $genType ldexp($genType x, in $genIType exp); //$genDType ldexp($genDType x, in $genIType exp); diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index 27797b6189..0b9ed35006 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -1945,4 +1945,21 @@ DEF_TEST(SkSLIncompleteShortIntPrecision, r) { SkSL::Program::kFragment_Kind); } +DEF_TEST(SkSLFrExp, r) { + test(r, + "void main() {" + " int exp;" + " float foo = frexp(0.5, exp);" + " sk_FragColor = float4(exp);" + "}", + *SkSL::ShaderCapsFactory::Default(), + "#version 400\n" + "out vec4 sk_FragColor;\n" + "void main() {\n" + " int exp;\n" + " float foo = frexp(0.5, exp);\n" + " sk_FragColor = vec4(float(exp));\n" + "}\n"); +} + #endif