From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24407 invoked by alias); 29 Mar 2012 03:53:53 -0000 Received: (qmail 24398 invoked by uid 22791); 29 Mar 2012 03:53:52 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,TW_CC,TW_FD,TW_FN,T_RP_MATCHES_RCVD,T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pb0-f47.google.com (HELO mail-pb0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 29 Mar 2012 03:53:38 +0000 Received: by pbcum15 with SMTP id um15so2764906pbc.20 for ; Wed, 28 Mar 2012 20:53:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=0lmUX9v37I/QCKC00mHNfc/JI4kcvWwlcb0LehBjIrc=; b=W2DX8eF4fFlSKqbqXBpq1LAgX6DHB0HBpV9sh7DyVoWUJUFhxYXSJCs1+Kcb7Vv9Zw iHGLX+y9c8krkCqzhmnzgIEJGiYD1kDmOz76UQpB5yUlC7BWfRlcHOzsGInNOCmebSrW 9MmxK0HB4JnpMRzpKyyF2vk3bTQtBiEMYnysvh4gq+6LaiUdmSRwaLUQWe0i4LrX99SO 4PxQL+5nCDKJTDv9qCmfHCgT7vd+v5nzf6g4dEaj+cidend2ll0M4Cf5yPLzr1sIGUMV 3yQbkDgLaXsEYLzmam8wYFx+VdnJlVEbbrkfnRCR20z8VgeEv+LyLCGxz4GhBKDTo7RO fDPw== Received: by 10.68.239.233 with SMTP id vv9mr2091366pbc.75.1332993218217; Wed, 28 Mar 2012 20:53:38 -0700 (PDT) Received: by 10.68.239.233 with SMTP id vv9mr2091338pbc.75.1332993217999; Wed, 28 Mar 2012 20:53:37 -0700 (PDT) Received: from coign.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net. [71.133.8.30]) by mx.google.com with ESMTPS id b10sm4057935pbr.46.2012.03.28.20.53.37 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 28 Mar 2012 20:53:37 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Fix return type of unsafe functions Date: Thu, 29 Mar 2012 03:53:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Gm-Message-State: ALoCoQmq/hqKdL6iq9gKn4rJ7X9cdYsIr4HTI2n8zrm+mm+HWKPNpKl3LPNMzQSy24v3ST5pUqy6igmFF0J02SmKcVQRI6yTTc6UxDG8lPcjl2LGmErCHTeF9Ma5jchTiCnVUrke0eV5q6Hv4xgaD41i43OGqiZiSSqwTa1iLM/FHgQ7S/gmvY8= X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-03/txt/msg01842.txt.bz2 --=-=-= Content-length: 405 The functions unsafe.Sizeof, unsafe.Alignof, and unsafe.Offsetof are supported to return uintptr. The Go frontend was incorrectly having them return int. This patch fixes the problem. This uncovered a couple of problems in the gccgo-specific part of libgo, which are also fixed by this patch. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.7 branch. Ian --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=foo.patch Content-Description: patch Content-length: 3980 diff -r 854ced9f1d72 go/expressions.cc --- a/go/expressions.cc Wed Mar 28 16:18:42 2012 -0700 +++ b/go/expressions.cc Wed Mar 28 20:50:30 2012 -0700 @@ -7091,7 +7091,8 @@ else go_unreachable(); - nc->set_unsigned_long(NULL, static_cast(ret)); + nc->set_unsigned_long(Type::lookup_integer_type("uintptr"), + static_cast(ret)); return true; } else if (this->code_ == BUILTIN_OFFSETOF) @@ -7113,7 +7114,8 @@ farg->field_index(), &offset)) return false; - nc->set_unsigned_long(NULL, static_cast(offset)); + nc->set_unsigned_long(Type::lookup_integer_type("uintptr"), + static_cast(offset)); return true; } else if (this->code_ == BUILTIN_REAL || this->code_ == BUILTIN_IMAG) @@ -7246,10 +7248,12 @@ case BUILTIN_CAP: case BUILTIN_COPY: case BUILTIN_LEN: + return Type::lookup_integer_type("int"); + case BUILTIN_ALIGNOF: case BUILTIN_OFFSETOF: case BUILTIN_SIZEOF: - return Type::lookup_integer_type("int"); + return Type::lookup_integer_type("uintptr"); case BUILTIN_CLOSE: case BUILTIN_DELETE: @@ -8078,8 +8082,8 @@ go_assert(saw_errors()); return error_mark_node; } - Type* int_type = Type::lookup_integer_type("int"); - tree type = type_to_tree(int_type->get_backend(gogo)); + Type* uintptr_type = Type::lookup_integer_type("uintptr"); + tree type = type_to_tree(uintptr_type->get_backend(gogo)); return build_int_cst(type, val); } diff -r 854ced9f1d72 go/unsafe.cc --- a/go/unsafe.cc Wed Mar 28 16:18:42 2012 -0700 +++ b/go/unsafe.cc Wed Mar 28 20:50:30 2012 -0700 @@ -57,11 +57,11 @@ if (add_to_globals) this->add_named_type(pointer_type); - Type* int_type = this->lookup_global("int")->type_value(); + Type* uintptr_type = Type::lookup_integer_type("uintptr"); // Sizeof. Typed_identifier_list* results = new Typed_identifier_list; - results->push_back(Typed_identifier("", int_type, bloc)); + results->push_back(Typed_identifier("", uintptr_type, bloc)); Function_type* fntype = Type::make_function_type(NULL, NULL, results, bloc); fntype->set_is_builtin(); no = bindings->add_function_declaration("Sizeof", package, fntype, bloc); @@ -70,7 +70,7 @@ // Offsetof. results = new Typed_identifier_list; - results->push_back(Typed_identifier("", int_type, bloc)); + results->push_back(Typed_identifier("", uintptr_type, bloc)); fntype = Type::make_function_type(NULL, NULL, results, bloc); fntype->set_is_varargs(); fntype->set_is_builtin(); @@ -80,7 +80,7 @@ // Alignof. results = new Typed_identifier_list; - results->push_back(Typed_identifier("", int_type, bloc)); + results->push_back(Typed_identifier("", uintptr_type, bloc)); fntype = Type::make_function_type(NULL, NULL, results, bloc); fntype->set_is_varargs(); fntype->set_is_builtin(); diff -r 854ced9f1d72 libgo/go/os/dir.go --- a/libgo/go/os/dir.go Wed Mar 28 16:18:42 2012 -0700 +++ b/libgo/go/os/dir.go Wed Mar 28 20:50:30 2012 -0700 @@ -34,7 +34,7 @@ func (file *File) readdirnames(n int) (names []string, err error) { if elen == 0 { var dummy syscall.Dirent - elen = (unsafe.Offsetof(dummy.Name) + + elen = (int(unsafe.Offsetof(dummy.Name)) + libc_pathconf(syscall.StringBytePtr(file.name), syscall.PC_NAME_MAX) + 1) } diff -r 854ced9f1d72 libgo/go/syscall/libcall_posix.go --- a/libgo/go/syscall/libcall_posix.go Wed Mar 28 16:18:42 2012 -0700 +++ b/libgo/go/syscall/libcall_posix.go Wed Mar 28 20:50:30 2012 -0700 @@ -138,7 +138,7 @@ //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) //select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) int -const nfdbits = unsafe.Sizeof(fds_bits_type) * 8 +const nfdbits = int(unsafe.Sizeof(fds_bits_type) * 8) type FdSet struct { Bits [(FD_SETSIZE + nfdbits - 1) / nfdbits]fds_bits_type --=-=-=--