From patchwork Tue Jan 9 21:13:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 857767 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-470606-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="VOO1CeeR"; 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 3zGPtN0cH4z9s0g for ; Wed, 10 Jan 2018 08:10: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; q=dns; s=default; b=mNvvQffTNdTL cvpYD81B1PD/T5ZvJHCT15Ntjhs86Ed+vLx456c3tlFwFXAagApsXITYYbCAg5eV /eoUcCKXVFfL/ie4TRWZYdWrQw0cTQ76tLpxyTIqwb4CAVD4SNg0lfz50Y6XGHFz kpAOcazQOr7OIw8cnmkfDXZUSAW7YJA= 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; s=default; bh=dyF4nyaqRRZKl/DmT4 n/aF7Jojw=; b=VOO1CeeR1BXwzLxkHgiC8oV87m+awF9xSSy7A4dtkfVGyeU4t5 9HPmkhEU5qY1V1GW4t/G7WxzIKUEWEp++/Bx3z5VO7lzlhiU8VQQDR+kfqlFmgCd xNsEnAgazBVWvvhHf3K3cbFbgNokljFa2ivgQ7AlWx8K1CUYx3NKFmHBY= Received: (qmail 88506 invoked by alias); 9 Jan 2018 21:09:44 -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 88387 invoked by uid 89); 9 Jan 2018 21:09:43 -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; Tue, 09 Jan 2018 21:09:41 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0AD0C027412 for ; Tue, 9 Jan 2018 21:09:39 +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 F031A7FB8F; Tue, 9 Jan 2018 21:09:38 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH] Add some reproducers for issues found when developing the location-wrappers patch Date: Tue, 9 Jan 2018 16:13:47 -0500 Message-Id: <1515532427-32572-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes Whilst developing the location-wrapper patch kit, I accumulated various source files for which my work-in-progress patched-cc1plus had different behavior to an unpatched cc1plus: some of these were crashes, others were erroneous diagnostics. All of these are now fixed, but it seems appropriate to capture them in our testsuite, hence this patch. Tested in conjunction with the patch kit; adds 12 PASS, 2 UNSUPPORTED and 3 XFAILs to g++.sum. The XFAILs are due to the use of dg-excess-errors in g++.dg/wrappers/cp-stdlib.C. This source file is full of syntax errors, but used to ICE my cc1plus *somewhere* in error recovery, and I wasn't able to minimize it further at the time. I fixed the ICE, but it seems worth keeping as a test case. I checked hacking in an ICE, and dg-excess-errors will FAIL on it (rather than merely XFAIL, on all of the syntax errors). OK for trunk? gcc/testsuite/ChangeLog: PR c++/43486 * g++.dg/wrappers: New subdirectory. * g++.dg/wrappers/README: New file. * g++.dg/wrappers/alloc.C: New test case. * g++.dg/wrappers/cow-istream-string.C: New test case. * g++.dg/wrappers/cp-stdlib.C: New test case. * g++.dg/wrappers/sanitizer_coverage_libcdep_new.C: New test case. * g++.dg/wrappers/wrapper-around-type-pack-expansion.C: New test case. --- gcc/testsuite/g++.dg/wrappers/README | 2 + gcc/testsuite/g++.dg/wrappers/alloc.C | 43 ++++++++ gcc/testsuite/g++.dg/wrappers/cow-istream-string.C | 15 +++ gcc/testsuite/g++.dg/wrappers/cp-stdlib.C | 117 +++++++++++++++++++++ .../wrappers/sanitizer_coverage_libcdep_new.C | 22 ++++ .../wrappers/wrapper-around-type-pack-expansion.C | 50 +++++++++ 6 files changed, 249 insertions(+) create mode 100644 gcc/testsuite/g++.dg/wrappers/README create mode 100644 gcc/testsuite/g++.dg/wrappers/alloc.C create mode 100644 gcc/testsuite/g++.dg/wrappers/cow-istream-string.C create mode 100644 gcc/testsuite/g++.dg/wrappers/cp-stdlib.C create mode 100644 gcc/testsuite/g++.dg/wrappers/sanitizer_coverage_libcdep_new.C create mode 100644 gcc/testsuite/g++.dg/wrappers/wrapper-around-type-pack-expansion.C diff --git a/gcc/testsuite/g++.dg/wrappers/README b/gcc/testsuite/g++.dg/wrappers/README new file mode 100644 index 0000000..9cba970 --- /dev/null +++ b/gcc/testsuite/g++.dg/wrappers/README @@ -0,0 +1,2 @@ +This directory contains reproducers for issues seen when adding location +wrapper nodes to the C++ frontend (ICEs and behavior changes). diff --git a/gcc/testsuite/g++.dg/wrappers/alloc.C b/gcc/testsuite/g++.dg/wrappers/alloc.C new file mode 100644 index 0000000..e004470 --- /dev/null +++ b/gcc/testsuite/g++.dg/wrappers/alloc.C @@ -0,0 +1,43 @@ +// { dg-do compile { target c++11 } } + +template class _Op, typename... _Args> +struct __detector +{ + using type = _Op<_Args...>; +}; +template class _Op, typename... _Args> +using __detected_or = __detector<_Default, void, _Op, _Args...>; +template class _Op, typename... _Args> +using __detected_or_t = typename __detected_or<_Default, _Op, _Args...>::type; +template +struct allocator_traits { + template + using __pointer = typename _Tp::pointer; + using pointer = __detected_or_t; +}; +template +struct _Pointer_adapter { + typedef typename _Storage_policy::element_type element_type; + typedef element_type& reference; +}; +template +inline _Tp* addressof(_Tp& __r); // { dg-warning "used but never defined" } +template +struct __allocated_ptr { + __allocated_ptr() + { + using pointer = typename allocator_traits<_Alloc>::pointer; + typename _Pointer_adapter::reference __r = *(int*)0; + addressof(__r); + } +}; +template +struct _Std_pointer_impl { + typedef _Tp element_type; +}; +template +struct CustomPointerAlloc { + typedef Tp value_type; + typedef _Pointer_adapter<_Std_pointer_impl> pointer; +}; +__allocated_ptr> __guard_ptr; diff --git a/gcc/testsuite/g++.dg/wrappers/cow-istream-string.C b/gcc/testsuite/g++.dg/wrappers/cow-istream-string.C new file mode 100644 index 0000000..23b0585 --- /dev/null +++ b/gcc/testsuite/g++.dg/wrappers/cow-istream-string.C @@ -0,0 +1,15 @@ +template +struct basic_string { + static const _CharT _S_terminal; + static void assign(const _CharT& __c2); + void _M_set_length_and_sharable() { + assign(_S_terminal); + } +}; + +template +const _CharT basic_string<_CharT>::_S_terminal = _CharT(); + +void getline(basic_string& __str) { + __str._M_set_length_and_sharable(); +} diff --git a/gcc/testsuite/g++.dg/wrappers/cp-stdlib.C b/gcc/testsuite/g++.dg/wrappers/cp-stdlib.C new file mode 100644 index 0000000..d29585f --- /dev/null +++ b/gcc/testsuite/g++.dg/wrappers/cp-stdlib.C @@ -0,0 +1,117 @@ +/* At one time this triggered ICEs with location wrapper nodes, + apparently requiring error-recovery (hence the various syntax + errors in this file. */ + +// { dg-excess-errors "expected to be full of errors, but not an ICE" } + +namespace std +{ + inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { } +} +namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) +{ + template + class new_allocator + { + typedef _Tp value_type; + }; +} +namespace std +{ + template + using __allocator_base = __gnu_cxx::new_allocator<_Tp>; +} +namespace std __attribute__ ((__visibility__ ("default"))) +{ + { + }; + template + class allocator : public __allocator_base<_Tp> + { + }; + template + struct allocator_traits : __allocator_traits_base + { + }; + template + struct allocator_traits> + { + using allocator_type = allocator<_Tp>; + template + using rebind_alloc = allocator<_Up>; + allocate(allocator_type& __a, size_type __n) + }; +} +namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) +{ +template + struct __alloc_traits + : std::allocator_traits<_Alloc> + { + typedef std::allocator_traits<_Alloc> _Base_type; + template + struct rebind + { typedef typename _Base_type::template rebind_alloc<_Tp> other; }; + }; +{ + { + } + } + } + { + { + } +} +namespace std __attribute__ ((__visibility__ ("default"))) +{ + struct char_traits; +namespace __cxx11 { + template, + typename _Alloc = allocator<_CharT> > + class basic_string; + } +} +namespace std __attribute__ ((__visibility__ ("default"))) +{ +namespace __cxx11 { + template + class basic_string + { + typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template + rebind<_CharT>::other _Char_alloc_type; + typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits; + public: + { + { + } + } + operator=(const basic_string& __str) + { + { + { + { + const auto __len = __str.size(); + auto __alloc = __str._M_get_allocator(); + auto __ptr = _Alloc_traits::allocate(__alloc, __len + 1); + } + } + } + } + { + } + size() const noexcept + } +namespace filesystem +{ + class path + { + typedef char value_type; + typedef std::basic_string string_type; + { + } + string_type _M_pathname; + }; + class directory_entry + { + void assign(const filesystem::path& __p) { _M_path = __p; } + filesystem::path _M_path; diff --git a/gcc/testsuite/g++.dg/wrappers/sanitizer_coverage_libcdep_new.C b/gcc/testsuite/g++.dg/wrappers/sanitizer_coverage_libcdep_new.C new file mode 100644 index 0000000..2be140b --- /dev/null +++ b/gcc/testsuite/g++.dg/wrappers/sanitizer_coverage_libcdep_new.C @@ -0,0 +1,22 @@ +namespace __sanitizer { + +enum FileAccessMode { + RdOnly, + WrOnly, + RdWr +}; + +int OpenFile(const char *filename, int mode, + int *errno_p); +} + +using namespace __sanitizer; + +namespace __sancov { + +static int OpenFile(const char* path) { + int err; + int fd = OpenFile(path, WrOnly, &err); + return fd; +} +} diff --git a/gcc/testsuite/g++.dg/wrappers/wrapper-around-type-pack-expansion.C b/gcc/testsuite/g++.dg/wrappers/wrapper-around-type-pack-expansion.C new file mode 100644 index 0000000..5072d1a --- /dev/null +++ b/gcc/testsuite/g++.dg/wrappers/wrapper-around-type-pack-expansion.C @@ -0,0 +1,50 @@ +// { dg-do compile { target c++11 } } + +typedef long unsigned int size_t; + +template +struct remove_reference {}; + +template +constexpr _Tp&& +forward(typename remove_reference<_Tp>::type& __t) noexcept +{ +} + +struct __allocator_traits_base { + template + struct __rebind + { + using type = typename _Tp::template rebind<_Up>::other; + }; +}; + +template +using __alloc_rebind = typename __allocator_traits_base::template __rebind<_Alloc, _Up>::type; + +template struct allocator_traits { + template using rebind_alloc = __alloc_rebind<_Alloc, _Tp>; + template + static auto construct(_Alloc& __a, _Tp* __p, _Args&&... __args) + -> decltype(_S_construct(__a, __p, forward<_Args>(__args)...)) { } +}; + +template +struct __alloc_traits : allocator_traits<_Alloc> { + typedef allocator_traits<_Alloc> _Base_type; + template struct rebind { typedef typename _Base_type::template rebind_alloc<_Tp> other; }; +}; + +template class allocator { + typedef _Tp value_type; + template struct rebind { typedef allocator<_Tp1> other; }; +}; + +template +class basic_string { + typedef typename __alloc_traits<_Alloc>::template rebind<_CharT>::other _Char_alloc_type; +}; + +template struct _Base_bitset { + static void foo (basic_string >) {} +};