From patchwork Mon Aug 9 20:25:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1515192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=j9B63Ak3; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gk75c5QzHz9s5R for ; Tue, 10 Aug 2021 06:31:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 203B73939C31 for ; Mon, 9 Aug 2021 20:31:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 203B73939C31 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1628541074; bh=1+Uh4gCrTjGFrgWsYtxvoAel5DiHjh3FJuEdCpViAJM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=j9B63Ak3NoZwf1QQB7zA8H7uMyUAF7z8wcJYmrvoPxNnZmUpulCaiWNnG8sHf8zAm F+IQofaCljtWlyXu6PkXApkFYe3Z5UqsadG0udiNGjMbEWrFyJEDRRKuf0LgZ68aXd 0vxN6nFtmr8leZupLf/3N8CYPDZYXRMZ7gcWMUhE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id B443C3938C0C for ; Mon, 9 Aug 2021 20:25:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B443C3938C0C Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-46-4YEJ_h8aPAuW2xzgokR2ig-1; Mon, 09 Aug 2021 16:25:21 -0400 X-MC-Unique: 4YEJ_h8aPAuW2xzgokR2ig-1 Received: by mail-qv1-f69.google.com with SMTP id b8-20020a0562141148b02902f1474ce8b7so13505384qvt.20 for ; Mon, 09 Aug 2021 13:25:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=1+Uh4gCrTjGFrgWsYtxvoAel5DiHjh3FJuEdCpViAJM=; b=Te0KLaI74F+F9tk2Bubn5hmGMkiv0yE3DN5uqiHSZA3lGCpielOTLNYabf8qR6OMNh l0gfru5vja02EiEfVbFWFhhphiWkd5Zbn8pU9qOW8q8CRPF19Uw4Cvfq+wbranaR8bQn YNGihrrTkTKhvxJGQ4durR6S81UEMgnhuSUbFct0iqod3/xJXfL79Mm6vxMSozu1N002 xuviATmfjxVshTQMFXM+n1QcuWIE4cotMxIRSu6tXslSC8XJzx7R0O9vmftjJfzPl0tA pMGZyG/zioV2Ma60b99E/oV2z3EycHQiZ/c9mmRYXSLDHWDZX7yZpDBc6h0pykIaShWz 8vtg== X-Gm-Message-State: AOAM531cH8sgBcxGwykJjXRLHCbjMXtVNUyKqRpyf9YRCkwWiP8JXV2R /ucxVHA4HbLOp4PCHnM0pzngpEyR+aI4BWhPMHHyfKJxMAEuzazTyArPI/H6sMlwxYr23wyHMAy UudLUcbIpbaSup4Da9g== X-Received: by 2002:ac8:44c2:: with SMTP id b2mr21360560qto.216.1628540721475; Mon, 09 Aug 2021 13:25:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlmUP5Xgby7Nn2aWV0mfPXwapablzD87HrBjZz0bcLdnwYW9NGqooOxcq6deE0lmT8tB1rHg== X-Received: by 2002:ac8:44c2:: with SMTP id b2mr21360547qto.216.1628540721292; Mon, 09 Aug 2021 13:25:21 -0700 (PDT) Received: from ?IPv6:2607:fea8:a241:4600::74d4? ([2607:fea8:a241:4600::74d4]) by smtp.gmail.com with ESMTPSA id j2sm7186428qtn.46.2021.08.09.13.25.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Aug 2021 13:25:20 -0700 (PDT) To: gcc-patches Subject: [COMMITTED] PR tree-optimization/101741 - Ensure toupper and tolower follow the expected pattern. Message-ID: <49b8d18d-98fe-84de-6a00-34d08fc2cfc7@redhat.com> Date: Mon, 9 Aug 2021 16:25:19 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The user has overridden the function name "toupper" . Its marked as a builtin function, presumably because it matches the name.  In range folding, we were assuming the LHS and the parameter were compatible types...  but they are not in this case.. I don't know if we should be marking such a thing as a builtin function, but regardless.. we shouldn't be trapping.  If the type of the argument is not compatible with  the LHS, then we'll simply assume nothing about the function. Bootstraps with no regression on x86_64-pc-linux-gnu.  pushed. Andrew commit c86c95edd165d674614516cda0b1fcb6616c1096 Author: Andrew MacLeod Date: Mon Aug 9 15:53:42 2021 -0400 Ensure toupper and tolower follow the expected pattern. If the parameter is not compatible with the LHS, assume this is not really a builtin function to avoid a trap. gcc/ PR tree-optimization/101741 * gimple-range-fold.cc (fold_using_range::range_of_builtin_call): Check type of parameter for toupper/tolower. gcc/testsuite/ * gcc.dg/pr101741.c: New. diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 410bc4ddca4..d3e3e14ff64 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -894,6 +894,9 @@ fold_using_range::range_of_builtin_call (irange &r, gcall *call, case CFN_BUILT_IN_TOUPPER: { arg = gimple_call_arg (call, 0); + // If the argument isn't compatible with the LHS, do nothing. + if (!range_compatible_p (type, TREE_TYPE (arg))) + return false; if (!src.get_operand (r, arg)) return false; @@ -913,6 +916,9 @@ fold_using_range::range_of_builtin_call (irange &r, gcall *call, case CFN_BUILT_IN_TOLOWER: { arg = gimple_call_arg (call, 0); + // If the argument isn't compatible with the LHS, do nothing. + if (!range_compatible_p (type, TREE_TYPE (arg))) + return false; if (!src.get_operand (r, arg)) return false; diff --git a/gcc/testsuite/gcc.dg/pr101741.c b/gcc/testsuite/gcc.dg/pr101741.c new file mode 100644 index 00000000000..6587dca77d5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr101741.c @@ -0,0 +1,16 @@ +/* PR tree-optimization/101741 */ +/* { dg-do compile } */ +/* { dg-options "-O2 " } */ + +int +foo (void); + +unsigned int +toupper (int c) +{ + c = foo (); + while (c) + c = toupper (c); + + return c; +}