From d3c123a034d865b2755eccd5352a2e636d7bfacb Mon Sep 17 00:00:00 2001
From: John Kessenich <cepheus@frii.com>
Date: Thu, 10 Jul 2014 23:49:21 +0000
Subject: [PATCH] Fix bug where non-constant test in ?: on a constant results
 thought the result was const, when it is really a temporary.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@27291 e7fa87d3-cd2b-0410-9028-fcbf551c1848
---
 Test/baseResults/constFold.frag.out         | 52 +++++++++++++++++++++
 Test/constFold.frag                         |  2 +
 glslang/MachineIndependent/Intermediate.cpp |  1 +
 3 files changed, 55 insertions(+)

diff --git a/Test/baseResults/constFold.frag.out b/Test/baseResults/constFold.frag.out
index 12a94fccc..06fc0200b 100644
--- a/Test/baseResults/constFold.frag.out
+++ b/Test/baseResults/constFold.frag.out
@@ -231,6 +231,32 @@ ERROR: node is still EOpNull!
 0:118        'p' (int)
 0:118        Constant:
 0:118          -2147483647 (const int)
+0:119      Sequence
+0:119        move second child to first child (float)
+0:119          'f' (float)
+0:119          Constant:
+0:119            1.444000
+0:120      move second child to first child (float)
+0:120        'f' (float)
+0:120        direct index (float)
+0:120          Construct vec4 (4-component vector of float)
+0:120            Test condition and select (float)
+0:120              Condition
+0:120              Compare Less Than (bool)
+0:120                direct index (float)
+0:120                  'inv' (smooth in 4-component vector of float)
+0:120                  Constant:
+0:120                    0 (const int)
+0:120                Constant:
+0:120                  2.400000
+0:120              true case
+0:120              Constant:
+0:120                -1.000000
+0:120              false case
+0:120              Constant:
+0:120                1.000000
+0:120          Constant:
+0:120            3 (const int)
 0:?   Linker Objects
 0:?     'a' (const int)
 0:?       1 (const int)
@@ -532,6 +558,32 @@ ERROR: node is still EOpNull!
 0:118        'p' (int)
 0:118        Constant:
 0:118          -2147483647 (const int)
+0:119      Sequence
+0:119        move second child to first child (float)
+0:119          'f' (float)
+0:119          Constant:
+0:119            1.444000
+0:120      move second child to first child (float)
+0:120        'f' (float)
+0:120        direct index (float)
+0:120          Construct vec4 (4-component vector of float)
+0:120            Test condition and select (float)
+0:120              Condition
+0:120              Compare Less Than (bool)
+0:120                direct index (float)
+0:120                  'inv' (smooth in 4-component vector of float)
+0:120                  Constant:
+0:120                    0 (const int)
+0:120                Constant:
+0:120                  2.400000
+0:120              true case
+0:120              Constant:
+0:120                -1.000000
+0:120              false case
+0:120              Constant:
+0:120                1.000000
+0:120          Constant:
+0:120            3 (const int)
 0:?   Linker Objects
 0:?     'a' (const int)
 0:?       1 (const int)
diff --git a/Test/constFold.frag b/Test/constFold.frag
index aa8a94bea..ae0817a61 100644
--- a/Test/constFold.frag
+++ b/Test/constFold.frag
@@ -116,4 +116,6 @@ void foo2()
     p = -2147483647 / -1;
     p = -2147483648 / -1;
     p =  2147483647 / -1;
+    float f = vec4(7.8 < 2.4 ? -1.333 : 1.444).a;
+    f = vec4(inv.x < 2.4 ? -1.0 : 1.0).a;  // not folded, ensuring no propagation
 }
diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp
index 7a9514b1e..c3c06d4e9 100644
--- a/glslang/MachineIndependent/Intermediate.cpp
+++ b/glslang/MachineIndependent/Intermediate.cpp
@@ -784,6 +784,7 @@ TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* true
     // Make a selection node.
     //
     TIntermSelection* node = new TIntermSelection(cond, trueBlock, falseBlock, trueBlock->getType());
+    node->getQualifier().storage = EvqTemporary;
     node->setLoc(loc);
     node->getQualifier().precision = std::max(trueBlock->getQualifier().precision, falseBlock->getQualifier().precision);
 
-- 
GitLab