Changeset 247675 in webkit


Ignore:
Timestamp:
Jul 21, 2019 11:31:53 AM (5 years ago)
Author:
sbarati@apple.com
Message:

[WHLSL] Return the zero-value enum in the enum-from-integer constructor when the integer is not a valid enum value
https://bugs.webkit.org/show_bug.cgi?id=199853

Reviewed by Dean Jackson.

Source/WebCore:

Test: webgpu/whlsl/enum-integer-constructor.html

  • Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp:

(WebCore::WHLSL::Metal::writeNativeFunction):

LayoutTests:

  • webgpu/whlsl/enum-integer-constructor-expected.txt: Added.
  • webgpu/whlsl/enum-integer-constructor.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r247674 r247675  
     12019-07-21  Saam Barati  <sbarati@apple.com>
     2
     3        [WHLSL] Return the zero-value enum in the enum-from-integer constructor when the integer is not a valid enum value
     4        https://bugs.webkit.org/show_bug.cgi?id=199853
     5
     6        Reviewed by Dean Jackson.
     7
     8        * webgpu/whlsl/enum-integer-constructor-expected.txt: Added.
     9        * webgpu/whlsl/enum-integer-constructor.html: Added.
     10
    1112019-07-21  Myles C. Maxfield  <mmaxfield@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r247674 r247675  
     12019-07-21  Saam Barati  <sbarati@apple.com>
     2
     3        [WHLSL] Return the zero-value enum in the enum-from-integer constructor when the integer is not a valid enum value
     4        https://bugs.webkit.org/show_bug.cgi?id=199853
     5
     6        Reviewed by Dean Jackson.
     7
     8        Test: webgpu/whlsl/enum-integer-constructor.html
     9
     10        * Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp:
     11        (WebCore::WHLSL::Metal::writeNativeFunction):
     12
    1132019-07-21  Myles C. Maxfield  <mmaxfield@apple.com>
    214
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp

    r247468 r247675  
    3232#include "WHLSLAddressSpace.h"
    3333#include "WHLSLArrayType.h"
     34#include "WHLSLEnumerationDefinition.h"
    3435#include "WHLSLInferTypes.h"
    3536#include "WHLSLIntrinsics.h"
     
    124125    StringBuilder stringBuilder;
    125126    if (nativeFunctionDeclaration.isCast()) {
    126         auto metalReturnName = typeNamer.mangledNameForType(nativeFunctionDeclaration.type());
     127        auto& returnType = nativeFunctionDeclaration.type();
     128        auto metalReturnName = typeNamer.mangledNameForType(returnType);
    127129        if (!nativeFunctionDeclaration.parameters().size()) {
    128130            stringBuilder.append(makeString(metalReturnName, ' ', outputFunctionName, "() {\n"));
     
    135137
    136138        ASSERT(nativeFunctionDeclaration.parameters().size() == 1);
    137         auto metalParameterName = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[0]->type());
     139        auto& parameterType = *nativeFunctionDeclaration.parameters()[0]->type();
     140        auto metalParameterName = typeNamer.mangledNameForType(parameterType);
    138141        stringBuilder.append(makeString(metalReturnName, ' ', outputFunctionName, '(', metalParameterName, " x) {\n"));
     142
     143        {
     144            auto isEnumerationDefinition = [] (auto& type) {
     145                return is<AST::NamedType>(type) && is<AST::EnumerationDefinition>(downcast<AST::NamedType>(type));
     146            };
     147            auto& unifiedReturnType = returnType.unifyNode();
     148            if (isEnumerationDefinition(unifiedReturnType) && !isEnumerationDefinition(parameterType.unifyNode())) {
     149                auto& enumerationDefinition = downcast<AST::EnumerationDefinition>(downcast<AST::NamedType>(unifiedReturnType));
     150                stringBuilder.append("    switch (x) {\n");
     151                bool hasZeroCase = false;
     152                for (auto& member : enumerationDefinition.enumerationMembers()) {
     153                    hasZeroCase |= !member.get().value();
     154                    stringBuilder.append(makeString("        case ", member.get().value(), ": break;\n"));
     155                }
     156                ASSERT_UNUSED(hasZeroCase, hasZeroCase);
     157                stringBuilder.append("        default: x = 0; break; }\n");
     158            }
     159        }
     160
    139161        stringBuilder.append(makeString("    return static_cast<", metalReturnName, ">(x);\n"));
    140162        stringBuilder.append("}\n");
Note: See TracChangeset for help on using the changeset viewer.