[Bug c++/39496] New: GCC uses non-standard calling conventions, even with -O0

2009-03-18 Thread jimb at red-bean dot com
Even when compiling with -O0, GCC uses non-standard parameter passing
conventions for static inline functions, which makes debugging difficult.

In this case, the function of interest converts a tagged value to a pointer;
it's very helpful to be able to use this in GDB 'print' commands.

In the assembly code shown, notice that the function is expecting to find its
argument in %eax, even though the standard IA-32 calling conventions pass the
first argument on the stack.  The GDB session also demonstrates this.

$ (cd ~/gcc/gcc; svn info)
Path: .
URL: svn://gcc.gnu.org/svn/gcc/trunk
Repository Root: svn://gcc.gnu.org/svn/gcc
Repository UUID: 138bc75d-0d04-0410-961f-82ee72b054a4
Revision: 144927
Node Kind: directory
Schedule: normal
Last Changed Author: gccadmin
Last Changed Rev: 144927
Last Changed Date: 2009-03-17 17:16:40 -0700 (Tue, 17 Mar 2009)

$ cat jsobj.i
extern "C"
{
  static inline struct JSObject *JSVAL_TO_OBJECT (int v)
  {
return (struct JSObject *) (v & ~3);
  }
}
static int
obj_toSource (int *vp)
{
  JSVAL_TO_OBJECT (vp[0]);
}
int
main(int argc, char **argv)
{
}
$ c++ -v -O0 -g jsobj.i -o jsobj -save-temps
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/jimb/gcc
--enable-languages=c,c++
Thread model: posix
gcc version 4.4.0 20090318 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-O0' '-g' '-o' 'jsobj' '-save-temps' '-shared-libgcc'
'-mtune=generic'
 /home/jimb/gcc/libexec/gcc/i686-pc-linux-gnu/4.4.0/cc1plus -fpreprocessed
jsobj.i -quiet -dumpbase jsobj.i -mtune=generic -auxbase jsobj -g -O0 -version
-o jsobj.s
GNU C++ (GCC) version 4.4.0 20090318 (experimental) (i686-pc-linux-gnu)
compiled by GNU C version 4.4.0 20090318 (experimental), GMP version
4.2.2, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 00b593c3c99bbacc875575ff2b6655cc
COLLECT_GCC_OPTIONS='-v' '-O0' '-g' '-o' 'jsobj' '-save-temps' '-shared-libgcc'
'-mtune=generic'
 as -V -Qy -o jsobj.o jsobj.s
GNU assembler version 2.18.93 (i486-linux-gnu) using BFD version (GNU Binutils
for Ubuntu) 2.18.93.20081009
COMPILER_PATH=/home/jimb/gcc/libexec/gcc/i686-pc-linux-gnu/4.4.0/:/home/jimb/gcc/libexec/gcc/i686-pc-linux-gnu/4.4.0/:/home/jimb/gcc/libexec/gcc/i686-pc-linux-gnu/:/home/jimb/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/:/home/jimb/gcc/lib/gcc/i686-pc-linux-gnu/
LIBRARY_PATH=/home/jimb/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/:/home/jimb/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-O0' '-g' '-o' 'jsobj' '-save-temps' '-shared-libgcc'
'-mtune=generic'
 /home/jimb/gcc/libexec/gcc/i686-pc-linux-gnu/4.4.0/collect2 --eh-frame-hdr -m
elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o jsobj /usr/lib/crt1.o
/usr/lib/crti.o /home/jimb/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/crtbegin.o
-L/home/jimb/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0
-L/home/jimb/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/../../.. jsobj.o -lstdc++ -lm
-lgcc_s -lgcc -lc -lgcc_s -lgcc
/home/jimb/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/crtend.o /usr/lib/crtn.o
$ cat jsobj.s
...
JSVAL_TO_OBJECT:
.LFB0:
.file 1 "jsobj.i"
.loc 1 4 0
.cfi_startproc
.cfi_personality 0x0,__gxx_personality_v0
pushl   %ebp
.cfi_def_cfa_offset 8
movl%esp, %ebp
.cfi_offset 5, -8
.cfi_def_cfa_register 5
subl$4, %esp
movl%eax, -4(%ebp)
.loc 1 5 0
movl-4(%ebp), %eax
andl$-4, %eax
.loc 1 6 0
leave
ret
...
$ gdb jsobj
GNU gdb (GDB) 6.8.50.20090106-cvs
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
(gdb) start
Temporary breakpoint 1 at 0x804844c: file jsobj.i, line 16.
Starting program: /home/jimb/mc/b/static-call/jsobj 

Temporary breakpoint 1, main (argc=1, argv=0xb8a4) at jsobj.i:16
16  }
Current language:  auto; currently c++
(gdb) set $eax = 0x42424242
(gdb) print JSVAL_TO_OBJECT(0x53535353)
$1 = (struct JSObject *) 0x42424240
(gdb) quit
The program is running.  Quit anyway (and kill it)? (y or n) y
$


-- 
       Summary: GCC uses non-standard calling conventions, even with -O0
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jimb at red-bean dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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



[Bug c++/39496] GCC uses non-standard calling conventions, even with -O0

2009-03-18 Thread jimb at red-bean dot com


--- Comment #1 from jimb at red-bean dot com  2009-03-18 21:11 ---
Created an attachment (id=17490)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17490&action=view)
Test case

This is the same test case used in the transcript; attached just for
convenience.


-- 


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



[Bug target/39496] [4.2/4.3 Regression] GCC uses non-standard calling conventions for static functions with -O0.

2009-03-19 Thread jimb at red-bean dot com


--- Comment #9 from jimb at red-bean dot com  2009-03-19 19:51 ---
Fixed for me in r144969.  Thank you all!


-- 


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



[Bug c++/43312] New: G++ emits bad DWARF for pointers to member functions

2010-03-09 Thread jimb at red-bean dot com
 DW_AT_sibling : <0xcf>   
 <2>: Abbrev Number: 15 (DW_TAG_member)
   DW_AT_name: (indirect string, offset: 0x78): __pfn   
   DW_AT_decl_file   : 1
   DW_AT_decl_line   : 6
   DW_AT_type: <0xe4>   
   DW_AT_data_member_location: 2 byte block: 23 0  
(DW_OP_plus_uconst: 0)
 <2>: Abbrev Number: 15 (DW_TAG_member)
   DW_AT_name: (indirect string, offset: 0x4a): __delta 
   DW_AT_decl_file   : 1
   DW_AT_decl_line   : 6
   DW_AT_type: <0x59>   
   DW_AT_data_member_location: 2 byte block: 23 4  
(DW_OP_plus_uconst: 4)
 <1>: Abbrev Number: 16 (DW_TAG_subroutine_type)
   DW_AT_type: <0x59>   
   DW_AT_sibling : <0xe4>   
 <2>: Abbrev Number: 5 (DW_TAG_formal_parameter)
       DW_AT_type: <0x60>   
   DW_AT_artificial  : 1
 <2>: Abbrev Number: 6 (DW_TAG_formal_parameter)
   DW_AT_type: <0x59>   
 <1>: Abbrev Number: 8 (DW_TAG_pointer_type)
   DW_AT_byte_size   : 4
   DW_AT_type: <0xcf>   

$


-- 
   Summary: G++ emits bad DWARF for pointers to member functions
   Product: gcc
   Version: 4.5.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jimb at red-bean dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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



[Bug c++/45492] New: G++ permits function-to-data pointer conversions with __extension__ in functions, but not function templates

2010-09-01 Thread jimb at red-bean dot com
With trunk G++:

$ ~/gcc/bin/g++ --version
g++ (GCC) 4.6.0 20100901 (experimental)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat fdc.cc
extern void cf();

// no warning
void *f() { return __extension__ (void *) cf; }

// warning:
// ISO C++ forbids casting between pointer-to-function and pointer-to-object
template
void *ft() { return __extension__ (void *) cf; }

template void *ft();
$ LD_LIBRARY_PATH=$HOME/gcc/lib ~/gcc/bin/g++ -Wall -pedantic -c fdc.cc
fdc.cc: In function ‘void* ft() [with bool flag = true]’:
fdc.cc:11:25:   instantiated from here
fdc.cc:9:44: warning: ISO C++ forbids casting between pointer-to-function and
pointer-to-object [enabled by default]

I would expect G++ to either complain about both casts, or neither; whether the
code appears in a function template shouldn't matter.


-- 
   Summary: G++ permits function-to-data pointer conversions with
__extension__ in functions, but not function templates
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jimb at red-bean dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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



[Bug c++/36266] New: C++ typedef misplaced in DWARF information

2008-05-19 Thread jimb at red-bean dot com
n : 1
 <1><79>: Abbrev Number: 9 (DW_TAG_pointer_type)
  <7a> DW_AT_byte_size   : 4
  <7b> DW_AT_type: <7f>
 <1><7f>: Abbrev Number: 10 (DW_TAG_const_type)
  <80> DW_AT_type: <25>
 <1><84>: Abbrev Number: 11 (DW_TAG_structure_type)
  <85> DW_AT_specification: <42>
  <89> DW_AT_byte_size   : 4
  <8a> DW_AT_decl_file   : 1
  <8b>     DW_AT_decl_line   : 6
  <8c> DW_AT_sibling : <99>
 <2><90>: Abbrev Number: 12 (DW_TAG_member)
  <91> DW_AT_type: <4c>
  <95> DW_AT_data_member_location: 2 byte block: 23 0  
(DW_OP_plus_uconst: 0)
 <1><99>: Abbrev Number: 10 (DW_TAG_const_type)
  <9a> DW_AT_type: <84>
 <1><9e>: Abbrev Number: 13 (DW_TAG_variable)
  <9f> DW_AT_specification: <6c>

$


-- 
   Summary: C++ typedef misplaced in DWARF information
   Product: gcc
   Version: 4.4.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jimb at red-bean dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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