Hash :
25390156
        
        Author :
  
        
        Date :
2025-08-21T00:13:19
        
      
Suppress unsafe buffers on a file-by-file basis in src/ [1 of N] In this CL, we suppress many files but stop short of actually enabling the warning by not removing the line from the unsafe_buffers_paths.txt file. That will happen in a follow-on CL, along with resolving any stragglers missed here. This is mostly a manual change so as to familiarize myself with the kinds of issues faced by the Angle codebase when applying buffer safety warnings. -- Re-generate affected hashes. -- Clang-format applied to all changed files. -- Add a few missing .reserve() calls to vectors as noticed. -- Fix some mismatches between file names and header comments. -- Be more consistent with header comment format (blank lines and trailing //-only lines when a filename comment adjoins license boilerplate). Bug: b/436880895 Change-Id: I3bde5cc2059acbe8345057289214f1a26f1c34aa Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6869022 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> 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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
//
// Copyright 2002 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.
//
#ifdef UNSAFE_BUFFERS_BUILD
#    pragma allow_unsafe_libc_calls
#endif
#include <sstream>
#include <string>
#include <vector>
#include "GLSLANG/ShaderLang.h"
#include "angle_gl.h"
#include "gtest/gtest.h"
class ExpressionLimitTest : public testing::Test
{
  protected:
    static const int kMaxExpressionComplexity = 16;
    static const int kMaxCallStackDepth       = 16;
    static const int kMaxFunctionParameters   = 16;
    virtual void SetUp()
    {
        memset(&resources, 0, sizeof(resources));
        GenerateResources(&resources);
    }
    // Set up the per compile resources
    static void GenerateResources(ShBuiltInResources *res)
    {
        sh::InitBuiltInResources(res);
        res->MaxVertexAttribs             = 8;
        res->MaxVertexUniformVectors      = 128;
        res->MaxVaryingVectors            = 8;
        res->MaxVertexTextureImageUnits   = 0;
        res->MaxCombinedTextureImageUnits = 8;
        res->MaxTextureImageUnits         = 8;
        res->MaxFragmentUniformVectors    = 16;
        res->MaxDrawBuffers               = 1;
        res->OES_standard_derivatives = 0;
        res->OES_EGL_image_external   = 0;
        res->MaxExpressionComplexity = kMaxExpressionComplexity;
        res->MaxCallStackDepth       = kMaxCallStackDepth;
        res->MaxFunctionParameters   = kMaxFunctionParameters;
    }
    static void GenerateLongExpression(int length, std::stringstream *ss)
    {
        for (int ii = 0; ii < length; ++ii)
        {
            *ss << "+ vec4(" << ii << ")";
        }
    }
    static std::string GenerateShaderWithLongExpression(int length)
    {
        static const char *shaderStart =
            R"(precision mediump float;
            uniform vec4 u_color;
            void main()
            {
               gl_FragColor = u_color
        )";
        std::stringstream ss;
        ss << shaderStart;
        GenerateLongExpression(length, &ss);
        ss << "; }";
        return ss.str();
    }
    static std::string GenerateShaderWithUnusedLongExpression(int length)
    {
        static const char *shaderStart =
            R"(precision mediump float;
            uniform vec4 u_color;
            void main()
            {
               gl_FragColor = u_color;
            }
            vec4 someFunction() {
              return u_color
        )";
        std::stringstream ss;
        ss << shaderStart;
        GenerateLongExpression(length, &ss);
        ss << "; }";
        return ss.str();
    }
    static void GenerateDeepFunctionStack(int length, std::stringstream *ss)
    {
        static const char *shaderStart =
            R"(precision mediump float;
            uniform vec4 u_color;
            vec4 function0()  {
              return u_color;
            }
        )";
        *ss << shaderStart;
        for (int ii = 0; ii < length; ++ii)
        {
            *ss << "vec4 function" << (ii + 1) << "() {\n"
                << "  return function" << ii << "();\n"
                << "}\n";
        }
    }
    static std::string GenerateShaderWithDeepFunctionStack(int length)
    {
        std::stringstream ss;
        GenerateDeepFunctionStack(length, &ss);
        ss << "void main() {\n" << "  gl_FragColor = function" << length << "();\n" << "}";
        return ss.str();
    }
    static std::string GenerateShaderWithUnusedDeepFunctionStack(int length)
    {
        std::stringstream ss;
        GenerateDeepFunctionStack(length, &ss);
        ss << "void main() {\n" << "  gl_FragColor = vec4(0,0,0,0);\n" << "}";
        return ss.str();
    }
    static std::string GenerateShaderWithFunctionParameters(int parameters)
    {
        std::stringstream ss;
        ss << "precision mediump float;\n" << "\n" << "float foo(";
        for (int i = 0; i < parameters; ++i)
        {
            ss << "float f" << i;
            if (i + 1 < parameters)
            {
                ss << ", ";
            }
        }
        ss << ")\n"
           << "{\n"
           << "    return f0;\n"
           << "}\n"
           << "\n"
           << "void main()\n"
           << "{\n"
           << "    gl_FragColor = vec4(0,0,0,0);\n"
           << "}";
        return ss.str();
    }
    static std::string GenerateShaderWithNestingInsideSwitch(int nesting)
    {
        std::stringstream shaderString;
        shaderString <<
            R"(#version 300 es
            uniform int u;
            void main()
            {
                int x;
                switch (u)
                {
                    case 0:
                        x = x)";
        for (int i = 0; i < nesting; ++i)
        {
            shaderString << " + x";
        }
        shaderString <<
            R"(;
                }  // switch (u)
            })";
        return shaderString.str();
    }
    static std::string GenerateShaderWithNestingInsideGlobalInitializer(int nesting)
    {
        std::stringstream shaderString;
        shaderString <<
            R"(uniform int u;
            int x = u)";
        for (int i = 0; i < nesting; ++i)
        {
            shaderString << " + u";
        }
        shaderString << R"(;
            void main()
            {
                gl_FragColor = vec4(0.0);
            })";
        return shaderString.str();
    }
    // Compiles a shader and if there's an error checks for a specific
    // substring in the error log. This way we know the error is specific
    // to the issue we are testing.
    bool CheckShaderCompilation(ShHandle compiler,
                                const char *source,
                                const ShCompileOptions &compileOptions,
                                const char *expected_error)
    {
        bool success = sh::Compile(compiler, &source, 1, compileOptions) != 0;
        if (success)
        {
            success = !expected_error;
        }
        else
        {
            std::string log = sh::GetInfoLog(compiler);
            if (expected_error)
                success = log.find(expected_error) != std::string::npos;
            EXPECT_TRUE(success) << log << "\n----shader----\n" << source;
        }
        return success;
    }
    ShBuiltInResources resources;
};
constexpr char kExpressionTooComplex[] = "Expression too complex";
constexpr char kCallStackTooDeep[]     = "Call stack too deep";
constexpr char kHasRecursion[]         = "Recursive function call in the following call chain";
constexpr char kTooManyParameters[]    = "Function has too many parameters";
constexpr char kTooComplexSwitch[]     = "too complex expressions inside a switch statement";
constexpr char kGlobalVariableInit[] = "global variable initializers must be constant expressions";
constexpr char kTooManyFields[]      = "Too many fields in the struct";
TEST_F(ExpressionLimitTest, ExpressionComplexity)
{
    ShShaderSpec spec       = SH_WEBGL_SPEC;
    ShShaderOutput output   = SH_ESSL_OUTPUT;
    ShHandle vertexCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
    ShCompileOptions compileOptions          = {};
    compileOptions.limitExpressionComplexity = true;
    // Test expression under the limit passes.
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler, GenerateShaderWithLongExpression(kMaxExpressionComplexity - 10).c_str(),
        compileOptions, nullptr));
    // Test expression over the limit fails.
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler, GenerateShaderWithLongExpression(kMaxExpressionComplexity + 10).c_str(),
        compileOptions, kExpressionTooComplex));
    // Test expression over the limit without a limit does not fail.
    compileOptions.limitExpressionComplexity = false;
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler, GenerateShaderWithLongExpression(kMaxExpressionComplexity + 10).c_str(),
        compileOptions, nullptr));
    sh::Destruct(vertexCompiler);
}
TEST_F(ExpressionLimitTest, UnusedExpressionComplexity)
{
    ShShaderSpec spec       = SH_WEBGL_SPEC;
    ShShaderOutput output   = SH_ESSL_OUTPUT;
    ShHandle vertexCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
    ShCompileOptions compileOptions          = {};
    compileOptions.limitExpressionComplexity = true;
    // Test expression under the limit passes.
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler,
        GenerateShaderWithUnusedLongExpression(kMaxExpressionComplexity - 10).c_str(),
        compileOptions, nullptr));
    // Test expression over the limit fails.
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler,
        GenerateShaderWithUnusedLongExpression(kMaxExpressionComplexity + 10).c_str(),
        compileOptions, kExpressionTooComplex));
    // Test expression over the limit without a limit does not fail.
    compileOptions.limitExpressionComplexity = false;
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler,
        GenerateShaderWithUnusedLongExpression(kMaxExpressionComplexity + 10).c_str(),
        compileOptions, nullptr));
    sh::Destruct(vertexCompiler);
}
TEST_F(ExpressionLimitTest, CallStackDepth)
{
    ShShaderSpec spec       = SH_WEBGL_SPEC;
    ShShaderOutput output   = SH_ESSL_OUTPUT;
    ShHandle vertexCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
    ShCompileOptions compileOptions    = {};
    compileOptions.limitCallStackDepth = true;
    // Test call stack under the limit passes.
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler, GenerateShaderWithDeepFunctionStack(kMaxCallStackDepth - 10).c_str(),
        compileOptions, nullptr));
    // Test call stack over the limit fails.
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler, GenerateShaderWithDeepFunctionStack(kMaxCallStackDepth + 10).c_str(),
        compileOptions, kCallStackTooDeep));
    // Test call stack over the limit without limit does not fail.
    compileOptions.limitCallStackDepth = false;
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler, GenerateShaderWithDeepFunctionStack(kMaxCallStackDepth + 10).c_str(),
        compileOptions, nullptr));
    sh::Destruct(vertexCompiler);
}
TEST_F(ExpressionLimitTest, UnusedCallStackDepth)
{
    ShShaderSpec spec       = SH_WEBGL_SPEC;
    ShShaderOutput output   = SH_ESSL_OUTPUT;
    ShHandle vertexCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
    ShCompileOptions compileOptions    = {};
    compileOptions.limitCallStackDepth = true;
    // Test call stack under the limit passes.
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler, GenerateShaderWithUnusedDeepFunctionStack(kMaxCallStackDepth - 10).c_str(),
        compileOptions, nullptr));
    // Test call stack over the limit fails.
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler, GenerateShaderWithUnusedDeepFunctionStack(kMaxCallStackDepth + 10).c_str(),
        compileOptions, kCallStackTooDeep));
    // Test call stack over the limit without limit does not fail.
    compileOptions.limitCallStackDepth = false;
    EXPECT_TRUE(CheckShaderCompilation(
        vertexCompiler, GenerateShaderWithUnusedDeepFunctionStack(kMaxCallStackDepth + 10).c_str(),
        compileOptions, nullptr));
    sh::Destruct(vertexCompiler);
}
TEST_F(ExpressionLimitTest, Recursion)
{
    ShShaderSpec spec       = SH_WEBGL_SPEC;
    ShShaderOutput output   = SH_ESSL_OUTPUT;
    ShHandle vertexCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
    ShCompileOptions compileOptions = {};
    static const char *shaderWithRecursion0 =
        R"(precision mediump float;
        uniform vec4 u_color;
        vec4 someFunc()  {
            return someFunc();
        }
        void main() {
            gl_FragColor = u_color * someFunc();
        }
    )";
    static const char *shaderWithRecursion1 =
        R"(precision mediump float;
        uniform vec4 u_color;
        vec4 someFunc();
        vec4 someFunc1()  {
            return someFunc();
        }
        vec4 someFunc()  {
            return someFunc1();
        }
        void main() {
            gl_FragColor = u_color * someFunc();
        }
    )";
    static const char *shaderWithRecursion2 =
        R"(precision mediump float;
        uniform vec4 u_color;
        vec4 someFunc()  {
            if (u_color.x > 0.5) {
                return someFunc();
            } else {
                return vec4(1);
            }
        }
        void main() {
            gl_FragColor = someFunc();
        }
    )";
    static const char *shaderWithRecursion3 =
        R"(precision mediump float;
        uniform vec4 u_color;
        vec4 someFunc()  {
            if (u_color.x > 0.5) {
                return vec4(1);
            } else {
                return someFunc();
            }
        }
        void main() {
            gl_FragColor = someFunc();
        }
    )";
    static const char *shaderWithRecursion4 =
        R"(precision mediump float;
        uniform vec4 u_color;
        vec4 someFunc()  {
            return (u_color.x > 0.5) ? vec4(1) : someFunc();
        }
        void main() {
            gl_FragColor = someFunc();
        }
    )";
    static const char *shaderWithRecursion5 =
        R"(precision mediump float;
        uniform vec4 u_color;
        vec4 someFunc()  {
            return (u_color.x > 0.5) ? someFunc() : vec4(1);
        }
        void main() {
            gl_FragColor = someFunc();
        }
    )";
    static const char *shaderWithRecursion6 =
        R"(precision mediump float;
        uniform vec4 u_color;
        vec4 someFunc()  {
            return someFunc();
        }
        void main() {
            gl_FragColor = u_color;
        }
    )";
    static const char *shaderWithNoRecursion =
        R"(precision mediump float;
        uniform vec4 u_color;
        vec3 rgb(int r, int g, int b) {
            return vec3(float(r) / 255.0, float(g) / 255.0, float(b) / 255.0);
        }
        void main() {
            vec3 hairColor0 = rgb(151, 200, 234);
            vec3 faceColor2 = rgb(183, 148, 133);
            gl_FragColor = u_color + vec4(hairColor0 + faceColor2, 0);
        }
    )";
    static const char *shaderWithRecursion7 =
        R"(precision mediump float;
        uniform vec4 u_color;
        vec4 function2() {
            return u_color;
        }
        vec4 function1() {
            vec4 a = function2();
            vec4 b = function1();
            return a + b;
        }
        void main() {
            gl_FragColor = function1();
        }
    )";
    static const char *shaderWithRecursion8 =
        R"(precision mediump float;
        uniform vec4 u_color;
        vec4 function1();
        vec4 function3() {
            return function1();
        }
        vec4 function2() {
            return function3();
        }
        vec4 function1() {
            return function2();
        }
        void main() {
            gl_FragColor = function1();
        }
    )";
    // Check simple recursions fails.
    EXPECT_TRUE(CheckShaderCompilation(vertexCompiler, shaderWithRecursion0, compileOptions,
                                       kHasRecursion));
    // Check simple recursions fails.
    EXPECT_TRUE(CheckShaderCompilation(vertexCompiler, shaderWithRecursion1, compileOptions,
                                       kHasRecursion));
    // Check if recursions fails.
    EXPECT_TRUE(CheckShaderCompilation(vertexCompiler, shaderWithRecursion2, compileOptions,
                                       kHasRecursion));
    // Check if recursions fails.
    EXPECT_TRUE(CheckShaderCompilation(vertexCompiler, shaderWithRecursion3, compileOptions,
                                       kHasRecursion));
    // Check ternary recursions fails.
    EXPECT_TRUE(CheckShaderCompilation(vertexCompiler, shaderWithRecursion4, compileOptions,
                                       kHasRecursion));
    // Check ternary recursions fails.
    EXPECT_TRUE(CheckShaderCompilation(vertexCompiler, shaderWithRecursion5, compileOptions,
                                       kHasRecursion));
    // Check some more forms of recursion
    EXPECT_TRUE(CheckShaderCompilation(vertexCompiler, shaderWithRecursion6, compileOptions,
                                       kHasRecursion));
    EXPECT_TRUE(CheckShaderCompilation(vertexCompiler, shaderWithRecursion7, compileOptions,
                                       kHasRecursion));
    EXPECT_TRUE(CheckShaderCompilation(vertexCompiler, shaderWithRecursion8, compileOptions,
                                       kHasRecursion));
    // Check unused recursions fails if limiting call stack
    // since we check all paths.
    compileOptions.limitCallStackDepth = true;
    EXPECT_TRUE(CheckShaderCompilation(vertexCompiler, shaderWithRecursion6, compileOptions,
                                       kHasRecursion));
    // Check unused recursions passes.
    EXPECT_TRUE(
        CheckShaderCompilation(vertexCompiler, shaderWithNoRecursion, compileOptions, nullptr));
    // Check unused recursions passes if limiting call stack.
    EXPECT_TRUE(
        CheckShaderCompilation(vertexCompiler, shaderWithNoRecursion, compileOptions, nullptr));
    sh::Destruct(vertexCompiler);
}
TEST_F(ExpressionLimitTest, FunctionParameterCount)
{
    ShShaderSpec spec     = SH_WEBGL_SPEC;
    ShShaderOutput output = SH_ESSL_OUTPUT;
    ShHandle compiler     = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
    ShCompileOptions compileOptions          = {};
    compileOptions.limitExpressionComplexity = true;
    // Test parameters under the limit succeeds.
    EXPECT_TRUE(CheckShaderCompilation(
        compiler, GenerateShaderWithFunctionParameters(kMaxFunctionParameters).c_str(),
        compileOptions, nullptr));
    // Test parameters over the limit fails.
    EXPECT_TRUE(CheckShaderCompilation(
        compiler, GenerateShaderWithFunctionParameters(kMaxFunctionParameters + 1).c_str(),
        compileOptions, kTooManyParameters));
    // Test parameters over the limit without limit does not fail.
    compileOptions.limitExpressionComplexity = false;
    EXPECT_TRUE(CheckShaderCompilation(
        compiler, GenerateShaderWithFunctionParameters(kMaxFunctionParameters + 1).c_str(),
        compileOptions, nullptr));
    sh::Destruct(compiler);
}
TEST_F(ExpressionLimitTest, NestingInsideSwitch)
{
    ShShaderSpec spec     = SH_WEBGL2_SPEC;
    ShShaderOutput output = SH_ESSL_OUTPUT;
    ShHandle compiler     = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
    ShCompileOptions compileOptions          = {};
    compileOptions.limitExpressionComplexity = true;
    // Test nesting over the limit fails.
    EXPECT_TRUE(CheckShaderCompilation(
        compiler, GenerateShaderWithNestingInsideSwitch(kMaxExpressionComplexity + 1).c_str(),
        compileOptions, kExpressionTooComplex));
    // Test that nesting way over the limit doesn't cause stack overflow but is handled
    // gracefully.
    EXPECT_TRUE(CheckShaderCompilation(compiler,
                                       GenerateShaderWithNestingInsideSwitch(5000).c_str(),
                                       compileOptions, kTooComplexSwitch));
    // Test nesting over the limit without limit does not fail.
    compileOptions.limitExpressionComplexity = false;
    EXPECT_TRUE(CheckShaderCompilation(
        compiler, GenerateShaderWithNestingInsideSwitch(kMaxExpressionComplexity + 1).c_str(),
        compileOptions, nullptr));
    sh::Destruct(compiler);
}
TEST_F(ExpressionLimitTest, NestingInsideGlobalInitializer)
{
    ShShaderSpec spec     = SH_WEBGL_SPEC;
    ShShaderOutput output = SH_ESSL_OUTPUT;
    ShHandle compiler     = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
    ShCompileOptions compileOptions          = {};
    compileOptions.limitExpressionComplexity = true;
    // Test nesting over the limit fails.
    EXPECT_TRUE(CheckShaderCompilation(
        compiler,
        GenerateShaderWithNestingInsideGlobalInitializer(kMaxExpressionComplexity + 1).c_str(),
        compileOptions, kExpressionTooComplex));
    // Test that nesting way over the limit doesn't cause stack overflow but is handled
    // gracefully.
    EXPECT_TRUE(CheckShaderCompilation(
        compiler, GenerateShaderWithNestingInsideGlobalInitializer(5000).c_str(), compileOptions,
        kGlobalVariableInit));
    // Test nesting over the limit without limit does not fail.
    compileOptions.limitExpressionComplexity = false;
    EXPECT_TRUE(CheckShaderCompilation(
        compiler,
        GenerateShaderWithNestingInsideGlobalInitializer(kMaxExpressionComplexity + 1).c_str(),
        compileOptions, nullptr));
    sh::Destruct(compiler);
}
TEST_F(ExpressionLimitTest, TooManyStructFields)
{
    ShShaderSpec spec     = SH_WEBGL2_SPEC;
    ShShaderOutput output = SH_ESSL_OUTPUT;
    ShHandle compiler     = sh::ConstructCompiler(GL_FRAGMENT_SHADER, spec, output, &resources);
    ShCompileOptions compileOptions = {};
    std::ostringstream fs;
    fs << R"(#version 300 es
precision highp float;
struct TooManyFields
{
)";
    for (uint32_t i = 0; i < (1 << 16); ++i)
    {
        fs << "    float field" << i << ";\n";
    }
    fs << R"(};
uniform B { TooManyFields s; };
out vec4 color;
void main() {
    color = vec4(s.field0, 0.0, 0.0, 1.0);
})";
    EXPECT_TRUE(CheckShaderCompilation(compiler, fs.str().c_str(), compileOptions, kTooManyFields));
    sh::Destruct(compiler);
}