From 7edf3a2b436934a4d12c0118b38a69963eb4d1ba Mon Sep 17 00:00:00 2001
From: geoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Sun, 27 Jul 2003 01:48:11 +0000
Subject: [PATCH] 	* varasm.c (output_constant_def_contents): Use 
 ASM_DECLARE_CONSTANT_NAME if defined. 	* doc/tm.texi (Label Output): Document
 ASM_DECLARE_CONSTANT_NAME. 	* config/darwin.h (ASM_DECLARE_OBJECT_NAME):
 Ensure zero-sized 	objects get at least one byte to prevent assembler
 problems. 	(ASM_DECLARE_CONSTANT_NAME): New.

Index: testsuite/ChangeLog
	* gcc.c-torture/compile/zero-strct-2.c: New test.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@69842 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                                 |  7 ++++
 gcc/config/darwin.h                           | 35 +++++++++++++------
 gcc/doc/tm.texi                               | 16 +++++++++
 gcc/testsuite/ChangeLog                       |  4 +++
 .../gcc.c-torture/compile/zero-strct-2.c      |  2 ++
 gcc/varasm.c                                  | 20 ++++++-----
 6 files changed, 65 insertions(+), 19 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/zero-strct-2.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6dcc99edf2d3..c0915fad8353 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -44,6 +44,13 @@
 
 2003-07-26  Geoffrey Keating  <geoffk@apple.com>
 
+	* varasm.c (output_constant_def_contents): Use 
+	ASM_DECLARE_CONSTANT_NAME if defined.
+	* doc/tm.texi (Label Output): Document ASM_DECLARE_CONSTANT_NAME.
+	* config/darwin.h (ASM_DECLARE_OBJECT_NAME): Ensure zero-sized
+	objects get at least one byte to prevent assembler problems.
+	(ASM_DECLARE_CONSTANT_NAME): New.
+
 	* Makefile.in (libbackend.o): Remove options_.h.
 	(mostlyclean): Likewise.
 
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 4f9b487fc8c5..64aab067f6f9 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -356,18 +356,22 @@ do { text_section ();							\
 #undef ASM_DECLARE_OBJECT_NAME
 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)			\
   do {									\
-    const char *xname = NAME;                                           \
-    if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF)             \
-      xname = IDENTIFIER_POINTER (DECL_NAME (DECL));                    \
-    if ((TREE_STATIC (DECL)                                             \
-	 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))               \
-        || DECL_INITIAL (DECL))                                         \
-      machopic_define_name (xname);                                     \
-    if ((TREE_STATIC (DECL)                                             \
-	 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))               \
-        || DECL_INITIAL (DECL))                                         \
+    const char *xname = NAME;						\
+    if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF)		\
+      xname = IDENTIFIER_POINTER (DECL_NAME (DECL));			\
+    if ((TREE_STATIC (DECL)						\
+	 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))		\
+        || DECL_INITIAL (DECL))						\
+      machopic_define_name (xname);					\
+    if ((TREE_STATIC (DECL)						\
+	 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL)))		\
+        || DECL_INITIAL (DECL))						\
       (* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false);	\
-    ASM_OUTPUT_LABEL (FILE, xname);                                     \
+    ASM_OUTPUT_LABEL (FILE, xname);					\
+    /* Darwin doesn't support zero-size objects, so give them a 	\
+       byte.  */							\
+    if (tree_low_cst (DECL_SIZE_UNIT (DECL), 1) == 0)			\
+      assemble_zeros (1);						\
   } while (0)
 
 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)                     \
@@ -389,6 +393,15 @@ do { text_section ();							\
     machopic_output_possible_stub_label (FILE, xname);			\
   } while (0)
 
+#define ASM_DECLARE_CONSTANT_NAME(FILE, NAME, EXP, SIZE)	\
+  do {								\
+    ASM_OUTPUT_LABEL (FILE, NAME);				\
+    /* Darwin doesn't support zero-size objects, so give them a	\
+       byte.  */						\
+    if ((SIZE) == 0)						\
+      assemble_zeros (1);					\
+  } while (0)
+
 /* Wrap new method names in quotes so the assembler doesn't gag.
    Make Objective-C internal symbols local.  */
 
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index e3f4afe03b3a..3f9dd15d7dab 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -6634,6 +6634,22 @@ You may wish to use @code{ASM_OUTPUT_TYPE_DIRECTIVE} and/or
 @code{ASM_OUTPUT_SIZE_DIRECTIVE} in the definition of this macro.
 @end defmac
 
+@defmac ASM_DECLARE_CONSTANT_NAME (@var{stream}, @var{name}, @var{exp}, @var{size})
+A C statement (sans semicolon) to output to the stdio stream
+@var{stream} any text necessary for declaring the name @var{name} of a
+constant which is being defined.  This macro is responsible for
+outputting the label definition (perhaps using
+@code{ASM_OUTPUT_LABEL}).  The argument @var{exp} is the
+value of the constant, and @var{size} is the size of the constant
+in bytes.  @var{name} will be an internal label.
+
+If this macro is not defined, then the @var{name} is defined in the
+usual manner as a label (by means of @code{ASM_OUTPUT_LABEL}).
+
+You may wish to use @code{ASM_OUTPUT_TYPE_DIRECTIVE} in the definition
+of this macro.
+@end defmac
+
 @defmac ASM_DECLARE_REGISTER_GLOBAL (@var{stream}, @var{decl}, @var{regno}, @var{name})
 A C statement (sans semicolon) to output to the stdio stream
 @var{stream} any text necessary for claiming a register @var{regno}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2f0e153cdf5b..c06df55a540d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2003-07-26  Geoffrey Keating  <geoffk@apple.com>
+
+	* gcc.c-torture/compile/zero-strct-2.c: New test.
+
 2003-07-25  Geoffrey Keating  <geoffk@apple.com>
 
 	* gcc.dg/intermod-1.c: New test.
diff --git a/gcc/testsuite/gcc.c-torture/compile/zero-strct-2.c b/gcc/testsuite/gcc.c-torture/compile/zero-strct-2.c
new file mode 100644
index 000000000000..0f97f7d12b26
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/zero-strct-2.c
@@ -0,0 +1,2 @@
+struct { } foo = { };
+void * bar(void) { return &foo; }
diff --git a/gcc/varasm.c b/gcc/varasm.c
index a8ff36fb0dcc..c9dae8954b74 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -2547,6 +2547,7 @@ output_constant_def_contents (rtx symbol)
 {
   tree exp = SYMBOL_REF_DECL (symbol);
   const char *label = XSTR (symbol, 0);
+  HOST_WIDE_INT size;
 
   /* Make sure any other constants whose addresses appear in EXP
      are assigned label numbers.  */
@@ -2571,17 +2572,20 @@ output_constant_def_contents (rtx symbol)
       ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
     }
 
-  /* Output the label itself.  */
+  size = int_size_in_bytes (TREE_TYPE (exp));
+  if (TREE_CODE (exp) == STRING_CST)
+    size = MAX (TREE_STRING_LENGTH (exp), size);
+
+  /* Do any machine/system dependent processing of the constant.  */
+#ifdef ASM_DECLARE_CONSTANT_NAME
+  ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
+#else
+  /* Standard thing is just output label for the constant.  */
   ASM_OUTPUT_LABEL (asm_out_file, label);
+#endif /* ASM_DECLARE_CONSTANT_NAME */
 
   /* Output the value of EXP.  */
-  output_constant (exp,
-		   (TREE_CODE (exp) == STRING_CST
-		    ? MAX (TREE_STRING_LENGTH (exp),
-			   int_size_in_bytes (TREE_TYPE (exp)))
-		    : int_size_in_bytes (TREE_TYPE (exp))),
-		   align);
-
+  output_constant (exp, size, align);
 }
 
 /* A constant which was deferred in its original location has been
-- 
GitLab