From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id ED7413858D33 for ; Thu, 16 Feb 2023 13:48:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED7413858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=jguk.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jguk.org Received: by mail-wr1-x435.google.com with SMTP id m10so1913438wrn.4 for ; Thu, 16 Feb 2023 05:48:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jguk.org; s=google; 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=qajx2p4we9+J4JSmkI6BxtqcZLuZZGEruWP1NICSOEI=; b=kVIOvdhuTyk/o8Cd4MP189TPJt6zPJk6wUsHRDDxAPZ9XNUPmwXDJ04vgt/CYIMmag xvih7n4mKnJqrR+HKfGCqsDjP8I/g2VZUbI5wUBbH3GiywcGx0X2yTdgBapoxgHuI5VN FKO0JBDlCV9EOB/auQ6mGXc8dVKp0rVxEgUUEYrJfewClmQuR+ViolFETO0IMOl/IjQ2 PmWY6/au70V7VcSYDfn8YEHIaFNlUuqOjf0/FVBF+UIf0GcTvvqaL0erUm4AVZyD+475 h6Q+5NI96ynBvgq18aFaA7u4jgh8Exnf/tibrYHdmV9YsaHNMjdMmJJ0Yg7K//ms6Pra kG+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=qajx2p4we9+J4JSmkI6BxtqcZLuZZGEruWP1NICSOEI=; b=3PPkDhlIcDA6JrhNRZfB2AFS7tsi/Dkb36WIpMkeb+KGbhojYkBPEfiAH0MsaBvaXS CXupDaB8nrKZsAewgGghCFhz+93cWfk5WbdlGr7QDsv79cH9FWSt4BuQUh7qCtQPW4MS SbpqohNl7ErAJSHV41lPlY3u/bK+rB+qCYjS+j44XKFaIet0TTs8E93Ua0VB6y6rHKYt ek6+jxCwAk0k6dJ1OzT97WfhjXBEm3GR8uTNoxDpoSLjAejsvwY3aaFVQuZfqbmHwaNC pnlhV0mVEobbLQzj2cGUABBAm7vxeFcnO05fdx/iNbbnZmU+jOBBM/t2c3LQ+dgAgXUf 6Q9w== X-Gm-Message-State: AO0yUKV4Py8/OahGzP9MhWzS6K4Rk1ho6jf356oofGpQdLOhkVUGN3Bn iUUooFkGymHGB8mqTyEUoqFkVA== X-Google-Smtp-Source: AK7set/1GQkWYZcg9JhNbpq2qhL16mJKxTG4QpQG/6ACIi0N50rMU7XwyVp4xzjnyZ3Q6jc7bbcZgA== X-Received: by 2002:adf:e6c2:0:b0:2c5:5574:5d5f with SMTP id y2-20020adfe6c2000000b002c555745d5fmr4548370wrm.57.1676555327744; Thu, 16 Feb 2023 05:48:47 -0800 (PST) Received: from [192.168.0.12] (cpc87345-slou4-2-0-cust172.17-4.cable.virginm.net. [81.101.252.173]) by smtp.gmail.com with ESMTPSA id k9-20020adfd849000000b002c3f50228afsm1525765wrl.3.2023.02.16.05.48.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Feb 2023 05:48:47 -0800 (PST) Message-ID: <3567fe85-3f93-7ff4-bf47-fc7b61dbbc00@jguk.org> Date: Thu, 16 Feb 2023 13:48:46 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: Could __builtin_printf parameters be optimized when being compiled Content-Language: en-GB To: Segher Boessenkool Cc: Richard Earnshaw , gcc-help References: <03717f06-9818-0c2a-6625-429887c55a17@jguk.org> <6bad0ce4-667f-0705-fc40-c40c9e8dec8f@jguk.org> <20230215154936.GG25951@gate.crashing.org> From: Jonny Grant In-Reply-To: <20230215154936.GG25951@gate.crashing.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham 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 15/02/2023 15:49, Segher Boessenkool wrote: > On Wed, Feb 15, 2023 at 03:10:15PM +0000, Jonny Grant wrote: >> On 15/02/2023 14:30, Richard Earnshaw wrote: >>>> int main() >>>> { >>>>      __builtin_printf("file %s:%d", __FILE__, __LINE__); >>>> } > > Note that the format needs to end in "\n" if you want this to be > converted to a puts() call. Without it it strangely doesn't seem to > be optimised, although fprintf() is converted to fwrite() in such cases. > This could be done for printf() as well: you are guaranteed to have > access to stdout as well, at least if you use printf() instead of the > builtin (I'm not sure if we do then). > >>> I guess it might be possible to handle cases where all the arguments are constant, but even that has its problems, eg: >>> >>> - can we guarantee identical output to the platform printf? >> >> That's a good question. I was using __builtin_printf so that should be GCC I expect. > > Not every printf() implementation has exactly the same output in all > cases. > > Another practically important consideration is what it does to i18n. > You really need to leave the format string unmodified for that to be > able to work. Thank you for your reply. i18n is a good point. At the moment I was just trying to get some strings for debugging in. Kind regards Jonny