compiler: error on func declaration/definition
authorIan Lance Taylor <ian@gcc.gnu.org>
Mon, 12 Feb 2018 19:29:52 +0000 (19:29 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Mon, 12 Feb 2018 19:29:52 +0000 (19:29 +0000)
    Long long long ago Go permitted writing
        func F()
    in one file and writing
        func F() {}
    in another file.  This was removed from the language, and that is now
    considered to be a multiple definition error.  Gccgo never caught up
    to that, and it has been permitting this invalid code for some time.

    Stop permitting it, so that we give correct errors.  Since we've
    supported it for a long time, the compiler uses it in a couple of
    cases: it predeclares the hash/equal methods if it decides to create
    them while compiling another function, and it predeclares main.main as
    a mechanism for getting the right warning if a program uses the wrong
    signature for main.  For simplicity, keep those existing uses.

    This required a few minor changes in libgo which were relying,
    unnecessarily, on the current behavior.

    Reviewed-on: https://go-review.googlesource.com/93083

From-SVN: r257600

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/gogo.cc
libgo/go/runtime/extern.go
libgo/go/runtime/stubs.go
libgo/misc/cgo/test/issue9400/gccgo.go
libgo/misc/cgo/test/issue9400/stubs.go

index e8a036f504a6ba964ca873f46c4bf6d56bac92b9..ea7ae4bf16e10d1b0e118f679f743840eb7e2955 100644 (file)
@@ -1,4 +1,4 @@
-cebdbf3f293f5b0f3120c009c47da0ceadc113cb
+7998e29eec43ede1cee925d87eef0b09da67d90b
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 11ac33840707e580a3b11c06701fdb6ec5e3465a..0eac1993402f776f1c300358a84db99c757e313d 100644 (file)
@@ -7762,33 +7762,29 @@ Bindings::new_definition(Named_object* old_object, Named_object* new_object)
       go_unreachable();
 
     case Named_object::NAMED_OBJECT_FUNC:
-      if (new_object->is_function_declaration())
-       {
-         if (!new_object->func_declaration_value()->asm_name().empty())
-           go_error_at(Linemap::unknown_location(),
-                       ("sorry, not implemented: "
-                        "__asm__ for function definitions"));
-         Function_type* old_type = old_object->func_value()->type();
-         Function_type* new_type =
-           new_object->func_declaration_value()->type();
-         if (old_type->is_valid_redeclaration(new_type, &reason))
-           return old_object;
-       }
       break;
 
     case Named_object::NAMED_OBJECT_FUNC_DECLARATION:
       {
-       if (new_object->is_function())
+       // We declare the hash and equality functions before defining
+       // them, because we sometimes see that we need the declaration
+       // while we are in the middle of a different function.  We
+       // declare the main function before the user defines it, to
+       // give better error messages.
+       if (new_object->is_function()
+           && ((Linemap::is_predeclared_location(old_object->location())
+                && Linemap::is_predeclared_location(new_object->location()))
+               || (Gogo::unpack_hidden_name(old_object->name()) == "main"
+                   && Linemap::is_unknown_location(old_object->location()))))
          {
             Function_type* old_type =
                 old_object->func_declaration_value()->type();
            Function_type* new_type = new_object->func_value()->type();
            if (old_type->is_valid_redeclaration(new_type, &reason))
              {
-               if (!old_object->func_declaration_value()->asm_name().empty())
-                 go_error_at(Linemap::unknown_location(),
-                             ("sorry, not implemented: "
-                              "__asm__ for function definitions"));
+               Function_declaration* fd =
+                 old_object->func_declaration_value();
+               go_assert(fd->asm_name().empty());
                old_object->set_function_value(new_object->func_value());
                this->named_objects_.push_back(old_object);
                return old_object;
@@ -7810,8 +7806,10 @@ Bindings::new_definition(Named_object* old_object, Named_object* new_object)
   old_object->set_is_redefinition();
   new_object->set_is_redefinition();
 
-  go_inform(old_object->location(), "previous definition of %qs was here",
-            n.c_str());
+  if (!Linemap::is_unknown_location(old_object->location())
+      && !Linemap::is_predeclared_location(old_object->location()))
+    go_inform(old_object->location(), "previous definition of %qs was here",
+             n.c_str());
 
   return old_object;
 }
index 36787e38b0289d064f86698295dfc111a8e44908..b3afd10ed6d18f9b96a40add2bb99d89d3bd4fba 100644 (file)
@@ -157,10 +157,6 @@ package runtime
 
 import "runtime/internal/sys"
 
-// Gosched yields the processor, allowing other goroutines to run.  It does not
-// suspend the current goroutine, so execution resumes automatically.
-func Gosched()
-
 // Caller reports file and line number information about function invocations on
 // the calling goroutine's stack. The argument skip is the number of stack frames
 // to ascend, with 0 identifying the caller of Caller.  (For historical reasons the
index efb037399bfc802665abb0e2b7b16f94428cafba..bda2c694ac67ab79c47c3752b83f693d9f1a08a2 100644 (file)
@@ -306,10 +306,6 @@ func setSupportAES(v bool) {
        support_aes = v
 }
 
-// Here for gccgo until we port lock_*.go.
-func lock(l *mutex)
-func unlock(l *mutex)
-
 // Here for gccgo.
 func errno() int
 
@@ -317,9 +313,6 @@ func errno() int
 func entersyscall(int32)
 func entersyscallblock(int32)
 
-// Here for gccgo until we port mgc.go.
-func GC()
-
 // For gccgo to call from C code, so that the C code and the Go code
 // can share the memstats variable for now.
 //go:linkname getMstats runtime.getMstats
@@ -327,16 +320,6 @@ func getMstats() *mstats {
        return &memstats
 }
 
-// Temporary for gccgo until we port mem_GOOS.go.
-func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer
-func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64)
-
-// Temporary for gccgo until we port malloc.go
-func persistentalloc(size, align uintptr, sysStat *uint64) unsafe.Pointer
-
-// Temporary for gccgo until we port mheap.go
-func setprofilebucket(p unsafe.Pointer, b *bucket)
-
 // Get signal trampoline, written in C.
 func getSigtramp() uintptr
 
index 0ef3a8cacf3a3b34da2cb41bdab9f91f7c337e25..a9b62b07a044045989e0eac4a8769db6fc30c925 100644 (file)
@@ -16,6 +16,8 @@ import (
 // without writing more assembly code, which we haven't bothered to
 // do.  So this is not much of a test.
 
+var Baton int32
+
 func RewindAndSetgid() {
        atomic.StoreInt32(&Baton, 1)
        for atomic.LoadInt32(&Baton) != 0 {
index 60193dc4117bdf31d1959fe83c3cebcaf393d24d..7b50cefc3a824dfc511d6bc91f51fe1e4613fbd1 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build !gccgo
+
 package issue9400
 
 var Baton int32