This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
2.95.3 fix request: inline asm in C++ templates fix
- To: bernds at redhat dot com
- Subject: 2.95.3 fix request: inline asm in C++ templates fix
- From: Hidvegi <hzoli at austin dot ibm dot com>
- Date: Fri, 1 Dec 2000 01:52:02 -0600 (CST)
- Cc: gcc at gcc dot gnu dot org
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 include a patch below I've been using for more than a year now. I'm
not a gcc developer, so this may not be the best way to fix this. The
patch is small and could only affect inline asm code in C++ templates,
so it cannot cause any regressions.
This problem is not present in the 2.97 tree. I do not know how it
was fixed there, maybe it just went away because of some general
rewrite. If there was a specific fix for that in the 2.96 tree, that
could be backported.
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)
{
----- End of forwarded message (env-from hzoli) -----