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

Dead code elimination can eliminate side-effecting code #931

Open
bakkot opened this issue Nov 25, 2018 · 0 comments
Open

Dead code elimination can eliminate side-effecting code #931

bakkot opened this issue Nov 25, 2018 · 0 comments

Comments

@bakkot
Copy link

bakkot commented Nov 25, 2018

Copying from #930 (comment) to make sure it gets tracked:

'use strict';
function foo() {
    if (bar(), true) {
        baz();
    } else {
        NOT_REACHABLE();
    }
}

with dead code and simplify gets transformed to

"use strict";function foo(){baz()}

which is wrong - the call to bar() can have side effects.

I expect the bug is here: this code assumes that anything which .evaluate()s confidently can be safely replaced with its evaluation, but that's not true - you can have side effects even for things you're confident about. Compare the more complex code in the path for IfStatement, which was added in #386 to fix #385. I imagine the fix is basically copying that code to the ConditionalExpression case; probably a good first issue for someone.

(This issue is pretty much the same as #385 (comment), just with slightly different input conditions.)

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

No branches or pull requests

1 participant