[InstCombine] Handle commuted pattern for `((X s/ C1) << C2) + X` (#121737)
[llvm-project.git] / libcxx / src / print.cpp
blob37b1fc00cd7c38f1209283005451929b32da4a53
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include <__config>
11 #include <cstdlib>
12 #include <print>
14 #include <__system_error/system_error.h>
16 #include "filesystem/error.h"
18 #if defined(_LIBCPP_WIN32API)
19 # define WIN32_LEAN_AND_MEAN
20 # define NOMINMAX
21 # include <io.h>
22 # include <windows.h>
23 #elif __has_include(<unistd.h>)
24 # include <unistd.h>
25 #endif
27 _LIBCPP_BEGIN_NAMESPACE_STD
29 #if defined(_LIBCPP_WIN32API)
31 _LIBCPP_EXPORTED_FROM_ABI bool __is_windows_terminal(FILE* __stream) {
32 // Note the Standard does this in one call, but it's unclear whether
33 // an invalid handle is allowed when calling GetConsoleMode.
35 // https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=msvc-170
36 // https://learn.microsoft.com/en-us/windows/console/getconsolemode
37 intptr_t __handle = _get_osfhandle(fileno(__stream));
38 if (__handle == -1)
39 return false;
41 unsigned long __mode;
42 return GetConsoleMode(reinterpret_cast<void*>(__handle), &__mode);
45 # if _LIBCPP_HAS_WIDE_CHARACTERS
46 _LIBCPP_EXPORTED_FROM_ABI void
47 __write_to_windows_console([[maybe_unused]] FILE* __stream, [[maybe_unused]] wstring_view __view) {
48 // https://learn.microsoft.com/en-us/windows/console/writeconsole
49 if (WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fileno(__stream))), // clang-format aid
50 __view.data(),
51 __view.size(),
52 nullptr,
53 nullptr) == 0) {
54 __throw_system_error(filesystem::detail::make_windows_error(GetLastError()), "failed to write formatted output");
57 # endif // _LIBCPP_HAS_WIDE_CHARACTERS
59 #elif __has_include(<unistd.h>) // !_LIBCPP_WIN32API
61 _LIBCPP_EXPORTED_FROM_ABI bool __is_posix_terminal(FILE* __stream) { return isatty(fileno(__stream)); }
62 #endif
64 _LIBCPP_END_NAMESPACE_STD