home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / gnu / gcc / bug / 3150 < prev    next >
Encoding:
Text File  |  1993-01-08  |  5.9 KB  |  672 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!solace.me.uiuc.edu!tiller
  3. From: tiller@solace.me.uiuc.edu (Mike Tiller)
  4. Subject: Possible Bug in gcc-2.3.3
  5. Message-ID: <C0K8BE.2Ko@news.cso.uiuc.edu>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: University of Illinois at Urbana
  8. Distribution: gnu
  9. Date: Sat, 9 Jan 1993 00:06:49 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 659
  12.  
  13. Possible bug or possible stupidity on my part.  The following
  14. program (the gcc -E output is at the end) compiles and runs
  15. fine without optimization but goes into an infinite loop with
  16. optimization.  My configuration is sparc-sun-sunos4.1 .
  17.  
  18. Here is the program, basically it just tests how many loops it
  19. can go through before the alarm goes off.  If optimization is
  20. turned on, the signal handling routine DOES get called, but
  21. the loop is optimized so as to ignore the 'done' variable.  As
  22. far as I can tell this is legal C.  Maybe I should make done
  23. 'volatile' or something, I don't know that is why I'm posting
  24. this.
  25.  
  26. #include    <sys/time.h>
  27. #include    <signal.h>
  28. #include    <stdio.h>
  29.  
  30. int done = 0;
  31.  
  32. void
  33. init_timer(long sec, long usec)
  34. {
  35.     struct  itimerval   value;
  36.  
  37.     value.it_interval.tv_sec = 0;
  38.     value.it_interval.tv_usec = 0;
  39.     value.it_value.tv_sec = sec;
  40.     value.it_value.tv_usec = usec;
  41.  
  42.     setitimer(ITIMER_VIRTUAL, &value, NULL);
  43. }
  44.  
  45. void
  46. handler(int sig, int code, struct sigcontext *scp, char *addr)
  47. {
  48.     printf("handler called!\n");
  49.     done = 1;
  50. }
  51.  
  52. int
  53. main(int argc, char **argv)
  54. {
  55.     long    c1,c2;
  56.  
  57.     signal(SIGVTALRM, handler);
  58.  
  59.     done = 0; init_timer(2,0);
  60.     for(c1=1;c1<100000 && !done;c1++)
  61.         for(c2=1;c2<100000 && !done;c2++);
  62.     printf("Looping = %ld.%d\n", c1, c2/1000);
  63. }
  64.  
  65. It goes into an infinite loop because as far as I can tell it doesn't
  66. check done in the loops (it doesn't recognize the possible side effect
  67. of the signal).  Does this violate some ANSI rule?
  68.  
  69. Thanks, here is the gcc -E output...
  70.  
  71. # 1 "bug.c"
  72. # 1 "/usr/include/sys/time.h" 1 3
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. struct timeval {
  90.     long    tv_sec;         
  91.     long    tv_usec;     
  92. };
  93.  
  94. struct timezone {
  95.     int    tz_minuteswest;     
  96.     int    tz_dsttime;     
  97. };
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. struct    itimerval {
  133.     struct    timeval it_interval;     
  134.     struct    timeval it_value;     
  135. };
  136.  
  137.  
  138.  
  139. # 1 "/usr/include/time.h" 1 3
  140.  
  141.  
  142.  
  143.  
  144.  
  145. # 1 "/usr/local/gnu/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/include/sys/stdtypes.h" 1 3
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159. typedef    int        sigset_t;     
  160.  
  161. typedef    unsigned int    speed_t;     
  162. typedef    unsigned long    tcflag_t;     
  163. typedef    unsigned char    cc_t;         
  164. typedef    int        pid_t;         
  165.  
  166. typedef    unsigned short    mode_t;         
  167. typedef    short        nlink_t;     
  168.  
  169. typedef    long        clock_t;     
  170. typedef    long        time_t;         
  171.  
  172.  
  173.  
  174. typedef    int        size_t;         
  175.  
  176.  
  177.  
  178. typedef int        ptrdiff_t;     
  179.  
  180.  
  181.  
  182.  
  183. typedef    unsigned short    wchar_t;     
  184.  
  185.  
  186.  
  187. # 6 "/usr/include/time.h" 2 3
  188.  
  189.  
  190.  
  191.  
  192. struct    tm {
  193.     int    tm_sec;
  194.     int    tm_min;
  195.     int    tm_hour;
  196.     int    tm_mday;
  197.     int    tm_mon;
  198.     int    tm_year;
  199.     int    tm_wday;
  200.     int    tm_yday;
  201.     int    tm_isdst;
  202.     char    *tm_zone;
  203.     long    tm_gmtoff;
  204. };
  205.  
  206. extern    struct tm *gmtime(), *localtime();
  207. extern    char *asctime(), *ctime();
  208. extern    void tzset(), tzsetwall();
  209. extern  int dysize();
  210. extern  time_t timelocal(), timegm();
  211.  
  212.  
  213. # 67 "/usr/include/sys/time.h" 2 3
  214.  
  215.  
  216.  
  217.  
  218. # 1 "bug.c" 2
  219.  
  220. # 1 "/usr/include/signal.h" 1 3
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235. # 1 "/usr/local/gnu/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/include/sys/signal.h" 1 3
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251. # 1 "/usr/include/vm/faultcode.h" 1 3
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281. typedef    int    faultcode_t;     
  282.  
  283.  
  284.  
  285. # 16 "/usr/local/gnu/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/include/sys/signal.h" 2 3
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303. # 51 "/usr/local/gnu/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/include/sys/signal.h" 3
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324. # 82 "/usr/local/gnu/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/include/sys/signal.h" 3
  325.  
  326. # 98 "/usr/local/gnu/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/include/sys/signal.h" 3
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395. void    (*signal())();
  396.  
  397.  
  398.  
  399.  
  400. void  (*sigset())();
  401. int   sighold();
  402. int   sigrelse();
  403. int   sigignore();
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410. struct    sigvec {
  411.     void    (*sv_handler)();     
  412.     int    sv_mask;         
  413.     int    sv_flags;         
  414. };
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433. struct    sigstack {
  434.     char    *ss_sp;             
  435.     int    ss_onstack;         
  436. };
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445. struct    sigcontext {
  446.     int    sc_onstack;         
  447.     int    sc_mask;         
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.     int    sc_sp;             
  463.     int    sc_pc;             
  464.     int    sc_npc;             
  465.     int    sc_psr;             
  466.     int    sc_g1;             
  467.     int    sc_o0;
  468.     int    sc_wbcnt;         
  469.     char    *sc_spbuf[31    ];  
  470.     int    sc_wbuf[31    ][16];  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479. };
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525. struct    sigaction {
  526.     void         (*sa_handler)();
  527.     sigset_t    sa_mask;
  528.     int        sa_flags;
  529. };
  530.  
  531.  
  532.  
  533.  
  534.  
  535. void    (*signal())();
  536. int    kill( );
  537. int    sigaction( 
  538. );
  539. int    sigaddset( );
  540. int    sigdelset( );
  541. int    sigemptyset( );
  542. int    sigfillset( );
  543. int    sigismember( );
  544. int    sigpending( );
  545. int    sigprocmask( );
  546. int    sigsuspend( );
  547.  
  548.  
  549.  
  550. # 15 "/usr/include/signal.h" 2 3
  551.  
  552. # 90 "/usr/include/signal.h" 3
  553.  
  554.  
  555. # 2 "bug.c" 2
  556.  
  557. # 1 "/usr/local/gnu/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/include/stdio.h" 1 3
  558.  
  559.  
  560.  
  561.  
  562.  
  563. extern    struct    _iobuf {
  564.     int    _cnt;
  565.     unsigned char *_ptr;
  566.     unsigned char *_base;
  567.     int    _bufsiz;
  568.     short    _flag;
  569.     char    _file;         
  570. } _iob[];
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611. extern struct _iobuf     *fopen();
  612. extern struct _iobuf     *fdopen();
  613. extern struct _iobuf     *freopen();
  614. extern struct _iobuf     *popen();
  615. extern struct _iobuf     *tmpfile();
  616. extern long    ftell();
  617. extern char    *fgets();
  618. extern char    *gets();
  619. extern char    *sprintf();
  620. extern char    *ctermid();
  621. extern char    *cuserid();
  622. extern char    *tempnam();
  623. extern char    *tmpnam();
  624.  
  625.  
  626. extern    int    printf(char *, ...);
  627. extern    int    fprintf(struct _iobuf  *, char *, ...);
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634. # 3 "bug.c" 2
  635.  
  636.  
  637. int    done = 0;
  638.  
  639. void
  640. init_timer(long sec, long usec)
  641. {
  642.     struct    itimerval    value;
  643.  
  644.     value.it_interval.tv_sec = 0;
  645.     value.it_interval.tv_usec = 0;
  646.     value.it_value.tv_sec = sec;
  647.     value.it_value.tv_usec = usec;
  648.  
  649.     setitimer(1 , &value, 0 );
  650. }
  651.  
  652. void
  653. handler(int sig, int code, struct sigcontext *scp, char *addr)
  654. {
  655.     done = 1;
  656. }
  657.  
  658. int
  659. main(int argc, char **argv)
  660. {
  661.     long    c1,c2;
  662.  
  663.     signal(26    , handler);
  664.  
  665.     done = 0; init_timer(2,0);
  666.     for(c1=1;c1<100000 && !done;c1++)
  667.         for(c2=1;c2<100000 && !done;c2++);
  668.     printf("Looping = %ld.%d\n", c1, c2/1000);
  669. }
  670.  
  671.  
  672.