]> source.dussan.org Git - aspectj.git/commitdiff
fix and testcode update for: 151673: after advice sometimes woven incorrectly into...
authoraclement <aclement>
Thu, 27 Jul 2006 09:57:26 +0000 (09:57 +0000)
committeraclement <aclement>
Thu, 27 Jul 2006 09:57:26 +0000 (09:57 +0000)
13 files changed:
tests/features152/synchronization/transformed/expected/C.m.txt
tests/features152/synchronization/transformed/expected/C.m3.txt
tests/features152/synchronization/transformed/expected/C.m33.txt
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/testdata/AfterFancyHelloWorld.txt
weaver/testdata/AfterHelloWorld.txt
weaver/testdata/AfterReturningFancyHelloWorld.txt
weaver/testdata/AfterReturningHelloWorld.txt
weaver/testdata/ArgsAfterReturningFancyHelloWorld.txt
weaver/testdata/ArgsAfterReturningHelloWorld.txt
weaver/testdata/ArgsBeforeAfterHelloWorld.txt
weaver/testdata/CflowNonStaticBeforeFancyHelloWorld.txt
weaver/testdata/CflowNonStaticBeforeHelloWorld.txt

index 70270b46364fb8423842ad23c9b758e496a4e352..7f5a34cdc08a15d68b98e4ecdee9803519fdfd52 100644 (file)
@@ -20,5 +20,4 @@
                 L0: INVOKESTATIC Four.aspectOf ()LFour;
                     INVOKEVIRTUAL Four.ajc$afterReturning$Four$1$c2776aed ()V
                     RETURN
-                    RETURN
   end public void m()
index f6406ff45c943feb056a430cbb88e6e1bd7f8846..f1157285e0dec7b59b443347fe7659db5a3b9def 100644 (file)
@@ -20,5 +20,4 @@
                 L0: INVOKESTATIC Three.aspectOf ()LThree;
                     INVOKEVIRTUAL Three.ajc$afterReturning$Three$1$3f09355c ()V
                     RETURN
-                    RETURN
   end public void m3()
index c96a8e2be7950d4f5fd37aaa2d230f530a1fd28d..6f09fc98a848344b42b0d027a458dbb53395dd67 100644 (file)
@@ -21,5 +21,4 @@
                     INVOKESTATIC Three.aspectOf ()LThree;
                     INVOKEVIRTUAL Three.ajc$afterReturning$Three$3$b48e4ae1 ()V
                     RETURN
-                    RETURN
   end public void m33()
index bfa5c23effd381880810854160c9b07c95546d4c..f1694cbb090ff0b01be743989580d29557edd9df 100644 (file)
@@ -49,6 +49,7 @@ import org.aspectj.apache.bcel.generic.MULTIANEWARRAY;
 import org.aspectj.apache.bcel.generic.NEW;
 import org.aspectj.apache.bcel.generic.ObjectType;
 import org.aspectj.apache.bcel.generic.PUSH;
+import org.aspectj.apache.bcel.generic.RETURN;
 import org.aspectj.apache.bcel.generic.ReturnInstruction;
 import org.aspectj.apache.bcel.generic.SWAP;
 import org.aspectj.apache.bcel.generic.StoreInstruction;
@@ -1792,6 +1793,12 @@ public class BcelShadow extends Shadow {
         * variable to hold the return value, and load the value from this var before
         * returning (see pr148007 for why we do this - it works around a JRockit bug,
         * and is also closer to what javac generates)
+        * 
+        * Sometimes the 'last return' isnt the right one - some rogue code can 
+        * include the real return from the body of a subroutine that exists at the end
+        * of the method. In this case the last return is RETURN but that may not be
+        * correct for a method with a non-void return type... pr151673
+        * 
         * @param returns list of all the return instructions in the shadow
         * @param returnInstructions instruction list into which the return instructions should
         * be generated
@@ -1799,15 +1806,26 @@ public class BcelShadow extends Shadow {
         */
        private BcelVar generateReturnInstructions(List returns, InstructionList returnInstructions) {
                BcelVar returnValueVar = null;
-       InstructionHandle lastReturnHandle = (InstructionHandle)returns.get(returns.size() - 1);
-       Instruction newReturnInstruction = Utility.copyInstruction(lastReturnHandle.getInstruction());
        if (this.hasANonVoidReturnType()) {
+               // Find the last *correct* return - this is a method with a non-void return type
+               // so ignore RETURN
+               Instruction  newReturnInstruction = null;
+               int i=returns.size()-1;
+               while (newReturnInstruction == null && i>=0) {
+                       InstructionHandle ih = (InstructionHandle)returns.get(i);
+                       if (!(ih.getInstruction() instanceof RETURN)) {
+                               newReturnInstruction = Utility.copyInstruction(ih.getInstruction());
+                       }
+                       i--;
+               }
                returnValueVar = genTempVar(this.getReturnType());
             returnValueVar.appendLoad(returnInstructions,getFactory());
+               returnInstructions.append(newReturnInstruction);
        } else {
+               InstructionHandle lastReturnHandle = (InstructionHandle)returns.get(returns.size() - 1);
+               Instruction newReturnInstruction = Utility.copyInstruction(lastReturnHandle.getInstruction());
                returnInstructions.append(newReturnInstruction);
        }
-       returnInstructions.append(newReturnInstruction);
        return returnValueVar;
        }
     
index bb35ec38ce42a7477b0c8fb792abd1be4c6d69e0..a00b8e78a2eb547a5bd105dc893290cc28f0a86f 100644 (file)
@@ -12,7 +12,6 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     |               ATHROW
     |           L0: INVOKESTATIC Aspect.ajc_after_constructor_execution ()V
     |               RETURN
-    |               RETURN
     constructor-execution(void FancyHelloWorld.<init>())
   end public void <init>()
 
@@ -101,7 +100,6 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     |               ATHROW
     |           L7: INVOKESTATIC Aspect.ajc_after_method_execution ()V
     |               RETURN
-    |               RETURN
     method-execution(void FancyHelloWorld.main(java.lang.String[]))
   end public static void main(String[])
 
index 2521c5f3c27c1f0b8f880ead4a1571222dbdf329..982112b967ad544ab664875f4931c0e434df321f 100644 (file)
@@ -12,7 +12,6 @@ public class HelloWorld extends java.lang.Object:
     |               ATHROW
     |           L0: INVOKESTATIC Aspect.ajc_after_constructor_execution ()V
     |               RETURN
-    |               RETURN
     constructor-execution(void HelloWorld.<init>())
   end public void <init>()
 
@@ -54,7 +53,6 @@ public class HelloWorld extends java.lang.Object:
     |               ATHROW
     |           L2: INVOKESTATIC Aspect.ajc_after_method_execution ()V
     |               RETURN
-    |               RETURN
     method-execution(void HelloWorld.main(java.lang.String[]))
   end public static void main(String[])
 
index 8429607db8c9d9f3bf23a0fbd613c53b0f997030..1132efee37fb4425e1df5253c56a2978cc19c0cd 100644 (file)
@@ -6,7 +6,6 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     |               NOP
     |               INVOKESTATIC Aspect.ajc_afterReturning_constructor_execution ()V
     |               RETURN
-    |               RETURN
     constructor-execution(void FancyHelloWorld.<init>())
   end public void <init>()
 
@@ -57,7 +56,6 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     |           L2: NOP   (line 17)
     |               INVOKESTATIC Aspect.ajc_afterReturning_method_execution ()V
     |               RETURN
-    |               RETURN
     method-execution(void FancyHelloWorld.main(java.lang.String[]))
   end public static void main(String[])
 
index abc748eb56ecdfebe712d272664b8131e2e96e5f..28f8980af3b3c02a8413b6d99d1e7761bd67b37d 100644 (file)
@@ -6,7 +6,6 @@ public class HelloWorld extends java.lang.Object:
     |               NOP
     |               INVOKESTATIC Aspect.ajc_afterReturning_constructor_execution ()V
     |               RETURN
-    |               RETURN
     constructor-execution(void HelloWorld.<init>())
   end public void <init>()
 
@@ -26,7 +25,6 @@ public class HelloWorld extends java.lang.Object:
     |               NOP   (line 11)
     |               INVOKESTATIC Aspect.ajc_afterReturning_method_execution ()V
     |               RETURN
-    |               RETURN
     method-execution(void HelloWorld.main(java.lang.String[]))
   end public static void main(String[])
 
index 6016b6d4b22cde231dac86ab00728d3f39a00d84..eeeb8db461e7d2464edad3c0fa9c8fdecd6b6dfe 100644 (file)
@@ -62,7 +62,6 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     |               ALOAD 8
     |               INVOKESTATIC Aspect.ajc_afterReturning_method_execution (Ljava/lang/Object;)V
     |               RETURN
-    |               RETURN
     method-execution(void FancyHelloWorld.main(java.lang.String[]))
   end public static void main(String[])
 
index d1de34129f2b9e71ae986865140406d7731f1bca..373a66bfc3725e7c1e9932a8b9c0fa3537269327 100644 (file)
@@ -25,7 +25,6 @@ public class HelloWorld extends java.lang.Object:
     |               ALOAD_2
     |               INVOKESTATIC Aspect.ajc_afterReturning_method_execution (Ljava/lang/Object;)V
     |               RETURN
-    |               RETURN
     method-execution(void HelloWorld.main(java.lang.String[]))
   end public static void main(String[])
 
index e7abc1f5716682a5b8634e93ca54f2b89a98e016..2da3bfdfc7246549fce8757352dda8262511542e 100644 (file)
@@ -45,7 +45,6 @@ public class HelloWorld extends java.lang.Object:
     |           L1: ALOAD_3
     |               INVOKESTATIC Aspect.ajc_afterReturning_method_execution (Ljava/lang/Object;)V
     |               RETURN
-    |               RETURN
     method-execution(void HelloWorld.main(java.lang.String[]))
   end public static void main(String[])
 
index c6c066ae1c73f02dbb13aba809c0fc41c99f9d22..d52ce2b797ff77944c080c9da6f8ea9779290296 100644 (file)
@@ -53,7 +53,6 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     |           L4: GETSTATIC Aspect.ajc$perCflowStack Lorg/aspectj/runtime/internal/CFlowStack;
     |               INVOKEVIRTUAL org.aspectj.runtime.internal.CFlowStack.pop ()V
     |               RETURN
-    |               RETURN
     method-execution(void FancyHelloWorld.main(java.lang.String[]))
   end public static void main(String[])
 
index 9970f974dfa18b5aa7f3d65f4d05e635b24faa53..b5c9e7c7a5854c042fd29d0a4930ab778b987063 100644 (file)
@@ -30,7 +30,6 @@ public class HelloWorld extends java.lang.Object:
     |           L1: GETSTATIC Aspect.ajc$perCflowStack Lorg/aspectj/runtime/internal/CFlowStack;
     |               INVOKEVIRTUAL org.aspectj.runtime.internal.CFlowStack.pop ()V
     |               RETURN
-    |               RETURN
     method-execution(void HelloWorld.main(java.lang.String[]))
   end public static void main(String[])