Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallthrough should not execute case expression #1683

Merged
merged 3 commits into from Mar 26, 2017

Conversation

alexlamsl
Copy link
Collaborator

Also enable switch statement fuzzing.

fixes #1680

Also enable switch statement fuzzing.

fixes mishoo#1680
@alexlamsl
Copy link
Collaborator Author

//=============================================================
// !!!!!! Failed...
// original code
//
var a = 100, b = 10;
function f21(){var Math79 = (a++), foo80 = ([,0].length === 2);{var brake81 = 5; while (((0 === 1 ? a : b)^new function(){
(b ^= a)
return Math;
}) && --brake81 > 0){{var brake83 = 5; do {;} while (((0 === 1 ? a : b)) && --brake83 > 0);}{!true}{!true}if ((typeof NaN93 != "number"))switch (null) { case (function a95(){switch ((0 === 1 ? a : b)) { case (a--):

 break;
case void function let97(){{;}{;}if (25. ); else ;}:
{var brake103 = 5; while (((22)) && --brake103 > 0)switch (({})) { case [,0][1]:
;
 break;
case undefined:
;
 break;
case [,0][1]:
;
 break;
case undefined:
;
 break;
}}
 break;
case (0 === 1 ? a : b):
;var arguments;
 break;
case (a--):
{}
 break;
}return;})()?((--(b))):((b !== a)):

 break;
case (a++):
;
 break;
case (--b):

 break;
case (typeof undefined110 == "unknown"):
;
 break;
}}}}
f21();

console.log(a, b);


//-------------------------------------------------------------
// original code (beautify'd)
//
var a = 100, b = 10;

function f21() {
    var Math79 = a++, foo80 = [ , 0 ].length === 2;
    {
        var brake81 = 5;
        while ((0 === 1 ? a : b) ^ new function() {
            b ^= a;
            return Math;
        }() && --brake81 > 0) {
            {
                var brake83 = 5;
                do {
                } while ((0 === 1 ? a : b) && --brake83 > 0);
            }
            {
                !true;
            }
            {
                !true;
            }
            if (typeof NaN93 != "number") {
                switch (null) {
                  case function a95() {
                        switch (0 === 1 ? a : b) {
                          case a--:
                            break;

                          case void function let97() {
                                {
                                }
                                {
                                }
                                if (25) {} else {}
                            }:
                            {
                                var brake103 = 5;
                                while (22 && --brake103 > 0) {
                                    switch ({}) {
                                      case [ , 0 ][1]:
                                        ;
                                        break;

                                      case undefined:
                                        ;
                                        break;

                                      case [ , 0 ][1]:
                                        ;
                                        break;

                                      case undefined:
                                        ;
                                        break;
                                    }
                                }
                            }
                            break;

                          case 0 === 1 ? a : b:
                            ;
                            var arguments;
                            break;

                          case a--:
                            {}
                            break;
                        }
                        return;
                    }() ? --b : b !== a:
                    break;

                  case a++:
                    ;
                    break;

                  case --b:
                    break;

                  case typeof undefined110 == "unknown":
                    ;
                    break;
                }
            }
        }
    }
}

f21();

console.log(a, b);


//-------------------------------------------------------------
// uglified code
//
function f21(){for(var e=(a++,[,0].length,5);b^new function(){return b^=a,Math}&&--e>0;){var c=5;do{}while(b&&--c>0);if("number"!=typeof NaN93)switch(null){case function(){switch(b){case a--:case a--:break;case void 0:for(var e=5;--e>0;)switch({}){case[,0][1]:case void 0:case[,0][1]:}}}()?--b:b!==a:case a++:case--b:case"unknown"==typeof undefined110:}}}var a=100,b=10;f21(),console.log(a,b);


original result:
101 111

beautified result:
101 111

uglified result:
97 107

!!!!!! Failed...

@kzc
Copy link
Contributor

kzc commented Mar 26, 2017

Was that a new failure with this PR?

@alexlamsl
Copy link
Collaborator Author

Nope - just a different bug after re-enabling switch in test/ufuzz.js. It's an easy fix, so lump it over here.

I'll continue to catch those low hanging fruits, then commit this PR.

@kzc
Copy link
Contributor

kzc commented Mar 26, 2017

That fuzzer is crazy useful.

avoid all potential side-effects
@kzc
Copy link
Contributor

kzc commented Mar 26, 2017

When a side effect is found in any case condition at all shouldn't the optimization of the switch be abandoned?

@alexlamsl
Copy link
Collaborator Author

Unlike previously, we are not eliminating the switch block completely or give up.

We drop definitely unreachable cases, de-duplicate others. Only then do we look at the switch block to see if it contains only one case which is definitely reachable.

If that's the case, then we ouput an AST_BlockStatement, otherwise we return the (now optimised) AST_Switch.

@kzc
Copy link
Contributor

kzc commented Mar 26, 2017

Good thing you have a fuzzer. There's a lot things that can potentially go wrong.

@alexlamsl
Copy link
Collaborator Author

Yup - without that I wouldn't have started #1677 at all.

@alexlamsl alexlamsl merged commit 3276740 into mishoo:master Mar 26, 2017
@alexlamsl alexlamsl deleted the issue-1680 branch March 26, 2017 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: fallthrough should not execute case expression
2 participants