### Initial Get with Pseudo-version Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_upgrade_pseudo.txt Starts with a specific pseudo-version and verifies the module list. Ensures that `go get` selects the specified pseudo-version. ```bash go get example.com/pseudoupgrade@b5426c8 go list -m -u all stdout '^example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553$' ``` -------------------------------- ### Initial Setup and Get Latest Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_ambiguous_arg.txt Initializes the module and fetches the latest version of a potentially ambiguous module/package 'm/p'. Verifies the retrieved version. ```bash go mod tidy cp go.mod go.mod.orig go get m/p # @latest go list -m all stdout '^m/p v0.3.0 ' ! stdout '^m ' ``` -------------------------------- ### Go Install with Shadowed GOPATH Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/install_shadow_gopath.txt This snippet demonstrates the setup and execution of a test case for 'go install' with shadowed GOPATH entries. It configures the environment, creates necessary directories and files, and then runs 'go install' to check for the expected error message. ```bash env GO111MODULE=off env GOPATH=$WORK/gopath1${:}$WORK/gopath2 mkdir $WORK/gopath1/src/test mkdir $WORK/gopath2/src/test cp main.go $WORK/gopath2/src/test/main.go cd $WORK/gopath2/src/test ! go install stderr 'no install location for.*gopath2.src.test: hidden by .*gopath1.src.test' ``` -------------------------------- ### Go Mod and Main Go File Setup Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_upgrade_patch.txt Provides the 'go.mod' and 'main.go' files used in the preceding examples to set up the project context. ```go module x require patch.example.com/direct v1.0.0 ``` ```go package x import _ "patch.example.com/direct" ``` -------------------------------- ### Go Get Update Test Setup Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/get_update.txt Sets up the environment and rewinds the repository to a previous state before running 'go get -u'. This is part of a test scenario to verify update logic. ```bash env GO111MODULE=off # Rewind go get github.com/rsc/go-get-issue-9224-cmd cd $GOPATH/src/github.com/rsc/go-get-issue-9224-lib exec git reset --hard HEAD~ ``` -------------------------------- ### Setup and Fetch Cgo Package Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_case_cgo.txt This snippet shows the commands to enable Go modules, get a package that uses Cgo, and then build it. Ensure GO111MODULE is set to 'on' before running these commands. ```bash env GO111MODULE=on go get rsc.io/CGO [short] stop go build rsc.io/CGO ``` -------------------------------- ### Setup and Build Go Module Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/vendor_test_issue14613.txt Sets up the Go environment by disabling module mode and then gets and builds a specific Go package. This is a prerequisite for testing vendored modules. ```bash env GO111MODULE=off cd $GOPATH go get github.com/clsung/go-vendor-issue-14613 go build -o $WORK/a.out -i github.com/clsung/go-vendor-issue-14613 ``` -------------------------------- ### Compile and Run Example Source: https://github.com/gcc-mirror/gcc/blob/master/gcc/doc/libgdiagnostics/intro/tutorial02.md Command-line instructions to compile a C file using libgccjit and then run the resulting executable. Ensure the libgccjit library is installed and accessible. ```console $ gcc \ tut02-square.c \ -o tut02-square \ -lgccjit # Run the built program: $ ./tut02-square result: 25 ``` -------------------------------- ### Doxygen File Header Example (Debug Extension) Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/documentation_hacking.html For filenames that are not unique across directories, include part of the installed path in the @file directive to disambiguate. ```cpp /** @file debug/vector * This file is a GNU debug extension to the Standard C++ Library. */ ``` -------------------------------- ### Initial Go Get with Ambiguous Package Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_ambiguous_pkg.txt When starting from a clean slate, 'go get' resolves the package from the module with the longest matching prefix. This example shows 'go get' choosing the nested package path. ```bash cp go.mod go.mod.orig go get example.net/ambiguous/nested/pkg@v0.1.0 go list -m all stdout '^example.net/ambiguous/nested v0.1.0$' ! stdout '^example.net/ambiguous ' ``` -------------------------------- ### Resolve to Empty Module with Wildcard and Go Get Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_split.txt Starting with no dependencies, a wildcard pattern can resolve to an empty module with the same prefix, even if it contains no packages. This allows for initial setup of module paths. ```bash go get example.net/...@none go get example.net/split/...@v0.1.0 go list -m all stdout '^example.net/split v0.1.0 ' ``` -------------------------------- ### Setup Go Cache and Build Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/clean_cache_n.txt Sets up a clean Go cache directory and builds a sample Go program to populate the cache. ```bash env GOCACHE=$WORK/cache go build main.go ``` -------------------------------- ### Tuning mt_allocator Parameters Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/mt_allocator_impl.html Demonstrates how to create and apply custom tuning parameters for the mt_allocator. Parameters must be set before any allocations occur. The example shows initializing tuning structs and using static methods to get and set global allocator options. ```cpp #include struct pod { int i; int j; }; int main() { typedef pod value_type; typedef __gnu_cxx::__mt_alloc allocator_type; typedef __gnu_cxx::__pool_base::_Tune tune_type; tune_type t_default; tune_type t_opt(16, 5120, 32, 5120, 20, 10, false); tune_type t_single(16, 5120, 32, 5120, 1, 10, false); tune_type t; t = allocator_type::_M_get_options(); allocator_type::_M_set_options(t_opt); t = allocator_type::_M_get_options(); allocator_type a; allocator_type::pointer p1 = a.allocate(128); allocator_type::pointer p2 = a.allocate(5128); a.deallocate(p1, 128); a.deallocate(p2, 5128); return 0; } ``` -------------------------------- ### Install Benign Repository with 'go get' Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/get_dotfiles.txt Uses 'go get -u' to install the benign repository, ensuring it's correctly fetched and built. ```bash cd $GOPATH go get -u example.com/foo ``` -------------------------------- ### Initial Setup and Control Case Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_update_unrelated_sum.txt Sets up the initial state by copying original go.mod and go.sum files and running 'go mod tidy'. Verifies that the files remain unchanged, establishing a baseline. ```bash cp go.mod.orig go.mod cp go.sum.orig go.sum go mod tidy cmp go.mod.orig go.mod cmp go.sum.orig go.sum ``` -------------------------------- ### Install Packages with Go Get Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/get_dash_t.txt Use 'go get' to download and install packages. The '-v' flag provides verbose output, and '-t' includes test dependencies. ```bash env GO111MODULE=off go get -v -t github.com/rsc/go-get-issue-8181/a github.com/rsc/go-get-issue-8181/b ``` -------------------------------- ### Example Project Structure and Build Commands Source: https://github.com/gcc-mirror/gcc/blob/master/gcc/doc/libgdiagnostics/cp/intro/tutorial04.md Lists the files in the example project directory and shows the commands to build and run the `toyvm` executable. ```console $ ls -al drwxrwxr-x. 2 david david 4096 Sep 19 17:46 . drwxrwxr-x. 3 david david 4096 Sep 19 15:26 .. -rw-rw-r--. 1 david david 615 Sep 19 12:43 factorial.toy -rw-rw-r--. 1 david david 834 Sep 19 13:08 fibonacci.toy -rw-rw-r--. 1 david david 238 Sep 19 14:22 Makefile -rw-rw-r--. 1 david david 16457 Sep 19 17:07 toyvm.cc $ make toyvm g++ -Wall -g -o toyvm toyvm.cc -lgccjit $ ./toyvm factorial.toy 10 interpreter result: 3628800 compiler result: 3628800 $ ./toyvm fibonacci.toy 10 interpreter result: 55 compiler result: 55 ``` -------------------------------- ### Example of Text Code Block Source: https://github.com/gcc-mirror/gcc/blob/master/gcc/ada/doc/gnat_ugn/about_this_guide.rst This is how text examples are presented in the guide. It is not executable code. ```text and then shown this way. ``` -------------------------------- ### Get Executable Start Address with objdump Source: https://github.com/gcc-mirror/gcc/blob/master/gcc/ada/doc/gnat_ugn/platform_specific_information.rst Use objdump to find the starting address of an executable for debugging purposes. ```bash $ objdump --file-header main.exe ``` -------------------------------- ### Initial Go Module Setup Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_lazy_import_allmod.txt Sets up the initial Go module configuration and verifies that dependencies are correctly listed. ```bash cp go.mod go.mod.orig go mod tidy cmp go.mod.orig go.mod go list -m all stdout '^a v0.1.0 ' stdout '^b v0.1.0 ' stdout '^c v0.1.0 ' ``` -------------------------------- ### Example: Get Built-in Memcpy Function Source: https://github.com/gcc-mirror/gcc/blob/master/gcc/doc/libgdiagnostics/topics/functions.md This example demonstrates how to obtain a handle to the '__builtin_memcpy' function using the GCC JIT API. ```c gcc_jit_function *fn = gcc_jit_context_get_builtin_function (ctxt, "__builtin_memcpy"); ``` -------------------------------- ### Initial Setup and Verification Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/work_sync_sum.txt Copies the go.sum file, tidies the module, and compares the modified go.sum with the original to ensure it remains unchanged. ```bash cp b/go.sum b/go.sum.want # As a sanity check, verify b/go.sum is tidy. cd b go mod tidy cd .. cmp b/go.sum b/go.sum.want ``` -------------------------------- ### Download and Initialize Module (GCS Bucket) Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_convert.txt This example demonstrates downloading a module, copying its lock file, initializing a new module, and comparing the go.mod file. ```bash go mod download github.com/fishy/gcsbucket@v0.0.0-20180217031846-618d60fe84e0 cp $GOPATH/pkg/mod/github.com/fishy/gcsbucket@v0.0.0-20180217031846-618d60fe84e0/Gopkg.lock ../y cd ../y go mod init github.com/fishy/gcsbucket cmpenv go.mod go.mod.want ``` -------------------------------- ### Install ZLIB Pkg-config File Source: https://github.com/gcc-mirror/gcc/blob/master/zlib/CMakeLists.txt Installs the zlib pkg-config file to the specified directory. This is skipped if SKIP_INSTALL_FILES or SKIP_INSTALL_ALL is set. ```cmake if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") endif() ``` -------------------------------- ### Go Get Missing VCS Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_vcs_missing.txt Demonstrates the error message when 'go get' is run without the necessary VCS executable (bzr) installed. ```bash env GO111MODULE=on env GOPROXY=direct cd empty ! go get launchpad.net/gocheck stderr '"bzr": executable file not found' cd .. ``` -------------------------------- ### Initial Module Setup Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_extra.txt Copies the go.mod file to preserve the original state before running commands. ```bash cp go.mod go.mod.orig ``` -------------------------------- ### Priority Queue Push and Modify Example Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/policy_data_structures.html Demonstrates using the push method of a priority queue to get an iterator, which can then be used to modify an element. This is useful for applications requiring dynamic updates to priority queue elements. ```cpp priority_queue p; priority_queue::point_iterator it = p.push(3); p.modify(it, 4); ``` -------------------------------- ### Build Example Executable Source: https://github.com/gcc-mirror/gcc/blob/master/zlib/CMakeLists.txt Adds an executable target named 'example' using test/example.c and links it against the zlib library. It also registers it as a CTest test. ```cmake add_executable(example test/example.c) target_link_libraries(example zlib) add_test(example example) ``` -------------------------------- ### Install ZLIB Man Page Source: https://github.com/gcc-mirror/gcc/blob/master/zlib/CMakeLists.txt Installs the zlib man page (zlib.3) to the specified man directory. This is skipped if SKIP_INSTALL_FILES or SKIP_INSTALL_ALL is set. ```cmake if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3") endif() ``` -------------------------------- ### Initialize Module and List Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_init_empty.txt Sets up the environment for an empty module and then lists the module path. Ensures GO111MODULE is on and GOPATH is nullified for isolated testing. ```bash env GO111MODULE=on env GOPATH=$devnull go list -m stdout '^example.com$' go list stdout '^example.com$' ``` -------------------------------- ### Module Code Example Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/work_replace_conflict.txt Example Go code within a module that imports and uses a dependency. This snippet is part of the setup for demonstrating replace conflicts. ```go package m import "example.com/dep" func F() { dep.G() } ``` ```go package n import "example.com/dep" func F() { dep.G() } ``` -------------------------------- ### Build 64-bit Example Executable Source: https://github.com/gcc-mirror/gcc/blob/master/zlib/CMakeLists.txt Adds a 64-bit example executable target named 'example64' using test/example.c, linking it against zlib, and setting the COMPILE_FLAGS to enable 64-bit file offsets. It's also registered as a CTest test. ```cmake add_executable(example64 test/example.c) target_link_libraries(example64 zlib) set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") add_test(example64 example64) ``` -------------------------------- ### Download Module Example Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_query_empty.txt Demonstrates downloading a specific version of a module. Ensure GO111MODULE and GOSUMDB are set appropriately. ```bash env GO111MODULE=on env GOSUMDB=off go mod download example.com/join@v1.1.0 ``` -------------------------------- ### Check Unicode Identifier Start Character Source: https://github.com/gcc-mirror/gcc/blob/master/libgrust/libformat_parser/vendor/unicode-xid/README.md Use `UnicodeXID::is_xid_start` to check if a character is a valid start for a Unicode identifier. This example requires the `unicode-xid` crate. ```rust extern crate unicode_xid; use unicode_xid::UnicodeXID; fn main() { let ch = 'a'; println!("Is {} a valid start of an identifier? {}", ch, UnicodeXID::is_xid_start(ch)); } ``` -------------------------------- ### Example target_list configuration Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/testsuite/experimental/simd/README.md Demonstrates how to configure the `target_list` environment variable for running SIMD tests with different compiler flags and architectures. ```sh target_list="unix{-march=sandybridge,-march=native/-ffast-math,-march=native/-ffinite-math-only}" ``` -------------------------------- ### Install ZLIB Libraries Source: https://github.com/gcc-mirror/gcc/blob/master/zlib/CMakeLists.txt Installs the zlib and zlibstatic targets to the appropriate runtime, archive, and library directories based on installation prefixes. This command is skipped if SKIP_INSTALL_LIBRARIES or SKIP_INSTALL_ALL is set. ```cmake if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) install(TARGETS zlib zlibstatic RUNTIME DESTINATION "${INSTALL_BIN_DIR}" ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) endif() ``` -------------------------------- ### Shell Script Example Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/appendix_porting.html A simple shell script example. Files containing pure shell script can be sourced directly at configure time. ```shell AC_TRY_LINK ``` -------------------------------- ### CHECK_SIMD_CONFIG script example Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/testsuite/experimental/simd/README.md An example `sh` script for `CHECK_SIMD_CONFIG` that sets `target_list` based on the target triplet, including definitions for different architectures and CPU types. ```sh case "$target_triplet" in x86_64-*) target_list="unix{-march=sandybridge,-march=skylake-avx512,-march=native/-ffast-math,-march=athlon64,-march=core2,-march=nehalem,-march=skylake,-march=native/-ffinite-math-only,-march=knl}" ;; powerpc64le-*) define_target power7 "-mcpu=power7 -static" "$HOME/bin/run_on_gccfarm gcc112" define_target power8 "-mcpu=power8 -static" "$HOME/bin/run_on_gccfarm gcc112" define_target power9 "-mcpu=power9 -static" "$HOME/bin/run_on_gccfarm gcc135" target_list="power7 power8 power9{,-ffast-math}" ;; powerpc64-*) define_target power7 "-mcpu=power7 -static" "$HOME/bin/run_on_gccfarm gcc110" define_target power8 "-mcpu=power8 -static" "$HOME/bin/run_on_gccfarm gcc110" target_list="power7 power8{,-ffast-math}" ;; esac ``` -------------------------------- ### Define TLS Get Addr Expand Source: https://github.com/gcc-mirror/gcc/blob/master/gcc/config/rs6000/rs6000.md Expands the TLS get address operation, handling operand setup and calling the internal instruction. Supports XCOFF and AS_TLS. ```gcc-machine-description (define_expand "tls_get_addr" [(set (match_operand:P 0 "gpc_reg_operand") (unspec:P [(match_operand:P 1 "gpc_reg_operand") (match_operand:P 2 "gpc_reg_operand")] UNSPEC_TLSTLS))] "TARGET_XCOFF && HAVE_AS_TLS" { emit_move_insn (gen_rtx_REG (Pmode, 3), operands[1]); emit_move_insn (gen_rtx_REG (Pmode, 4), operands[2]); emit_insn (gen_tls_get_addr_internal ()); emit_move_insn (operands[0], gen_rtx_REG (Pmode, 3)); DONE; }) ``` -------------------------------- ### Install ZLIB Public Headers Source: https://github.com/gcc-mirror/gcc/blob/master/zlib/CMakeLists.txt Installs the public header files for zlib to the specified include directory. This is skipped if SKIP_INSTALL_HEADERS or SKIP_INSTALL_ALL is set. ```cmake if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}") endif() ``` -------------------------------- ### Set up GOCACHE Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/build_cache_compile.txt Initializes a fresh GOCACHE directory for the build. ```bash env GO111MODULE=off [short] skip # Set up fresh GOCACHE. env GOCACHE=$WORK/gocache mkdir $GOCACHE ``` -------------------------------- ### Install Dependencies with `go get` Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/vendor_test_issue11864.txt Installs the necessary package for testing issue 11864. Ensure GO111MODULE is set to 'off' for this command to behave as expected in older Go versions. ```bash env GO111MODULE=off go get github.com/rsc/go-get-issue-11864 ``` -------------------------------- ### Autoconf Macro Example Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/appendix_porting.html An example of an autoconf macro. Macros written in ancillary .m4 files must be processed by autoconf. ```autoconf AC_DEFINE ``` -------------------------------- ### Install Echo Command for Windows Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/generate.txt Installs the 'echo.go' program to the GOBIN directory, making it available in the PATH. This is a setup step for Windows environments that lack a native echo command. ```bash env GOBIN=$WORK/tmp/bin go install echo.go env PATH=$GOBIN:${PATH} ``` -------------------------------- ### Start libstdc++ Build Process Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/appendix_porting.html Initiates the build process for libstdc++ after configuration is complete. This command is typically run from the build directory. ```shell make all ``` -------------------------------- ### Example of a Versioned Symbol Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/abi.html An example of a symbol name that includes versioning information, specifically 'GLIBCXX_3.4'. This confirms that ABI versioning is active. ```text `U _ZNSt8ios_base4InitC1Ev@@GLIBCXX_3.4` ``` -------------------------------- ### Run Tests with Installed Tools Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/test.html Execute the libstdc++ testsuite using an already installed compiler and library. Ensure the compiler is in PATH and the shared library is in LD_LIBRARY_PATH. ```bash runtest --tool libstdc++ --srcdir=/path/to/gcc/libstdc++-v3/testsuite ``` -------------------------------- ### Error Message for Shadowed Package Installation Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/list_shadow.txt This example shows the error message generated by 'go install -n' when attempting to install a shadowed package. The error message correctly identifies the conflicting package directory, aiding in debugging shadowing issues. ```bash # The error for go install should mention the conflicting directory. ! go install -n ./shadow/root2/src/foo stderr 'go: no install location for '$WORK'(\|/)?gopath(\|/)?src(\|/)?shadow(\|/)?root2(\|/)?src(\|/)?foo: hidden by '$WORK'(\|/)?gopath(\|/)?src(\|/)?shadow(\|/)?root1(\|/)?src(\|/)?foo' ``` -------------------------------- ### Initial Go Module Setup Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_downup_pseudo_artifact.txt Sets up the initial `go.mod` file for the test, defining module requirements and replacements, including pseudo-versions. ```go module example.net/a go 1.16 require ( example.net/b v0.3.0 example.net/c v0.2.0 ) replace ( example.net/b v0.1.0 => ./b1 example.net/b v0.2.1-0.20210219000000-000000000000 => ./b2 example.net/b v0.3.0 => ./b3 example.net/c v0.1.0 => ./c1 example.net/c v0.2.0 => ./c2 example.net/d v0.1.0 => ./d example.net/d v0.2.0 => ./d example.net/e v0.1.0 => ./e ) ``` -------------------------------- ### Parallel Algorithm Interface Example Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/parallel_mode_design.html Illustrates the expected interface for parallel algorithms, showing the ISO C++ signature and the internal parallel namespace signature. ```c++ namespace std { template _FIter adjacent_find(_FIter, _FIter); } ``` ```c++ namespace std { namespace __parallel { template _FIter adjacent_find(_FIter, _FIter); ... } } ``` -------------------------------- ### Project File Structure and Build Command Source: https://github.com/gcc-mirror/gcc/blob/master/gcc/jit/docs/intro/tutorial04.md Lists the files in the example project directory and shows the command used to build the `toyvm` executable. ```console $ ls -al drwxrwxr-x. 2 david david 4096 Sep 19 17:46 . drwxrwxr-x. 3 david david 4096 Sep 19 15:26 .. -rw-rw-r--. 1 david david 615 Sep 19 12:43 factorial.toy -rw-rw-r--. 1 david david 834 Sep 19 13:08 fibonacci.toy -rw-rw-r--. 1 david david 238 Sep 19 14:22 Makefile -rw-rw-r--. 1 david david 16457 Sep 19 17:07 toyvm.c $ make toyvm g++ -Wall -g -o toyvm toyvm.c -lgccjit ``` -------------------------------- ### Go Get with GO111MODULE=off Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/get_404_meta.txt Execute 'go get -d' with GO111MODULE set to 'off'. This configuration is used to download dependencies without installing them, relevant for testing older module behaviors. ```bash env GONOSUMDB=bazil.org,github.com,golang.org env GO111MODULE=off go get -d bazil.org/fuse/fs/fstestutil ``` -------------------------------- ### Unicode Code Conversion Example Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/facets.html Demonstrates converting a C-style string literal to a Unicode string using a specialized codecvt facet within a locale. This example requires constructing a locale with the custom facet and verifying the conversion results. ```cpp typedef codecvt_base::result result; typedef unsigned short unicode_t; typedef unicode_t int_type; typedef char ext_type; typedef encoding_state state_type; typedef codecvt unicode_codecvt; const ext_type* e_lit = "black pearl jasmine tea"; int size = strlen(e_lit); int_type i_lit_base[24] = { 25088, 27648, 24832, 25344, 27392, 8192, 28672, 25856, 24832, 29184, 27648, 8192, 27136, 24832, 29440, 27904, 26880, 28160, 25856, 8192, 29696, 25856, 24832, 2560 }; const int_type* i_lit = i_lit_base; const ext_type* efrom_next; const int_type* ifrom_next; ext_type* e_arr = new ext_type[size + 1]; ext_type* eto_next; int_type* i_arr = new int_type[size + 1]; int_type* ito_next; // construct a locale object with the specialized facet. locale loc(locale::classic(), new unicode_codecvt); // sanity check the constructed locale has the specialized facet. VERIFY( has_facet(loc) ); const unicode_codecvt& cvt = use_facet(loc); // convert between const char* and unicode strings unicode_codecvt::state_type state01("UNICODE", "ISO_8859-1"); initialize_state(state01); result r1 = cvt.in(state01, e_lit, e_lit + size, efrom_next, i_arr, i_arr + size, ito_next); VERIFY( r1 == codecvt_base::ok ); VERIFY( !int_traits::compare(i_arr, i_lit, size) ); VERIFY( efrom_next == e_lit + size ); VERIFY( ito_next == i_arr + size ); ``` -------------------------------- ### Go Get U Patch All Example Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_patch.txt Tests the behavior of 'go get -u=patch all', which should be equivalent to 'all@patch'. It verifies that this command fails if patched versions result in a higher-than-patch upgrade. ```go # "-u=patch all" should be equivalent to "all@patch", and should fail if the # patched versions result in a higher-than-patch upgrade. cp go.mod.orig go.mod ! go get -u=patch all stderr '^go: example.net/a@v0.1.1 \(matching all@patch\) requires example.net/b@v0.2.0, not example.net/b@v0.1.1 \(matching all@patch\)$' cmp go.mod go.mod.orig ``` -------------------------------- ### Initialize Git Repositories Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/get_brace.txt Sets up two empty Git repositories, one with a standard name and another with a confusing name, to test 'go get' behavior. ```bash cd $WORK/_origin/foo exec git init exec git config user.name 'Nameless Gopher' exec git config user.email 'nobody@golang.org' exec git commit --allow-empty -m 'create master branch' ``` ```bash cd $WORK cd '_origin/{confusing}' exec git init exec git config user.name 'Nameless Gopher' exec git config user.email 'nobody@golang.org' exec git commit --allow-empty -m 'create master branch' ``` -------------------------------- ### SIMD Test Directives Examples Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/testsuite/experimental/simd/README.md Examples of directives used to control SIMD test execution based on type, ABI subset, target, and CXXFLAGS. ```cpp // The test is only valid for floating-point types: // only: float|double|ldouble * * * ``` ```cpp // Skip the test for long double for all powerpc64* targets: // skip: ldouble * powerpc64* * ``` ```cpp // The test is expected to unconditionally fail on execution: // xfail: run * * * * ``` ```cpp // ABI subsets 1-9 are considered expensive: // expensive: * [1-9] * * ``` -------------------------------- ### Checking Thread Model Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/using_concurrency.html This example shows how to check the thread model reported by GCC. Ensure the thread model is not 'single' for multithreaded support. ```bash %gcc -v Using built-in specs. ... Thread model: posix gcc version 4.1.2 20070925 (Red Hat 4.1.2-33) ``` -------------------------------- ### Compile and Link a Simple C++ File Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/abi.html Example of compiling a basic C++ file and linking it against the shared libstdc++ library. This is a prerequisite for checking ABI versioning. ```c++ #include int main() { std::cout << "hello" << std::endl; return 0; } ``` -------------------------------- ### Execute Go Get with Verbose Output Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_fallback.txt Runs 'go get' with verbose and debug flags to observe the module download process. This command is used to fetch and install Go packages and their dependencies. ```bash go get -x -v golang.org/x/tools/cmd/goimports ``` -------------------------------- ### Example Module A v0.2.0 Go File Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_issue47979.txt A Go file for module 'example.net/a' version v0.2.0, demonstrating usage of an indirect dependency. ```go package a import "example.net/indirect" ``` -------------------------------- ### Forward Declaration Example Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/io.html Include when only the names of I/O-related classes are needed, such as for class members or function signatures. ```cpp #include class MyClass { .... std::ifstream& input_file; }; extern std::ostream& operator<< (std::ostream&, MyClass&); ``` -------------------------------- ### Example: Using messages facet with GNU model Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/facets.html Demonstrates opening a message catalog, retrieving translated strings, and closing the catalog. Ensure the locale directory and MO files are correctly set up. ```cpp #include #include using namespace std; void test01() { typedef messages::catalog catalog; const char* dir = "/mnt/egcs/build/i686-pc-linux-gnu/libstdc++/po/share/locale"; const locale loc_de("de_DE"); const messages& mssg_de = use_facet >(loc_de); catalog cat_de = mssg_de.open("libstdc++", loc_de, dir); string s01 = mssg_de.get(cat_de, 0, 0, "please"); string s02 = mssg_de.get(cat_de, 0, 0, "thank you"); cout << "please in german:" << s01 << '\n'; cout << "thank you in german:" << s02 << '\n'; mssg_de.close(cat_de); } ``` -------------------------------- ### Doxygen Math Markup Example Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/doc/html/manual/documentation_hacking.html Use the multi-line @f[...]@f$ format for complicated math functions within Doxygen comments. ```cpp /** * @brief A model of a linear congruential random number generator. * * @f[ * x_{i+1}\leftarrow(ax_{i} + c) \bmod m * @f] */ ``` -------------------------------- ### Main Module Configuration Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_downup_indirect.txt Defines the main module 'example.com/a' and its initial dependencies on 'example.com/b' and 'example.com/c'. Includes 'replace' directives to map module versions to local paths for testing. ```go module example.com/a go 1.15 require ( example.com/b v0.2.0 example.com/c v0.1.0 ) replace ( example.com/b v0.1.0 => ./b1 example.com/b v0.2.0 => ./b2 example.com/c v0.1.0 => ./c1 example.com/c v0.2.0 => ./c2 example.com/d v0.1.0 => ./d example.com/d v0.2.0 => ./d ) ``` -------------------------------- ### Go Get U Patch Dot All Example Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_get_patch.txt Demonstrates that 'go get -u=patch ./...' should patch-upgrade dependencies to a fixed point, even if this results in upgrades beyond the patch level. ```go # On the other hand, "-u=patch ./..." should patch-upgrade dependencies until # they reach a fixed point, even if that results in higher-than-patch upgrades. go get -u=patch ./... go list -m all stdout '^example.net/a v0.1.1 ' stdout '^example.net/b v0.2.1 ' ``` -------------------------------- ### Example: Parsing a Double with fast_float Source: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/src/c++17/fast_float/README.md Demonstrates how to use the fast_float::from_chars function to parse a string into a double. Includes error checking for parsing failures. ```cpp #include "fast_float/fast_float.h" #include int main() { const std::string input = "3.1416 xyz "; double result; auto answer = fast_float::from_chars(input.data(), input.data()+input.size(), result); if(answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; } std::cout << "parsed the number " << result << std::endl; return EXIT_SUCCESS; } ``` -------------------------------- ### Go Test File Setup Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/test_fuzz_cleanup.txt Sets up the test package and imports necessary libraries for fuzzing tests. ```go package cleanup import ( "runtime" "testing" ) ``` -------------------------------- ### Get Volatile Type Source: https://github.com/gcc-mirror/gcc/blob/master/gcc/jit/docs/cp/topics/types.md Obtain the volatile-qualified type. For example, given type 'T', this returns 'volatile T'. ```cpp int_type.get_volatile (); ``` -------------------------------- ### Start Zlib Compression Loop Source: https://github.com/gcc-mirror/gcc/blob/master/zlib/examples/zlib_how.html Begins the main compression loop which reads input data and processes it until the end of the file is reached. This loop contains the primary call to deflate(). ```c /* compress until end of file */ do { ``` -------------------------------- ### Go Source File Example Source: https://github.com/gcc-mirror/gcc/blob/master/libgo/go/cmd/go/testdata/script/mod_convert_tsv.txt This is a minimal Go source file 'x.go' used in the example. ```go -- $WORK/test/x/x.go -- package x // import "m/x" ```