[Bug c/44947] Optimizer doesn't see setjmp()
--- Comment #4 from cm1 at mumac dot de 2010-07-15 10:14 --- Thanks for the quick explanation and sorry for joining the club of "submit first, read the specs later" folks -- I actually thought I knew them ;) It makes of course sense to use volatile in the presence of setjmp/longjmp but in our case this is hidden underneath a try/catch framework with tons of code being unaware of setjmp/longjmp being involved. Either way, that's our problem. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44947
[Bug c/44947] Optimizer doesn't see setjmp()
--- Comment #3 from pinskia at gmail dot com 2010-07-15 09:19 --- Subject: Re: Optimizer doesn't see setjmp() On Jul 15, 2010, at 2:15 AM, "cm1 at mumac dot de" wrote: > > > --- Comment #1 from cm1 at mumac dot de 2010-07-15 09:15 --- > Sorry, I edited the contents of the precompiler output to make it > more readable > and messed up the auto variable name. Please use this code: > > #include > #include > #include > > #define EXC_TRY 1 > #define EXC_CATCH 2 > > func() > { > const char *p = NULL;/*** auto variable > ***/ IRRC you need volatile here as defined by the c standard. > { >jmp_buf exc_jmp_buf; >int exc_state; > >if (setjmp(exc_jmp_buf) == 0) {/*** setjmp() ***/ > exc_state = EXC_TRY; >} else { > exc_state = EXC_CATCH; >} > >if (exc_state == EXC_TRY) {/*** TRY BLOCK ***/ > p = "some value"; >} > >if (exc_state == EXC_CATCH) { /*** CATCH BLOCK > ***/ > puts(p); >} > } > } > > > -- > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44947 > -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44947
Re: [Bug c/44947] Optimizer doesn't see setjmp()
On Jul 15, 2010, at 2:15 AM, "cm1 at mumac dot de" > wrote: --- Comment #1 from cm1 at mumac dot de 2010-07-15 09:15 --- Sorry, I edited the contents of the precompiler output to make it more readable and messed up the auto variable name. Please use this code: #include #include #include #define EXC_TRY 1 #define EXC_CATCH 2 func() { const char *p = NULL;/*** auto variable ***/ IRRC you need volatile here as defined by the c standard. { jmp_buf exc_jmp_buf; int exc_state; if (setjmp(exc_jmp_buf) == 0) {/*** setjmp() ***/ exc_state = EXC_TRY; } else { exc_state = EXC_CATCH; } if (exc_state == EXC_TRY) {/*** TRY BLOCK ***/ p = "some value"; } if (exc_state == EXC_CATCH) { /*** CATCH BLOCK ***/ puts(p); } } } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44947
[Bug c/44947] Optimizer doesn't see setjmp()
--- Comment #2 from rguenth at gcc dot gnu dot org 2010-07-15 09:18 --- You need to mark auto variables that are life across setjmp/longjmp calls as volatile. -- rguenth at gcc dot gnu dot org changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44947
[Bug c/44947] Optimizer doesn't see setjmp()
--- Comment #1 from cm1 at mumac dot de 2010-07-15 09:15 --- Sorry, I edited the contents of the precompiler output to make it more readable and messed up the auto variable name. Please use this code: #include #include #include #define EXC_TRY 1 #define EXC_CATCH 2 func() { const char *p = NULL;/*** auto variable ***/ { jmp_buf exc_jmp_buf; int exc_state; if (setjmp(exc_jmp_buf) == 0) {/*** setjmp() ***/ exc_state = EXC_TRY; } else { exc_state = EXC_CATCH; } if (exc_state == EXC_TRY) {/*** TRY BLOCK ***/ p = "some value"; } if (exc_state == EXC_CATCH) { /*** CATCH BLOCK ***/ puts(p); } } } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44947