# compiler error at goto label

**URL:** <https://forums.developer.nvidia.com/t/compiler-error-at-goto-label/8603>\
**Category:** CUDA Programming and Performance\
**Created:** [March 29, 2009, 12:19am UTC](https://forums.developer.nvidia.com/t/compiler-error-at-goto-label/8603 "2009-03-29T00:19:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pug](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pug](https://forums.developer.nvidia.com/u/pug)\
**Post date:** [March 29, 2009, 12:19am UTC](https://forums.developer.nvidia.com/t/compiler-error-at-goto-label/8603/1 "2009-03-29T00:19:58Z")

</div>

Hi,

I get the compiler error

> [@](#):
>
> ptxas info : Compiling entry function ‘\_Z8kernel53v’
> 
> nvcc error : ‘ptxas’ died due to signal 11 (Invalid memory reference)
> 
> # –error 0xb –

with the kernel code

```auto
__global__ void kernel53(){

int xx = 0;

int psize=10;

goto L109;

L80:

if (xx>15) goto exception;

if (xx>20) goto exception;

xx+=1;

L109:

if (xx<psize) goto L80;

return;

exception:

return;

}

```

If the line _if (xx\>20) goto exception;_ is changed to _if (xx\>20) xx+=1;_ the compilation works.

The same happens in my real program. If I change the last goto exception to some expression that isn’t a goto or a return statement it works just fine and the program returns the correct results.

OS: Kubuntu 8.04

Kernel: 2.6.28.7

Cuda Toolkit: 2.1

Cuda SDK: 2.1

Host Compiler: gcc 4.2.4

Compiler Command: nvcc -g --verbose --shared --ptxas-options=-v -o libtest.so test.cu -L/usr/local/cuda/lib/ -lcudart

Graphic Card: GeForce 8600M GS

---

<div class="post-metadata">

**Author:** ![Noel\_Lopes](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Noel\_Lopes](https://forums.developer.nvidia.com/u/Noel_Lopes)\
**Post date:** [March 29, 2009, 12:57am UTC](https://forums.developer.nvidia.com/t/compiler-error-at-goto-label/8603/2 "2009-03-29T00:57:50Z")

</div>

wow, that remind me when I first start programming basic. There are some valid uses for goto. But this doesn’t seem to fit.

You should try something like this, instead:

```auto
__global__ void kernel53(){

   int xx = 0;

   int psize=10;

bool exception = false;

while (xx<psize) {

	  if (xx>15) {

		  exception = true;

		  break;

	  }

	  if (xx>20) { // you do realize this is not going to happen, but since it was on the original code		  

		  exception = true;

		  break;		

	  }

	 xx+=1;

   }

if (exception) {

	 //do what you have to do

   }

}

```

---

<div class="post-metadata">

**Author:** ![pug](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pug](https://forums.developer.nvidia.com/u/pug)\
**Post date:** [March 29, 2009, 12:49pm UTC](https://forums.developer.nvidia.com/t/compiler-error-at-goto-label/8603/3 "2009-03-29T12:49:44Z")

</div>

> [@](#):
>
> wow, that remind me when I first start programming basic. There are some valid uses for goto. But this doesn’t seem to fit.
> 
> You should try something like this, instead:
> 
> ,

I’m not aware that there are any limitations on the use of goto in c or cuda. Basically your while loop would be translated into the goto statements ;)

As I’m generating the cuda code out of Java Byte Code it is easier to use the already present goto statements. Looking for loop structures and transforming the gotos into loops would be more complicated and I’m not sure it would work in all occasions.

The second condition does not make sense but it is necessary to generate the compiler error ;)
