PATCH: attempt 2. Asm bug in C++ templates

Hidvegi hzoli@austin.ibm.com
Fri Nov 19 09:35:00 GMT 1999


I wrote:
> 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.

Well, my first patch was wrong, here is an other try. I'd really
appreciate if someone who knows more about this would check it and fix
it of confirm that the patch is OK.

Thanks,

Zoli

 *** gcc/cp/semantics.c.orig	Sat Jun 19 18:54:52 1999
 --- gcc/cp/semantics.c	Fri Nov 19 11:21:28 1999
 ***************
 *** 26,31 ****
 --- 26,32 ----
   
   #include "config.h"
   #include "system.h"
 + #include "obstack.h"
   #include "tree.h"
   #include "cp-tree.h"
   #include "except.h"
 ***************
 *** 712,717 ****
 --- 713,720 ----
     return r;
   }
   
 + 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)) {
       string = combine_strings (string);
 +     if (processing_template_decl) {
 +       int l = TREE_STRING_LENGTH(string);
 +       char *s = (char *) obstack_alloc(&permanent_obstack, l);
 +       memcpy(s, TREE_STRING_POINTER(string), l);
 +       TREE_STRING_POINTER(string) = s;
 +     }
 +   }
   
     if (processing_template_decl)
       {


More information about the Gcc-bugs mailing list