From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id F29C83858C1F for ; Tue, 22 Nov 2022 20:43:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F29C83858C1F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x62f.google.com with SMTP id y10so13601116plp.3 for ; Tue, 22 Nov 2022 12:43:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=9Le274OI6bPcVI4EaMyz0kvqEHHbVVLN9wiGqMfq4Tk=; b=XLAiN4iN274gfzeeO74s9j+rpRWKIupejBy18skR36fYpILThVeUy5nFtTq9STcChv kQ3xuZauQIaHoGCfZN0ExVRGT/4HBgwCGY4V/Ziqd5TMrdXcrN6k9k2MkiIAQEgRYcRo YGQH57OabHRWmTDGq42JaV88lb2yAdrfl1Bu3+xVskuLrG6VjW3xOQyAhRYkB26hVj6Q BHDv4JPBrhXbVdm72p4OU00+VMCvm0pLo0unGoJFbioPYPQyznpwxl/YDuKTW3CrMBc4 5QVOmVy9/RvfYTWzuO53uywPJ8eRYhKpRLyOTo//RAY5+pQAa0IBMgFCNaIYh/bp48tm UBiQ== 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=9Le274OI6bPcVI4EaMyz0kvqEHHbVVLN9wiGqMfq4Tk=; b=RnmzN80O0428Zwx9ZK4rk1lXV6DluEDGxTdUMfQhC4+Al5xhV9MZAZO99luMdrZJMh pGnWzZ4kMy5+Gx1uaPsnz8b2kw6DPveUTHcvkDMI1c/iGQUwoDfgL7gKausM7z3ELffp K/7gFRxXTjZoKQLfeEwD+xdpm4lnXpulX+gLkbppSGcmegvmtteOrpuhx1Xyiu3j9NkW yvylbhuchILkqys+SJurzhfBX/cKMWuXGxmSBv0JaC79+ru/le4GnA3qjx2RhayViFcg BMy6Hnie1KZzaBrO7YuJ6uk6MHoFZvAr2gq1JkmFv2BUTyp8JFzvPx2t12eAg39kA0M+ C/MQ== X-Gm-Message-State: ANoB5pnt4FIwRWbWJuMxiELDwUg9J8Hz+kXTSKZ6jCG9jaiSSrsSVI4+ eDVHlaj1Rw+OoeZt1RyRhCk= X-Google-Smtp-Source: AA0mqf61xAQQ7C7kcSJK8zf/ViGleFDgrdNgm73fCGp8jGh2NlpafaiteOW0ygsq17iRggzUf6ORZg== X-Received: by 2002:a17:90a:7d0e:b0:218:7c5c:44b with SMTP id g14-20020a17090a7d0e00b002187c5c044bmr24656684pjl.23.1669149803722; Tue, 22 Nov 2022 12:43:23 -0800 (PST) Received: from ?IPV6:2601:681:8600:13d0::99f? ([2601:681:8600:13d0::99f]) by smtp.gmail.com with ESMTPSA id u6-20020a170902e80600b001871461688esm12523808plg.175.2022.11.22.12.43.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Nov 2022 12:43:22 -0800 (PST) Message-ID: Date: Tue, 22 Nov 2022 13:43:21 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH v2] tree-object-size: Support strndup and strdup Content-Language: en-US To: Siddhesh Poyarekar , gcc-patches@gcc.gnu.org Cc: jakub@redhat.com References: <20220815192311.763473-1-siddhesh@gotplt.org> <20221104124800.910588-1-siddhesh@gotplt.org> <90c74d8b-6dd9-49f3-ae83-ee97edb21b0f@gotplt.org> From: Jeff Law In-Reply-To: <90c74d8b-6dd9-49f3-ae83-ee97edb21b0f@gotplt.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 11/21/22 07:27, Siddhesh Poyarekar wrote: > On 2022-11-20 10:42, Jeff Law wrote: >> >> On 11/4/22 06:48, Siddhesh Poyarekar wrote: >>> Use string length of input to strdup to determine the usable size of >>> the >>> resulting object.  Avoid doing the same for strndup since there's a >>> chance that the input may be too large, resulting in an unnecessary >>> overhead or worse, the input may not be NULL terminated, resulting in a >>> crash where there would otherwise have been none. >>> >>> gcc/ChangeLog: >>> >>>     * tree-object-size.cc (todo): New variable. >>>     (object_sizes_execute): Use it. >>>     (strdup_object_size): New function. >>>     (call_object_size): Use it. >>> >>> gcc/testsuite/ChangeLog: >>> >>>     * gcc.dg/builtin-dynamic-object-size-0.c (test_strdup, >>>     test_strndup, test_strdup_min, test_strndup_min): New tests. >>>     (main): Call them. >>>     * gcc.dg/builtin-dynamic-object-size-1.c: Silence overread >>>     warnings. >>>     * gcc.dg/builtin-dynamic-object-size-2.c: Likewise. >>>     * gcc.dg/builtin-dynamic-object-size-3.c: Likewise. >>>     * gcc.dg/builtin-dynamic-object-size-4.c: Likewise. >>>     * gcc.dg/builtin-object-size-1.c: Silence overread warnings. >>>     Declare free, strdup and strndup. >>>     (test11): New test. >>>     (main): Call it. >>>     * gcc.dg/builtin-object-size-2.c: Silence overread warnings. >>>     Declare free, strdup and strndup. >>>     (test9): New test. >>>     (main): Call it. >>>     * gcc.dg/builtin-object-size-3.c: Silence overread warnings. >>>     Declare free, strdup and strndup. >>>     (test11): New test. >>>     (main): Call it. >>>     * gcc.dg/builtin-object-size-4.c: Silence overread warnings. >>>     Declare free, strdup and strndup. >>>     (test9): New test. >>>     (main): Call it. >> >> I'm struggling to see how the SSA updating is correct.  Yes we need >> to update the virtuals due to the introduction of the call to strlen, >> particularly when SRC is not a string constant.  But do we need to do >> more? >> >> Don't we end up gimplifying the 1 + strlenfn (src) expression? Can >> that possibly create new SSA_NAMEs?  Do those need to be put into SSA >> form? I feel like I'm missing something here... > > We do all of that manually in gimplify_size_expressions, the only > thing left to do is updating virtuals AFAICT. I guess it's actually buried down in force_gimple_operand and I guess for temporaries they're not going to be alive across the new gimple sequence and each destination gets its own SSA_NAME, so it ought to be safe.  Just had to work a bit further through things. OK for the trunk. Thanks, jeff