[Bug c/96270] New: stdarg malfunction with -m32 and -Os

drh at sqlite dot org gcc-bugzilla@gcc.gnu.org
Tue Jul 21 16:06:08 GMT 2020


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

            Bug ID: 96270
           Summary: stdarg malfunction with -m32 and -Os
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: drh at sqlite dot org
  Target Milestone: ---

gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2), the Default install on ubuntu 20.04

A long long int varargs parameter goes in as 0xfff7ffffffff but comes out as
0xffffffffffff. In other words, bit 35 is getting set somehow.  (The "7"
changes to an "f".) This only happens with -m32 and one of -O2 or -Os.  It
works correctly with -O0, -O1 or without -m32.

Test program "b1.c" shown below.  To compile and run:

     gcc -Os -m32 b1.c && ./a.out 1

The test program:

/********************************************/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
struct val {
  union {
    double r;
    long long int i;
  } u;
  unsigned char type;
};
void f1(const char *b, ...){
  long long int v;
  va_list ap;
  va_start(ap, b);
  v = va_arg(ap, long long int);
  printf("IN f1:   %016llx\n", v);
  va_end(ap);
}
void f2(struct val *p){
  if( p->type & 0x01 ){
    f1("1",p->u.i);
  }else{
    f1("3",p->u.r);
  }
}
int main(int argc, char **argv){
  int i;
  struct val x;
  x.u.i = -2251799813685249LL;
  for(i=1; i<argc; i++){
    x.type = atoi(argv[i]);
    printf("in main: %016llx\n", x.u.i);
    f2(&x);
  }
  return 0;
}
/**********************************/


More information about the Gcc-bugs mailing list