Revision: 7914
Author: sco...@google.com
Date: Tue Apr 13 07:20:13 2010
Log: Fixes ICE in JsInliner.

We are getting a compiler crash if you try to inline a static JSNI method that references 'this' (weird case). This change disables inlining such methods.

http://gwt-code-reviews.appspot.com/284802/show
Found by: spoon
Review by: spoon

http://code.google.com/p/google-web-toolkit/source/detail?r=7914

Modified:
 /trunk/dev/core/src/com/google/gwt/dev/js/JsInliner.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/js/JsInliner.java Tue Apr 13 06:08:53 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/js/JsInliner.java Tue Apr 13 07:20:13 2010
@@ -1368,25 +1368,36 @@

   /**
* Detects uses of parameters that would produce incorrect results if inlined.
-   * Generally speaking, we disallow the use of parameters as lvalues.
+   * Generally speaking, we disallow the use of parameters as lvalues. Also
+ * detects trying to inline a method which references 'this' where the call
+   * site has no qualifier.
    */
   private static class ParameterUsageVisitor extends JsVisitor {
-    private boolean lvalue = false;
+    private final boolean hasThisExpr;
     private final Set<JsName> parameterNames;
-
-    public ParameterUsageVisitor(Set<JsName> parameterNames) {
+    private boolean violation = false;
+
+ public ParameterUsageVisitor(boolean hasThisExpr, Set<JsName> parameterNames) {
+      this.hasThisExpr = hasThisExpr;
       this.parameterNames = parameterNames;
     }

     @Override
     public void endVisit(JsNameRef x, JsContext<JsExpression> ctx) {
       if (ctx.isLvalue() && isParameter(x)) {
-        lvalue = true;
+        violation = true;
       }
     }

-    public boolean parameterAsLValue() {
-      return lvalue;
+    @Override
+    public void endVisit(JsThisRef x, JsContext<JsExpression> ctx) {
+      if (!hasThisExpr) {
+        violation = true;
+      }
+    }
+
+    public boolean hasViolation() {
+      return violation;
     }

     /**
@@ -1911,9 +1922,10 @@
     }

// Check that parameters aren't used in such a way as to prohibit inlining
-    ParameterUsageVisitor v = new ParameterUsageVisitor(parameterNames);
+    ParameterUsageVisitor v = new ParameterUsageVisitor(thisExpr != null,
+        parameterNames);
     v.accept(toInline);
-    if (v.parameterAsLValue()) {
+    if (v.hasViolation()) {
       return false;
     }

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to