From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 175993895FF5 for ; Sun, 20 Nov 2022 15:42:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 175993895FF5 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-pg1-x52d.google.com with SMTP id 6so9082135pgm.6 for ; Sun, 20 Nov 2022 07:42:26 -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=BClJjwr6evgiTwzAmV1PGz+0LPjvmllzodFR85hKcWs=; b=RMR10p4SuYU3WnhOyBfLD+NqyR8AwxJmDD7w3CdVatQQdNBYV7f7qdL5DQdDz5z5jW ns9hP0QjwBJnX7nch8Ck91ieb2u4gy1VjrkdU543QXIFmKN4zKChLb4bVCuDE1UjCCnY +7NQELkVUSjJpQ3laQW8xjnb76OQ0E/sZm0w5bVxf1Cd8uRJAY3sbZnVUoo7nScumEQ1 wDRzb2FaPn7ia5/Yn0U4PAcfZd9Do1Vh2ICTwAvqEh70p3vE1TVXrzZ6fLclWoOPxV+q eKKEHWU9H/bT2pIFjpEAU+LNUd+MkLzS4GeEQCtmS1f+PYYHaIJFX2wbhFXB10/QbmIz 2lBQ== 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=BClJjwr6evgiTwzAmV1PGz+0LPjvmllzodFR85hKcWs=; b=Nk4wyc+hznj4RCFuB3Gc47WX64mxbdA2NHqKuga6rAqpFbEK2NPbm6e4+joxIgQsmV dfoXtu/ySCYpsX+K0ZOwRfqGg1qR1Vai5LEJQ0wcOX/hiwlpSImT8YR3oZVoyExUzPt8 DNNPCc+C/4DSZnVONk2eTc8DTEMw3Ea7EAMpGAAeP7xsmsNhwXv5O0OroVRlU3M3Nom6 vGO6x+kMMDmEPQKscB+CjK+hE6LyMlW3Yw8IAKnxRYOE2oCakt2TejUjY6+LS38I8gOf osww4jckiEaeOVxNw6Cvy/BHfTiJWFYCATRkKnvNeOvBrHKbZ5mA241CMGyNFRYj/wkh OWsQ== X-Gm-Message-State: ANoB5pkmXq6DrjAk+7/f2Qajt1moUwSE1FAxsQG7/DKOarW40AezveHS 7oGwjfJP1LFTAt+TyoC4FwY= X-Google-Smtp-Source: AA0mqf7pgwFhum6B/w+APngCVqfPCTCqkFKnhVDPG6SPzwGAOTQOTeBLcMBCoRe7UCwnp5VCuPIP1Q== X-Received: by 2002:aa7:8493:0:b0:563:8d32:abdc with SMTP id u19-20020aa78493000000b005638d32abdcmr16489071pfn.47.1668958944830; Sun, 20 Nov 2022 07:42:24 -0800 (PST) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id r12-20020a635d0c000000b0043b565cb57csm1145104pgb.73.2022.11.20.07.42.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 20 Nov 2022 07:42:24 -0800 (PST) Message-ID: Date: Sun, 20 Nov 2022 08:42:22 -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> From: Jeff Law In-Reply-To: <20221104124800.910588-1-siddhesh@gotplt.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,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/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... jeff