public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/96270] New: stdarg malfunction with -m32 and -Os
@ 2020-07-21 16:06 drh at sqlite dot org
  2020-07-21 16:41 ` [Bug c/96270] " mikpelinux at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: drh at sqlite dot org @ 2020-07-21 16:06 UTC (permalink / raw)
  To: gcc-bugs

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;
}
/**********************************/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-08-04  9:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21 16:06 [Bug c/96270] New: stdarg malfunction with -m32 and -Os drh at sqlite dot org
2020-07-21 16:41 ` [Bug c/96270] " mikpelinux at gmail dot com
2020-07-21 16:55 ` [Bug c/96270] [8/9/10/11 Regression] " jakub at gcc dot gnu.org
2020-07-22  7:53 ` [Bug tree-optimization/96270] " rguenth at gcc dot gnu.org
2020-07-22  8:28 ` rguenth at gcc dot gnu.org
2020-08-04  9:29 ` rguenth at gcc dot gnu.org
2020-08-04  9:29 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).