Syncleus / aparapi

The New Official Aparapi: a framework for executing native Java and Scala code on the GPU.

Home Page:http://aparapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bounty $20] Pre-increment (++var) and pre-decrement (--var) throw exception.

freemo opened this issue · comments

calling ++var or --var throws an exception on code gen. However the post forms such as var-- work just fine.

This bug is demonstrated in the following unit test: https://github.com/Syncleus/aparapi/blob/master/src/test/java/com/aparapi/codegen/test/ContinueTortureTest.java

in that unit test if converted to a post decrement it works fine. As is it produces the following exception:

java.lang.AssertionError: Unexpected exception com.aparapi.internal.exception.CodeGenException: ifle -> 0065

	at com.aparapi.codegen.CodeGenJUnitBase.test(CodeGenJUnitBase.java:126)
	at com.aparapi.codegen.test.ContinueTortureTest.ContinueTortureTest(ContinueTortureTest.java:29)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: com.aparapi.internal.exception.CodeGenException: ifle -> 0065
	at com.aparapi.internal.writer.BlockWriter.writeInstruction(BlockWriter.java:748)
	at com.aparapi.internal.writer.KernelWriter.writeInstruction(KernelWriter.java:780)
	at com.aparapi.internal.writer.BlockWriter.writeSequence(BlockWriter.java:299)
	at com.aparapi.internal.writer.BlockWriter.writeBlock(BlockWriter.java:323)
	at com.aparapi.internal.writer.BlockWriter.writeMethodBody(BlockWriter.java:848)
	at com.aparapi.internal.writer.KernelWriter.write(KernelWriter.java:738)
	at com.aparapi.internal.writer.KernelWriter.writeToString(KernelWriter.java:792)
	at com.aparapi.codegen.CodeGenJUnitBase.test(CodeGenJUnitBase.java:82)
	... 23 more

this issue is actually unrelated to the post or predecrement itself. Instead the issue is that the system wasnt correctly parsing a "ifge" or similar bytecode conditional if it was reached outside of a composite if. This can be nduced by the conditional on a line by itself or as part of an if statement with an empty block. Regardless this has been fixed now.