Problem with array-notation in a function

Problem with array-notation in a function

Hi,i recently read about the Arraynotation in Cilk and tried to devise a test function of my own: I have an array of length 10, filled with ones and want to change that to twos.Now, when i do that in my main()-function using array notation it's not a problem. However, if i declare my own function and use the array as a parameter, i get a compiler error sayingarraynotation.cpp: In function int foo(int*):arraynotation.cpp:8:4: internal compiler error: Segmentation fault A[:] = 2; ^I am not very experienced using cilk/c++ but this seems to me like there is a bug in the compiler. Or is itin generalforbidden to use this arraynotation outside of the main function (which would not make sense). I used Fedora 16 w/ the cilkplus-branch of the gcc; this is the code i used:

int foo(int A[10]) {

	A[:] = 2;

	return(0);

}
int main(int argc, char** argv)

{

    int A[10];

    A[:]  = 1;

    int b = foo(&A[0]);
    return 0;
}

6 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Hello Leifblase,
In GCC, to use the ":" syntax, the compiler should know the size of array to find the length. When you pass Ainto foo, it is getting A as a pointer and that iswhy it is failing.

So, please replace theA[:] = 2 with A[0:10] = 2

Thanks,

Balaji V. Iyer.


Thank you very much. That was obviously the problem.

When I replaced the code as you suggested, it did not work at first, however. Only after inserting three lines to generate some output (see below) it compiled. Without the for-loop i get a compiler-error saying

array-notation-test.cpp: In function int foo(int*):
array-notation-test.cpp:8:20: internal compiler error: in gimplify_expr, at gimplify.c:7877

I am somewhat confused about this, because the for-loop has obviously nothing to do with the array code. Maybe i will post an answer here when i figure out what exactly happened.

Just to clarify, this works now:

int foo(int A[10]) {

	A[0:10] = 2;

	for (int i = 0; i < 10; i++) {

		cout << A[i];

	}

	cout << endl;

	return(0);

}   

Thanks,
Leif

I am able to reproduce this and I will get back to you as soon as I find a fix. Thank you very much forreporting this bug.

Thanks,

Balaji V. Iyer.

Hello Leif,
I have fixed the bug and submitted a patch (http://gcc.gnu.org/ml/gcc-patches/2012-06/msg00317.html). The patch is already checked into Cilkplus gcc.

Thank again!

Balaji V. Iyer.

Thank you, it works fine now.

Connectez-vous pour laisser un commentaire.