From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id 3756B385383A; Fri, 21 Oct 2022 13:28:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3756B385383A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666358915; bh=rHm7/afGZitS2SNMZIJ0FD6CbVSF1PwBIbNU1Ti5oMo=; h=From:To:Subject:Date:From; b=IGhFmVJQd+jVQZjIumfQm9jFPmw+mjoyvRPcEVjJlTmwryIcfmFGXaFX0FXfq6gDj eJnnXO2sueUi/knP7zDqd1X2R8otx+vUd+VrocQmKqPWBarNLMOxEPgE4chu37BoZq fGlwSKwBdIeDIi1+D0KbAuZgKYclNRs4DRd4AdK4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] libstdc++: iostream operator{<<|>>}(__intcap) enablement X-Act-Checkin: gcc X-Git-Author: Victor Do Nascimento X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: c4e36618f181789f0b737631bf3c28726c2a1296 X-Git-Newrev: 977fc61dbcf2124725f9fee2a67cac6df2ff4ebb Message-Id: <20221021132835.3756B385383A@sourceware.org> Date: Fri, 21 Oct 2022 13:28:35 +0000 (GMT) List-Id: https://gcc.gnu.org/g:977fc61dbcf2124725f9fee2a67cac6df2ff4ebb commit 977fc61dbcf2124725f9fee2a67cac6df2ff4ebb Author: Victor Do Nascimento Date: Fri Oct 21 14:27:24 2022 +0100 libstdc++: iostream operator{<<|>>}(__intcap) enablement Add overloads of basic_ostream::operator<< and basic_istream::operator<< for the signed and unsigned variants of the CHERI __intcap type. libstdc++-v3/Changelog: * include/std/ostream (basic_ostream): define operator<< overload for signed and unsigned __intptr. * include/std/istream (basic_istream): define operator>> overload for signed and unsigned __intptr. * testsuite/27_io/basic_ostream/inserters_arithmetic/char/cheri_types.cc: New. Diff: --- libstdc++-v3/include/std/istream | 20 ++++++++ libstdc++-v3/include/std/ostream | 11 +++++ .../inserters_arithmetic/char/cheri_types.cc | 53 ++++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/libstdc++-v3/include/std/istream b/libstdc++-v3/include/std/istream index 20a455a0ef1..9db2bc91b9a 100644 --- a/libstdc++-v3/include/std/istream +++ b/libstdc++-v3/include/std/istream @@ -190,6 +190,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator>>(unsigned long& __n) { return _M_extract(__n); } +#ifdef __CHERI__ + __istream_type& + operator>>(__intcap& __n) + { + long __tmp; + __istream_type& __istr_tmp = _M_extract(__tmp); + __n = __tmp; + return __istr_tmp; + } + + __istream_type& + operator>>(unsigned __intcap& __n) + { + unsigned long __tmp; + __istream_type& __istr_tmp = _M_extract(__tmp); + __n = __tmp; + return __istr_tmp; + } +#endif + #ifdef _GLIBCXX_USE_LONG_LONG __istream_type& operator>>(long long& __n) diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream index 9a80adf3a5a..48a1b74d5ae 100644 --- a/libstdc++-v3/include/std/ostream +++ b/libstdc++-v3/include/std/ostream @@ -162,6 +162,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * These functions use the stream's current locale (specifically, the * @c num_get facet) to perform numeric formatting. */ + +#ifdef __CHERI__ + __ostream_type& + operator<<(__intcap __n) + { return _M_insert(static_cast(__n)); } + + __ostream_type& + operator<<(unsigned __intcap __n) + { return _M_insert(static_cast(__n)); } +#endif + __ostream_type& operator<<(long __n) { return _M_insert(__n); } diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/cheri_types.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/cheri_types.cc new file mode 100644 index 00000000000..a27675c8c7f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/cheri_types.cc @@ -0,0 +1,53 @@ +// { dg-do run { target c++11 } } + +// Test the CHERI intcap inserters. + +// Copyright (C) 1999-2022 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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. + +// This library 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 this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void +test01() +{ + using namespace std; + stringstream ss; + + // Make sure istream operator>> and ostream operator<< are + // correctly overloaded to handle signed and unsigned __intcap + // for CHERI. + intptr_t smax_out, smax_in = LONG_MAX; + intptr_t smin_out, smin_in = LONG_MIN; + uintptr_t umax_out, umax_in = ULONG_MAX; + + ss << smax_in << " " << smin_in << " " << umax_in; + ss >> smax_out >> smin_out >> umax_out; + + VERIFY( smin_in == smin_out ); + VERIFY( smax_in == smax_out ); + VERIFY( umax_in == umax_out ); +} + +int +main() +{ + test01(); + return 0; +}