From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 69BAA385802B for ; Tue, 13 Feb 2024 16:11:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 69BAA385802B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 69BAA385802B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707840706; cv=none; b=T9zVPrAhzfR1to5K2vc5THWOGvNFYixH8r86A9ROe0d+BasYQpw5pft16wHORAvvqxn7Ns4NVYrpORdM1+2RK7itEI/QnT+sHCictUuTjBzN/SBpTEI1V9jTjHc9gfdnrAx9j7zj2b/8P0GSZTU+LR+Ed/e5QRdah9BKxy8V2dY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707840706; c=relaxed/simple; bh=a+ZFpHd5P5kXqVo0Cq186UBL7WwDdYa8BUKHSMtvJL8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=sEa5IiC5pAM6ZTekjkR8Va5wXc0VLvnb68xKNiqrtx8cg+3QCHfKhlyC2C+LMwURARAMXpTl7v7fM/LiQcPNbPoFHQdNeLSkI/w/MVU8cDKFLJ2y1wzWULPm63E9vjXpkHmuiFcdCmS5/B5xS+EQQI4oh9A2ttLAKQoWKMXLUWs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6e2f990c8b5so208077a34.1 for ; Tue, 13 Feb 2024 08:11:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707840703; x=1708445503; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=dwd/w0smd6o9wgCkyiJdHsXT/eX2jVnAaL4cuUUWxh8=; b=CnSbHMhxu0vbjuEHFFUxaCHMSeW5oK8IAgn98KkHSRs3dAv+XO3qv3NlYbFg2Mw4qo 3zTt9G8bYE/nGF5uq0jK1WEP5vB3B4sc+uGUydcT/8Lj2PidZJQLgl+rKKfRMJo24On4 UVh7Bll+utQtDtePQM5qlCVkx6vSSi53mLG/SF9J+Hg76ExP57IPckh8VBgktS1SatMC L/9ipcm/CwFmFLGk0bf6rWUb7wi11FHIuJVTx/svNe0t9x+nIuymVfduSI/XV+yD1aif ghw7XSN0gxidWqP1FMWZpSPH1E2Rm49lKJ1zR66n5P+EJq2VqCw/HWyp2Z9sc4x5+cFp oJRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707840703; x=1708445503; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dwd/w0smd6o9wgCkyiJdHsXT/eX2jVnAaL4cuUUWxh8=; b=mTTs/xtGhYwivzu1lNzMVdr5S5vuvsHAEL2ni55LNyDDzDZDDQWPWSwVyVepTHag7l OygINoW8iMl/+e+wMda3CoF2e3j7A6YjAFN+xj8N7rTfdBJCBO205zloG6yb9jISfWtc 1jUqQGjotwd9+jYRreotmzwtq0l/M+FNy3hom3R4GdAr21nSUFeKjy5ZYJJL+zEG4iCu wVmAziP/C4Jq7SlCBRhuYBNfhDdmjZ6+s5QLJX3DOeKYdpevVU7B4HPUd3VRmU3Wo2A8 DNN+5EuNucX0IkLDOEQYEzmdc9gkDPRbbYgh7DytWj8ThaBV9jnlqzktWL15jaq+ScwS bUiA== X-Gm-Message-State: AOJu0YzDj+V6nI+kV/oO9kOkAKPzUxxFUQgYpUEDcn/xAhEUoo42s2Tj YhRxVAc1pgdGKB7EVfLxf+SbnUc0l3QSKCtrRoEvOB0tgdfWeyqz X-Google-Smtp-Source: AGHT+IGzjcfMbj7mA7cFMQSdhe6a1lCO9w/+P0lak7/aOQT84wN8mR5lf7pdkBbLlVoks0pLlgCPxQ== X-Received: by 2002:a05:6830:151a:b0:6e2:eba0:ec4d with SMTP id k26-20020a056830151a00b006e2eba0ec4dmr476otp.33.1707840703718; Tue, 13 Feb 2024 08:11:43 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV1ajchLx3IjqiYEXR7Nnig7LgjmC1PrwLQPAcpd9I2tzNNtAlfgk81LzGuBCYBFePkVR+kQTMrxmL2J9YNUe42542qxDUvKXOx7ItWTdLvk21zcEBpgQ== Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id bf10-20020a056830354a00b006e2f7ddf4eesm160670otb.28.2024.02.13.08.11.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Feb 2024 08:11:43 -0800 (PST) Message-ID: <41b30348-39cb-47cd-91c9-2e21b0d509ea@gmail.com> Date: Tue, 13 Feb 2024 09:11:42 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] pretty-print: Fix up ptrdiff handling for %tu, %to, %tx Content-Language: en-US To: Jakub Jelinek , Richard Biener , "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org References: From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SCC_BODY_URI_ONLY,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2/13/24 01:21, Jakub Jelinek wrote: > Hi! > > This is IMHO more of a theoretical case, I believe my current code > doesn't handle %tu or %to or %tx correctly if ptrdiff_t is not one of > int, long int or long long int. For size_t and %zd or %zi I'm > using va_arg (whatever, ssize_t) and hope that ssize_t is the signed > type corresponding to size_t which C99 talks about. > For ptrdiff_t there is no type for unsigned type corresponding to > ptrdiff_t and I'm not aware of a portable way on the host to get > such a type (the fmt tests use hacks like > #define signed /* Type might or might not have explicit 'signed'. */ > typedef unsigned __PTRDIFF_TYPE__ unsigned_ptrdiff_t; > #undef signed > but that only works with compilers which predefine __PTRDIFF_TYPE__), > std::make_unsigned I believe only works reliably if > ptrdiff_t is one of char, signed char, short, int, long or long long, > but won't work e.g. for __int20__ or whatever other weird ptrdiff_t > the host might have. > > The following patch assumes host is two's complement (I think we > rely on it pretty much everywhere anyway) and prints unsigned type > corresponding to ptrdiff_t as unsigned long long printing of > ptrdiff_t value masked with 2ULL * PTRDIFF_MAX + 1. So the only > actual limitation is that it doesn't support ptrdiff_t wider than > long long int. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2024-02-13 Jakub Jelinek > > * pretty-print.cc (PTRDIFF_MAX): Define if not yet defined. > (pp_integer_with_precision): For unsigned ptrdiff_t printing > with u, o or x print ptrdiff_t argument converted to > unsigned long long and masked with 2ULL * PTRDIFF_MAX + 1. > > * error.cc (error_print): For u printing of ptrdiff_t, > print ptrdiff_t argument converted to unsigned long long and > masked with 2ULL * PTRDIFF_MAX + 1. OK jeff