PATCH: Asm bug in C++ templates
Hidvegi
hzoli@austin.ibm.com
Wed Nov 17 14:00:00 GMT 1999
I wrote:
> The following program produces bad assembly output with
>
> g++ -O3 -S foo.C
>
> ---------------------- CUT HERE ----------------------
> template <class T>
> class tmpl {
> public:
> static int foo(void);
> };
>
> template <class T>
> int
> tmpl<T>::foo(void)
> {
> int g;
>
> __asm__ ("bad" "bad" : "=r" (g));
>
> return g;
> }
>
> template tmpl<int>;
> ---------------------- CUT HERE ----------------------
>
> The "badbad" string is missing from the assembly, or it is replaced by
> junk. I tested this on rs6k and i386 with:
>
> gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
> gcc version 2.95.2 19991024 (release) (on i386 RedHat 6.0 and rs6k AIX4.3.2)
> gcc version 2.95 19990728 (release) (on rs6k aix 4.3.2)
Here is a patch for this. I'm not familiar with the gcc source, so
I'm not sure this is the right fix or if it really fixes all
occurances of this kind of a problem. The probelm is that when
processing an asm inside a template gcc saves it into permanent
storage using build min_nt. Unfortunately this does not saves the
string contents, which is probably OK for most cases, but when the
string was coming from combine_strings it was allocated in
non-permanent storage. I send this to both gcc-bugs as I originally
posted the problem there and to gcc-patches.
Zoli
*** cp/semantics.c~ Sat Jun 19 18:54:52 1999
--- cp/semantics.c Wed Nov 17 15:44:22 1999
***************
*** 712,717 ****
--- 712,720 ----
return r;
}
+ extern struct obstack *saveable_obstack;
+ extern struct obstack permanent_obstack;
+
/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
CLOBBERS. */
***************
*** 725,732 ****
tree input_operands;
tree clobbers;
{
! if (TREE_CHAIN (string))
! string = combine_strings (string);
if (processing_template_decl)
{
--- 728,742 ----
tree input_operands;
tree clobbers;
{
! if (TREE_CHAIN (string)) {
! if (processing_template_decl) {
! register struct obstack *ambient_saveable_obstack = saveable_obstack;
! saveable_obstack = &permanent_obstack;
! string = combine_strings (string);
! saveable_obstack = ambient_saveable_obstack;
! } else
! string = combine_strings (string);
! }
if (processing_template_decl)
{
More information about the Gcc-bugs
mailing list