C
compiler_newbie
Hi,
I have the following code that is compiled on gcc422 (linux) with -
O3 option. I see that one of the branch is discarded, even though it
is not a dead branch. Is this a bug or a feature?
#include <stdlib.h>
#include <stdio.h>
void show_issue(int number)
{
if( number < 0 ) {
printf("%d is a negative number \n", number);
number = - number;
printf("After conversion: %d\n", number);
if( number < 0 ) {
/* ################ with gcc422 -O3, this branch is
discarded ############ */
printf("Must be INT_MIN since negating has no effect\n");
}
}
else {
printf("%d is positive number\n", number);
}
}
int main()
{
int i;
for(i = 30; i < 32; i++ ) {
show_issue( 1 << i );
}
return 0;
}
I have the following code that is compiled on gcc422 (linux) with -
O3 option. I see that one of the branch is discarded, even though it
is not a dead branch. Is this a bug or a feature?
#include <stdlib.h>
#include <stdio.h>
void show_issue(int number)
{
if( number < 0 ) {
printf("%d is a negative number \n", number);
number = - number;
printf("After conversion: %d\n", number);
if( number < 0 ) {
/* ################ with gcc422 -O3, this branch is
discarded ############ */
printf("Must be INT_MIN since negating has no effect\n");
}
}
else {
printf("%d is positive number\n", number);
}
}
int main()
{
int i;
for(i = 30; i < 32; i++ ) {
show_issue( 1 << i );
}
return 0;
}