From patchwork Mon Dec 25 13:39:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Fedotov X-Patchwork-Id: 122695 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp5487188qgn; Mon, 25 Dec 2017 05:40:02 -0800 (PST) X-Google-Smtp-Source: ACJfBotKSN1YtstJYeqjBRW1SfSzpi8gX+k/ga7p8Mk/ay7vMpxZ7Y3F+8YikReRIwXB/fvvWEfw X-Received: by 10.99.152.25 with SMTP id q25mr19904557pgd.245.1514209202123; Mon, 25 Dec 2017 05:40:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514209202; cv=none; d=google.com; s=arc-20160816; b=zrBU00QiJXK685Wq1peV66Gah64diqN+Hv9Hm8mccEWbOrgpnoAcTLrJGiMRMfZAc0 oywDGiVlk4FpHMsLfXnmilIU52xBnMt3HfLowC3zZEdKtf3MI7yHd8WDDBNJMkGikWVM CSkA1kPZYnzMCrOtg761xhvD6WjPoUXY/nMgLIyE4QZCCd7bpPO8Lrbg7ChP7gz9s6Ti LPEXj6B9059cUsLAP4Cxl0aoIs7cpOHhV/8p5pTkuX64lw2yKsA/2aKX40qntgUbR2M2 rAQyozbErN+Ji+fBATJyfsze3YnfrHh6+lT55h/9uA375ucSl/e3iXRooG1IDuqPx5A0 r4iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-subscribe:list-unsubscribe :list-id:precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=GRHOLB8tphgYDhEHH22oG55ZkXThJ+3itmASb2axd8g=; b=LgjNqoEhAqFUMqR7Bo+EQiWIBmYzyqaKbtsH44OQpFqNFGBQMOOCqvP7K08rbqIMnA 68SY998qdjLFM49U578Vd+QytxBKvJp+YuwnCV8GeI9JVLxOsb/12VyNRTGeuK6H6GVD d8+ZQYiL1XnK63ZAOKMQjZq1JIpzxkF49U+UZEcOqe0vNj6XFDPaXFeidGmSOH5SkVJR dK14ieAr2dr3fKEogkz/D5GsT+3VAnhVVn1x8SeVsWcK+6xt2V4DpMZMZ9jg1IMct454 LkS67spsU+MlK3FWKNslVRKFIDzD9mFRN2+0MsJeaHonQUKDEP81W6P87hvLcxXGJR0F UohQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=agAZMd5X; spf=pass (google.com: domain of newlib-return-15541-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=newlib-return-15541-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p7si21524701plr.290.2017.12.25.05.40.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Dec 2017 05:40:02 -0800 (PST) Received-SPF: pass (google.com: domain of newlib-return-15541-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=agAZMd5X; spf=pass (google.com: domain of newlib-return-15541-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=newlib-return-15541-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; q=dns; s=default; b=Rk/nMt2uvT2SfXdyuqbCQ3kEkTSIu BUGx1bMvGRMh0bT1bgVfjnt9IKT+G3ABry0PxGYueakCjS3u1OutZORem3YoB0+4 DdxCszBwkDHEUb3JqlvsFA3hCt3A6SA693GvZu/9QzfVQt3kSIprTdet0aRQ/cz+ 0zmkP5l4oHNPbI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; s=default; bh=/ZS8GiW0K9Hxonr0KNcbX0q4RD0=; b=agA ZMd5Xd/X0E0wPpCL5dcnHgIPIJo3yi0PqELu4JHD2/MwIIwQ9LiC3GPj2GfwVPK8 GdbxdxDv8Z0KOqp21sS9HArHcCz4HdvasyObcu3C9OZXip2eOJEn35N1WWE7UVMJ IlB6IzknJ8uhSji55q5mTjIEZNYd0dbPRVVnAMvU= Received: (qmail 33663 invoked by alias); 25 Dec 2017 13:39:54 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Delivered-To: mailing list newlib@sourceware.org Received: (qmail 33643 invoked by uid 89); 25 Dec 2017 13:39:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-22.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 spammy= X-HELO: mail-pg0-f47.google.com Received: from mail-pg0-f47.google.com (HELO mail-pg0-f47.google.com) (74.125.83.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 25 Dec 2017 13:39:51 +0000 Received: by mail-pg0-f47.google.com with SMTP id g7so16991372pgs.0 for ; Mon, 25 Dec 2017 05:39:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=/6qmCvVBRUCyhbYaH7fFPnBiIhEw36B5JYqJ6pL0tBY=; b=A1v15HT3JpTMHBcb6mT2JidyF6s4DAZWLlA8waKj/CF9OUiewr7PZTwSIRt6G9R9dZ DYpPhH/8qW1A6epCO/GiACtpmh8JKKtcN/N1/En3xRi8CZVo7ZLmoLq3ILhhC1I7UoCv T4bTLF/of4PGfRyOLiCw6t2MF+ybv0sjfA4YUBZ5Vir1UuJgI5lF4jSqk3lPuna052We 7D45Tz4rQuTOAPX2beTQAeFi0Fgn1ROUw5p0YhN5Bqiv0dfs2Nf5+7XjXqMDVUpaup0e JxHnCwRjM+yn6dPbELB+YRQhkGqilCtJR+b7dfn7qyMe4m8jZo/kElDcmEHlMl0iUU0q lJCQ== X-Gm-Message-State: AKGB3mLUMsGi+tWFGOD+9jaShD9ii4R9onasnkorYNbY8FTHColR0KFW fUlcodtZCgktedcFCOxVB9+p5boWAmLf2D/ESso7vg== X-Received: by 10.99.123.14 with SMTP id w14mr16173656pgc.340.1514209189721; Mon, 25 Dec 2017 05:39:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.100.151.226 with HTTP; Mon, 25 Dec 2017 05:39:49 -0800 (PST) From: Alexander Fedotov Date: Mon, 25 Dec 2017 16:39:49 +0300 Message-ID: Subject: nano printf + powerpc gcc To: newlib@sourceware.org Hi I'm experienced a strange printf() for float variables behaviour with Nano version while regular is fine. It just prins out a garbage (even with enabled -u _printf_float). After some digging I've managed to track down issue until this line: n = _printf_float (data, &prt_data, fp, pfunc, &ap); Moreover there are number of warnings also in build log: src_newlib/newlib/libc/stdio/nano-vfprintf.c -o lib_a-nano-svfprintf.o ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf.c: In function '_svfprintf_r': ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf.c:645:55: warning: passing argument 5 of '_printf_float' from incompatible pointer type n = _printf_float (data, &prt_data, fp, pfunc, &ap); ^ In file included from ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf.c:169:0: ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf_local.h:228:1: note: expected 'struct __va_list_tag (*)[1]' but argument is of type 'struct __va_list_tag **' _printf_float (struct _reent *data, ^ ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf.c:650:45: warning: passing argument 5 of '_printf_i' from incompatible pointer type n = _printf_i (data, &prt_data, fp, pfunc, &ap); ^ In file included from ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf.c:169:0: ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf_local.h:221:1: note: expected 'struct __va_list_tag (*)[1]' but argument is of type 'struct __va_list_tag **' _printf_i (struct _reent *data, struct _prt_data_t *pdata, FILE *fp, It looks like nano written without taking in mind such targets. Here I found workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14557 that's working. I'm attaching a patch. Alex >From 47ee6b7a46e6331ae0840a2262258d2c868ccbc5 Mon Sep 17 00:00:00 2001 From: Alexander Fedotov Date: Mon, 25 Dec 2017 16:28:22 +0300 Subject: [PATCH] fix incompatible pointer type for va_list in nano versions of printf and scanf for target like PowerPC --- newlib/libc/stdio/nano-vfprintf.c | 14 ++++++++++++-- newlib/libc/stdio/nano-vfscanf.c | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/newlib/libc/stdio/nano-vfprintf.c b/newlib/libc/stdio/nano-vfprintf.c index e6604e7..663eb71 100644 --- a/newlib/libc/stdio/nano-vfprintf.c +++ b/newlib/libc/stdio/nano-vfprintf.c @@ -168,6 +168,16 @@ static char *rcsid = "$Id$"; #include "vfieeefp.h" #include "nano-vfprintf_local.h" + +/* GCC PR 14577 at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14557 */ +#if __STDC_VERSION__ >= 201112L +#define va_ptr(ap) _Generic(&(ap), va_list *: &(ap), default: (va_list *)(ap)) +#elif __GNUC__ >= 4 +#define va_ptr(ap) __builtin_choose_expr(__builtin_types_compatible_p(__typeof__(&(ap)), va_list *), &(ap), (va_list *)(ap)) +#else +#define va_ptr(ap) (sizeof(ap) == sizeof(va_list) ? (va_list *)&(ap) : (va_list *)(ap)) +#endif + /* The __ssputs_r function is shared between all versions of vfprintf and vfwprintf. */ #ifdef STRING_ONLY @@ -633,12 +643,12 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), } else { - n = _printf_float (data, &prt_data, fp, pfunc, &ap); + n = _printf_float (data, &prt_data, fp, pfunc, va_ptr(ap)); } } else #endif - n = _printf_i (data, &prt_data, fp, pfunc, &ap); + n = _printf_i (data, &prt_data, fp, pfunc, va_ptr(ap)); if (n == -1) goto error; diff --git a/newlib/libc/stdio/nano-vfscanf.c b/newlib/libc/stdio/nano-vfscanf.c index 564f291..6467e54 100644 --- a/newlib/libc/stdio/nano-vfscanf.c +++ b/newlib/libc/stdio/nano-vfscanf.c @@ -119,6 +119,15 @@ Supporting OS subroutines required: #include "../stdlib/local.h" #include "nano-vfscanf_local.h" +/* GCC PR 14577 at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14557 */ +#if __STDC_VERSION__ >= 201112L +#define va_ptr(ap) _Generic(&(ap), va_list *: &(ap), default: (va_list *)(ap)) +#elif __GNUC__ >= 4 +#define va_ptr(ap) __builtin_choose_expr(__builtin_types_compatible_p(__typeof__(&(ap)), va_list *), &(ap), (va_list *)(ap)) +#else +#define va_ptr(ap) (sizeof(ap) == sizeof(va_list) ? (va_list *)&(ap) : (va_list *)(ap)) +#endif + #define VFSCANF vfscanf #define _VFSCANF_R _vfscanf_r #define __SVFSCANF __svfscanf @@ -424,12 +433,12 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), } ret = 0; if (scan_data.code < CT_INT) - ret = _scanf_chars (rptr, &scan_data, fp, &ap); + ret = _scanf_chars (rptr, &scan_data, fp, va_ptr(ap)); else if (scan_data.code < CT_FLOAT) - ret = _scanf_i (rptr, &scan_data, fp, &ap); + ret = _scanf_i (rptr, &scan_data, fp, va_ptr(ap)); #ifdef FLOATING_POINT else if (_scanf_float) - ret = _scanf_float (rptr, &scan_data, fp, &ap); + ret = _scanf_float (rptr, &scan_data, fp, va_ptr(ap)); #endif if (ret == MATCH_FAILURE) -- 2.7.4