https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117695

王淳洋 <koule2333 at gmail dot com> changed:

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

--- Comment #3 from 王淳洋 <koule2333 at gmail dot com> ---
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
unsigned long Run_Index;
void report()
{
        fprintf(stderr,"COUNT|%ld|1|lps\n", Run_Index);
        exit(0);
}
int main (argc, argv)
int     argc;
char    *argv[];
{
    int duration = atoi(argv[1]);
    Run_Index = 0;
        signal(SIGALRM, report);
        alarm(duration);
        int ans = 0;
        for (Run_Index = 1; ; Run_Index++)
        {
                ans += Run_Index;
        }
        printf("%d\n", ans);
}

I have written a shorter test to describe the situation I encountered. This
time it has nothing to do with LTO. gcc -O2 will eliminate the loop in test.c,
resulting in the loss of calculations related to Run_Index, even though there
is a use of Run_Index in the report function. I wonder if this is reasonable?

Reply via email to