From patchwork Sat Nov 23 09:48:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 293650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 56DC02C0092 for ; Sat, 23 Nov 2013 20:48:30 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=LHNaHiiKOKtPswrO8/DtDTT3RdGUy+E3mTo7I/XmhMwT/a Ou6VFf3fUfloF3ZDqNShLhggwGG5wT8Wmql4ELiPs1vCOaXPoJwAsSmohrFeudvt iwgSlqNDNR/tXEm29LiKgZQNfxTrI3Y3+1HuNuNrJbb3c/UxK58kVokmDFo6s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=69wJwkqjxN/H5nExPVu17RZJVpc=; b=oFw2VP3L6/2Aziq7CWPJ Ky0UvBMegnAzN0iu8+8ZRpqxNTw+vwPUzN4CR4iAqqTwpJVaok2TC4IEnDGkoBzG HPPvSg8NqYBc/sybFSXcGJZuyVyqjxZ6mGDTWgkzd+Njex/BrxXzahI8K4NpjzaF FWTav7nnBOEcMt4uejITkWQ= Received: (qmail 12410 invoked by alias); 23 Nov 2013 09:48:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 12400 invoked by uid 89); 23 Nov 2013 09:48:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.7 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RDNS_NONE, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-qe0-f51.google.com Received: from Unknown (HELO mail-qe0-f51.google.com) (209.85.128.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 23 Nov 2013 09:48:19 +0000 Received: by mail-qe0-f51.google.com with SMTP id d4so1817284qej.24 for ; Sat, 23 Nov 2013 01:48:11 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.49.127.101 with SMTP id nf5mr29390149qeb.61.1385200091427; Sat, 23 Nov 2013 01:48:11 -0800 (PST) Received: by 10.229.251.201 with HTTP; Sat, 23 Nov 2013 01:48:11 -0800 (PST) Date: Sat, 23 Nov 2013 09:48:11 +0000 Message-ID: Subject: [PATCH] pointer to integer conversion. From: Iain Buclaw To: gcc-patches@gcc.gnu.org X-IsSubscribed: yes Hi, This is a one line patch to an unexpected behaviour noticed from ARM and x86 when testing the D frontend. --- import core.stdc.stdio; import core.stdc.stdint; void test(void* p) { uint64_t pl = cast(uint64_t)p; uint64_t p2 = cast(uint64_t)cast(int)p; int tmp = cast(int)p; uint64_t p3 = cast(uint64_t)tmp; printf("%llx %llx %llx\n", pl, p2, p3); } void main() { void* p = cast(void*)0xFFEECCAA; test(p); } ------------------------------ Output is: ffffffffffeeccaa ffffffffffeeccaa ffffffffffeeccaa Expected: ffeeccaa ffffffffffeeccaa ffffffffffeeccaa Doing a quick conversion to C found that the same thing occurs with GCC too. This is the comment associated with the change in the function. /* Convert to an unsigned integer of the correct width first, and from there widen/truncate to the required type. Some targets support the coexistence of multiple valid pointer sizes, so fetch the one we need from the type. */ Currently, GCC is converting the expression to a signed integer instead of an unsigned one. Does a test for the testsuite need to be written for this? Regards, Iain. diff --git a/gcc/convert.c b/gcc/convert.c index 4cf5001..262d080 100644 --- a/gcc/convert.c +++ b/gcc/convert.c @@ -547,7 +547,7 @@ convert_to_integer (tree type, tree expr) from the type. */ expr = fold_build1 (CONVERT_EXPR, lang_hooks.types.type_for_size - (TYPE_PRECISION (intype), 0), + (TYPE_PRECISION (intype), 1), expr); return fold_convert (type, expr);