From patchwork Fri Jan 12 17:37:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 860080 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-471015-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.b="fpDG9sEb"; 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 3zJ8wf0D2Sz9s4s for ; Sat, 13 Jan 2018 04:33:20 +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=gbwqX2qZXdE/YR5viyR0/rRiCui7fcymnsVFXt/kuL5YRE2VXJcSs 1JNbLh+PzB8p8quJLgSpgLgZqDWW+UALzNUVCoJ6XRTNX2PHUrpqKFMWmiW9VwzR 1Lv1d0VdvWwQ2o59DHdzbM/jWgKcHk5DXsFQ2TstyamqgewFr3B4Nw= 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=hsPiPGbEjJTa+IZzBGhTlw43UxM=; b=fpDG9sEbKXG2M7nKjJsv 1y/Y/OYahP/iY76UN8YUU9qgm2tHiLyqFTm/qIm/JKxyLS4Mp9f4A9lYEmsQbBKA acBuXSeX9UcS93vEFXnyffzssHeCa9BgT2XbvSkr5EPVBVYFEtbqStRqv+2b9IEU c6vV1MiqoMDB47Xu6gm2k/o= Received: (qmail 20612 invoked by alias); 12 Jan 2018 17:33:12 -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 20455 invoked by uid 89); 12 Jan 2018 17:33:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= 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; Fri, 12 Jan 2018 17:33:11 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C218590902; Fri, 12 Jan 2018 17:33:09 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-31.phx2.redhat.com [10.3.112.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C3975D6A6; Fri, 12 Jan 2018 17:33:08 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: Markus Trippelsdorf , David Malcolm Subject: [PATCH v2] Fix failure building LLVM with location wrapper nodes (PR c++/83799) Date: Fri, 12 Jan 2018 12:37:24 -0500 Message-Id: <1515778644-36057-1-git-send-email-dmalcolm@redhat.com> In-Reply-To: <20180112080726.GD249@x4> References: <20180112080726.GD249@x4> X-IsSubscribed: yes On Fri, 2018-01-12 at 09:07 +0100, Markus Trippelsdorf wrote: > On 2018.01.11 at 18:21 -0500, David Malcolm wrote: > > diff --git a/gcc/testsuite/g++.dg/wrappers/pr83799.C > > b/gcc/testsuite/g++.dg/wrappers/pr83799.C > > new file mode 100644 > > index 0000000..f93c0ae > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/wrappers/pr83799.C > > @@ -0,0 +1,18 @@ > > +class DataLayout; > > +class TargetLoweringBase { > > + void getTypeLegalizationCost(const DataLayout &DL) const; > > +}; > > +class TargetTransformInfoImplBase { > > + const DataLayout &DL; // this line isn't actually needed to > > reproduce the issue > > +}; > > +template > > +class TargetTransformInfoImplCRTPBase : public > > TargetTransformInfoImplBase {}; > > +template > > +class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase > > { > > + const TargetLoweringBase *getTLI() const; > > + using TargetTransformInfoImplBase::DL; > > + void getArithmeticInstrCost() { > > + const TargetLoweringBase *TLI = getTLI(); > > + TLI->getTypeLegalizationCost(DL); > > + } > > +}; > > Thanks for the fix. Minor nit: > Please make TargetLoweringBase and TargetLoweringBase a struct > instead > of a class, to prevent illegal access of private members. Here's an updated version of the patch which does so (so that the testcase compiles cleanly on clang). I also added some more assertions to selftest::test_type_dependent_expression_p. Successfully bootstrapped®rtested on x86_64-pc-linux-gnu. Manually tested with "make s-selftest-c++" (since we don't run the selftests for cc1plus by default). OK for trunk? Blurb from v1: PR c++/83799 reports a failure building LLVM due to a bogus "no matching function for call to" error at a callsite like this: TLI->getTypeLegalizationCost(DL); where "DL" is from: using TargetTransformInfoImplBase::DL; The root cause is that type_dependent_expression_p on a USING_DECL should return true when processing a template, but after r256448 the the argument at the callsite is a location wrapper around the USING_DECL, and type_dependent_expression_p erroneously returns false for it, as it is comparing tree codes, and failing a match, then looking at types. This prevents cp_parser_postfix_expression from using the "build_min_nt_call_vec" path for handling the call, instead erroneously handling it via build_new_method_call (which fails for this case). This patch fixes the problem by stripping any location wrappers before the various tree code tests in type_dependent_expression_p. It fixes the reduced test case, and the full BasicTargetTransformInfo.ii; after this patch, the assembly generated for that latter case is identical to that generated before r256448. gcc/cp/ChangeLog: PR c++/83799 * pt.c (type_dependent_expression_p): Strip any location wrapper before testing tree codes. (selftest::test_type_dependent_expression_p): New function. (selftest::cp_pt_c_tests): Call it. gcc/testsuite/ChangeLog: PR c++/83799 * g++.dg/wrappers/pr83799.C: New test case. --- gcc/cp/pt.c | 38 +++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/wrappers/pr83799.C | 18 ++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 gcc/testsuite/g++.dg/wrappers/pr83799.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4f8086b..1f868d0 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -24219,6 +24219,8 @@ type_dependent_expression_p (tree expression) if (expression == NULL_TREE || expression == error_mark_node) return false; + STRIP_ANY_LOCATION_WRAPPER (expression); + /* An unresolved name is always dependent. */ if (identifier_p (expression) || TREE_CODE (expression) == USING_DECL @@ -26657,12 +26659,48 @@ test_build_non_dependent_expr () build_non_dependent_expr (wrapped_string_lit)); } +/* Verify that type_dependent_expression_p () works correctly, even + in the presence of location wrapper nodes. */ + +static void +test_type_dependent_expression_p () +{ + location_t loc = BUILTINS_LOCATION; + + tree name = get_identifier ("foo"); + + /* If no templates are involved, nothing is type-dependent. */ + gcc_assert (!processing_template_decl); + ASSERT_FALSE (type_dependent_expression_p (name)); + + ++processing_template_decl; + + /* Within a template, an unresolved name is always type-dependent. */ + ASSERT_TRUE (type_dependent_expression_p (name)); + + /* Ensure it copes with NULL_TREE and errors. */ + ASSERT_FALSE (type_dependent_expression_p (NULL_TREE)); + ASSERT_FALSE (type_dependent_expression_p (error_mark_node)); + + /* A USING_DECL in a template should be type-dependent, even if wrapped + with a location wrapper (PR c++/83799). */ + tree using_decl = build_lang_decl (USING_DECL, name, NULL_TREE); + TREE_TYPE (using_decl) = integer_type_node; + ASSERT_TRUE (type_dependent_expression_p (using_decl)); + tree wrapped_using_decl = maybe_wrap_with_location (using_decl, loc); + ASSERT_TRUE (location_wrapper_p (wrapped_using_decl)); + ASSERT_TRUE (type_dependent_expression_p (wrapped_using_decl)); + + --processing_template_decl; +} + /* Run all of the selftests within this file. */ void cp_pt_c_tests () { test_build_non_dependent_expr (); + test_type_dependent_expression_p (); } } // namespace selftest diff --git a/gcc/testsuite/g++.dg/wrappers/pr83799.C b/gcc/testsuite/g++.dg/wrappers/pr83799.C new file mode 100644 index 0000000..b4f5a69 --- /dev/null +++ b/gcc/testsuite/g++.dg/wrappers/pr83799.C @@ -0,0 +1,18 @@ +struct DataLayout; +struct TargetLoweringBase { + void getTypeLegalizationCost(const DataLayout &DL) const; +}; +struct TargetTransformInfoImplBase { + const DataLayout &DL; +}; +template +struct TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {}; +template +struct BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { + const TargetLoweringBase *getTLI() const; + using TargetTransformInfoImplBase::DL; + void getArithmeticInstrCost() { + const TargetLoweringBase *TLI = getTLI(); + TLI->getTypeLegalizationCost(DL); + } +};