This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Optimizer Bug with gcc-2.95 on Solaris-(2.6|7)


The following code was found in a Linux Usenet-group, but it turned out,
that gcc-2.95 on Solaris-2.6 and
Solaris-7 shows the same behaviour.
CFLAGS="" and CFLAGS="-O3" produce correct results,
CFLAGS="-O" or CFLAGS="-O2" produce false results.

The code is:


#include <stdio.h>

/* If one=1, then the output should be: bit&1 */
unsigned test(unsigned one , unsigned  bit)
{
    unsigned val=  bit & 1;
    unsigned zero= one >> 1;

    val++;
    return zero + ( val>> 1 );
}

int main()
{
  printf("ret=%d\n", test(1,0)); /* should print 0 */
  printf("ret=%d\n", test(1,1)); /* should print 1 */
  printf("ret=%d\n", test(1,65535)); /* should print 1 */

  return 0;
}


So long,
  Juergen Zimmermann

-------------------------------------------------------------------------
  Jrgen Zimmermann                        Department of Computer
Science
  jnzimmer@informatik.uni-kl.de            University of Kaiserslautern
  Phone: +49 631 205 3280                  P.O. Box 3049
  Fax:   +49 631 205 3299                  67653 Kaiserslautern, Germany
  WWW:   http://www.uni-kl.de/AG-Haerder/Zimmermann/
-------------------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]