From patchwork Thu Feb 14 23:23:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1042476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496181-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="FfSRUncv"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440rlr3Gc6z9s3l for ; Fri, 15 Feb 2019 09:34:00 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=LMoR9PpAx4vd5uO7AsyWl3owIYLFS/3G570QDnL8jfUr8RkGaxEMx Ra08rm3fWaltIfn73oCDHJYSokm7wZz2C+e6SLQ/T0eM/WuWD8ZRqfnyijCVCHaM G0HYJrzu5BVzDQjH/y+VHamH5u5OiOzoP0L0XqSAc3fXNGsVIirQnQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=wBiM1oLYwu2ERbQq4aWIBMVrppY=; b=FfSRUncvTyB6RM3lM9PH wW2xhQ4xIrlzvcIY2F6Pm3FxA0DPP40Bd6BJ6epmQYR+NUKxR2w377+sRKnbDWqD oLUFarBa/11JHPo7/RN6qUT8kpEaIR9tsoboefA2hMTTIFjF4eC+FJq2aqzQfJsp 04N6D1+VVQ/SEyf2lXGmx1M= Received: (qmail 59644 invoked by alias); 14 Feb 2019 22:33:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 59399 invoked by uid 89); 14 Feb 2019 22:33:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=entities, offer X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Feb 2019 22:33:21 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0476A8338 for ; Thu, 14 Feb 2019 22:33:19 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-37.phx2.redhat.com [10.3.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADB8E5DEB2; Thu, 14 Feb 2019 22:33:18 +0000 (UTC) From: David Malcolm To: jakub@redhat.com, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 1/7] Don't offer suggestions for compiler-generated variables (PR c++/85515) Date: Thu, 14 Feb 2019 18:23:38 -0500 Message-Id: <1550186624-25444-2-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> References: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes gcc/cp/ChangeLog: Backport of r259720 from trunk. 2018-04-27 David Malcolm PR c++/85515 * name-lookup.c (consider_binding_level): Skip compiler-generated variables. * search.c (lookup_field_fuzzy_info::fuzzy_lookup_field): Flatten nested if statements into a series of rejection tests. Reject lambda-ignored entities as suggestions. gcc/testsuite/ChangeLog: Backport of r259720 from trunk. 2018-04-27 David Malcolm PR c++/85515 * g++.dg/pr85515-1.C: New test. * g++.dg/pr85515-2.C: New test. --- gcc/cp/name-lookup.c | 6 ++++++ gcc/cp/search.c | 13 ++++++++++--- gcc/testsuite/g++.dg/pr85515-1.C | 18 ++++++++++++++++++ gcc/testsuite/g++.dg/pr85515-2.C | 22 ++++++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr85515-1.C create mode 100644 gcc/testsuite/g++.dg/pr85515-2.C diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 4ce632c..86fa03b 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -5863,6 +5863,12 @@ consider_binding_level (tree name, best_match &bm, && DECL_ANTICIPATED (d)) continue; + /* Skip compiler-generated variables (e.g. __for_begin/__for_end + within range for). */ + if (TREE_CODE (d) == VAR_DECL + && DECL_ARTIFICIAL (d)) + continue; + tree suggestion = DECL_NAME (d); if (!suggestion) continue; diff --git a/gcc/cp/search.c b/gcc/cp/search.c index ca04dca..d4214d4 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -1227,9 +1227,16 @@ lookup_field_fuzzy_info::fuzzy_lookup_field (tree type) for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) { - if (!m_want_type_p || DECL_DECLARES_TYPE_P (field)) - if (DECL_NAME (field)) - m_candidates.safe_push (DECL_NAME (field)); + if (m_want_type_p && !DECL_DECLARES_TYPE_P (field)) + continue; + + if (!DECL_NAME (field)) + continue; + + if (is_lambda_ignored_entity (field)) + continue; + + m_candidates.safe_push (DECL_NAME (field)); } } diff --git a/gcc/testsuite/g++.dg/pr85515-1.C b/gcc/testsuite/g++.dg/pr85515-1.C new file mode 100644 index 0000000..0e27a9d --- /dev/null +++ b/gcc/testsuite/g++.dg/pr85515-1.C @@ -0,0 +1,18 @@ +// { dg-require-effective-target c++14 } + +void test_1 () +{ + auto lambda = [val = 2](){}; + lambda.val; // { dg-bogus "did you mean" } + // { dg-error "has no member named 'val'" "" { target *-*-* } .-1 } +} + +int test_2 () +{ + auto lambda = [val = 2](){ return val; }; + + // TODO: should we issue an error for the following assignment? + lambda.__val = 4; + + return lambda(); +} diff --git a/gcc/testsuite/g++.dg/pr85515-2.C b/gcc/testsuite/g++.dg/pr85515-2.C new file mode 100644 index 0000000..621ddb8 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr85515-2.C @@ -0,0 +1,22 @@ +// { dg-require-effective-target c++11 } + +void test_1 () +{ + int arr[] = {1, 2, 3, 4, 5}; + for (const auto v: arr) { + _forbegin; // { dg-bogus "suggested alternative" } + // { dg-error "'_forbegin' was not declared in this scope" "" { target *-*-*} .-1 } + } +} + +int test_2 () +{ + int arr[] = {1, 2, 3, 4, 5}; + int sum = 0; + for (const auto v: arr) { + sum += v; + // TODO: should we issue an error for the following assignment? + __for_begin = __for_end; + } + return sum; +} From patchwork Thu Feb 14 23:23:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1042477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496180-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xMia/n7p"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440rm45Mr9z9s3l for ; Fri, 15 Feb 2019 09:34:12 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=bAiex3retafUl93KI88rZ06K7y4K7iAt84NVfnN/gr2TBFmVSvmrJ p4JyipJAlvRPpfQ+I2c3Zp8lbpnxgGOnL8fgyzsQW7I8p+Cc/18hQxhSxJw9t4go Cb2xFNpnlwEgZMTnQ/Lhfx13DHgTREHuUy3RQyVmlegUZ09MyuZDnU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=Xuu0TA9sMZENjwhlJ+A1cBtTfJ0=; b=xMia/n7pFT/BsBCXDVGd 9vRcP9z1WBZeeDPZqjMzHgtkr6+wNpBrObAh80+TU1W+ANR69Z/kXlzEUJ7LGvpH g+PlMaB72E3weJ04gOZq8DuzptVlvDNQ5NXUg/gnrEXB/Mwh4/OTosLNvCkQ93GB OClIXORjxud/Q1kKchr4wZQ= Received: (qmail 59483 invoked by alias); 14 Feb 2019 22:33:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 59404 invoked by uid 89); 14 Feb 2019 22:33:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=offer X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Feb 2019 22:33:22 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66289F9E64 for ; Thu, 14 Feb 2019 22:33:21 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-37.phx2.redhat.com [10.3.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40F405E7D5; Thu, 14 Feb 2019 22:33:20 +0000 (UTC) From: David Malcolm To: jakub@redhat.com, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 2/7] C++: don't offer bogus "._0" suggestions (PR c++/86329) Date: Thu, 14 Feb 2019 18:23:39 -0500 Message-Id: <1550186624-25444-3-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> References: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes PR c++/86329 reports that the C++ frontend can offer bogus suggestions like: #include int compare() { return __n1 - __n2; } suggested.cc: In function 'int compare()': suggested.cc:5:10: error: '__n1' was not declared in this scope return __n1 - __n2; ^~~~ suggested.cc:5:10: note: suggested alternative: '._61' return __n1 - __n2; ^~~~ ._61 suggested.cc:5:17: error: '__n2' was not declared in this scope return __n1 - __n2; ^~~~ suggested.cc:5:17: note: suggested alternative: '._72' return __n1 - __n2; ^~~~ ._72 The dot-prefixed names are an implementation detail of how we implement anonymous enums found in the header files, generated via anon_aggrname_format in make_anon_name. This patch uses anon_aggrname_p to filter them out when considering which names to suggest. gcc/cp/ChangeLog: Backport of r262199 from trunk. 2018-06-27 David Malcolm PR c++/86329 * name-lookup.c (consider_binding_level): Filter out names that match anon_aggrname_p. gcc/testsuite/ChangeLog: Backport of r262199 from trunk. 2018-06-27 David Malcolm PR c++/86329 * g++.dg/lookup/pr86329.C: New test. --- gcc/cp/name-lookup.c | 5 +++++ gcc/testsuite/g++.dg/lookup/pr86329.C | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/lookup/pr86329.C diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 86fa03b..4e8263b 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -5873,6 +5873,11 @@ consider_binding_level (tree name, best_match &bm, if (!suggestion) continue; + /* Don't suggest names that are for anonymous aggregate types, as + they are an implementation detail generated by the compiler. */ + if (anon_aggrname_p (suggestion)) + continue; + const char *suggestion_str = IDENTIFIER_POINTER (suggestion); /* Ignore internal names with spaces in them. */ diff --git a/gcc/testsuite/g++.dg/lookup/pr86329.C b/gcc/testsuite/g++.dg/lookup/pr86329.C new file mode 100644 index 0000000..fc091ba --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/pr86329.C @@ -0,0 +1,11 @@ +/* PR c++/86329: ensure we don't erroneously offer suggestions like "._0", + which are an implementation detail of how e.g. anonymous enums are + handled internally. */ + +enum {NONEMPTY}; + +int test() +{ + return __0; // { dg-error "'__0' was not declared in this scope" } + // { dg-bogus "suggested alternative" "" { target *-*-* } .-1 } +} From patchwork Thu Feb 14 23:23:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1042479 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496183-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="C6O6QeA3"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440rmb0wbvz9s3l for ; Fri, 15 Feb 2019 09:34:38 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=AyEcpdM5HgqIVKeNIc/1DxaYsKghu2R0q3g/T+0r9ep0NfPuqZKS0 Q1iQdaI9mJHK6Hco65Ny8JYgPBsPmBY47zZWWY1kWY3dEgjf63NiiGBAwpMPu6uP ZSoKxqC2/5XhVBXVfxXzbQOleCODCmYgkONJNl7YwyTCHZ2o6DC4M8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=JmmV+3jXC/SlCkPpgd371Oyzy9o=; b=C6O6QeA3yAkZ9HmJPqpW 0Sa/ppsHQkns+Hdanw8ft+pGfQDiVWfHrRRJli9U5h4N1SfO0E+He2OvM4dsZoal 9hvBqmGoUYp/ovUuCRuPWweEEt32UVqn+pec1q2AdXaSL21ROTUA2HhktEZutmdO 9LF4n88NxjTsvoyjUQxTUwU= Received: (qmail 59725 invoked by alias); 14 Feb 2019 22:33:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 59439 invoked by uid 89); 14 Feb 2019 22:33:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=pps, owns, START, 2500 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Feb 2019 22:33:24 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF890A8342 for ; Thu, 14 Feb 2019 22:33:22 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-37.phx2.redhat.com [10.3.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id C91025E7D5; Thu, 14 Feb 2019 22:33:21 +0000 (UTC) From: David Malcolm To: jakub@redhat.com, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 3/7] Fix memory leak of pretty_printer prefixes Date: Thu, 14 Feb 2019 18:23:40 -0500 Message-Id: <1550186624-25444-4-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> References: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes We were rather sloppy about handling the ownership of prefixes for pretty_printer, and this lead to a memory leak for any time a diagnostic_show_locus call emits multiple line spans. This showed up in "make selftest-valgrind" as: 3,976 bytes in 28 blocks are definitely lost in loss record 632 of 669 at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x1F08227: xmalloc (xmalloc.c:147) by 0x1F083E6: xvasprintf (xvasprintf.c:58) by 0x1E7EC7D: build_message_string(char const*, ...) (diagnostic.c:78) by 0x1E7F438: diagnostic_get_location_text(diagnostic_context*, expanded_location) (diagnostic.c:328) by 0x1E7FD54: default_diagnostic_start_span_fn(diagnostic_context*, expanded_location) (diagnostic.c:626) by 0x1EB3508: selftest::test_diagnostic_context::start_span_cb(diagnostic_context*, expanded_location) (selftest-diagnostic.c:57) by 0x1E89215: diagnostic_show_locus(diagnostic_context*, rich_location*, diagnostic_t) (diagnostic-show-locus.c:1992) by 0x1E8ECAD: selftest::test_fixit_insert_containing_newline_2(selftest::line_table_case const&) (diagnostic-show-locus.c:3044) by 0x1EB0606: selftest::for_each_line_table_case(void (*)(selftest::line_table_case const&)) (input.c:3525) by 0x1E8F3F5: selftest::diagnostic_show_locus_c_tests() (diagnostic-show-locus.c:3164) by 0x1E010BF: selftest::run_tests() (selftest-run-tests.c:88) 4,004 bytes in 28 blocks are definitely lost in loss record 633 of 669 at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x1F08227: xmalloc (xmalloc.c:147) by 0x1F083E6: xvasprintf (xvasprintf.c:58) by 0x1E7EC7D: build_message_string(char const*, ...) (diagnostic.c:78) by 0x1E7F438: diagnostic_get_location_text(diagnostic_context*, expanded_location) (diagnostic.c:328) by 0x1E7FD54: default_diagnostic_start_span_fn(diagnostic_context*, expanded_location) (diagnostic.c:626) by 0x1EB3508: selftest::test_diagnostic_context::start_span_cb(diagnostic_context*, expanded_location) (selftest-diagnostic.c:57) by 0x1E89215: diagnostic_show_locus(diagnostic_context*, rich_location*, diagnostic_t) (diagnostic-show-locus.c:1992) by 0x1E8B373: selftest::test_diagnostic_show_locus_fixit_lines(selftest::line_table_case const&) (diagnostic-show-locus.c:2500) by 0x1EB0606: selftest::for_each_line_table_case(void (*)(selftest::line_table_case const&)) (input.c:3525) by 0x1E8F3B9: selftest::diagnostic_show_locus_c_tests() (diagnostic-show-locus.c:3159) by 0x1E010BF: selftest::run_tests() (selftest-run-tests.c:88) This patch fixes the leaks by ensuring that the pretty_printer "owns" the prefix if it's non-NULL, freeing it in the dtor and in pp_set_prefix. gcc/cp/ChangeLog: Backport of r263275 from trunk. 2018-08-02 David Malcolm * error.c (cxx_print_error_function): Duplicate "file" before passing it to pp_set_prefix. (cp_print_error_function): Use pp_take_prefix when saving the existing prefix. gcc/ChangeLog: Backport of r263275 from trunk. 2018-08-02 David Malcolm * diagnostic-show-locus.c (diagnostic_show_locus): Use pp_take_prefix when saving the existing prefix. * diagnostic.c (diagnostic_append_note): Likewise. * langhooks.c (lhd_print_error_function): Likewise. * pretty-print.c (pp_set_prefix): Drop the "const" from "prefix" param's type. Free the existing prefix. (pp_take_prefix): New function. (pretty_printer::pretty_printer): Drop the prefix parameter. Rename the length parameter to match the comment. (pretty_printer::~pretty_printer): Free the prefix. * pretty-print.h (pretty_printer::pretty_printer): Drop the prefix parameter. (struct pretty_printer): Drop the "const" from "prefix" field's type and clarify memory management. (pp_set_prefix): Drop the "const" from the 2nd param. (pp_take_prefix): New decl. --- gcc/cp/error.c | 9 +++++++-- gcc/diagnostic-show-locus.c | 2 +- gcc/diagnostic.c | 3 +-- gcc/langhooks.c | 2 +- gcc/pretty-print.c | 31 +++++++++++++++++++++++-------- gcc/pretty-print.h | 14 ++++++++------ 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 95b8b84..f7895de 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -3286,8 +3286,13 @@ void cxx_print_error_function (diagnostic_context *context, const char *file, diagnostic_info *diagnostic) { + char *prefix; + if (file) + prefix = xstrdup (file); + else + prefix = NULL; lhd_print_error_function (context, file, diagnostic); - pp_set_prefix (context->printer, file); + pp_set_prefix (context->printer, prefix); maybe_print_instantiation_context (context); } @@ -3315,7 +3320,7 @@ cp_print_error_function (diagnostic_context *context, return; if (diagnostic_last_function_changed (context, diagnostic)) { - const char *old_prefix = context->printer->prefix; + char *old_prefix = pp_take_prefix (context->printer); const char *file = LOCATION_FILE (diagnostic_location (diagnostic)); tree abstract_origin = diagnostic_abstract_origin (diagnostic); char *new_prefix = (file && abstract_origin == NULL) diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c index bdf608a..9c567bd 100644 --- a/gcc/diagnostic-show-locus.c +++ b/gcc/diagnostic-show-locus.c @@ -2000,7 +2000,7 @@ diagnostic_show_locus (diagnostic_context * context, context->last_location = loc; - const char *saved_prefix = pp_get_prefix (context->printer); + char *saved_prefix = pp_take_prefix (context->printer); pp_set_prefix (context->printer, NULL); layout layout (context, richloc, diagnostic_kind); diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index e22c17b..c61e0c4 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -1063,7 +1063,6 @@ diagnostic_append_note (diagnostic_context *context, { diagnostic_info diagnostic; va_list ap; - const char *saved_prefix; rich_location richloc (line_table, location); va_start (ap, gmsgid); @@ -1073,7 +1072,7 @@ diagnostic_append_note (diagnostic_context *context, va_end (ap); return; } - saved_prefix = pp_get_prefix (context->printer); + char *saved_prefix = pp_take_prefix (context->printer); pp_set_prefix (context->printer, diagnostic_build_prefix (context, &diagnostic)); pp_format (context->printer, &diagnostic.message); diff --git a/gcc/langhooks.c b/gcc/langhooks.c index 3cd7901..b24c87a 100644 --- a/gcc/langhooks.c +++ b/gcc/langhooks.c @@ -368,7 +368,7 @@ lhd_print_error_function (diagnostic_context *context, const char *file, { if (diagnostic_last_function_changed (context, diagnostic)) { - const char *old_prefix = context->printer->prefix; + char *old_prefix = pp_take_prefix (context->printer); tree abstract_origin = diagnostic_abstract_origin (diagnostic); char *new_prefix = (file && abstract_origin == NULL) ? file_name_as_prefix (context, file) : NULL; diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c index da0781e..6243aed 100644 --- a/gcc/pretty-print.c +++ b/gcc/pretty-print.c @@ -1491,23 +1491,38 @@ pp_clear_output_area (pretty_printer *pp) pp_buffer (pp)->line_length = 0; } -/* Set PREFIX for PRETTY-PRINTER. */ +/* Set PREFIX for PRETTY-PRINTER, taking ownership of PREFIX, which + will eventually be free-ed. */ + void -pp_set_prefix (pretty_printer *pp, const char *prefix) +pp_set_prefix (pretty_printer *pp, char *prefix) { + free (pp->prefix); pp->prefix = prefix; pp_set_real_maximum_length (pp); pp->emitted_prefix = false; pp_indentation (pp) = 0; } +/* Take ownership of PP's prefix, setting it to NULL. + This allows clients to save, overide, and then restore an existing + prefix, without it being free-ed. */ + +char * +pp_take_prefix (pretty_printer *pp) +{ + char *result = pp->prefix; + pp->prefix = NULL; + return result; +} + /* Free PRETTY-PRINTER's prefix, a previously malloc()'d string. */ void pp_destroy_prefix (pretty_printer *pp) { if (pp->prefix != NULL) { - free (CONST_CAST (char *, pp->prefix)); + free (pp->prefix); pp->prefix = NULL; } } @@ -1544,10 +1559,9 @@ pp_emit_prefix (pretty_printer *pp) } } -/* Construct a PRETTY-PRINTER with PREFIX and of MAXIMUM_LENGTH - characters per line. */ +/* Construct a PRETTY-PRINTER of MAXIMUM_LENGTH characters per line. */ -pretty_printer::pretty_printer (const char *p, int l) +pretty_printer::pretty_printer (int maximum_length) : buffer (new (XCNEW (output_buffer)) output_buffer ()), prefix (), padding (pp_none), @@ -1561,10 +1575,10 @@ pretty_printer::pretty_printer (const char *p, int l) translate_identifiers (true), show_color () { - pp_line_cutoff (this) = l; + pp_line_cutoff (this) = maximum_length; /* By default, we emit prefixes once per message. */ pp_prefixing_rule (this) = DIAGNOSTICS_SHOW_PREFIX_ONCE; - pp_set_prefix (this, p); + pp_set_prefix (this, NULL); } pretty_printer::~pretty_printer () @@ -1573,6 +1587,7 @@ pretty_printer::~pretty_printer () delete m_format_postprocessor; buffer->~output_buffer (); XDELETE (buffer); + free (prefix); } /* Append a string delimited by START and END to the output area of diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h index 56abe03..0d67e30 100644 --- a/gcc/pretty-print.h +++ b/gcc/pretty-print.h @@ -215,17 +215,18 @@ class format_postprocessor and add additional fields they need. */ struct pretty_printer { - // Default construct a pretty printer with specified prefix - // and a maximum line length cut off limit. - explicit pretty_printer (const char* = NULL, int = 0); + /* Default construct a pretty printer with specified + maximum line length cut off limit. */ + explicit pretty_printer (int = 0); virtual ~pretty_printer (); /* Where we print external representation of ENTITY. */ output_buffer *buffer; - /* The prefix for each new line. */ - const char *prefix; + /* The prefix for each new line. If non-NULL, this is "owned" by the + pretty_printer, and will eventually be free-ed. */ + char *prefix; /* Where to put whitespace around the entity being formatted. */ pp_padding padding; @@ -338,7 +339,8 @@ pp_get_prefix (const pretty_printer *pp) { return pp->prefix; } #define pp_buffer(PP) (PP)->buffer extern void pp_set_line_maximum_length (pretty_printer *, int); -extern void pp_set_prefix (pretty_printer *, const char *); +extern void pp_set_prefix (pretty_printer *, char *); +extern char *pp_take_prefix (pretty_printer *); extern void pp_destroy_prefix (pretty_printer *); extern int pp_remaining_character_count_for_line (pretty_printer *); extern void pp_clear_output_area (pretty_printer *); From patchwork Thu Feb 14 23:23:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1042480 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496184-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NRvkLQyp"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440rmq2K5zz9s7h for ; Fri, 15 Feb 2019 09:34:51 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=UAF5bLLQ8cCuw3XjOUWm1AdsvjT7ZDv9Ww/hwHajHeyIDW6fg80HW l8A/kCnydvqokkcF7FcthxTpoA0cg5tFsDNzIhTlpy1aJTyPKJgUPSQyRMvjTSbu aWLUHRYTNDGuwrPAN+B/iSTmx2iKIBDr5DiXpg5LpmDMZikAegEysA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=4dR9NwnG49jQ2J/eSbNTKEYyNac=; b=NRvkLQypOfS0LJIhVYw1 bOd8XGpdXQE7UyCYXjt6broayvJcAVNMHCUK40zOGplJf2VLloqQZ55fCCvjvKUA XLXXXdYTO8d6m7auhR77hIeRoHhjXd+qIdLpT6NBLtWiLr8QrKx2FZXNzF5zV5Xh YuPCME0nAzjMPO/ucCK8HY0= Received: (qmail 59799 invoked by alias); 14 Feb 2019 22:33:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 59446 invoked by uid 89); 14 Feb 2019 22:33:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:warn_if X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Feb 2019 22:33:25 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FA1F8B95C for ; Thu, 14 Feb 2019 22:33:24 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-37.phx2.redhat.com [10.3.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D4C05E7A8; Thu, 14 Feb 2019 22:33:23 +0000 (UTC) From: David Malcolm To: jakub@redhat.com, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 4/7] docs: fix stray duplicated words Date: Thu, 14 Feb 2019 18:23:41 -0500 Message-Id: <1550186624-25444-5-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> References: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes gcc/ChangeLog: Backport of 263295 from trunk. 2018-08-03 David Malcolm * doc/gcov.texi (-x): Remove duplicate "to". * doc/invoke.texi (-Wnoexcept-type): Remove duplicate "calls". (-Wif-not-aligned): Remove duplicate "is". (-flto): Remove duplicate "the". (MicroBlaze Options): In examples of "-mcpu=cpu-type", remove duplicate "v5.00.b". (MSP430 Options): Remove duplicate "and" from the description of "-mgprel-sec=regexp". (x86 Options): Remove duplicate copies of "vmldLog102" and vmlsLog104 from description of "-mveclibabi=type". --- gcc/doc/gcov.texi | 2 +- gcc/doc/invoke.texi | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi index 5923587..cc1376f 100644 --- a/gcc/doc/gcov.texi +++ b/gcc/doc/gcov.texi @@ -333,7 +333,7 @@ Print verbose informations related to basic blocks and arcs. @item -x @itemx --hash-filenames -By default, gcov uses the full pathname of the source files to to create +By default, gcov uses the full pathname of the source files to create an output filename. This can lead to long filenames that can overflow filesystem limits. This option creates names of the form @file{@var{source-file}##@var{md5}.gcov}, diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 8ec5f01..e5c4e81 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -3020,7 +3020,7 @@ void h() @{ f(g); @} @end smallexample @noindent -In C++14, @code{f} calls calls @code{f}, but in +In C++14, @code{f} calls @code{f}, but in C++17 it calls @code{f}. @item -Wclass-memaccess @r{(C++ and Objective-C++ only)} @@ -4539,7 +4539,7 @@ The @option{-Wimplicit-fallthrough=3} warning is enabled by @option{-Wextra}. @opindex Wif-not-aligned @opindex Wno-if-not-aligned Control if warning triggered by the @code{warn_if_not_aligned} attribute -should be issued. This is is enabled by default. +should be issued. This is enabled by default. Use @option{-Wno-if-not-aligned} to disable it. @item -Wignored-qualifiers @r{(C and C++ only)} @@ -9479,7 +9479,7 @@ for LTO, use @command{gcc-ar} and @command{gcc-ranlib} instead of @command{ar} and @command{ranlib}; to show the symbols of object files with GIMPLE bytecode, use @command{gcc-nm}. Those commands require that @command{ar}, @command{ranlib} -and @command{nm} have been compiled with plugin support. At link time, use the the +and @command{nm} have been compiled with plugin support. At link time, use the flag @option{-fuse-linker-plugin} to ensure that the library participates in the LTO optimization process: @@ -20084,7 +20084,7 @@ Use features of, and schedule code for, the given CPU. Supported values are in the format @samp{v@var{X}.@var{YY}.@var{Z}}, where @var{X} is a major version, @var{YY} is the minor version, and @var{Z} is compatibility code. Example values are @samp{v3.00.a}, -@samp{v4.00.b}, @samp{v5.00.a}, @samp{v5.00.b}, @samp{v5.00.b}, @samp{v6.00.a}. +@samp{v4.00.b}, @samp{v5.00.a}, @samp{v5.00.b}, @samp{v6.00.a}. @item -mxl-soft-mul @opindex mxl-soft-mul @@ -21746,7 +21746,7 @@ GP-relative addressing. It is most useful in conjunction with The @var{regexp} is a POSIX Extended Regular Expression. This option does not affect the behavior of the @option{-G} option, and -and the specified sections are in addition to the standard @code{.sdata} +the specified sections are in addition to the standard @code{.sdata} and @code{.sbss} small-data sections that are recognized by @option{-mgpopt}. @item -mr0rel-sec=@var{regexp} @@ -27588,11 +27588,11 @@ To use this option, both @option{-ftree-vectorize} and ABI-compatible library must be specified at link time. GCC currently emits calls to @code{vmldExp2}, -@code{vmldLn2}, @code{vmldLog102}, @code{vmldLog102}, @code{vmldPow2}, +@code{vmldLn2}, @code{vmldLog102}, @code{vmldPow2}, @code{vmldTanh2}, @code{vmldTan2}, @code{vmldAtan2}, @code{vmldAtanh2}, @code{vmldCbrt2}, @code{vmldSinh2}, @code{vmldSin2}, @code{vmldAsinh2}, @code{vmldAsin2}, @code{vmldCosh2}, @code{vmldCos2}, @code{vmldAcosh2}, -@code{vmldAcos2}, @code{vmlsExp4}, @code{vmlsLn4}, @code{vmlsLog104}, +@code{vmldAcos2}, @code{vmlsExp4}, @code{vmlsLn4}, @code{vmlsLog104}, @code{vmlsPow4}, @code{vmlsTanh4}, @code{vmlsTan4}, @code{vmlsAtan4}, @code{vmlsAtanh4}, @code{vmlsCbrt4}, @code{vmlsSinh4}, @code{vmlsSin4}, @code{vmlsAsinh4}, @code{vmlsAsin4}, @code{vmlsCosh4}, From patchwork Thu Feb 14 23:23:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1042482 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496186-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ARss06Xo"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440rnN0bp6z9s3l for ; Fri, 15 Feb 2019 09:35:19 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=R4EZMfbOswTKHw42N7ZDEof8h9p0jNdcCRxYOQjpIJa9/LC8lJFgz bClmRSPPrd+2Dj8CANFb4e3zm7cK+uqDRAa8CYMDTQpWo/v6c3wqZpo3oikV81sZ dynD3ou0/87MmhpnK9FOg5+V7gIepKP0nO9ujwk0f8Mtwrw8sNHvMY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=5FLrBwUaBSMAO0/hoqG+AdfXq3s=; b=ARss06XogwvJ1q/a/r6j INCClUjhKGSz0feYIHXNWlgDF9qGeivviAbgCsY8g4agFqsEqagU4iwNHN/ziVGT q+xnM4A+R/GGswIDxoIZY2DrXer49sPsoLExcrx471mEzhBmhLllqLgk5ZjerDf1 KRyUULq3mQlWoTSjdC9IQ3E= Received: (qmail 59940 invoked by alias); 14 Feb 2019 22:33:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 59451 invoked by uid 89); 14 Feb 2019 22:33:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=toplevc, toplev.c, UD:toplev.c X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Feb 2019 22:33:27 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15D35C0AAB27 for ; Thu, 14 Feb 2019 22:33:26 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-37.phx2.redhat.com [10.3.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4DBA5DEB2; Thu, 14 Feb 2019 22:33:24 +0000 (UTC) From: David Malcolm To: jakub@redhat.com, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 5/7] Fix memory leak in selftest::test_expansion_to_rtl Date: Thu, 14 Feb 2019 18:23:42 -0500 Message-Id: <1550186624-25444-6-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> References: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes "make selftest-valgrind" shows: 187 bytes in 1 blocks are definitely lost in loss record 567 of 669 at 0x4A081D4: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x1F08260: xcalloc (xmalloc.c:162) by 0xB24F32: init_emit() (emit-rtl.c:5843) by 0xC10080: prepare_function_start() (function.c:4803) by 0xC10254: init_function_start(tree_node*) (function.c:4877) by 0x1CDF92A: selftest::test_expansion_to_rtl() (function-tests.c:595) by 0x1CE007C: selftest::function_tests_c_tests() (function-tests.c:676) by 0x1E010E7: selftest::run_tests() (selftest-run-tests.c:98) by 0x1062D1E: toplev::run_self_tests() (toplev.c:2225) by 0x1062F40: toplev::main(int, char**) (toplev.c:2303) by 0x1E5B90A: main (main.c:39) The allocation in question is: crtl->emit.regno_pointer_align = XCNEWVEC (unsigned char, crtl->emit.regno_pointer_align_length); This patch fixes this leak (and makes the output of "make selftest-valgrind" clean) by calling free_after_compilation at the end of the selftest in question. gcc/ChangeLog: Backport of r263339 from trunk. 2018-08-06 David Malcolm * function-tests.c (selftest::test_expansion_to_rtl): Call free_after_compilation. --- gcc/function-tests.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/function-tests.c b/gcc/function-tests.c index 1b5ebf3..196b3a3 100644 --- a/gcc/function-tests.c +++ b/gcc/function-tests.c @@ -661,6 +661,7 @@ test_expansion_to_rtl () ASSERT_STR_CONTAINS (dump, ") ;; function \"test_fn\"\n"); free (dump); + free_after_compilation (fun); } /* Run all of the selftests within this file. */ From patchwork Thu Feb 14 23:23:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1042478 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496182-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="cFoe0ZiS"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440rmK4NHQz9s3l for ; Fri, 15 Feb 2019 09:34:25 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=UrielGKwjwhS3x2Kaogy9ncsHDkm6q0DnD8zLtPsTF/QObZ5JGE17 FyiKrw0fJkJd0RML7dgw92mQOixoKTgS1HiU1X4/IjfyjYFfhjP3d9KZFIRSx6jh MpWgUteuHz1KO0K1ypHG4wMW6K8zJsmfEDVrzGo1Ljvn9J9T0vPEFM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=hzKiZ9a6Cevw4ccUJpHAuW9RYb0=; b=cFoe0ZiSdYZk7hxnTQfS NSa2Ngu2pG/QQGP8oHRA6ABdkoak3DZX0LKyXHISAQYfyDOhVjP7UFi7H1sCACpp bbMbgRdVwSMQ+Qn5NePu25sm2pBaKo9QuQmj7YwNmbrHfJYHckXAktS6PjOKeXBS oMUHU6UZ52+g9zlS8Xw8sSM= Received: (qmail 59659 invoked by alias); 14 Feb 2019 22:33:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 59472 invoked by uid 89); 14 Feb 2019 22:33:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:tsubst_, error_mark_node X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Feb 2019 22:33:28 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C81544830 for ; Thu, 14 Feb 2019 22:33:27 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-37.phx2.redhat.com [10.3.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78DF95DEB2; Thu, 14 Feb 2019 22:33:26 +0000 (UTC) From: David Malcolm To: jakub@redhat.com, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 6/7] Fix ICE on class-template argument deduction (PR c++/88795) Date: Thu, 14 Feb 2019 18:23:43 -0500 Message-Id: <1550186624-25444-7-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> References: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes PR c++/88795 reports an ICE building a function_type for a deduction guide when the substitution into the function signature fails, due to an error_mark_node being returned from tsubst_arg_types but not being checked for. This error_mark_node gets used as the TYPE_ARG_TYPES, leading to ICEs in various places that assume this is a TREE_LIST. This patch checks the result of tsubst_arg_types and propagates the failure if it returns error_mark_node. It also adds an assertion to build_function_type, to fail faster if passed in error_mark_node. gcc/cp/ChangeLog: Backport of r267957 from trunk. 2019-01-15 David Malcolm PR c++/88795 * pt.c (build_deduction_guide): Bail out if tsubst_arg_types fails. gcc/testsuite/ChangeLog: Backport of r267957 from trunk. 2019-01-15 David Malcolm PR c++/88795 * g++.dg/template/pr88795.C: New test. gcc/ChangeLog: Backport of r267957 from trunk. 2019-01-15 David Malcolm PR c++/88795 * tree.c (build_function_type): Assert that arg_types is not error_mark_node. --- gcc/cp/pt.c | 2 ++ gcc/testsuite/g++.dg/template/pr88795.C | 23 +++++++++++++++++++++++ gcc/tree.c | 2 ++ 3 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/pr88795.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 72dc1e0..895cb5a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -26494,6 +26494,8 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain) targs = template_parms_to_args (tparms); fparms = tsubst_arg_types (fparms, tsubst_args, NULL_TREE, complain, ctor); + if (fparms == error_mark_node) + ok = false; fargs = tsubst (fargs, tsubst_args, complain, ctor); if (ci) ci = tsubst_constraint_info (ci, tsubst_args, complain, ctor); diff --git a/gcc/testsuite/g++.dg/template/pr88795.C b/gcc/testsuite/g++.dg/template/pr88795.C new file mode 100644 index 0000000..918aa6d --- /dev/null +++ b/gcc/testsuite/g++.dg/template/pr88795.C @@ -0,0 +1,23 @@ +// { dg-do compile { target c++17 } } + +template +struct Array {}; + +template +struct Foo { + static constexpr int size() { + return size_; + } + + template + Foo(U, Array) {} +}; + +template +Foo(U, Array) -> Foo; + +int main() { + Array arr{}; + + Foo foo{2.0, arr}; +} diff --git a/gcc/tree.c b/gcc/tree.c index ca5d810..091a63a 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -8023,6 +8023,8 @@ build_function_type (tree value_type, tree arg_types) bool any_structural_p, any_noncanonical_p; tree canon_argtypes; + gcc_assert (arg_types != error_mark_node); + if (TREE_CODE (value_type) == FUNCTION_TYPE) { error ("function return type cannot be function"); From patchwork Thu Feb 14 23:23:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1042481 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496185-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NKrieai0"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440rn35R6pz9s3l for ; Fri, 15 Feb 2019 09:35:03 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=RwGxnbH4TRNY3ctnIfsP+T++vzRM5E+csuaFxiZYh5YxYqRUZ28se hu/g62yOOeJTnv9GxtEPCagyyv3OgNUB14bIzHo7j+9vugyuIVKztvEjjlor86vE /ns1dgOMXcSEMubnvuoFTuHAfCfQoIse2VFGJOaQ1Ql/aOl5wms4wk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=OD//A2DVjexi+Qv+ATzlntPTi5E=; b=NKrieai0QWhO+6Z3vHYV xvU8BJmxcnsSrZI4Z1Pwhx1rORvGWs1Bylg0qrOvHvn05h2tI4DZ9G6IUYa7Q+x0 6mVt7LZtzH9BLUfolCq4LFVB7xmZxMT0cJ9aMJnNntqja+lSdaoDMUN2LPzDeBgx CXETcMBEutEUx7K+pQdXXRM= Received: (qmail 59879 invoked by alias); 14 Feb 2019 22:33:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 59518 invoked by uid 89); 14 Feb 2019 22:33:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:decl_ma, sk:DECL_MA X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Feb 2019 22:33:30 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31474C0ABF45 for ; Thu, 14 Feb 2019 22:33:29 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-37.phx2.redhat.com [10.3.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D4765E7A8; Thu, 14 Feb 2019 22:33:27 +0000 (UTC) From: David Malcolm To: jakub@redhat.com, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 7/7] C++ concepts: fix ICE with requires on dtors (PR c++/89036) Date: Thu, 14 Feb 2019 18:23:44 -0500 Message-Id: <1550186624-25444-8-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> References: <1550186624-25444-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes PR c++/89036 reports an ICE due to this assertion failing 1136 /* A class should never have more than one destructor. */ 1137 gcc_assert (!current_fns || via_using || !DECL_DESTRUCTOR_P (method)); on this template with a pair of dtors, with mutually exclusive "requires" clauses: template struct Y { ~Y() requires(true) = default; ~Y() requires(false) {} }; Nathan introduced this assertion as part of: ca9219bf18c68a001d62ecb981bc9176b0feaf12 (aka r251340): 2017-08-24 Nathan Sidwell Conversion operators kept on single overload set which, amongst other changes to add_method had this: /* A class should never have more than one destructor. */ - if (current_fns && DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (method)) - return false; + gcc_assert (!current_fns || !DECL_DESTRUCTOR_P (method)); The following patch drops the assertion. gcc/cp/ChangeLog: 2019-02-13 David Malcolm Backport of r268847 from trunk. PR c++/89036 * class.c (add_method): Drop destructor assertion. gcc/testsuite/ChangeLog: 2019-02-13 David Malcolm Backport of r268847 from trunk. PR c++/89036 * g++.dg/concepts/pr89036.C: New test. --- gcc/cp/class.c | 3 --- gcc/testsuite/g++.dg/concepts/pr89036.C | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/concepts/pr89036.C diff --git a/gcc/cp/class.c b/gcc/cp/class.c index d524a98..834ba17 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1141,9 +1141,6 @@ add_method (tree type, tree method, bool via_using) } } - /* A class should never have more than one destructor. */ - gcc_assert (!current_fns || !DECL_DESTRUCTOR_P (method)); - current_fns = ovl_insert (method, current_fns, via_using); if (!COMPLETE_TYPE_P (type) && !DECL_CONV_FN_P (method) diff --git a/gcc/testsuite/g++.dg/concepts/pr89036.C b/gcc/testsuite/g++.dg/concepts/pr89036.C new file mode 100644 index 0000000..f83ef8b --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/pr89036.C @@ -0,0 +1,8 @@ +// { dg-do compile { target c++11 } } +// { dg-options "-fconcepts" } + +template +struct Y { + ~Y() requires(true) = default; + ~Y() requires(false) {} +};