src/compiler/translator/ValidateSwitch.cpp


Log

Author Commit Date CI Message
Stuart Morgan 9d737966 2019-08-14T12:25:12 Standardize copyright notices to project style For all "ANGLE Project" copyrights, standardize to the format specified by the style guide. Changes: - "Copyright (c)" and "Copyright(c)" changed to just "Copyright". - Removed the second half of date ranges ("Y1Y1-Y2Y2"->"Y1Y1"). - Fixed a small number of files that had no copyright date using the initial commit year from the version control history. - Fixed one instance of copyright being "The ANGLE Project" rather than "The ANGLE Project Authors" These changes are applied both to the copyright of source file, and where applicable to copyright statements that are generated by templates. BUG=angleproject:3811 Change-Id: I973dd65e4ef9deeba232d5be74c768256a0eb2e5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1754397 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Jamie Madill b980c563 2018-11-27T11:34:27 Reformat all cpp and h files. This applies git cl format --full to all ANGLE sources. Bug: angleproject:2986 Change-Id: Ib504e618c1589332a37e97696cdc3515d739308f Reviewed-on: https://chromium-review.googlesource.com/c/1351367 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Olli Etuaho 4002e92a 2018-04-04T16:55:34 Guard traversers used during parsing against stack overflow Traversers used during parsing can be vulnerable to stack overflow since the AST has not yet been validated for max depth. Make sure to check for traversal depth in traversers used during parsing. We set the maximum traversal depth in ValidateGlobalInitializer and ValidateSwitchStatementList to 256, which matches the default value for validating general AST complexity. The depth check is on regardless of compiler options. In case the traversers go over the maximum traversal depth, they fail validation. BUG=angleproject:2453 TEST=angle_unittests Change-Id: I89ba576e8ef69663ba35d7b9050a6da319f1757c Reviewed-on: https://chromium-review.googlesource.com/995795 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho fd643283 2018-04-04T16:12:09 Disallow case statements nested in blocks The GLSL ES 3.00.6 spec is a bit unclear on this, but it does disallow case statements "inside control flow". GLSL ES 3.10 clarifies this and disallows any nesting of case or default labels within other statements. BUG=angleproject:2452 TEST=angle_unittests Change-Id: I289bb39abb5227eab7117638af388b0a57dc5dd8 Reviewed-on: https://chromium-review.googlesource.com/995478 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Olli Etuaho c26214de 2018-03-16T10:43:11 Move AST utilities to a subdirectory Move AST related utilities to compiler/translator/tree_util. BUG=angleproject:2409 TEST=angle_unittests Change-Id: I7567c2f6f2710292029263257c7ac26e2a144ac8 Reviewed-on: https://chromium-review.googlesource.com/966032 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho d05f964b 2018-03-05T12:13:26 Last case in switch statement can't be empty in ESSL 3.10 This is based on recent discussion in Khronos, though public specs have not yet been updated to reflect this. BUG=angleproject:2388 TEST=angle_unittests Change-Id: I66a0d03b3c2bb9740772a813b543f8f6c6bb2a28 Reviewed-on: https://chromium-review.googlesource.com/947977 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho cbcb96fc 2017-10-19T14:14:06 Fix switch/case last case validation for ESSL 3.10 No statement should be required after the last case label of a switch statement in ESSL 3.10. The validation is still kept for ESSL 3.00 for dEQP compatibility. If the dEQP tests are changed in the future, we might consider just issuing a warning regardless of shader version. BUG=angleproject:2189 TEST=angle_unittests Change-Id: Ic53e71e0176668a7dbffa315712885846e217f03 Reviewed-on: https://chromium-review.googlesource.com/727802 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 923ecef6 2017-10-11T12:01:38 Fix switch statement validation corner cases The grammar needs to generate AST nodes even for no-op statements, since they might be the last statement in a switch statement that is required for switch statement validity. Change the grammar to generate nodes from empty blocks and empty declarations. We also need to do some further processing of the AST. This is because PruneEmptyDeclarations will still remove empty declarations, and at least the NVIDIA driver GLSL compiler doesn't accept some types of no-op statements as the last statement inside a switch statement. So after parsing has finished we do rudimentary dead code elimination to remove dead cases from the end of switch statements. BUG=angleproject:2181 TEST=angle_unittests Change-Id: I586f2e4a3ac2171e65f1f0ccb7a7de220e3cc225 Reviewed-on: https://chromium-review.googlesource.com/712574 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Olli Etuaho cccf2b00 2017-07-05T14:50:54 Reorganize AST traversal utility code Define TIntermTraverser and TIntermLValueTrackingTraverser in a separate header file. hash() function is moved out from TIntermTraverser as it is not related to the core functionality of traversing and transforming ASTs. Also reorganize some traversers to follow common conventions: - Intermediate output is now in OutputTree.h/.cpp - Max tree depth check is now in IsASTDepthBelowLimit.h/.cpp BUG=angleproject:1490 TEST=angle_unittests Change-Id: Id4968aa9d4e24d0c5bac90dc147fc9f310de0184 Reviewed-on: https://chromium-review.googlesource.com/559531 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 7351c2a5 2016-12-15T18:06:41 Clean up GLSL switch statement validation Encapsulate all of the implementation inside the .cpp file, and pass just the diagnostics object instead of the whole ParseContext to the validation function. BUG=angleproject:1670 TEST=angle_unittests Change-Id: I89713b63e554dbedaa12b2270208f1fac496c54e Reviewed-on: https://chromium-review.googlesource.com/420788 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Jamie Madill d7b1ab58 2016-12-12T14:42:19 Fix up translator style. Using git cl format. BUG=angleproject:650 Change-Id: I7d3f98d2b0dcfb0a8de6c35327db74e55c28d761 Reviewed-on: https://chromium-review.googlesource.com/419059 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Jamie Madill 45bcc784 2016-11-07T13:58:48 translator: Scope all classes with "sh". I was seeing an odd problem with our PoolAlloc conflicting with the glslang/Vulkan TIntermNode, so the fix was to move everything to a separate namespace. The bison grammars are also regenerated. No functional changes. BUG=angleproject:1576 Change-Id: I959c7afe4c092f0d458432c07b4dcee4d39513f3 Reviewed-on: https://chromium-review.googlesource.com/408267 Reviewed-by: Yuly Novikov <ynovikov@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Olli Etuaho 6d40bbdd 2016-09-30T13:49:38 Split TIntermBlock from TIntermAggregate The new TIntermBlock node class replaces TIntermAggregate nodes with the EOpSequence op. It represents the root node of the tree which is a list of declarations and function definitions, and any code blocks that can be denoted by curly braces. These include function and loop bodies, and if-else branches. This change enables a bunch of more compile-time type checking, and makes the AST code easier to understand and less error-prone. The PostProcess step that used to be done to ensure that the root node is TIntermAggregate is removed in favor of making sure that the root node is a TIntermBlock in the glslang.y parsing code. Intermediate output formatting is improved to print the EOpNull error in a clearer way. After this patch, TIntermAggregate is still used for function definitions, function prototypes, function parameter lists, function calls, variable and invariant declarations and the comma (sequence) operator. BUG=angleproject:1490 TEST=angle_unittests, angle_end2end_tests Change-Id: I04044affff979a11577bc1fe75d747e538b799c8 Reviewed-on: https://chromium-review.googlesource.com/393726 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Olli Etuaho 5796127e 2016-09-14T13:57:46 Rename TIntermSelection to TIntermIfElse Now that ternary nodes are not represented by TIntermSelection any more, TIntermIfElse is an easier name to understand for newcomers to the code. BUG=angleproject:1490 TEST=angle_unittests Change-Id: Ia1e04e356ab93409400245092a84533d7dfd129d Reviewed-on: https://chromium-review.googlesource.com/385416 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho d0bad2c7 2016-09-09T18:01:16 Split ternary node class from TIntermSelection Ternary operator nodes are typed parts of expressions, they always have two children and the children are also guaranteed to be TIntermTyped. "If" selection nodes can't be a part of an expression, they can have either one or two children and the children are code blocks. Due to all of these differences it makes sense to store these using two different AST node classes. BUG=angleproject:1490 TEST=angle_unittests Change-Id: I913ab1d806e3cdb5c21106f078cc9c0b6c72ac54 Reviewed-on: https://chromium-review.googlesource.com/384512 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Olli Etuaho c8716df9 2015-02-26T17:17:22 Fix an issue with handling an error case inside ValidateSwitch In case a condition with a wrong type is given to a case statement, it generates an error but the compiler recovers. This caused ValidateSwitch to assert. Fix this. BUG=angle:921 Change-Id: I7949798cab923c2b168817471896470c6c611878 Reviewed-on: https://chromium-review.googlesource.com/254080 Reviewed-by: Zhenyao Mo <zmo@chromium.org> Tested-by: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Olli Etuaho ac5274df 2015-02-20T10:19:08 Add validation for the structure of switch statements Implement a traverser to check for the following errors: -More than one default or replicated constant expression -No statement between a label and the end of a switch statement -Statements in a switch statement before the first case statement -Mismatch between the type of init-expression and type of a case label -Case or default label nested inside other control flow nested within the corresponding switch Tested by manually disabling shading language version checks for switch and by manually enabling case statements in a Chromium build and checking that the expected errors are generated. BUG=angle:921 Change-Id: I99c49c17c8b520849adbe4d8521e46cb10e20e41 Reviewed-on: https://chromium-review.googlesource.com/251524 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Olli Etuaho <oetuaho@nvidia.com> Tested-by: Olli Etuaho <oetuaho@nvidia.com>