[Bug c/36255] New: -fstrict-aliasing breaks __builtin_va_args

juanjose dot garciaripoll at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat May 17 11:09:00 GMT 2008


When using -fstrict-aliasing the function LC1_f15 below gets miscompiled. More
precisely, the va_list object is only partially assigned. The system fails to
set the frame size or something similar. In the assembler I see

/*      local function %F15                                           */
static cl_object LC1_f15(cl_narg narg, volatile cl_object *lex0, ...)
{
        cl_object value0;
        cl_object V1;
        va_list args; va_start(args,lex0);
   0:   48 8d 44 24 08          lea    0x8(%rsp),%rax
   5:   48 89 44 24 e0          mov    %rax,-0x20(%rsp)
        if (narg < 1) {
   a:   ba 00 00 00 00          mov    $0x0,%edx
   f:   48 85 ff                test   %rdi,%rdi
  12:   7e 1a                   jle    2e <LC1_f15+0x2e>
          V1=0;
        } else {
          V1= va_arg(args,cl_object);
  14:   8b 44 24 d8             mov    -0x28(%rsp),%eax
  18:   83 f8 30                cmp    $0x30,%eax

Here we are reading -0x28(%rsp) which has not been set. The same code, with gcc
4.1 produces an assignment mov 0x10,-0x28(%rsp) that makes things right. The
preprocessed example follows.

# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.2.3/include/stdarg.h" 1 3 4
# 43 "/usr/lib/gcc/x86_64-linux-gnu/4.2.3/include/stdarg.h" 3 4
typedef __builtin_va_list __gnuc_va_list;
# 105 "/usr/lib/gcc/x86_64-linux-gnu/4.2.3/include/stdarg.h" 3 4
typedef __gnuc_va_list va_list;

typedef long cl_fixnum;
typedef unsigned long cl_index;
typedef union cl_lispunion *cl_object;
typedef cl_fixnum cl_narg;

struct ecl_singlefloat {
 float SFVAL;
};

struct ecl_stack_frame {
 cl_object *bottom;
 cl_object *top;
 cl_object *stack;
};

union cl_lispunion {
 struct ecl_singlefloat SF;
 struct ecl_stack_frame frame;
};

struct cl_env_struct2 {
 cl_index nvalues;
 cl_object values[64];
};

extern struct cl_env_struct2 cl_env2;


static cl_object LC1_f15(cl_narg narg, volatile cl_object *lex0, ...)
{
 cl_object value0;
 cl_object V1;
 va_list args; __builtin_va_start(args,lex0);
 if (narg < 1) {
   V1=0;
 } else {
          V1= __builtin_va_arg(args,cl_object);
 }
 value0=V1; cl_env2.nvalues=1;
 return value0;
}


cl_object LC2__g147(cl_object V1, cl_object V2, cl_object V3)
{
 cl_object T0;
 volatile cl_object lex0[1];
 cl_object value0;
 {
 lex0[0]= V3;
 value0=LC1_f15(1,lex0,MAKE_FIXNUM(-2688612)) ;
 return value0;
}}


-- 
           Summary: -fstrict-aliasing breaks __builtin_va_args
           Product: gcc
           Version: 4.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: juanjose dot garciaripoll at gmail dot com
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36255



More information about the Gcc-bugs mailing list