Skip to content

Commit

Permalink
Reland "Fix unit test for setting locale creating malformed HLSL shad…
Browse files Browse the repository at this point in the history
…er code

Fix malformed HLSL shader code in other locales than classic"

This is a reland of 5f662c0

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>

Bug: angleproject:1433
Change-Id: I94caf7b4c7179119e5a5567c3014d7232df45a13
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1516192
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Jonah Ryan-Davis <jonahr@google.com>
  • Loading branch information
jonahryandavis authored and Commit Bot committed Mar 11, 2019
1 parent 49c9dfe commit f563fdc
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 67 deletions.
3 changes: 2 additions & 1 deletion src/compiler/translator/AtomicCounterFunctionHLSL.cpp
Expand Up @@ -9,6 +9,7 @@

#include "compiler/translator/AtomicCounterFunctionHLSL.h"

#include "compiler/translator/Common.h"
#include "compiler/translator/ImmutableStringBuilder.h"
#include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h"
Expand Down Expand Up @@ -92,7 +93,7 @@ void AtomicCounterFunctionHLSL::atomicCounterFunctionHeader(TInfoSinkBase &out)

ImmutableString getAtomicCounterNameForBinding(int binding)
{
std::stringstream counterName;
std::stringstream counterName = sh::InitializeStream<std::stringstream>();
counterName << kAtomicCounterBaseName << binding;
return ImmutableString(counterName.str());
}
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/translator/BuiltInFunctionEmulatorGLSL.cpp
Expand Up @@ -5,6 +5,7 @@
//

#include "compiler/translator/BuiltInFunctionEmulatorGLSL.h"

#include "angle_gl.h"
#include "compiler/translator/BuiltInFunctionEmulator.h"
#include "compiler/translator/VersionGLSL.h"
Expand Down Expand Up @@ -87,7 +88,7 @@ void InitBuiltInAtanFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *
};
for (int dim = 2; dim <= 4; ++dim)
{
std::stringstream ss;
std::stringstream ss = sh::InitializeStream<std::stringstream>();
ss << "emu_precision vec" << dim << " atan_emu(emu_precision vec" << dim
<< " y, emu_precision vec" << dim << " x)\n"
<< "{\n"
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/translator/CallDAG.cpp
Expand Up @@ -171,7 +171,7 @@ class CallDAG::CallDAGCreator : public TIntermTraverser

InitResult result = INITDAG_SUCCESS;

std::stringstream errorStream;
std::stringstream errorStream = sh::InitializeStream<std::stringstream>();

while (!functionsToProcess.empty())
{
Expand Down
9 changes: 9 additions & 0 deletions src/compiler/translator/Common.h
Expand Up @@ -125,6 +125,15 @@ inline const char *AllocatePoolCharArray(const char *str, size_t strLength)
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 std
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/translator/Compiler.cpp
Expand Up @@ -68,7 +68,7 @@ void DumpFuzzerCase(char const *const *shaderStrings,
{
static int fileIndex = 0;

std::ostringstream o;
std::ostringstream o = sh::InitializeStream<std::ostringstream>();
o << "corpus/" << fileIndex++ << ".sample";
std::string s = o.str();

Expand Down Expand Up @@ -940,7 +940,7 @@ bool TCompiler::initBuiltInSymbolTable(const ShBuiltInResources &resources)

void TCompiler::setResourceString()
{
std::ostringstream strstream;
std::ostringstream strstream = sh::InitializeStream<std::ostringstream>();

// clang-format off
strstream << ":MaxVertexAttribs:" << mResources.MaxVertexAttribs
Expand Down Expand Up @@ -1094,7 +1094,7 @@ bool TCompiler::checkCallDepth()

for (size_t i = 0; i < mCallDag.size(); i++)
{
int depth = 0;
int depth = 0;
const CallDAG::Record &record = mCallDag.getRecordFromIndex(i);

for (const int &calleeIndex : record.callees)
Expand All @@ -1107,7 +1107,7 @@ bool TCompiler::checkCallDepth()
if (depth >= mResources.MaxCallStackDepth)
{
// Trace back the function chain to have a meaningful info log.
std::stringstream errorStream;
std::stringstream errorStream = sh::InitializeStream<std::stringstream>();
errorStream << "Call stack too deep (larger than " << mResources.MaxCallStackDepth
<< ") with the following call chain: "
<< record.node->getFunction()->name();
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/translator/DirectiveHandler.cpp
Expand Up @@ -10,6 +10,7 @@

#include "angle_gl.h"
#include "common/debug.h"
#include "compiler/translator/Common.h"
#include "compiler/translator/Diagnostics.h"

namespace sh
Expand Down Expand Up @@ -190,7 +191,7 @@ void TDirectiveHandler::handleVersion(const angle::pp::SourceLocation &loc, int
}
else
{
std::stringstream stream;
std::stringstream stream = sh::InitializeStream<std::stringstream>();
stream << version;
std::string str = stream.str();
mDiagnostics.error(loc, "version number not supported", str.c_str());
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/translator/InfoSink.cpp
Expand Up @@ -69,7 +69,7 @@ TInfoSinkBase &TInfoSinkBase::operator<<(const TType &type)

void TInfoSinkBase::location(int file, int line)
{
TPersistStringStream stream;
TPersistStringStream stream = sh::InitializeStream<TPersistStringStream>();
if (line)
stream << file << ":" << line;
else
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/translator/InfoSink.h
Expand Up @@ -41,7 +41,7 @@ class TInfoSinkBase
template <typename T>
TInfoSinkBase &operator<<(const T &t)
{
TPersistStringStream stream;
TPersistStringStream stream = sh::InitializeStream<TPersistStringStream>();
stream << t;
sink.append(stream.str());
return *this;
Expand Down Expand Up @@ -79,7 +79,7 @@ class TInfoSinkBase
// does not have a fractional part, the default precision format does
// not write the decimal portion which gets interpreted as integer by
// the compiler.
TPersistStringStream stream;
TPersistStringStream stream = sh::InitializeStream<TPersistStringStream>();
if (fractionalPart(f) == 0.0f)
{
stream.precision(1);
Expand Down
20 changes: 10 additions & 10 deletions src/compiler/translator/OutputHLSL.cpp
Expand Up @@ -39,7 +39,7 @@ constexpr const char kImage2DFunctionString[] = "// @@ IMAGE2D DECLARATION FUNCT

TString ArrayHelperFunctionName(const char *prefix, const TType &type)
{
TStringStream fnName;
TStringStream fnName = sh::InitializeStream<TStringStream>();
fnName << prefix << "_";
if (type.isArray())
{
Expand Down Expand Up @@ -132,7 +132,7 @@ const char *kZeros = "_ANGLE_ZEROS_";
constexpr int kZeroCount = 256;
std::string DefineZeroArray()
{
std::stringstream ss;
std::stringstream ss = sh::InitializeStream<std::stringstream>();
// 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
ss << "static uint " << kZeros << "[" << kZeroCount << "];\n";
Expand All @@ -141,9 +141,9 @@ std::string DefineZeroArray()

std::string GetZeroInitializer(size_t size)
{
std::stringstream ss;
size_t quotient = size / kZeroCount;
size_t reminder = size % kZeroCount;
std::stringstream ss = sh::InitializeStream<std::stringstream>();
size_t quotient = size / kZeroCount;
size_t reminder = size % kZeroCount;

for (size_t i = 0; i < quotient; ++i)
{
Expand Down Expand Up @@ -416,7 +416,7 @@ TString OutputHLSL::structInitializerString(int indent,
init += indentString + "{\n";
for (unsigned int arrayIndex = 0u; arrayIndex < type.getOutermostArraySize(); ++arrayIndex)
{
TStringStream indexedString;
TStringStream indexedString = sh::InitializeStream<TStringStream>();
indexedString << name << "[" << arrayIndex << "]";
TType elementType = type;
elementType.toArrayElementType();
Expand Down Expand Up @@ -891,8 +891,8 @@ void OutputHLSL::header(TInfoSinkBase &out,

out << kImage2DFunctionString << "\n";

std::ostringstream systemValueDeclaration;
std::ostringstream glBuiltinInitialization;
std::ostringstream systemValueDeclaration = sh::InitializeStream<std::ostringstream>();
std::ostringstream glBuiltinInitialization = sh::InitializeStream<std::ostringstream>();

systemValueDeclaration << "\nstruct CS_INPUT\n{\n";
glBuiltinInitialization << "\nvoid initGLBuiltins(CS_INPUT input)\n"
Expand Down Expand Up @@ -1900,7 +1900,7 @@ ImmutableString OutputHLSL::samplerNamePrefixFromStruct(TIntermTyped *node)
{
int index = nodeBinary->getRight()->getAsConstantUnion()->getIConst(0);

std::stringstream prefixSink;
std::stringstream prefixSink = sh::InitializeStream<std::stringstream>();
prefixSink << samplerNamePrefixFromStruct(nodeBinary->getLeft()) << "_" << index;
return ImmutableString(prefixSink.str());
}
Expand All @@ -1910,7 +1910,7 @@ ImmutableString OutputHLSL::samplerNamePrefixFromStruct(TIntermTyped *node)
int index = nodeBinary->getRight()->getAsConstantUnion()->getIConst(0);
const TField *field = s->fields()[index];

std::stringstream prefixSink;
std::stringstream prefixSink = sh::InitializeStream<std::stringstream>();
prefixSink << samplerNamePrefixFromStruct(nodeBinary->getLeft()) << "_"
<< field->name();
return ImmutableString(prefixSink.str());
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/translator/ParseContext.cpp
Expand Up @@ -611,7 +611,7 @@ bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIn
return true;
}

std::stringstream reasonStream;
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>();
reasonStream << "l-value required";
if (!message.empty())
{
Expand Down Expand Up @@ -902,7 +902,7 @@ bool TParseContext::checkIsNotOpaqueType(const TSourceLoc &line,
{
if (ContainsSampler(pType.userDef))
{
std::stringstream reasonStream;
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>();
reasonStream << reason << " (structure contains a sampler)";
std::string reasonStr = reasonStream.str();
error(line, reasonStr.c_str(), getBasicString(pType.type));
Expand Down Expand Up @@ -3066,7 +3066,7 @@ void TParseContext::parseGlobalLayoutQualifier(const TTypeQualifierBuilder &type
if (mComputeShaderLocalSize[i] < 1 ||
mComputeShaderLocalSize[i] > maxComputeWorkGroupSizeValue)
{
std::stringstream reasonStream;
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>();
reasonStream << "invalid value: Value must be at least 1 and no greater than "
<< maxComputeWorkGroupSizeValue;
const std::string &reason = reasonStream.str();
Expand Down Expand Up @@ -3891,7 +3891,7 @@ void TParseContext::checkIsBelowStructNestingLimit(const TSourceLoc &line, const
// one to the field's struct nesting.
if (1 + field.type()->getDeepestStructNesting() > kWebGLMaxStructNesting)
{
std::stringstream reasonStream;
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>();
if (field.type()->getStruct()->symbolType() == SymbolType::Empty)
{
// This may happen in case there are nested struct definitions. While they are also
Expand Down Expand Up @@ -4085,7 +4085,7 @@ int TParseContext::checkIndexLessThan(bool outOfRangeIndexIsError,
ASSERT(index >= 0);
if (index >= arraySize)
{
std::stringstream reasonStream;
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>();
reasonStream << reason << " '" << index << "'";
std::string token = reasonStream.str();
outOfRangeError(outOfRangeIndexIsError, location, reason, "[]");
Expand Down Expand Up @@ -4387,7 +4387,7 @@ void TParseContext::parseLocalSize(const ImmutableString &qualifierType,
checkLayoutQualifierSupported(qualifierTypeLine, qualifierType, 310);
if (intValue < 1)
{
std::stringstream reasonStream;
std::stringstream reasonStream = sh::InitializeStream<std::stringstream>();
reasonStream << "out of range: " << getWorkGroupSizeString(index) << " must be positive";
std::string reason = reasonStream.str();
error(intValueLine, reason.c_str(), intValueString.c_str());
Expand Down Expand Up @@ -5672,7 +5672,7 @@ void TParseContext::checkTextureOffsetConst(TIntermAggregate *functionCall)
int offsetValue = values[i].getIConst();
if (offsetValue > maxOffsetValue || offsetValue < minOffsetValue)
{
std::stringstream tokenStream;
std::stringstream tokenStream = sh::InitializeStream<std::stringstream>();
tokenStream << offsetValue;
std::string token = tokenStream.str();
error(offset->getLine(), "Texture offset value out of valid range",
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/translator/Symbol.cpp
Expand Up @@ -115,7 +115,7 @@ void TStructure::createSamplerSymbols(const char *namePrefix,
const TType *fieldType = field->type();
if (IsSampler(fieldType->getBasicType()) || fieldType->isStructureContainingSamplers())
{
std::stringstream fieldName;
std::stringstream fieldName = sh::InitializeStream<std::stringstream>();
fieldName << namePrefix << "_" << field->name();
TString fieldApiName = apiNamePrefix + ".";
fieldApiName += field->name().data();
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/translator/Types.cpp
Expand Up @@ -756,7 +756,7 @@ void TType::createSamplerSymbols(const ImmutableString &namePrefix,
elementType.toArrayElementType();
for (unsigned int arrayIndex = 0u; arrayIndex < getOutermostArraySize(); ++arrayIndex)
{
std::stringstream elementName;
std::stringstream elementName = sh::InitializeStream<std::stringstream>();
elementName << namePrefix << "_" << arrayIndex;
TStringStream elementApiName;
elementApiName << apiNamePrefix << "[" << arrayIndex << "]";
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/translator/ValidateOutputs.cpp
Expand Up @@ -119,7 +119,7 @@ void ValidateOutputsTraverser::validate(TDiagnostics *diagnostics) const
const size_t offsetLocation = location + elementIndex;
if ((*validOutputsToUse)[offsetLocation])
{
std::stringstream strstr;
std::stringstream strstr = sh::InitializeStream<std::stringstream>();
strstr << "conflicting output locations with previously defined output '"
<< (*validOutputsToUse)[offsetLocation]->getName() << "'";
error(*symbol, strstr.str().c_str(), diagnostics);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/translator/ValidateVaryingLocations.cpp
Expand Up @@ -83,7 +83,7 @@ void ValidateShaderInterface(TDiagnostics *diagnostics,
const int offsetLocation = location + elementIndex;
if (locationMap.find(offsetLocation) != locationMap.end())
{
std::stringstream strstr;
std::stringstream strstr = sh::InitializeStream<std::stringstream>();
strstr << "'" << varying->getName()
<< "' conflicting location with previously defined '"
<< locationMap[offsetLocation]->getName() << "'";
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/translator/blocklayout.cpp
Expand Up @@ -11,6 +11,7 @@

#include "common/mathutil.h"
#include "common/utilities.h"
#include "compiler/translator/Common.h"

namespace sh
{
Expand Down Expand Up @@ -132,7 +133,7 @@ void TraverseArrayOfArraysVariable(const ShaderVariable &variable,

std::string CollapseNameStack(const std::vector<std::string> &nameStack)
{
std::stringstream strstr;
std::stringstream strstr = sh::InitializeStream<std::stringstream>();
for (const std::string &part : nameStack)
{
strstr << part;
Expand Down Expand Up @@ -415,7 +416,7 @@ void VariableNameVisitor::exitArray(const ShaderVariable &arrayVar)
void VariableNameVisitor::enterArrayElement(const ShaderVariable &arrayVar,
unsigned int arrayElement)
{
std::stringstream strstr;
std::stringstream strstr = sh::InitializeStream<std::stringstream>();
strstr << "[" << arrayElement << "]";
std::string elementString = strstr.str();
mNameStack.push_back(elementString);
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/translator/tree_ops/EmulatePrecision.cpp
Expand Up @@ -174,7 +174,7 @@ std::string RoundingHelperWriterGLSL::getTypeString(const char *glslType)

std::string RoundingHelperWriterESSL::getTypeString(const char *glslType)
{
std::stringstream typeStrStr;
std::stringstream typeStrStr = sh::InitializeStream<std::stringstream>();
typeStrStr << "highp " << glslType;
return typeStrStr.str();
}
Expand Down Expand Up @@ -257,7 +257,7 @@ void RoundingHelperWriterGLSL::writeFloatRoundingHelpers(TInfoSinkBase &sink)
void RoundingHelperWriterGLSL::writeVectorRoundingHelpers(TInfoSinkBase &sink,
const unsigned int size)
{
std::stringstream vecTypeStrStr;
std::stringstream vecTypeStrStr = sh::InitializeStream<std::stringstream>();
vecTypeStrStr << "vec" << size;
std::string vecType = getTypeString(vecTypeStrStr.str().c_str());

Expand Down Expand Up @@ -287,7 +287,7 @@ void RoundingHelperWriterGLSL::writeMatrixRoundingHelper(TInfoSinkBase &sink,
const unsigned int rows,
const char *functionName)
{
std::stringstream matTypeStrStr;
std::stringstream matTypeStrStr = sh::InitializeStream<std::stringstream>();
matTypeStrStr << "mat" << columns;
if (rows != columns)
{
Expand Down Expand Up @@ -379,7 +379,7 @@ void RoundingHelperWriterHLSL::writeFloatRoundingHelpers(TInfoSinkBase &sink)
void RoundingHelperWriterHLSL::writeVectorRoundingHelpers(TInfoSinkBase &sink,
const unsigned int size)
{
std::stringstream vecTypeStrStr;
std::stringstream vecTypeStrStr = sh::InitializeStream<std::stringstream>();
vecTypeStrStr << "float" << size;
std::string vecType = vecTypeStrStr.str();

Expand Down Expand Up @@ -409,7 +409,7 @@ void RoundingHelperWriterHLSL::writeMatrixRoundingHelper(TInfoSinkBase &sink,
const unsigned int rows,
const char *functionName)
{
std::stringstream matTypeStrStr;
std::stringstream matTypeStrStr = sh::InitializeStream<std::stringstream>();
matTypeStrStr << "float" << columns << "x" << rows;
std::string matType = matTypeStrStr.str();

Expand Down Expand Up @@ -744,7 +744,7 @@ TIntermAggregate *EmulatePrecision::createCompoundAssignmentFunctionCallNode(TIn
TIntermTyped *right,
const char *opNameStr)
{
std::stringstream strstr;
std::stringstream strstr = sh::InitializeStream<std::stringstream>();
if (left->getPrecision() == EbpMedium)
strstr << "angle_compound_" << opNameStr << "_frm";
else
Expand Down

0 comments on commit f563fdc

Please sign in to comment.