Message ID | 20200227164651.13723-1-andrew.burgess@embecosm.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 128766 invoked by alias); 27 Feb 2020 16:46:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 128757 invoked by uid 89); 27 Feb 2020 16:46:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*MI:andrew, touching X-HELO: mail-wm1-f54.google.com Received: from mail-wm1-f54.google.com (HELO mail-wm1-f54.google.com) (209.85.128.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Feb 2020 16:46:58 +0000 Received: by mail-wm1-f54.google.com with SMTP id q9so19416wmj.5 for <gdb-patches@sourceware.org>; Thu, 27 Feb 2020 08:46:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id; bh=GBobIXVS4TF+gwZ2B8Ae1yGFxvxTI4m+2gA6Ti65Otc=; b=W98oWa5A7Jva3VvLREBbGVEvIovN36VY3s/xmPWH2rpyWJpArKtjnMeI32JAqhHU2Y 70j7iaTjbZLmQPlk8cHpf5W10ENCkSrH31CuE0Rzc818YVAmyWPLdFMtU/DM0G0xtfaY Hl2raWaSMCFPJL21Y/XD4InmlVLUpDdMm/fO+g1RkRGnGRiI/sC1nSY0A6qzidS/3Q2V SKUUhxrLO1mxovbr+kZv48WSIMvN04eRo2orAFoSSgP4DPFTr/psHxjl8I2DvlxCtRfE SZJN+IElmKFCHPSZ+/b8+d6YdPzmxv9E8jUBl7f3mwAjSvCvqgSRb0J6Pl+WoXDl9wwY aOrQ== Return-Path: <andrew.burgess@embecosm.com> Received: from localhost (host86-186-80-160.range86-186.btcentralplus.com. [86.186.80.160]) by smtp.gmail.com with ESMTPSA id c141sm8017549wme.41.2020.02.27.08.46.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Feb 2020 08:46:54 -0800 (PST) From: Andrew Burgess <andrew.burgess@embecosm.com> To: gdb-patches@sourceware.org Cc: Andrew Burgess <andrew.burgess@embecosm.com> Subject: [PUSHED] gdb: Use std::abs instead of abs on LONGEST types Date: Thu, 27 Feb 2020 16:46:51 +0000 Message-Id: <20200227164651.13723-1-andrew.burgess@embecosm.com> X-IsSubscribed: yes |
Commit Message
Andrew Burgess
Feb. 27, 2020, 4:46 p.m. UTC
Use std::abs so that we get the C++ overloaded version that matches the argument type instead of the C abs function which is only for int arguments. There should be no user visible change after this commit. gdb/ChangeLog: * gdbtypes.c (create_array_type_with_stride): Use std::abs not abs. --- gdb/ChangeLog | 5 +++++ gdb/gdbtypes.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-)
Comments
On 2/27/20 4:46 PM, Andrew Burgess wrote: > Use std::abs so that we get the C++ overloaded version that matches > the argument type instead of the C abs function which is only for int > arguments. Note that stdlib.h/stdmath.h are supposed to provide the overloads in the global namespace as well; the standard requires it. Older GCCs got that wrong (e.g. 4.8), but more modern GCCs get it right. Just a FYI, the patch is fine. > > There should be no user visible change after this commit. > > gdb/ChangeLog: > > * gdbtypes.c (create_array_type_with_stride): Use std::abs not > abs. Thanks, Pedro Alves
On Thu, Feb 27, 2020 at 1:07 PM Pedro Alves <palves@redhat.com> wrote: > > On 2/27/20 4:46 PM, Andrew Burgess wrote: > > Use std::abs so that we get the C++ overloaded version that matches > > the argument type instead of the C abs function which is only for int > > arguments. > > Note that stdlib.h/stdmath.h are supposed to provide the overloads in > the global namespace as well; the standard requires it. Older > GCCs got that wrong (e.g. 4.8), but more modern GCCs get it right. > > Just a FYI, the patch is fine. Hm... I saw a build error from this on arm-netbsd with clang 9, I wonder what happened there. Anyway, the patch does fix it. Christian > > > > > There should be no user visible change after this commit. > > > > gdb/ChangeLog: > > > > * gdbtypes.c (create_array_type_with_stride): Use std::abs not > > abs. > > Thanks, > Pedro Alves >
On 2/27/20 7:09 PM, Christian Biesinger via gdb-patches wrote: > On Thu, Feb 27, 2020 at 1:07 PM Pedro Alves <palves@redhat.com> wrote: >> >> On 2/27/20 4:46 PM, Andrew Burgess wrote: >>> Use std::abs so that we get the C++ overloaded version that matches >>> the argument type instead of the C abs function which is only for int >>> arguments. >> >> Note that stdlib.h/stdmath.h are supposed to provide the overloads in >> the global namespace as well; the standard requires it. Older >> GCCs got that wrong (e.g. 4.8), but more modern GCCs get it right. >> >> Just a FYI, the patch is fine. > > Hm... I saw a build error from this on arm-netbsd with clang 9, I > wonder what happened there. Anyway, the patch does fix it. > ( See: https://developers.redhat.com/blog/2016/02/29/why-cstdlib-is-more-complicated-than-you-might-think/ ) Odd, clang 5, which is what I have handy, gets it right: $ cat abs.cc #include <stdlib.h> #include <stdio.h> void foo (long i) { printf ("long\n"); } void foo (int i) { printf ("int\n"); } int main () { foo (abs ((long)1)); foo (abs ((int)1)); } $ clang++ abs.cc -o abs && ./abs long int I wonder whether you were seeing a gnulib override issue, but I can't find an abs override in our import. Thanks, Pedro Alves
* Pedro Alves <palves@redhat.com> [2020-02-27 19:06:47 +0000]: > On 2/27/20 4:46 PM, Andrew Burgess wrote: > > Use std::abs so that we get the C++ overloaded version that matches > > the argument type instead of the C abs function which is only for int > > arguments. > > Note that stdlib.h/stdmath.h are supposed to provide the overloads in > the global namespace as well; the standard requires it. Older > GCCs got that wrong (e.g. 4.8), but more modern GCCs get it right. > > Just a FYI, the patch is fine. Thanks for looking at this. Thanks, Andrew > > > > > There should be no user visible change after this commit. > > > > gdb/ChangeLog: > > > > * gdbtypes.c (create_array_type_with_stride): Use std::abs not > > abs. > > Thanks, > Pedro Alves >
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index ef110b30445..d89df9f7409 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1249,9 +1249,9 @@ create_array_type_with_stride (struct type *result_type, negative stride in Fortran (this doesn't mean anything special, it's still just a single element array) so do consider that case when touching this code. */ - LONGEST element_count = abs (high_bound - low_bound + 1); + LONGEST element_count = std::abs (high_bound - low_bound + 1); TYPE_LENGTH (result_type) - = ((abs (stride) * element_count) + 7) / 8; + = ((std::abs (stride) * element_count) + 7) / 8; } else TYPE_LENGTH (result_type) =