diff mbox

[PTX] weak references

Message ID b3571f8e-36da-5448-7bfa-8073af132fa4@acm.org
State New
Headers show

Commit Message

Nathan Sidwell June 1, 2016, 1:44 p.m. UTC
This patch emits an error if you try and weakly reference a declaration.  PTX 
doesn't support that.

I tried overriding ASM_OUTPUT_WEAREF, but that didn't seem to work.  So this is 
added to the assemble_undefined_decl hook.  that does mean it requires 
-ftoplevel-reorder to function, but that flags's on for PTX unless explicitly 
disabled.

Committed to trunk

nathan
diff mbox

Patch

2016-06-01  Nathan Sidwell  <nathan@acm.org>

	* config/nvptx/nvptx.c (nvptx_assemble_undefined_decl): Reject
	undefined weak.

	testsuite/
	* c-c++-common/torture/pr57945.c: Add expected PTX error.
	* gcc.target/nvptx/weak.c: New.

Index: config/nvptx/nvptx.c
===================================================================
--- config/nvptx/nvptx.c	(revision 236919)
+++ config/nvptx/nvptx.c	(working copy)
@@ -1777,6 +1777,12 @@  nvptx_assemble_undefined_decl (FILE *fil
   if (DECL_IN_CONSTANT_POOL (decl))
     return;
 
+  /*  We support weak defintions, and hence have the right
+      ASM_WEAKEN_DECL definition.  Diagnose the problem here.  */
+  if (DECL_WEAK (decl))
+    error_at (DECL_SOURCE_LOCATION (decl),
+	      "PTX does not support weak declarations"
+	      " (only weak definitions)");
   write_var_marker (file, false, TREE_PUBLIC (decl), name);
 
   fprintf (file, "\t.extern ");
Index: testsuite/c-c++-common/torture/pr57945.c
===================================================================
--- testsuite/c-c++-common/torture/pr57945.c	(revision 236919)
+++ testsuite/c-c++-common/torture/pr57945.c	(working copy)
@@ -9,3 +9,5 @@  foo (void)
 {
   return &i ? i : 0;
 }
+
+/* { dg-error "PTX does not support weak declarations" "" { target nvptx-*-* } 5 } */
Index: testsuite/gcc.target/nvptx/weak.c
===================================================================
--- testsuite/gcc.target/nvptx/weak.c	(nonexistent)
+++ testsuite/gcc.target/nvptx/weak.c	(working copy)
@@ -0,0 +1,9 @@ 
+
+extern int __attribute__((weak)) decl;  /* { dg-error "weak declarations" } */
+int __attribute__((weak)) defn;
+
+int Foo ()
+{
+  return decl + defn;
+}
+