From patchwork Fri Nov 9 14:37:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 995576 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489524-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="VhdR6yfp"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42s2my6TSJz9s5c for ; Sat, 10 Nov 2018 01:37:37 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=fi/2Oc6J3tVyhy4TQ T5a0Som1OjRVo9oAP8LaVyGpEBJPFmcEcUM+HQ0HmhhBf6SnnE0DYrJLWbzN4Yb7 rSBtPZCGRCHKuhbo2QDNCj4M9to4SR+SehXje36EDdfjhHd9Nmbm6rWfCJt94DR1 AcqGIwj0kPe+w9ruIU6wtqlTi0= 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:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=XQbRoPWORuwY75L628ScAZE jTUE=; b=VhdR6yfpbU6jahHEkdWSLckYjz/APelYZlxtPpdczkKAnhDPe4qfrBD 5DpDN5C2ypg6h3azBiqxlKcaMBqnkwJbiKfGnR6nzaFoW7a4twuiCwRcsGhcWUXl YkRSLhI0m6ThZ8PmWOhVzAHbBbd64M6Jrlty4HForJLh1Jhf6rr0= Received: (qmail 14440 invoked by alias); 9 Nov 2018 14:37:29 -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 14429 invoked by uid 89); 9 Nov 2018 14:37:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:display, UD:display-affinity-1.c X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Nov 2018 14:37:27 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C724481DE3; Fri, 9 Nov 2018 14:37:25 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4CF4D5D96E; Fri, 9 Nov 2018 14:37:25 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id wA9EbMXr009131; Fri, 9 Nov 2018 15:37:23 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id wA9EbJnv009130; Fri, 9 Nov 2018 15:37:19 +0100 Date: Fri, 9 Nov 2018 15:37:19 +0100 From: Jakub Jelinek To: "Dominique =?iso-8859-1?Q?d'Humi=E8res?=" Cc: gcc-patches , Rainer Orth Subject: [PATCH] Fix up affinity-fmt.c (was Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9) Message-ID: <20181109143719.GL11582@tucnak> Reply-To: Jakub Jelinek References: <20181109110454.GA11625@tucnak> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20181109110454.GA11625@tucnak> User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! The earlier patch doesn't work, because there were still expressions where handle could be still cast to integer of different size if it happened to be a pointer, or an invalid cast of e.g. aggregate to integer. The following patch so far only tested on a simplified code should handle it properly though, gomp_integral should yield an integral type without a warning (for aggregates etc. 0, but that is what I wanted to print, don't know what else to print if pthread_t is an aggregate I have no idea what it contains). Plus I've added some portability stuff for mingw %llx vs. %I64x. Can you please give it a whirl on Darwin and see what the display-affinity-1.c testcase prints (in libgomp/testsuite/libgomp.log) ? Thanks. 2018-11-09 Jakub Jelinek * affinity-fmt.c: Include inttypes.h if HAVE_INTTYPES_H. (gomp_display_affinity): Use __builtin_choose_expr to handle properly handle argument having integral, or pointer or some other type. If inttypes.h is available and PRIx64 is defined, use PRIx64 with uint64_t type instead of %llx and unsigned long long. Jakub --- libgomp/affinity-fmt.c.jj 2018-11-08 18:08:01.412987460 +0100 +++ libgomp/affinity-fmt.c 2018-11-09 15:24:52.049169494 +0100 @@ -30,6 +30,9 @@ #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_INTTYPES_H +# include /* For PRIx64. */ +#endif #ifdef HAVE_UNAME #include #endif @@ -356,37 +359,42 @@ gomp_display_affinity (char *buffer, siz goto do_int; case 'i': #if defined(LIBGOMP_USE_PTHREADS) && defined(__GNUC__) - /* Handle integral pthread_t. */ - if (__builtin_classify_type (handle) == 1) - { - char buf[3 * (sizeof (handle) + sizeof (int)) + 4]; - - if (sizeof (handle) == sizeof (long)) - sprintf (buf, "0x%lx", (long) handle); - else if (sizeof (handle) == sizeof (long long)) - sprintf (buf, "0x%llx", (long long) handle); - else - sprintf (buf, "0x%x", (int) handle); - gomp_display_num (buffer, size, &ret, zero, right, sz, buf); - break; - } - /* And pointer pthread_t. */ - else if (__builtin_classify_type (handle) == 5) - { - char buf[3 * (sizeof (uintptr_t) + sizeof (int)) + 4]; - - if (sizeof (uintptr_t) == sizeof (long)) - sprintf (buf, "0x%lx", (long) (uintptr_t) handle); - else if (sizeof (uintptr_t) == sizeof (long long)) - sprintf (buf, "0x%llx", (long long) (uintptr_t) handle); - else - sprintf (buf, "0x%x", (int) (uintptr_t) handle); - gomp_display_num (buffer, size, &ret, zero, right, sz, buf); - break; - } + { + char buf[3 * (sizeof (handle) + sizeof (uintptr_t) + sizeof (int)) + + 4]; + /* This macro returns expr unmodified for integral or pointer + types and 0 for anything else (e.g. aggregates). */ +#define gomp_nonaggregate(expr) \ + __builtin_choose_expr (__builtin_classify_type (expr) == 1 \ + || __builtin_classify_type (expr) == 5, expr, 0) + /* This macro returns expr unmodified for integral types, + (uintptr_t) (expr) for pointer types and 0 for anything else + (e.g. aggregates). */ +#define gomp_integral(expr) \ + __builtin_choose_expr (__builtin_classify_type (expr) == 5, \ + (uintptr_t) gomp_nonaggregate (expr), \ + gomp_nonaggregate (expr)) + + if (sizeof (gomp_integral (handle)) == sizeof (unsigned long)) + sprintf (buf, "0x%lx", (unsigned long) gomp_integral (handle)); +#if defined (HAVE_INTTYPES_H) && defined (PRIx64) + else if (sizeof (gomp_integral (handle)) == sizeof (uint64_t)) + sprintf (buf, "0x" PRIx64, (uint64_t) gomp_integral (handle)); +#else + else if (sizeof (gomp_integral (handle)) + == sizeof (unsigned long long)) + sprintf (buf, "0x%llx", + (unsigned long long) gomp_integral (handle)); #endif + else + sprintf (buf, "0x%x", (unsigned int) gomp_integral (handle)); + gomp_display_num (buffer, size, &ret, zero, right, sz, buf); + break; + } +#else val = 0; goto do_int; +#endif case 'A': if (sz == (size_t) -1) gomp_display_affinity_place (buffer, size, &ret,