From patchwork Wed Dec 14 21:38:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Magno de Almeida X-Patchwork-Id: 88072 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp431910qgi; Wed, 14 Dec 2016 13:39:30 -0800 (PST) X-Received: by 10.84.195.1 with SMTP id i1mr208855385pld.84.1481751570726; Wed, 14 Dec 2016 13:39:30 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id n22si54530535pfj.253.2016.12.14.13.39.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Dec 2016 13:39:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444454-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444454-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444454-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com 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:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=r6N5km6ZjTKqsaF bF/mw5C9YWTD5rlBFB85MG04RIV8fXRnEtf+qCKWmmz0v2X9HbEEEIMUL65njTYs 4un0q2INngXit7VSLFYq6sowL8Y1Ge4cwt4eBFO7En4KVRvuaPOXYth8AGDXaWMd V+Y4u39fHfMJuywX9H9z6VQp8K60= 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:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=lbsE8gZi5LKqWeZr3e4nA 8oLH2E=; b=mTvAw+SSnDVw75jRyBn9R3aZ9Ovb3RubP2EU9g9zJKwpciA0z0a9l X3nJL3KM3VOL07oUNECkFP6nwbbzxj2ENbaw31oqkUjfkoIcVelpHErg8ru3VqL9 rR1h8sULb4CQWcEhjz2+TublUkphQNLl9iWanIZ0GVrG16jzkkqeJA= Received: (qmail 7795 invoked by alias); 14 Dec 2016 21:39:12 -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 7765 invoked by uid 89); 14 Dec 2016 21:39:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=D*br, Month, D*com.br, HX-Envelope-From:sk:felipe. X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-qt0-f170.google.com Received: from mail-qt0-f170.google.com (HELO mail-qt0-f170.google.com) (209.85.216.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 14 Dec 2016 21:39:01 +0000 Received: by mail-qt0-f170.google.com with SMTP id c47so38527978qtc.2; Wed, 14 Dec 2016 13:39:01 -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:in-reply-to:references:from:date :message-id:subject:to:cc; bh=FFzDmNehKijOGXsE/XpIiaaZafd37qCJfdKRe/qfhsM=; b=bxrbkdpkGCRuPt5q2IcwrlVkzm9mZYRBljdMUythPwZY1bGkICWt2iqi7S2Y5ZWrCA VdOpXdZYlbElmT+xf8F/QlpOwSRxf5lA8X1TwIt6WRl+8CNZZQWTdFsByoKrdIH/kA/w aVU0yTycAZuf43uHV+wVp5aEMyEH2nPACu2QTu0IIFKfn1TjOaSQSN+v1hInp1P75o9R N4eaONQm4y6sWWOsgI2XCPt6yLoChPKL3XG1vNKNoaureZJ8wUJk6GxhuIACcEJuiCj7 dah/XxIIOir/c4iM1F98FXru/292tp03WQ6hkn+4fpBjXWAW0hEYMNeiFGjNZFDrCut/ rdBQ== X-Gm-Message-State: AKaTC023+/nfmHJL3cnY5kR7JU8ocSI4NsJcawGAbkXubmKo9B2tEyyRaJ+CC2xnNfLcZjeBUMFSkRrTa8s/hA== X-Received: by 10.200.51.251 with SMTP id d56mr86313726qtb.89.1481751540136; Wed, 14 Dec 2016 13:39:00 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.41.180 with HTTP; Wed, 14 Dec 2016 13:38:29 -0800 (PST) In-Reply-To: <20161206184508.GQ6326@redhat.com> References: <20161206184508.GQ6326@redhat.com> From: Felipe Magno de Almeida Date: Wed, 14 Dec 2016 18:38:29 -0300 Message-ID: Subject: Re: Fix compilation errors with libstdc++v3 for AVR target and allow --enable-libstdcxx To: Jonathan Wakely Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org X-IsSubscribed: yes Hello Jonathan, Sorry for the delay, I was in mid-vacation. Comments are inline. On Tue, Dec 6, 2016 at 3:45 PM, Jonathan Wakely wrote: > On 16/09/16 02:53 -0300, Felipe Magno de Almeida wrote: >> [snip] >> I've tried both approaches. Templates were causing problems of not >> defined instantations because they were being used as ints too >> in other _M_extract functions through a tmp integer. And typedef's >> caused the same problem of having to use a tmp value of the right >> type but for example _M_extract_wday_or_month could not have the >> same type (in AVR they do) and I'd have to use a temporary anyway >> then. >> >> This was the least intrusive way. > > > Did you consider something like this? I have, but I did not like how it could run code that is not very explicit in case of exceptions, possibly assigning from a non-initialized variable, causing, theoretically UB. Besides, __mem was already used for tm_mom, so it seemed best to just mimic for the rest. I have another patch attached which fixes the problem you mentioned and the same problem with the tm_wday in a different switch-case. I've removed all initializations of __mem, the same way that tm_mon already did not initialize it, because the value is not actually used at all in extract_num and variants. I have ran the test and nothing on locale failed, I've ran again with the fixes, and there are also no errors on locale. Testing with x86_64. Changelog is: 2016-11-10 Felipe Magno de Almeida * include/bits/locale_facets_nonio.tcc: Avoid compilation errors with non-standard struct tm. > This should have no overhead for the targets with standard conforming > struct tm, and only uses a temporary variable and additional > assignments for AVR. > > It's ugly though. Quite ugly, specially because of exceptions IMO. Kind regards, -- Felipe Magno de Almeida >From a16f976cc02d5d8431923943ba3962733e17d13f Mon Sep 17 00:00:00 2001 From: Felipe Magno de Almeida Date: Thu, 15 Sep 2016 18:52:57 -0300 Subject: [PATCH] Use temporary int objects to access struct tm members Call _M_extract_* functions family through temporary int objects, so it doesn't convert from lvalue to rvalue through a temporary in AVR because of the incompatible types used in AVR-Libc. This fixes compilation errors with AVR-Libc while compiling libstdc++ for AVR target. --- libstdc++-v3/include/bits/locale_facets_nonio.tcc | 34 +++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.tcc b/libstdc++-v3/include/bits/locale_facets_nonio.tcc index 1a4f9a0..cfbd381 100644 --- a/libstdc++-v3/include/bits/locale_facets_nonio.tcc +++ b/libstdc++-v3/include/bits/locale_facets_nonio.tcc @@ -659,30 +659,34 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11 // Abbreviated weekday name [tm_wday] const char_type* __days1[7]; __tp._M_days_abbreviated(__days1); - __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days1, + __beg = _M_extract_name(__beg, __end, __mem, __days1, 7, __io, __tmperr); + __tm->tm_wday = __mem; break; case 'A': // Weekday name [tm_wday]. const char_type* __days2[7]; __tp._M_days(__days2); - __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days2, + __beg = _M_extract_name(__beg, __end, __mem, __days2, 7, __io, __tmperr); + __tm->tm_wday = __mem; break; case 'h': case 'b': // Abbreviated month name [tm_mon] const char_type* __months1[12]; __tp._M_months_abbreviated(__months1); - __beg = _M_extract_name(__beg, __end, __tm->tm_mon, + __beg = _M_extract_name(__beg, __end, __mem, __months1, 12, __io, __tmperr); + __tm->tm_mon = __mem; break; case 'B': // Month name [tm_mon]. const char_type* __months2[12]; __tp._M_months(__months2); - __beg = _M_extract_name(__beg, __end, __tm->tm_mon, + __beg = _M_extract_name(__beg, __end, __mem, __months2, 12, __io, __tmperr); + __tm->tm_mon = __mem; break; case 'c': // Default time and date representation. @@ -693,18 +697,20 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11 break; case 'd': // Day [01, 31]. [tm_mday] - __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2, + __beg = _M_extract_num(__beg, __end, __mem, 1, 31, 2, __io, __tmperr); + __tm->tm_mday = __mem; break; case 'e': // Day [1, 31], with single digits preceded by // space. [tm_mday] if (__ctype.is(ctype_base::space, *__beg)) - __beg = _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9, + __beg = _M_extract_num(++__beg, __end, __mem, 1, 9, 1, __io, __tmperr); else - __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31, + __beg = _M_extract_num(__beg, __end, __mem, 10, 31, 2, __io, __tmperr); + __tm->tm_mday = __mem; break; case 'D': // Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year] @@ -715,13 +721,15 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11 break; case 'H': // Hour [00, 23]. [tm_hour] - __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 0, 23, 2, + __beg = _M_extract_num(__beg, __end, __mem, 0, 23, 2, __io, __tmperr); + __tm->tm_hour = __mem; break; case 'I': // Hour [01, 12]. [tm_hour] - __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2, + __beg = _M_extract_num(__beg, __end, __mem, 1, 12, 2, __io, __tmperr); + __tm->tm_hour = __mem; break; case 'm': // Month [01, 12]. [tm_mon] @@ -732,8 +740,9 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11 break; case 'M': // Minute [00, 59]. [tm_min] - __beg = _M_extract_num(__beg, __end, __tm->tm_min, 0, 59, 2, + __beg = _M_extract_num(__beg, __end, __mem, 0, 59, 2, __io, __tmperr); + __tm->tm_min = __mem; break; case 'n': if (__ctype.narrow(*__beg, 0) == '\n') @@ -752,11 +761,12 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11 // Seconds. [tm_sec] // [00, 60] in C99 (one leap-second), [00, 61] in C89. #if _GLIBCXX_USE_C99 - __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 60, 2, + __beg = _M_extract_num(__beg, __end, __mem, 0, 60, 2, #else - __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 61, 2, + __beg = _M_extract_num(__beg, __end, __mem, 0, 61, 2, #endif __io, __tmperr); + __tm->tm_sec = __mem; break; case 't': if (__ctype.narrow(*__beg, 0) == '\t') -- 2.10.2