From patchwork Fri Jun 4 21:41:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488128 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=2620:52:3:1:0:246e:9693:128c; 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=bGa9mlI/; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4FxbqS1Jfsz9sPf for ; Sat, 5 Jun 2021 07:43:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1AC7D39A1408 for ; Fri, 4 Jun 2021 21:43:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AC7D39A1408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843010; bh=ELaWmgMpOEFEvWMO22mrP1PDuNmQIsgenNDi2jmGH70=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bGa9mlI/gTX7b8X8N5+XNeIpsys5KUJ/v3ZAYAWmcpYAp+SPQekrGwv4X/bjjBrcs 4LANEv3OTUPC2pIZIdYhAbuZa/QeORL+d42tpuhmHDv9tjU3OZVIwbUWz/Fi0Q5YZS 6Co61zEo57KVxdbBKoNWlfwVh8oO6+5H0NN6Wk1k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by sourceware.org (Postfix) with ESMTPS id BEF193892466 for ; Fri, 4 Jun 2021 21:41:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BEF193892466 Received: by mail-oo1-xc35.google.com with SMTP id 67-20020a4a01460000b0290245b81f6261so2572373oor.6 for ; Fri, 04 Jun 2021 14:41:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=ELaWmgMpOEFEvWMO22mrP1PDuNmQIsgenNDi2jmGH70=; b=ZITG7TB7JkdDe6JmyTvBnyTYZC6XcALfMi7buro7pgEHaN+B9Xwz7AWZkXcqHk+kc/ DSi9tkQ8mLY50zaidgYsPIgHpJc3wEfKk/JQHADFM2eGryEm5UNYfXIgxbTnjimbJmbU BQMVDxB/Nb2yTEoLzvbhzE5q7ncIvIbKkU5Y0xM8mEaU8eqoWA9uqKHm7p50Z5dHN1rZ I2h1DnYj1IloaHe1uTtA4fiorp3q3ATqLAZTl833hbPXAAmWvWBVP8EHgbXhlLs656XN g3UflMOYjxaTsHf81frnHvN5kc0t2npzoXERu3DS8bmrodI0/251FHby3R3Dynx/u/rJ owhg== X-Gm-Message-State: AOAM531Pshicr7dDCsjmLUZIU6BtcsskgTF/yDTPF4HqwSENxu6oOOxv 31MVB14QkoXfZoCDPYYYjgo= X-Google-Smtp-Source: ABdhPJx65ZOrQT/PLbRflWKuRjAzYptQBFXzNgzPPKnIHLj2oKyksiWNQG7nxM8q5FVU3ME36E51zA== X-Received: by 2002:a4a:d4c7:: with SMTP id r7mr5283392oos.85.1622842884173; Fri, 04 Jun 2021 14:41:24 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id x9sm730416oto.79.2021.06.04.14.41.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:41:23 -0700 (PDT) Subject: [PATCH 1/13] v2 [PATCH 1/13] Add support for per-location warning groups (PR 74765) To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: Date: Fri, 4 Jun 2021 15:41:22 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch introduces the suppress_warning(), warning_suppressed(), and copy_no_warning() APIs without making use of them in the rest of GCC. They are in three files: diagnostic-spec.{h,c}: Location-centric overloads. warning-control.cc: Tree- and gimple*-centric overloads. The location-centric overloads are suitable to use from the diagnostic subsystem. The rest can be used from the front ends and the middle end. Add support for per-location warning groups. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Add diagnostic-spec.o. * gengtype.c (open_base_files): Add diagnostic-spec.h. * diagnostic-spec.c: New file. * diagnostic-spec.h: New file. * warning-control.cc: New file. diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 4cb2966157e..35eef812ac8 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1696,6 +1696,7 @@ OBJS = \ vmsdbgout.o \ vr-values.o \ vtable-verify.o \ + warning-control.o \ web.o \ wide-int.o \ wide-int-print.o \ @@ -1707,8 +1708,8 @@ OBJS = \ # Objects in libcommon.a, potentially used by all host binaries and with # no target dependencies. -OBJS-libcommon = diagnostic.o diagnostic-color.o diagnostic-show-locus.o \ - diagnostic-format-json.o json.o \ +OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \ + diagnostic-show-locus.o diagnostic-format-json.o json.o \ edit-context.o \ pretty-print.o intl.o \ sbitmap.o \ @@ -2648,6 +2649,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/ipa-modref.h $(srcdir)/ipa-modref.c \ $(srcdir)/ipa-modref-tree.h \ $(srcdir)/signop.h \ + $(srcdir)/diagnostic-spec.h $(srcdir)/diagnostic-spec.c \ $(srcdir)/dwarf2out.h \ $(srcdir)/dwarf2asm.c \ $(srcdir)/dwarf2cfi.c \ diff --git a/gcc/diagnostic-spec.c b/gcc/diagnostic-spec.c new file mode 100644 index 00000000000..c5668831a9b --- /dev/null +++ b/gcc/diagnostic-spec.c @@ -0,0 +1,177 @@ +/* Functions to enable and disable individual warnings on an expression + and statement basis. + Copyright (C) 2021 Free Software Foundation, Inc. + Contributed by Martin Sebor + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3, or (at your option) any later + version. + + GCC is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + . */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "bitmap.h" +#include "tree.h" +#include "cgraph.h" +#include "hash-map.h" +#include "diagnostic-spec.h" +#include "pretty-print.h" +#include "options.h" + +/* Initialize *THIS from warning option OPT. */ + +nowarn_spec_t::nowarn_spec_t (opt_code opt) +{ + /* Create a very simple mapping based on testing and experience. + It should become more refined with time. */ + switch (opt) + { + case no_warning: + bits = 0; + break; + + case all_warnings: + bits = -1; + break; + + /* Flow-sensitive warnings about pointer problems issued by both + front ends and the middle end. */ + case OPT_Waddress: + case OPT_Wnonnull: + bits = NW_NONNULL; + break; + + /* Flow-sensitive warnings about arithmetic overflow issued by both + front ends and the middle end. */ + case OPT_Woverflow: + case OPT_Wshift_count_negative: + case OPT_Wshift_count_overflow: + case OPT_Wstrict_overflow: + bits = NW_VFLOW; + break; + + /* Lexical warnings issued by front ends. */ + case OPT_Wabi: + case OPT_Wlogical_op: + case OPT_Wparentheses: + case OPT_Wreturn_type: + case OPT_Wsizeof_array_div: + case OPT_Wstrict_aliasing: + case OPT_Wunused: + case OPT_Wunused_function: + case OPT_Wunused_but_set_variable: + case OPT_Wunused_variable: + case OPT_Wunused_but_set_parameter: + bits = NW_LEXICAL; + break; + + /* Access warning group. */ + case OPT_Warray_bounds: + case OPT_Warray_bounds_: + case OPT_Wformat_overflow_: + case OPT_Wformat_truncation_: + case OPT_Wrestrict: + case OPT_Wstrict_aliasing_: + case OPT_Wstringop_overflow_: + case OPT_Wstringop_overread: + case OPT_Wstringop_truncation: + bits = NW_ACCESS; + break; + + /* Initialization warning group. */ + case OPT_Winit_self: + case OPT_Wuninitialized: + case OPT_Wmaybe_uninitialized: + bits = NW_UNINIT; + break; + + default: + /* A catchall group for everything else. */ + bits = NW_OTHER; + } +} + +/* Map from location to its no-warning disposition. */ + +GTY(()) xint_hash_map_t *nowarn_map; + +/* Return the no-warning disposition for location LOC and option OPT + or for all/any otions by default. */ + +bool +warning_suppressed_at (location_t loc, opt_code opt /* = all_warnings */) +{ + if (!nowarn_map) + return false; + + if (const nowarn_spec_t* const pspec = nowarn_map->get (loc)) + { + const nowarn_spec_t optspec (opt); + return *pspec & optspec; + } + + return false; +} + +/* Set the warning disposition for location LOC and option OPT when to + disabled if DIS is true and to enabled otherwise. Return true if + LOC has any warnings disabled at the end of processing. */ + +bool +suppress_warning_at (location_t loc, opt_code opt /* = all_warnings */, + bool dis /* = true */) +{ + const nowarn_spec_t optspec (dis ? opt : opt_code ()); + + if (nowarn_spec_t *pspec = nowarn_map ? nowarn_map->get (loc) : NULL) + { + if (dis) + { + *pspec |= optspec; + return true; + } + + *pspec &= optspec; + if (*pspec) + return true; + + nowarn_map->remove (loc); + return false; + } + + if (!dis || opt == no_warning) + return false; + + if (!nowarn_map) + nowarn_map = xint_hash_map_t::create_ggc (32); + + nowarn_map->put (loc, optspec); + return true; +} + +/* Copy the no-warning disposition from one location to another. */ + +void +copy_warning (location_t to, location_t from) +{ + if (!nowarn_map) + return; + + if (nowarn_spec_t *pspec = nowarn_map->get (from)) + nowarn_map->put (to, *pspec); + else + nowarn_map->remove (to); +} diff --git a/gcc/diagnostic-spec.h b/gcc/diagnostic-spec.h new file mode 100644 index 00000000000..62d9270ca6d --- /dev/null +++ b/gcc/diagnostic-spec.h @@ -0,0 +1,140 @@ +/* Language-independent APIs to enable/disable per-location warnings. + + Copyright (C) 2021 Free Software Foundation, Inc. + Contributed by Martin Sebor + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3, or (at your option) any later + version. + + GCC is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + . */ + +#ifndef DIAGNOSTIC_SPEC_H_INCLUDED +#define DIAGNOSTIC_SPEC_H_INCLUDED + +#include "hash-map.h" + +/* A "bitset" of warning groups. */ + +struct nowarn_spec_t +{ + enum + { + /* Middle end warnings about invalid accesses. */ + NW_ACCESS = 1 << 0, + /* Front end/lexical warnings. */ + NW_LEXICAL = 1 << 1, + /* Warnings about null pointers. */ + NW_NONNULL = 1 << 2, + /* Warnings about uninitialized reads. */ + NW_UNINIT = 1 << 3, + /* Warnings about arithmetic overflow. */ + NW_VFLOW = 1 << 4, + /* All other unclassified warnings. */ + NW_OTHER = 1 << 5, + /* All groups of warnings. */ + NW_ALL = (NW_ACCESS | NW_LEXICAL | NW_NONNULL + | NW_UNINIT | NW_VFLOW | NW_OTHER) + }; + + nowarn_spec_t (): bits () { } + + nowarn_spec_t (opt_code); + + /* Return the raw bitset. */ + operator unsigned() const + { + return bits; + } + + /* Return true if the bitset is clear. */ + bool operator!() const + { + return !bits; + } + + /* Return the inverse of the bitset. */ + nowarn_spec_t operator~() const + { + nowarn_spec_t res (*this); + res.bits &= ~NW_ALL; + return res; + } + + /* Set *THIS to the bitwise OR of *THIS and RHS. */ + nowarn_spec_t& operator|= (const nowarn_spec_t &rhs) + { + bits |= rhs.bits; + return *this; + } + + /* Set *THIS to the bitwise AND of *THIS and RHS. */ + nowarn_spec_t& operator&= (const nowarn_spec_t &rhs) + { + bits &= rhs.bits; + return *this; + } + + /* Set *THIS to the bitwise exclusive OR of *THIS and RHS. */ + nowarn_spec_t& operator^= (const nowarn_spec_t &rhs) + { + bits ^= rhs.bits; + return *this; + } + +private: + /* Bitset of warning groups. */ + unsigned bits; +}; + +/* Return the bitwise OR of LHS and RHS. */ + +inline nowarn_spec_t +operator| (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs) +{ + return nowarn_spec_t (lhs) |= rhs; +} + +/* Return the bitwise AND of LHS and RHS. */ + +inline nowarn_spec_t +operator& (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs) +{ + return nowarn_spec_t (lhs) &= rhs; +} + +/* Return true if LHS is equal RHS. */ + +inline bool +operator== (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs) +{ + return static_cast(lhs) == static_cast(rhs); +} + +/* Return true if LHS is not equal RHS. */ + +inline bool +operator!= (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs) +{ + return !(lhs == rhs); +} + +typedef location_t key_type_t; +typedef int_hash xint_hash_t; +typedef hash_map xint_hash_map_t; + +/* A mapping from the location of an expression to the warning spec + set for it. */ +extern GTY(()) xint_hash_map_t *nowarn_map; + +#endif // DIAGNOSTIC_SPEC_H_INCLUDED diff --git a/gcc/gengtype.c b/gcc/gengtype.c index b94e2f126ec..c1fa6d35c87 100644 --- a/gcc/gengtype.c +++ b/gcc/gengtype.c @@ -1727,7 +1727,7 @@ open_base_files (void) "target-globals.h", "ipa-ref.h", "cgraph.h", "symbol-summary.h", "ipa-prop.h", "ipa-fnsummary.h", "dwarf2out.h", "omp-general.h", "omp-offload.h", "ipa-modref-tree.h", "ipa-modref.h", "symtab-thunks.h", - "symtab-clones.h", + "symtab-clones.h", "diagnostic-spec.h", NULL }; const char *const *ifp; diff --git a/gcc/warning-control.cc b/gcc/warning-control.cc new file mode 100644 index 00000000000..21161caae3a --- /dev/null +++ b/gcc/warning-control.cc @@ -0,0 +1,238 @@ +/* Functions to enable and disable individual warnings on an expression + and statement basis. + + Copyright (C) 2021 Free Software Foundation, Inc. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3, or (at your option) any later + version. + + GCC is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + . */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "bitmap.h" +#include "tree.h" +#include "gimple.h" +#include "cgraph.h" +#include "hash-map.h" +#include "diagnostic-spec.h" + +/* Return the no-warning bit for EXPR. */ + +static inline bool +get_no_warning_bit (const_tree expr) +{ + return expr->base.nowarning_flag; +} + +/* Return the no-warning bit for statement STMT. */ + +static inline bool +get_no_warning_bit (const gimple *stmt) +{ + return stmt->no_warning; +} + +/* Set the no-warning bit for EXPR to VALUE. */ + +static inline void +set_no_warning_bit (tree expr, bool value) +{ + expr->base.nowarning_flag = value; +} + +/* Set the no-warning bit for statement STMT to VALUE. */ + +static inline void +set_no_warning_bit (gimple *stmt, bool value) +{ + stmt->no_warning = value; +} + +/* Return EXPR location or zero. */ + +static inline key_type_t +convert_to_key (const_tree expr) +{ + if (DECL_P (expr)) + return DECL_SOURCE_LOCATION (expr); + if (EXPR_P (expr)) + return EXPR_LOCATION (expr); + return 0; +} + +/* Return STMT location (may be zero). */ + +static inline key_type_t +convert_to_key (const gimple *stmt) +{ + return gimple_location (stmt); +} + +/* Return the no-warning bitmap for decl/expression EXPR. */ + +static nowarn_spec_t * +get_nowarn_spec (const_tree expr) +{ + const key_type_t key = convert_to_key (expr); + + if (!get_no_warning_bit (expr) || !key) + return NULL; + + return nowarn_map ? nowarn_map->get (key) : NULL; +} + +/* Return the no-warning bitmap for stateemt STMT. */ + +static nowarn_spec_t * +get_nowarn_spec (const gimple *stmt) +{ + const key_type_t key = convert_to_key (stmt); + + if (!get_no_warning_bit (stmt)) + return NULL; + + return nowarn_map ? nowarn_map->get (key) : NULL; +} + +/* Return true if warning OPT is suppressed for decl/expression EXPR. + By default tests the disposition for any warning. */ + +bool +warning_suppressed_p (const_tree expr, opt_code opt /* = all_warnings */) +{ + const nowarn_spec_t *spec = get_nowarn_spec (expr); + + if (!spec) + return get_no_warning_bit (expr); + + const nowarn_spec_t optspec (opt); + bool dis = *spec & optspec; + gcc_assert (get_no_warning_bit (expr) || !dis); + return dis; +} + +/* Return true if warning OPT is suppressed for statement STMT. + By default tests the disposition for any warning. */ + +bool +warning_suppressed_p (const gimple *stmt, opt_code opt /* = all_warnings */) +{ + const nowarn_spec_t *spec = get_nowarn_spec (stmt); + + if (!spec) + /* Fall back on the single no-warning bit. */ + return get_no_warning_bit (stmt); + + const nowarn_spec_t optspec (opt); + bool dis = *spec & optspec; + gcc_assert (get_no_warning_bit (stmt) || !dis); + return dis; +} + +/* Enable, or by default disable, a warning for the expression. + The wildcard OPT of -1 controls all warnings. */ + +void +suppress_warning (tree expr, opt_code opt /* = all_warnings */, + bool dis /* = true */) +{ + if (opt == no_warning) + return; + + const key_type_t key = convert_to_key (expr); + + dis = suppress_warning_at (key, opt, dis) || dis; + set_no_warning_bit (expr, dis); +} + +/* Enable, or by default disable, a warning for the statement STMT. + The wildcard OPT of -1 controls all warnings. */ + +void +suppress_warning (gimple *stmt, opt_code opt /* = all_warnings */, + bool dis /* = true */) +{ + if (opt == no_warning) + return; + + const key_type_t key = convert_to_key (stmt); + + dis = suppress_warning_at (key, opt, dis) || dis; + set_no_warning_bit (stmt, dis); +} + +/* Copy the warning disposition mapping between an expression and/or + a statement. */ + +template +void copy_warning (ToType to, FromType from) +{ + const key_type_t to_key = convert_to_key (to); + + if (nowarn_spec_t *from_map = get_nowarn_spec (from)) + { + /* If there's an entry in the map the no-warning bit must be set. */ + gcc_assert (get_no_warning_bit (from)); + + if (!nowarn_map) + nowarn_map = xint_hash_map_t::create_ggc (32); + + nowarn_map->put (to_key, *from_map); + set_no_warning_bit (to, true); + } + else + { + if (nowarn_map) + nowarn_map->remove (to_key); + + /* The no-warning bit might be set even if there's no entry + in the map. */ + set_no_warning_bit (to, get_no_warning_bit (from)); + } +} + +/* Copy the warning disposition mapping from one expression to another. */ + +void +copy_warning (tree to, const_tree from) +{ + copy_warning(to, from); +} + +/* Copy the warning disposition mapping from a statement to an expression. */ + +void +copy_warning (tree to, const gimple *from) +{ + copy_warning(to, from); +} + +/* Copy the warning disposition mapping from an expression to a statement. */ + +void +copy_warning (gimple *to, const_tree from) +{ + copy_warning(to, from); +} + +/* Copy the warning disposition mapping from one statement to another. */ + +void +copy_warning (gimple *to, const gimple *from) +{ + copy_warning(to, from); +} From patchwork Fri Jun 4 21:41:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488126 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=2620:52:3:1:0:246e:9693:128c; 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=CR4/2/IH; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Fxbp96nB5z9sT6 for ; Sat, 5 Jun 2021 07:42:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D1F1139A1428 for ; Fri, 4 Jun 2021 21:42:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1F1139A1428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622842941; bh=ca0llCTj03k9aUe10lCDPgRQSYBm/a0vYWUXWwEWm8w=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=CR4/2/IH/36M/d2hSvy5Na1HsIIKXivfrI/Xiflq1FFmXgbQgwoYzjBFnhT3K8e9G e4bzM1Le2ISP8MFjZvuZSSjdbdOsrqzc2ohLvZtiDDra8ed5cPsoSoFW9k2ki4fWIC AOU1vAE3LPJF2mqbT8Ls7G9z9CJwLWjOYgI1TuR8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id E8E4639A1417 for ; Fri, 4 Jun 2021 21:41:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E8E4639A1417 Received: by mail-oi1-x233.google.com with SMTP id r17so907098oic.7 for ; Fri, 04 Jun 2021 14:41:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=ca0llCTj03k9aUe10lCDPgRQSYBm/a0vYWUXWwEWm8w=; b=Oetz43h+sRKVOX2e2iDT4RQ7E70MqxGUWlh//kqrNGB4+xiodbM593fU8sjUstOr2C jG5PX0un77RKj7l2ru4OLkFSbWx1hStPkfHtlWxiackh52P6uVMQQkKTygcuY1qxUvnF RVLfwE28nYRRO7OiboXg8werngaa0ufAi8hFcxAIqfTjpwieeiKN5a8Kgv+liIcH7U4Z 0MczRbI2Q6jFLRIJR21pAbuWSXniacvhxy/s455PtW0tksZXRNz/JTYdH2iDdsYLVjWU KdlFt19sHunmjy6VHnclqGmUGYg5lh34x9Jcvh2WY675o6zqiLQRGkrP9JFdfhK2uno9 ojZQ== X-Gm-Message-State: AOAM531SF13IZ/wyWmQF3mbklRpp0lNClh1pUI39lyr1lmHRNloijo9n xrUE4r3XhnUMaHXEoQh6DSgJgHRiVAo= X-Google-Smtp-Source: ABdhPJyGl9IQFghoDRITAfuxkwR0fdQsYS6jjJ/xbZvRRD1NBAe8KabKM+LJvSh2i/n4Y5Ubrvu8pA== X-Received: by 2002:aca:ead4:: with SMTP id i203mr12450725oih.74.1622842889848; Fri, 04 Jun 2021 14:41:29 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id r5sm758250otp.45.2021.06.04.14.41.29 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:41:29 -0700 (PDT) Subject: [PATCH 2/13] v2 Use new per-location warning APIs in Ada. To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: <061e2fba-9222-2369-a5ef-2dd11c4a2fc0@gmail.com> Date: Fri, 4 Jun 2021 15:41:28 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch replaces the uses of TREE_NO_WARNING in the Ada front end with the new suppress_warning(), warning_suppressed_p(), and copy_warning() APIs. Add support for per-location warning groups. gcc/ada/ChangeLog: * gcc-interface/trans.c (Handled_Sequence_Of_Statements_to_gnu): Replace TREE_NO_WARNING with suppress_warning. (gnat_gimplify_expr): Same. * gcc-interface/utils.c (gnat_pushdecl): Same. diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index ee014a35cc2..949b7733766 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -5363,7 +5363,7 @@ Handled_Sequence_Of_Statements_to_gnu (Node_Id gnat_node) because of the unstructured form of EH used by fe_sjlj_eh, there might be forward edges going to __builtin_setjmp receivers on which it is uninitialized, although they will never be actually taken. */ - TREE_NO_WARNING (gnu_jmpsave_decl) = 1; + suppress_warning (gnu_jmpsave_decl, OPT_Wuninitialized); gnu_jmpbuf_decl = create_var_decl (get_identifier ("JMP_BUF"), NULL_TREE, jmpbuf_type, @@ -8805,7 +8805,7 @@ gnat_gimplify_expr (tree *expr_p, gimple_seq *pre_p, else { *expr_p = create_tmp_var (type, NULL); - TREE_NO_WARNING (*expr_p) = 1; + suppress_warning (*expr_p); } gimplify_and_add (TREE_OPERAND (expr, 0), pre_p); diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 1786fbf8186..982274c6d77 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -836,7 +836,8 @@ gnat_pushdecl (tree decl, Node_Id gnat_node) if (!deferred_decl_context) DECL_CONTEXT (decl) = context; - TREE_NO_WARNING (decl) = (No (gnat_node) || Warnings_Off (gnat_node)); + suppress_warning (decl, all_warnings, + No (gnat_node) || Warnings_Off (gnat_node)); /* Set the location of DECL and emit a declaration for it. */ if (Present (gnat_node) && !renaming_from_instantiation_p (gnat_node)) From patchwork Fri Jun 4 21:41:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488129 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=2620:52:3:1:0:246e:9693:128c; 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=d3CcqEX2; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Fxbrc0LQfz9sPf for ; Sat, 5 Jun 2021 07:44:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F17CA39A143E for ; Fri, 4 Jun 2021 21:44:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F17CA39A143E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843070; bh=d8w9gT8RfFXCmkOtLtxQaw6B4oWhCfrFZS+GLXhn2f8=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=d3CcqEX2rGQ/WxF++Cv3lI1pBLSmvF4vfM+FivYXtFpNVx72/XJqiXhTxZkPvZU2R 7PLHpCW4V8TU4i83pdYukm1/ppSAaBc6xDGVJvB6JKv7o4SyZlGuPGTrZ5Yc/jHjNq dIEh6oWuliE5dicxTn7F7p3jRqq2xPsljKgfOjeQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 5005039A141B for ; Fri, 4 Jun 2021 21:41:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5005039A141B Received: by mail-ot1-x333.google.com with SMTP id 66-20020a9d02c80000b02903615edf7c1aso10422012otl.13 for ; Fri, 04 Jun 2021 14:41:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=d8w9gT8RfFXCmkOtLtxQaw6B4oWhCfrFZS+GLXhn2f8=; b=kiQ6pQbfV2mAWrt5odMOs0elFT1Jv4lerN1kHj3eXiuQSJX110SuEDSs8IZzQNVOcx Pk2RqwqWBqxRQV1u788+KeX/WrMYum5d4hmwT2R14a3ZwjJUGAN2526Htu7RP93eN2Os 67XTX/QKWgf/CdLvesCgWv0VPfINwFocQlGFz4NIi8mz37MnYah4eJysMaKvK3UBaaus zjlzcCd+LhFAaaGGTkNulgIDxsKMwbaQZRI0A67dh6BUdBOlqw3+0b/jAShz5v9Brr9z 7IOmpmd+4q81UysRXXUjWKD0XJVLszNndLpa+wWpCFAyL0YCFfMe9YNCBrJDex+ApwWD BXJg== X-Gm-Message-State: AOAM532yLPWH9QD8ALhRlHShifLqU0vRM/Z00QoqMR5bogjpXz9DB9aO diEE6heqYOrAnskJVZ37Uwc+NXG9+HQ= X-Google-Smtp-Source: ABdhPJzrDvfcVkhZdYJXl0d8utmoBDs88gsHDCa/aPGZuGSvsCijIMg9Pt4Xz/bXOFzTKp0b3ni4kg== X-Received: by 2002:a9d:4115:: with SMTP id o21mr5375819ote.52.1622842909654; Fri, 04 Jun 2021 14:41:49 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id y7sm712831oix.36.2021.06.04.14.41.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:41:49 -0700 (PDT) Subject: [PATCH 3/13] v2 Use new per-location warning APIs in C front end To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: <8a7235a2-93ed-a9ed-bd22-1353ad56f009@gmail.com> Date: Fri, 4 Jun 2021 15:41:48 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch replaces the uses of TREE_NO_WARNING in the C front end with the new suppress_warning(), warning_suppressed_p(), and copy_warning() APIs. Add support for per-location warning groups. gcc/c/ChangeLog: * c-decl.c (pop_scope): Replace direct uses of TREE_NO_WARNING with warning_suppressed_p, suppress_warning, and copy_no_warning. (diagnose_mismatched_decls): Same. (duplicate_decls): Same. (grokdeclarator): Same. (finish_function): Same. (c_write_global_declarations_1): Same. * c-fold.c (c_fully_fold_internal): Same. * c-parser.c (c_parser_expr_no_commas): Same. (c_parser_postfix_expression): Same. * c-typeck.c (array_to_pointer_conversion): Same. (function_to_pointer_conversion): Same. (default_function_array_conversion): Same. (convert_lvalue_to_rvalue): Same. (default_conversion): Same. (build_indirect_ref): Same. (build_function_call_vec): Same. (build_atomic_assign): Same. (build_unary_op): Same. (c_finish_return): Same. (emit_side_effect_warnings): Same. (c_finish_stmt_expr): Same. (c_omp_clause_copy_ctor): Same. diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 28f851b9d0b..adfdd56d49d 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -1295,7 +1295,7 @@ pop_scope (void) case VAR_DECL: /* Warnings for unused variables. */ if ((!TREE_USED (p) || !DECL_READ_P (p)) - && !TREE_NO_WARNING (p) + && !warning_suppressed_p (p, OPT_Wunused_but_set_variable) && !DECL_IN_SYSTEM_HEADER (p) && DECL_NAME (p) && !DECL_ARTIFICIAL (p) @@ -2159,8 +2159,8 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, if (DECL_IN_SYSTEM_HEADER (newdecl) || DECL_IN_SYSTEM_HEADER (olddecl) - || TREE_NO_WARNING (newdecl) - || TREE_NO_WARNING (olddecl)) + || warning_suppressed_p (newdecl, OPT_Wpedantic) + || warning_suppressed_p (olddecl, OPT_Wpedantic)) return true; /* Allow OLDDECL to continue in use. */ if (variably_modified_type_p (newtype, NULL)) @@ -2953,7 +2953,7 @@ duplicate_decls (tree newdecl, tree olddecl) if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype)) { /* Avoid `unused variable' and other warnings for OLDDECL. */ - TREE_NO_WARNING (olddecl) = 1; + suppress_warning (olddecl, OPT_Wunused); return false; } @@ -7540,10 +7540,7 @@ grokdeclarator (const struct c_declarator *declarator, FIELD_DECL, declarator->u.id.id, type); DECL_NONADDRESSABLE_P (decl) = bitfield; if (bitfield && !declarator->u.id.id) - { - TREE_NO_WARNING (decl) = 1; - DECL_PADDING_P (decl) = 1; - } + DECL_PADDING_P (decl) = 1; if (size_varies) C_DECL_VARIABLE_SIZE (decl) = 1; @@ -10232,7 +10229,7 @@ finish_function (location_t end_loc) && targetm.warn_func_return (fndecl) && warning (OPT_Wreturn_type, "no return statement in function returning non-void")) - TREE_NO_WARNING (fndecl) = 1; + suppress_warning (fndecl, OPT_Wreturn_type); /* Complain about parameters that are only set, but never otherwise used. */ if (warn_unused_but_set_parameter) @@ -10247,7 +10244,7 @@ finish_function (location_t end_loc) && !DECL_READ_P (decl) && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl) - && !TREE_NO_WARNING (decl)) + && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter)) warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_but_set_parameter, "parameter %qD set but not used", decl); @@ -12114,19 +12111,20 @@ c_write_global_declarations_1 (tree globals) { if (C_DECL_USED (decl)) { + /* TODO: Add OPT_Wundefined-inline. */ if (pedwarn (input_location, 0, "%q+F used but never defined", decl)) - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl /* OPT_Wundefined-inline. */); } /* For -Wunused-function warn about unused static prototypes. */ else if (warn_unused_function && ! DECL_ARTIFICIAL (decl) - && ! TREE_NO_WARNING (decl)) + && ! warning_suppressed_p (decl, OPT_Wunused_function)) { if (warning (OPT_Wunused_function, "%q+F declared % but never defined", decl)) - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl, OPT_Wunused_function); } } diff --git a/gcc/c/c-fold.c b/gcc/c/c-fold.c index 68c74cc1eb2..0ebcb469d28 100644 --- a/gcc/c/c-fold.c +++ b/gcc/c/c-fold.c @@ -154,7 +154,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands, tree orig_op0, orig_op1, orig_op2; bool op0_const = true, op1_const = true, op2_const = true; bool op0_const_self = true, op1_const_self = true, op2_const_self = true; - bool nowarning = TREE_NO_WARNING (expr); + bool nowarning = warning_suppressed_p (expr, OPT_Woverflow); bool unused_p; bool op0_lval = false; source_range old_range; @@ -670,13 +670,13 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands, out: /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks have been done by this point, so remove them again. */ - nowarning |= TREE_NO_WARNING (ret); + nowarning |= warning_suppressed_p (ret, OPT_Woverflow); STRIP_TYPE_NOPS (ret); - if (nowarning && !TREE_NO_WARNING (ret)) + if (nowarning && !warning_suppressed_p (ret, OPT_Woverflow)) { if (!CAN_HAVE_LOCATION_P (ret)) ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret); - TREE_NO_WARNING (ret) = 1; + suppress_warning (ret, OPT_Woverflow); } if (ret != expr) { diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index c491b128da5..a188870bfb8 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -7558,7 +7558,7 @@ c_parser_expr_no_commas (c_parser *parser, struct c_expr *after, ret.original_code = MODIFY_EXPR; else { - TREE_NO_WARNING (ret.value) = 1; + suppress_warning (ret.value, OPT_Wparentheses); ret.original_code = ERROR_MARK; } ret.original_type = NULL; @@ -9085,7 +9085,7 @@ c_parser_postfix_expression (c_parser *parser) c_parser_consume_token (parser); expr = c_parser_expression (parser); if (TREE_CODE (expr.value) == MODIFY_EXPR) - TREE_NO_WARNING (expr.value) = 1; + suppress_warning (expr.value, OPT_Wparentheses); if (expr.original_code != C_MAYBE_CONST_EXPR && expr.original_code != SIZEOF_EXPR) expr.original_code = ERROR_MARK; diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index be3f4f09f6e..4f4d368dfb3 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -1911,8 +1911,7 @@ array_to_pointer_conversion (location_t loc, tree exp) STRIP_TYPE_NOPS (exp); - if (TREE_NO_WARNING (orig_exp)) - TREE_NO_WARNING (exp) = 1; + copy_warning (exp, orig_exp); ptrtype = build_pointer_type (restype); @@ -1945,8 +1944,7 @@ function_to_pointer_conversion (location_t loc, tree exp) STRIP_TYPE_NOPS (exp); - if (TREE_NO_WARNING (orig_exp)) - TREE_NO_WARNING (exp) = 1; + copy_warning (exp, orig_exp); return build_unary_op (loc, ADDR_EXPR, exp, false); } @@ -2055,8 +2053,7 @@ default_function_array_conversion (location_t loc, struct c_expr exp) exp.value = TREE_OPERAND (exp.value, 0); } - if (TREE_NO_WARNING (orig_exp)) - TREE_NO_WARNING (exp.value) = 1; + copy_warning (exp.value, orig_exp); lvalue_array_p = !not_lvalue && lvalue_p (exp.value); if (!flag_isoc99 && !lvalue_array_p) @@ -2154,7 +2151,8 @@ convert_lvalue_to_rvalue (location_t loc, struct c_expr exp, tmp = create_tmp_var_raw (nonatomic_type); tmp_addr = build_unary_op (loc, ADDR_EXPR, tmp, false); TREE_ADDRESSABLE (tmp) = 1; - TREE_NO_WARNING (tmp) = 1; + /* Do not disable warnings for TMP even though it's artificial. + -Winvalid-memory-model depends on it. */ /* Issue __atomic_load (&expr, &tmp, SEQ_CST); */ fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD); @@ -2251,8 +2249,7 @@ default_conversion (tree exp) orig_exp = exp; STRIP_TYPE_NOPS (exp); - if (TREE_NO_WARNING (orig_exp)) - TREE_NO_WARNING (exp) = 1; + copy_warning (exp, orig_exp); if (code == VOID_TYPE) { @@ -2616,7 +2613,7 @@ build_indirect_ref (location_t loc, tree ptr, ref_operator errstring) if (warn_strict_aliasing > 2) if (strict_aliasing_warning (EXPR_LOCATION (pointer), type, TREE_OPERAND (pointer, 0))) - TREE_NO_WARNING (pointer) = 1; + suppress_warning (pointer, OPT_Wstrict_aliasing_); } if (TREE_CODE (pointer) == ADDR_EXPR @@ -3218,7 +3215,7 @@ build_function_call_vec (location_t loc, vec arg_loc, /* If -Wnonnull warning has been diagnosed, avoid diagnosing it again later. */ if (warned_p && TREE_CODE (result) == CALL_EXPR) - TREE_NO_WARNING (result) = 1; + suppress_warning (result, OPT_Wnonnull); /* In this improbable scenario, a nested function returns a VM type. Create a TARGET_EXPR so that the call always has a LHS, much as @@ -4167,7 +4164,7 @@ build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode, TYPE_UNQUALIFIED); val = create_tmp_var_raw (nonatomic_rhs_type); TREE_ADDRESSABLE (val) = 1; - TREE_NO_WARNING (val) = 1; + suppress_warning (val); rhs = build4 (TARGET_EXPR, nonatomic_rhs_type, val, rhs, NULL_TREE, NULL_TREE); TREE_SIDE_EFFECTS (rhs) = 1; @@ -4268,7 +4265,7 @@ build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode, newval = create_tmp_var_raw (nonatomic_lhs_type); TREE_ADDRESSABLE (newval) = 1; - TREE_NO_WARNING (newval) = 1; + suppress_warning (newval); rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, func_call, NULL_TREE, NULL_TREE); SET_EXPR_LOCATION (rhs, loc); @@ -4287,12 +4284,12 @@ cas_loop: old = create_tmp_var_raw (nonatomic_lhs_type); old_addr = build_unary_op (loc, ADDR_EXPR, old, false); TREE_ADDRESSABLE (old) = 1; - TREE_NO_WARNING (old) = 1; + suppress_warning (old); newval = create_tmp_var_raw (nonatomic_lhs_type); newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false); TREE_ADDRESSABLE (newval) = 1; - TREE_NO_WARNING (newval) = 1; + suppress_warning (newval); loop_decl = create_artificial_label (loc); loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl); @@ -4781,8 +4778,6 @@ build_unary_op (location_t location, enum tree_code code, tree xarg, else val = build2 (code, TREE_TYPE (arg), arg, inc); TREE_SIDE_EFFECTS (val) = 1; - if (TREE_CODE (val) != code) - TREE_NO_WARNING (val) = 1; ret = val; goto return_build_unary_op; } @@ -10941,7 +10936,8 @@ c_finish_return (location_t loc, tree retval, tree origtype) } ret_stmt = build_stmt (loc, RETURN_EXPR, retval); - TREE_NO_WARNING (ret_stmt) |= no_warning; + if (no_warning) + suppress_warning (ret_stmt, OPT_Wreturn_type); return add_stmt (ret_stmt); } @@ -11217,7 +11213,8 @@ emit_side_effect_warnings (location_t loc, tree expr) ; else if (!TREE_SIDE_EFFECTS (expr)) { - if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr)) + if (!VOID_TYPE_P (TREE_TYPE (expr)) + && !warning_suppressed_p (expr, OPT_Wunused_value)) warning_at (loc, OPT_Wunused_value, "statement with no effect"); } else if (TREE_CODE (expr) == COMPOUND_EXPR) @@ -11233,8 +11230,8 @@ emit_side_effect_warnings (location_t loc, tree expr) if (!TREE_SIDE_EFFECTS (r) && !VOID_TYPE_P (TREE_TYPE (r)) && !CONVERT_EXPR_P (r) - && !TREE_NO_WARNING (r) - && !TREE_NO_WARNING (expr)) + && !warning_suppressed_p (r, OPT_Wunused_value) + && !warning_suppressed_p (expr, OPT_Wunused_value)) warning_at (cloc, OPT_Wunused_value, "right-hand operand of comma expression has no effect"); } @@ -11403,7 +11400,7 @@ c_finish_stmt_expr (location_t loc, tree body) last = c_wrap_maybe_const (last, true); /* Do not warn if the return value of a statement expression is unused. */ - TREE_NO_WARNING (last) = 1; + suppress_warning (last, OPT_Wunused); return last; } @@ -15453,7 +15450,7 @@ c_omp_clause_copy_ctor (tree clause, tree dst, tree src) tree tmp = create_tmp_var (nonatomic_type); tree tmp_addr = build_fold_addr_expr (tmp); TREE_ADDRESSABLE (tmp) = 1; - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tree src_addr = build_fold_addr_expr (src); tree dst_addr = build_fold_addr_expr (dst); tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST); From patchwork Fri Jun 4 21:42:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488130 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=2620:52:3:1:0:246e:9693:128c; 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=fQRCDh4D; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Fxbsv6mVNz9sPf for ; Sat, 5 Jun 2021 07:45:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D560939A1819 for ; Fri, 4 Jun 2021 21:45:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D560939A1819 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843137; bh=MQHPeFAOQyvh9ceHMbOu51oBtDGgrMT3SiakJJiFgpo=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fQRCDh4DgxBzNFEqW+bZ+P3CXF0uY/aOV5J4ildtQn4A5pcleRNfD5QsFaCl0tL2K ZaWqiRqQ/GQHA94rEY29BYsdUqrWiZzWMJasXctSut3L3sxXgNCom6FOsKlrbiZXNv 3Ww3oO7Bp1VTs8dlfJ6E11EuFcUOnVCPuxL3ppjo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) by sourceware.org (Postfix) with ESMTPS id 8F75A389244C for ; Fri, 4 Jun 2021 21:42:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8F75A389244C Received: by mail-oo1-xc2d.google.com with SMTP id t6-20020a4ae9a60000b0290245a5133898so2580299ood.4 for ; Fri, 04 Jun 2021 14:42:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=MQHPeFAOQyvh9ceHMbOu51oBtDGgrMT3SiakJJiFgpo=; b=ZmraZxMxcBO4Ty1vDbZrXNNM75Nm7DozZkkUYlQlPBMnkceHJVmEmjETL6adngxpfB hO7R9TgTpJylkdchNU+DCPL0zGTtEnPWMjF7VWPBrGPmB53KfDXx4RGP6m3HdEC3LIhb B3m+qHAK0JC1M8sj+wDMvxSoI+YLqNLEiG6Y4Rj1svoTKXHuYVjd4zO/btXlKpxDSapi CV4docAz2ZYOtFqx9rh+30ozDTChVZ82taIwKBFUv6eKe7DD5PHoC5XSjEIZBB1IAlGC 3t65mTyVaKGQTqgKZibRQETQ14iur0ogILe5Y1w/B7oh1JkfX5nMm7lYr82lnfrdKZoH CK9g== X-Gm-Message-State: AOAM532oG9i/qGEJPQ8p0AGr8Qk74X7pjAxIVQuiXCyu1bEersd0Z77N sofkk9qu1/fVjcHIRCnWVmXYcz2vv8I= X-Google-Smtp-Source: ABdhPJx0Nzr9PBNJCUvrGG6C29YHzC6rFVZXc4pecah89ustpM+XMooC54uy4YLMIAKXQzLkEQh+zw== X-Received: by 2002:a4a:a704:: with SMTP id g4mr5263561oom.36.1622842929942; Fri, 04 Jun 2021 14:42:09 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id e26sm443768oth.60.2021.06.04.14.42.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:42:09 -0700 (PDT) Subject: [PATCH 4/13] v2 Use new per-location warning APIs in C family code To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: <613b4fc4-4bf0-c226-15a9-b1fd4ccd9c8e@gmail.com> Date: Fri, 4 Jun 2021 15:42:09 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch replaces the uses of TREE_NO_WARNING in the shared C family front end with the new suppress_warning(), warning_suppressed_p(), and copy_warning() APIs. Add support for per-location warning groups. gcc/c-family/ChangeLog: * c-common.c (c_wrap_maybe_const): Remove TREE_NO_WARNING. (c_common_truthvalue_conversion): Replace direct uses of TREE_NO_WARNING with warning_suppressed_p, suppress_warning, and copy_no_warning. (check_function_arguments_recurse): Same. * c-gimplify.c (c_gimplify_expr): Same. * c-warn.c (overflow_warning): Same. (warn_logical_operator): Same. (warn_if_unused_value): Same. (do_warn_unused_parameter): Same. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index c4eb2b1c920..681fcc972f4 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -3375,7 +3375,6 @@ pointer_int_sum (location_t loc, enum tree_code resultcode, tree c_wrap_maybe_const (tree expr, bool non_const) { - bool nowarning = TREE_NO_WARNING (expr); location_t loc = EXPR_LOCATION (expr); /* This should never be called for C++. */ @@ -3386,8 +3385,6 @@ c_wrap_maybe_const (tree expr, bool non_const) STRIP_TYPE_NOPS (expr); expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, expr); C_MAYBE_CONST_EXPR_NON_CONST (expr) = non_const; - if (nowarning) - TREE_NO_WARNING (expr) = 1; protected_set_expr_location (expr, loc); return expr; @@ -3633,12 +3630,12 @@ c_common_truthvalue_conversion (location_t location, tree expr) break; case MODIFY_EXPR: - if (!TREE_NO_WARNING (expr) + if (!warning_suppressed_p (expr, OPT_Wparentheses) && warn_parentheses && warning_at (location, OPT_Wparentheses, "suggest parentheses around assignment used as " "truth value")) - TREE_NO_WARNING (expr) = 1; + suppress_warning (expr, OPT_Wparentheses); break; case CONST_DECL: @@ -6019,7 +6016,7 @@ check_function_arguments_recurse (void (*callback) void *ctx, tree param, unsigned HOST_WIDE_INT param_num) { - if (TREE_NO_WARNING (param)) + if (warning_suppressed_p (param)) return; if (CONVERT_EXPR_P (param) diff --git a/gcc/c-family/c-gimplify.c b/gcc/c-family/c-gimplify.c index 39c969d8f40..0d38b706f4c 100644 --- a/gcc/c-family/c-gimplify.c +++ b/gcc/c-family/c-gimplify.c @@ -713,7 +713,7 @@ c_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED, && !TREE_STATIC (DECL_EXPR_DECL (*expr_p)) && (DECL_INITIAL (DECL_EXPR_DECL (*expr_p)) == DECL_EXPR_DECL (*expr_p)) && !warn_init_self) - TREE_NO_WARNING (DECL_EXPR_DECL (*expr_p)) = 1; + suppress_warning (DECL_EXPR_DECL (*expr_p), OPT_Winit_self); break; case PREINCREMENT_EXPR: diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c index a587b993fde..cfa2373585f 100644 --- a/gcc/c-family/c-warn.c +++ b/gcc/c-family/c-warn.c @@ -155,7 +155,7 @@ overflow_warning (location_t loc, tree value, tree expr) value); if (warned) - TREE_NO_WARNING (value) = 1; + suppress_warning (value, OPT_Woverflow); } /* Helper function for walk_tree. Unwrap C_MAYBE_CONST_EXPRs in an expression @@ -219,7 +219,7 @@ warn_logical_operator (location_t location, enum tree_code code, tree type, && INTEGRAL_TYPE_P (TREE_TYPE (op_left)) && !CONSTANT_CLASS_P (stripped_op_left) && TREE_CODE (stripped_op_left) != CONST_DECL - && !TREE_NO_WARNING (op_left) + && !warning_suppressed_p (op_left, OPT_Wlogical_op) && TREE_CODE (op_right) == INTEGER_CST && !integer_zerop (op_right) && !integer_onep (op_right)) @@ -234,7 +234,7 @@ warn_logical_operator (location_t location, enum tree_code code, tree type, = warning_at (location, OPT_Wlogical_op, "logical % applied to non-boolean constant"); if (warned) - TREE_NO_WARNING (op_left) = true; + suppress_warning (op_left, OPT_Wlogical_op); return; } @@ -588,7 +588,7 @@ bool warn_if_unused_value (const_tree exp, location_t locus, bool quiet) { restart: - if (TREE_USED (exp) || TREE_NO_WARNING (exp)) + if (TREE_USED (exp) || warning_suppressed_p (exp, OPT_Wunused_value)) return false; /* Don't warn about void constructs. This includes casting to void, @@ -2422,7 +2422,7 @@ do_warn_unused_parameter (tree fn) decl; decl = DECL_CHAIN (decl)) if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl) - && !TREE_NO_WARNING (decl)) + && !warning_suppressed_p (decl, OPT_Wunused_parameter)) warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_parameter, "unused parameter %qD", decl); } From patchwork Fri Jun 4 21:42:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488131 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=IA+MSa8Y; dkim-atps=neutral Received: from sourceware.org (server2.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 4Fxbv41fMpz9sPf for ; Sat, 5 Jun 2021 07:46:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A3E239A2419 for ; Fri, 4 Jun 2021 21:46:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A3E239A2419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843197; bh=h+d0SPqYKYq3Co4QPYfPRS5IwacY03mFI3IFBfM3M6A=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=IA+MSa8YyJEEtw4Zk2a2YZHwnA6tsmpbPsiiORai6K32MtZ06AilGeTa80wfPNm8e ojQ3yQsz5ncQG+mF5W+MRilSGf5Qiw74leW8Q9SWcYANz4+K5HjjVABR7ELWiTtq3q vJ8IbwjeMEIJJkNhqshowPzN/42NdMAH6JP8yLmM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id 0E2F53892477 for ; Fri, 4 Jun 2021 21:42:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0E2F53892477 Received: by mail-oi1-x22c.google.com with SMTP id a21so11171909oiw.3 for ; Fri, 04 Jun 2021 14:42:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=h+d0SPqYKYq3Co4QPYfPRS5IwacY03mFI3IFBfM3M6A=; b=avn/Xb0/QqVPv4+G+Krh+gEzU7+ZiP1NZL1zY6+avfBj58bY6ld1VmIc5V0ARsvEK6 7uSWAS0Aon4y3PRi9Qw0dJDrx/quU7UJ0vopnEo/eXpTUC/5BBQD2nG0Hgxv7vcKUNsx Npwq57Q0t8dJLkhCHD2+kHdKmndonwLKGZxjFPVB+V8xGrcfIYwzMuU2gHozMq0EHA0Z AsJ/yFl0U0W8q92ZX7fYVyZRk6OrAV5afQH6c/wx616CELDxMpGlT9uMRNvONKd0X5y7 w/MfIEDXTVrwh/0lYk4E9QAYzqog8fAvA0hqrFyqggojM4L2fyeqe1IO8HtcMYOwe7TB vU7g== X-Gm-Message-State: AOAM533zyEo1y4Wsb8KAnNezBjILyfveGzI7k2RPnnIDeaGbb0nHzvE2 z9fotn1ZDfPFMMX/x99YtegvxFdteuo= X-Google-Smtp-Source: ABdhPJz8cRTlI//J/Cz2/7iEtPT6mq76F0+DJu/cTXIA2MGK6EpOFrFpUSGCL1K2K9RkGKp+pIlZGQ== X-Received: by 2002:a54:4e82:: with SMTP id c2mr12482345oiy.137.1622842941384; Fri, 04 Jun 2021 14:42:21 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id t23sm702376oij.21.2021.06.04.14.42.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:42:21 -0700 (PDT) Subject: [PATCH 5/13] v2 Use new per-location warning APIs in the RL78 back end To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: <10eabbe6-1b9d-ab2f-57bc-6badccd6347b@gmail.com> Date: Fri, 4 Jun 2021 15:42:20 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch replaces the uses of TREE_NO_WARNING in the RL78 back end with the new suppress_warning() and warning_suppressed_p() APIs. Add support for per-location warning groups. gcc/ChangeLog: * config/rl78/rl78.c (rl78_handle_naked_attribute): Replace a direct use of TREE_NO_WARNING with suppress_warning. diff --git a/gcc/config/rl78/rl78.c b/gcc/config/rl78/rl78.c index 4c34949a97f..22d1690a035 100644 --- a/gcc/config/rl78/rl78.c +++ b/gcc/config/rl78/rl78.c @@ -847,7 +847,7 @@ rl78_handle_naked_attribute (tree * node, /* Disable warnings about this function - eg reaching the end without seeing a return statement - because the programmer is doing things that gcc does not know about. */ - TREE_NO_WARNING (* node) = 1; + suppress_warning (* node); return NULL_TREE; } From patchwork Fri Jun 4 21:42:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488132 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=luN6cbPS; dkim-atps=neutral Received: from sourceware.org (server2.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 4FxbwF5h2tz9sT6 for ; Sat, 5 Jun 2021 07:47:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D28B039A2436 for ; Fri, 4 Jun 2021 21:47:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D28B039A2436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843258; bh=IqCWUSob4c17rLZcE/1XjY27Atla7So5U64AWPl+sSQ=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=luN6cbPSrzF8IN5X2lg9k4GA5qOff+Xcn7YXqQNjSP3ux7f/scJlP1NcMwmPU96/o yXabJNIK/3QIdM6QyPbaaJztCY4lmrGHCcutqVDh3l/5oepGVa+hpL4WKmVrg+vo8b i/0YY/0sQAZp708NF6WUOTa3POGA9ZjAJM0vum90= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 0075039A142D for ; Fri, 4 Jun 2021 21:42:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0075039A142D Received: by mail-ot1-x335.google.com with SMTP id w23-20020a9d5a970000b02903d0ef989477so6058159oth.9 for ; Fri, 04 Jun 2021 14:42:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=IqCWUSob4c17rLZcE/1XjY27Atla7So5U64AWPl+sSQ=; b=ga6+WuuxtqmOaov/eStwosr/glyTk2LyzTAeTK2GtFrYZYr4hyYTuKfJiSGbFbewUR pKohwRjOfYIWO0AROo45Po7989DlSDChk1oXK2uZ9FbaRXmT7D4WDUyG/AJpSyu7vNpd FVC+SUAjcYfvK0MfEsgKGwFVI6BqDIMDUwKutSY9EHmj3X2l3wWoesX97hSpyuXDLbCd oWxGkDyRVAo7uNU/0/6SHQZYRIzn/hWxu55ljcD82FoqN4KmNkdXHKVTmWR/adSc352l +YjDleiPr2n41Yi/LQw/5NDPwQJRsShX/HBEjVrwBkr/u1doWGhyNyzpJF53QDwCQaW1 GnFA== X-Gm-Message-State: AOAM530F5EpUewYE1zvVrMLBi/hMGSvopZvZmOvpqIWeql7gxp6Kdd84 WNyWxzgSC0YsrNLZZ+z4KVkmaL6uw+4= X-Google-Smtp-Source: ABdhPJyVtpxzQr+eAdzTgqpmQ/P6ZXcOQwFf38gvTTDQrKdkOibkncF02xHlz5SRIwuMS2kGxfAN3g== X-Received: by 2002:a9d:75d2:: with SMTP id c18mr5223424otl.219.1622842958518; Fri, 04 Jun 2021 14:42:38 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id p65sm43285oop.0.2021.06.04.14.42.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:42:38 -0700 (PDT) Subject: [PATCH 6/13] v2 Use new per-location warning APIs in the C++ front end To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: Date: Fri, 4 Jun 2021 15:42:37 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_SBL, URIBL_SBL_A autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch replaces the uses of TREE_NO_WARNING in the C++ front end with the new suppress_warning(), warning_suppressed_p(), and copy_warning() APIs. Add support for per-location warning groups. * call.c (build_over_call): Replace direct uses of TREE_NO_WARNING with warning_suppressed_p, suppress_warning, and copy_no_warning, or nothing if not necessary. (set_up_extended_ref_temp): Same. * class.c (layout_class_type): Same. * constraint.cc (constraint_satisfaction_value): Same. * coroutines.cc (finish_co_await_expr): Same. (finish_co_yield_expr): Same. (finish_co_return_stmt): Same. (build_actor_fn): Same. (coro_rewrite_function_body): Same. (morph_fn_to_coro): Same. * cp-gimplify.c (genericize_eh_spec_block): Same. (gimplify_expr_stmt): Same. (cp_genericize_r): Same. (cp_fold): Same. * cp-ubsan.c (cp_ubsan_instrument_vptr): Same. * cvt.c (cp_fold_convert): Same. (convert_to_void): Same. * decl.c (wrapup_namespace_globals): Same. (grokdeclarator): Same. (finish_function): Same. (require_deduced_type): Same. * decl2.c (no_linkage_error): Same. (c_parse_final_cleanups): Same. * except.c (expand_end_catch_block): Same. * init.c (build_new_1): Same. (build_new): Same. (build_vec_delete_1): Same. (build_vec_init): Same. (build_delete): Same. * method.c (defaultable_fn_check): Same. * parser.c (cp_parser_fold_expression): Same. (cp_parser_primary_expression): Same. * pt.c (push_tinst_level_loc): Same. (tsubst_copy): Same. (tsubst_omp_udr): Same. (tsubst_copy_and_build): Same. * rtti.c (build_if_nonnull): Same. * semantics.c (maybe_convert_cond): Same. (finish_return_stmt): Same. (finish_parenthesized_expr): Same. (cp_check_omp_declare_reduction): Same. * tree.c (build_cplus_array_type): Same. * typeck.c (build_ptrmemfunc_access_expr): Same. (cp_build_indirect_ref_1): Same. (cp_build_function_call_vec): Same. (warn_for_null_address): Same. (cp_build_binary_op): Same. (unary_complex_lvalue): Same. (cp_build_modify_expr): Same. (build_x_modify_expr): Same. (convert_for_assignment): Same. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 17fc60cd4af..0afddd56496 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -9461,7 +9461,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) { /* Avoid copying empty classes. */ val = build2 (COMPOUND_EXPR, type, arg, to); - TREE_NO_WARNING (val) = 1; + suppress_warning (val, OPT_Wunused); } else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base))) { @@ -9492,7 +9492,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) build2 (MEM_REF, array_type, arg0, alias_set), build2 (MEM_REF, array_type, arg, alias_set)); val = build2 (COMPOUND_EXPR, TREE_TYPE (to), t, to); - TREE_NO_WARNING (val) = 1; + suppress_warning (val, OPT_Wunused); } cp_warn_deprecated_use (fn, complain); @@ -9566,7 +9566,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) { tree c = extract_call_expr (call); if (TREE_CODE (c) == CALL_EXPR) - TREE_NO_WARNING (c) = 1; + suppress_warning (c /* Suppress all warnings. */); } if (TREE_CODE (fn) == ADDR_EXPR) { @@ -12516,11 +12516,11 @@ set_up_extended_ref_temp (tree decl, tree expr, vec **cleanups, TREE_ADDRESSABLE (var) = 1; if (TREE_CODE (decl) == FIELD_DECL - && extra_warnings && !TREE_NO_WARNING (decl)) + && extra_warnings && !warning_suppressed_p (decl)) { warning (OPT_Wextra, "a temporary bound to %qD only persists " "until the constructor exits", decl); - TREE_NO_WARNING (decl) = true; + suppress_warning (decl); } /* Recursively extend temps in this initializer. */ diff --git a/gcc/cp/class.c b/gcc/cp/class.c index b53a4dbdd4e..c89ffadcef8 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -6704,7 +6704,7 @@ layout_class_type (tree t, tree *virtuals_p) laying out an Objective-C class. The ObjC ABI differs from the C++ ABI, and so we do not want a warning here. */ - && !TREE_NO_WARNING (field) + && !warning_suppressed_p (field, OPT_Wabi) && !last_field_was_bitfield && !integer_zerop (size_binop (TRUNC_MOD_EXPR, DECL_FIELD_BIT_OFFSET (field), diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 03ce8eb9ff2..ae88666e4a2 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3281,14 +3281,14 @@ constraint_satisfaction_value (tree t, tree args, sat_info info) else r = satisfy_nondeclaration_constraints (t, args, info); if (r == error_mark_node && info.quiet () - && !(DECL_P (t) && TREE_NO_WARNING (t))) + && !(DECL_P (t) && warning_suppressed_p (t))) { /* Replay the error noisily. */ sat_info noisy (tf_warning_or_error, info.in_decl); constraint_satisfaction_value (t, args, noisy); if (DECL_P (t) && !args) /* Avoid giving these errors again. */ - TREE_NO_WARNING (t) = true; + suppress_warning (t); } return r; } diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 1bf1931e7be..a1b0b31f497 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -1078,7 +1078,7 @@ finish_co_await_expr (location_t kw, tree expr) is declared to return non-void (most likely). This is correct - we synthesize the return for the ramp in the compiler. So suppress any extraneous warnings during substitution. */ - TREE_NO_WARNING (current_function_decl) = true; + suppress_warning (current_function_decl, OPT_Wreturn_type); /* If we don't know the promise type, we can't proceed, build the co_await with the expression unchanged. */ @@ -1154,7 +1154,7 @@ finish_co_yield_expr (location_t kw, tree expr) is declared to return non-void (most likely). This is correct - we synthesize the return for the ramp in the compiler. So suppress any extraneous warnings during substitution. */ - TREE_NO_WARNING (current_function_decl) = true; + suppress_warning (current_function_decl, OPT_Wreturn_type); /* If we don't know the promise type, we can't proceed, build the co_await with the expression unchanged. */ @@ -1235,7 +1235,7 @@ finish_co_return_stmt (location_t kw, tree expr) is declared to return non-void (most likely). This is correct - we synthesize the return for the ramp in the compiler. So suppress any extraneous warnings during substitution. */ - TREE_NO_WARNING (current_function_decl) = true; + suppress_warning (current_function_decl, OPT_Wreturn_type); if (processing_template_decl && check_for_bare_parameter_packs (expr)) @@ -1259,7 +1259,7 @@ finish_co_return_stmt (location_t kw, tree expr) /* Suppress -Wreturn-type for co_return, we need to check indirectly whether the promise type has a suitable return_void/return_value. */ - TREE_NO_WARNING (current_function_decl) = true; + suppress_warning (current_function_decl, OPT_Wreturn_type); if (!processing_template_decl && warn_sequence_point) verify_sequence_points (expr); @@ -2458,7 +2458,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tree fnbody, /* done. */ r = build_stmt (loc, RETURN_EXPR, NULL); - TREE_NO_WARNING (r) |= 1; /* We don't want a warning about this. */ + suppress_warning (r); /* We don't want a warning about this. */ r = maybe_cleanup_point_expr_void (r); add_stmt (r); @@ -2467,7 +2467,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tree fnbody, add_stmt (r); r = build_stmt (loc, RETURN_EXPR, NULL); - TREE_NO_WARNING (r) |= 1; /* We don't want a warning about this. */ + suppress_warning (r); /* We don't want a warning about this. */ r = maybe_cleanup_point_expr_void (r); add_stmt (r); @@ -4142,7 +4142,7 @@ coro_rewrite_function_body (location_t fn_start, tree fnbody, tree orig, finish_if_stmt_cond (not_iarc, not_iarc_if); /* If the initial await resume called value is false, rethrow... */ tree rethrow = build_throw (fn_start, NULL_TREE); - TREE_NO_WARNING (rethrow) = true; + suppress_warning (rethrow); finish_expr_stmt (rethrow); finish_then_clause (not_iarc_if); tree iarc_scope = IF_SCOPE (not_iarc_if); @@ -4243,7 +4243,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) /* For early errors, we do not want a diagnostic about the missing ramp return value, since the user cannot fix this - a 'return' is not allowed in a coroutine. */ - TREE_NO_WARNING (orig) = true; + suppress_warning (orig, OPT_Wreturn_type); /* Discard the body, we can't process it further. */ pop_stmt_list (DECL_SAVED_TREE (orig)); DECL_SAVED_TREE (orig) = push_stmt_list (); @@ -4269,7 +4269,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) DECL_SAVED_TREE (orig) = push_stmt_list (); append_to_statement_list (fnbody, &DECL_SAVED_TREE (orig)); /* Suppress warnings about the missing return value. */ - TREE_NO_WARNING (orig) = true; + suppress_warning (orig, OPT_Wreturn_type); return false; } @@ -4948,7 +4948,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) BIND_EXPR_BODY (ramp_bind) = pop_stmt_list (ramp_body); DECL_SAVED_TREE (orig) = newbody; /* Suppress warnings about the missing return value. */ - TREE_NO_WARNING (orig) = true; + suppress_warning (orig, OPT_Wreturn_type); return false; } @@ -5159,7 +5159,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) promise_type, fn_start); finish_expr_stmt (del_coro_fr); tree rethrow = build_throw (fn_start, NULL_TREE); - TREE_NO_WARNING (rethrow) = true; + suppress_warning (rethrow); finish_expr_stmt (rethrow); finish_handler (handler); TRY_HANDLERS (ramp_cleanup) = pop_stmt_list (TRY_HANDLERS (ramp_cleanup)); diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 9079a5b90ca..8e14226844a 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -101,8 +101,8 @@ genericize_eh_spec_block (tree *stmt_p) tree failure = build_call_n (call_unexpected_fn, 1, build_exc_ptr ()); *stmt_p = build_gimple_eh_filter_tree (body, allowed, failure); - TREE_NO_WARNING (*stmt_p) = true; - TREE_NO_WARNING (TREE_OPERAND (*stmt_p, 1)) = true; + suppress_warning (*stmt_p); + suppress_warning (TREE_OPERAND (*stmt_p, 1)); } /* Return the first non-compound statement in STMT. */ @@ -214,7 +214,7 @@ gimplify_expr_stmt (tree *stmt_p) { if (!IS_EMPTY_STMT (stmt) && !VOID_TYPE_P (TREE_TYPE (stmt)) - && !TREE_NO_WARNING (stmt)) + && !warning_suppressed_p (stmt, OPT_Wunused_value)) warning (OPT_Wunused_value, "statement with no effect"); } else @@ -1322,7 +1322,7 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) case THROW_EXPR: { location_t loc = location_of (stmt); - if (TREE_NO_WARNING (stmt)) + if (warning_suppressed_p (stmt /* What warning? */)) /* Never mind. */; else if (wtd->try_block) { @@ -2443,8 +2443,9 @@ cp_fold (tree x) ; else if (COMPARISON_CLASS_P (x)) { - if (TREE_NO_WARNING (org_x) && warn_nonnull_compare) - TREE_NO_WARNING (x) = 1; + if (warn_nonnull_compare + && warning_suppressed_p (org_x, OPT_Wnonnull_compare)) + suppress_warning (x, OPT_Wnonnull_compare); } /* Otherwise give up on optimizing these, let GIMPLE folders optimize those later on. */ @@ -2452,8 +2453,9 @@ cp_fold (tree x) || op1 != TREE_OPERAND (org_x, 1)) { x = build2_loc (loc, code, TREE_TYPE (org_x), op0, op1); - if (TREE_NO_WARNING (org_x) && warn_nonnull_compare) - TREE_NO_WARNING (x) = 1; + if (warn_nonnull_compare + && warning_suppressed_p (org_x, OPT_Wnonnull_compare)) + suppress_warning (x, OPT_Wnonnull_compare); } else x = org_x; @@ -2709,7 +2711,7 @@ cp_fold (tree x) if (EXPR_P (x) && TREE_CODE (x) == code) { TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x); - TREE_NO_WARNING (x) = TREE_NO_WARNING (org_x); + copy_warning (x, org_x); } if (!c.evaluation_restricted_p ()) diff --git a/gcc/cp/cp-ubsan.c b/gcc/cp/cp-ubsan.c index 3dabb6aa18a..78545945d75 100644 --- a/gcc/cp/cp-ubsan.c +++ b/gcc/cp/cp-ubsan.c @@ -81,7 +81,7 @@ cp_ubsan_instrument_vptr (location_t loc, tree op, tree type, bool is_addr, build_zero_cst (TREE_TYPE (op))); /* This is a compiler generated comparison, don't emit e.g. -Wnonnull-compare warning for it. */ - TREE_NO_WARNING (cond) = 1; + suppress_warning (cond, OPT_Wnonnull_compare); vptr = build3_loc (loc, COND_EXPR, uint64_type_node, cond, vptr, build_int_cst (uint64_type_node, 0)); } diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 330d65854b4..d035e611be4 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -605,8 +605,6 @@ ignore_overflows (tree expr, tree orig) tree cp_fold_convert (tree type, tree expr) { - bool nowarn = TREE_NO_WARNING (expr); - tree conv; if (TREE_TYPE (expr) == type) conv = expr; @@ -630,8 +628,8 @@ cp_fold_convert (tree type, tree expr) conv = ignore_overflows (conv, expr); } - if (nowarn && TREE_CODE (expr) == TREE_CODE (conv)) - TREE_NO_WARNING (conv) = nowarn; + if (TREE_CODE (expr) == TREE_CODE (conv)) + copy_warning (conv, expr); return conv; } @@ -1208,7 +1206,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) /* The second part of a compound expr contains the value. */ tree op1 = TREE_OPERAND (expr,1); tree new_op1; - if (implicit != ICV_CAST && !TREE_NO_WARNING (expr)) + if (implicit != ICV_CAST && !warning_suppressed_p (expr /* What warning? */)) new_op1 = convert_to_void (op1, ICV_RIGHT_OF_COMMA, complain); else new_op1 = convert_to_void (op1, ICV_CAST, complain); @@ -1394,7 +1392,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) if (warn_unused_value && implicit != ICV_CAST && (complain & tf_warning) - && !TREE_NO_WARNING (expr) + && !warning_suppressed_p (expr, OPT_Wunused_value) && !is_reference) warning_at (loc, OPT_Wunused_value, "value computed is not used"); expr = TREE_OPERAND (expr, 0); @@ -1578,7 +1576,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) { if (implicit != ICV_CAST && warn_unused_value - && !TREE_NO_WARNING (expr) + && !warning_suppressed_p (expr, OPT_Wunused_value) && !processing_template_decl && !cp_unevaluated_operand && (complain & tf_warning)) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a3687dbb0dd..430979c47b9 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -839,7 +839,7 @@ wrapup_namespace_globals () && !TREE_PUBLIC (decl) && !DECL_ARTIFICIAL (decl) && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl) - && !TREE_NO_WARNING (decl)) + && !warning_suppressed_p (decl, OPT_Wunused_function)) warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_function, "%qF declared % but never defined", decl); @@ -13883,10 +13883,7 @@ grokdeclarator (const cp_declarator *declarator, decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type); DECL_NONADDRESSABLE_P (decl) = bitfield; if (bitfield && !unqualified_id) - { - TREE_NO_WARNING (decl) = 1; - DECL_PADDING_P (decl) = 1; - } + DECL_PADDING_P (decl) = 1; if (storage_class == sc_mutable) { @@ -17472,7 +17469,7 @@ finish_function (bool inline_p) /* Don't complain if we are declared noreturn. */ && !TREE_THIS_VOLATILE (fndecl) && !DECL_NAME (DECL_RESULT (fndecl)) - && !TREE_NO_WARNING (fndecl) + && !warning_suppressed_p (fndecl, OPT_Wreturn_type) /* Structor return values (if any) are set by the compiler. */ && !DECL_CONSTRUCTOR_P (fndecl) && !DECL_DESTRUCTOR_P (fndecl) @@ -17500,7 +17497,7 @@ finish_function (bool inline_p) else if (warning_at (&richloc, OPT_Wreturn_type, "no return statement in function returning " "non-void")) - TREE_NO_WARNING (fndecl) = 1; + suppress_warning (fndecl, OPT_Wreturn_type); } /* Lambda closure members are implicitly constexpr if possible. */ @@ -17574,7 +17571,7 @@ finish_function (bool inline_p) && !DECL_READ_P (decl) && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl) - && !TREE_NO_WARNING (decl) + && !warning_suppressed_p (decl,OPT_Wunused_but_set_parameter) && !DECL_IN_SYSTEM_HEADER (decl) && TREE_TYPE (decl) != error_mark_node && !TYPE_REF_P (TREE_TYPE (decl)) @@ -18065,7 +18062,7 @@ require_deduced_type (tree decl, tsubst_flags_t complain) { if (undeduced_auto_decl (decl)) { - if (TREE_NO_WARNING (decl) && seen_error ()) + if (warning_suppressed_p (decl) && seen_error ()) /* We probably already complained about deduction failure. */; else if (complain & tf_error) error ("use of %qD before deduction of %", decl); diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index e46fded908a..090a83bd670 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -4529,7 +4529,7 @@ no_linkage_error (tree decl) || (errorcount + sorrycount > 0 && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl) - && TREE_NO_WARNING (decl)))) + && warning_suppressed_p (decl /* What warning? */)))) /* In C++11 it's ok if the decl is defined. */ return; @@ -5204,7 +5204,7 @@ c_parse_final_cleanups (void) && warning_at (DECL_SOURCE_LOCATION (decl), 0, "inline function %qD used but never defined", decl)) /* Avoid a duplicate warning from check_global_declaration. */ - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl, OPT_Wunused); } /* So must decls that use a type with no linkage. */ diff --git a/gcc/cp/except.c b/gcc/cp/except.c index cbafc09629b..a8cea53cf91 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -466,7 +466,8 @@ expand_end_catch_block (void) || DECL_DESTRUCTOR_P (current_function_decl))) { tree rethrow = build_throw (input_location, NULL_TREE); - TREE_NO_WARNING (rethrow) = true; + /* Disable all warnings for the generated rethrow statement. */ + suppress_warning (rethrow); finish_expr_stmt (rethrow); } } diff --git a/gcc/cp/init.c b/gcc/cp/init.c index b1123287300..2873c13a235 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3536,11 +3536,11 @@ build_new_1 (vec **placement, tree type, tree nelts, the arguments to the constructor call. */ { /* CLEANUP is compiler-generated, so no diagnostics. */ - TREE_NO_WARNING (cleanup) = true; + suppress_warning (cleanup); init_expr = build2 (TRY_CATCH_EXPR, void_type_node, init_expr, cleanup); /* Likewise, this try-catch is compiler-generated. */ - TREE_NO_WARNING (init_expr) = true; + suppress_warning (init_expr); } else /* Ack! First we allocate the memory. Then we set our sentry @@ -3562,7 +3562,7 @@ build_new_1 (vec **placement, tree type, tree nelts, sentry = TARGET_EXPR_SLOT (begin); /* CLEANUP is compiler-generated, so no diagnostics. */ - TREE_NO_WARNING (cleanup) = true; + suppress_warning (cleanup); TARGET_EXPR_CLEANUP (begin) = build3 (COND_EXPR, void_type_node, sentry, @@ -3576,7 +3576,7 @@ build_new_1 (vec **placement, tree type, tree nelts, build2 (COMPOUND_EXPR, void_type_node, init_expr, end)); /* Likewise, this is compiler-generated. */ - TREE_NO_WARNING (init_expr) = true; + suppress_warning (init_expr); } } } @@ -3823,7 +3823,7 @@ build_new (location_t loc, vec **placement, tree type, /* Wrap it in a NOP_EXPR so warn_if_unused_value doesn't complain. */ rval = build1_loc (loc, NOP_EXPR, TREE_TYPE (rval), rval); - TREE_NO_WARNING (rval) = 1; + suppress_warning (rval, OPT_Wunused_value); return rval; } @@ -3995,7 +3995,7 @@ build_vec_delete_1 (location_t loc, tree base, tree maxindex, tree type, fold_convert (TREE_TYPE (base), nullptr_node)); /* This is a compiler generated comparison, don't emit e.g. -Wnonnull-compare warning for it. */ - TREE_NO_WARNING (cond) = 1; + suppress_warning (cond, OPT_Wnonnull_compare); body = build3_loc (loc, COND_EXPR, void_type_node, cond, body, integer_zero_node); COND_EXPR_IS_VEC_DELETE (body) = true; @@ -4657,7 +4657,7 @@ build_vec_init (tree base, tree maxindex, tree init, atype = build_pointer_type (atype); stmt_expr = build1 (NOP_EXPR, atype, stmt_expr); stmt_expr = cp_build_fold_indirect_ref (stmt_expr); - TREE_NO_WARNING (stmt_expr) = 1; + suppress_warning (stmt_expr /* What warning? */); } return stmt_expr; @@ -4927,7 +4927,7 @@ build_delete (location_t loc, tree otype, tree addr, /* This is a compiler generated comparison, don't emit e.g. -Wnonnull-compare warning for it. */ else if (TREE_CODE (ifexp) == NE_EXPR) - TREE_NO_WARNING (ifexp) = 1; + suppress_warning (ifexp, OPT_Wnonnull_compare); if (!integer_nonzerop (ifexp)) expr = build3 (COND_EXPR, void_type_node, ifexp, expr, void_node); diff --git a/gcc/cp/method.c b/gcc/cp/method.c index dd745237f22..f268aab1a79 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -3284,7 +3284,7 @@ defaultable_fn_check (tree fn) /* Avoid do_warn_unused_parameter warnings. */ for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p)) if (DECL_NAME (p)) - TREE_NO_WARNING (p) = 1; + suppress_warning (p, OPT_Wunused_parameter); if (current_class_type && TYPE_BEING_DEFINED (current_class_type)) /* Defer checking. */; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4a46828e162..8aa73781cc9 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -1,3 +1,4 @@ + /* -*- C++ -*- Parser. Copyright (C) 2000-2021 Free Software Foundation, Inc. Written by Mark Mitchell . @@ -5322,7 +5323,7 @@ cp_parser_fold_expression (cp_parser *parser, tree expr1) /* The operands of a fold-expression are cast-expressions, so binary or conditional expressions are not allowed. We check this here to avoid tentative parsing. */ - if (EXPR_P (expr1) && TREE_NO_WARNING (expr1)) + if (EXPR_P (expr1) && warning_suppressed_p (expr1, OPT_Wparentheses)) /* OK, the expression was parenthesized. */; else if (is_binary_op (TREE_CODE (expr1))) error_at (location_of (expr1), @@ -5604,7 +5605,10 @@ cp_parser_primary_expression (cp_parser *parser, /* Consume the `)'. */ token = cp_lexer_peek_token (parser->lexer); location_t close_paren_loc = token->location; + bool no_wparens = warning_suppressed_p (expr, OPT_Wparentheses); expr.set_range (open_paren_loc, close_paren_loc); + if (no_wparens) + suppress_warning (expr, OPT_Wparentheses); if (!parens.require_close (parser) && !cp_parser_uncommitted_to_tentative_parse_p (parser)) cp_parser_skip_to_end_of_statement (parser); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7211bdc5bbc..a7d4a222c8b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10936,9 +10936,9 @@ push_tinst_level_loc (tree tldcl, tree targs, location_t loc) constant expressions. */ if (!targs && limit_bad_template_recursion (tldcl)) { - /* Avoid no_linkage_errors and unused function warnings for this - decl. */ - TREE_NO_WARNING (tldcl) = 1; + /* Avoid no_linkage_errors and unused function (and all other) + warnings for this decl. */ + suppress_warning (tldcl); return false; } @@ -17084,7 +17084,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) tree op1 = tsubst_copy (TREE_OPERAND (t, 1), args, complain, in_decl); tree op2 = tsubst_copy (TREE_OPERAND (t, 2), args, complain, in_decl); r = build_nt (code, op0, op1, op2); - TREE_NO_WARNING (r) = TREE_NO_WARNING (t); + copy_warning (r, t); return r; } @@ -19166,8 +19166,7 @@ tsubst_omp_udr (tree t, tree args, tsubst_flags_t complain, tree in_decl) block = finish_omp_structured_block (block); block = maybe_cleanup_point_expr_void (block); add_decl_expr (omp_out); - if (TREE_NO_WARNING (DECL_EXPR_DECL (stmts[0]))) - TREE_NO_WARNING (omp_out) = 1; + copy_warning (omp_out, DECL_EXPR_DECL (stmts[0])); add_decl_expr (omp_in); finish_expr_stmt (block); } @@ -19843,17 +19842,17 @@ tsubst_copy_and_build (tree t, tree r = build_x_binary_op (input_location, TREE_CODE (t), op0, - (TREE_NO_WARNING (TREE_OPERAND (t, 0)) + (warning_suppressed_p (TREE_OPERAND (t, 0)) ? ERROR_MARK : TREE_CODE (TREE_OPERAND (t, 0))), op1, - (TREE_NO_WARNING (TREE_OPERAND (t, 1)) + (warning_suppressed_p (TREE_OPERAND (t, 1)) ? ERROR_MARK : TREE_CODE (TREE_OPERAND (t, 1))), /*overload=*/NULL, complain|decltype_flag); - if (EXPR_P (r) && TREE_NO_WARNING (t)) - TREE_NO_WARNING (r) = TREE_NO_WARNING (t); + if (EXPR_P (r)) + copy_warning (r, t); RETURN (r); } @@ -19989,8 +19988,8 @@ tsubst_copy_and_build (tree t, set and must be copied. In the latter case, build_x_modify_expr sets it and it must not be reset here. */ - if (TREE_NO_WARNING (t)) - TREE_NO_WARNING (r) = TREE_NO_WARNING (t); + if (warning_suppressed_p (t, OPT_Wparentheses)) + suppress_warning (r, OPT_Wparentheses); RETURN (r); } diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index 82eaa286514..fcb33088a21 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -536,14 +536,14 @@ build_if_nonnull (tree test, tree result, tsubst_flags_t complain) /* This is a compiler generated comparison, don't emit e.g. -Wnonnull-compare warning for it. */ - TREE_NO_WARNING (cond) = 1; + suppress_warning (cond, OPT_Wnonnull); null_ptr = cp_convert (TREE_TYPE (result), nullptr_node, complain); cond = build3 (COND_EXPR, TREE_TYPE (result), cond, result, null_ptr); /* Likewise, don't emit -Wnonnull for using the result to call a member function. */ - TREE_NO_WARNING (cond) = 1; + suppress_warning (cond, OPT_Wnonnull); return cond; } diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index d08c1ddabf9..79660964e69 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -835,12 +835,12 @@ maybe_convert_cond (tree cond) cond = convert_from_reference (cond); if (TREE_CODE (cond) == MODIFY_EXPR - && !TREE_NO_WARNING (cond) && warn_parentheses + && !warning_suppressed_p (cond, OPT_Wparentheses) && warning_at (cp_expr_loc_or_input_loc (cond), OPT_Wparentheses, "suggest parentheses around " "assignment used as truth value")) - TREE_NO_WARNING (cond) = 1; + suppress_warning (cond, OPT_Wparentheses); return condition_conversion (cond); } @@ -1143,7 +1143,7 @@ finish_return_stmt (tree expr) { /* Suppress -Wreturn-type for this function. */ if (warn_return_type) - TREE_NO_WARNING (current_function_decl) = true; + suppress_warning (current_function_decl, OPT_Wreturn_type); return error_mark_node; } @@ -1165,7 +1165,8 @@ finish_return_stmt (tree expr) } r = build_stmt (input_location, RETURN_EXPR, expr); - TREE_NO_WARNING (r) |= no_warning; + if (no_warning) + suppress_warning (r, OPT_Wreturn_type); r = maybe_cleanup_point_expr_void (r); r = add_stmt (r); @@ -2051,7 +2052,7 @@ finish_parenthesized_expr (cp_expr expr) { if (EXPR_P (expr)) /* This inhibits warnings in c_common_truthvalue_conversion. */ - TREE_NO_WARNING (expr) = 1; + suppress_warning (expr, OPT_Wparentheses); if (TREE_CODE (expr) == OFFSET_REF || TREE_CODE (expr) == SCOPE_REF) @@ -5926,12 +5927,12 @@ cp_check_omp_declare_reduction (tree udr) { gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR && TREE_CODE (data.stmts[1]) == DECL_EXPR); - if (TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0]))) + if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */)) return true; data.combiner_p = true; if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r, &data, NULL)) - TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])) = 1; + suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */); } if (i >= 6) { @@ -5942,7 +5943,7 @@ cp_check_omp_declare_reduction (tree udr) &data, NULL) || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])), cp_check_omp_declare_reduction_r, &data, NULL)) - TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])) = 1; + suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */); if (i == 7) gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR); } diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index fec5afaa2be..8595b3db9f2 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1127,7 +1127,7 @@ build_cplus_array_type (tree elt_type, tree index_type, int dependent) /* Avoid spurious warnings with VLAs (c++/54583). */ if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t))) - TREE_NO_WARNING (TYPE_SIZE (t)) = 1; + suppress_warning (TYPE_SIZE (t), OPT_Wunused); /* Push these needs up to the ARRAY_TYPE so that initialization takes place more easily. */ diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index dbb2370510c..3d8897d513a 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -3326,10 +3326,7 @@ build_ptrmemfunc_access_expr (tree ptrmem, tree member_name) member = DECL_CHAIN (member)) if (DECL_NAME (member) == member_name) break; - tree res = build_simple_component_ref (ptrmem, member); - - TREE_NO_WARNING (res) = 1; - return res; + return build_simple_component_ref (ptrmem, member); } /* Given an expression PTR for a pointer, return an expression @@ -3443,7 +3440,7 @@ cp_build_indirect_ref_1 (location_t loc, tree ptr, ref_operator errorstring, if (warn_strict_aliasing > 2 && cp_strict_aliasing_warning (EXPR_LOCATION (ptr), type, TREE_OPERAND (ptr, 0))) - TREE_NO_WARNING (ptr) = 1; + suppress_warning (ptr, OPT_Wstrict_aliasing); } if (VOID_TYPE_P (t)) @@ -4068,7 +4065,7 @@ cp_build_function_call_vec (tree function, vec **params, { tree c = extract_call_expr (ret); if (TREE_CODE (c) == CALL_EXPR) - TREE_NO_WARNING (c) = 1; + suppress_warning (c, OPT_Wnonnull); } if (allocated != NULL) @@ -4450,14 +4447,14 @@ warn_for_null_address (location_t location, tree op, tsubst_flags_t complain) if (!warn_address || (complain & tf_warning) == 0 || c_inhibit_evaluation_warnings != 0 - || TREE_NO_WARNING (op)) + || warning_suppressed_p (op, OPT_Waddress)) return; tree cop = fold_for_warn (op); if (TREE_CODE (cop) == ADDR_EXPR && decl_with_nonnull_addr_p (TREE_OPERAND (cop, 0)) - && !TREE_NO_WARNING (cop)) + && !warning_suppressed_p (cop, OPT_Waddress)) warning_at (location, OPT_Waddress, "the address of %qD will never " "be NULL", TREE_OPERAND (cop, 0)); @@ -4878,7 +4875,7 @@ cp_build_binary_op (const op_location_t &location, else if (TREE_CODE (type0) == ARRAY_TYPE && !char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type0))) /* Set by finish_parenthesized_expr. */ - && !TREE_NO_WARNING (op1) + && !warning_suppressed_p (op1, OPT_Wsizeof_array_div) && (complain & tf_warning)) maybe_warn_sizeof_array_div (location, first_arg, type0, op1, non_reference (type1)); @@ -5297,7 +5294,7 @@ cp_build_binary_op (const op_location_t &location, pfn0 = cp_fully_fold (pfn0); /* Avoid -Waddress warnings (c++/64877). */ if (TREE_CODE (pfn0) == ADDR_EXPR) - TREE_NO_WARNING (pfn0) = 1; + suppress_warning (pfn0, OPT_Waddress); pfn1 = pfn_from_ptrmemfunc (op1); pfn1 = cp_fully_fold (pfn1); delta0 = delta_from_ptrmemfunc (op0); @@ -7062,7 +7059,7 @@ unary_complex_lvalue (enum tree_code code, tree arg) tf_warning_or_error); arg = build2 (COMPOUND_EXPR, TREE_TYPE (real_result), arg, real_result); - TREE_NO_WARNING (arg) = 1; + suppress_warning (arg /* What warning? */); return arg; } @@ -8973,7 +8970,7 @@ cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, TREE_SIDE_EFFECTS (result) = 1; if (!plain_assign) - TREE_NO_WARNING (result) = 1; + suppress_warning (result, OPT_Wparentheses); ret: if (preeval) @@ -9017,7 +9014,7 @@ build_x_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, { if (rval == error_mark_node) return rval; - TREE_NO_WARNING (rval) = 1; + suppress_warning (rval /* What warning? */); if (processing_template_decl) { if (overload != NULL_TREE) @@ -9624,13 +9621,13 @@ convert_for_assignment (tree type, tree rhs, if (warn_parentheses && TREE_CODE (type) == BOOLEAN_TYPE && TREE_CODE (rhs) == MODIFY_EXPR - && !TREE_NO_WARNING (rhs) + && !warning_suppressed_p (rhs, OPT_Wparentheses) && TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE && (complain & tf_warning) && warning_at (rhs_loc, OPT_Wparentheses, "suggest parentheses around assignment used as " "truth value")) - TREE_NO_WARNING (rhs) = 1; + suppress_warning (rhs, OPT_Wparentheses); if (complain & tf_warning) warn_for_address_or_pointer_of_packed_member (type, rhs); From patchwork Fri Jun 4 21:42:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488133 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=2620:52:3:1:0:246e:9693:128c; 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=cEh+WYZQ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Fxbxb3tK7z9sPf for ; Sat, 5 Jun 2021 07:48:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A722939A1812 for ; Fri, 4 Jun 2021 21:48:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A722939A1812 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843328; bh=7cUImvgmExHPISK0vErFhWa9r6ecVIouj7FKLoTHEIw=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=cEh+WYZQ6SEUdanZqwNoSH2O8ddl1iyCu1MPwnOQ6UEinUYuec8MSxlp3atnZHBR5 PFJfkCJRidqat7KCeAC8nbfZ7lP6OuWOz+hGjPOB2GRoLpOkCZuZfizshqq4dmDM6t CaSNZ7o5iMBkSBsmNKl0sDC0YaplJcrDJfTtQ8Wg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 82EFE39A1417 for ; Fri, 4 Jun 2021 21:42:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 82EFE39A1417 Received: by mail-oi1-x22b.google.com with SMTP id r17so910137oic.7 for ; Fri, 04 Jun 2021 14:42:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=7cUImvgmExHPISK0vErFhWa9r6ecVIouj7FKLoTHEIw=; b=VQgDq/YADASVtKP0w3OK+yW5JUecFAlPSgAL+nWgFMUgcMvXhY+VIMkgAubg9Gm1F5 KIIzS1Lln/rQuY9AyxVnqL6KC7kABxZXSP+CQH7WQIL83ndU1yPB2ZJ9b5e0fhIbvXSS reMO9vCwHrCJH8J+xg3o/wWVcKGtlMHtVpijLTYvTY0Q1V7nGrvYDSELNglmyzcKft5z /IsdoIsdxP+tsML2m1PnODe1DyDKgzaOOpYgG7jMBzSXwf3SZNqhA6LXotHhl+gSJyKx 6EetBDjwMBu2Z398/c6Ron0vA5ffpov4MS8pt96k7cfHmXSrMs+/PZcXXeEaqMTafJDv +W+Q== X-Gm-Message-State: AOAM533ShU+dwHoRBZIIt4UAwdLNwuDUDejKE1/PAipr8tszXZEnygwS FbjZXmfr8SZ4gKaboRR/m2fzHwQl/e4= X-Google-Smtp-Source: ABdhPJx0xshk6xjLQk5S2ET8aS/1CsRQjGBaxXpE9Lkvcm/0p0HpSKDdAHT6mKNiECkyJBjVstjB1g== X-Received: by 2002:aca:2404:: with SMTP id n4mr4358467oic.169.1622842968969; Fri, 04 Jun 2021 14:42:48 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id x9sm681239ooo.27.2021.06.04.14.42.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:42:48 -0700 (PDT) Subject: [PATCH 7/13] v2 Use new per-location warning APIs in the FORTRAN front end To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: Date: Fri, 4 Jun 2021 15:42:47 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch replaces the uses of TREE_NO_WARNING in the FORTRAN front end with the new suppress_warning() API. Add support for per-location warning groups. gcc/fortran/ChangeLog: * trans-array.c (trans_array_constructor): Replace direct uses of TREE_NO_WARNING with warning_suppressed_p, and suppress_warning. * trans-decl.c (gfc_build_qualified_array): Same. (gfc_build_dummy_array_decl): Same. (generate_local_decl): Same. (gfc_generate_function_code): Same. * trans-openmp.c (gfc_omp_clause_default_ctor): Same. (gfc_omp_clause_copy_ctor): Same. * trans-types.c (get_dtype_type_node): Same. (gfc_get_desc_dim_type): Same. (gfc_get_array_descriptor_base): Same. (gfc_get_caf_vector_type): Same. (gfc_get_caf_reference_type): Same. * trans.c (gfc_create_var_np): Same. diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 7eeef554c0f..64a050ff196 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -2755,7 +2755,7 @@ trans_array_constructor (gfc_ss * ss, locus * where) desc = ss_info->data.array.descriptor; offset = gfc_index_zero_node; offsetvar = gfc_create_var_np (gfc_array_index_type, "offset"); - TREE_NO_WARNING (offsetvar) = 1; + suppress_warning (offsetvar); TREE_USED (offsetvar) = 0; gfc_trans_array_constructor_value (&outer_loop->pre, type, desc, c, &offset, &offsetvar, dynamic); diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index c32bd05bb1b..3f7953c8400 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1040,7 +1040,7 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym) if (GFC_TYPE_ARRAY_LBOUND (type, dim) == NULL_TREE) { GFC_TYPE_ARRAY_LBOUND (type, dim) = create_index_var ("lbound", nest); - TREE_NO_WARNING (GFC_TYPE_ARRAY_LBOUND (type, dim)) = 1; + suppress_warning (GFC_TYPE_ARRAY_LBOUND (type, dim)); } /* Don't try to use the unknown bound for assumed shape arrays. */ if (GFC_TYPE_ARRAY_UBOUND (type, dim) == NULL_TREE @@ -1048,13 +1048,13 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym) || dim < GFC_TYPE_ARRAY_RANK (type) - 1)) { GFC_TYPE_ARRAY_UBOUND (type, dim) = create_index_var ("ubound", nest); - TREE_NO_WARNING (GFC_TYPE_ARRAY_UBOUND (type, dim)) = 1; + suppress_warning (GFC_TYPE_ARRAY_UBOUND (type, dim)); } if (GFC_TYPE_ARRAY_STRIDE (type, dim) == NULL_TREE) { GFC_TYPE_ARRAY_STRIDE (type, dim) = create_index_var ("stride", nest); - TREE_NO_WARNING (GFC_TYPE_ARRAY_STRIDE (type, dim)) = 1; + suppress_warning (GFC_TYPE_ARRAY_STRIDE (type, dim)); } } for (dim = GFC_TYPE_ARRAY_RANK (type); @@ -1063,21 +1063,21 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym) if (GFC_TYPE_ARRAY_LBOUND (type, dim) == NULL_TREE) { GFC_TYPE_ARRAY_LBOUND (type, dim) = create_index_var ("lbound", nest); - TREE_NO_WARNING (GFC_TYPE_ARRAY_LBOUND (type, dim)) = 1; + suppress_warning (GFC_TYPE_ARRAY_LBOUND (type, dim)); } /* Don't try to use the unknown ubound for the last coarray dimension. */ if (GFC_TYPE_ARRAY_UBOUND (type, dim) == NULL_TREE && dim < GFC_TYPE_ARRAY_RANK (type) + GFC_TYPE_ARRAY_CORANK (type) - 1) { GFC_TYPE_ARRAY_UBOUND (type, dim) = create_index_var ("ubound", nest); - TREE_NO_WARNING (GFC_TYPE_ARRAY_UBOUND (type, dim)) = 1; + suppress_warning (GFC_TYPE_ARRAY_UBOUND (type, dim)); } } if (GFC_TYPE_ARRAY_OFFSET (type) == NULL_TREE) { GFC_TYPE_ARRAY_OFFSET (type) = gfc_create_var_np (gfc_array_index_type, "offset"); - TREE_NO_WARNING (GFC_TYPE_ARRAY_OFFSET (type)) = 1; + suppress_warning (GFC_TYPE_ARRAY_OFFSET (type)); if (nest) gfc_add_decl_to_parent_function (GFC_TYPE_ARRAY_OFFSET (type)); @@ -1089,7 +1089,7 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym) && as->type != AS_ASSUMED_SIZE) { GFC_TYPE_ARRAY_SIZE (type) = create_index_var ("size", nest); - TREE_NO_WARNING (GFC_TYPE_ARRAY_SIZE (type)) = 1; + suppress_warning (GFC_TYPE_ARRAY_SIZE (type)); } if (POINTER_TYPE_P (type)) @@ -1294,7 +1294,7 @@ gfc_build_dummy_array_decl (gfc_symbol * sym, tree dummy) /* Avoid uninitialized warnings for optional dummy arguments. */ if (sym->attr.optional) - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl); /* We should never get deferred shape arrays here. We used to because of frontend bugs. */ @@ -5981,7 +5981,7 @@ generate_local_decl (gfc_symbol * sym) "does not have a default initializer", sym->name, &sym->declared_at); if (sym->backend_decl != NULL_TREE) - TREE_NO_WARNING(sym->backend_decl) = 1; + suppress_warning (sym->backend_decl); } else if (warn_unused_dummy_argument) { @@ -5991,7 +5991,7 @@ generate_local_decl (gfc_symbol * sym) &sym->declared_at); if (sym->backend_decl != NULL_TREE) - TREE_NO_WARNING(sym->backend_decl) = 1; + suppress_warning (sym->backend_decl); } } @@ -6007,7 +6007,7 @@ generate_local_decl (gfc_symbol * sym) "explicitly imported at %L", sym->name, &sym->declared_at); if (sym->backend_decl != NULL_TREE) - TREE_NO_WARNING(sym->backend_decl) = 1; + suppress_warning (sym->backend_decl); } else if (!sym->attr.use_assoc) { @@ -6025,7 +6025,7 @@ generate_local_decl (gfc_symbol * sym) "Unused variable %qs declared at %L", sym->name, &sym->declared_at); if (sym->backend_decl != NULL_TREE) - TREE_NO_WARNING(sym->backend_decl) = 1; + suppress_warning (sym->backend_decl); } } @@ -6140,7 +6140,7 @@ generate_local_decl (gfc_symbol * sym) /* Silence bogus "unused parameter" warnings from the middle end. */ if (sym->backend_decl != NULL_TREE) - TREE_NO_WARNING (sym->backend_decl) = 1; + suppress_warning (sym->backend_decl); } } @@ -6971,7 +6971,7 @@ gfc_generate_function_code (gfc_namespace * ns) "Return value of function %qs at %L not set", sym->name, &sym->declared_at); if (warn_return_type > 0) - TREE_NO_WARNING(sym->backend_decl) = 1; + suppress_warning (sym->backend_decl); } if (result != NULL_TREE) gfc_add_expr_to_block (&body, gfc_generate_return ()); diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c index 1e22cdb82b7..39260027473 100644 --- a/gcc/fortran/trans-openmp.c +++ b/gcc/fortran/trans-openmp.c @@ -763,7 +763,7 @@ gfc_omp_clause_default_ctor (tree clause, tree decl, tree outer) else_b)); /* Avoid -W*uninitialized warnings. */ if (DECL_P (decl)) - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl, OPT_Wuninitialized); } else gfc_add_expr_to_block (&block, then_b); @@ -948,7 +948,7 @@ gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src) void_type_node, cond, then_b, else_b)); /* Avoid -W*uninitialized warnings. */ if (DECL_P (dest)) - TREE_NO_WARNING (dest) = 1; + suppress_warning (dest, OPT_Wuninitialized); return gfc_finish_block (&block); } diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index 9f21b3ee780..4e26aea7fe7 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -150,23 +150,23 @@ tree get_dtype_type_node (void) field = gfc_add_field_to_struct_1 (dtype_node, get_identifier ("elem_len"), size_type_node, &dtype_chain); - TREE_NO_WARNING (field) = 1; + suppress_warning (field); field = gfc_add_field_to_struct_1 (dtype_node, get_identifier ("version"), integer_type_node, &dtype_chain); - TREE_NO_WARNING (field) = 1; + suppress_warning (field); field = gfc_add_field_to_struct_1 (dtype_node, get_identifier ("rank"), signed_char_type_node, &dtype_chain); - TREE_NO_WARNING (field) = 1; + suppress_warning (field); field = gfc_add_field_to_struct_1 (dtype_node, get_identifier ("type"), signed_char_type_node, &dtype_chain); - TREE_NO_WARNING (field) = 1; + suppress_warning (field); field = gfc_add_field_to_struct_1 (dtype_node, get_identifier ("attribute"), short_integer_type_node, &dtype_chain); - TREE_NO_WARNING (field) = 1; + suppress_warning (field); gfc_finish_type (dtype_node); TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (dtype_node)) = 1; dtype_type_node = dtype_node; @@ -1453,17 +1453,17 @@ gfc_get_desc_dim_type (void) decl = gfc_add_field_to_struct_1 (type, get_identifier ("stride"), gfc_array_index_type, &chain); - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl); decl = gfc_add_field_to_struct_1 (type, get_identifier ("lbound"), gfc_array_index_type, &chain); - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl); decl = gfc_add_field_to_struct_1 (type, get_identifier ("ubound"), gfc_array_index_type, &chain); - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl); /* Finish off the type. */ gfc_finish_type (type); @@ -1831,19 +1831,19 @@ gfc_get_array_descriptor_base (int dimen, int codimen, bool restricted) decl = gfc_add_field_to_struct_1 (fat_type, get_identifier ("offset"), gfc_array_index_type, &chain); - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl); /* Add the dtype component. */ decl = gfc_add_field_to_struct_1 (fat_type, get_identifier ("dtype"), get_dtype_type_node (), &chain); - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl); /* Add the span component. */ decl = gfc_add_field_to_struct_1 (fat_type, get_identifier ("span"), gfc_array_index_type, &chain); - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl); /* Build the array type for the stride and bound components. */ if (dimen + codimen > 0) @@ -1856,7 +1856,7 @@ gfc_get_array_descriptor_base (int dimen, int codimen, bool restricted) decl = gfc_add_field_to_struct_1 (fat_type, get_identifier ("dim"), arraytype, &chain); - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl); } if (flag_coarray == GFC_FCOARRAY_LIB) @@ -1864,7 +1864,7 @@ gfc_get_array_descriptor_base (int dimen, int codimen, bool restricted) decl = gfc_add_field_to_struct_1 (fat_type, get_identifier ("token"), prvoid_type_node, &chain); - TREE_NO_WARNING (decl) = 1; + suppress_warning (decl); } /* Finish off the type. */ @@ -2856,7 +2856,7 @@ copy_derived_types: token = gfc_find_component (derived, caf_name, true, true, NULL); gcc_assert (token); c->caf_token = token->backend_decl; - TREE_NO_WARNING (c->caf_token) = 1; + suppress_warning (c->caf_token); } } @@ -3521,11 +3521,11 @@ gfc_get_caf_vector_type (int dim) tmp = gfc_add_field_to_struct_1 (vect_struct_type, get_identifier ("vector"), pvoid_type_node, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (vect_struct_type, get_identifier ("kind"), integer_type_node, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (vect_struct_type); chain = 0; @@ -3533,34 +3533,34 @@ gfc_get_caf_vector_type (int dim) tmp = gfc_add_field_to_struct_1 (triplet_struct_type, get_identifier ("lower_bound"), gfc_array_index_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (triplet_struct_type, get_identifier ("upper_bound"), gfc_array_index_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (triplet_struct_type, get_identifier ("stride"), gfc_array_index_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (triplet_struct_type); chain = 0; union_type = make_node (UNION_TYPE); tmp = gfc_add_field_to_struct_1 (union_type, get_identifier ("v"), vect_struct_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (union_type, get_identifier ("triplet"), triplet_struct_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (union_type); chain = 0; vec_type = make_node (RECORD_TYPE); tmp = gfc_add_field_to_struct_1 (vec_type, get_identifier ("nvec"), size_type_node, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (vec_type, get_identifier ("u"), union_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (vec_type); TYPE_NAME (vec_type) = get_identifier ("caf_vector_t"); } @@ -3587,11 +3587,11 @@ gfc_get_caf_reference_type () tmp = gfc_add_field_to_struct_1 (c_struct_type, get_identifier ("offset"), gfc_array_index_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (c_struct_type, get_identifier ("caf_token_offset"), gfc_array_index_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (c_struct_type); chain = 0; @@ -3599,15 +3599,15 @@ gfc_get_caf_reference_type () tmp = gfc_add_field_to_struct_1 (s_struct_type, get_identifier ("start"), gfc_array_index_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (s_struct_type, get_identifier ("end"), gfc_array_index_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (s_struct_type, get_identifier ("stride"), gfc_array_index_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (s_struct_type); chain = 0; @@ -3615,25 +3615,25 @@ gfc_get_caf_reference_type () tmp = gfc_add_field_to_struct_1 (v_struct_type, get_identifier ("vector"), pvoid_type_node, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (v_struct_type, get_identifier ("nvec"), size_type_node, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (v_struct_type, get_identifier ("kind"), integer_type_node, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (v_struct_type); chain = 0; union_type = make_node (UNION_TYPE); tmp = gfc_add_field_to_struct_1 (union_type, get_identifier ("s"), s_struct_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (union_type, get_identifier ("v"), v_struct_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (union_type); tmp = build_range_type (gfc_array_index_type, gfc_index_zero_node, @@ -3648,40 +3648,40 @@ gfc_get_caf_reference_type () gfc_index_zero_node, gfc_rank_cst[GFC_MAX_DIMENSIONS - 1])), &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (a_struct_type, get_identifier ("static_array_type"), integer_type_node, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (a_struct_type, get_identifier ("dim"), dim_union_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (a_struct_type); chain = 0; u_union_type = make_node (UNION_TYPE); tmp = gfc_add_field_to_struct_1 (u_union_type, get_identifier ("c"), c_struct_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (u_union_type, get_identifier ("a"), a_struct_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (u_union_type); chain = 0; reference_type = make_node (RECORD_TYPE); tmp = gfc_add_field_to_struct_1 (reference_type, get_identifier ("next"), build_pointer_type (reference_type), &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (reference_type, get_identifier ("type"), integer_type_node, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (reference_type, get_identifier ("item_size"), size_type_node, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); tmp = gfc_add_field_to_struct_1 (reference_type, get_identifier ("u"), u_union_type, &chain); - TREE_NO_WARNING (tmp) = 1; + suppress_warning (tmp); gfc_finish_type (reference_type); TYPE_NAME (reference_type) = get_identifier ("caf_reference_t"); diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c index 3ffa394d406..6db02bcdf24 100644 --- a/gcc/fortran/trans.c +++ b/gcc/fortran/trans.c @@ -129,7 +129,7 @@ gfc_create_var_np (tree type, const char *prefix) /* No warnings for anonymous variables. */ if (prefix == NULL) - TREE_NO_WARNING (t) = 1; + suppress_warning (t); return t; } From patchwork Fri Jun 4 21:42:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488134 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=FrqVAy9o; 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 4Fxbyk2XBQz9sPf for ; Sat, 5 Jun 2021 07:49:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6138E39A241B for ; Fri, 4 Jun 2021 21:49:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6138E39A241B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843388; bh=lUThgRmjypXl7sYspBnu+Xh1cpjmSK+RNM9zWF6lUeI=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FrqVAy9o1gAulX2xkhq2WNvpxpLj/VZry0bw01Ffr34ZqHrIkPpKuXMXHPS+mF+5o VUAWJHmdMI1K3QzJVoccfO9rSELCem8puAdM0zgFK3w/Hen36Zd7eAnLKH/halZmG0 q+lZOBvqgwLZnEULy4aXu3s7B/3MvlofZfzAmohE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id 5884B39A1439 for ; Fri, 4 Jun 2021 21:42:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5884B39A1439 Received: by mail-oi1-x22c.google.com with SMTP id z3so11145482oib.5 for ; Fri, 04 Jun 2021 14:42:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=lUThgRmjypXl7sYspBnu+Xh1cpjmSK+RNM9zWF6lUeI=; b=Vjr8LPoi3flP5L+qmwYqx8nf244zkSJ/2+lx0vJVaOPGIbQQPR67bKG7IQfvOj4x6b SPdRe4qCpVx/3XBSI1nPnnTwh6keYDdh6VvXWjdZVlIN98qtu0QFxD9EsOoAxvXtzugG 4aEompH2OfWD3I8HQVbqOHUJ6gBl+eoyPqhVQHsKkKlRy87W27yl5tKabwGSVKl/2NDp zaBE7lKK6ij4VXEEhBzJ6GW/BBLIHhoyfwlqb/+MVn6qMp04bXCQSAs9MJj0zCkI67q1 gjo28cCOBZYW5QEixhqD7RLEHzGp4Jo7xkUeKte8mWu8NcpeJHLHPq5gXsWqqigJiLnn jq+A== X-Gm-Message-State: AOAM533G3DnntMhcKSWvr61s7aisc9le4KZghvW8qZJh2V7H8Ce9WqB5 wN+JKAqGl8Bq8kbamxkYzqVy1Gih5Eo= X-Google-Smtp-Source: ABdhPJxOI7rCea6flnZ3h542pmqYI2zbmsr5k4L2jt/VpwWz3lqxLPaFn2uJ6JwLUvgfrLVsnuxqPQ== X-Received: by 2002:aca:280a:: with SMTP id 10mr12719630oix.13.1622842977739; Fri, 04 Jun 2021 14:42:57 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id u24sm740381otg.73.2021.06.04.14.42.57 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:42:57 -0700 (PDT) Subject: [PATCH 8/13] v2 Use new per-location warning APIs in libcc1 To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: Date: Fri, 4 Jun 2021 15:42:56 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch replaces the uses of TREE_NO_WARNING in libcc1 with the new suppress_warning() API. Add support for per-location warning groups. libcc1/ChangeLog: * libcp1plugin.cc (record_decl_address): Replace a direct use of TREE_NO_WARNING with suppress_warning. diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc index 79694b91964..ea6ee553401 100644 --- a/libcc1/libcp1plugin.cc +++ b/libcc1/libcp1plugin.cc @@ -541,7 +541,7 @@ record_decl_address (plugin_context *ctx, decl_addr_value value) **slot = value; /* We don't want GCC to warn about e.g. static functions without a code definition. */ - TREE_NO_WARNING (value.decl) = 1; + suppress_warning (value.decl); return *slot; } From patchwork Fri Jun 4 21:43:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488135 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=N2U8JNO0; dkim-atps=neutral Received: from sourceware.org (server2.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 4Fxbzs2bV5z9sW4 for ; Sat, 5 Jun 2021 07:50:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D44739A2439 for ; Fri, 4 Jun 2021 21:50:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D44739A2439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843447; bh=Aaicc/N2GANx0IaI0IdhbFZMqQM54k6dTkA6dZQ40cw=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=N2U8JNO0jQWInp0ujUaLl9nUFinQOg06m/7tWFqTW75+v0hrJBhwUiIfE3JPyTpFD U7CgVTX1/utFTPInN216YGHTgVCLxERlLSWxXNZy1Tcl+SJZVlQ0RDIewiHpnQRboD VV+CnzfE4IjVKk9cuS1s9qWl4zQV6lklXZgaq8AY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 6846D3892444 for ; Fri, 4 Jun 2021 21:43:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6846D3892444 Received: by mail-ot1-x333.google.com with SMTP id 66-20020a9d02c80000b02903615edf7c1aso10424840otl.13 for ; Fri, 04 Jun 2021 14:43:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=Aaicc/N2GANx0IaI0IdhbFZMqQM54k6dTkA6dZQ40cw=; b=jTElXbbPk4dUF3ceul5/y0xdA9Onb6QHsA0gLVFNp+X6Uo0gnqzOw3LNCHyT3sL+os eHJbmA+dRu4Crr9MD9E060x9YJYNjp4UgHavZJ7gamBRrhZTsTTdBQMUFnVXQzls1faY qdC7gOXxTIA3uCjIkIFbhbSJMbgAFsRShGY6pLRhK4wFtpGHYIg/Mf0rcOCGY8Nwnf8J KyNbOmIUMBnss8b0KNMJznZD3TGEeT2EPSageIZuV1cVn21YHz/ri5/LFsblK/YsnDqC Nffp6hnFlR4Ak/ELcyT19uo8DSSmUranFtyg8ic39AG3SncdESAICqXKn9gttEjq6S4e 2bJw== X-Gm-Message-State: AOAM533SQbGQl8TQ0nZayQYmnkzjQOCijwIQOo6+zpDhrtmde9b0jDi4 cx6Nkf49soxUbRsr/1SGasLsbYmEc+k= X-Google-Smtp-Source: ABdhPJyQjca5VulvqDeELB8M0G2xmxAIFAJxDxUszbe8cH8Jtyr8IkIHomy9uqWMYa+q1+Vzqn4J3A== X-Received: by 2002:a05:6830:19fd:: with SMTP id t29mr331915ott.296.1622842988800; Fri, 04 Jun 2021 14:43:08 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id t39sm687756ooi.42.2021.06.04.14.43.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:43:08 -0700 (PDT) Subject: [PATCH 9/13] v2 Use new per-location warning APIs in LTO To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: <59693cea-164e-bf51-d62a-096edcdb5218@gmail.com> Date: Fri, 4 Jun 2021 15:43:07 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch replaces the uses of TREE_NO_WARNING in the LTO front end with the new suppress_warning() API. It adds a couple of FIXMEs that I plan to take care of in a follow up. Add support for per-location warning groups. gcc/lto/ChangeLog: * gimple-streamer-out.c (output_gimple_stmt): Same. * lto-common.c (compare_tree_sccs_1): Expand use of TREE_NO_WARNING. * lto-streamer-out.c (hash_tree): Same. * tree-streamer-in.c (unpack_ts_base_value_fields): Same. * tree-streamer-out.c (pack_ts_base_value_fields): Same. diff --git a/gcc/gimple-streamer-out.c b/gcc/gimple-streamer-out.c index fcbf92300d4..7f7e06a79b8 100644 --- a/gcc/gimple-streamer-out.c +++ b/gcc/gimple-streamer-out.c @@ -73,7 +73,7 @@ output_gimple_stmt (struct output_block *ob, struct function *fn, gimple *stmt) /* Emit the tuple header. */ bp = bitpack_create (ob->main_stream); bp_pack_var_len_unsigned (&bp, gimple_num_ops (stmt)); - bp_pack_value (&bp, gimple_no_warning_p (stmt), 1); + bp_pack_value (&bp, warning_suppressed_p (stmt), 1); if (is_gimple_assign (stmt)) bp_pack_value (&bp, gimple_assign_nontemporal_move_p ( diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c index a26d4885800..f1809e60c1e 100644 --- a/gcc/lto-streamer-out.c +++ b/gcc/lto-streamer-out.c @@ -1207,7 +1207,7 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map *map, if (TYPE_P (t)) hstate.add_flag (TYPE_ARTIFICIAL (t)); else - hstate.add_flag (TREE_NO_WARNING (t)); + hstate.add_flag (warning_suppressed_p (t)); hstate.add_flag (TREE_NOTHROW (t)); hstate.add_flag (TREE_STATIC (t)); hstate.add_flag (TREE_PROTECTED (t)); diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c index bfe52a2e942..9e7ea877e66 100644 --- a/gcc/lto/lto-common.c +++ b/gcc/lto/lto-common.c @@ -1110,8 +1110,8 @@ compare_tree_sccs_1 (tree t1, tree t2, tree **map) compare_values (TYPE_UNSIGNED); if (TYPE_P (t1)) compare_values (TYPE_ARTIFICIAL); - else - compare_values (TREE_NO_WARNING); + else if (t1->base.nowarning_flag != t2->base.nowarning_flag) + return false; compare_values (TREE_NOTHROW); compare_values (TREE_STATIC); if (code != TREE_BINFO) diff --git a/gcc/tree-streamer-in.c b/gcc/tree-streamer-in.c index e0522bf2ac1..31dbf2fb992 100644 --- a/gcc/tree-streamer-in.c +++ b/gcc/tree-streamer-in.c @@ -131,7 +131,8 @@ unpack_ts_base_value_fields (struct bitpack_d *bp, tree expr) if (TYPE_P (expr)) TYPE_ARTIFICIAL (expr) = (unsigned) bp_unpack_value (bp, 1); else - TREE_NO_WARNING (expr) = (unsigned) bp_unpack_value (bp, 1); + /* FIXME: set all warning bits. */ + suppress_warning (expr, N_OPTS, (unsigned) bp_unpack_value (bp, 1)); TREE_NOTHROW (expr) = (unsigned) bp_unpack_value (bp, 1); TREE_STATIC (expr) = (unsigned) bp_unpack_value (bp, 1); if (TREE_CODE (expr) != TREE_BINFO) diff --git a/gcc/tree-streamer-out.c b/gcc/tree-streamer-out.c index 855d1cd59b9..b76e0c59c6f 100644 --- a/gcc/tree-streamer-out.c +++ b/gcc/tree-streamer-out.c @@ -104,7 +104,8 @@ pack_ts_base_value_fields (struct bitpack_d *bp, tree expr) if (TYPE_P (expr)) bp_pack_value (bp, TYPE_ARTIFICIAL (expr), 1); else - bp_pack_value (bp, TREE_NO_WARNING (expr), 1); + /* FIXME: pack all warning bits. */ + bp_pack_value (bp, warning_suppressed_p (expr), 1); bp_pack_value (bp, TREE_NOTHROW (expr), 1); bp_pack_value (bp, TREE_STATIC (expr), 1); if (TREE_CODE (expr) != TREE_BINFO) From patchwork Fri Jun 4 21:43:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488136 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=2620:52:3:1:0:246e:9693:128c; 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=fQMCeq7E; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Fxc1h32nMz9sPf for ; Sat, 5 Jun 2021 07:52:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D9D639A047F for ; Fri, 4 Jun 2021 21:52:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D9D639A047F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843542; bh=xOXRGKf2g0TUnOxHNdQO7O6i7hpabwG3QosieIUoMk0=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fQMCeq7Ev+0RNbrTS6dsabzU5oh/vKywX/sJGomRqcx8j9z+f6Ku2gfvJ8fuOdAe3 GrslGRf46oFvMfw8ExZE0X/Qh4xAjmOecjCnY4dtss8l89tNV1eIoy3d2P/oZamVe0 gJioJ6KsllMAWrRx8Ls3SyOQCnGtgSlD2kLOk48c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id C954339A1430 for ; Fri, 4 Jun 2021 21:43:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C954339A1430 Received: by mail-ot1-x32c.google.com with SMTP id 69-20020a9d0a4b0000b02902ed42f141e1so10502185otg.2 for ; Fri, 04 Jun 2021 14:43: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:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=xOXRGKf2g0TUnOxHNdQO7O6i7hpabwG3QosieIUoMk0=; b=Awzw8mEFbp+bf1M4oFIVqsOL8+6gBIWKJ/ZlCffwx86cNYKest2ZfcQJzu62EJNtm3 2qr8w+HwIPQipJ9OiDCLme9iUWi87e7B/myEj4+eCPajahhM7PNeXSQ7jskdW6bZ/ni+ T6egSfnjePNRj7E0+WBqDu615mrJzwpc2xCe8jgFNdLOwwadj2BtHc41GikPsPJUVFsV 6bf7r2K5jCv5iXI8V0qVhiCm7ONstBfQCzHtVYDmACbt3iu1+9xilVQvmeDwNcJI0RPB Hy6AN6O6vWdpfi1pQuXnCTNPX+we4KQoaP2z/T7NemCAkN0Gkce8a+YsRX32sYHbofl2 uAFw== X-Gm-Message-State: AOAM532OLzvKtE+0+bCx0xiRq7YPEdzXO24iwi3B1YNYGnO06m6bsGDj iFte7IGW2hkGVgq+vgp6rgaeO0MOznU= X-Google-Smtp-Source: ABdhPJyF6GQFLkl0Ho+Nt4pnfjwbVdUvKGKKbYfOnjm+bjeLzC839TUwi0G/AFRzREHoEeGrGDpM5g== X-Received: by 2002:a05:6830:20da:: with SMTP id z26mr4021810otq.175.1622843001200; Fri, 04 Jun 2021 14:43:21 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id w15sm754552oiw.34.2021.06.04.14.43.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:43:20 -0700 (PDT) Subject: [PATCH 10/13] v2 Use new per-location warning APIs in the middle end To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: Date: Fri, 4 Jun 2021 15:43:19 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_STOCKTIP, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch introduces declarations of the new suppress_warning(), warning_suppressed_p(), and copy_warning() APIs, and replaces the uses of TREE_NO_WARNING in the middle end with them. Add support for per-location warning groups. gcc/ChangeLog: * builtins.c (warn_string_no_nul): Replace uses of TREE_NO_WARNING, gimple_no_warning_p and gimple_set_no_warning with warning_suppressed_p, and suppress_warning. (c_strlen): Same. (maybe_warn_for_bound): Same. (warn_for_access): Same. (check_access): Same. (expand_builtin_strncmp): Same. (fold_builtin_varargs): Same. * calls.c (maybe_warn_nonstring_arg): Same. (maybe_warn_rdwr_sizes): Same. * cfgexpand.c (expand_call_stmt): Same. * cgraphunit.c (check_global_declaration): Same. * fold-const.c (fold_undefer_overflow_warnings): Same. (fold_truth_not_expr): Same. (fold_unary_loc): Same. (fold_checksum_tree): Same. * gengtype.c (open_base_files): Same. * gimple-array-bounds.cc (array_bounds_checker::check_array_ref): Same. (array_bounds_checker::check_mem_ref): Same. (array_bounds_checker::check_addr_expr): Same. (array_bounds_checker::check_array_bounds): Same. * gimple-expr.c (copy_var_decl): Same. * gimple-fold.c (gimple_fold_builtin_strcpy): Same. (gimple_fold_builtin_strncat): Same. (gimple_fold_builtin_stxcpy_chk): Same. (gimple_fold_builtin_stpcpy): Same. (gimple_fold_builtin_sprintf): Same. (fold_stmt_1): Same. * gimple-ssa-isolate-paths.c (diag_returned_locals): Same. * gimple-ssa-nonnull-compare.c (do_warn_nonnull_compare): Same. * gimple-ssa-sprintf.c (handle_printf_call): Same. * gimple-ssa-store-merging.c (imm_store_chain_info::output_merged_store): Same. * gimple-ssa-warn-restrict.c (maybe_diag_overlap): Same. (maybe_diag_access_bounds): Same. (check_call): Same. (check_bounds_or_overlap): Same. * gimple.c (gimple_build_call_from_tree): Same. * gimplify.c (gimplify_return_expr): Same. (gimplify_cond_expr): Same. (gimplify_modify_expr_complex_part): Same. (gimplify_modify_expr): Same. (gimple_push_cleanup): Same. (gimplify_expr): Same. * omp-expand.c (expand_omp_for_generic): Same. (expand_omp_taskloop_for_outer): Same. * omp-low.c (lower_rec_input_clauses): Same. (lower_lastprivate_clauses): Same. (lower_send_clauses): Same. (lower_omp_target): Same. * tree-cfg.c (pass_warn_function_return::execute): Same. * tree-complex.c (create_one_component_var): Same. * tree-inline.c (remap_gimple_op_r): Same. (copy_tree_body_r): Same. (declare_return_variable): Same. (expand_call_inline): Same. * tree-nested.c (lookup_field_for_decl): Same. * tree-sra.c (create_access_replacement): Same. (generate_subtree_copies): Same. * tree-ssa-ccp.c (pass_post_ipa_warn::execute): Same. * tree-ssa-forwprop.c (combine_cond_expr_cond): Same. * tree-ssa-loop-ch.c (ch_base::copy_headers): Same. * tree-ssa-loop-im.c (execute_sm): Same. * tree-ssa-phiopt.c (cond_store_replacement): Same. * tree-ssa-strlen.c (maybe_warn_overflow): Same. (handle_builtin_strcpy): Same. (maybe_diag_stxncpy_trunc): Same. (handle_builtin_stxncpy_strncat): Same. (handle_builtin_strcat): Same. * tree-ssa-uninit.c (get_no_uninit_warning): Same. (set_no_uninit_warning): Same. (uninit_undefined_value_p): Same. (warn_uninit): Same. (maybe_warn_operand): Same. * tree-vrp.c (compare_values_warnv): Same. * vr-values.c (vr_values::extract_range_for_var_from_comparison_expr): Same. (test_for_singularity): Same. * gimple.h (warning_suppressed_p): New function. (suppress_warning): Same. (copy_no_warning): Same. (gimple_set_block): Call gimple_set_location. (gimple_set_location): Call copy_warning. * tree.h (no_warning, all_warnings): New constants. (warning_suppressed_p): New function. (suppress_warning): Same. (copy_no_warning): Same. diff --git a/gcc/builtins.c b/gcc/builtins.c index af1fe49bb48..740fed69873 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -1095,7 +1095,9 @@ warn_string_no_nul (location_t loc, tree expr, const char *fname, bool exact /* = false */, const wide_int bndrng[2] /* = NULL */) { - if ((expr && TREE_NO_WARNING (expr)) || TREE_NO_WARNING (arg)) + const opt_code opt = OPT_Wstringop_overread; + if ((expr && warning_suppressed_p (expr, opt)) + || warning_suppressed_p (arg, opt)) return; loc = expansion_point_location_if_in_system_header (loc); @@ -1123,14 +1125,14 @@ warn_string_no_nul (location_t loc, tree expr, const char *fname, if (bndrng) { if (wi::ltu_p (maxsiz, bndrng[0])) - warned = warning_at (loc, OPT_Wstringop_overread, + warned = warning_at (loc, opt, "%K%qD specified bound %s exceeds " "maximum object size %E", expr, func, bndstr, maxobjsize); else { bool maybe = wi::to_wide (size) == bndrng[0]; - warned = warning_at (loc, OPT_Wstringop_overread, + warned = warning_at (loc, opt, exact ? G_("%K%qD specified bound %s exceeds " "the size %E of unterminated array") @@ -1145,7 +1147,7 @@ warn_string_no_nul (location_t loc, tree expr, const char *fname, } } else - warned = warning_at (loc, OPT_Wstringop_overread, + warned = warning_at (loc, opt, "%K%qD argument missing terminating nul", expr, func); } @@ -1154,14 +1156,14 @@ warn_string_no_nul (location_t loc, tree expr, const char *fname, if (bndrng) { if (wi::ltu_p (maxsiz, bndrng[0])) - warned = warning_at (loc, OPT_Wstringop_overread, + warned = warning_at (loc, opt, "%qs specified bound %s exceeds " "maximum object size %E", fname, bndstr, maxobjsize); else { bool maybe = wi::to_wide (size) == bndrng[0]; - warned = warning_at (loc, OPT_Wstringop_overread, + warned = warning_at (loc, opt, exact ? G_("%qs specified bound %s exceeds " "the size %E of unterminated array") @@ -1176,7 +1178,7 @@ warn_string_no_nul (location_t loc, tree expr, const char *fname, } } else - warned = warning_at (loc, OPT_Wstringop_overread, + warned = warning_at (loc, opt, "%qs argument missing terminating nul", fname); } @@ -1185,9 +1187,9 @@ warn_string_no_nul (location_t loc, tree expr, const char *fname, { inform (DECL_SOURCE_LOCATION (decl), "referenced argument declared here"); - TREE_NO_WARNING (arg) = 1; + suppress_warning (arg, opt); if (expr) - TREE_NO_WARNING (expr) = 1; + suppress_warning (expr, opt); } } @@ -1445,14 +1447,14 @@ c_strlen (tree arg, int only_value, c_strlen_data *data, unsigned eltsize) { /* Suppress multiple warnings for propagated constant strings. */ if (only_value != 2 - && !TREE_NO_WARNING (arg) + && !warning_suppressed_p (arg, OPT_Warray_bounds) && warning_at (loc, OPT_Warray_bounds, "offset %qwi outside bounds of constant string", eltoff)) { if (decl) inform (DECL_SOURCE_LOCATION (decl), "%qE declared here", decl); - TREE_NO_WARNING (arg) = 1; + suppress_warning (arg, OPT_Warray_bounds); } return NULL_TREE; } @@ -3947,10 +3949,10 @@ determine_block_size (tree len, rtx len_rtx, accessing an object with SIZE. */ static bool -maybe_warn_for_bound (int opt, location_t loc, tree exp, tree func, +maybe_warn_for_bound (opt_code opt, location_t loc, tree exp, tree func, tree bndrng[2], tree size, const access_data *pad = NULL) { - if (!bndrng[0] || TREE_NO_WARNING (exp)) + if (!bndrng[0] || warning_suppressed_p (exp, opt)) return false; tree maxobjsize = max_object_size (); @@ -4042,7 +4044,7 @@ maybe_warn_for_bound (int opt, location_t loc, tree exp, tree func, inform (EXPR_LOCATION (pad->src.ref), "source object allocated here"); } - TREE_NO_WARNING (exp) = true; + suppress_warning (exp, opt); } return warned; @@ -4089,14 +4091,14 @@ maybe_warn_for_bound (int opt, location_t loc, tree exp, tree func, return false; else if (tree_int_cst_equal (bndrng[0], bndrng[1])) warned = (func - ? warning_at (loc, OPT_Wstringop_overflow_, + ? warning_at (loc, opt, (maybe ? G_("%K%qD specified bound %E may exceed " "destination size %E") : G_("%K%qD specified bound %E exceeds " "destination size %E")), exp, func, bndrng[0], size) - : warning_at (loc, OPT_Wstringop_overflow_, + : warning_at (loc, opt, (maybe ? G_("%Kspecified bound %E may exceed " "destination size %E") @@ -4105,14 +4107,14 @@ maybe_warn_for_bound (int opt, location_t loc, tree exp, tree func, exp, bndrng[0], size)); else warned = (func - ? warning_at (loc, OPT_Wstringop_overflow_, + ? warning_at (loc, opt, (maybe ? G_("%K%qD specified bound [%E, %E] may exceed " "destination size %E") : G_("%K%qD specified bound [%E, %E] exceeds " "destination size %E")), exp, func, bndrng[0], bndrng[1], size) - : warning_at (loc, OPT_Wstringop_overflow_, + : warning_at (loc, opt, (maybe ? G_("%Kspecified bound [%E, %E] exceeds " "destination size %E") @@ -4131,7 +4133,7 @@ maybe_warn_for_bound (int opt, location_t loc, tree exp, tree func, inform (EXPR_LOCATION (pad->dst.ref), "destination object allocated here"); } - TREE_NO_WARNING (exp) = true; + suppress_warning (exp, opt); } return warned; @@ -4357,7 +4359,7 @@ warn_for_access (location_t loc, tree func, tree exp, int opt, tree range[2], exp, range[0], range[1], size)); if (warned) - TREE_NO_WARNING (exp) = true; + suppress_warning (exp, OPT_Wstringop_overread); return warned; } @@ -4400,7 +4402,7 @@ warn_for_access (location_t loc, tree func, tree exp, int opt, tree range[2], exp, range[0], range[1], size)); if (warned) - TREE_NO_WARNING (exp) = true; + suppress_warning (exp, OPT_Wstringop_overread); return warned; } @@ -4779,8 +4781,10 @@ check_access (tree exp, tree dstwrite, && tree_fits_uhwi_p (dstwrite) && tree_int_cst_lt (dstwrite, range[0])))) { - if (TREE_NO_WARNING (exp) - || (pad && pad->dst.ref && TREE_NO_WARNING (pad->dst.ref))) + const opt_code opt = OPT_Wstringop_overflow_; + if (warning_suppressed_p (exp, opt) + || (pad && pad->dst.ref + && warning_suppressed_p (pad->dst.ref, opt))) return false; location_t loc = tree_inlined_location (exp); @@ -4791,12 +4795,12 @@ check_access (tree exp, tree dstwrite, and a source of unknown length. The call will write at least one byte past the end of the destination. */ warned = (func - ? warning_at (loc, OPT_Wstringop_overflow_, + ? warning_at (loc, opt, "%K%qD writing %E or more bytes into " "a region of size %E overflows " "the destination", exp, func, range[0], dstsize) - : warning_at (loc, OPT_Wstringop_overflow_, + : warning_at (loc, opt, "%Kwriting %E or more bytes into " "a region of size %E overflows " "the destination", @@ -4817,7 +4821,7 @@ check_access (tree exp, tree dstwrite, if (warned) { - TREE_NO_WARNING (exp) = true; + suppress_warning (exp, OPT_Wstringop_overflow_); if (pad) pad->dst.inform_access (pad->mode); } @@ -4852,9 +4856,9 @@ check_access (tree exp, tree dstwrite, if (size != maxobjsize && tree_int_cst_lt (size, range[0])) { - int opt = (dstwrite || mode != access_read_only - ? OPT_Wstringop_overflow_ - : OPT_Wstringop_overread); + opt_code opt = (dstwrite || mode != access_read_only + ? OPT_Wstringop_overflow_ + : OPT_Wstringop_overread); maybe_warn_for_bound (opt, loc, exp, func, range, size, pad); return false; } @@ -4890,19 +4894,21 @@ check_access (tree exp, tree dstwrite, if (overread) { - if (TREE_NO_WARNING (exp) - || (srcstr && TREE_NO_WARNING (srcstr)) - || (pad && pad->src.ref && TREE_NO_WARNING (pad->src.ref))) + const opt_code opt = OPT_Wstringop_overread; + if (warning_suppressed_p (exp, opt) + || (srcstr && warning_suppressed_p (srcstr, opt)) + || (pad && pad->src.ref + && warning_suppressed_p (pad->src.ref, opt))) return false; location_t loc = tree_inlined_location (exp); const bool read = mode == access_read_only || mode == access_read_write; const bool maybe = pad && pad->dst.parmarray; - if (warn_for_access (loc, func, exp, OPT_Wstringop_overread, range, - slen, false, read, maybe)) + if (warn_for_access (loc, func, exp, opt, range, slen, false, read, + maybe)) { - TREE_NO_WARNING (exp) = true; + suppress_warning (exp, opt); if (pad) pad->src.inform_access (access_read_only); } @@ -7427,8 +7433,7 @@ expand_builtin_strncmp (tree exp, ATTRIBUTE_UNUSED rtx target, /* Expand the library call ourselves using a stabilized argument list to avoid re-evaluating the function's arguments twice. */ tree call = build_call_nofold_loc (loc, fndecl, 3, arg1, arg2, len); - if (TREE_NO_WARNING (exp)) - TREE_NO_WARNING (call) = true; + copy_warning (call, exp); gcc_assert (TREE_CODE (call) == CALL_EXPR); CALL_EXPR_TAILCALL (call) = CALL_EXPR_TAILCALL (exp); return expand_call (call, target, target == const0_rtx); @@ -13853,10 +13858,11 @@ maybe_emit_free_warning (tree exp) else { tree alloc_decl = gimple_call_fndecl (def_stmt); - int opt = (DECL_IS_OPERATOR_NEW_P (alloc_decl) - || DECL_IS_OPERATOR_DELETE_P (dealloc_decl) - ? OPT_Wmismatched_new_delete - : OPT_Wmismatched_dealloc); + const opt_code opt = + (DECL_IS_OPERATOR_NEW_P (alloc_decl) + || DECL_IS_OPERATOR_DELETE_P (dealloc_decl) + ? OPT_Wmismatched_new_delete + : OPT_Wmismatched_dealloc); warned = warning_at (loc, opt, "%K%qD called on pointer returned " "from a mismatched allocation " @@ -13967,7 +13973,7 @@ fold_builtin_varargs (location_t loc, tree fndecl, tree *args, int nargs) { ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret); SET_EXPR_LOCATION (ret, loc); - TREE_NO_WARNING (ret) = 1; + suppress_warning (ret); return ret; } return NULL_TREE; diff --git a/gcc/calls.c b/gcc/calls.c index a7c78ed9c16..bc6bc03d5d4 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -1623,7 +1623,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) if (!fndecl || !fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)) return false; - if (TREE_NO_WARNING (exp) || !warn_stringop_overread) + if (!warn_stringop_overread || warning_suppressed_p (exp, OPT_Wstringop_overread)) return false; /* Avoid clearly invalid calls (more checking done below). */ @@ -1739,7 +1739,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) exp, fndecl, bndrng[0], bndrng[1], maxobjsize); if (warned) - TREE_NO_WARNING (exp) = true; + suppress_warning (exp, OPT_Wstringop_overread); return warned; } @@ -1916,7 +1916,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) } if (any_arg_warned) - TREE_NO_WARNING (exp) = true; + suppress_warning (exp, OPT_Wstringop_overread); return any_arg_warned; } @@ -1979,7 +1979,7 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp) /* Set if a warning has been issued for any argument (used to decide whether to emit an informational note at the end). */ - bool any_warned = false; + opt_code opt_warned = N_OPTS; /* A string describing the attributes that the warnings issued by this function apply to. Used to print one informational note per function @@ -2054,7 +2054,7 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp) *sizstr = '\0'; /* Set if a warning has been issued for the current argument. */ - bool arg_warned = false; + opt_code arg_warned = N_OPTS; location_t loc = EXPR_LOCATION (exp); tree ptr = access.second.ptr; if (*sizstr @@ -2067,24 +2067,25 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp) const std::string argtypestr = access.second.array_as_string (ptrtype); - arg_warned = warning_at (loc, OPT_Wstringop_overflow_, - "%Kbound argument %i value %s is " - "negative for a variable length array " - "argument %i of type %s", - exp, sizidx + 1, sizstr, - ptridx + 1, argtypestr.c_str ()); + if (warning_at (loc, OPT_Wstringop_overflow_, + "%Kbound argument %i value %s is " + "negative for a variable length array " + "argument %i of type %s", + exp, sizidx + 1, sizstr, + ptridx + 1, argtypestr.c_str ())) + arg_warned = OPT_Wstringop_overflow_; } - else - arg_warned = warning_at (loc, OPT_Wstringop_overflow_, - "%Kargument %i value %s is negative", - exp, sizidx + 1, sizstr); + else if (warning_at (loc, OPT_Wstringop_overflow_, + "%Kargument %i value %s is negative", + exp, sizidx + 1, sizstr)) + arg_warned = OPT_Wstringop_overflow_; - if (arg_warned) + if (arg_warned != N_OPTS) { append_attrname (access, attrstr, sizeof attrstr); /* Remember a warning has been issued and avoid warning again below for the same attribute. */ - any_warned = true; + opt_warned = arg_warned; continue; } } @@ -2122,31 +2123,33 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp) const std::string argtypestr = access.second.array_as_string (ptrtype); - arg_warned = warning_at (loc, OPT_Wnonnull, - "%Kargument %i of variable length " - "array %s is null but " - "the corresponding bound argument " - "%i value is %s", - exp, sizidx + 1, argtypestr.c_str (), - ptridx + 1, sizstr); + if (warning_at (loc, OPT_Wnonnull, + "%Kargument %i of variable length " + "array %s is null but " + "the corresponding bound argument " + "%i value is %s", + exp, sizidx + 1, argtypestr.c_str (), + ptridx + 1, sizstr)) + arg_warned = OPT_Wnonnull; } - else - arg_warned = warning_at (loc, OPT_Wnonnull, - "%Kargument %i is null but " - "the corresponding size argument " - "%i value is %s", - exp, ptridx + 1, sizidx + 1, - sizstr); + else if (warning_at (loc, OPT_Wnonnull, + "%Kargument %i is null but " + "the corresponding size argument " + "%i value is %s", + exp, ptridx + 1, sizidx + 1, + sizstr)) + arg_warned = OPT_Wnonnull; } else if (access_size && access.second.static_p) { /* Warn about null pointers for [static N] array arguments but do not warn for ordinary (i.e., nonstatic) arrays. */ - arg_warned = warning_at (loc, OPT_Wnonnull, - "%Kargument %i to %<%T[static %E]%> " - "is null where non-null expected", - exp, ptridx + 1, argtype, - access_size); + if (warning_at (loc, OPT_Wnonnull, + "%Kargument %i to %<%T[static %E]%> " + "is null where non-null expected", + exp, ptridx + 1, argtype, + access_size)) + arg_warned = OPT_Wnonnull; } if (arg_warned) @@ -2154,7 +2157,7 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp) append_attrname (access, attrstr, sizeof attrstr); /* Remember a warning has been issued and avoid warning again below for the same attribute. */ - any_warned = true; + opt_warned = OPT_Wnonnull; continue; } } @@ -2190,17 +2193,17 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp) /* Clear the no-warning bit in case it was set by check_access in a prior iteration so that accesses via different arguments are diagnosed. */ - TREE_NO_WARNING (exp) = false; + suppress_warning (exp, OPT_Wstringop_overflow_, false); access_mode mode = data.mode; if (mode == access_deferred) mode = TYPE_READONLY (argtype) ? access_read_only : access_read_write; check_access (exp, access_size, /*maxread=*/ NULL_TREE, srcsize, dstsize, mode, &data); - if (TREE_NO_WARNING (exp)) + if (warning_suppressed_p (exp, OPT_Wstringop_overflow_)) + opt_warned = OPT_Wstringop_overflow_; + if (opt_warned != N_OPTS) { - any_warned = true; - if (access.second.internal_p) inform (loc, "referencing argument %u of type %qT", ptridx + 1, ptrtype); @@ -2222,7 +2225,7 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp) "in a call with type %qT and attribute %qs", fntype, attrstr); } - else if (any_warned) + else if (opt_warned != N_OPTS) { if (fndecl) inform (DECL_SOURCE_LOCATION (fndecl), @@ -2233,7 +2236,8 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp) } /* Set the bit in case if was cleared and not set above. */ - TREE_NO_WARNING (exp) = true; + if (opt_warned != N_OPTS) + suppress_warning (exp, opt_warned); } /* Fill in ARGS_SIZE and ARGS array based on the parameters found in diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 39e5b040427..92be5e044e9 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -2807,9 +2807,6 @@ expand_call_stmt (gcall *stmt) if (gimple_call_nothrow_p (stmt)) TREE_NOTHROW (exp) = 1; - if (gimple_no_warning_p (stmt)) - TREE_NO_WARNING (exp) = 1; - CALL_EXPR_TAILCALL (exp) = gimple_call_tail_p (stmt); CALL_EXPR_MUST_TAIL_CALL (exp) = gimple_call_must_tail_p (stmt); CALL_EXPR_RETURN_SLOT_OPT (exp) = gimple_call_return_slot_opt_p (stmt); @@ -2823,6 +2820,9 @@ expand_call_stmt (gcall *stmt) CALL_EXPR_BY_DESCRIPTOR (exp) = gimple_call_by_descriptor_p (stmt); SET_EXPR_LOCATION (exp, gimple_location (stmt)); + /* Must come after copying location. */ + copy_warning (exp, stmt); + /* Ensure RTL is created for debug args. */ if (decl && DECL_HAS_DEBUG_ARGS_P (decl)) { diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 098eb99dc95..55cb0347149 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -1074,7 +1074,7 @@ check_global_declaration (symtab_node *snode) && ! DECL_ARTIFICIAL (decl) && ! TREE_PUBLIC (decl)) { - if (TREE_NO_WARNING (decl)) + if (warning_suppressed_p (decl, OPT_Wunused)) ; else if (snode->referred_to_p (/*include_self=*/false)) pedwarn (input_location, 0, "%q+F used but never defined", decl); diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 33d64bfbbe8..8acc2c09b19 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -250,7 +250,7 @@ fold_undefer_overflow_warnings (bool issue, const gimple *stmt, int code) if (!issue || warnmsg == NULL) return; - if (gimple_no_warning_p (stmt)) + if (warning_suppressed_p (stmt, OPT_Wstrict_overflow)) return; /* Use the smallest code level when deciding to issue the @@ -4250,8 +4250,7 @@ fold_truth_not_expr (location_t loc, tree arg) tree ret = build2_loc (loc, code, type, TREE_OPERAND (arg, 0), TREE_OPERAND (arg, 1)); - if (TREE_NO_WARNING (arg)) - TREE_NO_WARNING (ret) = 1; + copy_warning (ret, arg); return ret; } @@ -9342,7 +9341,7 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0) tem = fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 1)); /* First do the assignment, then return converted constant. */ tem = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (tem), op0, tem); - TREE_NO_WARNING (tem) = 1; + suppress_warning (tem /* What warning? */); TREE_USED (tem) = 1; return tem; } @@ -13515,10 +13514,10 @@ fold_checksum_tree (const_tree expr, struct md5_ctx *ctx, TYPE_CACHED_VALUES (tmp) = NULL; } } - else if (TREE_NO_WARNING (expr) && (DECL_P (expr) || EXPR_P (expr))) + else if (warning_suppressed_p (expr) && (DECL_P (expr) || EXPR_P (expr))) { - /* Allow TREE_NO_WARNING to be set. Perhaps we shouldn't allow that - and change builtins.c etc. instead - see PR89543. */ + /* Allow the no-warning bit to be set. Perhaps we shouldn't allow + that and change builtins.c etc. instead - see PR89543. */ size_t sz = tree_size (expr); buf = XALLOCAVAR (union tree_node, sz); memcpy ((char *) buf, expr, sz); diff --git a/gcc/gengtype.c b/gcc/gengtype.c index b94e2f126ec..c1fa6d35c87 100644 --- a/gcc/gengtype.c +++ b/gcc/gengtype.c @@ -1727,7 +1727,7 @@ open_base_files (void) "target-globals.h", "ipa-ref.h", "cgraph.h", "symbol-summary.h", "ipa-prop.h", "ipa-fnsummary.h", "dwarf2out.h", "omp-general.h", "omp-offload.h", "ipa-modref-tree.h", "ipa-modref.h", "symtab-thunks.h", - "symtab-clones.h", + "symtab-clones.h", "diagnostic-spec.h", NULL }; const char *const *ifp; diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc index 199d9f5d216..13f08685f8f 100644 --- a/gcc/gimple-array-bounds.cc +++ b/gcc/gimple-array-bounds.cc @@ -175,7 +175,7 @@ bool array_bounds_checker::check_array_ref (location_t location, tree ref, bool ignore_off_by_one) { - if (TREE_NO_WARNING (ref)) + if (warning_suppressed_p (ref, OPT_Warray_bounds)) /* Return true to have the caller prevent warnings for enclosing refs. */ return true; @@ -346,7 +346,7 @@ array_bounds_checker::check_array_ref (location_t location, tree ref, /* Avoid more warnings when checking more significant subscripts of the same expression. */ ref = TREE_OPERAND (ref, 0); - TREE_NO_WARNING (ref) = 1; + suppress_warning (ref, OPT_Warray_bounds); if (decl) ref = decl; @@ -411,7 +411,7 @@ bool array_bounds_checker::check_mem_ref (location_t location, tree ref, bool ignore_off_by_one) { - if (TREE_NO_WARNING (ref)) + if (warning_suppressed_p (ref, OPT_Warray_bounds)) return false; tree arg = TREE_OPERAND (ref, 0); @@ -770,7 +770,7 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref, } } - TREE_NO_WARNING (ref) = 1; + suppress_warning (ref, OPT_Warray_bounds); return true; } @@ -787,7 +787,7 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref, "intermediate array offset %wi is outside array bounds " "of %qT", tmpidx, reftype)) { - TREE_NO_WARNING (ref) = 1; + suppress_warning (ref, OPT_Warray_bounds); return true; } } @@ -818,7 +818,7 @@ array_bounds_checker::check_addr_expr (location_t location, tree t) warned = check_mem_ref (location, t, ignore_off_by_one); if (warned) - TREE_NO_WARNING (t) = true; + suppress_warning (t, OPT_Warray_bounds); t = TREE_OPERAND (t, 0); } @@ -826,7 +826,7 @@ array_bounds_checker::check_addr_expr (location_t location, tree t) if (TREE_CODE (t) != MEM_REF || TREE_CODE (TREE_OPERAND (t, 0)) != ADDR_EXPR - || TREE_NO_WARNING (t)) + || warning_suppressed_p (t, OPT_Warray_bounds)) return; tree tem = TREE_OPERAND (TREE_OPERAND (t, 0), 0); @@ -886,7 +886,7 @@ array_bounds_checker::check_addr_expr (location_t location, tree t) if (DECL_P (t)) inform (DECL_SOURCE_LOCATION (t), "while referencing %qD", t); - TREE_NO_WARNING (t) = 1; + suppress_warning (t, OPT_Warray_bounds); } } @@ -980,9 +980,10 @@ array_bounds_checker::check_array_bounds (tree *tp, int *walk_subtree, See pr98266 and pr97595. */ *walk_subtree = false; - /* Propagate the no-warning bit to the outer expression. */ + /* Propagate the no-warning bit to the outer statement to avoid also + issuing -Wstringop-overflow/-overread for the out-of-bounds accesses. */ if (warned) - TREE_NO_WARNING (t) = true; + suppress_warning (wi->stmt, OPT_Warray_bounds); return NULL_TREE; } diff --git a/gcc/gimple-expr.c b/gcc/gimple-expr.c index c3211795d33..a2563a45c37 100644 --- a/gcc/gimple-expr.c +++ b/gcc/gimple-expr.c @@ -377,7 +377,6 @@ copy_var_decl (tree var, tree name, tree type) DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (var); DECL_IGNORED_P (copy) = DECL_IGNORED_P (var); DECL_CONTEXT (copy) = DECL_CONTEXT (var); - TREE_NO_WARNING (copy) = TREE_NO_WARNING (var); TREE_USED (copy) = 1; DECL_SEEN_IN_BIND_EXPR_P (copy) = 1; DECL_ATTRIBUTES (copy) = DECL_ATTRIBUTES (var); @@ -387,6 +386,7 @@ copy_var_decl (tree var, tree name, tree type) DECL_USER_ALIGN (copy) = 1; } + copy_warning (copy, var); return copy; } diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 1c0e930aba5..68031538145 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -2044,7 +2044,7 @@ gimple_fold_builtin_strcpy (gimple_stmt_iterator *gsi, not point to objects and so do not indicate an overlap; such calls could be the result of sanitization and jump threading). */ - if (!integer_zerop (dest) && !gimple_no_warning_p (stmt)) + if (!integer_zerop (dest) && !warning_suppressed_p (stmt, OPT_Wrestrict)) { tree func = gimple_call_fndecl (stmt); @@ -2071,9 +2071,9 @@ gimple_fold_builtin_strcpy (gimple_stmt_iterator *gsi, if (nonstr) { /* Avoid folding calls with unterminated arrays. */ - if (!gimple_no_warning_p (stmt)) + if (!warning_suppressed_p (stmt, OPT_Wstringop_overread)) warn_string_no_nul (loc, NULL_TREE, "strcpy", src, nonstr); - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, OPT_Wstringop_overread); return false; } @@ -2481,7 +2481,7 @@ gimple_fold_builtin_strncat (gimple_stmt_iterator *gsi) unsigned HOST_WIDE_INT dstsize; - bool nowarn = gimple_no_warning_p (stmt); + bool nowarn = warning_suppressed_p (stmt, OPT_Wstringop_overflow_); if (!nowarn && compute_builtin_object_size (dst, 1, &dstsize)) { @@ -2504,7 +2504,7 @@ gimple_fold_builtin_strncat (gimple_stmt_iterator *gsi) "destination size %wu"), stmt, fndecl, len, dstsize); if (nowarn) - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, OPT_Wstringop_overflow_); } } @@ -2520,7 +2520,7 @@ gimple_fold_builtin_strncat (gimple_stmt_iterator *gsi) if (warning_at (loc, OPT_Wstringop_overflow_, "%G%qD specified bound %E equals source length", stmt, fndecl, len)) - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, OPT_Wstringop_overflow_); } tree fn = builtin_decl_implicit (BUILT_IN_STRCAT); @@ -3105,7 +3105,8 @@ gimple_fold_builtin_stxcpy_chk (gimple_stmt_iterator *gsi, not point to objects and so do not indicate an overlap; such calls could be the result of sanitization and jump threading). */ - if (!integer_zerop (dest) && !gimple_no_warning_p (stmt)) + if (!integer_zerop (dest) + && !warning_suppressed_p (stmt, OPT_Wrestrict)) { tree func = gimple_call_fndecl (stmt); @@ -3288,10 +3289,10 @@ gimple_fold_builtin_stpcpy (gimple_stmt_iterator *gsi) if (data.decl) { /* Avoid folding calls with unterminated arrays. */ - if (!gimple_no_warning_p (stmt)) + if (!warning_suppressed_p (stmt, OPT_Wstringop_overread)) warn_string_no_nul (loc, NULL_TREE, "stpcpy", src, data.decl, size, exact); - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, OPT_Wstringop_overread); return false; } @@ -3554,8 +3555,7 @@ gimple_fold_builtin_sprintf (gimple_stmt_iterator *gsi) /* Propagate the NO_WARNING bit to avoid issuing the same warning more than once. */ - if (gimple_no_warning_p (stmt)) - gimple_set_no_warning (repl, true); + copy_warning (repl, stmt); gimple_seq_add_stmt_without_update (&stmts, repl); if (tree lhs = gimple_call_lhs (stmt)) @@ -3606,8 +3606,7 @@ gimple_fold_builtin_sprintf (gimple_stmt_iterator *gsi) /* Propagate the NO_WARNING bit to avoid issuing the same warning more than once. */ - if (gimple_no_warning_p (stmt)) - gimple_set_no_warning (repl, true); + copy_warning (repl, stmt); gimple_seq_add_stmt_without_update (&stmts, repl); if (tree lhs = gimple_call_lhs (stmt)) @@ -6065,7 +6064,7 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, bool inplace, tree (*valueize) (tree)) { bool changed = false; gimple *stmt = gsi_stmt (*gsi); - bool nowarning = gimple_no_warning_p (stmt); + bool nowarning = warning_suppressed_p (stmt, OPT_Wstrict_overflow); unsigned i; fold_defer_overflow_warnings (); diff --git a/gcc/gimple-ssa-isolate-paths.c b/gcc/gimple-ssa-isolate-paths.c index eb23cd41f4b..2dafe849ad3 100644 --- a/gcc/gimple-ssa-isolate-paths.c +++ b/gcc/gimple-ssa-isolate-paths.c @@ -400,6 +400,11 @@ diag_returned_locals (bool maybe, const locmap_t &locmap) gimple *stmt = (*it).first; const args_loc_t &argsloc = (*it).second; location_t stmtloc = gimple_location (stmt); + if (stmtloc == UNKNOWN_LOCATION) + /* When multiple return statements are merged into one it + may not have an associated location. Use the location + of the closing brace instead. */ + stmtloc = cfun->function_end_locus; auto_diagnostic_group d; unsigned nargs = argsloc.locvec.length (); diff --git a/gcc/gimple-ssa-nonnull-compare.c b/gcc/gimple-ssa-nonnull-compare.c index 9d7894633dc..f2757b66b28 100644 --- a/gcc/gimple-ssa-nonnull-compare.c +++ b/gcc/gimple-ssa-nonnull-compare.c @@ -97,7 +97,7 @@ do_warn_nonnull_compare (function *fun, tree arg) if (op && (POINTER_TYPE_P (TREE_TYPE (arg)) ? integer_zerop (op) : integer_minus_onep (op)) - && !gimple_no_warning_p (stmt)) + && !warning_suppressed_p (stmt, OPT_Wnonnull_compare)) warning_at (loc, OPT_Wnonnull_compare, "% argument %qD compared to NULL", arg); } diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c index fc744669e4b..41e3be6f9f4 100644 --- a/gcc/gimple-ssa-sprintf.c +++ b/gcc/gimple-ssa-sprintf.c @@ -330,7 +330,8 @@ get_format_string (tree format, location_t *ploc) static bool ATTRIBUTE_GCC_DIAG (5, 6) fmtwarn (const substring_loc &fmt_loc, location_t param_loc, - const char *corrected_substring, int opt, const char *gmsgid, ...) + const char *corrected_substring, opt_code opt, + const char *gmsgid, ...) { format_string_diagnostic_t diag (fmt_loc, NULL, param_loc, NULL, corrected_substring); @@ -345,7 +346,8 @@ fmtwarn (const substring_loc &fmt_loc, location_t param_loc, static bool ATTRIBUTE_GCC_DIAG (6, 8) ATTRIBUTE_GCC_DIAG (7, 8) fmtwarn_n (const substring_loc &fmt_loc, location_t param_loc, - const char *corrected_substring, int opt, unsigned HOST_WIDE_INT n, + const char *corrected_substring, opt_code opt, + unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid, ...) { format_string_diagnostic_t diag (fmt_loc, NULL, param_loc, NULL, @@ -921,7 +923,7 @@ struct call_info } /* Return the warning option corresponding to the called function. */ - int warnopt () const + opt_code warnopt () const { return bounded ? OPT_Wformat_truncation_ : OPT_Wformat_overflow_; } @@ -4680,7 +4682,7 @@ handle_printf_call (gimple_stmt_iterator *gsi, pointer_query &ptr_qry) bool success = compute_format_length (info, &res, ptr_qry.rvals); if (res.warned) - gimple_set_no_warning (info.callstmt, true); + suppress_warning (info.callstmt, info.warnopt ()); /* When optimizing and the printf return value optimization is enabled, attempt to substitute the computed result for the return value of diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index 123c92d9b44..a9694ddd598 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -4348,10 +4348,12 @@ imm_store_chain_info::output_merged_store (merged_store_group *group) MR_DEPENDENCE_BASE (ops[j]) = base; } if (!integer_zerop (mask)) - /* The load might load some bits (that will be masked off - later on) uninitialized, avoid -W*uninitialized - warnings in that case. */ - TREE_NO_WARNING (ops[j]) = 1; + { + /* The load might load some bits (that will be masked + off later on) uninitialized, avoid -W*uninitialized + warnings in that case. */ + suppress_warning (ops[j], OPT_Wuninitialized); + } stmt = gimple_build_assign (make_ssa_name (dest_type), ops[j]); gimple_set_location (stmt, load_loc); @@ -4533,7 +4535,7 @@ imm_store_chain_info::output_merged_store (merged_store_group *group) provably uninitialized (no stores at all yet or previous store a CLOBBER) we'd optimize away the load and replace it e.g. with 0. */ - TREE_NO_WARNING (load_src) = 1; + suppress_warning (load_src, OPT_Wuninitialized); stmt = gimple_build_assign (tem, load_src); gimple_set_location (stmt, loc); gimple_set_vuse (stmt, new_vuse); diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c index c8c9f9581a8..02771e4cd60 100644 --- a/gcc/gimple-ssa-warn-restrict.c +++ b/gcc/gimple-ssa-warn-restrict.c @@ -1431,7 +1431,7 @@ maybe_diag_overlap (location_t loc, gimple *call, builtin_access &acs) if (!acs.overlap ()) return false; - if (gimple_no_warning_p (call)) + if (warning_suppressed_p (call, OPT_Wrestrict)) return true; /* For convenience. */ @@ -1680,10 +1680,11 @@ maybe_diag_overlap (location_t loc, gimple *call, builtin_access &acs) be issued, false otherwise. Both initial values of the offsets and their final value computed by the function by incrementing the initial value by the size are - validated. Return true if the offsets are not valid and a diagnostic - has been issued, or would have been issued if DO_WARN had been true. */ + validated. Return the warning number if the offsets are not valid + and a diagnostic has been issued, or would have been issued if + DO_WARN had been true, otherwise an invalid warning number. */ -static bool +static opt_code maybe_diag_access_bounds (gimple *call, tree func, int strict, const builtin_memref &ref, offset_int wroff, bool do_warn) @@ -1695,28 +1696,31 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, since the result is used to make codegen decisions. */ if (ref.sizrange[0] > maxobjsize) { + const opt_code opt = OPT_Wstringop_overflow_; /* Return true without issuing a warning. */ if (!do_warn) - return true; + return opt; - if (ref.ref && TREE_NO_WARNING (ref.ref)) - return false; + if (ref.ref && warning_suppressed_p (ref.ref, OPT_Wstringop_overflow_)) + return no_warning; + bool warned = false; if (warn_stringop_overflow) { if (ref.sizrange[0] == ref.sizrange[1]) - return warning_at (loc, OPT_Wstringop_overflow_, - "%G%qD specified bound %wu " - "exceeds maximum object size %wu", - call, func, ref.sizrange[0].to_uhwi (), - maxobjsize.to_uhwi ()); - - return warning_at (loc, OPT_Wstringop_overflow_, - "%G%qD specified bound between %wu and %wu " - "exceeds maximum object size %wu", - call, func, ref.sizrange[0].to_uhwi (), - ref.sizrange[1].to_uhwi (), - maxobjsize.to_uhwi ()); + warned = warning_at (loc, opt, + "%G%qD specified bound %wu " + "exceeds maximum object size %wu", + call, func, ref.sizrange[0].to_uhwi (), + maxobjsize.to_uhwi ()); + else + warned = warning_at (loc, opt, + "%G%qD specified bound between %wu and %wu " + "exceeds maximum object size %wu", + call, func, ref.sizrange[0].to_uhwi (), + ref.sizrange[1].to_uhwi (), + maxobjsize.to_uhwi ()); + return warned ? opt : no_warning; } } @@ -1729,18 +1733,19 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, offset_int ooboff[] = { ref.offrange[0], ref.offrange[1], wroff }; tree oobref = ref.offset_out_of_bounds (strict, ooboff); if (!oobref) - return false; + return no_warning; + const opt_code opt = OPT_Warray_bounds; /* Return true without issuing a warning. */ if (!do_warn) - return true; + return opt; if (!warn_array_bounds) - return false; + return no_warning; - if (TREE_NO_WARNING (ref.ptr) - || (ref.ref && TREE_NO_WARNING (ref.ref))) - return false; + if (warning_suppressed_p (ref.ptr, opt) + || (ref.ref && warning_suppressed_p (ref.ref, opt))) + return no_warning; char rangestr[2][64]; if (ooboff[0] == ooboff[1] @@ -1770,7 +1775,7 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, && TREE_CODE (type = TREE_TYPE (ref.base)) == ARRAY_TYPE) { auto_diagnostic_group d; - if (warning_at (loc, OPT_Warray_bounds, + if (warning_at (loc, opt, "%G%qD pointer overflow between offset %s " "and size %s accessing array %qD with type %qT", call, func, rangestr[0], rangestr[1], ref.base, type)) @@ -1780,13 +1785,13 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, warned = true; } else - warned = warning_at (loc, OPT_Warray_bounds, + warned = warning_at (loc, opt, "%G%qD pointer overflow between offset %s " "and size %s", call, func, rangestr[0], rangestr[1]); } else - warned = warning_at (loc, OPT_Warray_bounds, + warned = warning_at (loc, opt, "%G%qD pointer overflow between offset %s " "and size %s", call, func, rangestr[0], rangestr[1]); @@ -1802,7 +1807,7 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, { auto_diagnostic_group d; if ((ref.basesize < maxobjsize - && warning_at (loc, OPT_Warray_bounds, + && warning_at (loc, opt, form ? G_("%G%qD forming offset %s is out of " "the bounds [0, %wu] of object %qD with " @@ -1811,7 +1816,7 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, "[0, %wu] of object %qD with type %qT"), call, func, rangestr[0], ref.basesize.to_uhwi (), ref.base, TREE_TYPE (ref.base))) - || warning_at (loc, OPT_Warray_bounds, + || warning_at (loc, opt, form ? G_("%G%qD forming offset %s is out of " "the bounds of object %qD with type %qT") @@ -1826,7 +1831,7 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, } } else if (ref.basesize < maxobjsize) - warned = warning_at (loc, OPT_Warray_bounds, + warned = warning_at (loc, opt, form ? G_("%G%qD forming offset %s is out " "of the bounds [0, %wu]") @@ -1834,7 +1839,7 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, "of the bounds [0, %wu]"), call, func, rangestr[0], ref.basesize.to_uhwi ()); else - warned = warning_at (loc, OPT_Warray_bounds, + warned = warning_at (loc, opt, form ? G_("%G%qD forming offset %s is out of bounds") : G_("%G%qD offset %s is out of bounds"), @@ -1848,7 +1853,7 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, type = TREE_TYPE (type); type = TYPE_MAIN_VARIANT (type); - if (warning_at (loc, OPT_Warray_bounds, + if (warning_at (loc, opt, "%G%qD offset %s from the object at %qE is out " "of the bounds of %qT", call, func, rangestr[0], ref.base, type)) @@ -1866,7 +1871,7 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, tree refop = TREE_OPERAND (ref.ref, 0); tree type = TYPE_MAIN_VARIANT (TREE_TYPE (ref.ref)); - if (warning_at (loc, OPT_Warray_bounds, + if (warning_at (loc, opt, "%G%qD offset %s from the object at %qE is out " "of the bounds of referenced subobject %qD with " "type %qT at offset %wi", @@ -1883,7 +1888,7 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict, } } - return warned; + return warned ? opt : no_warning; } /* Check a CALL statement for restrict-violations and issue warnings @@ -1894,7 +1899,7 @@ check_call (range_query *query, gimple *call) { /* Avoid checking the call if it has already been diagnosed for some reason. */ - if (gimple_no_warning_p (call)) + if (warning_suppressed_p (call, OPT_Wrestrict)) return; tree func = gimple_call_fndecl (call); @@ -1980,11 +1985,10 @@ check_call (range_query *query, gimple *call) || (dstwr && !INTEGRAL_TYPE_P (TREE_TYPE (dstwr)))) return; - if (!check_bounds_or_overlap (query, call, dst, src, dstwr, NULL_TREE)) - return; - + opt_code opt = check_bounds_or_overlap (query, call, dst, src, dstwr, + NULL_TREE); /* Avoid diagnosing the call again. */ - gimple_set_no_warning (call, true); + suppress_warning (call, opt); } } /* anonymous namespace */ @@ -1996,7 +2000,7 @@ check_call (range_query *query, gimple *call) without issue a warning. Return the OPT_Wxxx constant corresponding to the warning if one has been detected and zero otherwise. */ -int +opt_code check_bounds_or_overlap (gimple *call, tree dst, tree src, tree dstsize, tree srcsize, bool bounds_only /* = false */, bool do_warn /* = true */) @@ -2006,7 +2010,7 @@ check_bounds_or_overlap (gimple *call, tree dst, tree src, tree dstsize, bounds_only, do_warn); } -int +opt_code check_bounds_or_overlap (range_query *query, gimple *call, tree dst, tree src, tree dstsize, tree srcsize, bool bounds_only /* = false */, @@ -2032,16 +2036,20 @@ check_bounds_or_overlap (range_query *query, /* Validate offsets to each reference before the access first to make sure they are within the bounds of the destination object if its size is known, or PTRDIFF_MAX otherwise. */ - if (maybe_diag_access_bounds (call, func, strict, dstref, wroff, do_warn) - || maybe_diag_access_bounds (call, func, strict, srcref, 0, do_warn)) + opt_code opt + = maybe_diag_access_bounds (call, func, strict, dstref, wroff, do_warn); + if (opt == no_warning) + opt = maybe_diag_access_bounds (call, func, strict, srcref, 0, do_warn); + + if (opt != no_warning) { if (do_warn) - gimple_set_no_warning (call, true); - return OPT_Warray_bounds; + suppress_warning (call, opt); + return opt; } if (!warn_restrict || bounds_only || !src) - return 0; + return no_warning; if (!bounds_only) { @@ -2051,7 +2059,7 @@ check_bounds_or_overlap (range_query *query, case BUILT_IN_MEMMOVE_CHK: case BUILT_IN_MEMSET: case BUILT_IN_MEMSET_CHK: - return 0; + return no_warning; default: break; } @@ -2064,26 +2072,26 @@ check_bounds_or_overlap (range_query *query, not point to objects and so do not indicate an overlap; such calls could be the result of sanitization and jump threading). */ - if (!integer_zerop (dst) && !gimple_no_warning_p (call)) + if (!integer_zerop (dst) && !warning_suppressed_p (call, OPT_Wrestrict)) { warning_at (loc, OPT_Wrestrict, "%G%qD source argument is the same as destination", call, func); - gimple_set_no_warning (call, true); + suppress_warning (call, OPT_Wrestrict); return OPT_Wrestrict; } - return 0; + return no_warning; } /* Return false when overlap has been detected. */ if (maybe_diag_overlap (loc, call, acs)) { - gimple_set_no_warning (call, true); + suppress_warning (call, OPT_Wrestrict); return OPT_Wrestrict; } - return 0; + return no_warning; } gimple_opt_pass * diff --git a/gcc/gimple.c b/gcc/gimple.c index f1044e9c630..60a90667e4b 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -399,7 +399,7 @@ gimple_build_call_from_tree (tree t, tree fnptrtype) gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t)); gimple_call_set_nothrow (call, TREE_NOTHROW (t)); gimple_call_set_by_descriptor (call, CALL_EXPR_BY_DESCRIPTOR (t)); - gimple_set_no_warning (call, TREE_NO_WARNING (t)); + copy_warning (call, t); if (fnptrtype) { diff --git a/gcc/gimple.h b/gcc/gimple.h index 91b92b4a4d1..ca5d4acfc71 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -1634,6 +1634,24 @@ extern bool gimple_inexpensive_call_p (gcall *); extern bool stmt_can_terminate_bb_p (gimple *); extern location_t gimple_or_expr_nonartificial_location (gimple *, tree); +/* Return the disposition for a warning (or all warnings by default) + for a statement. */ +extern bool warning_suppressed_p (const gimple *, opt_code = all_warnings) + ATTRIBUTE_NONNULL (1); +/* Set the disposition for a warning (or all warnings by default) + at a location to enabled by default. */ +extern void suppress_warning (gimple *, opt_code = all_warnings, + bool = true) ATTRIBUTE_NONNULL (1); + +/* Copy the warning disposition mapping from one statement to another. */ +extern void copy_warning (gimple *, const gimple *) + ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2); +/* Copy the warning disposition mapping from an expression to a statement. */ +extern void copy_warning (gimple *, const_tree) + ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2); +/* Copy the warning disposition mapping from a statement to an expression. */ +extern void copy_warning (tree, const gimple *) + ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2); /* Formal (expression) temporary table handling: multiple occurrences of the same scalar expression are evaluated into the same temporary. */ @@ -1854,16 +1872,17 @@ gimple_block (const gimple *g) return LOCATION_BLOCK (g->location); } +/* Forward declare. */ +static inline void gimple_set_location (gimple *, location_t); /* Set BLOCK to be the lexical scope block holding statement G. */ static inline void gimple_set_block (gimple *g, tree block) { - g->location = set_block (g->location, block); + gimple_set_location (g, set_block (g->location, block)); } - /* Return location information for statement G. */ static inline location_t @@ -1886,6 +1905,8 @@ gimple_location_safe (const gimple *g) static inline void gimple_set_location (gimple *g, location_t location) { + /* Copy the no-warning data to the statement location. */ + copy_warning (location, g->location); g->location = location; } diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 39f5b973d18..e26c8106cfa 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1599,7 +1599,7 @@ gimplify_return_expr (tree stmt, gimple_seq *pre_p) { maybe_add_early_return_predict_stmt (pre_p); greturn *ret = gimple_build_return (ret_expr); - gimple_set_no_warning (ret, TREE_NO_WARNING (stmt)); + copy_warning (ret, stmt); gimplify_seq_add_stmt (pre_p, ret); return GS_ALL_DONE; } @@ -1661,7 +1661,7 @@ gimplify_return_expr (tree stmt, gimple_seq *pre_p) we can wind up warning about an uninitialized value for this. Due to how this variable is constructed and initialized, this is never true. Give up and never warn. */ - TREE_NO_WARNING (result) = 1; + suppress_warning (result, OPT_Wuninitialized); gimplify_ctxp->return_temp = result; } @@ -1675,7 +1675,7 @@ gimplify_return_expr (tree stmt, gimple_seq *pre_p) maybe_add_early_return_predict_stmt (pre_p); ret = gimple_build_return (result); - gimple_set_no_warning (ret, TREE_NO_WARNING (stmt)); + copy_warning (ret, stmt); gimplify_seq_add_stmt (pre_p, ret); return GS_ALL_DONE; @@ -4250,7 +4250,8 @@ gimplify_cond_expr (tree *expr_p, gimple_seq *pre_p, fallback_t fallback) &arm2); cond_stmt = gimple_build_cond (pred_code, arm1, arm2, label_true, label_false); - gimple_set_no_warning (cond_stmt, TREE_NO_WARNING (COND_EXPR_COND (expr))); + gimple_set_location (cond_stmt, EXPR_LOCATION (expr)); + copy_warning (cond_stmt, COND_EXPR_COND (expr)); gimplify_seq_add_stmt (&seq, cond_stmt); gimple_stmt_iterator gsi = gsi_last (seq); maybe_fold_stmt (&gsi); @@ -5680,7 +5681,7 @@ gimplify_modify_expr_complex_part (tree *expr_p, gimple_seq *pre_p, ocode = code == REALPART_EXPR ? IMAGPART_EXPR : REALPART_EXPR; other = build1 (ocode, TREE_TYPE (rhs), lhs); - TREE_NO_WARNING (other) = 1; + suppress_warning (other); other = get_formal_tmp_var (other, pre_p); realpart = code == REALPART_EXPR ? rhs : other; @@ -5965,7 +5966,7 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, assign = gimple_build_assign (*to_p, *from_p); gimple_set_location (assign, EXPR_LOCATION (*expr_p)); if (COMPARISON_CLASS_P (*from_p)) - gimple_set_no_warning (assign, TREE_NO_WARNING (*from_p)); + copy_warning (assign, *from_p); } if (gimplify_ctxp->into_ssa && is_gimple_reg (*to_p)) @@ -6724,7 +6725,7 @@ gimple_push_cleanup (tree var, tree cleanup, bool eh_only, gimple_seq *pre_p, /* Because of this manipulation, and the EH edges that jump threading cannot redirect, the temporary (VAR) will appear to be used uninitialized. Don't warn. */ - TREE_NO_WARNING (var) = 1; + suppress_warning (var, OPT_Wuninitialized); } } else @@ -14491,7 +14492,7 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, gimplify_and_add (EH_FILTER_FAILURE (*expr_p), &failure); ehf = gimple_build_eh_filter (EH_FILTER_TYPES (*expr_p), failure); - gimple_set_no_warning (ehf, TREE_NO_WARNING (*expr_p)); + copy_warning (ehf, *expr_p); gimplify_seq_add_stmt (pre_p, ehf); ret = GS_ALL_DONE; break; diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c index 0f843bad79a..6a0e0966ead 100644 --- a/gcc/omp-expand.c +++ b/gcc/omp-expand.c @@ -3845,7 +3845,7 @@ expand_omp_for_generic (struct omp_region *region, for (i = first_zero_iter1; i < (fd->ordered ? fd->ordered : fd->collapse); i++) if (SSA_VAR_P (counts[i])) - TREE_NO_WARNING (counts[i]) = 1; + suppress_warning (counts[i], OPT_Wuninitialized); gsi_prev (&gsi); e = split_block (entry_bb, gsi_stmt (gsi)); entry_bb = e->dest; @@ -3862,7 +3862,7 @@ expand_omp_for_generic (struct omp_region *region, be executed in that case, so just avoid uninit warnings. */ for (i = first_zero_iter2; i < fd->ordered; i++) if (SSA_VAR_P (counts[i])) - TREE_NO_WARNING (counts[i]) = 1; + suppress_warning (counts[i], OPT_Wuninitialized); if (zero_iter1_bb) make_edge (zero_iter2_bb, entry_bb, EDGE_FALLTHRU); else @@ -7051,7 +7051,7 @@ expand_omp_taskloop_for_outer (struct omp_region *region, be executed in that case, so just avoid uninit warnings. */ for (i = first_zero_iter; i < fd->collapse; i++) if (SSA_VAR_P (counts[i])) - TREE_NO_WARNING (counts[i]) = 1; + suppress_warning (counts[i], OPT_Wuninitialized); gsi_prev (&gsi); edge e = split_block (entry_bb, gsi_stmt (gsi)); entry_bb = e->dest; diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 2d5cdf671eb..c5abab6a281 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -5627,7 +5627,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, able to notice this and not store anything at all, but we're generating code too early. Suppress the warning. */ if (!by_ref) - TREE_NO_WARNING (var) = 1; + suppress_warning (var, OPT_Wuninitialized); break; case OMP_CLAUSE__CONDTEMP_: @@ -6588,7 +6588,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, uid = create_tmp_var (ptr_type_node, "simduid"); /* Don't want uninit warnings on simduid, it is always uninitialized, but we use it not for the value, but for the DECL_UID only. */ - TREE_NO_WARNING (uid) = 1; + suppress_warning (uid, OPT_Wuninitialized); c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__SIMDUID_); OMP_CLAUSE__SIMDUID__DECL (c) = uid; OMP_CLAUSE_CHAIN (c) = gimple_omp_for_clauses (ctx->stmt); @@ -7016,7 +7016,7 @@ lower_lastprivate_clauses (tree clauses, tree predicate, gimple_seq *body_p, if (predicate && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE || OMP_CLAUSE_LINEAR_NO_COPYIN (c))) - TREE_NO_WARNING (new_var) = 1; + suppress_warning (new_var, OPT_Wuninitialized); } if (!maybe_simt && simduid && DECL_HAS_VALUE_EXPR_P (new_var)) @@ -7850,7 +7850,7 @@ lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist, if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !by_ref && is_task_ctx (ctx)) - TREE_NO_WARNING (var) = 1; + suppress_warning (var); do_in = true; break; @@ -12634,7 +12634,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) { if (is_gimple_reg (var) && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)) - TREE_NO_WARNING (var) = 1; + suppress_warning (var); var = build_fold_addr_expr (var); } else @@ -12658,7 +12658,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) we'll get a warning for the store to avar. Don't warn in that case, the mapping might be implicit. */ - TREE_NO_WARNING (var) = 1; + suppress_warning (var, OPT_Wuninitialized); gimplify_assign (avar, var, &ilist); } avar = build_fold_addr_expr (avar); @@ -12812,7 +12812,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) if (omp_is_reference (var)) t = build_simple_mem_ref (var); else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)) - TREE_NO_WARNING (var) = 1; + suppress_warning (var); if (TREE_CODE (type) != POINTER_TYPE) t = fold_convert (pointer_sized_int_node, t); t = fold_convert (TREE_TYPE (x), t); @@ -12825,7 +12825,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) tree avar = create_tmp_var (TREE_TYPE (var)); mark_addressable (avar); if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)) - TREE_NO_WARNING (var) = 1; + suppress_warning (var); gimplify_assign (avar, var, &ilist); avar = build_fold_addr_expr (avar); gimplify_assign (x, avar, &ilist); diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 02256580c98..9bb436aad77 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -9428,7 +9428,7 @@ pass_warn_function_return::execute (function *fun) /* If we see "return;" in some basic block, then we do reach the end without returning a value. */ else if (warn_return_type > 0 - && !TREE_NO_WARNING (fun->decl) + && !warning_suppressed_p (fun->decl, OPT_Wreturn_type) && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fun->decl)))) { FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (fun)->preds) @@ -9437,14 +9437,14 @@ pass_warn_function_return::execute (function *fun) greturn *return_stmt = dyn_cast (last); if (return_stmt && gimple_return_retval (return_stmt) == NULL - && !gimple_no_warning_p (last)) + && !warning_suppressed_p (last, OPT_Wreturn_type)) { location = gimple_location (last); if (LOCATION_LOCUS (location) == UNKNOWN_LOCATION) location = fun->function_end_locus; if (warning_at (location, OPT_Wreturn_type, "control reaches end of non-void function")) - TREE_NO_WARNING (fun->decl) = 1; + suppress_warning (fun->decl, OPT_Wreturn_type); break; } } @@ -9452,7 +9452,7 @@ pass_warn_function_return::execute (function *fun) into __builtin_unreachable () call with BUILTINS_LOCATION. Recognize those too. */ basic_block bb; - if (!TREE_NO_WARNING (fun->decl)) + if (!warning_suppressed_p (fun->decl, OPT_Wreturn_type)) FOR_EACH_BB_FN (bb, fun) if (EDGE_COUNT (bb->succs) == 0) { @@ -9476,7 +9476,7 @@ pass_warn_function_return::execute (function *fun) location = fun->function_end_locus; if (warning_at (location, OPT_Wreturn_type, "control reaches end of non-void function")) - TREE_NO_WARNING (fun->decl) = 1; + suppress_warning (fun->decl, OPT_Wreturn_type); break; } } diff --git a/gcc/tree-complex.c b/gcc/tree-complex.c index d7d991714de..a528cdc7fee 100644 --- a/gcc/tree-complex.c +++ b/gcc/tree-complex.c @@ -456,12 +456,12 @@ create_one_component_var (tree type, tree orig, const char *prefix, SET_DECL_DEBUG_EXPR (r, build1 (code, type, orig)); DECL_HAS_DEBUG_EXPR_P (r) = 1; DECL_IGNORED_P (r) = 0; - TREE_NO_WARNING (r) = TREE_NO_WARNING (orig); + copy_warning (r, orig); } else { DECL_IGNORED_P (r) = 1; - TREE_NO_WARNING (r) = 1; + suppress_warning (r); } return r; diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 05d1a253d5b..9ec2013b56d 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1116,7 +1116,7 @@ remap_gimple_op_r (tree *tp, int *walk_subtrees, void *data) *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1)); TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old); - TREE_NO_WARNING (*tp) = TREE_NO_WARNING (old); + copy_warning (*tp, old); if (MR_DEPENDENCE_CLIQUE (old) != 0) { MR_DEPENDENCE_CLIQUE (*tp) @@ -1375,7 +1375,7 @@ copy_tree_body_r (tree *tp, int *walk_subtrees, void *data) *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1)); TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old); - TREE_NO_WARNING (*tp) = TREE_NO_WARNING (old); + copy_warning (*tp, old); if (MR_DEPENDENCE_CLIQUE (old) != 0) { MR_DEPENDENCE_CLIQUE (*tp) @@ -3775,7 +3775,7 @@ declare_return_variable (copy_body_data *id, tree return_slot, tree modify_dest, /* Do not have the rest of GCC warn about this variable as it should not be visible to the user. */ - TREE_NO_WARNING (var) = 1; + suppress_warning (var /* OPT_Wuninitialized? */); declare_inline_vars (id->block, var); @@ -5033,7 +5033,7 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id, initialized. We do not want to issue a warning about that uninitialized variable. */ if (DECL_P (modify_dest)) - TREE_NO_WARNING (modify_dest) = 1; + suppress_warning (modify_dest, OPT_Wuninitialized); if (gimple_call_return_slot_opt_p (call_stmt)) { diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index cea917a4d58..5ca6db248d5 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -411,8 +411,8 @@ lookup_field_for_decl (struct nesting_info *info, tree decl, DECL_USER_ALIGN (field) = DECL_USER_ALIGN (decl); DECL_IGNORED_P (field) = DECL_IGNORED_P (decl); DECL_NONADDRESSABLE_P (field) = !TREE_ADDRESSABLE (decl); - TREE_NO_WARNING (field) = TREE_NO_WARNING (decl); TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (decl); + copy_warning (field, decl); /* Declare the transformation and adjust the original DECL. For a variable or for a parameter when not optimizing, we make it point diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 8dfc923ed7e..385b228dbbc 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -2240,12 +2240,12 @@ create_access_replacement (struct access *access, tree reg_type = NULL_TREE) DECL_HAS_DEBUG_EXPR_P (repl) = 1; } if (access->grp_no_warning) - TREE_NO_WARNING (repl) = 1; + suppress_warning (repl /* Be more selective! */); else - TREE_NO_WARNING (repl) = TREE_NO_WARNING (access->base); + copy_warning (repl, access->base); } else - TREE_NO_WARNING (repl) = 1; + suppress_warning (repl /* Be more selective! */); if (dump_file) { @@ -3556,7 +3556,7 @@ generate_subtree_copies (struct access *access, tree agg, } else { - TREE_NO_WARNING (repl) = 1; + suppress_warning (repl /* Be more selective! */); if (access->grp_partial_lhs) repl = force_gimple_operand_gsi (gsi, repl, true, NULL_TREE, !insert_after, diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 3834212b867..42585412325 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -3527,7 +3527,7 @@ pass_post_ipa_warn::execute (function *fun) for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); - if (!is_gimple_call (stmt) || gimple_no_warning_p (stmt)) + if (!is_gimple_call (stmt) || warning_suppressed_p (stmt, OPT_Wnonnull)) continue; tree fntype = gimple_call_fntype (stmt); diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index beb2702f3b6..db3b18b275c 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -403,7 +403,8 @@ combine_cond_expr_cond (gimple *stmt, enum tree_code code, tree type, return NULL_TREE; } - fold_undefer_overflow_warnings (!gimple_no_warning_p (stmt), stmt, 0); + bool nowarn = warning_suppressed_p (stmt, OPT_Wstrict_overflow); + fold_undefer_overflow_warnings (!nowarn, stmt, 0); return t; } diff --git a/gcc/tree-ssa-loop-ch.c b/gcc/tree-ssa-loop-ch.c index 08caa83b4b4..dfa5dc87c34 100644 --- a/gcc/tree-ssa-loop-ch.c +++ b/gcc/tree-ssa-loop-ch.c @@ -458,7 +458,7 @@ ch_base::copy_headers (function *fun) && gimple_cond_code (stmt) != NE_EXPR && INTEGRAL_TYPE_P (TREE_TYPE (lhs)) && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (lhs))) - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, OPT_Wstrict_overflow_); } else if (is_gimple_assign (stmt)) { @@ -469,7 +469,7 @@ ch_base::copy_headers (function *fun) && rhs_code != NE_EXPR && INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (rhs1))) - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, OPT_Wstrict_overflow_); } } } diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index 8034cf68d27..c3fecb26b2b 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -2143,7 +2143,7 @@ execute_sm (class loop *loop, im_mem_ref *ref, /* If not emitting a load mark the uninitialized state on the loop entry as not to be warned for. */ tree uninit = create_tmp_reg (TREE_TYPE (aux->tmp_var)); - TREE_NO_WARNING (uninit) = 1; + suppress_warning (uninit, OPT_Wuninitialized); load = gimple_build_assign (aux->tmp_var, uninit); } lim_data = init_lim_data (load); diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index 969b868397e..1763ad4ce7b 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -3010,9 +3010,12 @@ cond_store_replacement (basic_block middle_bb, basic_block join_bb, new_stmt = gimple_build_assign (name, lhs); gimple_set_location (new_stmt, locus); lhs = unshare_expr (lhs); - /* Set TREE_NO_WARNING on the rhs of the load to avoid uninit - warnings. */ - TREE_NO_WARNING (gimple_assign_rhs1 (new_stmt)) = 1; + { + /* Set the no-warning bit on the rhs of the load to avoid uninit + warnings. */ + tree rhs1 = gimple_assign_rhs1 (new_stmt); + suppress_warning (rhs1, OPT_Wuninitialized); + } gsi_insert_on_edge (e1, new_stmt); /* 3) Create a PHI node at the join block, with one argument diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 423075b2bd1..656dfa465f4 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -1935,7 +1935,7 @@ maybe_warn_overflow (gimple *stmt, tree len, pointer_query &ptr_qry, strinfo *si = NULL, bool plus_one = false, bool rawmem = false) { - if (!len || gimple_no_warning_p (stmt)) + if (!len || warning_suppressed_p (stmt, OPT_Wstringop_overflow_)) return; /* The DECL of the function performing the write if it is done @@ -1954,7 +1954,7 @@ maybe_warn_overflow (gimple *stmt, tree len, pointer_query &ptr_qry, else return; - if (TREE_NO_WARNING (dest)) + if (warning_suppressed_p (dest, OPT_Wstringop_overflow_)) return; const int ostype = rawmem ? 0 : 1; @@ -2098,7 +2098,7 @@ maybe_warn_overflow (gimple *stmt, tree len, pointer_query &ptr_qry, if (!warned) return; - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, OPT_Wstringop_overflow_); aref.inform_access (access_write_only); } @@ -2621,16 +2621,16 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi, len = fold_convert_loc (loc, type, unshare_expr (srclen)); len = fold_build2_loc (loc, PLUS_EXPR, type, len, build_int_cst (type, 1)); - /* Set the no-warning bit on the transformed statement? */ - bool set_no_warning = false; + /* Disable warning for the transformed statement? */ + opt_code no_warning_opt = no_warning; - if (const strinfo *chksi = olddsi ? olddsi : dsi) - if (si - && check_bounds_or_overlap (stmt, chksi->ptr, si->ptr, NULL_TREE, len)) - { - gimple_set_no_warning (stmt, true); - set_no_warning = true; - } + if (const strinfo *chksi = si ? olddsi ? olddsi : dsi : NULL) + { + no_warning_opt = check_bounds_or_overlap (stmt, chksi->ptr, si->ptr, + NULL_TREE, len); + if (no_warning_opt) + suppress_warning (stmt, no_warning_opt); + } if (fn == NULL_TREE) return; @@ -2664,8 +2664,8 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi, else if (dump_file && (dump_flags & TDF_DETAILS) != 0) fprintf (dump_file, "not possible.\n"); - if (set_no_warning) - gimple_set_no_warning (stmt, true); + if (no_warning_opt) + suppress_warning (stmt, no_warning_opt); } /* Check the size argument to the built-in forms of stpncpy and strncpy @@ -2793,7 +2793,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt, pointer_query *ptr_qry /* = NULL */) { gimple *stmt = gsi_stmt (gsi); - if (gimple_no_warning_p (stmt)) + if (warning_suppressed_p (stmt, OPT_Wstringop_truncation)) return false; wide_int cntrange[2]; @@ -3153,9 +3153,10 @@ handle_builtin_stxncpy_strncat (bool append_p, gimple_stmt_iterator *gsi) else srclenp1 = NULL_TREE; - if (check_bounds_or_overlap (stmt, dst, src, dstlenp1, srclenp1)) + opt_code opt = check_bounds_or_overlap (stmt, dst, src, dstlenp1, srclenp1); + if (opt != no_warning) { - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, opt); return; } @@ -3166,7 +3167,7 @@ handle_builtin_stxncpy_strncat (bool append_p, gimple_stmt_iterator *gsi) if (!pss || pss->first <= 0) { if (maybe_diag_stxncpy_trunc (*gsi, src, len)) - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, OPT_Wstringop_truncation); return; } @@ -3203,8 +3204,8 @@ handle_builtin_stxncpy_strncat (bool append_p, gimple_stmt_iterator *gsi) /* Issue -Wstringop-overflow when appending or when writing into a destination of a known size. Otherwise, when copying into a destination of an unknown size, it's truncation. */ - int opt = (append_p || dstsize - ? OPT_Wstringop_overflow_ : OPT_Wstringop_truncation); + opt_code opt = (append_p || dstsize + ? OPT_Wstringop_overflow_ : OPT_Wstringop_truncation); warned = warning_at (callloc, opt, "%G%qD specified bound depends on the length " "of the source argument", @@ -3445,8 +3446,8 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi, srclen = get_string_length (si); } - /* Set the no-warning bit on the transformed statement? */ - bool set_no_warning = false; + /* Disable warning for the transformed statement? */ + opt_code no_warning_opt = no_warning; if (dsi == NULL || get_string_length (dsi) == NULL_TREE) { @@ -3463,12 +3464,10 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi, } tree sptr = si && si->ptr ? si->ptr : src; - - if (check_bounds_or_overlap (stmt, dst, sptr, NULL_TREE, slen)) - { - gimple_set_no_warning (stmt, true); - set_no_warning = true; - } + no_warning_opt = check_bounds_or_overlap (stmt, dst, sptr, NULL_TREE, + slen); + if (no_warning_opt) + suppress_warning (stmt, no_warning_opt); } /* strcat (p, q) can be transformed into @@ -3575,11 +3574,10 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi, tree dstsize = fold_build2 (PLUS_EXPR, type, dstlen, one); tree sptr = si && si->ptr ? si->ptr : src; - if (check_bounds_or_overlap (stmt, dst, sptr, dstsize, srcsize)) - { - gimple_set_no_warning (stmt, true); - set_no_warning = true; - } + no_warning_opt = check_bounds_or_overlap (stmt, dst, sptr, dstsize, + srcsize); + if (no_warning_opt) + suppress_warning (stmt, no_warning_opt); } tree len = NULL_TREE; @@ -3645,8 +3643,8 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi, else if (dump_file && (dump_flags & TDF_DETAILS) != 0) fprintf (dump_file, "not possible.\n"); - if (set_no_warning) - gimple_set_no_warning (stmt, true); + if (no_warning_opt) + suppress_warning (stmt, no_warning_opt); } /* Handle a call to an allocation function like alloca, malloc or calloc, diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c index 7c002f8ed87..99442d7f975 100644 --- a/gcc/tree-ssa-uninit.c +++ b/gcc/tree-ssa-uninit.c @@ -87,17 +87,33 @@ has_undefined_value_p (tree t) && possibly_undefined_names->contains (t))); } -/* Like has_undefined_value_p, but don't return true if TREE_NO_WARNING - is set on SSA_NAME_VAR. */ +/* Return true if EXPR should suppress either uninitialized warning. */ + +static inline bool +get_no_uninit_warning (tree expr) +{ + return warning_suppressed_p (expr, OPT_Wuninitialized); +} + +/* Suppress both uninitialized warnings for EXPR. */ + +static inline void +set_no_uninit_warning (tree expr) +{ + suppress_warning (expr, OPT_Wuninitialized); +} + +/* Like has_undefined_value_p, but don't return true if the no-warning + bit is set on SSA_NAME_VAR for either uninit warning. */ static inline bool uninit_undefined_value_p (tree t) { if (!has_undefined_value_p (t)) return false; - if (SSA_NAME_VAR (t) && TREE_NO_WARNING (SSA_NAME_VAR (t))) - return false; - return true; + if (!SSA_NAME_VAR (t)) + return true; + return !get_no_uninit_warning (SSA_NAME_VAR (t)); } /* Emit warnings for uninitialized variables. This is done in two passes. @@ -165,10 +181,10 @@ warn_uninit (enum opt_code wc, tree t, tree expr, tree var, /* TREE_NO_WARNING either means we already warned, or the front end wishes to suppress the warning. */ if ((context - && (gimple_no_warning_p (context) + && (warning_suppressed_p (context, OPT_Wuninitialized) || (gimple_assign_single_p (context) - && TREE_NO_WARNING (gimple_assign_rhs1 (context))))) - || TREE_NO_WARNING (expr)) + && get_no_uninit_warning (gimple_assign_rhs1 (context))))) + || get_no_uninit_warning (expr)) return; if (context != NULL && gimple_has_location (context)) @@ -185,7 +201,7 @@ warn_uninit (enum opt_code wc, tree t, tree expr, tree var, auto_diagnostic_group d; if (warning_at (location, wc, gmsgid, expr)) { - TREE_NO_WARNING (expr) = 1; + suppress_warning (expr, wc); if (location == DECL_SOURCE_LOCATION (var)) return; @@ -260,7 +276,7 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs, use_operand_p luse_p; imm_use_iterator liter; - if (TREE_NO_WARNING (rhs)) + if (get_no_uninit_warning (rhs)) return NULL_TREE; /* Do not warn if the base was marked so or this is a @@ -268,7 +284,7 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs, tree base = ao_ref_base (&ref); if ((VAR_P (base) && DECL_HARD_REGISTER (base)) - || TREE_NO_WARNING (base)) + || get_no_uninit_warning (base)) return NULL_TREE; /* Do not warn if the access is fully outside of the variable. */ @@ -407,7 +423,7 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs, rhs = TREE_OPERAND (rhs, 0); /* Check again since RHS may have changed above. */ - if (TREE_NO_WARNING (rhs)) + if (get_no_uninit_warning (rhs)) return NULL_TREE; /* Avoid warning about empty types such as structs with no members. @@ -435,7 +451,7 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs, uses or accesses by functions as it may hide important locations. */ if (lhs) - TREE_NO_WARNING (rhs) = 1; + set_no_uninit_warning (rhs); warned = true; } } diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index b9c0e65bd98..0565c9b5073 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -406,10 +406,10 @@ compare_values_warnv (tree val1, tree val2, bool *strict_overflow_p) return -2; if (strict_overflow_p != NULL - /* Symbolic range building sets TREE_NO_WARNING to declare + /* Symbolic range building sets the no-warning bit to declare that overflow doesn't happen. */ - && (!inv1 || !TREE_NO_WARNING (val1)) - && (!inv2 || !TREE_NO_WARNING (val2))) + && (!inv1 || !warning_suppressed_p (val1, OPT_Woverflow)) + && (!inv2 || !warning_suppressed_p (val2, OPT_Woverflow))) *strict_overflow_p = true; if (!inv1) @@ -432,10 +432,10 @@ compare_values_warnv (tree val1, tree val2, bool *strict_overflow_p) return -2; if (strict_overflow_p != NULL - /* Symbolic range building sets TREE_NO_WARNING to declare + /* Symbolic range building sets the no-warning bit to declare that overflow doesn't happen. */ - && (!sym1 || !TREE_NO_WARNING (val1)) - && (!sym2 || !TREE_NO_WARNING (val2))) + && (!sym1 || !warning_suppressed_p (val1, OPT_Woverflow)) + && (!sym2 || !warning_suppressed_p (val2, OPT_Woverflow))) *strict_overflow_p = true; const signop sgn = TYPE_SIGN (TREE_TYPE (val1)); diff --git a/gcc/tree.h b/gcc/tree.h index 62b2de46479..3c92c58980e 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see #define GCC_TREE_H #include "tree-core.h" +#include "options.h" /* Convert a target-independent built-in function code to a combined_fn. */ @@ -6440,4 +6434,30 @@ public: operator location_t () const { return m_combined_loc; } }; +/* Code that doesn't refer to any warning. Has no effect on suppression + functions. */ +constexpr opt_code no_warning = opt_code (); +/* Wildcard code that refers to all warnings. */ +constexpr opt_code all_warnings = N_OPTS; + +/* Return the disposition for a warning (or all warnings by default) + at a location. */ +extern bool warning_suppressed_at (location_t, opt_code = all_warnings); +/* Set the disposition for a warning (or all warnings by default) + at a location to disabled by default. */ +extern bool suppress_warning_at (location_t, opt_code = all_warnings, + bool = true); +/* Copy warning disposition from one location to another. */ +extern void copy_warning (location_t, location_t); + +/* Return the disposition for a warning (or all warnings by default) + for an expression. */ +extern bool warning_suppressed_p (const_tree, opt_code = all_warnings); +/* Set the disposition for a warning (or all warnings by default) + at a location to disabled by default. */ +extern void suppress_warning (tree, opt_code = all_warnings, bool = true) + ATTRIBUTE_NONNULL (1); +/* Copy warning disposition from one expression to another. */ +extern void copy_warning (tree, const_tree); + #endif /* GCC_TREE_H */ diff --git a/gcc/vr-values.c b/gcc/vr-values.c index 509c8b093c5..3ae2c68499d 100644 --- a/gcc/vr-values.c +++ b/gcc/vr-values.c @@ -699,7 +699,7 @@ vr_values::extract_range_for_var_from_comparison_expr (tree var, build_int_cst (TREE_TYPE (max), 1)); /* Signal to compare_values_warnv this expr doesn't overflow. */ if (EXPR_P (max)) - TREE_NO_WARNING (max) = 1; + suppress_warning (max, OPT_Woverflow); } vr_p->update (min, max); @@ -739,7 +739,7 @@ vr_values::extract_range_for_var_from_comparison_expr (tree var, build_int_cst (TREE_TYPE (min), 1)); /* Signal to compare_values_warnv this expr doesn't overflow. */ if (EXPR_P (min)) - TREE_NO_WARNING (min) = 1; + suppress_warning (min, OPT_Woverflow); } vr_p->update (min, max); @@ -3355,7 +3355,7 @@ test_for_singularity (enum tree_code cond_code, tree op0, max = fold_build2 (MINUS_EXPR, TREE_TYPE (op0), max, one); /* Signal to compare_values_warnv this expr doesn't overflow. */ if (EXPR_P (max)) - TREE_NO_WARNING (max) = 1; + suppress_warning (max, OPT_Woverflow); } } else if (cond_code == GE_EXPR || cond_code == GT_EXPR) @@ -3369,7 +3369,7 @@ test_for_singularity (enum tree_code cond_code, tree op0, min = fold_build2 (PLUS_EXPR, TREE_TYPE (op0), min, one); /* Signal to compare_values_warnv this expr doesn't overflow. */ if (EXPR_P (min)) - TREE_NO_WARNING (min) = 1; + suppress_warning (min, OPT_Woverflow); } } From patchwork Fri Jun 4 21:43:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488137 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=2620:52:3:1:0:246e:9693:128c; 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=prCoAN3f; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Fxc3G10B8z9sPf for ; Sat, 5 Jun 2021 07:53:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A067B39A240F for ; Fri, 4 Jun 2021 21:53:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A067B39A240F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843622; bh=DNUfZKIsMg1dbhVwTGK+3vyUPtoXIiAWePkdtIu59bU=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=prCoAN3fXNua2meIYtG5trmFsY9I9nNQcZUxfxWuUXAezf9sR8R9kifi/EOvf7ghl RXrX0E99Rwh6oLVn3uV4EjrTANNpfqzTYSnp1kqJ/t6hdC/0kAF0b0j061nHhAtesk RevwIQXSgjFvN/tloyEs6ePr5EJ/8djnF31S9au0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 4DD0739A1420 for ; Fri, 4 Jun 2021 21:43:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4DD0739A1420 Received: by mail-ot1-x32b.google.com with SMTP id q9-20020a9d66490000b02903c741e5b703so9355123otm.0 for ; Fri, 04 Jun 2021 14:43:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=DNUfZKIsMg1dbhVwTGK+3vyUPtoXIiAWePkdtIu59bU=; b=egG9dXQOQFmhwxorD3bCCckJWIXJ8IdqaHhBa4/mJ4zPPD0ih/9xA21zsP5xWjcDBD iMdyqdPq+7o1pJtcJmjHpClo9I0iZqxs0pJ57fkrr+xz1f2BuYOVm04JbKAlzcvl8yr/ Y8phLHnRuhlEr1gsz8MOG7fFxBS+bvJwDsP1pGYcH91m0YwZ3zfH22LKg6Nx9mtahBaq G8rWS6nvyT42Yx5GrNAUeY740tPYH4mathF4nDFwFECgkW2QnESmq5Ezb/TyBY+JK4+m pAz4F1RowrJFo3lyDcIxIs2Hi/PJCUVNDvEzf17m7RWdfnwVKKvQ3nHw5HSYo8cE0USG g6VA== X-Gm-Message-State: AOAM5302lwb+WIQi1+LpgcORgaAzOUV8RRxI1naCkOtRTKGgRL2EtRrn Weg4i/NKy3ezxQgRlvj+KI0lm2rmcZI= X-Google-Smtp-Source: ABdhPJx5b5/ElkhhCn3SIdYZTO+KWRNzNN/+ARDyJ0ZhKrkbWp29OhBaui38pEznRGRZMV9tnez5NA== X-Received: by 2002:a05:6830:1b6e:: with SMTP id d14mr5444123ote.186.1622843011696; Fri, 04 Jun 2021 14:43:31 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id 21sm113692otd.21.2021.06.04.14.43.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:43:31 -0700 (PDT) Subject: [PATCH 11/13] v2 Use new per-location warning APIs in the Objective-C front end To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: <969d1ed9-5a7e-5e30-dae0-ac0937bdfaa6@gmail.com> Date: Fri, 4 Jun 2021 15:43:30 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch replaces the uses of TREE_NO_WARNING in the Objective-C front end with the new suppress_warning(), warning_suppressed_p(), and copy_warning() APIs. Add support for per-location warning groups. gcc/objc/ChangeLog: * objc-act.c (objc_maybe_build_modify_expr): Replace direct uses of TREE_NO_WARNING with warning_suppressed_p, and suppress_warning. (objc_build_incr_expr_for_property_ref): Same. (objc_build_struct): Same. (synth_module_prologue): Same. * objc-gnu-runtime-abi-01.c (gnu_runtime_01_initialize): Same. * objc-next-runtime-abi-01.c (next_runtime_01_initialize): Same. * objc-next-runtime-abi-02.c (next_runtime_02_initialize): Same. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 8d106a4de26..ec20891152b 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -2007,7 +2007,7 @@ objc_maybe_build_modify_expr (tree lhs, tree rhs) correct (maybe a more sophisticated implementation could avoid generating the compound expression if not needed), but we need to turn it off. */ - TREE_NO_WARNING (compound_expr) = 1; + suppress_warning (compound_expr, OPT_Wunused); return compound_expr; } else @@ -2129,7 +2129,7 @@ objc_build_incr_expr_for_property_ref (location_t location, /* Prevent C++ from warning with -Wall that "right operand of comma operator has no effect". */ - TREE_NO_WARNING (compound_expr) = 1; + suppress_warning (compound_expr, OPT_Wunused); return compound_expr; } @@ -2262,8 +2262,9 @@ objc_build_struct (tree klass, tree fields, tree super_name) DECL_FIELD_IS_BASE (base) = 1; if (fields) - TREE_NO_WARNING (fields) = 1; /* Suppress C++ ABI warnings -- we */ -#endif /* are following the ObjC ABI here. */ + /* Suppress C++ ABI warnings: we are following the ObjC ABI here. */ + suppress_warning (fields, OPT_Wabi); +#endif DECL_CHAIN (base) = fields; fields = base; } @@ -3112,19 +3113,19 @@ synth_module_prologue (void) TYPE_DECL, objc_object_name, objc_object_type)); - TREE_NO_WARNING (type) = 1; + suppress_warning (type); type = lang_hooks.decls.pushdecl (build_decl (input_location, TYPE_DECL, objc_instancetype_name, objc_instancetype_type)); - TREE_NO_WARNING (type) = 1; + suppress_warning (type); type = lang_hooks.decls.pushdecl (build_decl (input_location, TYPE_DECL, objc_class_name, objc_class_type)); - TREE_NO_WARNING (type) = 1; + suppress_warning (type); /* Forward-declare '@interface Protocol'. */ type = get_identifier (PROTOCOL_OBJECT_CLASS_NAME); diff --git a/gcc/objc/objc-gnu-runtime-abi-01.c b/gcc/objc/objc-gnu-runtime-abi-01.c index 4add71edf41..976fa1e36cb 100644 --- a/gcc/objc/objc-gnu-runtime-abi-01.c +++ b/gcc/objc/objc-gnu-runtime-abi-01.c @@ -213,7 +213,7 @@ static void gnu_runtime_01_initialize (void) TYPE_DECL, objc_selector_name, objc_selector_type)); - TREE_NO_WARNING (type) = 1; + suppress_warning (type); /* typedef id (*IMP)(id, SEL, ...); */ ftype = build_varargs_function_type_list (objc_object_type, diff --git a/gcc/objc/objc-next-runtime-abi-01.c b/gcc/objc/objc-next-runtime-abi-01.c index 3ec6e1703c1..183fc01abb2 100644 --- a/gcc/objc/objc-next-runtime-abi-01.c +++ b/gcc/objc/objc-next-runtime-abi-01.c @@ -282,7 +282,7 @@ static void next_runtime_01_initialize (void) TYPE_DECL, objc_selector_name, objc_selector_type)); - TREE_NO_WARNING (type) = 1; + suppress_warning (type); build_v1_class_template (); build_super_template (); diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c index 3cfcd0b1a57..963d1bf1ad8 100644 --- a/gcc/objc/objc-next-runtime-abi-02.c +++ b/gcc/objc/objc-next-runtime-abi-02.c @@ -379,7 +379,7 @@ static void next_runtime_02_initialize (void) TYPE_DECL, objc_selector_name, objc_selector_type)); - TREE_NO_WARNING (type) = 1; + suppress_warning (type); /* IMP : id (*) (id, _message_ref_t*, ...) SUPER_IMP : id (*) ( super_t*, _super_message_ref_t*, ...) From patchwork Fri Jun 4 21:43:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488138 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=2620:52:3:1:0:246e:9693:128c; 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=emF6qZzN; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Fxc4N10Pqz9sPf for ; Sat, 5 Jun 2021 07:54:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF5A939A2418 for ; Fri, 4 Jun 2021 21:54:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF5A939A2418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843681; bh=vHSrF29kredk09Cz+D9nqgIynte0zXFZDfcMhsX/EuQ=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=emF6qZzNxDyTsn52Dt9wMTe00TvfZrOX2gApGi1B3BCqrWqQkmvzNpRcHxNjxRpMS Ib8es3nf7nFx5YoVxWWKxa34Mgh8z6z7nKjc1VJdB8iBj63Vv9opWWAoyTizuFTI1I /i3k2idsCFma8QCTk2Vr+LU169WBOeWcrcRWW5pc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id B25E339A140E for ; Fri, 4 Jun 2021 21:43:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B25E339A140E Received: by mail-ot1-x32c.google.com with SMTP id t10-20020a05683022eab0290304ed8bc759so10434331otc.12 for ; Fri, 04 Jun 2021 14:43:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=vHSrF29kredk09Cz+D9nqgIynte0zXFZDfcMhsX/EuQ=; b=iNBs8YbKasizKK2f1jxu3oXZJ1Oz9WpEsAU+U/EQFFrQw3sTzd6Mtu3IGUEALFrh/Z jJYaDKvuXvx9RfvNf2kQNsfM4VW0Has1uE1/PrB0p0dou2Qf6sifnb/8eNl1LZ6O7jro 9l7UdVlRQkrbeH2ta0xNfW1/Q2eGYtldRrHIh6XZBhwib5lRSAcZ/kbFcxPZWJKCyyKP 1R0OJza4BhMeJS9u7owVaspmfDRWv3Fhe28z9xbnXPH+5SrbwSM8GvA+TSSt/gnRGJIA yVTPBeNnB/7I3POnUx9TTPVeZUNmm7n2klT9IUHBHW1OWKyazAkVGmTAqZ3DaI1ADmp1 ff9w== X-Gm-Message-State: AOAM533iLrs/6aDM+o/Sf8UOFEE3OxMflHEHdJI3vOV/HbDMYLYd3IUf CY0MRdVJe9hAq1N1izGYDcEFIBLnxT8= X-Google-Smtp-Source: ABdhPJxa5wb6tZdhtQ6gDDOO6o7fUnVwTmH6Tplo3Fj8n/fg6e/oyomY3+ndPYT+4rqFDuYxzK6hKg== X-Received: by 2002:a9d:1e4:: with SMTP id e91mr5288349ote.211.1622843023122; Fri, 04 Jun 2021 14:43:43 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id z15sm744670otp.20.2021.06.04.14.43.42 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:43:42 -0700 (PDT) Subject: [PATCH 12/13] v2 Remove TREE_NO_WARNING and gimple*no_warning* APIs To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: <9902ab65-65a7-a40f-7b4e-864e6c3250dc@gmail.com> Date: Fri, 4 Jun 2021 15:43:42 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch removes the definitions of the TREE_NO_WARNING macro and the gimple_get_no_warning_p() and gimple_set_no_warning() functions. Remove legacy TREE_NO_WARNING amd gimple_*no_warning* APIs. gcc/ChangeLog: * tree.h (TREE_NO_WARNING): Remove. * gimple.h (gimple_no_warning_p): Remove. (gimple_suppress_warning): Same. diff --git a/gcc/tree.h b/gcc/tree.h index 62b2de46479..3c92c58980e 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -699,13 +700,6 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, /* Determines whether an ENUMERAL_TYPE has defined the list of constants. */ #define ENUM_IS_OPAQUE(NODE) (ENUMERAL_TYPE_CHECK (NODE)->base.private_flag) -/* In an expr node (usually a conversion) this means the node was made - implicitly and should not lead to any sort of warning. In a decl node, - warnings concerning the decl should be suppressed. This is used at - least for used-before-set warnings, and it set after one warning is - emitted. */ -#define TREE_NO_WARNING(NODE) ((NODE)->base.nowarning_flag) - /* Nonzero if we should warn about the change in empty class parameter passing ABI in this TU. */ #define TRANSLATION_UNIT_WARN_EMPTY_P(NODE) \ diff --git a/gcc/gimple.h b/gcc/gimple.h index 91b92b4a4d1..ca5d4acfc71 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -1948,22 +1969,6 @@ gimple_seq_singleton_p (gimple_seq seq) && (gimple_seq_first (seq) == gimple_seq_last (seq))); } -/* Return true if no warnings should be emitted for statement STMT. */ - -static inline bool -gimple_no_warning_p (const gimple *stmt) -{ - return stmt->no_warning; -} - -/* Set the no_warning flag of STMT to NO_WARNING. */ - -static inline void -gimple_set_no_warning (gimple *stmt, bool no_warning) -{ - stmt->no_warning = (unsigned) no_warning; -} - /* Set the visited status on statement STMT to VISITED_P. Please note that this 'visited' property of the gimple statement is From patchwork Fri Jun 4 21:43:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1488139 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=pBiPBlkX; dkim-atps=neutral Received: from sourceware.org (server2.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 4Fxc5V65Vzz9sPf for ; Sat, 5 Jun 2021 07:55:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4ED439A241C for ; Fri, 4 Jun 2021 21:55:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4ED439A241C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622843740; bh=JX+TzVrgjuHUUNr//VxdgpXu+BhPwQKHPUC0Yclj4yc=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=pBiPBlkXtHrSFaR+wBswmHmGtpit3W5WtpThhx2QpdOWekfJ5aIYZNp9W2xuf9SLw W5K4bAuee0u5IPFUm4v65bc6/0josFkqLoWgR9GhlvTXIuCxvXaMWTgSte/Q4EGYtc 5/GFmngFNPJVZFQge1d7QM6XzDp5z9tnr3lNfCT0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 212CE39A1420 for ; Fri, 4 Jun 2021 21:43:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 212CE39A1420 Received: by mail-oi1-x232.google.com with SMTP id u11so11168674oiv.1 for ; Fri, 04 Jun 2021 14:43:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=JX+TzVrgjuHUUNr//VxdgpXu+BhPwQKHPUC0Yclj4yc=; b=Gw4ticd1SKEdr8ey8AvtAt9ksa8La7Mqyqh6qb30AU9VYEGcBDQw9u53cSIQtubLv4 vDll3g56UZ//V5IRYgGED2kqNFXjN4TLZUcfc9MzRJLw9ISGDN+j32FoB7Rbz5bMLEMS EDLxVWcnODkUZYyrFP37A83uDcK+CEeQkwf4MaWgz6lMicGsrGxJpWHkc2adhFomEIOg TJSMgRYRzKQBDsFaYO+JLGonrUeDJdsjcv/CKORDWh0JXiiyD/RuBkrnbuFdI4fiEYqG 3dsz030gPv3+HPBsKkNlGCDQjp+eGv7KXo5JU5J06zh2oAxNnS6E/hmG176n4Cxt9U++ deNg== X-Gm-Message-State: AOAM532aAvVo1ko7x5N4yfosSBpqQOLylKxrBFxj37kPf5e4IvfMw0mq 0YWAwgy3Nub7ASro7FFlYL6hzT2coH0= X-Google-Smtp-Source: ABdhPJyKB/l+952NK5frgVxbLS21wQ+NeLdzlkVJB3rJyndurFiCGcminSWxl8JCwShQMXsO++dU7w== X-Received: by 2002:a54:460a:: with SMTP id p10mr12282301oip.47.1622843034516; Fri, 04 Jun 2021 14:43:54 -0700 (PDT) Received: from [192.168.0.41] (184-96-226-253.hlrn.qwest.net. [184.96.226.253]) by smtp.gmail.com with ESMTPSA id i4sm733015oth.38.2021.06.04.14.43.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jun 2021 14:43:54 -0700 (PDT) Subject: [PATCH 13/13] v2 Add regression tests for PR 74765 and 74762 To: gcc-patches References: <92db3776-af59-fa20-483b-aa67b17d0751@gmail.com> <47d06c821a53f5bd2246f0fca2c9a693bff6b882.camel@redhat.com> <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Message-ID: <6466673c-21e5-4cce-0149-f7cad73de5d0@gmail.com> Date: Fri, 4 Jun 2021 15:43:53 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <3a5ea83c-0d91-d123-f537-f8f1223df890@gmail.com> Content-Language: en-US X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch adds regression tests for two closely related bugs resolved by the patch series. Regression tests for TREE_NO_WARNING enhancement to warning groups. PR middle-end/74765 - missing uninitialized warning (parenthesis, TREE_NO_WARNING abuse) PR middle-end/74762 - [9/10/11/12 Regression] missing uninitialized warning (C++, parenthesized expr, TREE_NO_WARNING) gcc/testsuite/ChangeLog: * g++.dg/uninit-pr74762.C: New test. * g++.dg/warn/uninit-pr74765.C: Same. diff --git a/gcc/testsuite/g++.dg/uninit-pr74762.C b/gcc/testsuite/g++.dg/uninit-pr74762.C new file mode 100644 index 00000000000..ce1bc59773e --- /dev/null +++ b/gcc/testsuite/g++.dg/uninit-pr74762.C @@ -0,0 +1,24 @@ +/* PR c++/74762 - missing uninitialized warning (C++, parenthesized expr) + { dg-do compile } + { dg-options "-Wall" } */ + +struct tree2; +struct tree_vector2 +{ + tree2 *elts[1]; +}; + +struct tree2 +{ + struct + { + tree_vector2 vector; + } u; +}; + +tree2 * +const_with_all_bytes_same (tree2 *val) +{ + int i; + return ((val->u.vector.elts[i])); // { dg-warning "\\\[-Wuninitialized" } +} diff --git a/gcc/testsuite/g++.dg/warn/uninit-pr74765.C b/gcc/testsuite/g++.dg/warn/uninit-pr74765.C new file mode 100644 index 00000000000..1b8c124b18b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/uninit-pr74765.C @@ -0,0 +1,24 @@ +/* PR c++/74765 - missing uninitialized warning (parenthesis, + TREE_NO_WARNING abuse) + { dg-do compile } + { dg-options "-Wall" } */ + +int warn_equal_parens (int x, int y) +{ + int i; + + if ((i == 0)) // { dg-warning "\\\[-Wuninitialized" } + return x; + + return y; +} + +int warn_equal (int x, int y) +{ + int i; + + if (i == 0) // { dg-warning "\\\[-Wuninitialized" } + return x; + + return y; +}