Closed Bug 349596 Opened 18 years ago Closed 18 years ago

Labeled "if(0)..." disappears but label remains

Categories

(Core :: JavaScript Engine, defect, P1)

defect

Tracking

()

VERIFIED FIXED
mozilla1.8.1

People

(Reporter: jruderman, Assigned: brendan)

References

Details

(Keywords: testcase, verified1.8.1)

Attachments

(3 files)

Steps to reproduce:
  javascript:function() { L: if (0) return 5 }

Result:
  function () { L: }
  
Expected:
  (1) Decompile to what I had originally, or
  (2) Decompile to a simpler useless statement/block, such as "L: if (0) { }" or "L: null", or
  (3) Also remove the label, since it is useless given that nothing can break/continue to it.

This is similar to bug 349489, which is already fixed.
This could be a problem in the constant folder, which runs right after the parse phase.  It's therefore not like bug 349489, which was a bug in the useless expression eliminator, which runs from the code generator -- a later phase than the constant folding phase.  But it is actually a bug in the decompiler:

js> function f(){L:;}
js> f
function f() {
L:
}

Old bug, taking.

/be
Assignee: general → brendan
Flags: blocking1.8.1?
OS: Mac OS X 10.4 → All
Priority: -- → P1
Hardware: Macintosh → All
Target Milestone: --- → mozilla1.8.1
Status: NEW → ASSIGNED
Attached patch fixSplinter Review
Turns out that the easiest, and the singular, place to fix this is in the constant folder.  There is no point elaborating the compiled code with a special "smoke signal" just for empty labeled statements, which are rare in JS (compared to C, where you sometimes need a goto target at the bottom of a loop, e.g.).

By turning all empty labeled statements into labeled empty blocks, we save on code for special or redundant case logic, at the cost of an extra nop.  This fixes both the verbatim L:; input case, and equivalent L:if(0)foo(); constant-folded cases.

/be
Attachment #234883 - Flags: review?(mrbkap)
This may be a bit more code, but on second thought I'd rather not mandate the constant folding phase.

/be
Attachment #234887 - Flags: review?(mrbkap)
Blocks: js1.7
Flags: blocking1.8.1? → blocking1.8.1+
Attachment #234887 - Flags: review?(mrbkap) → review+
Attachment #234883 - Flags: review?(mrbkap)
Comment on attachment 234887 [details] [diff] [review]
alterna-fix that doesn't require the constant folding phase

Checking in jsparse.c;
/cvsroot/mozilla/js/src/jsparse.c,v  <--  jsparse.c
new revision: 3.206; previous revision: 3.205
done
Attachment #234887 - Flags: approval1.8.1?
Fixed on trunk.

/be
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Comment on attachment 234887 [details] [diff] [review]
alterna-fix that doesn't require the constant folding phase

a=schrep for drivers.
Attachment #234887 - Flags: approval1.8.1? → approval1.8.1+
Fixed on the 1.8 branch.

/be
Keywords: fixed1.8.1
Checking in regress-349596.js;
/cvsroot/mozilla/js/tests/js1_5/Regress/regress-349596.js,v  <--  regress-349596.js
initial revision: 1.1
Flags: in-testsuite+
verified fixed 1.8, 1.9 20060824 windows/mac*/linux
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: