public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Zack Weinberg <zack@rabi.columbia.edu>
To: Alexandre Oliva <oliva@dcc.unicamp.br>
Cc: egcs@egcs.cygnus.com, egcs-patches@egcs.cygnus.com
Subject: Re: making aliases into the middle of a structure
Date: Fri, 30 Apr 1999 23:15:00 -0000	[thread overview]
Message-ID: <199904222131.RAA09537@blastula.phys.columbia.edu> (raw)
Message-ID: <19990430231500.8UlZqdzsqlQyi1F4hxSOxLFDle1R5JuiEcpwX600PCE@z> (raw)
In-Reply-To: <org15s33hj.fsf@lua.lbi.dcc.unicamp.br>

On 22 Apr 1999 15:38:16 -0300, Alexandre Oliva wrote:
>On Apr 22, 1999, Zack Weinberg <zack@rabi.columbia.edu> wrote:
>
>> On 22 Apr 1999 15:24:46 -0300, Alexandre Oliva wrote:
>>> On Apr 22, 1999, Zack Weinberg <zack@rabi.columbia.edu> wrote:
>>> 
>>>> extern __typeof(x.b) y __attribute__ ((alias("x.b")));
>>> 
>>> This can't work.  The alias attribute defines an alias to a *symbol*,
>>> not to an arbitrary expression. 
>
>> I don't see that it would be terribly hard to extend alias so it could
>> handle SYMBOL_REFs and COMPONENT_REFs as well as strings.
>
>That would probably be a good idea.  alias could accept an arbitrary
>expression.  If it's an lvalue within a global symbol, it will define
>an actual alias, otherwise it could just emit an error or ``construct
>a temporary and bind the reference to it'', to put it in C++ terms :-) 

It turns out to be relatively simple to implement, too (at least if
you don't try to construct temporaries).  The appended patch is
a proof-of-concept; I don't expect it'll make it into 1.2.  I had to
introduce a new MD macro, ASM_OUTPUT_OFFSET_DEF, and the patch does
not modify the relevant tm.h files, only defaults.h (so it works only
with assemblers that use .set).  Any front-end that calls
assemble_alias also needs to be adjusted; none of the ones in current
CVS do.

The subset of this patch that lets attribute alias accept bare
identifiers is trivial, and it'd be nice if that got into 1.2.

[As an aside, get_inner_reference has a rather nonintuitive name...]

zw

1999-04-22 17:22 -0400  Zack Weinberg  <zack@rabi.phys.columbia.edu>

	* c-common.c (decl_attributes: A_ALIAS): Accept an
	IDENTIFIER_NODE or COMPONENT_REF in args.  If we get a
	COMPONENT_REF, sanity-check it (no bitfields, no non-lvalues,
	no variable offsets) and pass the component offset on to
	assemble_alias.
	* varasm.c (assemble_alias): Add `offset' argument.  If it's
	nonzero, use ASM_OUTPUT_OFFSET_DEF to output the alias
	definition with its offset from the base symbol.
	* defaults.h (ASM_OUTPUT_OFFSET_DEF): New macro, for
	outputting alias defns of the form ".set b,a+4".
	* output.h: Update prototype of assemble_alias.

===================================================================
Index: c-common.c
--- c-common.c	1999/04/13 21:04:06	1.56
+++ c-common.c	1999/04/22 21:20:34
@@ -891,20 +891,62 @@
 	  else if (decl_function_context (decl) == 0)
 	    {
 	      tree id;
+	      int offset;
 
 	      id = TREE_VALUE (args);
-	      if (TREE_CODE (id) != STRING_CST)
+	      if (TREE_CODE (id) == STRING_CST)
 		{
-		  error ("alias arg not a string");
+		  id = get_identifier (TREE_STRING_POINTER (id));
+		  offset = 0;
+		}
+	      else if (TREE_CODE (id) == IDENTIFIER_NODE)
+		{
+		  offset = 0;
+		}
+	      else if (TREE_CODE (id) == COMPONENT_REF)
+		{
+		  if (! lvalue_p (TREE_OPERAND (id, 0)))
+		    {
+		      error ("alias arg not an lvalue expression");
+		      break;
+		    }
+		  else if (DECL_C_BIT_FIELD (TREE_OPERAND (id, 1)))
+		    {
+		      error ("cannot set alias to bitfield `%s'",
+			     IDENTIFIER_POINTER (DECL_NAME (
+						      TREE_OPERAND (id, 1))));
+		      break;
+		    }
+		  else
+		    {
+		      int boffset, bsiz, puns, pvol, palign;
+		      tree poff, newid;
+		      enum machine_mode mode;
+		      
+		      newid = get_inner_reference (id, &bsiz, &boffset, &poff,
+						&mode, &puns, &pvol, &palign);
+		      if (poff != NULL_TREE)
+			{
+			  error ("cannot set alias to variably offset field `%s'",
+				 IDENTIFIER_POINTER (DECL_NAME (
+						       TREE_OPERAND (id, 1))));
+			  break;
+			}
+		      id = DECL_NAME (newid);
+		      offset = boffset / BITS_PER_UNIT;
+		    }
+		}
+	      else
+		{
+		  error ("alias arg not a string or lvalue expression");
 		  break;
 		}
-	      id = get_identifier (TREE_STRING_POINTER (id));
 
 	      if (TREE_CODE (decl) == FUNCTION_DECL)
 		DECL_INITIAL (decl) = error_mark_node;
 	      else
 		DECL_EXTERNAL (decl) = 0;
-	      assemble_alias (decl, id);
+	      assemble_alias (decl, id, offset);
 	    }
 	  else
 	    warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
===================================================================
Index: varasm.c
--- varasm.c	1999/03/28 15:35:04	1.57
+++ varasm.c	1999/04/22 21:20:36
@@ -4334,8 +4334,9 @@
 }
 
 void
-assemble_alias (decl, target)
+assemble_alias (decl, target, offset)
      tree decl, target ATTRIBUTE_UNUSED;
+     int offset ATTRIBUTE_UNUSED;
 {
   char *name;
 
@@ -4355,14 +4356,26 @@
 	ASM_GLOBALIZE_LABEL (asm_out_file, name);
     }
 
-  ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
+  if (offset == 0)
+    ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
+  else
+#ifdef ASM_OUTPUT_OFFSET_DEF
+    ASM_OUTPUT_OFFSET_DEF (asm_out_file, name,
+			   IDENTIFIER_POINTER (target), offset);
+#else
+  warning ("offset alias definitions not supported in this configuration; ignored");
+#endif
+
   TREE_ASM_WRITTEN (decl) = 1;
 #else
 #ifdef ASM_OUTPUT_WEAK_ALIAS
   if (! DECL_WEAK (decl))
     warning ("only weak aliases are supported in this configuration");
 
-  ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
+  if (offset == 0)
+    ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
+  else
+    warning ("offset alias definitions not supported in this configuration; ignored");
   TREE_ASM_WRITTEN (decl) = 1;
 #else
   warning ("alias definitions not supported in this configuration; ignored");
===================================================================
Index: defaults.h
--- defaults.h	1999/02/27 22:21:57	1.7
+++ defaults.h	1999/04/22 21:20:36
@@ -116,6 +116,15 @@
 	fprintf (FILE, "\n");						\
   } while (0)
 #endif
+#ifndef ASM_OUTPUT_OFFSET_DEF
+#define ASM_OUTPUT_OFFSET_DEF(FILE,LABEL1,LABEL2,OFFSET)		\
+ do {	fprintf ((FILE), "\t%s\t", SET_ASM_OP);				\
+	assemble_name (FILE, LABEL1);					\
+	fprintf (FILE, ",");						\
+	assemble_name (FILE, LABEL2);					\
+	fprintf (FILE, "+%d\n", OFFSET);				\
+  } while (0)
+#endif
 #endif
 
 /* This is how to output a reference to a user-level label named NAME.  */
===================================================================
Index: output.h
--- output.h	1999/04/18 13:09:18	1.23
+++ output.h	1999/04/22 21:20:36
@@ -207,7 +207,7 @@
 /* Output alignment directive to align for constant expression EXP.  */
 extern void assemble_constant_align	PROTO((tree));
 
-extern void assemble_alias		PROTO((tree, tree));
+extern void assemble_alias		PROTO((tree, tree, int));
 
 /* Output a string of literal assembler code
    for an `asm' keyword used between functions.  */

  reply	other threads:[~1999-04-30 23:15 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-22 11:13 Zack Weinberg
1999-04-22 11:25 ` Alexandre Oliva
1999-04-22 11:30   ` Zack Weinberg
1999-04-22 11:38     ` Alexandre Oliva
1999-04-22 14:31       ` Zack Weinberg [this message]
1999-04-23 15:24         ` Richard Henderson
1999-04-23 16:27           ` Zack Weinberg
1999-04-23 16:52             ` Richard Henderson
1999-04-30 23:15               ` Richard Henderson
1999-04-30 23:15             ` Zack Weinberg
1999-04-30 23:15           ` Richard Henderson
1999-04-30 23:15         ` Zack Weinberg
1999-04-23 10:34       ` Jeffrey A Law
1999-04-23 10:40         ` Zack Weinberg
1999-04-23 15:54           ` Richard Henderson
1999-04-23 16:19             ` Zack Weinberg
1999-04-26  1:46               ` Andreas Schwab
1999-04-30 23:15                 ` Andreas Schwab
1999-04-30 23:15               ` Zack Weinberg
1999-04-30 23:15             ` Richard Henderson
1999-04-30 23:15           ` Zack Weinberg
1999-04-23 13:36         ` Jamie Lokier
1999-04-23 13:49           ` Zack Weinberg
1999-04-23 15:20             ` Jamie Lokier
1999-04-30 23:15               ` Jamie Lokier
1999-04-23 22:58             ` Andi Kleen
1999-04-30 23:15               ` Andi Kleen
1999-04-30 23:15             ` Zack Weinberg
1999-04-24 21:53           ` Jeffrey A Law
1999-04-30 23:15             ` Jeffrey A Law
1999-04-30 23:15           ` Jamie Lokier
1999-04-30 23:15         ` Jeffrey A Law
1999-04-30 23:15       ` Alexandre Oliva
1999-04-30 23:15     ` Zack Weinberg
1999-04-30 23:15   ` Alexandre Oliva
1999-04-30 23:15 ` Zack Weinberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199904222131.RAA09537@blastula.phys.columbia.edu \
    --to=zack@rabi.columbia.edu \
    --cc=egcs-patches@egcs.cygnus.com \
    --cc=egcs@egcs.cygnus.com \
    --cc=oliva@dcc.unicamp.br \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).