Hash :
ab71d751
Author :
Date :
2024-02-07T14:25:32
Fix an assert on multidim array constructors Fail early instead of asserting when trying to parse a multidimensional array constructor call with unsized argument array argument. int A[]; int B[int[][](A)]; Bug: angleproject:8519 Change-Id: Iee2c70318eebd2def57ffab8db709d1076692922 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5272434 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
//
// Copyright 2024 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Parse_test.cpp:
// Test for parsing erroneous and correct GLSL input.
//
#include "GLSLANG/ShaderLang.h"
#include "angle_gl.h"
#include "compiler/translator/glsl/TranslatorESSL.h"
#include "gtest/gtest.h"
using namespace sh;
class ParseTest : public testing::Test
{
public:
ParseTest() {}
protected:
void SetUp() override
{
ShBuiltInResources resources;
InitBuiltInResources(&resources);
resources.FragmentPrecisionHigh = 1;
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
void TearDown() override { delete mTranslator; }
testing::AssertionResult compile(const std::string &shaderString)
{
ShCompileOptions compileOptions = {};
compileOptions.intermediateTree = true;
const char *shaderStrings[] = {shaderString.c_str()};
bool compilationSuccess = mTranslator->compile(shaderStrings, 1, compileOptions);
TInfoSink &infoSink = mTranslator->getInfoSink();
mInfoLog = RemoveSymbolIdsFromInfoLog(infoSink.info.c_str());
if (!compilationSuccess)
{
return testing::AssertionFailure() << "Shader compilation failed " << mInfoLog;
}
return testing::AssertionSuccess();
}
bool foundErrorInIntermediateTree() const { return foundInIntermediateTree("ERROR:"); }
bool foundInIntermediateTree(const char *stringToFind) const
{
return mInfoLog.find(stringToFind) != std::string::npos;
}
private:
// Remove symbol ids from info log - the tests don't care about them.
static std::string RemoveSymbolIdsFromInfoLog(const char *infoLog)
{
std::string filteredLog(infoLog);
size_t idPrefixPos = 0u;
do
{
idPrefixPos = filteredLog.find(" (symbol id");
if (idPrefixPos != std::string::npos)
{
size_t idSuffixPos = filteredLog.find(")", idPrefixPos);
filteredLog.erase(idPrefixPos, idSuffixPos - idPrefixPos + 1u);
}
} while (idPrefixPos != std::string::npos);
return filteredLog;
}
TranslatorESSL *mTranslator;
std::string mInfoLog;
};
TEST_F(ParseTest, UnsizedArrayConstructorNoCrash)
{
const char kShader[] = R"(#version 310 es\n"
int A[];
int B[int[][](A)];)";
EXPECT_FALSE(compile(kShader));
EXPECT_TRUE(foundErrorInIntermediateTree());
EXPECT_TRUE(foundInIntermediateTree("constructing from an unsized array"));
}