Commit 1d35d511 by Jonah Ryan-Davis Committed by Geoff Lang

Revert "Fix unit test for setting locale creating malformed HLSL shader code"

This reverts commit 5f662c00. Reason for revert: Some recent crashes related to streams, could be related to this change. https://bugs.chromium.org/p/chromium/issues/detail?id=932359 Original change's description: > Fix unit test for setting locale creating malformed HLSL shader code > Fix malformed HLSL shader code in other locales than classic > > Bug: angleproject:1433 > Change-Id: I30bad0bd0cfda465ec7200e48e12800d7d8efd26 > Reviewed-on: https://chromium-review.googlesource.com/c/1447862 > Reviewed-by: Geoff Lang <geofflang@chromium.org> > Reviewed-by: Jamie Madill <jmadill@chromium.org> > Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> TBR=geofflang@chromium.org,jmadill@chromium.org,jonahr@google.com Bug: angleproject:1433 Change-Id: I28caa073b3996a95f3f233bed9dc91dc44263835 Reviewed-on: https://chromium-review.googlesource.com/c/1474624Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent aca30f56
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "compiler/translator/AtomicCounterFunctionHLSL.h" #include "compiler/translator/AtomicCounterFunctionHLSL.h"
#include "compiler/translator/Common.h"
#include "compiler/translator/ImmutableStringBuilder.h" #include "compiler/translator/ImmutableStringBuilder.h"
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermNode.h"
...@@ -93,7 +92,7 @@ void AtomicCounterFunctionHLSL::atomicCounterFunctionHeader(TInfoSinkBase &out) ...@@ -93,7 +92,7 @@ void AtomicCounterFunctionHLSL::atomicCounterFunctionHeader(TInfoSinkBase &out)
ImmutableString getAtomicCounterNameForBinding(int binding) ImmutableString getAtomicCounterNameForBinding(int binding)
{ {
std::stringstream counterName = sh::InitializeStream<std::stringstream>(); std::stringstream counterName;
counterName << kAtomicCounterBaseName << binding; counterName << kAtomicCounterBaseName << binding;
return ImmutableString(counterName.str()); return ImmutableString(counterName.str());
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
// //
#include "compiler/translator/BuiltInFunctionEmulatorGLSL.h" #include "compiler/translator/BuiltInFunctionEmulatorGLSL.h"
#include "angle_gl.h" #include "angle_gl.h"
#include "compiler/translator/BuiltInFunctionEmulator.h" #include "compiler/translator/BuiltInFunctionEmulator.h"
#include "compiler/translator/VersionGLSL.h" #include "compiler/translator/VersionGLSL.h"
...@@ -88,7 +87,7 @@ void InitBuiltInAtanFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator * ...@@ -88,7 +87,7 @@ void InitBuiltInAtanFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *
}; };
for (int dim = 2; dim <= 4; ++dim) for (int dim = 2; dim <= 4; ++dim)
{ {
std::stringstream ss = sh::InitializeStream<std::stringstream>(); std::stringstream ss;
ss << "emu_precision vec" << dim << " atan_emu(emu_precision vec" << dim ss << "emu_precision vec" << dim << " atan_emu(emu_precision vec" << dim
<< " y, emu_precision vec" << dim << " x)\n" << " y, emu_precision vec" << dim << " x)\n"
<< "{\n" << "{\n"
......
...@@ -171,7 +171,7 @@ class CallDAG::CallDAGCreator : public TIntermTraverser ...@@ -171,7 +171,7 @@ class CallDAG::CallDAGCreator : public TIntermTraverser
InitResult result = INITDAG_SUCCESS; InitResult result = INITDAG_SUCCESS;
std::stringstream errorStream = sh::InitializeStream<std::stringstream>(); std::stringstream errorStream;
while (!functionsToProcess.empty()) while (!functionsToProcess.empty())
{ {
......
...@@ -125,15 +125,6 @@ inline const char *AllocatePoolCharArray(const char *str, size_t strLength) ...@@ -125,15 +125,6 @@ inline const char *AllocatePoolCharArray(const char *str, size_t strLength)
return buffer; return buffer;
} }
// Initialize a new stream which must be imbued with the classic locale
template <typename T>
T InitializeStream()
{
T stream;
stream.imbue(std::locale::classic());
return stream;
}
} // namespace sh } // namespace sh
namespace std namespace std
......
...@@ -68,7 +68,7 @@ void DumpFuzzerCase(char const *const *shaderStrings, ...@@ -68,7 +68,7 @@ void DumpFuzzerCase(char const *const *shaderStrings,
{ {
static int fileIndex = 0; static int fileIndex = 0;
std::ostringstream o = sh::InitializeStream<std::ostringstream>(); std::ostringstream o;
o << "corpus/" << fileIndex++ << ".sample"; o << "corpus/" << fileIndex++ << ".sample";
std::string s = o.str(); std::string s = o.str();
...@@ -940,7 +940,7 @@ bool TCompiler::initBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -940,7 +940,7 @@ bool TCompiler::initBuiltInSymbolTable(const ShBuiltInResources &resources)
void TCompiler::setResourceString() void TCompiler::setResourceString()
{ {
std::ostringstream strstream = sh::InitializeStream<std::ostringstream>(); std::ostringstream strstream;
// clang-format off // clang-format off
strstream << ":MaxVertexAttribs:" << mResources.MaxVertexAttribs strstream << ":MaxVertexAttribs:" << mResources.MaxVertexAttribs
...@@ -1107,7 +1107,7 @@ bool TCompiler::checkCallDepth() ...@@ -1107,7 +1107,7 @@ bool TCompiler::checkCallDepth()
if (depth >= mResources.MaxCallStackDepth) if (depth >= mResources.MaxCallStackDepth)
{ {
// Trace back the function chain to have a meaningful info log. // Trace back the function chain to have a meaningful info log.
std::stringstream errorStream = sh::InitializeStream<std::stringstream>(); std::stringstream errorStream;
errorStream << "Call stack too deep (larger than " << mResources.MaxCallStackDepth errorStream << "Call stack too deep (larger than " << mResources.MaxCallStackDepth
<< ") with the following call chain: " << ") with the following call chain: "
<< record.node->getFunction()->name(); << record.node->getFunction()->name();
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "common/debug.h" #include "common/debug.h"
#include "compiler/translator/Common.h"
#include "compiler/translator/Diagnostics.h" #include "compiler/translator/Diagnostics.h"
namespace sh namespace sh
...@@ -191,7 +190,7 @@ void TDirectiveHandler::handleVersion(const angle::pp::SourceLocation &loc, int ...@@ -191,7 +190,7 @@ void TDirectiveHandler::handleVersion(const angle::pp::SourceLocation &loc, int
} }
else else
{ {
std::stringstream stream = sh::InitializeStream<std::stringstream>(); std::stringstream stream;
stream << version; stream << version;
std::string str = stream.str(); std::string str = stream.str();
mDiagnostics.error(loc, "version number not supported", str.c_str()); mDiagnostics.error(loc, "version number not supported", str.c_str());
......
...@@ -69,7 +69,7 @@ TInfoSinkBase &TInfoSinkBase::operator<<(const TType &type) ...@@ -69,7 +69,7 @@ TInfoSinkBase &TInfoSinkBase::operator<<(const TType &type)
void TInfoSinkBase::location(int file, int line) void TInfoSinkBase::location(int file, int line)
{ {
TPersistStringStream stream = sh::InitializeStream<TPersistStringStream>(); TPersistStringStream stream;
if (line) if (line)
stream << file << ":" << line; stream << file << ":" << line;
else else
......
...@@ -41,7 +41,7 @@ class TInfoSinkBase ...@@ -41,7 +41,7 @@ class TInfoSinkBase
template <typename T> template <typename T>
TInfoSinkBase &operator<<(const T &t) TInfoSinkBase &operator<<(const T &t)
{ {
TPersistStringStream stream = sh::InitializeStream<TPersistStringStream>(); TPersistStringStream stream;
stream << t; stream << t;
sink.append(stream.str()); sink.append(stream.str());
return *this; return *this;
...@@ -79,7 +79,7 @@ class TInfoSinkBase ...@@ -79,7 +79,7 @@ class TInfoSinkBase
// does not have a fractional part, the default precision format does // does not have a fractional part, the default precision format does
// not write the decimal portion which gets interpreted as integer by // not write the decimal portion which gets interpreted as integer by
// the compiler. // the compiler.
TPersistStringStream stream = sh::InitializeStream<TPersistStringStream>(); TPersistStringStream stream;
if (fractionalPart(f) == 0.0f) if (fractionalPart(f) == 0.0f)
{ {
stream.precision(1); stream.precision(1);
......
...@@ -39,7 +39,7 @@ constexpr const char kImage2DFunctionString[] = "// @@ IMAGE2D DECLARATION FUNCT ...@@ -39,7 +39,7 @@ constexpr const char kImage2DFunctionString[] = "// @@ IMAGE2D DECLARATION FUNCT
TString ArrayHelperFunctionName(const char *prefix, const TType &type) TString ArrayHelperFunctionName(const char *prefix, const TType &type)
{ {
TStringStream fnName = sh::InitializeStream<TStringStream>(); TStringStream fnName;
fnName << prefix << "_"; fnName << prefix << "_";
if (type.isArray()) if (type.isArray())
{ {
...@@ -132,7 +132,7 @@ const char *kZeros = "_ANGLE_ZEROS_"; ...@@ -132,7 +132,7 @@ const char *kZeros = "_ANGLE_ZEROS_";
constexpr int kZeroCount = 256; constexpr int kZeroCount = 256;
std::string DefineZeroArray() std::string DefineZeroArray()
{ {
std::stringstream ss = sh::InitializeStream<std::stringstream>(); std::stringstream ss;
// For 'static', if the declaration does not include an initializer, the value is set to zero. // For 'static', if the declaration does not include an initializer, the value is set to zero.
// https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/dx-graphics-hlsl-variable-syntax // https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/dx-graphics-hlsl-variable-syntax
ss << "static uint " << kZeros << "[" << kZeroCount << "];\n"; ss << "static uint " << kZeros << "[" << kZeroCount << "];\n";
...@@ -141,7 +141,7 @@ std::string DefineZeroArray() ...@@ -141,7 +141,7 @@ std::string DefineZeroArray()
std::string GetZeroInitializer(size_t size) std::string GetZeroInitializer(size_t size)
{ {
std::stringstream ss = sh::InitializeStream<std::stringstream>(); std::stringstream ss;
size_t quotient = size / kZeroCount; size_t quotient = size / kZeroCount;
size_t reminder = size % kZeroCount; size_t reminder = size % kZeroCount;
...@@ -416,7 +416,7 @@ TString OutputHLSL::structInitializerString(int indent, ...@@ -416,7 +416,7 @@ TString OutputHLSL::structInitializerString(int indent,
init += indentString + "{\n"; init += indentString + "{\n";
for (unsigned int arrayIndex = 0u; arrayIndex < type.getOutermostArraySize(); ++arrayIndex) for (unsigned int arrayIndex = 0u; arrayIndex < type.getOutermostArraySize(); ++arrayIndex)
{ {
TStringStream indexedString = sh::InitializeStream<TStringStream>(); TStringStream indexedString;
indexedString << name << "[" << arrayIndex << "]"; indexedString << name << "[" << arrayIndex << "]";
TType elementType = type; TType elementType = type;
elementType.toArrayElementType(); elementType.toArrayElementType();
...@@ -891,8 +891,8 @@ void OutputHLSL::header(TInfoSinkBase &out, ...@@ -891,8 +891,8 @@ void OutputHLSL::header(TInfoSinkBase &out,
out << kImage2DFunctionString << "\n"; out << kImage2DFunctionString << "\n";
std::ostringstream systemValueDeclaration = sh::InitializeStream<std::ostringstream>(); std::ostringstream systemValueDeclaration;
std::ostringstream glBuiltinInitialization = sh::InitializeStream<std::ostringstream>(); std::ostringstream glBuiltinInitialization;
systemValueDeclaration << "\nstruct CS_INPUT\n{\n"; systemValueDeclaration << "\nstruct CS_INPUT\n{\n";
glBuiltinInitialization << "\nvoid initGLBuiltins(CS_INPUT input)\n" glBuiltinInitialization << "\nvoid initGLBuiltins(CS_INPUT input)\n"
...@@ -1900,7 +1900,7 @@ ImmutableString OutputHLSL::samplerNamePrefixFromStruct(TIntermTyped *node) ...@@ -1900,7 +1900,7 @@ ImmutableString OutputHLSL::samplerNamePrefixFromStruct(TIntermTyped *node)
{ {
int index = nodeBinary->getRight()->getAsConstantUnion()->getIConst(0); int index = nodeBinary->getRight()->getAsConstantUnion()->getIConst(0);
std::stringstream prefixSink = sh::InitializeStream<std::stringstream>(); std::stringstream prefixSink;
prefixSink << samplerNamePrefixFromStruct(nodeBinary->getLeft()) << "_" << index; prefixSink << samplerNamePrefixFromStruct(nodeBinary->getLeft()) << "_" << index;
return ImmutableString(prefixSink.str()); return ImmutableString(prefixSink.str());
} }
...@@ -1910,7 +1910,7 @@ ImmutableString OutputHLSL::samplerNamePrefixFromStruct(TIntermTyped *node) ...@@ -1910,7 +1910,7 @@ ImmutableString OutputHLSL::samplerNamePrefixFromStruct(TIntermTyped *node)
int index = nodeBinary->getRight()->getAsConstantUnion()->getIConst(0); int index = nodeBinary->getRight()->getAsConstantUnion()->getIConst(0);
const TField *field = s->fields()[index]; const TField *field = s->fields()[index];
std::stringstream prefixSink = sh::InitializeStream<std::stringstream>(); std::stringstream prefixSink;
prefixSink << samplerNamePrefixFromStruct(nodeBinary->getLeft()) << "_" prefixSink << samplerNamePrefixFromStruct(nodeBinary->getLeft()) << "_"
<< field->name(); << field->name();
return ImmutableString(prefixSink.str()); return ImmutableString(prefixSink.str());
......
...@@ -611,7 +611,7 @@ bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIn ...@@ -611,7 +611,7 @@ bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIn
return true; return true;
} }
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>(); std::stringstream reasonStream;
reasonStream << "l-value required"; reasonStream << "l-value required";
if (!message.empty()) if (!message.empty())
{ {
...@@ -902,7 +902,7 @@ bool TParseContext::checkIsNotOpaqueType(const TSourceLoc &line, ...@@ -902,7 +902,7 @@ bool TParseContext::checkIsNotOpaqueType(const TSourceLoc &line,
{ {
if (ContainsSampler(pType.userDef)) if (ContainsSampler(pType.userDef))
{ {
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>(); std::stringstream reasonStream;
reasonStream << reason << " (structure contains a sampler)"; reasonStream << reason << " (structure contains a sampler)";
std::string reasonStr = reasonStream.str(); std::string reasonStr = reasonStream.str();
error(line, reasonStr.c_str(), getBasicString(pType.type)); error(line, reasonStr.c_str(), getBasicString(pType.type));
...@@ -3066,7 +3066,7 @@ void TParseContext::parseGlobalLayoutQualifier(const TTypeQualifierBuilder &type ...@@ -3066,7 +3066,7 @@ void TParseContext::parseGlobalLayoutQualifier(const TTypeQualifierBuilder &type
if (mComputeShaderLocalSize[i] < 1 || if (mComputeShaderLocalSize[i] < 1 ||
mComputeShaderLocalSize[i] > maxComputeWorkGroupSizeValue) mComputeShaderLocalSize[i] > maxComputeWorkGroupSizeValue)
{ {
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>(); std::stringstream reasonStream;
reasonStream << "invalid value: Value must be at least 1 and no greater than " reasonStream << "invalid value: Value must be at least 1 and no greater than "
<< maxComputeWorkGroupSizeValue; << maxComputeWorkGroupSizeValue;
const std::string &reason = reasonStream.str(); const std::string &reason = reasonStream.str();
...@@ -3891,7 +3891,7 @@ void TParseContext::checkIsBelowStructNestingLimit(const TSourceLoc &line, const ...@@ -3891,7 +3891,7 @@ void TParseContext::checkIsBelowStructNestingLimit(const TSourceLoc &line, const
// one to the field's struct nesting. // one to the field's struct nesting.
if (1 + field.type()->getDeepestStructNesting() > kWebGLMaxStructNesting) if (1 + field.type()->getDeepestStructNesting() > kWebGLMaxStructNesting)
{ {
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>(); std::stringstream reasonStream;
if (field.type()->getStruct()->symbolType() == SymbolType::Empty) if (field.type()->getStruct()->symbolType() == SymbolType::Empty)
{ {
// This may happen in case there are nested struct definitions. While they are also // This may happen in case there are nested struct definitions. While they are also
...@@ -4085,7 +4085,7 @@ int TParseContext::checkIndexLessThan(bool outOfRangeIndexIsError, ...@@ -4085,7 +4085,7 @@ int TParseContext::checkIndexLessThan(bool outOfRangeIndexIsError,
ASSERT(index >= 0); ASSERT(index >= 0);
if (index >= arraySize) if (index >= arraySize)
{ {
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>(); std::stringstream reasonStream;
reasonStream << reason << " '" << index << "'"; reasonStream << reason << " '" << index << "'";
std::string token = reasonStream.str(); std::string token = reasonStream.str();
outOfRangeError(outOfRangeIndexIsError, location, reason, "[]"); outOfRangeError(outOfRangeIndexIsError, location, reason, "[]");
...@@ -4387,7 +4387,7 @@ void TParseContext::parseLocalSize(const ImmutableString &qualifierType, ...@@ -4387,7 +4387,7 @@ void TParseContext::parseLocalSize(const ImmutableString &qualifierType,
checkLayoutQualifierSupported(qualifierTypeLine, qualifierType, 310); checkLayoutQualifierSupported(qualifierTypeLine, qualifierType, 310);
if (intValue < 1) if (intValue < 1)
{ {
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>(); std::stringstream reasonStream;
reasonStream << "out of range: " << getWorkGroupSizeString(index) << " must be positive"; reasonStream << "out of range: " << getWorkGroupSizeString(index) << " must be positive";
std::string reason = reasonStream.str(); std::string reason = reasonStream.str();
error(intValueLine, reason.c_str(), intValueString.c_str()); error(intValueLine, reason.c_str(), intValueString.c_str());
...@@ -5672,7 +5672,7 @@ void TParseContext::checkTextureOffsetConst(TIntermAggregate *functionCall) ...@@ -5672,7 +5672,7 @@ void TParseContext::checkTextureOffsetConst(TIntermAggregate *functionCall)
int offsetValue = values[i].getIConst(); int offsetValue = values[i].getIConst();
if (offsetValue > maxOffsetValue || offsetValue < minOffsetValue) if (offsetValue > maxOffsetValue || offsetValue < minOffsetValue)
{ {
std::stringstream tokenStream = sh::InitializeStream<std::stringstream>(); std::stringstream tokenStream;
tokenStream << offsetValue; tokenStream << offsetValue;
std::string token = tokenStream.str(); std::string token = tokenStream.str();
error(offset->getLine(), "Texture offset value out of valid range", error(offset->getLine(), "Texture offset value out of valid range",
......
...@@ -115,7 +115,7 @@ void TStructure::createSamplerSymbols(const char *namePrefix, ...@@ -115,7 +115,7 @@ void TStructure::createSamplerSymbols(const char *namePrefix,
const TType *fieldType = field->type(); const TType *fieldType = field->type();
if (IsSampler(fieldType->getBasicType()) || fieldType->isStructureContainingSamplers()) if (IsSampler(fieldType->getBasicType()) || fieldType->isStructureContainingSamplers())
{ {
std::stringstream fieldName = sh::InitializeStream<std::stringstream>(); std::stringstream fieldName;
fieldName << namePrefix << "_" << field->name(); fieldName << namePrefix << "_" << field->name();
TString fieldApiName = apiNamePrefix + "."; TString fieldApiName = apiNamePrefix + ".";
fieldApiName += field->name().data(); fieldApiName += field->name().data();
......
...@@ -756,7 +756,7 @@ void TType::createSamplerSymbols(const ImmutableString &namePrefix, ...@@ -756,7 +756,7 @@ void TType::createSamplerSymbols(const ImmutableString &namePrefix,
elementType.toArrayElementType(); elementType.toArrayElementType();
for (unsigned int arrayIndex = 0u; arrayIndex < getOutermostArraySize(); ++arrayIndex) for (unsigned int arrayIndex = 0u; arrayIndex < getOutermostArraySize(); ++arrayIndex)
{ {
std::stringstream elementName = sh::InitializeStream<std::stringstream>(); std::stringstream elementName;
elementName << namePrefix << "_" << arrayIndex; elementName << namePrefix << "_" << arrayIndex;
TStringStream elementApiName; TStringStream elementApiName;
elementApiName << apiNamePrefix << "[" << arrayIndex << "]"; elementApiName << apiNamePrefix << "[" << arrayIndex << "]";
......
...@@ -119,7 +119,7 @@ void ValidateOutputsTraverser::validate(TDiagnostics *diagnostics) const ...@@ -119,7 +119,7 @@ void ValidateOutputsTraverser::validate(TDiagnostics *diagnostics) const
const size_t offsetLocation = location + elementIndex; const size_t offsetLocation = location + elementIndex;
if ((*validOutputsToUse)[offsetLocation]) if ((*validOutputsToUse)[offsetLocation])
{ {
std::stringstream strstr = sh::InitializeStream<std::stringstream>(); std::stringstream strstr;
strstr << "conflicting output locations with previously defined output '" strstr << "conflicting output locations with previously defined output '"
<< (*validOutputsToUse)[offsetLocation]->getName() << "'"; << (*validOutputsToUse)[offsetLocation]->getName() << "'";
error(*symbol, strstr.str().c_str(), diagnostics); error(*symbol, strstr.str().c_str(), diagnostics);
......
...@@ -83,7 +83,7 @@ void ValidateShaderInterface(TDiagnostics *diagnostics, ...@@ -83,7 +83,7 @@ void ValidateShaderInterface(TDiagnostics *diagnostics,
const int offsetLocation = location + elementIndex; const int offsetLocation = location + elementIndex;
if (locationMap.find(offsetLocation) != locationMap.end()) if (locationMap.find(offsetLocation) != locationMap.end())
{ {
std::stringstream strstr = sh::InitializeStream<std::stringstream>(); std::stringstream strstr;
strstr << "'" << varying->getName() strstr << "'" << varying->getName()
<< "' conflicting location with previously defined '" << "' conflicting location with previously defined '"
<< locationMap[offsetLocation]->getName() << "'"; << locationMap[offsetLocation]->getName() << "'";
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "common/mathutil.h" #include "common/mathutil.h"
#include "common/utilities.h" #include "common/utilities.h"
#include "compiler/translator/Common.h"
namespace sh namespace sh
{ {
...@@ -133,7 +132,7 @@ void TraverseArrayOfArraysVariable(const ShaderVariable &variable, ...@@ -133,7 +132,7 @@ void TraverseArrayOfArraysVariable(const ShaderVariable &variable,
std::string CollapseNameStack(const std::vector<std::string> &nameStack) std::string CollapseNameStack(const std::vector<std::string> &nameStack)
{ {
std::stringstream strstr = sh::InitializeStream<std::stringstream>(); std::stringstream strstr;
for (const std::string &part : nameStack) for (const std::string &part : nameStack)
{ {
strstr << part; strstr << part;
...@@ -416,7 +415,7 @@ void VariableNameVisitor::exitArray(const ShaderVariable &arrayVar) ...@@ -416,7 +415,7 @@ void VariableNameVisitor::exitArray(const ShaderVariable &arrayVar)
void VariableNameVisitor::enterArrayElement(const ShaderVariable &arrayVar, void VariableNameVisitor::enterArrayElement(const ShaderVariable &arrayVar,
unsigned int arrayElement) unsigned int arrayElement)
{ {
std::stringstream strstr = sh::InitializeStream<std::stringstream>(); std::stringstream strstr;
strstr << "[" << arrayElement << "]"; strstr << "[" << arrayElement << "]";
std::string elementString = strstr.str(); std::string elementString = strstr.str();
mNameStack.push_back(elementString); mNameStack.push_back(elementString);
......
...@@ -174,7 +174,7 @@ std::string RoundingHelperWriterGLSL::getTypeString(const char *glslType) ...@@ -174,7 +174,7 @@ std::string RoundingHelperWriterGLSL::getTypeString(const char *glslType)
std::string RoundingHelperWriterESSL::getTypeString(const char *glslType) std::string RoundingHelperWriterESSL::getTypeString(const char *glslType)
{ {
std::stringstream typeStrStr = sh::InitializeStream<std::stringstream>(); std::stringstream typeStrStr;
typeStrStr << "highp " << glslType; typeStrStr << "highp " << glslType;
return typeStrStr.str(); return typeStrStr.str();
} }
...@@ -257,7 +257,7 @@ void RoundingHelperWriterGLSL::writeFloatRoundingHelpers(TInfoSinkBase &sink) ...@@ -257,7 +257,7 @@ void RoundingHelperWriterGLSL::writeFloatRoundingHelpers(TInfoSinkBase &sink)
void RoundingHelperWriterGLSL::writeVectorRoundingHelpers(TInfoSinkBase &sink, void RoundingHelperWriterGLSL::writeVectorRoundingHelpers(TInfoSinkBase &sink,
const unsigned int size) const unsigned int size)
{ {
std::stringstream vecTypeStrStr = sh::InitializeStream<std::stringstream>(); std::stringstream vecTypeStrStr;
vecTypeStrStr << "vec" << size; vecTypeStrStr << "vec" << size;
std::string vecType = getTypeString(vecTypeStrStr.str().c_str()); std::string vecType = getTypeString(vecTypeStrStr.str().c_str());
...@@ -287,7 +287,7 @@ void RoundingHelperWriterGLSL::writeMatrixRoundingHelper(TInfoSinkBase &sink, ...@@ -287,7 +287,7 @@ void RoundingHelperWriterGLSL::writeMatrixRoundingHelper(TInfoSinkBase &sink,
const unsigned int rows, const unsigned int rows,
const char *functionName) const char *functionName)
{ {
std::stringstream matTypeStrStr = sh::InitializeStream<std::stringstream>(); std::stringstream matTypeStrStr;
matTypeStrStr << "mat" << columns; matTypeStrStr << "mat" << columns;
if (rows != columns) if (rows != columns)
{ {
...@@ -379,7 +379,7 @@ void RoundingHelperWriterHLSL::writeFloatRoundingHelpers(TInfoSinkBase &sink) ...@@ -379,7 +379,7 @@ void RoundingHelperWriterHLSL::writeFloatRoundingHelpers(TInfoSinkBase &sink)
void RoundingHelperWriterHLSL::writeVectorRoundingHelpers(TInfoSinkBase &sink, void RoundingHelperWriterHLSL::writeVectorRoundingHelpers(TInfoSinkBase &sink,
const unsigned int size) const unsigned int size)
{ {
std::stringstream vecTypeStrStr = sh::InitializeStream<std::stringstream>(); std::stringstream vecTypeStrStr;
vecTypeStrStr << "float" << size; vecTypeStrStr << "float" << size;
std::string vecType = vecTypeStrStr.str(); std::string vecType = vecTypeStrStr.str();
...@@ -409,7 +409,7 @@ void RoundingHelperWriterHLSL::writeMatrixRoundingHelper(TInfoSinkBase &sink, ...@@ -409,7 +409,7 @@ void RoundingHelperWriterHLSL::writeMatrixRoundingHelper(TInfoSinkBase &sink,
const unsigned int rows, const unsigned int rows,
const char *functionName) const char *functionName)
{ {
std::stringstream matTypeStrStr = sh::InitializeStream<std::stringstream>(); std::stringstream matTypeStrStr;
matTypeStrStr << "float" << columns << "x" << rows; matTypeStrStr << "float" << columns << "x" << rows;
std::string matType = matTypeStrStr.str(); std::string matType = matTypeStrStr.str();
...@@ -744,7 +744,7 @@ TIntermAggregate *EmulatePrecision::createCompoundAssignmentFunctionCallNode(TIn ...@@ -744,7 +744,7 @@ TIntermAggregate *EmulatePrecision::createCompoundAssignmentFunctionCallNode(TIn
TIntermTyped *right, TIntermTyped *right,
const char *opNameStr) const char *opNameStr)
{ {
std::stringstream strstr = sh::InitializeStream<std::stringstream>(); std::stringstream strstr;
if (left->getPrecision() == EbpMedium) if (left->getPrecision() == EbpMedium)
strstr << "angle_compound_" << opNameStr << "_frm"; strstr << "angle_compound_" << opNameStr << "_frm";
else else
......
...@@ -117,59 +117,39 @@ TEST_F(ShCompileTest, TokensSplitInShaderStrings) ...@@ -117,59 +117,39 @@ TEST_F(ShCompileTest, TokensSplitInShaderStrings)
} }
// Parsing floats in shaders can run afoul of locale settings. // Parsing floats in shaders can run afoul of locale settings.
// Eg. in de_DE, `strtof("1.9")` will yield `1.0f`. (It's expecting "1,9") // In de_DE, `strtof("1.9")` will yield `1.0f`. (It's expecting "1,9")
TEST_F(ShCompileTest, DecimalSepLocale) TEST_F(ShCompileTest, DecimalSepLocale)
{ {
// Locale names are platform dependent, add platform-specific names of locales to be tested here const auto defaultLocale = setlocale(LC_NUMERIC, nullptr);
const std::string availableLocales[] = {
"de_DE", "de-DE", "de_DE.UTF-8", "de_DE.ISO8859-1", "de_DE.ISO8859-15", "de_DE@euro", const auto fnSetLocale = [](const char *const name) {
"de_DE.88591", "de_DE.88591.en", "de_DE.iso88591", "de_DE.ISO-8859-1", "de_DE.ISO_8859-1", return bool(setlocale(LC_NUMERIC, name));
"de_DE.iso885915", "de_DE.ISO-8859-15", "de_DE.ISO_8859-15", "de_DE.8859-15",
"de_DE.8859-15@euro", "de_DE.ISO-8859-15@euro", "de_DE.UTF-8@euro", "de_DE.utf8",
"German_germany", "German_Germany", "German_Germany.1252", "German_Germany.UTF-8", "German",
// One ubuntu tester doesn't have a german locale, but da_DK.utf8 has similar float
// representation
"da_DK.utf8"};
const auto localeExists = [](const std::string name) {
return bool(setlocale(LC_ALL, name.c_str()));
}; };
const char kSource[] = R"( const bool setLocaleToDe =
void main() fnSetLocale("de_DE") || fnSetLocale("de-DE"); // Windows doesn't like de_DE.
{
gl_FragColor = vec4(1.9);
})";
const char *parts[] = {kSource};
for (const std::string &locale : availableLocales) // These configs don't support de_DE: android_angle_vk[32,64]_rel_ng, linux_angle_rel_ng
// Just allow those platforms to quietly fail, but require other platforms to succeed.
#if defined(ANGLE_PLATFORM_ANDROID) || defined(ANGLE_PLATFORM_LINUX)
if (!setLocaleToDe)
{ {
// If the locale doesn't exist on the testing platform, the locale constructor will fail, return;
// throwing an exception
// We use setlocale() (through localeExists) to test whether a locale
// exists before calling the locale constructor
if (localeExists(locale))
{
std::locale localizedLoc(locale);
// std::locale::global() must be used instead of setlocale() to affect new streams'
// default locale
std::locale::global(std::locale::classic());
sh::Compile(mCompiler, parts, 1, SH_OBJECT_CODE);
std::string referenceOut = sh::GetObjectCode(mCompiler);
EXPECT_NE(referenceOut.find("1.9"), std::string::npos)
<< "float formatted incorrectly with classic locale";
sh::ClearResults(mCompiler);
std::locale::global(localizedLoc);
sh::Compile(mCompiler, parts, 1, SH_OBJECT_CODE);
std::string localizedOut = sh::GetObjectCode(mCompiler);
EXPECT_NE(localizedOut.find("1.9"), std::string::npos)
<< "float formatted incorrectly with locale (" << localizedLoc.name() << ") set";
ASSERT_EQ(referenceOut, localizedOut)
<< "different output with locale (" << localizedLoc.name() << ") set";
}
} }
} #endif
\ No newline at end of file ASSERT_TRUE(setLocaleToDe);
const char kSource[] = R"(
void main()
{
gl_FragColor = vec4(1.9);
})";
const char *parts[] = {kSource};
testCompile(parts, 1, true);
const auto &translated = sh::GetObjectCode(mCompiler);
// printf("%s\n", translated.data());
EXPECT_NE(translated.find("1.9"), std::string::npos);
fnSetLocale(defaultLocale);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment