Changeset 248650 in webkit


Ignore:
Timestamp:
Aug 13, 2019 6:05:27 PM (5 years ago)
Author:
rmorisset@apple.com
Message:

[WHLSL] Don't generate empty comma expressions for bare ';'
https://bugs.webkit.org/show_bug.cgi?id=200681

Reviewed by Myles C. Maxfield.

Currently we emit a comma expression with no sub-expression for bare ';', as well as for the initialization of for loops with no initializers.
This crashes the Checker, as it tries to access the last sub-expression of comma expressions.
Instead we should generate an empty statement block for that case.

This problem was found (and originally fixed before the commit was reverted) in https://bugs.webkit.org/show_bug.cgi?id=199726.
I am just isolating the fix here for easier review and debugging.

New test: LayoutTests/webgpu/whlsl/for-loop.html

  • Modules/webgpu/WHLSL/AST/WHLSLForLoop.h:
  • Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:

(WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):

  • Modules/webgpu/WHLSL/WHLSLASTDumper.cpp:

(WebCore::WHLSL::ASTDumper::visit):

  • Modules/webgpu/WHLSL/WHLSLChecker.cpp:

(WebCore::WHLSL::Checker::visit):

  • Modules/webgpu/WHLSL/WHLSLParser.cpp:

(WebCore::WHLSL::Parser::parseForLoop):
(WebCore::WHLSL::Parser::parseStatement):
(WebCore::WHLSL::Parser::parseEffectfulExpression):

  • Modules/webgpu/WHLSL/WHLSLParser.h:
  • Modules/webgpu/WHLSL/WHLSLVisitor.cpp:

(WebCore::WHLSL::Visitor::visit):

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r248648 r248650  
     12019-08-13  Robin Morisset  <rmorisset@apple.com>
     2
     3        [WHLSL] Don't generate empty comma expressions for bare ';'
     4        https://bugs.webkit.org/show_bug.cgi?id=200681
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Currently we emit a comma expression with no sub-expression for bare ';', as well as for the initialization of for loops with no initializers.
     9        This crashes the Checker, as it tries to access the last sub-expression of comma expressions.
     10        Instead we should generate an empty statement block for that case.
     11
     12        This problem was found (and originally fixed before the commit was reverted) in https://bugs.webkit.org/show_bug.cgi?id=199726.
     13        I am just isolating the fix here for easier review and debugging.
     14
     15        New test: LayoutTests/webgpu/whlsl/for-loop.html
     16
     17        * Modules/webgpu/WHLSL/AST/WHLSLForLoop.h:
     18        * Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
     19        (WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
     20        * Modules/webgpu/WHLSL/WHLSLASTDumper.cpp:
     21        (WebCore::WHLSL::ASTDumper::visit):
     22        * Modules/webgpu/WHLSL/WHLSLChecker.cpp:
     23        (WebCore::WHLSL::Checker::visit):
     24        * Modules/webgpu/WHLSL/WHLSLParser.cpp:
     25        (WebCore::WHLSL::Parser::parseForLoop):
     26        (WebCore::WHLSL::Parser::parseStatement):
     27        (WebCore::WHLSL::Parser::parseEffectfulExpression):
     28        * Modules/webgpu/WHLSL/WHLSLParser.h:
     29        * Modules/webgpu/WHLSL/WHLSLVisitor.cpp:
     30        (WebCore::WHLSL::Visitor::visit):
     31
    1322019-08-13  Daniel Bates  <dabates@apple.com>
    233
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLForLoop.h

    r248488 r248650  
    4646    WTF_MAKE_FAST_ALLOCATED;
    4747public:
    48     ForLoop(CodeLocation location, Variant<UniqueRef<Statement>, UniqueRef<Expression>>&& initialization, std::unique_ptr<Expression>&& condition, std::unique_ptr<Expression>&& increment, UniqueRef<Statement>&& body)
     48    ForLoop(CodeLocation location, UniqueRef<Statement>&& initialization, std::unique_ptr<Expression>&& condition, std::unique_ptr<Expression>&& increment, UniqueRef<Statement>&& body)
    4949        : Statement(location, Kind::ForLoop)
    5050        , m_initialization(WTFMove(initialization))
     
    6060    ForLoop(ForLoop&&) = default;
    6161
    62     Variant<UniqueRef<Statement>, UniqueRef<Expression>>& initialization() { return m_initialization; }
     62    UniqueRef<Statement>& initialization() { return m_initialization; }
    6363    Expression* condition() { return m_condition.get(); }
    6464    Expression* increment() { return m_increment.get(); }
     
    6666
    6767private:
    68     Variant<UniqueRef<Statement>, UniqueRef<Expression>> m_initialization;
     68    UniqueRef<Statement> m_initialization;
    6969    std::unique_ptr<Expression> m_condition;
    7070    std::unique_ptr<Expression> m_increment;
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp

    r248384 r248650  
    357357{
    358358    m_stringBuilder.append("{\n");
    359 
    360     WTF::visit(WTF::makeVisitor([&](AST::Statement& statement) {
    361         checkErrorAndVisit(statement);
    362     }, [&](UniqueRef<AST::Expression>& expression) {
    363         checkErrorAndVisit(expression);
    364         takeLastValue(); // We don't need to do anything with the result.
    365     }), forLoop.initialization());
    366 
     359    checkErrorAndVisit(forLoop.initialization());
    367360    emitLoop(LoopConditionLocation::BeforeBody, forLoop.condition(), forLoop.increment(), forLoop.body());
    368361    m_stringBuilder.append("}\n");
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp

    r248021 r248650  
    410410{
    411411    m_out.print("for (");
    412     WTF::visit(WTF::makeVisitor([&](UniqueRef<AST::Statement>& statement) {
    413         visit(statement);
    414     }, [&](UniqueRef<AST::Expression>& expression) {
    415         visit(expression);
    416     }), forLoop.initialization());
     412    visit(forLoop.initialization());
    417413    m_out.print("; ");
    418414    if (forLoop.condition())
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp

    r248378 r248650  
    14441444void Checker::visit(AST::ForLoop& forLoop)
    14451445{
    1446     WTF::visit(WTF::makeVisitor([&](UniqueRef<AST::Statement>& statement) {
    1447         checkErrorAndVisit(statement);
    1448     }, [&](UniqueRef<AST::Expression>& expression) {
    1449         checkErrorAndVisit(expression);
    1450     }), forLoop.initialization());
     1446    checkErrorAndVisit(forLoop.initialization());
    14511447    if (hasError())
    14521448        return;
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp

    r248488 r248650  
    11641164    CONSUME_TYPE(leftParenthesis, LeftParenthesis);
    11651165
    1166     auto parseRemainder = [&](Variant<UniqueRef<AST::Statement>, UniqueRef<AST::Expression>>&& initialization) -> Expected<AST::ForLoop, Error> {
     1166    auto parseRemainder = [&](UniqueRef<AST::Statement>&& initialization) -> Expected<AST::ForLoop, Error> {
    11671167        CONSUME_TYPE(semicolon, Semicolon);
    11681168
     
    13571357
    13581358    {
    1359         auto effectfulExpression = backtrackingScope<Expected<UniqueRef<AST::Expression>, Error>>([&]() -> Expected<UniqueRef<AST::Expression>, Error> {
     1359        auto effectfulExpression = backtrackingScope<Expected<UniqueRef<AST::Statement>, Error>>([&]() -> Expected<UniqueRef<AST::Statement>, Error> {
    13601360            PARSE(result, EffectfulExpression);
    13611361            CONSUME_TYPE(semicolon, Semicolon);
     
    13631363        });
    13641364        if (effectfulExpression)
    1365             return { makeUniqueRef<AST::EffectfulExpressionStatement>(WTFMove(*effectfulExpression)) };
     1365            return WTFMove(*effectfulExpression);
    13661366    }
    13671367
     
    13711371}
    13721372
    1373 auto Parser::parseEffectfulExpression() -> Expected<UniqueRef<AST::Expression>, Error>
     1373auto Parser::parseEffectfulExpression() -> Expected<UniqueRef<AST::Statement>, Error>
    13741374{
    13751375    PEEK(origin);
     1376    if (origin->type == Token::Type::Semicolon)
     1377        return { makeUniqueRef<AST::Block>(*origin, Vector<UniqueRef<AST::Statement>>()) };
     1378
    13761379    Vector<UniqueRef<AST::Expression>> expressions;
    1377     if (origin->type == Token::Type::Semicolon)
    1378         return { makeUniqueRef<AST::CommaExpression>(*origin, WTFMove(expressions)) };
    1379 
    13801380    PARSE(effectfulExpression, EffectfulAssignment);
    13811381    expressions.append(WTFMove(*effectfulExpression));
     
    13871387
    13881388    if (expressions.size() == 1)
    1389         return WTFMove(expressions[0]);
     1389        return { makeUniqueRef<AST::EffectfulExpressionStatement>(WTFMove(expressions[0])) };
    13901390    unsigned endOffset = m_lexer.peek().startOffset();
    13911391    CodeLocation location(origin->startOffset(), endOffset);
    1392     return { makeUniqueRef<AST::CommaExpression>(location, WTFMove(expressions)) };
     1392    auto commaExpression = makeUniqueRef<AST::CommaExpression>(location, WTFMove(expressions));
     1393    return { makeUniqueRef<AST::EffectfulExpressionStatement>(WTFMove(commaExpression)) };
    13931394}
    13941395
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.h

    r248303 r248650  
    132132    Expected<UniqueRef<AST::Statement>, Error> parseStatement();
    133133
    134     Expected<UniqueRef<AST::Expression>, Error> parseEffectfulExpression();
     134    Expected<UniqueRef<AST::Statement>, Error> parseEffectfulExpression();
    135135    Expected<UniqueRef<AST::Expression>, Error> parseEffectfulAssignment();
    136136    struct SuffixExpression {
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp

    r248488 r248650  
    462462void Visitor::visit(AST::ForLoop& forLoop)
    463463{
    464     WTF::visit(WTF::makeVisitor([&](UniqueRef<AST::Statement>& statement) {
    465         checkErrorAndVisit(statement);
    466     }, [&](UniqueRef<AST::Expression>& expression) {
    467         checkErrorAndVisit(expression);
    468     }), forLoop.initialization());
     464    checkErrorAndVisit(forLoop.initialization());
    469465    if (forLoop.condition())
    470466        checkErrorAndVisit(*forLoop.condition());
Note: See TracChangeset for help on using the changeset viewer.