User account creation filtered due to spam.

Bug 19704 - ICE for tail call of regparm 3 and dllimport
Summary: ICE for tail call of regparm 3 and dllimport
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
Keywords: ice-on-valid-code, patch
Depends on:
Reported: 2005-01-30 04:48 UTC by Danny Smith
Modified: 2005-10-12 21:09 UTC (History)
1 user (show)

See Also:
Host: i686-pc-mingw32
Target: i686-pc-mingw32
Build: i686-pc-mingw32
Known to work:
Known to fail:
Last reconfirmed: 2005-01-30 05:37:07


Note You need to log in before you can comment on or make changes to this bug.
Description Danny Smith 2005-01-30 04:48:47 UTC
C++ methods that have both dllimport and regparm(3) can result in 
"unable to find a register to spill in class 'CREG'" error message when 
compiled at -O2 or -Os

This causes windows port of Mozilla to fail as reported at:

Here is reduced testcase:
// imp_regparm_method.cpp

struct Bar
  char* data;
  int getlen() const;
  char* getdata() const;
  __declspec(dllimport) void __attribute__ ((regparm(3))) assign(char*, int);

struct Foo
        Bar foobar;
        void GetData();

void Foo::GetData()
    foobar.assign(foobar.getdata(), foobar.getlen());

g++ -c -Os imp_regparm_method.cpp 

C:\WINNT\Profiles\danny\Desktop>g++-4.0.0  -c -Os imp_regparm_method.cpp 
imp_regparm_method.cpp: In member function 'void Foo::GetData()':
imp_regparm_method.cpp:18: error: unable to find a register to spill in 
class 'CREG'
imp_regparm_method.cpp:18: error: this is the insn:
(call_insn/j:HI 24 23 25 0 (call (mem:QI (reg/f:SI 4 si [62]) [0 S1 A8])
        (const_int 0 [0x0])) 358 {*sibcall_1} (insn_list:REG_DEP_TRUE 20 
(insn_list:REG_DEP_TRUE 21 (insn_list:REG_DEP_TRUE 22 (insn_list:REG_DEP_TRUE 
23 (nil)))))
    (expr_list:REG_DEAD (reg:SI 2 cx [ D.1581 ])
        (expr_list:REG_DEAD (reg:SI 1 dx [ D.1582 ])
            (expr_list:REG_DEAD (reg:SI 0 ax [ D.1580 ])
                (expr_list:REG_DEAD (reg/f:SI 4 si [62])
    (expr_list:REG_DEP_TRUE (use (reg:SI 0 ax [ D.1580 ]))
        (expr_list:REG_DEP_TRUE (use (reg:SI 1 dx [ D.1582 ]))
            (expr_list:REG_DEP_TRUE (use (reg:SI 2 cx [ D.1581 ]))
imp_regparm_method.cpp:18: confused by earlier errors, bailing out

Changing regparm(3) to regparm(2) avoids the error.
Removing dllimport attribute  avoids the error.
Making Foo::GetData inline avoids the error.

The failure occurs with GCC 4.0 and 3.4.4.  But not with 3.3.3 nor 2.95.3

Comment 1 Andrew Pinski 2005-01-30 05:37:07 UTC
Here is the reduced testcase which shows that it has nothing to do with C++ methods at all but just tail 
call and regparm 3 and dllimport:

__declspec(dllimport) void __attribute__ ((regparm(3))) assign(const int *this1, char*, int);
void Foo_GetData(int *this1, char * D1588, int D1587)
  assign (this1, D1588, D1587);
Comment 2 Andrew Pinski 2005-01-30 19:55:52 UTC
Patch here: <>.
Comment 3 CVS Commits 2005-01-31 05:49:31 UTC
Subject: Bug 19704

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	2005-01-31 05:49:16

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: i386.c 

Log message:
	PR target/19704
	* config/i386/i386.c (ix86_function_ok_for_sibcall):  Also check
	that dllimport'd functions do not use all call-clobbered registers
	to pass parameters.


Comment 4 Danny Smith 2005-01-31 05:55:16 UTC
Fixed on mainline.
Should this also be applied be applied to 3_4-barnch (assuming regtesting is 
OK), where the bug also exists?

Comment 5 Danny Smith 2005-05-16 07:52:35 UTC
The patch in comment #3 isn't sufficient for cases where C++ class members get 
their dllimport status from attribute applied to class type, rather than from 
explicit attribute on the member.  This still fails with same error as original 

// dllimport attribute applied to class type causes non-inline class members to 
// use dllimport indirect reference semantics

struct __declspec(dllimport)  Bar { 
  char* data;
  int getlen() const;
  char* getdata() const;
  void __attribute__ ((regparm(3))) assign(char*, int);  

struct Foo
        Bar foobar;
        void GetData();

void Foo::GetData()
    foobar.assign(foobar.getdata(), foobar.getlen());

Comment 6 CVS Commits 2005-10-12 20:54:58 UTC
Subject: Bug 19704

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	2005-10-12 20:54:50

Modified files:
	gcc            : ChangeLog config.gcc tree.c tree.h varasm.c 
	                 target.h target-def.h 
	gcc/doc        : tm.texi 
	gcc/config/i386: i386-protos.h i386.c winnt.c cygming.h 
	gcc/cp         : ChangeLog class.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg: dll-2.c dll-3.c dll-4.c 
	gcc/testsuite/g++.dg/ext: dllimport1.C dllimport2.C dllimport3.C 
	                          dllimport7.C dllimport8.C dllimport9.C 
Added files:
	gcc/config/i386: winnt-stubs.c winnt-cxx.c 

Log message:
	PR middle-end/21275
	PR middle-end/21766
	* target.h (struct gcc_target): Add valid_dllimport_attribute_p
	target hook.
	(struct cxx): Add adjust_class_at_definition target hook.
	* target-def.h: (TARGET_VALID_DLLIMPORT_ATTRIBUTE_P): New define,
	defaulting to hook_bool_tree_true. Add to TARGET_INITIALIZER
	(TARGET_CXX_ADJUST_CLASS_AT_DEFINITION): New define, defaulting to
	hook_void_tree. Add to TARGET_CXX.
	* tree.h (struct decl_with_vis): Rename non_addr_const_p field to
	* tree.c (merge_dllimport_decl_attributes): Check DECL_DLLIMPORT_P
	instead of attribute. Check for dllexport override.  Warn if
	inconsistent dll linkage. Don't lose old dllimport if decl has
	had address referenced.   Tweak lookup of dllimport atribute.
	(handle_dll_attribute): Check targetm.valid_dllimport_attribute_p
	for target specific rules.  Don't add dllimport attribute if
	dllimport attribute.
	* varasm.c (initializer_constant_valid_p): Replace
	PR target/21801
	PR target/23589
	* config.gcc (i[34567]86-*-cygwin*): Add winnt-cxx.o to
	'cxx_target_objs', winnt-stubs,o to 'extra_objs'.
	(i[34567]86-*-mingw32*): Likewise.
	* config/i386/winnt.c (i386_pe_dllimport_p): Factor out
	C++-specific code. Change return value to bool.
	(i386_pe_dllimport_p): Likewise.
	(associated_type): Simplify and make language-independent
	(i386_pe_encode_section_info): Replace override of ambiguous
	dllimport symbol refs with a gcc_assert.
	(i386_pe_valid_dllimport_attribute_p): Define.
	* config/i386/winnt-cxx.c: New file. Define C++ versions of
	i386_pe_type_dllimport_p, i386_pe_type_dllexport_p,
	* config/i386/winnt-stubs.c: New file. Define stub versions of
	lang-specific functions.
	* config/i386/i386-protos.h: Declare winnt-[cxx|stubs].c functions
	i386_pe_type_dllimport_p, i386_pe_type_dllexport_p,
	(i386_pe_valid_dllimport_attribute_p): Declare.
	* config/i386/cygming.h (TARGET_VALID_DLLIMPORT_ATTRIBUTE_P): Define.
	* config/i386/t-cygming: Add rules for winnt-cxx.o, winnt-stubs.o.
	PR target/19704
	* config/i386/i386.c (ix86_function_ok_for_sibcall): Replace test for
	dllimport attribute with test of DECL_DLLIMPORT_P.
	PR target/21801
	PR target/23589
	* class.c (finish_struct_1): Call
	* gcc.dg/dll-2.c: Add tests for warnings.
	* gcc.dg/dll-3.c: Likewise.
	* gcc.dg/dll-4.c: Likewise.
	* g++.dg/ext/dllimport1.C: Adjust tests for warnings.
	* g++.dg/ext/dllimport2.C: Likewise.
	* g++.dg/ext/dllimport3.C: Likewise.
	* g++.dg/ext/dllimport7.C: Likewise.
	* g++.dg/ext/dllimport8.C: Likewise.
	* g++.dg/ext/dllimport9.C: Likewise.


Comment 7 Danny Smith 2005-10-12 21:03:24 UTC
Now fixed on trunk for C++ too.
Comment 8 Andrew Pinski 2005-10-12 21:09:54 UTC
Fixed so closing as such.