C++ PATCH for inline-asms and templates
mark@codesourcery.com
mark@codesourcery.com
Tue May 25 15:29:00 GMT 1999
Here are a couple of fixes for the handling of inline-assembly in
templates.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
1999-05-25 Mark Mitchell <mark@codesourcery.com>
* pt.c (tsubst_expr, case ASM_STMT): Don't tsubst into
ASM_CV_QUAL.
* semantics.c (finish_asm_stmt): Make strings permanent if they're
used in a template.
Index: testsuite/g++.old-deja/g++.pt/asm1.C
===================================================================
RCS file: asm1.C
diff -N asm1.C
--- /dev/null Sat Dec 5 20:30:03 1998
+++ asm1.C Tue May 25 11:31:14 1999
@@ -0,0 +1,16 @@
+// Build don't link:
+// Origin: "Weidmann, Nicholas" <nicholas.weidmann@swx.ch>
+// Skip if not target: i?86-*-linux*
+
+template<int i> int foo(int v)
+{
+ __asm__ __volatile__("addl %1, %0" : "=a" (v) : "b" (i));
+
+ return v;
+}
+
+int bar(int i)
+{
+ return foo<123>(i);
+}
+
Index: testsuite/g++.old-deja/g++.pt/asm2.C
===================================================================
RCS file: asm2.C
diff -N asm2.C
--- /dev/null Sat Dec 5 20:30:03 1998
+++ asm2.C Tue May 25 11:31:14 1999
@@ -0,0 +1,23 @@
+// Build don't link:
+// Origin: "Weidmann, Nicholas" <nicholas.weidmann@swx.ch>
+// Skip if not target: i?86-*-linux*
+
+typedef void (function_ptr)(int);
+
+void foo(int)
+{
+}
+
+template<function_ptr ptr> void doit(int i)
+{
+ __asm__("pushl %0\n\t"
+ "call *%1\n\t"
+ "popl %0"
+ :
+ : "a" (i), "b" (ptr));
+}
+
+void bar()
+{
+ doit<foo>(123);
+}
Index: testsuite/cp/pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.305
diff -u -p -r1.305 pt.c
--- pt.c 1999/05/22 19:00:23 1.305
+++ pt.c 1999/05/25 18:31:36
@@ -7200,7 +7190,7 @@ tsubst_expr (t, args, complain, in_decl)
case ASM_STMT:
lineno = TREE_COMPLEXITY (t);
- finish_asm_stmt (tsubst_expr (ASM_CV_QUAL (t), args, complain, in_decl),
+ finish_asm_stmt (ASM_CV_QUAL (t),
tsubst_expr (ASM_STRING (t), args, complain, in_decl),
tsubst_expr (ASM_OUTPUTS (t), args, complain, in_decl),
tsubst_expr (ASM_INPUTS (t), args, complain, in_decl),
Index: testsuite/cp/semantics.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/semantics.c,v
retrieving revision 1.48
diff -u -p -r1.48 semantics.c
--- semantics.c 1999/04/18 10:58:42 1.48
+++ semantics.c 1999/05/25 18:31:37
@@ -718,7 +718,7 @@ finish_compound_stmt (has_no_scope, comp
void
finish_asm_stmt (cv_qualifier, string, output_operands,
- input_operands, clobbers)
+ input_operands, clobbers)
tree cv_qualifier;
tree string;
tree output_operands;
@@ -726,7 +726,20 @@ finish_asm_stmt (cv_qualifier, string, o
tree clobbers;
{
if (TREE_CHAIN (string))
- string = combine_strings (string);
+ {
+ if (processing_template_decl)
+ {
+ /* We need to build the combined string on the permanent
+ obstack so that we can use it during instantiations. */
+ push_obstacks_nochange ();
+ end_temporary_allocation ();
+ }
+
+ string = combine_strings (string);
+
+ if (processing_template_decl)
+ pop_obstacks ();
+ }
if (processing_template_decl)
{
More information about the Gcc-patches
mailing list