Porting GDC to QNX

Thomas Kuehne thomas-dloop at kuehne.cn
Mon Apr 23 04:18:56 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sheff schrieb am 2007-04-22:
> Hi!
> I'm porting GDC compiler to QNX (my previous posts related to this topic are: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=51281 and http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=51456)
> I'm almost done here, everything is working great, except one little thing: optimization. It seems to me that -O1, -O2 and -O3 (but not -Os) options generate bad code. The problem is that the following code doesn't work as expected:
>
>     char[] a = "abcd";
>     char[] r;
>
>     r = a.dup.reverse;
>     assert(r == "dcba");
>
>     a = "a\u1235\u1234c";
>     r = a.dup.reverse;
>     assert(r == "c\u1234\u1235a");
>
> When you compile it without optimization everything is ok, but when you use -O for example,
> the following happens:
>
> function _adReverseChar (that's the function that is called when you use .reverse)
> works for a very very very long time, that happens because the "char[] a" parameter
> that is passed to that function is passed wrongly, if you call a.length then you'll
> see that it'll return something like 134_XXX_XXX, i.e a very large number though the
> real size of a string is 4.

What is the ouput of the below code if it is run inside _adReverseChar?

# printf("LEN  %zX\n", a.length);
# printf("PTR  %zX\n", a.ptr);
# size_t* data = &a;
# printf("pre  %zX\n", *(data-1));
# printf("len  %zX\n", *(data));
# printf("ptr  %zX\n", *(data+1));
# printf("post %zX\n", *(data+2));

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFGLJYZLK5blCcjpWoRAmH5AJ9Kr2t386L1mD1pkg1Y2RXuY0Y3iACdGYwt
MyznI2I11SSGFAcjRBEic54=
=rPGB
-----END PGP SIGNATURE-----


More information about the D.gnu mailing list