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]
Other format: [Raw text]

[Bug c++/14531] New: pessimise code, loose constantness


I've found some case, where g++ fails to recognize an expression as compile time const 
(ok, it recognizes it, but delays initialization till program run) 
 
 
Here is the case source with g++ and icc8 assember output. Just look on how subidx_rmap is 
initialized. 
 
--- const_array.cpp --- 
    //! calculates offset of (unambigous, non-virtual) BASE in CHILD 
    //! @param  TYPE    class inhereted from BASE 
    //! @param  BASE    the base class for TYPE 
    //! @note it looks like C++ mandates NULL pointer to be always casted to NULL, hence i 	 
    //!           use 0x1000 here. 
#define base_delta(TYPE, BASE)  ( (signed long)((static_cast<BASE*>( 
reinterpret_cast<TYPE*>(0x1000UL) ))) - 0x1000 ) 
 
struct A 
{ 
	int a; 
}; 
 
struct B 
{ 
    int b; 
}; 
 
 
struct C : public A, public B 
{ 
}; 
 
 
 
const signed long subidx_rmap[] =  
{ 
    base_delta(C, B), 
    33, 
    137 
}; 
 
--------------------------------- 
 
---const_array.s.g++---- 
	.file	"const_array.cpp" 
	.local	subidx_rmap 
	.comm	subidx_rmap,12,4 
	.text 
	.align 2 
	.type	__static_initialization_and_destruction_0(int, int), @function 
__static_initialization_and_destruction_0(int, int): 
.LFB3: 
	pushl	%ebp 
.LCFI0: 
	movl	%esp, %ebp 
.LCFI1: 
	cmpl	$65535, 12(%ebp) 
	jne	.L1 
	cmpl	$1, 8(%ebp) 
	jne	.L1 
	movl	$4, %eax 
	movl	%eax, subidx_rmap 
	movl	$33, subidx_rmap+4 
	movl	$137, subidx_rmap+8 
.L1: 
	popl	%ebp 
	ret 
.LFE3: 
	.size	__static_initialization_and_destruction_0(int, int), 
.-__static_initialization_and_destruction_0(int, int) 
	.align 2 
	.type	_GLOBAL__I_const_array.cppG85Xva, @function 
_GLOBAL__I_const_array.cppG85Xva: 
.LFB5: 
	pushl	%ebp 
.LCFI2: 
	movl	%esp, %ebp 
.LCFI3: 
	subl	$8, %esp 
.LCFI4: 
	movl	$65535, 4(%esp) 
	movl	$1, (%esp) 
	call	__static_initialization_and_destruction_0(int, int) 
	leave 
	ret 
.LFE5: 
	.size	_GLOBAL__I_const_array.cppG85Xva, .-_GLOBAL__I_const_array.cppG85Xva 
	.section	.ctors,"aw",@progbits 
	.align 4 
	.long	_GLOBAL__I_const_array.cppG85Xva 
	.section	.note.GNU-stack,"",@progbits 
	.ident	"GCC: (GNU) 3.3.3" 
-------------------------------- 
 
---const_array.s.icc--- 
# -- Machine type IA32 
# mark_description "Intel(R) C++ Compiler for 32-bit applications, Version 8.0   Build 
20031016Z %s"; 
# mark_description "-long_double -Wall -S -o const_array.s.icc"; 
	.ident "Intel(R) C++ Compiler for 32-bit applications, Version 8.0   Build 20031016Z %s" 
	.ident "-long_double -Wall -S -o const_array.s.icc" 
	.file "const_array.cpp" 
	.text 
	.data 
	.align 4 
	.bss 
	.align 4 
	.section .rodata, "a" 
	.align 4 
	.section .data1, "wa" 
	.align 4 
	.section .text1, "wa" 
	.align 4 
	.section .rodata, "a" 
	.align 4 
subidx_rmap: 
	.long 4	# s32 
	.long 33	# s32 
	.long 137	# s32 
	.type	subidx_rmap,@object 
	.size	subidx_rmap,12 
	.data 
	.section .text 
.LNDBG_TXe: 
# End 
--------------------------------- 
 
g++ info: 
[kirr@tugrik test]$ g++ -v 
Reading specs from /usr/local/gcc-3.3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/specs 
Configured with: ../gcc-3.3.3/configure --prefix=/usr/local/gcc-3.3.3 --enable-threads=posix 
--enable-languages=c,c++,f77 --enable-checking --disable-nls 
Thread model: posix 
gcc version 3.3.3

-- 
           Summary: pessimise code, loose constantness
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: smelkov at mph1 dot phys dot spbu dot ru
                CC: gcc-bugs at gcc dot gnu dot org
 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=14531


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