public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/29592]  New: Unending loops
@ 2006-10-25 16:11 darkjames at darkjames dot ath dot cx
  2006-10-25 16:12 ` [Bug c/29592] " darkjames at darkjames dot ath dot cx
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: darkjames at darkjames dot ath dot cx @ 2006-10-25 16:11 UTC (permalink / raw)
  To: gcc-bugs

After compilation test1.c with -O2 program loops unending.. Yeah I know is
possible cause -fstrict-aliasing and program works compilated with -O2 &&
-fno-strict-aliasing 
It works too if it was compilated just only with -fstrict-aliasing so it loops
when some other optimization was turned on.

It works too (not loops unending) if in loop while (* ((char *) str))
we `printf("0x%x\n", str);` (maybe some other code which evaluate and use that
exp works too, i don't really know) [test2.c]

If it's not gcc bug, I'm really sorry inconvience.. (something code like that
was used in ekg2 
#v+
(functions:
http://webcvs.ekg2.org/_checkout_/ekg2/plugins/ncurses/ecurses.c?rev=1.3 

usage:
while (__S(str, 0)) {           /* while (*str)  */
        __SN(&str, 1);                  /* str++ */
        attr++;
}
loops unending, however if __SN() was declared not inline it works... for me it
was really strange, in testcases keyword 'inline' doesn't change behavior.
#v-

If it's not gcc bug, but mine, once again i'm really sorry... Sorry for me
English too.

testcase tested with:
gcc (GCC) 4.1.1 (Gentoo 4.1.1-r1)
gcc (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5)
gcc (GCC) 4.1.0 (SUSE Linux)


-- 
           Summary: Unending loops
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: darkjames at darkjames dot ath dot cx
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29592


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/29592] Unending loops
  2006-10-25 16:11 [Bug c/29592] New: Unending loops darkjames at darkjames dot ath dot cx
@ 2006-10-25 16:12 ` darkjames at darkjames dot ath dot cx
  2006-10-25 16:13 ` darkjames at darkjames dot ath dot cx
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: darkjames at darkjames dot ath dot cx @ 2006-10-25 16:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from darkjames at darkjames dot ath dot cx  2006-10-25 16:12 -------
Created an attachment (id=12490)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12490&action=view)
First testcase

First testcase loops unending with -O2, not loops with -O2 -fno-strict-aliasing
|| 
-fstrict-aliasing -O1


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29592


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/29592] Unending loops
  2006-10-25 16:11 [Bug c/29592] New: Unending loops darkjames at darkjames dot ath dot cx
  2006-10-25 16:12 ` [Bug c/29592] " darkjames at darkjames dot ath dot cx
@ 2006-10-25 16:13 ` darkjames at darkjames dot ath dot cx
  2006-10-25 16:20 ` darkjames at darkjames dot ath dot cx
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: darkjames at darkjames dot ath dot cx @ 2006-10-25 16:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from darkjames at darkjames dot ath dot cx  2006-10-25 16:13 -------
Created an attachment (id=12491)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12491&action=view)
Second testcase

test1.c + added printf() to loop, not loops with -O2 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29592


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/29592] Unending loops
  2006-10-25 16:11 [Bug c/29592] New: Unending loops darkjames at darkjames dot ath dot cx
  2006-10-25 16:12 ` [Bug c/29592] " darkjames at darkjames dot ath dot cx
  2006-10-25 16:13 ` darkjames at darkjames dot ath dot cx
@ 2006-10-25 16:20 ` darkjames at darkjames dot ath dot cx
  2006-10-25 16:45 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: darkjames at darkjames dot ath dot cx @ 2006-10-25 16:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from darkjames at darkjames dot ath dot cx  2006-10-25 16:20 -------
By the way, it's possible to fix the code in other way than using unions?
It just need to work both for wchar_t strings and normal strings...
If you have some ideas how, it'll be nice if you give me some hint...
maybe use char * everywhere and use:

real_char_index = index * (config_use_unicode * sizeof(wchar_t)) ? 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29592


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/29592] Unending loops
  2006-10-25 16:11 [Bug c/29592] New: Unending loops darkjames at darkjames dot ath dot cx
                   ` (2 preceding siblings ...)
  2006-10-25 16:20 ` darkjames at darkjames dot ath dot cx
@ 2006-10-25 16:45 ` pinskia at gcc dot gnu dot org
  2006-10-25 17:12 ` darkjames at darkjames dot ath dot cx
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-10-25 16:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2006-10-25 16:45 -------
In the both case, you are accessing "wchar *" via "char *" which causes an
alias violation.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29592


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/29592] Unending loops
  2006-10-25 16:11 [Bug c/29592] New: Unending loops darkjames at darkjames dot ath dot cx
                   ` (3 preceding siblings ...)
  2006-10-25 16:45 ` pinskia at gcc dot gnu dot org
@ 2006-10-25 17:12 ` darkjames at darkjames dot ath dot cx
  2006-10-25 17:18 ` pinskia at gcc dot gnu dot org
  2006-10-25 17:25 ` darkjames at darkjames dot ath dot cx
  6 siblings, 0 replies; 8+ messages in thread
From: darkjames at darkjames dot ath dot cx @ 2006-10-25 17:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from darkjames at darkjames dot ath dot cx  2006-10-25 17:11 -------
Yeah, I know, but why gcc generate good code if we add that printf to test1.c
(test2.c) ? It's still wchar * -> char * still aliasing violation.

or if we replace:
__SN(&str, 1); with
str = (CHAR_T *) (((char *) str) + 1);

it generate good code too. it's still aliasing violation?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29592


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/29592] Unending loops
  2006-10-25 16:11 [Bug c/29592] New: Unending loops darkjames at darkjames dot ath dot cx
                   ` (4 preceding siblings ...)
  2006-10-25 17:12 ` darkjames at darkjames dot ath dot cx
@ 2006-10-25 17:18 ` pinskia at gcc dot gnu dot org
  2006-10-25 17:25 ` darkjames at darkjames dot ath dot cx
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-10-25 17:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2006-10-25 17:18 -------
(In reply to comment #5)
> Yeah, I know, but why gcc generate good code if we add that printf to test1.c
> (test2.c) ? It's still wchar * -> char * still aliasing violation.

Yes but there is a barrier which cause optimizations not to happen.
> 
> or if we replace:
> __SN(&str, 1); with
> str = (CHAR_T *) (((char *) str) + 1);
> 
> it generate good code too. it's still aliasing violation?

No, that is legal as you are not accessing str (wchar_t*) as a "char*" any
longer but as a "wchar_t*".  You access str as a "wchar_t*" and then cast that
value to a "char*" and then add one and then cast back to "wchar_t*" which
causes the above code to be valid and defined.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29592


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/29592] Unending loops
  2006-10-25 16:11 [Bug c/29592] New: Unending loops darkjames at darkjames dot ath dot cx
                   ` (5 preceding siblings ...)
  2006-10-25 17:18 ` pinskia at gcc dot gnu dot org
@ 2006-10-25 17:25 ` darkjames at darkjames dot ath dot cx
  6 siblings, 0 replies; 8+ messages in thread
From: darkjames at darkjames dot ath dot cx @ 2006-10-25 17:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from darkjames at darkjames dot ath dot cx  2006-10-25 17:24 -------
Ok, one more question, is it possible to gcc print some warnings about code
like that? Cause even with -Wall it doesn't ;( 
gcc4 is quite more verbose than gcc3 so I think 
It'll be better to print warning about situation which doesn't even generate
invalid code...

which actually -Wstrict-aliasing does (according to manpage), but neither
-Wstrict-aliasing nor -Wstrict-aliasing=2 prints warning in that testcode...

I hope it's possible, thx for all.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29592


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-10-25 17:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-25 16:11 [Bug c/29592] New: Unending loops darkjames at darkjames dot ath dot cx
2006-10-25 16:12 ` [Bug c/29592] " darkjames at darkjames dot ath dot cx
2006-10-25 16:13 ` darkjames at darkjames dot ath dot cx
2006-10-25 16:20 ` darkjames at darkjames dot ath dot cx
2006-10-25 16:45 ` pinskia at gcc dot gnu dot org
2006-10-25 17:12 ` darkjames at darkjames dot ath dot cx
2006-10-25 17:18 ` pinskia at gcc dot gnu dot org
2006-10-25 17:25 ` darkjames at darkjames dot ath dot cx

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).