Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test/span-main.t.cpp
// Copyright 2018-2019 Martin Moene // // https://github.com/martinmoene/span-lite // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include "span-main.t.hpp" #ifndef span_HAVE # define span_HAVE( feature ) ( span_HAVE_##feature ) #endif #define span_PRESENT( x ) \ std::cout << #x << ": " << x << "\n" #define span_ABSENT( x ) \ std::cout << #x << ": (undefined)\n" lest::tests & specification() { static lest::tests tests; return tests; } CASE( "span-lite version" "[.span][.version]" ) { span_PRESENT( span_lite_MAJOR ); span_PRESENT( span_lite_MINOR ); span_PRESENT( span_lite_PATCH ); span_PRESENT( span_lite_VERSION ); } CASE( "span configuration" "[.span][.config]" ) { #if span_USES_STD_SPAN std::cout << "(Note: Configuration has no effect: using std::span)\n"; #endif span_PRESENT( span_HAVE_STD_SPAN ); span_PRESENT( span_USES_STD_SPAN ); span_PRESENT( span_SPAN_DEFAULT ); span_PRESENT( span_SPAN_NONSTD ); span_PRESENT( span_SPAN_STD ); span_PRESENT( span_CONFIG_SELECT_SPAN ); // span_PRESENT( span_CONFIG_EXTENT_TYPE ); // span_PRESENT( span_CONFIG_SIZE_TYPE ); span_PRESENT( span_CONFIG_NO_EXCEPTIONS ); } CASE( "Presence of span library features" "[.span][.config]" ) { #if span_USES_STD_SPAN std::cout << "(Note: library feature configuration has no effect: using std::span)\n"; #endif span_PRESENT( span_FEATURE_BYTE_SPAN ); span_PRESENT( span_FEATURE_MAKE_SPAN ); #ifdef span_FEATURE_MAKE_SPAN_TO_STD span_PRESENT( span_FEATURE_MAKE_SPAN_TO_STD ); #else span_ABSENT( span_FEATURE_MAKE_SPAN_TO_STD ); #endif span_PRESENT( span_FEATURE_WITH_CONTAINER ); #ifdef span_FEATURE_WITH_CONTAINER_TO_STD span_PRESENT( span_FEATURE_WITH_CONTAINER_TO_STD ); #else span_ABSENT( span_FEATURE_WITH_CONTAINER_TO_STD ); #endif span_PRESENT( span_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE ); span_PRESENT( span_FEATURE_MEMBER_CALL_OPERATOR ); span_PRESENT( span_FEATURE_MEMBER_AT ); span_PRESENT( span_FEATURE_MEMBER_BACK_FRONT ); span_PRESENT( span_FEATURE_MEMBER_SWAP ); span_PRESENT( span_FEATURE_NON_MEMBER_FIRST_LAST_SUB ); span_PRESENT( span_FEATURE_COMPARISON ); span_PRESENT( span_FEATURE_SAME ); } CASE( "span configuration, contract level" "[.span][.config][.contract]" ) { #if span_USES_STD_SPAN std::cout << "(Note: contract level configuration has no effect: using std::span)\n"; #endif #ifdef span_CONFIG_CONTRACT_LEVEL_ON span_PRESENT( span_CONFIG_CONTRACT_LEVEL_ON ); #else span_ABSENT( span_CONFIG_CONTRACT_LEVEL_ON ); #endif #ifdef span_CONFIG_CONTRACT_LEVEL_OFF span_PRESENT( span_CONFIG_CONTRACT_LEVEL_OFF ); #else span_ABSENT( span_CONFIG_CONTRACT_LEVEL_OFF ); #endif #ifdef span_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY span_PRESENT( span_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY ); #else span_ABSENT( span_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY ); #endif #ifdef span_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY span_PRESENT( span_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY ); #else span_ABSENT( span_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY ); #endif #ifdef span_CONFIG_CONTRACT_VIOLATION_THROWS span_PRESENT( span_CONFIG_CONTRACT_VIOLATION_THROWS ); #else span_ABSENT( span_CONFIG_CONTRACT_VIOLATION_THROWS ); #endif #ifdef span_CONFIG_CONTRACT_VIOLATION_TERMINATES span_PRESENT( span_CONFIG_CONTRACT_VIOLATION_TERMINATES ); #else span_ABSENT( span_CONFIG_CONTRACT_VIOLATION_TERMINATES ); #endif } CASE( "__cplusplus" "[.stdc++]" ) { span_PRESENT( __cplusplus ); #ifdef _MSVC_LANG span_PRESENT( _MSVC_LANG ); #else span_ABSENT( _MSVC_LANG ); #endif span_PRESENT( span_CPLUSPLUS ); span_PRESENT( span_CPLUSPLUS_V ); } CASE( "Compiler version" "[.compiler]" ) { #if span_USES_STD_SPAN std::cout << "(Compiler version not available: using std::span)\n"; #else span_PRESENT( span_COMPILER_CLANG_VERSION ); span_PRESENT( span_COMPILER_GNUC_VERSION ); span_PRESENT( span_COMPILER_MSVC_VERSION ); #endif } CASE( "Presence of C++ language features" "[.stdlanguage]" ) { #if defined(__cpp_exceptions) span_PRESENT( __cpp_exceptions ); #else span_ABSENT( __cpp_exceptions ); #endif #if defined(__EXCEPTIONS) span_PRESENT( __EXCEPTIONS ); #else span_ABSENT( __EXCEPTIONS ); #endif #if defined(_CPPUNWIND) span_PRESENT( _CPPUNWIND ); #else span_ABSENT( _CPPUNWIND ); #endif #if defined(_DEBUG) span_PRESENT( _DEBUG ); #else span_ABSENT( _DEBUG ); #endif #if defined(NDEBUG) span_PRESENT( NDEBUG ); #else span_ABSENT( NDEBUG ); #endif #if span_USES_STD_SPAN std::cout << "(Presence of C++ language features not available: using std::span)\n"; #else span_PRESENT( span_HAVE_ALIAS_TEMPLATE ); span_PRESENT( span_HAVE_AUTO ); span_PRESENT( span_HAVE_CONSTEXPR_11 ); span_PRESENT( span_HAVE_CONSTEXPR_14 ); span_PRESENT( span_HAVE_CONSTRAINED_SPAN_CONTAINER_CTOR ); span_PRESENT( span_HAVE_DEDUCTION_GUIDES ); span_PRESENT( span_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG ); span_PRESENT( span_HAVE_DEPRECATED ); span_PRESENT( span_HAVE_EXPLICIT_CONVERSION ); span_PRESENT( span_HAVE_IS_DEFAULT ); span_PRESENT( span_HAVE_IS_DELETE ); span_PRESENT( span_HAVE_NODISCARD ); span_PRESENT( span_HAVE_NOEXCEPT ); span_PRESENT( span_HAVE_NORETURN ); span_PRESENT( span_HAVE_NULLPTR ); span_PRESENT( span_HAVE_STATIC_ASSERT ); #endif } CASE( "Presence of C++ library features" "[.stdlibrary]" ) { #if span_USES_STD_SPAN std::cout << "(Presence of C++ library features not available: using std::span)\n"; #else span_PRESENT( span_HAS_CPP0X ); span_PRESENT( span_HAVE_ADDRESSOF ); span_PRESENT( span_HAVE_ARRAY ); span_PRESENT( span_HAVE_BYTE ); span_PRESENT( span_HAVE_CONDITIONAL ); span_PRESENT( span_HAVE_CONTAINER_DATA_METHOD ); span_PRESENT( span_HAVE_DATA ); span_PRESENT( span_HAVE_NONSTD_BYTE ); span_PRESENT( span_HAVE_REMOVE_CONST ); span_PRESENT( span_HAVE_SNPRINTF ); span_PRESENT( span_HAVE_STRUCT_BINDING ); span_PRESENT( span_HAVE_TYPE_TRAITS ); #endif } int main( int argc, char * argv[] ) { return lest::run( specification(), argc, argv ); } #if 0 g++ -I../include -o span-lite.t.exe span-lite.t.cpp && span-lite.t.exe --pass g++ -std=c++98 -I../include -o span-lite.t.exe span-lite.t.cpp && span-lite.t.exe --pass g++ -std=c++03 -I../include -o span-lite.t.exe span-lite.t.cpp && span-lite.t.exe --pass g++ -std=c++0x -I../include -o span-lite.t.exe span-lite.t.cpp && span-lite.t.exe --pass g++ -std=c++11 -I../include -o span-lite.t.exe span-lite.t.cpp && span-lite.t.exe --pass g++ -std=c++14 -I../include -o span-lite.t.exe span-lite.t.cpp && span-lite.t.exe --pass g++ -std=c++17 -I../include -o span-lite.t.exe span-lite.t.cpp && span-lite.t.exe --pass cl -EHsc -I../include span-lite.t.cpp && span-lite.t.exe --pass #endif // end of file
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test/tc.bat
@echo off & setlocal enableextensions enabledelayedexpansion :: :: tc.bat - compile & run tests (clang). :: set unit=span :: if no std is given, use c++14 set std=%1 if "%std%"=="" set std=c++14 set clang=clang call :CompilerVersion version echo %clang% %version%: %std% set UCAP=%unit% call :toupper UCAP set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_DEFAULT ::set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_NONSTD ::set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_STD set unit_contract=^ -Dspan_CONFIG_CONTRACT_VIOLATION_TERMINATES=0 ^ -Dspan_CONFIG_CONTRACT_VIOLATION_THROWS=1 :: Alternative flags: :: -Dspan_FEATURE_WITH_CONTAINER=1 takes precedence over span_FEATURE_WITH_CONTAINER_TO_STD :: -Dspan_FEATURE_MAKE_SPAN=1 takes precedence over span_FEATURE_MAKE_SPAN_TO_STD set unit_config=^ -Dspan_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE=1 ^ -Dspan_FEATURE_WITH_INITIALIZER_LIST_P2447=1 ^ -Dspan_FEATURE_WITH_CONTAINER_TO_STD=99 ^ -Dspan_FEATURE_MEMBER_CALL_OPERATOR=1 ^ -Dspan_FEATURE_MEMBER_AT=2 ^ -Dspan_FEATURE_MEMBER_BACK_FRONT=1 ^ -Dspan_FEATURE_MEMBER_SWAP=1 ^ -Dspan_FEATURE_COMPARISON=1 ^ -Dspan_FEATURE_SAME=1 ^ -Dspan_FEATURE_NON_MEMBER_FIRST_LAST_SUB=0 ^ -Dspan_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN=1 ^ -Dspan_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER=1 ^ -Dspan_FEATURE_MAKE_SPAN_TO_STD=99 ^ -Dspan_FEATURE_BYTE_SPAN=1 set byte_lite=^ -Dspan_BYTE_LITE_HEADER=\"../../byte-lite/include/nonstd/byte.hpp\" rem -flto / -fwhole-program set optflags=-O2 set warnflags=-Wall -Wextra -Wpedantic -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-missing-noreturn -Wno-documentation-unknown-command -Wno-documentation-deprecated-sync -Wno-documentation -Wno-weak-vtables -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-exit-time-destructors -Wno-global-constructors "%clang%" -m32 -std=%std% %optflags% %warnflags% %unit_select% %unit_contract% %unit_config% %byte_lite% -fms-compatibility-version=19.00 -isystem "%VCInstallDir%include" -isystem "%WindowsSdkDir_71A%include" -isystem lest -I../include -I. -o %unit%-main.t.exe %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe endlocal & goto :EOF :: subroutines: :CompilerVersion version echo off & setlocal enableextensions set tmpprogram=_getcompilerversion.tmp set tmpsource=%tmpprogram%.c echo #include ^<stdio.h^> > %tmpsource% echo int main(){printf("%%d.%%d.%%d\n",__clang_major__,__clang_minor__,__clang_patchlevel__);} >> %tmpsource% "%clang%" -m32 -o %tmpprogram% %tmpsource% >nul for /f %%x in ('%tmpprogram%') do set version=%%x del %tmpprogram%.* >nul endlocal & set %1=%version%& goto :EOF :: toupper; makes use of the fact that string :: replacement (via SET) is not case sensitive :toupper for %%L IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET %1=!%1:%%L=%%L! goto :EOF
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test/tc-cl.bat
@echo off & setlocal enableextensions enabledelayedexpansion :: :: tc-cl.bat - compile & run tests (clang-cl). :: set unit=span set unit_file=%unit% :: if no std is given, use c++14 set std=c++14 if NOT "%1" == "" set std=%1 & shift set UCAP=%unit% call :toupper UCAP set unit_select=%unit%_%UCAP%_NONSTD ::set unit_select=%unit%_CONFIG_SELECT_%UCAP%_NONSTD if NOT "%1" == "" set unit_select=%1 & shift set args=%1 %2 %3 %4 %5 %6 %7 %8 %9 set clang=clang-cl call :CompilerVersion version echo %clang% %version%: %std% %unit_select% %args% set unit_config=^ -D%unit%_%UCAP%_HEADER=\"nonstd/%unit%.hpp\" ^ -D%unit%_TEST_NODISCARD=0 ^ -D%unit%_CONFIG_SELECT_%UCAP%=%unit_select% rem -flto / -fwhole-program set optflags=-O2 set warnflags=-Wall -Wextra -Wpedantic -Weverything -Wshadow -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-missing-noreturn -Wno-documentation-unknown-command -Wno-documentation-deprecated-sync -Wno-documentation -Wno-weak-vtables -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-exit-time-destructors -Wno-global-constructors -Wno-sign-conversion -Wno-sign-compare -Wno-implicit-int-conversion -Wno-deprecated-declarations -Wno-date-time "%clang%" -EHsc -std:%std% %optflags% %warnflags% %unit_config% -fms-compatibility-version=19.00 /imsvc lest -I../include -Ics_string -I. -o %unit_file%-main.t.exe %unit_file%-main.t.cpp %unit_file%.t.cpp && %unit_file%-main.t.exe endlocal & goto :EOF :: subroutines: :CompilerVersion version echo off & setlocal enableextensions set tmpprogram=_getcompilerversion.tmp set tmpsource=%tmpprogram%.c echo #include ^<stdio.h^> > %tmpsource% echo int main(){printf("%%d.%%d.%%d\n",__clang_major__,__clang_minor__,__clang_patchlevel__);} >> %tmpsource% "%clang%" -m32 -o %tmpprogram% %tmpsource% >nul for /f %%x in ('%tmpprogram%') do set version=%%x del %tmpprogram%.* >nul endlocal & set %1=%version%& goto :EOF :: toupper; makes use of the fact that string :: replacement (via SET) is not case sensitive :toupper for %%L IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET %1=!%1:%%L=%%L! goto :EOF
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test/span-main.t.hpp
// Copyright 2018-2019 Martin Moene // // https://github.com/martinmoene/span-lite // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #pragma once #ifndef TEST_SPAN_LITE_H_INCLUDED #define TEST_SPAN_LITE_H_INCLUDED // Optionally provide byte-lite: #ifdef span_BYTE_LITE_HEADER # include span_BYTE_LITE_HEADER #endif #include "nonstd/span.hpp" #if span_USES_STD_SPAN # include <array> # include <tuple> # define span_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) ) #endif // Compiler warning suppression for usage of lest: #ifdef __clang__ # pragma clang diagnostic ignored "-Wstring-conversion" # pragma clang diagnostic ignored "-Wunused-parameter" # pragma clang diagnostic ignored "-Wunused-template" # pragma clang diagnostic ignored "-Wunused-function" # pragma clang diagnostic ignored "-Wunused-member-function" #elif defined __GNUC__ # pragma GCC diagnostic ignored "-Wunused-parameter" # pragma GCC diagnostic ignored "-Wunused-function" #endif // provide std::byte or nonstd::byte as xstd::byte: namespace xstd { #if span_HAVE( BYTE ) using std::byte; using std::to_integer; #elif span_HAVE( NONSTD_BYTE ) using nonstd::byte; using nonstd::to_integer; #endif } #if span_HAVE( BYTE ) || span_HAVE( NONSTD_BYTE ) #include <iosfwd> namespace lest { std::ostream & operator<<( std::ostream & os, xstd::byte b ); } #endif #include "lest_cpp03.hpp" extern lest::tests & specification(); #define CASE( name ) lest_CASE( specification(), name ) namespace nonstd { namespace span_lite { // use oparator<< instead of to_string() overload; // see http://stackoverflow.com/a/10651752/437272 template< typename T > inline std::ostream & operator<<( std::ostream & os, span<T> const & v ) { using lest::to_string; return os << "[span:" << (v.empty() ? "[empty]" : to_string( v[0] ) ) << "]"; } }} namespace lest { using ::nonstd::span_lite::operator<<; #if span_HAVE( BYTE ) ||span_HAVE( NONSTD_BYTE ) inline std::ostream & operator<<( std::ostream & os, xstd::byte b ) { return os << "[byte:" << std::hex << std::showbase << xstd::to_integer<int>(b) << "]"; } #endif } // namespace lest #endif // TEST_SPAN_LITE_H_INCLUDED // end of file
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test/tg.bat
@echo off & setlocal enableextensions enabledelayedexpansion :: :: tg.bat - compile & run tests (GNUC). :: set unit=span set unit_file=span :: if no std is given, use c++11 :: if no std is given, use c++11 set std=c++11 if NOT "%1" == "" set std=%1 & shift set UCAP=%unit% call :toupper UCAP set unit_select=%unit%_%UCAP%_DEFAULT ::set unit_select==%unit%_%UCAP%_NONSTD ::set unit_select=%unit%_%UCAP%_STD if NOT "%1" == "" set unit_select=%1 & shift set args=%1 %2 %3 %4 %5 %6 %7 %8 %9 set gpp=g++ call :CompilerVersion version echo %gpp% %version%: %std% %unit_select% %args% set unit_contract=^ -Dspan_CONFIG_SELECT_SPAN=%unit_select% ^ -Dspan_CONFIG_CONTRACT_VIOLATION_TERMINATES=0 ^ -Dspan_CONFIG_CONTRACT_VIOLATION_THROWS=1 :: Alternative flags: :: -Dspan_FEATURE_WITH_CONTAINER=1 takes precedence over span_FEATURE_WITH_CONTAINER_TO_STD :: -Dspan_FEATURE_MAKE_SPAN=1 takes precedence over span_FEATURE_MAKE_SPAN_TO_STD set unit_config=^ -Dspan_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE=1 ^ -Dspan_FEATURE_WITH_INITIALIZER_LIST_P2447=1 ^ -Dspan_FEATURE_WITH_CONTAINER_TO_STD=99 ^ -Dspan_FEATURE_MEMBER_CALL_OPERATOR=1 ^ -Dspan_FEATURE_MEMBER_AT=2 ^ -Dspan_FEATURE_MEMBER_BACK_FRONT=1 ^ -Dspan_FEATURE_MEMBER_SWAP=1 ^ -Dspan_FEATURE_COMPARISON=1 ^ -Dspan_FEATURE_SAME=1 ^ -Dspan_FEATURE_NON_MEMBER_FIRST_LAST_SUB=0 ^ -Dspan_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN=1 ^ -Dspan_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER=1 ^ -Dspan_FEATURE_MAKE_SPAN_TO_STD=99 ^ -Dspan_FEATURE_BYTE_SPAN=1 set byte_lite=^ -Dspan_BYTE_LITE_HEADER=\"../../byte-lite/include/nonstd/byte.hpp\" rem -flto / -fwhole-program set optflags=-O2 set warnflags=-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wno-padded -Wno-missing-noreturn %gpp% -std=%std% %optflags% %warnflags% %unit_contract% %unit_config% %byte_lite% -o %unit%-main.t.exe -isystem lest -I../include -I. %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe endlocal & goto :EOF :: subroutines: :CompilerVersion version echo off & setlocal enableextensions set tmpprogram=_getcompilerversion.tmp set tmpsource=%tmpprogram%.c echo #include ^<stdio.h^> > %tmpsource% echo int main(){printf("%%d.%%d.%%d\n",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);} >> %tmpsource% %gpp% -o %tmpprogram% %tmpsource% >nul for /f %%x in ('%tmpprogram%') do set version=%%x del %tmpprogram%.* >nul endlocal & set %1=%version%& goto :EOF :: toupper; makes use of the fact that string :: replacement (via SET) is not case sensitive :toupper for %%L IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET %1=!%1:%%L=%%L! goto :EOF
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test/t-all.bat
@echo off & setlocal enableextensions enabledelayedexpansion :: :: t-all.bat - perform tests with varying contract violation response, features and C++ standard (MSVC). :: set log=%0.log echo. > %log% set /a compiler_version=0 call :CompilerVersion compiler_version set spanProgram=span-main.t.exe set spanSources=span-main.t.cpp span.t.cpp set cvResponses=^ span_CONFIG_CONTRACT_VIOLATION_THROWS ^ span_CONFIG_CONTRACT_VIOLATION_TERMINATES set spanFeatures=^ "span_FEATURE_BYTE_SPAN=1" ^ "span_FEATURE_MAKE_SPAN_TO_STD=99" ^ "span_FEATURE_WITH_CONTAINER_TO_STD=99" ^ "span_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE=1" ^ "span_FEATURE_MEMBER_AT=2" ^ "span_FEATURE_MEMBER_BACK_FRONT=1" ^ "span_FEATURE_MEMBER_SWAP=1" ^ "span_FEATURE_NON_MEMBER_FIRST_LAST_SUB=1" ^ "span_FEATURE_SAME=1" set cppStandards=^ c++14 ^ c++17 ^ c++latest set msvc_defines=^ -D_CRT_SECURE_NO_WARNINGS ^ -D_SCL_SECURE_NO_WARNINGS set CppCoreCheckInclude=%VCINSTALLDIR%\Auxiliary\VS\include call :ForAllCombinations endlocal & goto :EOF :: subroutines :ForAllCombinations :ForContractViolationResponse for %%r in ( %cvResponses% ) do ( call :ForSpanFeature -D%%r ) goto :EOF :ForSpanFeature contractViolationResponse for %%i in ( %spanFeatures% ) do ( call :ForCppStd %* "-D%%i" ) goto :EOF :ForCppStd contractViolationResponse spanFeature if %compiler_version% LSS 14 ( call :CompileLog %* ) else ( for %%s in ( %cppStandards% ) do ( call :CompileLog %* -std:%%s )) goto :EOF :CompileLog contractViolationResponse spanFeature [CppStd] echo VC%compiler_version%: %* call :Compile %* >> %log% 2>&1 if errorlevel 1 ( less %log% & goto :EOF ) else ( echo.%* | findstr /C:"THROWS" 1>nul if not errorlevel 1 ( %spanProgram% ) ) goto :EOF :Compile contractViolationResponse spanFeature [CppStd] ::call t.bat %* set args=%* set compile=cl -EHsc -I../include -I"%CppCoreCheckInclude%" %args% %msvc_defines% %spanSources% echo %compile% && %compile% goto :EOF :CompilerVersion version @echo off & setlocal enableextensions set tmpprogram=_getcompilerversion.tmp set tmpsource=%tmpprogram%.c echo #include ^<stdio.h^> >%tmpsource% echo int main(){printf("%%d\n",_MSC_VER);} >>%tmpsource% cl /nologo %tmpsource% >nul for /f %%x in ('%tmpprogram%') do set version=%%x del %tmpprogram%.* >nul set offset=0 if %version% LSS 1900 set /a offset=1 set /a version="version / 10 - 10*(5 - offset)" endlocal & set %1=%version%& goto :EOF
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test/CMakeLists.txt
# Copyright 2017-2018 by Martin Moene # # https://github.com/martinmoene/span-lite # # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) if( NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION ) cmake_minimum_required( VERSION 3.5 FATAL_ERROR ) endif() project( test LANGUAGES CXX ) set( unit_name "span" ) set( PACKAGE ${unit_name}-lite ) set( PROGRAM ${unit_name}-lite ) set( SOURCES ${unit_name}-main.t.cpp ${unit_name}.t.cpp ) set( TWEAKD "." ) message( STATUS "Subproject '${PROJECT_NAME}', programs '${PROGRAM}-*'") # Configure span-lite for testing: set( OPTIONS "" ) set( SPAN_CONFIG -Dspan_CONFIG_CONTRACT_VIOLATION_THROWS -Dspan_FEATURE_MEMBER_CALL_OPERATOR=1 -Dspan_FEATURE_MEMBER_AT=1 -Dspan_FEATURE_MEMBER_BACK_FRONT=1 -Dspan_FEATURE_MEMBER_SWAP=1 -Dspan_FEATURE_COMPARISON=1 -Dspan_FEATURE_SAME=1 -Dspan_FEATURE_NON_MEMBER_FIRST_LAST_SUB=1 -Dspan_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE=1 -Dspan_FEATURE_WITH_INITIALIZER_LIST_P2447=1 # -Dspan_FEATURE_WITH_CONTAINER=1 # instead use more involved ..._TO_STD below: -Dspan_FEATURE_WITH_CONTAINER_TO_STD=99 # -Dspan_FEATURE_MAKE_SPAN=1 # instead use more involved ..._TO_STD below: -Dspan_FEATURE_MAKE_SPAN_TO_STD=99 -Dspan_FEATURE_BYTE_SPAN=1 ) set( HAS_STD_FLAGS FALSE ) set( HAS_CPP98_FLAG FALSE ) set( HAS_CPP11_FLAG FALSE ) set( HAS_CPP14_FLAG FALSE ) set( HAS_CPP17_FLAG FALSE ) set( HAS_CPP20_FLAG FALSE ) set( HAS_CPPLATEST_FLAG FALSE ) if( MSVC ) message( STATUS "Matched: MSVC") set( HAS_STD_FLAGS TRUE ) set( OPTIONS -W3 -EHsc ) set( DEFINITIONS -D_SCL_SECURE_NO_WARNINGS ${SPAN_CONFIG} ) if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.00 ) set( HAS_CPP14_FLAG TRUE ) set( HAS_CPPLATEST_FLAG TRUE ) endif() if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.11 ) set( HAS_CPP17_FLAG TRUE ) endif() elseif( CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang" ) message( STATUS "CompilerId: '${CMAKE_CXX_COMPILER_ID}'") set( HAS_STD_FLAGS TRUE ) set( HAS_CPP98_FLAG TRUE ) set( OPTIONS -Wall -Wextra -Wconversion -Wsign-conversion -Wno-missing-braces -fno-elide-constructors ) set( DEFINITIONS ${SPAN_CONFIG} ) # GNU: available -std flags depends on version if( CMAKE_CXX_COMPILER_ID MATCHES "GNU" ) message( STATUS "Matched: GNU") if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.0 ) set( HAS_CPP11_FLAG TRUE ) endif() if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.2 ) set( HAS_CPP14_FLAG TRUE ) endif() if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.1.0 ) set( HAS_CPP17_FLAG TRUE ) endif() # AppleClang: available -std flags depends on version elseif( CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" ) message( STATUS "Matched: AppleClang") if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0.0 ) set( HAS_CPP11_FLAG TRUE ) endif() if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1.0 ) set( HAS_CPP14_FLAG TRUE ) endif() if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.2.0 ) set( HAS_CPP17_FLAG TRUE ) endif() # Clang: available -std flags depends on version elseif( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) message( STATUS "Matched: Clang") if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3.0 ) set( HAS_CPP11_FLAG TRUE ) endif() if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4.0 ) set( HAS_CPP14_FLAG TRUE ) endif() if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0.0 ) set( HAS_CPP17_FLAG TRUE ) endif() endif() elseif( CMAKE_CXX_COMPILER_ID MATCHES "Intel" ) # as is message( STATUS "Matched: Intel") else() # as is message( STATUS "Matched: nothing") endif() # enable MS C++ Core Guidelines checker if MSVC: function( enable_msvs_guideline_checker target ) if( MSVC ) set_target_properties( ${target} PROPERTIES VS_GLOBAL_EnableCppCoreCheck true VS_GLOBAL_CodeAnalysisRuleSet CppCoreCheckRules.ruleset VS_GLOBAL_RunCodeAnalysis true ) endif() endfunction() # make target, compile for given standard if specified: function( make_target target std ) message( STATUS "Make target: '${std}'" ) add_executable ( ${target} ${SOURCES} ${HDRPATH} ) target_include_directories( ${target} SYSTEM PRIVATE lest ) target_include_directories( ${target} PRIVATE ${TWEAKD} ) target_link_libraries ( ${target} PRIVATE ${PACKAGE} ) target_compile_options ( ${target} PRIVATE ${OPTIONS} ) target_compile_definitions( ${target} PRIVATE ${DEFINITIONS} ) if( std ) if( MSVC ) target_compile_options( ${target} PRIVATE -std:c++${std} ) else() # Necessary for clang 3.x: target_compile_options( ${target} PRIVATE -std=c++${std} ) # Ok for clang 4 and later: # set( CMAKE_CXX_STANDARD ${std} ) # set( CMAKE_CXX_STANDARD_REQUIRED ON ) # set( CMAKE_CXX_EXTENSIONS OFF ) endif() endif() endfunction() # add generic executable, unless -std flags can be specified: if( NOT HAS_STD_FLAGS ) make_target( ${PROGRAM}.t "" ) else() # unconditionally add C++98 variant as MSVC has no option for it: if( HAS_CPP98_FLAG ) make_target( ${PROGRAM}-cpp98.t 98 ) else() make_target( ${PROGRAM}-cpp98.t "" ) endif() if( HAS_CPP11_FLAG ) make_target( ${PROGRAM}-cpp11.t 11 ) endif() if( HAS_CPP14_FLAG ) make_target( ${PROGRAM}-cpp14.t 14 ) endif() if( HAS_CPP17_FLAG ) set( std17 17 ) if( CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" ) set( std17 1z ) endif() make_target( ${PROGRAM}-cpp17.t ${std17} ) enable_msvs_guideline_checker( ${PROGRAM}-cpp17.t ) endif() if( HAS_CPPLATEST_FLAG ) make_target( ${PROGRAM}-cpplatest.t latest ) endif() endif() # with C++20, honour explicit request for std::span or nonstd::span: if( HAS_CPP20_FLAG ) set( WHICH span_SPAN_DEFAULT ) if( SPAN_LITE_OPT_SELECT_STD ) set( WHICH span_SPAN_STD ) elseif( SPAN_LITE_OPT_SELECT_NONSTD ) set( WHICH span_SPAN_NONSTD ) endif() target_compile_definitions( ${PROGRAM}-cpp20.t PRIVATE span_CONFIG_SELECT_ANY=${WHICH} ) if( HAS_CPPLATEST_FLAG ) target_compile_definitions( ${PROGRAM}-cpplatest.t PRIVATE span_CONFIG_SELECT_ANY=${WHICH} ) endif() endif() # configure unit tests via CTest: enable_testing() if( HAS_STD_FLAGS ) # unconditionally add C++98 variant for MSVC: add_test( NAME test-cpp98 COMMAND ${PROGRAM}-cpp98.t ) if( HAS_CPP11_FLAG ) add_test( NAME test-cpp11 COMMAND ${PROGRAM}-cpp11.t ) endif() if( HAS_CPP14_FLAG ) add_test( NAME test-cpp14 COMMAND ${PROGRAM}-cpp14.t ) endif() if( HAS_CPP17_FLAG ) add_test( NAME test-cpp17 COMMAND ${PROGRAM}-cpp17.t ) endif() if( HAS_CPP20_FLAG ) add_test( NAME test-cpp20 COMMAND ${PROGRAM}-cpp20.t ) endif() if( HAS_CPPLATEST_FLAG ) add_test( NAME test-cpplatest COMMAND ${PROGRAM}-cpplatest.t ) endif() else() add_test( NAME test COMMAND ${PROGRAM}.t --pass ) add_test( NAME list_version COMMAND ${PROGRAM}.t --version ) add_test( NAME list_tags COMMAND ${PROGRAM}.t --list-tags ) add_test( NAME list_tests COMMAND ${PROGRAM}.t --list-tests ) endif() # end of file
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test/t.bat
@echo off & setlocal enableextensions enabledelayedexpansion :: :: t.bat - compile & run tests (MSVC). :: set unit=span :: if no std is given, use compiler default set std=%1 if not "%std%"=="" set std=-std:%std% call :CompilerVersion version echo VC%version%: %args% set UCAP=%unit% call :toupper UCAP set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_DEFAULT ::set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_NONSTD ::set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_STD set unit_contract=^ -Dspan_CONFIG_CONTRACT_VIOLATION_TERMINATES=0 ^ -Dspan_CONFIG_CONTRACT_VIOLATION_THROWS=1 :: Alternative flags: :: -Dspan_FEATURE_WITH_CONTAINER=1 takes precedence over span_FEATURE_WITH_CONTAINER_TO_STD :: -Dspan_FEATURE_MAKE_SPAN=1 takes precedence over span_FEATURE_MAKE_SPAN_TO_STD set unit_config=^ -Dspan_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE=1 ^ -Dspan_FEATURE_WITH_INITIALIZER_LIST_P2447=1 ^ -Dspan_FEATURE_WITH_CONTAINER_TO_STD=99 ^ -Dspan_FEATURE_MEMBER_CALL_OPERATOR=1 ^ -Dspan_FEATURE_MEMBER_AT=2 ^ -Dspan_FEATURE_MEMBER_BACK_FRONT=1 ^ -Dspan_FEATURE_MEMBER_SWAP=1 ^ -Dspan_FEATURE_COMPARISON=1 ^ -Dspan_FEATURE_SAME=1 ^ -Dspan_FEATURE_NON_MEMBER_FIRST_LAST_SUB=0 ^ -Dspan_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN=1 ^ -Dspan_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER=1 ^ -Dspan_FEATURE_MAKE_SPAN_TO_STD=99 ^ -Dspan_FEATURE_BYTE_SPAN=1 set msvc_defines=^ -D_CRT_SECURE_NO_WARNINGS ^ -D_SCL_SECURE_NO_WARNINGS set CppCoreCheckInclude=^ %VCINSTALLDIR%\Auxiliary\VS\include set byte_lite=^ -Dspan_BYTE_LITE_HEADER=\"../../byte-lite/include/nonstd/byte.hpp\" cl -nologo -W3 -EHsc %std% %unit_select% %unit_contract% %unit_config% %msvc_defines% %byte_lite% -I"%CppCoreCheckInclude%" -Ilest -I../include -I. %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe endlocal & goto :EOF :: subroutines: :CompilerVersion version @echo off & setlocal enableextensions set tmpprogram=_getcompilerversion.tmp set tmpsource=%tmpprogram%.c echo #include ^<stdio.h^> >%tmpsource% echo int main(){printf("%%d\n",_MSC_VER);} >>%tmpsource% cl /nologo %tmpsource% >nul for /f %%x in ('%tmpprogram%') do set version=%%x del %tmpprogram%.* >nul set offset=0 if %version% LSS 1900 set /a offset=1 set /a version="version / 10 - 10 * ( 5 + offset )" endlocal & set %1=%version%& goto :EOF :: toupper; makes use of the fact that string :: replacement (via SET) is not case sensitive :toupper for %%L IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET %1=!%1:%%L=%%L! goto :EOF
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test/lest/lest_cpp03.hpp
// Copyright 2013-2018 by Martin Moene // // lest is based on ideas by Kevlin Henney, see video at // http://skillsmatter.com/podcast/agile-testing/kevlin-henney-rethinking-unit-testing-in-c-plus-plus // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef LEST_LEST_HPP_INCLUDED #define LEST_LEST_HPP_INCLUDED #include <algorithm> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <sstream> #include <stdexcept> #include <set> #include <string> #include <utility> #include <vector> #include <cctype> #include <cmath> #include <cstddef> #include <cstdlib> #include <ctime> #define lest_MAJOR 1 #define lest_MINOR 35 #define lest_PATCH 1 #define lest_VERSION lest_STRINGIFY(lest_MAJOR) "." lest_STRINGIFY(lest_MINOR) "." lest_STRINGIFY(lest_PATCH) #ifndef lest_FEATURE_COLOURISE # define lest_FEATURE_COLOURISE 0 #endif #ifndef lest_FEATURE_LITERAL_SUFFIX # define lest_FEATURE_LITERAL_SUFFIX 0 #endif #ifndef lest_FEATURE_REGEX_SEARCH # define lest_FEATURE_REGEX_SEARCH 0 #endif #ifndef lest_FEATURE_TIME # define lest_FEATURE_TIME 1 #endif #ifndef lest_FEATURE_TIME_PRECISION #define lest_FEATURE_TIME_PRECISION 0 #endif #ifdef _WIN32 # define lest_PLATFORM_IS_WINDOWS 1 #else # define lest_PLATFORM_IS_WINDOWS 0 #endif #if lest_FEATURE_REGEX_SEARCH # include <regex> #endif #if lest_FEATURE_TIME # if lest_PLATFORM_IS_WINDOWS # include <iomanip> # include <Windows.h> # else # include <iomanip> # include <sys/time.h> # endif #endif // Compiler warning suppression: #if defined (__clang__) # pragma clang diagnostic ignored "-Waggregate-return" # pragma clang diagnostic ignored "-Woverloaded-shift-op-parentheses" # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wdate-time" #elif defined (__GNUC__) # pragma GCC diagnostic ignored "-Waggregate-return" # pragma GCC diagnostic push #endif // Suppress shadow and unused-value warning for sections: #if defined (__clang__) # define lest_SUPPRESS_WSHADOW _Pragma( "clang diagnostic push" ) \ _Pragma( "clang diagnostic ignored \"-Wshadow\"" ) # define lest_SUPPRESS_WUNUSED _Pragma( "clang diagnostic push" ) \ _Pragma( "clang diagnostic ignored \"-Wunused-value\"" ) # define lest_RESTORE_WARNINGS _Pragma( "clang diagnostic pop" ) #elif defined (__GNUC__) # define lest_SUPPRESS_WSHADOW _Pragma( "GCC diagnostic push" ) \ _Pragma( "GCC diagnostic ignored \"-Wshadow\"" ) # define lest_SUPPRESS_WUNUSED _Pragma( "GCC diagnostic push" ) \ _Pragma( "GCC diagnostic ignored \"-Wunused-value\"" ) # define lest_RESTORE_WARNINGS _Pragma( "GCC diagnostic pop" ) #else # define lest_SUPPRESS_WSHADOW /*empty*/ # define lest_SUPPRESS_WUNUSED /*empty*/ # define lest_RESTORE_WARNINGS /*empty*/ #endif // Stringify: #define lest_STRINGIFY( x ) lest_STRINGIFY_( x ) #define lest_STRINGIFY_( x ) #x // Compiler versions: #if defined( _MSC_VER ) && !defined( __clang__ ) # define lest_COMPILER_MSVC_VERSION ( _MSC_VER / 10 - 10 * ( 5 + ( _MSC_VER < 1900 ) ) ) #else # define lest_COMPILER_MSVC_VERSION 0 #endif #define lest_COMPILER_VERSION( major, minor, patch ) ( 10 * ( 10 * major + minor ) + patch ) #if defined (__clang__) # define lest_COMPILER_CLANG_VERSION lest_COMPILER_VERSION( __clang_major__, __clang_minor__, __clang_patchlevel__ ) #else # define lest_COMPILER_CLANG_VERSION 0 #endif #if defined (__GNUC__) # define lest_COMPILER_GNUC_VERSION lest_COMPILER_VERSION( __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ ) #else # define lest_COMPILER_GNUC_VERSION 0 #endif // C++ language version detection (C++20 is speculative): // Note: VC14.0/1900 (VS2015) lacks too much from C++14. #ifndef lest_CPLUSPLUS # if defined(_MSVC_LANG ) && !defined(__clang__) # define lest_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG ) # else # define lest_CPLUSPLUS __cplusplus # endif #endif #define lest_CPP98_OR_GREATER ( lest_CPLUSPLUS >= 199711L ) #define lest_CPP11_OR_GREATER ( lest_CPLUSPLUS >= 201103L || lest_COMPILER_MSVC_VERSION >= 120 ) #define lest_CPP14_OR_GREATER ( lest_CPLUSPLUS >= 201402L ) #define lest_CPP17_OR_GREATER ( lest_CPLUSPLUS >= 201703L ) #define lest_CPP20_OR_GREATER ( lest_CPLUSPLUS >= 202000L ) #define lest_CPP11_100 (lest_CPP11_OR_GREATER || lest_COMPILER_MSVC_VERSION >= 100) #ifndef __has_cpp_attribute # define __has_cpp_attribute(name) 0 #endif // Indicate argument as possibly unused, if possible: #if __has_cpp_attribute(maybe_unused) && lest_CPP17_OR_GREATER # define lest_MAYBE_UNUSED(ARG) [[maybe_unused]] ARG #elif defined (__GNUC__) # define lest_MAYBE_UNUSED(ARG) ARG __attribute((unused)) #else # define lest_MAYBE_UNUSED(ARG) ARG #endif // Presence of language and library features: #define lest_HAVE(FEATURE) ( lest_HAVE_##FEATURE ) // Presence of C++11 language features: #define lest_HAVE_NOEXCEPT ( lest_CPP11_100 ) #define lest_HAVE_NULLPTR ( lest_CPP11_100 ) // C++ feature usage: #if lest_HAVE( NULLPTR ) # define lest_nullptr nullptr #else # define lest_nullptr NULL #endif // Additional includes and tie: #if lest_CPP11_100 # include <cstdint> # include <random> # include <tuple> namespace lest { using std::tie; } #else # if !defined(__clang__) && defined(__GNUC__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Weffc++" # endif namespace lest { // tie: template< typename T1, typename T2 > struct Tie { Tie( T1 & first_, T2 & second_) : first( first_), second( second_) {} std::pair<T1, T2> const & operator=( std::pair<T1, T2> const & rhs ) { first = rhs.first; second = rhs.second; return rhs; } private: void operator=( Tie const & ); T1 & first; T2 & second; }; template< typename T1, typename T2 > inline Tie<T1,T2> tie( T1 & first, T2 & second ) { return Tie<T1, T2>( first, second ); } } # if !defined(__clang__) && defined(__GNUC__) # pragma GCC diagnostic pop # endif #endif // lest_CPP11_100 namespace lest { using std::abs; using std::min; using std::strtol; using std::rand; using std::srand; } #if ! defined( lest_NO_SHORT_MACRO_NAMES ) && ! defined( lest_NO_SHORT_ASSERTION_NAMES ) # define SETUP lest_SETUP # define SECTION lest_SECTION # define EXPECT lest_EXPECT # define EXPECT_NOT lest_EXPECT_NOT # define EXPECT_NO_THROW lest_EXPECT_NO_THROW # define EXPECT_THROWS lest_EXPECT_THROWS # define EXPECT_THROWS_AS lest_EXPECT_THROWS_AS # define SCENARIO lest_SCENARIO # define GIVEN lest_GIVEN # define WHEN lest_WHEN # define THEN lest_THEN # define AND_WHEN lest_AND_WHEN # define AND_THEN lest_AND_THEN #endif #define lest_SCENARIO( specification, sketch ) \ lest_CASE( specification, lest::text("Scenario: ") + sketch ) #define lest_GIVEN( context ) lest_SETUP( lest::text(" Given: ") + context ) #define lest_WHEN( story ) lest_SECTION( lest::text(" When: ") + story ) #define lest_THEN( story ) lest_SECTION( lest::text(" Then: ") + story ) #define lest_AND_WHEN( story ) lest_SECTION( lest::text("And then: ") + story ) #define lest_AND_THEN( story ) lest_SECTION( lest::text("And then: ") + story ) #define lest_CASE( specification, proposition ) \ static void lest_FUNCTION( lest::env & ); \ namespace { lest::add_test lest_REGISTRAR( specification, lest::test( proposition, lest_FUNCTION ) ); } \ static void lest_FUNCTION( lest_MAYBE_UNUSED( lest::env & lest_env ) ) #define lest_ADD_TEST( specification, test ) \ specification.push_back( test ) #define lest_SETUP( context ) \ for ( int lest__section = 0, lest__count = 1; lest__section < lest__count; lest__count -= 0==lest__section++ ) \ for ( lest::ctx lest__ctx_setup( lest_env, context ); lest__ctx_setup; ) #define lest_SECTION( proposition ) \ lest_SUPPRESS_WSHADOW \ static int lest_UNIQUE( id ) = 0; \ if ( lest::guard( lest_UNIQUE( id ), lest__section, lest__count ) ) \ for ( int lest__section = 0, lest__count = 1; lest__section < lest__count; lest__count -= 0==lest__section++ ) \ for ( lest::ctx lest__ctx_section( lest_env, proposition ); lest__ctx_section; ) \ lest_RESTORE_WARNINGS #define lest_EXPECT( expr ) \ do { \ try \ { \ if ( lest::result score = lest_DECOMPOSE( expr ) ) \ throw lest::failure( lest_LOCATION, #expr, score.decomposition ); \ else if ( lest_env.pass() ) \ lest::report( lest_env.os, lest::passing( lest_LOCATION, #expr, score.decomposition, lest_env.zen() ), lest_env.context() ); \ } \ catch(...) \ { \ lest::inform( lest_LOCATION, #expr ); \ } \ } while ( lest::is_false() ) #define lest_EXPECT_NOT( expr ) \ do { \ try \ { \ if ( lest::result score = lest_DECOMPOSE( expr ) ) \ { \ if ( lest_env.pass() ) \ lest::report( lest_env.os, lest::passing( lest_LOCATION, lest::not_expr( #expr ), lest::not_expr( score.decomposition ), lest_env.zen() ), lest_env.context() ); \ } \ else \ throw lest::failure( lest_LOCATION, lest::not_expr( #expr ), lest::not_expr( score.decomposition ) ); \ } \ catch(...) \ { \ lest::inform( lest_LOCATION, lest::not_expr( #expr ) ); \ } \ } while ( lest::is_false() ) #define lest_EXPECT_NO_THROW( expr ) \ do \ { \ try \ { \ lest_SUPPRESS_WUNUSED \ expr; \ lest_RESTORE_WARNINGS \ } \ catch (...) { lest::inform( lest_LOCATION, #expr ); } \ if ( lest_env.pass() ) \ lest::report( lest_env.os, lest::got_none( lest_LOCATION, #expr ), lest_env.context() ); \ } while ( lest::is_false() ) #define lest_EXPECT_THROWS( expr ) \ do \ { \ try \ { \ lest_SUPPRESS_WUNUSED \ expr; \ lest_RESTORE_WARNINGS \ } \ catch (...) \ { \ if ( lest_env.pass() ) \ lest::report( lest_env.os, lest::got( lest_LOCATION, #expr ), lest_env.context() ); \ break; \ } \ throw lest::expected( lest_LOCATION, #expr ); \ } \ while ( lest::is_false() ) #define lest_EXPECT_THROWS_AS( expr, excpt ) \ do \ { \ try \ { \ lest_SUPPRESS_WUNUSED \ expr; \ lest_RESTORE_WARNINGS \ } \ catch ( excpt & ) \ { \ if ( lest_env.pass() ) \ lest::report( lest_env.os, lest::got( lest_LOCATION, #expr, lest::of_type( #excpt ) ), lest_env.context() ); \ break; \ } \ catch (...) {} \ throw lest::expected( lest_LOCATION, #expr, lest::of_type( #excpt ) ); \ } \ while ( lest::is_false() ) #define lest_DECOMPOSE( expr ) ( lest::expression_decomposer() << expr ) #define lest_STRING( name ) lest_STRING2( name ) #define lest_STRING2( name ) #name #define lest_UNIQUE( name ) lest_UNIQUE2( name, __LINE__ ) #define lest_UNIQUE2( name, line ) lest_UNIQUE3( name, line ) #define lest_UNIQUE3( name, line ) name ## line #define lest_LOCATION lest::location(__FILE__, __LINE__) #define lest_FUNCTION lest_UNIQUE(__lest_function__ ) #define lest_REGISTRAR lest_UNIQUE(__lest_registrar__ ) #define lest_DIMENSION_OF( a ) ( sizeof(a) / sizeof(0[a]) ) namespace lest { const int exit_max_value = 255; typedef std::string text; typedef std::vector<text> texts; struct env; struct test { text name; void (* behaviour)( env & ); test( text name_, void (* behaviour_)( env & ) ) : name( name_), behaviour( behaviour_) {} }; typedef std::vector<test> tests; typedef tests test_specification; struct add_test { add_test( tests & specification, test const & test_case ) { specification.push_back( test_case ); } }; struct result { const bool passed; const text decomposition; template< typename T > result( T const & passed_, text decomposition_) : passed( !!passed_), decomposition( decomposition_) {} operator bool() { return ! passed; } }; struct location { const text file; const int line; location( text file_, int line_) : file( file_), line( line_) {} }; struct comment { const text info; comment( text info_) : info( info_) {} operator bool() { return ! info.empty(); } }; struct message : std::runtime_error { const text kind; const location where; const comment note; #if ! lest_CPP11_OR_GREATER ~message() throw() {} #endif message( text kind_, location where_, text expr_, text note_ = "" ) : std::runtime_error( expr_), kind( kind_), where( where_), note( note_) {} }; struct failure : message { failure( location where_, text expr_, text decomposition_) : message( "failed", where_, expr_ + " for " + decomposition_) {} }; struct success : message { success( text kind_, location where_, text expr_, text note_ = "" ) : message( kind_, where_, expr_, note_) {} }; struct passing : success { passing( location where_, text expr_, text decomposition_, bool zen ) : success( "passed", where_, expr_ + (zen ? "":" for " + decomposition_) ) {} }; struct got_none : success { got_none( location where_, text expr_) : success( "passed: got no exception", where_, expr_) {} }; struct got : success { got( location where_, text expr_) : success( "passed: got exception", where_, expr_) {} got( location where_, text expr_, text excpt_) : success( "passed: got exception " + excpt_, where_, expr_) {} }; struct expected : message { expected( location where_, text expr_, text excpt_ = "" ) : message( "failed: didn't get exception", where_, expr_, excpt_) {} }; struct unexpected : message { unexpected( location where_, text expr_, text note_ = "" ) : message( "failed: got unexpected exception", where_, expr_, note_) {} }; struct guard { int & id; int const & section; guard( int & id_, int const & section_, int & count ) : id( id_ ), section( section_ ) { if ( section == 0 ) id = count++ - 1; } operator bool() { return id == section; } }; class approx { public: explicit approx ( double magnitude ) : epsilon_ ( 100.0 * static_cast<double>( std::numeric_limits<float>::epsilon() ) ) , scale_ ( 1.0 ) , magnitude_( magnitude ) {} static approx custom() { return approx( 0 ); } approx operator()( double new_magnitude ) { approx appr( new_magnitude ); appr.epsilon( epsilon_ ); appr.scale ( scale_ ); return appr; } double magnitude() const { return magnitude_; } approx & epsilon( double epsilon ) { epsilon_ = epsilon; return *this; } approx & scale ( double scale ) { scale_ = scale; return *this; } friend bool operator == ( double lhs, approx const & rhs ) { // Thanks to Richard Harris for his help refining this formula. return lest::abs( lhs - rhs.magnitude_ ) < rhs.epsilon_ * ( rhs.scale_ + (lest::min)( lest::abs( lhs ), lest::abs( rhs.magnitude_ ) ) ); } friend bool operator == ( approx const & lhs, double rhs ) { return operator==( rhs, lhs ); } friend bool operator != ( double lhs, approx const & rhs ) { return !operator==( lhs, rhs ); } friend bool operator != ( approx const & lhs, double rhs ) { return !operator==( rhs, lhs ); } friend bool operator <= ( double lhs, approx const & rhs ) { return lhs < rhs.magnitude_ || lhs == rhs; } friend bool operator <= ( approx const & lhs, double rhs ) { return lhs.magnitude_ < rhs || lhs == rhs; } friend bool operator >= ( double lhs, approx const & rhs ) { return lhs > rhs.magnitude_ || lhs == rhs; } friend bool operator >= ( approx const & lhs, double rhs ) { return lhs.magnitude_ > rhs || lhs == rhs; } private: double epsilon_; double scale_; double magnitude_; }; inline bool is_false( ) { return false; } inline bool is_true ( bool flag ) { return flag; } inline text not_expr( text message ) { return "! ( " + message + " )"; } inline text with_message( text message ) { return "with message \"" + message + "\""; } inline text of_type( text type ) { return "of type " + type; } inline void inform( location where, text expr ) { try { throw; } catch( failure const & ) { throw; } catch( std::exception const & e ) { throw unexpected( where, expr, with_message( e.what() ) ); \ } catch(...) { throw unexpected( where, expr, "of unknown type" ); \ } } // Expression decomposition: inline bool unprintable( char c ) { return 0 <= c && c < ' '; } inline std::string to_hex_string(char c) { std::ostringstream os; os << "\\x" << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>( static_cast<unsigned char>(c) ); return os.str(); } inline std::string transformed( char chr ) { struct Tr { char chr; char const * str; } table[] = { {'\\', "\\\\" }, {'\r', "\\r" }, {'\f', "\\f" }, {'\n', "\\n" }, {'\t', "\\t" }, }; for ( Tr * pos = table; pos != table + lest_DIMENSION_OF( table ); ++pos ) { if ( chr == pos->chr ) return pos->str; } return unprintable( chr ) ? to_hex_string( chr ) : std::string( 1, chr ); } inline std::string make_tran_string( std::string const & txt ) { std::ostringstream os; for( std::string::const_iterator pos = txt.begin(); pos != txt.end(); ++pos ) os << transformed( *pos ); return os.str(); } template< typename T > inline std::string to_string( T const & value ); #if lest_CPP11_OR_GREATER || lest_COMPILER_MSVC_VERSION >= 100 inline std::string to_string( std::nullptr_t const & ) { return "nullptr"; } #endif inline std::string to_string( std::string const & txt ) { return "\"" + make_tran_string( txt ) + "\""; } inline std::string to_string( char const * const & txt ) { return "\"" + make_tran_string( txt ) + "\""; } inline std::string to_string( char const & chr ) { return "'" + make_tran_string( std::string( 1, chr ) ) + "'"; } inline std::string to_string( signed char const & chr ) { return to_string( static_cast<char const &>( chr ) ); } inline std::string to_string( unsigned char const & chr ) { return to_string( static_cast<char const &>( chr ) ); } inline std::ostream & operator<<( std::ostream & os, approx const & appr ) { return os << appr.magnitude(); } template< typename T > inline std::string make_string( T const * ptr ) { // Note showbase affects the behavior of /integer/ output; std::ostringstream os; os << std::internal << std::hex << std::showbase << std::setw( 2 + 2 * sizeof(T*) ) << std::setfill('0') << reinterpret_cast<std::ptrdiff_t>( ptr ); return os.str(); } template< typename C, typename R > inline std::string make_string( R C::* ptr ) { std::ostringstream os; os << std::internal << std::hex << std::showbase << std::setw( 2 + 2 * sizeof(R C::* ) ) << std::setfill('0') << ptr; return os.str(); } template< typename T > struct string_maker { static std::string to_string( T const & value ) { std::ostringstream os; os << std::boolalpha << value; return os.str(); } }; template< typename T > struct string_maker< T* > { static std::string to_string( T const * ptr ) { return ! ptr ? lest_STRING( lest_nullptr ) : make_string( ptr ); } }; template< typename C, typename R > struct string_maker< R C::* > { static std::string to_string( R C::* ptr ) { return ! ptr ? lest_STRING( lest_nullptr ) : make_string( ptr ); } }; template< typename T > inline std::string to_string( T const & value ) { return string_maker<T>::to_string( value ); } template< typename T1, typename T2 > std::string to_string( std::pair<T1,T2> const & pair ) { std::ostringstream oss; oss << "{ " << to_string( pair.first ) << ", " << to_string( pair.second ) << " }"; return oss.str(); } #if lest_CPP11_OR_GREATER template< typename TU, std::size_t N > struct make_tuple_string { static std::string make( TU const & tuple ) { std::ostringstream os; os << to_string( std::get<N - 1>( tuple ) ) << ( N < std::tuple_size<TU>::value ? ", ": " "); return make_tuple_string<TU, N - 1>::make( tuple ) + os.str(); } }; template< typename TU > struct make_tuple_string<TU, 0> { static std::string make( TU const & ) { return ""; } }; template< typename ...TS > auto to_string( std::tuple<TS...> const & tuple ) -> std::string { return "{ " + make_tuple_string<std::tuple<TS...>, sizeof...(TS)>::make( tuple ) + "}"; } #endif // lest_CPP11_OR_GREATER template< typename L, typename R > std::string to_string( L const & lhs, std::string op, R const & rhs ) { std::ostringstream os; os << to_string( lhs ) << " " << op << " " << to_string( rhs ); return os.str(); } template< typename L > struct expression_lhs { L lhs; expression_lhs( L lhs_) : lhs( lhs_) {} operator result() { return result( !!lhs, to_string( lhs ) ); } template< typename R > result operator==( R const & rhs ) { return result( lhs == rhs, to_string( lhs, "==", rhs ) ); } template< typename R > result operator!=( R const & rhs ) { return result( lhs != rhs, to_string( lhs, "!=", rhs ) ); } template< typename R > result operator< ( R const & rhs ) { return result( lhs < rhs, to_string( lhs, "<" , rhs ) ); } template< typename R > result operator<=( R const & rhs ) { return result( lhs <= rhs, to_string( lhs, "<=", rhs ) ); } template< typename R > result operator> ( R const & rhs ) { return result( lhs > rhs, to_string( lhs, ">" , rhs ) ); } template< typename R > result operator>=( R const & rhs ) { return result( lhs >= rhs, to_string( lhs, ">=", rhs ) ); } }; struct expression_decomposer { template< typename L > expression_lhs<L const &> operator<< ( L const & operand ) { return expression_lhs<L const &>( operand ); } }; // Reporter: #if lest_FEATURE_COLOURISE inline text red ( text words ) { return "\033[1;31m" + words + "\033[0m"; } inline text green( text words ) { return "\033[1;32m" + words + "\033[0m"; } inline text gray ( text words ) { return "\033[1;30m" + words + "\033[0m"; } inline bool starts_with( text words, text with ) { return 0 == words.find( with ); } inline text replace( text words, text from, text to ) { size_t pos = words.find( from ); return pos == std::string::npos ? words : words.replace( pos, from.length(), to ); } inline text colour( text words ) { if ( starts_with( words, "failed" ) ) return replace( words, "failed", red ( "failed" ) ); else if ( starts_with( words, "passed" ) ) return replace( words, "passed", green( "passed" ) ); return replace( words, "for", gray( "for" ) ); } inline bool is_cout( std::ostream & os ) { return &os == &std::cout; } struct colourise { const text words; colourise( text words ) : words( words ) {} // only colourise for std::cout, not for a stringstream as used in tests: std::ostream & operator()( std::ostream & os ) const { return is_cout( os ) ? os << colour( words ) : os << words; } }; inline std::ostream & operator<<( std::ostream & os, colourise words ) { return words( os ); } #else inline text colourise( text words ) { return words; } #endif inline text pluralise( text word,int n ) { return n == 1 ? word : word + "s"; } inline std::ostream & operator<<( std::ostream & os, comment note ) { return os << (note ? " " + note.info : "" ); } inline std::ostream & operator<<( std::ostream & os, location where ) { #ifdef __GNUG__ return os << where.file << ":" << where.line; #else return os << where.file << "(" << where.line << ")"; #endif } inline void report( std::ostream & os, message const & e, text test ) { os << e.where << ": " << colourise( e.kind ) << e.note << ": " << test << ": " << colourise( e.what() ) << std::endl; } // Test runner: #if lest_FEATURE_REGEX_SEARCH inline bool search( text re, text line ) { return std::regex_search( line, std::regex( re ) ); } #else inline bool case_insensitive_equal( char a, char b ) { return tolower( a ) == tolower( b ); } inline bool search( text part, text line ) { return std::search( line.begin(), line.end(), part.begin(), part.end(), case_insensitive_equal ) != line.end(); } #endif inline bool match( texts whats, text line ) { for ( texts::iterator what = whats.begin(); what != whats.end() ; ++what ) { if ( search( *what, line ) ) return true; } return false; } inline bool hidden( text name ) { #if lest_FEATURE_REGEX_SEARCH texts skipped; skipped.push_back( "\\[\\.\\]" ); skipped.push_back( "\\[hide\\]" ); #else texts skipped; skipped.push_back( "[." ); skipped.push_back( "[hide]" ); #endif return match( skipped, name ); } inline bool none( texts args ) { return args.size() == 0; } inline bool select( text name, texts include ) { if ( none( include ) ) { return ! hidden( name ); } bool any = false; for ( texts::reverse_iterator pos = include.rbegin(); pos != include.rend(); ++pos ) { text & part = *pos; if ( part == "@" || part == "*" ) return true; if ( search( part, name ) ) return true; if ( '!' == part[0] ) { any = true; if ( search( part.substr(1), name ) ) return false; } else { any = false; } } return any && ! hidden( name ); } inline int indefinite( int repeat ) { return repeat == -1; } #if lest_CPP11_OR_GREATER typedef std::mt19937::result_type seed_t; #else typedef unsigned int seed_t; #endif struct options { options() : help(false), abort(false), count(false), list(false), tags(false), time(false) , pass(false), zen(false), lexical(false), random(false), verbose(false), version(false), repeat(1), seed(0) {} bool help; bool abort; bool count; bool list; bool tags; bool time; bool pass; bool zen; bool lexical; bool random; bool verbose; bool version; int repeat; seed_t seed; }; struct env { std::ostream & os; options opt; text testing; std::vector< text > ctx; env( std::ostream & out, options option ) : os( out ), opt( option ), testing(), ctx() {} env & operator()( text test ) { clear(); testing = test; return *this; } bool abort() { return opt.abort; } bool pass() { return opt.pass; } bool zen() { return opt.zen; } void clear() { ctx.clear(); } void pop() { ctx.pop_back(); } void push( text proposition ) { ctx.push_back( proposition ); } text context() { return testing + sections(); } text sections() { if ( ! opt.verbose ) return ""; text msg; for( size_t i = 0; i != ctx.size(); ++i ) { msg += "\n " + ctx[i]; } return msg; } }; struct ctx { env & environment; bool once; ctx( env & environment_, text proposition_ ) : environment( environment_), once( true ) { environment.push( proposition_); } ~ctx() { #if lest_CPP17_OR_GREATER if ( std::uncaught_exceptions() == 0 ) #else if ( ! std::uncaught_exception() ) #endif { environment.pop(); } } operator bool() { bool result = once; once = false; return result; } }; struct action { std::ostream & os; action( std::ostream & out ) : os( out ) {} operator int() { return 0; } bool abort() { return false; } action & operator()( test ) { return *this; } private: action( action const & ); void operator=( action const & ); }; struct print : action { print( std::ostream & out ) : action( out ) {} print & operator()( test testing ) { os << testing.name << "\n"; return *this; } }; inline texts tags( text name, texts result = texts() ) { size_t none = std::string::npos; size_t lb = name.find_first_of( "[" ); size_t rb = name.find_first_of( "]" ); if ( lb == none || rb == none ) return result; result.push_back( name.substr( lb, rb - lb + 1 ) ); return tags( name.substr( rb + 1 ), result ); } struct ptags : action { std::set<text> result; ptags( std::ostream & out ) : action( out ), result() {} ptags & operator()( test testing ) { texts tags_( tags( testing.name ) ); for ( texts::iterator pos = tags_.begin(); pos != tags_.end() ; ++pos ) result.insert( *pos ); return *this; } ~ptags() { std::copy( result.begin(), result.end(), std::ostream_iterator<text>( os, "\n" ) ); } }; struct count : action { int n; count( std::ostream & out ) : action( out ), n( 0 ) {} count & operator()( test ) { ++n; return *this; } ~count() { os << n << " selected " << pluralise("test", n) << "\n"; } }; #if lest_FEATURE_TIME #if lest_PLATFORM_IS_WINDOWS # if ! lest_CPP11_OR_GREATER && ! lest_COMPILER_MSVC_VERSION typedef unsigned long uint64_t; # elif lest_COMPILER_MSVC_VERSION >= 60 && lest_COMPILER_MSVC_VERSION < 100 typedef /*un*/signed __int64 uint64_t; # else using ::uint64_t; # endif #else # if ! lest_CPP11_OR_GREATER typedef unsigned long long uint64_t; # endif #endif #if lest_PLATFORM_IS_WINDOWS inline uint64_t current_ticks() { static LARGE_INTEGER hz = {{ 0,0 }}, hzo = {{ 0,0 }}; if ( ! hz.QuadPart ) { QueryPerformanceFrequency( &hz ); QueryPerformanceCounter ( &hzo ); } LARGE_INTEGER t = {{ 0,0 }}; QueryPerformanceCounter( &t ); return uint64_t( ( ( t.QuadPart - hzo.QuadPart ) * 1000000 ) / hz.QuadPart ); } #else inline uint64_t current_ticks() { timeval t; gettimeofday( &t, lest_nullptr ); return static_cast<uint64_t>( t.tv_sec ) * 1000000ull + static_cast<uint64_t>( t.tv_usec ); } #endif struct timer { const uint64_t start_ticks; timer() : start_ticks( current_ticks() ) {} double elapsed_seconds() const { return static_cast<double>( current_ticks() - start_ticks ) / 1e6; } }; struct times : action { env output; int selected; int failures; timer total; times( std::ostream & out, options option ) : action( out ), output( out, option ), selected( 0 ), failures( 0 ), total() { os << std::setfill(' ') << std::fixed << std::setprecision( lest_FEATURE_TIME_PRECISION ); } operator int() { return failures; } bool abort() { return output.abort() && failures > 0; } times & operator()( test testing ) { timer t; try { testing.behaviour( output( testing.name ) ); } catch( message const & ) { ++failures; } os << std::setw(5) << ( 1000 * t.elapsed_seconds() ) << " ms: " << testing.name << "\n"; return *this; } ~times() { os << "Elapsed time: " << std::setprecision(1) << total.elapsed_seconds() << " s\n"; } }; #else struct times : action { times( std::ostream & out, options ) : action( out ) {} }; #endif struct confirm : action { env output; int selected; int failures; confirm( std::ostream & out, options option ) : action( out ), output( out, option ), selected( 0 ), failures( 0 ) {} operator int() { return failures; } bool abort() { return output.abort() && failures > 0; } confirm & operator()( test testing ) { try { ++selected; testing.behaviour( output( testing.name ) ); } catch( message const & e ) { ++failures; report( os, e, output.context() ); } return *this; } ~confirm() { if ( failures > 0 ) { os << failures << " out of " << selected << " selected " << pluralise("test", selected) << " " << colourise( "failed.\n" ); } else if ( output.pass() ) { os << "All " << selected << " selected " << pluralise("test", selected) << " " << colourise( "passed.\n" ); } } }; template< typename Action > bool abort( Action & perform ) { return perform.abort(); } template< typename Action > Action & for_test( tests specification, texts in, Action & perform, int n = 1 ) { for ( int i = 0; indefinite( n ) || i < n; ++i ) { for ( tests::iterator pos = specification.begin(); pos != specification.end() ; ++pos ) { test & testing = *pos; if ( select( testing.name, in ) ) if ( abort( perform( testing ) ) ) return perform; } } return perform; } inline bool test_less( test const & a, test const & b ) { return a.name < b.name; } inline void sort( tests & specification ) { std::sort( specification.begin(), specification.end(), test_less ); } // Use struct to avoid VC6 error C2664 when using free function: struct rng { int operator()( int n ) { return lest::rand() % n; } }; inline void shuffle( tests & specification, options option ) { #if lest_CPP11_OR_GREATER std::shuffle( specification.begin(), specification.end(), std::mt19937( option.seed ) ); #else lest::srand( option.seed ); rng generator; std::random_shuffle( specification.begin(), specification.end(), generator ); #endif } inline int stoi( text num ) { return static_cast<int>( lest::strtol( num.c_str(), lest_nullptr, 10 ) ); } inline bool is_number( text arg ) { const text digits = "0123456789"; return text::npos != arg.find_first_of ( digits ) && text::npos == arg.find_first_not_of( digits ); } inline seed_t seed( text opt, text arg ) { // std::time_t: implementation dependent if ( arg == "time" ) return static_cast<seed_t>( time( lest_nullptr ) ); if ( is_number( arg ) ) return static_cast<seed_t>( lest::stoi( arg ) ); throw std::runtime_error( "expecting 'time' or positive number with option '" + opt + "', got '" + arg + "' (try option --help)" ); } inline int repeat( text opt, text arg ) { const int num = lest::stoi( arg ); if ( indefinite( num ) || num >= 0 ) return num; throw std::runtime_error( "expecting '-1' or positive number with option '" + opt + "', got '" + arg + "' (try option --help)" ); } inline std::pair<text, text> split_option( text arg ) { text::size_type pos = arg.rfind( '=' ); return pos == text::npos ? std::make_pair( arg, text() ) : std::make_pair( arg.substr( 0, pos ), arg.substr( pos + 1 ) ); } inline std::pair<options, texts> split_arguments( texts args ) { options option; texts in; bool in_options = true; for ( texts::iterator pos = args.begin(); pos != args.end() ; ++pos ) { text opt, val, arg = *pos; tie( opt, val ) = split_option( arg ); if ( in_options ) { if ( opt[0] != '-' ) { in_options = false; } else if ( opt == "--" ) { in_options = false; continue; } else if ( opt == "-h" || "--help" == opt ) { option.help = true; continue; } else if ( opt == "-a" || "--abort" == opt ) { option.abort = true; continue; } else if ( opt == "-c" || "--count" == opt ) { option.count = true; continue; } else if ( opt == "-g" || "--list-tags" == opt ) { option.tags = true; continue; } else if ( opt == "-l" || "--list-tests" == opt ) { option.list = true; continue; } else if ( opt == "-t" || "--time" == opt ) { option.time = true; continue; } else if ( opt == "-p" || "--pass" == opt ) { option.pass = true; continue; } else if ( opt == "-z" || "--pass-zen" == opt ) { option.zen = true; continue; } else if ( opt == "-v" || "--verbose" == opt ) { option.verbose = true; continue; } else if ( "--version" == opt ) { option.version = true; continue; } else if ( opt == "--order" && "declared" == val ) { /* by definition */ ; continue; } else if ( opt == "--order" && "lexical" == val ) { option.lexical = true; continue; } else if ( opt == "--order" && "random" == val ) { option.random = true; continue; } else if ( opt == "--random-seed" ) { option.seed = seed ( "--random-seed", val ); continue; } else if ( opt == "--repeat" ) { option.repeat = repeat( "--repeat" , val ); continue; } else throw std::runtime_error( "unrecognised option '" + opt + "' (try option --help)" ); } in.push_back( arg ); } option.pass = option.pass || option.zen; return std::make_pair( option, in ); } inline int usage( std::ostream & os ) { os << "\nUsage: test [options] [test-spec ...]\n" "\n" "Options:\n" " -h, --help this help message\n" " -a, --abort abort at first failure\n" " -c, --count count selected tests\n" " -g, --list-tags list tags of selected tests\n" " -l, --list-tests list selected tests\n" " -p, --pass also report passing tests\n" " -z, --pass-zen ... without expansion\n" #if lest_FEATURE_TIME " -t, --time list duration of selected tests\n" #endif " -v, --verbose also report passing or failing sections\n" " --order=declared use source code test order (default)\n" " --order=lexical use lexical sort test order\n" " --order=random use random test order\n" " --random-seed=n use n for random generator seed\n" " --random-seed=time use time for random generator seed\n" " --repeat=n repeat selected tests n times (-1: indefinite)\n" " --version report lest version and compiler used\n" " -- end options\n" "\n" "Test specification:\n" " \"@\", \"*\" all tests, unless excluded\n" " empty all tests, unless tagged [hide] or [.optional-name]\n" #if lest_FEATURE_REGEX_SEARCH " \"re\" select tests that match regular expression\n" " \"!re\" omit tests that match regular expression\n" #else " \"text\" select tests that contain text (case insensitive)\n" " \"!text\" omit tests that contain text (case insensitive)\n" #endif ; return 0; } inline text compiler() { std::ostringstream os; #if defined (__clang__ ) os << "clang " << __clang_version__; #elif defined (__GNUC__ ) os << "gcc " << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__; #elif defined ( _MSC_VER ) os << "MSVC " << lest_COMPILER_MSVC_VERSION << " (" << _MSC_VER << ")"; #else os << "[compiler]"; #endif return os.str(); } inline int version( std::ostream & os ) { os << "lest version " << lest_VERSION << "\n" << "Compiled with " << compiler() << " on " << __DATE__ << " at " << __TIME__ << ".\n" << "For more information, see https://github.com/martinmoene/lest.\n"; return 0; } inline int run( tests specification, texts arguments, std::ostream & os = std::cout ) { try { options option; texts in; tie( option, in ) = split_arguments( arguments ); if ( option.lexical ) { sort( specification ); } if ( option.random ) { shuffle( specification, option ); } if ( option.help ) { return usage ( os ); } if ( option.version ) { return version( os ); } if ( option.count ) { count count_( os ); return for_test( specification, in, count_ ); } if ( option.list ) { print print_( os ); return for_test( specification, in, print_ ); } if ( option.tags ) { ptags ptags_( os ); return for_test( specification, in, ptags_ ); } if ( option.time ) { times times_( os, option ); return for_test( specification, in, times_ ); } { confirm confirm_( os, option ); return for_test( specification, in, confirm_, option.repeat ); } } catch ( std::exception const & e ) { os << "Error: " << e.what() << "\n"; return 1; } } // VC6: make<cont>(first,last) replaces cont(first,last) template< typename C, typename T > C make( T const * first, T const * const last ) { C result; for ( ; first != last; ++first ) { result.push_back( *first ); } return result; } inline tests make_tests( test const * first, test const * const last ) { return make<tests>( first, last ); } inline texts make_texts( char const * const * first, char const * const * last ) { return make<texts>( first, last ); } // Traversal of test[N] (test_specification[N]) set up to also work with MSVC6: template< typename C > test const * test_begin( C const & c ) { return &*c; } template< typename C > test const * test_end( C const & c ) { return test_begin( c ) + lest_DIMENSION_OF( c ); } template< typename C > char const * const * text_begin( C const & c ) { return &*c; } template< typename C > char const * const * text_end( C const & c ) { return text_begin( c ) + lest_DIMENSION_OF( c ); } template< typename C > tests make_tests( C const & c ) { return make_tests( test_begin( c ), test_end( c ) ); } template< typename C > texts make_texts( C const & c ) { return make_texts( text_begin( c ), text_end( c ) ); } inline int run( tests const & specification, int argc, char ** argv, std::ostream & os = std::cout ) { return run( specification, make_texts( argv + 1, argv + argc ), os ); } inline int run( tests const & specification, std::ostream & os = std::cout ) { std::cout.sync_with_stdio( false ); return (min)( run( specification, texts(), os ), exit_max_value ); } template< typename C > int run( C const & specification, texts args, std::ostream & os = std::cout ) { return run( make_tests( specification ), args, os ); } template< typename C > int run( C const & specification, int argc, char ** argv, std::ostream & os = std::cout ) { return run( make_tests( specification ), argv, argc, os ); } template< typename C > int run( C const & specification, std::ostream & os = std::cout ) { return run( make_tests( specification ), os ); } } // namespace lest #if defined (__clang__) # pragma clang diagnostic pop #elif defined (__GNUC__) # pragma GCC diagnostic pop #endif #endif // LEST_LEST_HPP_INCLUDED
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/test/nonstd/span.tweak.hpp
#define SPAN_TWEAK_VALUE 42
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/cmake/span-lite-config-version.cmake.in
# Adapted from write_basic_package_version_file(... COMPATIBILITY SameMajorVersion) output # ARCH_INDEPENDENT is only present in cmake 3.14 and onwards set(PACKAGE_VERSION "@package_version@") if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() if("@package_version@" MATCHES "^([0-9]+)\\.") set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") else() set(CVF_VERSION_MAJOR "@package_version@") endif() if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) set(PACKAGE_VERSION_COMPATIBLE TRUE) else() set(PACKAGE_VERSION_COMPATIBLE FALSE) endif() if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) set(PACKAGE_VERSION_EXACT TRUE) endif() endif()
0
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite
repos/outcome/test/quickcpplib/include/quickcpplib/span-lite/cmake/span-lite-config.cmake.in
@PACKAGE_INIT@ # Only include targets once: if( NOT TARGET @package_name@::@package_name@ ) include( "${CMAKE_CURRENT_LIST_DIR}/@[email protected]" ) endif()
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/valgrind/drd.h
/* ---------------------------------------------------------------- Notice that the following BSD-style license applies to this one file (drd.h) only. The rest of Valgrind is licensed under the terms of the GNU General Public License, version 2, unless otherwise indicated. See the COPYING file in the source distribution for details. ---------------------------------------------------------------- This file is part of DRD, a Valgrind tool for verification of multithreaded programs. Copyright (C) 2006-2013 Bart Van Assche <[email protected]>. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 3. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 4. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------- Notice that the above BSD-style license applies to this one file (drd.h) only. The entire rest of Valgrind is licensed under the terms of the GNU General Public License, version 2. See the COPYING file in the source distribution for details. ---------------------------------------------------------------- */ #ifndef __VALGRIND_DRD_H #define __VALGRIND_DRD_H #include "valgrind.h" /** Obtain the thread ID assigned by Valgrind's core. */ #define DRD_GET_VALGRIND_THREADID \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID, \ 0, 0, 0, 0, 0) /** Obtain the thread ID assigned by DRD. */ #define DRD_GET_DRD_THREADID \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__DRD_GET_DRD_THREAD_ID, \ 0, 0, 0, 0, 0) /** Tell DRD not to complain about data races for the specified variable. */ #define DRD_IGNORE_VAR(x) ANNOTATE_BENIGN_RACE_SIZED(&(x), sizeof(x), "") /** Tell DRD to no longer ignore data races for the specified variable. */ #define DRD_STOP_IGNORING_VAR(x) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_FINISH_SUPPRESSION, \ &(x), sizeof(x), 0, 0, 0) /** * Tell DRD to trace all memory accesses for the specified variable * until the memory that was allocated for the variable is freed. */ #define DRD_TRACE_VAR(x) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_TRACE_ADDR, \ &(x), sizeof(x), 0, 0, 0) /** * Tell DRD to stop tracing memory accesses for the specified variable. */ #define DRD_STOP_TRACING_VAR(x) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_STOP_TRACE_ADDR, \ &(x), sizeof(x), 0, 0, 0) /** * @defgroup RaceDetectionAnnotations Data race detection annotations. * * @see See also the source file <a href="http://code.google.com/p/data-race-test/source/browse/trunk/dynamic_annotations/dynamic_annotations.h</a> * in the ThreadSanitizer project. */ /*@{*/ #ifndef __HELGRIND_H /** * Tell DRD to insert a happens-before mark. addr is the address of an object * that is not a pthread synchronization object. */ #define ANNOTATE_HAPPENS_BEFORE(addr) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE, \ addr, 0, 0, 0, 0) /** * Tell DRD that the memory accesses executed after this annotation will * happen after all memory accesses performed before all preceding * ANNOTATE_HAPPENS_BEFORE(addr). addr is the address of an object that is not * a pthread synchronization object. Inserting a happens-after annotation * before any other thread has passed by a happens-before annotation for the * same address is an error. */ #define ANNOTATE_HAPPENS_AFTER(addr) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER, \ addr, 0, 0, 0, 0) #else /* __HELGRIND_H */ #undef ANNOTATE_CONDVAR_LOCK_WAIT #undef ANNOTATE_CONDVAR_WAIT #undef ANNOTATE_CONDVAR_SIGNAL #undef ANNOTATE_CONDVAR_SIGNAL_ALL #undef ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX #undef ANNOTATE_PUBLISH_MEMORY_RANGE #undef ANNOTATE_BARRIER_INIT #undef ANNOTATE_BARRIER_WAIT_BEFORE #undef ANNOTATE_BARRIER_WAIT_AFTER #undef ANNOTATE_BARRIER_DESTROY #undef ANNOTATE_PCQ_CREATE #undef ANNOTATE_PCQ_DESTROY #undef ANNOTATE_PCQ_PUT #undef ANNOTATE_PCQ_GET #undef ANNOTATE_BENIGN_RACE #undef ANNOTATE_BENIGN_RACE_SIZED #undef ANNOTATE_IGNORE_READS_BEGIN #undef ANNOTATE_IGNORE_READS_END #undef ANNOTATE_IGNORE_WRITES_BEGIN #undef ANNOTATE_IGNORE_WRITES_END #undef ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN #undef ANNOTATE_IGNORE_READS_AND_WRITES_END #undef ANNOTATE_NEW_MEMORY #undef ANNOTATE_TRACE_MEMORY #undef ANNOTATE_THREAD_NAME #endif /* __HELGRIND_H */ /** * Tell DRD that waiting on the condition variable at address cv has succeeded * and a lock on the mutex at address mtx is now held. Since DRD always inserts * a happens before relation between the pthread_cond_signal() or * pthread_cond_broadcast() call that wakes up a pthread_cond_wait() or * pthread_cond_timedwait() call and the woken up thread, this macro has been * defined such that it has no effect. */ #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, mtx) do { } while(0) /** * Tell DRD that the condition variable at address cv is about to be signaled. */ #define ANNOTATE_CONDVAR_SIGNAL(cv) do { } while(0) /** * Tell DRD that the condition variable at address cv is about to be signaled. */ #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) do { } while(0) /** * Tell DRD that waiting on condition variable at address cv succeeded and that * the memory operations performed after this annotation should be considered * to happen after the matching ANNOTATE_CONDVAR_SIGNAL(cv). Since this is the * default behavior of DRD, this macro and the macro above have been defined * such that they have no effect. */ #define ANNOTATE_CONDVAR_WAIT(cv) do { } while(0) /** * Tell DRD to consider the memory operations that happened before a mutex * unlock event and after the subsequent mutex lock event on the same mutex as * ordered. This is how DRD always behaves, so this macro has been defined * such that it has no effect. */ #define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mtx) do { } while(0) /** Deprecated -- don't use this annotation. */ #define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mtx) do { } while(0) /** * Tell DRD to handle the specified memory range like a pure happens-before * detector would do. Since this is how DRD always behaves, this annotation * has been defined such that it has no effect. */ #define ANNOTATE_PUBLISH_MEMORY_RANGE(addr, size) do { } while(0) /** Deprecated -- don't use this annotation. */ #define ANNOTATE_UNPUBLISH_MEMORY_RANGE(addr, size) do { } while(0) /** Deprecated -- don't use this annotation. */ #define ANNOTATE_SWAP_MEMORY_RANGE(addr, size) do { } while(0) #ifndef __HELGRIND_H /** Tell DRD that a reader-writer lock object has been initialized. */ #define ANNOTATE_RWLOCK_CREATE(rwlock) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE, \ rwlock, 0, 0, 0, 0); /** Tell DRD that a reader-writer lock object has been destroyed. */ #define ANNOTATE_RWLOCK_DESTROY(rwlock) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY, \ rwlock, 0, 0, 0, 0); /** * Tell DRD that a reader-writer lock has been acquired. is_w == 1 means that * a write lock has been obtained, is_w == 0 means that a read lock has been * obtained. */ #define ANNOTATE_RWLOCK_ACQUIRED(rwlock, is_w) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED, \ rwlock, is_w, 0, 0, 0) #endif /* __HELGRIND_H */ /** * Tell DRD that a reader lock has been acquired on a reader-writer * synchronization object. */ #define ANNOTATE_READERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 0) /** * Tell DRD that a writer lock has been acquired on a reader-writer * synchronization object. */ #define ANNOTATE_WRITERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 1) #ifndef __HELGRIND_H /** * Tell DRD that a reader-writer lock is about to be released. is_w == 1 means * that a write lock is about to be released, is_w == 0 means that a read lock * is about to be released. */ #define ANNOTATE_RWLOCK_RELEASED(rwlock, is_w) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED, \ rwlock, is_w, 0, 0, 0); #endif /* __HELGRIND_H */ /** * Tell DRD that a reader lock is about to be released. */ #define ANNOTATE_READERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 0) /** * Tell DRD that a writer lock is about to be released. */ #define ANNOTATE_WRITERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 1) /* * Report that a barrier has been initialized with a given barrier count. The * third argument specifies whether or not reinitialization is allowed, that * is, whether or not it is allowed to call barrier_init() several times * without calling barrier_destroy(). */ #define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \ "ANNOTATE_BARRIER_INIT", barrier, \ count, reinitialization_allowed, 0) /* Report that a barrier has been destroyed. */ #define ANNOTATE_BARRIER_DESTROY(barrier) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \ "ANNOTATE_BARRIER_DESTROY", \ barrier, 0, 0, 0) /* Report that the calling thread is about to start waiting for a barrier. */ #define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \ "ANNOTATE_BARRIER_WAIT_BEFORE", \ barrier, 0, 0, 0) /* Report that the calling thread has just finished waiting for a barrier. */ #define ANNOTATE_BARRIER_WAIT_AFTER(barrier) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \ "ANNOTATE_BARRIER_WAIT_AFTER", \ barrier, 0, 0, 0) /** * Tell DRD that a FIFO queue has been created. The abbreviation PCQ stands for * <em>producer-consumer</em>. */ #define ANNOTATE_PCQ_CREATE(pcq) do { } while(0) /** Tell DRD that a FIFO queue has been destroyed. */ #define ANNOTATE_PCQ_DESTROY(pcq) do { } while(0) /** * Tell DRD that an element has been added to the FIFO queue at address pcq. */ #define ANNOTATE_PCQ_PUT(pcq) do { } while(0) /** * Tell DRD that an element has been removed from the FIFO queue at address pcq, * and that DRD should insert a happens-before relationship between the memory * accesses that occurred before the corresponding ANNOTATE_PCQ_PUT(pcq) * annotation and the memory accesses after this annotation. Correspondence * between PUT and GET annotations happens in FIFO order. Since locking * of the queue is needed anyway to add elements to or to remove elements from * the queue, for DRD all four FIFO annotations are defined as no-ops. */ #define ANNOTATE_PCQ_GET(pcq) do { } while(0) /** * Tell DRD that data races at the specified address are expected and must not * be reported. */ #define ANNOTATE_BENIGN_RACE(addr, descr) \ ANNOTATE_BENIGN_RACE_SIZED(addr, sizeof(*addr), descr) /* Same as ANNOTATE_BENIGN_RACE(addr, descr), but applies to the memory range [addr, addr + size). */ #define ANNOTATE_BENIGN_RACE_SIZED(addr, size, descr) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_SUPPRESSION, \ addr, size, 0, 0, 0) /** Tell DRD to ignore all reads performed by the current thread. */ #define ANNOTATE_IGNORE_READS_BEGIN() \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_LOADS, \ 0, 0, 0, 0, 0); /** Tell DRD to no longer ignore the reads performed by the current thread. */ #define ANNOTATE_IGNORE_READS_END() \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_LOADS, \ 1, 0, 0, 0, 0); /** Tell DRD to ignore all writes performed by the current thread. */ #define ANNOTATE_IGNORE_WRITES_BEGIN() \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_STORES, \ 0, 0, 0, 0, 0) /** Tell DRD to no longer ignore the writes performed by the current thread. */ #define ANNOTATE_IGNORE_WRITES_END() \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_STORES, \ 1, 0, 0, 0, 0) /** Tell DRD to ignore all memory accesses performed by the current thread. */ #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ do { ANNOTATE_IGNORE_READS_BEGIN(); ANNOTATE_IGNORE_WRITES_BEGIN(); } while(0) /** * Tell DRD to no longer ignore the memory accesses performed by the current * thread. */ #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \ do { ANNOTATE_IGNORE_READS_END(); ANNOTATE_IGNORE_WRITES_END(); } while(0) /** * Tell DRD that size bytes starting at addr has been allocated by a custom * memory allocator. */ #define ANNOTATE_NEW_MEMORY(addr, size) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_CLEAN_MEMORY, \ addr, size, 0, 0, 0) /** Ask DRD to report every access to the specified address. */ #define ANNOTATE_TRACE_MEMORY(addr) DRD_TRACE_VAR(*(char*)(addr)) /** * Tell DRD to assign the specified name to the current thread. This name will * be used in error messages printed by DRD. */ #define ANNOTATE_THREAD_NAME(name) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_SET_THREAD_NAME, \ name, 0, 0, 0, 0) /*@}*/ /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! This enum comprises an ABI exported by Valgrind to programs which use client requests. DO NOT CHANGE THE ORDER OF THESE ENTRIES, NOR DELETE ANY -- add new ones at the end. */ enum { /* Ask the DRD tool to discard all information about memory accesses */ /* and client objects for the specified range. This client request is */ /* binary compatible with the similarly named Helgrind client request. */ VG_USERREQ__DRD_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'), /* args: Addr, SizeT. */ /* Ask the DRD tool the thread ID assigned by Valgrind. */ VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID = VG_USERREQ_TOOL_BASE('D','R'), /* args: none. */ /* Ask the DRD tool the thread ID assigned by DRD. */ VG_USERREQ__DRD_GET_DRD_THREAD_ID, /* args: none. */ /* To tell the DRD tool to suppress data race detection on the */ /* specified address range. */ VG_USERREQ__DRD_START_SUPPRESSION, /* args: start address, size in bytes */ /* To tell the DRD tool no longer to suppress data race detection on */ /* the specified address range. */ VG_USERREQ__DRD_FINISH_SUPPRESSION, /* args: start address, size in bytes */ /* To ask the DRD tool to trace all accesses to the specified range. */ VG_USERREQ__DRD_START_TRACE_ADDR, /* args: Addr, SizeT. */ /* To ask the DRD tool to stop tracing accesses to the specified range. */ VG_USERREQ__DRD_STOP_TRACE_ADDR, /* args: Addr, SizeT. */ /* Tell DRD whether or not to record memory loads in the calling thread. */ VG_USERREQ__DRD_RECORD_LOADS, /* args: Bool. */ /* Tell DRD whether or not to record memory stores in the calling thread. */ VG_USERREQ__DRD_RECORD_STORES, /* args: Bool. */ /* Set the name of the thread that performs this client request. */ VG_USERREQ__DRD_SET_THREAD_NAME, /* args: null-terminated character string. */ /* Tell DRD that a DRD annotation has not yet been implemented. */ VG_USERREQ__DRD_ANNOTATION_UNIMP, /* args: char*. */ /* Tell DRD that a user-defined reader-writer synchronization object * has been created. */ VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE = VG_USERREQ_TOOL_BASE('H','G') + 256 + 14, /* args: Addr. */ /* Tell DRD that a user-defined reader-writer synchronization object * is about to be destroyed. */ VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY = VG_USERREQ_TOOL_BASE('H','G') + 256 + 15, /* args: Addr. */ /* Tell DRD that a lock on a user-defined reader-writer synchronization * object has been acquired. */ VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED = VG_USERREQ_TOOL_BASE('H','G') + 256 + 17, /* args: Addr, Int is_rw. */ /* Tell DRD that a lock on a user-defined reader-writer synchronization * object is about to be released. */ VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED = VG_USERREQ_TOOL_BASE('H','G') + 256 + 18, /* args: Addr, Int is_rw. */ /* Tell DRD that a Helgrind annotation has not yet been implemented. */ VG_USERREQ__HELGRIND_ANNOTATION_UNIMP = VG_USERREQ_TOOL_BASE('H','G') + 256 + 32, /* args: char*. */ /* Tell DRD to insert a happens-before annotation. */ VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE = VG_USERREQ_TOOL_BASE('H','G') + 256 + 33, /* args: Addr. */ /* Tell DRD to insert a happens-after annotation. */ VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER = VG_USERREQ_TOOL_BASE('H','G') + 256 + 34, /* args: Addr. */ }; /** * @addtogroup RaceDetectionAnnotations */ /*@{*/ #ifdef __cplusplus /* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racy reads. Instead of doing ANNOTATE_IGNORE_READS_BEGIN(); ... = x; ANNOTATE_IGNORE_READS_END(); one can use ... = ANNOTATE_UNPROTECTED_READ(x); */ template <typename T> inline T ANNOTATE_UNPROTECTED_READ(const volatile T& x) { ANNOTATE_IGNORE_READS_BEGIN(); const T result = x; ANNOTATE_IGNORE_READS_END(); return result; } /* Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable. */ #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \ namespace { \ static class static_var##_annotator \ { \ public: \ static_var##_annotator() \ { \ ANNOTATE_BENIGN_RACE_SIZED(&static_var, sizeof(static_var), \ #static_var ": " description); \ } \ } the_##static_var##_annotator; \ } #endif /*@}*/ #endif /* __VALGRIND_DRD_H */
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/valgrind/memcheck.h
/* ---------------------------------------------------------------- Notice that the following BSD-style license applies to this one file (memcheck.h) only. The rest of Valgrind is licensed under the terms of the GNU General Public License, version 2, unless otherwise indicated. See the COPYING file in the source distribution for details. ---------------------------------------------------------------- This file is part of MemCheck, a heavyweight Valgrind tool for detecting memory errors. Copyright (C) 2000-2013 Julian Seward. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 3. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 4. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------- Notice that the above BSD-style license applies to this one file (memcheck.h) only. The entire rest of Valgrind is licensed under the terms of the GNU General Public License, version 2. See the COPYING file in the source distribution for details. ---------------------------------------------------------------- */ #ifndef __MEMCHECK_H #define __MEMCHECK_H /* This file is for inclusion into client (your!) code. You can use these macros to manipulate and query memory permissions inside your own programs. See comment near the top of valgrind.h on how to use them. */ #include "valgrind.h" /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! This enum comprises an ABI exported by Valgrind to programs which use client requests. DO NOT CHANGE THE ORDER OF THESE ENTRIES, NOR DELETE ANY -- add new ones at the end. */ typedef enum { VG_USERREQ__MAKE_MEM_NOACCESS = VG_USERREQ_TOOL_BASE('M','C'), VG_USERREQ__MAKE_MEM_UNDEFINED, VG_USERREQ__MAKE_MEM_DEFINED, VG_USERREQ__DISCARD, VG_USERREQ__CHECK_MEM_IS_ADDRESSABLE, VG_USERREQ__CHECK_MEM_IS_DEFINED, VG_USERREQ__DO_LEAK_CHECK, VG_USERREQ__COUNT_LEAKS, VG_USERREQ__GET_VBITS, VG_USERREQ__SET_VBITS, VG_USERREQ__CREATE_BLOCK, VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE, /* Not next to VG_USERREQ__COUNT_LEAKS because it was added later. */ VG_USERREQ__COUNT_LEAK_BLOCKS, /* This is just for memcheck's internal use - don't use it */ _VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR = VG_USERREQ_TOOL_BASE('M','C') + 256 } Vg_MemCheckClientRequest; /* Client-code macros to manipulate the state of memory. */ /* Mark memory at _qzz_addr as unaddressable for _qzz_len bytes. */ #define VALGRIND_MAKE_MEM_NOACCESS(_qzz_addr,_qzz_len) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__MAKE_MEM_NOACCESS, \ (_qzz_addr), (_qzz_len), 0, 0, 0) /* Similarly, mark memory at _qzz_addr as addressable but undefined for _qzz_len bytes. */ #define VALGRIND_MAKE_MEM_UNDEFINED(_qzz_addr,_qzz_len) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__MAKE_MEM_UNDEFINED, \ (_qzz_addr), (_qzz_len), 0, 0, 0) /* Similarly, mark memory at _qzz_addr as addressable and defined for _qzz_len bytes. */ #define VALGRIND_MAKE_MEM_DEFINED(_qzz_addr,_qzz_len) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__MAKE_MEM_DEFINED, \ (_qzz_addr), (_qzz_len), 0, 0, 0) /* Similar to VALGRIND_MAKE_MEM_DEFINED except that addressability is not altered: bytes which are addressable are marked as defined, but those which are not addressable are left unchanged. */ #define VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(_qzz_addr,_qzz_len) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE, \ (_qzz_addr), (_qzz_len), 0, 0, 0) /* Create a block-description handle. The description is an ascii string which is included in any messages pertaining to addresses within the specified memory range. Has no other effect on the properties of the memory range. */ #define VALGRIND_CREATE_BLOCK(_qzz_addr,_qzz_len, _qzz_desc) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__CREATE_BLOCK, \ (_qzz_addr), (_qzz_len), (_qzz_desc), \ 0, 0) /* Discard a block-description-handle. Returns 1 for an invalid handle, 0 for a valid handle. */ #define VALGRIND_DISCARD(_qzz_blkindex) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__DISCARD, \ 0, (_qzz_blkindex), 0, 0, 0) /* Client-code macros to check the state of memory. */ /* Check that memory at _qzz_addr is addressable for _qzz_len bytes. If suitable addressibility is not established, Valgrind prints an error message and returns the address of the first offending byte. Otherwise it returns zero. */ #define VALGRIND_CHECK_MEM_IS_ADDRESSABLE(_qzz_addr,_qzz_len) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__CHECK_MEM_IS_ADDRESSABLE, \ (_qzz_addr), (_qzz_len), 0, 0, 0) /* Check that memory at _qzz_addr is addressable and defined for _qzz_len bytes. If suitable addressibility and definedness are not established, Valgrind prints an error message and returns the address of the first offending byte. Otherwise it returns zero. */ #define VALGRIND_CHECK_MEM_IS_DEFINED(_qzz_addr,_qzz_len) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__CHECK_MEM_IS_DEFINED, \ (_qzz_addr), (_qzz_len), 0, 0, 0) /* Use this macro to force the definedness and addressibility of an lvalue to be checked. If suitable addressibility and definedness are not established, Valgrind prints an error message and returns the address of the first offending byte. Otherwise it returns zero. */ #define VALGRIND_CHECK_VALUE_IS_DEFINED(__lvalue) \ VALGRIND_CHECK_MEM_IS_DEFINED( \ (volatile unsigned char *)&(__lvalue), \ (unsigned long)(sizeof (__lvalue))) /* Do a full memory leak check (like --leak-check=full) mid-execution. */ #define VALGRIND_DO_LEAK_CHECK \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \ 0, 0, 0, 0, 0) /* Same as VALGRIND_DO_LEAK_CHECK but only showing the entries for which there was an increase in leaked bytes or leaked nr of blocks since the previous leak search. */ #define VALGRIND_DO_ADDED_LEAK_CHECK \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \ 0, 1, 0, 0, 0) /* Same as VALGRIND_DO_ADDED_LEAK_CHECK but showing entries with increased or decreased leaked bytes/blocks since previous leak search. */ #define VALGRIND_DO_CHANGED_LEAK_CHECK \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \ 0, 2, 0, 0, 0) /* Do a summary memory leak check (like --leak-check=summary) mid-execution. */ #define VALGRIND_DO_QUICK_LEAK_CHECK \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \ 1, 0, 0, 0, 0) /* Return number of leaked, dubious, reachable and suppressed bytes found by all previous leak checks. They must be lvalues. */ #define VALGRIND_COUNT_LEAKS(leaked, dubious, reachable, suppressed) \ /* For safety on 64-bit platforms we assign the results to private unsigned long variables, then assign these to the lvalues the user specified, which works no matter what type 'leaked', 'dubious', etc are. We also initialise '_qzz_leaked', etc because VG_USERREQ__COUNT_LEAKS doesn't mark the values returned as defined. */ \ { \ unsigned long _qzz_leaked = 0, _qzz_dubious = 0; \ unsigned long _qzz_reachable = 0, _qzz_suppressed = 0; \ VALGRIND_DO_CLIENT_REQUEST_STMT( \ VG_USERREQ__COUNT_LEAKS, \ &_qzz_leaked, &_qzz_dubious, \ &_qzz_reachable, &_qzz_suppressed, 0); \ leaked = _qzz_leaked; \ dubious = _qzz_dubious; \ reachable = _qzz_reachable; \ suppressed = _qzz_suppressed; \ } /* Return number of leaked, dubious, reachable and suppressed bytes found by all previous leak checks. They must be lvalues. */ #define VALGRIND_COUNT_LEAK_BLOCKS(leaked, dubious, reachable, suppressed) \ /* For safety on 64-bit platforms we assign the results to private unsigned long variables, then assign these to the lvalues the user specified, which works no matter what type 'leaked', 'dubious', etc are. We also initialise '_qzz_leaked', etc because VG_USERREQ__COUNT_LEAKS doesn't mark the values returned as defined. */ \ { \ unsigned long _qzz_leaked = 0, _qzz_dubious = 0; \ unsigned long _qzz_reachable = 0, _qzz_suppressed = 0; \ VALGRIND_DO_CLIENT_REQUEST_STMT( \ VG_USERREQ__COUNT_LEAK_BLOCKS, \ &_qzz_leaked, &_qzz_dubious, \ &_qzz_reachable, &_qzz_suppressed, 0); \ leaked = _qzz_leaked; \ dubious = _qzz_dubious; \ reachable = _qzz_reachable; \ suppressed = _qzz_suppressed; \ } /* Get the validity data for addresses [zza..zza+zznbytes-1] and copy it into the provided zzvbits array. Return values: 0 if not running on valgrind 1 success 2 [previously indicated unaligned arrays; these are now allowed] 3 if any parts of zzsrc/zzvbits are not addressable. The metadata is not copied in cases 0, 2 or 3 so it should be impossible to segfault your system by using this call. */ #define VALGRIND_GET_VBITS(zza,zzvbits,zznbytes) \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__GET_VBITS, \ (const char*)(zza), \ (char*)(zzvbits), \ (zznbytes), 0, 0) /* Set the validity data for addresses [zza..zza+zznbytes-1], copying it from the provided zzvbits array. Return values: 0 if not running on valgrind 1 success 2 [previously indicated unaligned arrays; these are now allowed] 3 if any parts of zza/zzvbits are not addressable. The metadata is not copied in cases 0, 2 or 3 so it should be impossible to segfault your system by using this call. */ #define VALGRIND_SET_VBITS(zza,zzvbits,zznbytes) \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__SET_VBITS, \ (const char*)(zza), \ (const char*)(zzvbits), \ (zznbytes), 0, 0 ) #endif
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/valgrind/valgrind.h
/* -*- c -*- ---------------------------------------------------------------- Notice that the following BSD-style license applies to this one file (valgrind.h) only. The rest of Valgrind is licensed under the terms of the GNU General Public License, version 2, unless otherwise indicated. See the COPYING file in the source distribution for details. ---------------------------------------------------------------- This file is part of Valgrind, a dynamic binary instrumentation framework. Copyright (C) 2000-2013 Julian Seward. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 3. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 4. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------- Notice that the above BSD-style license applies to this one file (valgrind.h) only. The entire rest of Valgrind is licensed under the terms of the GNU General Public License, version 2. See the COPYING file in the source distribution for details. ---------------------------------------------------------------- */ /* This file is for inclusion into client (your!) code. You can use these macros to manipulate and query Valgrind's execution inside your own programs. The resulting executables will still run without Valgrind, just a little bit more slowly than they otherwise would, but otherwise unchanged. When not running on valgrind, each client request consumes very few (eg. 7) instructions, so the resulting performance loss is negligible unless you plan to execute client requests millions of times per second. Nevertheless, if that is still a problem, you can compile with the NVALGRIND symbol defined (gcc -DNVALGRIND) so that client requests are not even compiled in. */ #ifndef __VALGRIND_H #define __VALGRIND_H /* ------------------------------------------------------------------ */ /* VERSION NUMBER OF VALGRIND */ /* ------------------------------------------------------------------ */ /* Specify Valgrind's version number, so that user code can conditionally compile based on our version number. Note that these were introduced at version 3.6 and so do not exist in version 3.5 or earlier. The recommended way to use them to check for "version X.Y or later" is (eg) #if defined(__VALGRIND_MAJOR__) && defined(__VALGRIND_MINOR__) \ && (__VALGRIND_MAJOR__ > 3 \ || (__VALGRIND_MAJOR__ == 3 && __VALGRIND_MINOR__ >= 6)) */ #define __VALGRIND_MAJOR__ 3 #define __VALGRIND_MINOR__ 8 #include <stdarg.h> /* Nb: this file might be included in a file compiled with -ansi. So we can't use C++ style "//" comments nor the "asm" keyword (instead use "__asm__"). */ /* Derive some tags indicating what the target platform is. Note that in this file we're using the compiler's CPP symbols for identifying architectures, which are different to the ones we use within the rest of Valgrind. Note, __powerpc__ is active for both 32 and 64-bit PPC, whereas __powerpc64__ is only active for the latter (on Linux, that is). Misc note: how to find out what's predefined in gcc by default: gcc -Wp,-dM somefile.c */ #undef PLAT_x86_darwin #undef PLAT_amd64_darwin #undef PLAT_x86_win32 #undef PLAT_amd64_win64 #undef PLAT_x86_linux #undef PLAT_amd64_linux #undef PLAT_ppc32_linux #undef PLAT_ppc64_linux #undef PLAT_arm_linux #undef PLAT_s390x_linux #undef PLAT_mips32_linux #undef PLAT_mips64_linux #if defined(__APPLE__) && defined(__i386__) # define PLAT_x86_darwin 1 #elif defined(__APPLE__) && defined(__x86_64__) # define PLAT_amd64_darwin 1 #elif defined(__MINGW32__) || defined(__CYGWIN32__) \ || (defined(_WIN32) && defined(_M_IX86)) # define PLAT_x86_win32 1 // ned: C2 clang dislikey the inline asm #ifdef __c2__ # define NVALGRIND 1 #endif #elif defined(__MINGW64__) || (defined(_WIN64) && defined(_M_X64)) # define PLAT_amd64_win64 1 // ned: Looks like PLAT_amd64_win64 isn't really implemented # define NVALGRIND 1 #elif defined(__linux__) && defined(__i386__) # define PLAT_x86_linux 1 #elif defined(__linux__) && defined(__x86_64__) # define PLAT_amd64_linux 1 #elif defined(__linux__) && defined(__powerpc__) && !defined(__powerpc64__) # define PLAT_ppc32_linux 1 #elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__) # define PLAT_ppc64_linux 1 #elif defined(__linux__) && defined(__arm__) # define PLAT_arm_linux 1 #elif defined(__linux__) && defined(__s390__) && defined(__s390x__) # define PLAT_s390x_linux 1 #elif defined(__linux__) && defined(__mips__) #if (__mips==64) # define PLAT_mips64_linux 1 #else # define PLAT_mips32_linux 1 #endif #else /* If we're not compiling for our target platform, don't generate any inline asms. */ # if !defined(NVALGRIND) # define NVALGRIND 1 # endif #endif /* ------------------------------------------------------------------ */ /* ARCHITECTURE SPECIFICS for SPECIAL INSTRUCTIONS. There is nothing */ /* in here of use to end-users -- skip to the next section. */ /* ------------------------------------------------------------------ */ /* * VALGRIND_DO_CLIENT_REQUEST(): a statement that invokes a Valgrind client * request. Accepts both pointers and integers as arguments. * * VALGRIND_DO_CLIENT_REQUEST_STMT(): a statement that invokes a Valgrind * client request that does not return a value. * VALGRIND_DO_CLIENT_REQUEST_EXPR(): a C expression that invokes a Valgrind * client request and whose value equals the client request result. Accepts * both pointers and integers as arguments. Note that such calls are not * necessarily pure functions -- they may have side effects. */ #define VALGRIND_DO_CLIENT_REQUEST(_zzq_rlval, _zzq_default, \ _zzq_request, _zzq_arg1, _zzq_arg2, \ _zzq_arg3, _zzq_arg4, _zzq_arg5) \ do { (_zzq_rlval) = VALGRIND_DO_CLIENT_REQUEST_EXPR((_zzq_default), \ (_zzq_request), (_zzq_arg1), (_zzq_arg2), \ (_zzq_arg3), (_zzq_arg4), (_zzq_arg5)); } while (0) #define VALGRIND_DO_CLIENT_REQUEST_STMT(_zzq_request, _zzq_arg1, \ _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ do { (void) VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ (_zzq_request), (_zzq_arg1), (_zzq_arg2), \ (_zzq_arg3), (_zzq_arg4), (_zzq_arg5)); } while (0) #if defined(NVALGRIND) /* Define NVALGRIND to completely remove the Valgrind magic sequence from the compiled code (analogous to NDEBUG's effects on assert()) */ #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ (_zzq_default) #else /* ! NVALGRIND */ /* The following defines the magic code sequences which the JITter spots and handles magically. Don't look too closely at them as they will rot your brain. The assembly code sequences for all architectures is in this one file. This is because this file must be stand-alone, and we don't want to have multiple files. For VALGRIND_DO_CLIENT_REQUEST, we must ensure that the default value gets put in the return slot, so that everything works when this is executed not under Valgrind. Args are passed in a memory block, and so there's no intrinsic limit to the number that could be passed, but it's currently five. The macro args are: _zzq_rlval result lvalue _zzq_default default value (result returned when running on real CPU) _zzq_request request code _zzq_arg1..5 request params The other two macros are used to support function wrapping, and are a lot simpler. VALGRIND_GET_NR_CONTEXT returns the value of the guest's NRADDR pseudo-register and whatever other information is needed to safely run the call original from the wrapper: on ppc64-linux, the R2 value at the divert point is also needed. This information is abstracted into a user-visible type, OrigFn. VALGRIND_CALL_NOREDIR_* behaves the same as the following on the guest, but guarantees that the branch instruction will not be redirected: x86: call *%eax, amd64: call *%rax, ppc32/ppc64: branch-and-link-to-r11. VALGRIND_CALL_NOREDIR is just text, not a complete inline asm, since it needs to be combined with more magic inline asm stuff to be useful. */ /* ------------------------- x86-{linux,darwin} ---------------- */ #if defined(PLAT_x86_linux) || defined(PLAT_x86_darwin) \ || (defined(PLAT_x86_win32) && defined(__GNUC__)) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "roll $3, %%edi ; roll $13, %%edi\n\t" \ "roll $29, %%edi ; roll $19, %%edi\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({volatile unsigned int _zzq_args[6]; \ volatile unsigned int _zzq_result; \ _zzq_args[0] = (unsigned int)(_zzq_request); \ _zzq_args[1] = (unsigned int)(_zzq_arg1); \ _zzq_args[2] = (unsigned int)(_zzq_arg2); \ _zzq_args[3] = (unsigned int)(_zzq_arg3); \ _zzq_args[4] = (unsigned int)(_zzq_arg4); \ _zzq_args[5] = (unsigned int)(_zzq_arg5); \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %EDX = client_request ( %EAX ) */ \ "xchgl %%ebx,%%ebx" \ : "=d" (_zzq_result) \ : "a" (&_zzq_args[0]), "0" (_zzq_default) \ : "cc", "memory" \ ); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %EAX = guest_NRADDR */ \ "xchgl %%ecx,%%ecx" \ : "=a" (__addr) \ : \ : "cc", "memory" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_EAX \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* call-noredir *%EAX */ \ "xchgl %%edx,%%edx\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "xchgl %%edi,%%edi\n\t" \ : : : "cc", "memory" \ ); \ } while (0) #endif /* PLAT_x86_linux || PLAT_x86_darwin || (PLAT_x86_win32 && __GNUC__) */ /* ------------------------- x86-Win32 ------------------------- */ #if defined(PLAT_x86_win32) && !defined(__GNUC__) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; #if defined(_MSC_VER) #define __SPECIAL_INSTRUCTION_PREAMBLE \ __asm rol edi, 3 __asm rol edi, 13 \ __asm rol edi, 29 __asm rol edi, 19 #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ valgrind_do_client_request_expr((uintptr_t)(_zzq_default), \ (uintptr_t)(_zzq_request), (uintptr_t)(_zzq_arg1), \ (uintptr_t)(_zzq_arg2), (uintptr_t)(_zzq_arg3), \ (uintptr_t)(_zzq_arg4), (uintptr_t)(_zzq_arg5)) static __inline uintptr_t valgrind_do_client_request_expr(uintptr_t _zzq_default, uintptr_t _zzq_request, uintptr_t _zzq_arg1, uintptr_t _zzq_arg2, uintptr_t _zzq_arg3, uintptr_t _zzq_arg4, uintptr_t _zzq_arg5) { volatile uintptr_t _zzq_args[6]; volatile unsigned int _zzq_result; _zzq_args[0] = (uintptr_t)(_zzq_request); _zzq_args[1] = (uintptr_t)(_zzq_arg1); _zzq_args[2] = (uintptr_t)(_zzq_arg2); _zzq_args[3] = (uintptr_t)(_zzq_arg3); _zzq_args[4] = (uintptr_t)(_zzq_arg4); _zzq_args[5] = (uintptr_t)(_zzq_arg5); __asm { __asm lea eax, _zzq_args __asm mov edx, _zzq_default __SPECIAL_INSTRUCTION_PREAMBLE /* %EDX = client_request ( %EAX ) */ __asm xchg ebx,ebx __asm mov _zzq_result, edx } return _zzq_result; } #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned int __addr; \ __asm { __SPECIAL_INSTRUCTION_PREAMBLE \ /* %EAX = guest_NRADDR */ \ __asm xchg ecx,ecx \ __asm mov __addr, eax \ } \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_EAX ERROR #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm { __SPECIAL_INSTRUCTION_PREAMBLE \ __asm xchg edi,edi \ } \ } while (0) #else #error Unsupported compiler. #endif #endif /* PLAT_x86_win32 */ /* ------------------------ amd64-{linux,darwin} --------------- */ #if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) typedef struct { unsigned long long int nraddr; /* where's the code? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \ "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({ volatile unsigned long long int _zzq_args[6]; \ volatile unsigned long long int _zzq_result; \ _zzq_args[0] = (unsigned long long int)(_zzq_request); \ _zzq_args[1] = (unsigned long long int)(_zzq_arg1); \ _zzq_args[2] = (unsigned long long int)(_zzq_arg2); \ _zzq_args[3] = (unsigned long long int)(_zzq_arg3); \ _zzq_args[4] = (unsigned long long int)(_zzq_arg4); \ _zzq_args[5] = (unsigned long long int)(_zzq_arg5); \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %RDX = client_request ( %RAX ) */ \ "xchgq %%rbx,%%rbx" \ : "=d" (_zzq_result) \ : "a" (&_zzq_args[0]), "0" (_zzq_default) \ : "cc", "memory" \ ); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned long long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %RAX = guest_NRADDR */ \ "xchgq %%rcx,%%rcx" \ : "=a" (__addr) \ : \ : "cc", "memory" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_RAX \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* call-noredir *%RAX */ \ "xchgq %%rdx,%%rdx\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "xchgq %%rdi,%%rdi\n\t" \ : : : "cc", "memory" \ ); \ } while (0) #endif /* PLAT_amd64_linux || PLAT_amd64_darwin */ /* ------------------------ ppc32-linux ------------------------ */ #if defined(PLAT_ppc32_linux) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "rlwinm 0,0,3,0,0 ; rlwinm 0,0,13,0,0\n\t" \ "rlwinm 0,0,29,0,0 ; rlwinm 0,0,19,0,0\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ \ __extension__ \ ({ unsigned int _zzq_args[6]; \ unsigned int _zzq_result; \ unsigned int* _zzq_ptr; \ _zzq_args[0] = (unsigned int)(_zzq_request); \ _zzq_args[1] = (unsigned int)(_zzq_arg1); \ _zzq_args[2] = (unsigned int)(_zzq_arg2); \ _zzq_args[3] = (unsigned int)(_zzq_arg3); \ _zzq_args[4] = (unsigned int)(_zzq_arg4); \ _zzq_args[5] = (unsigned int)(_zzq_arg5); \ _zzq_ptr = _zzq_args; \ __asm__ volatile("mr 3,%1\n\t" /*default*/ \ "mr 4,%2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = client_request ( %R4 ) */ \ "or 1,1,1\n\t" \ "mr %0,3" /*result*/ \ : "=b" (_zzq_result) \ : "b" (_zzq_default), "b" (_zzq_ptr) \ : "cc", "memory", "r3", "r4"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ unsigned int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = guest_NRADDR */ \ "or 2,2,2\n\t" \ "mr %0,3" \ : "=b" (__addr) \ : \ : "cc", "memory", "r3" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* branch-and-link-to-noredir *%R11 */ \ "or 3,3,3\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "or 5,5,5\n\t" \ ); \ } while (0) #endif /* PLAT_ppc32_linux */ /* ------------------------ ppc64-linux ------------------------ */ #if defined(PLAT_ppc64_linux) typedef struct { unsigned long long int nraddr; /* where's the code? */ unsigned long long int r2; /* what tocptr do we need? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "rotldi 0,0,3 ; rotldi 0,0,13\n\t" \ "rotldi 0,0,61 ; rotldi 0,0,51\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ \ __extension__ \ ({ unsigned long long int _zzq_args[6]; \ unsigned long long int _zzq_result; \ unsigned long long int* _zzq_ptr; \ _zzq_args[0] = (unsigned long long int)(_zzq_request); \ _zzq_args[1] = (unsigned long long int)(_zzq_arg1); \ _zzq_args[2] = (unsigned long long int)(_zzq_arg2); \ _zzq_args[3] = (unsigned long long int)(_zzq_arg3); \ _zzq_args[4] = (unsigned long long int)(_zzq_arg4); \ _zzq_args[5] = (unsigned long long int)(_zzq_arg5); \ _zzq_ptr = _zzq_args; \ __asm__ volatile("mr 3,%1\n\t" /*default*/ \ "mr 4,%2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = client_request ( %R4 ) */ \ "or 1,1,1\n\t" \ "mr %0,3" /*result*/ \ : "=b" (_zzq_result) \ : "b" (_zzq_default), "b" (_zzq_ptr) \ : "cc", "memory", "r3", "r4"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ unsigned long long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = guest_NRADDR */ \ "or 2,2,2\n\t" \ "mr %0,3" \ : "=b" (__addr) \ : \ : "cc", "memory", "r3" \ ); \ _zzq_orig->nraddr = __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = guest_NRADDR_GPR2 */ \ "or 4,4,4\n\t" \ "mr %0,3" \ : "=b" (__addr) \ : \ : "cc", "memory", "r3" \ ); \ _zzq_orig->r2 = __addr; \ } #define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* branch-and-link-to-noredir *%R11 */ \ "or 3,3,3\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "or 5,5,5\n\t" \ ); \ } while (0) #endif /* PLAT_ppc64_linux */ /* ------------------------- arm-linux ------------------------- */ #if defined(PLAT_arm_linux) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "mov r12, r12, ror #3 ; mov r12, r12, ror #13 \n\t" \ "mov r12, r12, ror #29 ; mov r12, r12, ror #19 \n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ \ __extension__ \ ({volatile unsigned int _zzq_args[6]; \ volatile unsigned int _zzq_result; \ _zzq_args[0] = (unsigned int)(_zzq_request); \ _zzq_args[1] = (unsigned int)(_zzq_arg1); \ _zzq_args[2] = (unsigned int)(_zzq_arg2); \ _zzq_args[3] = (unsigned int)(_zzq_arg3); \ _zzq_args[4] = (unsigned int)(_zzq_arg4); \ _zzq_args[5] = (unsigned int)(_zzq_arg5); \ __asm__ volatile("mov r3, %1\n\t" /*default*/ \ "mov r4, %2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* R3 = client_request ( R4 ) */ \ "orr r10, r10, r10\n\t" \ "mov %0, r3" /*result*/ \ : "=r" (_zzq_result) \ : "r" (_zzq_default), "r" (&_zzq_args[0]) \ : "cc","memory", "r3", "r4"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ unsigned int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* R3 = guest_NRADDR */ \ "orr r11, r11, r11\n\t" \ "mov %0, r3" \ : "=r" (__addr) \ : \ : "cc", "memory", "r3" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* branch-and-link-to-noredir *%R4 */ \ "orr r12, r12, r12\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "orr r9, r9, r9\n\t" \ : : : "cc", "memory" \ ); \ } while (0) #endif /* PLAT_arm_linux */ /* ------------------------ s390x-linux ------------------------ */ #if defined(PLAT_s390x_linux) typedef struct { unsigned long long int nraddr; /* where's the code? */ } OrigFn; /* __SPECIAL_INSTRUCTION_PREAMBLE will be used to identify Valgrind specific * code. This detection is implemented in platform specific toIR.c * (e.g. VEX/priv/guest_s390_decoder.c). */ #define __SPECIAL_INSTRUCTION_PREAMBLE \ "lr 15,15\n\t" \ "lr 1,1\n\t" \ "lr 2,2\n\t" \ "lr 3,3\n\t" #define __CLIENT_REQUEST_CODE "lr 2,2\n\t" #define __GET_NR_CONTEXT_CODE "lr 3,3\n\t" #define __CALL_NO_REDIR_CODE "lr 4,4\n\t" #define __VEX_INJECT_IR_CODE "lr 5,5\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({volatile unsigned long long int _zzq_args[6]; \ volatile unsigned long long int _zzq_result; \ _zzq_args[0] = (unsigned long long int)(_zzq_request); \ _zzq_args[1] = (unsigned long long int)(_zzq_arg1); \ _zzq_args[2] = (unsigned long long int)(_zzq_arg2); \ _zzq_args[3] = (unsigned long long int)(_zzq_arg3); \ _zzq_args[4] = (unsigned long long int)(_zzq_arg4); \ _zzq_args[5] = (unsigned long long int)(_zzq_arg5); \ __asm__ volatile(/* r2 = args */ \ "lgr 2,%1\n\t" \ /* r3 = default */ \ "lgr 3,%2\n\t" \ __SPECIAL_INSTRUCTION_PREAMBLE \ __CLIENT_REQUEST_CODE \ /* results = r3 */ \ "lgr %0, 3\n\t" \ : "=d" (_zzq_result) \ : "a" (&_zzq_args[0]), "0" (_zzq_default) \ : "cc", "2", "3", "memory" \ ); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned long long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ __GET_NR_CONTEXT_CODE \ "lgr %0, 3\n\t" \ : "=a" (__addr) \ : \ : "cc", "3", "memory" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_R1 \ __SPECIAL_INSTRUCTION_PREAMBLE \ __CALL_NO_REDIR_CODE #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ __VEX_INJECT_IR_CODE); \ } while (0) #endif /* PLAT_s390x_linux */ /* ------------------------- mips32-linux ---------------- */ #if defined(PLAT_mips32_linux) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; /* .word 0x342 * .word 0x742 * .word 0xC2 * .word 0x4C2*/ #define __SPECIAL_INSTRUCTION_PREAMBLE \ "srl $0, $0, 13\n\t" \ "srl $0, $0, 29\n\t" \ "srl $0, $0, 3\n\t" \ "srl $0, $0, 19\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({ volatile unsigned int _zzq_args[6]; \ volatile unsigned int _zzq_result; \ _zzq_args[0] = (unsigned int)(_zzq_request); \ _zzq_args[1] = (unsigned int)(_zzq_arg1); \ _zzq_args[2] = (unsigned int)(_zzq_arg2); \ _zzq_args[3] = (unsigned int)(_zzq_arg3); \ _zzq_args[4] = (unsigned int)(_zzq_arg4); \ _zzq_args[5] = (unsigned int)(_zzq_arg5); \ __asm__ volatile("move $11, %1\n\t" /*default*/ \ "move $12, %2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* T3 = client_request ( T4 ) */ \ "or $13, $13, $13\n\t" \ "move %0, $11\n\t" /*result*/ \ : "=r" (_zzq_result) \ : "r" (_zzq_default), "r" (&_zzq_args[0]) \ : "$11", "$12"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %t9 = guest_NRADDR */ \ "or $14, $14, $14\n\t" \ "move %0, $11" /*result*/ \ : "=r" (__addr) \ : \ : "$11" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_T9 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* call-noredir *%t9 */ \ "or $15, $15, $15\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "or $11, $11, $11\n\t" \ ); \ } while (0) #endif /* PLAT_mips32_linux */ /* ------------------------- mips64-linux ---------------- */ #if defined(PLAT_mips64_linux) typedef struct { unsigned long long nraddr; /* where's the code? */ } OrigFn; /* dsll $0,$0, 3 * dsll $0,$0, 13 * dsll $0,$0, 29 * dsll $0,$0, 19*/ #define __SPECIAL_INSTRUCTION_PREAMBLE \ "dsll $0,$0, 3 ; dsll $0,$0,13\n\t" \ "dsll $0,$0,29 ; dsll $0,$0,19\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({ volatile unsigned long long int _zzq_args[6]; \ volatile unsigned long long int _zzq_result; \ _zzq_args[0] = (unsigned long long int)(_zzq_request); \ _zzq_args[1] = (unsigned long long int)(_zzq_arg1); \ _zzq_args[2] = (unsigned long long int)(_zzq_arg2); \ _zzq_args[3] = (unsigned long long int)(_zzq_arg3); \ _zzq_args[4] = (unsigned long long int)(_zzq_arg4); \ _zzq_args[5] = (unsigned long long int)(_zzq_arg5); \ __asm__ volatile("move $11, %1\n\t" /*default*/ \ "move $12, %2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* $11 = client_request ( $12 ) */ \ "or $13, $13, $13\n\t" \ "move %0, $11\n\t" /*result*/ \ : "=r" (_zzq_result) \ : "r" (_zzq_default), "r" (&_zzq_args[0]) \ : "$11", "$12"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned long long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* $11 = guest_NRADDR */ \ "or $14, $14, $14\n\t" \ "move %0, $11" /*result*/ \ : "=r" (__addr) \ : \ : "$11"); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_T9 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* call-noredir $25 */ \ "or $15, $15, $15\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "or $11, $11, $11\n\t" \ ); \ } while (0) #endif /* PLAT_mips64_linux */ /* Insert assembly code for other platforms here... */ #endif /* NVALGRIND */ /* ------------------------------------------------------------------ */ /* PLATFORM SPECIFICS for FUNCTION WRAPPING. This is all very */ /* ugly. It's the least-worst tradeoff I can think of. */ /* ------------------------------------------------------------------ */ /* This section defines magic (a.k.a appalling-hack) macros for doing guaranteed-no-redirection macros, so as to get from function wrappers to the functions they are wrapping. The whole point is to construct standard call sequences, but to do the call itself with a special no-redirect call pseudo-instruction that the JIT understands and handles specially. This section is long and repetitious, and I can't see a way to make it shorter. The naming scheme is as follows: CALL_FN_{W,v}_{v,W,WW,WWW,WWWW,5W,6W,7W,etc} 'W' stands for "word" and 'v' for "void". Hence there are different macros for calling arity 0, 1, 2, 3, 4, etc, functions, and for each, the possibility of returning a word-typed result, or no result. */ /* Use these to write the name of your wrapper. NOTE: duplicates VG_WRAP_FUNCTION_Z{U,Z} in pub_tool_redir.h. NOTE also: inserts the default behaviour equivalance class tag "0000" into the name. See pub_tool_redir.h for details -- normally you don't need to think about this, though. */ /* Use an extra level of macroisation so as to ensure the soname/fnname args are fully macro-expanded before pasting them together. */ #define VG_CONCAT4(_aa,_bb,_cc,_dd) _aa##_bb##_cc##_dd #define I_WRAP_SONAME_FNNAME_ZU(soname,fnname) \ VG_CONCAT4(_vgw00000ZU_,soname,_,fnname) #define I_WRAP_SONAME_FNNAME_ZZ(soname,fnname) \ VG_CONCAT4(_vgw00000ZZ_,soname,_,fnname) /* Use this macro from within a wrapper function to collect the context (address and possibly other info) of the original function. Once you have that you can then use it in one of the CALL_FN_ macros. The type of the argument _lval is OrigFn. */ #define VALGRIND_GET_ORIG_FN(_lval) VALGRIND_GET_NR_CONTEXT(_lval) /* Also provide end-user facilities for function replacement, rather than wrapping. A replacement function differs from a wrapper in that it has no way to get hold of the original function being called, and hence no way to call onwards to it. In a replacement function, VALGRIND_GET_ORIG_FN always returns zero. */ #define I_REPLACE_SONAME_FNNAME_ZU(soname,fnname) \ VG_CONCAT4(_vgr00000ZU_,soname,_,fnname) #define I_REPLACE_SONAME_FNNAME_ZZ(soname,fnname) \ VG_CONCAT4(_vgr00000ZZ_,soname,_,fnname) /* Derivatives of the main macros below, for calling functions returning void. */ #define CALL_FN_v_v(fnptr) \ do { volatile unsigned long _junk; \ CALL_FN_W_v(_junk,fnptr); } while (0) #define CALL_FN_v_W(fnptr, arg1) \ do { volatile unsigned long _junk; \ CALL_FN_W_W(_junk,fnptr,arg1); } while (0) #define CALL_FN_v_WW(fnptr, arg1,arg2) \ do { volatile unsigned long _junk; \ CALL_FN_W_WW(_junk,fnptr,arg1,arg2); } while (0) #define CALL_FN_v_WWW(fnptr, arg1,arg2,arg3) \ do { volatile unsigned long _junk; \ CALL_FN_W_WWW(_junk,fnptr,arg1,arg2,arg3); } while (0) #define CALL_FN_v_WWWW(fnptr, arg1,arg2,arg3,arg4) \ do { volatile unsigned long _junk; \ CALL_FN_W_WWWW(_junk,fnptr,arg1,arg2,arg3,arg4); } while (0) #define CALL_FN_v_5W(fnptr, arg1,arg2,arg3,arg4,arg5) \ do { volatile unsigned long _junk; \ CALL_FN_W_5W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5); } while (0) #define CALL_FN_v_6W(fnptr, arg1,arg2,arg3,arg4,arg5,arg6) \ do { volatile unsigned long _junk; \ CALL_FN_W_6W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5,arg6); } while (0) #define CALL_FN_v_7W(fnptr, arg1,arg2,arg3,arg4,arg5,arg6,arg7) \ do { volatile unsigned long _junk; \ CALL_FN_W_7W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5,arg6,arg7); } while (0) /* ------------------------- x86-{linux,darwin} ---------------- */ #if defined(PLAT_x86_linux) || defined(PLAT_x86_darwin) /* These regs are trashed by the hidden call. No need to mention eax as gcc can already see that, plus causes gcc to bomb. */ #define __CALLER_SAVED_REGS /*"eax"*/ "ecx", "edx" /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ #define VALGRIND_ALIGN_STACK \ "movl %%esp,%%edi\n\t" \ "andl $0xfffffff0,%%esp\n\t" #define VALGRIND_RESTORE_STACK \ "movl %%edi,%%esp\n\t" /* These CALL_FN_ macros assume that on x86-linux, sizeof(unsigned long) == 4. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $12, %%esp\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $8, %%esp\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $4, %%esp\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $12, %%esp\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $8, %%esp\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $4, %%esp\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "pushl 32(%%eax)\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $12, %%esp\n\t" \ "pushl 36(%%eax)\n\t" \ "pushl 32(%%eax)\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $8, %%esp\n\t" \ "pushl 40(%%eax)\n\t" \ "pushl 36(%%eax)\n\t" \ "pushl 32(%%eax)\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $4, %%esp\n\t" \ "pushl 44(%%eax)\n\t" \ "pushl 40(%%eax)\n\t" \ "pushl 36(%%eax)\n\t" \ "pushl 32(%%eax)\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "pushl 48(%%eax)\n\t" \ "pushl 44(%%eax)\n\t" \ "pushl 40(%%eax)\n\t" \ "pushl 36(%%eax)\n\t" \ "pushl 32(%%eax)\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_x86_linux || PLAT_x86_darwin */ /* ------------------------ amd64-{linux,darwin} --------------- */ #if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) /* ARGREGS: rdi rsi rdx rcx r8 r9 (the rest on stack in R-to-L order) */ /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS /*"rax",*/ "rcx", "rdx", "rsi", \ "rdi", "r8", "r9", "r10", "r11" /* This is all pretty complex. It's so as to make stack unwinding work reliably. See bug 243270. The basic problem is the sub and add of 128 of %rsp in all of the following macros. If gcc believes the CFA is in %rsp, then unwinding may fail, because what's at the CFA is not what gcc "expected" when it constructs the CFIs for the places where the macros are instantiated. But we can't just add a CFI annotation to increase the CFA offset by 128, to match the sub of 128 from %rsp, because we don't know whether gcc has chosen %rsp as the CFA at that point, or whether it has chosen some other register (eg, %rbp). In the latter case, adding a CFI annotation to change the CFA offset is simply wrong. So the solution is to get hold of the CFA using __builtin_dwarf_cfa(), put it in a known register, and add a CFI annotation to say what the register is. We choose %rbp for this (perhaps perversely), because: (1) %rbp is already subject to unwinding. If a new register was chosen then the unwinder would have to unwind it in all stack traces, which is expensive, and (2) %rbp is already subject to precise exception updates in the JIT. If a new register was chosen, we'd have to have precise exceptions for it too, which reduces performance of the generated code. However .. one extra complication. We can't just whack the result of __builtin_dwarf_cfa() into %rbp and then add %rbp to the list of trashed registers at the end of the inline assembly fragments; gcc won't allow %rbp to appear in that list. Hence instead we need to stash %rbp in %r15 for the duration of the asm, and say that %r15 is trashed instead. gcc seems happy to go with that. Oh .. and this all needs to be conditionalised so that it is unchanged from before this commit, when compiled with older gccs that don't support __builtin_dwarf_cfa. Furthermore, since this header file is freestanding, it has to be independent of config.h, and so the following conditionalisation cannot depend on configure time checks. Although it's not clear from 'defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)', this expression excludes Darwin. .cfi directives in Darwin assembly appear to be completely different and I haven't investigated how they work. For even more entertainment value, note we have to use the completely undocumented __builtin_dwarf_cfa(), which appears to really compute the CFA, whereas __builtin_frame_address(0) claims to but actually doesn't. See https://bugs.kde.org/show_bug.cgi?id=243270#c47 */ #if defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM) # define __FRAME_POINTER \ ,"r"(__builtin_dwarf_cfa()) # define VALGRIND_CFI_PROLOGUE \ "movq %%rbp, %%r15\n\t" \ "movq %2, %%rbp\n\t" \ ".cfi_remember_state\n\t" \ ".cfi_def_cfa rbp, 0\n\t" # define VALGRIND_CFI_EPILOGUE \ "movq %%r15, %%rbp\n\t" \ ".cfi_restore_state\n\t" #else # define __FRAME_POINTER # define VALGRIND_CFI_PROLOGUE # define VALGRIND_CFI_EPILOGUE #endif /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ #define VALGRIND_ALIGN_STACK \ "movq %%rsp,%%r14\n\t" \ "andq $0xfffffffffffffff0,%%rsp\n\t" #define VALGRIND_RESTORE_STACK \ "movq %%r14,%%rsp\n\t" /* These CALL_FN_ macros assume that on amd64-linux, sizeof(unsigned long) == 8. */ /* NB 9 Sept 07. There is a nasty kludge here in all these CALL_FN_ macros. In order not to trash the stack redzone, we need to drop %rsp by 128 before the hidden call, and restore afterwards. The nastyness is that it is only by luck that the stack still appears to be unwindable during the hidden call - since then the behaviour of any routine using this macro does not match what the CFI data says. Sigh. Why is this important? Imagine that a wrapper has a stack allocated local, and passes to the hidden call, a pointer to it. Because gcc does not know about the hidden call, it may allocate that local in the redzone. Unfortunately the hidden call may then trash it before it comes to use it. So we must step clear of the redzone, for the duration of the hidden call, to make it safe. Probably the same problem afflicts the other redzone-style ABIs too (ppc64-linux); but for those, the stack is self describing (none of this CFI nonsense) so at least messing with the stack pointer doesn't give a danger of non-unwindable stack. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $136,%%rsp\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "pushq 64(%%rax)\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $136,%%rsp\n\t" \ "pushq 72(%%rax)\n\t" \ "pushq 64(%%rax)\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "pushq 80(%%rax)\n\t" \ "pushq 72(%%rax)\n\t" \ "pushq 64(%%rax)\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $136,%%rsp\n\t" \ "pushq 88(%%rax)\n\t" \ "pushq 80(%%rax)\n\t" \ "pushq 72(%%rax)\n\t" \ "pushq 64(%%rax)\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "pushq 96(%%rax)\n\t" \ "pushq 88(%%rax)\n\t" \ "pushq 80(%%rax)\n\t" \ "pushq 72(%%rax)\n\t" \ "pushq 64(%%rax)\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_amd64_linux || PLAT_amd64_darwin */ /* ------------------------ ppc32-linux ------------------------ */ #if defined(PLAT_ppc32_linux) /* This is useful for finding out about the on-stack stuff: extern int f9 ( int,int,int,int,int,int,int,int,int ); extern int f10 ( int,int,int,int,int,int,int,int,int,int ); extern int f11 ( int,int,int,int,int,int,int,int,int,int,int ); extern int f12 ( int,int,int,int,int,int,int,int,int,int,int,int ); int g9 ( void ) { return f9(11,22,33,44,55,66,77,88,99); } int g10 ( void ) { return f10(11,22,33,44,55,66,77,88,99,110); } int g11 ( void ) { return f11(11,22,33,44,55,66,77,88,99,110,121); } int g12 ( void ) { return f12(11,22,33,44,55,66,77,88,99,110,121,132); } */ /* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */ /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS \ "lr", "ctr", "xer", \ "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \ "r0", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \ "r11", "r12", "r13" /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ #define VALGRIND_ALIGN_STACK \ "mr 28,1\n\t" \ "rlwinm 1,1,0,0,27\n\t" #define VALGRIND_RESTORE_STACK \ "mr 1,28\n\t" /* These CALL_FN_ macros assume that on ppc32-linux, sizeof(unsigned long) == 4. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 10,32(11)\n\t" /* arg8->r10 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "addi 1,1,-16\n\t" \ /* arg9 */ \ "lwz 3,36(11)\n\t" \ "stw 3,8(1)\n\t" \ /* args1-8 */ \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 10,32(11)\n\t" /* arg8->r10 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "addi 1,1,-16\n\t" \ /* arg10 */ \ "lwz 3,40(11)\n\t" \ "stw 3,12(1)\n\t" \ /* arg9 */ \ "lwz 3,36(11)\n\t" \ "stw 3,8(1)\n\t" \ /* args1-8 */ \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 10,32(11)\n\t" /* arg8->r10 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ _argvec[11] = (unsigned long)arg11; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "addi 1,1,-32\n\t" \ /* arg11 */ \ "lwz 3,44(11)\n\t" \ "stw 3,16(1)\n\t" \ /* arg10 */ \ "lwz 3,40(11)\n\t" \ "stw 3,12(1)\n\t" \ /* arg9 */ \ "lwz 3,36(11)\n\t" \ "stw 3,8(1)\n\t" \ /* args1-8 */ \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 10,32(11)\n\t" /* arg8->r10 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ _argvec[11] = (unsigned long)arg11; \ _argvec[12] = (unsigned long)arg12; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "addi 1,1,-32\n\t" \ /* arg12 */ \ "lwz 3,48(11)\n\t" \ "stw 3,20(1)\n\t" \ /* arg11 */ \ "lwz 3,44(11)\n\t" \ "stw 3,16(1)\n\t" \ /* arg10 */ \ "lwz 3,40(11)\n\t" \ "stw 3,12(1)\n\t" \ /* arg9 */ \ "lwz 3,36(11)\n\t" \ "stw 3,8(1)\n\t" \ /* args1-8 */ \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 10,32(11)\n\t" /* arg8->r10 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_ppc32_linux */ /* ------------------------ ppc64-linux ------------------------ */ #if defined(PLAT_ppc64_linux) /* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */ /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS \ "lr", "ctr", "xer", \ "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \ "r0", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \ "r11", "r12", "r13" /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ #define VALGRIND_ALIGN_STACK \ "mr 28,1\n\t" \ "rldicr 1,1,0,59\n\t" #define VALGRIND_RESTORE_STACK \ "mr 1,28\n\t" /* These CALL_FN_ macros assume that on ppc64-linux, sizeof(unsigned long) == 8. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+0]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+1]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+2]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+3]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+4]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+5]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+6]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+7]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+8]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 10, 64(11)\n\t" /* arg8->r10 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+9]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-128\n\t" /* expand stack frame */ \ /* arg9 */ \ "ld 3,72(11)\n\t" \ "std 3,112(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 10, 64(11)\n\t" /* arg8->r10 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+10]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ _argvec[2+10] = (unsigned long)arg10; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-128\n\t" /* expand stack frame */ \ /* arg10 */ \ "ld 3,80(11)\n\t" \ "std 3,120(1)\n\t" \ /* arg9 */ \ "ld 3,72(11)\n\t" \ "std 3,112(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 10, 64(11)\n\t" /* arg8->r10 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+11]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ _argvec[2+10] = (unsigned long)arg10; \ _argvec[2+11] = (unsigned long)arg11; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-144\n\t" /* expand stack frame */ \ /* arg11 */ \ "ld 3,88(11)\n\t" \ "std 3,128(1)\n\t" \ /* arg10 */ \ "ld 3,80(11)\n\t" \ "std 3,120(1)\n\t" \ /* arg9 */ \ "ld 3,72(11)\n\t" \ "std 3,112(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 10, 64(11)\n\t" /* arg8->r10 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+12]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ _argvec[2+10] = (unsigned long)arg10; \ _argvec[2+11] = (unsigned long)arg11; \ _argvec[2+12] = (unsigned long)arg12; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-144\n\t" /* expand stack frame */ \ /* arg12 */ \ "ld 3,96(11)\n\t" \ "std 3,136(1)\n\t" \ /* arg11 */ \ "ld 3,88(11)\n\t" \ "std 3,128(1)\n\t" \ /* arg10 */ \ "ld 3,80(11)\n\t" \ "std 3,120(1)\n\t" \ /* arg9 */ \ "ld 3,72(11)\n\t" \ "std 3,112(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 10, 64(11)\n\t" /* arg8->r10 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_ppc64_linux */ /* ------------------------- arm-linux ------------------------- */ #if defined(PLAT_arm_linux) /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS "r0", "r1", "r2", "r3","r4","r14" /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ /* This is a bit tricky. We store the original stack pointer in r10 as it is callee-saves. gcc doesn't allow the use of r11 for some reason. Also, we can't directly "bic" the stack pointer in thumb mode since r13 isn't an allowed register number in that context. So use r4 as a temporary, since that is about to get trashed anyway, just after each use of this macro. Side effect is we need to be very careful about any future changes, since VALGRIND_ALIGN_STACK simply assumes r4 is usable. */ #define VALGRIND_ALIGN_STACK \ "mov r10, sp\n\t" \ "mov r4, sp\n\t" \ "bic r4, r4, #7\n\t" \ "mov sp, r4\n\t" #define VALGRIND_RESTORE_STACK \ "mov sp, r10\n\t" /* These CALL_FN_ macros assume that on arm-linux, sizeof(unsigned long) == 4. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #4] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #4 \n\t" \ "ldr r0, [%1, #20] \n\t" \ "push {r0} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "push {r0, r1} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #4 \n\t" \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "push {r0, r1, r2} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "ldr r3, [%1, #32] \n\t" \ "push {r0, r1, r2, r3} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #4 \n\t" \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "ldr r3, [%1, #32] \n\t" \ "ldr r4, [%1, #36] \n\t" \ "push {r0, r1, r2, r3, r4} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #40] \n\t" \ "push {r0} \n\t" \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "ldr r3, [%1, #32] \n\t" \ "ldr r4, [%1, #36] \n\t" \ "push {r0, r1, r2, r3, r4} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #4 \n\t" \ "ldr r0, [%1, #40] \n\t" \ "ldr r1, [%1, #44] \n\t" \ "push {r0, r1} \n\t" \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "ldr r3, [%1, #32] \n\t" \ "ldr r4, [%1, #36] \n\t" \ "push {r0, r1, r2, r3, r4} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #40] \n\t" \ "ldr r1, [%1, #44] \n\t" \ "ldr r2, [%1, #48] \n\t" \ "push {r0, r1, r2} \n\t" \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "ldr r3, [%1, #32] \n\t" \ "ldr r4, [%1, #36] \n\t" \ "push {r0, r1, r2, r3, r4} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_arm_linux */ /* ------------------------- s390x-linux ------------------------- */ #if defined(PLAT_s390x_linux) /* Similar workaround as amd64 (see above), but we use r11 as frame pointer and save the old r11 in r7. r11 might be used for argvec, therefore we copy argvec in r1 since r1 is clobbered after the call anyway. */ #if defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM) # define __FRAME_POINTER \ ,"d"(__builtin_dwarf_cfa()) # define VALGRIND_CFI_PROLOGUE \ ".cfi_remember_state\n\t" \ "lgr 1,%1\n\t" /* copy the argvec pointer in r1 */ \ "lgr 7,11\n\t" \ "lgr 11,%2\n\t" \ ".cfi_def_cfa r11, 0\n\t" # define VALGRIND_CFI_EPILOGUE \ "lgr 11, 7\n\t" \ ".cfi_restore_state\n\t" #else # define __FRAME_POINTER # define VALGRIND_CFI_PROLOGUE \ "lgr 1,%1\n\t" # define VALGRIND_CFI_EPILOGUE #endif /* Nb: On s390 the stack pointer is properly aligned *at all times* according to the s390 GCC maintainer. (The ABI specification is not precise in this regard.) Therefore, VALGRIND_ALIGN_STACK and VALGRIND_RESTORE_STACK are not defined here. */ /* These regs are trashed by the hidden call. Note that we overwrite r14 in s390_irgen_noredir (VEX/priv/guest_s390_irgen.c) to give the function a proper return address. All others are ABI defined call clobbers. */ #define __CALLER_SAVED_REGS "0","1","2","3","4","5","14", \ "f0","f1","f2","f3","f4","f5","f6","f7" /* Nb: Although r11 is modified in the asm snippets below (inside VALGRIND_CFI_PROLOGUE) it is not listed in the clobber section, for two reasons: (1) r11 is restored in VALGRIND_CFI_EPILOGUE, so effectively it is not modified (2) GCC will complain that r11 cannot appear inside a clobber section, when compiled with -O -fno-omit-frame-pointer */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 1, 0(1)\n\t" /* target->r1 */ \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "d" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) /* The call abi has the arguments in r2-r6 and stack */ #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 2, 8(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1, arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1, arg2, arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1, arg2, arg3, arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1, arg2, arg3, arg4, arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-168\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,168\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-176\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,176\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 ,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-184\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "mvc 176(8,15), 64(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,184\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 ,arg8, arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-192\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "mvc 176(8,15), 64(1)\n\t" \ "mvc 184(8,15), 72(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,192\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 ,arg8, arg9, arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-200\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "mvc 176(8,15), 64(1)\n\t" \ "mvc 184(8,15), 72(1)\n\t" \ "mvc 192(8,15), 80(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,200\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 ,arg8, arg9, arg10, arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ _argvec[11] = (unsigned long)arg11; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-208\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "mvc 176(8,15), 64(1)\n\t" \ "mvc 184(8,15), 72(1)\n\t" \ "mvc 192(8,15), 80(1)\n\t" \ "mvc 200(8,15), 88(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,208\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 ,arg8, arg9, arg10, arg11, arg12)\ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ _argvec[11] = (unsigned long)arg11; \ _argvec[12] = (unsigned long)arg12; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-216\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "mvc 176(8,15), 64(1)\n\t" \ "mvc 184(8,15), 72(1)\n\t" \ "mvc 192(8,15), 80(1)\n\t" \ "mvc 200(8,15), 88(1)\n\t" \ "mvc 208(8,15), 96(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "lgr %0, 2\n\t" \ "aghi 15,216\n\t" \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_s390x_linux */ /* ------------------------- mips32-linux ----------------------- */ #if defined(PLAT_mips32_linux) /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS "$2", "$3", "$4", "$5", "$6", \ "$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", \ "$25", "$31" /* These CALL_FN_ macros assume that on mips-linux, sizeof(unsigned long) == 4. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "subu $29, $29, 16 \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 16\n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "subu $29, $29, 16 \n\t" \ "lw $4, 4(%1) \n\t" /* arg1*/ \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 16 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "subu $29, $29, 16 \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 16 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "subu $29, $29, 16 \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 16 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "subu $29, $29, 16 \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 16 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 24\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 24 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 32\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "nop\n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 32 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 32\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 32 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 40\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 32(%1) \n\t" \ "sw $4, 28($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 40 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 40\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 32(%1) \n\t" \ "sw $4, 28($29) \n\t" \ "lw $4, 36(%1) \n\t" \ "sw $4, 32($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 40 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 48\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 32(%1) \n\t" \ "sw $4, 28($29) \n\t" \ "lw $4, 36(%1) \n\t" \ "sw $4, 32($29) \n\t" \ "lw $4, 40(%1) \n\t" \ "sw $4, 36($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 48 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 48\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 32(%1) \n\t" \ "sw $4, 28($29) \n\t" \ "lw $4, 36(%1) \n\t" \ "sw $4, 32($29) \n\t" \ "lw $4, 40(%1) \n\t" \ "sw $4, 36($29) \n\t" \ "lw $4, 44(%1) \n\t" \ "sw $4, 40($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 48 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 56\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 32(%1) \n\t" \ "sw $4, 28($29) \n\t" \ "lw $4, 36(%1) \n\t" \ "sw $4, 32($29) \n\t" \ "lw $4, 40(%1) \n\t" \ "sw $4, 36($29) \n\t" \ "lw $4, 44(%1) \n\t" \ "sw $4, 40($29) \n\t" \ "lw $4, 48(%1) \n\t" \ "sw $4, 44($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 56 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_mips32_linux */ /* ------------------------- mips64-linux ------------------------- */ #if defined(PLAT_mips64_linux) /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS "$2", "$3", "$4", "$5", "$6", \ "$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", \ "$25", "$31" /* These CALL_FN_ macros assume that on mips-linux, sizeof(unsigned long) == 4. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" /* arg1*/ \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $11, 64(%1)\n\t" \ "ld $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ "dsubu $29, $29, 8\n\t" \ "ld $4, 72(%1)\n\t" \ "sd $4, 0($29)\n\t" \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $11, 64(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "daddu $29, $29, 8\n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ "dsubu $29, $29, 16\n\t" \ "ld $4, 72(%1)\n\t" \ "sd $4, 0($29)\n\t" \ "ld $4, 80(%1)\n\t" \ "sd $4, 8($29)\n\t" \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $11, 64(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "daddu $29, $29, 16\n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ "dsubu $29, $29, 24\n\t" \ "ld $4, 72(%1)\n\t" \ "sd $4, 0($29)\n\t" \ "ld $4, 80(%1)\n\t" \ "sd $4, 8($29)\n\t" \ "ld $4, 88(%1)\n\t" \ "sd $4, 16($29)\n\t" \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $11, 64(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "daddu $29, $29, 24\n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ "dsubu $29, $29, 32\n\t" \ "ld $4, 72(%1)\n\t" \ "sd $4, 0($29)\n\t" \ "ld $4, 80(%1)\n\t" \ "sd $4, 8($29)\n\t" \ "ld $4, 88(%1)\n\t" \ "sd $4, 16($29)\n\t" \ "ld $4, 96(%1)\n\t" \ "sd $4, 24($29)\n\t" \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $11, 64(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "daddu $29, $29, 32\n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_mips64_linux */ /* ------------------------------------------------------------------ */ /* ARCHITECTURE INDEPENDENT MACROS for CLIENT REQUESTS. */ /* */ /* ------------------------------------------------------------------ */ /* Some request codes. There are many more of these, but most are not exposed to end-user view. These are the public ones, all of the form 0x1000 + small_number. Core ones are in the range 0x00000000--0x0000ffff. The non-public ones start at 0x2000. */ /* These macros are used by tools -- they must be public, but don't embed them into other programs. */ #define VG_USERREQ_TOOL_BASE(a,b) \ ((unsigned int)(((a)&0xff) << 24 | ((b)&0xff) << 16)) #define VG_IS_TOOL_USERREQ(a, b, v) \ (VG_USERREQ_TOOL_BASE(a,b) == ((v) & 0xffff0000)) /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! This enum comprises an ABI exported by Valgrind to programs which use client requests. DO NOT CHANGE THE ORDER OF THESE ENTRIES, NOR DELETE ANY -- add new ones at the end. */ typedef enum { VG_USERREQ__RUNNING_ON_VALGRIND = 0x1001, VG_USERREQ__DISCARD_TRANSLATIONS = 0x1002, /* These allow any function to be called from the simulated CPU but run on the real CPU. Nb: the first arg passed to the function is always the ThreadId of the running thread! So CLIENT_CALL0 actually requires a 1 arg function, etc. */ VG_USERREQ__CLIENT_CALL0 = 0x1101, VG_USERREQ__CLIENT_CALL1 = 0x1102, VG_USERREQ__CLIENT_CALL2 = 0x1103, VG_USERREQ__CLIENT_CALL3 = 0x1104, /* Can be useful in regression testing suites -- eg. can send Valgrind's output to /dev/null and still count errors. */ VG_USERREQ__COUNT_ERRORS = 0x1201, /* Allows the client program and/or gdbserver to execute a monitor command. */ VG_USERREQ__GDB_MONITOR_COMMAND = 0x1202, /* These are useful and can be interpreted by any tool that tracks malloc() et al, by using vg_replace_malloc.c. */ VG_USERREQ__MALLOCLIKE_BLOCK = 0x1301, VG_USERREQ__RESIZEINPLACE_BLOCK = 0x130b, VG_USERREQ__FREELIKE_BLOCK = 0x1302, /* Memory pool support. */ VG_USERREQ__CREATE_MEMPOOL = 0x1303, VG_USERREQ__DESTROY_MEMPOOL = 0x1304, VG_USERREQ__MEMPOOL_ALLOC = 0x1305, VG_USERREQ__MEMPOOL_FREE = 0x1306, VG_USERREQ__MEMPOOL_TRIM = 0x1307, VG_USERREQ__MOVE_MEMPOOL = 0x1308, VG_USERREQ__MEMPOOL_CHANGE = 0x1309, VG_USERREQ__MEMPOOL_EXISTS = 0x130a, /* Allow printfs to valgrind log. */ /* The first two pass the va_list argument by value, which assumes it is the same size as or smaller than a UWord, which generally isn't the case. Hence are deprecated. The second two pass the vargs by reference and so are immune to this problem. */ /* both :: char* fmt, va_list vargs (DEPRECATED) */ VG_USERREQ__PRINTF = 0x1401, VG_USERREQ__PRINTF_BACKTRACE = 0x1402, /* both :: char* fmt, va_list* vargs */ VG_USERREQ__PRINTF_VALIST_BY_REF = 0x1403, VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF = 0x1404, /* Stack support. */ VG_USERREQ__STACK_REGISTER = 0x1501, VG_USERREQ__STACK_DEREGISTER = 0x1502, VG_USERREQ__STACK_CHANGE = 0x1503, /* Wine support */ VG_USERREQ__LOAD_PDB_DEBUGINFO = 0x1601, /* Querying of debug info. */ VG_USERREQ__MAP_IP_TO_SRCLOC = 0x1701, /* Disable/enable error reporting level. Takes a single Word arg which is the delta to this thread's error disablement indicator. Hence 1 disables or further disables errors, and -1 moves back towards enablement. Other values are not allowed. */ VG_USERREQ__CHANGE_ERR_DISABLEMENT = 0x1801, /* Initialise IR injection */ VG_USERREQ__VEX_INIT_FOR_IRI = 0x1901 } Vg_ClientRequest; #if !defined(__GNUC__) # define __extension__ /* */ #endif /* Returns the number of Valgrinds this code is running under. That is, 0 if running natively, 1 if running under Valgrind, 2 if running under Valgrind which is running under another Valgrind, etc. */ #define RUNNING_ON_VALGRIND \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* if not */, \ VG_USERREQ__RUNNING_ON_VALGRIND, \ 0, 0, 0, 0, 0) \ /* Discard translation of code in the range [_qzz_addr .. _qzz_addr + _qzz_len - 1]. Useful if you are debugging a JITter or some such, since it provides a way to make sure valgrind will retranslate the invalidated area. Returns no value. */ #define VALGRIND_DISCARD_TRANSLATIONS(_qzz_addr,_qzz_len) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DISCARD_TRANSLATIONS, \ _qzz_addr, _qzz_len, 0, 0, 0) /* These requests are for getting Valgrind itself to print something. Possibly with a backtrace. This is a really ugly hack. The return value is the number of characters printed, excluding the "**<pid>** " part at the start and the backtrace (if present). */ #if defined(__GNUC__) || defined(__INTEL_COMPILER) && !defined(_MSC_VER) /* Modern GCC will optimize the static routine out if unused, and unused attribute will shut down warnings about it. */ static int VALGRIND_PRINTF(const char *format, ...) __attribute__((format(__printf__, 1, 2), __unused__)); #endif static int #if defined(_MSC_VER) __inline #endif VALGRIND_PRINTF(const char *format, ...) { #if defined(NVALGRIND) (void)format; return 0; #else /* NVALGRIND */ #if defined(_MSC_VER) || defined(__MINGW64__) uintptr_t _qzz_res; #else unsigned long _qzz_res; #endif va_list vargs; va_start(vargs, format); #if defined(_MSC_VER) || defined(__MINGW64__) _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__PRINTF_VALIST_BY_REF, (uintptr_t)format, (uintptr_t)&vargs, 0, 0, 0); #else _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__PRINTF_VALIST_BY_REF, (unsigned long)format, (unsigned long)&vargs, 0, 0, 0); #endif va_end(vargs); return (int)_qzz_res; #endif /* NVALGRIND */ } #if defined(__GNUC__) || defined(__INTEL_COMPILER) && !defined(_MSC_VER) static int VALGRIND_PRINTF_BACKTRACE(const char *format, ...) __attribute__((format(__printf__, 1, 2), __unused__)); #endif static int #if defined(_MSC_VER) __inline #endif VALGRIND_PRINTF_BACKTRACE(const char *format, ...) { #if defined(NVALGRIND) (void) format; return 0; #else /* NVALGRIND */ #if defined(_MSC_VER) || defined(__MINGW64__) uintptr_t _qzz_res; #else unsigned long _qzz_res; #endif va_list vargs; va_start(vargs, format); #if defined(_MSC_VER) || defined(__MINGW64__) _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF, (uintptr_t)format, (uintptr_t)&vargs, 0, 0, 0); #else _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF, (unsigned long)format, (unsigned long)&vargs, 0, 0, 0); #endif va_end(vargs); return (int)_qzz_res; #endif /* NVALGRIND */ } /* These requests allow control to move from the simulated CPU to the real CPU, calling an arbitary function. Note that the current ThreadId is inserted as the first argument. So this call: VALGRIND_NON_SIMD_CALL2(f, arg1, arg2) requires f to have this signature: Word f(Word tid, Word arg1, Word arg2) where "Word" is a word-sized type. Note that these client requests are not entirely reliable. For example, if you call a function with them that subsequently calls printf(), there's a high chance Valgrind will crash. Generally, your prospects of these working are made higher if the called function does not refer to any global variables, and does not refer to any libc or other functions (printf et al). Any kind of entanglement with libc or dynamic linking is likely to have a bad outcome, for tricky reasons which we've grappled with a lot in the past. */ #define VALGRIND_NON_SIMD_CALL0(_qyy_fn) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__CLIENT_CALL0, \ _qyy_fn, \ 0, 0, 0, 0) #define VALGRIND_NON_SIMD_CALL1(_qyy_fn, _qyy_arg1) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__CLIENT_CALL1, \ _qyy_fn, \ _qyy_arg1, 0, 0, 0) #define VALGRIND_NON_SIMD_CALL2(_qyy_fn, _qyy_arg1, _qyy_arg2) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__CLIENT_CALL2, \ _qyy_fn, \ _qyy_arg1, _qyy_arg2, 0, 0) #define VALGRIND_NON_SIMD_CALL3(_qyy_fn, _qyy_arg1, _qyy_arg2, _qyy_arg3) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__CLIENT_CALL3, \ _qyy_fn, \ _qyy_arg1, _qyy_arg2, \ _qyy_arg3, 0) /* Counts the number of errors that have been recorded by a tool. Nb: the tool must record the errors with VG_(maybe_record_error)() or VG_(unique_error)() for them to be counted. */ #define VALGRIND_COUNT_ERRORS \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR( \ 0 /* default return */, \ VG_USERREQ__COUNT_ERRORS, \ 0, 0, 0, 0, 0) /* Several Valgrind tools (Memcheck, Massif, Helgrind, DRD) rely on knowing when heap blocks are allocated in order to give accurate results. This happens automatically for the standard allocator functions such as malloc(), calloc(), realloc(), memalign(), new, new[], free(), delete, delete[], etc. But if your program uses a custom allocator, this doesn't automatically happen, and Valgrind will not do as well. For example, if you allocate superblocks with mmap() and then allocates chunks of the superblocks, all Valgrind's observations will be at the mmap() level and it won't know that the chunks should be considered separate entities. In Memcheck's case, that means you probably won't get heap block overrun detection (because there won't be redzones marked as unaddressable) and you definitely won't get any leak detection. The following client requests allow a custom allocator to be annotated so that it can be handled accurately by Valgrind. VALGRIND_MALLOCLIKE_BLOCK marks a region of memory as having been allocated by a malloc()-like function. For Memcheck (an illustrative case), this does two things: - It records that the block has been allocated. This means any addresses within the block mentioned in error messages will be identified as belonging to the block. It also means that if the block isn't freed it will be detected by the leak checker. - It marks the block as being addressable and undefined (if 'is_zeroed' is not set), or addressable and defined (if 'is_zeroed' is set). This controls how accesses to the block by the program are handled. 'addr' is the start of the usable block (ie. after any redzone), 'sizeB' is its size. 'rzB' is the redzone size if the allocator can apply redzones -- these are blocks of padding at the start and end of each block. Adding redzones is recommended as it makes it much more likely Valgrind will spot block overruns. `is_zeroed' indicates if the memory is zeroed (or filled with another predictable value), as is the case for calloc(). VALGRIND_MALLOCLIKE_BLOCK should be put immediately after the point where a heap block -- that will be used by the client program -- is allocated. It's best to put it at the outermost level of the allocator if possible; for example, if you have a function my_alloc() which calls internal_alloc(), and the client request is put inside internal_alloc(), stack traces relating to the heap block will contain entries for both my_alloc() and internal_alloc(), which is probably not what you want. For Memcheck users: if you use VALGRIND_MALLOCLIKE_BLOCK to carve out custom blocks from within a heap block, B, that has been allocated with malloc/calloc/new/etc, then block B will be *ignored* during leak-checking -- the custom blocks will take precedence. VALGRIND_FREELIKE_BLOCK is the partner to VALGRIND_MALLOCLIKE_BLOCK. For Memcheck, it does two things: - It records that the block has been deallocated. This assumes that the block was annotated as having been allocated via VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued. - It marks the block as being unaddressable. VALGRIND_FREELIKE_BLOCK should be put immediately after the point where a heap block is deallocated. VALGRIND_RESIZEINPLACE_BLOCK informs a tool about reallocation. For Memcheck, it does four things: - It records that the size of a block has been changed. This assumes that the block was annotated as having been allocated via VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued. - If the block shrunk, it marks the freed memory as being unaddressable. - If the block grew, it marks the new area as undefined and defines a red zone past the end of the new block. - The V-bits of the overlap between the old and the new block are preserved. VALGRIND_RESIZEINPLACE_BLOCK should be put after allocation of the new block and before deallocation of the old block. In many cases, these three client requests will not be enough to get your allocator working well with Memcheck. More specifically, if your allocator writes to freed blocks in any way then a VALGRIND_MAKE_MEM_UNDEFINED call will be necessary to mark the memory as addressable just before the zeroing occurs, otherwise you'll get a lot of invalid write errors. For example, you'll need to do this if your allocator recycles freed blocks, but it zeroes them before handing them back out (via VALGRIND_MALLOCLIKE_BLOCK). Alternatively, if your allocator reuses freed blocks for allocator-internal data structures, VALGRIND_MAKE_MEM_UNDEFINED calls will also be necessary. Really, what's happening is a blurring of the lines between the client program and the allocator... after VALGRIND_FREELIKE_BLOCK is called, the memory should be considered unaddressable to the client program, but the allocator knows more than the rest of the client program and so may be able to safely access it. Extra client requests are necessary for Valgrind to understand the distinction between the allocator and the rest of the program. Ignored if addr == 0. */ #define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MALLOCLIKE_BLOCK, \ addr, sizeB, rzB, is_zeroed, 0) /* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details. Ignored if addr == 0. */ #define VALGRIND_RESIZEINPLACE_BLOCK(addr, oldSizeB, newSizeB, rzB) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__RESIZEINPLACE_BLOCK, \ addr, oldSizeB, newSizeB, rzB, 0) /* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details. Ignored if addr == 0. */ #define VALGRIND_FREELIKE_BLOCK(addr, rzB) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__FREELIKE_BLOCK, \ addr, rzB, 0, 0, 0) /* Create a memory pool. */ #define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \ pool, rzB, is_zeroed, 0, 0) /* Destroy a memory pool. */ #define VALGRIND_DESTROY_MEMPOOL(pool) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DESTROY_MEMPOOL, \ pool, 0, 0, 0, 0) /* Associate a piece of memory with a memory pool. */ #define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_ALLOC, \ pool, addr, size, 0, 0) /* Disassociate a piece of memory from a memory pool. */ #define VALGRIND_MEMPOOL_FREE(pool, addr) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_FREE, \ pool, addr, 0, 0, 0) /* Disassociate any pieces outside a particular range. */ #define VALGRIND_MEMPOOL_TRIM(pool, addr, size) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_TRIM, \ pool, addr, size, 0, 0) /* Resize and/or move a piece associated with a memory pool. */ #define VALGRIND_MOVE_MEMPOOL(poolA, poolB) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MOVE_MEMPOOL, \ poolA, poolB, 0, 0, 0) /* Resize and/or move a piece associated with a memory pool. */ #define VALGRIND_MEMPOOL_CHANGE(pool, addrA, addrB, size) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_CHANGE, \ pool, addrA, addrB, size, 0) /* Return 1 if a mempool exists, else 0. */ #define VALGRIND_MEMPOOL_EXISTS(pool) \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__MEMPOOL_EXISTS, \ pool, 0, 0, 0, 0) /* Mark a piece of memory as being a stack. Returns a stack id. */ #define VALGRIND_STACK_REGISTER(start, end) \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__STACK_REGISTER, \ start, end, 0, 0, 0) /* Unmark the piece of memory associated with a stack id as being a stack. */ #define VALGRIND_STACK_DEREGISTER(id) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STACK_DEREGISTER, \ id, 0, 0, 0, 0) /* Change the start and end address of the stack id. */ #define VALGRIND_STACK_CHANGE(id, start, end) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STACK_CHANGE, \ id, start, end, 0, 0) /* Load PDB debug info for Wine PE image_map. */ #define VALGRIND_LOAD_PDB_DEBUGINFO(fd, ptr, total_size, delta) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__LOAD_PDB_DEBUGINFO, \ fd, ptr, total_size, delta, 0) /* Map a code address to a source file name and line number. buf64 must point to a 64-byte buffer in the caller's address space. The result will be dumped in there and is guaranteed to be zero terminated. If no info is found, the first byte is set to zero. */ #define VALGRIND_MAP_IP_TO_SRCLOC(addr, buf64) \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__MAP_IP_TO_SRCLOC, \ addr, buf64, 0, 0, 0) /* Disable error reporting for this thread. Behaves in a stack like way, so you can safely call this multiple times provided that VALGRIND_ENABLE_ERROR_REPORTING is called the same number of times to re-enable reporting. The first call of this macro disables reporting. Subsequent calls have no effect except to increase the number of VALGRIND_ENABLE_ERROR_REPORTING calls needed to re-enable reporting. Child threads do not inherit this setting from their parents -- they are always created with reporting enabled. */ #define VALGRIND_DISABLE_ERROR_REPORTING \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CHANGE_ERR_DISABLEMENT, \ 1, 0, 0, 0, 0) /* Re-enable error reporting, as per comments on VALGRIND_DISABLE_ERROR_REPORTING. */ #define VALGRIND_ENABLE_ERROR_REPORTING \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CHANGE_ERR_DISABLEMENT, \ -1, 0, 0, 0, 0) /* Execute a monitor command from the client program. If a connection is opened with GDB, the output will be sent according to the output mode set for vgdb. If no connection is opened, output will go to the log output. Returns 1 if command not recognised, 0 otherwise. */ #define VALGRIND_MONITOR_COMMAND(command) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__GDB_MONITOR_COMMAND, \ command, 0, 0, 0, 0) #undef PLAT_x86_darwin #undef PLAT_amd64_darwin #undef PLAT_x86_win32 #undef PLAT_amd64_win64 #undef PLAT_x86_linux #undef PLAT_amd64_linux #undef PLAT_ppc32_linux #undef PLAT_ppc64_linux #undef PLAT_arm_linux #undef PLAT_s390x_linux #undef PLAT_mips32_linux #undef PLAT_mips64_linux #endif /* __VALGRIND_H */
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/valgrind/helgrind.h
/* ---------------------------------------------------------------- Notice that the above BSD-style license applies to this one file (helgrind.h) only. The entire rest of Valgrind is licensed under the terms of the GNU General Public License, version 2. See the COPYING file in the source distribution for details. ---------------------------------------------------------------- This file is part of Helgrind, a Valgrind tool for detecting errors in threaded programs. Copyright (C) 2007-2013 OpenWorks LLP [email protected] Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 3. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 4. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------- Notice that the above BSD-style license applies to this one file (helgrind.h) only. The entire rest of Valgrind is licensed under the terms of the GNU General Public License, version 2. See the COPYING file in the source distribution for details. ---------------------------------------------------------------- */ #ifndef __HELGRIND_H #define __HELGRIND_H #include "valgrind.h" /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! This enum comprises an ABI exported by Valgrind to programs which use client requests. DO NOT CHANGE THE ORDER OF THESE ENTRIES, NOR DELETE ANY -- add new ones at the end. */ typedef enum { VG_USERREQ__HG_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'), /* The rest are for Helgrind's internal use. Not for end-user use. Do not use them unless you are a Valgrind developer. */ /* Notify the tool what this thread's pthread_t is. */ _VG_USERREQ__HG_SET_MY_PTHREAD_T = VG_USERREQ_TOOL_BASE('H','G') + 256, _VG_USERREQ__HG_PTH_API_ERROR, /* char*, int */ _VG_USERREQ__HG_PTHREAD_JOIN_POST, /* pthread_t of quitter */ _VG_USERREQ__HG_PTHREAD_MUTEX_INIT_POST, /* pth_mx_t*, long mbRec */ _VG_USERREQ__HG_PTHREAD_MUTEX_DESTROY_PRE, /* pth_mx_t*, long isInit */ _VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE, /* pth_mx_t* */ _VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_POST, /* pth_mx_t* */ _VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE, /* pth_mx_t*, long isTryLock */ _VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST, /* pth_mx_t* */ _VG_USERREQ__HG_PTHREAD_COND_SIGNAL_PRE, /* pth_cond_t* */ _VG_USERREQ__HG_PTHREAD_COND_BROADCAST_PRE, /* pth_cond_t* */ _VG_USERREQ__HG_PTHREAD_COND_WAIT_PRE, /* pth_cond_t*, pth_mx_t* */ _VG_USERREQ__HG_PTHREAD_COND_WAIT_POST, /* pth_cond_t*, pth_mx_t* */ _VG_USERREQ__HG_PTHREAD_COND_DESTROY_PRE, /* pth_cond_t*, long isInit */ _VG_USERREQ__HG_PTHREAD_RWLOCK_INIT_POST, /* pth_rwlk_t* */ _VG_USERREQ__HG_PTHREAD_RWLOCK_DESTROY_PRE, /* pth_rwlk_t* */ _VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, /* pth_rwlk_t*, long isW */ _VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST, /* pth_rwlk_t*, long isW */ _VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_PRE, /* pth_rwlk_t* */ _VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_POST, /* pth_rwlk_t* */ _VG_USERREQ__HG_POSIX_SEM_INIT_POST, /* sem_t*, ulong value */ _VG_USERREQ__HG_POSIX_SEM_DESTROY_PRE, /* sem_t* */ _VG_USERREQ__HG_POSIX_SEM_POST_PRE, /* sem_t* */ _VG_USERREQ__HG_POSIX_SEM_WAIT_POST, /* sem_t* */ _VG_USERREQ__HG_PTHREAD_BARRIER_INIT_PRE, /* pth_bar_t*, ulong, ulong */ _VG_USERREQ__HG_PTHREAD_BARRIER_WAIT_PRE, /* pth_bar_t* */ _VG_USERREQ__HG_PTHREAD_BARRIER_DESTROY_PRE, /* pth_bar_t* */ _VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_PRE, /* pth_slk_t* */ _VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_POST, /* pth_slk_t* */ _VG_USERREQ__HG_PTHREAD_SPIN_LOCK_PRE, /* pth_slk_t* */ _VG_USERREQ__HG_PTHREAD_SPIN_LOCK_POST, /* pth_slk_t* */ _VG_USERREQ__HG_PTHREAD_SPIN_DESTROY_PRE, /* pth_slk_t* */ _VG_USERREQ__HG_CLIENTREQ_UNIMP, /* char* */ _VG_USERREQ__HG_USERSO_SEND_PRE, /* arbitrary UWord SO-tag */ _VG_USERREQ__HG_USERSO_RECV_POST, /* arbitrary UWord SO-tag */ _VG_USERREQ__HG_USERSO_FORGET_ALL, /* arbitrary UWord SO-tag */ _VG_USERREQ__HG_RESERVED2, /* Do not use */ _VG_USERREQ__HG_RESERVED3, /* Do not use */ _VG_USERREQ__HG_RESERVED4, /* Do not use */ _VG_USERREQ__HG_ARANGE_MAKE_UNTRACKED, /* Addr a, ulong len */ _VG_USERREQ__HG_ARANGE_MAKE_TRACKED, /* Addr a, ulong len */ _VG_USERREQ__HG_PTHREAD_BARRIER_RESIZE_PRE, /* pth_bar_t*, ulong */ _VG_USERREQ__HG_CLEAN_MEMORY_HEAPBLOCK, /* Addr start_of_block */ _VG_USERREQ__HG_PTHREAD_COND_INIT_POST /* pth_cond_t*, pth_cond_attr_t*/ } Vg_TCheckClientRequest; /*----------------------------------------------------------------*/ /*--- ---*/ /*--- Implementation-only facilities. Not for end-user use. ---*/ /*--- For end-user facilities see below (the next section in ---*/ /*--- this file.) ---*/ /*--- ---*/ /*----------------------------------------------------------------*/ /* Do a client request. These are macros rather than a functions so as to avoid having an extra frame in stack traces. NB: these duplicate definitions in hg_intercepts.c. But here, we have to make do with weaker typing (no definition of Word etc) and no assertions, whereas in helgrind.h we can use those facilities. Obviously it's important the two sets of definitions are kept in sync. The commented-out asserts should actually hold, but unfortunately they can't be allowed to be visible here, because that would require the end-user code to #include <assert.h>. */ #define DO_CREQ_v_W(_creqF, _ty1F,_arg1F) \ do { \ long int _arg1; \ /* assert(sizeof(_ty1F) == sizeof(long int)); */ \ _arg1 = (long int)(_arg1F); \ VALGRIND_DO_CLIENT_REQUEST_STMT( \ (_creqF), \ _arg1, 0,0,0,0); \ } while (0) #define DO_CREQ_W_W(_resF, _dfltF, _creqF, _ty1F,_arg1F) \ do { \ long int arg1; \ /* assert(sizeof(_ty1F) == sizeof(long int)); */ \ _arg1 = (long int)(_arg1F); \ _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR( \ (_dfltF), \ (_creqF), \ _arg1, 0,0,0,0); \ _resF = _qzz_res; \ } while (0) #define DO_CREQ_v_WW(_creqF, _ty1F,_arg1F, _ty2F,_arg2F) \ do { \ long int _arg1, _arg2; \ /* assert(sizeof(_ty1F) == sizeof(long int)); */ \ /* assert(sizeof(_ty2F) == sizeof(long int)); */ \ _arg1 = (long int)(_arg1F); \ _arg2 = (long int)(_arg2F); \ VALGRIND_DO_CLIENT_REQUEST_STMT( \ (_creqF), \ _arg1,_arg2,0,0,0); \ } while (0) #define DO_CREQ_v_WWW(_creqF, _ty1F,_arg1F, \ _ty2F,_arg2F, _ty3F, _arg3F) \ do { \ long int _arg1, _arg2, _arg3; \ /* assert(sizeof(_ty1F) == sizeof(long int)); */ \ /* assert(sizeof(_ty2F) == sizeof(long int)); */ \ /* assert(sizeof(_ty3F) == sizeof(long int)); */ \ _arg1 = (long int)(_arg1F); \ _arg2 = (long int)(_arg2F); \ _arg3 = (long int)(_arg3F); \ VALGRIND_DO_CLIENT_REQUEST_STMT( \ (_creqF), \ _arg1,_arg2,_arg3,0,0); \ } while (0) #define _HG_CLIENTREQ_UNIMP(_qzz_str) \ DO_CREQ_v_W(_VG_USERREQ__HG_CLIENTREQ_UNIMP, \ (char*),(_qzz_str)) /*----------------------------------------------------------------*/ /*--- ---*/ /*--- Helgrind-native requests. These allow access to ---*/ /*--- the same set of annotation primitives that are used ---*/ /*--- to build the POSIX pthread wrappers. ---*/ /*--- ---*/ /*----------------------------------------------------------------*/ /* ---------------------------------------------------------- For describing ordinary mutexes (non-rwlocks). For rwlock descriptions see ANNOTATE_RWLOCK_* below. ---------------------------------------------------------- */ /* Notify here immediately after mutex creation. _mbRec == 0 for a non-recursive mutex, 1 for a recursive mutex. */ #define VALGRIND_HG_MUTEX_INIT_POST(_mutex, _mbRec) \ DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_INIT_POST, \ void*,(_mutex), long,(_mbRec)) /* Notify here immediately before mutex acquisition. _isTryLock == 0 for a normal acquisition, 1 for a "try" style acquisition. */ #define VALGRIND_HG_MUTEX_LOCK_PRE(_mutex, _isTryLock) \ DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE, \ void*,(_mutex), long,(_isTryLock)) /* Notify here immediately after a successful mutex acquisition. */ #define VALGRIND_HG_MUTEX_LOCK_POST(_mutex) \ DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST, \ void*,(_mutex)) /* Notify here immediately before a mutex release. */ #define VALGRIND_HG_MUTEX_UNLOCK_PRE(_mutex) \ DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE, \ void*,(_mutex)) /* Notify here immediately after a mutex release. */ #define VALGRIND_HG_MUTEX_UNLOCK_POST(_mutex) \ DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_POST, \ void*,(_mutex)) /* Notify here immediately before mutex destruction. */ #define VALGRIND_HG_MUTEX_DESTROY_PRE(_mutex) \ DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_DESTROY_PRE, \ void*,(_mutex)) /* ---------------------------------------------------------- For describing semaphores. ---------------------------------------------------------- */ /* Notify here immediately after semaphore creation. */ #define VALGRIND_HG_SEM_INIT_POST(_sem, _value) \ DO_CREQ_v_WW(_VG_USERREQ__HG_POSIX_SEM_INIT_POST, \ void*, (_sem), unsigned long, (_value)) /* Notify here immediately after a semaphore wait (an acquire-style operation) */ #define VALGRIND_HG_SEM_WAIT_POST(_sem) \ DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_WAIT_POST, \ void*,(_sem)) /* Notify here immediately before semaphore post (a release-style operation) */ #define VALGRIND_HG_SEM_POST_PRE(_sem) \ DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_POST_PRE, \ void*,(_sem)) /* Notify here immediately before semaphore destruction. */ #define VALGRIND_HG_SEM_DESTROY_PRE(_sem) \ DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_DESTROY_PRE, \ void*, (_sem)) /* ---------------------------------------------------------- For describing barriers. ---------------------------------------------------------- */ /* Notify here immediately before barrier creation. _count is the capacity. _resizable == 0 means the barrier may not be resized, 1 means it may be. */ #define VALGRIND_HG_BARRIER_INIT_PRE(_bar, _count, _resizable) \ DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_BARRIER_INIT_PRE, \ void*,(_bar), \ unsigned long,(_count), \ unsigned long,(_resizable)) /* Notify here immediately before arrival at a barrier. */ #define VALGRIND_HG_BARRIER_WAIT_PRE(_bar) \ DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_BARRIER_WAIT_PRE, \ void*,(_bar)) /* Notify here immediately before a resize (change of barrier capacity). If _newcount >= the existing capacity, then there is no change in the state of any threads waiting at the barrier. If _newcount < the existing capacity, and >= _newcount threads are currently waiting at the barrier, then this notification is considered to also have the effect of telling the checker that all waiting threads have now moved past the barrier. (I can't think of any other sane semantics.) */ #define VALGRIND_HG_BARRIER_RESIZE_PRE(_bar, _newcount) \ DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_BARRIER_RESIZE_PRE, \ void*,(_bar), \ unsigned long,(_newcount)) /* Notify here immediately before barrier destruction. */ #define VALGRIND_HG_BARRIER_DESTROY_PRE(_bar) \ DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_BARRIER_DESTROY_PRE, \ void*,(_bar)) /* ---------------------------------------------------------- For describing memory ownership changes. ---------------------------------------------------------- */ /* Clean memory state. This makes Helgrind forget everything it knew about the specified memory range. Effectively this announces that the specified memory range now "belongs" to the calling thread, so that: (1) the calling thread can access it safely without synchronisation, and (2) all other threads must sync with this one to access it safely. This is particularly useful for memory allocators that wish to recycle memory. */ #define VALGRIND_HG_CLEAN_MEMORY(_qzz_start, _qzz_len) \ DO_CREQ_v_WW(VG_USERREQ__HG_CLEAN_MEMORY, \ void*,(_qzz_start), \ unsigned long,(_qzz_len)) /* The same, but for the heap block starting at _qzz_blockstart. This allows painting when we only know the address of an object, but not its size, which is sometimes the case in C++ code involving inheritance, and in which RTTI is not, for whatever reason, available. Returns the number of bytes painted, which can be zero for a zero-sized block. Hence, return values >= 0 indicate success (the block was found), and the value -1 indicates block not found, and -2 is returned when not running on Helgrind. */ #define VALGRIND_HG_CLEAN_MEMORY_HEAPBLOCK(_qzz_blockstart) \ (__extension__ \ ({long int _npainted; \ DO_CREQ_W_W(_npainted, (-2)/*default*/, \ _VG_USERREQ__HG_CLEAN_MEMORY_HEAPBLOCK, \ void*,(_qzz_blockstart)); \ _npainted; \ })) /* ---------------------------------------------------------- For error control. ---------------------------------------------------------- */ /* Tell H that an address range is not to be "tracked" until further notice. This puts it in the NOACCESS state, in which case we ignore all reads and writes to it. Useful for ignoring ranges of memory where there might be races we don't want to see. If the memory is subsequently reallocated via malloc/new/stack allocation, then it is put back in the trackable state. Hence it is safe in the situation where checking is disabled, the containing area is deallocated and later reallocated for some other purpose. */ #define VALGRIND_HG_DISABLE_CHECKING(_qzz_start, _qzz_len) \ DO_CREQ_v_WW(_VG_USERREQ__HG_ARANGE_MAKE_UNTRACKED, \ void*,(_qzz_start), \ unsigned long,(_qzz_len)) /* And put it back into the normal "tracked" state, that is, make it once again subject to the normal race-checking machinery. This puts it in the same state as new memory allocated by this thread -- that is, basically owned exclusively by this thread. */ #define VALGRIND_HG_ENABLE_CHECKING(_qzz_start, _qzz_len) \ DO_CREQ_v_WW(_VG_USERREQ__HG_ARANGE_MAKE_TRACKED, \ void*,(_qzz_start), \ unsigned long,(_qzz_len)) /*----------------------------------------------------------------*/ /*--- ---*/ /*--- ThreadSanitizer-compatible requests ---*/ /*--- (mostly unimplemented) ---*/ /*--- ---*/ /*----------------------------------------------------------------*/ /* A quite-broad set of annotations, as used in the ThreadSanitizer project. This implementation aims to be a (source-level) compatible implementation of the macros defined in: http://code.google.com/p/data-race-test/source /browse/trunk/dynamic_annotations/dynamic_annotations.h (some of the comments below are taken from the above file) The implementation here is very incomplete, and intended as a starting point. Many of the macros are unimplemented. Rather than allowing unimplemented macros to silently do nothing, they cause an assertion. Intention is to implement them on demand. The major use of these macros is to make visible to race detectors, the behaviour (effects) of user-implemented synchronisation primitives, that the detectors could not otherwise deduce from the normal observation of pthread etc calls. Some of the macros are no-ops in Helgrind. That's because Helgrind is a pure happens-before detector, whereas ThreadSanitizer uses a hybrid lockset and happens-before scheme, which requires more accurate annotations for correct operation. The macros are listed in the same order as in dynamic_annotations.h (URL just above). I should point out that I am less than clear about the intended semantics of quite a number of them. Comments and clarifications welcomed! */ /* ---------------------------------------------------------------- These four allow description of user-level condition variables, apparently in the style of POSIX's pthread_cond_t. Currently unimplemented and will assert. ---------------------------------------------------------------- */ /* Report that wait on the condition variable at address CV has succeeded and the lock at address LOCK is now held. CV and LOCK are completely arbitrary memory addresses which presumably mean something to the application, but are meaningless to Helgrind. */ #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_CONDVAR_LOCK_WAIT") /* Report that wait on the condition variable at CV has succeeded. Variant w/o lock. */ #define ANNOTATE_CONDVAR_WAIT(cv) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_CONDVAR_WAIT") /* Report that we are about to signal on the condition variable at address CV. */ #define ANNOTATE_CONDVAR_SIGNAL(cv) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_CONDVAR_SIGNAL") /* Report that we are about to signal_all on the condition variable at CV. */ #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_CONDVAR_SIGNAL_ALL") /* ---------------------------------------------------------------- Create completely arbitrary happens-before edges between threads. If threads T1 .. Tn all do ANNOTATE_HAPPENS_BEFORE(obj) and later (w.r.t. some notional global clock for the computation) thread Tm does ANNOTATE_HAPPENS_AFTER(obj), then Helgrind will regard all memory accesses done by T1 .. Tn before the ..BEFORE.. call as happening-before all memory accesses done by Tm after the ..AFTER.. call. Hence Helgrind won't complain about races if Tm's accesses afterwards are to the same locations as accesses before by any of T1 .. Tn. OBJ is a machine word (unsigned long, or void*), is completely arbitrary, and denotes the identity of some synchronisation object you're modelling. You must do the _BEFORE call just before the real sync event on the signaller's side, and _AFTER just after the real sync event on the waiter's side. If none of the rest of these macros make sense to you, at least take the time to understand these two. They form the very essence of describing arbitrary inter-thread synchronisation events to Helgrind. You can get a long way just with them alone. See also, extensive discussion on semantics of this in https://bugs.kde.org/show_bug.cgi?id=243935 ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj) is interim until such time as bug 243935 is fully resolved. It instructs Helgrind to forget about any ANNOTATE_HAPPENS_BEFORE calls on the specified object, in effect putting it back in its original state. Once in that state, a use of ANNOTATE_HAPPENS_AFTER on it has no effect on the calling thread. An implementation may optionally release resources it has associated with 'obj' when ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj) happens. Users are recommended to use ANNOTATE_HAPPENS_BEFORE_FORGET_ALL to indicate when a synchronisation object is no longer needed, so as to avoid potential indefinite resource leaks. ---------------------------------------------------------------- */ #define ANNOTATE_HAPPENS_BEFORE(obj) \ DO_CREQ_v_W(_VG_USERREQ__HG_USERSO_SEND_PRE, void*,(obj)) #define ANNOTATE_HAPPENS_AFTER(obj) \ DO_CREQ_v_W(_VG_USERREQ__HG_USERSO_RECV_POST, void*,(obj)) #define ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj) \ DO_CREQ_v_W(_VG_USERREQ__HG_USERSO_FORGET_ALL, void*,(obj)) /* ---------------------------------------------------------------- Memory publishing. The TSan sources say: Report that the bytes in the range [pointer, pointer+size) are about to be published safely. The race checker will create a happens-before arc from the call ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size) to subsequent accesses to this memory. I'm not sure I understand what this means exactly, nor whether it is relevant for a pure h-b detector. Leaving unimplemented for now. ---------------------------------------------------------------- */ #define ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_PUBLISH_MEMORY_RANGE") /* DEPRECATED. Don't use it. */ /* #define ANNOTATE_UNPUBLISH_MEMORY_RANGE(pointer, size) */ /* DEPRECATED. Don't use it. */ /* #define ANNOTATE_SWAP_MEMORY_RANGE(pointer, size) */ /* ---------------------------------------------------------------- TSan sources say: Instruct the tool to create a happens-before arc between MU->Unlock() and MU->Lock(). This annotation may slow down the race detector; normally it is used only when it would be difficult to annotate each of the mutex's critical sections individually using the annotations above. If MU is a posix pthread_mutex_t then Helgrind will do this anyway. In any case, leave as unimp for now. I'm unsure about the intended behaviour. ---------------------------------------------------------------- */ #define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX") /* Deprecated. Use ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX. */ /* #define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) */ /* ---------------------------------------------------------------- TSan sources say: Annotations useful when defining memory allocators, or when memory that was protected in one way starts to be protected in another. Report that a new memory at "address" of size "size" has been allocated. This might be used when the memory has been retrieved from a free list and is about to be reused, or when a the locking discipline for a variable changes. AFAICS this is the same as VALGRIND_HG_CLEAN_MEMORY. ---------------------------------------------------------------- */ #define ANNOTATE_NEW_MEMORY(address, size) \ VALGRIND_HG_CLEAN_MEMORY((address), (size)) /* ---------------------------------------------------------------- TSan sources say: Annotations useful when defining FIFO queues that transfer data between threads. All unimplemented. Am not claiming to understand this (yet). ---------------------------------------------------------------- */ /* Report that the producer-consumer queue object at address PCQ has been created. The ANNOTATE_PCQ_* annotations should be used only for FIFO queues. For non-FIFO queues use ANNOTATE_HAPPENS_BEFORE (for put) and ANNOTATE_HAPPENS_AFTER (for get). */ #define ANNOTATE_PCQ_CREATE(pcq) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_PCQ_CREATE") /* Report that the queue at address PCQ is about to be destroyed. */ #define ANNOTATE_PCQ_DESTROY(pcq) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_PCQ_DESTROY") /* Report that we are about to put an element into a FIFO queue at address PCQ. */ #define ANNOTATE_PCQ_PUT(pcq) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_PCQ_PUT") /* Report that we've just got an element from a FIFO queue at address PCQ. */ #define ANNOTATE_PCQ_GET(pcq) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_PCQ_GET") /* ---------------------------------------------------------------- Annotations that suppress errors. It is usually better to express the program's synchronization using the other annotations, but these can be used when all else fails. Currently these are all unimplemented. I can't think of a simple way to implement them without at least some performance overhead. ---------------------------------------------------------------- */ /* Report that we may have a benign race at "pointer", with size "sizeof(*(pointer))". "pointer" must be a non-void* pointer. Insert at the point where "pointer" has been allocated, preferably close to the point where the race happens. See also ANNOTATE_BENIGN_RACE_STATIC. XXX: what's this actually supposed to do? And what's the type of DESCRIPTION? When does the annotation stop having an effect? */ #define ANNOTATE_BENIGN_RACE(pointer, description) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_BENIGN_RACE") /* Same as ANNOTATE_BENIGN_RACE(address, description), but applies to the memory range [address, address+size). */ #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \ VALGRIND_HG_DISABLE_CHECKING(address, size) /* Request the analysis tool to ignore all reads in the current thread until ANNOTATE_IGNORE_READS_END is called. Useful to ignore intentional racey reads, while still checking other reads and all writes. */ #define ANNOTATE_IGNORE_READS_BEGIN() \ _HG_CLIENTREQ_UNIMP("ANNOTATE_IGNORE_READS_BEGIN") /* Stop ignoring reads. */ #define ANNOTATE_IGNORE_READS_END() \ _HG_CLIENTREQ_UNIMP("ANNOTATE_IGNORE_READS_END") /* Similar to ANNOTATE_IGNORE_READS_BEGIN, but ignore writes. */ #define ANNOTATE_IGNORE_WRITES_BEGIN() \ _HG_CLIENTREQ_UNIMP("ANNOTATE_IGNORE_WRITES_BEGIN") /* Stop ignoring writes. */ #define ANNOTATE_IGNORE_WRITES_END() \ _HG_CLIENTREQ_UNIMP("ANNOTATE_IGNORE_WRITES_END") /* Start ignoring all memory accesses (reads and writes). */ #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ do { \ ANNOTATE_IGNORE_READS_BEGIN(); \ ANNOTATE_IGNORE_WRITES_BEGIN(); \ } while (0) /* Stop ignoring all memory accesses. */ #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \ do { \ ANNOTATE_IGNORE_WRITES_END(); \ ANNOTATE_IGNORE_READS_END(); \ } while (0) /* ---------------------------------------------------------------- Annotations useful for debugging. Again, so for unimplemented, partly for performance reasons. ---------------------------------------------------------------- */ /* Request to trace every access to ADDRESS. */ #define ANNOTATE_TRACE_MEMORY(address) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_TRACE_MEMORY") /* Report the current thread name to a race detector. */ #define ANNOTATE_THREAD_NAME(name) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_THREAD_NAME") /* ---------------------------------------------------------------- Annotations for describing behaviour of user-implemented lock primitives. In all cases, the LOCK argument is a completely arbitrary machine word (unsigned long, or void*) and can be any value which gives a unique identity to the lock objects being modelled. We just pretend they're ordinary posix rwlocks. That'll probably give some rather confusing wording in error messages, claiming that the arbitrary LOCK values are pthread_rwlock_t*'s, when in fact they are not. Ah well. ---------------------------------------------------------------- */ /* Report that a lock has just been created at address LOCK. */ #define ANNOTATE_RWLOCK_CREATE(lock) \ DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_INIT_POST, \ void*,(lock)) /* Report that the lock at address LOCK is about to be destroyed. */ #define ANNOTATE_RWLOCK_DESTROY(lock) \ DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_DESTROY_PRE, \ void*,(lock)) /* Report that the lock at address LOCK has just been acquired. is_w=1 for writer lock, is_w=0 for reader lock. */ #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \ DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST, \ void*,(lock), unsigned long,(is_w)) /* Report that the lock at address LOCK is about to be released. */ #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \ DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_PRE, \ void*,(lock)) /* is_w is ignored */ /* ------------------------------------------------------------- Annotations useful when implementing barriers. They are not normally needed by modules that merely use barriers. The "barrier" argument is a pointer to the barrier object. ---------------------------------------------------------------- */ /* Report that the "barrier" has been initialized with initial "count". If 'reinitialization_allowed' is true, initialization is allowed to happen multiple times w/o calling barrier_destroy() */ #define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_BARRIER_INIT") /* Report that we are about to enter barrier_wait("barrier"). */ #define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_BARRIER_DESTROY") /* Report that we just exited barrier_wait("barrier"). */ #define ANNOTATE_BARRIER_WAIT_AFTER(barrier) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_BARRIER_DESTROY") /* Report that the "barrier" has been destroyed. */ #define ANNOTATE_BARRIER_DESTROY(barrier) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_BARRIER_DESTROY") /* ---------------------------------------------------------------- Annotations useful for testing race detectors. ---------------------------------------------------------------- */ /* Report that we expect a race on the variable at ADDRESS. Use only in unit tests for a race detector. */ #define ANNOTATE_EXPECT_RACE(address, description) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_EXPECT_RACE") /* A no-op. Insert where you like to test the interceptors. */ #define ANNOTATE_NO_OP(arg) \ _HG_CLIENTREQ_UNIMP("ANNOTATE_NO_OP") /* Force the race detector to flush its state. The actual effect depends on * the implementation of the detector. */ #define ANNOTATE_FLUSH_STATE() \ _HG_CLIENTREQ_UNIMP("ANNOTATE_FLUSH_STATE") #endif /* __HELGRIND_H */
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/optional/copyright.txt
Copyright (C) 2011-2016 Andrzej Krzemienski Distributed under the Boost Software License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt) The idea and interface is based on Boost.Optional library authored by Fernando Luis Cacciola Carballal Home at https://github.com/akrzemi1/Optional
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/optional/optional.hpp
// Copyright (C) 2011 - 2012 Andrzej Krzemienski. // // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // The idea and interface is based on Boost.Optional library // authored by Fernando Luis Cacciola Carballal # ifndef ___OPTIONAL_HPP___ # define ___OPTIONAL_HPP___ # include <utility> # include <type_traits> # include <initializer_list> # include <cassert> # include <functional> # include <string> # include <stdexcept> # define TR2_OPTIONAL_REQUIRES(...) typename enable_if<__VA_ARGS__::value, bool>::type = false # if defined __GNUC__ // NOTE: GNUC is also defined for Clang # if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) # define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ # elif (__GNUC__ > 4) # define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ # endif # if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7) # define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ # elif (__GNUC__ > 4) # define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ # endif # if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1) # define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ # elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9) # define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ # elif (__GNUC__ > 4) # define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ # endif # endif # if defined __clang_major__ # if (__clang_major__ == 3 && __clang_minor__ >= 5) # define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ # elif (__clang_major__ > 3) # define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ # endif # if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ # define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ # elif (__clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2) # define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ # endif # endif # if defined _MSC_VER # if (_MSC_VER >= 1900) # define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ # endif # endif # if defined __clang__ # if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9) # define OPTIONAL_HAS_THIS_RVALUE_REFS 1 # else # define OPTIONAL_HAS_THIS_RVALUE_REFS 0 # endif # elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ # define OPTIONAL_HAS_THIS_RVALUE_REFS 1 # elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ # define OPTIONAL_HAS_THIS_RVALUE_REFS 1 # else # define OPTIONAL_HAS_THIS_RVALUE_REFS 0 # endif # if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ # define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1 # define OPTIONAL_CONSTEXPR_INIT_LIST constexpr # else # define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0 # define OPTIONAL_CONSTEXPR_INIT_LIST # endif # if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && (__cplusplus != 201103L) # define OPTIONAL_HAS_MOVE_ACCESSORS 1 # else # define OPTIONAL_HAS_MOVE_ACCESSORS 0 # endif // In C++11 constexpr implies const, so we need to make non-const members also non-constexpr # if (defined __cplusplus) && (__cplusplus == 201103L) # define OPTIONAL_MUTABLE_CONSTEXPR # else # define OPTIONAL_MUTABLE_CONSTEXPR constexpr # endif namespace std{ namespace experimental{ // BEGIN workaround for missing is_trivially_destructible # if defined TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ // leave it: it is already there # elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ // leave it: it is already there # elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ // leave it: it is already there # elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS // leave it: the user doesn't want it # else template <typename T> using is_trivially_destructible = std::has_trivial_destructor<T>; # endif // END workaround for missing is_trivially_destructible # if (defined TR2_OPTIONAL_GCC_4_7_AND_HIGHER___) // leave it; our metafunctions are already defined. # elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ // leave it; our metafunctions are already defined. # elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ // leave it: it is already there # elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS // leave it: the user doesn't want it # else // workaround for missing traits in GCC and CLANG template <class T> struct is_nothrow_move_constructible { constexpr static bool value = std::is_nothrow_constructible<T, T&&>::value; }; template <class T, class U> struct is_assignable { template <class X, class Y> constexpr static bool has_assign(...) { return false; } template <class X, class Y, size_t S = sizeof((std::declval<X>() = std::declval<Y>(), true)) > // the comma operator is necessary for the cases where operator= returns void constexpr static bool has_assign(bool) { return true; } constexpr static bool value = has_assign<T, U>(true); }; template <class T> struct is_nothrow_move_assignable { template <class X, bool has_any_move_assign> struct has_nothrow_move_assign { constexpr static bool value = false; }; template <class X> struct has_nothrow_move_assign<X, true> { constexpr static bool value = noexcept( std::declval<X&>() = std::declval<X&&>() ); }; constexpr static bool value = has_nothrow_move_assign<T, is_assignable<T&, T&&>::value>::value; }; // end workaround # endif // 20.5.4, optional for object types template <class T> class optional; // 20.5.5, optional for lvalue reference types template <class T> class optional<T&>; // workaround: std utility functions aren't constexpr yet template <class T> inline constexpr T&& constexpr_forward(typename std::remove_reference<T>::type& t) noexcept { return static_cast<T&&>(t); } template <class T> inline constexpr T&& constexpr_forward(typename std::remove_reference<T>::type&& t) noexcept { static_assert(!std::is_lvalue_reference<T>::value, "!!"); return static_cast<T&&>(t); } template <class T> inline constexpr typename std::remove_reference<T>::type&& constexpr_move(T&& t) noexcept { return static_cast<typename std::remove_reference<T>::type&&>(t); } #if defined NDEBUG # define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR) #else # define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert(!#CHECK);}(), (EXPR))) #endif namespace detail_ { // static_addressof: a constexpr version of addressof template <typename T> struct has_overloaded_addressof { template <class X> constexpr static bool has_overload(...) { return false; } template <class X, size_t S = sizeof(std::declval<X&>().operator&()) > constexpr static bool has_overload(bool) { return true; } constexpr static bool value = has_overload<T>(true); }; template <typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)> constexpr T* static_addressof(T& ref) { return &ref; } template <typename T, TR2_OPTIONAL_REQUIRES(has_overloaded_addressof<T>)> T* static_addressof(T& ref) { return std::addressof(ref); } // the call to convert<A>(b) has return type A and converts b to type A iff b decltype(b) is implicitly convertible to A template <class U> constexpr U convert(U v) { return v; } namespace swap_ns { using std::swap; template <class T> void adl_swap(T& t, T& u) noexcept(noexcept(swap(t, u))) { swap(t, u); } } // namespace swap_ns } // namespace detail constexpr struct trivial_init_t{} trivial_init{}; // 20.5.6, In-place construction constexpr struct in_place_t{} in_place{}; // 20.5.7, Disengaged state indicator struct nullopt_t { struct init{}; constexpr explicit nullopt_t(init){} }; constexpr nullopt_t nullopt{nullopt_t::init()}; // 20.5.8, class bad_optional_access class bad_optional_access : public logic_error { public: explicit bad_optional_access(const string& what_arg) : logic_error{what_arg} {} explicit bad_optional_access(const char* what_arg) : logic_error{what_arg} {} }; template <class T> union storage_t { unsigned char dummy_; T value_; constexpr storage_t( trivial_init_t ) noexcept : dummy_() {}; template <class... Args> constexpr storage_t( Args&&... args ) : value_(constexpr_forward<Args>(args)...) {} ~storage_t(){} }; template <class T> union constexpr_storage_t { unsigned char dummy_; T value_; constexpr constexpr_storage_t( trivial_init_t ) noexcept : dummy_() {}; template <class... Args> constexpr constexpr_storage_t( Args&&... args ) : value_(constexpr_forward<Args>(args)...) {} ~constexpr_storage_t() = default; }; template <class T> struct optional_base { bool init_; storage_t<T> storage_; constexpr optional_base() noexcept : init_(false), storage_(trivial_init) {}; explicit constexpr optional_base(const T& v) : init_(true), storage_(v) {} explicit constexpr optional_base(T&& v) : init_(true), storage_(constexpr_move(v)) {} template <class... Args> explicit optional_base(in_place_t, Args&&... args) : init_(true), storage_(constexpr_forward<Args>(args)...) {} template <class U, class... Args, TR2_OPTIONAL_REQUIRES(is_constructible<T, std::initializer_list<U>>)> explicit optional_base(in_place_t, std::initializer_list<U> il, Args&&... args) : init_(true), storage_(il, std::forward<Args>(args)...) {} ~optional_base() { if (init_) storage_.value_.T::~T(); } }; template <class T> struct constexpr_optional_base { bool init_; constexpr_storage_t<T> storage_; constexpr constexpr_optional_base() noexcept : init_(false), storage_(trivial_init) {}; explicit constexpr constexpr_optional_base(const T& v) : init_(true), storage_(v) {} explicit constexpr constexpr_optional_base(T&& v) : init_(true), storage_(constexpr_move(v)) {} template <class... Args> explicit constexpr constexpr_optional_base(in_place_t, Args&&... args) : init_(true), storage_(constexpr_forward<Args>(args)...) {} template <class U, class... Args, TR2_OPTIONAL_REQUIRES(is_constructible<T, std::initializer_list<U>>)> OPTIONAL_CONSTEXPR_INIT_LIST explicit constexpr_optional_base(in_place_t, std::initializer_list<U> il, Args&&... args) : init_(true), storage_(il, std::forward<Args>(args)...) {} ~constexpr_optional_base() = default; }; template <class T> using OptionalBase = typename std::conditional< is_trivially_destructible<T>::value, // if possible constexpr_optional_base<typename std::remove_const<T>::type>, // use base with trivial destructor optional_base<typename std::remove_const<T>::type> >::type; template <class T> class optional : private OptionalBase<T> { static_assert( !std::is_same<typename std::decay<T>::type, nullopt_t>::value, "bad T" ); static_assert( !std::is_same<typename std::decay<T>::type, in_place_t>::value, "bad T" ); constexpr bool initialized() const noexcept { return OptionalBase<T>::init_; } typename std::remove_const<T>::type* dataptr() { return std::addressof(OptionalBase<T>::storage_.value_); } constexpr const T* dataptr() const { return detail_::static_addressof(OptionalBase<T>::storage_.value_); } # if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 constexpr const T& contained_val() const& { return OptionalBase<T>::storage_.value_; } # if OPTIONAL_HAS_MOVE_ACCESSORS == 1 OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && { return std::move(OptionalBase<T>::storage_.value_); } OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & { return OptionalBase<T>::storage_.value_; } # else T& contained_val() & { return OptionalBase<T>::storage_.value_; } T&& contained_val() && { return std::move(OptionalBase<T>::storage_.value_); } # endif # else constexpr const T& contained_val() const { return OptionalBase<T>::storage_.value_; } T& contained_val() { return OptionalBase<T>::storage_.value_; } # endif void clear() noexcept { if (initialized()) dataptr()->T::~T(); OptionalBase<T>::init_ = false; } template <class... Args> void initialize(Args&&... args) noexcept(noexcept(T(std::forward<Args>(args)...))) { assert(!OptionalBase<T>::init_); ::new (static_cast<void*>(dataptr())) T(std::forward<Args>(args)...); OptionalBase<T>::init_ = true; } template <class U, class... Args> void initialize(std::initializer_list<U> il, Args&&... args) noexcept(noexcept(T(il, std::forward<Args>(args)...))) { assert(!OptionalBase<T>::init_); ::new (static_cast<void*>(dataptr())) T(il, std::forward<Args>(args)...); OptionalBase<T>::init_ = true; } public: typedef T value_type; // 20.5.5.1, constructors constexpr optional() noexcept : OptionalBase<T>() {}; constexpr optional(nullopt_t) noexcept : OptionalBase<T>() {}; optional(const optional& rhs) : OptionalBase<T>() { if (rhs.initialized()) { ::new (static_cast<void*>(dataptr())) T(*rhs); OptionalBase<T>::init_ = true; } } optional(optional&& rhs) noexcept(is_nothrow_move_constructible<T>::value) : OptionalBase<T>() { if (rhs.initialized()) { ::new (static_cast<void*>(dataptr())) T(std::move(*rhs)); OptionalBase<T>::init_ = true; } } constexpr optional(const T& v) : OptionalBase<T>(v) {} constexpr optional(T&& v) : OptionalBase<T>(constexpr_move(v)) {} template <class... Args> explicit constexpr optional(in_place_t, Args&&... args) : OptionalBase<T>(in_place_t{}, constexpr_forward<Args>(args)...) {} template <class U, class... Args, TR2_OPTIONAL_REQUIRES(is_constructible<T, std::initializer_list<U>>)> OPTIONAL_CONSTEXPR_INIT_LIST explicit optional(in_place_t, std::initializer_list<U> il, Args&&... args) : OptionalBase<T>(in_place_t{}, il, constexpr_forward<Args>(args)...) {} // 20.5.4.2, Destructor ~optional() = default; // 20.5.4.3, assignment optional& operator=(nullopt_t) noexcept { clear(); return *this; } optional& operator=(const optional& rhs) { if (initialized() == true && rhs.initialized() == false) clear(); else if (initialized() == false && rhs.initialized() == true) initialize(*rhs); else if (initialized() == true && rhs.initialized() == true) contained_val() = *rhs; return *this; } optional& operator=(optional&& rhs) noexcept(is_nothrow_move_assignable<T>::value && is_nothrow_move_constructible<T>::value) { if (initialized() == true && rhs.initialized() == false) clear(); else if (initialized() == false && rhs.initialized() == true) initialize(std::move(*rhs)); else if (initialized() == true && rhs.initialized() == true) contained_val() = std::move(*rhs); return *this; } template <class U> auto operator=(U&& v) -> typename enable_if < is_same<typename decay<U>::type, T>::value, optional& >::type { if (initialized()) { contained_val() = std::forward<U>(v); } else { initialize(std::forward<U>(v)); } return *this; } template <class... Args> void emplace(Args&&... args) { clear(); initialize(std::forward<Args>(args)...); } template <class U, class... Args> void emplace(initializer_list<U> il, Args&&... args) { clear(); initialize<U, Args...>(il, std::forward<Args>(args)...); } // 20.5.4.4, Swap void swap(optional<T>& rhs) noexcept(is_nothrow_move_constructible<T>::value && noexcept(detail_::swap_ns::adl_swap(declval<T&>(), declval<T&>()))) { if (initialized() == true && rhs.initialized() == false) { rhs.initialize(std::move(**this)); clear(); } else if (initialized() == false && rhs.initialized() == true) { initialize(std::move(*rhs)); rhs.clear(); } else if (initialized() == true && rhs.initialized() == true) { using std::swap; swap(**this, *rhs); } } // 20.5.4.5, Observers explicit constexpr operator bool() const noexcept { return initialized(); } constexpr bool has_value() const noexcept { return initialized(); } constexpr T const* operator ->() const { return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr()); } # if OPTIONAL_HAS_MOVE_ACCESSORS == 1 OPTIONAL_MUTABLE_CONSTEXPR T* operator ->() { assert (initialized()); return dataptr(); } constexpr T const& operator *() const& { return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val()); } OPTIONAL_MUTABLE_CONSTEXPR T& operator *() & { assert (initialized()); return contained_val(); } OPTIONAL_MUTABLE_CONSTEXPR T&& operator *() && { assert (initialized()); return constexpr_move(contained_val()); } constexpr T const& value() const& { return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); } OPTIONAL_MUTABLE_CONSTEXPR T& value() & { return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); } OPTIONAL_MUTABLE_CONSTEXPR T&& value() && { if (!initialized()) throw bad_optional_access("bad optional access"); return std::move(contained_val()); } # else T* operator ->() { assert (initialized()); return dataptr(); } constexpr T const& operator *() const { return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val()); } T& operator *() { assert (initialized()); return contained_val(); } constexpr T const& value() const { return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); } T& value() { return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); } # endif # if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 template <class V> constexpr T value_or(V&& v) const& { return *this ? **this : detail_::convert<T>(constexpr_forward<V>(v)); } # if OPTIONAL_HAS_MOVE_ACCESSORS == 1 template <class V> OPTIONAL_MUTABLE_CONSTEXPR T value_or(V&& v) && { return *this ? constexpr_move(const_cast<optional<T>&>(*this).contained_val()) : detail_::convert<T>(constexpr_forward<V>(v)); } # else template <class V> T value_or(V&& v) && { return *this ? constexpr_move(const_cast<optional<T>&>(*this).contained_val()) : detail_::convert<T>(constexpr_forward<V>(v)); } # endif # else template <class V> constexpr T value_or(V&& v) const { return *this ? **this : detail_::convert<T>(constexpr_forward<V>(v)); } # endif // 20.6.3.6, modifiers void reset() noexcept { clear(); } }; template <class T> class optional<T&> { static_assert( !std::is_same<T, nullopt_t>::value, "bad T" ); static_assert( !std::is_same<T, in_place_t>::value, "bad T" ); T* ref; public: // 20.5.5.1, construction/destruction constexpr optional() noexcept : ref(nullptr) {} constexpr optional(nullopt_t) noexcept : ref(nullptr) {} constexpr optional(T& v) noexcept : ref(detail_::static_addressof(v)) {} optional(T&&) = delete; constexpr optional(const optional& rhs) noexcept : ref(rhs.ref) {} explicit constexpr optional(in_place_t, T& v) noexcept : ref(detail_::static_addressof(v)) {} explicit optional(in_place_t, T&&) = delete; ~optional() = default; // 20.5.5.2, mutation optional& operator=(nullopt_t) noexcept { ref = nullptr; return *this; } // optional& operator=(const optional& rhs) noexcept { // ref = rhs.ref; // return *this; // } // optional& operator=(optional&& rhs) noexcept { // ref = rhs.ref; // return *this; // } template <typename U> auto operator=(U&& rhs) noexcept -> typename enable_if < is_same<typename decay<U>::type, optional<T&>>::value, optional& >::type { ref = rhs.ref; return *this; } template <typename U> auto operator=(U&& rhs) noexcept -> typename enable_if < !is_same<typename decay<U>::type, optional<T&>>::value, optional& >::type = delete; void emplace(T& v) noexcept { ref = detail_::static_addressof(v); } void emplace(T&&) = delete; void swap(optional<T&>& rhs) noexcept { std::swap(ref, rhs.ref); } // 20.5.5.3, observers constexpr T* operator->() const { return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, ref); } constexpr T& operator*() const { return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, *ref); } constexpr T& value() const { return ref ? *ref : (throw bad_optional_access("bad optional access"), *ref); } explicit constexpr operator bool() const noexcept { return ref != nullptr; } constexpr bool has_value() const noexcept { return ref != nullptr; } template <class V> constexpr typename decay<T>::type value_or(V&& v) const { return *this ? **this : detail_::convert<typename decay<T>::type>(constexpr_forward<V>(v)); } // x.x.x.x, modifiers void reset() noexcept { ref = nullptr; } }; template <class T> class optional<T&&> { static_assert( sizeof(T) == 0, "optional rvalue references disallowed" ); }; // 20.5.8, Relational operators template <class T> constexpr bool operator==(const optional<T>& x, const optional<T>& y) { return bool(x) != bool(y) ? false : bool(x) == false ? true : *x == *y; } template <class T> constexpr bool operator!=(const optional<T>& x, const optional<T>& y) { return !(x == y); } template <class T> constexpr bool operator<(const optional<T>& x, const optional<T>& y) { return (!y) ? false : (!x) ? true : *x < *y; } template <class T> constexpr bool operator>(const optional<T>& x, const optional<T>& y) { return (y < x); } template <class T> constexpr bool operator<=(const optional<T>& x, const optional<T>& y) { return !(y < x); } template <class T> constexpr bool operator>=(const optional<T>& x, const optional<T>& y) { return !(x < y); } // 20.5.9, Comparison with nullopt template <class T> constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept { return (!x); } template <class T> constexpr bool operator==(nullopt_t, const optional<T>& x) noexcept { return (!x); } template <class T> constexpr bool operator!=(const optional<T>& x, nullopt_t) noexcept { return bool(x); } template <class T> constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept { return bool(x); } template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept { return false; } template <class T> constexpr bool operator<(nullopt_t, const optional<T>& x) noexcept { return bool(x); } template <class T> constexpr bool operator<=(const optional<T>& x, nullopt_t) noexcept { return (!x); } template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept { return true; } template <class T> constexpr bool operator>(const optional<T>& x, nullopt_t) noexcept { return bool(x); } template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept { return false; } template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept { return true; } template <class T> constexpr bool operator>=(nullopt_t, const optional<T>& x) noexcept { return (!x); } // 20.5.10, Comparison with T template <class T> constexpr bool operator==(const optional<T>& x, const T& v) { return bool(x) ? *x == v : false; } template <class T> constexpr bool operator==(const T& v, const optional<T>& x) { return bool(x) ? v == *x : false; } template <class T> constexpr bool operator!=(const optional<T>& x, const T& v) { return bool(x) ? *x != v : true; } template <class T> constexpr bool operator!=(const T& v, const optional<T>& x) { return bool(x) ? v != *x : true; } template <class T> constexpr bool operator<(const optional<T>& x, const T& v) { return bool(x) ? *x < v : true; } template <class T> constexpr bool operator>(const T& v, const optional<T>& x) { return bool(x) ? v > *x : true; } template <class T> constexpr bool operator>(const optional<T>& x, const T& v) { return bool(x) ? *x > v : false; } template <class T> constexpr bool operator<(const T& v, const optional<T>& x) { return bool(x) ? v < *x : false; } template <class T> constexpr bool operator>=(const optional<T>& x, const T& v) { return bool(x) ? *x >= v : false; } template <class T> constexpr bool operator<=(const T& v, const optional<T>& x) { return bool(x) ? v <= *x : false; } template <class T> constexpr bool operator<=(const optional<T>& x, const T& v) { return bool(x) ? *x <= v : true; } template <class T> constexpr bool operator>=(const T& v, const optional<T>& x) { return bool(x) ? v >= *x : true; } // Comparison of optional<T&> with T template <class T> constexpr bool operator==(const optional<T&>& x, const T& v) { return bool(x) ? *x == v : false; } template <class T> constexpr bool operator==(const T& v, const optional<T&>& x) { return bool(x) ? v == *x : false; } template <class T> constexpr bool operator!=(const optional<T&>& x, const T& v) { return bool(x) ? *x != v : true; } template <class T> constexpr bool operator!=(const T& v, const optional<T&>& x) { return bool(x) ? v != *x : true; } template <class T> constexpr bool operator<(const optional<T&>& x, const T& v) { return bool(x) ? *x < v : true; } template <class T> constexpr bool operator>(const T& v, const optional<T&>& x) { return bool(x) ? v > *x : true; } template <class T> constexpr bool operator>(const optional<T&>& x, const T& v) { return bool(x) ? *x > v : false; } template <class T> constexpr bool operator<(const T& v, const optional<T&>& x) { return bool(x) ? v < *x : false; } template <class T> constexpr bool operator>=(const optional<T&>& x, const T& v) { return bool(x) ? *x >= v : false; } template <class T> constexpr bool operator<=(const T& v, const optional<T&>& x) { return bool(x) ? v <= *x : false; } template <class T> constexpr bool operator<=(const optional<T&>& x, const T& v) { return bool(x) ? *x <= v : true; } template <class T> constexpr bool operator>=(const T& v, const optional<T&>& x) { return bool(x) ? v >= *x : true; } // Comparison of optional<T const&> with T template <class T> constexpr bool operator==(const optional<const T&>& x, const T& v) { return bool(x) ? *x == v : false; } template <class T> constexpr bool operator==(const T& v, const optional<const T&>& x) { return bool(x) ? v == *x : false; } template <class T> constexpr bool operator!=(const optional<const T&>& x, const T& v) { return bool(x) ? *x != v : true; } template <class T> constexpr bool operator!=(const T& v, const optional<const T&>& x) { return bool(x) ? v != *x : true; } template <class T> constexpr bool operator<(const optional<const T&>& x, const T& v) { return bool(x) ? *x < v : true; } template <class T> constexpr bool operator>(const T& v, const optional<const T&>& x) { return bool(x) ? v > *x : true; } template <class T> constexpr bool operator>(const optional<const T&>& x, const T& v) { return bool(x) ? *x > v : false; } template <class T> constexpr bool operator<(const T& v, const optional<const T&>& x) { return bool(x) ? v < *x : false; } template <class T> constexpr bool operator>=(const optional<const T&>& x, const T& v) { return bool(x) ? *x >= v : false; } template <class T> constexpr bool operator<=(const T& v, const optional<const T&>& x) { return bool(x) ? v <= *x : false; } template <class T> constexpr bool operator<=(const optional<const T&>& x, const T& v) { return bool(x) ? *x <= v : true; } template <class T> constexpr bool operator>=(const T& v, const optional<const T&>& x) { return bool(x) ? v >= *x : true; } // 20.5.12, Specialized algorithms template <class T> void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y))) { x.swap(y); } template <class T> constexpr optional<typename decay<T>::type> make_optional(T&& v) { return optional<typename decay<T>::type>(constexpr_forward<T>(v)); } template <class X> constexpr optional<X&> make_optional(reference_wrapper<X> v) { return optional<X&>(v.get()); } } // namespace experimental } // namespace std namespace std { template <typename T> struct hash<std::experimental::optional<T>> { typedef typename hash<T>::result_type result_type; typedef std::experimental::optional<T> argument_type; constexpr result_type operator()(argument_type const& arg) const { return arg ? std::hash<T>{}(*arg) : result_type{}; } }; template <typename T> struct hash<std::experimental::optional<T&>> { typedef typename hash<T>::result_type result_type; typedef std::experimental::optional<T&> argument_type; constexpr result_type operator()(argument_type const& arg) const { return arg ? std::hash<T>{}(*arg) : result_type{}; } }; } # undef TR2_OPTIONAL_REQUIRES # undef TR2_OPTIONAL_ASSERTED_EXPRESSION # endif //___OPTIONAL_HPP___
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/optional/LICENSE_1_0.txt
Boost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/optional/test_type_traits.cpp
// Copyright (C) 2011 - 2012 Andrzej Krzemienski. // // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #if (defined __clang__) namespace std { class type_info; } #endif # include "optional.hpp" namespace std { namespace experimental { struct Val { Val(){} Val( Val const & ){} Val( Val && ) noexcept {} Val & operator=( Val const & ) = delete; Val & operator=( Val && ) noexcept = delete; }; struct Safe { Safe(){} Safe( Safe const & ){} Safe( Safe && ) noexcept {} Safe & operator=( Safe const & ){ return *this; } Safe & operator=( Safe && ) noexcept { return *this; } }; struct Unsafe { Unsafe(){} Unsafe( Unsafe const & ){} Unsafe( Unsafe && ){} Unsafe & operator=( Unsafe const & ){ return *this; } Unsafe & operator=( Unsafe && ) { return *this; } }; struct VoidNothrowBoth { VoidNothrowBoth(VoidNothrowBoth&&) noexcept(true) {}; void operator=(VoidNothrowBoth&&) noexcept(true) {}; // note void return type }; static_assert(is_nothrow_move_constructible<Safe>::value, "WTF!"); static_assert(!is_nothrow_move_constructible<Unsafe>::value, "WTF!"); static_assert(is_assignable<Safe&, Safe&&>::value, "WTF!"); static_assert(!is_assignable<Val&, Val&&>::value, "WTF!"); static_assert(is_nothrow_move_assignable<Safe>::value, "WTF!"); static_assert(!is_nothrow_move_assignable<Unsafe>::value, "WTF!"); static_assert(is_nothrow_move_constructible<VoidNothrowBoth>::value, "WTF!"); static_assert(is_nothrow_move_assignable<VoidNothrowBoth>::value, "WTF!"); }} // namespace std::experimental int main() { }
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/optional/test_optional.cpp
// Copyright (C) 2011 - 2017 Andrzej Krzemienski. // // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // The idea and interface is based on Boost.Optional library // authored by Fernando Luis Cacciola Carballal # include "optional.hpp" # include <vector> # include <iostream> # include <functional> # include <complex> struct caller { template <class T> caller(T fun) { fun(); } }; # define CAT2(X, Y) X ## Y # define CAT(X, Y) CAT2(X, Y) # define TEST(NAME) caller CAT(__VAR, __LINE__) = [] enum State { sDefaultConstructed, sValueCopyConstructed, sValueMoveConstructed, sCopyConstructed, sMoveConstructed, sMoveAssigned, sCopyAssigned, sValueCopyAssigned, sValueMoveAssigned, sMovedFrom, sValueConstructed }; struct OracleVal { State s; int i; OracleVal(int i = 0) : s(sValueConstructed), i(i) {} }; struct Oracle { State s; OracleVal val; Oracle() : s(sDefaultConstructed) {} Oracle(const OracleVal& v) : s(sValueCopyConstructed), val(v) {} Oracle(OracleVal&& v) : s(sValueMoveConstructed), val(std::move(v)) {v.s = sMovedFrom;} Oracle(const Oracle& o) : s(sCopyConstructed), val(o.val) {} Oracle(Oracle&& o) : s(sMoveConstructed), val(std::move(o.val)) {o.s = sMovedFrom;} Oracle& operator=(const OracleVal& v) { s = sValueCopyConstructed; val = v; return *this; } Oracle& operator=(OracleVal&& v) { s = sValueMoveConstructed; val = std::move(v); v.s = sMovedFrom; return *this; } Oracle& operator=(const Oracle& o) { s = sCopyConstructed; val = o.val; return *this; } Oracle& operator=(Oracle&& o) { s = sMoveConstructed; val = std::move(o.val); o.s = sMovedFrom; return *this; } }; struct Guard { std::string val; Guard() : val{} {} explicit Guard(std::string s, int = 0) : val(s) {} Guard(const Guard&) = delete; Guard(Guard&&) = delete; void operator=(const Guard&) = delete; void operator=(Guard&&) = delete; }; struct ExplicitStr { std::string s; explicit ExplicitStr(const char* chp) : s(chp) {}; }; struct Date { int i; Date() = delete; Date(int i) : i{i} {}; Date(Date&& d) : i(d.i) { d.i = 0; } Date(const Date&) = delete; Date& operator=(const Date&) = delete; Date& operator=(Date&& d) { i = d.i; d.i = 0; return *this;}; }; bool operator==( Oracle const& a, Oracle const& b ) { return a.val.i == b.val.i; } bool operator!=( Oracle const& a, Oracle const& b ) { return a.val.i != b.val.i; } namespace tr2 = std::experimental; TEST(disengaged_ctor) { tr2::optional<int> o1; assert (!o1); tr2::optional<int> o2 = tr2::nullopt; assert (!o2); tr2::optional<int> o3 = o2; assert (!o3); assert (o1 == tr2::nullopt); assert (o1 == tr2::optional<int>{}); assert (!o1); assert (bool(o1) == false); assert (o2 == tr2::nullopt); assert (o2 == tr2::optional<int>{}); assert (!o2); assert (bool(o2) == false); assert (o3 == tr2::nullopt); assert (o3 == tr2::optional<int>{}); assert (!o3); assert (bool(o3) == false); assert (o1 == o2); assert (o2 == o1); assert (o1 == o3); assert (o3 == o1); assert (o2 == o3); assert (o3 == o2); }; TEST(value_ctor) { OracleVal v; tr2::optional<Oracle> oo1(v); assert (oo1 != tr2::nullopt); assert (oo1 != tr2::optional<Oracle>{}); assert (oo1 == tr2::optional<Oracle>{v}); assert (!!oo1); assert (bool(oo1)); // NA: assert (oo1->s == sValueCopyConstructed); assert (oo1->s == sMoveConstructed); assert (v.s == sValueConstructed); tr2::optional<Oracle> oo2(std::move(v)); assert (oo2 != tr2::nullopt); assert (oo2 != tr2::optional<Oracle>{}); assert (oo2 == oo1); assert (!!oo2); assert (bool(oo2)); // NA: assert (oo2->s == sValueMoveConstructed); assert (oo2->s == sMoveConstructed); assert (v.s == sMovedFrom); { OracleVal v; tr2::optional<Oracle> oo1{tr2::in_place, v}; assert (oo1 != tr2::nullopt); assert (oo1 != tr2::optional<Oracle>{}); assert (oo1 == tr2::optional<Oracle>{v}); assert (!!oo1); assert (bool(oo1)); assert (oo1->s == sValueCopyConstructed); assert (v.s == sValueConstructed); tr2::optional<Oracle> oo2{tr2::in_place, std::move(v)}; assert (oo2 != tr2::nullopt); assert (oo2 != tr2::optional<Oracle>{}); assert (oo2 == oo1); assert (!!oo2); assert (bool(oo2)); assert (oo2->s == sValueMoveConstructed); assert (v.s == sMovedFrom); } }; TEST(assignment) { tr2::optional<int> oi; oi = tr2::optional<int>{1}; assert (*oi == 1); oi = tr2::nullopt; assert (!oi); oi = 2; assert (*oi == 2); oi = {}; assert (!oi); }; template <class T> struct MoveAware { T val; bool moved; MoveAware(T val) : val(val), moved(false) {} MoveAware(MoveAware const&) = delete; MoveAware(MoveAware&& rhs) : val(rhs.val), moved(rhs.moved) { rhs.moved = true; } MoveAware& operator=(MoveAware const&) = delete; MoveAware& operator=(MoveAware&& rhs) { val = (rhs.val); moved = (rhs.moved); rhs.moved = true; return *this; } }; TEST(moved_from_state) { // first, test mock: MoveAware<int> i{1}, j{2}; assert (i.val == 1); assert (!i.moved); assert (j.val == 2); assert (!j.moved); MoveAware<int> k = std::move(i); assert (k.val == 1); assert (!k.moved); assert (i.val == 1); assert (i.moved); k = std::move(j); assert (k.val == 2); assert (!k.moved); assert (j.val == 2); assert (j.moved); // now, test optional tr2::optional<MoveAware<int>> oi{1}, oj{2}; assert (oi); assert (!oi->moved); assert (oj); assert (!oj->moved); tr2::optional<MoveAware<int>> ok = std::move(oi); assert (ok); assert (!ok->moved); assert (oi); assert (oi->moved); ok = std::move(oj); assert (ok); assert (!ok->moved); assert (oj); assert (oj->moved); }; TEST(copy_move_ctor_optional_int) { tr2::optional<int> oi; tr2::optional<int> oj = oi; assert (!oj); assert (oj == oi); assert (oj == tr2::nullopt); assert (!bool(oj)); oi = 1; tr2::optional<int> ok = oi; assert (!!ok); assert (bool(ok)); assert (ok == oi); assert (ok != oj); assert (*ok == 1); tr2::optional<int> ol = std::move(oi); assert (!!ol); assert (bool(ol)); assert (ol == oi); assert (ol != oj); assert (*ol == 1); }; TEST(optional_optional) { tr2::optional<tr2::optional<int>> oi1 = tr2::nullopt; assert (oi1 == tr2::nullopt); assert (!oi1); { tr2::optional<tr2::optional<int>> oi2 {tr2::in_place}; assert (oi2 != tr2::nullopt); assert (bool(oi2)); assert (*oi2 == tr2::nullopt); //assert (!(*oi2)); //std::cout << typeid(**oi2).name() << std::endl; } { tr2::optional<tr2::optional<int>> oi2 {tr2::in_place, tr2::nullopt}; assert (oi2 != tr2::nullopt); assert (bool(oi2)); assert (*oi2 == tr2::nullopt); assert (!*oi2); } { tr2::optional<tr2::optional<int>> oi2 {tr2::optional<int>{}}; assert (oi2 != tr2::nullopt); assert (bool(oi2)); assert (*oi2 == tr2::nullopt); assert (!*oi2); } tr2::optional<int> oi; auto ooi = tr2::make_optional(oi); static_assert( std::is_same<tr2::optional<tr2::optional<int>>, decltype(ooi)>::value, ""); }; TEST(example_guard) { using namespace tr2; //FAILS: optional<Guard> ogx(Guard("res1")); //FAILS: optional<Guard> ogx = "res1"; //FAILS: optional<Guard> ogx("res1"); optional<Guard> oga; // Guard is non-copyable (and non-moveable) optional<Guard> ogb(in_place, "res1"); // initialzes the contained value with "res1" assert (bool(ogb)); assert (ogb->val == "res1"); optional<Guard> ogc(in_place); // default-constructs the contained value assert (bool(ogc)); assert (ogc->val == ""); oga.emplace("res1"); // initialzes the contained value with "res1" assert (bool(oga)); assert (oga->val == "res1"); oga.emplace(); // destroys the contained value and // default-constructs the new one assert (bool(oga)); assert (oga->val == ""); oga = nullopt; // OK: make disengaged the optional Guard assert (!(oga)); //FAILS: ogb = {}; // ERROR: Guard is not Moveable }; void process(){} void process(int ){} void processNil(){} TEST(example1) { using namespace tr2; optional<int> oi; // create disengaged object optional<int> oj = nullopt; // alternative syntax oi = oj; // assign disengaged object optional<int> ok = oj; // ok is disengaged if (oi) assert(false); // 'if oi is engaged...' if (!oi) assert(true); // 'if oi is disengaged...' if (oi != nullopt) assert(false); // 'if oi is engaged...' if (oi == nullopt) assert(true); // 'if oi is disengaged...' assert(oi == ok); // two disengaged optionals compare equal /////////////////////////////////////////////////////////////////////////// optional<int> ol{1}; // ol is engaged; its contained value is 1 ok = 2; // ok becomes engaged; its contained value is 2 oj = ol; // oj becomes engaged; its contained value is 1 assert(oi != ol); // disengaged != engaged assert(ok != ol); // different contained values assert(oj == ol); // same contained value assert(oi < ol); // disengaged < engaged assert(ol < ok); // less by contained value ///////////////////////////////////////////////////////////////////////////// optional<int> om{1}; // om is engaged; its contained value is 1 optional<int> on = om; // on is engaged; its contained value is 1 om = 2; // om is engaged; its contained value is 2 assert (on != om); // on still contains 3. They are not pointers ///////////////////////////////////////////////////////////////////////////// int i = *ol; // i obtains the value contained in ol assert (i == 1); *ol = 9; // the object contained in ol becomes 9 assert(*ol == 9); assert(ol == make_optional(9)); /////////////////////////////////// int p = 1; optional<int> op = p; assert(*op == 1); p = 2; assert(*op == 1); // value contained in op is separated from p //////////////////////////////// if (ol) process(*ol); // use contained value if present else process(); // proceed without contained value if (!om) processNil(); else process(*om); ///////////////////////////////////////// process(ol.value_or(0)); // use 0 if ol is disengaged //////////////////////////////////////////// ok = nullopt; // if ok was engaged calls T's dtor oj = {}; // assigns a temporary disengaged optional }; TEST(example_guard) { using std::experimental::optional; const optional<int> c = 4; int i = *c; // i becomes 4 assert (i == 4); // FAILS: *c = i; // ERROR: cannot assign to const int& }; TEST(example_ref) { using namespace std::experimental; int i = 1; int j = 2; optional<int&> ora; // disengaged optional reference to int optional<int&> orb = i; // contained reference refers to object i *orb = 3; // i becomes 3 // FAILS: ora = j; // ERROR: optional refs do not have assignment from T // FAILS: ora = {j}; // ERROR: optional refs do not have copy/move assignment // FAILS: ora = orb; // ERROR: no copy/move assignment ora.emplace(j); // OK: contained reference refers to object j ora.emplace(i); // OK: contained reference now refers to object i ora = nullopt; // OK: ora becomes disengaged }; template <typename T> T getValue( tr2::optional<T> newVal = tr2::nullopt, tr2::optional<T&> storeHere = tr2::nullopt ) { T cached{}; if (newVal) { cached = *newVal; if (storeHere) { *storeHere = *newVal; // LEGAL: assigning T to T } } return cached; } TEST(example_optional_arg) { int iii = 0; iii = getValue<int>(iii, iii); iii = getValue<int>(iii); iii = getValue<int>(); { using namespace std::experimental; optional<Guard> grd1{in_place, "res1", 1}; // guard 1 initialized optional<Guard> grd2; grd2.emplace("res2", 2); // guard 2 initialized grd1 = nullopt; // guard 1 released } // guard 2 released (in dtor) }; std::tuple<Date, Date, Date> getStartMidEnd() { return std::tuple<Date, Date, Date>{Date{1}, Date{2}, Date{3}}; } void run(Date const&, Date const&, Date const&) {} TEST(example_date) { using namespace std::experimental; optional<Date> start, mid, end; // Date doesn't have default ctor (no good default date) std::tie(start, mid, end) = getStartMidEnd(); run(*start, *mid, *end); }; std::experimental::optional<char> readNextChar(){ return{}; } void run(std::experimental::optional<std::string>) {} void run(std::complex<double>) {} template <class T> void assign_norebind(tr2::optional<T&>& optref, T& obj) { if (optref) *optref = obj; else optref.emplace(obj); } template <typename T> void unused(T&&) {} TEST(example_conceptual_model) { using namespace std::experimental; optional<int> oi = 0; optional<int> oj = 1; optional<int> ok = nullopt; oi = 1; oj = nullopt; ok = 0; unused(oi == nullopt); unused(oj == 0); unused(ok == 1); }; TEST(example_rationale) { using namespace std::experimental; if (optional<char> ch = readNextChar()) { unused(ch); // ... } ////////////////////////////////// optional<int> opt1 = nullopt; optional<int> opt2 = {}; opt1 = nullopt; opt2 = {}; if (opt1 == nullopt) {} if (!opt2) {} if (opt2 == optional<int>{}) {} //////////////////////////////// run(nullopt); // pick the second overload // FAILS: run({}); // ambiguous if (opt1 == nullopt) {} // fine // FAILS: if (opt2 == {}) {} // ilegal //////////////////////////////// assert (optional<unsigned>{} < optional<unsigned>{0}); assert (optional<unsigned>{0} < optional<unsigned>{1}); assert (!(optional<unsigned>{} < optional<unsigned>{}) ); assert (!(optional<unsigned>{1} < optional<unsigned>{1})); assert (optional<unsigned>{} != optional<unsigned>{0}); assert (optional<unsigned>{0} != optional<unsigned>{1}); assert (optional<unsigned>{} == optional<unsigned>{} ); assert (optional<unsigned>{0} == optional<unsigned>{0}); ///////////////////////////////// optional<int> o; o = make_optional(1); // copy/move assignment o = 1; // assignment from T o.emplace(1); // emplacement //////////////////////////////////// int isas = 0, i = 9; optional<int&> asas = i; assign_norebind(asas, isas); ///////////////////////////////////// ////tr2::optional<std::vector<int>> ov2 = {2, 3}; ////assert (bool(ov2)); ////assert ((*ov2)[1] == 3); //// //////////////////////////////// ////std::vector<int> v = {1, 2, 4, 8}; ////optional<std::vector<int>> ov = {1, 2, 4, 8}; ////assert (v == *ov); //// ////ov = {1, 2, 4, 8}; ////std::allocator<int> a; ////optional<std::vector<int>> ou { in_place, {1, 2, 4, 8}, a }; ////assert (ou == ov); ////////////////////////////// // inconvenient syntax: { tr2::optional<std::vector<int>> ov2{tr2::in_place, {2, 3}}; assert (bool(ov2)); assert ((*ov2)[1] == 3); //////////////////////////// std::vector<int> v = {1, 2, 4, 8}; optional<std::vector<int>> ov{tr2::in_place, {1, 2, 4, 8}}; assert (v == *ov); ov.emplace({1, 2, 4, 8}); /* std::allocator<int> a; optional<std::vector<int>> ou { in_place, {1, 2, 4, 8}, a }; assert (ou == ov); */ } ///////////////////////////////// { typedef int T; optional<optional<T>> ot {in_place}; optional<optional<T>> ou {in_place, nullopt}; optional<optional<T>> ov {optional<T>{}}; optional<int> oi; auto ooi = make_optional(oi); static_assert( std::is_same<optional<optional<int>>, decltype(ooi)>::value, ""); } }; bool fun(std::string , std::experimental::optional<int> oi = std::experimental::nullopt) { return bool(oi); } TEST(example_converting_ctor) { using namespace std::experimental; assert (true == fun("dog", 2)); assert (false == fun("dog")); assert (false == fun("dog", nullopt)); // just to be explicit }; TEST(bad_comparison) { tr2::optional<int> oi, oj; int i; bool b = (oi == oj); b = (oi >= i); b = (oi == i); unused(b); }; //// NOT APPLICABLE ANYMORE ////TEST(perfect_ctor) ////{ //// //tr2::optional<std::string> ois = "OS"; //// assert (*ois == "OS"); //// //// // FAILS: tr2::optional<ExplicitStr> oes = "OS"; //// tr2::optional<ExplicitStr> oes{"OS"}; //// assert (oes->s == "OS"); ////}; TEST(value_or) { tr2::optional<int> oi = 1; int i = oi.value_or(0); assert (i == 1); oi = tr2::nullopt; assert (oi.value_or(3) == 3); tr2::optional<std::string> os{"AAA"}; assert (os.value_or("BBB") == "AAA"); os = {}; assert (os.value_or("BBB") == "BBB"); }; TEST(reset) { using namespace std::experimental; optional<int> oi {1}; oi.reset(); assert (!oi); int i = 1; optional<const int&> oir {i}; oir.reset(); assert (!oir); }; TEST(mixed_order) { using namespace std::experimental; optional<int> oN {nullopt}; optional<int> o0 {0}; optional<int> o1 {1}; assert ( (oN < 0)); assert ( (oN < 1)); assert (!(o0 < 0)); assert ( (o0 < 1)); assert (!(o1 < 0)); assert (!(o1 < 1)); assert (!(oN >= 0)); assert (!(oN >= 1)); assert ( (o0 >= 0)); assert (!(o0 >= 1)); assert ( (o1 >= 0)); assert ( (o1 >= 1)); assert (!(oN > 0)); assert (!(oN > 1)); assert (!(o0 > 0)); assert (!(o0 > 1)); assert ( (o1 > 0)); assert (!(o1 > 1)); assert ( (oN <= 0)); assert ( (oN <= 1)); assert ( (o0 <= 0)); assert ( (o0 <= 1)); assert (!(o1 <= 0)); assert ( (o1 <= 1)); assert ( (0 > oN)); assert ( (1 > oN)); assert (!(0 > o0)); assert ( (1 > o0)); assert (!(0 > o1)); assert (!(1 > o1)); assert (!(0 <= oN)); assert (!(1 <= oN)); assert ( (0 <= o0)); assert (!(1 <= o0)); assert ( (0 <= o1)); assert ( (1 <= o1)); assert (!(0 < oN)); assert (!(1 < oN)); assert (!(0 < o0)); assert (!(1 < o0)); assert ( (0 < o1)); assert (!(1 < o1)); assert ( (0 >= oN)); assert ( (1 >= oN)); assert ( (0 >= o0)); assert ( (1 >= o0)); assert (!(0 >= o1)); assert ( (1 >= o1)); }; struct BadRelops { int i; }; constexpr bool operator<(BadRelops a, BadRelops b) { return a.i < b.i; } constexpr bool operator>(BadRelops a, BadRelops b) { return a.i < b.i; } // intentional error! TEST(bad_relops) { using namespace std::experimental; BadRelops a{1}, b{2}; assert (a < b); assert (a > b); optional<BadRelops> oa = a, ob = b; assert (oa < ob); assert (!(oa > ob)); assert (oa < b); assert (oa > b); optional<BadRelops&> ra = a, rb = b; assert (ra < rb); assert (!(ra > rb)); assert (ra < b); assert (ra > b); }; TEST(mixed_equality) { using namespace std::experimental; assert (make_optional(0) == 0); assert (make_optional(1) == 1); assert (make_optional(0) != 1); assert (make_optional(1) != 0); optional<int> oN {nullopt}; optional<int> o0 {0}; optional<int> o1 {1}; assert (o0 == 0); assert ( 0 == o0); assert (o1 == 1); assert ( 1 == o1); assert (o1 != 0); assert ( 0 != o1); assert (o0 != 1); assert ( 1 != o0); assert ( 1 != oN); assert ( 0 != oN); assert (oN != 1); assert (oN != 0); assert (!( 1 == oN)); assert (!( 0 == oN)); assert (!(oN == 1)); assert (!(oN == 0)); std::string cat{"cat"}, dog{"dog"}; optional<std::string> oNil{}, oDog{"dog"}, oCat{"cat"}; assert (oCat == cat); assert ( cat == oCat); assert (oDog == dog); assert ( dog == oDog); assert (oDog != cat); assert ( cat != oDog); assert (oCat != dog); assert ( dog != oCat); assert ( dog != oNil); assert ( cat != oNil); assert (oNil != dog); assert (oNil != cat); assert (!( dog == oNil)); assert (!( cat == oNil)); assert (!(oNil == dog)); assert (!(oNil == cat)); }; TEST(const_propagation) { using namespace std::experimental; optional<int> mmi{0}; static_assert(std::is_same<decltype(*mmi), int&>::value, "WTF"); const optional<int> cmi{0}; static_assert(std::is_same<decltype(*cmi), const int&>::value, "WTF"); optional<const int> mci{0}; static_assert(std::is_same<decltype(*mci), const int&>::value, "WTF"); optional<const int> cci{0}; static_assert(std::is_same<decltype(*cci), const int&>::value, "WTF"); }; static_assert(std::is_base_of<std::logic_error, std::experimental::bad_optional_access>::value, ""); TEST(safe_value) { using namespace std::experimental; try { optional<int> ovN{}, ov1{1}; int& r1 = ov1.value(); assert (r1 == 1); try { ovN.value(); assert (false); } catch (bad_optional_access const&) { } { // ref variant int i1 = 1; optional<int&> orN{}, or1{i1}; int& r2 = or1.value(); assert (r2 == 1); try { orN.value(); assert (false); } catch (bad_optional_access const&) { } } } catch(...) { assert (false); } }; TEST(optional_ref) { using namespace tr2; // FAILS: optional<int&&> orr; // FAILS: optional<nullopt_t&> on; int i = 8; optional<int&> ori; assert (!ori); ori.emplace(i); assert (bool(ori)); assert (*ori == 8); assert (&*ori == &i); *ori = 9; assert (i == 9); // FAILS: int& ir = ori.value_or(i); int ii = ori.value_or(i); assert (ii == 9); ii = 7; assert (*ori == 9); int j = 22; auto&& oj = make_optional(std::ref(j)); *oj = 23; assert (&*oj == &j); assert (j == 23); }; TEST(optional_ref_const_propagation) { using namespace std::experimental; int i = 9; const optional<int&> mi = i; int& r = *mi; optional<const int&> ci = i; static_assert(std::is_same<decltype(*mi), int&>::value, "WTF"); static_assert(std::is_same<decltype(*ci), const int&>::value, "WTF"); unused(r); }; TEST(optional_ref_assign) { using namespace std::experimental; int i = 9; optional<int&> ori = i; int j = 1; ori = optional<int&>{j}; ori = {j}; // FAILS: ori = j; optional<int&> orx = ori; ori = orx; optional<int&> orj = j; assert (ori); assert (*ori == 1); assert (ori == orj); assert (i == 9); *ori = 2; assert (*ori == 2); assert (ori == 2); assert (2 == ori); assert (ori != 3); assert (ori == orj); assert (j == 2); assert (i == 9); ori = {}; assert (!ori); assert (ori != orj); assert (j == 2); assert (i == 9); }; TEST(optional_swap) { namespace tr2 = std::experimental; tr2::optional<int> oi {1}, oj {}; swap(oi, oj); assert (oj); assert (*oj == 1); assert (!oi); static_assert(noexcept(swap(oi, oj)), "swap() is not noexcept"); }; TEST(optional_ref_swap) { using namespace std::experimental; int i = 0; int j = 1; optional<int&> oi = i; optional<int&> oj = j; assert (&*oi == &i); assert (&*oj == &j); swap(oi, oj); assert (&*oi == &j); assert (&*oj == &i); }; TEST(optional_initialization) { using namespace tr2; using std::string; string s = "STR"; optional<string> os{s}; optional<string> ot = s; optional<string> ou{"STR"}; optional<string> ov = string{"STR"}; }; #include <unordered_set> TEST(optional_hashing) { using namespace tr2; using std::string; std::hash<int> hi; std::hash<optional<int>> hoi; std::hash<string> hs; std::hash<optional<string>> hos; assert (hi(0) == hoi(optional<int>{0})); assert (hi(1) == hoi(optional<int>{1})); assert (hi(3198) == hoi(optional<int>{3198})); assert (hs("") == hos(optional<string>{""})); assert (hs("0") == hos(optional<string>{"0"})); assert (hs("Qa1#") == hos(optional<string>{"Qa1#"})); std::unordered_set<optional<string>> set; assert(set.find({"Qa1#"}) == set.end()); set.insert({"0"}); assert(set.find({"Qa1#"}) == set.end()); set.insert({"Qa1#"}); assert(set.find({"Qa1#"}) != set.end()); }; // optional_ref_emulation template <class T> struct generic { typedef T type; }; template <class U> struct generic<U&> { typedef std::reference_wrapper<U> type; }; template <class T> using Generic = typename generic<T>::type; template <class X> bool generic_fun() { std::experimental::optional<Generic<X>> op; return bool(op); } TEST(optional_ref_emulation) { using namespace std::experimental; optional<Generic<int>> oi = 1; assert (*oi == 1); int i = 8; int j = 4; optional<Generic<int&>> ori {i}; assert (*ori == 8); assert ((void*)&*ori != (void*)&i); // !DIFFERENT THAN optional<T&> *ori = j; assert (*ori == 4); }; # if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 TEST(moved_on_value_or) { using namespace tr2; optional<Oracle> oo{in_place}; assert (oo); assert (oo->s == sDefaultConstructed); Oracle o = std::move(oo).value_or( Oracle{OracleVal{}} ); assert (oo); assert (oo->s == sMovedFrom); assert (o.s == sMoveConstructed); optional<MoveAware<int>> om {in_place, 1}; assert (om); assert (om->moved == false); /*MoveAware<int> m =*/ std::move(om).value_or( MoveAware<int>{1} ); assert (om); assert (om->moved == true); # if OPTIONAL_HAS_MOVE_ACCESSORS == 1 { Date d = optional<Date>{in_place, 1}.value(); assert (d.i); // to silence compiler warning Date d2 = *optional<Date>{in_place, 1}; assert (d2.i); // to silence compiler warning } # endif }; # endif TEST(optional_ref_hashing) { using namespace tr2; using std::string; std::hash<int> hi; std::hash<optional<int&>> hoi; std::hash<string> hs; std::hash<optional<string&>> hos; int i0 = 0; int i1 = 1; assert (hi(0) == hoi(optional<int&>{i0})); assert (hi(1) == hoi(optional<int&>{i1})); string s{""}; string s0{"0"}; string sCAT{"CAT"}; assert (hs("") == hos(optional<string&>{s})); assert (hs("0") == hos(optional<string&>{s0})); assert (hs("CAT") == hos(optional<string&>{sCAT})); std::unordered_set<optional<string&>> set; assert(set.find({sCAT}) == set.end()); set.insert({s0}); assert(set.find({sCAT}) == set.end()); set.insert({sCAT}); assert(set.find({sCAT}) != set.end()); }; struct Combined { int m = 0; int n = 1; constexpr Combined() : m{5}, n{6} {} constexpr Combined(int m, int n) : m{m}, n{n} {} }; struct Nasty { int m = 0; int n = 1; constexpr Nasty() : m{5}, n{6} {} constexpr Nasty(int m, int n) : m{m}, n{n} {} int operator&() { return n; } int operator&() const { return n; } }; TEST(arrow_operator) { using namespace std::experimental; optional<Combined> oc1{in_place, 1, 2}; assert (oc1); assert (oc1->m == 1); assert (oc1->n == 2); optional<Nasty> on{in_place, 1, 2}; assert (on); assert (on->m == 1); assert (on->n == 2); }; TEST(arrow_wit_optional_ref) { using namespace std::experimental; Combined c{1, 2}; optional<Combined&> oc = c; assert (oc); assert (oc->m == 1); assert (oc->n == 2); Nasty n{1, 2}; Nasty m{3, 4}; Nasty p{5, 6}; optional<Nasty&> on{n}; assert (on); assert (on->m == 1); assert (on->n == 2); on = {m}; assert (on); assert (on->m == 3); assert (on->n == 4); on.emplace(p); assert (on); assert (on->m == 5); assert (on->n == 6); optional<Nasty&> om{in_place, n}; assert (om); assert (om->m == 1); assert (om->n == 2); }; TEST(no_dangling_reference_in_value) { // this mostly tests compiler warnings using namespace std::experimental; optional<int> oi {2}; unused (oi.value()); const optional<int> coi {3}; unused (coi.value()); }; struct CountedObject { static int _counter; bool _throw; CountedObject(bool b) : _throw(b) { ++_counter; } CountedObject(CountedObject const& rhs) : _throw(rhs._throw) { if (_throw) throw int(); } ~CountedObject() { --_counter; } }; int CountedObject::_counter = 0; TEST(exception_safety) { using namespace std::experimental; try { optional<CountedObject> oo(in_place, true); // throw optional<CountedObject> o1(oo); } catch(...) { // } assert(CountedObject::_counter == 0); try { optional<CountedObject> oo(in_place, true); // throw optional<CountedObject> o1(std::move(oo)); // now move } catch(...) { // } assert(CountedObject::_counter == 0); }; TEST(nested_optional) { using namespace std::experimental; optional<optional<optional<int>>> o1 {nullopt}; assert (!o1); optional<optional<optional<int>>> o2 {in_place, nullopt}; assert (o2); assert (!*o2); optional<optional<optional<int>>> o3 (in_place, in_place, nullopt); assert (o3); assert (*o3); assert (!**o3); }; TEST(three_ways_of_having_value) { using namespace std::experimental; optional<int> oN, o1 (1); assert (!oN); assert (!oN.has_value()); assert (oN == nullopt); assert (o1); assert (o1.has_value()); assert (o1 != nullopt); assert (bool(oN) == oN.has_value()); assert (bool(o1) == o1.has_value()); int i = 1; optional<int&> rN, r1 (i); assert (!rN); assert (!rN.has_value()); assert (rN == nullopt); assert (r1); assert (r1.has_value()); assert (r1 != nullopt); assert (bool(rN) == rN.has_value()); assert (bool(r1) == r1.has_value()); }; //// constexpr tests // these 4 classes have different noexcept signatures in move operations struct NothrowBoth { NothrowBoth(NothrowBoth&&) noexcept(true) {}; void operator=(NothrowBoth&&) noexcept(true) {}; }; struct NothrowCtor { NothrowCtor(NothrowCtor&&) noexcept(true) {}; void operator=(NothrowCtor&&) noexcept(false) {}; }; struct NothrowAssign { NothrowAssign(NothrowAssign&&) noexcept(false) {}; void operator=(NothrowAssign&&) noexcept(true) {}; }; struct NothrowNone { NothrowNone(NothrowNone&&) noexcept(false) {}; void operator=(NothrowNone&&) noexcept(false) {}; }; void test_noexcept() { { tr2::optional<NothrowBoth> b1, b2; static_assert(noexcept(tr2::optional<NothrowBoth>{tr2::constexpr_move(b1)}), "bad noexcept!"); static_assert(noexcept(b1 = tr2::constexpr_move(b2)), "bad noexcept!"); } { tr2::optional<NothrowCtor> c1, c2; static_assert(noexcept(tr2::optional<NothrowCtor>{tr2::constexpr_move(c1)}), "bad noexcept!"); static_assert(!noexcept(c1 = tr2::constexpr_move(c2)), "bad noexcept!"); } { tr2::optional<NothrowAssign> a1, a2; static_assert(!noexcept(tr2::optional<NothrowAssign>{tr2::constexpr_move(a1)}), "bad noexcept!"); static_assert(!noexcept(a1 = tr2::constexpr_move(a2)), "bad noexcept!"); } { tr2::optional<NothrowNone> n1, n2; static_assert(!noexcept(tr2::optional<NothrowNone>{tr2::constexpr_move(n1)}), "bad noexcept!"); static_assert(!noexcept(n1 = tr2::constexpr_move(n2)), "bad noexcept!"); } } void constexpr_test_disengaged() { constexpr tr2::optional<int> g0{}; constexpr tr2::optional<int> g1{tr2::nullopt}; static_assert( !g0, "initialized!" ); static_assert( !g1, "initialized!" ); static_assert( bool(g1) == bool(g0), "ne!" ); static_assert( g1 == g0, "ne!" ); static_assert( !(g1 != g0), "ne!" ); static_assert( g1 >= g0, "ne!" ); static_assert( !(g1 > g0), "ne!" ); static_assert( g1 <= g0, "ne!" ); static_assert( !(g1 <g0), "ne!" ); static_assert( g1 == tr2::nullopt, "!" ); static_assert( !(g1 != tr2::nullopt), "!" ); static_assert( g1 <= tr2::nullopt, "!" ); static_assert( !(g1 < tr2::nullopt), "!" ); static_assert( g1 >= tr2::nullopt, "!" ); static_assert( !(g1 > tr2::nullopt), "!" ); static_assert( (tr2::nullopt == g0), "!" ); static_assert( !(tr2::nullopt != g0), "!" ); static_assert( (tr2::nullopt >= g0), "!" ); static_assert( !(tr2::nullopt > g0), "!" ); static_assert( (tr2::nullopt <= g0), "!" ); static_assert( !(tr2::nullopt < g0), "!" ); static_assert( (g1 != tr2::optional<int>(1)), "!" ); static_assert( !(g1 == tr2::optional<int>(1)), "!" ); static_assert( (g1 < tr2::optional<int>(1)), "!" ); static_assert( (g1 <= tr2::optional<int>(1)), "!" ); static_assert( !(g1 > tr2::optional<int>(1)), "!" ); static_assert( !(g1 > tr2::optional<int>(1)), "!" ); } constexpr tr2::optional<int> g0{}; constexpr tr2::optional<int> g2{2}; static_assert( g2, "not initialized!" ); static_assert( *g2 == 2, "not 2!" ); static_assert( g2 == tr2::optional<int>(2), "not 2!" ); static_assert( g2 != g0, "eq!" ); # if OPTIONAL_HAS_MOVE_ACCESSORS == 1 static_assert( *tr2::optional<int>{3} == 3, "WTF!" ); static_assert( tr2::optional<int>{3}.value() == 3, "WTF!" ); static_assert( tr2::optional<int>{3}.value_or(1) == 3, "WTF!" ); static_assert( tr2::optional<int>{}.value_or(4) == 4, "WTF!" ); # endif constexpr tr2::optional<Combined> gc0{tr2::in_place}; static_assert(gc0->n == 6, "WTF!"); // optional refs int gi = 0; constexpr tr2::optional<int&> gori = gi; constexpr tr2::optional<int&> gorn{}; constexpr int& gri = *gori; static_assert(gori, "WTF"); static_assert(!gorn, "WTF"); static_assert(gori != tr2::nullopt, "WTF"); static_assert(gorn == tr2::nullopt, "WTF"); static_assert(&gri == &*gori, "WTF"); constexpr int gci = 1; constexpr tr2::optional<int const&> gorci = gci; constexpr tr2::optional<int const&> gorcn{}; static_assert(gorcn < gorci, "WTF"); static_assert(gorcn <= gorci, "WTF"); static_assert(gorci == gorci, "WTF"); static_assert(*gorci == 1, "WTF"); static_assert(gorci == gci, "WTF"); namespace constexpr_optional_ref_and_arrow { using namespace std::experimental; constexpr Combined c{1, 2}; constexpr optional<Combined const&> oc = c; static_assert(oc, "WTF!"); static_assert(oc->m == 1, "WTF!"); static_assert(oc->n == 2, "WTF!"); } #if OPTIONAL_HAS_CONSTEXPR_INIT_LIST namespace InitList { using namespace std::experimental; struct ConstInitLister { template <typename T> constexpr ConstInitLister(std::initializer_list<T> il) : len (il.size()) {} size_t len; }; constexpr ConstInitLister CIL {2, 3, 4}; static_assert(CIL.len == 3, "WTF!"); constexpr optional<ConstInitLister> oil {in_place, {4, 5, 6, 7}}; static_assert(oil, "WTF!"); static_assert(oil->len == 4, "WTF!"); } #endif // OPTIONAL_HAS_CONSTEXPR_INIT_LIST // end constexpr tests #include <string> struct VEC { std::vector<int> v; template <typename... X> VEC( X&&...x) : v(std::forward<X>(x)...) {} template <typename U, typename... X> VEC(std::initializer_list<U> il, X&&...x) : v(il, std::forward<X>(x)...) {} }; int main() { tr2::optional<int> oi = 1; assert (bool(oi)); oi.operator=({}); assert (!oi); VEC v = {5, 6}; if (OPTIONAL_HAS_THIS_RVALUE_REFS) std::cout << "Optional has rvalue references for *this" << std::endl; else std::cout << "Optional doesn't have rvalue references for *this" << std::endl; if (OPTIONAL_HAS_CONSTEXPR_INIT_LIST) std::cout << "Optional has constexpr initializer_list" << std::endl; else std::cout << "Optional doesn't have constexpr initializer_list" << std::endl; if (OPTIONAL_HAS_MOVE_ACCESSORS) std::cout << "Optional has constexpr move accessors" << std::endl; else std::cout << "Optional doesn't have constexpr move accessors" << std::endl; }
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/optional/CMakeLists.txt
# if CMAKE_VERSION >= 3.0 this project installs an INTERFACE target for # the optional.hpp file. # # Usage: # # In your project's CMakeLists.txt: # # find_package(akrzemi1_optional REQUIRED) # ... # target_link_libraries(mytarget ... akrzemi1::optional ...) # # In your C++ source file: # # #include "akrzemi1/optional.hpp" # project(optional) cmake_minimum_required(VERSION 2.8) enable_testing() if(CMAKE_VERSION VERSION_LESS 3.1) set(CMAKE_CXX_FLAGS "-std=c++11") elseif(NOT CMAKE_CXX_STANDARD) # don't override c++ standard if already set set(CMAKE_CXX_STANDARD 11) endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") # if CMAKE_VERSION >= 3.0 if(NOT (CMAKE_VERSION VERSION_LESS 3.0)) add_library(optional INTERFACE) target_include_directories(optional INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include>) install(TARGETS optional EXPORT optional-targets) install(EXPORT optional-targets DESTINATION lib/cmake/akrzemi1_optional FILE akrzemi1_optional-config.cmake NAMESPACE akrzemi1::) install(FILES optional.hpp DESTINATION include/akrzemi1) endif() add_executable(test_optional test_optional.cpp) add_executable(test_type_traits test_type_traits.cpp) add_test(test_optional test_optional) add_test(test_type_traits test_type_traits)
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/optional/README.md
Optional ======== A single-header header-only library for representing optional (nullable) objects for C++14 (and C++11 to some extent) and passing them by value. This is the reference implementation of proposal N3793 (see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3793.html). Optional is now accepted into Library Fundamentals Technical Specification (see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3848.html). The interface is based on Fernando Cacciola's Boost.Optional library (see http://www.boost.org/doc/libs/1_52_0/libs/optional/doc/html/index.html) Usage ----- ```cpp optional<int> readInt(); // this function may return int or a not-an-int if (optional<int> oi = readInt()) // did I get a real int cout << "my int is: " << *oi; // use my int else cout << "I have no int"; ``` For more usage examples and the overview see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3527.html Supported compilers ------------------- Clang 3.2, Clang 3.4, G++ 4.7.2, G++ 4.8.1. Tested only with libstdc++, versions 20130531, 20120920, 20110428. Others have reported it also works with libc++. Known Issues ------------ - Currently, the reference (and the only known) implementation of certain pieces of functionality explore what C++11 identifies as undefined behavior (see national body comment FI 15: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3770.html#FI15). This is mostly why Optional was removed from C++14 and put into Library Fundamentals TS. Luckily what the Standard identifies as UB is well defined on all known platforms. We expect that the C++14 wil fix this problem, so that our trick becomes well-defined. - In libstdc++ versions below 20130531 the constructor taking `initializer_list` argument is not `constexpr`. This is because `initializer_list` operations are not `constexpr` in C++11. This works however in version 20130531. It is also not enabled for libc++ because I do not have access to it and do not know if it provides `constexpr` `initializer_list`. - In G++ 4.7.2 and 4.8.0 member function `value_or` does not have rvalue reference overload. These compilers do not support rvalue overloding on `*this`. - In order for the library to work with slightly older compilers, we emulate some missing type traits. On some platforms we cannot correctly detect the available features, and attempts at workarounds for missing type trait definitions can cause compile-time errors. Define macro `TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS` if you know that all the necessary type traits are defined, and no emulation is required. License ------- Distributed under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt).
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/utils/thread.hpp
/* Thread related functions (C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (3 commits) File Created: Jun 2016 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef QUICKCPPLIB_UTILS_THREAD_HPP #define QUICKCPPLIB_UTILS_THREAD_HPP #include "../config.hpp" #ifdef __linux__ #include <sys/syscall.h> // for SYS_gettid #include <unistd.h> // for syscall() #endif #if defined(__APPLE__) #include <mach/mach_init.h> // for mach_thread_self #include <mach/mach_port.h> // for mach_port_deallocate #endif #ifdef __FreeBSD__ #include <pthread_np.h> // for pthread_getthreadid_np #endif QUICKCPPLIB_NAMESPACE_BEGIN namespace utils { namespace thread { #ifdef _WIN32 namespace win32 { extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(void); } #endif //! The thread id of the calling thread inline unsigned this_thread_id() noexcept { #ifdef _WIN32 return (unsigned) win32::GetCurrentThreadId(); #elif defined(__linux__) return (unsigned) syscall(SYS_gettid); #elif defined(__APPLE__) thread_port_t tid = mach_thread_self(); mach_port_deallocate(mach_task_self(), tid); return (unsigned) tid; #else return (unsigned) pthread_getthreadid_np(); #endif } } } QUICKCPPLIB_NAMESPACE_END #endif
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/algorithm/small_prng.hpp
/* Small PRNG (C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (3 commits) File Created: Sept 2016 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef QUICKCPPLIB_ALGORITHM_SMALL_PRNG_HPP #define QUICKCPPLIB_ALGORITHM_SMALL_PRNG_HPP #include "../config.hpp" #include "../utils/thread.hpp" #include <cstdint> #include <iterator> QUICKCPPLIB_NAMESPACE_BEGIN namespace algorithm { namespace small_prng { /*! \class small_prng \brief From http://burtleburtle.net/bob/rand/smallprng.html, a not awful fast random number source. */ class small_prng { protected: uint32_t a; uint32_t b; uint32_t c; uint32_t d; static inline uint32_t rot(uint32_t x, uint32_t k) noexcept { return (((x) << (k)) | ((x) >> (32 - (k)))); } public: //! The type produced by the small prng using value_type = uint32_t; //! Construct an instance with `seed` explicit small_prng(uint32_t seed = 0xdeadbeef) noexcept { a = 0xf1ea5eed; b = c = d = seed; for(size_t i = 0; i < 20; ++i) (*this)(); } //! Return `value_type` of pseudo-randomness inline uint32_t operator()() noexcept { uint32_t e = a - rot(b, 27); a = b ^ rot(c, 17); b = c + d; c = d + e; d = e + a; return d; } }; //! \brief A thread safe small prng seeded with the thread id inline small_prng &thread_local_prng() { #ifdef QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 static thread_local small_prng v(utils::thread::this_thread_id()); return v; #else static QUICKCPPLIB_THREAD_LOCAL small_prng *v; if(!v) v = new small_prng(utils::thread::this_thread_id()); // leaks memory return *v; #endif } //! A `random_shuffle` implementation which uses the small prng template <class RandomIt> void random_shuffle(RandomIt first, RandomIt last, small_prng &r = thread_local_prng()) { typename std::iterator_traits<RandomIt>::difference_type i, n; n = last - first; for(i = n - 1; i > 0; --i) { using std::swap; swap(first[i], first[r() % (i + 1)]); } } } } QUICKCPPLIB_NAMESPACE_END #endif
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/algorithm/memory.hpp
/* Memory algorithms (C) 2018-2020 Niall Douglas <http://www.nedproductions.biz/> (7 commits) File Created: Jun 2018 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef QUICKCPPLIB_ALGORITHM_MEMORY_HPP #define QUICKCPPLIB_ALGORITHM_MEMORY_HPP #include "../config.hpp" #include <cstring> // for memcpy QUICKCPPLIB_NAMESPACE_BEGIN namespace algorithm { namespace memory { QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) constexpr inline T *cmemcpy(T *dst, const T *src, size_t num) { #if __cpp_lib_is_constant_evaluated >= 201811 if(std::is_constant_evaluated()) { #endif for(size_t n = 0; n < num; n++) { dst[n] = src[n]; } #if __cpp_lib_is_constant_evaluated >= 201811 } else { memcpy(dst, src, num); } #endif return dst; } QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) constexpr inline int cmemcmp(const T *a, const T *b, size_t num) { #if __cpp_lib_is_constant_evaluated >= 201811 if(std::is_constant_evaluated()) { #endif for(size_t n = 0; n < num; n++) { if(a[n] < b[n]) { return -1; } else if(a[n] > b[n]) { return 1; } } return 0; #if __cpp_lib_is_constant_evaluated >= 201811 } else { return memcmp(a, b, num); } #endif } QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) constexpr inline T *cmemset(T *dst, T value, size_t num) { #if __cpp_lib_is_constant_evaluated >= 201811 if(std::is_constant_evaluated()) { #endif for(size_t n = 0; n < num; n++) { dst[n] = value; } #if __cpp_lib_is_constant_evaluated >= 201811 } else { memset(dst, (int) value, num); } #endif return dst; } } // namespace memory } // namespace algorithm QUICKCPPLIB_NAMESPACE_END #endif
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/algorithm/hash.hpp
/* Hash algorithms (C) 2016-2021 Niall Douglas <http://www.nedproductions.biz/> (6 commits) File Created: Aug 2016 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef QUICKCPPLIB_ALGORITHM_HASH_HPP #define QUICKCPPLIB_ALGORITHM_HASH_HPP #include "../uint128.hpp" #include "memory.hpp" #include <cassert> #include <cstdint> #include <type_traits> QUICKCPPLIB_NAMESPACE_BEGIN namespace algorithm { namespace hash { //! \brief A STL compatible hash which passes through its input template <class T> struct passthru_hash { size_t operator()(T v) const { return static_cast<size_t>(v); } }; //! \brief A STL compatible hash based on the high quality FNV1 hash algorithm template <class T> struct fnv1a_hash { size_t operator()(T v) const { #if QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH < 64 using working_type = uint32_t; static constexpr working_type basis = 2166136261U, prime = 16777619U; #else using working_type = uint64_t; static constexpr working_type basis = 14695981039346656037ULL, prime = 1099511628211ULL; #endif const unsigned char *_v = (const unsigned char *) &v; working_type ret = basis; for(size_t n = 0; n < sizeof(T); n++) { ret ^= (working_type) _v[n]; ret *= prime; } #if !defined(__SIZEOF_SIZE_T__) || (__SIZEOF_SIZE_T__ * __CHAR_BIT__) < QUICKCPPLIB_PLATFORM_NATIVE_BITLENGTH return size_t(ret); #else return ret; #endif } }; namespace fash_hash_detail { using uint8 = unsigned char; using uint32 = unsigned int; using uint64 = unsigned long long; using uint128 = integers128::uint128; #if(defined(mips) || defined(__mips__) || defined(MIPS) || defined(_MIPS_) || defined(__mips64)) || \ (defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__)) // These require aligned reads static constexpr bool ALLOW_UNALIGNED_READS = false; #else static constexpr bool ALLOW_UNALIGNED_READS = !QUICKCPPLIB_IN_UNDEFINED_SANITIZER; #endif static inline QUICKCPPLIB_FORCEINLINE uint64 Rot64(uint64 x, int k) { return (x << k) | (x >> (64 - k)); } static inline QUICKCPPLIB_FORCEINLINE void Mix(const uint64 *data, uint64 &s0, uint64 &s1, uint64 &s2, uint64 &s3, uint64 &s4, uint64 &s5, uint64 &s6, uint64 &s7, uint64 &s8, uint64 &s9, uint64 &s10, uint64 &s11) { s0 += data[0]; s2 ^= s10; s11 ^= s0; s0 = Rot64(s0, 11); s11 += s1; s1 += data[1]; s3 ^= s11; s0 ^= s1; s1 = Rot64(s1, 32); s0 += s2; s2 += data[2]; s4 ^= s0; s1 ^= s2; s2 = Rot64(s2, 43); s1 += s3; s3 += data[3]; s5 ^= s1; s2 ^= s3; s3 = Rot64(s3, 31); s2 += s4; s4 += data[4]; s6 ^= s2; s3 ^= s4; s4 = Rot64(s4, 17); s3 += s5; s5 += data[5]; s7 ^= s3; s4 ^= s5; s5 = Rot64(s5, 28); s4 += s6; s6 += data[6]; s8 ^= s4; s5 ^= s6; s6 = Rot64(s6, 39); s5 += s7; s7 += data[7]; s9 ^= s5; s6 ^= s7; s7 = Rot64(s7, 57); s6 += s8; s8 += data[8]; s10 ^= s6; s7 ^= s8; s8 = Rot64(s8, 55); s7 += s9; s9 += data[9]; s11 ^= s7; s8 ^= s9; s9 = Rot64(s9, 54); s8 += s10; s10 += data[10]; s0 ^= s8; s9 ^= s10; s10 = Rot64(s10, 22); s9 += s11; s11 += data[11]; s1 ^= s9; s10 ^= s11; s11 = Rot64(s11, 46); s10 += s0; } static inline QUICKCPPLIB_FORCEINLINE void EndPartial(uint64 &h0, uint64 &h1, uint64 &h2, uint64 &h3, uint64 &h4, uint64 &h5, uint64 &h6, uint64 &h7, uint64 &h8, uint64 &h9, uint64 &h10, uint64 &h11) { h11 += h1; h2 ^= h11; h1 = Rot64(h1, 44); h0 += h2; h3 ^= h0; h2 = Rot64(h2, 15); h1 += h3; h4 ^= h1; h3 = Rot64(h3, 34); h2 += h4; h5 ^= h2; h4 = Rot64(h4, 21); h3 += h5; h6 ^= h3; h5 = Rot64(h5, 38); h4 += h6; h7 ^= h4; h6 = Rot64(h6, 33); h5 += h7; h8 ^= h5; h7 = Rot64(h7, 10); h6 += h8; h9 ^= h6; h8 = Rot64(h8, 13); h7 += h9; h10 ^= h7; h9 = Rot64(h9, 38); h8 += h10; h11 ^= h8; h10 = Rot64(h10, 53); h9 += h11; h0 ^= h9; h11 = Rot64(h11, 42); h10 += h0; h1 ^= h10; h0 = Rot64(h0, 54); } static inline QUICKCPPLIB_FORCEINLINE void End(const uint64 *data, uint64 &h0, uint64 &h1, uint64 &h2, uint64 &h3, uint64 &h4, uint64 &h5, uint64 &h6, uint64 &h7, uint64 &h8, uint64 &h9, uint64 &h10, uint64 &h11) { h0 += data[0]; h1 += data[1]; h2 += data[2]; h3 += data[3]; h4 += data[4]; h5 += data[5]; h6 += data[6]; h7 += data[7]; h8 += data[8]; h9 += data[9]; h10 += data[10]; h11 += data[11]; EndPartial(h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); EndPartial(h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); EndPartial(h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); } static inline QUICKCPPLIB_FORCEINLINE void ShortMix(uint64 &h0, uint64 &h1, uint64 &h2, uint64 &h3) { h2 = Rot64(h2, 50); h2 += h3; h0 ^= h2; h3 = Rot64(h3, 52); h3 += h0; h1 ^= h3; h0 = Rot64(h0, 30); h0 += h1; h2 ^= h0; h1 = Rot64(h1, 41); h1 += h2; h3 ^= h1; h2 = Rot64(h2, 54); h2 += h3; h0 ^= h2; h3 = Rot64(h3, 48); h3 += h0; h1 ^= h3; h0 = Rot64(h0, 38); h0 += h1; h2 ^= h0; h1 = Rot64(h1, 37); h1 += h2; h3 ^= h1; h2 = Rot64(h2, 62); h2 += h3; h0 ^= h2; h3 = Rot64(h3, 34); h3 += h0; h1 ^= h3; h0 = Rot64(h0, 5); h0 += h1; h2 ^= h0; h1 = Rot64(h1, 36); h1 += h2; h3 ^= h1; } static inline QUICKCPPLIB_FORCEINLINE void ShortEnd(uint64 &h0, uint64 &h1, uint64 &h2, uint64 &h3) { h3 ^= h2; h2 = Rot64(h2, 15); h3 += h2; h0 ^= h3; h3 = Rot64(h3, 52); h0 += h3; h1 ^= h0; h0 = Rot64(h0, 26); h1 += h0; h2 ^= h1; h1 = Rot64(h1, 51); h2 += h1; h3 ^= h2; h2 = Rot64(h2, 28); h3 += h2; h0 ^= h3; h3 = Rot64(h3, 9); h0 += h3; h1 ^= h0; h0 = Rot64(h0, 47); h1 += h0; h2 ^= h1; h1 = Rot64(h1, 54); h2 += h1; h3 ^= h2; h2 = Rot64(h2, 32); h3 += h2; h0 ^= h3; h3 = Rot64(h3, 25); h0 += h3; h1 ^= h0; h0 = Rot64(h0, 63); h1 += h0; } } // namespace fash_hash_detail #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4127) // use of ALLOW_UNALIGNED_READS #endif /*! \class fast_hash \brief Fast very collision resistant uint128 hash. Currently SpookyHash @ 0.3 cycles/byte. */ class fast_hash { using uint8 = unsigned char; using uint64 = unsigned long long; using uint128 = integers128::uint128; // number of uint64's in internal state static constexpr size_t sc_numVars = 12; // size of the internal state static constexpr size_t sc_blockSize = sc_numVars * 8; // size of buffer of unhashed data, in bytes static constexpr size_t sc_bufSize = 2 * sc_blockSize; // // sc_const: a constant which: // * is not zero // * is odd // * is a not-very-regular mix of 1's and 0's // * does not need any other special mathematical properties // static constexpr uint64 sc_const = 0xdeadbeefdeadbeefULL; union { uint8 m_data_[2 * sc_numVars * 8]; uint64 m_data[2 * sc_numVars]; // unhashed data, for partial messages }; uint64 m_state[sc_numVars]; // internal state of the hash size_t m_length; // total length of the input so far uint8 m_remainder; // length of unhashed data stashed in m_data QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) static inline void short_(uint128 &hash, const T *message, size_t length) noexcept { using namespace fash_hash_detail; uint64 buf[2 * sc_numVars]; union { const uint8 *p8; uint32 *p32; uint64 *p64; size_t i; } u; u.p8 = (const uint8 *) message; if(!ALLOW_UNALIGNED_READS && (u.i & 0x7)) { memcpy(buf, message, length); u.p64 = buf; } size_t remainder = length % 32; uint64 a = hash.as_longlongs[0]; uint64 b = hash.as_longlongs[1]; uint64 c = sc_const; uint64 d = sc_const; if(length > 15) { const uint64 *end = u.p64 + (length / 32) * 4; // handle all complete sets of 32 bytes for(; u.p64 < end; u.p64 += 4) { c += u.p64[0]; d += u.p64[1]; ShortMix(a, b, c, d); a += u.p64[2]; b += u.p64[3]; } // Handle the case of 16+ remaining bytes. if(remainder >= 16) { c += u.p64[0]; d += u.p64[1]; ShortMix(a, b, c, d); u.p64 += 2; remainder -= 16; } } // Handle the last 0..15 bytes, and its length d += ((uint64) length) << 56; switch(remainder) { case 15: d += ((uint64) u.p8[14]) << 48; // fallthrough case 14: d += ((uint64) u.p8[13]) << 40; // fallthrough case 13: d += ((uint64) u.p8[12]) << 32; // fallthrough case 12: d += u.p32[2]; c += u.p64[0]; break; case 11: d += ((uint64) u.p8[10]) << 16; // fallthrough case 10: d += ((uint64) u.p8[9]) << 8; // fallthrough case 9: d += (uint64) u.p8[8]; // fallthrough case 8: c += u.p64[0]; break; case 7: c += ((uint64) u.p8[6]) << 48; // fallthrough case 6: c += ((uint64) u.p8[5]) << 40; // fallthrough case 5: c += ((uint64) u.p8[4]) << 32; // fallthrough case 4: c += u.p32[0]; break; case 3: c += ((uint64) u.p8[2]) << 16; // fallthrough case 2: c += ((uint64) u.p8[1]) << 8; // fallthrough case 1: c += (uint64) u.p8[0]; break; case 0: c += sc_const; d += sc_const; } ShortEnd(a, b, c, d); hash.as_longlongs[0] = a; hash.as_longlongs[1] = b; } public: //! The result type of the hash using result_type = uint128; //! Initialise the hash with an optional seed constexpr fast_hash(const uint128 &seed = 0) noexcept : m_data{0} , m_state{seed.as_longlongs[0], seed.as_longlongs[1]} , m_length(0) , m_remainder(0) { } //! Hash input QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) inline void add(const T *message, size_t length) noexcept { using namespace fash_hash_detail; uint64 h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11; size_t newLength = length + m_remainder; uint8 remainder; union { const uint8 *p8; uint64 *p64; size_t i; } u; const uint64 *end; // Is this message fragment too short? If it is, stuff it away. if(newLength < sc_bufSize) { memcpy(&((uint8 *) m_data)[m_remainder], message, length); m_length = length + m_length; m_remainder = (uint8) newLength; return; } // init the variables if(m_length < sc_bufSize) { h0 = h3 = h6 = h9 = m_state[0]; h1 = h4 = h7 = h10 = m_state[1]; h2 = h5 = h8 = h11 = sc_const; } else { h0 = m_state[0]; h1 = m_state[1]; h2 = m_state[2]; h3 = m_state[3]; h4 = m_state[4]; h5 = m_state[5]; h6 = m_state[6]; h7 = m_state[7]; h8 = m_state[8]; h9 = m_state[9]; h10 = m_state[10]; h11 = m_state[11]; } m_length = length + m_length; // if we've got anything stuffed away, use it now if(m_remainder) { uint8 prefix = sc_bufSize - m_remainder; memcpy(&(((uint8 *) m_data)[m_remainder]), message, prefix); u.p64 = m_data; Mix(u.p64, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); Mix(&u.p64[sc_numVars], h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); u.p8 = ((const uint8 *) message) + prefix; length -= prefix; } else { u.p8 = (const uint8 *) message; } // handle all whole blocks of sc_blockSize bytes end = u.p64 + (length / sc_blockSize) * sc_numVars; remainder = (uint8) (length - ((const uint8 *) end - u.p8)); if(ALLOW_UNALIGNED_READS || (u.i & 0x7) == 0) { while(u.p64 < end) { Mix(u.p64, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); u.p64 += sc_numVars; } } else { while(u.p64 < end) { memcpy(m_data, u.p8, sc_blockSize); Mix(m_data, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); u.p64 += sc_numVars; } } // stuff away the last few bytes m_remainder = remainder; memcpy(m_data, end, remainder); // stuff away the variables m_state[0] = h0; m_state[1] = h1; m_state[2] = h2; m_state[3] = h3; m_state[4] = h4; m_state[5] = h5; m_state[6] = h6; m_state[7] = h7; m_state[8] = h8; m_state[9] = h9; m_state[10] = h10; m_state[11] = h11; } //! Finalise and return hash inline uint128 finalise() noexcept { using namespace fash_hash_detail; uint128 ret; // init the variables if(m_length < sc_bufSize) { ret.as_longlongs[0] = m_state[0]; ret.as_longlongs[1] = m_state[1]; short_(ret, m_data_, m_length); return ret; } const uint64 *data = (const uint64 *) m_data; uint8 remainder = m_remainder; uint64 h0 = m_state[0]; uint64 h1 = m_state[1]; uint64 h2 = m_state[2]; uint64 h3 = m_state[3]; uint64 h4 = m_state[4]; uint64 h5 = m_state[5]; uint64 h6 = m_state[6]; uint64 h7 = m_state[7]; uint64 h8 = m_state[8]; uint64 h9 = m_state[9]; uint64 h10 = m_state[10]; uint64 h11 = m_state[11]; if(remainder >= sc_blockSize) { // m_data can contain two blocks; handle any whole first block Mix(data, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); data += sc_numVars; remainder -= sc_blockSize; } // mix in the last partial block, and the length mod sc_blockSize memset(&((uint8 *) data)[remainder], 0, (sc_blockSize - remainder)); ((uint8 *) data)[sc_blockSize - 1] = remainder; // do some final mixing End(data, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); ret.as_longlongs[0] = h0; ret.as_longlongs[1] = h1; return ret; } //! Single shot hash of a sequence of bytes QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) static inline uint128 hash(const T *message, size_t length, const uint128 &_ret = 0) noexcept { uint128 ret(_ret); using namespace fash_hash_detail; if(length < sc_bufSize) { short_(ret, message, length); return ret; } uint64 h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11; uint64 buf[sc_numVars]; uint64 *end; union { const uint8 *p8; uint64 *p64; size_t i; } u; size_t remainder; h0 = h3 = h6 = h9 = ret.as_longlongs[0]; h1 = h4 = h7 = h10 = ret.as_longlongs[1]; h2 = h5 = h8 = h11 = sc_const; u.p8 = (const uint8 *) message; end = u.p64 + (length / sc_blockSize) * sc_numVars; // handle all whole sc_blockSize blocks of bytes if(ALLOW_UNALIGNED_READS || ((u.i & 0x7) == 0)) { while(u.p64 < end) { Mix(u.p64, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); u.p64 += sc_numVars; } } else { while(u.p64 < end) { memcpy(buf, u.p64, sc_blockSize); Mix(buf, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); u.p64 += sc_numVars; } } // handle the last partial block of sc_blockSize bytes remainder = (length - ((const uint8 *) end - (const uint8 *) message)); memcpy(buf, end, remainder); memory::cmemset(((uint8 *) buf) + remainder, (uint8) 0, sc_blockSize - remainder); ((uint8 *) buf)[sc_blockSize - 1] = (uint8) remainder; // do some final mixing End(buf, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11); ret.as_longlongs[0] = h0; ret.as_longlongs[1] = h1; return ret; } //! Single shot hash of a span // template <typename T> static inline uint128 hash(const span::span<T> &str) noexcept { return hash((char *) str.data(), str.size() * sizeof(T)); // } }; /*! \class sha256_hash \brief SHA256 hash. */ class sha256_hash { // Implementation is adapted from https://github.com/amosnier/sha-2/blob/master/sha-256.c, which does // not have a licence as it was placed into the public domain. static constexpr size_t _CHUNK_SIZE = 64; static constexpr size_t _TOTAL_LEN_LEN = 8; static const uint32_t *_k() noexcept { static const uint32_t v[] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, // 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, // 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, // 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, // 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, // 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, // 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 // }; return v; } static constexpr inline uint32_t _right_rot(uint32_t value, unsigned int count) { return (value >> count) | (value << (32 - count)); } public: //! The result type of the hash union alignas(32) result_type { struct empty_type { } _empty; uint8_t as_bytes[32]; uint32_t as_ints[8]; uint64_t as_longlongs[4]; // Strongly hint to the compiler what to do here #if defined(__SSE2__) || defined(_M_X64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2) __m128i as_m128is[2]; #endif #if defined(__GNUC__) || defined(__clang__) typedef unsigned uint32_4_t __attribute__((vector_size(32))); uint32_4_t as_uint32_8; #endif constexpr result_type() : _empty{} { } constexpr result_type(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t e, uint32_t f, uint32_t g, uint32_t h) : as_ints{a, b, c, d, e, f, g, h} { } }; private: /* * Initialize hash values: * (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19): */ result_type _h{0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; uint8_t _chunk[_CHUNK_SIZE]{}; size_t _chunkidx{0}; size_t _total_len{0}; QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) const uint8_t *_calc_chunk(const T *&data, size_t &bytes) { // fixed size fast path if(_chunkidx == 0 && bytes >= _CHUNK_SIZE) { memcpy(_chunk, data, _CHUNK_SIZE); _total_len += _CHUNK_SIZE; data += _CHUNK_SIZE; bytes -= _CHUNK_SIZE; return (const uint8_t *) (data - _CHUNK_SIZE); } size_t tocopy = _CHUNK_SIZE; if(tocopy > _CHUNK_SIZE - _chunkidx) { tocopy = _CHUNK_SIZE - _chunkidx; } if(tocopy > bytes) { tocopy = bytes; } if(data != nullptr) { memcpy(_chunk + _chunkidx, data, tocopy); _total_len += tocopy; data += tocopy; bytes -= tocopy; } _chunkidx += tocopy; if(_chunkidx == _CHUNK_SIZE) { _chunkidx = 0; return _chunk; } return nullptr; } public: //! Initialise the hash constexpr sha256_hash() noexcept {} //! Hash input QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) void add(const T *data, size_t bytes) noexcept { static const uint32_t *const k = _k(); /* * Note 1: All integers (expect indexes) are 32-bit unsigned integers and addition is calculated modulo 2^32. * Note 2: For each round, there is one round constant k[i] and one entry in the message schedule array w[i], 0 = i = 63 * Note 3: The compression function uses 8 working variables, a through h * Note 4: Big-endian convention is used when expressing the constants in this pseudocode, * and when parsing message block data from bytes to words, for example, * the first word of the input message "abc" after padding is 0x61626380 */ while(const uint8_t *p = _calc_chunk(data, bytes)) { /* Note that if we ever do support CPUID detection for the Intel SHA extensions, there is a public domain implementation of the SHA256 rounds at https://github.com/noloader/SHA-Intrinsics/blob/master/sha256-x86.c */ alignas(32) uint32_t ah[8]; /* Initialize working variables to current hash value: */ memcpy(ah, _h.as_ints, sizeof(ah)); /* * create a 64-entry message schedule array w[0..63] of 32-bit words * copy chunk into first 16 words w[0..15] of the message schedule array */ alignas(32) uint32_t w[64]; for(unsigned i = 0; i < 16; i++) { w[i] = ((uint32_t) p[0] << 24) | ((uint32_t) p[1] << 16) | ((uint32_t) p[2] << 8) | ((uint32_t) p[3]); p += 4; } /* Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array: */ for(unsigned i = 16; i < 64; i++) { const uint32_t s0 = _right_rot(w[i - 15], 7) ^ _right_rot(w[i - 15], 18) ^ (w[i - 15] >> 3); const uint32_t s1 = _right_rot(w[i - 2], 17) ^ _right_rot(w[i - 2], 19) ^ (w[i - 2] >> 10); w[i] = w[i - 16] + s0 + w[i - 7] + s1; } /* Compression function main loop: */ for(unsigned i = 0; i < 64; i++) { const uint32_t s1 = _right_rot(ah[4], 6) ^ _right_rot(ah[4], 11) ^ _right_rot(ah[4], 25); const uint32_t ch = (ah[4] & ah[5]) ^ (~ah[4] & ah[6]); const uint32_t temp1 = ah[7] + s1 + ch + k[i] + w[i]; const uint32_t s0 = _right_rot(ah[0], 2) ^ _right_rot(ah[0], 13) ^ _right_rot(ah[0], 22); const uint32_t maj = (ah[0] & ah[1]) ^ (ah[0] & ah[2]) ^ (ah[1] & ah[2]); const uint32_t temp2 = s0 + maj; ah[7] = ah[6]; ah[6] = ah[5]; ah[5] = ah[4]; ah[4] = ah[3] + temp1; ah[3] = ah[2]; ah[2] = ah[1]; ah[1] = ah[0]; ah[0] = temp1 + temp2; } /* Add the compressed chunk to the current hash value: */ for(unsigned i = 0; i < 8; i++) _h.as_ints[i] += ah[i]; } } //! Finalise and return hash result_type finalise() noexcept { /* * Now: * - either there is enough space left for the total length, and we can conclude, * - or there is too little space left, and we have to pad the rest of this chunk with zeroes. * In the latter case, we will conclude at the next invokation of this function. */ size_t space_in_chunk = _CHUNK_SIZE - _chunkidx; assert(space_in_chunk > 0); _chunk[_chunkidx++] = 0x80; space_in_chunk--; if(space_in_chunk < _TOTAL_LEN_LEN) { memory::cmemset(_chunk + _chunkidx, (uint8_t) 0, space_in_chunk); _chunkidx += space_in_chunk; assert(_chunkidx == _CHUNK_SIZE); add((const uint8_t *) nullptr, 0); assert(_chunkidx == 0); space_in_chunk = _CHUNK_SIZE - _chunkidx; } assert(space_in_chunk >= _TOTAL_LEN_LEN); const size_t left = space_in_chunk - _TOTAL_LEN_LEN; memory::cmemset(_chunk + _chunkidx, (uint8_t) 0, left); _chunkidx += left; /* Storing of len * 8 as a big endian 64-bit without overflow. */ size_t len = _total_len; _chunk[_chunkidx + 7] = (uint8_t) ((len << 3) & 0xff); len >>= 5; for(int i = 6; i >= 0; i--) { _chunk[_chunkidx + i] = (uint8_t) (len & 0xff); len >>= 8; } _chunkidx += 8; assert(_chunkidx == _CHUNK_SIZE); add((const uint8_t *) nullptr, 0); assert(_chunkidx == 0); result_type ret; /* Produce the final hash value (big-endian): */ for(unsigned i = 0, j = 0; i < 8; i++) { ret.as_bytes[j++] = (uint8_t) ((_h.as_ints[i] >> 24) & 0xff); ret.as_bytes[j++] = (uint8_t) ((_h.as_ints[i] >> 16) & 0xff); ret.as_bytes[j++] = (uint8_t) ((_h.as_ints[i] >> 8) & 0xff); ret.as_bytes[j++] = (uint8_t) (_h.as_ints[i] & 0xff); } _h = result_type{0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; _chunkidx = _total_len = 0; return ret; } //! Single shot hash of a sequence of bytes QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) static constexpr result_type hash(const T *data, size_t bytes) noexcept { sha256_hash ret; ret.add(data, bytes); return ret.finalise(); } }; #ifdef _MSC_VER #pragma warning(pop) #endif } // namespace hash } // namespace algorithm QUICKCPPLIB_NAMESPACE_END #endif
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/algorithm/secded_ecc.hpp
/* ECC algorithms (C) 2016-2018 Niall Douglas <http://www.nedproductions.biz/> (3 commits) File Created: Jun 2016 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef QUICKCPPLIB_ALGORITHM_SECDED_ECC_HPP #define QUICKCPPLIB_ALGORITHM_SECDED_ECC_HPP #include "../config.hpp" #include <stdexcept> // std::runtime_error #if 0 #include <cstring> #include <x86intrin.h> #endif QUICKCPPLIB_NAMESPACE_BEGIN namespace algorithm { namespace secded_ecc { #ifndef QUICKCPPLIB_SECDED_INTRINSICS #if defined(__GCC__) || defined(__clang__) #define QUICKCPPLIB_SECDED_INTRINSICS 1 #elif defined(_MSC_VER) && (defined(_M_X64) || _M_IX86_FP == 1) #define QUICKCPPLIB_SECDED_INTRINSICS 1 #endif #endif #ifndef QUICKCPPLIB_SECDED_INTRINSICS #define QUICKCPPLIB_SECDED_INTRINSICS 0 #endif /*! \class secded_ecc \brief Calculates the single error correcting double error detecting (SECDED) Hamming Error Correcting Code for a \em blocksize block of bytes. For example, a secdec_ecc<8> would be the very common 72,64 Hamming code used in ECC RAM, or secdec_ecc<4096> would be for a 32784,32768 Hamming code. \warning This class needs to be completely reimplemented using SSE and AVX. Its current implementation works fine, but performance is far below what it can be. Did you know that some non-ECC RAM systems can see 1e-12 flips/bit/hour, which is 3.3 bits flipped in a 16Gb RAM system per 24 hours). See Schroeder, Pinheiro and Weber (2009) 'DRAM Errors in the Wild: A Large-Scale Field Study'. After construction during which lookup tables are built, no state is modified and therefore this class is safe for static storage (indeed if C++ 14 is available, the constructor is constexpr). The maximum number of bits in a code is a good four billion, I did try limiting it to 65536 for performance but it wasn't worth it, and one might want > 8Kb blocks maybe. As with all SECDED ECC, undefined behaviour occurs when more than two bits of error are present or the ECC supplied is incorrect. You should combine this SECDED with a robust hash which can tell you definitively if a buffer is error free or not rather than relying on this to correctly do so. The main intended use case for this routine is calculating the ECC on data being written to disc, and hence that is where performance has been maximised. It is not expected that this routine will be frequently called on data being read from disc i.e. only when its hash doesn't match its contents which should be very rare, and then a single bit heal using this routine is attempted before trying again with the hash. Care was taken that really enormous SECDEDs are fast, in fact tuning was mostly done for the 32784,32768 code which can heal one bad bit per 4Kb page as the main thing we have in mind is achieving reliable filing system code on computers without ECC RAM and in which sustained large quantities of random disc i/o produce a worrying number of flipped bits in a 24 hour period (anywhere between 0 and 3 on my hardware here, average is about 0.8). ## Performance notes of this current implementation: For a Skylake CPU: - MSVC Fixed buffer: 125.719 Mb/sec, or 23.48 cycles/byte - MSVC Variable buffer: 144.167 Mb/sec, or 20.48 cycles/byte - MSVC heal: 80.4498 Mb/sec - GCC7 Fixed buffer: 201.509 Mb/sec, or 14.65 cycles/byte - GCC7 Variable buffer: 317.97 Mb/sec, or 9.28 cycles/byte - GCC7 heal: 126.099 Mb/sec - cla6 Fixed buffer: 276.962 Mb/sec, or 10.66 cycles/byte - cla6 Variable buffer: 210.248 Mb/sec, or 14.04 cycles/byte - cla6 heal: 171.174 Mb/sec Note that better than 1Gb/sec is easily possible if I rewrite the implementation. \ingroup utils \complexity{O(N) where N is the blocksize} \exceptionmodel{Throws constexpr exceptions in constructor only, otherwise entirely noexcept.} */ template <size_t blocksize> class secded_ecc { public: typedef unsigned int result_type; //!< The largest ECC which can be calculated private: static constexpr size_t bits_per_byte = 8; typedef unsigned char unit_type; // The batch unit of processing result_type bitsvalid; // Many CPUs (x86) are slow doing variable bit shifts, so keep a table result_type ecc_twospowers[sizeof(result_type) * bits_per_byte]; unsigned short ecc_table[blocksize * bits_per_byte]; static bool _is_single_bit_set(result_type x) { #ifndef _MSC_VER #if defined(__i386__) || defined(__x86_64__) #ifndef __SSE4_2__ // Do a once off runtime check static int have_popcnt = [] { size_t cx, dx; #if defined(__x86_64__) asm("cpuid" : "=c"(cx), "=d"(dx) : "a"(1), "b"(0), "c"(0), "d"(0)); #else asm("pushl %%ebx\n\tcpuid\n\tpopl %%ebx\n\t" : "=c"(cx), "=d"(dx) : "a"(1), "c"(0), "d"(0)); #endif return (dx & (1 << 26)) != 0 /*SSE2*/ && (cx & (1 << 23)) != 0 /*POPCNT*/; }(); if(have_popcnt) #endif { unsigned count; asm("popcnt %1,%0" : "=r"(count) : "rm"(x) : "cc"); return count == 1; } #endif return __builtin_popcount(x) == 1; #else x -= (x >> 1) & 0x55555555; x = (x & 0x33333333) + ((x >> 2) & 0x33333333); x = (x + (x >> 4)) & 0x0f0f0f0f; unsigned int count = (x * 0x01010101) >> 24; return count == 1; #if 0 x -= (x >> 1) & 0x5555555555555555ULL; x = (x & 0x3333333333333333ULL) + ((x >> 2) & 0x3333333333333333ULL); x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0fULL; unsigned long long count = (x * 0x0101010101010101ULL) >> 56; return count == 1; #endif #endif } public: //! Constructs an instance, configuring the necessary lookup tables constexpr secded_ecc() { for(size_t n = 0; n < sizeof(result_type) * bits_per_byte; n++) ecc_twospowers[n] = ((result_type) 1 << n); result_type length = blocksize * bits_per_byte; // This is (data bits + parity bits + 1) <= 2^(parity bits) for(result_type p = 1; p < sizeof(result_type) * bits_per_byte; p++) if((length + p + 1) <= ecc_twospowers[p]) { bitsvalid = p; break; } if((bits_per_byte - 1 + bitsvalid) / bits_per_byte > sizeof(result_type)) throw std::runtime_error("secdec_ecc: ECC would exceed the size of result_type!"); for(result_type i = 0; i < blocksize * bits_per_byte; i++) { // Make a code bit result_type b = i + 1; #if QUICKCPPLIB_SECDED_INTRINSICS && 0 // let constexpr do its thing #ifdef _MSC_VER unsigned long _topbit; _BitScanReverse(&_topbit, b); result_type topbit = _topbit; #else result_type topbit = bits_per_byte * sizeof(result_type) - __builtin_clz(b); #endif b += topbit; if(b >= ecc_twospowers[topbit]) b++; // while(b>ecc_twospowers(_topbit+1)) _topbit++; // b+=_topbit; // if(b>=ecc_twospowers(_topbit)) b++; #else for(size_t p = 0; ecc_twospowers[p] < (b + 1); p++) b++; #endif ecc_table[i] = (unsigned short) b; if(b > (unsigned short) -1) throw std::runtime_error("secdec_ecc: Precalculated table has exceeded its bounds"); } } //! The number of bits valid in result_type constexpr result_type result_bits_valid() const noexcept { return bitsvalid; } #if 1 //! Accumulate ECC from fixed size buffer result_type operator()(result_type ecc, const char *buffer) const noexcept { #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4127) // conditional expression is constant #endif if(blocksize < sizeof(unit_type) * 8) return (*this)(ecc, buffer, blocksize); #ifdef _MSC_VER #pragma warning(pop) #endif // Process in lumps of eight const unit_type *_buffer = (const unit_type *) buffer; //#pragma omp parallel for reduction(^:ecc) for(size_t i = 0; i < blocksize; i += sizeof(unit_type) * 8) { union { unsigned long long v; unit_type c[8]; }; result_type prefetch[8]; v = *(unsigned long long *) (&_buffer[0 + i / sizeof(unit_type)]); // min 1 cycle #define QUICKCPPLIB_SECDED_ROUND(n) \ prefetch[0] = ecc_table[(i + 0) * 8 + n]; \ prefetch[1] = ecc_table[(i + 1) * 8 + n]; \ prefetch[2] = ecc_table[(i + 2) * 8 + n]; \ prefetch[3] = ecc_table[(i + 3) * 8 + n]; \ prefetch[4] = ecc_table[(i + 4) * 8 + n]; \ prefetch[5] = ecc_table[(i + 5) * 8 + n]; \ prefetch[6] = ecc_table[(i + 6) * 8 + n]; \ prefetch[7] = ecc_table[(i + 7) * 8 + n]; \ if(c[0] & ((unit_type) 1 << n)) \ ecc ^= prefetch[0]; \ if(c[1] & ((unit_type) 1 << n)) \ ecc ^= prefetch[1]; \ if(c[2] & ((unit_type) 1 << n)) \ ecc ^= prefetch[2]; \ if(c[3] & ((unit_type) 1 << n)) \ ecc ^= prefetch[3]; \ if(c[4] & ((unit_type) 1 << n)) \ ecc ^= prefetch[4]; \ if(c[5] & ((unit_type) 1 << n)) \ ecc ^= prefetch[5]; \ if(c[6] & ((unit_type) 1 << n)) \ ecc ^= prefetch[6]; \ if(c[7] & ((unit_type) 1 << n)) \ ecc ^= prefetch[7]; QUICKCPPLIB_SECDED_ROUND(0) // prefetch = min 8, bit test and xor = min 16, total = 24 QUICKCPPLIB_SECDED_ROUND(1) QUICKCPPLIB_SECDED_ROUND(2) QUICKCPPLIB_SECDED_ROUND(3) QUICKCPPLIB_SECDED_ROUND(4) QUICKCPPLIB_SECDED_ROUND(5) QUICKCPPLIB_SECDED_ROUND(6) QUICKCPPLIB_SECDED_ROUND(7) #undef QUICKCPPLIB_SECDED_ROUND // total should be 1+(8*24/3)=65 } return ecc; } //! Accumulate ECC from partial buffer where \em length <= \em blocksize result_type operator()(result_type ecc, const char *buffer, size_t length) const noexcept { const unit_type *_buffer = (const unit_type *) buffer; //#pragma omp parallel for reduction(^:ecc) for(size_t i = 0; i < length; i += sizeof(unit_type)) { unit_type c = _buffer[i / sizeof(unit_type)]; // min 1 cycle if(!c) // min 1 cycle continue; char bitset[bits_per_byte * sizeof(unit_type)]; result_type prefetch[bits_per_byte * sizeof(unit_type)]; // Most compilers will roll this out for(size_t n = 0; n < bits_per_byte * sizeof(unit_type); n++) // min 16 cycles { bitset[n] = !!(c & ((unit_type) 1 << n)); prefetch[n] = ecc_table[i * bits_per_byte + n]; // min 8 cycles } result_type localecc = 0; for(size_t n = 0; n < bits_per_byte * sizeof(unit_type); n++) { if(bitset[n]) // min 8 cycles localecc ^= prefetch[n]; // min 8 cycles } ecc ^= localecc; // min 1 cycle. Total cycles = min 43 cycles/byte } return ecc; } #elif 1 //! Accumulate ECC from partial buffer where \em length <= \em blocksize result_type operator()(result_type ecc, const char *buffer, size_t length) const noexcept { uint64_t ecc_xors = 0; for(size_t i = 0; i < length; ++i) { uint64_t ecc_xors_lo; // 4x uint16_t uint64_t ecc_xors_hi; // 4x uint16_t memcpy(&ecc_xors_lo, &ecc_table[i * 8 + 0], 8); memcpy(&ecc_xors_hi, &ecc_table[i * 8 + 4], 8); uint8_t bitmask = buffer[i]; #define OPTION 1 // GCC 7 (-march=skylake): Variable buffer size calculating is approximately 615.615 Mb/sec, or 4.79551 cycles/byte #if OPTION == 1 // pdep is fast but doesn't vectorize and requires BMI2 uint64_t mask_lo = _pdep_u64(bitmask >> 0, UINT64_C(0x0001000100010001)) * 0xFFFF; uint64_t mask_hi = _pdep_u64(bitmask >> 4, UINT64_C(0x0001000100010001)) * 0xFFFF; // GCC 7 (no -march): Variable buffer size calculating is approximately 670.766 Mb/sec, or 4.40118 cycles/byte // GCC 7 (-march=skylake): Variable buffer size calculating is approximately 1115.43 Mb/sec, or 2.64652 cycles/byte #elif OPTION == 2 // Competitive with pdep without requiring BMI2. // Vectorizes *extremely* aggressively with -march=skylake. // It's hard to read so I'm not sure if that's great or terrible. uint64_t mask_lo = bitmask * UINT64_C(0x0000200040008001); mask_lo &= UINT64_C(0x0001000100010001); mask_lo *= 0xFFFF; uint64_t mask_hi = (bitmask >> 4) * UINT64_C(0x0000200040008001); mask_hi &= UINT64_C(0x0001000100010001); mask_hi *= 0xFFFF; #elif OPTION == 3 // fails tests // Vectorizes less aggressively than option 2, // but produces meh code without -march=skylake. uint64_t mask_lo = (((bitmask >> 0) & 1) * UINT64_C(0x000000000000FFFF)) | (((bitmask >> 1) & 1) * UINT64_C(0x00000000FFFF0000)) | (((bitmask >> 2) & 1) * UINT64_C(0x0000FFFF00000000)) | (((bitmask >> 3) & 1) * UINT64_C(0xFFFF000000000000)); uint64_t mask_hi = (((bitmask >> 4) & 1) * UINT64_C(0x000000000000FFFF)) | (((bitmask >> 6) & 1) * UINT64_C(0x00000000FFFF0000)) | (((bitmask >> 5) & 1) * UINT64_C(0x0000FFFF00000000)) | (((bitmask >> 7) & 1) * UINT64_C(0xFFFF000000000000)); #endif ecc_xors ^= (mask_lo & ecc_xors_lo) ^ (mask_hi & ecc_xors_hi); } ecc_xors ^= ecc_xors >> 32; ecc_xors ^= ecc_xors >> 16; return ecc ^ static_cast<uint16_t>(ecc_xors); } result_type operator()(result_type ecc, const char *buffer) const noexcept { return (*this)(ecc, buffer, blocksize); } #else //! Accumulate ECC from partial buffer where \em length <= \em blocksize result_type operator()(result_type ecc, const char *buffer, size_t length) const noexcept { // Process in lumps of eight } result_type operator()(result_type ecc, const char *buffer) const noexcept { return (*this)(ecc, buffer, blocksize); } #endif result_type operator()(const char *buffer) const noexcept { return (*this)(0, buffer); } result_type operator()(const char *buffer, size_t length) const noexcept { return (*this)(0, buffer, length); } //! Given the original ECC and the new ECC for a buffer, find the bad bit. Return (result_type)-1 if not found (e.g. ECC corrupt) result_type find_bad_bit(result_type good_ecc, result_type bad_ecc) const noexcept { result_type length = blocksize * bits_per_byte, eccdiff = good_ecc ^ bad_ecc; if(_is_single_bit_set(eccdiff)) return (result_type) -1; for(result_type i = 0, b = 1; i < length; i++, b++) { // Skip parity bits while(_is_single_bit_set(b)) b++; if(b == eccdiff) return i; } return (result_type) -1; } //! The outcomes from verify() enum verify_status { corrupt = 0, //!< The buffer had more than a single bit corrupted or the ECC was invalid okay = 1, //!< The buffer had no errors healed = 2 //!< The buffer was healed }; //! Verifies and heals when possible a buffer, returning non zero if the buffer is error free verify_status verify(char *buffer, result_type good_ecc) const noexcept { result_type this_ecc = (*this)(0, buffer); if(this_ecc == good_ecc) return verify_status::okay; // no errors result_type badbit = find_bad_bit(good_ecc, this_ecc); if((result_type) -1 == badbit) return verify_status::corrupt; // parity corrupt? buffer[badbit / bits_per_byte] ^= (unsigned char) ecc_twospowers[badbit % bits_per_byte]; this_ecc = (*this)(0, buffer); if(this_ecc == good_ecc) return healed; // error healed // Put the bit back buffer[badbit / bits_per_byte] ^= (unsigned char) ecc_twospowers[badbit % bits_per_byte]; return verify_status::corrupt; // more than one bit was corrupt } }; } } QUICKCPPLIB_NAMESPACE_END #endif
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/algorithm/string.hpp
/* String algorithms (C) 2016-2020 Niall Douglas <http://www.nedproductions.biz/> (7 commits) File Created: Jun 2016 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef QUICKCPPLIB_ALGORITHM_STRING_HPP #define QUICKCPPLIB_ALGORITHM_STRING_HPP #include "../span.hpp" #include <algorithm> #include <locale> #include <string> QUICKCPPLIB_NAMESPACE_BEGIN namespace algorithm { namespace string { //! Returns an all lower case edition of the input string. i18n aware. template <class Char> std::basic_string<Char> tolower(std::basic_string<Char> s) { auto &f = std::use_facet<std::ctype<Char>>(std::locale()); std::transform(s.begin(), s.end(), s.begin(), [&](Char c) { return f.tolower(c); }); return s; } //! Returns an all upper case edition of the input string. i18n aware. template <class Char> std::basic_string<Char> toupper(std::basic_string<Char> s) { auto &f = std::use_facet<std::ctype<Char>>(std::locale()); std::transform(s.begin(), s.end(), s.begin(), [&](Char c) { return f.toupper(c); }); return s; } /*! \brief Converts a number to a hex string. Out buffer can be same as in buffer. Note that the character range used is a 16 item table of: 0123456789abcdef This lets one pack one byte of input into two bytes of output. \ingroup utils \complexity{O(N) where N is the length of the number.} \exceptionmodel{Throws exception if output buffer is too small for input.} */ #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 6293) // MSVC sanitiser warns that we wrap n in the for loop #endif QUICKCPPLIB_TEMPLATE(class CharType, class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value), QUICKCPPLIB_TPRED(!std::is_const<CharType>::value)) inline size_t to_hex_string(CharType *out, size_t outlen, const T *_in, size_t inlen) { unsigned const char *in = (unsigned const char *) _in; static constexpr char table[] = "0123456789abcdef"; if(outlen < inlen * 2) throw std::invalid_argument("Output buffer too small."); if(inlen >= 2) { for(size_t n = inlen - 2; n <= inlen - 2; n -= 2) { out[n * 2 + 3] = table[in[n + 1] & 0xf]; out[n * 2 + 2] = table[(in[n + 1] >> 4) & 0xf]; out[n * 2 + 1] = table[in[n] & 0xf]; out[n * 2 + 0] = table[(in[n] >> 4) & 0xf]; } } if(inlen & 1) { out[1] = table[in[0] & 0xf]; out[0] = table[(in[0] >> 4) & 0xf]; } return inlen * 2; } #ifdef _MSC_VER #pragma warning(pop) #endif //! \overload QUICKCPPLIB_TEMPLATE(class CharType, class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value), QUICKCPPLIB_TPRED(!std::is_const<CharType>::value)) inline size_t to_hex_string(span::span<CharType> out, const span::span<T> in) { return to_hex_string(out.data(), out.size(), in.data(), in.size()); } //! \overload QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) inline std::string to_hex_string(span::span<T> in) { std::string out(in.size() * 2, ' '); to_hex_string(const_cast<char *>(out.data()), out.size(), in.data(), in.size()); return out; } //! \overload QUICKCPPLIB_TEMPLATE(class T) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value)) inline std::string to_hex_string(const T *in, size_t len) { std::string out(len * 2, ' '); to_hex_string(const_cast<char *>(out.data()), out.size(), in, len); return out; } /*! \brief Converts a hex string to a number. Out buffer can be same as in buffer. Note that this routine is about 43% slower than to_hex_string(), half of which is due to input validation. \ingroup utils \complexity{O(N) where N is the length of the string.} \exceptionmodel{Throws exception if output buffer is too small for input or input size is not multiple of two.} */ QUICKCPPLIB_TEMPLATE(class T, class CharType) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(sizeof(T) == 1), QUICKCPPLIB_TPRED(std::is_trivially_copyable<T>::value), QUICKCPPLIB_TPRED(!std::is_const<T>::value)) inline size_t from_hex_string(T *out, size_t outlen, const CharType *in, size_t inlen) { if(inlen % 2) throw std::invalid_argument("Input buffer not multiple of two."); if(outlen < inlen / 2) throw std::invalid_argument("Output buffer too small."); bool is_invalid = false; auto fromhex = [&is_invalid](CharType c) -> unsigned char { #if 1 // ASCII starting from 48 is 0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ // 48 65 97 static constexpr unsigned char table[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // +10 = 58 255, 255, 255, 255, 255, 255, 255, // +7 = 65 10, 11, 12, 13, 14, 15, // +6 = 71 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // +26 = 97 10, 11, 12, 13, 14, 15}; unsigned char r = 255; if(c >= 48 && c <= 102) r = table[c - 48]; if(r == 255) is_invalid = true; return r; #else if(c >= '0' && c <= '9') return c - '0'; if(c >= 'a' && c <= 'f') return c - 'a' + 10; if(c >= 'A' && c <= 'F') return c - 'A' + 10; throw std::invalid_argument("Input is not hexadecimal."); #endif }; const auto bulklen = inlen / 2 - (inlen / 2) % 4; if(bulklen >= 4) { for(size_t n = 0; n < bulklen; n += 4) { unsigned char c[8]; c[0] = fromhex(in[n * 2]); c[1] = fromhex(in[n * 2 + 1]); c[2] = fromhex(in[n * 2 + 2]); c[3] = fromhex(in[n * 2 + 3]); out[n] = (T)((c[0] << 4) | c[1]); c[4] = fromhex(in[n * 2 + 4]); c[5] = fromhex(in[n * 2 + 5]); out[n + 1] = (T)((c[2] << 4) | c[3]); c[6] = fromhex(in[n * 2 + 6]); c[7] = fromhex(in[n * 2 + 7]); out[n + 2] = (T)((c[4] << 4) | c[5]); out[n + 3] = (T)((c[6] << 4) | c[7]); } } for(size_t n = bulklen; n < inlen / 2; n++) { auto c1 = fromhex(in[n * 2]), c2 = fromhex(in[n * 2 + 1]); out[n] = (T)((c1 << 4) | c2); } if(is_invalid) throw std::invalid_argument("Input is not hexadecimal."); return inlen / 2; } } // namespace string } // namespace algorithm QUICKCPPLIB_NAMESPACE_END #endif
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/algorithm/prime_modulus.hpp
/* Fixed overhead twos power prime modulus (C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (7 commits) File Created: Aug 2019 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef QUICKCPPLIB_ALGORITHM_PRIME_MODULUS_HPP #define QUICKCPPLIB_ALGORITHM_PRIME_MODULUS_HPP #include "../config.hpp" #include <cstdint> QUICKCPPLIB_NAMESPACE_BEGIN namespace algorithm { namespace prime_modulus { //! \brief Returns a constexpr prime just under a twos power e.g. for 8, you get 251, which is the prime just below (1<<8) = 256. Very handy for hash tables. constexpr inline uint64_t twos_power_prime(size_t power) noexcept { // Primes come from https://primes.utm.edu/lists/2small/0bit.html // There is a fascinatingly close relationship between powers of two and prime numbers, // as is obvious from the table below. See https://en.wikipedia.org/wiki/Mersenne_prime/. switch(power) { case 0: return 1; case 1: return 2; case 2: return (1ULL << 2) - 1; case 3: return (1ULL << 3) - 1; case 4: return (1ULL << 4) - 3; case 5: return (1ULL << 5) - 1; case 6: return (1ULL << 6) - 3; case 7: return (1ULL << 7) - 1; case 8: return (1ULL << 8) - 5; case 9: return (1ULL << 9) - 3; case 10: return (1ULL << 10) - 3; case 11: return (1ULL << 11) - 9; case 12: return (1ULL << 12) - 3; case 13: return (1ULL << 13) - 1; case 14: return (1ULL << 14) - 3; case 15: return (1ULL << 15) - 19; case 16: return (1ULL << 16) - 15; // case 17: return (1ULL << 17) - 1; case 18: return (1ULL << 18) - 5; case 19: return (1ULL << 19) - 1; case 20: return (1ULL << 20) - 3; case 21: return (1ULL << 21) - 9; case 22: return (1ULL << 22) - 3; case 23: return (1ULL << 23) - 15; case 24: return (1ULL << 24) - 3; case 25: return (1ULL << 25) - 39; case 26: return (1ULL << 26) - 5; case 27: return (1ULL << 27) - 39; case 28: return (1ULL << 28) - 57; case 29: return (1ULL << 29) - 3; case 30: return (1ULL << 30) - 35; case 31: return (1ULL << 31) - 1; // case 32: return (1ULL << 32) - 5; case 33: return (1ULL << 33) - 9; case 34: return (1ULL << 34) - 41; case 35: return (1ULL << 35) - 31; case 36: return (1ULL << 36) - 5; case 37: return (1ULL << 37) - 25; case 38: return (1ULL << 38) - 45; case 39: return (1ULL << 39) - 7; case 40: return (1ULL << 40) - 87; case 41: return (1ULL << 41) - 21; case 42: return (1ULL << 42) - 11; case 43: return (1ULL << 43) - 57; case 44: return (1ULL << 44) - 17; case 45: return (1ULL << 45) - 55; case 46: return (1ULL << 46) - 21; case 47: return (1ULL << 47) - 115; case 48: return (1ULL << 48) - 59; // case 49: return (1ULL << 49) - 81; case 50: return (1ULL << 50) - 27; case 51: return (1ULL << 51) - 129; case 52: return (1ULL << 52) - 47; case 53: return (1ULL << 53) - 111; case 54: return (1ULL << 54) - 33; case 55: return (1ULL << 55) - 55; case 56: return (1ULL << 56) - 5; case 57: return (1ULL << 57) - 13; case 58: return (1ULL << 58) - 27; case 59: return (1ULL << 59) - 55; case 60: return (1ULL << 60) - 93; case 61: return (1ULL << 61) - 1; case 62: return (1ULL << 62) - 57; case 63: return (1ULL << 63) - 25; case 64: return (0xffffffffffffffffULL - 58); //(1ULL << 64) - 59 default: return 0; } } namespace detail { template <uint32_t power, class T> constexpr inline T mod(T v) { return v % twos_power_prime(power); } } // namespace detail /*! \brief Return the modulus of a number by the prime just below a twos power. Implemented as a fixed jump table, so the compiler can avoid the CPU division opcode, which still costs 40-90 CPU cycles, and excludes all CPU level parallelism. Example: prime_modulus(1234, 8) is 1234 % 251 = 230. 251 is the next prime number below (1<<8) = 256. */ template <class T> constexpr inline T prime_modulus(T v, uint32_t power) { using detail::mod; switch(power) { case 0: return mod<0>(v); case 1: return mod<1>(v); case 2: return mod<2>(v); case 3: return mod<3>(v); case 4: return mod<4>(v); case 5: return mod<5>(v); case 6: return mod<6>(v); case 7: return mod<7>(v); case 8: return mod<8>(v); case 9: return mod<9>(v); case 10: return mod<10>(v); case 11: return mod<11>(v); case 12: return mod<12>(v); case 13: return mod<13>(v); case 14: return mod<14>(v); case 15: return mod<15>(v); case 16: return mod<16>(v); case 17: return mod<17>(v); case 18: return mod<18>(v); case 19: return mod<19>(v); case 20: return mod<20>(v); case 21: return mod<21>(v); case 22: return mod<22>(v); case 23: return mod<23>(v); case 24: return mod<24>(v); case 25: return mod<25>(v); case 26: return mod<26>(v); case 27: return mod<27>(v); case 28: return mod<28>(v); case 29: return mod<29>(v); case 30: return mod<30>(v); case 31: return mod<31>(v); case 32: return mod<32>(v); case 33: return mod<33>(v); case 34: return mod<34>(v); case 35: return mod<35>(v); case 36: return mod<36>(v); case 37: return mod<37>(v); case 38: return mod<38>(v); case 39: return mod<39>(v); case 40: return mod<40>(v); case 41: return mod<41>(v); case 42: return mod<42>(v); case 43: return mod<43>(v); case 44: return mod<44>(v); case 45: return mod<45>(v); case 46: return mod<46>(v); case 47: return mod<47>(v); case 48: return mod<48>(v); case 49: return mod<49>(v); case 50: return mod<50>(v); case 51: return mod<51>(v); case 52: return mod<52>(v); case 53: return mod<53>(v); case 54: return mod<54>(v); case 55: return mod<55>(v); case 56: return mod<56>(v); case 57: return mod<57>(v); case 58: return mod<58>(v); case 59: return mod<59>(v); case 60: return mod<60>(v); case 61: return mod<61>(v); case 62: return mod<62>(v); case 63: return mod<63>(v); case 64: return mod<64>(v); default: return 0; } } } // namespace prime_modulus } // namespace algorithm QUICKCPPLIB_NAMESPACE_END #endif
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/algorithm/bitwise_trie.hpp
/* Bitwise trie algorithm (C) 2010-2021 Niall Douglas <http://www.nedproductions.biz/> (7 commits) File Created: Jun 2016 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ /* This is basically a C++-ification of https://github.com/ned14/nedtries, and some of the implementation code is lifted from that library. */ /* On my Windows 10 laptop with VS2019: There are 1.99201 TSCs in 1 nanosecond and it takes 26 ticks per nanoclock(). For bitwise_trie: 1: 700 ns per item insert 2: 405 ns per item insert 4: 221.25 ns per item insert 8: 124.5 ns per item insert 16: 86.1875 ns per item insert 32: 54.5938 ns per item insert 64: 40 ns per item insert 128: 67.8438 ns per item insert 256: 56.4453 ns per item insert 512: 50.1895 ns per item insert 1024: 49.541 ns per item insert 2048: 52.668 ns per item insert 4096: 54.4043 ns per item insert 8192: 58.7235 ns per item insert 16384: 65.7745 ns per item insert 32768: 64.5418 ns per item insert 65536: 77.3544 ns per item insert 131072: 136.162 ns per item insert 262144: 235.861 ns per item insert 524288: 327.583 ns per item insert 1048576: 487.093 ns per item insert 2097152: 618.338 ns per item insert 4194304: 775.045 ns per item insert 8388608: 960.853 ns per item insert 16777216: 1193.55 ns per item insert 33554432: 1449.82 ns per item insert Allocating 1879048192 bytes, 28 bytes per item seems acceptable. For set: 1: 360 ns per item insert 2: 256 ns per item insert 4: 167.75 ns per item insert 8: 138.5 ns per item insert 16: 116.812 ns per item insert 32: 96.7188 ns per item insert 64: 348.109 ns per item insert 128: 257.531 ns per item insert 256: 258.66 ns per item insert 512: 179.943 ns per item insert 1024: 143.746 ns per item insert 2048: 135.893 ns per item insert 4096: 127.59 ns per item insert 8192: 127.266 ns per item insert 16384: 137.855 ns per item insert 32768: 158.687 ns per item insert 65536: 177.508 ns per item insert 131072: 268.773 ns per item insert 262144: 321.283 ns per item insert 524288: 438.037 ns per item insert 1048576: 678.942 ns per item insert 2097152: 954.575 ns per item insert 4194304: 1229.11 ns per item insert 8388608: 1503.02 ns per item insert 16777216: 1830.15 ns per item insert 33554432: 2183.64 ns per item insert Allocating 1879048192 bytes, 28 bytes per item seems acceptable. For unordered_set: 1: 903 ns per item insert 2: 580.5 ns per item insert 4: 361.75 ns per item insert 8: 257.625 ns per item insert 16: 204.188 ns per item insert 32: 168.438 ns per item insert 64: 139.391 ns per item insert 128: 125.227 ns per item insert 256: 113.055 ns per item insert 512: 107.533 ns per item insert 1024: 104.273 ns per item insert 2048: 104.322 ns per item insert 4096: 101.578 ns per item insert 8192: 101.251 ns per item insert 16384: 98.8997 ns per item insert 32768: 99.8262 ns per item insert 65536: 96.0937 ns per item insert 131072: 93.246 ns per item insert 262144: 97.9117 ns per item insert 524288: 107.957 ns per item insert 1048576: 121.08 ns per item insert 2097152: 124.938 ns per item insert 4194304: 132.597 ns per item insert 8388608: 141.761 ns per item insert 16777216: 158.779 ns per item insert 33554432: 194.535 ns per item insert duration 134773 ms */ #ifndef QUICKCPPLIB_ALGORITHM_BITWISE_TRIE_HPP #define QUICKCPPLIB_ALGORITHM_BITWISE_TRIE_HPP #define QUICKCPPLIB_ALGORITHM_BITWISE_TRIE_DEBUG 1 #include "../declval.hpp" #include <cassert> #include <cstring> // for memset #include <iterator> #include <type_traits> #if __cpp_exceptions && !QUICKCPPLIB_ALGORITHM_BITWISE_TRIE_DISABLE_EXCEPTION_THROWS #include <stdexcept> #endif QUICKCPPLIB_NAMESPACE_BEGIN namespace algorithm { namespace bitwise_trie { namespace detail { inline unsigned bitscanr(size_t value) { if(!value) return 0; #if defined(_MSC_VER) && !defined(__cplusplus_cli) { unsigned long bitpos; #if defined(_M_IA64) || defined(_M_X64) || defined(WIN64) assert(8 == sizeof(size_t)); _BitScanReverse64(&bitpos, value); #else assert(4 == sizeof(size_t)); _BitScanReverse(&bitpos, value); #endif return (unsigned) bitpos; } #elif defined(__GNUC__) return sizeof(value) * 8 /*CHAR_BIT*/ - 1 - (unsigned) __builtin_clzl(value); #else /* The following code is illegal C, but it almost certainly will work. If not use the legal implementation below */ #if !defined(__cplusplus_cli) union { unsigned asInt[2]; double asDouble; }; int n; asDouble = (double) value + 0.5; n = (asInt[0 /*Use 1 if your CPU is big endian!*/] >> 20) - 1023; #ifdef _MSC_VER #pragma message(__FILE__ ": WARNING: Make sure you change the line above me if your CPU is big endian!") #else #warning Make sure you change the line above me if your CPU is big endian! #endif return (unsigned) n; #else #if CHAR_BIT != 8 #error CHAR_BIT is not eight, and therefore this generic bitscan routine will need adjusting! #endif /* This is a generic 32 and 64 bit compatible branch free bitscan right */ size_t x = value; x = x | (x >> 1); x = x | (x >> 2); x = x | (x >> 4); x = x | (x >> 8); if(16 < sizeof(x) * CHAR_BIT) x = x | (x >> 16); if(32 < sizeof(x) * CHAR_BIT) x = x | (x >> 32); x = ~x; x = x - ((x >> 1) & (SIZE_MAX / 3)); x = (x & (SIZE_MAX / 15 * 3)) + ((x >> 2) & (SIZE_MAX / 15 * 3)); x = ((x + (x >> 4)) & (SIZE_MAX / UCHAR_MAX * 15)) * (SIZE_MAX / UCHAR_MAX); x = (CHAR_BIT * sizeof(x) - 1) - (x >> (CHAR_BIT * (sizeof(x) - 1))); return (unsigned) x; #endif #endif } template <int Dir> struct nobble_function_implementation { template <class T> constexpr bool operator()(T &&accessors) const noexcept { return accessors.flip_nobbledir(); } }; template <> struct nobble_function_implementation<-1> { template <class T> constexpr bool operator()(T && /*unused*/) const noexcept { return false; } }; template <> struct nobble_function_implementation<1> { template <class T> constexpr bool operator()(T && /*unused*/) const noexcept { return true; } }; template <class T, class ItemType, class = int> struct trie_sibling { static constexpr ItemType *get(const T * /*unused*/, bool /*unused*/, ItemType *r) noexcept { return r; } static constexpr bool set(T * /*unused*/, bool /*unused*/, ItemType * /*unused*/) noexcept { return false; } }; template <class T, class ItemType> struct trie_sibling<T, ItemType, decltype((void) ItemType::trie_sibling, 0)> { static constexpr ItemType *get(const T *inst, bool right, const ItemType * /*unused*/) noexcept { return inst->trie_sibling[right]; } static constexpr bool set(T *inst, bool right, ItemType *x) noexcept { inst->trie_sibling[right] = x; return true; } }; } // namespace detail /*! \class bitwise_trie_item_accessors \brief Default accessor for a bitwise trie item. \tparam ItemType The type of item indexed. This default accessor requires the following member variables in the trie item type: - `ItemType *trie_parent` - `ItemType *trie_child[2]` - `ItemType *trie_sibling[2]` - `KeyType trie_key` */ template <class ItemType> class bitwise_trie_item_accessors { ItemType *_v; public: constexpr bitwise_trie_item_accessors(ItemType *v) : _v(v) { } constexpr explicit operator bool() const noexcept { return _v != nullptr; } constexpr const ItemType *parent() const noexcept { assert(!parent_is_index()); return _v->trie_parent; } constexpr ItemType *parent() noexcept { assert(!parent_is_index()); return _v->trie_parent; } constexpr void set_parent(ItemType *x) noexcept { _v->trie_parent = x; } constexpr bool parent_is_index() const noexcept { return ((uintptr_t) _v->trie_parent & 3) == 3; } constexpr unsigned bit_index() const noexcept { assert(parent_is_index()); return ((unsigned) (uintptr_t) _v->trie_parent) >> 2; } constexpr void set_parent_is_index(unsigned bit_index) noexcept { _v->trie_parent = (ItemType *) (((uintptr_t) bit_index << 2) | 3); } constexpr const ItemType *child(bool right) const noexcept { return _v->trie_child[right]; } constexpr ItemType *child(bool right) noexcept { return _v->trie_child[right]; } constexpr void set_child(bool right, ItemType *x) noexcept { _v->trie_child[right] = x; } constexpr const ItemType *sibling(bool right) const noexcept { return detail::trie_sibling<ItemType, ItemType>::get(_v, right, _v); } constexpr ItemType *sibling(bool right) noexcept { return detail::trie_sibling<ItemType, ItemType>::get(_v, right, _v); } constexpr bool set_sibling(bool right, ItemType *x) noexcept { return detail::trie_sibling<ItemType, ItemType>::set(_v, right, x); } constexpr auto key() const noexcept { return _v->trie_key; } constexpr bool is_primary_sibling() const noexcept { return _v->trie_parent != nullptr; } // there is exactly one of these ever per key value constexpr void set_is_primary_sibling() noexcept { assert(_v->trie_parent != nullptr); } constexpr bool is_secondary_sibling() const noexcept { return _v->trie_parent == nullptr; } // i.e. has same key as primary sibling constexpr void set_is_secondary_sibling() noexcept { _v->trie_parent = nullptr; } }; /*! \class bitwise_trie_head_accessors \brief Default accessor for a bitwise trie index head. \tparam HeadBaseType The type from which `bitwise_trie` inherits \tparam ItemType The type of item indexed. This default accessor requires the following member variables in the trie index head type: - `<unsigned type> trie_count` - `ItemType *trie_children[8 * sizeof(<unsigned type>)]` - `bool trie_nobbledir` (if you use equal nobbling only) */ template <class HeadBaseType, class ItemType> class bitwise_trie_head_accessors { HeadBaseType *_v; using _index_type = decltype(_v->trie_count); static_assert(std::is_unsigned<_index_type>::value, "count type must be unsigned"); static constexpr size_t _index_type_bits = 8 * sizeof(_index_type); using _child_array_type = decltype(_v->trie_children); static_assert(sizeof(_child_array_type) / sizeof(void *) >= _index_type_bits, "children array is not big enough"); using _key_type = decltype(declval<bitwise_trie_item_accessors<ItemType> *>()->key()); public: constexpr bitwise_trie_head_accessors(HeadBaseType *v) : _v(v) { } constexpr explicit operator bool() const noexcept { return _v != nullptr; } constexpr _index_type size() const noexcept { return _v->trie_count; } constexpr void incr_size() noexcept { ++_v->trie_count; } constexpr void decr_size() noexcept { --_v->trie_count; } constexpr void set_size(_index_type x) noexcept { _v->trie_count = x; } constexpr _index_type max_size() const noexcept { return (_index_type) -1; } constexpr const ItemType *child(_index_type idx) const noexcept { return _v->trie_children[idx]; } constexpr ItemType *child(_index_type idx) noexcept { return _v->trie_children[idx]; } constexpr void set_child(_index_type idx, ItemType *x) noexcept { _v->trie_children[idx] = x; } constexpr _index_type lock_branch(_key_type key, bool exclusive, unsigned bitidxhint = (unsigned) -1) const noexcept // note return type can be ANY type { (void) key; (void) exclusive; (void) bitidxhint; return 0; } constexpr void unlock_branch(_index_type /*unused*/, bool /*unused*/) const noexcept {} constexpr bool flip_nobbledir() noexcept { return (_v->trie_nobbledir = !_v->trie_nobbledir); } }; /*! \class bitwise_trie \brief Never-allocating in-place bitwise Fredkin trie index head type. \tparam Base The base type from which to inherit (and thus overlay the index member functions). \tparam ItemType The type of item indexed. \tparam NobbleDir -1 to nobble zeros, +1 to nobble ones, 0 to nobble both equally (see below). This uses the bitwise Fredkin trie algorithm to index a collection of items by an unsigned integral key (e.g. a `size_t` from `std::hash`), providing identical O(log2 N) time insertion, removal, and finds (i.e. insert, remove and find all take identical time). It is thus most like a red-black tree. However it has a number of very useful characteristics which make it invaluable in certain use cases. Firstly, unlike a hash table, this algorithm requires no additional memory allocation whatsoever. It wholly and exclusively uses only the items added to the index, and the index head, for storage. This makes it invaluable for bootstrap type scenarios, such as in memory allocators or first boot of a kernel. It also works well with C++ exceptions globally disabled. Secondly, unlike a hash table it provides a _bounded time_ close fit find, which is particularly useful for where you need an item closely matching what you need, but you don't care if it's the *closest* matching item. An example of where this is super useful to have is in memory allocators, where you need a free block bigger than or equal to the size you are allocating. There is also a guaranteed closest rather than closely matching item find, however it is more expensive than a red-black tree whose guaranteed sortedness makes finding exact upper bounds easy. Thirdly, unlike any other algorithm, this one is much faster for low key values than large key values, so if you can keep most of your keys small, you will see more benefit. As you can see, bitwise tries have most of the same benefits of red-black trees, but they approximate hash tables for performance of insert-find-remove-findclosefit on most CPUs. This makes them very compelling where red-black trees are too slow, or where some concurrency is desirable (concurrent modify is easy to implement for all keys whose topmost set bit differs). The order of the items during iteration is *somewhat* sorted by key incrementing. Note the somewhat, it is fully ordered for each top bit set increment, but within each of those there is an interleave of insertion order and key increment. A bubble sort can be a good sort algorithm depending on relationship of key increment to insertion order, but you shouldn't assume it to be so without empirically checking. Items inserted with the same key preserve order of insertion. Performance is great on all CPUs which have a single cycle opcode for finding the first set bit in a key. If your CPU has a slow bitscan opcode (e.g. older Intel Atom), performance is merely good rather than great. The index is intrusive, as in, your types must provide the storage needed by the index for housekeeping. You can very tightly pack or compress or calculate those numbers by defining a specialised `bitwise_trie_head_accessors<Base, ItemType>` if you wish to customise storage of housekeeping for the trie index head; and/or specialise `bitwise_trie_item_accessors<ItemType>` if you wish to customise storage of housekeeping for each item indexed by the trie. The default implementations of those accessor types require various member variables prefixed with `trie_` in your types: - The default `bitwise_trie_head_accessors<Base, ItemType>` requires the following member variables in the trie index head type: - `<unsigned type> trie_count` - `ItemType *trie_children[8 * sizeof(<unsigned type>)]` - `bool trie_nobbledir` (if you use equal nobbling only) - The default `bitwise_trie_item_accessors<ItemType>` requires the following member variables in the trie item type: - `ItemType *trie_parent` - `ItemType *trie_child[2]` - `ItemType *trie_sibling[2]` (if you allow multiple items with the same key value only) - `KeyType trie_key` Again, I stress that the above can be completely customised and packed tighter with custom accessor type specialisations for your type. The tigher you can pack your structures, the more fits into L3 cache, and the faster everything goes. You can also store these in a file, and store offset pointers which are safe when a memory map relocates in memory. Close and closest fit finds always find an item whose key is larger or equal to the key sought. Lower bound is not implemented yet. Most of this implementation is lifted from https://github.com/ned14/nedtries, but it has been modernised for current C++ idomatic practice. ### Differences from a C++ container As this is an index, not a container, the value type is always a pointer. I chose pointers instead of references to aid readability i.e. it is very clear from reading code using this index that it is an index not a container. Because custom accessors may not store pointers as pointers, `reference` is not a reference, but also a pointer. Iteration thus yields pointers, not references. ### Nobble direction During item removal **only**, to keep the tree balanced one needs to choose which node to nobble. If for all the keys you use there is a surplus of zeros after the first set bit (this would be common for pointers), you should nobble zeros by setting the template parameter `NobbleDir` to `-1`. If for all the keys you use there is a surplus of ones after the first set bit, you should nobble ones by setting the template parameter `NobbleDir` to `1`. If for all the keys you use there is an equal balance between zeros and ones after the first set bit (this would be common for hashes), you will get the best results if you add state storage to keep a nobble direction boolean which flips between false and true such that nobbling is equally distributed. In this case, set `NobbleDir` to 0. tl;dr; If your key results from a hash function, choose `NobbleDir = 0`. If your key results from a pointer, or is some number which clusters on regular even boundaries, choose `NobbleDir = -1`. \todo Implement `lower_bound()`. */ template <class Base, class ItemType, int NobbleDir = 0> class bitwise_trie : public Base { constexpr bitwise_trie_head_accessors<const Base, const ItemType> _head_accessors() const noexcept { return bitwise_trie_head_accessors<const Base, const ItemType>(this); } constexpr bitwise_trie_head_accessors<Base, ItemType> _head_accessors() noexcept { return bitwise_trie_head_accessors<Base, ItemType>(this); } static constexpr bitwise_trie_item_accessors<const ItemType> _item_accessors(const ItemType *item) noexcept { return bitwise_trie_item_accessors<const ItemType>(item); } static constexpr bitwise_trie_item_accessors<ItemType> _item_accessors(ItemType *item) noexcept { return bitwise_trie_item_accessors<ItemType>(item); } template <class T> static constexpr bitwise_trie_item_accessors<T> _null_item_accessors(T * /*unused*/) noexcept { return bitwise_trie_item_accessors<T>(nullptr); } public: //! Key type indexing the items using key_type = decltype(_item_accessors(static_cast<ItemType *>(nullptr)).key()); //! The type of item indexed using mapped_type = ItemType *; //! The value type using value_type = ItemType *; //! The size type using size_type = decltype(bitwise_trie_head_accessors<const Base, const ItemType>(nullptr).size()); //! The type of a difference between pointers to the type of item indexed using difference_type = ptrdiff_t; //! A reference to the type of item indexed using reference = value_type; //! A const reference to the type of item indexed using const_reference = const ItemType; //! A pointer to the type of item indexed using pointer = ItemType *; //! A const pointer to the type of item indexed using const_pointer = const ItemType *; //! The direction of nobble configured. static constexpr int nobble_direction = (NobbleDir < 0) ? -1 : ((NobbleDir > 0) ? 1 : 0); private: static constexpr unsigned _key_type_bits = (unsigned) (8 * sizeof(key_type)); static_assert(std::is_unsigned<key_type>::value, "key type must be unsigned"); static_assert(std::is_unsigned<size_type>::value, "head_accessor size type must be unsigned"); bool _to_nobble() noexcept { return detail::nobble_function_implementation<nobble_direction>()(_head_accessors()); } struct _lock_unlock_branch { const bitwise_trie *_parent{nullptr}; bool _exclusive{false}; decltype(bitwise_trie_head_accessors<const Base, const ItemType>(nullptr).lock_branch((key_type) 0, 0)) _v; _lock_unlock_branch(const bitwise_trie *parent, key_type key, bool exclusive, unsigned bitidxhint = (unsigned) -1) noexcept : _parent(parent) , _exclusive(exclusive) , _v(parent->_head_accessors().lock_branch(key, bitidxhint)) { } ~_lock_unlock_branch() { if(_parent != nullptr) { _parent->_head_accessors().unlock_branch(_v, _exclusive); } } }; const_pointer _triemin() const noexcept { auto head = _head_accessors(); const_pointer node = nullptr; if(0 == head.size()) { return nullptr; } for(unsigned bitidx = 0; bitidx < _key_type_bits && nullptr == (node = head.child(bitidx)); bitidx++) ; assert(node != nullptr); return node; } pointer _triemin() noexcept { return const_cast<pointer>(static_cast<const bitwise_trie *>(this)->_triemin()); } const_pointer _triemax() const noexcept { auto head = _head_accessors(); const_pointer node = 0, child; if(0 == head.size()) { return nullptr; } unsigned bitidx = _key_type_bits - 1; for(; bitidx < _key_type_bits && nullptr == (node = head.child(bitidx)); bitidx--) ; assert(node != nullptr); auto nodelink = _item_accessors(node); _lock_unlock_branch lock_unlock(this, nodelink.key(), false, bitidx); while(nullptr != (child = (nodelink.child(true) != nullptr) ? nodelink.child(true) : nodelink.child(false))) { node = child; nodelink = _item_accessors(node); } /* Now go to end leaf */ if(nodelink.sibling(false) != node) { return nodelink.sibling(false); } return node; } pointer _triemax() noexcept { return const_cast<pointer>(static_cast<const bitwise_trie *>(this)->_triemax()); } pointer _trieinsert(pointer r) noexcept { auto head = _head_accessors(); if(head.size() >= head.max_size() - 1) { return nullptr; } pointer node = nullptr; auto nodelink = _item_accessors(node); auto rlink = _item_accessors(r); key_type rkey = rlink.key(); rlink.set_parent(nullptr); rlink.set_child(false, nullptr); rlink.set_child(true, nullptr); rlink.set_sibling(false, r); rlink.set_sibling(true, r); unsigned bitidx = detail::bitscanr(rkey); /* Avoid unknown bit shifts where possible, their performance can suck */ key_type keybit = (key_type) 1 << bitidx; assert(bitidx < _key_type_bits); if(nullptr == (node = head.child(bitidx))) { /* Set parent is index flag */ rlink.set_parent_is_index(bitidx); head.set_child(bitidx, r); head.incr_size(); return r; } _lock_unlock_branch lock_unlock(this, rkey, true, bitidx); for(pointer childnode = nullptr;; node = childnode) { nodelink = _item_accessors(node); key_type nodekey = nodelink.key(); if(nodekey == rkey) { /* Insert into end of ring list */ #if 0 { auto *left = nodelink.sibling(false), *right = nodelink.sibling(true); assert(left->trie_key == node->trie_key); assert(right->trie_key == node->trie_key); { auto link = _item_accessors(right); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(true)).sibling(false) == right); right = link.sibling(true); assert(right->trie_key == node->trie_key); link = _item_accessors(right); } assert(_item_accessors(link.sibling(true)).sibling(false) == right); } { auto link = _item_accessors(left); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(false)).sibling(true) == left); left = link.sibling(false); assert(left->trie_key == node->trie_key); link = _item_accessors(left); } assert(_item_accessors(link.sibling(false)).sibling(true) == left); } assert(left == right); } #endif rlink.set_is_secondary_sibling(); if(!rlink.set_sibling(true, node)) { return node; } auto *newest_sibling = nodelink.sibling(false); _item_accessors(newest_sibling).set_sibling(true, r); rlink.set_sibling(false, newest_sibling); nodelink.set_sibling(false, r); #if 0 { auto *left = rlink.sibling(false), *right = rlink.sibling(true); assert(left->trie_key == r->trie_key); assert(right->trie_key == r->trie_key); { auto link = _item_accessors(right); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(true)).sibling(false) == right); right = link.sibling(true); assert(right->trie_key == r->trie_key); link = _item_accessors(right); } assert(_item_accessors(link.sibling(true)).sibling(false) == right); } { auto link = _item_accessors(left); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(false)).sibling(true) == left); left = link.sibling(false); assert(left->trie_key == r->trie_key); link = _item_accessors(left); } assert(_item_accessors(link.sibling(false)).sibling(true) == left); } assert(left == right); } { auto *left = nodelink.sibling(false), *right = nodelink.sibling(true); assert(left->trie_key == node->trie_key); assert(right->trie_key == node->trie_key); { auto link = _item_accessors(right); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(true)).sibling(false) == right); right = link.sibling(true); assert(right->trie_key == node->trie_key); link = _item_accessors(right); } assert(_item_accessors(link.sibling(true)).sibling(false) == right); } { auto link = _item_accessors(left); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(false)).sibling(true) == left); left = link.sibling(false); assert(left->trie_key == node->trie_key); link = _item_accessors(left); } assert(_item_accessors(link.sibling(false)).sibling(true) == left); } assert(left == right); } #endif break; } keybit >>= 1; const bool keybitset = !!(rkey & keybit); childnode = nodelink.child(keybitset); if(nullptr == childnode) { /* Insert here */ rlink.set_parent(node); rlink.set_is_primary_sibling(); nodelink.set_child(keybitset, r); break; } } head.incr_size(); return r; } void _trieremove(pointer r) noexcept { auto head = _head_accessors(); pointer node = nullptr; auto nodelink = _item_accessors(node); auto rlink = _item_accessors(r); _lock_unlock_branch lock_unlock(this, rlink.key(), true); /* Am I a leaf off the tree? */ if(rlink.is_secondary_sibling()) { /* Remove from linked list */ assert(rlink.parent() == nullptr); #if 0 { auto *left = rlink.sibling(false), *right = rlink.sibling(true); assert(left->trie_key == r->trie_key); assert(right->trie_key == r->trie_key); { auto link = _item_accessors(right); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(true)).sibling(false) == right); right = link.sibling(true); assert(right->trie_key == r->trie_key); link = _item_accessors(right); } assert(_item_accessors(link.sibling(true)).sibling(false) == right); } { auto link = _item_accessors(left); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(false)).sibling(true) == left); left = link.sibling(false); assert(left->trie_key == r->trie_key); link = _item_accessors(left); } assert(_item_accessors(link.sibling(false)).sibling(true) == left); } assert(left == right); } #endif auto *left = rlink.sibling(false), *right = rlink.sibling(true); nodelink = _item_accessors(left); nodelink.set_sibling(true, right); nodelink = _item_accessors(right); nodelink.set_sibling(false, left); #if 0 { auto link = _item_accessors(right); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(true)).sibling(false) == right); right = link.sibling(true); assert(right->trie_key == r->trie_key); link = _item_accessors(right); } assert(_item_accessors(link.sibling(true)).sibling(false) == right); } { auto link = _item_accessors(left); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(false)).sibling(true) == left); left = link.sibling(false); assert(left->trie_key == r->trie_key); link = _item_accessors(left); } assert(_item_accessors(link.sibling(false)).sibling(true) == left); } assert(left == right); #endif head.decr_size(); #ifndef NDEBUG rlink.set_parent(nullptr); rlink.set_child(false, nullptr); rlink.set_child(true, nullptr); rlink.set_sibling(false, r); rlink.set_sibling(true, r); #endif return; } /* I must therefore be part of the tree */ assert(rlink.parent_is_index() || rlink.parent() != nullptr); assert(rlink.is_primary_sibling()); auto set_parent = [&]() { // sets rlink's parent to node, and node's parent to rlink's parent // Set the replacement node to my children, and their parent to the new node pointer childnode; if(nullptr != (childnode = rlink.child(false))) { auto childnodelink = _item_accessors(childnode); nodelink.set_child(false, childnode); childnodelink.set_parent(node); } if(nullptr != (childnode = rlink.child(true))) { auto childnodelink = _item_accessors(childnode); nodelink.set_child(true, childnode); childnodelink.set_parent(node); } // Set the replacement node parent to my parent, and its child if(rlink.parent_is_index()) { /* Extract my bitidx */ unsigned bitidx = rlink.bit_index(); assert(head.child(bitidx) == r); head.set_child(bitidx, node); nodelink.set_parent_is_index(bitidx); } else { auto parentlink = _item_accessors(rlink.parent()); if(parentlink.child(false) == r) { parentlink.set_child(false, node); } else { assert(parentlink.child(true) == r); parentlink.set_child(true, node); } nodelink.set_parent(rlink.parent()); } nodelink.set_is_primary_sibling(); #ifndef NDEBUG assert(node->trie_key == nodelink.sibling(false)->trie_key); rlink.set_parent(nullptr); rlink.set_child(false, nullptr); rlink.set_child(true, nullptr); rlink.set_sibling(false, r); rlink.set_sibling(true, r); #endif }; /* Can I replace me with a sibling? */ if(rlink.sibling(true) != r) { #if 0 { auto *left = rlink.sibling(false), *right = rlink.sibling(true); assert(left->trie_key == r->trie_key); assert(right->trie_key == r->trie_key); { auto link = _item_accessors(right); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(true)).sibling(false) == right); right = link.sibling(true); assert(right->trie_key == r->trie_key); link = _item_accessors(right); } assert(_item_accessors(link.sibling(true)).sibling(false) == right); } { auto link = _item_accessors(left); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(false)).sibling(true) == left); left = link.sibling(false); assert(left->trie_key == r->trie_key); link = _item_accessors(left); } assert(_item_accessors(link.sibling(false)).sibling(true) == left); } assert(left == right); } #endif auto *left = rlink.sibling(false), *right = rlink.sibling(true); nodelink = _item_accessors(left); nodelink.set_sibling(true, right); nodelink = _item_accessors(right); nodelink.set_sibling(false, left); #if 0 nodelink.set_parent_is_index(1); { auto link = _item_accessors(right); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(true)).sibling(false) == right); right = link.sibling(true); assert(right->trie_key == r->trie_key); link = _item_accessors(right); } assert(_item_accessors(link.sibling(true)).sibling(false) == right); } { auto link = _item_accessors(left); while(link.is_secondary_sibling()) { assert(_item_accessors(link.sibling(false)).sibling(true) == left); left = link.sibling(false); assert(left->trie_key == r->trie_key); link = _item_accessors(left); } assert(_item_accessors(link.sibling(false)).sibling(true) == left); } assert(left == right); #endif node = right; set_parent(); head.decr_size(); return; } /* Can I simply remove myself from my parent? */ if(nullptr == rlink.child(false) && nullptr == rlink.child(true)) { if(rlink.parent_is_index()) { /* Extract my bitidx */ unsigned bitidx = rlink.bit_index(); assert(head.child(bitidx) == r); head.set_child(bitidx, nullptr); } else { auto parentlink = _item_accessors(rlink.parent()); if(parentlink.child(false) == r) { parentlink.set_child(false, nullptr); } else { assert(parentlink.child(true) == r); parentlink.set_child(true, nullptr); } } head.decr_size(); #ifndef NDEBUG rlink.set_parent(nullptr); rlink.set_child(false, nullptr); rlink.set_child(true, nullptr); rlink.set_sibling(false, r); rlink.set_sibling(true, r); #endif return; } /* I need someone to replace me in the trie, so simply find any grandchild of mine (who has the right bits to be here) which has no children. */ const bool nobbledir = _to_nobble(); bool parentchildidx; pointer childnode; if(rlink.child(nobbledir) != nullptr) { childnode = rlink.child(nobbledir); parentchildidx = nobbledir; } else { childnode = rlink.child(!nobbledir); parentchildidx = !nobbledir; } auto childnodelink = _item_accessors(childnode); for(;;) { if(nullptr != childnodelink.child(nobbledir)) { childnode = childnodelink.child(nobbledir); parentchildidx = nobbledir; childnodelink = _item_accessors(childnode); continue; } if(nullptr != childnodelink.child(!nobbledir)) { childnode = childnodelink.child(!nobbledir); parentchildidx = !nobbledir; childnodelink = _item_accessors(childnode); continue; } break; } // Detach this grandchild from its parent _item_accessors(childnodelink.parent()).set_child(parentchildidx, nullptr); node = childnode; nodelink = childnodelink; // Set my parent to point at the replacement node set_parent(); head.decr_size(); } static const_pointer _triebranchprev(const_pointer r, bitwise_trie_item_accessors<const ItemType> *rlinkaddr = nullptr) noexcept { const_pointer node = nullptr, child = nullptr; auto nodelink = _item_accessors(node); auto rlink = _item_accessors(r); /* Am I a leaf off the tree? */ if(rlink.is_secondary_sibling()) { return rlink.sibling(false); } /* Trace up my parents to prev branch */ while(!rlink.parent_is_index()) { node = rlink.parent(); nodelink = _item_accessors(node); /* If I was on child[1] and there is a child[0], go to bottom of child[0] */ if(nodelink.child(true) == r && nodelink.child(false) != nullptr) { node = nodelink.child(false); nodelink = _item_accessors(node); /* Follow child[1] preferentially downwards */ while(nullptr != (child = (nodelink.child(true) != nullptr) ? nodelink.child(1) : nodelink.child(0))) { node = child; nodelink = _item_accessors(node); } } /* If I was already on child[0] or there are no more children, return this node */ /* Now go to end leaf */ if(nodelink.sibling(false) != node) { return nodelink.sibling(false); } return node; } /* I have reached the top of my trie, no more on this branch */ if(rlinkaddr != nullptr) { *rlinkaddr = rlink; } return nullptr; } const_pointer _trieprev(const_pointer r) const noexcept { auto head = _head_accessors(); const_pointer node = nullptr, child = nullptr; auto nodelink = _item_accessors(node); auto rlink = _item_accessors(r); _lock_unlock_branch lock_unlock(this, rlink.key(), false); rlink = _null_item_accessors(r); if((node = _triebranchprev(r, &rlink)) != nullptr || !rlink) { return node; } /* I have reached the top of my trie, so on to prev bin */ unsigned bitidx = rlink.bit_index(); assert(head.child(bitidx) == r); for(bitidx--; bitidx < _key_type_bits && nullptr == (node = head.child(bitidx)); bitidx--) ; if(bitidx >= _key_type_bits) { return nullptr; } nodelink = _item_accessors(node); /* Follow child[1] preferentially downwards */ while(nullptr != (child = (nodelink.child(1) != nullptr) ? nodelink.child(1) : nodelink.child(0))) { node = child; nodelink = _item_accessors(node); } /* Now go to end leaf */ if(nodelink.sibling(false) != node) { return nodelink.sibling(false); } return node; } pointer _trieprev(const_pointer r) noexcept { return const_cast<pointer>(static_cast<const bitwise_trie *>(this)->_trieprev(r)); } static const_pointer _triebranchnext(const_pointer r, bitwise_trie_item_accessors<const ItemType> *rlinkaddr = nullptr) noexcept { const_pointer node = nullptr; auto nodelink = _item_accessors(node); auto rlink = _item_accessors(r); /* Am I a leaf off the tree? */ if(rlink.sibling(true) != node) { r = rlink.sibling(true); rlink = _item_accessors(r); if(!rlink.is_primary_sibling()) { return r; } } /* Follow my children, preferring child[0] */ if(nullptr != (node = (rlink.child(false) != nullptr) ? rlink.child(false) : rlink.child(true))) { nodelink = _item_accessors(node); assert(nodelink.parent() == r); return node; } /* Trace up my parents to next branch */ while(!rlink.parent_is_index()) { node = rlink.parent(); nodelink = _item_accessors(node); if(nodelink.child(false) == r && nodelink.child(true) != nullptr) { return nodelink.child(true); } r = node; rlink = nodelink; } /* I have reached the top of my trie, no more on this branch */ if(rlinkaddr != nullptr) { *rlinkaddr = rlink; } return nullptr; } const_pointer _trienext(const_pointer r) const noexcept { auto head = _head_accessors(); const_pointer node = nullptr; auto rlink = _item_accessors(r); _lock_unlock_branch lock_unlock(this, rlink.key(), false); rlink = _null_item_accessors(r); if((node = _triebranchnext(r, &rlink)) != nullptr) { return node; } /* I have reached the top of my trie, so on to next bin */ unsigned bitidx = rlink.bit_index(); for(bitidx++; bitidx < _key_type_bits && nullptr == (node = head.child(bitidx)); bitidx++) ; if(bitidx >= _key_type_bits) { return nullptr; } return node; } pointer _trienext(const_pointer r) noexcept { return const_cast<pointer>(static_cast<const bitwise_trie *>(this)->_trienext(r)); } pointer _triefind(key_type rkey) const noexcept { auto head = _head_accessors(); if(0 == head.size()) { return nullptr; } const_pointer node = nullptr; unsigned bitidx = detail::bitscanr(rkey); /* Avoid unknown bit shifts where possible, their performance can suck */ key_type keybit = (key_type) 1 << bitidx; assert(bitidx < _key_type_bits); if(nullptr == (node = head.child(bitidx))) { return nullptr; } _lock_unlock_branch lock_unlock(this, rkey, false, bitidx); for(const_pointer childnode = nullptr;; node = childnode) { auto nodelink = _item_accessors(node); key_type nodekey = nodelink.key(); if(nodekey == rkey) { return const_cast<pointer>(node); } keybit >>= 1; const bool keybitset = !!(rkey & keybit); childnode = nodelink.child(keybitset); if(childnode == nullptr) { return nullptr; } } return nullptr; } /* The algorithm for this is the most complex in here, so it's worth documenting as it also documents the others. Firstly to describe the trie, it is a binary tree switching on each bit in the key: if the bit is zero, we go left, if one, we go right. In parallel to this, each node also stores a value, so during traversal down the tree we may well encounter the value we seek on our way. We thus get two orderings during a traversal, the first is somewhat randomly ordered, but we are guaranteed that each node is ordered with respect to the bit switches which occurred previous to encountering it i.e. the bit switches from the top of each branch will match that of the value encountered. The second ordering is by key increasing from left in the binary tree towards the right. If you think this through, for an equidistributed key, approximately half the time keys will be found during traversal downwards, the other half of the time keys will found at the end of traversal downwards in the leaf node. To create a close find for some given key value, we traverse down the trie, same as we would for exact find. If we exact find, we return immediately. Otherwise we reach the point at which the key would be inserted as a new leaf. From the perspective of the second ordering, every leaf node to the right of this point will contain values greater than our origin point, so by traversing right one will find all the values greater than our search key, by the second ordering. One therefore just traverses right until one finds the next rightmost leaf key. But, in the path between our origin point and the first rightmost leaf key, closer values to the search key may be encountered. We still need to find the first rightmost leaf key, as that is our maximum bound, but in so doing we should encounter all possible values between our search value and the value of that first rightmost leaf key. It's a bit hard to estimate the complexities of this operation with rounds approximating infinity. For an equidistributed key, the average should not exceed O(log2 N) where N is the number of items with the same top bit set. That's a worst case however. To estimate the average case, I still can't do better than the original nedtries documentation from 2010: it depends somewhat upon consecutive distance between keys. So, if the origin point is at X, and we need to find the first rightmost leaf key and there are say a run of six consecutive difference bits between the search key and the next rightmost leaf key, then we would have to traverse three parents upwards and three parents downwards to find the first rightmost leaf key. However the probability of there being six consecutive difference bits is identical to the probability of there being any other sequence of six bits, so the probability of there being two consecutive same bits is 0.25, of three consecutive same bits 0.125, of six consecutive same bits 0.015625. Therefore, most of the time, there will be very little parent traversal. It was a long time ago I did pure maths, but I vaguely remember that summing a series of 0.25 + 0.125 + 0.0625 ... approaches 0.5. That's a linear multiplier of bit difference which is one, so I'm going to suggest the average complexity of nearest find is O(1) for an equidistributed key. Email or other communications proving I am wrong is welcomed. Obviously, in the real world, this algorithm will mostly stall on main memory just like any binary tree if the tree is not in CPU cache. This is why bitwise Fredkin tries almost exactly approximate a 2x performance increase over red-black trees, because they are half as deep for the same item count, and therefore there are half as many main memory stalls, for large item counts. For smaller item counts, branch predictors since Haswell are basically statistical bitfield predictors, so you see O(1) performance similar to a hash table. Put simply, if all your binary tree fits inside L2 cache, the CPU can do four chained indirections in a similar time to a single indirection. */ pointer _trieCfind(key_type rkey, int64_t rounds) const noexcept { auto head = _head_accessors(); if(0 == head.size()) { return 0; } const_pointer node = nullptr, ret = nullptr; unsigned bitidx = detail::bitscanr(rkey); assert(bitidx < _key_type_bits); do { /* Keeping raising the bin until we find a larger key */ while(bitidx < _key_type_bits && nullptr == (node = head.child(bitidx))) { bitidx++; rkey = (key_type) 1 << bitidx; } if(bitidx >= _key_type_bits) { return nullptr; } /* Avoid unknown bit shifts where possible, their performance can suck */ key_type keybit = (key_type) 1 << bitidx; _lock_unlock_branch lock_unlock(this, keybit, false, bitidx); key_type retkey = (key_type) -1; /* Find where we would insert this key */ auto nodelink = _item_accessors(node); bool keybitset; for(const_pointer childnode = nullptr;; node = childnode, nodelink = _item_accessors(node)) { auto nodekey = nodelink.key(); /* If nodekey is a closer fit to search key, mark as best result so far */ if(nodekey >= rkey && nodekey - rkey < retkey) { ret = node; retkey = nodekey - rkey; } if(ret != nullptr) { --rounds; } if((retkey == 0 || rounds <= 0) && ret != nullptr) { return const_cast<pointer>(ret); } /* Which child branch should we check? */ keybit >>= 1; keybitset = !!(rkey & keybit); childnode = nodelink.child(keybitset); if(childnode == nullptr) { break; } } /* node now points at where we would insert the key. Find the rightmost leaf. */ if(keybitset == false && nodelink.child(true) != nullptr) { node = nodelink.child(true); do { nodelink = _item_accessors(node); auto nodekey = nodelink.key(); if(nodekey >= rkey && nodekey - rkey < retkey) { ret = node; retkey = nodekey - rkey; } if(ret != nullptr) { --rounds; } if(rounds <= 0 && ret != nullptr) { return const_cast<pointer>(ret); } node = (nodelink.child(false) != nullptr) ? nodelink.child(false) : nodelink.child(true); } while(node != nullptr); // We are at the rightmost leaf, so we have by now encountered the closest possible value return const_cast<pointer>(ret); } auto *origin = node; auto originlink = nodelink; while(!originlink.parent_is_index()) { node = originlink.parent(); nodelink = _item_accessors(node); auto nodekey = nodelink.key(); if(nodekey >= rkey && nodekey - rkey < retkey) { ret = node; retkey = nodekey - rkey; } if(ret != nullptr) { --rounds; } if(rounds <= 0 && ret != nullptr) { return const_cast<pointer>(ret); } if(nodelink.child(false) == origin && nodelink.child(true) != nullptr) { node = nodelink.child(true); do { nodelink = _item_accessors(node); nodekey = nodelink.key(); if(nodekey >= rkey && nodekey - rkey < retkey) { ret = node; retkey = nodekey - rkey; } if(ret != nullptr) { --rounds; } node = (nodelink.child(false) != nullptr) ? nodelink.child(false) : nodelink.child(true); } while(node != nullptr); // We are at the rightmost leaf, so we have by now encountered the closest possible value return const_cast<pointer>(ret); } else { origin = node; originlink = nodelink; } } /* Move up a branch, resetting key sought to the smallest possible for that branch */ bitidx++; rkey = (key_type) 1 << bitidx; } while(nullptr == ret); return const_cast<pointer>(ret); } #ifndef NDEBUG struct _trie_validity_state { size_type count, tops, lefts, rights, leafs; key_type smallestkey, largestkey; }; static void _triecheckvaliditybranch(const_pointer node, key_type bitidx, _trie_validity_state &state) noexcept { auto nodelink = _item_accessors(node); key_type nodekey = nodelink.key(); if(nodekey < state.smallestkey) { state.smallestkey = nodekey; } if(nodekey > state.largestkey) { state.largestkey = nodekey; } assert(nodelink.parent() != nullptr); auto *child = nodelink.parent(); auto childlink = _item_accessors(child); assert(childlink.child(0) == node || childlink.child(1) == node); assert(node == childlink.child(!!(nodekey & ((key_type) 1 << bitidx)))); while(_item_accessors(child = nodelink.sibling(true)).is_secondary_sibling()) { state.leafs++; childlink = _item_accessors(child); assert(nullptr == childlink.parent()); assert(nullptr == childlink.child(0)); assert(nullptr == childlink.child(1)); assert(child == _item_accessors(childlink.sibling(false)).sibling(true)); assert(child == _item_accessors(childlink.sibling(true)).sibling(false)); nodelink = childlink; state.count++; } nodelink = _item_accessors(node); state.count++; if(nodelink.child(0) != nullptr) { state.lefts++; _triecheckvaliditybranch(nodelink.child(0), bitidx - 1, state); } if(nodelink.child(1) != nullptr) { state.rights++; _triecheckvaliditybranch(nodelink.child(1), bitidx - 1, state); } } #endif public: void triecheckvalidity(const key_type *tocheck = nullptr) const noexcept { (void) tocheck; #ifndef NDEBUG auto head = _head_accessors(); const_pointer node = nullptr, child = nullptr; _trie_validity_state state; memset(&state, 0, sizeof(state)); for(unsigned n = 0; n < _key_type_bits; n++) { if(tocheck != nullptr) { if((((key_type) -1 << n) & *tocheck) != ((key_type) 1 << n)) { continue; } } if((node = head.child(n)) != nullptr) { auto nodelink = _item_accessors(node); key_type nodekey = nodelink.key(); _lock_unlock_branch lock_unlock(this, nodekey, false, n); state.tops++; auto bitidx = nodelink.bit_index(); assert(bitidx == n); assert(head.child(bitidx) == node); assert(0 == nodekey || ((((size_t) -1) << bitidx) & nodekey) == ((size_t) 1 << bitidx)); while(_item_accessors(child = nodelink.sibling(true)).is_secondary_sibling()) { state.leafs++; auto childlink = _item_accessors(child); assert(nullptr == childlink.parent()); assert(nullptr == childlink.child(false)); assert(nullptr == childlink.child(true)); assert(child == _item_accessors(childlink.sibling(false)).sibling(true)); assert(child == _item_accessors(childlink.sibling(true)).sibling(false)); nodelink = childlink; state.count++; } nodelink = _item_accessors(node); state.count++; if(nodelink.child(0) != nullptr) { state.lefts++; state.smallestkey = (key_type) -1; state.largestkey = 0; _triecheckvaliditybranch(nodelink.child(0), bitidx - 1, state); assert(0 == state.smallestkey || state.smallestkey >= (key_type) 1 << bitidx); assert(bitidx + 1 >= _key_type_bits || state.largestkey < (key_type) 1 << (bitidx + 1)); } if(nodelink.child(1) != nullptr) { state.rights++; state.smallestkey = (key_type) -1; state.largestkey = 0; _triecheckvaliditybranch(nodelink.child(1), bitidx - 1, state); assert(state.smallestkey >= (key_type) 1 << bitidx); assert(bitidx + 1 >= _key_type_bits || state.largestkey < (key_type) 1 << (bitidx + 1)); } } } if(tocheck == nullptr) { assert(state.count == head.size()); } #if 1 for(state.count = 0, node = _triemin(); node != nullptr; (node = _trienext(node)), state.count++) #if 0 printf("%p\n", node) #endif ; if(state.count != head.size()) { assert(state.count == head.size()); } #if 0 printf("\n"); #endif for(state.count = 0, node = _triemax(); node != nullptr; (node = _trieprev(node)), state.count++) #if 0 printf("%p\n", node) #endif ; if(state.count != head.size()) { assert(state.count == head.size()); } #if 0 printf("\n"); #endif #if !defined(NDEBUG) && 0 if(count > 50) printf("Of count %u, tops %.2lf%%, lefts %.2lf%%, rights %.2lf%%, leafs %.2lf%%\n", count, 100.0 * tops / count, 100.0 * lefts / count, 100.0 * rights / count, 100.0 * leafs / count); #endif #endif /* !NDEBUG */ #endif } private: template <bool is_const, class Parent, class Pointer, class Reference> class iterator_ { friend class bitwise_trie; template <bool _is_const, class _Parent, class _Pointer, class _Reference> friend class iterator_; Parent *_parent{nullptr}; Pointer _p{nullptr}; iterator_ &_inc() noexcept { if(_parent != nullptr && _p != nullptr) { _p = _parent->_trienext(_p); } return *this; } iterator_ &_dec() noexcept { if(_parent != nullptr) { if(_p == nullptr) { _p = _parent->_triemax(); } else { _p = _parent->_trieprev(_p); } } return *this; } constexpr iterator_(const Parent *parent, Pointer p) noexcept : _parent(const_cast<Parent *>(parent)) , _p(p) { } constexpr iterator_(const Parent *parent) noexcept : _parent(const_cast<Parent *>(parent)) , _p(nullptr) { } struct _implicit_nonconst_to_const_conversion { }; struct _explicit_const_to_nonconst_conversion { }; public: using difference_type = typename Parent::difference_type; using value_type = typename Parent::value_type; using pointer = Pointer; using reference = Reference; using iterator_category = std::bidirectional_iterator_tag; constexpr iterator_() noexcept : _parent(nullptr) , _p(nullptr) { } constexpr iterator_(const iterator_ &) = default; constexpr iterator_(iterator_ &&) noexcept = default; constexpr iterator_ &operator=(const iterator_ &) = default; constexpr iterator_ &operator=(iterator_ &&) noexcept = default; // Implicit non-const to const iterator QUICKCPPLIB_TEMPLATE(class _Parent, class _Pointer, class _Reference) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(is_const &&std::is_same<typename std::remove_const<Parent>::type, _Parent>::value)) constexpr iterator_(const iterator_<false, _Parent, _Pointer, _Reference> &o, _implicit_nonconst_to_const_conversion = {}) noexcept : _parent(o._parent) , _p(o._p) { } // Explicit const to non-const iterator QUICKCPPLIB_TEMPLATE(class _Parent, class _Pointer, class _Reference) QUICKCPPLIB_TREQUIRES(QUICKCPPLIB_TPRED(!is_const && std::is_same<typename std::remove_const<_Parent>::type, Parent>::value)) explicit constexpr iterator_(const iterator_<true, _Parent, _Pointer, _Reference> &o, _explicit_const_to_nonconst_conversion = {}) noexcept : _parent(const_cast<Parent *>(o._parent)) , _p(const_cast<Pointer>(o._p)) { } void swap(iterator_ &o) noexcept { std::swap(_parent, o._parent); std::swap(_p, o._p); } explicit operator bool() const noexcept { return _parent != nullptr && _p != nullptr; } bool operator!() const noexcept { return _parent == nullptr || _p == nullptr; } Pointer operator->() noexcept { return _p; } const Pointer operator->() const noexcept { return _p; } bool operator==(const iterator_ &o) const noexcept { return _parent == o._parent && _p == o._p; } bool operator!=(const iterator_ &o) const noexcept { return _parent != o._parent || _p != o._p; } Reference operator*() noexcept { if(_parent == nullptr || _p == nullptr) { abort(); } return _p; } const Reference operator*() const noexcept { if(_parent == nullptr || _p == nullptr) { abort(); } return _p; } iterator_ &operator++() noexcept { return _inc(); } iterator_ operator++(int) noexcept { iterator_ ret(*this); ++*this; return ret; } iterator_ &operator--() noexcept { return _dec(); } iterator_ operator--(int) noexcept { iterator_ ret(*this); --*this; return ret; } bool operator<(const iterator_ &o) const noexcept { if(_parent != o._parent) { abort(); } return _p != nullptr && (o._p == nullptr || _p < o._p); } bool operator>(const iterator_ &o) const noexcept { if(_parent != o._parent) { abort(); } return o._p != nullptr && (_p == nullptr || _p > o._p); } bool operator<=(const iterator_ &o) const noexcept { if(_parent != o._parent) { abort(); } return !(o > *this); } bool operator>=(const iterator_ &o) const noexcept { if(_parent != o._parent) { abort(); } return !(o < *this); } }; public: //! The iterator type using iterator = iterator_<false, bitwise_trie, pointer, reference>; //! The const iterator type using const_iterator = iterator_<true, const bitwise_trie, const_pointer, const_reference>; //! The reverse iterator type using reverse_iterator = std::reverse_iterator<iterator>; //! The const reverse iterator type using const_reverse_iterator = std::reverse_iterator<const_iterator>; static_assert(std::is_convertible<iterator, const_iterator>::value, "iterator is not implicitly convertible to const_iterator"); static_assert(!std::is_convertible<const_iterator, iterator>::value, "iterator is implicitly convertible to const_iterator"); static_assert(std::is_constructible<iterator, const_iterator>::value, "iterator is not explicitly constructible from const_iterator"); constexpr bitwise_trie() { clear(); } bitwise_trie(const bitwise_trie &o) noexcept { auto myhead = _head_accessors(); auto ohead = o._head_accessors(); for(unsigned n = 0; n < _key_type_bits; n++) { myhead.set_child(n, ohead.child(n)); } myhead.set_size(ohead.size()); } bitwise_trie &operator=(const bitwise_trie &o) noexcept { auto myhead = _head_accessors(); auto ohead = o._head_accessors(); for(unsigned n = 0; n < _key_type_bits; n++) { myhead.set_child(n, ohead.child(n)); } myhead.set_size(ohead.size()); return *this; } //! Swaps the contents of the index void swap(bitwise_trie &o) noexcept { auto myhead = _head_accessors(); auto ohead = o._head_accessors(); for(unsigned n = 0; n < _key_type_bits; n++) { auto t = myhead.child(n); myhead.set_child(n, ohead.child(n)); ohead.set_child(n, t); } auto t = myhead.size(); myhead.set_size(ohead.size()); ohead.set_size(t); } //! True if the bitwise trie is empty QUICKCPPLIB_NODISCARD constexpr bool empty() const noexcept { return size() == 0; } //! Returns the number of items in the bitwise trie constexpr size_type size() const noexcept { return _head_accessors().size(); } //! Returns the maximum number of items in the index constexpr size_type max_size() const noexcept { return _head_accessors().max_size(); } //! Returns the front of the index. reference front() noexcept { if(auto p = _triemin()) { return *p; } abort(); } //! Returns the front of the index. const_reference front() const noexcept { if(auto p = _triemin()) { return *p; } abort(); } //! Returns the back of the index. reference back() noexcept { if(auto p = _triemax()) { return *p; } abort(); } //! Returns the back of the index. const_reference back() const noexcept { if(auto p = _triemax()) { return *p; } abort(); } //! Returns an iterator to the first item in the index. iterator begin() noexcept { if(auto p = _triemin()) { return iterator(this, p); } return iterator(this); } //! Returns an iterator to the first item in the index. const_iterator begin() const noexcept { if(auto p = _triemin()) { return const_iterator(this, p); } return const_iterator(this); } //! Returns an iterator to the last item in the index. reverse_iterator rbegin() noexcept { if(auto p = _triemax()) { return reverse_iterator(iterator(this, p)); } return reverse_iterator(iterator(this)); } //! Returns an iterator to the last item in the index. const_reverse_iterator rbegin() const noexcept { if(auto p = _triemax()) { return const_reverse_iterator(const_iterator(this, p)); } return const_reverse_iterator(const_iterator(this)); } //! Returns an iterator to the first item in the index. const_iterator cbegin() const noexcept { return begin(); } //! Returns an iterator to the last item in the index. const_reverse_iterator crbegin() const noexcept { return rbegin(); } //! Returns an iterator to the item after the last in the index. iterator end() noexcept { return iterator(this); } //! Returns an iterator to the item before the first in the index. const_iterator end() const noexcept { return const_iterator(this); } //! Returns an iterator to the item before the first in the index. reverse_iterator rend() noexcept { return reverse_iterator(iterator(this)); } //! Returns an iterator to the item before the first in the index. const_reverse_iterator rend() const noexcept { return const_reverse_iterator(const_iterator(this)); } //! Returns an iterator to the item after the last in the index. const_iterator cend() const noexcept { return const_iterator(this); } //! Returns an iterator to the item before the first in the index. const_reverse_iterator crend() const noexcept { return const_reverse_iterator(const_iterator(this)); } //! Clears the index. constexpr void clear() noexcept { auto head = _head_accessors(); for(unsigned n = 0; n < _key_type_bits; n++) { head.set_child(n, nullptr); } head.set_size(0); } //! Return how many items with key there are. size_type count(key_type k) const noexcept { return count(find(k)); } //! Return how many items with the same key as iterator there are. size_type count(const_iterator it) const noexcept { if(it != end()) { size_type ret = 1; auto plink = _item_accessors(it._p); for(auto *i = plink.sibling(true); i != it._p; i = _item_accessors(i).sibling(true)) { ret++; } return ret; } return 0; } /*! Inserts a new item, returning an iterator to the new item if the key is new. If there is an item with that key already, if sibling storage is enabled, insert a new item with the same key. If sibling storage is disabled, return an iterator to the existing item. If the maximum number of items has been inserted, if C++ exceptions are disabled or `QUICKCPPLIB_ALGORITHM_BITWISE_TRIE_DISABLE_EXCEPTION_THROWS != 0`, the returned iterator is invalid if there is no more space. Otherwise it throws `std::length_error`. */ iterator insert(pointer p) { if(size() == max_size()) { #if __cpp_exceptions && !QUICKCPPLIB_ALGORITHM_BITWISE_TRIE_DISABLE_EXCEPTION_THROWS throw std::length_error("too many items"); #else return end(); #endif } p = _trieinsert(p); if(p != nullptr) { return iterator(this, p); } return end(); } //! Erases an item. iterator erase(const_iterator it) noexcept { if(it == end()) { assert(it != end()); return end(); } iterator ret(this, const_cast<pointer>(it._p)); ++ret; _trieremove(const_cast<pointer>(it._p)); return ret; } //! Erases an item. iterator erase(key_type k) noexcept { return erase(find(k)); } //! Finds an item iterator find(key_type k) const noexcept { if(auto p = _triefind(k)) { return iterator(this, p); } return iterator(this); } /*! Finds either an item with identical key, or an item with a larger key. The higher the value in `rounds`, the less average distance between the larger key and the key requested. The complexity of this function is bound by `rounds`. Some useful statistics about `rounds` values for five million ideally distributed keys: - `rounds = 17` returns an item with key 99.99% close to the ideal key. - `rounds = 12` returns an item with key 99.9% close to the ideal key. - `rounds = 7` returns an item with key 99.1% close to the ideal key. - `rounds = 3` returns an item with key 95.1% close to the ideal key. - `rounds = 2` returns an item with key 92% close to the ideal key. */ iterator find_equal_or_larger(key_type k, int64_t rounds) const noexcept { if(auto p = _trieCfind(k, rounds)) { return iterator(this, p); } return iterator(this); } //! Finds either an item with identical key, or an item with the guaranteed next largest key. This is //! identical to `close_find(k, INT64_MAX)` and its average case complexity is `O(log N)` where `N` is //! the number of items in the index with the same top bit set. This is equivalent to `upper_bound(k - 1)`. iterator find_equal_or_next_largest(key_type k) const noexcept { if(auto p = _trieCfind(k, INT64_MAX)) { return iterator(this, p); } return iterator(this); } //! Finds the item next larger than the key. This is equivalent to `find_equal_or_next_largest(k + 1)`. iterator upper_bound(key_type k) const noexcept { if(auto p = _trieCfind(k + 1, INT64_MAX)) { return iterator(this, p); } return iterator(this); } //! Estimate the item next larger than the key. This is equivalent to `find_equal_or_larger(k + 1, rounds)`. iterator upper_bound_estimate(key_type k, int64_t rounds) const noexcept { if(auto p = _trieCfind(k + 1, rounds)) { return iterator(this, p); } return iterator(this); } //! True if the index contains the key bool contains(key_type k) const noexcept { return nullptr != _triefind(k); } //! Returns a reference to the specified element, aborting if key not found. reference operator[](key_type k) noexcept { if(auto p = _triefind(k)) { return *p; } abort(); } //! Returns a reference to the specified element, aborting if key not found. const_reference operator[](const key_type &k) const noexcept { if(auto p = _triefind(k)) { return *p; } abort(); } }; } // namespace bitwise_trie } // namespace algorithm QUICKCPPLIB_NAMESPACE_END #endif
0
repos/outcome/test/quickcpplib/include/quickcpplib
repos/outcome/test/quickcpplib/include/quickcpplib/algorithm/open_hash_index.hpp
/* Very fast threadsafe unordered lookup (C) 2016-2017 Niall Douglas <http://www.nedproductions.biz/> (5 commits) File Created: Aug 2016 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef QUICKCPPLIB_ALGORITHM_OPEN_HASH_INDEX_HPP #define QUICKCPPLIB_ALGORITHM_OPEN_HASH_INDEX_HPP #include "../spinlock.hpp" #include <cstddef> // for ptrdiff_t etc #include <cstdint> // for uint32_t etc #include <cstdlib> // for abort() QUICKCPPLIB_NAMESPACE_BEGIN namespace algorithm { namespace open_hash_index { namespace detail { template <size_t limit, class Container, class U> auto linear_find(Container &c, size_t hint, U &&pred) -> decltype(&c[0]) { if(pred(c[hint])) return &c[hint]; size_t idx1 = hint, idx2 = hint; for(size_t n = 0; n < limit; n++) { --idx1; ++idx2; if(idx2 < c.size() && pred(c[idx2])) return &c[idx2]; if(idx1 < c.size() && pred(c[idx1])) return &c[idx1]; } return nullptr; } template <class T> auto look_for_lock_shared(int) -> typename std::enable_if<std::is_same<decltype(std::declval<T>().lock_shared()), decltype(std::declval<T>().lock_shared())>::value, std::true_type>::type; template <class T> std::false_type look_for_lock_shared(...); template <class T> struct is_shared_mutex : decltype(look_for_lock_shared<T>(0)) { }; template <bool lock_is_shared> struct lock_shared_if { template <class T> lock_shared_if(T &lock) { lock.lock(); } }; template <> struct lock_shared_if<true> { template <class T> lock_shared_if(T &lock) { lock.lock_shared(); } }; template <bool lock_is_shared> struct unlock_shared_if { template <class T> unlock_shared_if(T &lock) { lock.unlock(); } }; template <> struct unlock_shared_if<true> { template <class T> unlock_shared_if(T &lock) { lock.unlock_shared(); } }; } //! Performs k % divisor which is up to 40 CPU cycles depending on architecture template <class KeyType> struct arithmetic_modulus { size_t operator()(const KeyType &k, size_t divisor) const noexcept { return divisor ? static_cast<size_t>(k % divisor) : 0; } }; //! Performs k & (divisor-1) which is typically one or two CPU cycles. Suitable if divisor is always going to be a two's power. template <class KeyType> struct twos_power_modulus { size_t operator()(const KeyType &k, size_t divisor) const noexcept { return divisor ? static_cast<size_t>(k & (divisor - 1)) : 0; } }; /*! \struct linear_memory_policy \brief The simplest possible open_hash_index memory policy, with just the key, value and a boolean marking if the item is in use. A linear scan is performed up to LinearSearchLimit either side of any collision. \tparam KeyType The type of key to use. Must be a trivial type which acts as if an unsigned integer type. \tparam T The type of mapped value to use. \tparam LinearSearchLimit How far to search either side of a collison for an entry or an empty slot. \tparam KeyModulus A callable which performs modulus of the KeyType with the storage container's size. If you know the container's size will always be a power of two, use `twos_power_modulus` instead of `arithmetic_modulus`. \tparam KeyCompare A callable which compares two KeyTypes. */ template <class KeyType, class T, size_t LinearSearchLimit = 2, class KeyModulus = arithmetic_modulus<KeyType>, class KeyCompare = std::equal_to<KeyType>> struct linear_memory_policy { using key_type = typename std::add_const<KeyType>::type; using mapped_type = T; struct value_type { using first_type = key_type; using second_type = mapped_type; key_type first; bool _inuse; mapped_type second; constexpr value_type() : first() , _inuse(false) , second() { } template <class U, class V> constexpr value_type(U &&f, V &&s) : first(std::forward<U>(f)) , _inuse(false) , second(std::forward<V>(s)) { } template <class U, class V> constexpr value_type(const std::pair<U, V> &v) : first(v.first) , _inuse(false) , second(v.second) { } template <class U, class V> constexpr value_type(std::pair<U, V> &&v) : first(std::move(v.first)) , _inuse(false) , second(std::move(v.second)) { } value_type(value_type &&o) noexcept : first(std::move(o.first)), _inuse(o._inuse), second(std::move(o.second)) {} value_type &operator=(value_type &&o) noexcept { this->~value_type(); new(this) value_type(std::move(o)); return *this; } constexpr bool operator==(const value_type &o) const noexcept { return first == o.first && second == o.second; } constexpr bool operator!=(const value_type &o) const noexcept { return first != o.first || second != o.second; } constexpr bool operator<(const value_type &o) const noexcept { return first < o.first || (first == o.first && second < o.second); } constexpr bool operator<=(const value_type &o) const noexcept { return first < o.first || (first == o.first && second <= o.second); } constexpr bool operator>(const value_type &o) const noexcept { return o < *this; } constexpr bool operator>=(const value_type &o) const noexcept { return !(*this < o); } }; using size_type = size_t; using difference_type = ptrdiff_t; using reference = value_type &; using const_reference = const value_type &; using pointer = value_type *; using const_pointer = const value_type *; using items_count_type = size_t; // True if item is in use static bool is_inuse(const value_type *p) noexcept { return p->_inuse; } // Returns a pointer to an item if it is in use static pointer if_inuse_to_pointer(value_type *p) noexcept { return pointer(p->_inuse ? p : nullptr); } // Returns a pointer to an item if it is in use static const_pointer if_inuse_to_pointer(const value_type *p) noexcept { return const_pointer(p->_inuse ? p : nullptr); } // Looks up a key in the contiguous container returning a value_type_ptr to any value_type found template <class Container> static pointer find_exclusive(Container &c, const key_type &k) noexcept { auto count = c.size(); if(!count) return nullptr; return detail::linear_find<LinearSearchLimit>(c, KeyModulus()(k, count), [&k](const_reference v) { return v._inuse && KeyCompare()(k, v.first); }); } // Looks up a key in the contiguous container returning a value_type_ptr to any value_type found template <class Container> static const_pointer find_shared(const Container &c, const key_type &k) noexcept { auto count = c.size(); if(!count) return nullptr; return detail::linear_find<LinearSearchLimit>(c, KeyModulus()(k, count), [&k](const_reference v) { return v._inuse && KeyCompare()(k, v.first); }); } // Inserts an item into the contiguous container returning a value_type_ptr to any value_type found template <class Container> static pointer insert(Container &c, value_type &&newv) noexcept { return detail::linear_find<LinearSearchLimit>(c, KeyModulus()(newv.first, c.size()), [&newv](reference v) { if(v._inuse) return false; v = std::move(newv); v._inuse = true; return true; }); } // Removes an item, returning by value the value_type removed. If returned item doesn't have its bool set, key was not found. static std::pair<value_type, bool> erase(pointer v) noexcept { value_type ret; if(v) { ret = std::move(*v); v->_inuse = false; return std::make_pair(std::move(ret), true); } return std::make_pair(std::move(ret), false); } // Removes an item, returning by value the value_type removed. If returned item doesn't have its bool set, key was not found. template <class Container> static std::pair<value_type, bool> erase(Container &c, const key_type &k) noexcept { return erase(find_exclusive(c, k)); } }; /*! \struct atomic_linear_memory_policy \brief Like `linear_memory_policy`, but threadsafe for key finding, insertion and removal. \warning Anything returning an iterator is threadsafe because any iterator holds the lock on the item until it is destructed, but anything returning a reference is NOT THREADSAFE. Additionally, all finds which traverse a locked item if `LinearSearchLimit` is not zero must necessarily spin on that lock even if that item isn't actually the right one, so if you set `LinearSearchLimit` to anything but zero, then you can only ever safely take one exclusive lock at a time ever, otherwise there is a chance of deadlock. \note If you use a `SharedMutex` instead of a `Mutex` as the LockType (detected via Expression SFINAE), const operations returning a `const_iterator` will take a shared lock instead of an exclusive lock. That makes concurrent read-only usage non-blocking. \note Because iterators hold a lock to their pointed to item, iterators are move only and cannot be copied. As basic_open_hash_index is a hash table, simply look up a new iterator, though obviously looking up the same key twice means instant deadlock unless you are using a shared or recursive mutex as the lock. \tparam KeyType The type of key to use. Must be a trivial type which acts as if an unsigned integer type. \tparam T The type of mapped value to use. \tparam LinearSearchLimit How far to search either side of a collison for an entry or an empty slot. \tparam LockType The type of `Mutex` or `SharedMutex` to use as the lock type. \tparam KeyModulus A callable which performs modulus of the KeyType with the storage container's size. If you know the container's size will always be a power of two, use `twos_power_modulus` instead of `arithmetic_modulus`. \tparam KeyCompare A callable which compares two KeyTypes. */ template <class KeyType, class T, size_t LinearSearchLimit = 0, class LockType = configurable_spinlock::spinlock<uint32_t>, class KeyModulus = arithmetic_modulus<KeyType>, class KeyCompare = std::equal_to<KeyType>> struct atomic_linear_memory_policy { using key_type = typename std::add_const<KeyType>::type; using mapped_type = T; using lock_type = LockType; static constexpr bool lock_type_is_shared = detail::is_shared_mutex<lock_type>::value; struct value_type { using first_type = key_type; using second_type = mapped_type; mutable lock_type lock; std::atomic<uint32_t> _inuse; // 0 = not in use, 1 = in use, 2 = being constructed or destroyed right now key_type first; mapped_type second; constexpr value_type() : _inuse(0) , first() , second() { } template <class U, class V> constexpr value_type(U &&f, V &&s) : _inuse(0) , first(std::forward<U>(f)) , second(std::forward<V>(s)) { } template <class U, class V> constexpr value_type(const std::pair<U, V> &v) : _inuse(false) , first(v.first) , second(v.second) { } template <class U, class V> constexpr value_type(std::pair<U, V> &&v) : _inuse(false) , first(std::move(v.first)) , second(std::move(v.second)) { } value_type(value_type &&o) noexcept : _inuse(o._inuse.exchange(0)), first(std::move(o.first)), second(std::move(o.second)) {} value_type(const value_type &) = delete; value_type &operator=(value_type &&o) noexcept { this->~value_type(); new(this) value_type(std::move(o)); return *this; } constexpr bool operator==(const value_type &o) const noexcept { return first == o.first && second == o.second; } constexpr bool operator!=(const value_type &o) const noexcept { return first != o.first || second != o.second; } constexpr bool operator<(const value_type &o) const noexcept { return first < o.first || (first == o.first && second < o.second); } constexpr bool operator<=(const value_type &o) const noexcept { return first < o.first || (first == o.first && second <= o.second); } constexpr bool operator>(const value_type &o) const noexcept { return o < *this; } constexpr bool operator>=(const value_type &o) const noexcept { return !(*this < o); } }; using size_type = size_t; using difference_type = ptrdiff_t; using reference = value_type &; using const_reference = const value_type &; struct const_pointer { const value_type *_v; int _locked_type; explicit const_pointer(const value_type *v = nullptr, bool exclusive_locked = false) noexcept : _v(v), _locked_type(exclusive_locked ? 2 : 1) { /*assert(!v || is_lockable_locked(v->lock));*/} constexpr const_pointer(const_pointer &&o) noexcept : _v(o._v), _locked_type(o._locked_type) { o._v = nullptr; } const_pointer(const const_pointer &) = delete; void reset() noexcept { if(_v) { if(2 == _locked_type) _v->lock.unlock(); else if(1 == _locked_type) detail::unlock_shared_if<lock_type_is_shared>(_v->lock); // IMPORTANT: DO NOT RESET _v TO NULLPTR! _locked_type = 0; } } ~const_pointer() { reset(); } const_pointer &operator=(const_pointer &&o) noexcept { this->~const_pointer(); new(this) const_pointer(std::move(o)); return *this; } constexpr explicit operator bool() const noexcept { return !!_v; } constexpr bool operator!() const noexcept { return !_v; } constexpr const value_type *operator->() const noexcept { return _v; } constexpr const value_type &operator*() const noexcept { return *_v; } constexpr explicit operator const value_type *() const noexcept { return _v; } constexpr bool operator==(const const_pointer &o) const noexcept { return _v == o._v; } constexpr bool operator!=(const const_pointer &o) const noexcept { return _v != o._v; } constexpr bool operator<(const const_pointer &o) const noexcept { return _v < o._v; } constexpr bool operator<=(const const_pointer &o) const noexcept { return _v <= o._v; } constexpr bool operator>(const const_pointer &o) const noexcept { return _v > o._v; } constexpr bool operator>=(const const_pointer &o) const noexcept { return _v >= o._v; } constexpr bool operator==(const value_type *o) const noexcept { return _v == o; } constexpr bool operator!=(const value_type *o) const noexcept { return _v != o; } constexpr bool operator<(const value_type *o) const noexcept { return _v < o; } constexpr bool operator<=(const value_type *o) const noexcept { return _v <= o; } constexpr bool operator>(const value_type *o) const noexcept { return _v > o; } constexpr bool operator>=(const value_type *o) const noexcept { return _v >= o; } constexpr size_t operator-(const value_type *o) const noexcept { return _v - o; } }; struct pointer : public const_pointer { explicit pointer(value_type *v = nullptr) noexcept : const_pointer(v, true) {} constexpr pointer(pointer &&o) noexcept : const_pointer(std::move(o)) {} pointer &operator=(pointer &&o) noexcept { this->~pointer(); new(this) pointer(std::move(o)); return *this; } constexpr value_type *operator->() noexcept { return const_cast<value_type *>(this->_v); } constexpr const value_type *operator->() const noexcept { return this->_v; } constexpr value_type &operator*() noexcept { return *const_cast<value_type *>(this->_v); } constexpr const value_type &operator*() const noexcept { return *this->_v; } constexpr explicit operator value_type *() noexcept { return const_cast<value_type *>(this->_v); } constexpr explicit operator const value_type *() const noexcept { return this->_v; } }; struct items_count_type { std::atomic<size_t> _v; constexpr items_count_type(size_t v) noexcept : _v(v) {} items_count_type &operator--() noexcept { _v.fetch_sub(1, std::memory_order_relaxed); return *this; } items_count_type &operator++() noexcept { _v.fetch_add(1, std::memory_order_relaxed); return *this; } explicit operator size_t() const noexcept { return _v.load(std::memory_order_relaxed); } }; // True if item is in use static bool is_inuse(const value_type *p) noexcept { return p->_inuse.load(std::memory_order_acquire) == 1; } // Returns a LOCKED pointer to an item if it is in use static pointer if_inuse_to_pointer(value_type *p) noexcept { if(p->_inuse.load(std::memory_order_acquire) != 1) return pointer(); p->lock.lock(); if(p->_inuse.load(std::memory_order_acquire) == 1) return pointer(p); p->lock.unlock(); return pointer(); } // Returns a LOCKED pointer to an item if it is in use static const_pointer if_inuse_to_pointer(const value_type *p) noexcept { if(p->_inuse.load(std::memory_order_acquire) != 1) return const_pointer(); detail::lock_shared_if<lock_type_is_shared>(p->lock); if(p->_inuse.load(std::memory_order_acquire) == 1) return const_pointer(p); detail::unlock_shared_if<lock_type_is_shared>(p->lock); return const_pointer(); } // Looks up a key in the contiguous container returning the LOCKED address of any value_type found template <class Container> static pointer find_exclusive(Container &c, const key_type &k) noexcept { return pointer(detail::linear_find<LinearSearchLimit>(c, KeyModulus()(k, c.size()), [&k](const value_type &v) { if(v._inuse.load(std::memory_order_acquire) != 1) return false; v.lock.lock(); if(v._inuse.load(std::memory_order_acquire) == 1 && KeyCompare()(k, v.first)) return true; v.lock.unlock(); return false; })); } // Looks up a key in the contiguous container returning the LOCKED address of any value_type found template <class Container> static const_pointer find_shared(const Container &c, const key_type &k) noexcept { return const_pointer(detail::linear_find<LinearSearchLimit>(c, KeyModulus()(k, c.size()), [&k](const value_type &v) { if(v._inuse.load(std::memory_order_acquire) != 1) return false; detail::lock_shared_if<lock_type_is_shared>(v.lock); if(v._inuse.load(std::memory_order_acquire) == 1 && KeyCompare()(k, v.first)) return true; detail::unlock_shared_if<lock_type_is_shared>(v.lock); return false; })); } // Inserts an item into the contiguous container returning a LOCKED value_type_ptr to any value_type inserted template <class Container> static pointer insert(Container &c, value_type &&newv) noexcept { return pointer(detail::linear_find<LinearSearchLimit>(c, KeyModulus()(newv.first, c.size()), [&newv](value_type &v) { uint32_t expected = 0; if(v._inuse.compare_exchange_strong(expected, 2, std::memory_order_acquire, std::memory_order_relaxed)) { newv._inuse.store(2, std::memory_order_release); v = std::move(newv); v.lock.lock(); v._inuse.store(1, std::memory_order_release); return true; } return false; })); } // Removes an item, returning by value the value_type removed. If returned item doesn't have its bool set, key was not found. static std::pair<value_type, bool> erase(pointer &v) noexcept { value_type ret; if(v) { uint32_t expected = 1; if(v->_inuse.compare_exchange_strong(expected, 2, std::memory_order_acquire, std::memory_order_relaxed)) { ret = value_type(std::move(v->first), std::move(v->second)); // assert(is_lockable_locked(v->lock)); v.reset(); // unlocks the item and makes the pointer no longer unlock on destruct v->_inuse.store(0, std::memory_order_release); // mark as unused return std::make_pair(std::move(ret), true); } } return std::make_pair(std::move(ret), false); } // Removes an item, returning by value the value_type removed. If returned item doesn't have its bool set, key was not found. template <class Container> static std::pair<value_type, bool> erase(Container &c, const key_type &k) noexcept { pointer p = find_exclusive(c, k); return erase(p); } }; /* \class basic_open_hash_index \brief Policy driven open addressed hash index \tparam Policy See list of standard policies below. \tparam ContiguousContainerType Some STL container meeting the `ContiguousContainer` concept. `std::array<>` and `std::vector` are two of the most commonly used. \tparam disable_existing_key_check Don't check for existing keys during insertion which is faster. This is the most fundamental building block of a hash table possible - it simply lets you look up a key and get back a value. Indexing is based on open addressing whereby the key value is modulused by the underlying container's size into an index. We then compare keys at the index and either side of the index until a match or empty slot as appropriate is found. This type of hash table is therefore highly dependent on a high quality hashing function. Use FNV1 quality or better, not the usually poor quality `std::hash` implementation (see `fnv1a_hash`). Note this particular implementation does NOT hash keys for you, 'key' here means some type which behaves as if an unsigned integer integral type. Because it does so much less work than an `unordered_map<>`, insert/erase performance is typically ~4x faster and lookup performance is typically <= ~2x faster depending on how your STL implements `std::hash<>`. A particularly interesting use of this class is as a shared memory hash index. Simply use `std::array<>` as the container and placement new this class directly into shared memory - `sizeof(basic_open_hash_index) == sizeof(ContiguousContainerType) + sizeof(size_t)`. If you'd like to safely concurrently read and modify the shared memory hash index, see the `atomic_linear_memory_policy<...>` below. Some standard policies available: * `linear_memory_policy<...>`: Keeps a simple boolean for whether the slot is in use. Collision is handled via a linear scan either side of the arrival point. * `atomic_linear_memory_policy<...>`: Keeps a tristate atomic for whether the slot is in use or being constructed or destructed. Also keeps a mutex held locked <b>whilst any iterator is held open to that item</b>. You can of course supply your own policies to implement any semantics you like e.g. storage is a huge sparse file on disc and every key lookup is a `read()` and every key update is a `write()`. */ template <class Policy, template <class> class ContiguousContainerType, bool disable_existing_key_check = false> class basic_open_hash_index { public: //! The key type used to look up a mapped type using key_type = typename Policy::key_type; //! The type looked up by a key using mapped_type = typename Policy::mapped_type; //! The type stored in the container using value_type = typename Policy::value_type; //! The size type using size_type = typename Policy::size_type; //! The difference type using difference_type = typename Policy::difference_type; //! The reference type using reference = typename Policy::reference; //! The const reference type using const_reference = typename Policy::const_reference; //! The pointer type. May be a smart pointer which unlocks things on destruction. using pointer = typename Policy::pointer; //! The const pointer type. May be a smart pointer which unlocks things on destruction. using const_pointer = typename Policy::const_pointer; /*! The container used to store the hash entries defined by Policy::value_type. Must be a ContiguousContainer. */ using container_type = ContiguousContainerType<value_type>; protected: template <bool is_const, class Parent, class Pointer, class Reference> class iterator_; template <bool is_const, class Parent, class Pointer, class Reference> class iterator_ : public std::iterator<std::bidirectional_iterator_tag, value_type, difference_type, pointer, reference> { friend class basic_open_hash_index; template <bool is_const_, class Parent_, class Pointer_, class Reference_> friend class iterator_; Parent *_parent; Pointer _p; using underlying_pointer_type = typename std::add_pointer<decltype(*_p)>::type; using const_underlying_pointer_type = typename std::add_const<underlying_pointer_type>::type; static_assert(is_const == std::is_const<typename std::remove_reference<decltype(*_p)>::type>::value, ""); iterator_ &_inc() noexcept { if(_parent && _p >= _parent->_store.data() && _p < (_parent->_store.data() + _parent->_store.size())) { underlying_pointer_type p(_p); do { ++p; if(p < (_parent->_store.data() + _parent->_store.size())) _p = Policy::if_inuse_to_pointer(p); else break; } while(!_p); if(p >= (_parent->_store.data() + _parent->_store.size())) _p = Pointer(nullptr); } return *this; } iterator_ &_dec() noexcept { if(_parent) { underlying_pointer_type p(_p); if(p < _parent->_store.data()) p = (_parent->_store.data() + _parent->_store.size()); do { --p; if(p >= _parent->_store.data()) _p = Policy::if_inuse_to_pointer(p); else break; } while(!_p); if(p < _parent->_store.data()) _p = Pointer(nullptr); } return *this; } constexpr iterator_(Parent *parent, Pointer &&p) noexcept : _parent(parent), _p(std::move(p)) {} constexpr iterator_(Parent *parent) noexcept : _parent(parent), _p(nullptr) {} public: constexpr iterator_() noexcept : _parent(nullptr), _p(nullptr) {} constexpr iterator_(const iterator_ &) = default; constexpr iterator_(iterator_ &&) noexcept = default; constexpr iterator_ &operator=(const iterator_ &) = default; constexpr iterator_ &operator=(iterator_ &&) noexcept = default; // Non-const to const iterator template <class _Parent, class _Pointer, class _Reference, typename = typename std::enable_if<std::is_same<_Parent, _Parent>::value && is_const, _Parent>::type> constexpr iterator_(const iterator_<false, _Parent, _Pointer, _Reference> &o) noexcept : _parent(o._parent), _p(o._p) {} template <class _Parent, class _Pointer, class _Reference, typename = typename std::enable_if<std::is_same<_Parent, _Parent>::value && is_const, _Parent>::type> constexpr iterator_(iterator_<false, _Parent, _Pointer, _Reference> &&o) noexcept : _parent(std::move(o._parent)), _p(std::move(o._p)) {} void swap(iterator_ &o) noexcept { std::swap(_parent, o._parent); std::swap(_p, o._p); } explicit operator bool() const noexcept { return _parent && _p; } bool operator!() const noexcept { return !_parent || !_p; } underlying_pointer_type operator->() noexcept { if(!_parent || !_p || _p < _parent->_store.data() || _p >= (_parent->_store.data() + _parent->_store.size())) return nullptr; return underlying_pointer_type(_p); } const_underlying_pointer_type operator->() const noexcept { if(!_parent || !_p || _p < _parent->_store.data() || _p >= (_parent->_store.data() + _parent->_store.size())) return nullptr; return const_underlying_pointer_type(_p); } bool operator==(const iterator_ &o) const noexcept { return _parent == o._parent && _p == o._p; } bool operator!=(const iterator_ &o) const noexcept { return _parent != o._parent || _p != o._p; } Reference operator*() noexcept { if(!_parent || !_p || _p < _parent->_store.data() || _p >= (_parent->_store.data() + _parent->_store.size())) { abort(); } return *_p; } const Reference operator*() const noexcept { if(!_parent || !_p || _p < _parent->_store.data() || _p >= (_parent->_store.data() + _parent->_store.size())) { abort(); } return *_p; } iterator_ &operator++() noexcept { return _inc(); } iterator_ operator++(int) noexcept { iterator_ ret(*this); ++*this; return ret; } iterator_ &operator--() noexcept { return _dec(); } iterator_ operator--(int) noexcept { iterator_ ret(*this); --*this; return ret; } bool operator<(const iterator_ &o) const noexcept { if(_parent != o._parent) abort(); return !!_p && (!o._p || _p < o._p); } bool operator>(const iterator_ &o) const noexcept { if(_parent != o._parent) abort(); return !!o._p && (!_p || _p > o._p); } bool operator<=(const iterator_ &o) const noexcept { if(_parent != o._parent) abort(); return !(o > *this); } bool operator>=(const iterator_ &o) const noexcept { if(_parent != o._parent) abort(); return !(o < *this); } }; template <bool is_const, class Parent, class Pointer, class Reference> friend class iterator_; public: //! The iterator type using iterator = iterator_<false, basic_open_hash_index, pointer, reference>; //! The const iterator type using const_iterator = iterator_<true, const basic_open_hash_index, const_pointer, const_reference>; //! The reverse iterator type using reverse_iterator = std::reverse_iterator<iterator>; //! The const reverse iterator type using const_reverse_iterator = std::reverse_iterator<const_iterator>; protected: container_type _store; typename Policy::items_count_type _count; public: //! Default construction, passes through args to container_type template <class... Args> basic_open_hash_index(Args &&... args) : _store(std::forward<Args>(args)...) , _count(0) { } //! Swaps with another instance void swap(basic_open_hash_index &o) noexcept { std::swap(_store, o._store); std::swap(_count, o._count); } //! Returns true if the index is empty bool empty() const noexcept { return size_type(_count) == 0; } //! Returns the number of items in the index size_type size() const noexcept { return size_type(_count); } //! Returns the maximum number of items in the index size_type max_size() const noexcept { return _store.size(); } //! Returns the STL container backing the store of this index const container_type &container() const noexcept { return _store; } //! Returns the STL container backing the store of this index container_type &container() noexcept { return _store; } //! Returns the front of the index. reference front() noexcept { for(size_t idx = 0; idx < _store.size(); idx++) { if(Policy::is_inuse(&_store[idx])) return _store[idx]; } abort(); } //! Returns the front of the index. const_reference front() const noexcept { for(size_t idx = 0; idx < _store.size(); idx++) { if(Policy::is_inuse(&_store[idx])) return _store[idx]; } abort(); } //! Returns the back of the index. reference back() noexcept { for(size_t idx = _store.size() - 1; idx < _store.size(); idx--) { if(Policy::is_inuse(&_store[idx])) return _store[idx]; } abort(); } //! Returns the back of the index. const_reference back() const noexcept { for(size_t idx = _store.size() - 1; idx < _store.size(); idx--) { if(Policy::is_inuse(&_store[idx])) return _store[idx]; } abort(); } //! Returns an iterator to the first item in the index. iterator begin() noexcept { pointer p; for(size_t idx = 0; idx < _store.size(); idx++) { p = Policy::if_inuse_to_pointer(&_store[idx]); if(p) return iterator(this, std::move(p)); } return iterator(this); } //! Returns an iterator to the first item in the index. const_iterator begin() const noexcept { const_pointer p; for(size_t idx = 0; idx < _store.size(); idx++) { p = Policy::if_inuse_to_pointer(&_store[idx]); if(p) return const_iterator(this, std::move(p)); } return const_iterator(this); } //! Returns an iterator to the first item in the index. const_iterator cbegin() const noexcept { return begin(); } //! Returns an iterator to the item after the last in the index. iterator end() noexcept { return iterator(this); } //! Returns an iterator to the item after the last in the index. const_iterator end() const noexcept { return const_iterator(this); } //! Returns an iterator to the item after the last in the index. const_iterator cend() const noexcept { return const_iterator(this); } //! Clears the log void clear() noexcept { _count = typename Policy::items_count_type(0); auto oldsize = _store.size(); _store.clear(); _store.resize(oldsize); } //! Inserts a new item, returning an iterator to the new item if the bool is true, else an iterator to existing item. If the returned iterator is invalid, there is no more space. std::pair<iterator, bool> insert(value_type &&v) noexcept { pointer p(!disable_existing_key_check ? Policy::find_exclusive(_store, v.first) : pointer(nullptr)); if(p) return std::make_pair(iterator(this, std::move(p)), false); p = Policy::insert(_store, std::move(v)); if(!p) return std::make_pair(end(), false); ++_count; return std::make_pair(iterator(this, std::move(p)), true); } //! Inserts a new item or assigns to an existing one, returning an iterator to the new or existing item. If the returned iterator is invalid, there is no more space. template <class T> std::pair<iterator, bool> insert_or_assign(const key_type &k, T &&t) noexcept { auto p = Policy::find_exclusive(_store, k); if(p) { p->second = std::forward<T>(t); return std::make_pair(iterator(this, std::move(p)), false); } p = Policy::insert(_store, value_type(k, std::forward<T>(t))); if(!p) return std::make_pair(end(), false); ++_count; return std::make_pair(iterator(this, std::move(p)), true); } //! Emplaces a new item, returning an iterator to the new item template <class... Args> std::pair<iterator, bool> emplace(Args &&... args) noexcept { return insert(value_type(std::forward<Args>(args)...)); } //! Emplaces a new item, returning an iterator to the new item template <class... Args> std::pair<iterator, bool> try_emplace(const key_type &k, Args &&... args) noexcept { pointer p(!disable_existing_key_check ? Policy::find_exclusive(_store, k) : pointer(nullptr)); if(p) return std::make_pair(iterator(this, std::move(p)), false); p = Policy::insert(_store, value_type(k, mapped_type(std::forward<Args>(args)...))); if(!p) return std::make_pair(end(), false); ++_count; return std::make_pair(iterator(this, std::move(p)), true); } //! Erases an item. Note takes an iterator not a const_iterator as the STL would. iterator erase(iterator it) noexcept { if(it._parent != this) abort(); auto v = Policy::erase(it._p); if(v.second) --_count; // it._p is still valid but now unlocked ++it; return it; } //! Erases an item. Note this implementation does not return an iterator as per the STL. void erase(const key_type &k) noexcept { auto v = Policy::erase(_store, k); if(v.second) --_count; } //! Finds an item iterator find_exclusive(const key_type &k) noexcept { auto p = Policy::find_exclusive(_store, k); if(p) return iterator(this, std::move(p)); return end(); } //! Finds an item const_iterator find_shared(const key_type &k) const noexcept { auto p = Policy::find_shared(_store, k); if(p) return const_iterator(this, std::move(p)); return cend(); } //! Finds an item (exclusive) iterator find(const key_type &k) noexcept { return find_exclusive(k); } //! Finds an item (shared) const_iterator find(const key_type &k) const noexcept { return find_shared(k); } //! Returns a reference to the specified element, inserting an empty mapped type if necessary reference operator[](const key_type &k) noexcept { auto p = Policy::find_exclusive(_store, k); if(p) return p->second; p = Policy::insert(_store, value_type(k, mapped_type())); if(p) { ++_count; return p->second; } abort(); } //! Returns a reference to the specified element. const_reference operator[](const key_type &k) const noexcept { auto p = Policy::find_exclusive(_store, k); if(p) { ++_count; return p->second; } abort(); } }; //! std::ostream writer for an index template <class Policy, template <class> class ContiguousContainerType> inline std::ostream &operator<<(std::ostream &s, const basic_open_hash_index<Policy, ContiguousContainerType> &l) { for(const auto &i : l) { s << i; } return s; } } } QUICKCPPLIB_NAMESPACE_END #endif
0
repos/outcome/test
repos/outcome/test/compile-fail/result-int-int-1.cpp
/* clang-format off (use of deleted function|call to deleted constructor|attempting to reference a deleted function) clang-format on Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../../include/outcome/result.hpp" int main() { using namespace OUTCOME_V2_NAMESPACE; // Must not be possible to initialise a result with same R and S types result<int, int> m(5); (void) m; return 0; }
0
repos/outcome/test
repos/outcome/test/compile-fail/outcome-int-int-1.cpp
/* clang-format off (use of deleted function|call to deleted constructor|attempting to reference a deleted function) clang-format on Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../../include/outcome.hpp" int main() { using namespace OUTCOME_V2_NAMESPACE; // Must not be possible to initialise an outcome with same R, S and P types outcome<int, int, int> m(5); (void) m; return 0; }
0
repos/outcome/test
repos/outcome/test/compile-fail/result-int-int-2.cpp
/* clang-format off (use of deleted function|call to deleted constructor|attempting to reference a deleted function) clang-format on Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../../include/outcome/result.hpp" int main() { using namespace OUTCOME_V2_NAMESPACE; // Must not be possible to initialise a result with same R and S types result<int, int> m(in_place_type<int>); (void) m; return 0; }
0
repos/outcome/test
repos/outcome/test/compile-fail/issue0071-fail.cpp
/* clang-format off (error: no matching function for call to .+::basic_result|error: no matching constructor for initialization of 'result<udt>'|cannot convert argument 1 from 'int'|no overloaded function could convert all the argument types) clang-format on Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../../include/outcome/result.hpp" int main() { using namespace OUTCOME_V2_NAMESPACE; struct udt { explicit udt(int /*unused*/) {} }; // Must not be possible to implicitly initialise a result<udt> result<udt> m(5); (void) m; return 0; }
0
repos/outcome/test
repos/outcome/test/constexprs/max_result_get_value.cpp
/* Canned codegen quality test sequences (C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (9 commits) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../../single-header/outcome.hpp" #ifdef __GNUC__ #define WEAK __attribute__((weak)) #else #define WEAK #endif using namespace OUTCOME_V2_NAMESPACE; extern result<int> unknown() WEAK; extern QUICKCPPLIB_NOINLINE int test1() { return unknown().value(); } extern QUICKCPPLIB_NOINLINE void test2() { } int main(void) { int ret=0; if(5!=test1()) ret=1; test2(); return ret; }
0
repos/outcome/test
repos/outcome/test/constexprs/min_result_get_value.clang.S.test1.s
400630: b8 05 00 00 00 mov $0x5,%eax 400635: c3 retq 400636: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
0
repos/outcome/test
repos/outcome/test/constexprs/WG21_P1886.gcc.S.test1.s
920: 41 54 push %r12 922: 49 89 fc mov %rdi,%r12 925: 48 83 ec 30 sub $0x30,%rsp 929: 48 8d 7c 24 10 lea 0x10(%rsp),%rdi 900: 48 8d 15 69 14 20 00 lea 0x201469(%rip),%rdx # 201d70 <system_error2::generic_code_domain> 907: c7 47 04 02 00 00 00 movl $0x2,0x4(%rdi) 90e: 48 89 f8 mov %rdi,%rax 911: 48 89 57 08 mov %rdx,0x8(%rdi) 915: 48 c7 47 10 21 00 00 movq $0x21,0x10(%rdi) 91d: c3 retq 91e: 66 90 xchg %ax,%ax 933: f6 44 24 14 01 testb $0x1,0x14(%rsp) 938: 74 76 je 9b0 <test1()+0x90> 93a: 8b 44 24 10 mov 0x10(%rsp),%eax 93e: 48 8b 7c 24 18 mov 0x18(%rsp),%rdi 943: c7 05 c7 16 20 00 00 movl $0x0,0x2016c7(%rip) # 202014 <foo> 94d: 41 c7 44 24 04 01 00 movl $0x1,0x4(%r12) 956: 41 89 04 24 mov %eax,(%r12) 95a: 49 c7 44 24 08 00 00 movq $0x0,0x8(%r12) 963: 49 c7 44 24 10 00 00 movq $0x0,0x10(%r12) 96c: 48 85 ff test %rdi,%rdi 96f: 74 13 je 984 <test1()+0x64> 971: 48 8b 07 mov (%rdi),%rax 974: 48 8d 15 75 00 00 00 lea 0x75(%rip),%rdx # 9f0 <system_error2::status_code_domain::_do_erased_destroy(system_error2::status_code<void>&, unsigned long) const> 97b: 48 8b 40 38 mov 0x38(%rax),%rax 97f: 48 39 d0 cmp %rdx,%rax 982: 75 0c jne 990 <test1()+0x70> 984: 48 83 c4 30 add $0x30,%rsp 988: 4c 89 e0 mov %r12,%rax 98b: 41 5c pop %r12 98d: c3 retq 98e: 66 90 xchg %ax,%ax 990: 48 8d 74 24 18 lea 0x18(%rsp),%rsi 995: ba 10 00 00 00 mov $0x10,%edx 99a: ff d0 callq *%rax 99c: 48 83 c4 30 add $0x30,%rsp 9a0: 4c 89 e0 mov %r12,%rax 9a3: 41 5c pop %r12 9a5: c3 retq 9a6: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 9b0: 41 c7 44 24 04 02 00 movl $0x2,0x4(%r12) 9b9: 48 8b 44 24 18 mov 0x18(%rsp),%rax 9be: 49 89 44 24 08 mov %rax,0x8(%r12) 9c3: 48 8b 44 24 20 mov 0x20(%rsp),%rax 9c8: 49 89 44 24 10 mov %rax,0x10(%r12) 9cd: 48 83 c4 30 add $0x30,%rsp 9d1: 4c 89 e0 mov %r12,%rax 9d4: 41 5c pop %r12 9d6: c3 retq 9d7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
0
repos/outcome/test
repos/outcome/test/constexprs/min_result_construct_value_move_destruct.msvc.S.test1.s
0000000000000000: 40 53 push rbx 0000000000000002: 48 83 EC 50 sub rsp,50h 0000000000000006: 48 8D 1D 00 00 00 lea rbx,[?_Storage@?1???$_Immortalize@V_System_error_category@std@@@std@@YAAEAV_System_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A] 000000000000000D: C7 44 24 20 05 00 mov dword ptr [rsp+20h],5 0000000000000015: 4C 8B C3 mov r8,rbx 0000000000000018: 48 C7 44 24 24 01 mov qword ptr [rsp+24h],1 0000000000000021: 48 8D 15 00 00 00 lea rdx,[??$_Immortalize_impl@V_System_error_category@std@@@std@@YAHPEAX0PEAPEAX@Z] 0000000000000028: 48 8D 0D 00 00 00 lea rcx,[?_Flag@?1???$_Immortalize@V_System_error_category@std@@@std@@YAAEAV_System_error_category@1@XZ@4PEAXEA] 000000000000002F: E8 00 00 00 00 call ?_Execute_once@std@@YAHAEAUonce_flag@1@P6AHPEAX1PEAPEAX@Z1@Z 0000000000000034: 85 C0 test eax,eax 0000000000000036: 74 79 je 00000000000000B1 0000000000000038: 0F 10 4C 24 20 movups xmm1,xmmword ptr [rsp+20h] 000000000000003D: 48 89 5C 24 30 mov qword ptr [rsp+30h],rbx 0000000000000042: F2 0F 10 44 24 30 movsd xmm0,mmword ptr [rsp+30h] 0000000000000048: 66 48 0F 7E C8 movq rax,xmm1 000000000000004D: F2 0F 11 44 24 48 movsd mmword ptr [rsp+48h],xmm0 0000000000000053: 48 C1 E8 20 shr rax,20h 0000000000000057: 0F 11 4C 24 38 movups xmmword ptr [rsp+38h],xmm1 000000000000005C: A8 01 test al,1 000000000000005E: 75 08 jne 0000000000000068 0000000000000060: D0 E8 shr al,1 0000000000000062: A8 01 test al,1 0000000000000064: 75 30 jne 0000000000000096 0000000000000066: EB 0B jmp 0000000000000073 0000000000000068: B8 05 00 00 00 mov eax,5 000000000000006D: 48 83 C4 50 add rsp,50h 0000000000000071: 5B pop rbx 0000000000000072: C3 ret 0000000000000073: 48 8D 15 00 00 00 lea rdx,[??_C@_08JEIPHCP@no?5value@] 000000000000007A: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000000: 40 53 push rbx 0000000000000002: 48 83 EC 30 sub rsp,30h 0000000000000006: 48 8B D9 mov rbx,rcx 0000000000000009: C6 44 24 28 01 mov byte ptr [rsp+28h],1 000000000000000E: 48 8B C2 mov rax,rdx 0000000000000011: 48 8D 0D 00 00 00 lea rcx,[??_7exception@std@@6B@] 0000000000000018: 48 8D 53 08 lea rdx,[rbx+8] 000000000000001C: 48 89 44 24 20 mov qword ptr [rsp+20h],rax 0000000000000021: 0F 57 C0 xorps xmm0,xmm0 0000000000000024: 48 89 0B mov qword ptr [rbx],rcx 0000000000000027: 48 8D 4C 24 20 lea rcx,[rsp+20h] 000000000000002C: 0F 11 02 movups xmmword ptr [rdx],xmm0 000000000000002F: E8 00 00 00 00 call __std_exception_copy 0000000000000034: 48 8D 05 00 00 00 lea rax,[??_7bad_result_access@outcome_v2_3f877000@@6B@] 000000000000003B: 48 89 03 mov qword ptr [rbx],rax 000000000000003E: 48 8B C3 mov rax,rbx 0000000000000041: 48 83 C4 30 add rsp,30h 0000000000000045: 5B pop rbx 0000000000000046: C3 ret 0000000000000084: 48 8D 15 00 00 00 lea rdx,[_TI3?AVbad_result_access@outcome_v2_3f877000@@] 000000000000008B: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000090: E8 00 00 00 00 call _CxxThrowException 0000000000000095: CC int 3 0000000000000096: 48 8D 4C 24 38 lea rcx,[rsp+38h] 0000000000000000: 48 8B C1 mov rax,rcx 0000000000000003: C3 ret 00000000000000A0: 48 8B C8 mov rcx,rax 0000000000000000: 48 8D 41 08 lea rax,[rcx+8] 0000000000000004: C3 ret 00000000000000A8: 48 8B C8 mov rcx,rax 0000000000000000: 48 83 EC 68 sub rsp,68h 0000000000000004: 0F 10 01 movups xmm0,xmmword ptr [rcx] 0000000000000007: 48 8D 54 24 20 lea rdx,[rsp+20h] 000000000000000C: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000011: 0F 29 44 24 20 movaps xmmword ptr [rsp+20h],xmm0 0000000000000000: 48 89 5C 24 08 mov qword ptr [rsp+8],rbx 0000000000000005: 57 push rdi 0000000000000006: 48 83 EC 50 sub rsp,50h 000000000000000A: 48 8B DA mov rbx,rdx 000000000000000D: 48 8B F9 mov rdi,rcx 0000000000000010: 48 C7 44 24 40 00 mov qword ptr [rsp+40h],0 0000000000000019: 48 C7 44 24 48 0F mov qword ptr [rsp+48h],0Fh 0000000000000022: C6 44 24 30 00 mov byte ptr [rsp+30h],0 0000000000000027: 45 33 C0 xor r8d,r8d 000000000000002A: 48 8D 15 00 00 00 lea rdx,[??_C@_00CNPNBAHC@@] 0000000000000031: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000000: 48 89 5C 24 10 mov qword ptr [rsp+10h],rbx 0000000000000005: 48 89 6C 24 18 mov qword ptr [rsp+18h],rbp 000000000000000A: 56 push rsi 000000000000000B: 57 push rdi 000000000000000C: 41 57 push r15 000000000000000E: 48 83 EC 20 sub rsp,20h 0000000000000012: 48 8B 69 18 mov rbp,qword ptr [rcx+18h] 0000000000000016: 49 8B F0 mov rsi,r8 0000000000000019: 4C 8B FA mov r15,rdx 000000000000001C: 48 8B D9 mov rbx,rcx 000000000000001F: 4C 3B C5 cmp r8,rbp 0000000000000022: 77 21 ja 0000000000000045 0000000000000024: 48 8B F9 mov rdi,rcx 0000000000000027: 48 83 FD 10 cmp rbp,10h 000000000000002B: 72 03 jb 0000000000000030 000000000000002D: 48 8B 39 mov rdi,qword ptr [rcx] 0000000000000030: 48 89 71 10 mov qword ptr [rcx+10h],rsi 0000000000000034: 48 8B CF mov rcx,rdi 0000000000000037: E8 00 00 00 00 call memmove 000000000000003C: C6 04 37 00 mov byte ptr [rdi+rsi],0 0000000000000040: E9 E4 00 00 00 jmp 0000000000000129 0000000000000045: 48 BF FF FF FF FF mov rdi,7FFFFFFFFFFFFFFFh 000000000000004F: 48 3B F7 cmp rsi,rdi 0000000000000052: 0F 87 F3 00 00 00 ja 000000000000014B 0000000000000058: 48 8B CE mov rcx,rsi 000000000000005B: 48 83 C9 0F or rcx,0Fh 000000000000005F: 48 3B CF cmp rcx,rdi 0000000000000062: 77 1F ja 0000000000000083 0000000000000064: 48 8B D5 mov rdx,rbp 0000000000000067: 48 8B C7 mov rax,rdi 000000000000006A: 48 D1 EA shr rdx,1 000000000000006D: 48 2B C2 sub rax,rdx 0000000000000070: 48 3B E8 cmp rbp,rax 0000000000000073: 77 0E ja 0000000000000083 0000000000000075: 48 8D 04 2A lea rax,[rdx+rbp] 0000000000000079: 48 8B F9 mov rdi,rcx 000000000000007C: 48 3B C8 cmp rcx,rax 000000000000007F: 48 0F 42 F8 cmovb rdi,rax 0000000000000083: 48 8D 4F 01 lea rcx,[rdi+1] 0000000000000087: 4C 89 74 24 40 mov qword ptr [rsp+40h],r14 000000000000008C: 48 81 F9 00 10 00 cmp rcx,1000h 0000000000000093: 72 2C jb 00000000000000C1 0000000000000095: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000099: 48 3B C1 cmp rax,rcx 000000000000009C: 0F 86 9D 00 00 00 jbe 000000000000013F 00000000000000A2: 48 8B C8 mov rcx,rax 00000000000000A5: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000AA: 48 85 C0 test rax,rax 00000000000000AD: 0F 84 92 00 00 00 je 0000000000000145 00000000000000B3: 4C 8D 70 27 lea r14,[rax+27h] 00000000000000B7: 49 83 E6 E0 and r14,0FFFFFFFFFFFFFFE0h 00000000000000BB: 49 89 46 F8 mov qword ptr [r14-8],rax 00000000000000BF: EB 12 jmp 00000000000000D3 00000000000000C1: 48 85 C9 test rcx,rcx 00000000000000C4: 74 0A je 00000000000000D0 00000000000000C6: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000CB: 4C 8B F0 mov r14,rax 00000000000000CE: EB 03 jmp 00000000000000D3 00000000000000D0: 45 33 F6 xor r14d,r14d 00000000000000D3: 4C 8B C6 mov r8,rsi 00000000000000D6: 48 89 73 10 mov qword ptr [rbx+10h],rsi 00000000000000DA: 49 8B D7 mov rdx,r15 00000000000000DD: 48 89 7B 18 mov qword ptr [rbx+18h],rdi 00000000000000E1: 49 8B CE mov rcx,r14 00000000000000E4: E8 00 00 00 00 call memcpy 00000000000000E9: 41 C6 04 36 00 mov byte ptr [r14+rsi],0 00000000000000EE: 48 83 FD 10 cmp rbp,10h 00000000000000F2: 72 2D jb 0000000000000121 00000000000000F4: 48 8B 0B mov rcx,qword ptr [rbx] 00000000000000F7: 48 8D 55 01 lea rdx,[rbp+1] 00000000000000FB: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000102: 72 18 jb 000000000000011C 0000000000000104: 4C 8B 41 F8 mov r8,qword ptr [rcx-8] 0000000000000108: 48 83 C2 27 add rdx,27h 000000000000010C: 49 2B C8 sub rcx,r8 000000000000010F: 48 8D 41 F8 lea rax,[rcx-8] 0000000000000113: 48 83 F8 1F cmp rax,1Fh 0000000000000117: 77 2C ja 0000000000000145 0000000000000119: 49 8B C8 mov rcx,r8 000000000000011C: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000121: 4C 89 33 mov qword ptr [rbx],r14 0000000000000124: 4C 8B 74 24 40 mov r14,qword ptr [rsp+40h] 0000000000000129: 48 8B 6C 24 50 mov rbp,qword ptr [rsp+50h] 000000000000012E: 48 8B C3 mov rax,rbx 0000000000000131: 48 8B 5C 24 48 mov rbx,qword ptr [rsp+48h] 0000000000000136: 48 83 C4 20 add rsp,20h 000000000000013A: 41 5F pop r15 000000000000013C: 5F pop rdi 000000000000013D: 5E pop rsi 000000000000013E: C3 ret 0000000000000000: 48 83 EC 48 sub rsp,48h 0000000000000004: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000000: 48 8D 05 00 00 00 lea rax,[??_C@_0BF@KINCDENJ@bad?5array?5new?5length@] 0000000000000007: 48 C7 41 10 00 00 mov qword ptr [rcx+10h],0 000000000000000F: 48 89 41 08 mov qword ptr [rcx+8],rax 0000000000000013: 48 8D 05 00 00 00 lea rax,[??_7bad_array_new_length@std@@6B@] 000000000000001A: 48 89 01 mov qword ptr [rcx],rax 000000000000001D: 48 8B C1 mov rax,rcx 0000000000000020: C3 ret 000000000000000E: 48 8D 15 00 00 00 lea rdx,[_TI3?AVbad_array_new_length@std@@] 0000000000000015: 48 8D 4C 24 20 lea rcx,[rsp+20h] 000000000000001A: E8 00 00 00 00 call _CxxThrowException 000000000000001F: CC int 3 0000000000000144: CC int 3 0000000000000145: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 000000000000014A: CC int 3 0000000000000000: 48 83 EC 28 sub rsp,28h 0000000000000004: 48 8D 0D 00 00 00 lea rcx,[??_C@_0BA@JFNIOLAK@string?5too?5long@] 000000000000000B: E8 00 00 00 00 call ?_Xlength_error@std@@YAXPEBD@Z 0000000000000010: CC int 3 0000000000000150: CC int 3 000000000000003B: 90 nop 000000000000003C: 0F 10 03 movups xmm0,xmmword ptr [rbx] 000000000000003F: 0F 29 44 24 20 movaps xmmword ptr [rsp+20h],xmm0 0000000000000044: 4C 8D 44 24 30 lea r8,[rsp+30h] 0000000000000049: 48 8D 54 24 20 lea rdx,[rsp+20h] 000000000000004E: 48 8B CF mov rcx,rdi 0000000000000000: 48 89 5C 24 08 mov qword ptr [rsp+8],rbx 0000000000000005: 48 89 74 24 10 mov qword ptr [rsp+10h],rsi 000000000000000A: 48 89 7C 24 20 mov qword ptr [rsp+20h],rdi 000000000000000F: 55 push rbp 0000000000000010: 41 56 push r14 0000000000000012: 41 57 push r15 0000000000000014: 48 8D 6C 24 B9 lea rbp,[rsp-47h] 0000000000000019: 48 81 EC 90 00 00 sub rsp,90h 0000000000000020: 49 8B F0 mov rsi,r8 0000000000000023: 4C 8B FA mov r15,rdx 0000000000000026: 4C 8B F1 mov r14,rcx 0000000000000029: 48 C7 45 17 00 00 mov qword ptr [rbp+17h],0 0000000000000031: 48 C7 45 1F 00 00 mov qword ptr [rbp+1Fh],0 0000000000000039: 49 8B 78 10 mov rdi,qword ptr [r8+10h] 000000000000003D: 49 83 78 18 10 cmp qword ptr [r8+18h],10h 0000000000000042: 72 03 jb 0000000000000047 0000000000000044: 49 8B 30 mov rsi,qword ptr [r8] 0000000000000047: 48 83 FF 10 cmp rdi,10h 000000000000004B: 73 0E jae 000000000000005B 000000000000004D: 0F 10 06 movups xmm0,xmmword ptr [rsi] 0000000000000050: 0F 11 45 07 movups xmmword ptr [rbp+7],xmm0 0000000000000054: BB 0F 00 00 00 mov ebx,0Fh 0000000000000059: EB 75 jmp 00000000000000D0 000000000000005B: 48 8B DF mov rbx,rdi 000000000000005E: 48 83 CB 0F or rbx,0Fh 0000000000000062: 48 B8 FF FF FF FF mov rax,7FFFFFFFFFFFFFFFh 000000000000006C: 48 3B D8 cmp rbx,rax 000000000000006F: 48 0F 47 D8 cmova rbx,rax 0000000000000073: 48 8D 4B 01 lea rcx,[rbx+1] 0000000000000077: 48 81 F9 00 10 00 cmp rcx,1000h 000000000000007E: 72 2F jb 00000000000000AF 0000000000000080: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000084: 48 3B C1 cmp rax,rcx 0000000000000087: 0F 86 F9 01 00 00 jbe 0000000000000286 000000000000008D: 48 8B C8 mov rcx,rax 0000000000000090: E8 00 00 00 00 call ??2@YAPEAX_K@Z 0000000000000095: 48 8B C8 mov rcx,rax 0000000000000098: 48 85 C0 test rax,rax 000000000000009B: 0F 84 DF 01 00 00 je 0000000000000280 00000000000000A1: 48 83 C0 27 add rax,27h 00000000000000A5: 48 83 E0 E0 and rax,0FFFFFFFFFFFFFFE0h 00000000000000A9: 48 89 48 F8 mov qword ptr [rax-8],rcx 00000000000000AD: EB 0E jmp 00000000000000BD 00000000000000AF: 48 85 C9 test rcx,rcx 00000000000000B2: 74 07 je 00000000000000BB 00000000000000B4: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000B9: EB 02 jmp 00000000000000BD 00000000000000BB: 33 C0 xor eax,eax 00000000000000BD: 48 89 45 07 mov qword ptr [rbp+7],rax 00000000000000C1: 4C 8D 47 01 lea r8,[rdi+1] 00000000000000C5: 48 8B D6 mov rdx,rsi 00000000000000C8: 48 8B C8 mov rcx,rax 00000000000000CB: E8 00 00 00 00 call memcpy 00000000000000D0: 48 89 7D 17 mov qword ptr [rbp+17h],rdi 00000000000000D4: 48 89 5D 1F mov qword ptr [rbp+1Fh],rbx 00000000000000D8: 48 8D 45 07 lea rax,[rbp+7] 00000000000000DC: 48 89 45 77 mov qword ptr [rbp+77h],rax 00000000000000E0: 41 0F 10 07 movups xmm0,xmmword ptr [r15] 00000000000000E4: 0F 29 45 E7 movaps xmmword ptr [rbp-19h],xmm0 00000000000000E8: 48 85 FF test rdi,rdi 00000000000000EB: 74 51 je 000000000000013E 00000000000000ED: 48 8B C3 mov rax,rbx 00000000000000F0: 48 2B C7 sub rax,rdi 00000000000000F3: 48 83 F8 02 cmp rax,2 00000000000000F7: 72 25 jb 000000000000011E 00000000000000F9: 48 8D 47 02 lea rax,[rdi+2] 00000000000000FD: 48 89 45 17 mov qword ptr [rbp+17h],rax 0000000000000101: 48 8D 45 07 lea rax,[rbp+7] 0000000000000105: 48 83 FB 10 cmp rbx,10h 0000000000000109: 48 0F 43 45 07 cmovae rax,qword ptr [rbp+7] 000000000000010E: B9 3A 20 00 00 mov ecx,203Ah 0000000000000113: 66 89 0C 38 mov word ptr [rax+rdi],cx 0000000000000117: C6 44 38 02 00 mov byte ptr [rax+rdi+2],0 000000000000011C: EB 20 jmp 000000000000013E 000000000000011E: 48 C7 44 24 20 02 mov qword ptr [rsp+20h],2 0000000000000127: 4C 8D 0D 00 00 00 lea r9,[??_C@_02LMMGGCAJ@?3?5@] 000000000000012E: 45 33 C0 xor r8d,r8d 0000000000000131: 41 8D 50 02 lea edx,[r8+2] 0000000000000135: 48 8D 4D 07 lea rcx,[rbp+7] 0000000000000000: 40 53 push rbx 0000000000000002: 56 push rsi 0000000000000003: 41 55 push r13 0000000000000005: 41 56 push r14 0000000000000007: 48 83 EC 28 sub rsp,28h 000000000000000B: 4C 8B 71 10 mov r14,qword ptr [rcx+10h] 000000000000000F: 48 BB FF FF FF FF mov rbx,7FFFFFFFFFFFFFFFh 0000000000000019: 48 8B C3 mov rax,rbx 000000000000001C: 4D 8B E9 mov r13,r9 000000000000001F: 49 2B C6 sub rax,r14 0000000000000022: 48 8B F1 mov rsi,rcx 0000000000000025: 48 3B C2 cmp rax,rdx 0000000000000028: 0F 82 41 01 00 00 jb 000000000000016F 000000000000002E: 48 89 6C 24 50 mov qword ptr [rsp+50h],rbp 0000000000000033: 48 8B 69 18 mov rbp,qword ptr [rcx+18h] 0000000000000037: 4C 89 7C 24 20 mov qword ptr [rsp+20h],r15 000000000000003C: 4D 8D 3C 16 lea r15,[r14+rdx] 0000000000000040: 49 8B CF mov rcx,r15 0000000000000043: 48 83 C9 0F or rcx,0Fh 0000000000000047: 48 3B CB cmp rcx,rbx 000000000000004A: 77 1F ja 000000000000006B 000000000000004C: 48 8B D5 mov rdx,rbp 000000000000004F: 48 8B C3 mov rax,rbx 0000000000000052: 48 D1 EA shr rdx,1 0000000000000055: 48 2B C2 sub rax,rdx 0000000000000058: 48 3B E8 cmp rbp,rax 000000000000005B: 77 0E ja 000000000000006B 000000000000005D: 48 8D 04 2A lea rax,[rdx+rbp] 0000000000000061: 48 8B D9 mov rbx,rcx 0000000000000064: 48 3B C8 cmp rcx,rax 0000000000000067: 48 0F 42 D8 cmovb rbx,rax 000000000000006B: 48 8D 4B 01 lea rcx,[rbx+1] 000000000000006F: 48 89 7C 24 58 mov qword ptr [rsp+58h],rdi 0000000000000074: 4C 89 64 24 60 mov qword ptr [rsp+60h],r12 0000000000000079: 48 81 F9 00 10 00 cmp rcx,1000h 0000000000000080: 72 2C jb 00000000000000AE 0000000000000082: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000086: 48 3B C1 cmp rax,rcx 0000000000000089: 0F 86 E6 00 00 00 jbe 0000000000000175 000000000000008F: 48 8B C8 mov rcx,rax 0000000000000092: E8 00 00 00 00 call ??2@YAPEAX_K@Z 0000000000000097: 48 85 C0 test rax,rax 000000000000009A: 0F 84 C9 00 00 00 je 0000000000000169 00000000000000A0: 48 8D 78 27 lea rdi,[rax+27h] 00000000000000A4: 48 83 E7 E0 and rdi,0FFFFFFFFFFFFFFE0h 00000000000000A8: 48 89 47 F8 mov qword ptr [rdi-8],rax 00000000000000AC: EB 11 jmp 00000000000000BF 00000000000000AE: 48 85 C9 test rcx,rcx 00000000000000B1: 74 0A je 00000000000000BD 00000000000000B3: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000B8: 48 8B F8 mov rdi,rax 00000000000000BB: EB 02 jmp 00000000000000BF 00000000000000BD: 33 FF xor edi,edi 00000000000000BF: 4C 8B 64 24 70 mov r12,qword ptr [rsp+70h] 00000000000000C4: 4D 8B C6 mov r8,r14 00000000000000C7: 4C 89 7E 10 mov qword ptr [rsi+10h],r15 00000000000000CB: 4E 8D 3C 37 lea r15,[rdi+r14] 00000000000000CF: 48 89 5E 18 mov qword ptr [rsi+18h],rbx 00000000000000D3: 48 8B CF mov rcx,rdi 00000000000000D6: 48 83 FD 10 cmp rbp,10h 00000000000000DA: 72 4D jb 0000000000000129 00000000000000DC: 48 8B 1E mov rbx,qword ptr [rsi] 00000000000000DF: 48 8B D3 mov rdx,rbx 00000000000000E2: E8 00 00 00 00 call memcpy 00000000000000E7: 4D 8B C4 mov r8,r12 00000000000000EA: 49 8B D5 mov rdx,r13 00000000000000ED: 49 8B CF mov rcx,r15 00000000000000F0: E8 00 00 00 00 call memcpy 00000000000000F5: 48 8D 55 01 lea rdx,[rbp+1] 00000000000000F9: 43 C6 04 27 00 mov byte ptr [r15+r12],0 00000000000000FE: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000105: 72 18 jb 000000000000011F 0000000000000107: 48 8B 4B F8 mov rcx,qword ptr [rbx-8] 000000000000010B: 48 83 C2 27 add rdx,27h 000000000000010F: 48 2B D9 sub rbx,rcx 0000000000000112: 48 8D 43 F8 lea rax,[rbx-8] 0000000000000116: 48 83 F8 1F cmp rax,1Fh 000000000000011A: 77 4D ja 0000000000000169 000000000000011C: 48 8B D9 mov rbx,rcx 000000000000011F: 48 8B CB mov rcx,rbx 0000000000000122: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000127: EB 1B jmp 0000000000000144 0000000000000129: 48 8B D6 mov rdx,rsi 000000000000012C: E8 00 00 00 00 call memcpy 0000000000000131: 4D 8B C4 mov r8,r12 0000000000000134: 49 8B D5 mov rdx,r13 0000000000000137: 49 8B CF mov rcx,r15 000000000000013A: E8 00 00 00 00 call memcpy 000000000000013F: 43 C6 04 27 00 mov byte ptr [r15+r12],0 0000000000000144: 48 89 3E mov qword ptr [rsi],rdi 0000000000000147: 48 8B C6 mov rax,rsi 000000000000014A: 4C 8B 64 24 60 mov r12,qword ptr [rsp+60h] 000000000000014F: 48 8B 7C 24 58 mov rdi,qword ptr [rsp+58h] 0000000000000154: 48 8B 6C 24 50 mov rbp,qword ptr [rsp+50h] 0000000000000159: 4C 8B 7C 24 20 mov r15,qword ptr [rsp+20h] 000000000000015E: 48 83 C4 28 add rsp,28h 0000000000000162: 41 5E pop r14 0000000000000164: 41 5D pop r13 0000000000000166: 5E pop rsi 0000000000000167: 5B pop rbx 0000000000000168: C3 ret 0000000000000169: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 000000000000016E: CC int 3 000000000000016F: E8 00 00 00 00 call ?_Xlen@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@CAXXZ 0000000000000174: CC int 3 0000000000000175: E8 00 00 00 00 call ?_Throw_bad_array_new_length@std@@YAXXZ 000000000000017A: CC int 3 000000000000013E: 48 8B 4D EF mov rcx,qword ptr [rbp-11h] 0000000000000142: 48 8B 01 mov rax,qword ptr [rcx] 0000000000000145: 44 8B 45 E7 mov r8d,dword ptr [rbp-19h] 0000000000000149: 48 8D 55 E7 lea rdx,[rbp-19h] 000000000000014D: FF 50 10 call qword ptr [rax+10h] 0000000000000150: 90 nop 0000000000000151: 48 8D 55 E7 lea rdx,[rbp-19h] 0000000000000155: 48 83 7D FF 10 cmp qword ptr [rbp-1],10h 000000000000015A: 48 0F 43 55 E7 cmovae rdx,qword ptr [rbp-19h] 000000000000015F: 4C 8B 45 F7 mov r8,qword ptr [rbp-9] 0000000000000163: 48 8D 4D 07 lea rcx,[rbp+7] 0000000000000000: 48 89 74 24 10 mov qword ptr [rsp+10h],rsi 0000000000000005: 57 push rdi 0000000000000006: 48 83 EC 30 sub rsp,30h 000000000000000A: 48 8B F9 mov rdi,rcx 000000000000000D: 49 8B F0 mov rsi,r8 0000000000000010: 48 8B 49 10 mov rcx,qword ptr [rcx+10h] 0000000000000014: 4C 8B 47 18 mov r8,qword ptr [rdi+18h] 0000000000000018: 49 8B C0 mov rax,r8 000000000000001B: 48 2B C1 sub rax,rcx 000000000000001E: 48 3B F0 cmp rsi,rax 0000000000000021: 77 3F ja 0000000000000062 0000000000000023: 48 89 5C 24 40 mov qword ptr [rsp+40h],rbx 0000000000000028: 48 8D 04 31 lea rax,[rcx+rsi] 000000000000002C: 48 89 47 10 mov qword ptr [rdi+10h],rax 0000000000000030: 48 8B C7 mov rax,rdi 0000000000000033: 49 83 F8 10 cmp r8,10h 0000000000000037: 72 03 jb 000000000000003C 0000000000000039: 48 8B 07 mov rax,qword ptr [rdi] 000000000000003C: 48 8D 1C 08 lea rbx,[rax+rcx] 0000000000000040: 4C 8B C6 mov r8,rsi 0000000000000043: 48 8B CB mov rcx,rbx 0000000000000046: E8 00 00 00 00 call memmove 000000000000004B: C6 04 33 00 mov byte ptr [rbx+rsi],0 000000000000004F: 48 8B C7 mov rax,rdi 0000000000000052: 48 8B 5C 24 40 mov rbx,qword ptr [rsp+40h] 0000000000000057: 48 8B 74 24 48 mov rsi,qword ptr [rsp+48h] 000000000000005C: 48 83 C4 30 add rsp,30h 0000000000000060: 5F pop rdi 0000000000000061: C3 ret 0000000000000062: 4C 8B CA mov r9,rdx 0000000000000065: 48 89 74 24 20 mov qword ptr [rsp+20h],rsi 000000000000006A: 48 8B D6 mov rdx,rsi 000000000000006D: 45 33 C0 xor r8d,r8d 0000000000000070: 48 8B CF mov rcx,rdi 0000000000000073: E8 00 00 00 00 call ??$_Reallocate_grow_by@V<lambda_65e615be2a453ca0576c979606f46740>@@PEBD_K@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAAAEAV01@_KV<lambda_65e615be2a453ca0576c979606f46740>@@PEBD_K@Z 0000000000000078: 48 8B 74 24 48 mov rsi,qword ptr [rsp+48h] 000000000000007D: 48 83 C4 30 add rsp,30h 0000000000000081: 5F pop rdi 0000000000000082: C3 ret 000000000000016C: 90 nop 000000000000016D: 48 8B 55 FF mov rdx,qword ptr [rbp-1] 0000000000000171: 48 83 FA 10 cmp rdx,10h 0000000000000175: 72 31 jb 00000000000001A8 0000000000000177: 48 FF C2 inc rdx 000000000000017A: 48 8B 4D E7 mov rcx,qword ptr [rbp-19h] 000000000000017E: 48 8B C1 mov rax,rcx 0000000000000181: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000188: 72 19 jb 00000000000001A3 000000000000018A: 48 83 C2 27 add rdx,27h 000000000000018E: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 0000000000000192: 48 2B C1 sub rax,rcx 0000000000000195: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000199: 48 83 F8 1F cmp rax,1Fh 000000000000019D: 0F 87 E9 00 00 00 ja 000000000000028C 00000000000001A3: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 00000000000001A8: 0F 10 45 07 movups xmm0,xmmword ptr [rbp+7] 00000000000001AC: 0F 11 45 27 movups xmmword ptr [rbp+27h],xmm0 00000000000001B0: 0F 10 4D 17 movups xmm1,xmmword ptr [rbp+17h] 00000000000001B4: 0F 11 4D 37 movups xmmword ptr [rbp+37h],xmm1 00000000000001B8: 48 C7 45 17 00 00 mov qword ptr [rbp+17h],0 00000000000001C0: 48 C7 45 1F 0F 00 mov qword ptr [rbp+1Fh],0Fh 00000000000001C8: C6 45 07 00 mov byte ptr [rbp+7],0 00000000000001CC: 4C 8D 45 27 lea r8,[rbp+27h] 00000000000001D0: 66 48 0F 7E C1 movq rcx,xmm0 00000000000001D5: 66 0F 73 D9 08 psrldq xmm1,8 00000000000001DA: 66 48 0F 7E C8 movq rax,xmm1 00000000000001DF: 48 83 F8 10 cmp rax,10h 00000000000001E3: 4C 0F 43 C1 cmovae r8,rcx 00000000000001E7: 48 8D 05 00 00 00 lea rax,[??_7exception@std@@6B@] 00000000000001EE: 49 89 06 mov qword ptr [r14],rax 00000000000001F1: 49 8D 56 08 lea rdx,[r14+8] 00000000000001F5: 0F 57 C0 xorps xmm0,xmm0 00000000000001F8: 0F 11 02 movups xmmword ptr [rdx],xmm0 00000000000001FB: 4C 89 45 E7 mov qword ptr [rbp-19h],r8 00000000000001FF: C6 45 EF 01 mov byte ptr [rbp-11h],1 0000000000000203: 48 8D 4D E7 lea rcx,[rbp-19h] 0000000000000207: E8 00 00 00 00 call __std_exception_copy 000000000000020C: 48 8D 05 00 00 00 lea rax,[??_7runtime_error@std@@6B@] 0000000000000213: 49 89 06 mov qword ptr [r14],rax 0000000000000216: 48 8B 55 3F mov rdx,qword ptr [rbp+3Fh] 000000000000021A: 48 83 FA 10 cmp rdx,10h 000000000000021E: 72 2D jb 000000000000024D 0000000000000220: 48 FF C2 inc rdx 0000000000000223: 48 8B 4D 27 mov rcx,qword ptr [rbp+27h] 0000000000000227: 48 8B C1 mov rax,rcx 000000000000022A: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000231: 72 15 jb 0000000000000248 0000000000000233: 48 83 C2 27 add rdx,27h 0000000000000237: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 000000000000023B: 48 2B C1 sub rax,rcx 000000000000023E: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000242: 48 83 F8 1F cmp rax,1Fh 0000000000000246: 77 38 ja 0000000000000280 0000000000000248: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 000000000000024D: 48 8D 05 00 00 00 lea rax,[??_7_System_error@std@@6B@] 0000000000000254: 49 89 06 mov qword ptr [r14],rax 0000000000000257: 41 0F 10 07 movups xmm0,xmmword ptr [r15] 000000000000025B: 41 0F 11 46 18 movups xmmword ptr [r14+18h],xmm0 0000000000000260: 49 8B C6 mov rax,r14 0000000000000263: 4C 8D 9C 24 90 00 lea r11,[rsp+90h] 000000000000026B: 49 8B 5B 20 mov rbx,qword ptr [r11+20h] 000000000000026F: 49 8B 73 28 mov rsi,qword ptr [r11+28h] 0000000000000273: 49 8B 7B 38 mov rdi,qword ptr [r11+38h] 0000000000000277: 49 8B E3 mov rsp,r11 000000000000027A: 41 5F pop r15 000000000000027C: 41 5E pop r14 000000000000027E: 5D pop rbp 000000000000027F: C3 ret 0000000000000280: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 0000000000000285: CC int 3 0000000000000286: E8 00 00 00 00 call ?_Throw_bad_array_new_length@std@@YAXXZ 000000000000028B: 90 nop 000000000000028C: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 0000000000000291: 90 nop 0000000000000056: 90 nop 0000000000000057: 48 8B 54 24 48 mov rdx,qword ptr [rsp+48h] 000000000000005C: 48 83 FA 10 cmp rdx,10h 0000000000000060: 72 2E jb 0000000000000090 0000000000000062: 48 FF C2 inc rdx 0000000000000065: 48 8B 4C 24 30 mov rcx,qword ptr [rsp+30h] 000000000000006A: 48 8B C1 mov rax,rcx 000000000000006D: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000074: 72 15 jb 000000000000008B 0000000000000076: 48 83 C2 27 add rdx,27h 000000000000007A: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 000000000000007E: 48 2B C1 sub rax,rcx 0000000000000081: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000085: 48 83 F8 1F cmp rax,1Fh 0000000000000089: 77 1D ja 00000000000000A8 000000000000008B: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000090: 48 8D 05 00 00 00 lea rax,[??_7system_error@std@@6B@] 0000000000000097: 48 89 07 mov qword ptr [rdi],rax 000000000000009A: 48 8B C7 mov rax,rdi 000000000000009D: 48 8B 5C 24 60 mov rbx,qword ptr [rsp+60h] 00000000000000A2: 48 83 C4 50 add rsp,50h 00000000000000A6: 5F pop rdi 00000000000000A7: C3 ret 00000000000000A8: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 00000000000000AD: CC int 3 000000000000001B: 48 8D 15 00 00 00 lea rdx,[_TI4?AVsystem_error@std@@] 0000000000000022: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000027: E8 00 00 00 00 call _CxxThrowException 000000000000002C: CC int 3 00000000000000B0: CC int 3 00000000000000B1: E8 00 00 00 00 call terminate 00000000000000B6: CC int 3
0
repos/outcome/test
repos/outcome/test/constexprs/max_result_get_value.gcc.S.test1.s
9a0: 48 83 ec 28 sub $0x28,%rsp 9a4: 48 89 e7 mov %rsp,%rdi 840: ff 25 82 17 20 00 jmpq *0x201782(%rip) # 201fc8 <unknown()> 846: 68 07 00 00 00 pushq $0x7 84b: e9 70 ff ff ff jmpq 7c0 <.plt> 9ac: 0f b7 44 24 04 movzwl 0x4(%rsp),%eax 9b1: a8 01 test $0x1,%al 9b3: 75 13 jne 9c8 <test1()+0x28> 9b5: a8 02 test $0x2,%al 9b7: 74 17 je 9d0 <test1()+0x30> 9b9: 48 8d 3d 9e 01 00 00 lea 0x19e(%rip),%rdi # b5e <_IO_stdin_used+0x4e> 9f0: 41 56 push %r14 9f2: be 10 00 00 00 mov $0x10,%esi 9f7: 41 55 push %r13 9f9: 41 54 push %r12 9fb: 49 89 fc mov %rdi,%r12 9fe: 55 push %rbp 9ff: 53 push %rbx a00: 48 83 c4 80 add $0xffffffffffffff80,%rsp a04: 49 89 e5 mov %rsp,%r13 a07: 4c 89 ef mov %r13,%rdi 800: ff 25 a2 17 20 00 jmpq *0x2017a2(%rip) # 201fa8 <backtrace@GLIBC_2.2.5> 806: 68 03 00 00 00 pushq $0x3 80b: e9 b0 ff ff ff jmpq 7c0 <.plt> a0f: 48 8b 3d 0a 16 20 00 mov 0x20160a(%rip),%rdi # 202020 <stderr@@GLIBC_2.2.5> a16: 4c 89 e1 mov %r12,%rcx a19: be 01 00 00 00 mov $0x1,%esi a1e: 4c 63 f0 movslq %eax,%r14 a21: 48 8d 15 f0 00 00 00 lea 0xf0(%rip),%rdx # b18 <_IO_stdin_used+0x8> a28: 31 c0 xor %eax,%eax 830: ff 25 8a 17 20 00 jmpq *0x20178a(%rip) # 201fc0 <__fprintf_chk@GLIBC_2.3.4> 836: 68 06 00 00 00 pushq $0x6 83b: e9 80 ff ff ff jmpq 7c0 <.plt> a2f: 44 89 f6 mov %r14d,%esi a32: 4c 89 ef mov %r13,%rdi 810: ff 25 9a 17 20 00 jmpq *0x20179a(%rip) # 201fb0 <backtrace_symbols@GLIBC_2.2.5> 816: 68 04 00 00 00 pushq $0x4 81b: e9 a0 ff ff ff jmpq 7c0 <.plt> a3a: 48 85 c0 test %rax,%rax a3d: 74 43 je a82 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x92> a3f: 49 89 c5 mov %rax,%r13 a42: 4d 85 f6 test %r14,%r14 a45: 74 33 je a7a <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x8a> a47: 48 89 c3 mov %rax,%rbx a4a: 4e 8d 24 f0 lea (%rax,%r14,8),%r12 a4e: 48 8d 2d 03 01 00 00 lea 0x103(%rip),%rbp # b58 <_IO_stdin_used+0x48> a55: 0f 1f 00 nopl (%rax) a58: 48 8b 0b mov (%rbx),%rcx a5b: 48 8b 3d be 15 20 00 mov 0x2015be(%rip),%rdi # 202020 <stderr@@GLIBC_2.2.5> a62: 48 89 ea mov %rbp,%rdx a65: 31 c0 xor %eax,%eax a67: be 01 00 00 00 mov $0x1,%esi a6c: 48 83 c3 08 add $0x8,%rbx a70: e8 bb fd ff ff callq 830 <__fprintf_chk@plt> a75: 4c 39 e3 cmp %r12,%rbx a78: 75 de jne a58 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x68> a7a: 4c 89 ef mov %r13,%rdi 7f0: ff 25 aa 17 20 00 jmpq *0x2017aa(%rip) # 201fa0 <free@GLIBC_2.2.5> 7f6: 68 02 00 00 00 pushq $0x2 7fb: e9 c0 ff ff ff jmpq 7c0 <.plt> 7d0: ff 25 ba 17 20 00 jmpq *0x2017ba(%rip) # 201f90 <abort@GLIBC_2.2.5> 7d6: 68 00 00 00 00 pushq $0x0 7db: e9 e0 ff ff ff jmpq 7c0 <.plt> a87: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1) 9c5: 0f 1f 00 nopl (%rax) 9c8: 8b 04 24 mov (%rsp),%eax 9cb: 48 83 c4 28 add $0x28,%rsp 9cf: c3 retq 9d0: 48 8d 3d a0 01 00 00 lea 0x1a0(%rip),%rdi # b77 <_IO_stdin_used+0x67> 9f0: 41 56 push %r14 9f2: be 10 00 00 00 mov $0x10,%esi 9f7: 41 55 push %r13 9f9: 41 54 push %r12 9fb: 49 89 fc mov %rdi,%r12 9fe: 55 push %rbp 9ff: 53 push %rbx a00: 48 83 c4 80 add $0xffffffffffffff80,%rsp a04: 49 89 e5 mov %rsp,%r13 a07: 4c 89 ef mov %r13,%rdi 800: ff 25 a2 17 20 00 jmpq *0x2017a2(%rip) # 201fa8 <backtrace@GLIBC_2.2.5> 806: 68 03 00 00 00 pushq $0x3 80b: e9 b0 ff ff ff jmpq 7c0 <.plt> a0f: 48 8b 3d 0a 16 20 00 mov 0x20160a(%rip),%rdi # 202020 <stderr@@GLIBC_2.2.5> a16: 4c 89 e1 mov %r12,%rcx a19: be 01 00 00 00 mov $0x1,%esi a1e: 4c 63 f0 movslq %eax,%r14 a21: 48 8d 15 f0 00 00 00 lea 0xf0(%rip),%rdx # b18 <_IO_stdin_used+0x8> a28: 31 c0 xor %eax,%eax 830: ff 25 8a 17 20 00 jmpq *0x20178a(%rip) # 201fc0 <__fprintf_chk@GLIBC_2.3.4> 836: 68 06 00 00 00 pushq $0x6 83b: e9 80 ff ff ff jmpq 7c0 <.plt> a2f: 44 89 f6 mov %r14d,%esi a32: 4c 89 ef mov %r13,%rdi 810: ff 25 9a 17 20 00 jmpq *0x20179a(%rip) # 201fb0 <backtrace_symbols@GLIBC_2.2.5> 816: 68 04 00 00 00 pushq $0x4 81b: e9 a0 ff ff ff jmpq 7c0 <.plt> a3a: 48 85 c0 test %rax,%rax a3d: 74 43 je a82 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x92> a3f: 49 89 c5 mov %rax,%r13 a42: 4d 85 f6 test %r14,%r14 a45: 74 33 je a7a <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x8a> a47: 48 89 c3 mov %rax,%rbx a4a: 4e 8d 24 f0 lea (%rax,%r14,8),%r12 a4e: 48 8d 2d 03 01 00 00 lea 0x103(%rip),%rbp # b58 <_IO_stdin_used+0x48> a55: 0f 1f 00 nopl (%rax) a58: 48 8b 0b mov (%rbx),%rcx a5b: 48 8b 3d be 15 20 00 mov 0x2015be(%rip),%rdi # 202020 <stderr@@GLIBC_2.2.5> a62: 48 89 ea mov %rbp,%rdx a65: 31 c0 xor %eax,%eax a67: be 01 00 00 00 mov $0x1,%esi a6c: 48 83 c3 08 add $0x8,%rbx a70: e8 bb fd ff ff callq 830 <__fprintf_chk@plt> a75: 4c 39 e3 cmp %r12,%rbx a78: 75 de jne a58 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x68> a7a: 4c 89 ef mov %r13,%rdi 7f0: ff 25 aa 17 20 00 jmpq *0x2017aa(%rip) # 201fa0 <free@GLIBC_2.2.5> 7f6: 68 02 00 00 00 pushq $0x2 7fb: e9 c0 ff ff ff jmpq 7c0 <.plt> 7d0: ff 25 ba 17 20 00 jmpq *0x2017ba(%rip) # 201f90 <abort@GLIBC_2.2.5> 7d6: 68 00 00 00 00 pushq $0x0 7db: e9 e0 ff ff ff jmpq 7c0 <.plt> a87: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1) 9dc: 0f 1f 40 00 nopl 0x0(%rax)
0
repos/outcome/test
repos/outcome/test/constexprs/max_result_get_value.clang.S.test1.s
400830: 48 83 ec 18 sub $0x18,%rsp 400834: 48 89 e7 mov %rsp,%rdi 400700: ff 25 4a 09 20 00 jmpq *0x20094a(%rip) # 601050 <unknown()> 400706: 68 07 00 00 00 pushq $0x7 40070b: e9 70 ff ff ff jmpq 400680 <.plt> 40083c: 0f b7 44 24 04 movzwl 0x4(%rsp),%eax 400841: a8 01 test $0x1,%al 400843: 74 08 je 40084d <test1()+0x1d> 400845: 8b 04 24 mov (%rsp),%eax 400848: 48 83 c4 18 add $0x18,%rsp 40084c: c3 retq 40084d: a8 02 test $0x2,%al 40084f: 75 0a jne 40085b <test1()+0x2b> 400851: bf b4 09 40 00 mov $0x4009b4,%edi 4008a0: 55 push %rbp 4008a1: 41 56 push %r14 4008a3: 53 push %rbx 4008a4: 48 81 ec 80 00 00 00 sub $0x80,%rsp 4008ab: 48 89 fb mov %rdi,%rbx 4008ae: 49 89 e6 mov %rsp,%r14 4008b1: 4c 89 f7 mov %r14,%rdi 4008b4: be 10 00 00 00 mov $0x10,%esi 4006d0: ff 25 62 09 20 00 jmpq *0x200962(%rip) # 601038 <backtrace@GLIBC_2.2.5> 4006d6: 68 04 00 00 00 pushq $0x4 4006db: e9 a0 ff ff ff jmpq 400680 <.plt> 4008be: 89 c5 mov %eax,%ebp 4008c0: 48 8b 3d b9 07 20 00 mov 0x2007b9(%rip),%rdi # 601080 <stderr@@GLIBC_2.2.5> 4008c7: be eb 09 40 00 mov $0x4009eb,%esi 4008cc: 48 89 da mov %rbx,%rdx 4008cf: 31 c0 xor %eax,%eax 4006c0: ff 25 6a 09 20 00 jmpq *0x20096a(%rip) # 601030 <fprintf@GLIBC_2.2.5> 4006c6: 68 03 00 00 00 pushq $0x3 4006cb: e9 b0 ff ff ff jmpq 400680 <.plt> 4008d6: 4c 89 f7 mov %r14,%rdi 4008d9: 89 ee mov %ebp,%esi 4006e0: ff 25 5a 09 20 00 jmpq *0x20095a(%rip) # 601040 <backtrace_symbols@GLIBC_2.2.5> 4006e6: 68 05 00 00 00 pushq $0x5 4006eb: e9 90 ff ff ff jmpq 400680 <.plt> 4008e0: 48 85 c0 test %rax,%rax 4008e3: 74 43 je 400928 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x88> 4008e5: 49 89 c6 mov %rax,%r14 4008e8: 85 ed test %ebp,%ebp 4008ea: 74 34 je 400920 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x80> 4008ec: 48 63 ed movslq %ebp,%rbp 4008ef: 31 db xor %ebx,%ebx 4008f1: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 4008fb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 400900: 48 8b 3d 79 07 20 00 mov 0x200779(%rip),%rdi # 601080 <stderr@@GLIBC_2.2.5> 400907: 49 8b 14 de mov (%r14,%rbx,8),%rdx 40090b: be 28 0a 40 00 mov $0x400a28,%esi 400910: 31 c0 xor %eax,%eax 400912: e8 a9 fd ff ff callq 4006c0 <fprintf@plt> 400917: 48 83 c3 01 add $0x1,%rbx 40091b: 48 39 eb cmp %rbp,%rbx 40091e: 72 e0 jb 400900 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x60> 400920: 4c 89 f7 mov %r14,%rdi 4006b0: ff 25 72 09 20 00 jmpq *0x200972(%rip) # 601028 <free@GLIBC_2.2.5> 4006b6: 68 02 00 00 00 pushq $0x2 4006bb: e9 c0 ff ff ff jmpq 400680 <.plt> 400690: ff 25 82 09 20 00 jmpq *0x200982(%rip) # 601018 <abort@GLIBC_2.2.5> 400696: 68 00 00 00 00 pushq $0x0 40069b: e9 e0 ff ff ff jmpq 400680 <.plt> 40092d: 0f 1f 00 nopl (%rax) 40085b: bf d2 09 40 00 mov $0x4009d2,%edi 4008a0: 55 push %rbp 4008a1: 41 56 push %r14 4008a3: 53 push %rbx 4008a4: 48 81 ec 80 00 00 00 sub $0x80,%rsp 4008ab: 48 89 fb mov %rdi,%rbx 4008ae: 49 89 e6 mov %rsp,%r14 4008b1: 4c 89 f7 mov %r14,%rdi 4008b4: be 10 00 00 00 mov $0x10,%esi 4006d0: ff 25 62 09 20 00 jmpq *0x200962(%rip) # 601038 <backtrace@GLIBC_2.2.5> 4006d6: 68 04 00 00 00 pushq $0x4 4006db: e9 a0 ff ff ff jmpq 400680 <.plt> 4008be: 89 c5 mov %eax,%ebp 4008c0: 48 8b 3d b9 07 20 00 mov 0x2007b9(%rip),%rdi # 601080 <stderr@@GLIBC_2.2.5> 4008c7: be eb 09 40 00 mov $0x4009eb,%esi 4008cc: 48 89 da mov %rbx,%rdx 4008cf: 31 c0 xor %eax,%eax 4006c0: ff 25 6a 09 20 00 jmpq *0x20096a(%rip) # 601030 <fprintf@GLIBC_2.2.5> 4006c6: 68 03 00 00 00 pushq $0x3 4006cb: e9 b0 ff ff ff jmpq 400680 <.plt> 4008d6: 4c 89 f7 mov %r14,%rdi 4008d9: 89 ee mov %ebp,%esi 4006e0: ff 25 5a 09 20 00 jmpq *0x20095a(%rip) # 601040 <backtrace_symbols@GLIBC_2.2.5> 4006e6: 68 05 00 00 00 pushq $0x5 4006eb: e9 90 ff ff ff jmpq 400680 <.plt> 4008e0: 48 85 c0 test %rax,%rax 4008e3: 74 43 je 400928 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x88> 4008e5: 49 89 c6 mov %rax,%r14 4008e8: 85 ed test %ebp,%ebp 4008ea: 74 34 je 400920 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x80> 4008ec: 48 63 ed movslq %ebp,%rbp 4008ef: 31 db xor %ebx,%ebx 4008f1: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 4008fb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 400900: 48 8b 3d 79 07 20 00 mov 0x200779(%rip),%rdi # 601080 <stderr@@GLIBC_2.2.5> 400907: 49 8b 14 de mov (%r14,%rbx,8),%rdx 40090b: be 28 0a 40 00 mov $0x400a28,%esi 400910: 31 c0 xor %eax,%eax 400912: e8 a9 fd ff ff callq 4006c0 <fprintf@plt> 400917: 48 83 c3 01 add $0x1,%rbx 40091b: 48 39 eb cmp %rbp,%rbx 40091e: 72 e0 jb 400900 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x60> 400920: 4c 89 f7 mov %r14,%rdi 4006b0: ff 25 72 09 20 00 jmpq *0x200972(%rip) # 601028 <free@GLIBC_2.2.5> 4006b6: 68 02 00 00 00 pushq $0x2 4006bb: e9 c0 ff ff ff jmpq 400680 <.plt> 400690: ff 25 82 09 20 00 jmpq *0x200982(%rip) # 601018 <abort@GLIBC_2.2.5> 400696: 68 00 00 00 00 pushq $0x0 40069b: e9 e0 ff ff ff jmpq 400680 <.plt> 40092d: 0f 1f 00 nopl (%rax) 400865: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 40086f: 90 nop
0
repos/outcome/test
repos/outcome/test/constexprs/max_result_construct_value_move_destruct.msvc.S.test1.s
0000000000000000: 48 83 EC 78 sub rsp,78h 0000000000000004: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000009: E8 00 00 00 00 call ?unknown@@YA?AV?$basic_result@HVerror_code@std@@U?$error_code_throw_as_system_error@HVerror_code@std@@X@policy@outcome_v2_3f877000@@@outcome_v2_3f877000@@XZ 000000000000000E: 0F 10 4C 24 20 movups xmm1,xmmword ptr [rsp+20h] 0000000000000013: F2 0F 10 44 24 30 movsd xmm0,mmword ptr [rsp+30h] 0000000000000019: 66 48 0F 7E C8 movq rax,xmm1 000000000000001E: F2 0F 11 44 24 48 movsd mmword ptr [rsp+48h],xmm0 0000000000000024: 48 C1 E8 20 shr rax,20h 0000000000000028: 0F 11 4C 24 38 movups xmmword ptr [rsp+38h],xmm1 000000000000002D: A8 01 test al,1 000000000000002F: 75 08 jne 0000000000000039 0000000000000031: D0 E8 shr al,1 0000000000000033: A8 01 test al,1 0000000000000035: 75 2E jne 0000000000000065 0000000000000037: EB 09 jmp 0000000000000042 0000000000000039: 66 0F 7E C8 movd eax,xmm1 000000000000003D: 48 83 C4 78 add rsp,78h 0000000000000041: C3 ret 0000000000000042: 48 8D 15 00 00 00 lea rdx,[??_C@_08JEIPHCP@no?5value@] 0000000000000049: 48 8D 4C 24 50 lea rcx,[rsp+50h] 0000000000000000: 40 53 push rbx 0000000000000002: 48 83 EC 30 sub rsp,30h 0000000000000006: 48 8B D9 mov rbx,rcx 0000000000000009: C6 44 24 28 01 mov byte ptr [rsp+28h],1 000000000000000E: 48 8B C2 mov rax,rdx 0000000000000011: 48 8D 0D 00 00 00 lea rcx,[??_7exception@std@@6B@] 0000000000000018: 48 8D 53 08 lea rdx,[rbx+8] 000000000000001C: 48 89 44 24 20 mov qword ptr [rsp+20h],rax 0000000000000021: 0F 57 C0 xorps xmm0,xmm0 0000000000000024: 48 89 0B mov qword ptr [rbx],rcx 0000000000000027: 48 8D 4C 24 20 lea rcx,[rsp+20h] 000000000000002C: 0F 11 02 movups xmmword ptr [rdx],xmm0 000000000000002F: E8 00 00 00 00 call __std_exception_copy 0000000000000034: 48 8D 05 00 00 00 lea rax,[??_7bad_result_access@outcome_v2_3f877000@@6B@] 000000000000003B: 48 89 03 mov qword ptr [rbx],rax 000000000000003E: 48 8B C3 mov rax,rbx 0000000000000041: 48 83 C4 30 add rsp,30h 0000000000000045: 5B pop rbx 0000000000000046: C3 ret 0000000000000053: 48 8D 15 00 00 00 lea rdx,[_TI3?AVbad_result_access@outcome_v2_3f877000@@] 000000000000005A: 48 8D 4C 24 50 lea rcx,[rsp+50h] 000000000000005F: E8 00 00 00 00 call _CxxThrowException 0000000000000064: CC int 3 0000000000000065: 48 8D 4C 24 38 lea rcx,[rsp+38h] 0000000000000000: 48 8B C1 mov rax,rcx 0000000000000003: C3 ret 000000000000006F: 48 8B C8 mov rcx,rax 0000000000000000: 48 8D 41 08 lea rax,[rcx+8] 0000000000000004: C3 ret 0000000000000077: 48 8B C8 mov rcx,rax 0000000000000000: 48 83 EC 68 sub rsp,68h 0000000000000004: 0F 10 01 movups xmm0,xmmword ptr [rcx] 0000000000000007: 48 8D 54 24 20 lea rdx,[rsp+20h] 000000000000000C: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000011: 0F 29 44 24 20 movaps xmmword ptr [rsp+20h],xmm0 0000000000000000: 48 89 5C 24 08 mov qword ptr [rsp+8],rbx 0000000000000005: 57 push rdi 0000000000000006: 48 83 EC 50 sub rsp,50h 000000000000000A: 48 8B DA mov rbx,rdx 000000000000000D: 48 8B F9 mov rdi,rcx 0000000000000010: 48 C7 44 24 40 00 mov qword ptr [rsp+40h],0 0000000000000019: 48 C7 44 24 48 0F mov qword ptr [rsp+48h],0Fh 0000000000000022: C6 44 24 30 00 mov byte ptr [rsp+30h],0 0000000000000027: 45 33 C0 xor r8d,r8d 000000000000002A: 48 8D 15 00 00 00 lea rdx,[??_C@_00CNPNBAHC@@] 0000000000000031: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000000: 48 89 5C 24 10 mov qword ptr [rsp+10h],rbx 0000000000000005: 48 89 6C 24 18 mov qword ptr [rsp+18h],rbp 000000000000000A: 56 push rsi 000000000000000B: 57 push rdi 000000000000000C: 41 57 push r15 000000000000000E: 48 83 EC 20 sub rsp,20h 0000000000000012: 48 8B 69 18 mov rbp,qword ptr [rcx+18h] 0000000000000016: 49 8B F0 mov rsi,r8 0000000000000019: 4C 8B FA mov r15,rdx 000000000000001C: 48 8B D9 mov rbx,rcx 000000000000001F: 4C 3B C5 cmp r8,rbp 0000000000000022: 77 21 ja 0000000000000045 0000000000000024: 48 8B F9 mov rdi,rcx 0000000000000027: 48 83 FD 10 cmp rbp,10h 000000000000002B: 72 03 jb 0000000000000030 000000000000002D: 48 8B 39 mov rdi,qword ptr [rcx] 0000000000000030: 48 89 71 10 mov qword ptr [rcx+10h],rsi 0000000000000034: 48 8B CF mov rcx,rdi 0000000000000037: E8 00 00 00 00 call memmove 000000000000003C: C6 04 37 00 mov byte ptr [rdi+rsi],0 0000000000000040: E9 E4 00 00 00 jmp 0000000000000129 0000000000000045: 48 BF FF FF FF FF mov rdi,7FFFFFFFFFFFFFFFh 000000000000004F: 48 3B F7 cmp rsi,rdi 0000000000000052: 0F 87 F3 00 00 00 ja 000000000000014B 0000000000000058: 48 8B CE mov rcx,rsi 000000000000005B: 48 83 C9 0F or rcx,0Fh 000000000000005F: 48 3B CF cmp rcx,rdi 0000000000000062: 77 1F ja 0000000000000083 0000000000000064: 48 8B D5 mov rdx,rbp 0000000000000067: 48 8B C7 mov rax,rdi 000000000000006A: 48 D1 EA shr rdx,1 000000000000006D: 48 2B C2 sub rax,rdx 0000000000000070: 48 3B E8 cmp rbp,rax 0000000000000073: 77 0E ja 0000000000000083 0000000000000075: 48 8D 04 2A lea rax,[rdx+rbp] 0000000000000079: 48 8B F9 mov rdi,rcx 000000000000007C: 48 3B C8 cmp rcx,rax 000000000000007F: 48 0F 42 F8 cmovb rdi,rax 0000000000000083: 48 8D 4F 01 lea rcx,[rdi+1] 0000000000000087: 4C 89 74 24 40 mov qword ptr [rsp+40h],r14 000000000000008C: 48 81 F9 00 10 00 cmp rcx,1000h 0000000000000093: 72 2C jb 00000000000000C1 0000000000000095: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000099: 48 3B C1 cmp rax,rcx 000000000000009C: 0F 86 9D 00 00 00 jbe 000000000000013F 00000000000000A2: 48 8B C8 mov rcx,rax 00000000000000A5: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000AA: 48 85 C0 test rax,rax 00000000000000AD: 0F 84 92 00 00 00 je 0000000000000145 00000000000000B3: 4C 8D 70 27 lea r14,[rax+27h] 00000000000000B7: 49 83 E6 E0 and r14,0FFFFFFFFFFFFFFE0h 00000000000000BB: 49 89 46 F8 mov qword ptr [r14-8],rax 00000000000000BF: EB 12 jmp 00000000000000D3 00000000000000C1: 48 85 C9 test rcx,rcx 00000000000000C4: 74 0A je 00000000000000D0 00000000000000C6: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000CB: 4C 8B F0 mov r14,rax 00000000000000CE: EB 03 jmp 00000000000000D3 00000000000000D0: 45 33 F6 xor r14d,r14d 00000000000000D3: 4C 8B C6 mov r8,rsi 00000000000000D6: 48 89 73 10 mov qword ptr [rbx+10h],rsi 00000000000000DA: 49 8B D7 mov rdx,r15 00000000000000DD: 48 89 7B 18 mov qword ptr [rbx+18h],rdi 00000000000000E1: 49 8B CE mov rcx,r14 00000000000000E4: E8 00 00 00 00 call memcpy 00000000000000E9: 41 C6 04 36 00 mov byte ptr [r14+rsi],0 00000000000000EE: 48 83 FD 10 cmp rbp,10h 00000000000000F2: 72 2D jb 0000000000000121 00000000000000F4: 48 8B 0B mov rcx,qword ptr [rbx] 00000000000000F7: 48 8D 55 01 lea rdx,[rbp+1] 00000000000000FB: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000102: 72 18 jb 000000000000011C 0000000000000104: 4C 8B 41 F8 mov r8,qword ptr [rcx-8] 0000000000000108: 48 83 C2 27 add rdx,27h 000000000000010C: 49 2B C8 sub rcx,r8 000000000000010F: 48 8D 41 F8 lea rax,[rcx-8] 0000000000000113: 48 83 F8 1F cmp rax,1Fh 0000000000000117: 77 2C ja 0000000000000145 0000000000000119: 49 8B C8 mov rcx,r8 000000000000011C: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000121: 4C 89 33 mov qword ptr [rbx],r14 0000000000000124: 4C 8B 74 24 40 mov r14,qword ptr [rsp+40h] 0000000000000129: 48 8B 6C 24 50 mov rbp,qword ptr [rsp+50h] 000000000000012E: 48 8B C3 mov rax,rbx 0000000000000131: 48 8B 5C 24 48 mov rbx,qword ptr [rsp+48h] 0000000000000136: 48 83 C4 20 add rsp,20h 000000000000013A: 41 5F pop r15 000000000000013C: 5F pop rdi 000000000000013D: 5E pop rsi 000000000000013E: C3 ret 0000000000000000: 48 83 EC 48 sub rsp,48h 0000000000000004: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000000: 48 8D 05 00 00 00 lea rax,[??_C@_0BF@KINCDENJ@bad?5array?5new?5length@] 0000000000000007: 48 C7 41 10 00 00 mov qword ptr [rcx+10h],0 000000000000000F: 48 89 41 08 mov qword ptr [rcx+8],rax 0000000000000013: 48 8D 05 00 00 00 lea rax,[??_7bad_array_new_length@std@@6B@] 000000000000001A: 48 89 01 mov qword ptr [rcx],rax 000000000000001D: 48 8B C1 mov rax,rcx 0000000000000020: C3 ret 000000000000000E: 48 8D 15 00 00 00 lea rdx,[_TI3?AVbad_array_new_length@std@@] 0000000000000015: 48 8D 4C 24 20 lea rcx,[rsp+20h] 000000000000001A: E8 00 00 00 00 call _CxxThrowException 000000000000001F: CC int 3 0000000000000144: CC int 3 0000000000000145: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 000000000000014A: CC int 3 0000000000000000: 48 83 EC 28 sub rsp,28h 0000000000000004: 48 8D 0D 00 00 00 lea rcx,[??_C@_0BA@JFNIOLAK@string?5too?5long@] 000000000000000B: E8 00 00 00 00 call ?_Xlength_error@std@@YAXPEBD@Z 0000000000000010: CC int 3 0000000000000150: CC int 3 000000000000003B: 90 nop 000000000000003C: 0F 10 03 movups xmm0,xmmword ptr [rbx] 000000000000003F: 0F 29 44 24 20 movaps xmmword ptr [rsp+20h],xmm0 0000000000000044: 4C 8D 44 24 30 lea r8,[rsp+30h] 0000000000000049: 48 8D 54 24 20 lea rdx,[rsp+20h] 000000000000004E: 48 8B CF mov rcx,rdi 0000000000000000: 48 89 5C 24 08 mov qword ptr [rsp+8],rbx 0000000000000005: 48 89 74 24 10 mov qword ptr [rsp+10h],rsi 000000000000000A: 48 89 7C 24 20 mov qword ptr [rsp+20h],rdi 000000000000000F: 55 push rbp 0000000000000010: 41 56 push r14 0000000000000012: 41 57 push r15 0000000000000014: 48 8D 6C 24 B9 lea rbp,[rsp-47h] 0000000000000019: 48 81 EC 90 00 00 sub rsp,90h 0000000000000020: 49 8B F0 mov rsi,r8 0000000000000023: 4C 8B FA mov r15,rdx 0000000000000026: 4C 8B F1 mov r14,rcx 0000000000000029: 48 C7 45 17 00 00 mov qword ptr [rbp+17h],0 0000000000000031: 48 C7 45 1F 00 00 mov qword ptr [rbp+1Fh],0 0000000000000039: 49 8B 78 10 mov rdi,qword ptr [r8+10h] 000000000000003D: 49 83 78 18 10 cmp qword ptr [r8+18h],10h 0000000000000042: 72 03 jb 0000000000000047 0000000000000044: 49 8B 30 mov rsi,qword ptr [r8] 0000000000000047: 48 83 FF 10 cmp rdi,10h 000000000000004B: 73 0E jae 000000000000005B 000000000000004D: 0F 10 06 movups xmm0,xmmword ptr [rsi] 0000000000000050: 0F 11 45 07 movups xmmword ptr [rbp+7],xmm0 0000000000000054: BB 0F 00 00 00 mov ebx,0Fh 0000000000000059: EB 75 jmp 00000000000000D0 000000000000005B: 48 8B DF mov rbx,rdi 000000000000005E: 48 83 CB 0F or rbx,0Fh 0000000000000062: 48 B8 FF FF FF FF mov rax,7FFFFFFFFFFFFFFFh 000000000000006C: 48 3B D8 cmp rbx,rax 000000000000006F: 48 0F 47 D8 cmova rbx,rax 0000000000000073: 48 8D 4B 01 lea rcx,[rbx+1] 0000000000000077: 48 81 F9 00 10 00 cmp rcx,1000h 000000000000007E: 72 2F jb 00000000000000AF 0000000000000080: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000084: 48 3B C1 cmp rax,rcx 0000000000000087: 0F 86 F9 01 00 00 jbe 0000000000000286 000000000000008D: 48 8B C8 mov rcx,rax 0000000000000090: E8 00 00 00 00 call ??2@YAPEAX_K@Z 0000000000000095: 48 8B C8 mov rcx,rax 0000000000000098: 48 85 C0 test rax,rax 000000000000009B: 0F 84 DF 01 00 00 je 0000000000000280 00000000000000A1: 48 83 C0 27 add rax,27h 00000000000000A5: 48 83 E0 E0 and rax,0FFFFFFFFFFFFFFE0h 00000000000000A9: 48 89 48 F8 mov qword ptr [rax-8],rcx 00000000000000AD: EB 0E jmp 00000000000000BD 00000000000000AF: 48 85 C9 test rcx,rcx 00000000000000B2: 74 07 je 00000000000000BB 00000000000000B4: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000B9: EB 02 jmp 00000000000000BD 00000000000000BB: 33 C0 xor eax,eax 00000000000000BD: 48 89 45 07 mov qword ptr [rbp+7],rax 00000000000000C1: 4C 8D 47 01 lea r8,[rdi+1] 00000000000000C5: 48 8B D6 mov rdx,rsi 00000000000000C8: 48 8B C8 mov rcx,rax 00000000000000CB: E8 00 00 00 00 call memcpy 00000000000000D0: 48 89 7D 17 mov qword ptr [rbp+17h],rdi 00000000000000D4: 48 89 5D 1F mov qword ptr [rbp+1Fh],rbx 00000000000000D8: 48 8D 45 07 lea rax,[rbp+7] 00000000000000DC: 48 89 45 77 mov qword ptr [rbp+77h],rax 00000000000000E0: 41 0F 10 07 movups xmm0,xmmword ptr [r15] 00000000000000E4: 0F 29 45 E7 movaps xmmword ptr [rbp-19h],xmm0 00000000000000E8: 48 85 FF test rdi,rdi 00000000000000EB: 74 51 je 000000000000013E 00000000000000ED: 48 8B C3 mov rax,rbx 00000000000000F0: 48 2B C7 sub rax,rdi 00000000000000F3: 48 83 F8 02 cmp rax,2 00000000000000F7: 72 25 jb 000000000000011E 00000000000000F9: 48 8D 47 02 lea rax,[rdi+2] 00000000000000FD: 48 89 45 17 mov qword ptr [rbp+17h],rax 0000000000000101: 48 8D 45 07 lea rax,[rbp+7] 0000000000000105: 48 83 FB 10 cmp rbx,10h 0000000000000109: 48 0F 43 45 07 cmovae rax,qword ptr [rbp+7] 000000000000010E: B9 3A 20 00 00 mov ecx,203Ah 0000000000000113: 66 89 0C 38 mov word ptr [rax+rdi],cx 0000000000000117: C6 44 38 02 00 mov byte ptr [rax+rdi+2],0 000000000000011C: EB 20 jmp 000000000000013E 000000000000011E: 48 C7 44 24 20 02 mov qword ptr [rsp+20h],2 0000000000000127: 4C 8D 0D 00 00 00 lea r9,[??_C@_02LMMGGCAJ@?3?5@] 000000000000012E: 45 33 C0 xor r8d,r8d 0000000000000131: 41 8D 50 02 lea edx,[r8+2] 0000000000000135: 48 8D 4D 07 lea rcx,[rbp+7] 0000000000000000: 40 53 push rbx 0000000000000002: 56 push rsi 0000000000000003: 41 55 push r13 0000000000000005: 41 56 push r14 0000000000000007: 48 83 EC 28 sub rsp,28h 000000000000000B: 4C 8B 71 10 mov r14,qword ptr [rcx+10h] 000000000000000F: 48 BB FF FF FF FF mov rbx,7FFFFFFFFFFFFFFFh 0000000000000019: 48 8B C3 mov rax,rbx 000000000000001C: 4D 8B E9 mov r13,r9 000000000000001F: 49 2B C6 sub rax,r14 0000000000000022: 48 8B F1 mov rsi,rcx 0000000000000025: 48 3B C2 cmp rax,rdx 0000000000000028: 0F 82 41 01 00 00 jb 000000000000016F 000000000000002E: 48 89 6C 24 50 mov qword ptr [rsp+50h],rbp 0000000000000033: 48 8B 69 18 mov rbp,qword ptr [rcx+18h] 0000000000000037: 4C 89 7C 24 20 mov qword ptr [rsp+20h],r15 000000000000003C: 4D 8D 3C 16 lea r15,[r14+rdx] 0000000000000040: 49 8B CF mov rcx,r15 0000000000000043: 48 83 C9 0F or rcx,0Fh 0000000000000047: 48 3B CB cmp rcx,rbx 000000000000004A: 77 1F ja 000000000000006B 000000000000004C: 48 8B D5 mov rdx,rbp 000000000000004F: 48 8B C3 mov rax,rbx 0000000000000052: 48 D1 EA shr rdx,1 0000000000000055: 48 2B C2 sub rax,rdx 0000000000000058: 48 3B E8 cmp rbp,rax 000000000000005B: 77 0E ja 000000000000006B 000000000000005D: 48 8D 04 2A lea rax,[rdx+rbp] 0000000000000061: 48 8B D9 mov rbx,rcx 0000000000000064: 48 3B C8 cmp rcx,rax 0000000000000067: 48 0F 42 D8 cmovb rbx,rax 000000000000006B: 48 8D 4B 01 lea rcx,[rbx+1] 000000000000006F: 48 89 7C 24 58 mov qword ptr [rsp+58h],rdi 0000000000000074: 4C 89 64 24 60 mov qword ptr [rsp+60h],r12 0000000000000079: 48 81 F9 00 10 00 cmp rcx,1000h 0000000000000080: 72 2C jb 00000000000000AE 0000000000000082: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000086: 48 3B C1 cmp rax,rcx 0000000000000089: 0F 86 E6 00 00 00 jbe 0000000000000175 000000000000008F: 48 8B C8 mov rcx,rax 0000000000000092: E8 00 00 00 00 call ??2@YAPEAX_K@Z 0000000000000097: 48 85 C0 test rax,rax 000000000000009A: 0F 84 C9 00 00 00 je 0000000000000169 00000000000000A0: 48 8D 78 27 lea rdi,[rax+27h] 00000000000000A4: 48 83 E7 E0 and rdi,0FFFFFFFFFFFFFFE0h 00000000000000A8: 48 89 47 F8 mov qword ptr [rdi-8],rax 00000000000000AC: EB 11 jmp 00000000000000BF 00000000000000AE: 48 85 C9 test rcx,rcx 00000000000000B1: 74 0A je 00000000000000BD 00000000000000B3: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000B8: 48 8B F8 mov rdi,rax 00000000000000BB: EB 02 jmp 00000000000000BF 00000000000000BD: 33 FF xor edi,edi 00000000000000BF: 4C 8B 64 24 70 mov r12,qword ptr [rsp+70h] 00000000000000C4: 4D 8B C6 mov r8,r14 00000000000000C7: 4C 89 7E 10 mov qword ptr [rsi+10h],r15 00000000000000CB: 4E 8D 3C 37 lea r15,[rdi+r14] 00000000000000CF: 48 89 5E 18 mov qword ptr [rsi+18h],rbx 00000000000000D3: 48 8B CF mov rcx,rdi 00000000000000D6: 48 83 FD 10 cmp rbp,10h 00000000000000DA: 72 4D jb 0000000000000129 00000000000000DC: 48 8B 1E mov rbx,qword ptr [rsi] 00000000000000DF: 48 8B D3 mov rdx,rbx 00000000000000E2: E8 00 00 00 00 call memcpy 00000000000000E7: 4D 8B C4 mov r8,r12 00000000000000EA: 49 8B D5 mov rdx,r13 00000000000000ED: 49 8B CF mov rcx,r15 00000000000000F0: E8 00 00 00 00 call memcpy 00000000000000F5: 48 8D 55 01 lea rdx,[rbp+1] 00000000000000F9: 43 C6 04 27 00 mov byte ptr [r15+r12],0 00000000000000FE: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000105: 72 18 jb 000000000000011F 0000000000000107: 48 8B 4B F8 mov rcx,qword ptr [rbx-8] 000000000000010B: 48 83 C2 27 add rdx,27h 000000000000010F: 48 2B D9 sub rbx,rcx 0000000000000112: 48 8D 43 F8 lea rax,[rbx-8] 0000000000000116: 48 83 F8 1F cmp rax,1Fh 000000000000011A: 77 4D ja 0000000000000169 000000000000011C: 48 8B D9 mov rbx,rcx 000000000000011F: 48 8B CB mov rcx,rbx 0000000000000122: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000127: EB 1B jmp 0000000000000144 0000000000000129: 48 8B D6 mov rdx,rsi 000000000000012C: E8 00 00 00 00 call memcpy 0000000000000131: 4D 8B C4 mov r8,r12 0000000000000134: 49 8B D5 mov rdx,r13 0000000000000137: 49 8B CF mov rcx,r15 000000000000013A: E8 00 00 00 00 call memcpy 000000000000013F: 43 C6 04 27 00 mov byte ptr [r15+r12],0 0000000000000144: 48 89 3E mov qword ptr [rsi],rdi 0000000000000147: 48 8B C6 mov rax,rsi 000000000000014A: 4C 8B 64 24 60 mov r12,qword ptr [rsp+60h] 000000000000014F: 48 8B 7C 24 58 mov rdi,qword ptr [rsp+58h] 0000000000000154: 48 8B 6C 24 50 mov rbp,qword ptr [rsp+50h] 0000000000000159: 4C 8B 7C 24 20 mov r15,qword ptr [rsp+20h] 000000000000015E: 48 83 C4 28 add rsp,28h 0000000000000162: 41 5E pop r14 0000000000000164: 41 5D pop r13 0000000000000166: 5E pop rsi 0000000000000167: 5B pop rbx 0000000000000168: C3 ret 0000000000000169: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 000000000000016E: CC int 3 000000000000016F: E8 00 00 00 00 call ?_Xlen@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@CAXXZ 0000000000000174: CC int 3 0000000000000175: E8 00 00 00 00 call ?_Throw_bad_array_new_length@std@@YAXXZ 000000000000017A: CC int 3 000000000000013E: 48 8B 4D EF mov rcx,qword ptr [rbp-11h] 0000000000000142: 48 8B 01 mov rax,qword ptr [rcx] 0000000000000145: 44 8B 45 E7 mov r8d,dword ptr [rbp-19h] 0000000000000149: 48 8D 55 E7 lea rdx,[rbp-19h] 000000000000014D: FF 50 10 call qword ptr [rax+10h] 0000000000000150: 90 nop 0000000000000151: 48 8D 55 E7 lea rdx,[rbp-19h] 0000000000000155: 48 83 7D FF 10 cmp qword ptr [rbp-1],10h 000000000000015A: 48 0F 43 55 E7 cmovae rdx,qword ptr [rbp-19h] 000000000000015F: 4C 8B 45 F7 mov r8,qword ptr [rbp-9] 0000000000000163: 48 8D 4D 07 lea rcx,[rbp+7] 0000000000000000: 48 89 74 24 10 mov qword ptr [rsp+10h],rsi 0000000000000005: 57 push rdi 0000000000000006: 48 83 EC 30 sub rsp,30h 000000000000000A: 48 8B F9 mov rdi,rcx 000000000000000D: 49 8B F0 mov rsi,r8 0000000000000010: 48 8B 49 10 mov rcx,qword ptr [rcx+10h] 0000000000000014: 4C 8B 47 18 mov r8,qword ptr [rdi+18h] 0000000000000018: 49 8B C0 mov rax,r8 000000000000001B: 48 2B C1 sub rax,rcx 000000000000001E: 48 3B F0 cmp rsi,rax 0000000000000021: 77 3F ja 0000000000000062 0000000000000023: 48 89 5C 24 40 mov qword ptr [rsp+40h],rbx 0000000000000028: 48 8D 04 31 lea rax,[rcx+rsi] 000000000000002C: 48 89 47 10 mov qword ptr [rdi+10h],rax 0000000000000030: 48 8B C7 mov rax,rdi 0000000000000033: 49 83 F8 10 cmp r8,10h 0000000000000037: 72 03 jb 000000000000003C 0000000000000039: 48 8B 07 mov rax,qword ptr [rdi] 000000000000003C: 48 8D 1C 08 lea rbx,[rax+rcx] 0000000000000040: 4C 8B C6 mov r8,rsi 0000000000000043: 48 8B CB mov rcx,rbx 0000000000000046: E8 00 00 00 00 call memmove 000000000000004B: C6 04 33 00 mov byte ptr [rbx+rsi],0 000000000000004F: 48 8B C7 mov rax,rdi 0000000000000052: 48 8B 5C 24 40 mov rbx,qword ptr [rsp+40h] 0000000000000057: 48 8B 74 24 48 mov rsi,qword ptr [rsp+48h] 000000000000005C: 48 83 C4 30 add rsp,30h 0000000000000060: 5F pop rdi 0000000000000061: C3 ret 0000000000000062: 4C 8B CA mov r9,rdx 0000000000000065: 48 89 74 24 20 mov qword ptr [rsp+20h],rsi 000000000000006A: 48 8B D6 mov rdx,rsi 000000000000006D: 45 33 C0 xor r8d,r8d 0000000000000070: 48 8B CF mov rcx,rdi 0000000000000073: E8 00 00 00 00 call ??$_Reallocate_grow_by@V<lambda_65e615be2a453ca0576c979606f46740>@@PEBD_K@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAAAEAV01@_KV<lambda_65e615be2a453ca0576c979606f46740>@@PEBD_K@Z 0000000000000078: 48 8B 74 24 48 mov rsi,qword ptr [rsp+48h] 000000000000007D: 48 83 C4 30 add rsp,30h 0000000000000081: 5F pop rdi 0000000000000082: C3 ret 000000000000016C: 90 nop 000000000000016D: 48 8B 55 FF mov rdx,qword ptr [rbp-1] 0000000000000171: 48 83 FA 10 cmp rdx,10h 0000000000000175: 72 31 jb 00000000000001A8 0000000000000177: 48 FF C2 inc rdx 000000000000017A: 48 8B 4D E7 mov rcx,qword ptr [rbp-19h] 000000000000017E: 48 8B C1 mov rax,rcx 0000000000000181: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000188: 72 19 jb 00000000000001A3 000000000000018A: 48 83 C2 27 add rdx,27h 000000000000018E: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 0000000000000192: 48 2B C1 sub rax,rcx 0000000000000195: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000199: 48 83 F8 1F cmp rax,1Fh 000000000000019D: 0F 87 E9 00 00 00 ja 000000000000028C 00000000000001A3: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 00000000000001A8: 0F 10 45 07 movups xmm0,xmmword ptr [rbp+7] 00000000000001AC: 0F 11 45 27 movups xmmword ptr [rbp+27h],xmm0 00000000000001B0: 0F 10 4D 17 movups xmm1,xmmword ptr [rbp+17h] 00000000000001B4: 0F 11 4D 37 movups xmmword ptr [rbp+37h],xmm1 00000000000001B8: 48 C7 45 17 00 00 mov qword ptr [rbp+17h],0 00000000000001C0: 48 C7 45 1F 0F 00 mov qword ptr [rbp+1Fh],0Fh 00000000000001C8: C6 45 07 00 mov byte ptr [rbp+7],0 00000000000001CC: 4C 8D 45 27 lea r8,[rbp+27h] 00000000000001D0: 66 48 0F 7E C1 movq rcx,xmm0 00000000000001D5: 66 0F 73 D9 08 psrldq xmm1,8 00000000000001DA: 66 48 0F 7E C8 movq rax,xmm1 00000000000001DF: 48 83 F8 10 cmp rax,10h 00000000000001E3: 4C 0F 43 C1 cmovae r8,rcx 00000000000001E7: 48 8D 05 00 00 00 lea rax,[??_7exception@std@@6B@] 00000000000001EE: 49 89 06 mov qword ptr [r14],rax 00000000000001F1: 49 8D 56 08 lea rdx,[r14+8] 00000000000001F5: 0F 57 C0 xorps xmm0,xmm0 00000000000001F8: 0F 11 02 movups xmmword ptr [rdx],xmm0 00000000000001FB: 4C 89 45 E7 mov qword ptr [rbp-19h],r8 00000000000001FF: C6 45 EF 01 mov byte ptr [rbp-11h],1 0000000000000203: 48 8D 4D E7 lea rcx,[rbp-19h] 0000000000000207: E8 00 00 00 00 call __std_exception_copy 000000000000020C: 48 8D 05 00 00 00 lea rax,[??_7runtime_error@std@@6B@] 0000000000000213: 49 89 06 mov qword ptr [r14],rax 0000000000000216: 48 8B 55 3F mov rdx,qword ptr [rbp+3Fh] 000000000000021A: 48 83 FA 10 cmp rdx,10h 000000000000021E: 72 2D jb 000000000000024D 0000000000000220: 48 FF C2 inc rdx 0000000000000223: 48 8B 4D 27 mov rcx,qword ptr [rbp+27h] 0000000000000227: 48 8B C1 mov rax,rcx 000000000000022A: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000231: 72 15 jb 0000000000000248 0000000000000233: 48 83 C2 27 add rdx,27h 0000000000000237: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 000000000000023B: 48 2B C1 sub rax,rcx 000000000000023E: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000242: 48 83 F8 1F cmp rax,1Fh 0000000000000246: 77 38 ja 0000000000000280 0000000000000248: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 000000000000024D: 48 8D 05 00 00 00 lea rax,[??_7_System_error@std@@6B@] 0000000000000254: 49 89 06 mov qword ptr [r14],rax 0000000000000257: 41 0F 10 07 movups xmm0,xmmword ptr [r15] 000000000000025B: 41 0F 11 46 18 movups xmmword ptr [r14+18h],xmm0 0000000000000260: 49 8B C6 mov rax,r14 0000000000000263: 4C 8D 9C 24 90 00 lea r11,[rsp+90h] 000000000000026B: 49 8B 5B 20 mov rbx,qword ptr [r11+20h] 000000000000026F: 49 8B 73 28 mov rsi,qword ptr [r11+28h] 0000000000000273: 49 8B 7B 38 mov rdi,qword ptr [r11+38h] 0000000000000277: 49 8B E3 mov rsp,r11 000000000000027A: 41 5F pop r15 000000000000027C: 41 5E pop r14 000000000000027E: 5D pop rbp 000000000000027F: C3 ret 0000000000000280: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 0000000000000285: CC int 3 0000000000000286: E8 00 00 00 00 call ?_Throw_bad_array_new_length@std@@YAXXZ 000000000000028B: 90 nop 000000000000028C: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 0000000000000291: 90 nop 0000000000000056: 90 nop 0000000000000057: 48 8B 54 24 48 mov rdx,qword ptr [rsp+48h] 000000000000005C: 48 83 FA 10 cmp rdx,10h 0000000000000060: 72 2E jb 0000000000000090 0000000000000062: 48 FF C2 inc rdx 0000000000000065: 48 8B 4C 24 30 mov rcx,qword ptr [rsp+30h] 000000000000006A: 48 8B C1 mov rax,rcx 000000000000006D: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000074: 72 15 jb 000000000000008B 0000000000000076: 48 83 C2 27 add rdx,27h 000000000000007A: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 000000000000007E: 48 2B C1 sub rax,rcx 0000000000000081: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000085: 48 83 F8 1F cmp rax,1Fh 0000000000000089: 77 1D ja 00000000000000A8 000000000000008B: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000090: 48 8D 05 00 00 00 lea rax,[??_7system_error@std@@6B@] 0000000000000097: 48 89 07 mov qword ptr [rdi],rax 000000000000009A: 48 8B C7 mov rax,rdi 000000000000009D: 48 8B 5C 24 60 mov rbx,qword ptr [rsp+60h] 00000000000000A2: 48 83 C4 50 add rsp,50h 00000000000000A6: 5F pop rdi 00000000000000A7: C3 ret 00000000000000A8: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 00000000000000AD: CC int 3 000000000000001B: 48 8D 15 00 00 00 lea rdx,[_TI4?AVsystem_error@std@@] 0000000000000022: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000027: E8 00 00 00 00 call _CxxThrowException 000000000000002C: CC int 3 000000000000007F: CC int 3
0
repos/outcome/test
repos/outcome/test/constexprs/WG21_P1886a.clang.S.test1.s
400730: 41 56 push %r14 400732: 53 push %rbx 400733: 48 83 ec 18 sub $0x18,%rsp 400737: 48 89 fb mov %rdi,%rbx 40073a: 48 89 e7 mov %rsp,%rdi 400710: 53 push %rbx 400711: 48 89 fb mov %rdi,%rbx 4005b0: ff 25 62 0a 20 00 jmpq *0x200a62(%rip) # 601018 <std::_V2::generic_category()@GLIBCXX_3.4.21> 4005b6: 68 00 00 00 00 pushq $0x0 4005bb: e9 e0 ff ff ff jmpq 4005a0 <.plt> 400719: 48 b9 12 00 00 00 21 movabs $0x2100000012,%rcx 400723: 48 89 4b 04 mov %rcx,0x4(%rbx) 400727: 48 89 43 10 mov %rax,0x10(%rbx) 40072b: 48 89 d8 mov %rbx,%rax 40072e: 5b pop %rbx 40072f: c3 retq 400742: 0f b7 44 24 04 movzwl 0x4(%rsp),%eax 400747: a8 01 test $0x1,%al 400749: 74 33 je 40077e <test1()+0x4e> 40074b: c7 05 03 09 20 00 00 movl $0x0,0x200903(%rip) # 601058 <foo> 400755: 8b 04 24 mov (%rsp),%eax 400758: 89 03 mov %eax,(%rbx) 40075a: 48 c7 43 04 01 00 00 movq $0x1,0x4(%rbx) 4005c0: ff 25 5a 0a 20 00 jmpq *0x200a5a(%rip) # 601020 <std::_V2::system_category()@GLIBCXX_3.4.21> 4005c6: 68 01 00 00 00 pushq $0x1 4005cb: e9 d0 ff ff ff jmpq 4005a0 <.plt> 400767: 48 89 43 10 mov %rax,0x10(%rbx) 40076b: 48 89 e7 mov %rsp,%rdi 4007f0: c3 retq 4007f1: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 4007fb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 400773: 48 89 d8 mov %rbx,%rax 400776: 48 83 c4 18 add $0x18,%rsp 40077a: 5b pop %rbx 40077b: 41 5e pop %r14 40077d: c3 retq 40077e: 8b 44 24 08 mov 0x8(%rsp),%eax 400782: 4c 8b 74 24 10 mov 0x10(%rsp),%r14 400787: c7 43 04 02 00 00 00 movl $0x2,0x4(%rbx) 40078e: 89 43 08 mov %eax,0x8(%rbx) 400791: 4c 89 73 10 mov %r14,0x10(%rbx) 4005b0: ff 25 62 0a 20 00 jmpq *0x200a62(%rip) # 601018 <std::_V2::generic_category()@GLIBCXX_3.4.21> 4005b6: 68 00 00 00 00 pushq $0x0 4005bb: e9 e0 ff ff ff jmpq 4005a0 <.plt> 40079a: 49 39 c6 cmp %rax,%r14 40079d: 74 0a je 4007a9 <test1()+0x79> 4005c0: ff 25 5a 0a 20 00 jmpq *0x200a5a(%rip) # 601020 <std::_V2::system_category()@GLIBCXX_3.4.21> 4005c6: 68 01 00 00 00 pushq $0x1 4005cb: e9 d0 ff ff ff jmpq 4005a0 <.plt> 4007a4: 49 39 c6 cmp %rax,%r14 4007a7: 75 c2 jne 40076b <test1()+0x3b> 4007a9: 66 c7 43 04 12 00 movw $0x12,0x4(%rbx) 4007af: eb ba jmp 40076b <test1()+0x3b> 4007b1: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 4007bb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
0
repos/outcome/test
repos/outcome/test/constexprs/count_opcodes.py
#!/usr/bin/python3 # Parse x64 assembler dumps and figure out how many opcodes something takes # # File created: (C) 2015 Niall Douglas http://www.nedprod.com/ # File created: June 2015 # File edited by Tom Westerhout in May 2017 import sys, os, re debug = False # if len(sys.argv) < 2: # print('Usage: ' + sys.argv[0] + ' <assembler file containing test1()>', # file=sys.stderr) # sys.exit(1) # input_file = sys.argv[1] # objdump format example: # 0000000000000000 <_Z5test1v>: # 0: 55 push %rbp # 1: 48 89 e5 mov %rsp,%rbp # 4: be 00 00 00 00 mov $0x0,%esi # 9: bf 00 00 00 00 mov $0x0,%edi # e: e8 00 00 00 00 callq 13 <_Z5test1v+0x13> # 13: be 0a 00 00 00 mov $0xa,%esi # 18: 48 89 c7 mov %rax,%rdi # 1b: e8 00 00 00 00 callq 20 <_Z5test1v+0x20> # 20: 90 nop # 21: 5d pop %rbp # 22: c3 retq def get_call_target_objdump(l): r = re.match(r".*callq\s+[0-9a-f]+\s+<(.+)>$", l) if r: return r.group(1) return None _is_new_function_ = \ { # ---> 4 zeros in the begining # ---> then some unknown number of lower case HEX numbers # ---> a space # ---> function name enclosed in <> # ---> colon : 'objdump' : lambda l: re.match(r"^0{4}[0-9a-f]+ <.+>:$", l) is not None # ---> line starts with a non-space character # ---> something # ---> line ends with a colon : , 'dumpbin' : lambda l: re.match(r"^[^ ].*:$", l) is not None } _get_function_name_ = \ { 'objdump' : lambda l: re.match(r"^0{4}[0-9a-f]+ <(.+)>:$", l).group(1) , 'dumpbin' : lambda l: re.match(r"^([^ ]+).*:$", l).group(1) } _is_instruction_ = \ { # ---> at least 1 space # ---> address, i.e. some HEX numbers # ---> colon : # ---> more HEX numbers and spaces # ---> asm instruction, i.e. a word of latin characters # ---> arguments 'objdump' : lambda l: re.match(r"^[ ]{1,}[0-9a-f]+:\s*[0-9a-f ]+\s+[a-z]+.*$", l) \ is not None # the same, except that the line starts with exactly two spaces , 'dumpbin' : lambda l: re.match(r"^[ ]{2,}[0-9A-F]+:[0-9A-F ]+[a-z]+.*$", l) \ is not None } _is_normal_instruction_ = \ { 'objdump' : lambda l: _is_instruction_['objdump'](l) and 'retq' not in l and 'nop' not in l , 'dumpbin' : lambda l: _is_instruction_['dumpbin'](l) and 'ret' not in l and 'nop' not in l } _is_call_instruction_ = \ { 'objdump' : lambda l: "callq" in l , 'dumpbin' : lambda l: "call" in l } _get_call_target_ = \ { 'objdump' : get_call_target_objdump , 'dumpbin' : lambda l: re.match(r".*call\s+(.+)$", l).group(1) } _is_our_function_ = \ { 'objdump' : lambda f: lambda l: (f in l) and ('-0x' not in l) , 'dumpbin' : lambda f: lambda l: (f in l) and ('?dtor' not in l) } def parse(input_file : str, file_type : str) -> dict: functions = {} f = None ops = [] def save(): nonlocal f nonlocal ops if f is not None: debug and print("[*] Storing function " + str(f) + " with " + str(len(ops)) + " lines", file=sys.stderr) functions[f] = ops f = None ops = [] def append(l : str): nonlocal ops if f is not None: ops.append(l) def skip(): pass is_func = _is_new_function_[file_type] is_op = _is_instruction_[file_type] get_name = _get_function_name_[file_type] for i, line in filter( lambda t: len(t[1]) > 0, map( lambda t: (t[0], t[1].rstrip()), enumerate(input_file, start=1) )): debug and print("[*] Line " + str(i) + " is '" + line + "'", file=sys.stderr) if is_func(line): save() f = get_name(line) debug and print("[*] Line " + str(i) + ": new objdump function: " + f, file=sys.stderr) elif is_op(line): if f is not None: append(line) else: skip() else: skip() save() return functions def find_opcodes(name : str, functions : dict, file_type : str) -> tuple: is_match = _is_our_function_[file_type](name) all_matches = list(filter(lambda t: is_match(t[0]), functions.items())) if len(all_matches) == 0: return name, None if len(all_matches) > 1: print("[*] Matching functions: ", list(map(lambda t: t[0], all_matches)), file=sys.stderr) assert len(all_matches) == 1 return all_matches[0] def _inline_all_impl_(operation : str, functions : dict, black_list : set, is_a_call, get_target, allow_recursion : bool): if not is_a_call(operation): debug and print("[*] '" + operation + "' is not a call operation.", file=sys.stderr) return [operation] debug and print("[*] '" + operation + "'...", file=sys.stderr) target = get_target(operation) debug and print("[*] Expanding " + repr(target) + "...", file=sys.stderr) if (not allow_recursion) and (target in black_list): debug and print("[*] '" + target + "' in black list.", file=sys.stderr) return [operation] if (target not in functions): print("[*] No info on " + repr(target) + ".", file=sys.stderr) return [operation] black_list.add(target) opcodes = functions[target] return sum(map(lambda op: _inline_all_impl_(op, functions, black_list, is_a_call, get_target, allow_recursion), opcodes), []) def inline_all(name : str, functions : dict, file_type : str, allow_recursion : bool = False): is_a_call = _is_call_instruction_[file_type] get_target = _get_call_target_[file_type] debug and print("Initially: ", functions[name], file=sys.stderr) return sum(map(lambda op: _inline_all_impl_(op, functions, {name}, is_a_call, get_target, allow_recursion), functions[name]), []) def count_opcodes(output_file_name : str, input_file : str, func : str): functions = {} file_type = 'objdump' if os.name == 'posix' else 'dumpbin' # Read all the functions with open(input_file, "rt") as ih: functions = parse(ih, file_type) # Find the one we're interested in name, opcodes = find_opcodes(func, functions, file_type) if opcodes is None: return -1, None # Inline as much as possible opcodes = inline_all(name, functions, file_type, False) # Save results output_file = input_file + '.' + output_file_name + '.s' try: os.remove(output_file) except: pass with open(output_file, "wt") as oh: oh.write('\n'.join(opcodes) + '\n') # Calculate number of operations is_normal = _is_normal_instruction_[file_type] count = sum(map(is_normal, opcodes)) return count, opcodes
0
repos/outcome/test
repos/outcome/test/constexprs/WG21_P1886a.gcc.S.test1.s
880: 41 54 push %r12 882: 49 89 fc mov %rdi,%r12 885: 53 push %rbx 886: 48 83 ec 28 sub $0x28,%rsp 88a: 48 89 e7 mov %rsp,%rdi 850: 41 54 push %r12 852: 49 89 fc mov %rdi,%r12 6c0: ff 25 ea 08 20 00 jmpq *0x2008ea(%rip) # 200fb0 <std::_V2::generic_category()@GLIBCXX_3.4.21> 6c6: 68 00 00 00 00 pushq $0x0 6cb: e9 e0 ff ff ff jmpq 6b0 <.plt> 85a: 49 89 44 24 10 mov %rax,0x10(%r12) 85f: 48 b8 12 00 00 00 21 movabs $0x2100000012,%rax 869: 49 89 44 24 04 mov %rax,0x4(%r12) 86e: 4c 89 e0 mov %r12,%rax 871: 41 5c pop %r12 873: c3 retq 874: 66 90 xchg %ax,%ax 876: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 892: f6 44 24 04 01 testb $0x1,0x4(%rsp) 897: 74 3f je 8d8 <test1()+0x58> 899: 41 c7 44 24 04 01 00 movl $0x1,0x4(%r12) 8a2: 8b 04 24 mov (%rsp),%eax 8a5: 41 c7 44 24 08 00 00 movl $0x0,0x8(%r12) 8ae: 41 89 04 24 mov %eax,(%r12) 8b2: c7 05 58 07 20 00 00 movl $0x0,0x200758(%rip) # 201014 <foo> 6d0: ff 25 e2 08 20 00 jmpq *0x2008e2(%rip) # 200fb8 <std::_V2::system_category()@GLIBCXX_3.4.21> 6d6: 68 01 00 00 00 pushq $0x1 6db: e9 d0 ff ff ff jmpq 6b0 <.plt> 8c1: 49 89 44 24 10 mov %rax,0x10(%r12) 8c6: 48 83 c4 28 add $0x28,%rsp 8ca: 4c 89 e0 mov %r12,%rax 8cd: 5b pop %rbx 8ce: 41 5c pop %r12 8d0: c3 retq 8d1: 0f 1f 80 00 00 00 00 nopl 0x0(%rax) 8d8: 48 8b 5c 24 10 mov 0x10(%rsp),%rbx 8dd: 8b 44 24 08 mov 0x8(%rsp),%eax 8e1: 41 c7 44 24 04 02 00 movl $0x2,0x4(%r12) 8ea: 41 89 44 24 08 mov %eax,0x8(%r12) 8ef: 49 89 5c 24 10 mov %rbx,0x10(%r12) 6c0: ff 25 ea 08 20 00 jmpq *0x2008ea(%rip) # 200fb0 <std::_V2::generic_category()@GLIBCXX_3.4.21> 6c6: 68 00 00 00 00 pushq $0x0 6cb: e9 e0 ff ff ff jmpq 6b0 <.plt> 8f9: 48 39 c3 cmp %rax,%rbx 8fc: 74 0a je 908 <test1()+0x88> 6d0: ff 25 e2 08 20 00 jmpq *0x2008e2(%rip) # 200fb8 <std::_V2::system_category()@GLIBCXX_3.4.21> 6d6: 68 01 00 00 00 pushq $0x1 6db: e9 d0 ff ff ff jmpq 6b0 <.plt> 903: 48 39 c3 cmp %rax,%rbx 906: 75 be jne 8c6 <test1()+0x46> 908: b8 12 00 00 00 mov $0x12,%eax 90d: 66 41 89 44 24 04 mov %ax,0x4(%r12) 913: eb b1 jmp 8c6 <test1()+0x46> 915: 90 nop 916: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
0
repos/outcome/test
repos/outcome/test/constexprs/min_result_construct_value_move_destruct.clang.S.test1.s
400630: b8 05 00 00 00 mov $0x5,%eax 400635: c3 retq 400636: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
0
repos/outcome/test
repos/outcome/test/constexprs/max_result_construct_value_move_destruct.cpp
/* Canned codegen quality test sequences (C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../../single-header/outcome.hpp" #ifdef __GNUC__ #define WEAK __attribute__((weak)) #else #define WEAK #endif using namespace OUTCOME_V2_NAMESPACE; extern result<int> unknown() WEAK; extern QUICKCPPLIB_NOINLINE int test1() { using namespace OUTCOME_V2_NAMESPACE; result<int> m1(unknown()); result<int> m2(std::move(m1)); return std::move(m2).value(); } extern QUICKCPPLIB_NOINLINE void test2() { } int main(void) { int ret=0; if(5!=test1()) ret=1; test2(); return ret; }
0
repos/outcome/test
repos/outcome/test/constexprs/max_result_get_value.msvc.S.test1.s
0000000000000000: 48 83 EC 58 sub rsp,58h 0000000000000004: 48 8D 4C 24 38 lea rcx,[rsp+38h] 0000000000000009: E8 00 00 00 00 call ?unknown@@YA?AV?$basic_result@HVerror_code@std@@U?$error_code_throw_as_system_error@HVerror_code@std@@X@policy@outcome_v2_3f877000@@@outcome_v2_3f877000@@XZ 000000000000000E: F6 40 04 01 test byte ptr [rax+4],1 0000000000000012: 75 0D jne 0000000000000021 0000000000000014: 0F B6 48 04 movzx ecx,byte ptr [rax+4] 0000000000000018: D0 E9 shr cl,1 000000000000001A: F6 C1 01 test cl,1 000000000000001D: 75 2C jne 000000000000004B 000000000000001F: EB 07 jmp 0000000000000028 0000000000000021: 8B 00 mov eax,dword ptr [rax] 0000000000000023: 48 83 C4 58 add rsp,58h 0000000000000027: C3 ret 0000000000000028: 48 8D 15 00 00 00 lea rdx,[??_C@_08JEIPHCP@no?5value@] 000000000000002F: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000000: 40 53 push rbx 0000000000000002: 48 83 EC 30 sub rsp,30h 0000000000000006: 48 8B D9 mov rbx,rcx 0000000000000009: C6 44 24 28 01 mov byte ptr [rsp+28h],1 000000000000000E: 48 8B C2 mov rax,rdx 0000000000000011: 48 8D 0D 00 00 00 lea rcx,[??_7exception@std@@6B@] 0000000000000018: 48 8D 53 08 lea rdx,[rbx+8] 000000000000001C: 48 89 44 24 20 mov qword ptr [rsp+20h],rax 0000000000000021: 0F 57 C0 xorps xmm0,xmm0 0000000000000024: 48 89 0B mov qword ptr [rbx],rcx 0000000000000027: 48 8D 4C 24 20 lea rcx,[rsp+20h] 000000000000002C: 0F 11 02 movups xmmword ptr [rdx],xmm0 000000000000002F: E8 00 00 00 00 call __std_exception_copy 0000000000000034: 48 8D 05 00 00 00 lea rax,[??_7bad_result_access@outcome_v2_3f877000@@6B@] 000000000000003B: 48 89 03 mov qword ptr [rbx],rax 000000000000003E: 48 8B C3 mov rax,rbx 0000000000000041: 48 83 C4 30 add rsp,30h 0000000000000045: 5B pop rbx 0000000000000046: C3 ret 0000000000000039: 48 8D 15 00 00 00 lea rdx,[_TI3?AVbad_result_access@outcome_v2_3f877000@@] 0000000000000040: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000045: E8 00 00 00 00 call _CxxThrowException 000000000000004A: CC int 3 000000000000004B: 48 8B C8 mov rcx,rax 0000000000000000: 48 8B C1 mov rax,rcx 0000000000000003: C3 ret 0000000000000053: 48 8B C8 mov rcx,rax 0000000000000000: 48 8D 41 08 lea rax,[rcx+8] 0000000000000004: C3 ret 000000000000005B: 48 8B C8 mov rcx,rax 0000000000000000: 48 83 EC 68 sub rsp,68h 0000000000000004: 0F 10 01 movups xmm0,xmmword ptr [rcx] 0000000000000007: 48 8D 54 24 20 lea rdx,[rsp+20h] 000000000000000C: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000011: 0F 29 44 24 20 movaps xmmword ptr [rsp+20h],xmm0 0000000000000000: 48 89 5C 24 08 mov qword ptr [rsp+8],rbx 0000000000000005: 57 push rdi 0000000000000006: 48 83 EC 50 sub rsp,50h 000000000000000A: 48 8B DA mov rbx,rdx 000000000000000D: 48 8B F9 mov rdi,rcx 0000000000000010: 48 C7 44 24 40 00 mov qword ptr [rsp+40h],0 0000000000000019: 48 C7 44 24 48 0F mov qword ptr [rsp+48h],0Fh 0000000000000022: C6 44 24 30 00 mov byte ptr [rsp+30h],0 0000000000000027: 45 33 C0 xor r8d,r8d 000000000000002A: 48 8D 15 00 00 00 lea rdx,[??_C@_00CNPNBAHC@@] 0000000000000031: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000000: 48 89 5C 24 10 mov qword ptr [rsp+10h],rbx 0000000000000005: 48 89 6C 24 18 mov qword ptr [rsp+18h],rbp 000000000000000A: 56 push rsi 000000000000000B: 57 push rdi 000000000000000C: 41 57 push r15 000000000000000E: 48 83 EC 20 sub rsp,20h 0000000000000012: 48 8B 69 18 mov rbp,qword ptr [rcx+18h] 0000000000000016: 49 8B F0 mov rsi,r8 0000000000000019: 4C 8B FA mov r15,rdx 000000000000001C: 48 8B D9 mov rbx,rcx 000000000000001F: 4C 3B C5 cmp r8,rbp 0000000000000022: 77 21 ja 0000000000000045 0000000000000024: 48 8B F9 mov rdi,rcx 0000000000000027: 48 83 FD 10 cmp rbp,10h 000000000000002B: 72 03 jb 0000000000000030 000000000000002D: 48 8B 39 mov rdi,qword ptr [rcx] 0000000000000030: 48 89 71 10 mov qword ptr [rcx+10h],rsi 0000000000000034: 48 8B CF mov rcx,rdi 0000000000000037: E8 00 00 00 00 call memmove 000000000000003C: C6 04 37 00 mov byte ptr [rdi+rsi],0 0000000000000040: E9 E4 00 00 00 jmp 0000000000000129 0000000000000045: 48 BF FF FF FF FF mov rdi,7FFFFFFFFFFFFFFFh 000000000000004F: 48 3B F7 cmp rsi,rdi 0000000000000052: 0F 87 F3 00 00 00 ja 000000000000014B 0000000000000058: 48 8B CE mov rcx,rsi 000000000000005B: 48 83 C9 0F or rcx,0Fh 000000000000005F: 48 3B CF cmp rcx,rdi 0000000000000062: 77 1F ja 0000000000000083 0000000000000064: 48 8B D5 mov rdx,rbp 0000000000000067: 48 8B C7 mov rax,rdi 000000000000006A: 48 D1 EA shr rdx,1 000000000000006D: 48 2B C2 sub rax,rdx 0000000000000070: 48 3B E8 cmp rbp,rax 0000000000000073: 77 0E ja 0000000000000083 0000000000000075: 48 8D 04 2A lea rax,[rdx+rbp] 0000000000000079: 48 8B F9 mov rdi,rcx 000000000000007C: 48 3B C8 cmp rcx,rax 000000000000007F: 48 0F 42 F8 cmovb rdi,rax 0000000000000083: 48 8D 4F 01 lea rcx,[rdi+1] 0000000000000087: 4C 89 74 24 40 mov qword ptr [rsp+40h],r14 000000000000008C: 48 81 F9 00 10 00 cmp rcx,1000h 0000000000000093: 72 2C jb 00000000000000C1 0000000000000095: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000099: 48 3B C1 cmp rax,rcx 000000000000009C: 0F 86 9D 00 00 00 jbe 000000000000013F 00000000000000A2: 48 8B C8 mov rcx,rax 00000000000000A5: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000AA: 48 85 C0 test rax,rax 00000000000000AD: 0F 84 92 00 00 00 je 0000000000000145 00000000000000B3: 4C 8D 70 27 lea r14,[rax+27h] 00000000000000B7: 49 83 E6 E0 and r14,0FFFFFFFFFFFFFFE0h 00000000000000BB: 49 89 46 F8 mov qword ptr [r14-8],rax 00000000000000BF: EB 12 jmp 00000000000000D3 00000000000000C1: 48 85 C9 test rcx,rcx 00000000000000C4: 74 0A je 00000000000000D0 00000000000000C6: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000CB: 4C 8B F0 mov r14,rax 00000000000000CE: EB 03 jmp 00000000000000D3 00000000000000D0: 45 33 F6 xor r14d,r14d 00000000000000D3: 4C 8B C6 mov r8,rsi 00000000000000D6: 48 89 73 10 mov qword ptr [rbx+10h],rsi 00000000000000DA: 49 8B D7 mov rdx,r15 00000000000000DD: 48 89 7B 18 mov qword ptr [rbx+18h],rdi 00000000000000E1: 49 8B CE mov rcx,r14 00000000000000E4: E8 00 00 00 00 call memcpy 00000000000000E9: 41 C6 04 36 00 mov byte ptr [r14+rsi],0 00000000000000EE: 48 83 FD 10 cmp rbp,10h 00000000000000F2: 72 2D jb 0000000000000121 00000000000000F4: 48 8B 0B mov rcx,qword ptr [rbx] 00000000000000F7: 48 8D 55 01 lea rdx,[rbp+1] 00000000000000FB: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000102: 72 18 jb 000000000000011C 0000000000000104: 4C 8B 41 F8 mov r8,qword ptr [rcx-8] 0000000000000108: 48 83 C2 27 add rdx,27h 000000000000010C: 49 2B C8 sub rcx,r8 000000000000010F: 48 8D 41 F8 lea rax,[rcx-8] 0000000000000113: 48 83 F8 1F cmp rax,1Fh 0000000000000117: 77 2C ja 0000000000000145 0000000000000119: 49 8B C8 mov rcx,r8 000000000000011C: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000121: 4C 89 33 mov qword ptr [rbx],r14 0000000000000124: 4C 8B 74 24 40 mov r14,qword ptr [rsp+40h] 0000000000000129: 48 8B 6C 24 50 mov rbp,qword ptr [rsp+50h] 000000000000012E: 48 8B C3 mov rax,rbx 0000000000000131: 48 8B 5C 24 48 mov rbx,qword ptr [rsp+48h] 0000000000000136: 48 83 C4 20 add rsp,20h 000000000000013A: 41 5F pop r15 000000000000013C: 5F pop rdi 000000000000013D: 5E pop rsi 000000000000013E: C3 ret 0000000000000000: 48 83 EC 48 sub rsp,48h 0000000000000004: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000000: 48 8D 05 00 00 00 lea rax,[??_C@_0BF@KINCDENJ@bad?5array?5new?5length@] 0000000000000007: 48 C7 41 10 00 00 mov qword ptr [rcx+10h],0 000000000000000F: 48 89 41 08 mov qword ptr [rcx+8],rax 0000000000000013: 48 8D 05 00 00 00 lea rax,[??_7bad_array_new_length@std@@6B@] 000000000000001A: 48 89 01 mov qword ptr [rcx],rax 000000000000001D: 48 8B C1 mov rax,rcx 0000000000000020: C3 ret 000000000000000E: 48 8D 15 00 00 00 lea rdx,[_TI3?AVbad_array_new_length@std@@] 0000000000000015: 48 8D 4C 24 20 lea rcx,[rsp+20h] 000000000000001A: E8 00 00 00 00 call _CxxThrowException 000000000000001F: CC int 3 0000000000000144: CC int 3 0000000000000145: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 000000000000014A: CC int 3 0000000000000000: 48 83 EC 28 sub rsp,28h 0000000000000004: 48 8D 0D 00 00 00 lea rcx,[??_C@_0BA@JFNIOLAK@string?5too?5long@] 000000000000000B: E8 00 00 00 00 call ?_Xlength_error@std@@YAXPEBD@Z 0000000000000010: CC int 3 0000000000000150: CC int 3 000000000000003B: 90 nop 000000000000003C: 0F 10 03 movups xmm0,xmmword ptr [rbx] 000000000000003F: 0F 29 44 24 20 movaps xmmword ptr [rsp+20h],xmm0 0000000000000044: 4C 8D 44 24 30 lea r8,[rsp+30h] 0000000000000049: 48 8D 54 24 20 lea rdx,[rsp+20h] 000000000000004E: 48 8B CF mov rcx,rdi 0000000000000000: 48 89 5C 24 08 mov qword ptr [rsp+8],rbx 0000000000000005: 48 89 74 24 10 mov qword ptr [rsp+10h],rsi 000000000000000A: 48 89 7C 24 20 mov qword ptr [rsp+20h],rdi 000000000000000F: 55 push rbp 0000000000000010: 41 56 push r14 0000000000000012: 41 57 push r15 0000000000000014: 48 8D 6C 24 B9 lea rbp,[rsp-47h] 0000000000000019: 48 81 EC 90 00 00 sub rsp,90h 0000000000000020: 49 8B F0 mov rsi,r8 0000000000000023: 4C 8B FA mov r15,rdx 0000000000000026: 4C 8B F1 mov r14,rcx 0000000000000029: 48 C7 45 17 00 00 mov qword ptr [rbp+17h],0 0000000000000031: 48 C7 45 1F 00 00 mov qword ptr [rbp+1Fh],0 0000000000000039: 49 8B 78 10 mov rdi,qword ptr [r8+10h] 000000000000003D: 49 83 78 18 10 cmp qword ptr [r8+18h],10h 0000000000000042: 72 03 jb 0000000000000047 0000000000000044: 49 8B 30 mov rsi,qword ptr [r8] 0000000000000047: 48 83 FF 10 cmp rdi,10h 000000000000004B: 73 0E jae 000000000000005B 000000000000004D: 0F 10 06 movups xmm0,xmmword ptr [rsi] 0000000000000050: 0F 11 45 07 movups xmmword ptr [rbp+7],xmm0 0000000000000054: BB 0F 00 00 00 mov ebx,0Fh 0000000000000059: EB 75 jmp 00000000000000D0 000000000000005B: 48 8B DF mov rbx,rdi 000000000000005E: 48 83 CB 0F or rbx,0Fh 0000000000000062: 48 B8 FF FF FF FF mov rax,7FFFFFFFFFFFFFFFh 000000000000006C: 48 3B D8 cmp rbx,rax 000000000000006F: 48 0F 47 D8 cmova rbx,rax 0000000000000073: 48 8D 4B 01 lea rcx,[rbx+1] 0000000000000077: 48 81 F9 00 10 00 cmp rcx,1000h 000000000000007E: 72 2F jb 00000000000000AF 0000000000000080: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000084: 48 3B C1 cmp rax,rcx 0000000000000087: 0F 86 F9 01 00 00 jbe 0000000000000286 000000000000008D: 48 8B C8 mov rcx,rax 0000000000000090: E8 00 00 00 00 call ??2@YAPEAX_K@Z 0000000000000095: 48 8B C8 mov rcx,rax 0000000000000098: 48 85 C0 test rax,rax 000000000000009B: 0F 84 DF 01 00 00 je 0000000000000280 00000000000000A1: 48 83 C0 27 add rax,27h 00000000000000A5: 48 83 E0 E0 and rax,0FFFFFFFFFFFFFFE0h 00000000000000A9: 48 89 48 F8 mov qword ptr [rax-8],rcx 00000000000000AD: EB 0E jmp 00000000000000BD 00000000000000AF: 48 85 C9 test rcx,rcx 00000000000000B2: 74 07 je 00000000000000BB 00000000000000B4: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000B9: EB 02 jmp 00000000000000BD 00000000000000BB: 33 C0 xor eax,eax 00000000000000BD: 48 89 45 07 mov qword ptr [rbp+7],rax 00000000000000C1: 4C 8D 47 01 lea r8,[rdi+1] 00000000000000C5: 48 8B D6 mov rdx,rsi 00000000000000C8: 48 8B C8 mov rcx,rax 00000000000000CB: E8 00 00 00 00 call memcpy 00000000000000D0: 48 89 7D 17 mov qword ptr [rbp+17h],rdi 00000000000000D4: 48 89 5D 1F mov qword ptr [rbp+1Fh],rbx 00000000000000D8: 48 8D 45 07 lea rax,[rbp+7] 00000000000000DC: 48 89 45 77 mov qword ptr [rbp+77h],rax 00000000000000E0: 41 0F 10 07 movups xmm0,xmmword ptr [r15] 00000000000000E4: 0F 29 45 E7 movaps xmmword ptr [rbp-19h],xmm0 00000000000000E8: 48 85 FF test rdi,rdi 00000000000000EB: 74 51 je 000000000000013E 00000000000000ED: 48 8B C3 mov rax,rbx 00000000000000F0: 48 2B C7 sub rax,rdi 00000000000000F3: 48 83 F8 02 cmp rax,2 00000000000000F7: 72 25 jb 000000000000011E 00000000000000F9: 48 8D 47 02 lea rax,[rdi+2] 00000000000000FD: 48 89 45 17 mov qword ptr [rbp+17h],rax 0000000000000101: 48 8D 45 07 lea rax,[rbp+7] 0000000000000105: 48 83 FB 10 cmp rbx,10h 0000000000000109: 48 0F 43 45 07 cmovae rax,qword ptr [rbp+7] 000000000000010E: B9 3A 20 00 00 mov ecx,203Ah 0000000000000113: 66 89 0C 38 mov word ptr [rax+rdi],cx 0000000000000117: C6 44 38 02 00 mov byte ptr [rax+rdi+2],0 000000000000011C: EB 20 jmp 000000000000013E 000000000000011E: 48 C7 44 24 20 02 mov qword ptr [rsp+20h],2 0000000000000127: 4C 8D 0D 00 00 00 lea r9,[??_C@_02LMMGGCAJ@?3?5@] 000000000000012E: 45 33 C0 xor r8d,r8d 0000000000000131: 41 8D 50 02 lea edx,[r8+2] 0000000000000135: 48 8D 4D 07 lea rcx,[rbp+7] 0000000000000000: 40 53 push rbx 0000000000000002: 56 push rsi 0000000000000003: 41 55 push r13 0000000000000005: 41 56 push r14 0000000000000007: 48 83 EC 28 sub rsp,28h 000000000000000B: 4C 8B 71 10 mov r14,qword ptr [rcx+10h] 000000000000000F: 48 BB FF FF FF FF mov rbx,7FFFFFFFFFFFFFFFh 0000000000000019: 48 8B C3 mov rax,rbx 000000000000001C: 4D 8B E9 mov r13,r9 000000000000001F: 49 2B C6 sub rax,r14 0000000000000022: 48 8B F1 mov rsi,rcx 0000000000000025: 48 3B C2 cmp rax,rdx 0000000000000028: 0F 82 41 01 00 00 jb 000000000000016F 000000000000002E: 48 89 6C 24 50 mov qword ptr [rsp+50h],rbp 0000000000000033: 48 8B 69 18 mov rbp,qword ptr [rcx+18h] 0000000000000037: 4C 89 7C 24 20 mov qword ptr [rsp+20h],r15 000000000000003C: 4D 8D 3C 16 lea r15,[r14+rdx] 0000000000000040: 49 8B CF mov rcx,r15 0000000000000043: 48 83 C9 0F or rcx,0Fh 0000000000000047: 48 3B CB cmp rcx,rbx 000000000000004A: 77 1F ja 000000000000006B 000000000000004C: 48 8B D5 mov rdx,rbp 000000000000004F: 48 8B C3 mov rax,rbx 0000000000000052: 48 D1 EA shr rdx,1 0000000000000055: 48 2B C2 sub rax,rdx 0000000000000058: 48 3B E8 cmp rbp,rax 000000000000005B: 77 0E ja 000000000000006B 000000000000005D: 48 8D 04 2A lea rax,[rdx+rbp] 0000000000000061: 48 8B D9 mov rbx,rcx 0000000000000064: 48 3B C8 cmp rcx,rax 0000000000000067: 48 0F 42 D8 cmovb rbx,rax 000000000000006B: 48 8D 4B 01 lea rcx,[rbx+1] 000000000000006F: 48 89 7C 24 58 mov qword ptr [rsp+58h],rdi 0000000000000074: 4C 89 64 24 60 mov qword ptr [rsp+60h],r12 0000000000000079: 48 81 F9 00 10 00 cmp rcx,1000h 0000000000000080: 72 2C jb 00000000000000AE 0000000000000082: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000086: 48 3B C1 cmp rax,rcx 0000000000000089: 0F 86 E6 00 00 00 jbe 0000000000000175 000000000000008F: 48 8B C8 mov rcx,rax 0000000000000092: E8 00 00 00 00 call ??2@YAPEAX_K@Z 0000000000000097: 48 85 C0 test rax,rax 000000000000009A: 0F 84 C9 00 00 00 je 0000000000000169 00000000000000A0: 48 8D 78 27 lea rdi,[rax+27h] 00000000000000A4: 48 83 E7 E0 and rdi,0FFFFFFFFFFFFFFE0h 00000000000000A8: 48 89 47 F8 mov qword ptr [rdi-8],rax 00000000000000AC: EB 11 jmp 00000000000000BF 00000000000000AE: 48 85 C9 test rcx,rcx 00000000000000B1: 74 0A je 00000000000000BD 00000000000000B3: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000B8: 48 8B F8 mov rdi,rax 00000000000000BB: EB 02 jmp 00000000000000BF 00000000000000BD: 33 FF xor edi,edi 00000000000000BF: 4C 8B 64 24 70 mov r12,qword ptr [rsp+70h] 00000000000000C4: 4D 8B C6 mov r8,r14 00000000000000C7: 4C 89 7E 10 mov qword ptr [rsi+10h],r15 00000000000000CB: 4E 8D 3C 37 lea r15,[rdi+r14] 00000000000000CF: 48 89 5E 18 mov qword ptr [rsi+18h],rbx 00000000000000D3: 48 8B CF mov rcx,rdi 00000000000000D6: 48 83 FD 10 cmp rbp,10h 00000000000000DA: 72 4D jb 0000000000000129 00000000000000DC: 48 8B 1E mov rbx,qword ptr [rsi] 00000000000000DF: 48 8B D3 mov rdx,rbx 00000000000000E2: E8 00 00 00 00 call memcpy 00000000000000E7: 4D 8B C4 mov r8,r12 00000000000000EA: 49 8B D5 mov rdx,r13 00000000000000ED: 49 8B CF mov rcx,r15 00000000000000F0: E8 00 00 00 00 call memcpy 00000000000000F5: 48 8D 55 01 lea rdx,[rbp+1] 00000000000000F9: 43 C6 04 27 00 mov byte ptr [r15+r12],0 00000000000000FE: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000105: 72 18 jb 000000000000011F 0000000000000107: 48 8B 4B F8 mov rcx,qword ptr [rbx-8] 000000000000010B: 48 83 C2 27 add rdx,27h 000000000000010F: 48 2B D9 sub rbx,rcx 0000000000000112: 48 8D 43 F8 lea rax,[rbx-8] 0000000000000116: 48 83 F8 1F cmp rax,1Fh 000000000000011A: 77 4D ja 0000000000000169 000000000000011C: 48 8B D9 mov rbx,rcx 000000000000011F: 48 8B CB mov rcx,rbx 0000000000000122: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000127: EB 1B jmp 0000000000000144 0000000000000129: 48 8B D6 mov rdx,rsi 000000000000012C: E8 00 00 00 00 call memcpy 0000000000000131: 4D 8B C4 mov r8,r12 0000000000000134: 49 8B D5 mov rdx,r13 0000000000000137: 49 8B CF mov rcx,r15 000000000000013A: E8 00 00 00 00 call memcpy 000000000000013F: 43 C6 04 27 00 mov byte ptr [r15+r12],0 0000000000000144: 48 89 3E mov qword ptr [rsi],rdi 0000000000000147: 48 8B C6 mov rax,rsi 000000000000014A: 4C 8B 64 24 60 mov r12,qword ptr [rsp+60h] 000000000000014F: 48 8B 7C 24 58 mov rdi,qword ptr [rsp+58h] 0000000000000154: 48 8B 6C 24 50 mov rbp,qword ptr [rsp+50h] 0000000000000159: 4C 8B 7C 24 20 mov r15,qword ptr [rsp+20h] 000000000000015E: 48 83 C4 28 add rsp,28h 0000000000000162: 41 5E pop r14 0000000000000164: 41 5D pop r13 0000000000000166: 5E pop rsi 0000000000000167: 5B pop rbx 0000000000000168: C3 ret 0000000000000169: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 000000000000016E: CC int 3 000000000000016F: E8 00 00 00 00 call ?_Xlen@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@CAXXZ 0000000000000174: CC int 3 0000000000000175: E8 00 00 00 00 call ?_Throw_bad_array_new_length@std@@YAXXZ 000000000000017A: CC int 3 000000000000013E: 48 8B 4D EF mov rcx,qword ptr [rbp-11h] 0000000000000142: 48 8B 01 mov rax,qword ptr [rcx] 0000000000000145: 44 8B 45 E7 mov r8d,dword ptr [rbp-19h] 0000000000000149: 48 8D 55 E7 lea rdx,[rbp-19h] 000000000000014D: FF 50 10 call qword ptr [rax+10h] 0000000000000150: 90 nop 0000000000000151: 48 8D 55 E7 lea rdx,[rbp-19h] 0000000000000155: 48 83 7D FF 10 cmp qword ptr [rbp-1],10h 000000000000015A: 48 0F 43 55 E7 cmovae rdx,qword ptr [rbp-19h] 000000000000015F: 4C 8B 45 F7 mov r8,qword ptr [rbp-9] 0000000000000163: 48 8D 4D 07 lea rcx,[rbp+7] 0000000000000000: 48 89 74 24 10 mov qword ptr [rsp+10h],rsi 0000000000000005: 57 push rdi 0000000000000006: 48 83 EC 30 sub rsp,30h 000000000000000A: 48 8B F9 mov rdi,rcx 000000000000000D: 49 8B F0 mov rsi,r8 0000000000000010: 48 8B 49 10 mov rcx,qword ptr [rcx+10h] 0000000000000014: 4C 8B 47 18 mov r8,qword ptr [rdi+18h] 0000000000000018: 49 8B C0 mov rax,r8 000000000000001B: 48 2B C1 sub rax,rcx 000000000000001E: 48 3B F0 cmp rsi,rax 0000000000000021: 77 3F ja 0000000000000062 0000000000000023: 48 89 5C 24 40 mov qword ptr [rsp+40h],rbx 0000000000000028: 48 8D 04 31 lea rax,[rcx+rsi] 000000000000002C: 48 89 47 10 mov qword ptr [rdi+10h],rax 0000000000000030: 48 8B C7 mov rax,rdi 0000000000000033: 49 83 F8 10 cmp r8,10h 0000000000000037: 72 03 jb 000000000000003C 0000000000000039: 48 8B 07 mov rax,qword ptr [rdi] 000000000000003C: 48 8D 1C 08 lea rbx,[rax+rcx] 0000000000000040: 4C 8B C6 mov r8,rsi 0000000000000043: 48 8B CB mov rcx,rbx 0000000000000046: E8 00 00 00 00 call memmove 000000000000004B: C6 04 33 00 mov byte ptr [rbx+rsi],0 000000000000004F: 48 8B C7 mov rax,rdi 0000000000000052: 48 8B 5C 24 40 mov rbx,qword ptr [rsp+40h] 0000000000000057: 48 8B 74 24 48 mov rsi,qword ptr [rsp+48h] 000000000000005C: 48 83 C4 30 add rsp,30h 0000000000000060: 5F pop rdi 0000000000000061: C3 ret 0000000000000062: 4C 8B CA mov r9,rdx 0000000000000065: 48 89 74 24 20 mov qword ptr [rsp+20h],rsi 000000000000006A: 48 8B D6 mov rdx,rsi 000000000000006D: 45 33 C0 xor r8d,r8d 0000000000000070: 48 8B CF mov rcx,rdi 0000000000000073: E8 00 00 00 00 call ??$_Reallocate_grow_by@V<lambda_65e615be2a453ca0576c979606f46740>@@PEBD_K@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAAAEAV01@_KV<lambda_65e615be2a453ca0576c979606f46740>@@PEBD_K@Z 0000000000000078: 48 8B 74 24 48 mov rsi,qword ptr [rsp+48h] 000000000000007D: 48 83 C4 30 add rsp,30h 0000000000000081: 5F pop rdi 0000000000000082: C3 ret 000000000000016C: 90 nop 000000000000016D: 48 8B 55 FF mov rdx,qword ptr [rbp-1] 0000000000000171: 48 83 FA 10 cmp rdx,10h 0000000000000175: 72 31 jb 00000000000001A8 0000000000000177: 48 FF C2 inc rdx 000000000000017A: 48 8B 4D E7 mov rcx,qword ptr [rbp-19h] 000000000000017E: 48 8B C1 mov rax,rcx 0000000000000181: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000188: 72 19 jb 00000000000001A3 000000000000018A: 48 83 C2 27 add rdx,27h 000000000000018E: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 0000000000000192: 48 2B C1 sub rax,rcx 0000000000000195: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000199: 48 83 F8 1F cmp rax,1Fh 000000000000019D: 0F 87 E9 00 00 00 ja 000000000000028C 00000000000001A3: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 00000000000001A8: 0F 10 45 07 movups xmm0,xmmword ptr [rbp+7] 00000000000001AC: 0F 11 45 27 movups xmmword ptr [rbp+27h],xmm0 00000000000001B0: 0F 10 4D 17 movups xmm1,xmmword ptr [rbp+17h] 00000000000001B4: 0F 11 4D 37 movups xmmword ptr [rbp+37h],xmm1 00000000000001B8: 48 C7 45 17 00 00 mov qword ptr [rbp+17h],0 00000000000001C0: 48 C7 45 1F 0F 00 mov qword ptr [rbp+1Fh],0Fh 00000000000001C8: C6 45 07 00 mov byte ptr [rbp+7],0 00000000000001CC: 4C 8D 45 27 lea r8,[rbp+27h] 00000000000001D0: 66 48 0F 7E C1 movq rcx,xmm0 00000000000001D5: 66 0F 73 D9 08 psrldq xmm1,8 00000000000001DA: 66 48 0F 7E C8 movq rax,xmm1 00000000000001DF: 48 83 F8 10 cmp rax,10h 00000000000001E3: 4C 0F 43 C1 cmovae r8,rcx 00000000000001E7: 48 8D 05 00 00 00 lea rax,[??_7exception@std@@6B@] 00000000000001EE: 49 89 06 mov qword ptr [r14],rax 00000000000001F1: 49 8D 56 08 lea rdx,[r14+8] 00000000000001F5: 0F 57 C0 xorps xmm0,xmm0 00000000000001F8: 0F 11 02 movups xmmword ptr [rdx],xmm0 00000000000001FB: 4C 89 45 E7 mov qword ptr [rbp-19h],r8 00000000000001FF: C6 45 EF 01 mov byte ptr [rbp-11h],1 0000000000000203: 48 8D 4D E7 lea rcx,[rbp-19h] 0000000000000207: E8 00 00 00 00 call __std_exception_copy 000000000000020C: 48 8D 05 00 00 00 lea rax,[??_7runtime_error@std@@6B@] 0000000000000213: 49 89 06 mov qword ptr [r14],rax 0000000000000216: 48 8B 55 3F mov rdx,qword ptr [rbp+3Fh] 000000000000021A: 48 83 FA 10 cmp rdx,10h 000000000000021E: 72 2D jb 000000000000024D 0000000000000220: 48 FF C2 inc rdx 0000000000000223: 48 8B 4D 27 mov rcx,qword ptr [rbp+27h] 0000000000000227: 48 8B C1 mov rax,rcx 000000000000022A: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000231: 72 15 jb 0000000000000248 0000000000000233: 48 83 C2 27 add rdx,27h 0000000000000237: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 000000000000023B: 48 2B C1 sub rax,rcx 000000000000023E: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000242: 48 83 F8 1F cmp rax,1Fh 0000000000000246: 77 38 ja 0000000000000280 0000000000000248: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 000000000000024D: 48 8D 05 00 00 00 lea rax,[??_7_System_error@std@@6B@] 0000000000000254: 49 89 06 mov qword ptr [r14],rax 0000000000000257: 41 0F 10 07 movups xmm0,xmmword ptr [r15] 000000000000025B: 41 0F 11 46 18 movups xmmword ptr [r14+18h],xmm0 0000000000000260: 49 8B C6 mov rax,r14 0000000000000263: 4C 8D 9C 24 90 00 lea r11,[rsp+90h] 000000000000026B: 49 8B 5B 20 mov rbx,qword ptr [r11+20h] 000000000000026F: 49 8B 73 28 mov rsi,qword ptr [r11+28h] 0000000000000273: 49 8B 7B 38 mov rdi,qword ptr [r11+38h] 0000000000000277: 49 8B E3 mov rsp,r11 000000000000027A: 41 5F pop r15 000000000000027C: 41 5E pop r14 000000000000027E: 5D pop rbp 000000000000027F: C3 ret 0000000000000280: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 0000000000000285: CC int 3 0000000000000286: E8 00 00 00 00 call ?_Throw_bad_array_new_length@std@@YAXXZ 000000000000028B: 90 nop 000000000000028C: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 0000000000000291: 90 nop 0000000000000056: 90 nop 0000000000000057: 48 8B 54 24 48 mov rdx,qword ptr [rsp+48h] 000000000000005C: 48 83 FA 10 cmp rdx,10h 0000000000000060: 72 2E jb 0000000000000090 0000000000000062: 48 FF C2 inc rdx 0000000000000065: 48 8B 4C 24 30 mov rcx,qword ptr [rsp+30h] 000000000000006A: 48 8B C1 mov rax,rcx 000000000000006D: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000074: 72 15 jb 000000000000008B 0000000000000076: 48 83 C2 27 add rdx,27h 000000000000007A: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 000000000000007E: 48 2B C1 sub rax,rcx 0000000000000081: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000085: 48 83 F8 1F cmp rax,1Fh 0000000000000089: 77 1D ja 00000000000000A8 000000000000008B: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000090: 48 8D 05 00 00 00 lea rax,[??_7system_error@std@@6B@] 0000000000000097: 48 89 07 mov qword ptr [rdi],rax 000000000000009A: 48 8B C7 mov rax,rdi 000000000000009D: 48 8B 5C 24 60 mov rbx,qword ptr [rsp+60h] 00000000000000A2: 48 83 C4 50 add rsp,50h 00000000000000A6: 5F pop rdi 00000000000000A7: C3 ret 00000000000000A8: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 00000000000000AD: CC int 3 000000000000001B: 48 8D 15 00 00 00 lea rdx,[_TI4?AVsystem_error@std@@] 0000000000000022: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000027: E8 00 00 00 00 call _CxxThrowException 000000000000002C: CC int 3 0000000000000063: CC int 3
0
repos/outcome/test
repos/outcome/test/constexprs/min_result_get_value.msvc.S.test1.s
0000000000000000: 40 53 push rbx 0000000000000002: 48 83 EC 50 sub rsp,50h 0000000000000006: 48 8D 1D 00 00 00 lea rbx,[?_Storage@?1???$_Immortalize@V_System_error_category@std@@@std@@YAAEAV_System_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A] 000000000000000D: C7 44 24 20 05 00 mov dword ptr [rsp+20h],5 0000000000000015: 4C 8B C3 mov r8,rbx 0000000000000018: 48 C7 44 24 24 01 mov qword ptr [rsp+24h],1 0000000000000021: 48 8D 15 00 00 00 lea rdx,[??$_Immortalize_impl@V_System_error_category@std@@@std@@YAHPEAX0PEAPEAX@Z] 0000000000000028: 48 8D 0D 00 00 00 lea rcx,[?_Flag@?1???$_Immortalize@V_System_error_category@std@@@std@@YAAEAV_System_error_category@1@XZ@4PEAXEA] 000000000000002F: E8 00 00 00 00 call ?_Execute_once@std@@YAHAEAUonce_flag@1@P6AHPEAX1PEAPEAX@Z1@Z 0000000000000034: 85 C0 test eax,eax 0000000000000036: 74 5E je 0000000000000096 0000000000000038: 0F B6 44 24 24 movzx eax,byte ptr [rsp+24h] 000000000000003D: 48 89 5C 24 30 mov qword ptr [rsp+30h],rbx 0000000000000042: A8 01 test al,1 0000000000000044: 75 08 jne 000000000000004E 0000000000000046: D0 E8 shr al,1 0000000000000048: A8 01 test al,1 000000000000004A: 75 2F jne 000000000000007B 000000000000004C: EB 0A jmp 0000000000000058 000000000000004E: 8B 44 24 20 mov eax,dword ptr [rsp+20h] 0000000000000052: 48 83 C4 50 add rsp,50h 0000000000000056: 5B pop rbx 0000000000000057: C3 ret 0000000000000058: 48 8D 15 00 00 00 lea rdx,[??_C@_08JEIPHCP@no?5value@] 000000000000005F: 48 8D 4C 24 38 lea rcx,[rsp+38h] 0000000000000000: 40 53 push rbx 0000000000000002: 48 83 EC 30 sub rsp,30h 0000000000000006: 48 8B D9 mov rbx,rcx 0000000000000009: C6 44 24 28 01 mov byte ptr [rsp+28h],1 000000000000000E: 48 8B C2 mov rax,rdx 0000000000000011: 48 8D 0D 00 00 00 lea rcx,[??_7exception@std@@6B@] 0000000000000018: 48 8D 53 08 lea rdx,[rbx+8] 000000000000001C: 48 89 44 24 20 mov qword ptr [rsp+20h],rax 0000000000000021: 0F 57 C0 xorps xmm0,xmm0 0000000000000024: 48 89 0B mov qword ptr [rbx],rcx 0000000000000027: 48 8D 4C 24 20 lea rcx,[rsp+20h] 000000000000002C: 0F 11 02 movups xmmword ptr [rdx],xmm0 000000000000002F: E8 00 00 00 00 call __std_exception_copy 0000000000000034: 48 8D 05 00 00 00 lea rax,[??_7bad_result_access@outcome_v2_3f877000@@6B@] 000000000000003B: 48 89 03 mov qword ptr [rbx],rax 000000000000003E: 48 8B C3 mov rax,rbx 0000000000000041: 48 83 C4 30 add rsp,30h 0000000000000045: 5B pop rbx 0000000000000046: C3 ret 0000000000000069: 48 8D 15 00 00 00 lea rdx,[_TI3?AVbad_result_access@outcome_v2_3f877000@@] 0000000000000070: 48 8D 4C 24 38 lea rcx,[rsp+38h] 0000000000000075: E8 00 00 00 00 call _CxxThrowException 000000000000007A: CC int 3 000000000000007B: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000000: 48 8B C1 mov rax,rcx 0000000000000003: C3 ret 0000000000000085: 48 8B C8 mov rcx,rax 0000000000000000: 48 8D 41 08 lea rax,[rcx+8] 0000000000000004: C3 ret 000000000000008D: 48 8B C8 mov rcx,rax 0000000000000000: 48 83 EC 68 sub rsp,68h 0000000000000004: 0F 10 01 movups xmm0,xmmword ptr [rcx] 0000000000000007: 48 8D 54 24 20 lea rdx,[rsp+20h] 000000000000000C: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000011: 0F 29 44 24 20 movaps xmmword ptr [rsp+20h],xmm0 0000000000000000: 48 89 5C 24 08 mov qword ptr [rsp+8],rbx 0000000000000005: 57 push rdi 0000000000000006: 48 83 EC 50 sub rsp,50h 000000000000000A: 48 8B DA mov rbx,rdx 000000000000000D: 48 8B F9 mov rdi,rcx 0000000000000010: 48 C7 44 24 40 00 mov qword ptr [rsp+40h],0 0000000000000019: 48 C7 44 24 48 0F mov qword ptr [rsp+48h],0Fh 0000000000000022: C6 44 24 30 00 mov byte ptr [rsp+30h],0 0000000000000027: 45 33 C0 xor r8d,r8d 000000000000002A: 48 8D 15 00 00 00 lea rdx,[??_C@_00CNPNBAHC@@] 0000000000000031: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000000: 48 89 5C 24 10 mov qword ptr [rsp+10h],rbx 0000000000000005: 48 89 6C 24 18 mov qword ptr [rsp+18h],rbp 000000000000000A: 56 push rsi 000000000000000B: 57 push rdi 000000000000000C: 41 57 push r15 000000000000000E: 48 83 EC 20 sub rsp,20h 0000000000000012: 48 8B 69 18 mov rbp,qword ptr [rcx+18h] 0000000000000016: 49 8B F0 mov rsi,r8 0000000000000019: 4C 8B FA mov r15,rdx 000000000000001C: 48 8B D9 mov rbx,rcx 000000000000001F: 4C 3B C5 cmp r8,rbp 0000000000000022: 77 21 ja 0000000000000045 0000000000000024: 48 8B F9 mov rdi,rcx 0000000000000027: 48 83 FD 10 cmp rbp,10h 000000000000002B: 72 03 jb 0000000000000030 000000000000002D: 48 8B 39 mov rdi,qword ptr [rcx] 0000000000000030: 48 89 71 10 mov qword ptr [rcx+10h],rsi 0000000000000034: 48 8B CF mov rcx,rdi 0000000000000037: E8 00 00 00 00 call memmove 000000000000003C: C6 04 37 00 mov byte ptr [rdi+rsi],0 0000000000000040: E9 E4 00 00 00 jmp 0000000000000129 0000000000000045: 48 BF FF FF FF FF mov rdi,7FFFFFFFFFFFFFFFh 000000000000004F: 48 3B F7 cmp rsi,rdi 0000000000000052: 0F 87 F3 00 00 00 ja 000000000000014B 0000000000000058: 48 8B CE mov rcx,rsi 000000000000005B: 48 83 C9 0F or rcx,0Fh 000000000000005F: 48 3B CF cmp rcx,rdi 0000000000000062: 77 1F ja 0000000000000083 0000000000000064: 48 8B D5 mov rdx,rbp 0000000000000067: 48 8B C7 mov rax,rdi 000000000000006A: 48 D1 EA shr rdx,1 000000000000006D: 48 2B C2 sub rax,rdx 0000000000000070: 48 3B E8 cmp rbp,rax 0000000000000073: 77 0E ja 0000000000000083 0000000000000075: 48 8D 04 2A lea rax,[rdx+rbp] 0000000000000079: 48 8B F9 mov rdi,rcx 000000000000007C: 48 3B C8 cmp rcx,rax 000000000000007F: 48 0F 42 F8 cmovb rdi,rax 0000000000000083: 48 8D 4F 01 lea rcx,[rdi+1] 0000000000000087: 4C 89 74 24 40 mov qword ptr [rsp+40h],r14 000000000000008C: 48 81 F9 00 10 00 cmp rcx,1000h 0000000000000093: 72 2C jb 00000000000000C1 0000000000000095: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000099: 48 3B C1 cmp rax,rcx 000000000000009C: 0F 86 9D 00 00 00 jbe 000000000000013F 00000000000000A2: 48 8B C8 mov rcx,rax 00000000000000A5: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000AA: 48 85 C0 test rax,rax 00000000000000AD: 0F 84 92 00 00 00 je 0000000000000145 00000000000000B3: 4C 8D 70 27 lea r14,[rax+27h] 00000000000000B7: 49 83 E6 E0 and r14,0FFFFFFFFFFFFFFE0h 00000000000000BB: 49 89 46 F8 mov qword ptr [r14-8],rax 00000000000000BF: EB 12 jmp 00000000000000D3 00000000000000C1: 48 85 C9 test rcx,rcx 00000000000000C4: 74 0A je 00000000000000D0 00000000000000C6: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000CB: 4C 8B F0 mov r14,rax 00000000000000CE: EB 03 jmp 00000000000000D3 00000000000000D0: 45 33 F6 xor r14d,r14d 00000000000000D3: 4C 8B C6 mov r8,rsi 00000000000000D6: 48 89 73 10 mov qword ptr [rbx+10h],rsi 00000000000000DA: 49 8B D7 mov rdx,r15 00000000000000DD: 48 89 7B 18 mov qword ptr [rbx+18h],rdi 00000000000000E1: 49 8B CE mov rcx,r14 00000000000000E4: E8 00 00 00 00 call memcpy 00000000000000E9: 41 C6 04 36 00 mov byte ptr [r14+rsi],0 00000000000000EE: 48 83 FD 10 cmp rbp,10h 00000000000000F2: 72 2D jb 0000000000000121 00000000000000F4: 48 8B 0B mov rcx,qword ptr [rbx] 00000000000000F7: 48 8D 55 01 lea rdx,[rbp+1] 00000000000000FB: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000102: 72 18 jb 000000000000011C 0000000000000104: 4C 8B 41 F8 mov r8,qword ptr [rcx-8] 0000000000000108: 48 83 C2 27 add rdx,27h 000000000000010C: 49 2B C8 sub rcx,r8 000000000000010F: 48 8D 41 F8 lea rax,[rcx-8] 0000000000000113: 48 83 F8 1F cmp rax,1Fh 0000000000000117: 77 2C ja 0000000000000145 0000000000000119: 49 8B C8 mov rcx,r8 000000000000011C: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000121: 4C 89 33 mov qword ptr [rbx],r14 0000000000000124: 4C 8B 74 24 40 mov r14,qword ptr [rsp+40h] 0000000000000129: 48 8B 6C 24 50 mov rbp,qword ptr [rsp+50h] 000000000000012E: 48 8B C3 mov rax,rbx 0000000000000131: 48 8B 5C 24 48 mov rbx,qword ptr [rsp+48h] 0000000000000136: 48 83 C4 20 add rsp,20h 000000000000013A: 41 5F pop r15 000000000000013C: 5F pop rdi 000000000000013D: 5E pop rsi 000000000000013E: C3 ret 0000000000000000: 48 83 EC 48 sub rsp,48h 0000000000000004: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000000: 48 8D 05 00 00 00 lea rax,[??_C@_0BF@KINCDENJ@bad?5array?5new?5length@] 0000000000000007: 48 C7 41 10 00 00 mov qword ptr [rcx+10h],0 000000000000000F: 48 89 41 08 mov qword ptr [rcx+8],rax 0000000000000013: 48 8D 05 00 00 00 lea rax,[??_7bad_array_new_length@std@@6B@] 000000000000001A: 48 89 01 mov qword ptr [rcx],rax 000000000000001D: 48 8B C1 mov rax,rcx 0000000000000020: C3 ret 000000000000000E: 48 8D 15 00 00 00 lea rdx,[_TI3?AVbad_array_new_length@std@@] 0000000000000015: 48 8D 4C 24 20 lea rcx,[rsp+20h] 000000000000001A: E8 00 00 00 00 call _CxxThrowException 000000000000001F: CC int 3 0000000000000144: CC int 3 0000000000000145: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 000000000000014A: CC int 3 0000000000000000: 48 83 EC 28 sub rsp,28h 0000000000000004: 48 8D 0D 00 00 00 lea rcx,[??_C@_0BA@JFNIOLAK@string?5too?5long@] 000000000000000B: E8 00 00 00 00 call ?_Xlength_error@std@@YAXPEBD@Z 0000000000000010: CC int 3 0000000000000150: CC int 3 000000000000003B: 90 nop 000000000000003C: 0F 10 03 movups xmm0,xmmword ptr [rbx] 000000000000003F: 0F 29 44 24 20 movaps xmmword ptr [rsp+20h],xmm0 0000000000000044: 4C 8D 44 24 30 lea r8,[rsp+30h] 0000000000000049: 48 8D 54 24 20 lea rdx,[rsp+20h] 000000000000004E: 48 8B CF mov rcx,rdi 0000000000000000: 48 89 5C 24 08 mov qword ptr [rsp+8],rbx 0000000000000005: 48 89 74 24 10 mov qword ptr [rsp+10h],rsi 000000000000000A: 48 89 7C 24 20 mov qword ptr [rsp+20h],rdi 000000000000000F: 55 push rbp 0000000000000010: 41 56 push r14 0000000000000012: 41 57 push r15 0000000000000014: 48 8D 6C 24 B9 lea rbp,[rsp-47h] 0000000000000019: 48 81 EC 90 00 00 sub rsp,90h 0000000000000020: 49 8B F0 mov rsi,r8 0000000000000023: 4C 8B FA mov r15,rdx 0000000000000026: 4C 8B F1 mov r14,rcx 0000000000000029: 48 C7 45 17 00 00 mov qword ptr [rbp+17h],0 0000000000000031: 48 C7 45 1F 00 00 mov qword ptr [rbp+1Fh],0 0000000000000039: 49 8B 78 10 mov rdi,qword ptr [r8+10h] 000000000000003D: 49 83 78 18 10 cmp qword ptr [r8+18h],10h 0000000000000042: 72 03 jb 0000000000000047 0000000000000044: 49 8B 30 mov rsi,qword ptr [r8] 0000000000000047: 48 83 FF 10 cmp rdi,10h 000000000000004B: 73 0E jae 000000000000005B 000000000000004D: 0F 10 06 movups xmm0,xmmword ptr [rsi] 0000000000000050: 0F 11 45 07 movups xmmword ptr [rbp+7],xmm0 0000000000000054: BB 0F 00 00 00 mov ebx,0Fh 0000000000000059: EB 75 jmp 00000000000000D0 000000000000005B: 48 8B DF mov rbx,rdi 000000000000005E: 48 83 CB 0F or rbx,0Fh 0000000000000062: 48 B8 FF FF FF FF mov rax,7FFFFFFFFFFFFFFFh 000000000000006C: 48 3B D8 cmp rbx,rax 000000000000006F: 48 0F 47 D8 cmova rbx,rax 0000000000000073: 48 8D 4B 01 lea rcx,[rbx+1] 0000000000000077: 48 81 F9 00 10 00 cmp rcx,1000h 000000000000007E: 72 2F jb 00000000000000AF 0000000000000080: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000084: 48 3B C1 cmp rax,rcx 0000000000000087: 0F 86 F9 01 00 00 jbe 0000000000000286 000000000000008D: 48 8B C8 mov rcx,rax 0000000000000090: E8 00 00 00 00 call ??2@YAPEAX_K@Z 0000000000000095: 48 8B C8 mov rcx,rax 0000000000000098: 48 85 C0 test rax,rax 000000000000009B: 0F 84 DF 01 00 00 je 0000000000000280 00000000000000A1: 48 83 C0 27 add rax,27h 00000000000000A5: 48 83 E0 E0 and rax,0FFFFFFFFFFFFFFE0h 00000000000000A9: 48 89 48 F8 mov qword ptr [rax-8],rcx 00000000000000AD: EB 0E jmp 00000000000000BD 00000000000000AF: 48 85 C9 test rcx,rcx 00000000000000B2: 74 07 je 00000000000000BB 00000000000000B4: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000B9: EB 02 jmp 00000000000000BD 00000000000000BB: 33 C0 xor eax,eax 00000000000000BD: 48 89 45 07 mov qword ptr [rbp+7],rax 00000000000000C1: 4C 8D 47 01 lea r8,[rdi+1] 00000000000000C5: 48 8B D6 mov rdx,rsi 00000000000000C8: 48 8B C8 mov rcx,rax 00000000000000CB: E8 00 00 00 00 call memcpy 00000000000000D0: 48 89 7D 17 mov qword ptr [rbp+17h],rdi 00000000000000D4: 48 89 5D 1F mov qword ptr [rbp+1Fh],rbx 00000000000000D8: 48 8D 45 07 lea rax,[rbp+7] 00000000000000DC: 48 89 45 77 mov qword ptr [rbp+77h],rax 00000000000000E0: 41 0F 10 07 movups xmm0,xmmword ptr [r15] 00000000000000E4: 0F 29 45 E7 movaps xmmword ptr [rbp-19h],xmm0 00000000000000E8: 48 85 FF test rdi,rdi 00000000000000EB: 74 51 je 000000000000013E 00000000000000ED: 48 8B C3 mov rax,rbx 00000000000000F0: 48 2B C7 sub rax,rdi 00000000000000F3: 48 83 F8 02 cmp rax,2 00000000000000F7: 72 25 jb 000000000000011E 00000000000000F9: 48 8D 47 02 lea rax,[rdi+2] 00000000000000FD: 48 89 45 17 mov qword ptr [rbp+17h],rax 0000000000000101: 48 8D 45 07 lea rax,[rbp+7] 0000000000000105: 48 83 FB 10 cmp rbx,10h 0000000000000109: 48 0F 43 45 07 cmovae rax,qword ptr [rbp+7] 000000000000010E: B9 3A 20 00 00 mov ecx,203Ah 0000000000000113: 66 89 0C 38 mov word ptr [rax+rdi],cx 0000000000000117: C6 44 38 02 00 mov byte ptr [rax+rdi+2],0 000000000000011C: EB 20 jmp 000000000000013E 000000000000011E: 48 C7 44 24 20 02 mov qword ptr [rsp+20h],2 0000000000000127: 4C 8D 0D 00 00 00 lea r9,[??_C@_02LMMGGCAJ@?3?5@] 000000000000012E: 45 33 C0 xor r8d,r8d 0000000000000131: 41 8D 50 02 lea edx,[r8+2] 0000000000000135: 48 8D 4D 07 lea rcx,[rbp+7] 0000000000000000: 40 53 push rbx 0000000000000002: 56 push rsi 0000000000000003: 41 55 push r13 0000000000000005: 41 56 push r14 0000000000000007: 48 83 EC 28 sub rsp,28h 000000000000000B: 4C 8B 71 10 mov r14,qword ptr [rcx+10h] 000000000000000F: 48 BB FF FF FF FF mov rbx,7FFFFFFFFFFFFFFFh 0000000000000019: 48 8B C3 mov rax,rbx 000000000000001C: 4D 8B E9 mov r13,r9 000000000000001F: 49 2B C6 sub rax,r14 0000000000000022: 48 8B F1 mov rsi,rcx 0000000000000025: 48 3B C2 cmp rax,rdx 0000000000000028: 0F 82 41 01 00 00 jb 000000000000016F 000000000000002E: 48 89 6C 24 50 mov qword ptr [rsp+50h],rbp 0000000000000033: 48 8B 69 18 mov rbp,qword ptr [rcx+18h] 0000000000000037: 4C 89 7C 24 20 mov qword ptr [rsp+20h],r15 000000000000003C: 4D 8D 3C 16 lea r15,[r14+rdx] 0000000000000040: 49 8B CF mov rcx,r15 0000000000000043: 48 83 C9 0F or rcx,0Fh 0000000000000047: 48 3B CB cmp rcx,rbx 000000000000004A: 77 1F ja 000000000000006B 000000000000004C: 48 8B D5 mov rdx,rbp 000000000000004F: 48 8B C3 mov rax,rbx 0000000000000052: 48 D1 EA shr rdx,1 0000000000000055: 48 2B C2 sub rax,rdx 0000000000000058: 48 3B E8 cmp rbp,rax 000000000000005B: 77 0E ja 000000000000006B 000000000000005D: 48 8D 04 2A lea rax,[rdx+rbp] 0000000000000061: 48 8B D9 mov rbx,rcx 0000000000000064: 48 3B C8 cmp rcx,rax 0000000000000067: 48 0F 42 D8 cmovb rbx,rax 000000000000006B: 48 8D 4B 01 lea rcx,[rbx+1] 000000000000006F: 48 89 7C 24 58 mov qword ptr [rsp+58h],rdi 0000000000000074: 4C 89 64 24 60 mov qword ptr [rsp+60h],r12 0000000000000079: 48 81 F9 00 10 00 cmp rcx,1000h 0000000000000080: 72 2C jb 00000000000000AE 0000000000000082: 48 8D 41 27 lea rax,[rcx+27h] 0000000000000086: 48 3B C1 cmp rax,rcx 0000000000000089: 0F 86 E6 00 00 00 jbe 0000000000000175 000000000000008F: 48 8B C8 mov rcx,rax 0000000000000092: E8 00 00 00 00 call ??2@YAPEAX_K@Z 0000000000000097: 48 85 C0 test rax,rax 000000000000009A: 0F 84 C9 00 00 00 je 0000000000000169 00000000000000A0: 48 8D 78 27 lea rdi,[rax+27h] 00000000000000A4: 48 83 E7 E0 and rdi,0FFFFFFFFFFFFFFE0h 00000000000000A8: 48 89 47 F8 mov qword ptr [rdi-8],rax 00000000000000AC: EB 11 jmp 00000000000000BF 00000000000000AE: 48 85 C9 test rcx,rcx 00000000000000B1: 74 0A je 00000000000000BD 00000000000000B3: E8 00 00 00 00 call ??2@YAPEAX_K@Z 00000000000000B8: 48 8B F8 mov rdi,rax 00000000000000BB: EB 02 jmp 00000000000000BF 00000000000000BD: 33 FF xor edi,edi 00000000000000BF: 4C 8B 64 24 70 mov r12,qword ptr [rsp+70h] 00000000000000C4: 4D 8B C6 mov r8,r14 00000000000000C7: 4C 89 7E 10 mov qword ptr [rsi+10h],r15 00000000000000CB: 4E 8D 3C 37 lea r15,[rdi+r14] 00000000000000CF: 48 89 5E 18 mov qword ptr [rsi+18h],rbx 00000000000000D3: 48 8B CF mov rcx,rdi 00000000000000D6: 48 83 FD 10 cmp rbp,10h 00000000000000DA: 72 4D jb 0000000000000129 00000000000000DC: 48 8B 1E mov rbx,qword ptr [rsi] 00000000000000DF: 48 8B D3 mov rdx,rbx 00000000000000E2: E8 00 00 00 00 call memcpy 00000000000000E7: 4D 8B C4 mov r8,r12 00000000000000EA: 49 8B D5 mov rdx,r13 00000000000000ED: 49 8B CF mov rcx,r15 00000000000000F0: E8 00 00 00 00 call memcpy 00000000000000F5: 48 8D 55 01 lea rdx,[rbp+1] 00000000000000F9: 43 C6 04 27 00 mov byte ptr [r15+r12],0 00000000000000FE: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000105: 72 18 jb 000000000000011F 0000000000000107: 48 8B 4B F8 mov rcx,qword ptr [rbx-8] 000000000000010B: 48 83 C2 27 add rdx,27h 000000000000010F: 48 2B D9 sub rbx,rcx 0000000000000112: 48 8D 43 F8 lea rax,[rbx-8] 0000000000000116: 48 83 F8 1F cmp rax,1Fh 000000000000011A: 77 4D ja 0000000000000169 000000000000011C: 48 8B D9 mov rbx,rcx 000000000000011F: 48 8B CB mov rcx,rbx 0000000000000122: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000127: EB 1B jmp 0000000000000144 0000000000000129: 48 8B D6 mov rdx,rsi 000000000000012C: E8 00 00 00 00 call memcpy 0000000000000131: 4D 8B C4 mov r8,r12 0000000000000134: 49 8B D5 mov rdx,r13 0000000000000137: 49 8B CF mov rcx,r15 000000000000013A: E8 00 00 00 00 call memcpy 000000000000013F: 43 C6 04 27 00 mov byte ptr [r15+r12],0 0000000000000144: 48 89 3E mov qword ptr [rsi],rdi 0000000000000147: 48 8B C6 mov rax,rsi 000000000000014A: 4C 8B 64 24 60 mov r12,qword ptr [rsp+60h] 000000000000014F: 48 8B 7C 24 58 mov rdi,qword ptr [rsp+58h] 0000000000000154: 48 8B 6C 24 50 mov rbp,qword ptr [rsp+50h] 0000000000000159: 4C 8B 7C 24 20 mov r15,qword ptr [rsp+20h] 000000000000015E: 48 83 C4 28 add rsp,28h 0000000000000162: 41 5E pop r14 0000000000000164: 41 5D pop r13 0000000000000166: 5E pop rsi 0000000000000167: 5B pop rbx 0000000000000168: C3 ret 0000000000000169: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 000000000000016E: CC int 3 000000000000016F: E8 00 00 00 00 call ?_Xlen@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@CAXXZ 0000000000000174: CC int 3 0000000000000175: E8 00 00 00 00 call ?_Throw_bad_array_new_length@std@@YAXXZ 000000000000017A: CC int 3 000000000000013E: 48 8B 4D EF mov rcx,qword ptr [rbp-11h] 0000000000000142: 48 8B 01 mov rax,qword ptr [rcx] 0000000000000145: 44 8B 45 E7 mov r8d,dword ptr [rbp-19h] 0000000000000149: 48 8D 55 E7 lea rdx,[rbp-19h] 000000000000014D: FF 50 10 call qword ptr [rax+10h] 0000000000000150: 90 nop 0000000000000151: 48 8D 55 E7 lea rdx,[rbp-19h] 0000000000000155: 48 83 7D FF 10 cmp qword ptr [rbp-1],10h 000000000000015A: 48 0F 43 55 E7 cmovae rdx,qword ptr [rbp-19h] 000000000000015F: 4C 8B 45 F7 mov r8,qword ptr [rbp-9] 0000000000000163: 48 8D 4D 07 lea rcx,[rbp+7] 0000000000000000: 48 89 74 24 10 mov qword ptr [rsp+10h],rsi 0000000000000005: 57 push rdi 0000000000000006: 48 83 EC 30 sub rsp,30h 000000000000000A: 48 8B F9 mov rdi,rcx 000000000000000D: 49 8B F0 mov rsi,r8 0000000000000010: 48 8B 49 10 mov rcx,qword ptr [rcx+10h] 0000000000000014: 4C 8B 47 18 mov r8,qword ptr [rdi+18h] 0000000000000018: 49 8B C0 mov rax,r8 000000000000001B: 48 2B C1 sub rax,rcx 000000000000001E: 48 3B F0 cmp rsi,rax 0000000000000021: 77 3F ja 0000000000000062 0000000000000023: 48 89 5C 24 40 mov qword ptr [rsp+40h],rbx 0000000000000028: 48 8D 04 31 lea rax,[rcx+rsi] 000000000000002C: 48 89 47 10 mov qword ptr [rdi+10h],rax 0000000000000030: 48 8B C7 mov rax,rdi 0000000000000033: 49 83 F8 10 cmp r8,10h 0000000000000037: 72 03 jb 000000000000003C 0000000000000039: 48 8B 07 mov rax,qword ptr [rdi] 000000000000003C: 48 8D 1C 08 lea rbx,[rax+rcx] 0000000000000040: 4C 8B C6 mov r8,rsi 0000000000000043: 48 8B CB mov rcx,rbx 0000000000000046: E8 00 00 00 00 call memmove 000000000000004B: C6 04 33 00 mov byte ptr [rbx+rsi],0 000000000000004F: 48 8B C7 mov rax,rdi 0000000000000052: 48 8B 5C 24 40 mov rbx,qword ptr [rsp+40h] 0000000000000057: 48 8B 74 24 48 mov rsi,qword ptr [rsp+48h] 000000000000005C: 48 83 C4 30 add rsp,30h 0000000000000060: 5F pop rdi 0000000000000061: C3 ret 0000000000000062: 4C 8B CA mov r9,rdx 0000000000000065: 48 89 74 24 20 mov qword ptr [rsp+20h],rsi 000000000000006A: 48 8B D6 mov rdx,rsi 000000000000006D: 45 33 C0 xor r8d,r8d 0000000000000070: 48 8B CF mov rcx,rdi 0000000000000073: E8 00 00 00 00 call ??$_Reallocate_grow_by@V<lambda_65e615be2a453ca0576c979606f46740>@@PEBD_K@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAAAEAV01@_KV<lambda_65e615be2a453ca0576c979606f46740>@@PEBD_K@Z 0000000000000078: 48 8B 74 24 48 mov rsi,qword ptr [rsp+48h] 000000000000007D: 48 83 C4 30 add rsp,30h 0000000000000081: 5F pop rdi 0000000000000082: C3 ret 000000000000016C: 90 nop 000000000000016D: 48 8B 55 FF mov rdx,qword ptr [rbp-1] 0000000000000171: 48 83 FA 10 cmp rdx,10h 0000000000000175: 72 31 jb 00000000000001A8 0000000000000177: 48 FF C2 inc rdx 000000000000017A: 48 8B 4D E7 mov rcx,qword ptr [rbp-19h] 000000000000017E: 48 8B C1 mov rax,rcx 0000000000000181: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000188: 72 19 jb 00000000000001A3 000000000000018A: 48 83 C2 27 add rdx,27h 000000000000018E: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 0000000000000192: 48 2B C1 sub rax,rcx 0000000000000195: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000199: 48 83 F8 1F cmp rax,1Fh 000000000000019D: 0F 87 E9 00 00 00 ja 000000000000028C 00000000000001A3: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 00000000000001A8: 0F 10 45 07 movups xmm0,xmmword ptr [rbp+7] 00000000000001AC: 0F 11 45 27 movups xmmword ptr [rbp+27h],xmm0 00000000000001B0: 0F 10 4D 17 movups xmm1,xmmword ptr [rbp+17h] 00000000000001B4: 0F 11 4D 37 movups xmmword ptr [rbp+37h],xmm1 00000000000001B8: 48 C7 45 17 00 00 mov qword ptr [rbp+17h],0 00000000000001C0: 48 C7 45 1F 0F 00 mov qword ptr [rbp+1Fh],0Fh 00000000000001C8: C6 45 07 00 mov byte ptr [rbp+7],0 00000000000001CC: 4C 8D 45 27 lea r8,[rbp+27h] 00000000000001D0: 66 48 0F 7E C1 movq rcx,xmm0 00000000000001D5: 66 0F 73 D9 08 psrldq xmm1,8 00000000000001DA: 66 48 0F 7E C8 movq rax,xmm1 00000000000001DF: 48 83 F8 10 cmp rax,10h 00000000000001E3: 4C 0F 43 C1 cmovae r8,rcx 00000000000001E7: 48 8D 05 00 00 00 lea rax,[??_7exception@std@@6B@] 00000000000001EE: 49 89 06 mov qword ptr [r14],rax 00000000000001F1: 49 8D 56 08 lea rdx,[r14+8] 00000000000001F5: 0F 57 C0 xorps xmm0,xmm0 00000000000001F8: 0F 11 02 movups xmmword ptr [rdx],xmm0 00000000000001FB: 4C 89 45 E7 mov qword ptr [rbp-19h],r8 00000000000001FF: C6 45 EF 01 mov byte ptr [rbp-11h],1 0000000000000203: 48 8D 4D E7 lea rcx,[rbp-19h] 0000000000000207: E8 00 00 00 00 call __std_exception_copy 000000000000020C: 48 8D 05 00 00 00 lea rax,[??_7runtime_error@std@@6B@] 0000000000000213: 49 89 06 mov qword ptr [r14],rax 0000000000000216: 48 8B 55 3F mov rdx,qword ptr [rbp+3Fh] 000000000000021A: 48 83 FA 10 cmp rdx,10h 000000000000021E: 72 2D jb 000000000000024D 0000000000000220: 48 FF C2 inc rdx 0000000000000223: 48 8B 4D 27 mov rcx,qword ptr [rbp+27h] 0000000000000227: 48 8B C1 mov rax,rcx 000000000000022A: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000231: 72 15 jb 0000000000000248 0000000000000233: 48 83 C2 27 add rdx,27h 0000000000000237: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 000000000000023B: 48 2B C1 sub rax,rcx 000000000000023E: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000242: 48 83 F8 1F cmp rax,1Fh 0000000000000246: 77 38 ja 0000000000000280 0000000000000248: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 000000000000024D: 48 8D 05 00 00 00 lea rax,[??_7_System_error@std@@6B@] 0000000000000254: 49 89 06 mov qword ptr [r14],rax 0000000000000257: 41 0F 10 07 movups xmm0,xmmword ptr [r15] 000000000000025B: 41 0F 11 46 18 movups xmmword ptr [r14+18h],xmm0 0000000000000260: 49 8B C6 mov rax,r14 0000000000000263: 4C 8D 9C 24 90 00 lea r11,[rsp+90h] 000000000000026B: 49 8B 5B 20 mov rbx,qword ptr [r11+20h] 000000000000026F: 49 8B 73 28 mov rsi,qword ptr [r11+28h] 0000000000000273: 49 8B 7B 38 mov rdi,qword ptr [r11+38h] 0000000000000277: 49 8B E3 mov rsp,r11 000000000000027A: 41 5F pop r15 000000000000027C: 41 5E pop r14 000000000000027E: 5D pop rbp 000000000000027F: C3 ret 0000000000000280: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 0000000000000285: CC int 3 0000000000000286: E8 00 00 00 00 call ?_Throw_bad_array_new_length@std@@YAXXZ 000000000000028B: 90 nop 000000000000028C: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 0000000000000291: 90 nop 0000000000000056: 90 nop 0000000000000057: 48 8B 54 24 48 mov rdx,qword ptr [rsp+48h] 000000000000005C: 48 83 FA 10 cmp rdx,10h 0000000000000060: 72 2E jb 0000000000000090 0000000000000062: 48 FF C2 inc rdx 0000000000000065: 48 8B 4C 24 30 mov rcx,qword ptr [rsp+30h] 000000000000006A: 48 8B C1 mov rax,rcx 000000000000006D: 48 81 FA 00 10 00 cmp rdx,1000h 0000000000000074: 72 15 jb 000000000000008B 0000000000000076: 48 83 C2 27 add rdx,27h 000000000000007A: 48 8B 49 F8 mov rcx,qword ptr [rcx-8] 000000000000007E: 48 2B C1 sub rax,rcx 0000000000000081: 48 83 C0 F8 add rax,0FFFFFFFFFFFFFFF8h 0000000000000085: 48 83 F8 1F cmp rax,1Fh 0000000000000089: 77 1D ja 00000000000000A8 000000000000008B: E8 00 00 00 00 call ??3@YAXPEAX_K@Z 0000000000000090: 48 8D 05 00 00 00 lea rax,[??_7system_error@std@@6B@] 0000000000000097: 48 89 07 mov qword ptr [rdi],rax 000000000000009A: 48 8B C7 mov rax,rdi 000000000000009D: 48 8B 5C 24 60 mov rbx,qword ptr [rsp+60h] 00000000000000A2: 48 83 C4 50 add rsp,50h 00000000000000A6: 5F pop rdi 00000000000000A7: C3 ret 00000000000000A8: E8 00 00 00 00 call _invalid_parameter_noinfo_noreturn 00000000000000AD: CC int 3 000000000000001B: 48 8D 15 00 00 00 lea rdx,[_TI4?AVsystem_error@std@@] 0000000000000022: 48 8D 4C 24 30 lea rcx,[rsp+30h] 0000000000000027: E8 00 00 00 00 call _CxxThrowException 000000000000002C: CC int 3 0000000000000095: CC int 3 0000000000000096: E8 00 00 00 00 call terminate 000000000000009B: CC int 3
0
repos/outcome/test
repos/outcome/test/constexprs/WG21_P1886a.cpp
/* Canned codegen quality test sequences (C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (9 commits) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../../single-header/outcome.hpp" struct obj { QUICKCPPLIB_NOINLINE ~obj() {} }; extern int foo; int foo; using namespace OUTCOME_V2_NAMESPACE; extern QUICKCPPLIB_NOINLINE result<int> src1() noexcept { return std::errc::argument_out_of_domain; } extern QUICKCPPLIB_NOINLINE result<int> test1() noexcept { obj x; OUTCOME_TRY(auto &&v, src1()); foo = 0; return success(v); } extern QUICKCPPLIB_NOINLINE void test2() { } int main(void) { int ret=0; if(test1()) ret=1; test2(); return ret; }
0
repos/outcome/test
repos/outcome/test/constexprs/min_result_construct_value_move_destruct.cpp
/* Canned codegen quality test sequences (C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (8 commits) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../../single-header/outcome.hpp" extern QUICKCPPLIB_NOINLINE int test1() { using namespace OUTCOME_V2_NAMESPACE; result<int> m1(5); result<int> m2(std::move(m1)); return std::move(m2).value(); } extern QUICKCPPLIB_NOINLINE void test2() { } int main(void) { int ret=0; if(5!=test1()) ret=1; test2(); return ret; }
0
repos/outcome/test
repos/outcome/test/constexprs/min_result_get_value.cpp
/* Canned codegen quality test sequences (C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (9 commits) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../../single-header/outcome.hpp" extern QUICKCPPLIB_NOINLINE int test1() { using namespace OUTCOME_V2_NAMESPACE; result<int> m1(5); return m1.value(); } extern QUICKCPPLIB_NOINLINE void test2() { } int main(void) { int ret=0; if(5!=test1()) ret=1; test2(); return ret; }
0
repos/outcome/test
repos/outcome/test/constexprs/compile_and_count.py
#!/usr/bin/python3 # File created by Tom Westerhout in May 2017 import sys import os import subprocess import count_opcodes def _mk_f(format_string : str): return lambda s1, s2 : format_string.format(s1, s2) def _mk_o(initial_ext: str, final_ext : str): return lambda s : s.replace("." + initial_ext, "." + final_ext) _compilers_ = \ { "posix" : ["gcc", "clang"] , "nt" : ["msvc"] #, "msvc_clang"] } _compile_info_ = \ { "gcc" : (_mk_f("g++-9 -std=c++17 -DNDEBUG -O3 -fno-stack-protector -fno-exceptions {} -o {}"), _mk_o("cpp", "out")) , "clang" : (_mk_f("clang++-9 -std=c++17 -DNDEBUG -O3 -fno-exceptions {} -o {}"), _mk_o("cpp", "out")) , "msvc" : (_mk_f("cl /std:c++17 /c /EHsc /DNDEBUG /O2 /GS- /GR /Gy /Zc:inline /MT " + "/D_UNICODE=1 /DUNICODE=1 {} /Fo{}"), _mk_o("cpp", "obj")) , "msvc_clang" : (_mk_f("clang -std=c++17 -c -DNDEBUG -O3 -fno-exceptions " + "-D_UNICODE=1 -DUNICODE=1 {} -o {} -fms-compatibility-version=19"), _mk_o("cpp", "out")) } _disassemble_info_ = \ { "gcc" : (_mk_f("objdump -C -d {} > {}"), _mk_o("out", "gcc.S")) , "clang" : (_mk_f("objdump -C -d {} > {}"), _mk_o("out", "clang.S")) , "msvc" : (_mk_f("dumpbin /disasm {} > {}"), _mk_o("obj", "msvc.S")) , "msvc_clang" : (_mk_f("dumpbin /disasm {} > {}"), _mk_o("out", "msvc_clang.S")) } _function_ = \ { "gcc" : ("test1(", "test1") , "clang" : ("test1(", "test1") , "msvc" : ("test1", "test1") , "msvc_clang" : ("test1", "test1") } # # Contains upper bounds on number of ops in the format # # { 'test1' : { 'gcc' : 10, 'clang' : 8, 'msvc' : 123, 'msvc_clang' : 20 } # , 'test2' : { ... } # , ... # } # limits = { "min_result_construct_value_move_destruct" : { 'gcc' : 5, 'clang' : 5, 'msvc' : 5 }, "min_result_next" : { 'gcc' : 5, 'clang' : 5, 'msvc' : 5 }, } # # Tries to compiler src_file using compiler. # On success: returns name of the executable. # On failure: returns None # def compile(src_file : str, compiler : str) -> str: if src_file is None: return None print("[*] Compiling '" + src_file + "' with " + compiler + "...", file=sys.stderr) command, output = _compile_info_[compiler] try: subprocess.check_output(command(src_file, output(src_file)), stderr=subprocess.STDOUT, shell=True) except subprocess.CalledProcessError as e: print("[-] Error while compiling: " + e.output.decode('utf-8'), file=sys.stderr) return None return output(src_file) # # Tries to disassemble obj_file using a tool corresponding # to compiler. If disassembling suceeds, deletes the obj_file. # On success: returns name of the file with asm code. # On failure: returns None # def disassemble(obj_file : str, compiler : str) -> str: if obj_file is None: return None print("[*] Disassembling '" + obj_file + "' with " + compiler + "...", file=sys.stderr) command, output = _disassemble_info_[compiler] try: subprocess.check_output(command(obj_file, output(obj_file)), stderr=subprocess.STDOUT, shell=True) except subprocess.CalledProcessError as e: print("[-] Error while dissasembling: " + e.output.decode('utf-8'), file=sys.stderr) return None try: os.remove(obj_file) except OSError as e: print("[-] Error removing file: " + e.strerror) return None return output(obj_file) def test_single(outname : str, func : str, src_file : str, compiler : str, indent : int): asm_file = disassemble(compile(src_file, compiler), compiler) assert asm_file is not None test_name = src_file.replace(".cpp", "") count, opcodes = count_opcodes.count_opcodes(outname, asm_file, func) if count == -1: print("[-] No call to " + func + " found.", file=sys.stderr) sys.exit(1) try: os.remove(asm_file) except OSError as e: print("[-] Error removing file: " + e.strerror) output = "<![CDATA[\n" + "\n".join(opcodes) + "\n]]>" xml_string = ' '*indent + '<testcase name="' + test_name + '.' + \ compiler + '">\n' if test_name in limits and compiler in limits[test_name] and limits[test_name][compiler] < count: xml_string += ' '*(indent+1) + '<failure message="Opcodes generated ' + \ str(count) + ' exceeds limit ' + str(limits[test_name][compiler]) + '"/>\n' xml_string += ' '*(indent+2) + '<system-out>\n' + output + '\n' + \ ' '*(indent+2) + '</system-out>\n' + \ ' '*indent + '</testcase>\n' return (test_name, count, xml_string) def list_src_files(): return sorted(filter(lambda src_file: os.path.isfile(src_file), filter(lambda s: s.endswith(".cpp"), os.listdir()))) def test_all(func : dict): xml_string = '<?xml version="1.0" encoding="UTF-8"?>\n' + \ '<testsuite name="constexpr">\n' # holds (compiler, name, count) tuples csv_data = [] for src_file in list_src_files(): print(src_file) for compiler in _compilers_[os.name]: name, count, xml_output = test_single(func[compiler][1], func[compiler][0], src_file, compiler, 1) csv_data.append((compiler, name, count)) xml_string += xml_output xml_string += '</testsuite>' with open("results." + os.name + ".xml", "wt") as xml_file: xml_file.write(xml_string) for compiler in _compilers_[os.name]: with open(compiler + ".csv", "a+t") as csv_file: csv_file.write(','.join( map(lambda t: '"'+t[1]+'"', filter(lambda t: t[0] == compiler, csv_data)))) csv_file.write('\n') csv_file.write(','.join( map(lambda t: str(t[2]), filter(lambda t: t[0] == compiler, csv_data)))) csv_file.write('\n') test_all(_function_)
0
repos/outcome/test
repos/outcome/test/constexprs/max_result_construct_value_move_destruct.gcc.S.test1.s
9a0: 48 83 ec 28 sub $0x28,%rsp 9a4: 48 89 e7 mov %rsp,%rdi 840: ff 25 82 17 20 00 jmpq *0x201782(%rip) # 201fc8 <unknown()> 846: 68 07 00 00 00 pushq $0x7 84b: e9 70 ff ff ff jmpq 7c0 <.plt> 9ac: 0f b7 44 24 04 movzwl 0x4(%rsp),%eax 9b1: a8 01 test $0x1,%al 9b3: 75 13 jne 9c8 <test1()+0x28> 9b5: a8 02 test $0x2,%al 9b7: 74 17 je 9d0 <test1()+0x30> 9b9: 48 8d 3d 9e 01 00 00 lea 0x19e(%rip),%rdi # b5e <_IO_stdin_used+0x4e> 9f0: 41 56 push %r14 9f2: be 10 00 00 00 mov $0x10,%esi 9f7: 41 55 push %r13 9f9: 41 54 push %r12 9fb: 49 89 fc mov %rdi,%r12 9fe: 55 push %rbp 9ff: 53 push %rbx a00: 48 83 c4 80 add $0xffffffffffffff80,%rsp a04: 49 89 e5 mov %rsp,%r13 a07: 4c 89 ef mov %r13,%rdi 800: ff 25 a2 17 20 00 jmpq *0x2017a2(%rip) # 201fa8 <backtrace@GLIBC_2.2.5> 806: 68 03 00 00 00 pushq $0x3 80b: e9 b0 ff ff ff jmpq 7c0 <.plt> a0f: 48 8b 3d 0a 16 20 00 mov 0x20160a(%rip),%rdi # 202020 <stderr@@GLIBC_2.2.5> a16: 4c 89 e1 mov %r12,%rcx a19: be 01 00 00 00 mov $0x1,%esi a1e: 4c 63 f0 movslq %eax,%r14 a21: 48 8d 15 f0 00 00 00 lea 0xf0(%rip),%rdx # b18 <_IO_stdin_used+0x8> a28: 31 c0 xor %eax,%eax 830: ff 25 8a 17 20 00 jmpq *0x20178a(%rip) # 201fc0 <__fprintf_chk@GLIBC_2.3.4> 836: 68 06 00 00 00 pushq $0x6 83b: e9 80 ff ff ff jmpq 7c0 <.plt> a2f: 44 89 f6 mov %r14d,%esi a32: 4c 89 ef mov %r13,%rdi 810: ff 25 9a 17 20 00 jmpq *0x20179a(%rip) # 201fb0 <backtrace_symbols@GLIBC_2.2.5> 816: 68 04 00 00 00 pushq $0x4 81b: e9 a0 ff ff ff jmpq 7c0 <.plt> a3a: 48 85 c0 test %rax,%rax a3d: 74 43 je a82 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x92> a3f: 49 89 c5 mov %rax,%r13 a42: 4d 85 f6 test %r14,%r14 a45: 74 33 je a7a <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x8a> a47: 48 89 c3 mov %rax,%rbx a4a: 4e 8d 24 f0 lea (%rax,%r14,8),%r12 a4e: 48 8d 2d 03 01 00 00 lea 0x103(%rip),%rbp # b58 <_IO_stdin_used+0x48> a55: 0f 1f 00 nopl (%rax) a58: 48 8b 0b mov (%rbx),%rcx a5b: 48 8b 3d be 15 20 00 mov 0x2015be(%rip),%rdi # 202020 <stderr@@GLIBC_2.2.5> a62: 48 89 ea mov %rbp,%rdx a65: 31 c0 xor %eax,%eax a67: be 01 00 00 00 mov $0x1,%esi a6c: 48 83 c3 08 add $0x8,%rbx a70: e8 bb fd ff ff callq 830 <__fprintf_chk@plt> a75: 4c 39 e3 cmp %r12,%rbx a78: 75 de jne a58 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x68> a7a: 4c 89 ef mov %r13,%rdi 7f0: ff 25 aa 17 20 00 jmpq *0x2017aa(%rip) # 201fa0 <free@GLIBC_2.2.5> 7f6: 68 02 00 00 00 pushq $0x2 7fb: e9 c0 ff ff ff jmpq 7c0 <.plt> 7d0: ff 25 ba 17 20 00 jmpq *0x2017ba(%rip) # 201f90 <abort@GLIBC_2.2.5> 7d6: 68 00 00 00 00 pushq $0x0 7db: e9 e0 ff ff ff jmpq 7c0 <.plt> a87: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1) 9c5: 0f 1f 00 nopl (%rax) 9c8: 8b 04 24 mov (%rsp),%eax 9cb: 48 83 c4 28 add $0x28,%rsp 9cf: c3 retq 9d0: 48 8d 3d a0 01 00 00 lea 0x1a0(%rip),%rdi # b77 <_IO_stdin_used+0x67> 9f0: 41 56 push %r14 9f2: be 10 00 00 00 mov $0x10,%esi 9f7: 41 55 push %r13 9f9: 41 54 push %r12 9fb: 49 89 fc mov %rdi,%r12 9fe: 55 push %rbp 9ff: 53 push %rbx a00: 48 83 c4 80 add $0xffffffffffffff80,%rsp a04: 49 89 e5 mov %rsp,%r13 a07: 4c 89 ef mov %r13,%rdi 800: ff 25 a2 17 20 00 jmpq *0x2017a2(%rip) # 201fa8 <backtrace@GLIBC_2.2.5> 806: 68 03 00 00 00 pushq $0x3 80b: e9 b0 ff ff ff jmpq 7c0 <.plt> a0f: 48 8b 3d 0a 16 20 00 mov 0x20160a(%rip),%rdi # 202020 <stderr@@GLIBC_2.2.5> a16: 4c 89 e1 mov %r12,%rcx a19: be 01 00 00 00 mov $0x1,%esi a1e: 4c 63 f0 movslq %eax,%r14 a21: 48 8d 15 f0 00 00 00 lea 0xf0(%rip),%rdx # b18 <_IO_stdin_used+0x8> a28: 31 c0 xor %eax,%eax 830: ff 25 8a 17 20 00 jmpq *0x20178a(%rip) # 201fc0 <__fprintf_chk@GLIBC_2.3.4> 836: 68 06 00 00 00 pushq $0x6 83b: e9 80 ff ff ff jmpq 7c0 <.plt> a2f: 44 89 f6 mov %r14d,%esi a32: 4c 89 ef mov %r13,%rdi 810: ff 25 9a 17 20 00 jmpq *0x20179a(%rip) # 201fb0 <backtrace_symbols@GLIBC_2.2.5> 816: 68 04 00 00 00 pushq $0x4 81b: e9 a0 ff ff ff jmpq 7c0 <.plt> a3a: 48 85 c0 test %rax,%rax a3d: 74 43 je a82 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x92> a3f: 49 89 c5 mov %rax,%r13 a42: 4d 85 f6 test %r14,%r14 a45: 74 33 je a7a <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x8a> a47: 48 89 c3 mov %rax,%rbx a4a: 4e 8d 24 f0 lea (%rax,%r14,8),%r12 a4e: 48 8d 2d 03 01 00 00 lea 0x103(%rip),%rbp # b58 <_IO_stdin_used+0x48> a55: 0f 1f 00 nopl (%rax) a58: 48 8b 0b mov (%rbx),%rcx a5b: 48 8b 3d be 15 20 00 mov 0x2015be(%rip),%rdi # 202020 <stderr@@GLIBC_2.2.5> a62: 48 89 ea mov %rbp,%rdx a65: 31 c0 xor %eax,%eax a67: be 01 00 00 00 mov $0x1,%esi a6c: 48 83 c3 08 add $0x8,%rbx a70: e8 bb fd ff ff callq 830 <__fprintf_chk@plt> a75: 4c 39 e3 cmp %r12,%rbx a78: 75 de jne a58 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x68> a7a: 4c 89 ef mov %r13,%rdi 7f0: ff 25 aa 17 20 00 jmpq *0x2017aa(%rip) # 201fa0 <free@GLIBC_2.2.5> 7f6: 68 02 00 00 00 pushq $0x2 7fb: e9 c0 ff ff ff jmpq 7c0 <.plt> 7d0: ff 25 ba 17 20 00 jmpq *0x2017ba(%rip) # 201f90 <abort@GLIBC_2.2.5> 7d6: 68 00 00 00 00 pushq $0x0 7db: e9 e0 ff ff ff jmpq 7c0 <.plt> a87: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1) 9dc: 0f 1f 40 00 nopl 0x0(%rax)
0
repos/outcome/test
repos/outcome/test/constexprs/WG21_P1886.cpp
/* Canned codegen quality test sequences (C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (9 commits) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../../single-header/outcome-experimental.hpp" struct obj { QUICKCPPLIB_NOINLINE ~obj() {} }; extern int foo; int foo; using namespace OUTCOME_V2_NAMESPACE::experimental; static_assert(OUTCOME_V2_NAMESPACE::trait::is_move_relocating<status_result<int>::error_type>::value, "system_code is not move relocating!"); static QUICKCPPLIB_NOINLINE status_result<int> src1() noexcept { return errc::argument_out_of_domain; } extern QUICKCPPLIB_NOINLINE status_result<int> test1() noexcept { obj x; OUTCOME_TRY(auto &&v, src1()); foo = 0; return success(v); } extern QUICKCPPLIB_NOINLINE void test2() { } int main(void) { int ret=0; if(test1()) ret=1; test2(); return ret; }
0
repos/outcome/test
repos/outcome/test/constexprs/min_result_construct_value_move_destruct.gcc.S.test1.s
940: b8 05 00 00 00 mov $0x5,%eax 945: c3 retq 946: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
0
repos/outcome/test
repos/outcome/test/constexprs/max_result_construct_value_move_destruct.clang.S.test1.s
400830: 48 83 ec 18 sub $0x18,%rsp 400834: 48 89 e7 mov %rsp,%rdi 400700: ff 25 4a 09 20 00 jmpq *0x20094a(%rip) # 601050 <unknown()> 400706: 68 07 00 00 00 pushq $0x7 40070b: e9 70 ff ff ff jmpq 400680 <.plt> 40083c: 0f b7 44 24 04 movzwl 0x4(%rsp),%eax 400841: a8 01 test $0x1,%al 400843: 74 08 je 40084d <test1()+0x1d> 400845: 8b 04 24 mov (%rsp),%eax 400848: 48 83 c4 18 add $0x18,%rsp 40084c: c3 retq 40084d: a8 02 test $0x2,%al 40084f: 75 0a jne 40085b <test1()+0x2b> 400851: bf b4 09 40 00 mov $0x4009b4,%edi 4008a0: 55 push %rbp 4008a1: 41 56 push %r14 4008a3: 53 push %rbx 4008a4: 48 81 ec 80 00 00 00 sub $0x80,%rsp 4008ab: 48 89 fb mov %rdi,%rbx 4008ae: 49 89 e6 mov %rsp,%r14 4008b1: 4c 89 f7 mov %r14,%rdi 4008b4: be 10 00 00 00 mov $0x10,%esi 4006d0: ff 25 62 09 20 00 jmpq *0x200962(%rip) # 601038 <backtrace@GLIBC_2.2.5> 4006d6: 68 04 00 00 00 pushq $0x4 4006db: e9 a0 ff ff ff jmpq 400680 <.plt> 4008be: 89 c5 mov %eax,%ebp 4008c0: 48 8b 3d b9 07 20 00 mov 0x2007b9(%rip),%rdi # 601080 <stderr@@GLIBC_2.2.5> 4008c7: be eb 09 40 00 mov $0x4009eb,%esi 4008cc: 48 89 da mov %rbx,%rdx 4008cf: 31 c0 xor %eax,%eax 4006c0: ff 25 6a 09 20 00 jmpq *0x20096a(%rip) # 601030 <fprintf@GLIBC_2.2.5> 4006c6: 68 03 00 00 00 pushq $0x3 4006cb: e9 b0 ff ff ff jmpq 400680 <.plt> 4008d6: 4c 89 f7 mov %r14,%rdi 4008d9: 89 ee mov %ebp,%esi 4006e0: ff 25 5a 09 20 00 jmpq *0x20095a(%rip) # 601040 <backtrace_symbols@GLIBC_2.2.5> 4006e6: 68 05 00 00 00 pushq $0x5 4006eb: e9 90 ff ff ff jmpq 400680 <.plt> 4008e0: 48 85 c0 test %rax,%rax 4008e3: 74 43 je 400928 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x88> 4008e5: 49 89 c6 mov %rax,%r14 4008e8: 85 ed test %ebp,%ebp 4008ea: 74 34 je 400920 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x80> 4008ec: 48 63 ed movslq %ebp,%rbp 4008ef: 31 db xor %ebx,%ebx 4008f1: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 4008fb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 400900: 48 8b 3d 79 07 20 00 mov 0x200779(%rip),%rdi # 601080 <stderr@@GLIBC_2.2.5> 400907: 49 8b 14 de mov (%r14,%rbx,8),%rdx 40090b: be 28 0a 40 00 mov $0x400a28,%esi 400910: 31 c0 xor %eax,%eax 400912: e8 a9 fd ff ff callq 4006c0 <fprintf@plt> 400917: 48 83 c3 01 add $0x1,%rbx 40091b: 48 39 eb cmp %rbp,%rbx 40091e: 72 e0 jb 400900 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x60> 400920: 4c 89 f7 mov %r14,%rdi 4006b0: ff 25 72 09 20 00 jmpq *0x200972(%rip) # 601028 <free@GLIBC_2.2.5> 4006b6: 68 02 00 00 00 pushq $0x2 4006bb: e9 c0 ff ff ff jmpq 400680 <.plt> 400690: ff 25 82 09 20 00 jmpq *0x200982(%rip) # 601018 <abort@GLIBC_2.2.5> 400696: 68 00 00 00 00 pushq $0x0 40069b: e9 e0 ff ff ff jmpq 400680 <.plt> 40092d: 0f 1f 00 nopl (%rax) 40085b: bf d2 09 40 00 mov $0x4009d2,%edi 4008a0: 55 push %rbp 4008a1: 41 56 push %r14 4008a3: 53 push %rbx 4008a4: 48 81 ec 80 00 00 00 sub $0x80,%rsp 4008ab: 48 89 fb mov %rdi,%rbx 4008ae: 49 89 e6 mov %rsp,%r14 4008b1: 4c 89 f7 mov %r14,%rdi 4008b4: be 10 00 00 00 mov $0x10,%esi 4006d0: ff 25 62 09 20 00 jmpq *0x200962(%rip) # 601038 <backtrace@GLIBC_2.2.5> 4006d6: 68 04 00 00 00 pushq $0x4 4006db: e9 a0 ff ff ff jmpq 400680 <.plt> 4008be: 89 c5 mov %eax,%ebp 4008c0: 48 8b 3d b9 07 20 00 mov 0x2007b9(%rip),%rdi # 601080 <stderr@@GLIBC_2.2.5> 4008c7: be eb 09 40 00 mov $0x4009eb,%esi 4008cc: 48 89 da mov %rbx,%rdx 4008cf: 31 c0 xor %eax,%eax 4006c0: ff 25 6a 09 20 00 jmpq *0x20096a(%rip) # 601030 <fprintf@GLIBC_2.2.5> 4006c6: 68 03 00 00 00 pushq $0x3 4006cb: e9 b0 ff ff ff jmpq 400680 <.plt> 4008d6: 4c 89 f7 mov %r14,%rdi 4008d9: 89 ee mov %ebp,%esi 4006e0: ff 25 5a 09 20 00 jmpq *0x20095a(%rip) # 601040 <backtrace_symbols@GLIBC_2.2.5> 4006e6: 68 05 00 00 00 pushq $0x5 4006eb: e9 90 ff ff ff jmpq 400680 <.plt> 4008e0: 48 85 c0 test %rax,%rax 4008e3: 74 43 je 400928 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x88> 4008e5: 49 89 c6 mov %rax,%r14 4008e8: 85 ed test %ebp,%ebp 4008ea: 74 34 je 400920 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x80> 4008ec: 48 63 ed movslq %ebp,%rbp 4008ef: 31 db xor %ebx,%ebx 4008f1: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 4008fb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 400900: 48 8b 3d 79 07 20 00 mov 0x200779(%rip),%rdi # 601080 <stderr@@GLIBC_2.2.5> 400907: 49 8b 14 de mov (%r14,%rbx,8),%rdx 40090b: be 28 0a 40 00 mov $0x400a28,%esi 400910: 31 c0 xor %eax,%eax 400912: e8 a9 fd ff ff callq 4006c0 <fprintf@plt> 400917: 48 83 c3 01 add $0x1,%rbx 40091b: 48 39 eb cmp %rbp,%rbx 40091e: 72 e0 jb 400900 <outcome_v2_3f877000::detail::do_fatal_exit(char const*)+0x60> 400920: 4c 89 f7 mov %r14,%rdi 4006b0: ff 25 72 09 20 00 jmpq *0x200972(%rip) # 601028 <free@GLIBC_2.2.5> 4006b6: 68 02 00 00 00 pushq $0x2 4006bb: e9 c0 ff ff ff jmpq 400680 <.plt> 400690: ff 25 82 09 20 00 jmpq *0x200982(%rip) # 601018 <abort@GLIBC_2.2.5> 400696: 68 00 00 00 00 pushq $0x0 40069b: e9 e0 ff ff ff jmpq 400680 <.plt> 40092d: 0f 1f 00 nopl (%rax) 400865: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 40086f: 90 nop
0
repos/outcome/test
repos/outcome/test/constexprs/WG21_P1886a.msvc.S.test1.s
0000000000000000: 40 53 push rbx 0000000000000002: 48 83 EC 40 sub rsp,40h 0000000000000006: 48 8B D9 mov rbx,rcx 0000000000000009: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000000: 48 89 5C 24 08 mov qword ptr [rsp+8],rbx 0000000000000005: 48 89 74 24 10 mov qword ptr [rsp+10h],rsi 000000000000000A: 57 push rdi 000000000000000B: 48 83 EC 30 sub rsp,30h 000000000000000F: 0F B6 1D 00 00 00 movzx ebx,byte ptr [??$in_place_type@Verror_code@std@@@std@@3U?$in_place_type_t@Verror_code@std@@@1@B] 0000000000000016: 48 8D 35 00 00 00 lea rsi,[?_Storage@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A] 000000000000001D: 48 8B F9 mov rdi,rcx 0000000000000020: 48 8D 15 00 00 00 lea rdx,[??$_Immortalize_impl@V_Generic_error_category@std@@@std@@YAHPEAX0PEAPEAX@Z] 0000000000000027: 4C 8B C6 mov r8,rsi 000000000000002A: 48 8D 0D 00 00 00 lea rcx,[?_Flag@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4PEAXEA] 0000000000000031: E8 00 00 00 00 call ?_Execute_once@std@@YAHAEAUonce_flag@1@P6AHPEAX1PEAPEAX@Z1@Z 0000000000000036: 85 C0 test eax,eax 0000000000000038: 74 30 je 000000000000006A 000000000000003A: 4C 8D 44 24 20 lea r8,[rsp+20h] 000000000000003F: C7 44 24 20 21 00 mov dword ptr [rsp+20h],21h 0000000000000047: 0F B6 D3 movzx edx,bl 000000000000004A: 48 89 74 24 28 mov qword ptr [rsp+28h],rsi 000000000000004F: 48 8B CF mov rcx,rdi 0000000000000000: 48 89 5C 24 10 mov qword ptr [rsp+10h],rbx 0000000000000005: 57 push rdi 0000000000000006: 48 83 EC 20 sub rsp,20h 000000000000000A: 48 8B D9 mov rbx,rcx 000000000000000D: C7 44 24 30 02 00 mov dword ptr [rsp+30h],2 0000000000000015: 8B 44 24 30 mov eax,dword ptr [rsp+30h] 0000000000000019: 48 8D 15 00 00 00 lea rdx,[??$_Immortalize_impl@V_Generic_error_category@std@@@std@@YAHPEAX0PEAPEAX@Z] 0000000000000020: 89 41 04 mov dword ptr [rcx+4],eax 0000000000000023: 41 0F 10 00 movups xmm0,xmmword ptr [r8] 0000000000000027: 4C 8D 05 00 00 00 lea r8,[?_Storage@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A] 000000000000002E: 0F 11 41 08 movups xmmword ptr [rcx+8],xmm0 0000000000000032: 48 8B 79 10 mov rdi,qword ptr [rcx+10h] 0000000000000036: 48 8D 0D 00 00 00 lea rcx,[?_Flag@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4PEAXEA] 000000000000003D: E8 00 00 00 00 call ?_Execute_once@std@@YAHAEAUonce_flag@1@P6AHPEAX1PEAPEAX@Z1@Z 0000000000000042: 85 C0 test eax,eax 0000000000000044: 74 20 je 0000000000000066 0000000000000046: 48 8B 05 08 00 00 mov rax,qword ptr [?_Storage@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A+8] 000000000000004D: 48 39 47 08 cmp qword ptr [rdi+8],rax 0000000000000051: 75 05 jne 0000000000000058 0000000000000053: 66 83 4B 04 10 or word ptr [rbx+4],10h 0000000000000058: 48 8B C3 mov rax,rbx 000000000000005B: 48 8B 5C 24 38 mov rbx,qword ptr [rsp+38h] 0000000000000060: 48 83 C4 20 add rsp,20h 0000000000000064: 5F pop rdi 0000000000000065: C3 ret 0000000000000066: E8 00 00 00 00 call terminate 000000000000006B: CC int 3 0000000000000057: 48 8B 5C 24 40 mov rbx,qword ptr [rsp+40h] 000000000000005C: 48 8B C7 mov rax,rdi 000000000000005F: 48 8B 74 24 48 mov rsi,qword ptr [rsp+48h] 0000000000000064: 48 83 C4 30 add rsp,30h 0000000000000068: 5F pop rdi 0000000000000069: C3 ret 000000000000006A: E8 00 00 00 00 call terminate 000000000000006F: CC int 3 0000000000000013: F6 44 24 24 01 test byte ptr [rsp+24h],1 0000000000000018: 74 4E je 0000000000000068 000000000000001A: 8B 44 24 20 mov eax,dword ptr [rsp+20h] 000000000000001E: 48 8D 15 00 00 00 lea rdx,[??$_Immortalize_impl@V_System_error_category@std@@@std@@YAHPEAX0PEAPEAX@Z] 0000000000000025: 33 C9 xor ecx,ecx 0000000000000027: 48 89 7C 24 50 mov qword ptr [rsp+50h],rdi 000000000000002C: 89 0D 00 00 00 00 mov dword ptr [?foo@@3HA],ecx 0000000000000032: 48 8D 3D 00 00 00 lea rdi,[?_Storage@?1???$_Immortalize@V_System_error_category@std@@@std@@YAAEAV_System_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A] 0000000000000039: 4C 8B C7 mov r8,rdi 000000000000003C: 89 03 mov dword ptr [rbx],eax 000000000000003E: 48 8D 0D 00 00 00 lea rcx,[?_Flag@?1???$_Immortalize@V_System_error_category@std@@@std@@YAAEAV_System_error_category@1@XZ@4PEAXEA] 0000000000000045: 48 C7 43 04 01 00 mov qword ptr [rbx+4],1 000000000000004D: E8 00 00 00 00 call ?_Execute_once@std@@YAHAEAUonce_flag@1@P6AHPEAX1PEAPEAX@Z1@Z 0000000000000052: 85 C0 test eax,eax 0000000000000054: 74 39 je 000000000000008F 0000000000000056: 48 89 7B 10 mov qword ptr [rbx+10h],rdi 000000000000005A: 48 8B C3 mov rax,rbx 000000000000005D: 48 8B 7C 24 50 mov rdi,qword ptr [rsp+50h] 0000000000000062: 48 83 C4 40 add rsp,40h 0000000000000066: 5B pop rbx 0000000000000067: C3 ret 0000000000000068: 0F 10 44 24 28 movups xmm0,xmmword ptr [rsp+28h] 000000000000006D: 0F B6 15 00 00 00 movzx edx,byte ptr [??$in_place_type@Verror_code@std@@@std@@3U?$in_place_type_t@Verror_code@std@@@1@B] 0000000000000074: 4C 8D 44 24 20 lea r8,[rsp+20h] 0000000000000079: 48 8B CB mov rcx,rbx 000000000000007C: 0F 11 44 24 20 movups xmmword ptr [rsp+20h],xmm0 0000000000000000: 48 89 5C 24 10 mov qword ptr [rsp+10h],rbx 0000000000000005: 57 push rdi 0000000000000006: 48 83 EC 20 sub rsp,20h 000000000000000A: 48 8B D9 mov rbx,rcx 000000000000000D: C7 44 24 30 02 00 mov dword ptr [rsp+30h],2 0000000000000015: 8B 44 24 30 mov eax,dword ptr [rsp+30h] 0000000000000019: 48 8D 15 00 00 00 lea rdx,[??$_Immortalize_impl@V_Generic_error_category@std@@@std@@YAHPEAX0PEAPEAX@Z] 0000000000000020: 89 41 04 mov dword ptr [rcx+4],eax 0000000000000023: 41 0F 10 00 movups xmm0,xmmword ptr [r8] 0000000000000027: 4C 8D 05 00 00 00 lea r8,[?_Storage@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A] 000000000000002E: 0F 11 41 08 movups xmmword ptr [rcx+8],xmm0 0000000000000032: 48 8B 79 10 mov rdi,qword ptr [rcx+10h] 0000000000000036: 48 8D 0D 00 00 00 lea rcx,[?_Flag@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4PEAXEA] 000000000000003D: E8 00 00 00 00 call ?_Execute_once@std@@YAHAEAUonce_flag@1@P6AHPEAX1PEAPEAX@Z1@Z 0000000000000042: 85 C0 test eax,eax 0000000000000044: 74 20 je 0000000000000066 0000000000000046: 48 8B 05 08 00 00 mov rax,qword ptr [?_Storage@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A+8] 000000000000004D: 48 39 47 08 cmp qword ptr [rdi+8],rax 0000000000000051: 75 05 jne 0000000000000058 0000000000000053: 66 83 4B 04 10 or word ptr [rbx+4],10h 0000000000000058: 48 8B C3 mov rax,rbx 000000000000005B: 48 8B 5C 24 38 mov rbx,qword ptr [rsp+38h] 0000000000000060: 48 83 C4 20 add rsp,20h 0000000000000064: 5F pop rdi 0000000000000065: C3 ret 0000000000000066: E8 00 00 00 00 call terminate 000000000000006B: CC int 3 0000000000000086: 48 8B C3 mov rax,rbx 0000000000000089: 48 83 C4 40 add rsp,40h 000000000000008D: 5B pop rbx 000000000000008E: C3 ret 000000000000008F: E8 00 00 00 00 call terminate 0000000000000094: CC int 3
0
repos/outcome/test
repos/outcome/test/constexprs/WG21_P1886.msvc.S.test1.s
0000000000000000: 40 53 push rbx 0000000000000002: 48 83 EC 40 sub rsp,40h 0000000000000006: 48 8B D9 mov rbx,rcx 0000000000000009: 48 8D 4C 24 20 lea rcx,[rsp+20h] 0000000000000000: C7 44 24 08 02 00 mov dword ptr [rsp+8],2 0000000000000008: 8B 44 24 08 mov eax,dword ptr [rsp+8] 000000000000000C: 89 41 04 mov dword ptr [rcx+4],eax 000000000000000F: 48 8D 05 00 00 00 lea rax,[?generic_code_domain@system_error2@@3V_generic_code_domain@1@B] 0000000000000016: 48 89 41 08 mov qword ptr [rcx+8],rax 000000000000001A: 48 8B C1 mov rax,rcx 000000000000001D: 48 C7 41 10 21 00 mov qword ptr [rcx+10h],21h 0000000000000025: C3 ret 0000000000000013: F6 44 24 24 01 test byte ptr [rsp+24h],1 0000000000000018: 74 41 je 000000000000005B 000000000000001A: 8B 44 24 20 mov eax,dword ptr [rsp+20h] 000000000000001E: 33 C9 xor ecx,ecx 0000000000000020: 89 0D 00 00 00 00 mov dword ptr [?foo@@3HA],ecx 0000000000000026: 89 03 mov dword ptr [rbx],eax 0000000000000028: C7 43 04 01 00 00 mov dword ptr [rbx+4],1 000000000000002F: 48 89 4B 08 mov qword ptr [rbx+8],rcx 0000000000000033: 48 89 4B 10 mov qword ptr [rbx+10h],rcx 0000000000000037: 48 8B 4C 24 28 mov rcx,qword ptr [rsp+28h] 000000000000003C: 48 85 C9 test rcx,rcx 000000000000003F: 74 3B je 000000000000007C 0000000000000041: 48 8B 01 mov rax,qword ptr [rcx] 0000000000000044: 48 8D 54 24 28 lea rdx,[rsp+28h] 0000000000000049: 41 B8 10 00 00 00 mov r8d,10h 000000000000004F: FF 50 38 call qword ptr [rax+38h] 0000000000000052: 48 8B C3 mov rax,rbx 0000000000000055: 48 83 C4 40 add rsp,40h 0000000000000059: 5B pop rbx 000000000000005A: C3 ret 000000000000005B: C7 44 24 58 02 00 mov dword ptr [rsp+58h],2 0000000000000063: 8B 44 24 58 mov eax,dword ptr [rsp+58h] 0000000000000067: 89 43 04 mov dword ptr [rbx+4],eax 000000000000006A: 48 8B 44 24 28 mov rax,qword ptr [rsp+28h] 000000000000006F: 48 89 43 08 mov qword ptr [rbx+8],rax 0000000000000073: 48 8B 44 24 30 mov rax,qword ptr [rsp+30h] 0000000000000078: 48 89 43 10 mov qword ptr [rbx+10h],rax 000000000000007C: 48 8B C3 mov rax,rbx 000000000000007F: 48 83 C4 40 add rsp,40h 0000000000000083: 5B pop rbx 0000000000000084: C3 ret
0
repos/outcome/test
repos/outcome/test/constexprs/min_result_get_value.gcc.S.test1.s
940: b8 05 00 00 00 mov $0x5,%eax 945: c3 retq 946: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
0
repos/outcome/test
repos/outcome/test/constexprs/WG21_P1886.clang.S.test1.s
400680: 53 push %rbx 400681: 48 83 ec 20 sub $0x20,%rsp 400685: 48 89 fb mov %rdi,%rbx 400688: 48 8d 7c 24 08 lea 0x8(%rsp),%rdi 400660: 48 89 f8 mov %rdi,%rax 400663: c7 47 04 02 00 00 00 movl $0x2,0x4(%rdi) 40066a: 48 c7 47 08 48 09 40 movq $0x400948,0x8(%rdi) 400672: 48 c7 47 10 21 00 00 movq $0x21,0x10(%rdi) 40067a: c3 retq 40067b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 400692: 0f b7 44 24 0c movzwl 0xc(%rsp),%eax 400697: a8 01 test $0x1,%al 400699: 74 4b je 4006e6 <test1()+0x66> 40069b: c7 05 97 19 20 00 00 movl $0x0,0x201997(%rip) # 60203c <foo> 4006a5: 8b 44 24 08 mov 0x8(%rsp),%eax 4006a9: 89 03 mov %eax,(%rbx) 4006ab: c7 43 04 01 00 00 00 movl $0x1,0x4(%rbx) 4006b2: 0f 57 c0 xorps %xmm0,%xmm0 4006b5: 0f 11 43 08 movups %xmm0,0x8(%rbx) 4006b9: 48 8b 7c 24 10 mov 0x10(%rsp),%rdi 4006be: 48 85 ff test %rdi,%rdi 4006c1: 74 10 je 4006d3 <test1()+0x53> 4006c3: 48 8d 74 24 10 lea 0x10(%rsp),%rsi 4006c8: 48 8b 07 mov (%rdi),%rax 4006cb: ba 10 00 00 00 mov $0x10,%edx 4006d0: ff 50 38 callq *0x38(%rax) 4006d3: 48 8d 7c 24 08 lea 0x8(%rsp),%rdi 400760: c3 retq 400761: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 40076b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 4006dd: 48 89 d8 mov %rbx,%rax 4006e0: 48 83 c4 20 add $0x20,%rsp 4006e4: 5b pop %rbx 4006e5: c3 retq 4006e6: 0f 10 44 24 10 movups 0x10(%rsp),%xmm0 4006eb: 48 c7 44 24 10 00 00 movq $0x0,0x10(%rsp) 4006f4: c7 43 04 02 00 00 00 movl $0x2,0x4(%rbx) 4006fb: 0f 11 43 08 movups %xmm0,0x8(%rbx) 4006ff: eb d2 jmp 4006d3 <test1()+0x53> 400701: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 40070b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
0
repos/outcome
repos/outcome/boostify/Readme.md
Build and tests passing: POSIX [![Build Status](https://drone.cpp.al/api/badges/boostorg/outcome/status.svg)](https://drone.cpp.al/boostorg/outcome) Boost's regression test matrix and history: https://www.boost.org/development/tests/develop/developer/outcome.html Documentation generated from the master branch shown below (may be newer than boost.org's): http://boostorg.github.io/outcome This is the Boost-ified edition of standalone https://github.com/ned14/outcome. Every commit made to standalone Outcome (develop and master branches only) gets automatically converted and merged to here. Note that changes made here may not get noticed in a timely fashion. Please try to send pull requests to https://github.com/ned14/outcome/pulls instead. Similarly, please report bugs to https://github.com/ned14/outcome/issues. This library works well in older Boosts missing Outcome. Installation into an older Boost and running the test suite would be as follows: ``` cd boost/libs git clone --depth 1 https://github.com/boostorg/outcome.git outcome cd .. ./b2 headers ./b2 libs/outcome/test cxxflags=--std=c++14 ```
0
repos/outcome
repos/outcome/boostify/CMakeLists.txt
# Generated by `boostdep --cmake outcome` # Copyright 2020 Peter Dimov # Distributed under the Boost Software License, Version 1.0. # https://www.boost.org/LICENSE_1_0.txt cmake_minimum_required(VERSION 3.5...3.16) project(boost_outcome VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) if (${PROJECT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) # Project is root. Find Boost source. set(BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.." CACHE STRING "Boost source dir to use when running CMake from this directory") if (NOT IS_ABSOLUTE ${BOOST_SRC_DIR}) set(BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${BOOST_SRC_DIR}") endif() set(BOOST_SRC_DIR_IS_VALID ON) foreach (F "CMakeLists.txt" "Jamroot" "boost-build.jam" "bootstrap.sh" "libs") if (NOT EXISTS "${BOOST_SRC_DIR}/${F}") message(STATUS "${BOOST_SRC_DIR}/${F} does not exist. Fallback to find_package.") set(BOOST_SRC_DIR_IS_VALID OFF) break() endif() endforeach() # Create Boost targets from source dir or boost package. set(BOOST_INCLUDE_LIBRARIES config exception system throw_exception test) if (BOOST_SRC_DIR_IS_VALID) set(BOOST_EXCLUDE_LIBRARIES ${PROJECT_NAME}) add_subdirectory(${BOOST_SRC_DIR} deps_/boost EXCLUDE_FROM_ALL) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${BOOST_SRC_DIR}/tools/cmake/include") else() find_package(Boost 1.81.0 REQUIRED) foreach (BOOST_INCLUDE_LIBRARY ${BOOST_INCLUDE_LIBRARIES}) add_library(Boost::${BOOST_INCLUDE_LIBRARY} ALIAS Boost::headers) endforeach () endif() endif() add_library(boost_outcome INTERFACE) add_library(Boost::outcome ALIAS boost_outcome) target_include_directories(boost_outcome INTERFACE include) target_link_libraries(boost_outcome INTERFACE Boost::config Boost::exception Boost::system Boost::throw_exception ) target_compile_features(boost_outcome INTERFACE cxx_std_14 ) if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11) target_compile_options(boost_outcome INTERFACE -ftemplate-depth=5000) endif () if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") enable_testing() add_subdirectory(test) endif()
0
repos/outcome
repos/outcome/boostify/.travis.yml
dist: trusty language: cpp compiler: - g++-6 sudo: false os: - linux branches: only: - master notifications: email: recipients: - [email protected] addons: apt: sources: - ubuntu-toolchain-r-test packages: - g++-6 env: - __="link=shared" FLAGS="link=shared" - __="link=static" FLAGS="link=static" cache: apt: true directories: - boost before_install: - if [ ! -f "boost/bootstrap.sh" ]; then wget -O boost.tar.bz2 https://dl.bintray.com/boostorg/release/1.71.0/source/boost_1_71_0.tar.bz2; tar xf boost.tar.bz2 -C boost; mv boost/boost_1_71_0 .; rm -rf boost; mv boost_1_71_0 boost; ls -l; ls -l boost; cd boost; ./bootstrap.sh; cd ..; fi; - rm -rf bin.v2/libs/outcome - rm -rf boost/boost/outcome - rm -rf boost/libs/outcome - ln -s ../.. boost/libs/outcome - ls -l boost/libs/outcome/ script: - if [ "$CXX" = "g++" ]; then FLAGS="$FLAGS toolset=gcc-6"; fi; - if [ "$CXX" = "clang++" ]; then FLAGS="$FLAGS toolset=clang-5.0 cxxflags=--std=c++14"; fi; - cd boost - ./b2 headers - ./b2 libs/outcome/test $FLAGS - rm -rf bin.v2/libs/outcome - rm -rf boost/libs/outcome after_success: after_failure:
0
repos/outcome/boostify/include
repos/outcome/boostify/include/boost/outcome.hpp
/* Include the default amount of outcome (C) 2018-2021 Niall Douglas <http://www.nedproductions.biz/> (4 commits) File Created: Mar 2018 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "outcome/coroutine_support.hpp" #include "outcome/iostream_support.hpp" #include "outcome/try.hpp"
0
repos/outcome/boostify/include/boost
repos/outcome/boostify/include/boost/outcome/config.hpp
/* Configure Boost.Outcome with Boost (C) 2015-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits) File Created: August 2015 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_OUTCOME_V2_CONFIG_HPP #define BOOST_OUTCOME_V2_CONFIG_HPP #include "detail/version.hpp" // Pull in detection of __MINGW64_VERSION_MAJOR #if defined(__MINGW32__) && !defined(DOXYGEN_IS_IN_THE_HOUSE) #include <_mingw.h> #endif #include <boost/config.hpp> #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES #error Boost.Outcome needs variadic template support in the compiler #endif #if defined(BOOST_NO_CXX14_CONSTEXPR) && _MSC_FULL_VER < 191100000 #error Boost.Outcome needs constexpr (C++ 14) support in the compiler #endif #ifdef BOOST_NO_CXX14_VARIABLE_TEMPLATES #error Boost.Outcome needs variable template support in the compiler #endif #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 6 #error Due to a bug in nested template variables parsing, Boost.Outcome does not work on GCCs earlier than v6. #endif #ifndef BOOST_OUTCOME_SYMBOL_VISIBLE #define BOOST_OUTCOME_SYMBOL_VISIBLE BOOST_SYMBOL_VISIBLE #endif #ifdef __has_cpp_attribute #define BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(attr) __has_cpp_attribute(attr) #else #define BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(attr) (0) #endif // Weird that Boost.Config doesn't define a BOOST_NO_CXX17_NODISCARD #ifndef BOOST_OUTCOME_NODISCARD #if BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(nodiscard) #define BOOST_OUTCOME_NODISCARD [[nodiscard]] #elif defined(__clang__) // deliberately not GCC #define BOOST_OUTCOME_NODISCARD __attribute__((warn_unused_result)) #elif defined(_MSC_VER) // _Must_inspect_result_ expands into this #define BOOST_OUTCOME_NODISCARD \ __declspec( \ "SAL_name" \ "(" \ "\"_Must_inspect_result_\"" \ "," \ "\"\"" \ "," \ "\"2\"" \ ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end") #endif #endif #ifndef BOOST_OUTCOME_NODISCARD #define BOOST_OUTCOME_NODISCARD #endif #ifndef BOOST_OUTCOME_THREAD_LOCAL #ifndef BOOST_NO_CXX11_THREAD_LOCAL #define BOOST_OUTCOME_THREAD_LOCAL thread_local #else #if defined(_MSC_VER) #define BOOST_OUTCOME_THREAD_LOCAL __declspec(thread) #elif defined(__GNUC__) #define BOOST_OUTCOME_THREAD_LOCAL __thread #else #error Unknown compiler, cannot set BOOST_OUTCOME_THREAD_LOCAL #endif #endif #endif // Can't use the QuickCppLib preprocessor metaprogrammed Concepts TS support, so ... #ifndef BOOST_OUTCOME_TEMPLATE #define BOOST_OUTCOME_TEMPLATE(...) template <__VA_ARGS__ #endif #ifndef BOOST_OUTCOME_TREQUIRES #define BOOST_OUTCOME_TREQUIRES(...) , __VA_ARGS__ > #endif #ifndef BOOST_OUTCOME_TEXPR #define BOOST_OUTCOME_TEXPR(...) typename = decltype(__VA_ARGS__) #endif #ifndef BOOST_OUTCOME_TPRED #define BOOST_OUTCOME_TPRED(...) typename = std::enable_if_t<__VA_ARGS__> #endif #ifndef BOOST_OUTCOME_REQUIRES #if defined(__cpp_concepts) && (!defined(_MSC_VER) || _MSC_FULL_VER >= 192400000) // VS 2019 16.3 is broken here #define BOOST_OUTCOME_REQUIRES(...) requires(__VA_ARGS__) #else #define BOOST_OUTCOME_REQUIRES(...) #endif #endif #ifndef BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR #define BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR 220 // the v2.2 Outcome release #endif namespace boost { #define BOOST_OUTCOME_V2 //! The Boost.Outcome namespace namespace outcome_v2 { } } /*! The namespace of this Boost.Outcome v2. */ #define BOOST_OUTCOME_V2_NAMESPACE boost::outcome_v2 /*! Expands into the appropriate namespace markup to enter the Boost.Outcome v2 namespace. */ #define BOOST_OUTCOME_V2_NAMESPACE_BEGIN \ namespace boost \ { \ namespace outcome_v2 \ { /*! Expands into the appropriate namespace markup to enter the C++ module exported Boost.Outcome v2 namespace. */ #define BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN \ namespace boost \ { \ namespace outcome_v2 \ { /*! \brief Expands into the appropriate namespace markup to exit the Boost.Outcome v2 namespace. \ingroup config */ #define BOOST_OUTCOME_V2_NAMESPACE_END \ } \ } #include <cstdint> // for uint32_t etc #include <initializer_list> #include <iosfwd> // for future serialisation #include <new> // for placement in moves etc #include <type_traits> #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE #if defined(_MSC_VER) && _HAS_CXX17 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type #elif __cplusplus >= 201700 // libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support #ifdef __has_include #if !__has_include(<variant>) #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present #endif #endif #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1 #endif #else #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0 #endif #endif #if BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE #include <utility> // for in_place_type_t BOOST_OUTCOME_V2_NAMESPACE_BEGIN template <class T> using in_place_type_t = std::in_place_type_t<T>; using std::in_place_type; BOOST_OUTCOME_V2_NAMESPACE_END #else BOOST_OUTCOME_V2_NAMESPACE_BEGIN //! Aliases `std::in_place_type_t<T>` if on C++ 17 or later, else defined locally. template <class T> struct in_place_type_t { explicit in_place_type_t() = default; }; //! Aliases `std::in_place_type<T>` if on C++ 17 or later, else defined locally. template <class T> constexpr in_place_type_t<T> in_place_type{}; BOOST_OUTCOME_V2_NAMESPACE_END #endif #if defined(BOOST_OUTCOME_USE_STD_ADDRESSOF) && !BOOST_OUTCOME_USE_STD_ADDRESSOF #define BOOST_OUTCOME_ADDRESS_OF(...) (&__VA_ARGS__) #else #include <memory> // for std::addressof #define BOOST_OUTCOME_ADDRESS_OF(...) std::addressof(__VA_ARGS__) #endif #ifndef BOOST_OUTCOME_ASSERT #include <boost/assert.hpp> #define BOOST_OUTCOME_ASSERT(...) BOOST_ASSERT(__VA_ARGS__) #endif #ifndef BOOST_OUTCOME_TRIVIAL_ABI #if defined(STANDARDESE_IS_IN_THE_HOUSE) || __clang_major__ >= 7 //! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden. #define BOOST_OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]] #else #define BOOST_OUTCOME_TRIVIAL_ABI #endif #endif BOOST_OUTCOME_V2_NAMESPACE_BEGIN namespace detail { // Test if type is an in_place_type_t template <class T> struct is_in_place_type_t { static constexpr bool value = false; }; template <class U> struct is_in_place_type_t<in_place_type_t<U>> { static constexpr bool value = true; }; // Replace void with constructible void_type struct empty_type { }; struct void_type { // We always compare true to another instance of me constexpr bool operator==(void_type /*unused*/) const noexcept { return true; } constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; } }; template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>; template <class Output, class Input> using rebind_type5 = Output; template <class Output, class Input> using rebind_type4 = std::conditional_t< // std::is_volatile<Input>::value, // std::add_volatile_t<rebind_type5<Output, std::remove_volatile_t<Input>>>, // rebind_type5<Output, Input>>; template <class Output, class Input> using rebind_type3 = std::conditional_t< // std::is_const<Input>::value, // std::add_const_t<rebind_type4<Output, std::remove_const_t<Input>>>, // rebind_type4<Output, Input>>; template <class Output, class Input> using rebind_type2 = std::conditional_t< // std::is_lvalue_reference<Input>::value, // std::add_lvalue_reference_t<rebind_type3<Output, std::remove_reference_t<Input>>>, // rebind_type3<Output, Input>>; template <class Output, class Input> using rebind_type = std::conditional_t< // std::is_rvalue_reference<Input>::value, // std::add_rvalue_reference_t<rebind_type2<Output, std::remove_reference_t<Input>>>, // rebind_type2<Output, Input>>; // static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, ""); /* True if type is the same or constructible. Works around a bug where clang + libstdc++ pukes on std::is_constructible<filesystem::path, void> (this bug is fixed upstream). */ template <class T, class U> struct _is_explicitly_constructible { static constexpr bool value = std::is_constructible<T, U>::value; }; template <class T> struct _is_explicitly_constructible<T, void> { static constexpr bool value = false; }; template <> struct _is_explicitly_constructible<void, void> { static constexpr bool value = false; }; template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value; template <class T, class U> struct _is_implicitly_constructible { static constexpr bool value = std::is_convertible<U, T>::value; }; template <class T> struct _is_implicitly_constructible<T, void> { static constexpr bool value = false; }; template <> struct _is_implicitly_constructible<void, void> { static constexpr bool value = false; }; template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value; template <class T, class... Args> struct _is_nothrow_constructible { static constexpr bool value = std::is_nothrow_constructible<T, Args...>::value; }; template <class T> struct _is_nothrow_constructible<T, void> { static constexpr bool value = false; }; template <> struct _is_nothrow_constructible<void, void> { static constexpr bool value = false; }; template <class T, class... Args> static constexpr bool is_nothrow_constructible = _is_nothrow_constructible<T, Args...>::value; template <class T, class... Args> struct _is_constructible { static constexpr bool value = std::is_constructible<T, Args...>::value; }; template <class T> struct _is_constructible<T, void> { static constexpr bool value = false; }; template <> struct _is_constructible<void, void> { static constexpr bool value = false; }; template <class T, class... Args> static constexpr bool is_constructible = _is_constructible<T, Args...>::value; #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE #if defined(_MSC_VER) && _HAS_CXX17 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable #elif __cplusplus >= 201700 // libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support #ifdef __has_include #if !__has_include(<variant>) #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0 // must have it if <variant> is present #endif #endif #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 #endif #else #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0 #endif #endif // True if type is nothrow swappable #if !defined(STANDARDESE_IS_IN_THE_HOUSE) && BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE template <class T> using is_nothrow_swappable = std::is_nothrow_swappable<T>; #else template <class T> struct is_nothrow_swappable { static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value; }; #endif } // namespace detail BOOST_OUTCOME_V2_NAMESPACE_END #ifndef BOOST_OUTCOME_THROW_EXCEPTION #include <boost/throw_exception.hpp> #define BOOST_OUTCOME_THROW_EXCEPTION(expr) BOOST_THROW_EXCEPTION(expr) #endif #ifndef BOOST_OUTCOME_AUTO_TEST_CASE #define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a) #endif #endif
0
repos/outcome/boostify/include/boost
repos/outcome/boostify/include/boost/outcome/outcome.hpp
/* A less simple result type (C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (1 commit) File Created: June 2017 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_OUTCOME_OUTCOME_HPP #define BOOST_OUTCOME_OUTCOME_HPP #include "result.hpp" #include "boost_outcome.hpp" BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN /*! In standalone Outcome, this aliases `std_outcome<>`. In Boost.Outcome, this aliases `boost_outcome<>`. */ template <class R, class S = boost::system::error_code, class P = boost::exception_ptr, class NoValuePolicy = policy::default_policy<R, S, P>> // using outcome = boost_outcome<R, S, P, NoValuePolicy>; BOOST_OUTCOME_V2_NAMESPACE_END #endif
0
repos/outcome/boostify/include/boost
repos/outcome/boostify/include/boost/outcome/result.hpp
/* A very simple result type (C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (2 commits) File Created: June 2017 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_OUTCOME_RESULT_HPP #define BOOST_OUTCOME_RESULT_HPP #include "boost_result.hpp" BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN /*! In standalone Outcome, this aliases `std_result<>`. In Boost.Outcome, this aliases `boost_result<>`. */ template <class R, class S = boost::system::error_code, class NoValuePolicy = policy::default_policy<R, S, void>> // using result = boost_result<R, S, NoValuePolicy>; /*! In standalone Outcome, this aliases `std_unchecked<>`. In Boost.Outcome, this aliases `boost_checked<>`. */ template <class R, class S = boost::system::error_code> using unchecked = result<R, S, policy::all_narrow>; /*! In standalone Outcome, this aliases `std_checked<>`. In Boost.Outcome, this aliases `boost_checked<>`. */ template <class R, class S = boost::system::error_code> using checked = result<R, S, policy::throw_bad_result_access<S, void>>; BOOST_OUTCOME_V2_NAMESPACE_END #endif
0
repos/outcome/boostify
repos/outcome/boostify/.drone/drone.sh
#!/bin/bash # Copyright 2020 Rene Rivera, Sam Darwin # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.txt or copy at http://boost.org/LICENSE_1_0.txt) set -e export DRONE_BUILD_DIR=$(pwd) export VCS_COMMIT_ID=$DRONE_COMMIT export GIT_COMMIT=$DRONE_COMMIT export REPO_NAME=$DRONE_REPO export USER=$(whoami) export CC=${CC:-gcc} export PATH=~/.local/bin:/usr/local/bin:$PATH export TRAVIS_BUILD_DIR=$(pwd) export TRAVIS_BRANCH=$DRONE_BRANCH export TRAVIS_EVENT_TYPE=$DRONE_BUILD_EVENT common_install () { git clone https://github.com/boostorg/boost-ci.git boost-ci-cloned --depth 1 [ "$(basename $REPO_NAME)" == "boost-ci" ] || cp -prf boost-ci-cloned/ci . rm -rf boost-ci-cloned if [ "$TRAVIS_OS_NAME" == "osx" ]; then unset -f cd fi export BOOST_CI_TARGET_BRANCH="$TRAVIS_BRANCH" export BOOST_CI_SRC_FOLDER=$(pwd) . ./ci/common_install.sh } if [ "$DRONE_JOB_BUILDTYPE" == "boost" ]; then echo '==================================> INSTALL' common_install echo '==================================> SCRIPT' . $BOOST_ROOT/libs/$SELF/ci/build.sh elif [ "$DRONE_JOB_BUILDTYPE" == "codecov" ]; then echo '==================================> INSTALL' common_install echo '==================================> SCRIPT' cd $BOOST_ROOT/libs/$SELF ci/travis/codecov.sh elif [ "$DRONE_JOB_BUILDTYPE" == "valgrind" ]; then echo '==================================> INSTALL' common_install echo '==================================> SCRIPT' cd $BOOST_ROOT/libs/$SELF ci/travis/valgrind.sh elif [ "$DRONE_JOB_BUILDTYPE" == "coverity" ]; then echo '==================================> INSTALL' common_install echo '==================================> SCRIPT' if [ -n "${COVERITY_SCAN_NOTIFICATION_EMAIL}" -a \( "$TRAVIS_BRANCH" = "develop" -o "$TRAVIS_BRANCH" = "master" \) -a \( "$DRONE_BUILD_EVENT" = "push" -o "$DRONE_BUILD_EVENT" = "cron" \) ] ; then cd $BOOST_ROOT/libs/$SELF ci/travis/coverity.sh fi fi
0
repos/outcome/boostify
repos/outcome/boostify/meta/explicit-failures-markup.xml
<?xml version="1.0" encoding="utf-8"?> <explicit-failures-markup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/boostorg/boost/master/status/explicit-failures.xsd"> <!-- outcome --> <library name="outcome"> <mark-unusable> <toolset name="*c++98"/> <toolset name="*c++11"/> <toolset name="*gnu++98"/> <toolset name="*gnu++11"/> <toolset name="*gnu98"/> <toolset name="*gnu11"/> <toolset name="clang-linux-3*"/> <toolset name="gcc-3*"/> <toolset name="gcc-4*"/> <toolset name="gcc-5*"/> <toolset name="gcc-mngw-3*"/> <toolset name="gcc-mngw-4*"/> <toolset name="gcc-mngw-5*"/> <toolset name="msvc-7*"/> <toolset name="msvc-8*"/> <toolset name="msvc-9*"/> <toolset name="msvc-10*"/> <toolset name="msvc-11*"/> <toolset name="msvc-12*"/> <toolset name="msvc-13*"/> <toolset name="msvc-14.0"/> <toolset name="msvc-14.0*"/> <note author="Niall Douglas">Complete C++14 support is the minimum requirement.</note> </mark-unusable> <mark-unusable> <toolset name="clang-linux-4.0~c++14"/> <toolset name="clang-linux-5.0~c++14"/> <toolset name="clang-linux-6.0~c++17"/> <note author="Niall Douglas">libstdc++ 6 is the minimum version which works.</note> </mark-unusable> <mark-unusable> <toolset name="gcc-6*"/> <note author="Niall Douglas">Tests are unstable on GCC 6.</note> </mark-unusable> <mark-unusable> <toolset name="msvc-14.1"/> <toolset name="msvc-14.1*"/> <toolset name="msvc-14.2"/> <toolset name="msvc-14.2*"/> <note author="Niall Douglas">Tests are unstable on VS2017 and VS2019.</note> </mark-unusable> </library> </explicit-failures-markup>
0
repos/outcome/boostify
repos/outcome/boostify/meta/libraries.json
{ "key": "outcome", "name": "Outcome", "authors": [ "Niall Douglas" ], "maintainers": [ "Niall Douglas <s -underscore- sourceforge -at- nedprod -dot- com>" ], "description": "A deterministic failure handling library partially simulating lightweight exceptions.", "std": [ "proposal" ], "category": [ "Patterns", "Emulation", "Programming" ], "cxxstd": "14" }
0
repos/outcome/boostify
repos/outcome/boostify/test/CMakeLists.txt
# Distributed under the Boost Software License, Version 1.0. # https://www.boost.org/LICENSE_1_0.txt include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST) if(NOT HAVE_BOOST_TEST) return() endif() set(BOOST_TEST_LINK_LIBRARIES Boost::outcome) boost_test(TYPE compile-fail SOURCES "compile-fail/issue0071-fail.cpp") boost_test(TYPE compile-fail SOURCES "compile-fail/outcome-int-int-1.cpp") boost_test(TYPE compile-fail SOURCES "compile-fail/result-int-int-1.cpp") boost_test(TYPE compile-fail SOURCES "compile-fail/result-int-int-2.cpp") set(BOOST_TEST_LINK_LIBRARIES Boost::outcome Boost::unit_test_framework) set(BOOST_TEST_COMPILE_DEFINITIONS BOOST_TEST_MODULE=Outcome) boost_test(TYPE run SOURCES "tests/comparison.cpp") boost_test(TYPE run SOURCES "tests/constexpr.cpp") boost_test(TYPE run SOURCES "tests/containers.cpp") boost_test(TYPE run SOURCES "tests/core-outcome.cpp") boost_test(TYPE run SOURCES "tests/core-result.cpp") boost_test(TYPE run SOURCES "tests/default-construction.cpp") boost_test(TYPE run SOURCES "tests/experimental-core-outcome-status.cpp") boost_test(TYPE run SOURCES "tests/experimental-core-result-status.cpp") boost_test(TYPE run SOURCES "tests/experimental-p0709a.cpp") boost_test(TYPE run SOURCES "tests/fileopen.cpp") boost_test(TYPE run SOURCES "tests/hooks.cpp") boost_test(TYPE run SOURCES "tests/issue0007.cpp") boost_test(TYPE run SOURCES "tests/issue0009.cpp") boost_test(TYPE run SOURCES "tests/issue0010.cpp") boost_test(TYPE run SOURCES "tests/issue0012.cpp") boost_test(TYPE run SOURCES "tests/issue0016.cpp") boost_test(TYPE run SOURCES "tests/issue0059.cpp") boost_test(TYPE run SOURCES "tests/issue0061.cpp") boost_test(TYPE run SOURCES "tests/issue0064.cpp") boost_test(TYPE run SOURCES "tests/issue0065.cpp") boost_test(TYPE run SOURCES "tests/issue0071.cpp") boost_test(TYPE run SOURCES "tests/issue0095.cpp") boost_test(TYPE run SOURCES "tests/issue0115.cpp") boost_test(TYPE run SOURCES "tests/issue0116.cpp") boost_test(TYPE run SOURCES "tests/issue0140.cpp") #boost_test(TYPE run SOURCES "tests/issue0182.cpp") ## not applicable to Boost boost_test(TYPE run SOURCES "tests/issue0203.cpp") boost_test(TYPE run SOURCES "tests/issue0210.cpp") boost_test(TYPE run SOURCES "tests/issue0220.cpp") boost_test(TYPE run SOURCES "tests/issue0244.cpp") boost_test(TYPE run SOURCES "tests/issue0247.cpp") boost_test(TYPE run SOURCES "tests/noexcept-propagation.cpp") boost_test(TYPE run SOURCES "tests/propagate.cpp") boost_test(TYPE run SOURCES "tests/serialisation.cpp") boost_test(TYPE run SOURCES "tests/success-failure.cpp") boost_test(TYPE run SOURCES "tests/swap.cpp") boost_test(TYPE run SOURCES "tests/udts.cpp") boost_test(TYPE run SOURCES "tests/value-or-error.cpp") boost_test(TYPE run SOURCES "expected-pass.cpp")
0
repos/outcome/boostify
repos/outcome/boostify/doc/Readme.md
Note that the html documentation is generated from the Markdown in src by a Travis job on standalone https://github.com/ned14/outcome. Please send pull requests fixing documentation issues to https://github.com/ned14/outcome/pulls.
0
repos/outcome/boostify/doc
repos/outcome/boostify/doc/src/config.toml
theme = "boostdoc" title = "Boost.Outcome documentation" publishDir = "../html" pygmentsStyle = "vs" pygmentsUseClasses = true PygmentsCodeFences = true enableGitInfo = true disableKinds = [ "RSS", "404" ] relativeURLs = true uglyURLs = true [outputs] home = [ "HTML" ] [params] snippetsURL = "https://github.com/boostorg/outcome/tree/master/doc/src/snippets/" editURL = "https://github.com/boostorg/outcome/edit/develop/doc/src/content/"
0
repos/outcome
repos/outcome/cmake/interface.cmake
# DO NOT EDIT, GENERATED BY SCRIPT set(outcome_INTERFACE "include/outcome.hpp" "include/outcome/outcome.natvis" ) # DO NOT EDIT, GENERATED BY SCRIPT set(outcome_INTERFACE_SOURCE "include/outcome.ixx" )
0
repos/outcome
repos/outcome/cmake/tests.cmake
# DO NOT EDIT, GENERATED BY SCRIPT set(outcome_TESTS "test/expected-pass.cpp" "test/single-header-test.cpp" "test/tests/comparison.cpp" "test/tests/constexpr.cpp" "test/tests/containers.cpp" "test/tests/core-outcome.cpp" "test/tests/core-result.cpp" "test/tests/coroutine-support.cpp" "test/tests/default-construction.cpp" "test/tests/experimental-c-result.cpp" "test/tests/experimental-core-outcome-status.cpp" "test/tests/experimental-core-result-status.cpp" "test/tests/experimental-p0709a.cpp" "test/tests/fileopen.cpp" "test/tests/hooks.cpp" "test/tests/issue0007.cpp" "test/tests/issue0009.cpp" "test/tests/issue0010.cpp" "test/tests/issue0012.cpp" "test/tests/issue0016.cpp" "test/tests/issue0059.cpp" "test/tests/issue0061.cpp" "test/tests/issue0064.cpp" "test/tests/issue0065.cpp" "test/tests/issue0071.cpp" "test/tests/issue0095.cpp" "test/tests/issue0115.cpp" "test/tests/issue0116.cpp" "test/tests/issue0140.cpp" "test/tests/issue0182.cpp" "test/tests/issue0203.cpp" "test/tests/issue0210.cpp" "test/tests/issue0220.cpp" "test/tests/issue0244.cpp" "test/tests/issue0247.cpp" "test/tests/issue0255.cpp" "test/tests/issue0259.cpp" "test/tests/issue0291.cpp" "test/tests/noexcept-propagation.cpp" "test/tests/propagate.cpp" "test/tests/serialisation.cpp" "test/tests/success-failure.cpp" "test/tests/swap.cpp" "test/tests/udts.cpp" "test/tests/value-or-error.cpp" ) # DO NOT EDIT, GENERATED BY SCRIPT set(outcome_COMPILE_TESTS ) # DO NOT EDIT, GENERATED BY SCRIPT set(outcome_COMPILE_FAIL_TESTS "test/compile-fail/issue0071-fail.cpp" "test/compile-fail/outcome-int-int-1.cpp" "test/compile-fail/result-int-int-1.cpp" "test/compile-fail/result-int-int-2.cpp" )
0
repos/outcome
repos/outcome/cmake/QuickCppLibBootstrap.cmake
# QuickCppLib cmake # (C) 2016-2019 Niall Douglas <http://www.nedproductions.biz/> # # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License in the accompanying file # Licence.txt or at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # # Distributed under the Boost Software License, Version 1.0. # (See accompanying file Licence.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) cmake_minimum_required(VERSION 3.5 FATAL_ERROR) # If necessary bring in the quickcpplib cmake tooling set(quickcpplib_done OFF) foreach(item ${CMAKE_MODULE_PATH}) if(item MATCHES "quickcpplib/cmakelib") set(quickcpplib_done ON) endif() endforeach() if(NOT quickcpplib_done) find_package(quickcpplib QUIET CONFIG) if(quickcpplib_FOUND) if(DEFINED quickcpplib_CMAKELIB_DIR AND DEFINED quickcpplib_SCRIPTS_DIR) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${quickcpplib_CMAKELIB_DIR}") set(CTEST_QUICKCPPLIB_SCRIPTS "${quickcpplib_SCRIPTS_DIR}") set(quickcpplib_done ON) elseif(EXISTS "${quickcpplib_DIR}/share/cmakelib") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${quickcpplib_DIR}/share/cmakelib") set(CTEST_QUICKCPPLIB_SCRIPTS "${quickcpplib_DIR}/share/scripts") set(quickcpplib_done ON) elseif(EXISTS "${quickcpplib_DIR}/../../../share/cmakelib") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${quickcpplib_DIR}/../../../share/cmakelib") set(CTEST_QUICKCPPLIB_SCRIPTS "${quickcpplib_DIR}/../../../share/scripts") set(quickcpplib_done ON) endif() endif() endif() #message("*** ${CMAKE_MODULE_PATH}") if(NOT quickcpplib_done) # CMAKE_SOURCE_DIR is the very topmost parent cmake project # CMAKE_CURRENT_SOURCE_DIR is the current cmake subproject if(NOT DEFINED CTEST_QUICKCPPLIB_CLONE_DIR) if(EXISTS "${CMAKE_SOURCE_DIR}/../.quickcpplib_use_siblings" AND NOT QUICKCPPLIB_DISABLE_SIBLINGS) # If there is a magic .quickcpplib_use_siblings directory above the topmost project, use sibling edition set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../quickcpplib/cmakelib") set(CTEST_QUICKCPPLIB_SCRIPTS "${CMAKE_SOURCE_DIR}/../quickcpplib/scripts") # Copy latest version of myself into end user file(COPY "${CTEST_QUICKCPPLIB_SCRIPTS}/../cmake/QuickCppLibBootstrap.cmake" DESTINATION "${CMAKE_SOURCE_DIR}/cmake/") elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../.quickcpplib_use_siblings" AND NOT QUICKCPPLIB_DISABLE_SIBLINGS) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../quickcpplib/cmakelib") set(CTEST_QUICKCPPLIB_SCRIPTS "${CMAKE_CURRENT_SOURCE_DIR}/../quickcpplib/scripts") elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib/repo/cmakelib") set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib") elseif(CMAKE_BINARY_DIR) # Place into root binary directory, same place as where find_quickcpplib_library() puts dependencies. set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_BINARY_DIR}/quickcpplib") else() # We must be being called from a ctest script. No way of knowing what the build directory # will be, so simply clone into the current directory set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib") endif() endif() if(CTEST_QUICKCPPLIB_CLONE_DIR) if(NOT EXISTS "${CTEST_QUICKCPPLIB_CLONE_DIR}/repo/cmakelib") file(MAKE_DIRECTORY "${CTEST_QUICKCPPLIB_CLONE_DIR}") message(STATUS "quickcpplib not found, cloning git repository and installing into ${CTEST_QUICKCPPLIB_CLONE_DIR} ...") include(FindGit) execute_process(COMMAND "${GIT_EXECUTABLE}" clone --recurse-submodules --depth 1 --jobs 8 --shallow-submodules "https://github.com/ned14/quickcpplib.git" repo WORKING_DIRECTORY "${CTEST_QUICKCPPLIB_CLONE_DIR}" OUTPUT_VARIABLE cloneout ERROR_VARIABLE errout ) if(NOT EXISTS "${CTEST_QUICKCPPLIB_CLONE_DIR}/repo/cmakelib") message(FATAL_ERROR "FATAL: Failed to git clone quickcpplib!\n\nstdout was: ${cloneout}\n\nstderr was: ${errout}\n\nIf you are in a build environment which prevents use of the internet during superbuild, please place a clone of quickcpplib into '${CTEST_QUICKCPPLIB_CLONE_DIR}/repo' i.e. as if 'cd \"${CTEST_QUICKCPPLIB_CLONE_DIR}\" && git clone --recursive \"https://github.com/ned14/quickcpplib.git\" repo'. You can also predefine CTEST_QUICKCPPLIB_CLONE_DIR to point at a copy of quickcpplib during cmake configuration.") endif() endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CTEST_QUICKCPPLIB_CLONE_DIR}/repo/cmakelib") set(CTEST_QUICKCPPLIB_SCRIPTS "${CTEST_QUICKCPPLIB_CLONE_DIR}/repo/scripts") endif() endif()
0
repos/outcome
repos/outcome/cmake/headers.cmake
# DO NOT EDIT, GENERATED BY SCRIPT set(outcome_HEADERS "include/outcome.hpp" "include/outcome/bad_access.hpp" "include/outcome/basic_outcome.hpp" "include/outcome/basic_result.hpp" "include/outcome/boost_outcome.hpp" "include/outcome/boost_result.hpp" "include/outcome/config.hpp" "include/outcome/convert.hpp" "include/outcome/coroutine_support.hpp" "include/outcome/detail/basic_outcome_exception_observers.hpp" "include/outcome/detail/basic_outcome_exception_observers_impl.hpp" "include/outcome/detail/basic_outcome_failure_observers.hpp" "include/outcome/detail/basic_result_error_observers.hpp" "include/outcome/detail/basic_result_final.hpp" "include/outcome/detail/basic_result_storage.hpp" "include/outcome/detail/basic_result_value_observers.hpp" "include/outcome/detail/coroutine_support.ipp" "include/outcome/detail/revision.hpp" "include/outcome/detail/trait_std_error_code.hpp" "include/outcome/detail/trait_std_exception.hpp" "include/outcome/detail/try.h" "include/outcome/detail/value_storage.hpp" "include/outcome/detail/version.hpp" "include/outcome/experimental/coroutine_support.hpp" "include/outcome/experimental/result.h" "include/outcome/experimental/status-code/include/status-code/boost_error_code.hpp" "include/outcome/experimental/status-code/include/status-code/com_code.hpp" "include/outcome/experimental/status-code/include/status-code/config.hpp" "include/outcome/experimental/status-code/include/status-code/detail/nt_code_to_generic_code.ipp" "include/outcome/experimental/status-code/include/status-code/detail/nt_code_to_win32_code.ipp" "include/outcome/experimental/status-code/include/status-code/detail/win32_code_to_generic_code.ipp" "include/outcome/experimental/status-code/include/status-code/error.hpp" "include/outcome/experimental/status-code/include/status-code/errored_status_code.hpp" "include/outcome/experimental/status-code/include/status-code/generic_code.hpp" "include/outcome/experimental/status-code/include/status-code/getaddrinfo_code.hpp" "include/outcome/experimental/status-code/include/status-code/http_status_code.hpp" "include/outcome/experimental/status-code/include/status-code/iostream_support.hpp" "include/outcome/experimental/status-code/include/status-code/nested_status_code.hpp" "include/outcome/experimental/status-code/include/status-code/nt_code.hpp" "include/outcome/experimental/status-code/include/status-code/posix_code.hpp" "include/outcome/experimental/status-code/include/status-code/quick_status_code_from_enum.hpp" "include/outcome/experimental/status-code/include/status-code/result.hpp" "include/outcome/experimental/status-code/include/status-code/status_code.hpp" "include/outcome/experimental/status-code/include/status-code/status_code_domain.hpp" "include/outcome/experimental/status-code/include/status-code/status_error.hpp" "include/outcome/experimental/status-code/include/status-code/std_error_code.hpp" "include/outcome/experimental/status-code/include/status-code/system_code.hpp" "include/outcome/experimental/status-code/include/status-code/system_code_from_exception.hpp" "include/outcome/experimental/status-code/include/status-code/system_error2.hpp" "include/outcome/experimental/status-code/include/status-code/win32_code.hpp" "include/outcome/experimental/status-code/single-header/system_error2.hpp" "include/outcome/experimental/status_outcome.hpp" "include/outcome/experimental/status_result.hpp" "include/outcome/iostream_support.hpp" "include/outcome/outcome.hpp" "include/outcome/outcome.natvis" "include/outcome/outcome_gdb.h" "include/outcome/policy/all_narrow.hpp" "include/outcome/policy/base.hpp" "include/outcome/policy/fail_to_compile_observers.hpp" "include/outcome/policy/outcome_error_code_throw_as_system_error.hpp" "include/outcome/policy/outcome_exception_ptr_rethrow.hpp" "include/outcome/policy/result_error_code_throw_as_system_error.hpp" "include/outcome/policy/result_exception_ptr_rethrow.hpp" "include/outcome/policy/terminate.hpp" "include/outcome/policy/throw_bad_result_access.hpp" "include/outcome/result.hpp" "include/outcome/std_outcome.hpp" "include/outcome/std_result.hpp" "include/outcome/success_failure.hpp" "include/outcome/trait.hpp" "include/outcome/try.hpp" "include/outcome/utils.hpp" )
0
repos/outcome
repos/outcome/cmake/toolchain-linux-libc++.cmake
set(CMAKE_C_COMPILER clang-11) set(CMAKE_CXX_COMPILER clang++-11) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++ -fcoroutines-ts") set(CMAKE_EXE_LINKER_FLAGS_INIT "-stdlib=libc++") set(CMAKE_MODULE_LINKER_FLAGS_INIT "-stdlib=libc++") set(CMAKE_SHARED_LINKER_FLAGS_INIT "-stdlib=libc++")
0
repos/outcome/doc
repos/outcome/doc/presentations/videos.txt
20170429, ACCU, Mongrel Monads, Dirty, dirty, dirty Covers the history of error handling in C++, and how the LEWG Expected works. Slides: https://docs.google.com/presentation/d/1X_3VOxb8PMGXHBzjmzl5oVnwYVIyBpZHcY0Idv_9tSc/edit?usp=sharing Video: https://youtu.be/XVofgKH-uu4 20171110, Meeting C++, Introduction to proposed std::expected<T, E> Literature review of the several WG21 papers relating to std::expected<T, E> Slides: https://docs.google.com/presentation/d/1XTsnsGIV4HTh_07bjpCk_XG2NWDs6Tlrw8f5rrUHodc/edit?usp=sharing Video: https://www.youtube.com/watch?v=JfMBLx7qE0I 20180917, Dublin C++ users group, Deterministic Disappointment Literature review of the WG21 papers relating to deterministically handling failure, and using libraries such as Outcome to implement the same. Slides: https://docs.google.com/presentation/d/1fSkpD51FKmy8VEO9P86jWN6tOEaBmzHOXo14zLRkFKE/edit?usp=sharing Video: https://www.youtube.com/watch?v=cbUTAoHy6Ls
0
repos/outcome/doc
repos/outcome/doc/src/config.toml
theme = "docdock" baseURL = "https://ned14.github.io/outcome/" title = "Outcome documentation" publishDir = "../html" pygmentsStyle = "vs" pygmentsUseClasses = true PygmentsCodeFences = true enableGitInfo = true [blackfriday] fractions = false [outputs] home = [ "HTML", "RSS", "JSON"] [params] snippetsURL = "https://github.com/ned14/outcome/tree/master/doc/src/snippets/" editURL = "https://github.com/ned14/outcome/edit/develop/doc/src/content/" [[menu.shortcuts]] pre = "<h3>More</h3>" name = "<i class='fa fa-github'></i> Outcome 2.2 github repo" identifier = "ds" url = "https://github.com/ned14/outcome" weight = 10 [[menu.shortcuts]] name = "<i class='fa fa-bullhorn'></i> Acknowledgements" url = "/credits" weight = 30
0
repos/outcome/doc/src/static
repos/outcome/doc/src/static/css/local.css
body { text-align: justify; } h2, h3, h4, h5, h6 { text-align: left; } article section.page h1:first-of-type { font-weight: 900; text-transform: inherit; line-height: 3.25rem; } article > aside .menu { text-align: left; } article > aside .menu code { border-left: 0.25em solid transparent; border-right: 0.25em solid transparent; } h1 { font-weight: inherit; line-height: 3.25rem; } h2 { text-transform: none; font-weight: inherit; line-height: 2.55rem; } h4 { line-height: 1.9rem; font-size: small; } dd { margin-inline-start: 40px; } blockquote { border-left: 4px solid #ccc; background: #f9f9f9; font-style: italic; padding-left: 4em; padding-right: 4em; quotes: "\201C""\201D""\2018""\2019"; } figure figcaption { margin-top: -2em; } figure figcaption h4 { text-align: center; } code, pre { text-align: left; } a code { color: inherit; } a.api-reference { font-family: monospace; } div.footnotes { font-size: 85%; } article section.page pre .copy-to-clipboard { background-color: #eee; } div.code-snippet { position: relative; } div.code-snippet a.code-snippet-url { font-size: small; position: absolute; right: 3em; top: 0.7em; } /*nav#TableOfContents { width: 30em; float: right; text-align: left; font-size: inherit !important; } nav#TableOfContents > ul { list-style: none; } nav#TableOfContents > ul > li > ul { border-radius: 5px; box-shadow: 0px 0px 10px #000000; background-color: white; padding-right: 1em; list-style-type: lower-roman; } nav#TableOfContents > ul > li > ul > li { line-height: normal; margin-top: 0.25em; margin-bottom: 0.25em; } nav#TableOfContents > ul > li > ul > li > a.highlight { display: inline; } nav#TableOfContents > ul > li > ul > li > a.highlight code { vertical-align: inherit; }*/ #navigation a { color: blue; } .children p { font-size: small; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; } .children-li p { font-size: small; font-style: italic; } ol.children li { margin-top: 0.75em; } ol.children ol { list-style-type: lower-alpha; } ol.children ol li { margin-top: 0; } /* Background */ .chroma { background-color: #ffffff } /* Error */ .chroma .err { } /* LineTableTD */ .chroma .lntd { ; vertical-align: top; padding: 0; margin: 0; border: 0; } /* LineTable */ .chroma .lntable { ; border-spacing: 0; padding: 0; margin: 0; border: 0; width: 100%; overflow: auto; display: block; } /* LineHighlight */ .chroma .hl { background-color: #ffffcc; display: block; width: 100% } /* LineNumbersTable */ .chroma .lnt { ; margin-right: 0.4em; padding: 0 0.4em 0 0.4em; display: block; } /* LineNumbers */ .chroma .ln { ; margin-right: 0.4em; padding: 0 0.4em 0 0.4em; } /* Keyword */ .chroma .k { color: #0000ff } /* KeywordConstant */ .chroma .kc { color: #0000ff } /* KeywordDeclaration */ .chroma .kd { color: #0000ff } /* KeywordNamespace */ .chroma .kn { color: #0000ff } /* KeywordPseudo */ .chroma .kp { color: #0000ff } /* KeywordReserved */ .chroma .kr { color: #0000ff } /* KeywordType */ .chroma .kt { color: #2b91af } /* NameClass */ .chroma .nc { color: #2b91af } /* LiteralString */ .chroma .s { color: #a31515 } /* LiteralStringAffix */ .chroma .sa { color: #a31515 } /* LiteralStringBacktick */ .chroma .sb { color: #a31515 } /* LiteralStringChar */ .chroma .sc { color: #a31515 } /* LiteralStringDelimiter */ .chroma .dl { color: #a31515 } /* LiteralStringDoc */ .chroma .sd { color: #a31515 } /* LiteralStringDouble */ .chroma .s2 { color: #a31515 } /* LiteralStringEscape */ .chroma .se { color: #a31515 } /* LiteralStringHeredoc */ .chroma .sh { color: #a31515 } /* LiteralStringInterpol */ .chroma .si { color: #a31515 } /* LiteralStringOther */ .chroma .sx { color: #a31515 } /* LiteralStringRegex */ .chroma .sr { color: #a31515 } /* LiteralStringSingle */ .chroma .s1 { color: #a31515 } /* LiteralStringSymbol */ .chroma .ss { color: #a31515 } /* OperatorWord */ .chroma .ow { color: #0000ff } /* Comment */ .chroma .c { color: #008000 } /* CommentHashbang */ .chroma .ch { color: #008000 } /* CommentMultiline */ .chroma .cm { color: #008000 } /* CommentSingle */ .chroma .c1 { color: #008000 } /* CommentSpecial */ .chroma .cs { color: #008000 } /* CommentPreproc */ .chroma .cp { color: #0000ff } /* CommentPreprocFile */ .chroma .cpf { color: #0000ff } /* GenericEmph */ .chroma .ge { font-style: italic } /* GenericHeading */ .chroma .gh { font-weight: bold } /* GenericPrompt */ .chroma .gp { font-weight: bold } /* GenericStrong */ .chroma .gs { font-weight: bold } /* GenericSubheading */ .chroma .gu { font-weight: bold }
0
repos/outcome/doc/src
repos/outcome/doc/src/content/_index.md
+++ title = "Home" +++ # Outcome 2.2 library {{% boost-copyright %}} {{% notice note %}} At the end of December 2021, Standalone Outcome <a href="{{% relref "/abi-stability" %}}">went guaranteed future ABI stable</a>. From v2.2.3 onwards, you get ABI compatibilty guarantees across Outcome releases. {{% /notice %}} Outcome is a set of tools for reporting and handling function failures in contexts where *directly* using C++ exception handling is unsuitable. Such contexts include: - there are programs, or parts thereof, that are compiled with exceptions disabled; - there are parts of program that have a lot of branches depending on types of failures, where if-statements are cleaner than try-catch blocks; - there is a hard requirement that the failure path of execution should not cost more than the successful path of execution; - there are situations, like in the [`filesystem`](http://www.boost.org/doc/libs/release/libs/filesystem/doc/index.htm) library, where whether the failure should be handled remotely (using a C++ exception throw), or locally cannot be made inside the function and needs to be decided by the caller, and in the latter case throwing a C++ exception is not desirable for the aforementioned reasons; - there are parts of the program/framework that themselves implement exception handling and prefer to not use exceptions to propagate failure reports across threads, tasks, fibers, etc; - one needs to propagate exceptions through layers that do not implement exception throw safety; - there is an external requirement (such as a company-wide policy) that failure handling paths are explicitly indicated in the code. - where interoperation with C code, without having to resort to C++ exception wrapper shims, is important. - where your mostly C code base needs exception-like error handling, and the subset of Outcome's functionality available in C is sufficient for your needs. Outcome addresses failure handling through returning a special type from functions, which is able to store either a successfully computed value (or `void`), or the information about failure. Outcome also comes with a set of idioms for dealing with such types. Particular care has been taken to ensure that Outcome has the lowest possible impact on build times, thus making it suitable for use in the global headers of really large codebases. Storage layout is guaranteed and is C-compatible for `result<T, E>`[^1], thus making Outcome based code long term ABI-stable. Fully deterministic all-`noexcept` C++ Coroutine support in Outcome is particularly strong, and we supply Outcome-optimising {{< api "eager<T, Executor = void>/atomic_eager<T, Executor = void>" >}}, {{< api "lazy<T, Executor = void>/atomic_lazy<T, Executor = void>" >}} and {{<api "generator<T, Executor = void>" >}} awaitables which work for any user type. ## Sample usage (C++) The main workhorse in the Outcome library is `result<T>`: it represents either a successfully computed value of type `T`, or a `std::error_code`/`boost::system::error_code`[^2] representing the reason for failure. You use it in the function's return type: {{% snippet "intro_example.cpp" "signature" %}} It is possible to inspect the state manually: {{% snippet "intro_example.cpp" "inspect" %}} Or, if this function is called in another function that also returns `result<T>`, you can use a dedicated control statement: {{% snippet "intro_example.cpp" "implementation" %}} `OUTCOME_TRY` is a control statement. If the returned `result<T>` object contains an error information, the enclosing function is immediately returned with `result<U>` containing the same failure information; otherwise an automatic object of type `T` is available in scope. ## Sample usage \(C) Equivalent to the C++ API: `CXX_DECLARE_RESULT_SYSTEM(ident, T)` declares the C type, thereafter `CXX_RESULT_SYSTEM(ident)` refers to it. You use it in the function's return type: {{% snippet "intro_c_example.cpp" "signature" %}} It is possible to inspect the state manually: {{% snippet "intro_c_example.cpp" "inspect" %}} Or, if this function is called in another function that also returns `CXX_RESULT_SYSTEM(ident)`, you can use a dedicated control statement: {{% snippet "intro_c_example.cpp" "implementation" %}} The C Result is guaranteed to be layout identical to its C++ equivalent. Convenience conversion functions are available, but you can reinterpret cast too. {{% notice note %}} This library joined [the Boost C++ libraries](https://www.boost.org/doc/libs/develop/libs/outcome/doc/html/index.html) in the 1.70 release (Spring 2019). [It can be grafted into much older Boost releases if desired](https://github.com/boostorg/outcome). {{% /notice %}} [^1]: If you choose a C-compatible `T` and `E` type. [^2]: `result<T>` defaults to `std::error_code` for Standalone Outcome, and to `boost::system::error_code` for Boost.Outcome. You can mandate a choice using `std_result<T>` or `boost_result<T>`.
0
repos/outcome/doc/src
repos/outcome/doc/src/content/_header.md
Outcome 2.2 library documentation
0
repos/outcome/doc/src
repos/outcome/doc/src/content/credits.md
+++ title = "Acknowledgements" description = "Giving thanks to those who made Outcome happen" +++ ## github contributors {{%ghcontributors "https://api.github.com/repos/ned14/outcome/contributors?per_page=100" %}} ## This pretty, modern C++ documentation * [Hugo](https://gohugo.io) - static website generator of this documentation. * [hugo-theme-docdock](https://github.com/vjeantet/hugo-theme-docdock) - the Hugo theme used by this documentation. * [Standardese](https://github.com/foonathan/standardese) - the API reference generator (up until Outcome v2.0) # Special thanks for Outcome v2.1 Once again Andrzej Krzemienski stands out for a never ceasing flow of excellent questions, "what if?"'s, eagle eyed spotting of corner case logic bugs, and design contradictions. Thank you Andrzej! My thanks to the Microsoft Visual C++ compiler team for incorporating Outcome into the MSVC test suite, and thus finding many interesting corner case quirks in how best to interpret the C++ standard. In some cases, Outcome was refactored to be less ambiguous; in others, defects had to be submitted to WG21 because the standard wording was not clear. The Visual C++ compiler team were particularly generous with their time in helping track down the cause of these issues, complete with submitting pull requests with bug fixes. I am very grateful to them. # Special thanks for Outcome v2.0 For a second time, Charley Bay stepped up as review manager. Given how much work it was for the v1 review, I can only say **thank you**. Andrzej Krzemienski went far beyond the call of duty in the development of Outcome v2. He wrote the front page, and the start of the tutorial. He thus set the tone, pacing, style and form of the tutorial which I merely continued for the rest of the tutorial. He also volunteered considerable amounts of his time as as primary peer reviewer for the v2 design and implementation, asking many very valuable "stupid questions" at least one of which caused a major rethink and refactor. If Outcome v2 passes its second peer review, it's because of Andrzej. Thank you. Jonathan Müller invested countless hours in his doxygen replacement tool Standardese which Outcome uses to generate the reference API docs, and a not insignificant number of those went on fixing issues for Outcome. Thank you. # Special thanks for Outcome v1 To Paul Bristow who <a href="https://lists.boost.org/Archives/boost/2015/05/222687.php"> proposed the name "Outcome"</a> for the library after a very extended period of name bikeshedding on boost-dev. I had been minded to call the library "Boost.Donkey" just to shut everyone up because the name bike shedding was getting ridiculous. But Outcome is a lot nicer, so thank you Paul. My heartfelt thanks to Charley Bay for acting as review manager for Outcome in May 2017. It is becoming ever harder to find a Boost review manager, so thank you! My thanks also to the CppCast team Rob Irving and Jason Turner for so quickly getting me on to CppCast to discuss `expected<T, E>` during the Outcome peer review to help publicise the review. More general thanks are due to those on boost-dev, Reddit and SG14 for extensive and often very detailed feedback on the library pretty much from its beginning. You are all too numerous to remember, but certainly Tongari and Andrzej Krzemienski come to mind as having engaged in particularly long discussion threads with tons of useful feedback which clarified my thinking. Andrzej also went through the documentation with a fine toothed comb before the review, finding many small errata and confusing wording. Finally, my thanks to Vicente for driving Expected from its beginnings to hopefully standardisation before 2020. It's many years of work getting something standardised, even more years than getting a library into Boost which as you can see from the history above took about three years.
0
repos/outcome/doc/src/content
repos/outcome/doc/src/content/changelog/_index.md
+++ title = "Changelog" weight = 80 +++ --- ## v2.2.11 ? (Boost 1.87) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.11) ### Enhancements: - Outcome.Experimental has had C representation support since the beginning, however it had been mainly intended that C++ would originate Results, they would pass through C, and back into C++. It hadn't really been expected that C would want to do much with Results other than inspect them for happy or sad path. It turns out there is more demand than expected for a more functional Result from within C, so this release adds the power to create Results in success and two types of failure, semantic comparison of Results, and printing of Result messages. You can also wrap a C enum into a quick status code from enum, allowing easy custom C error coding from 100% within C. [The documentation for the C support]({{% relref "../experimental/c-api" %}}) has been updated to reflect the new facilities. ### Bug fixes: --- ## v2.2.10 14th August 2024 (Boost 1.86) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.10) ### Enhancements: - Something I've been meaning to do for far too long now is make the GDB pretty printers auto-loading so you don't have to set up `.gdbinit`. This is now done. I also improved the pretty printers to also pretty print the C result type which can be very useful if working with that type, as it will print the error message in GDB. Experimental Outcome's `status_code` has also gained its own auto-loading GDB pretty printer with display of `strerror()` if the code domain is POSIX or generic. --- ## v2.2.9 15th April 2024 (Boost 1.85) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.9) ### Enhancements: [#293](https://github.com/ned14/outcome/issues/293) - Some users wished that Outcome would be clean with `-Wpedantic`, this is now turned on for the test suite. [#294](https://github.com/ned14/outcome/issues/294) - All use of `assert()` has been replaced with `OUTCOME_ASSERT`, which can be user overridden at compile time. [#295](https://github.com/ned14/outcome/issues/295) - In git commit 12b14e1533848e9a0f7f3c38e41da0ee4e819770 (Aug 11 2022) status code had its paths changed due to its headers not previously having the right path convention. It was not realised at the time that in Boost.Outcome this resulted in `<boost/outcome/experimental/status-code/status-code/headers.hpp>` which is not desirable. This has now been remedied to remove the double `status-code`, which will obviously break any Boost.Outcome code which relies on the double `status-code`. Standalone Outcome is unaffected. --- ## v2.2.8 13th December 2023 (Boost 1.84) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.8) ### Enhancements: - cmake 3.9 is now the minimum required for standalone Outcome. This fixes a long standing cmake issue with probing for standard library facilities. cmake 3.9 is what RHEL7 ships with, when RHEL7 EOLs we may raise the minimum cmake version at that point. ### Bug fixes: - There was a bug in the Outcome C++ coroutine awaitables whereby we were over eagerly resuming execution of coroutines which return one of our awaitables. It is surprising how many years have passed before this was noticed, but it is now fixed. It is believed that this has been fixed without affecting ABI stability, however mixing old Outcome and new Outcome in the same binary without recompiling all the C++ coroutine code to use new Outcome will not fix the bug. [#291](https://github.com/ned14/outcome/issues/291) - A Result or Outcome with `void` value type and move-only non-value type was only usable in const use cases, due to the lack of provision of non-const member functions in relevant observers injection layers for the `void` specialisation. The missing non-const member functions have now been added. --- ## v2.2.7 13th August 2023 (Boost 1.83) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.7) ### Enhancements: - Update the list of known compiler issues in the docs. - Update Outcome.Experimental to match latest changes requested of `status_code` by WG21. This as usual will cause minor breakage due to LEWG renaming of things. - Outcome previously took addresses of things not using `std::addressof()`, and until now nobody complained because custom `operator&` which doesn't return an address is an abomination not used in much modern C++. But finally someone did complain, so for both normal Outcome and Experimental.Outcome, if you set `OUTCOME_USE_STD_ADDRESSOF = 1`, Outcome will use `std::addressof()` ### Bug fixes: [#273](https://github.com/ned14/outcome/issues/273) - Changes to other Boost libraries had caused Boost.Outcome's test suite to fail to compile for some compiler and C++ language configurations in recent releases. Thanks to work contributed by @alandefreitas and @pdimov, Boost.Outcome now CI tests a wide range of compilers and configurations and it is believed all those corner case issues have been fixed or worked around, for the compilers and configurations within that CI matrix. Standalone Outcome's test suite was never affected, as it did not have Boost changing underneath it. Nevertheless, a few of the compiler parse bug workarounds will have improved compatibility there too for atyical toolchain choices. - Experimental.Outcome now supports big endian architectures. Implementation for them simply wasn't done before under the assumption that nobody would be using Experimental.Outcome on big endian architectures. Turns out that was a wrong assumption! --- ## v2.2.6 24th March 2023 (Boost 1.82) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.6) ### Enhancements: - Update to latest `status-code` in Experimental.Outcome, which relocates its header files and may cause some end user inclusions to need path changes. ### Bug fixes: - Latest `status-code` fixes a number of nasty bugs, some mild build breakage in Experimental.Outcome may occur as a result. See its commit log for more information. --- ## v2.2.4 11th August 2022 (Boost 1.80) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.4) ### Enhancements: - Update to latest `status-code` in Experimental.Outcome, which has some breaking changes and important bug fixes. - Add {{<api "generator<T, Executor = void>" >}} to coroutine awaitables. - Add optional `Executor` template parameter to all Outcome awaitable types for improved compatibility with third party software such as [ASIO](https://think-async.com/Asio/). - To Experimental.Outcome add `clone()` for `basic_result` and `basic_outcome` types whose `EC` is a `status_code`. Erased status codes are move-only which makes the Result/Outcome type move-only, but they provide a cloning function, so this convenience function both clones the status code and propagates the spare storage so stack backtraces etc are also cloned. - Add type constraints to `success()` and `failure()` to disable them if they aren't available. - Work around a bug in GCC's C++ Coroutines implementation whereby one gets an ICE from `gimplify_expr` in any `OUTCOME_CO_TRY` taking even a mildly complex expression, which obviously is a showstopper. The work around assigns the failure type to a stack temporary before `co_return`-ing that temporary. Thanks to RVO pre-17 and copy elision since, this should add no runtime overhead. ### Bug fixes: [#261](https://github.com/ned14/outcome/issues/261) : Move assignable with move constructible not available did not work with `void`. --- ## v2.2.3 17th March 2022 (Boost 1.79) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.3) ### Enhancements: Standalone Outcome permanently locks ABI to v2.2.3 release : From this release onwards, you are guaranteed that any code compiled with v2.2.3 Outcome or newer will link without issue with any code compiled with a different version of Outcome after v2.2.3. As a result, `OUTCOME_UNSTABLE_VERSION` is no longer defined by default, and therefore `OUTCOME_V2_NAMESPACE` is now hard coded to `outcome_v2` rather than a namespace which permutes per commit. ### Bug fixes: [#255](https://github.com/ned14/outcome/issues/259) : Fix enabling of move assignable was not calculated correctly. --- ## v2.2.2 8th December 2021 (Boost 1.78) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.2) ### Enhancements: [#255](https://github.com/ned14/outcome/issues/255) : Restore Experimental Outcome constexpr compatibility in C++ 20 which was an undocumented property of the Outcome v2.1 series, and which had been dropped in the v2.2 series. GCC Coroutines support : Coroutine support in GCCs after 10 is now correctly detected. ### Bug fixes: - None. --- ## v2.2.1 13th August 2021 (Boost 1.77) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.1) ### Bug fixes: [#251](https://github.com/ned14/outcome/issues/251) : Fix failure to compile Boost.Outcome when the compiler declares support for C++ modules. - Don't use `[[likely]]` in GCCs before 9. [#251](https://github.com/ned14/outcome/issues/253) : Make support for C++ modules opt-in. --- ## v2.2.0 16th April 2021 (Boost 1.76) [[release]](https://github.com/ned14/outcome/releases/tag/v2.2.0) BREAKING CHANGE As announced for a year and three Boost releases, Outcome v2.2 became the default, replacing v2.1. : All v2.1 Outcome code will need to be upgraded as described in [the v2.1 => v2.2 upgrade guide]({{% relref "/changelog/upgrade_v21_v22" %}}). This branch has a number of major breaking changes to Outcome v2.1, see [the list of v2.2 major changes]({{% relref "/changelog/v22" %}}). ### Enhancements: VS2019.8 compatibility : VS2019.8 changed how to enable Coroutines, which caused Outcome to not compile on that compiler. [#237](https://github.com/ned14/outcome/issues/237) : If on C++ 20, we now use C++ 20 `[[likely]]` instead of compiler-specific markup to indicate when TRY has likely success or failure. BREAKING CHANGE [#247](https://github.com/ned14/outcome/issues/247) : Previously the value of {{% api "spare_storage(const basic_result|basic_outcome *) noexcept" %}} was not propagated over `OUTCOME_TRY`, which causes things like stack backtraces captured at the point of construction of an errored result to get dropped at every `TRY` point. This has been fixed by adding an optional `spare_storage` to {{% api "success_type<T>" %}} and {{% api "failure_type<T>" %}}, as well as to {{% api "auto success(T &&, ...)" %}} and {{% api "auto failure(T &&, ...)" %}}. You should not notice this in your code, except that where before spare storage values did not propagate through TRY, now they do, which is a breaking change. ### Bug fixes: BREAKING CHANGE [#244](https://github.com/ned14/outcome/issues/244) : It came as a shock to learn that `OUTCOME_TRY` had been broken since the inception of this library for certain corner case code: ```c++ outcome::result<Foo> get_foo(); outcome::result<Foo> filter1(outcome::result<Foo> &&); outcome::result<Foo> && filter2(outcome::result<Foo> &&); // This works fine, and always has OUTCOME_TRY(auto v, filter1(get_foo())) // This causes UB due to result<Foo> being destructed before move of value into v OUTCOME_TRY(auto v, filter2(get_foo())) ``` Whilst reference passthrough filter functions are not common, they can turn up in highly generic code, where destruction before copy/move is not helpful. The cause is that TRY used to work by binding the result of the expression to an `auto &&unique`, testing if that unique if successful or not, and if successful then moving from `unique.value()` into the user's output variable. If the expression returned is a prvalue, the Result's lifetime is extended by the bound reference to outside of the statement, and all is good. If the expression returned is an xvalue or lvalue, then the lifetime extension does not exceed that of the statement, and the Result is destructed after the semicolon succeeding the assignment to `auto &&unique`. This bug has been fixed by TRY deducing the [value category](https://en.cppreference.com/w/cpp/language/value_category) of its input expression as follows: - prvalues => `auto unique = (expr)` (breaking change) - xvalue => `auto unique = (expr)` (breaking change) - lvalue => `auto unique = (expr)` (breaking change) This ensures that xvalue and lvalue inputs do not cause unhelpfully early lifetime end, though it does silently change the behaviour of existing code which relied on rvalues and lvalues being passed through, as a new construct-move-destruct or construct-copy-destruct cycle is introduced to where there was none before. Also, before C++ 17, there is now an added copy/move for prvalue inputs, which does not affect runtime codegen due to Return Value Optimisation (RVO), but does cause Results containing non-copying non-moving types to fail to compile, which is a breaking change from beforehand. If one wishes rvalues or lvalues to be passed through, one can avail of a new TRY syntax based on preprocessor overloading: - `OUTCOME_TRY((refspec, varname), expr)` - `OUTCOME_TRYV2(refspec, expr)` Here `refspec` is the storage to be used for **both** the internal temporary unique, AND `varname`. So if you write: ```c++ Foo &&foo; OUTCOME_TRY((auto &&, v), filter2(foo)) ``` ... then the internal unique is declared as `auto &&unique = (filter2(foo))`, and the output variable is declared as `auto &&v = std::move(unique).assume_value()`. This passes through the rvalue referencing, and completely avoids copies and moves of `Foo`. If you wish to not extract the value but also specify unique storage, there is a new `OUTCOME_TRYV2(refspec, expr)`. My thanks to KamilCuk from https://stackoverflow.com/questions/66069152/token-detection-within-a-c-preprocessor-macro-argument for all their help in designing the new overloaded TRY syntax. My thanks also to vasama for reporting this issue and working through how best to fix it with me. [#249](https://github.com/ned14/outcome/issues/249) : The preprocessor logic for choosing when to use `bool` with `concept` on GCC was yet again refactored. This should fix those choices of GCC configuration which caused failure due to the wrong combination being chosen. --- ## v2.1.5 11th December 2020 (Boost 1.75) [[release]](https://github.com/ned14/outcome/releases/tag/v2.1.5) ### Enhancements: [The ADL discovered event hooks]({{% relref "/tutorial/advanced/hooks" %}}) have been replaced with policy-specified event hooks instead : This is due to brittleness (where hooks would quietly self-disable if somebody changed something), compiler bugs (a difference in compiler settings causes the wrong hooks, or some but not all hooks, to get discovered), and end user difficulty in using them at all. The policy-specified event hooks can be told to default to ADL discovered hooks for backwards compatibility: set {{% api "OUTCOME_ENABLE_LEGACY_SUPPORT_FOR" %}} to less than `220` to enable emulation. Improve configuring `OUTCOME_GCC6_CONCEPT_BOOL` : Older GCCs had boolean based concepts syntax, whereas newer GCCs are standards conforming. However the precise logic of when to use legacy and conforming syntax was not well understood, which caused Outcome to fail to compile depending on what options you pass to GCC. The new logic always uses the legacy syntax if on GCC 8 or older, otherwise we use conforming syntax if and only if GCC is in C++ 20 mode or later. This hopefully will resolve the corner case build failures on GCC. ### Bug fixes: Boost.Outcome should now compile with `BOOST_NO_EXCEPTIONS` defined : Thanks to Emil, maintainer of Boost.Exception, making a change for me, Boost.Outcome should now compile with C++ exceptions globally disabled. You won't be able to use `boost::exception_ptr` as it can't be included if C++ exceptions are globally disabled. [#236](https://github.com/ned14/outcome/issues/236) : In the Coroutine support the `final_suspend()` was not `noexcept`, despite being required to be so in the C++ 20 standard. This has been fixed, but only if your compiler implements `noop_coroutine`. Additionally, if `noop_coroutine` is available, we use the much more efficient coroutine handle returning variant of `await_suspend()` which should significantly improve codegen and context switching performance. --- ## v2.1.4 14th August 2020 (Boost 1.74) [[release]](https://github.com/ned14/outcome/releases/tag/v2.1.4) ### Enhancements: BREAKING CHANGE `void` results and outcomes no longer default construct types during explicit construction : Previously if you explicitly constructed a `result<T>` from a non-errored `result<void>`, it default constructed `T`. This was found to cause unhelpful surprise, so it has been disabled. New macro `OUTCOME_ENABLE_LEGACY_SUPPORT_FOR` : The macro {{% api "OUTCOME_ENABLE_LEGACY_SUPPORT_FOR" %}} can be used to enable aliasing of older naming and features to newer naming and features when using a newer version of Outcome. Concepts now have snake case style naming instead of camel case style : When Outcome was first implemented, it was thought that C++ 20 concepts were going to have camel case style. This was changed before the C++ 20 release, and Outcome's concepts have been renamed similarly. This won't break any code in Outcome v2.1, as compatibility aliases are provided. However code compiled against Outcome v2.2 will need to be upgraded, unless `OUTCOME_ENABLE_LEGACY_SUPPORT_FOR` is set to less than `220`. Concepts now live in `OUTCOME_V2_NAMESPACE::concepts` namespace : Previously concepts lived in the `convert` namespace, now they live in their own namespace. New concepts {{% api "basic_result<T>" %}} and {{% api "basic_outcome<T>" %}} added : End users were finding an unhelpful gap in between {{% api "is_basic_result<T>" %}} and {{% api "value_or_error<T>" %}} where they wanted a concept that matched types which were `basic_result`, but not exactly one of those. Concepts filling that gap were added. Operation `TRY` works differently from Outcome v2.2 onwards : This is a severely code breaking change which change the syntax of how one uses `OUTCOME_TRY()`. A regular expression suitable for upgrading code can be found in the list of changes between Outcome v2.1 and v2.2. ### Bug fixes: [#224](https://github.com/ned14/outcome/issues/224) : The clang Apple ships in Xcode 11.4 (currently the latest) has not been patched with the fixes to LLVM clang that fix `noexcept(std::is_constructible<T, void>)` failing to compile which I originally submitted years ago. So give up waiting on Apple to fix their clang, add a workaround to Outcome. Use of `void` in `T` or `E` caused `noexcept(false)` : Direct traits examination of `void` was causing nothrow detection to return false, fixed. Spare storage could not be used from within no-value policy classes : Due to an obvious brain fart when writing the code at the time, the spare storage APIs had the wrong prototype which prevented them working from within policy classes. Sorry. --- ## v2.1.3 29th April 2020 (Boost 1.73) [[release]](https://github.com/ned14/outcome/releases/tag/v2.1.3) ### Enhancements: Performance of Outcome-based code compiled by clang has been greatly improved : The previous implementation of Outcome's status bitfield confused clang's optimiser, which caused low quality codegen. Unlike most codegen issues, this was noticeably in empirical benchmarks of real world code, as was shown by [P1886 *Error speed benchmarking*](https://wg21.link/P1886). The safe part of the [`better_optimisation`](https://github.com/ned14/outcome/tree/better_optimisation) Outcome v2.2.0 future branch was merged to Outcome v2.1.3 which includes a new status bitfield implementation. This appears to not confuse clang's optimiser, and clang 9 produces code which routinely beats GCC 9's code for various canned use cases. Precompiled headers are automatically enabled on new enough cmake's for standalone Outcome : If on cmake 3.16 or later, its new precompiled headers build support is used to tell consumers of the `outcome::hl` cmake target to precompile Outcome, **if and only if** `outcome_IS_DEPENDENCY` is false. `outcome_IS_DEPENDENCY` is set by Outcome's CMakeLists.txt if it detects that it was included using `add_subdirectory()`, so for the vast majority of Outcome end users, the use of precompiled headers will NOT be enabled. Exported targets do NOT request precompilation of headers, as it is assumed that importers of the Outcome cmake targets will configure their own precompiled headers which incorporate Outcome. Installability is now CI tested per commit : Due to installability of standalone Outcome (e.g. `make install`) breaking itself rather more frequently than is ideal, installability is now tested on CI per commit. Coroutines support has been documented : The coroutines support added in v2.1.2 has now been properly documented. ### Bug fixes: [#214](https://github.com/ned14/outcome/issues/214) : Newer Concepts implementing compilers were unhappy with the early check for destructibility of `T` and `E`, so removed template constraints, falling back to static assert which runs later in the type instantiation sequence. [#215](https://github.com/ned14/outcome/issues/215) : For standalone Outcome, `CMAKE_TOOLCHAIN_FILE` is now passed through during dependency superbuild. This should solve build issues for some embedded toolchain users. [#220](https://github.com/ned14/outcome/issues/220) : A false positive undefined behaviour sanitiser failure in some use cases of Experimental Outcome was worked around to avoid the failure message. [#221](https://github.com/ned14/outcome/issues/221) : Restored compatibility with x86 on Windows, which was failing with link errors. It was quite surprising that this bug was not reported sooner, but obviously almost nobody is using Outcome with x86 on Windows. [#223](https://github.com/ned14/outcome/issues/223) : Fix a segfault in Debug builds only when cloning a `status_code_ptr` in Experimental.Outcome only. --- ## v2.1.2 11th December 2019 (Boost 1.72) [[release]](https://github.com/ned14/outcome/releases/tag/v2.1.2) ### Enhancements: Improved compatibility with cmake tooling : Standalone outcome is now `make install`-able, and cmake `find_package()` can find it. Note that you must separately install and `find_package()` Outcome's dependency, quickcpplib, else `find_package()` of Outcome will fail. Non-permissive parsing is now default in Visual Studio : The default targets in standalone Outcome's cmake now enable non-permissive parsing. This was required partially because VS2019 16.3's quite buggy Concepts implementation is unusuable in permissive parsing mode. Even then, lazy ADL two phase lookup is broken in VS2019 16.3 with `/std:latest`, you may wish to use an earlier language standard. **Breaking change!** : The git submodule mechanism used by standalone Outcome of specifying dependent libraries has been replaced with a cmake superbuild of dependencies mechanism instead. Upon cmake configure, an internal copy of quickcpplib will be git cloned, built and installed into the build directory from where an internal `find_package()` uses it. This breaks the use of the unconfigured Outcome repo as an implementation of Outcome, one must now do one of: 1. Add Outcome as subdirectory to cmake build. 2. Use cmake superbuild (i.e. `ExternalProject_Add()`) to build and install Outcome into a local installation. 3. Use one of the single header editions. **Breaking change!** : For standalone Outcome, the current compiler is now checked for whether it will compile code containing C++ Concepts, and if it does, all cmake consumers of Outcome will enable C++ Concepts. Set the cmake variable `CXX_CONCEPTS_FLAGS` to an empty string to prevent auto detection and enabling of C++ Concepts support occurring. `OUTCOME_TRY` operation now hints to the compiler that operation will be successful : [P1886 *Error speed benchmarking*](https://wg21.link/P1886) showed that there is considerable gain in very small functions by hinting to the compiler whether the expression is expected to be successful or not. `OUTCOME_TRY` previously did not hint to the compiler at all, but now it does. A new suite of macros `OUTCOME_TRY_FAILURE_LIKELY` hint to the compiler that failure is expected. If you wish to return to the previously unhinted behaviour, define `OUTCOME_TRY_LIKELY(expr)` to `(!!expr)`. [#199](https://github.com/ned14/outcome/issues/199) : Support for C++ Coroutines has been added. This comes in two parts, firstly there is now an `OUTCOME_CO_TRY()` operation suitable for performing the `TRY` operation from within a C++ Coroutine. Secondly, in the header `outcome/coroutine_support.hpp` there are implementations of `eager<OutcomeType>` and `lazy<OutcomeType>` which let you more naturally and efficiently use `basic_result` or `basic_outcome` from within C++ Coroutines -- specifically, if the result or outcome will construct from an exception pointer, exceptions thrown in the coroutine return an errored or excepted result with the thrown exception instead of throwing the exception through the coroutine machinery (which in current compilers, has a high likelihood of blowing up the program). Both `eager<T>` and `lazy<T>` can accept any `T` as well. Both have been tested and found working on VS2019 and clang 9. [#210](https://github.com/ned14/outcome/issues/210) : `make_error_code()` and `make_exception_ptr()` are now additionally considered for compatible copy and move conversions for `basic_result<>`. This lets you construct a `basic_result<T, E>` into a `basic_result<T, error_code>`, where `E` is a custom type which has implemented the ADL discovered free function `error_code make_error_code(E)`, but is otherwise unrelated to `error_code`. The same availability applies for `exception_ptr` with `make_exception_ptr()` being the ADL discovered free function. `basic_outcome<>` has less support for this than `basic_result<>` in order to keep constructor count down, but it will accept via this mechanism conversions from `basic_result<>` and `failure_type<>`. ### Bug fixes: [#184](https://github.com/ned14/outcome/issues/207) : The detection of `[[nodiscard]]` support in the compiler was very mildly broken. --- ## v2.1.1 19th August 2019 (Boost 1.71) [[release]](https://github.com/ned14/outcome/releases/tag/v2.1.1) ### Enhancements: [#184](https://github.com/ned14/outcome/issues/184) : As per request from Boost release managers, relocated `version.hpp` and `revision.hpp` into detail, and added the Boost licence boilerplate to the top of every source file which was missing one (I think). Also took the opportunity to run the licence restamping script over all Outcome, so copyright dates are now up to date. [#185](https://github.com/ned14/outcome/issues/185) : Add FAQ item explaining issue #185, and why we will do nothing to fix it right now. [#189](https://github.com/ned14/outcome/issues/189) : Refactored the `OUTCOME_TRY` implementation to use more clarified customisation points capable of accepting very foreign inputs. Removed the `std::experimental::expected<T, E>` specialisations, as those are no longer necessary. Fixed the documentation for the customisation points which previously claimed that they are ADL discovered, which they are not. Added a recipe describing how to add in support for foreign input types. [#183](https://github.com/ned14/outcome/issues/183) : Added a separate `motivation/plug_error_code` specifically for Boost. ### Bug fixes: - : `OUTCOME_VERSION_MINOR` hadn't been updated to 1. [#181](https://github.com/ned14/outcome/issues/181) : Fix issue #181 where Outcome didn't actually implement the strong swap guarantee, despite being documented as doing so. [#190](https://github.com/ned14/outcome/issues/190) : Fix issue #190 in Boost edition where unit test suite was not runnable from the Boost release distro. [#182](https://github.com/ned14/outcome/issues/182) : Fix issue #182 where `trait::is_exception_ptr_available<T>` was always true, thus causing much weirdness, like not printing diagnostics and trying to feed everything to `make_exception_ptr()`. [#194](https://github.com/ned14/outcome/issues/192) : Fix issue #192 where the `std::basic_outcome_failure_exception_from_error()` was being defined twice for translation units which combine standalone and Boost Outcome's. --- ## v2.1 12th Apr 2019 (Boost 1.70) [[release]](https://github.com/ned14/outcome/releases/tag/v2.1) - [#180](https://github.com/ned14/outcome/issues/180) - `success()` and `failure()` now produce types marked `[[nodiscard]]`. - `include/outcome/outcome.natvis` is now namespace permuted like the rest of Outcome, so debugging Outcome based code in Visual Studio should look much prettier than before. - [#162](https://github.com/ned14/outcome/issues/162) - `.has_failure()` was returning false at times when it should have returned true. - [#152](https://github.com/ned14/outcome/issues/152) - GCC 5 no longer can compile Outcome at all due to [https://stackoverflow.com/questions/45607450/gcc5-nested-variable-template-is-not-a-function-template](https://stackoverflow.com/questions/45607450/gcc5-nested-variable-template-is-not-a-function-template). Added explicit version trap for GCC 5 to say it can not work. Note this is not a breaking change, GCC 5 was never supported officially in any v2 Outcome. - [#150](https://github.com/ned14/outcome/issues/150) - **BREAKING CHANGE** `result<T, E>`, `boost_result<T, E>` and `std_result<T, E>` no longer implement hard UB on fetching a value from a valueless instance if `E` is a UDT, they now fail to compile with a useful error message. If you wish hard UB, use `unchecked<T, E>`, `boost_unchecked<T, E>` or `std_unchecked<T, E>` instead. - [#140](https://github.com/ned14/outcome/issues/140) - Fixed a nasty corner case bug where value type's without a copy constructor but with a move constructor would indicate via traits that copy construction was available. Thanks to Microsoft's compiler team for reporting this issue. - Added experimental `status_result` and `status_outcome` based on experimental `status_code`. - Boost edition is now 100% Boost, so defaults for `result` and `outcome` are `boost::system::error_code::errc_t` and `boost::exception_ptr`. Moreover, the test suite in the Boost edition now exclusively tests the Boost edition. One can, of course, freely use the standalone edition with Boost, and the Boost edition with `std` types. - Renamed ADL discovered customisation point `throw_as_system_error_with_payload()` to `outcome_throw_as_system_error_with_payload()`. - [#135](https://github.com/ned14/outcome/issues/135) - Added much clearer compile failure when user tries `result<T, T>` or `outcome` where two or more types are identical. Thanks to Andrzej Krzemieński for suggesting a technique which combines SFINAE correctness with the remaining ability for `result<T, T>` etc to be a valid type, but not constructible. - [#67](https://github.com/ned14/outcome/issues/67) - Fixed one of the oldest long open bugs in Outcome, that the noexcept unit tests failed on OS X for an unknown reason. - [#115](https://github.com/ned14/outcome/issues/115) - Outcome did not construct correctly from `failure_type`. - Inexplicably outcome's error + exception constructor had been removed. Nobody noticed during the Boost peer review, which is worrying seeing as that constructor is needed for one of the main advertised features to Boost! - [#107](https://github.com/ned14/outcome/issues/107) and [#116](https://github.com/ned14/outcome/issues/116) - `operator==` and `operator!=` now become disabled if the value, error and exception types do not implement the same operator. - Relatedly, both comparison operators simply didn't work right. Fixed. - [#109](https://github.com/ned14/outcome/issues/109) - `swap()` now has correct `noexcept` calculation and now correctly orders the swaps to be whichever is the throwing swap first. - Added reference dump of v2.1 ABI so we can check if ABI breakage detection works in the next set of changes, plus Travis job to check ABI and API compatibility per commit. - [#124](https://github.com/ned14/outcome/issues/124) - `OUTCOME_TRY` is now overloaded and selects `void` or `auto` edition according to input parameter count. - [#120](https://github.com/ned14/outcome/issues/120) - Fix generation of double underscored temporary variables in `OUTCOME_UNIQUE_NAME`, which is UB. - [#110](https://github.com/ned14/outcome/issues/110) - Separated `result` from its hard coded dependency on the `<system_error>` header. - Renamed `result` and `outcome` to `basic_result` and `basic_outcome`. - Renamed `result.hpp` into `basic_result.hpp`. - Moved `<system_error>` and `<exception>` dependent code into new `std_result.hpp` and `std_outcome.hpp` header files. - Added `boost_result.hpp` and `boost_outcome.hpp` which use Boost.System and Boost.Exception (these are `result.hpp` and `outcome.hpp` in the Boost edition). --- ## v2.0 18th Jan 2018 [[release]](https://github.com/ned14/outcome/releases/tag/v2.0-boost-peer-review) - Boost peer review edition. This is what was reviewed. - Changelog from v1 can be found in the release notes for this release.
0
repos/outcome/doc/src/content
repos/outcome/doc/src/content/changelog/v22.md
+++ title = "v2.2 major changes" weight = 30 +++ Major changes in v2.2 over v2.1 are listed here. 1. A new trait `is_move_bitcopying<T>` is added, which opts types into a library-based emulation of [P1029 *move = bitcopies*](https://wg21.link/P1029). [Experimental `std::error`](https://wg21.link/P1028) is opted in by default. If this trait is true for your `T` or `E` type, Outcome will track moved-from status for your type, and will only call your type's destructor if it was not moved from. If your compiler's optimiser is sufficiently able to fold code, this improves codegen quality for Experimental Outcome very considerably, approaching the same gains as P1029 types would have. Note that the empirical performance difference will likely be nil, but the codegen does look much more elegant. 2. If for `basic_result<T, E>` both `T` and `E` are trivially copyable, union-based rather than struct-based storage will be used. This significantly improves performance in synthetic benchmarks which do nothing in deep call stacks of function calls except create and return `result<T, E>`, and makes Outcome return competitive results to alternative error handling choices, improving comparative optics. It is not expected that the performance difference will be detectable empirically in real world code. It is expected that the build time impact of union storage won't be noticeable, as union storage for trivially copyable types is much easier than for non-TC types. Note that storage remains struct-based if either `T` or `E` is neither trivially copyable nor for which trait `is_move_bitcopying<T>` is true. This is because union-based storage for complex types has significant build time impact, as anyone who has deployed `std::variant` or `std::expected` into globally visible public APIs will have noticed. 3. The compile time requirement for `E` types to have a default constructor is removed. 4. `OUTCOME_TRY(var, expr)` no longer always declares `var` as `auto &&var`, but simply uses it as is. This allows `TRY` to initialise or assign. You can use the macro `OUTCOME21_TRY` if you want the pre-Outcome v2.2 behaviour. You may find the regular expression `_TRY\(([^(]*?),(.*?)\);` => `_TRY(auto &&\1,\2);` of use to you when upgrading code. 5. `OUTCOME_TRY` now declares its internal uniquely named temporary variable which holds the result of the expression as `auto unique = expr` instead of `auto &&unique = expr`. This will cause TRY of `result<UncopyableAndImmovable>` and `outcome<UncopyableAndImmovable>` to fail to compile, whereas previously they did compile. Another big change in semantic is that TRY now will 'consume' values moved into it, whereas previously it did not/ The reason for this change was that the previous behaviour produced undefined behaviour in various corner use cases, particulary in generic code. You can tell TRY to use references instead of values for its uniquely named temporary [using a special syntax]({{% relref "/tutorial/essential/result/try_ref" %}}). 6. `OUTCOME_TRY` now propagates the value from {{% api "spare_storage(const basic_result|basic_outcome *) noexcept" %}} of the input Result/Outcome into any {{% api "failure_type<T>" %}} returned by TRY. Result/Outcome now sets its spare storage value from any {{% api "success_type<T>" %}} or {{% api "failure_type<T>" %}} from which it is constructed. This is a breaking change, as spare storage values were not propagated beforehand. However this change means that any stack backtrace identifier captured by a failed result construction hook is now fully propagated from failure point up through all TRY operations to the code which handles the failure. 7. [The ADL discovered event hooks]({{% relref "/tutorial/advanced/hooks" %}}) have been replaced with policy-specified event hooks instead. This is due to brittleness (where hooks would quietly self-disable if somebody changed something), compiler bugs (a difference in compiler settings causes the wrong hooks, or some but not all hooks, to get discovered), and end user difficulty in using them at all. The policy-specified event hooks can be told to default to ADL discovered hooks for backwards compatibility: set {{% api "OUTCOME_ENABLE_LEGACY_SUPPORT_FOR" %}} to less than `220` to enable emulation.
0
repos/outcome/doc/src/content
repos/outcome/doc/src/content/changelog/upgrade_v21_v22.md
+++ title = "Upgrade guide v2.1 => v2.2" weight = 20 +++ In the start of 2020, after a year of listening to user feedback since entering Boost, Outcome v2.2 was published with a number of breaking source changes from Outcome v2.1 The full year of 2020 (three Boost releases) was given to announcing those upcoming changes, and testing the v2.2 branch in production. In late December 2020, Outcome v2.2 became the default Outcome, and all Outcome v2.1 code shall need to be upgraded to work with v2.2. To upgrade an Outcome v2.1 based codebase to Outcome v2.2 is very easy: 1. You will need a tool capable of finding regular expressions in all source files in a directory tree and replacing them -- most IDEs such as Visual Studio have such a tool with GUI, on POSIX a shell script such as this ought to work: find /path/to/project -type f -name "*.hpp" | xargs sed -i "s/_TRY\(([^(]*?),(.*?)\);/_TRY((auto &&, \1),\2);/g" find /path/to/project -type f -name "*.cpp" | xargs sed -i "s/_TRY\(([^(]*?),(.*?)\);/_TRY((auto &&, \1),\2);/g" find /path/to/project -type f -name "*.hpp" | xargs sed -i "s/_TRY\(([^(]*?)\);/_TRYV2(auto &&, \1);/g" find /path/to/project -type f -name "*.cpp" | xargs sed -i "s/_TRY\(([^(]*?)\);/_TRYV2(auto &&, \1);/g" The transformation needed are the regular expressions `_TRY\(([^(]*?),(.*?)\);` => `_TRY((auto &&, \1),\2);` and `TRY\(([^(]*?)\);` => `_TRYV2(auto &&, \1);`. This is because in Outcome v2.2 onwards, `OUTCOME_TRY(var, expr)` no longer implicitly declares the variable created as `auto&&` on your behalf, now you must specify the storage of the variable. It also declares the internal uniquely named temporary as a value rather than as a reference, the initial brackets overrides this to force the use of a rvalue reference for the internal uniquely named temporary instead. This makes use of Outcome's [new TRY syntax]({{% relref "/tutorial/essential/result/try_ref" %}}) to tell the TRY operation to use references rather than values for the internal uniquely named temporary, thus avoiding any copies and moves. The only way to override the storage of the internal uniquely named temporary for non-value outputting TRY is via the new `OUTCOME_TRYV2()` which takes the storage specifier you desire as its first parameter. The principle advantage of this change is that you can now assign to existing variables the successful results of expressions, instead of being forced to TRY into a new variable, and move that variable into the destination you intended. Also, because you can now specify storage, you can now assign the result of a TRYied operation into static or thread local storage. 2. The find regex and replace rule above is to preserve exact semantics with Outcome v2.1 whereby the internal uniquely named temporary and the variable for the value are both rvalue references. If you're feeling like more work, it is safer if you convert as many `OUTCOME_TRY((auto &&, v), expr)` to `OUTCOME_TRY(auto &&v, expr)` as possible. This will mean that TRY 'consumes' `expr` i.e. moves it into the internal uniquely named temporary, if expr is an rvalue reference. Usually this does not affect existing code, but occasionally it can, generally a bit of code reordering will fix it. 3. If your code uses [the ADL discovered event hooks]({{% relref "/tutorial/advanced/hooks" %}}) to intercept when `basic_result` and `basic_outcome` is constructed, copies or moved, you will need to either define the macro {{% api "OUTCOME_ENABLE_LEGACY_SUPPORT_FOR" %}} to less than `220` to enable emulation, or upgrade the code to use the new mechanism. The hooks themselves have identical signature, [only the name and location has changed]({{% relref "/tutorial/advanced/hooks" %}}). Therefore upgrade is usually a case of copy-pasting the hook implementation into a custom `NoValuePolicy` implementation, and changing the ADL free function's name from `hook_*` to `on_*`. You are recommended to upgrade if possible, as the ADL discovered hooks were found in real world code usage to be brittle and surprising. 4. Any usage of CamelCase named concepts from Outcome must be replaced with snake_case named concepts instead: - `concepts::ValueOrError<T>` => `concepts::value_or_error<T>` - `concepts::ValueOrNone<T>` => `concepts::value_or_none<T>` The CamelCase naming is aliased to the snake_case naming if the macro {{% api "OUTCOME_ENABLE_LEGACY_SUPPORT_FOR" %}} is defined to less than `220`. Nevertheless you ought to upgrade here is possible, as due to a late change in C++ 20 all standard concepts are now snake_case named. 5. Finally, despite that Outcome does not currently offer a stable ABI guarantee (hoped to begin in 2022), v2.1 had a stable storage layout for `basic_result` and `basic_outcome`. In v2.2 that storage layout has changed, so the ABIs generated by use of v2.1 and v2.2 are incompatible i.e. you will need to recompile everything using Outcome after you upgrade to v2.2.
0
repos/outcome/doc/src/content
repos/outcome/doc/src/content/reference/_index.md
+++ title = "API reference" weight = 20 +++ {{% children description="true" depth="2" %}}
0
repos/outcome/doc/src/content/reference
repos/outcome/doc/src/content/reference/concepts/value_or_none.md
+++ title = "`value_or_none<T>`" description = "A boolean concept matching types with an optional value." +++ If on C++ 20 or the Concepts TS is enabled, a boolean concept matching types with a public `.has_value()` observer which returns `bool`, and a public `.value()` observer function. If without Concepts, a static constexpr bool which is true for types matching the same requirements, using a SFINAE based emulation. This concept matches optional-like types such as {{% api "std::optional<T>" %}}. Note it also matches {{% api "std::expected<T, E>" %}}, which also has an optional-like interface. You may thus wish to preferentially match {{% api "concepts::value_or_error<T, E>" %}} for any given `T`. *Namespace*: `OUTCOME_V2_NAMESPACE::concepts` *Header*: `<outcome/convert.hpp>` *Legacy*: This was named `convert::ValueOrNone<T>` in Outcome v2.1 and earlier. Define {{% api "OUTCOME_ENABLE_LEGACY_SUPPORT_FOR" %}} to less than `220` to enable.
0
repos/outcome/doc/src/content/reference
repos/outcome/doc/src/content/reference/concepts/_index.md
+++ title = "Concepts" weight = 20 +++ {{% children description="true" depth="2" %}}
0
repos/outcome/doc/src/content/reference
repos/outcome/doc/src/content/reference/concepts/basic_outcome.md
+++ title = "`basic_outcome<T>`" description = "A boolean concept matching types which are convertible to a `basic_outcome<T, EC, EP, NoValuePolicy>`." +++ If on C++ 20 or the Concepts TS is enabled, a boolean concept matching types which have `value_type`, `error_type` and `no_value_policy_type` member typedefs; that the type is convertible to `basic_result<value_type, error_type, no_value_policy_type>`; that `basic_result<value_type, error_type, no_value_policy_type>` is a base of the type. If without Concepts, a static constexpr bool which is true for types matching the same requirements, using a SFINAE based emulation. This concept matches any type which provides the same typedefs as a {{% api "basic_result<T, E, NoValuePolicy>" %}}, has that `basic_result` as a base class, and is implicitly convertible to `basic_result`. Whilst not guaranteed, it is very likely that the type is a `basic_result`, or inherits publicly from a `basic_result`. If you want something which matches any value-or-error type, consider {{% api "value_or_error<T>" %}}. If you want something which exactly matches `basic_outcome`, use {{% api "is_basic_outcome<T>" %}}. *Namespace*: `OUTCOME_V2_NAMESPACE::concepts` *Header*: `<outcome/basic_result.hpp>`
0
repos/outcome/doc/src/content/reference
repos/outcome/doc/src/content/reference/concepts/value_or_error.md
+++ title = "`value_or_error<T>`" description = "A boolean concept matching types with either a value or an error." +++ If on C++ 20 or the Concepts TS is enabled, a boolean concept matching types with a public `.has_value()` observer which returns `bool`, a public `.value()` observer function, and a public `.error()` observer function. If without Concepts, a static constexpr bool which is true for types matching the same requirements, using a SFINAE based emulation. This concept matches expected-like types such as {{% api "std::expected<T, E>" %}}, one of which is {{% api "basic_result<T, E, NoValuePolicy>" %}}. Be aware it does not differentiate between value-*or*-error types and value-*and*-error types if they present the interface matched above. If you want a concept matching specifically {{% api "basic_result<T, E, NoValuePolicy>" %}}, see {{% api "basic_result<T>" %}}. *Namespace*: `OUTCOME_V2_NAMESPACE::concepts` *Header*: `<outcome/convert.hpp>` *Legacy*: This was named `convert::ValueOrError<T>` in Outcome v2.1 and earlier. Define {{% api "OUTCOME_ENABLE_LEGACY_SUPPORT_FOR" %}} to less than `220` to enable.
0
repos/outcome/doc/src/content/reference
repos/outcome/doc/src/content/reference/concepts/basic_result.md
+++ title = "`basic_result<T>`" description = "A boolean concept matching types which are convertible to a `basic_result<T, E, NoValuePolicy>`." +++ If on C++ 20 or the Concepts TS is enabled, a boolean concept matching types which have `value_type`, `error_type` and `no_value_policy_type` member typedefs; that the type is convertible to `basic_result<value_type, error_type, no_value_policy_type>`; that `basic_result<value_type, error_type, no_value_policy_type>` is a base of the type. If without Concepts, a static constexpr bool which is true for types matching the same requirements, using a SFINAE based emulation. This concept matches any type which provides the same typedefs as a {{% api "basic_result<T, E, NoValuePolicy>" %}}, has that `basic_result` as a base class, and is implicitly convertible to `basic_result`. Whilst not guaranteed, it is very likely that the type is a `basic_result`, or inherits publicly from a `basic_result`. If you want something which matches any value-or-error type, consider {{% api "value_or_error<T>" %}}. If you want something which exactly matches `basic_result`, use {{% api "is_basic_result<T>" %}}. *Namespace*: `OUTCOME_V2_NAMESPACE::concepts` *Header*: `<outcome/basic_result.hpp>`
0
repos/outcome/doc/src/content/reference
repos/outcome/doc/src/content/reference/aliases/checked.md
+++ title = "`checked<T, E = varies>`" description = "A type alias to a `std_checked<T, E>` (standalone edition) or `boost_checked<T, E>` (Boost edition)." +++ A type alias to either {{% api "std_checked<T, E = std::error_code>" %}} (standalone edition) or {{% api "boost_checked<T, E = boost::system::error_code>" %}} (Boost edition). This means that `checked<T>` uses the appropriate default alias depending on which edition of Outcome is in use. *Namespace*: `OUTCOME_V2_NAMESPACE` *Header*: `<outcome/result.hpp>`
0
repos/outcome/doc/src/content/reference
repos/outcome/doc/src/content/reference/aliases/_index.md
+++ title = "Aliases" weight = 60 +++ {{% children description="true" depth="2" %}}
0
repos/outcome/doc/src/content/reference
repos/outcome/doc/src/content/reference/aliases/boost_checked.md
+++ title = "`boost_checked<T, E = boost::system::error_code>`" description = "A type alias to a `basic_result` configured with `boost::system::error_code` and `policy::throw_bad_result_access<EC>`." +++ A type alias to a {{% api "basic_result<T, E, NoValuePolicy>" %}} configured with `boost::system::error_code` and `policy::`{{% api "throw_bad_result_access<EC>" %}}. This type alias always references the `boost` edition of things, unlike {{% api "checked<T, E = varies>" %}} which references either this alias or {{% api "std_checked<T, E = std::error_code>" %}}. *Namespace*: `OUTCOME_V2_NAMESPACE` *Header*: `<outcome/boost_result.hpp>`
0
repos/outcome/doc/src/content/reference
repos/outcome/doc/src/content/reference/aliases/outcome.md
+++ title = "`outcome<T, EC = varies, EP = varies, NoValuePolicy = policy::default_policy<T, EC, EP>>`" description = "A type alias to a `std_outcome<T, EC, EP, NoValuePolicy>` (standalone edition) or `boost_outcome<T, EC, EP, NoValuePolicy>` (Boost edition)." +++ A type alias to either {{% api "std_outcome<T, EC = std::error_code, EP = std::exception_ptr, NoValuePolicy = policy::default_policy<T, EC, EP>>" %}} (standalone edition) or {{% api "boost_outcome<T, EC = boost::system::error_code, EP = boost::exception_ptr, NoValuePolicy = policy::default_policy<T, EC, EP>>" %}} (Boost edition), and `policy::`{{% api "default_policy" %}}. This means that `outcome<T>` uses the appropriate default alias depending on which edition of Outcome is in use. *Namespace*: `OUTCOME_V2_NAMESPACE` *Header*: `<outcome/outcome.hpp>`
0
repos/outcome/doc/src/content/reference
repos/outcome/doc/src/content/reference/aliases/std_result.md
+++ title = "`std_result<T, E = std::error_code, NoValuePolicy = policy::default_policy<T, E, void>>`" description = "A type alias to a `basic_result` configured with `std::error_code` and `policy::default_policy`." +++ A type alias to a {{% api "basic_result<T, E, NoValuePolicy>" %}} configured with {{% api "std::error_code" %}} and `policy::`{{% api "default_policy" %}}. This type alias always references the `std` edition of things, unlike {{% api "result<T, E = varies, NoValuePolicy = policy::default_policy<T, E, void>>" %}} which references either this alias or {{% api "boost_result<T, E = boost::system::error_code, NoValuePolicy = policy::default_policy<T, E, void>>" %}}. *Namespace*: `OUTCOME_V2_NAMESPACE` *Header*: `<outcome/std_result.hpp>`