Parcourir la source

Merge pull request #13488 from ghalliday/issue23695

HPCC-23695 CASE() returning unsigned6 constants could generate incorrect code

Reviewed-By: Shamser Ahmed <shamser.ahmed@lexisnexis.co.uk>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman il y a 5 ans
Parent
commit
9b1eb08768

+ 4 - 3
ecl/hqlcpp/hqlcppcase.cpp

@@ -1010,10 +1010,11 @@ IHqlExpression * HqlCppCaseInfo::createResultsExpr(IHqlExpression * matchVar, bo
     }
 
     unsigned firstMatchEntry = 0;
-    if (canIncludeDefault)
+    const bool useStaticArray = areConstant && canBuildStaticList(resultType);
+    if (useStaticArray)
     {
         //If all the values are constant, then can add the default as an extra 0th entry, because -1 will be the index for the default
-        if (areConstant && defaultValue->isConstant() && defaultValue->queryType() == values.item(0).queryType())
+        if (canIncludeDefault && defaultValue->isConstant() && defaultValue->queryType() == values.item(0).queryType())
         {
             firstMatchEntry = 1;
             values.add(*LINK(defaultValue), 0);
@@ -1024,7 +1025,7 @@ IHqlExpression * HqlCppCaseInfo::createResultsExpr(IHqlExpression * matchVar, bo
     // easy way to create a value list...
     ITypeInfo * storeType = getArrayElementType(retType);
     OwnedHqlExpr newlist = createValue(no_list, makeSetType(storeType), values);
-    if (areConstant && canBuildStaticList(resultType))
+    if (useStaticArray)
     {
         IHqlExpression * index = adjustValue(matchVar, 1+firstMatchEntry);
         return createValue(no_index, LINK(retType), LINK(newlist), index, createAttribute(noBoundCheckAtom));

+ 15 - 0
testing/regress/ecl/casestmt.ecl

@@ -36,3 +36,18 @@ output(case(s, '1'=>d1, '2'=>d2, '3'=>d3, d4));
 case(i, 1=>o1, 2=>o2, 3=>o3, o4);
 output(case(i, 1=>d1, 2=>d2, 3=>d3, d4));
 
+UNSIGNED6 Score(STRING level) := CASE(level,
+     'medium2' => 91,
+     'medium'  => 90,
+     'high'    => 98,
+     55);
+
+string low := 'low' : stored('low');
+string medium := 'medium' : stored('medium');
+string high := 'high' : stored('high');
+string none := 'none' : stored('none');
+
+low;    Score(low);
+medium; Score(medium);
+high;   Score(high);
+none;   Score(none);

+ 24 - 0
testing/regress/ecl/key/casestmt.xml

@@ -10,3 +10,27 @@
 <Dataset name='Result 10'>
  <Row><x>2</x></Row>
 </Dataset>
+<Dataset name='Result 11'>
+ <Row><Result_11>low</Result_11></Row>
+</Dataset>
+<Dataset name='Result 12'>
+ <Row><Result_12>55</Result_12></Row>
+</Dataset>
+<Dataset name='Result 13'>
+ <Row><Result_13>medium</Result_13></Row>
+</Dataset>
+<Dataset name='Result 14'>
+ <Row><Result_14>90</Result_14></Row>
+</Dataset>
+<Dataset name='Result 15'>
+ <Row><Result_15>high</Result_15></Row>
+</Dataset>
+<Dataset name='Result 16'>
+ <Row><Result_16>98</Result_16></Row>
+</Dataset>
+<Dataset name='Result 17'>
+ <Row><Result_17>none</Result_17></Row>
+</Dataset>
+<Dataset name='Result 18'>
+ <Row><Result_18>55</Result_18></Row>
+</Dataset>