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: https://sourceforge.net/tracker/? func=detail&atid=102435&aid=1112123&group_id=2435 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]) (nil))))) (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 ])) (nil))))) 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 Danny -- Summary: regparm vs dllimport of C++ methods Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: target AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dannysmith at users dot sourceforge dot net CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-mingw32 GCC host triplet: i686-pc-mingw32 GCC target triplet: i686-pc-mingw32 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19704