diff options
| -rw-r--r-- | libbase/CMakeLists.txt | 67 | ||||
| -rw-r--r-- | libbase/include/core/adt/STLFunctionalExtras.h (renamed from libsupport/include/CoreLib/ADT/STLFunctionalExtras.h) | 12 | ||||
| -rw-r--r-- | libbase/include/core/adt/SmallVector.h (renamed from libsupport/include/CoreLib/ADT/SmallVector.h) | 28 | ||||
| -rw-r--r-- | libbase/include/core/compiler/Compiler.h | 843 | ||||
| -rw-r--r-- | libbase/include/core/compiler/DataTypes.h (renamed from rcc/include/rcc/DataTypes.h) | 4 | ||||
| -rw-r--r-- | libbase/include/core/config/config.h.cmake | 219 | ||||
| -rw-r--r-- | libbase/include/core/config/libbase-config.h.cmake | 89 | ||||
| -rw-r--r-- | libbase/include/core/error/Errno.h (renamed from libsupport/include/CoreLib/System/Errno.h) | 12 | ||||
| -rw-r--r-- | libbase/include/core/error/ErrorHandling.h (renamed from libsupport/include/CoreLib/Error/ErrorHandling.h) | 48 | ||||
| -rw-r--r-- | libbase/include/core/math/MathExtras.h (renamed from libsupport/include/CoreLib/Math/MathExtras.h) | 10 | ||||
| -rw-r--r-- | libbase/include/core/memory/Alignment.h | 342 | ||||
| -rw-r--r-- | libbase/include/core/memory/AllocatorBase.h | 154 | ||||
| -rw-r--r-- | libbase/include/core/memory/MemAlloc.h (renamed from libsupport/include/CoreLib/Memory/MemAlloc.h) | 18 | ||||
| -rw-r--r-- | libbase/src/core/error/Errno.cc (renamed from libsupport/src/corelib/system/Errno.cc) | 4 | ||||
| -rw-r--r-- | libbase/src/core/math/MathExtras.cc (renamed from libsupport/src/corelib/math/MathExtras.cc) | 2 | ||||
| -rw-r--r-- | libbase/src/core/memory/MemAlloc.cpp (renamed from libsupport/src/corelib/memory/MemAlloc.cpp) | 4 | ||||
| -rw-r--r-- | libsupport/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | libsupport/include/CoreLib/Compiler/Compiler.h | 853 | ||||
| -rw-r--r-- | libsupport/include/CoreLib/Error/ErrorOr.h | 378 | ||||
| -rw-r--r-- | rcc/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | rcc/cmake/modules/AddRCC.cmake | 14 | ||||
| -rw-r--r-- | rcc/include/rcc/Config/config.h.cmake | 215 | ||||
| -rw-r--r-- | rcc/include/rcc/Config/rcc-config.h.cmake | 60 | ||||
| -rw-r--r-- | rcc/include/rcc/Support/Compiler.h | 106 |
24 files changed, 1911 insertions, 1601 deletions
diff --git a/libbase/CMakeLists.txt b/libbase/CMakeLists.txt new file mode 100644 index 0000000..798c850 --- /dev/null +++ b/libbase/CMakeLists.txt @@ -0,0 +1,67 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +include(CheckSymbolExists) +include(GNUInstallDirs) + +if(NOT DEFINED RCC_ENABLE_THREADS) + set(RCC_ENABLE_THREADS ON) +endif() + +if(NOT DEFINED LIBBASE_ENABLE_THREADS) + set(LIBBASE_ENABLE_THREADS "${RCC_ENABLE_THREADS}") +endif() +if(NOT DEFINED LIBBASE_BUILD_SHARED_LIBS) + set(LIBBASE_BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS}") +endif() +if(NOT DEFINED LIBBASE_BUILD_STATIC) + if(BUILD_SHARED_LIBS) + set(LIBBASE_BUILD_STATIC OFF) + else() + set(LIBBASE_BUILD_STATIC ON) + endif() +endif() +if(NOT DEFINED LIBBASE_BUILD_LIBBASE_DYLIB) + set(LIBBASE_BUILD_LIBBASE_DYLIB OFF) +endif() + +set(LIBBASE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") +set(LIBBASE_BINARY_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include") +file(MAKE_DIRECTORY "${LIBBASE_BINARY_INCLUDE_DIR}/core/config") + +check_symbol_exists(strerror_r "string.h" HAVE_STRERROR_R) +check_symbol_exists(strerror_s "string.h" HAVE_DECL_STRERROR_S) + +configure_file( + "${LIBBASE_INCLUDE_DIR}/core/config/config.h.cmake" + "${LIBBASE_BINARY_INCLUDE_DIR}/core/config/config.h") +configure_file( + "${LIBBASE_INCLUDE_DIR}/core/config/libbase-config.h.cmake" + "${LIBBASE_BINARY_INCLUDE_DIR}/core/config/libbase-config.h") + +add_library(RCCCore + src/core/math/MathExtras.cc + src/core/memory/MemAlloc.cpp + src/core/error/Errno.cc +) + +target_compile_features(RCCCore PUBLIC cxx_std_23) +target_compile_definitions(RCCCore PRIVATE LIBBASE_EXPORTS) + +target_include_directories(RCCCore + PUBLIC + "$<BUILD_INTERFACE:${LIBBASE_BINARY_INCLUDE_DIR}>" + "$<BUILD_INTERFACE:${LIBBASE_INCLUDE_DIR}>" + "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>") + +install(TARGETS RCCCore + EXPORT RCCTargets + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + +install(DIRECTORY include/core DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + FILES_MATCHING PATTERN "*.h" PATTERN "*.inc" PATTERN "*.def") +install(DIRECTORY "${LIBBASE_BINARY_INCLUDE_DIR}/core" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + FILES_MATCHING PATTERN "*.h" PATTERN "*.inc" PATTERN "*.def" + PATTERN "config.h" EXCLUDE) diff --git a/libsupport/include/CoreLib/ADT/STLFunctionalExtras.h b/libbase/include/core/adt/STLFunctionalExtras.h index 993acc0..915796b 100644 --- a/libsupport/include/CoreLib/ADT/STLFunctionalExtras.h +++ b/libbase/include/core/adt/STLFunctionalExtras.h @@ -33,10 +33,10 @@ // //===----------------------------------------------------------------------===// -#ifndef RCC_ADT_STLFUNCTIONALEXTRAS_H -#define RCC_ADT_STLFUNCTIONALEXTRAS_H +#ifndef LIBBASE_ADT_STLFUNCTIONALEXTRAS_H +#define LIBBASE_ADT_STLFUNCTIONALEXTRAS_H -#include "CoreLib/Compiler/Compiler.h" +#include "core/compiler/Compiler.h" #include <cstddef #include <cstdint> @@ -59,7 +59,7 @@ namespace rcc template <typename Fn> class function_ref; template <typename Ret, typename... Params> -class RCC_GSL_POINTER function_ref<Ret (Params...)> +class LIBBASE_GSL_POINTER function_ref<Ret (Params...)> { Ret (*callback) (intptr_t callable, Params... params) = nullptr; intptr_t callable = 0; @@ -80,7 +80,7 @@ public: template <typename Callable> function_ref ( - Callable &&callable RCC_LIFETIME_BOUND, + Callable &&callable LIBBASE_LIFETIME_BOUND, // This is not the copy-constructor. std::enable_if_t<!std::is_same<std::remove_cvref_t<Callable>, function_ref>::value> * = nullptr, @@ -109,4 +109,4 @@ public: } // end namespace rcc -#endif // RCC_ADT_STLFUNCTIONALEXTRAS_H +#endif // LIBBASE_ADT_STLFUNCTIONALEXTRAS_H diff --git a/libsupport/include/CoreLib/ADT/SmallVector.h b/libbase/include/core/adt/SmallVector.h index 8b9826a..7b3c554 100644 --- a/libsupport/include/CoreLib/ADT/SmallVector.h +++ b/libbase/include/core/adt/SmallVector.h @@ -32,10 +32,10 @@ /// //===----------------------------------------------------------------------===// -#ifndef RCC_ADT_SMALLVECTOR_H -#define RCC_ADT_SMALLVECTOR_H +#ifndef LIBBASE_ADT_SMALLVECTOR_H +#define LIBBASE_ADT_SMALLVECTOR_H -#include "CoreLib/Compiler/Compiler.h" +#include "core/compiler/Compiler.h" #include <algorithm> #include <cassert> #include <cstddef> @@ -97,14 +97,14 @@ protected: /// This is a helper for \a grow() that's out of line to reduce code /// duplication. This function will report a fatal error if it can't grow at /// least to \p MinSize. - RCC_ABI void * + LIBBASE_ABI void * mallocForGrow (void *FirstEl, size_t MinSize, size_t TSize, size_t &NewCapacity); /// This is an implementation of the grow() method which only works /// on POD-like data types and is out of line to reduce code duplication. /// This function will report a fatal error if it cannot increase capacity. - RCC_ABI void + LIBBASE_ABI void grow_pod (void *FirstEl, size_t MinSize, size_t TSize); public: @@ -245,7 +245,7 @@ protected: isSafeToReferenceAfterResize (const void *Elt, size_t NewSize) { // Past the end. - if (RCC_LIKELY (!isReferenceToStorage (Elt))) + if (LIBBASE_LIKELY (!isReferenceToStorage (Elt))) { return true; } @@ -325,7 +325,7 @@ protected: reserveForParamAndGetAddressImpl (U *This, const T &Elt, size_t N) { size_t NewSize = This->size () + N; - if (RCC_LIKELY (NewSize <= This->capacity ())) + if (LIBBASE_LIKELY (NewSize <= This->capacity ())) { return &Elt; } @@ -334,7 +334,7 @@ protected: int64_t Index = -1; if (!U::TakesParamByValue) { - if (RCC_UNLIKELY (This->isReferenceToStorage (&Elt))) + if (LIBBASE_UNLIKELY (This->isReferenceToStorage (&Elt))) { ReferencesStorage = true; Index = &Elt - This->begin (); @@ -799,7 +799,7 @@ protected: // Out-of-line slow path so the inline push_back needs no callee-saved // registers or stack frame on its hot path. - RCC_ATTRIBUTE_NOINLINE void + LIBBASE_ATTRIBUTE_NOINLINE void growAndPushBack (ValueParamT Elt) { // Copy in case Elt is an internal reference invalidated by grow. @@ -813,7 +813,7 @@ public: void push_back (ValueParamT Elt) { - if (RCC_UNLIKELY (this->size () >= this->capacity ())) + if (LIBBASE_UNLIKELY (this->size () >= this->capacity ())) { return growAndPushBack (Elt); } @@ -1354,7 +1354,7 @@ public: reference emplace_back (ArgTypes &&...Args) { - if (RCC_UNLIKELY (this->size () >= this->capacity ())) + if (LIBBASE_UNLIKELY (this->size () >= this->capacity ())) { return this->growAndEmplaceBack (std::forward<ArgTypes> (Args)...); } @@ -1605,7 +1605,7 @@ template <typename T> struct alignas (T) SmallVectorStorage<T, 0> /// Forward declaration of SmallVector so that /// calculateSmallVectorDefaultInlinedElements can reference /// `sizeof(SmallVector<T, 0>)`. -template <typename T, unsigned N> class RCC_GSL_OWNER SmallVector; +template <typename T, unsigned N> class LIBBASE_GSL_OWNER SmallVector; /// Helper class for calculating the default number of inline elements for /// `SmallVector<T>`. @@ -1680,7 +1680,7 @@ template <typename T> struct CalculateSmallVectorDefaultInlinedElements /// \see https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h template <typename T, unsigned N = CalculateSmallVectorDefaultInlinedElements<T>::value> -class RCC_GSL_OWNER SmallVector : public SmallVectorImpl<T>, +class LIBBASE_GSL_OWNER SmallVector : public SmallVectorImpl<T>, SmallVectorStorage<T, N> { public: @@ -1923,4 +1923,4 @@ swap (rcc::SmallVector<T, N> &LHS, rcc::SmallVector<T, N> &RHS) } // end namespace std -#endif // RCC_ADT_SMALLVECTOR_H +#endif // LIBBASE_ADT_SMALLVECTOR_H diff --git a/libbase/include/core/compiler/Compiler.h b/libbase/include/core/compiler/Compiler.h new file mode 100644 index 0000000..b21d6a1 --- /dev/null +++ b/libbase/include/core/compiler/Compiler.h @@ -0,0 +1,843 @@ +/* + RCC-Project + + Copyright (C) 2026 Richard Qin + + This file is part of RCC-Project. + + RCC-Project is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your option) any + later version. + + RCC-Project is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + RCC-Project; see the file COPYING. If not see + <http://www.gnu.org/licenses/>. +*/ + +//===-- core/compiler/Compiler.h - Compiler abstraction support --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines several macros, based on the current compiler. This allows +// use of compiler-specific features in a way that remains portable. This header +// can be included from either C or C++. +// +//===----------------------------------------------------------------------===// + +#ifndef LIBBASE_CORE_COMPILER_H +#define LIBBASE_CORE_COMPILER_H + +#include "core/config/libbase-config.h" + +#include <stddef.h> + +#if defined(_MSC_VER) +#include <sal.h> +#endif + +#ifndef __has_feature +# define __has_feature(x) 0 +#endif + +#ifndef __has_extension +# define __has_extension(x) 0 +#endif + +#ifndef __has_attribute +# define __has_attribute(x) 0 +#endif + +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif + +#ifndef __has_warning +# define __has_warning(x) 0 +#endif + +// Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in +// C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid. +#ifndef LIBBASE_HAS_CPP_ATTRIBUTE +#if defined(__cplusplus) && defined(__has_cpp_attribute) +# define LIBBASE_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) +#else +# define LIBBASE_HAS_CPP_ATTRIBUTE(x) 0 +#endif +#endif + +/// \macro LIBBASE_GNUC_PREREQ +/// Extend the default __GNUC_PREREQ even if glibc's features.h isn't +/// available. +#ifndef LIBBASE_GNUC_PREREQ +# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LIBBASE_GNUC_PREREQ(maj, min, patch) \ + ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \ + ((maj) << 20) + ((min) << 10) + (patch)) +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) +# define LIBBASE_GNUC_PREREQ(maj, min, patch) \ + ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10)) +# else +# define LIBBASE_GNUC_PREREQ(maj, min, patch) 0 +# endif +#endif + +/// \macro LIBBASE_MSC_PREREQ +/// Is the compiler MSVC of at least the specified version? +/// The common \param version values to check for are: +/// * 1910: VS2017, version 15.1 & 15.2 +/// * 1911: VS2017, version 15.3 & 15.4 +/// * 1912: VS2017, version 15.5 +/// * 1913: VS2017, version 15.6 +/// * 1914: VS2017, version 15.7 +/// * 1915: VS2017, version 15.8 +/// * 1916: VS2017, version 15.9 +/// * 1920: VS2019, version 16.0 +/// * 1921: VS2019, version 16.1 +/// * 1922: VS2019, version 16.2 +/// * 1923: VS2019, version 16.3 +/// * 1924: VS2019, version 16.4 +/// * 1925: VS2019, version 16.5 +/// * 1926: VS2019, version 16.6 +/// * 1927: VS2019, version 16.7 +/// * 1928: VS2019, version 16.8 + 16.9 +/// * 1929: VS2019, version 16.10 + 16.11 +/// * 1930: VS2022, version 17.0 +#ifdef _MSC_VER +#define LIBBASE_MSC_PREREQ(version) (_MSC_VER >= (version)) + +// We require at least VS 2019. +#if !defined(LIBBASE_FORCE_USE_OLD_TOOLCHAIN) +#if !LIBBASE_MSC_PREREQ(1920) +#error LLVM requires at least VS 2019. +#endif +#endif + +#else +#define LIBBASE_MSC_PREREQ(version) 0 +#endif + +/// LIBBASE_LIBRARY_VISIBILITY - If a class marked with this attribute is linked +/// into a shared library, then the class should be private to the library and +/// not accessible from outside it. Can also be used to mark variables and +/// functions, making them private to any shared library they are linked into. +/// On PE/COFF targets, library visibility is the default, so this isn't needed. +/// +/// LIBBASE_EXTERNAL_VISIBILITY - classes, functions, and variables marked with +/// this attribute will be made public and visible outside of any shared library +/// they are linked in to. + +#if LIBBASE_HAS_CPP_ATTRIBUTE(gnu::visibility) && defined(__GNUC__) && \ + !defined(__clang__) +#define LIBBASE_ATTRIBUTE_VISIBILITY_HIDDEN [[gnu::visibility("hidden")]] +#define LIBBASE_ATTRIBUTE_VISIBILITY_DEFAULT [[gnu::visibility("default")]] +#elif __has_attribute(visibility) +#define LIBBASE_ATTRIBUTE_VISIBILITY_HIDDEN __attribute__((visibility("hidden"))) +#define LIBBASE_ATTRIBUTE_VISIBILITY_DEFAULT __attribute__((visibility("default"))) +#else +#define LIBBASE_ATTRIBUTE_VISIBILITY_HIDDEN +#define LIBBASE_ATTRIBUTE_VISIBILITY_DEFAULT +#endif + +#if defined(LIBBASE_BUILD_SHARED_LIBS) +#define LIBBASE_EXTERNAL_VISIBILITY LIBBASE_ATTRIBUTE_VISIBILITY_DEFAULT +#else +#define LIBBASE_EXTERNAL_VISIBILITY +#endif + +#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \ + ((defined(__MINGW32__) || defined(__CYGWIN__)) && defined(__clang__))) +#define LIBBASE_LIBRARY_VISIBILITY LIBBASE_ATTRIBUTE_VISIBILITY_HIDDEN +// Clang compilers older then 15 do not support gnu style attributes on +// namespaces. +#if defined(__clang__) && __clang_major__ < 15 +#define LIBBASE_LIBRARY_VISIBILITY_NAMESPACE [[gnu::visibility("hidden")]] +#else +#define LIBBASE_LIBRARY_VISIBILITY_NAMESPACE LIBBASE_ATTRIBUTE_VISIBILITY_HIDDEN +#endif +#define LIBBASE_ALWAYS_EXPORT LIBBASE_ATTRIBUTE_VISIBILITY_DEFAULT +#elif defined(_WIN32) +#define LIBBASE_ALWAYS_EXPORT __declspec(dllexport) +#define LIBBASE_LIBRARY_VISIBILITY +#define LIBBASE_LIBRARY_VISIBILITY_NAMESPACE +#else +#define LIBBASE_LIBRARY_VISIBILITY +#define LIBBASE_ALWAYS_EXPORT +#define LIBBASE_LIBRARY_VISIBILITY_NAMESPACE +#endif + +/// LIBBASE_ABI is the main export/visibility macro to mark something as explicitly +/// exported when llvm is built as a shared library with everything else that is +/// unannotated will have internal visibility. +/// +/// LIBBASE_ABI_EXPORT is for the special case for things like plugin symbol +/// declarations or definitions where we don't want the macro to be switching +/// between dllexport and dllimport on windows based on what codebase is being +/// built, it will only be dllexport. For non windows platforms this macro +/// behaves the same as LIBBASE_ABI. +/// +/// LIBBASE_EXPORT_TEMPLATE is used on explicit template instantiations in source +/// files that were declared extern in a header. This macro is only set as a +/// compiler export attribute on windows, on other platforms it does nothing. +/// +/// LIBBASE_TEMPLATE_ABI is for annotating extern template declarations in headers +/// for both functions and classes. On windows its turned in to dllimport for +/// library consumers, for other platforms its a default visibility attribute. +/// +/// LIBBASE_ABI_FOR_TEST is for annotating symbols that are exported from a +/// library-internal header solely so that unit tests can link against them. +/// Symbols in LLVM's public headers are part of the LLVM public interface and +/// should use LIBBASE_ABI. LIBBASE_ABI_FOR_TEST is reserved for internal headers, +/// whose symbols could be conditionally excluded when not building tests in the +/// future. +/// +#ifndef LIBBASE_ABI_GENERATING_ANNOTATIONS +// Marker to add to classes or functions in public headers that should not have +// export macros added to them by the clang tool +#define LIBBASE_ABI_NOT_EXPORTED +// TODO(https://github.com/llvm/llvm-project/issues/145406): eliminate need for +// two preprocessor definitions to gate LIBBASE_ABI macro definitions. +#if defined(LIBBASE_ENABLE_EXPORT_ANNOTATIONS) && !defined(LIBBASE_BUILD_STATIC) +#if defined(_WIN32) && !defined(__MINGW32__) +#if defined(LIBBASE_EXPORTS) +#define LIBBASE_ABI __declspec(dllexport) +#define LIBBASE_TEMPLATE_ABI +#define LIBBASE_EXPORT_TEMPLATE __declspec(dllexport) +#else +#define LIBBASE_ABI __declspec(dllimport) +#define LIBBASE_TEMPLATE_ABI __declspec(dllimport) +#define LIBBASE_EXPORT_TEMPLATE +#endif +#define LIBBASE_ABI_EXPORT __declspec(dllexport) +#elif __has_attribute(visibility) +#if defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ + defined(__MVS__) || defined(__CYGWIN__) +#define LIBBASE_ABI __attribute__((visibility("default"))) +#define LIBBASE_TEMPLATE_ABI LIBBASE_ABI +#define LIBBASE_EXPORT_TEMPLATE +#define LIBBASE_ABI_EXPORT LIBBASE_ABI +#elif defined(__MACH__) || defined(__wasm__) || defined(__EMSCRIPTEN__) +#define LIBBASE_ABI __attribute__((visibility("default"))) +#define LIBBASE_TEMPLATE_ABI +#define LIBBASE_EXPORT_TEMPLATE +#define LIBBASE_ABI_EXPORT LIBBASE_ABI +#endif +#endif +#endif +#if !defined(LIBBASE_ABI) +#define LIBBASE_ABI +#define LIBBASE_TEMPLATE_ABI +#define LIBBASE_EXPORT_TEMPLATE +#define LIBBASE_ABI_EXPORT +#endif +#define LIBBASE_ABI_FOR_TEST LIBBASE_ABI +#endif + +#if defined(__GNUC__) +#define LIBBASE_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality) +#else +#define LIBBASE_PREFETCH(addr, rw, locality) +#endif + +#if __has_attribute(uninitialized) +#define LIBBASE_ATTRIBUTE_UNINITIALIZED __attribute__((uninitialized)) +#else +#define LIBBASE_ATTRIBUTE_UNINITIALIZED +#endif + +#if __has_attribute(used) +#define LIBBASE_ATTRIBUTE_USED __attribute__((__used__)) +#else +#define LIBBASE_ATTRIBUTE_USED +#endif + +#if __has_attribute(warn_unused) +#define LIBBASE_ATTRIBUTE_WARN_UNUSED __attribute__((warn_unused)) +#else +#define LIBBASE_ATTRIBUTE_WARN_UNUSED +#endif + +// Only enabled for clang: +// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99587 +// GCC may produce "warning: 'retain' attribute ignored" (despite +// __has_attribute(retain) being 1). +#if defined(__clang__) && __has_attribute(retain) +#define LIBBASE_ATTRIBUTE_RETAIN __attribute__((__retain__)) +#else +#define LIBBASE_ATTRIBUTE_RETAIN +#endif + +// For deprecations that are not a simple rename, use [[deprecated(MSG)]] +// instead. +#if defined(__clang__) +#define LIBBASE_DEPRECATED_WITH_FIXIT(MSG, FIX) \ + __attribute__((deprecated(MSG, FIX))) +#else +#define LIBBASE_DEPRECATED_WITH_FIXIT(MSG, FIX) [[deprecated(MSG)]] +#endif + +// clang-format off +#if defined(__clang__) || defined(__GNUC__) +#define LIBBASE_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define LIBBASE_SUPPRESS_DEPRECATED_DECLARATIONS_POP \ + _Pragma("GCC diagnostic pop") +#elif defined(_MSC_VER) +#define LIBBASE_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \ + __pragma(warning(push)) \ + __pragma(warning(disable : 4996)) +#define LIBBASE_SUPPRESS_DEPRECATED_DECLARATIONS_POP \ + __pragma(warning(pop)) +#else +#define LIBBASE_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH +#define LIBBASE_SUPPRESS_DEPRECATED_DECLARATIONS_POP +#endif +// clang-format on + +// Indicate that a non-static, non-const C++ member function reinitializes +// the entire object to a known state, independent of the previous state of +// the object. +// +// The clang-tidy check bugprone-use-after-move recognizes this attribute as a +// marker that a moved-from object has left the indeterminate state and can be +// reused. +#if LIBBASE_HAS_CPP_ATTRIBUTE(clang::reinitializes) +#define LIBBASE_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]] +#else +#define LIBBASE_ATTRIBUTE_REINITIALIZES +#endif + +// Some compilers warn about unused functions. When a function is sometimes +// used or not depending on build settings (e.g. a function only called from +// within "assert"), this attribute can be used to suppress such warnings. +// +// However, it shouldn't be used for unused *variables*, as those have a much +// more portable solution: +// (void)unused_var_name; +// Prefer cast-to-void wherever it is sufficient. +#if __has_attribute(unused) +#define LIBBASE_ATTRIBUTE_UNUSED __attribute__((__unused__)) +#else +#define LIBBASE_ATTRIBUTE_UNUSED +#endif + +// FIXME: Provide this for PE/COFF targets. +#if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \ + !defined(_WIN32) +#define LIBBASE_HAS_ATTRIBUTE_WEAK 1 +#else +#define LIBBASE_HAS_ATTRIBUTE_WEAK 0 +#endif +#if LIBBASE_HAS_ATTRIBUTE_WEAK +#define LIBBASE_ATTRIBUTE_WEAK __attribute__((__weak__)) +#else +#define LIBBASE_ATTRIBUTE_WEAK +#endif + +// Prior to clang 3.2, clang did not accept any spelling of +// __has_attribute(const), so assume it is supported. +#if defined(__clang__) || defined(__GNUC__) +// aka 'CONST' but following LLVM Conventions. +#define LIBBASE_READNONE __attribute__((__const__)) +#else +#define LIBBASE_READNONE +#endif + +#if __has_attribute(pure) || defined(__GNUC__) +// aka 'PURE' but following LLVM Conventions. +#define LIBBASE_READONLY __attribute__((__pure__)) +#else +#define LIBBASE_READONLY +#endif + +#if __has_attribute(minsize) +#define LIBBASE_ATTRIBUTE_MINSIZE __attribute__((minsize)) +#else +#define LIBBASE_ATTRIBUTE_MINSIZE +#endif + +#if __has_builtin(__builtin_expect) || defined(__GNUC__) +#define LIBBASE_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true) +#define LIBBASE_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false) +#else +#define LIBBASE_LIKELY(EXPR) (EXPR) +#define LIBBASE_UNLIKELY(EXPR) (EXPR) +#endif + +/// LIBBASE_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, +/// mark a method "not for inlining". +#if __has_attribute(noinline) +#define LIBBASE_ATTRIBUTE_NOINLINE __attribute__((noinline)) +#elif defined(_MSC_VER) +#define LIBBASE_ATTRIBUTE_NOINLINE __declspec(noinline) +#else +#define LIBBASE_ATTRIBUTE_NOINLINE +#endif + +/// LIBBASE_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do +/// so, mark a method "always inline" because it is performance sensitive. +#if __has_attribute(always_inline) +#define LIBBASE_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline)) +#elif defined(_MSC_VER) +#define LIBBASE_ATTRIBUTE_ALWAYS_INLINE __forceinline +#else +#define LIBBASE_ATTRIBUTE_ALWAYS_INLINE inline +#endif + +/// LIBBASE_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG - Like +/// LIBBASE_ATTRIBUTE_ALWAYS_INLINE but disabled in debug builds to avoid stack +/// overflow with deep recursion. +#if defined(NDEBUG) +#define LIBBASE_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG LIBBASE_ATTRIBUTE_ALWAYS_INLINE +#else +#define LIBBASE_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG inline +#endif + +/// LIBBASE_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do +/// so, mark a method "no debug" because debug info makes the debugger +/// experience worse. +#if __has_attribute(nodebug) +#define LIBBASE_ATTRIBUTE_NODEBUG __attribute__((nodebug)) +#else +#define LIBBASE_ATTRIBUTE_NODEBUG +#endif + +#if __has_attribute(returns_nonnull) +#define LIBBASE_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) +#elif defined(_MSC_VER) +#define LIBBASE_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_ +#else +#define LIBBASE_ATTRIBUTE_RETURNS_NONNULL +#endif + +/// LIBBASE_ATTRIBUTE_RESTRICT - Annotates a pointer to tell the compiler that +/// it is not aliased in the current scope. +#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) +#define LIBBASE_ATTRIBUTE_RESTRICT __restrict +#else +#define LIBBASE_ATTRIBUTE_RESTRICT +#endif + +/// \macro LIBBASE_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a +/// pointer that does not alias any other valid pointer. +#ifdef __GNUC__ +#define LIBBASE_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) +#elif defined(_MSC_VER) +#define LIBBASE_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) +#else +#define LIBBASE_ATTRIBUTE_RETURNS_NOALIAS +#endif + +/// LIBBASE_FALLTHROUGH - Mark fallthrough cases in switch statements. +#if defined(__cplusplus) && __cplusplus > 201402L && LIBBASE_HAS_CPP_ATTRIBUTE(fallthrough) +#define LIBBASE_FALLTHROUGH [[fallthrough]] +#elif LIBBASE_HAS_CPP_ATTRIBUTE(gnu::fallthrough) +#define LIBBASE_FALLTHROUGH [[gnu::fallthrough]] +#elif __has_attribute(fallthrough) +#define LIBBASE_FALLTHROUGH __attribute__((fallthrough)) +#elif LIBBASE_HAS_CPP_ATTRIBUTE(clang::fallthrough) +#define LIBBASE_FALLTHROUGH [[clang::fallthrough]] +#else +#define LIBBASE_FALLTHROUGH +#endif + +/// LIBBASE_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that +/// they are constant initialized. +#if LIBBASE_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization) +#define LIBBASE_REQUIRE_CONSTANT_INITIALIZATION \ + [[clang::require_constant_initialization]] +#else +#define LIBBASE_REQUIRE_CONSTANT_INITIALIZATION +#endif + +/// LIBBASE_GSL_OWNER - Apply this to owning classes like SmallVector to enable +/// lifetime warnings. +#if LIBBASE_HAS_CPP_ATTRIBUTE(gsl::Owner) +#define LIBBASE_GSL_OWNER [[gsl::Owner]] +#else +#define LIBBASE_GSL_OWNER +#endif + +/// LIBBASE_GSL_POINTER - Apply this to non-owning classes like +/// StringRef to enable lifetime warnings. +#if LIBBASE_HAS_CPP_ATTRIBUTE(gsl::Pointer) +#define LIBBASE_GSL_POINTER [[gsl::Pointer]] +#else +#define LIBBASE_GSL_POINTER +#endif + +#if LIBBASE_HAS_CPP_ATTRIBUTE(clang::lifetimebound) +#define LIBBASE_LIFETIME_BOUND [[clang::lifetimebound]] +#else +#define LIBBASE_LIFETIME_BOUND +#endif + +#if LIBBASE_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L +#define LIBBASE_CTOR_NODISCARD [[nodiscard]] +#else +#define LIBBASE_CTOR_NODISCARD +#endif + +// Macro to suppress the MSVC warning C4848: +// "support for attribute [[msvc::no_unique_address]] in C++17 and earlier +// is a vendor extension". +// This warning is removed in versions >= 19.43. +#if !defined(_MSC_VER) || _MSC_VER >= 1943 || defined(__clang__) +#define LIBBASE_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_PUSH +#define LIBBASE_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_POP +#else // MSVC < 19.43 +#define LIBBASE_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_PUSH \ + __pragma(warning(push)) __pragma(warning(disable : 4848)) +#define LIBBASE_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_POP __pragma(warning(pop)) +#endif + +#if LIBBASE_HAS_CPP_ATTRIBUTE(no_unique_address) +#define LIBBASE_NO_UNIQUE_ADDRESS [[no_unique_address]] +#elif LIBBASE_HAS_CPP_ATTRIBUTE(msvc::no_unique_address) +#define LIBBASE_NO_UNIQUE_ADDRESS \ + LIBBASE_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_PUSH \ + [[msvc::no_unique_address]] LIBBASE_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_POP +#else +#define LIBBASE_NO_UNIQUE_ADDRESS +#endif + +/// LIBBASE_EXTENSION - Support compilers where we have a keyword to suppress +/// pedantic diagnostics. +#ifdef __GNUC__ +#define LIBBASE_EXTENSION __extension__ +#else +#define LIBBASE_EXTENSION +#endif + +/// LIBBASE_BUILTIN_UNREACHABLE - On compilers which support it, expands +/// to an expression which states that it is undefined behavior for the +/// compiler to reach this point. Otherwise is not defined. +/// +/// '#else' is intentionally left out so that other macro logic (e.g., +/// LIBBASE_ASSUME_ALIGNED and llvm_unreachable()) can detect whether +/// LIBBASE_BUILTIN_UNREACHABLE has a definition. +#if __has_builtin(__builtin_unreachable) || defined(__GNUC__) +# define LIBBASE_BUILTIN_UNREACHABLE __builtin_unreachable() +#elif defined(_MSC_VER) +# define LIBBASE_BUILTIN_UNREACHABLE __assume(false) +#endif + +/// LIBBASE_BUILTIN_TRAP - On compilers which support it, expands to an expression +/// which causes the program to exit abnormally. +#if __has_builtin(__builtin_trap) || defined(__GNUC__) +# define LIBBASE_BUILTIN_TRAP __builtin_trap() +#elif defined(_MSC_VER) +// The __debugbreak intrinsic is supported by MSVC, does not require forward +// declarations involving platform-specific typedefs (unlike RaiseException), +// results in a call to vectored exception handlers, and encodes to a short +// instruction that still causes the trapping behavior we want. +# define LIBBASE_BUILTIN_TRAP __debugbreak() +#else +# define LIBBASE_BUILTIN_TRAP *(volatile int*)0x11 = 0 +#endif + +/// LIBBASE_BUILTIN_DEBUGTRAP - On compilers which support it, expands to +/// an expression which causes the program to break while running +/// under a debugger. +#if __has_builtin(__builtin_debugtrap) +# define LIBBASE_BUILTIN_DEBUGTRAP __builtin_debugtrap() +#elif defined(_MSC_VER) +// The __debugbreak intrinsic is supported by MSVC and breaks while +// running under the debugger, and also supports invoking a debugger +// when the OS is configured appropriately. +# define LIBBASE_BUILTIN_DEBUGTRAP __debugbreak() +#else +// Just continue execution when built with compilers that have no +// support. This is a debugging aid and not intended to force the +// program to abort if encountered. +# define LIBBASE_BUILTIN_DEBUGTRAP +#endif + +/// \macro LIBBASE_ASSUME_ALIGNED +/// Returns a pointer with an assumed alignment. +#if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__) +# define LIBBASE_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a) +#elif defined(LIBBASE_BUILTIN_UNREACHABLE) +# define LIBBASE_ASSUME_ALIGNED(p, a) \ + (((uintptr_t(p) % (a)) == 0) ? (p) : (LIBBASE_BUILTIN_UNREACHABLE, (p))) +#else +# define LIBBASE_ASSUME_ALIGNED(p, a) (p) +#endif + +/// \macro LIBBASE_PACKED +/// Used to specify a packed structure. +/// LIBBASE_PACKED( +/// struct A { +/// int i; +/// int j; +/// int k; +/// long long l; +/// }); +/// +/// LIBBASE_PACKED_START +/// struct B { +/// int i; +/// int j; +/// int k; +/// long long l; +/// }; +/// LIBBASE_PACKED_END +#ifdef _MSC_VER +# define LIBBASE_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop)) +# define LIBBASE_PACKED_START __pragma(pack(push, 1)) +# define LIBBASE_PACKED_END __pragma(pack(pop)) +#else +# define LIBBASE_PACKED(d) d __attribute__((packed)) +# define LIBBASE_PACKED_START _Pragma("pack(push, 1)") +# define LIBBASE_PACKED_END _Pragma("pack(pop)") +#endif + +/// \macro LIBBASE_MEMORY_SANITIZER_BUILD +/// Whether LLVM itself is built with MemorySanitizer instrumentation. +#if __has_feature(memory_sanitizer) +# define LIBBASE_MEMORY_SANITIZER_BUILD 1 +# include <sanitizer/msan_interface.h> +# define LIBBASE_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory)) +#else +# define LIBBASE_MEMORY_SANITIZER_BUILD 0 +# define __msan_allocated_memory(p, size) +# define __msan_unpoison(p, size) +# define LIBBASE_NO_SANITIZE_MEMORY_ATTRIBUTE +#endif + +/// \macro LIBBASE_ADDRESS_SANITIZER_BUILD +/// Whether LLVM itself is built with AddressSanitizer instrumentation. +#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) +# define LIBBASE_ADDRESS_SANITIZER_BUILD 1 +#if __has_include(<sanitizer/asan_interface.h>) +# include <sanitizer/asan_interface.h> +#else +// These declarations exist to support ASan with MSVC. If MSVC eventually ships +// asan_interface.h in their headers, then we can remove this. +#ifdef __cplusplus +extern "C" { +#endif +void __asan_poison_memory_region(void const volatile *addr, size_t size); +void __asan_unpoison_memory_region(void const volatile *addr, size_t size); +#ifdef __cplusplus +} // extern "C" +#endif +#endif +#else +# define LIBBASE_ADDRESS_SANITIZER_BUILD 0 +# define __asan_poison_memory_region(p, size) +# define __asan_unpoison_memory_region(p, size) +#endif + +/// \macro LIBBASE_HWADDRESS_SANITIZER_BUILD +/// Whether LLVM itself is built with HWAddressSanitizer instrumentation. +#if __has_feature(hwaddress_sanitizer) +#define LIBBASE_HWADDRESS_SANITIZER_BUILD 1 +#else +#define LIBBASE_HWADDRESS_SANITIZER_BUILD 0 +#endif + +/// \macro LIBBASE_THREAD_SANITIZER_BUILD +/// Whether LLVM itself is built with ThreadSanitizer instrumentation. +#if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__) +# define LIBBASE_THREAD_SANITIZER_BUILD 1 +#else +# define LIBBASE_THREAD_SANITIZER_BUILD 0 +#endif + +#if LIBBASE_THREAD_SANITIZER_BUILD +// Thread Sanitizer is a tool that finds races in code. +// See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations . +// tsan detects these exact functions by name. +#ifdef __cplusplus +extern "C" { +#endif +void AnnotateHappensAfter(const char *file, int line, const volatile void *cv); +void AnnotateHappensBefore(const char *file, int line, const volatile void *cv); +void AnnotateIgnoreWritesBegin(const char *file, int line); +void AnnotateIgnoreWritesEnd(const char *file, int line); +#ifdef __cplusplus +} +#endif + +// This marker is used to define a happens-before arc. The race detector will +// infer an arc from the begin to the end when they share the same pointer +// argument. +# define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv) + +// This marker defines the destination of a happens-before arc. +# define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv) + +// Ignore any races on writes between here and the next TsanIgnoreWritesEnd. +# define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__) + +// Resume checking for racy writes. +# define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__) +#else +# define TsanHappensBefore(cv) +# define TsanHappensAfter(cv) +# define TsanIgnoreWritesBegin() +# define TsanIgnoreWritesEnd() +#endif + +/// \macro LIBBASE_NO_SANITIZE +/// Disable a particular sanitizer for a function. +#if __has_attribute(no_sanitize) +#define LIBBASE_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND))) +#else +#define LIBBASE_NO_SANITIZE(KIND) +#endif + +/// Mark debug helper function definitions like dump() that should not be +/// stripped from debug builds. +/// Note that you should also surround dump() functions with +/// `#if !defined(NDEBUG) || defined(LIBBASE_ENABLE_DUMP)` so they do always +/// get stripped in release builds. +// FIXME: Move this to a private config.h as it's not usable in public headers. +#if !defined(NDEBUG) || defined(LIBBASE_ENABLE_DUMP) +#define LIBBASE_DUMP_METHOD \ + LIBBASE_ATTRIBUTE_NOINLINE LIBBASE_ATTRIBUTE_USED LIBBASE_ATTRIBUTE_RETAIN +#else +#define LIBBASE_DUMP_METHOD LIBBASE_ATTRIBUTE_NOINLINE +#endif + +/// \macro LIBBASE_PRETTY_FUNCTION +/// Gets a user-friendly looking function signature for the current scope +/// using the best available method on each platform. The exact format of the +/// resulting string is implementation specific and non-portable, so this should +/// only be used, for example, for logging or diagnostics. +#if defined(_MSC_VER) +#define LIBBASE_PRETTY_FUNCTION __FUNCSIG__ +#elif defined(__GNUC__) || defined(__clang__) +#define LIBBASE_PRETTY_FUNCTION __PRETTY_FUNCTION__ +#else +#define LIBBASE_PRETTY_FUNCTION __func__ +#endif + +/// \macro LIBBASE_THREAD_LOCAL +/// A thread-local storage specifier which can be used with globals, +/// extern globals, and static globals. +/// +/// This is essentially an extremely restricted analog to C++11's thread_local +/// support. It uses thread_local if available, falling back on gcc __thread +/// if not. __thread doesn't support many of the C++11 thread_local's +/// features. You should only use this for PODs that you can statically +/// initialize to some constant value. In almost all circumstances this is most +/// appropriate for use with a pointer, integer, or small aggregation of +/// pointers and integers. +#if LIBBASE_ENABLE_THREADS +#if __has_feature(cxx_thread_local) || defined(_MSC_VER) +#define LIBBASE_THREAD_LOCAL thread_local +#else +// Clang, GCC, and other compatible compilers used __thread prior to C++11 and +// we only need the restricted functionality that provides. +#define LIBBASE_THREAD_LOCAL __thread +#endif +#else // !LIBBASE_ENABLE_THREADS +// If threading is disabled entirely, this compiles to nothing and you get +// a normal global variable. +#define LIBBASE_THREAD_LOCAL +#endif + +/// \macro LIBBASE_ENABLE_EXCEPTIONS +/// Whether LLVM is built with exception support. +#if __has_feature(cxx_exceptions) +#define LIBBASE_ENABLE_EXCEPTIONS 1 +#elif defined(__GNUC__) && defined(__EXCEPTIONS) +#define LIBBASE_ENABLE_EXCEPTIONS 1 +#elif defined(_MSC_VER) && defined(_CPPUNWIND) +#define LIBBASE_ENABLE_EXCEPTIONS 1 +#endif + +/// \macro LIBBASE_NO_PROFILE_INSTRUMENT_FUNCTION +/// Disable the profile instrument for a function. +#if __has_attribute(no_profile_instrument_function) +#define LIBBASE_NO_PROFILE_INSTRUMENT_FUNCTION \ + __attribute__((no_profile_instrument_function)) +#else +#define LIBBASE_NO_PROFILE_INSTRUMENT_FUNCTION +#endif + +/// \macro LIBBASE_PREFERRED_TYPE +/// Adjust type of bit-field in debug info. +#if __has_attribute(preferred_type) +#define LIBBASE_PREFERRED_TYPE(T) __attribute__((preferred_type(T))) +#else +#define LIBBASE_PREFERRED_TYPE(T) +#endif + +#if LIBBASE_HAS_CPP_ATTRIBUTE(clang::ptrauth_vtable_pointer) && \ + (defined(__PTRAUTH__) || __has_feature(ptrauth_calls)) +#define LIBBASE_MOVABLE_POLYMORPHIC_TYPE \ + [[clang::ptrauth_vtable_pointer(default_key, no_address_discrimination, \ + default_extra_discrimination)]] +#else +#define LIBBASE_MOVABLE_POLYMORPHIC_TYPE +#endif + +/// \macro LIBBASE_VIRTUAL_ANCHOR_FUNCTION +/// This macro is used to adhere to LLVM's policy that each class with a vtable +/// must have at least one out-of-line virtual function. This macro allows us +/// to declare such a function in `final` classes without triggering a warning. +// clang-format off +// Autoformatting makes this look awful. +#if defined(__clang__) + // Make sure this is only parsed if __clang__ is defined + #if __has_warning("-Wunnecessary-virtual-specifier") + #define LIBBASE_DECLARE_VIRTUAL_ANCHOR_FUNCTION() \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wunnecessary-virtual-specifier\"") \ + virtual void anchor() \ + _Pragma("clang diagnostic pop") + #else // __has_warning + #define LIBBASE_DECLARE_VIRTUAL_ANCHOR_FUNCTION() \ + virtual void anchor() + #endif +#else // defined(__clang__) + #define LIBBASE_DECLARE_VIRTUAL_ANCHOR_FUNCTION() \ + virtual void anchor() +#endif +// clang-format on + +/// \macro LIBBASE_IS_X86 +/// Whether the target architecture is x86 / x86-64. +#if defined(__x86_64__) || defined(__i386__) +#define LIBBASE_IS_X86 1 +#else +#define LIBBASE_IS_X86 0 +#endif + +/// \macro LIBBASE_TARGET_SSE42 +/// Function attribute to compile a function with SSE4.2 enabled. +#if defined(__has_attribute) && __has_attribute(target) +#define LIBBASE_TARGET_SSE42 __attribute__((target("sse4.2"))) +#else +#define LIBBASE_TARGET_SSE42 +#endif + +#if __has_builtin(__builtin_cpu_supports) && \ + (defined(__linux__) || defined(__APPLE__)) +#define LIBBASE_CPU_SUPPORTS(feature) __builtin_cpu_supports(feature) +#else +#define LIBBASE_CPU_SUPPORTS(feature) 0 +#endif + +/// \macro LIBBASE_CPU_SUPPORTS_SSE42 +/// Expands to true if the runtime cpu supports SSE4.2, or if compiled with +/// SSE4.2 enabled. +#if defined(__SSE4_2__) +#define LIBBASE_CPU_SUPPORTS_SSE42 1 +#else +#define LIBBASE_CPU_SUPPORTS_SSE42 LIBBASE_CPU_SUPPORTS("sse4.2") +#endif + +#endif diff --git a/rcc/include/rcc/DataTypes.h b/libbase/include/core/compiler/DataTypes.h index 59e9b75..bfcf577 100644 --- a/rcc/include/rcc/DataTypes.h +++ b/libbase/include/core/compiler/DataTypes.h @@ -46,8 +46,8 @@ along with RCC-Project; see the file COPYING. If not see |*===----------------------------------------------------------------------===*/ /* Please leave this file C-compatible. */ -#ifndef RCC_DATATYPES_H -#define RCC_DATATYPES_H +#ifndef LIBBASE_DATATYPES_H +#define LIBBASE_DATATYPES_H #include <inttypes.h> #include <stdint.h> diff --git a/libbase/include/core/config/config.h.cmake b/libbase/include/core/config/config.h.cmake new file mode 100644 index 0000000..cf9b602 --- /dev/null +++ b/libbase/include/core/config/config.h.cmake @@ -0,0 +1,219 @@ +#ifndef LIBBASE_PRIVATE_CONFIG_H +#define LIBBASE_PRIVATE_CONFIG_H + +// Include this header only under the libbase source tree. +// This is a private header. + +/* Exported configuration */ +#include "core/config/libbase-config.h" + +/* Define to 1 to enable backtraces, and to 0 otherwise. */ +#cmakedefine01 ENABLE_BACKTRACES + +/* Define to 1 to enable crash overrides, and to 0 otherwise. */ +#cmakedefine01 ENABLE_CRASH_OVERRIDES + +/* Define to 1 to enable crash memory dumps, and to 0 otherwise. */ +#cmakedefine01 RCC_ENABLE_CRASH_DUMPS + +/* Define to 1 to prefer forward slashes on Windows, and to 0 otherwise. */ +#cmakedefine01 RCC_WINDOWS_PREFER_FORWARD_SLASH + +/* Define to 1 if you have the `backtrace' function. */ +#cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE} + +#define BACKTRACE_HEADER <${BACKTRACE_HEADER}> + +/* can use __crashreporter_info__ */ +#cmakedefine01 HAVE_CRASHREPORTER_INFO + +/* Define to 1 if you have the declaration of `arc4random', and to 0 if you + don't. */ +#cmakedefine01 HAVE_DECL_ARC4RANDOM + +/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you + don't. */ +#cmakedefine01 HAVE_DECL_STRERROR_S + +/* Define if dlopen() is available on this platform. */ +#cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN} + +/* Define to 1 if you have the `futimens' function. */ +#cmakedefine HAVE_FUTIMENS ${HAVE_FUTIMENS} + +/* Define to 1 if you have the `futimes' function. */ +#cmakedefine HAVE_FUTIMES ${HAVE_FUTIMES} + +/* Define to 1 if you have the `getpagesize' function. */ +#cmakedefine HAVE_GETPAGESIZE ${HAVE_GETPAGESIZE} + +/* Define to 1 if you have the `getrusage' function. */ +#cmakedefine HAVE_GETRUSAGE ${HAVE_GETRUSAGE} + +/* Define to 1 if you have the `isatty' function. */ +#cmakedefine HAVE_ISATTY 1 + +/* Define to 1 if you have the `edit' library (-ledit). */ +#cmakedefine HAVE_LIBEDIT ${HAVE_LIBEDIT} + +/* Define to 1 if you have the `psapi' library (-lpsapi). */ +#cmakedefine HAVE_LIBPSAPI ${HAVE_LIBPSAPI} + +/* Define to 1 if you have the `pthread' library (-lpthread). */ +#cmakedefine HAVE_LIBPTHREAD ${HAVE_LIBPTHREAD} + +/* Define to 1 if you have the `pthread_getname_np' function. */ +#cmakedefine HAVE_PTHREAD_GETNAME_NP ${HAVE_PTHREAD_GETNAME_NP} + +/* Define to 1 if you have the `pthread_setname_np' function. */ +#cmakedefine HAVE_PTHREAD_SETNAME_NP ${HAVE_PTHREAD_SETNAME_NP} + +/* Define to 1 if you have the `pthread_get_name_np' function. */ +#cmakedefine HAVE_PTHREAD_GET_NAME_NP ${HAVE_PTHREAD_GET_NAME_NP} + +/* Define to 1 if you have the `pthread_set_name_np' function. */ +#cmakedefine HAVE_PTHREAD_SET_NAME_NP ${HAVE_PTHREAD_SET_NAME_NP} + +/* Define to 1 if you have the <mach/mach.h> header file. */ +#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H} + +/* Define to 1 if you have the `mallctl' function. */ +#cmakedefine HAVE_MALLCTL ${HAVE_MALLCTL} + +/* Define to 1 if you have the `mallinfo' function. */ +#cmakedefine HAVE_MALLINFO ${HAVE_MALLINFO} + +/* Define to 1 if you have the `mallinfo2' function. */ +#cmakedefine HAVE_MALLINFO2 ${HAVE_MALLINFO2} + +/* Define to 1 if you have the <malloc/malloc.h> header file. */ +#cmakedefine HAVE_MALLOC_MALLOC_H ${HAVE_MALLOC_MALLOC_H} + +/* Define to 1 if you have the `malloc_zone_statistics' function. */ +#cmakedefine HAVE_MALLOC_ZONE_STATISTICS ${HAVE_MALLOC_ZONE_STATISTICS} + +/* Define to 1 if you have the `posix_spawn' function. */ +#cmakedefine HAVE_POSIX_SPAWN ${HAVE_POSIX_SPAWN} + +/* Define to 1 if you have the `pread' function. */ +#cmakedefine HAVE_PREAD ${HAVE_PREAD} + +/* Define to 1 if you have the <pthread.h> header file. */ +#cmakedefine HAVE_PTHREAD_H ${HAVE_PTHREAD_H} + +/* Have pthread_rwlock_init */ +#cmakedefine HAVE_PTHREAD_RWLOCK_INIT ${HAVE_PTHREAD_RWLOCK_INIT} + +/* Define to 1 if you have the `sbrk' function. */ +#cmakedefine HAVE_SBRK ${HAVE_SBRK} + +/* Define to 1 if you have the `setenv' function. */ +#cmakedefine HAVE_SETENV ${HAVE_SETENV} + +/* Define to 1 if you have the `sigaltstack' function. */ +#cmakedefine HAVE_SIGALTSTACK ${HAVE_SIGALTSTACK} + +/* Define to 1 if you have the `strerror_r' function. */ +#cmakedefine HAVE_STRERROR_R ${HAVE_STRERROR_R} + +/* Define to 1 if you have the `sysconf' function. */ +#cmakedefine HAVE_SYSCONF ${HAVE_SYSCONF} + +/* Define to 1 if you have the <sys/mman.h> header file. */ +#cmakedefine HAVE_SYS_MMAN_H ${HAVE_SYS_MMAN_H} + +/* Define to 1 if you have the <sys/ioctl.h> header file. */ +#cmakedefine HAVE_SYS_IOCTL_H ${HAVE_SYS_IOCTL_H} + +/* Define to 1 if stat struct has st_mtimespec member .*/ +#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC} + +/* Define to 1 if stat struct has st_mtim member. */ +#cmakedefine HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC} + +/* Define to 1 if you have the <unistd.h> header file. */ +#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H} + +/* Have host's _alloca */ +#cmakedefine HAVE__ALLOCA ${HAVE__ALLOCA} + +/* Define to 1 if you have the `_chsize_s' function. */ +#cmakedefine HAVE__CHSIZE_S ${HAVE__CHSIZE_S} + +/* Define to 1 if you have the `_Unwind_Backtrace' function. */ +#cmakedefine HAVE__UNWIND_BACKTRACE ${HAVE__UNWIND_BACKTRACE} + +/* Have host's __alloca */ +#cmakedefine HAVE___ALLOCA ${HAVE___ALLOCA} + +/* Have host's __ashldi3 */ +#cmakedefine HAVE___ASHLDI3 ${HAVE___ASHLDI3} + +/* Have host's __ashrdi3 */ +#cmakedefine HAVE___ASHRDI3 ${HAVE___ASHRDI3} + +/* Have host's __chkstk */ +#cmakedefine HAVE___CHKSTK ${HAVE___CHKSTK} + +/* Have host's __chkstk_ms */ +#cmakedefine HAVE___CHKSTK_MS ${HAVE___CHKSTK_MS} + +/* Have host's __cmpdi2 */ +#cmakedefine HAVE___CMPDI2 ${HAVE___CMPDI2} + +/* Have host's __divdi3 */ +#cmakedefine HAVE___DIVDI3 ${HAVE___DIVDI3} + +/* Have host's __fixdfdi */ +#cmakedefine HAVE___FIXDFDI ${HAVE___FIXDFDI} + +/* Have host's __fixsfdi */ +#cmakedefine HAVE___FIXSFDI ${HAVE___FIXSFDI} + +/* Have host's __floatdidf */ +#cmakedefine HAVE___FLOATDIDF ${HAVE___FLOATDIDF} + +/* Have host's __lshrdi3 */ +#cmakedefine HAVE___LSHRDI3 ${HAVE___LSHRDI3} + +/* Have host's __main */ +#cmakedefine HAVE___MAIN ${HAVE___MAIN} + +/* Have host's __moddi3 */ +#cmakedefine HAVE___MODDI3 ${HAVE___MODDI3} + +/* Have host's __udivdi3 */ +#cmakedefine HAVE___UDIVDI3 ${HAVE___UDIVDI3} + +/* Have host's __umoddi3 */ +#cmakedefine HAVE___UMODDI3 ${HAVE___UMODDI3} + +/* Have host's ___chkstk */ +#cmakedefine HAVE____CHKSTK ${HAVE____CHKSTK} + +/* Have host's ___chkstk_ms */ +#cmakedefine HAVE____CHKSTK_MS ${HAVE____CHKSTK_MS} + +/* Define if ICU library is available */ +#cmakedefine01 HAVE_ICU + +/* Define if Windows vendored ICU is available */ +#cmakedefine01 HAVE_WINDOWS_ICU + +/* Define if iconv library is available */ +#cmakedefine01 HAVE_ICONV + +/* Define to a function implementing stricmp */ +#cmakedefine stricmp ${stricmp} + +/* Define to a function implementing strdup */ +#cmakedefine strdup ${strdup} + +/* Whether Timers signpost passes in Xcode Instruments */ +#cmakedefine01 RCC_SUPPORT_XCODE_SIGNPOSTS + +#cmakedefine HAVE_PROC_PID_RUSAGE 1 + +#cmakedefine HAVE_GETAUXVAL ${HAVE_GETAUXVAL} + +#endif diff --git a/libbase/include/core/config/libbase-config.h.cmake b/libbase/include/core/config/libbase-config.h.cmake new file mode 100644 index 0000000..2ea111b --- /dev/null +++ b/libbase/include/core/config/libbase-config.h.cmake @@ -0,0 +1,89 @@ +/* + RCC-Project + + Copyright (C) 2026 Richard Qin + + This file is part of RCC-Project. + + RCC-Project is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your option) any + later version. + + RCC-Project is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + RCC-Project; see the file COPYING. If not see + <http://www.gnu.org/licenses/>. +*/ + +/* This file enumerates variables from the libbase configuration so that they + can be used by exported headers without depending on RCC configuration. */ + +#ifndef LIBBASE_CONFIG_H +#define LIBBASE_CONFIG_H + +/* Define if libbase dump support is enabled. */ +#cmakedefine LIBBASE_ENABLE_DUMP + +/* Define if threads are enabled in libbase. */ +#cmakedefine01 LIBBASE_ENABLE_THREADS + +/* Has gcc/MSVC atomic intrinsics. */ +#cmakedefine01 LIBBASE_HAS_ATOMICS + +/* Define if this is a Unixish platform. */ +#cmakedefine LIBBASE_ON_UNIX ${LIBBASE_ON_UNIX} + +/* Whether libbase records statistics. */ +#cmakedefine01 LIBBASE_FORCE_ENABLE_STATS + +/* Define if libbase has z3 support. */ +#cmakedefine LIBBASE_WITH_Z3 ${LIBBASE_WITH_Z3} + +/* Define if libbase has curl support. */ +#cmakedefine LIBBASE_ENABLE_CURL ${LIBBASE_ENABLE_CURL} + +/* Define if libbase has cpp-httplib support. */ +#cmakedefine LIBBASE_ENABLE_HTTPLIB ${LIBBASE_ENABLE_HTTPLIB} + +/* Define if zlib compression is available to libbase. */ +#cmakedefine01 LIBBASE_ENABLE_ZLIB + +/* Define if zstd compression is available to libbase. */ +#cmakedefine01 LIBBASE_ENABLE_ZSTD + +/* Define if xz (lzma) decompression is available to libbase. */ +#cmakedefine01 LIBBASE_ENABLE_LZMA + +/* Define to 1 if libbase has the <sysexits.h> header file. */ +#cmakedefine LIBBASE_HAVE_SYSEXITS_H ${LIBBASE_HAVE_SYSEXITS_H} + +/* Define if libbase is built with BUILD_SHARED_LIBS. */ +#cmakedefine LIBBASE_BUILD_SHARED_LIBS + +/* Define if libbase is built as a static library. */ +#cmakedefine LIBBASE_BUILD_STATIC + +/* Define if exporting the libbase public interface for a shared library. */ +#cmakedefine LIBBASE_ENABLE_EXPORT_ANNOTATIONS + +/* Define if libbase uses the old toolchain behavior. */ +#cmakedefine LIBBASE_FORCE_USE_OLD_TOOLCHAIN ${LIBBASE_FORCE_USE_OLD_TOOLCHAIN} + +/* Define if libbase_unreachable should be optimized with undefined behavior + * in non-assert builds. */ +#cmakedefine01 LIBBASE_UNREACHABLE_OPTIMIZE + +/* Define if libbase provides I/O sandbox support. */ +#cmakedefine01 LIBBASE_ENABLE_IO_SANDBOX + +/* Define if logf128 is available to libbase. */ +#cmakedefine LIBBASE_HAS_LOGF128 + +/* Define if libbase provides on-disk content-addressable storage. */ +#cmakedefine01 LIBBASE_ENABLE_ONDISK_CAS + +#endif diff --git a/libsupport/include/CoreLib/System/Errno.h b/libbase/include/core/error/Errno.h index 2626ad9..01d4ff8 100644 --- a/libsupport/include/CoreLib/System/Errno.h +++ b/libbase/include/core/error/Errno.h @@ -21,10 +21,10 @@ // This implementation is based on llvm/include/llvm/Support/Errno.h. -#ifndef RCC_SUPPORT_ERRNO_H -#define RCC_SUPPORT_ERRNO_H +#ifndef LIBBASE_SUPPORT_ERRNO_H +#define LIBBASE_SUPPORT_ERRNO_H -#include "CoreLib/Compiler/Compiler.h" +#include "core/compiler/Compiler.h" #include <cerrno> #include <string> @@ -38,11 +38,11 @@ namespace sys /// thread-safe variant of strerror() is available. Be sure to call this /// immediately after the function that set errno, or errno may have been /// overwritten by an intervening call. -RCC_ABI std::string +LIBBASE_ABI std::string StrError (); /// Like the no-argument version above, but uses \p errnum instead of errno. -RCC_ABI std::string +LIBBASE_ABI std::string StrError (int errnum); template <typename FailT, typename Fun, typename... Args> @@ -61,4 +61,4 @@ RetryAfterSignal (const FailT &Fail, const Fun &F, const Args &...As) } // namespace sys } // namespace rcc -#endif // RCC_SUPPORT_ERRNO_H +#endif // LIBBASE_SUPPORT_ERRNO_H diff --git a/libsupport/include/CoreLib/Error/ErrorHandling.h b/libbase/include/core/error/ErrorHandling.h index 5ab5a9e..b27104c 100644 --- a/libsupport/include/CoreLib/Error/ErrorHandling.h +++ b/libbase/include/core/error/ErrorHandling.h @@ -32,10 +32,10 @@ // //===----------------------------------------------------------------------===// -#ifndef RCC_SUPPORT_ERRORHANDLING_H -#define RCC_SUPPORT_ERRORHANDLING_H +#ifndef LIBBASE_SUPPORT_ERRORHANDLING_H +#define LIBBASE_SUPPORT_ERRORHANDLING_H -#include "CoreLib/Compiler/Compiler.h" +#include "core/compiler/Compiler.h" namespace rcc { @@ -62,12 +62,12 @@ using fatal_error_handler_t = void (*) (void *user_data, const char *reason, /// /// \param user_data - An argument which will be passed to the install error /// handler. -RCC_ABI void +LIBBASE_ABI void install_fatal_error_handler (fatal_error_handler_t handler, void *user_data = nullptr); /// Restores default error handling behaviour. -RCC_ABI void +LIBBASE_ABI void remove_fatal_error_handler (); /// ScopedFatalErrorHandler - This is a simple helper class which just @@ -89,11 +89,11 @@ struct ScopedFatalErrorHandler /// @deprecated Use reportFatalInternalError() or reportFatalUsageError() /// instead. -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void report_fatal_error (const char *reason, bool gen_crash_diag = true); -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void report_fatal_error (StringRef reason, bool gen_crash_diag = true); -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void report_fatal_error (const Twine &reason, bool gen_crash_diag = true); /// Report a fatal error that likely indicates a bug in LLVM. It serves a @@ -103,11 +103,11 @@ report_fatal_error (const Twine &reason, bool gen_crash_diag = true); /// This will call installed error handlers (or print the message by default) /// and then abort. This will produce a crash trace and *will* ask users to /// report an LLVM bug. -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void reportFatalInternalError (const char *reason); -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void reportFatalInternalError (StringRef reason); -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void reportFatalInternalError (const Twine &reason); /// Report a fatal error that does not indicate a bug in LLVM. @@ -124,11 +124,11 @@ reportFatalInternalError (const Twine &reason); /// This will call installed error handlers (or print the message by default) /// and then exit with code 1. It will not produce a crash trace and will /// *not* ask users to report an LLVM bug. -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void reportFatalUsageError (const char *reason); -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void reportFatalUsageError (StringRef reason); -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void reportFatalUsageError (const Twine &reason); /// Installs a new bad alloc error handler that should be used whenever a @@ -147,15 +147,15 @@ reportFatalUsageError (const Twine &reason); /// /// \param user_data - An argument which will be passed to the installed error /// handler. -RCC_ABI void +LIBBASE_ABI void install_bad_alloc_error_handler (fatal_error_handler_t handler, void *user_data = nullptr); /// Restores default bad alloc error handling behavior. -RCC_ABI void +LIBBASE_ABI void remove_bad_alloc_error_handler (); -RCC_ABI void +LIBBASE_ABI void install_out_of_memory_new_handler (); /// Reports a bad alloc error, calling any user defined bad alloc @@ -170,13 +170,13 @@ install_out_of_memory_new_handler (); /// If no error handler is installed (default), throws a bad_alloc exception /// if LLVM is compiled with exception support. Otherwise prints the error /// to standard error and calls abort(). -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void report_bad_alloc_error (const char *Reason, bool GenCrashDiag = true); /// This function calls abort(), and prints the optional message to stderr. /// Use the llvm_unreachable macro (that adds location info), instead of /// calling this function directly. -[[noreturn]] RCC_ABI void +[[noreturn]] LIBBASE_ABI void rcc_unreachable_internal (const char *msg = nullptr, const char *file = nullptr, unsigned line = 0); } // namespace rcc @@ -201,16 +201,16 @@ rcc_unreachable_internal (const char *msg = nullptr, const char *file = nullptr, #ifndef NDEBUG #define rcc_unreachable(msg) \ ::rcc::rcc_unreachable_internal (msg, __FILE__, __LINE__) -#elif !defined(RCC_BUILTIN_UNREACHABLE) +#elif !defined(LIBBASE_BUILTIN_UNREACHABLE) #define rcc_unreachable(msg) ::rcc::rcc_unreachable_internal () -#elif RCC_UNREACHABLE_OPTIMIZE -#define rcc_unreachable(msg) RCC_BUILTIN_UNREACHABLE +#elif LIBBASE_UNREACHABLE_OPTIMIZE +#define rcc_unreachable(msg) LIBBASE_BUILTIN_UNREACHABLE #else #define rcc_unreachable(msg) \ do \ { \ - RCC_BUILTIN_TRAP; \ - RCC_BUILTIN_UNREACHABLE; \ + LIBBASE_BUILTIN_TRAP; \ + LIBBASE_BUILTIN_UNREACHABLE; \ } while (false) #endif diff --git a/libsupport/include/CoreLib/Math/MathExtras.h b/libbase/include/core/math/MathExtras.h index a9c954d..880ba74 100644 --- a/libsupport/include/CoreLib/Math/MathExtras.h +++ b/libbase/include/core/math/MathExtras.h @@ -31,10 +31,10 @@ // //===----------------------------------------------------------------------===// -#ifndef RCC_SUPPORT_MATHEXTRAS_H -#define RCC_SUPPORT_MATHEXTRAS_H +#ifndef LIBBASE_SUPPORT_MATHEXTRAS_H +#define LIBBASE_SUPPORT_MATHEXTRAS_H -#include "CoreLib/Compiler/Compiler.h" +#include "core/compiler/Compiler.h" #include <bit> #include <cassert> #include <climits> @@ -894,7 +894,7 @@ SaturatingMultiplyAdd (T X, T Y, T A, bool *ResultOverflowed = nullptr) } /// Use this rather than HUGE_VALF; the latter causes warnings on MSVC. -RCC_ABI extern const float huge_valf; +LIBBASE_ABI extern const float huge_valf; /// Add two signed integers, computing the two's complement truncated result, /// returning a pair {result, overflow}, where "overflow" is a boolean value @@ -1042,7 +1042,7 @@ using stack_float_t = float; #endif /// Returns the number of digits in the given integer. -RCC_ABI int +LIBBASE_ABI int NumDigitsBase10 (uint64_t X); } // namespace rcc diff --git a/libbase/include/core/memory/Alignment.h b/libbase/include/core/memory/Alignment.h new file mode 100644 index 0000000..a3b5d38 --- /dev/null +++ b/libbase/include/core/memory/Alignment.h @@ -0,0 +1,342 @@ +/* + R *CC-Project + + Copyright (C) 2026 Richard Qin + + This file is part of RCC-Project. + + RCC-Project is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your option) any + later version. + + RCC-Project is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + RCC-Project; see the file COPYING. If not see + <http://www.gnu.org/licenses/>. + */ + +//===-- rcc/Memory/Alignment.h - Useful alignment functions ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file contains types to represent alignments. +// They are instrumented to guarantee some invariants are preserved and prevent +// invalid manipulations. +// +// - Align represents an alignment in bytes, it is always set and always a valid +// power of two, its minimum value is 1 which means no alignment requirements. +// +// - MaybeAlign is an optional type, it may be undefined or set. When it's set +// you can get the underlying Align type by using the value() method. +// +//===----------------------------------------------------------------------===// + +#ifndef LIBBASE_SUPPORT_ALIGNMENT_H_ +#define LIBBASE_SUPPORT_ALIGNMENT_H_ + +#include "core/math/MathExtras.h" +#include <cassert> +#include <optional> +#ifndef NDEBUG +#include <string> +#endif // NDEBUG + +namespace rcc { + +#define ALIGN_CHECK_ISPOSITIVE(decl) \ + assert(decl > 0 && (#decl " should be defined")) + +/// This struct is a compact representation of a valid (non-zero power of two) +/// alignment. +/// It is suitable for use as static global constants. +struct Align { +private: + uint8_t ShiftValue = 0; /// The log2 of the required alignment. + /// ShiftValue is less than 64 by construction. + + friend struct MaybeAlign; + friend unsigned Log2(Align); + friend bool operator==(Align Lhs, Align Rhs); + friend bool operator!=(Align Lhs, Align Rhs); + friend bool operator<=(Align Lhs, Align Rhs); + friend bool operator>=(Align Lhs, Align Rhs); + friend bool operator<(Align Lhs, Align Rhs); + friend bool operator>(Align Lhs, Align Rhs); + friend unsigned encode(struct MaybeAlign A); + friend struct MaybeAlign decodeMaybeAlign(unsigned Value); + +public: + /// Default is byte-aligned. + constexpr Align() = default; + /// Do not perform checks in case of copy/move construct/assign, because the + /// checks have been performed when building `Other`. + constexpr Align(const Align &Other) = default; + constexpr Align(Align &&Other) = default; + constexpr Align &operator=(const Align &Other) = default; + constexpr Align &operator=(Align &&Other) = default; + + explicit Align(uint64_t Value) { + assert(Value > 0 && "Value must not be 0"); + assert(rcc::isPowerOf2_64(Value) && "Alignment is not a power of 2"); + ShiftValue = Log2_64(Value); + assert(ShiftValue < 64 && "Broken invariant"); + } + + /// Returns an alignment of `1 << Log2Value` bytes. + constexpr static Align fromLog2(unsigned Log2Value) { + assert(Log2Value < 64 && "Alignment exponent is too large"); + Align Out; + Out.ShiftValue = Log2Value; + return Out; + } + + /// This is a hole in the type system and should not be abused. + /// Needed to interact with C for instance. + constexpr uint64_t value() const { return uint64_t(1) << ShiftValue; } + + // Returns the previous alignment. + Align previous() const { + assert(ShiftValue != 0 && "Undefined operation"); + Align Out; + Out.ShiftValue = ShiftValue - 1; + return Out; + } + + /// Allow constructions of constexpr Align. + template <size_t kValue> constexpr static Align Constant() { + return fromLog2(ConstantLog2<kValue>()); + } + + /// Allow constructions of constexpr Align from types. + /// Compile time equivalent to Align(alignof(T)). + template <typename T> constexpr static Align Of() { + return Constant<std::alignment_of_v<T>>(); + } +}; + +/// Treats the value 0 as a 1, so Align is always at least 1. +inline Align assumeAligned(uint64_t Value) { + return Value ? Align(Value) : Align(); +} + +/// This struct is a compact representation of a valid (power of two) or +/// undefined (0) alignment. +struct MaybeAlign : std::optional<Align> { +private: + using UP = std::optional<Align>; + +public: + /// Default is undefined. + MaybeAlign() = default; + /// Do not perform checks in case of copy/move construct/assign, because the + /// checks have been performed when building `Other`. + MaybeAlign(const MaybeAlign &Other) = default; + MaybeAlign &operator=(const MaybeAlign &Other) = default; + MaybeAlign(MaybeAlign &&Other) = default; + MaybeAlign &operator=(MaybeAlign &&Other) = default; + + constexpr MaybeAlign(std::nullopt_t None) : UP(None) {} + constexpr MaybeAlign(Align Value) : UP(Value) {} + explicit MaybeAlign(uint64_t Value) { + assert((Value == 0 || rcc::isPowerOf2_64(Value)) && + "Alignment is neither 0 nor a power of 2"); + if (Value) + emplace(Value); + } + + /// For convenience, returns a valid alignment or 1 if undefined. + Align valueOrOne() const { return value_or(Align()); } +}; + +/// Checks that SizeInBytes is a multiple of the alignment. +inline bool isAligned(Align Lhs, uint64_t SizeInBytes) { + return SizeInBytes % Lhs.value() == 0; +} + +/// Checks that Addr is a multiple of the alignment. +inline bool isAddrAligned(Align Lhs, const void *Addr) { + return isAligned(Lhs, reinterpret_cast<uintptr_t>(Addr)); +} + +/// Returns a multiple of A needed to store `Size` bytes. +constexpr inline uint64_t alignTo(uint64_t Size, Align A) { + const uint64_t Value = A.value(); + // The following line is equivalent to `(Size + Value - 1) / Value * Value`. + + // The division followed by a multiplication can be thought of as a right + // shift followed by a left shift which zeros out the extra bits produced in + // the bump; `~(Value - 1)` is a mask where all those bits being zeroed out + // are just zero. + + // Most compilers can generate this code but the pattern may be missed when + // multiple functions gets inlined. + return (Size + Value - 1) & ~(Value - 1U); +} + +/// If non-zero \p Skew is specified, the return value will be a minimal integer +/// that is greater than or equal to \p Size and equal to \p A * N + \p Skew for +/// some integer N. If \p Skew is larger than \p A, its value is adjusted to '\p +/// Skew mod \p A'. +/// +/// Examples: +/// \code +/// alignTo(5, Align(8), 7) = 7 +/// alignTo(17, Align(8), 1) = 17 +/// alignTo(~0LL, Align(8), 3) = 3 +/// \endcode +inline uint64_t alignTo(uint64_t Size, Align A, uint64_t Skew) { + const uint64_t Value = A.value(); + Skew %= Value; + return alignTo(Size - Skew, A) + Skew; +} + +/// Aligns `Addr` to `Alignment` bytes, rounding up. +inline uintptr_t alignAddr(const void *Addr, Align Alignment) { + uintptr_t ArithAddr = reinterpret_cast<uintptr_t>(Addr); + assert(static_cast<uintptr_t>(ArithAddr + Alignment.value() - 1) >= + ArithAddr && + "Overflow"); + return alignTo(ArithAddr, Alignment); +} + +/// Returns the offset to the next integer (mod 2**64) that is greater than +/// or equal to \p Value and is a multiple of \p Align. +inline uint64_t offsetToAlignment(uint64_t Value, Align Alignment) { + return alignTo(Value, Alignment) - Value; +} + +/// Returns the necessary adjustment for aligning `Addr` to `Alignment` +/// bytes, rounding up. +inline uint64_t offsetToAlignedAddr(const void *Addr, Align Alignment) { + return offsetToAlignment(reinterpret_cast<uintptr_t>(Addr), Alignment); +} + +/// Returns the log2 of the alignment. +inline unsigned Log2(Align A) { return A.ShiftValue; } + +/// Returns the alignment that satisfies both alignments. +/// Same semantic as MinAlign. +inline Align commonAlignment(Align A, uint64_t Offset) { + return Align(MinAlign(A.value(), Offset)); +} + +/// Returns a representation of the alignment that encodes undefined as 0. +inline unsigned encode(MaybeAlign A) { return A ? A->ShiftValue + 1 : 0; } + +/// Dual operation of the encode function above. +inline MaybeAlign decodeMaybeAlign(unsigned Value) { + if (Value == 0) + return MaybeAlign(); + Align Out; + Out.ShiftValue = Value - 1; + return Out; +} + +/// Returns a representation of the alignment, the encoded value is positive by +/// definition. +inline unsigned encode(Align A) { return encode(MaybeAlign(A)); } + +/// Comparisons between Align and scalars. Rhs must be positive. +inline bool operator==(Align Lhs, uint64_t Rhs) { + ALIGN_CHECK_ISPOSITIVE(Rhs); + return Lhs.value() == Rhs; +} +inline bool operator!=(Align Lhs, uint64_t Rhs) { + ALIGN_CHECK_ISPOSITIVE(Rhs); + return Lhs.value() != Rhs; +} +inline bool operator<=(Align Lhs, uint64_t Rhs) { + ALIGN_CHECK_ISPOSITIVE(Rhs); + return Lhs.value() <= Rhs; +} +inline bool operator>=(Align Lhs, uint64_t Rhs) { + ALIGN_CHECK_ISPOSITIVE(Rhs); + return Lhs.value() >= Rhs; +} +inline bool operator<(Align Lhs, uint64_t Rhs) { + ALIGN_CHECK_ISPOSITIVE(Rhs); + return Lhs.value() < Rhs; +} +inline bool operator>(Align Lhs, uint64_t Rhs) { + ALIGN_CHECK_ISPOSITIVE(Rhs); + return Lhs.value() > Rhs; +} + +/// Comparisons operators between Align. +inline bool operator==(Align Lhs, Align Rhs) { + return Lhs.ShiftValue == Rhs.ShiftValue; +} +inline bool operator!=(Align Lhs, Align Rhs) { + return Lhs.ShiftValue != Rhs.ShiftValue; +} +inline bool operator<=(Align Lhs, Align Rhs) { + return Lhs.ShiftValue <= Rhs.ShiftValue; +} +inline bool operator>=(Align Lhs, Align Rhs) { + return Lhs.ShiftValue >= Rhs.ShiftValue; +} +inline bool operator<(Align Lhs, Align Rhs) { + return Lhs.ShiftValue < Rhs.ShiftValue; +} +inline bool operator>(Align Lhs, Align Rhs) { + return Lhs.ShiftValue > Rhs.ShiftValue; +} + +// Don't allow relational comparisons with MaybeAlign. +bool operator<=(Align Lhs, MaybeAlign Rhs) = delete; +bool operator>=(Align Lhs, MaybeAlign Rhs) = delete; +bool operator<(Align Lhs, MaybeAlign Rhs) = delete; +bool operator>(Align Lhs, MaybeAlign Rhs) = delete; + +bool operator<=(MaybeAlign Lhs, Align Rhs) = delete; +bool operator>=(MaybeAlign Lhs, Align Rhs) = delete; +bool operator<(MaybeAlign Lhs, Align Rhs) = delete; +bool operator>(MaybeAlign Lhs, Align Rhs) = delete; + +bool operator<=(MaybeAlign Lhs, MaybeAlign Rhs) = delete; +bool operator>=(MaybeAlign Lhs, MaybeAlign Rhs) = delete; +bool operator<(MaybeAlign Lhs, MaybeAlign Rhs) = delete; +bool operator>(MaybeAlign Lhs, MaybeAlign Rhs) = delete; + +// Allow equality comparisons between Align and MaybeAlign. +inline bool operator==(MaybeAlign Lhs, Align Rhs) { return Lhs && *Lhs == Rhs; } +inline bool operator!=(MaybeAlign Lhs, Align Rhs) { return !(Lhs == Rhs); } +inline bool operator==(Align Lhs, MaybeAlign Rhs) { return Rhs == Lhs; } +inline bool operator!=(Align Lhs, MaybeAlign Rhs) { return !(Rhs == Lhs); } +// Allow equality comparisons with MaybeAlign. +inline bool operator==(MaybeAlign Lhs, MaybeAlign Rhs) { + return (Lhs && Rhs && (*Lhs == *Rhs)) || (!Lhs && !Rhs); +} +inline bool operator!=(MaybeAlign Lhs, MaybeAlign Rhs) { return !(Lhs == Rhs); } +// Allow equality comparisons with std::nullopt. +inline bool operator==(MaybeAlign Lhs, std::nullopt_t) { return !bool(Lhs); } +inline bool operator!=(MaybeAlign Lhs, std::nullopt_t) { return bool(Lhs); } +inline bool operator==(std::nullopt_t, MaybeAlign Rhs) { return !bool(Rhs); } +inline bool operator!=(std::nullopt_t, MaybeAlign Rhs) { return bool(Rhs); } + +#ifndef NDEBUG +// For usage in LLVM_DEBUG macros. +inline std::string DebugStr(const Align &A) { + return std::to_string(A.value()); +} +// For usage in LLVM_DEBUG macros. +inline std::string DebugStr(const MaybeAlign &MA) { + if (MA) + return std::to_string(MA->value()); + return "None"; +} +#endif // NDEBUG + +#undef ALIGN_CHECK_ISPOSITIVE + +} // namespace rcc + +#endif // LIBBASE_SUPPORT_ALIGNMENT_H_ diff --git a/libbase/include/core/memory/AllocatorBase.h b/libbase/include/core/memory/AllocatorBase.h new file mode 100644 index 0000000..248ea9b --- /dev/null +++ b/libbase/include/core/memory/AllocatorBase.h @@ -0,0 +1,154 @@ +/* + R *CC-Project + + Copyright (C) 2026 Richard Qin + + This file is part of RCC-Project. + + RCC-Project is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your option) any + later version. + + RCC-Project is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + RCC-Project; see the file COPYING. If not see + <http://www.gnu.org/licenses/>. + */ + +//===- AllocatorBase.h - Simple memory allocation abstraction ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// \file +/// +/// This file defines MallocAllocator. MallocAllocator conforms to the LLVM +/// "Allocator" concept which consists of an Allocate method accepting a size +/// and alignment, and a Deallocate accepting a pointer and size. Further, the +/// LLVM "Allocator" concept has overloads of Allocate and Deallocate for +/// setting size and alignment based on the final type. These overloads are +/// typically provided by a base class template \c AllocatorBase. +/// +//===----------------------------------------------------------------------===// + +#ifndef LIBBASE_SUPPORT_ALLOCATORBASE_H +#define LIBBASE_SUPPORT_ALLOCATORBASE_H + +#ifdef _MSC_VER +#define LIBBASE_ALLOCATORHOLDER_EMPTYBASE __declspec(empty_bases) +#else +#define LIBBASE_ALLOCATORHOLDER_EMPTYBASE +#endif // _MSC_VER + +#include "core/compiler/Compiler.h" +#include "core/memory/MemAlloc.h" +#include <type_traits> +#include <utility> + +namespace rcc { + +/// CRTP base class providing obvious overloads for the core \c +/// Allocate() methods of LLVM-style allocators. +/// +/// This base class both documents the full public interface exposed by all +/// LLVM-style allocators, and redirects all of the overloads to a single core +/// set of methods which the derived class must define. +template <typename DerivedT> class AllocatorBase { +public: + /// Allocate \a Size bytes of \a Alignment aligned memory. This method + /// must be implemented by \c DerivedT. + void *Allocate(size_t Size, size_t Alignment) { +#ifdef __clang__ + static_assert(static_cast<void *(AllocatorBase::*)(size_t, size_t)>( + &AllocatorBase::Allocate) != + static_cast<void *(DerivedT::*)(size_t, size_t)>( + &DerivedT::Allocate), + "Class derives from AllocatorBase without implementing the " + "core Allocate(size_t, size_t) overload!"); +#endif + return static_cast<DerivedT *>(this)->Allocate(Size, Alignment); + } + + /// Deallocate \a Ptr to \a Size bytes of memory allocated by this + /// allocator. + void Deallocate(const void *Ptr, size_t Size, size_t Alignment) { +#ifdef __clang__ + static_assert( + static_cast<void (AllocatorBase::*)(const void *, size_t, size_t)>( + &AllocatorBase::Deallocate) != + static_cast<void (DerivedT::*)(const void *, size_t, size_t)>( + &DerivedT::Deallocate), + "Class derives from AllocatorBase without implementing the " + "core Deallocate(void *) overload!"); +#endif + return static_cast<DerivedT *>(this)->Deallocate(Ptr, Size, Alignment); + } + + // The rest of these methods are helpers that redirect to one of the above + // core methods. + + /// Allocate space for a sequence of objects without constructing them. + template <typename T> T *Allocate(size_t Num = 1) { + return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T))); + } + + /// Deallocate space for a sequence of objects without constructing them. + template <typename T> + std::enable_if_t<!std::is_same_v<std::remove_cv_t<T>, void>, void> + Deallocate(T *Ptr, size_t Num = 1) { + Deallocate(static_cast<const void *>(Ptr), Num * sizeof(T), alignof(T)); + } +}; + +class MallocAllocator : public AllocatorBase<MallocAllocator> { +public: + void Reset() {} + + LIBBASE_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size, size_t Alignment) { + return allocate_buffer(Size, Alignment); + } + + // Pull in base class overloads. + using AllocatorBase<MallocAllocator>::Allocate; + + void Deallocate(const void *Ptr, size_t Size, size_t Alignment) { + deallocate_buffer(const_cast<void *>(Ptr), Size, Alignment); + } + + // Pull in base class overloads. + using AllocatorBase<MallocAllocator>::Deallocate; + + void PrintStats() const {} +}; + +namespace detail { + +template <typename Alloc> class AllocatorHolder : Alloc { +public: + AllocatorHolder() = default; + AllocatorHolder(const Alloc &A) : Alloc(A) {} + AllocatorHolder(Alloc &&A) : Alloc(std::move(A)) {} + Alloc &getAllocator() { return *this; } + const Alloc &getAllocator() const { return *this; } +}; + +template <typename Alloc> class AllocatorHolder<Alloc &> { + Alloc &A; + +public: + AllocatorHolder(Alloc &A) : A(A) {} + Alloc &getAllocator() { return A; } + const Alloc &getAllocator() const { return A; } +}; + +} // namespace detail + +} // namespace rcc + +#endif // LIBBASE_SUPPORT_ALLOCATORBASE_H diff --git a/libsupport/include/CoreLib/Memory/MemAlloc.h b/libbase/include/core/memory/MemAlloc.h index b7183c0..bd98864 100644 --- a/libsupport/include/CoreLib/Memory/MemAlloc.h +++ b/libbase/include/core/memory/MemAlloc.h @@ -34,17 +34,17 @@ /// //===----------------------------------------------------------------------===// -#ifndef RCC_SUPPORT_MEMALLOC_H -#define RCC_SUPPORT_MEMALLOC_H +#ifndef LIBBASE_SUPPORT_MEMALLOC_H +#define LIBBASE_SUPPORT_MEMALLOC_H -#include "CoreLib/Compiler/Compiler.h" -#include "CoreLib/Error/ErrorHandling.h" +#include "core/compiler/Compiler.h" +#include "core/error/ErrorHandling.h" #include <cstdlib> namespace rcc { -RCC_ATTRIBUTE_RETURNS_NONNULL inline void * +LIBBASE_ATTRIBUTE_RETURNS_NONNULL inline void * safe_malloc (size_t Sz) { void *Result = std::malloc (Sz); @@ -62,7 +62,7 @@ safe_malloc (size_t Sz) return Result; } -RCC_ATTRIBUTE_RETURNS_NONNULL inline void * +LIBBASE_ATTRIBUTE_RETURNS_NONNULL inline void * safe_calloc (size_t Count, size_t Sz) { void *Result = std::calloc (Count, Sz); @@ -80,7 +80,7 @@ safe_calloc (size_t Count, size_t Sz) return Result; } -RCC_ATTRIBUTE_RETURNS_NONNULL inline void * +LIBBASE_ATTRIBUTE_RETURNS_NONNULL inline void * safe_realloc (void *Ptr, size_t Sz) { void *Result = std::realloc (Ptr, Sz); @@ -107,7 +107,7 @@ safe_realloc (void *Ptr, size_t Sz) /// like posix_memalign due to portability. It is mostly intended to allow /// compatibility with platforms that, after aligned allocation was added, use /// reduced default alignment. -RCC_ABI RCC_ATTRIBUTE_RETURNS_NONNULL RCC_ATTRIBUTE_RETURNS_NOALIAS void * +LIBBASE_ABI LIBBASE_ATTRIBUTE_RETURNS_NONNULL LIBBASE_ATTRIBUTE_RETURNS_NOALIAS void * allocate_buffer (size_t Size, size_t Alignment); /// Deallocate a buffer of memory with the given size and alignment. @@ -117,7 +117,7 @@ allocate_buffer (size_t Size, size_t Alignment); /// /// The pointer must have been allocated with the corresponding new operator, /// most likely using the above helper. -RCC_ABI void +LIBBASE_ABI void deallocate_buffer (void *Ptr, size_t Size, size_t Alignment); } // namespace rcc diff --git a/libsupport/src/corelib/system/Errno.cc b/libbase/src/core/error/Errno.cc index 66ced94..3c85930 100644 --- a/libsupport/src/corelib/system/Errno.cc +++ b/libbase/src/core/error/Errno.cc @@ -21,8 +21,8 @@ // This implementation is based on llvm/lib/Support/Errno.cpp. -#include "CoreLib/System/Errno.h" -#include "rcc/Config/config.h" +#include "core/error/Errno.h" +#include "core/config/config.h" #include <cstring> #include <errno.h> diff --git a/libsupport/src/corelib/math/MathExtras.cc b/libbase/src/core/math/MathExtras.cc index 99d7ba7..8d1798f 100644 --- a/libsupport/src/corelib/math/MathExtras.cc +++ b/libbase/src/core/math/MathExtras.cc @@ -31,7 +31,7 @@ // //===----------------------------------------------------------------------===// -#include "CoreLib/Math/MathExtras.h" +#include "core/math/MathExtras.h" #ifdef _MSC_VER #include <limits> diff --git a/libsupport/src/corelib/memory/MemAlloc.cpp b/libbase/src/core/memory/MemAlloc.cpp index 9413922..b418d40 100644 --- a/libsupport/src/corelib/memory/MemAlloc.cpp +++ b/libbase/src/core/memory/MemAlloc.cpp @@ -27,12 +27,12 @@ // //===----------------------------------------------------------------------===// -#include "CoreLib/Memory/MemAlloc.h" +#include "core/memory/MemAlloc.h" #include <new> // These are out of line to have __cpp_aligned_new not affect ABI. -RCC_ATTRIBUTE_RETURNS_NONNULL RCC_ATTRIBUTE_RETURNS_NOALIAS void * +LIBBASE_ATTRIBUTE_RETURNS_NONNULL LIBBASE_ATTRIBUTE_RETURNS_NOALIAS void * rcc::allocate_buffer (size_t Size, size_t Alignment) { void *Result = ::operator new (Size, diff --git a/libsupport/CMakeLists.txt b/libsupport/CMakeLists.txt deleted file mode 100644 index 0784f3b..0000000 --- a/libsupport/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-or-later - -add_rcc_library(RCCSupport - STATIC - src/corelib/math/MathExtras.cc - src/corelib/memory/MemAlloc.cpp - src/corelib/system/Errno.cc -) - -target_include_directories(RCCSupport - PUBLIC - "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" - "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>") - -install(DIRECTORY include/CoreLib DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/libsupport/include/CoreLib/Compiler/Compiler.h b/libsupport/include/CoreLib/Compiler/Compiler.h deleted file mode 100644 index 511c4cd..0000000 --- a/libsupport/include/CoreLib/Compiler/Compiler.h +++ /dev/null @@ -1,853 +0,0 @@ -/* - RCC-Project - - Copyright (C) 2026 Richard Qin - - This file is part of RCC-Project. - - RCC-Project is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 3 of the License, or (at your option) any - later version. - - RCC-Project is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - RCC-Project; see the file COPYING. If not see - <http://www.gnu.org/licenses/>. -*/ - -//===-- llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file defines several macros, based on the current compiler. This allows -// use of compiler-specific features in a way that remains portable. This header -// can be included from either C or C++. -// -//===----------------------------------------------------------------------===// - -#ifndef RCC_SUPPORT_COMPILER_H -#define RCC_SUPPORT_COMPILER_H - -#include "rcc/Config/rcc-config.h" - -#include <stddef.h> - -#if defined(_MSC_VER) -#include <sal.h> -#endif - -#ifndef __has_feature -#define __has_feature(x) 0 -#endif - -#ifndef __has_extension -#define __has_extension(x) 0 -#endif - -#ifndef __has_attribute -#define __has_attribute(x) 0 -#endif - -#ifndef __has_builtin -#define __has_builtin(x) 0 -#endif - -#ifndef __has_warning -#define __has_warning(x) 0 -#endif - -// Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in -// C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid. -#ifndef RCC_HAS_CPP_ATTRIBUTE -#if defined(__cplusplus) && defined(__has_cpp_attribute) -#define RCC_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute (x) -#else -#define RCC_HAS_CPP_ATTRIBUTE(x) 0 -#endif -#endif - -/// \macro RCC_GNUC_PREREQ -/// Extend the default __GNUC_PREREQ even if glibc's features.h isn't -/// available. -#ifndef RCC_GNUC_PREREQ -#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -#define RCC_GNUC_PREREQ(maj, min, patch) \ - ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \ - ((maj) << 20) + ((min) << 10) + (patch)) -#elif defined(__GNUC__) && defined(__GNUC_MINOR__) -#define RCC_GNUC_PREREQ(maj, min, patch) \ - ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10)) -#else -#define RCC_GNUC_PREREQ(maj, min, patch) 0 -#endif -#endif - -/// \macro RCC_MSC_PREREQ -/// Is the compiler MSVC of at least the specified version? -/// The common \param version values to check for are: -/// * 1910: VS2017, version 15.1 & 15.2 -/// * 1911: VS2017, version 15.3 & 15.4 -/// * 1912: VS2017, version 15.5 -/// * 1913: VS2017, version 15.6 -/// * 1914: VS2017, version 15.7 -/// * 1915: VS2017, version 15.8 -/// * 1916: VS2017, version 15.9 -/// * 1920: VS2019, version 16.0 -/// * 1921: VS2019, version 16.1 -/// * 1922: VS2019, version 16.2 -/// * 1923: VS2019, version 16.3 -/// * 1924: VS2019, version 16.4 -/// * 1925: VS2019, version 16.5 -/// * 1926: VS2019, version 16.6 -/// * 1927: VS2019, version 16.7 -/// * 1928: VS2019, version 16.8 + 16.9 -/// * 1929: VS2019, version 16.10 + 16.11 -/// * 1930: VS2022, version 17.0 -#ifdef _MSC_VER -#define RCC_MSC_PREREQ(version) (_MSC_VER >= (version)) - -// We require at least VS 2019. -#if !defined(RCC_FORCE_USE_OLD_TOOLCHAIN) -#if !RCC_MSC_PREREQ(1920) -#error RCC requires at least VS 2019. -#endif -#endif - -#else -#define RCC_MSC_PREREQ(version) 0 -#endif - -/// RCC_LIBRARY_VISIBILITY - If a class marked with this attribute is linked -/// into a shared library, then the class should be private to the library and -/// not accessible from outside it. Can also be used to mark variables and -/// functions, making them private to any shared library they are linked into. -/// On PE/COFF targets, library visibility is the default, so this isn't needed. -/// -/// RCC_EXTERNAL_VISIBILITY - classes, functions, and variables marked with -/// this attribute will be made public and visible outside of any shared library -/// they are linked in to. - -#if RCC_HAS_CPP_ATTRIBUTE(gnu::visibility) && defined(__GNUC__) && \ - !defined(__clang__) -#define RCC_ATTRIBUTE_VISIBILITY_HIDDEN [[gnu::visibility ("hidden")]] -#define RCC_ATTRIBUTE_VISIBILITY_DEFAULT [[gnu::visibility ("default")]] -#elif __has_attribute(visibility) -#define RCC_ATTRIBUTE_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden"))) -#define RCC_ATTRIBUTE_VISIBILITY_DEFAULT \ - __attribute__ ((visibility ("default"))) -#else -#define RCC_ATTRIBUTE_VISIBILITY_HIDDEN -#define RCC_ATTRIBUTE_VISIBILITY_DEFAULT -#endif - -#if defined(RCC_BUILD_RCC_DYLIB) || defined(RCC_BUILD_SHARED_LIBS) -#define RCC_EXTERNAL_VISIBILITY RCC_ATTRIBUTE_VISIBILITY_DEFAULT -#else -#define RCC_EXTERNAL_VISIBILITY -#endif - -#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \ - ((defined(__MINGW32__) || defined(__CYGWIN__)) && defined(__clang__))) -#define RCC_LIBRARY_VISIBILITY RCC_ATTRIBUTE_VISIBILITY_HIDDEN -// Clang compilers older then 15 do not support gnu style attributes on -// namespaces. -#if defined(__clang__) && __clang_major__ < 15 -#define RCC_LIBRARY_VISIBILITY_NAMESPACE [[gnu::visibility ("hidden")]] -#else -#define RCC_LIBRARY_VISIBILITY_NAMESPACE RCC_ATTRIBUTE_VISIBILITY_HIDDEN -#endif -#define RCC_ALWAYS_EXPORT RCC_ATTRIBUTE_VISIBILITY_DEFAULT -#elif defined(_WIN32) -#define RCC_ALWAYS_EXPORT __declspec (dllexport) -#define RCC_LIBRARY_VISIBILITY -#define RCC_LIBRARY_VISIBILITY_NAMESPACE -#else -#define RCC_LIBRARY_VISIBILITY -#define RCC_ALWAYS_EXPORT -#define RCC_LIBRARY_VISIBILITY_NAMESPACE -#endif - -/// RCC_ABI is the main export/visibility macro to mark something as explicitly -/// exported when rcc is built as a shared library with everything else that is -/// unannotated will have internal visibility. -/// -/// RCC_ABI_EXPORT is for the special case for things like plugin symbol -/// declarations or definitions where we don't want the macro to be switching -/// between dllexport and dllimport on windows based on what codebase is being -/// built, it will only be dllexport. For non windows platforms this macro -/// behaves the same as RCC_ABI. -/// -/// RCC_EXPORT_TEMPLATE is used on explicit template instantiations in source -/// files that were declared extern in a header. This macro is only set as a -/// compiler export attribute on windows, on other platforms it does nothing. -/// -/// RCC_TEMPLATE_ABI is for annotating extern template declarations in headers -/// for both functions and classes. On windows its turned in to dllimport for -/// library consumers, for other platforms its a default visibility attribute. -/// -/// RCC_ABI_FOR_TEST is for annotating symbols that are exported from a -/// library-internal header solely so that unit tests can link against them. -/// Symbols in RCC's public headers are part of the RCC public interface and -/// should use RCC_ABI. RCC_ABI_FOR_TEST is reserved for internal headers, -/// whose symbols could be conditionally excluded when not building tests in the -/// future. -/// -#ifndef RCC_ABI_GENERATING_ANNOTATIONS -// Marker to add to classes or functions in public headers that should not have -// export macros added to them by the clang tool -#define RCC_ABI_NOT_EXPORTED -// TODO(https://github.com/rcc/rcc-project/issues/145406): eliminate need for -// two preprocessor definitions to gate RCC_ABI macro definitions. -#if defined(RCC_ENABLE_RCC_EXPORT_ANNOTATIONS) && !defined(RCC_BUILD_STATIC) -#if defined(_WIN32) && !defined(__MINGW32__) -#if defined(RCC_EXPORTS) -#define RCC_ABI __declspec (dllexport) -#define RCC_TEMPLATE_ABI -#define RCC_EXPORT_TEMPLATE __declspec (dllexport) -#else -#define RCC_ABI __declspec (dllimport) -#define RCC_TEMPLATE_ABI __declspec (dllimport) -#define RCC_EXPORT_TEMPLATE -#endif -#define RCC_ABI_EXPORT __declspec (dllexport) -#elif __has_attribute(visibility) -#if defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ - defined(__MVS__) || defined(__CYGWIN__) -#define RCC_ABI __attribute__ ((visibility ("default"))) -#define RCC_TEMPLATE_ABI RCC_ABI -#define RCC_EXPORT_TEMPLATE -#define RCC_ABI_EXPORT RCC_ABI -#elif defined(__MACH__) || defined(__wasm__) || defined(__EMSCRIPTEN__) -#define RCC_ABI __attribute__ ((visibility ("default"))) -#define RCC_TEMPLATE_ABI -#define RCC_EXPORT_TEMPLATE -#define RCC_ABI_EXPORT RCC_ABI -#endif -#endif -#endif -#if !defined(RCC_ABI) -#define RCC_ABI -#define RCC_TEMPLATE_ABI -#define RCC_EXPORT_TEMPLATE -#define RCC_ABI_EXPORT -#endif -#define RCC_ABI_FOR_TEST RCC_ABI -#endif - -#if defined(__GNUC__) -#define RCC_PREFETCH(addr, rw, locality) __builtin_prefetch (addr, rw, locality) -#else -#define RCC_PREFETCH(addr, rw, locality) -#endif - -#if __has_attribute(uninitialized) -#define RCC_ATTRIBUTE_UNINITIALIZED __attribute__ ((uninitialized)) -#else -#define RCC_ATTRIBUTE_UNINITIALIZED -#endif - -#if __has_attribute(used) -#define RCC_ATTRIBUTE_USED __attribute__ ((__used__)) -#else -#define RCC_ATTRIBUTE_USED -#endif - -#if __has_attribute(warn_unused) -#define RCC_ATTRIBUTE_WARN_UNUSED __attribute__ ((warn_unused)) -#else -#define RCC_ATTRIBUTE_WARN_UNUSED -#endif - -// Only enabled for clang: -// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99587 -// GCC may produce "warning: 'retain' attribute ignored" (despite -// __has_attribute(retain) being 1). -#if defined(__clang__) && __has_attribute(retain) -#define RCC_ATTRIBUTE_RETAIN __attribute__ ((__retain__)) -#else -#define RCC_ATTRIBUTE_RETAIN -#endif - -// For deprecations that are not a simple rename, use [[deprecated(MSG)]] -// instead. -#if defined(__clang__) -#define RCC_DEPRECATED_WITH_FIXIT(MSG, FIX) \ - __attribute__ ((deprecated (MSG, FIX))) -#else -#define RCC_DEPRECATED_WITH_FIXIT(MSG, FIX) [[deprecated (MSG)]] -#endif - -// clang-format off -#if defined(__clang__) || defined(__GNUC__) -#define RCC_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \ - _Pragma("GCC diagnostic push") \ - _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") -#define RCC_SUPPRESS_DEPRECATED_DECLARATIONS_POP \ - _Pragma("GCC diagnostic pop") -#elif defined(_MSC_VER) -#define RCC_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \ - __pragma(warning(push)) \ - __pragma(warning(disable : 4996)) -#define RCC_SUPPRESS_DEPRECATED_DECLARATIONS_POP \ - __pragma(warning(pop)) -#else -#define RCC_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH -#define RCC_SUPPRESS_DEPRECATED_DECLARATIONS_POP -#endif -// clang-format on - -// Indicate that a non-static, non-const C++ member function reinitializes -// the entire object to a known state, independent of the previous state of -// the object. -// -// The clang-tidy check bugprone-use-after-move recognizes this attribute as a -// marker that a moved-from object has left the indeterminate state and can be -// reused. -#if RCC_HAS_CPP_ATTRIBUTE(clang::reinitializes) -#define RCC_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]] -#else -#define RCC_ATTRIBUTE_REINITIALIZES -#endif - -// Some compilers warn about unused functions. When a function is sometimes -// used or not depending on build settings (e.g. a function only called from -// within "assert"), this attribute can be used to suppress such warnings. -// -// However, it shouldn't be used for unused *variables*, as those have a much -// more portable solution: -// (void)unused_var_name; -// Prefer cast-to-void wherever it is sufficient. -#if __has_attribute(unused) -#define RCC_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) -#else -#define RCC_ATTRIBUTE_UNUSED -#endif - -// FIXME: Provide this for PE/COFF targets. -#if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \ - !defined(_WIN32) -#define RCC_HAS_ATTRIBUTE_WEAK 1 -#else -#define RCC_HAS_ATTRIBUTE_WEAK 0 -#endif -#if RCC_HAS_ATTRIBUTE_WEAK -#define RCC_ATTRIBUTE_WEAK __attribute__ ((__weak__)) -#else -#define RCC_ATTRIBUTE_WEAK -#endif - -// Prior to clang 3.2, clang did not accept any spelling of -// __has_attribute(const), so assume it is supported. -#if defined(__clang__) || defined(__GNUC__) -// aka 'CONST' but following RCC Conventions. -#define RCC_READNONE __attribute__ ((__const__)) -#else -#define RCC_READNONE -#endif - -#if __has_attribute(pure) || defined(__GNUC__) -// aka 'PURE' but following RCC Conventions. -#define RCC_READONLY __attribute__ ((__pure__)) -#else -#define RCC_READONLY -#endif - -#if __has_attribute(minsize) -#define RCC_ATTRIBUTE_MINSIZE __attribute__ ((minsize)) -#else -#define RCC_ATTRIBUTE_MINSIZE -#endif - -#if __has_builtin(__builtin_expect) || defined(__GNUC__) -#define RCC_LIKELY(EXPR) __builtin_expect ((bool)(EXPR), true) -#define RCC_UNLIKELY(EXPR) __builtin_expect ((bool)(EXPR), false) -#else -#define RCC_LIKELY(EXPR) (EXPR) -#define RCC_UNLIKELY(EXPR) (EXPR) -#endif - -/// RCC_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, -/// mark a method "not for inlining". -#if __has_attribute(noinline) -#define RCC_ATTRIBUTE_NOINLINE __attribute__ ((noinline)) -#elif defined(_MSC_VER) -#define RCC_ATTRIBUTE_NOINLINE __declspec (noinline) -#else -#define RCC_ATTRIBUTE_NOINLINE -#endif - -/// RCC_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do -/// so, mark a method "always inline" because it is performance sensitive. -#if __has_attribute(always_inline) -#define RCC_ATTRIBUTE_ALWAYS_INLINE inline __attribute__ ((always_inline)) -#elif defined(_MSC_VER) -#define RCC_ATTRIBUTE_ALWAYS_INLINE __forceinline -#else -#define RCC_ATTRIBUTE_ALWAYS_INLINE inline -#endif - -/// RCC_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG - Like -/// RCC_ATTRIBUTE_ALWAYS_INLINE but disabled in debug builds to avoid stack -/// overflow with deep recursion. -#if defined(NDEBUG) -#define RCC_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG RCC_ATTRIBUTE_ALWAYS_INLINE -#else -#define RCC_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG inline -#endif - -/// RCC_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do -/// so, mark a method "no debug" because debug info makes the debugger -/// experience worse. -#if __has_attribute(nodebug) -#define RCC_ATTRIBUTE_NODEBUG __attribute__ ((nodebug)) -#else -#define RCC_ATTRIBUTE_NODEBUG -#endif - -#if __has_attribute(returns_nonnull) -#define RCC_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((returns_nonnull)) -#elif defined(_MSC_VER) -#define RCC_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_ -#else -#define RCC_ATTRIBUTE_RETURNS_NONNULL -#endif - -/// RCC_ATTRIBUTE_RESTRICT - Annotates a pointer to tell the compiler that -/// it is not aliased in the current scope. -#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) -#define RCC_ATTRIBUTE_RESTRICT __restrict -#else -#define RCC_ATTRIBUTE_RESTRICT -#endif - -/// \macro RCC_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a -/// pointer that does not alias any other valid pointer. -#ifdef __GNUC__ -#define RCC_ATTRIBUTE_RETURNS_NOALIAS __attribute__ ((__malloc__)) -#elif defined(_MSC_VER) -#define RCC_ATTRIBUTE_RETURNS_NOALIAS __declspec (restrict) -#else -#define RCC_ATTRIBUTE_RETURNS_NOALIAS -#endif - -/// RCC_FALLTHROUGH - Mark fallthrough cases in switch statements. -#if defined(__cplusplus) && __cplusplus > 201402L && \ - RCC_HAS_CPP_ATTRIBUTE(fallthrough) -#define RCC_FALLTHROUGH [[fallthrough]] -#elif RCC_HAS_CPP_ATTRIBUTE(gnu::fallthrough) -#define RCC_FALLTHROUGH [[gnu::fallthrough]] -#elif __has_attribute(fallthrough) -#define RCC_FALLTHROUGH __attribute__ ((fallthrough)) -#elif RCC_HAS_CPP_ATTRIBUTE(clang::fallthrough) -#define RCC_FALLTHROUGH [[clang::fallthrough]] -#else -#define RCC_FALLTHROUGH -#endif - -/// RCC_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that -/// they are constant initialized. -#if RCC_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization) -#define RCC_REQUIRE_CONSTANT_INITIALIZATION \ - [[clang::require_constant_initialization]] -#else -#define RCC_REQUIRE_CONSTANT_INITIALIZATION -#endif - -/// RCC_GSL_OWNER - Apply this to owning classes like SmallVector to enable -/// lifetime warnings. -#if RCC_HAS_CPP_ATTRIBUTE(gsl::Owner) -#define RCC_GSL_OWNER [[gsl::Owner]] -#else -#define RCC_GSL_OWNER -#endif - -/// RCC_GSL_POINTER - Apply this to non-owning classes like -/// StringRef to enable lifetime warnings. -#if RCC_HAS_CPP_ATTRIBUTE(gsl::Pointer) -#define RCC_GSL_POINTER [[gsl::Pointer]] -#else -#define RCC_GSL_POINTER -#endif - -#if RCC_HAS_CPP_ATTRIBUTE(clang::lifetimebound) -#define RCC_LIFETIME_BOUND [[clang::lifetimebound]] -#else -#define RCC_LIFETIME_BOUND -#endif - -#if RCC_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L -#define RCC_CTOR_NODISCARD [[nodiscard]] -#else -#define RCC_CTOR_NODISCARD -#endif - -// Macro to suppress the MSVC warning C4848: -// "support for attribute [[msvc::no_unique_address]] in C++17 and earlier -// is a vendor extension". -// This warning is removed in versions >= 19.43. -#if !defined(_MSC_VER) || _MSC_VER >= 1943 || defined(__clang__) -#define RCC_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_PUSH -#define RCC_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_POP -#else // MSVC < 19.43 -#define RCC_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_PUSH \ - __pragma (warning (push)) __pragma (warning (disable : 4848)) -#define RCC_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_POP __pragma (warning (pop)) -#endif - -#if RCC_HAS_CPP_ATTRIBUTE(no_unique_address) -#define RCC_NO_UNIQUE_ADDRESS [[no_unique_address]] -#elif RCC_HAS_CPP_ATTRIBUTE(msvc::no_unique_address) -#define RCC_NO_UNIQUE_ADDRESS \ - RCC_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_PUSH \ - [[msvc::no_unique_address]] RCC_SUPPRESS_MSVC_ATTR_IS_VENDOR_EXT_POP -#else -#define RCC_NO_UNIQUE_ADDRESS -#endif - -/// RCC_EXTENSION - Support compilers where we have a keyword to suppress -/// pedantic diagnostics. -#ifdef __GNUC__ -#define RCC_EXTENSION __extension__ -#else -#define RCC_EXTENSION -#endif - -/// RCC_BUILTIN_UNREACHABLE - On compilers which support it, expands -/// to an expression which states that it is undefined behavior for the -/// compiler to reach this point. Otherwise is not defined. -/// -/// '#else' is intentionally left out so that other macro logic (e.g., -/// RCC_ASSUME_ALIGNED and rcc_unreachable()) can detect whether -/// RCC_BUILTIN_UNREACHABLE has a definition. -#if __has_builtin(__builtin_unreachable) || defined(__GNUC__) -#define RCC_BUILTIN_UNREACHABLE __builtin_unreachable () -#elif defined(_MSC_VER) -#define RCC_BUILTIN_UNREACHABLE __assume (false) -#endif - -/// RCC_BUILTIN_TRAP - On compilers which support it, expands to an expression -/// which causes the program to exit abnormally. -#if __has_builtin(__builtin_trap) || defined(__GNUC__) -#define RCC_BUILTIN_TRAP __builtin_trap () -#elif defined(_MSC_VER) -// The __debugbreak intrinsic is supported by MSVC, does not require forward -// declarations involving platform-specific typedefs (unlike RaiseException), -// results in a call to vectored exception handlers, and encodes to a short -// instruction that still causes the trapping behavior we want. -#define RCC_BUILTIN_TRAP __debugbreak () -#else -#define RCC_BUILTIN_TRAP *(volatile int *)0x11 = 0 -#endif - -/// RCC_BUILTIN_DEBUGTRAP - On compilers which support it, expands to -/// an expression which causes the program to break while running -/// under a debugger. -#if __has_builtin(__builtin_debugtrap) -#define RCC_BUILTIN_DEBUGTRAP __builtin_debugtrap () -#elif defined(_MSC_VER) -// The __debugbreak intrinsic is supported by MSVC and breaks while -// running under the debugger, and also supports invoking a debugger -// when the OS is configured appropriately. -#define RCC_BUILTIN_DEBUGTRAP __debugbreak () -#else -// Just continue execution when built with compilers that have no -// support. This is a debugging aid and not intended to force the -// program to abort if encountered. -#define RCC_BUILTIN_DEBUGTRAP -#endif - -/// \macro RCC_ASSUME_ALIGNED -/// Returns a pointer with an assumed alignment. -#if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__) -#define RCC_ASSUME_ALIGNED(p, a) __builtin_assume_aligned (p, a) -#elif defined(RCC_BUILTIN_UNREACHABLE) -#define RCC_ASSUME_ALIGNED(p, a) \ - (((uintptr_t (p) % (a)) == 0) ? (p) : (RCC_BUILTIN_UNREACHABLE, (p))) -#else -#define RCC_ASSUME_ALIGNED(p, a) (p) -#endif - -/// \macro RCC_PACKED -/// Used to specify a packed structure. -/// RCC_PACKED( -/// struct A { -/// int i; -/// int j; -/// int k; -/// long long l; -/// }); -/// -/// RCC_PACKED_START -/// struct B { -/// int i; -/// int j; -/// int k; -/// long long l; -/// }; -/// RCC_PACKED_END -#ifdef _MSC_VER -#define RCC_PACKED(d) __pragma (pack (push, 1)) d __pragma (pack (pop)) -#define RCC_PACKED_START __pragma (pack (push, 1)) -#define RCC_PACKED_END __pragma (pack (pop)) -#else -#define RCC_PACKED(d) d __attribute__ ((packed)) -#define RCC_PACKED_START _Pragma ("pack(push, 1)") -#define RCC_PACKED_END _Pragma ("pack(pop)") -#endif - -/// \macro RCC_MEMORY_SANITIZER_BUILD -/// Whether RCC itself is built with MemorySanitizer instrumentation. -#if __has_feature(memory_sanitizer) -#define RCC_MEMORY_SANITIZER_BUILD 1 -#include <sanitizer/msan_interface.h> -#define RCC_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__ ((no_sanitize_memory)) -#else -#define RCC_MEMORY_SANITIZER_BUILD 0 -#define __msan_allocated_memory(p, size) -#define __msan_unpoison(p, size) -#define RCC_NO_SANITIZE_MEMORY_ATTRIBUTE -#endif - -/// \macro RCC_ADDRESS_SANITIZER_BUILD -/// Whether RCC itself is built with AddressSanitizer instrumentation. -#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) -#define RCC_ADDRESS_SANITIZER_BUILD 1 -#if __has_include(<sanitizer/asan_interface.h>) -#include <sanitizer/asan_interface.h> -#else -// These declarations exist to support ASan with MSVC. If MSVC eventually ships -// asan_interface.h in their headers, then we can remove this. -#ifdef __cplusplus -extern "C" -{ -#endif - void - __asan_poison_memory_region (void const volatile *addr, size_t size); - void - __asan_unpoison_memory_region (void const volatile *addr, size_t size); -#ifdef __cplusplus -} // extern "C" -#endif -#endif -#else -#define RCC_ADDRESS_SANITIZER_BUILD 0 -#define __asan_poison_memory_region(p, size) -#define __asan_unpoison_memory_region(p, size) -#endif - -/// \macro RCC_HWADDRESS_SANITIZER_BUILD -/// Whether RCC itself is built with HWAddressSanitizer instrumentation. -#if __has_feature(hwaddress_sanitizer) -#define RCC_HWADDRESS_SANITIZER_BUILD 1 -#else -#define RCC_HWADDRESS_SANITIZER_BUILD 0 -#endif - -/// \macro RCC_THREAD_SANITIZER_BUILD -/// Whether RCC itself is built with ThreadSanitizer instrumentation. -#if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__) -#define RCC_THREAD_SANITIZER_BUILD 1 -#else -#define RCC_THREAD_SANITIZER_BUILD 0 -#endif - -#if RCC_THREAD_SANITIZER_BUILD -// Thread Sanitizer is a tool that finds races in code. -// See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations . -// tsan detects these exact functions by name. -#ifdef __cplusplus -extern "C" -{ -#endif - void - AnnotateHappensAfter (const char *file, int line, const volatile void *cv); - void - AnnotateHappensBefore (const char *file, int line, const volatile void *cv); - void - AnnotateIgnoreWritesBegin (const char *file, int line); - void - AnnotateIgnoreWritesEnd (const char *file, int line); -#ifdef __cplusplus -} -#endif - -// This marker is used to define a happens-before arc. The race detector will -// infer an arc from the begin to the end when they share the same pointer -// argument. -#define TsanHappensBefore(cv) AnnotateHappensBefore (__FILE__, __LINE__, cv) - -// This marker defines the destination of a happens-before arc. -#define TsanHappensAfter(cv) AnnotateHappensAfter (__FILE__, __LINE__, cv) - -// Ignore any races on writes between here and the next TsanIgnoreWritesEnd. -#define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin (__FILE__, __LINE__) - -// Resume checking for racy writes. -#define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd (__FILE__, __LINE__) -#else -#define TsanHappensBefore(cv) -#define TsanHappensAfter(cv) -#define TsanIgnoreWritesBegin() -#define TsanIgnoreWritesEnd() -#endif - -/// \macro RCC_NO_SANITIZE -/// Disable a particular sanitizer for a function. -#if __has_attribute(no_sanitize) -#define RCC_NO_SANITIZE(KIND) __attribute__ ((no_sanitize (KIND))) -#else -#define RCC_NO_SANITIZE(KIND) -#endif - -/// Mark debug helper function definitions like dump() that should not be -/// stripped from debug builds. -/// Note that you should also surround dump() functions with -/// `#if !defined(NDEBUG) || defined(RCC_ENABLE_DUMP)` so they do always -/// get stripped in release builds. -// FIXME: Move this to a private config.h as it's not usable in public headers. -#if !defined(NDEBUG) || defined(RCC_ENABLE_DUMP) -#define RCC_DUMP_METHOD \ - RCC_ATTRIBUTE_NOINLINE RCC_ATTRIBUTE_USED RCC_ATTRIBUTE_RETAIN -#else -#define RCC_DUMP_METHOD RCC_ATTRIBUTE_NOINLINE -#endif - -/// \macro RCC_PRETTY_FUNCTION -/// Gets a user-friendly looking function signature for the current scope -/// using the best available method on each platform. The exact format of the -/// resulting string is implementation specific and non-portable, so this should -/// only be used, for example, for logging or diagnostics. -#if defined(_MSC_VER) -#define RCC_PRETTY_FUNCTION __FUNCSIG__ -#elif defined(__GNUC__) || defined(__clang__) -#define RCC_PRETTY_FUNCTION __PRETTY_FUNCTION__ -#else -#define RCC_PRETTY_FUNCTION __func__ -#endif - -/// \macro RCC_THREAD_LOCAL -/// A thread-local storage specifier which can be used with globals, -/// extern globals, and static globals. -/// -/// This is essentially an extremely restricted analog to C++11's thread_local -/// support. It uses thread_local if available, falling back on gcc __thread -/// if not. __thread doesn't support many of the C++11 thread_local's -/// features. You should only use this for PODs that you can statically -/// initialize to some constant value. In almost all circumstances this is most -/// appropriate for use with a pointer, integer, or small aggregation of -/// pointers and integers. -#if RCC_ENABLE_THREADS -#if __has_feature(cxx_thread_local) || defined(_MSC_VER) -#define RCC_THREAD_LOCAL thread_local -#else -// Clang, GCC, and other compatible compilers used __thread prior to C++11 and -// we only need the restricted functionality that provides. -#define RCC_THREAD_LOCAL __thread -#endif -#else // !RCC_ENABLE_THREADS -// If threading is disabled entirely, this compiles to nothing and you get -// a normal global variable. -#define RCC_THREAD_LOCAL -#endif - -/// \macro RCC_ENABLE_EXCEPTIONS -/// Whether RCC is built with exception support. -#if __has_feature(cxx_exceptions) -#define RCC_ENABLE_EXCEPTIONS 1 -#elif defined(__GNUC__) && defined(__EXCEPTIONS) -#define RCC_ENABLE_EXCEPTIONS 1 -#elif defined(_MSC_VER) && defined(_CPPUNWIND) -#define RCC_ENABLE_EXCEPTIONS 1 -#endif - -/// \macro RCC_NO_PROFILE_INSTRUMENT_FUNCTION -/// Disable the profile instrument for a function. -#if __has_attribute(no_profile_instrument_function) -#define RCC_NO_PROFILE_INSTRUMENT_FUNCTION \ - __attribute__ ((no_profile_instrument_function)) -#else -#define RCC_NO_PROFILE_INSTRUMENT_FUNCTION -#endif - -/// \macro RCC_PREFERRED_TYPE -/// Adjust type of bit-field in debug info. -#if __has_attribute(preferred_type) -#define RCC_PREFERRED_TYPE(T) __attribute__ ((preferred_type (T))) -#else -#define RCC_PREFERRED_TYPE(T) -#endif - -#if RCC_HAS_CPP_ATTRIBUTE(clang::ptrauth_vtable_pointer) && \ - (defined(__PTRAUTH__) || __has_feature(ptrauth_calls)) -#define RCC_MOVABLE_POLYMORPHIC_TYPE \ - [[clang::ptrauth_vtable_pointer (default_key, no_address_discrimination, \ - default_extra_discrimination)]] -#else -#define RCC_MOVABLE_POLYMORPHIC_TYPE -#endif - -/// \macro RCC_VIRTUAL_ANCHOR_FUNCTION -/// This macro is used to adhere to RCC's policy that each class with a vtable -/// must have at least one out-of-line virtual function. This macro allows us -/// to declare such a function in `final` classes without triggering a warning. -// clang-format off -// Autoformatting makes this look awful. -#if defined(__clang__) - // Make sure this is only parsed if __clang__ is defined - #if __has_warning("-Wunnecessary-virtual-specifier") - #define RCC_DECLARE_VIRTUAL_ANCHOR_FUNCTION() \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Wunnecessary-virtual-specifier\"") \ - virtual void anchor() \ - _Pragma("clang diagnostic pop") - #else // __has_warning - #define RCC_DECLARE_VIRTUAL_ANCHOR_FUNCTION() \ - virtual void anchor() - #endif -#else // defined(__clang__) - #define RCC_DECLARE_VIRTUAL_ANCHOR_FUNCTION() \ - virtual void anchor() -#endif -// clang-format on - -/// \macro RCC_IS_X86 -/// Whether the target architecture is x86 / x86-64. -#if defined(__x86_64__) || defined(__i386__) -#define RCC_IS_X86 1 -#else -#define RCC_IS_X86 0 -#endif - -/// \macro RCC_TARGET_SSE42 -/// Function attribute to compile a function with SSE4.2 enabled. -#if defined(__has_attribute) && __has_attribute(target) -#define RCC_TARGET_SSE42 __attribute__ ((target ("sse4.2"))) -#else -#define RCC_TARGET_SSE42 -#endif - -#if __has_builtin(__builtin_cpu_supports) && \ - (defined(__linux__) || defined(__APPLE__)) -#define RCC_CPU_SUPPORTS(feature) __builtin_cpu_supports (feature) -#else -#define RCC_CPU_SUPPORTS(feature) 0 -#endif - -/// \macro RCC_CPU_SUPPORTS_SSE42 -/// Expands to true if the runtime cpu supports SSE4.2, or if compiled with -/// SSE4.2 enabled. -#if defined(__SSE4_2__) -#define RCC_CPU_SUPPORTS_SSE42 1 -#else -#define RCC_CPU_SUPPORTS_SSE42 RCC_CPU_SUPPORTS ("sse4.2") -#endif - -#endif diff --git a/libsupport/include/CoreLib/Error/ErrorOr.h b/libsupport/include/CoreLib/Error/ErrorOr.h deleted file mode 100644 index 0e17822..0000000 --- a/libsupport/include/CoreLib/Error/ErrorOr.h +++ /dev/null @@ -1,378 +0,0 @@ -/* - RCC-Project - - Copyright (C) 2026 Richard Qin - - This file is part of RCC-Project. - - RCC-Project is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 3 of the License, or (at your option) any - later version. - - RCC-Project is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - RCC-Project; see the file COPYING. If not see - <http://www.gnu.org/licenses/>. -*/ - -//===- llvm/Support/ErrorOr.h - Error Smart Pointer -------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// -/// Provides ErrorOr<T> smart pointer. -/// -//===----------------------------------------------------------------------===// - -#ifndef RCC_SUPPORT_ERROROR_H -#define RCC_SUPPORT_ERROROR_H - -#include <cassert> -#include <functional> // for std::reference_wrapper -#include <system_error> -#include <type_traits> -#include <utility> - -namespace rcc -{ - -/// Represents either an error or a value T. -/// -/// ErrorOr<T> is a pointer-like class that represents the result of an -/// operation. The result is either an error, or a value of type T. This is -/// designed to emulate the usage of returning a pointer where nullptr indicates -/// failure. However instead of just knowing that the operation failed, we also -/// have an error_code that describes why it failed. -/// -/// It is used like the following. -/// \code -/// ErrorOr<Buffer> getBuffer(); -/// -/// auto buffer = getBuffer(); -/// if (error_code ec = buffer.getError()) -/// return ec; -/// buffer->write("adena"); -/// \endcode -/// -/// -/// Implicit conversion to bool returns true if there is a usable value. The -/// unary * and -> operators provide pointer like access to the value. Accessing -/// the value when there is an error has undefined behavior. -/// -/// When T is a reference type the behavior is slightly different. The reference -/// is held in a std::reference_wrapper<std::remove_reference<T>::type>, and -/// there is special handling to make operator -> work as if T was not a -/// reference. -/// -/// T cannot be a rvalue reference. -template <class T> class ErrorOr -{ - template <class OtherT> friend class ErrorOr; - - static constexpr bool isRef = std::is_reference_v<T>; - - using wrap = std::reference_wrapper<std::remove_reference_t<T>>; - -public: - using storage_type = std::conditional_t<isRef, wrap, T>; - -private: - using reference = std::remove_reference_t<T> &; - using const_reference = const std::remove_reference_t<T> &; - using pointer = std::remove_reference_t<T> *; - using const_pointer = const std::remove_reference_t<T> *; - -public: - template <class E> - ErrorOr (E ErrorCode, - std::enable_if_t<std::is_error_code_enum<E>::value || - std::is_error_condition_enum<E>::value, - void *> = nullptr) - : HasError (true) - { - new (getErrorStorage ()) std::error_code (make_error_code (ErrorCode)); - } - - ErrorOr (std::error_code EC) : HasError (true) - { - new (getErrorStorage ()) std::error_code (EC); - } - - template <class OtherT> - ErrorOr (OtherT &&Val, - std::enable_if_t<std::is_convertible_v<OtherT, T>> * = nullptr) - : HasError (false) - { - new (getStorage ()) storage_type (std::forward<OtherT> (Val)); - } - - ErrorOr (const ErrorOr &Other) - { - copyConstruct (Other); - } - - template <class OtherT> - ErrorOr (const ErrorOr<OtherT> &Other, - std::enable_if_t<std::is_convertible_v<OtherT, T>> * = nullptr) - { - copyConstruct (Other); - } - - template <class OtherT> - explicit ErrorOr ( - const ErrorOr<OtherT> &Other, - std::enable_if_t<!std::is_convertible_v<OtherT, const T &>> * = nullptr) - { - copyConstruct (Other); - } - - ErrorOr (ErrorOr &&Other) - { - moveConstruct (std::move (Other)); - } - - template <class OtherT> - ErrorOr (ErrorOr<OtherT> &&Other, - std::enable_if_t<std::is_convertible_v<OtherT, T>> * = nullptr) - { - moveConstruct (std::move (Other)); - } - - // This might eventually need SFINAE but it's more complex than is_convertible - // & I'm too lazy to write it right now. - template <class OtherT> - explicit ErrorOr ( - ErrorOr<OtherT> &&Other, - std::enable_if_t<!std::is_convertible_v<OtherT, T>> * = nullptr) - { - moveConstruct (std::move (Other)); - } - - ErrorOr & - operator= (const ErrorOr &Other) - { - copyAssign (Other); - return *this; - } - - ErrorOr & - operator= (ErrorOr &&Other) - { - moveAssign (std::move (Other)); - return *this; - } - - ~ErrorOr () - { - if (!HasError) - { - getStorage ()->~storage_type (); - } - } - - /// Return false if there is an error. - explicit - operator bool () const - { - return !HasError; - } - - reference - get () - { - return *getStorage (); - } - const_reference - get () const - { - return const_cast<ErrorOr<T> *> (this)->get (); - } - - std::error_code - getError () const - { - return HasError ? *getErrorStorage () : std::error_code (); - } - - pointer - operator->() - { - return toPointer (getStorage ()); - } - - const_pointer - operator->() const - { - return toPointer (getStorage ()); - } - - reference - operator* () - { - return *getStorage (); - } - - const_reference - operator* () const - { - return *getStorage (); - } - -private: - template <class OtherT> - void - copyConstruct (const ErrorOr<OtherT> &Other) - { - if (!Other.HasError) - { - // Get the other value. - HasError = false; - new (getStorage ()) storage_type (*Other.getStorage ()); - } - else - { - // Get other's error. - HasError = true; - new (getErrorStorage ()) std::error_code (Other.getError ()); - } - } - - template <class T1> - static bool - compareThisIfSameType (const T1 &a, const T1 &b) - { - return &a == &b; - } - - template <class T1, class T2> - static bool - compareThisIfSameType (const T1 &, const T2 &) - { - return false; - } - - template <class OtherT> - void - copyAssign (const ErrorOr<OtherT> &Other) - { - if (compareThisIfSameType (*this, Other)) - { - return; - } - - this->~ErrorOr (); - new (this) ErrorOr (Other); - } - - template <class OtherT> - void - moveConstruct (ErrorOr<OtherT> &&Other) - { - if (!Other.HasError) - { - // Get the other value. - HasError = false; - new (getStorage ()) storage_type (std::move (*Other.getStorage ())); - } - else - { - // Get other's error. - HasError = true; - new (getErrorStorage ()) std::error_code (Other.getError ()); - } - } - - template <class OtherT> - void - moveAssign (ErrorOr<OtherT> &&Other) - { - if (compareThisIfSameType (*this, Other)) - { - return; - } - - this->~ErrorOr (); - new (this) ErrorOr (std::move (Other)); - } - - pointer - toPointer (pointer Val) - { - return Val; - } - - const_pointer - toPointer (const_pointer Val) const - { - return Val; - } - - pointer - toPointer (wrap *Val) - { - return &Val->get (); - } - - const_pointer - toPointer (const wrap *Val) const - { - return &Val->get (); - } - - storage_type * - getStorage () - { - assert (!HasError && "Cannot get value when an error exists!"); - return &TStorage; - } - - const storage_type * - getStorage () const - { - assert (!HasError && "Cannot get value when an error exists!"); - return &TStorage; - } - - std::error_code * - getErrorStorage () - { - assert (HasError && "Cannot get error when a value exists!"); - return &ErrorStorage; - } - - const std::error_code * - getErrorStorage () const - { - assert (HasError && "Cannot get error when a value exists!"); - return &ErrorStorage; - } - - union - { - storage_type TStorage; - std::error_code ErrorStorage; - }; - bool HasError : 1; -}; - -template <class T, class E> -std::enable_if_t<std::is_error_code_enum<E>::value || - std::is_error_condition_enum<E>::value, - bool> -operator== (const ErrorOr<T> &Err, E Code) -{ - return Err.getError () == Code; -} - -} // end namespace rcc - -#endif // RCC_SUPPORT_ERROROR_H diff --git a/rcc/CMakeLists.txt b/rcc/CMakeLists.txt index 3825e8a..1fb86a0 100644 --- a/rcc/CMakeLists.txt +++ b/rcc/CMakeLists.txt @@ -53,20 +53,15 @@ configure_file( "${RCC_MAIN_INCLUDE_DIR}/rcc/Config/rcc-config.h.cmake" "${RCC_INCLUDE_DIR}/rcc/Config/rcc-config.h") -add_library(RCCHeaders INTERFACE) -target_compile_features(RCCHeaders INTERFACE cxx_std_23) -target_include_directories(RCCHeaders INTERFACE - "$<BUILD_INTERFACE:${RCC_SOURCE_DIR}/include>" - "$<BUILD_INTERFACE:${RCC_BINARY_DIR}/include>" - "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>") -install(TARGETS RCCHeaders EXPORT RCCTargets) install(DIRECTORY include/rcc DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING PATTERN "*.h" PATTERN "*.inc" PATTERN "*.def") -install(DIRECTORY "${RCC_BINARY_DIR}/include/rcc" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +install(DIRECTORY "${RCC_BINARY_DIR}/include/rcc/Config" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/rcc" FILES_MATCHING PATTERN "*.h" PATTERN "*.inc" PATTERN "*.def" - PATTERN "CMakeFiles" EXCLUDE PATTERN "config.h" EXCLUDE) + PATTERN "config.h" EXCLUDE) -add_subdirectory("${RCC_SOURCE_DIR}/../libsupport" "${CMAKE_CURRENT_BINARY_DIR}/libsupport") +set(RCC_LIBBASE_SOURCE_DIR "${RCC_SOURCE_DIR}/../libbase") +set(RCC_LIBBASE_BINARY_DIR "${RCC_BINARY_DIR}/libbase") +add_subdirectory("${RCC_LIBBASE_SOURCE_DIR}" "${RCC_LIBBASE_BINARY_DIR}") add_subdirectory(tools) foreach(rccProject IN LISTS RCC_ENABLE_PROJECTS) if(NOT rccProject STREQUAL "cfront") diff --git a/rcc/cmake/modules/AddRCC.cmake b/rcc/cmake/modules/AddRCC.cmake index 11bd92e..738df5f 100644 --- a/rcc/cmake/modules/AddRCC.cmake +++ b/rcc/cmake/modules/AddRCC.cmake @@ -162,7 +162,13 @@ endfunction() function(add_rcc_library name) cmake_parse_arguments(PARSE_ARGV 1 arg "DISABLE_PCH_REUSE;NO_INSTALL_RPATH" "" "LINK_LIBS;PRECOMPILE_HEADERS") add_library(${name} ${arg_UNPARSED_ARGUMENTS}) - target_link_libraries(${name} PUBLIC RCCHeaders ${arg_LINK_LIBS}) + target_link_libraries(${name} PUBLIC RCCCore ${arg_LINK_LIBS}) + target_compile_features(${name} PUBLIC cxx_std_23) + target_compile_definitions(${name} PRIVATE RCC_EXPORTS) + target_include_directories(${name} PUBLIC + "$<BUILD_INTERFACE:${RCC_SOURCE_DIR}/include>" + "$<BUILD_INTERFACE:${RCC_BINARY_DIR}/include>" + "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>") rcc_configure_target(${name}) install(TARGETS ${name} EXPORT RCCTargets ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" @@ -173,7 +179,11 @@ endfunction() function(add_rcc_executable name) cmake_parse_arguments(PARSE_ARGV 1 arg "DISABLE_PCH_REUSE;NO_INSTALL_RPATH" "" "LINK_LIBS;PRECOMPILE_HEADERS") add_executable(${name} ${arg_UNPARSED_ARGUMENTS}) - target_link_libraries(${name} PRIVATE RCCHeaders ${arg_LINK_LIBS}) + target_link_libraries(${name} PRIVATE RCCCore ${arg_LINK_LIBS}) + target_compile_features(${name} PRIVATE cxx_std_23) + target_include_directories(${name} PRIVATE + "${RCC_SOURCE_DIR}/include" + "${RCC_BINARY_DIR}/include") rcc_configure_target(${name}) endfunction() diff --git a/rcc/include/rcc/Config/config.h.cmake b/rcc/include/rcc/Config/config.h.cmake index 32761c1..8830412 100644 --- a/rcc/include/rcc/Config/config.h.cmake +++ b/rcc/include/rcc/Config/config.h.cmake @@ -1,5 +1,5 @@ -#ifndef CONFIG_H -#define CONFIG_H +#ifndef RCC_PRIVATE_CONFIG_H +#define RCC_PRIVATE_CONFIG_H // Include this header only under the rcc source tree. // This is a private header. @@ -10,38 +10,6 @@ /* Bug report URL. */ #define BUG_REPORT_URL "${BUG_REPORT_URL}" -/* Define to 1 to enable backtraces, and to 0 otherwise. */ -#cmakedefine01 ENABLE_BACKTRACES - -/* Define to 1 to enable crash overrides, and to 0 otherwise. */ -#cmakedefine01 ENABLE_CRASH_OVERRIDES - -/* Define to 1 to enable crash memory dumps, and to 0 otherwise. */ -#cmakedefine01 RCC_ENABLE_CRASH_DUMPS - -/* Define to 1 to prefer forward slashes on Windows, and to 0 prefer - backslashes. */ -#cmakedefine01 RCC_WINDOWS_PREFER_FORWARD_SLASH - -/* Define to 1 if you have the `backtrace' function. */ -#cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE} - -#define BACKTRACE_HEADER <${BACKTRACE_HEADER}> - -/* can use __crashreporter_info__ */ -#cmakedefine01 HAVE_CRASHREPORTER_INFO - -/* Define to 1 if you have the declaration of `arc4random', and to 0 if you - don't. */ -#cmakedefine01 HAVE_DECL_ARC4RANDOM - -/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you - don't. */ -#cmakedefine01 HAVE_DECL_STRERROR_S - -/* Define if dlopen() is available on this platform. */ -#cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN} - /* Define to 1 if we can register EH frames on this platform. */ #cmakedefine HAVE_REGISTER_FRAME ${HAVE_REGISTER_FRAME} @@ -60,177 +28,12 @@ /* Define to 1 if you have the <ffi.h> header file. */ #cmakedefine HAVE_FFI_H ${HAVE_FFI_H} -/* Define to 1 if you have the `futimens' function. */ -#cmakedefine HAVE_FUTIMENS ${HAVE_FUTIMENS} - -/* Define to 1 if you have the `futimes' function. */ -#cmakedefine HAVE_FUTIMES ${HAVE_FUTIMES} - -/* Define to 1 if you have the `getpagesize' function. */ -#cmakedefine HAVE_GETPAGESIZE ${HAVE_GETPAGESIZE} - -/* Define to 1 if you have the `getrusage' function. */ -#cmakedefine HAVE_GETRUSAGE ${HAVE_GETRUSAGE} - -/* Define to 1 if you have the `isatty' function. */ -#cmakedefine HAVE_ISATTY 1 - -/* Define to 1 if you have the `edit' library (-ledit). */ -#cmakedefine HAVE_LIBEDIT ${HAVE_LIBEDIT} - /* Define to 1 if you have the `pfm' library (-lpfm). */ #cmakedefine HAVE_LIBPFM ${HAVE_LIBPFM} /* Define to 1 if the `perf_branch_entry' struct has field cycles. */ #cmakedefine LIBPFM_HAS_FIELD_CYCLES ${LIBPFM_HAS_FIELD_CYCLES} -/* Define to 1 if you have the `psapi' library (-lpsapi). */ -#cmakedefine HAVE_LIBPSAPI ${HAVE_LIBPSAPI} - -/* Define to 1 if you have the `pthread' library (-lpthread). */ -#cmakedefine HAVE_LIBPTHREAD ${HAVE_LIBPTHREAD} - -/* Define to 1 if you have the `pthread_getname_np' function. */ -#cmakedefine HAVE_PTHREAD_GETNAME_NP ${HAVE_PTHREAD_GETNAME_NP} - -/* Define to 1 if you have the `pthread_setname_np' function. */ -#cmakedefine HAVE_PTHREAD_SETNAME_NP ${HAVE_PTHREAD_SETNAME_NP} - -/* Define to 1 if you have the `pthread_get_name_np' function. */ -#cmakedefine HAVE_PTHREAD_GET_NAME_NP ${HAVE_PTHREAD_GET_NAME_NP} - -/* Define to 1 if you have the `pthread_set_name_np' function. */ -#cmakedefine HAVE_PTHREAD_SET_NAME_NP ${HAVE_PTHREAD_SET_NAME_NP} - -/* Define to 1 if you have the <mach/mach.h> header file. */ -#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H} - -/* Define to 1 if you have the `mallctl' function. */ -#cmakedefine HAVE_MALLCTL ${HAVE_MALLCTL} - -/* Define to 1 if you have the `mallinfo' function. */ -#cmakedefine HAVE_MALLINFO ${HAVE_MALLINFO} - -/* Define to 1 if you have the `mallinfo2' function. */ -#cmakedefine HAVE_MALLINFO2 ${HAVE_MALLINFO2} - -/* Define to 1 if you have the <malloc/malloc.h> header file. */ -#cmakedefine HAVE_MALLOC_MALLOC_H ${HAVE_MALLOC_MALLOC_H} - -/* Define to 1 if you have the `malloc_zone_statistics' function. */ -#cmakedefine HAVE_MALLOC_ZONE_STATISTICS ${HAVE_MALLOC_ZONE_STATISTICS} - -/* Define to 1 if you have the `posix_spawn' function. */ -#cmakedefine HAVE_POSIX_SPAWN ${HAVE_POSIX_SPAWN} - -/* Define to 1 if you have the `pread' function. */ -#cmakedefine HAVE_PREAD ${HAVE_PREAD} - -/* Define to 1 if you have the <pthread.h> header file. */ -#cmakedefine HAVE_PTHREAD_H ${HAVE_PTHREAD_H} - -/* Have pthread_rwlock_init */ -#cmakedefine HAVE_PTHREAD_RWLOCK_INIT ${HAVE_PTHREAD_RWLOCK_INIT} - -/* Define to 1 if you have the `sbrk' function. */ -#cmakedefine HAVE_SBRK ${HAVE_SBRK} - -/* Define to 1 if you have the `setenv' function. */ -#cmakedefine HAVE_SETENV ${HAVE_SETENV} - -/* Define to 1 if you have the `sigaltstack' function. */ -#cmakedefine HAVE_SIGALTSTACK ${HAVE_SIGALTSTACK} - -/* Define to 1 if you have the `strerror_r' function. */ -#cmakedefine HAVE_STRERROR_R ${HAVE_STRERROR_R} - -/* Define to 1 if you have the `sysconf' function. */ -#cmakedefine HAVE_SYSCONF ${HAVE_SYSCONF} - -/* Define to 1 if you have the <sys/mman.h> header file. */ -#cmakedefine HAVE_SYS_MMAN_H ${HAVE_SYS_MMAN_H} - -/* Define to 1 if you have the <sys/ioctl.h> header file. */ -#cmakedefine HAVE_SYS_IOCTL_H ${HAVE_SYS_IOCTL_H} - -/* Define to 1 if stat struct has st_mtimespec member .*/ -#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC} - -/* Define to 1 if stat struct has st_mtim member. */ -#cmakedefine HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC} - -/* Define to 1 if you have the <unistd.h> header file. */ -#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H} - -/* Have host's _alloca */ -#cmakedefine HAVE__ALLOCA ${HAVE__ALLOCA} - -/* Define to 1 if you have the `_chsize_s' function. */ -#cmakedefine HAVE__CHSIZE_S ${HAVE__CHSIZE_S} - -/* Define to 1 if you have the `_Unwind_Backtrace' function. */ -#cmakedefine HAVE__UNWIND_BACKTRACE ${HAVE__UNWIND_BACKTRACE} - -/* Have host's __alloca */ -#cmakedefine HAVE___ALLOCA ${HAVE___ALLOCA} - -/* Have host's __ashldi3 */ -#cmakedefine HAVE___ASHLDI3 ${HAVE___ASHLDI3} - -/* Have host's __ashrdi3 */ -#cmakedefine HAVE___ASHRDI3 ${HAVE___ASHRDI3} - -/* Have host's __chkstk */ -#cmakedefine HAVE___CHKSTK ${HAVE___CHKSTK} - -/* Have host's __chkstk_ms */ -#cmakedefine HAVE___CHKSTK_MS ${HAVE___CHKSTK_MS} - -/* Have host's __cmpdi2 */ -#cmakedefine HAVE___CMPDI2 ${HAVE___CMPDI2} - -/* Have host's __divdi3 */ -#cmakedefine HAVE___DIVDI3 ${HAVE___DIVDI3} - -/* Have host's __fixdfdi */ -#cmakedefine HAVE___FIXDFDI ${HAVE___FIXDFDI} - -/* Have host's __fixsfdi */ -#cmakedefine HAVE___FIXSFDI ${HAVE___FIXSFDI} - -/* Have host's __floatdidf */ -#cmakedefine HAVE___FLOATDIDF ${HAVE___FLOATDIDF} - -/* Have host's __lshrdi3 */ -#cmakedefine HAVE___LSHRDI3 ${HAVE___LSHRDI3} - -/* Have host's __main */ -#cmakedefine HAVE___MAIN ${HAVE___MAIN} - -/* Have host's __moddi3 */ -#cmakedefine HAVE___MODDI3 ${HAVE___MODDI3} - -/* Have host's __udivdi3 */ -#cmakedefine HAVE___UDIVDI3 ${HAVE___UDIVDI3} - -/* Have host's __umoddi3 */ -#cmakedefine HAVE___UMODDI3 ${HAVE___UMODDI3} - -/* Have host's ___chkstk */ -#cmakedefine HAVE____CHKSTK ${HAVE____CHKSTK} - -/* Have host's ___chkstk_ms */ -#cmakedefine HAVE____CHKSTK_MS ${HAVE____CHKSTK_MS} - -/* Define if ICU library is available */ -#cmakedefine01 HAVE_ICU - -/* Define if Windows vendored ICU is available */ -#cmakedefine01 HAVE_WINDOWS_ICU - -/* Define if iconv library is available */ -#cmakedefine01 HAVE_ICONV - /* Linker version detected at compile time. */ #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}" @@ -267,25 +70,13 @@ /* Define to the vendor of this package. */ #cmakedefine PACKAGE_VENDOR "${PACKAGE_VENDOR}" -/* Define to a function implementing stricmp */ -#cmakedefine stricmp ${stricmp} - -/* Define to a function implementing strdup */ -#cmakedefine strdup ${strdup} - /* Whether GlobalISel rule coverage is being collected */ #cmakedefine01 RCC_GISEL_COV_ENABLED /* Define to the default GlobalISel coverage file prefix */ #cmakedefine RCC_GISEL_COV_PREFIX "${RCC_GISEL_COV_PREFIX}" -/* Whether Timers signpost passes in Xcode Instruments */ -#cmakedefine01 RCC_SUPPORT_XCODE_SIGNPOSTS - -#cmakedefine HAVE_PROC_PID_RUSAGE 1 - +/* Have host's builtin thread pointer. */ #cmakedefine HAVE_BUILTIN_THREAD_POINTER ${HAVE_BUILTIN_THREAD_POINTER} -#cmakedefine HAVE_GETAUXVAL ${HAVE_GETAUXVAL} - #endif diff --git a/rcc/include/rcc/Config/rcc-config.h.cmake b/rcc/include/rcc/Config/rcc-config.h.cmake index 9c0ba18..fb76d22 100644 --- a/rcc/include/rcc/Config/rcc-config.h.cmake +++ b/rcc/include/rcc/Config/rcc-config.h.cmake @@ -14,19 +14,10 @@ #ifndef RCC_CONFIG_H #define RCC_CONFIG_H -/* Define if RCC_ENABLE_DUMP is enabled */ -#cmakedefine RCC_ENABLE_DUMP - /* Target triple RCC will generate code for by default */ /* Doesn't use `cmakedefine` because it is allowed to be empty. */ #define RCC_DEFAULT_TARGET_TRIPLE "${RCC_DEFAULT_TARGET_TRIPLE}" -/* Define if threads enabled */ -#cmakedefine01 RCC_ENABLE_THREADS - -/* Has gcc/MSVC atomic intrinsics */ -#cmakedefine01 RCC_HAS_ATOMICS - /* Host triple RCC will be executed on */ #cmakedefine RCC_HOST_TRIPLE "${RCC_HOST_TRIPLE}" @@ -54,9 +45,6 @@ /* RCC name for the native target MCA init function, if available */ #cmakedefine RCC_NATIVE_TARGETMCA RCCInitialize${RCC_NATIVE_ARCH}TargetMCA -/* Define if this is Unixish platform */ -#cmakedefine RCC_ON_UNIX ${RCC_ON_UNIX} - /* Define if we have the Intel JIT API runtime support library */ #cmakedefine01 RCC_USE_INTEL_JITEVENTS @@ -78,69 +66,24 @@ /* RCC version string */ #define RCC_VERSION_STRING "${PACKAGE_VERSION}" -/* Whether RCC records statistics for use with GetStatistics(), - * PrintStatistics() or PrintStatisticsJSON() - */ -#cmakedefine01 RCC_FORCE_ENABLE_STATS - -/* Define if we have z3 and want to build it */ -#cmakedefine RCC_WITH_Z3 ${RCC_WITH_Z3} - -/* Define if we have curl and want to use it */ -#cmakedefine RCC_ENABLE_CURL ${RCC_ENABLE_CURL} - -/* Define if we have cpp-httplib and want to use it */ -#cmakedefine RCC_ENABLE_HTTPLIB ${RCC_ENABLE_HTTPLIB} - -/* Define if zlib compression is available */ -#cmakedefine01 RCC_ENABLE_ZLIB - -/* Define if zstd compression is available */ -#cmakedefine01 RCC_ENABLE_ZSTD - -/* Define if xz (lzma) decompression is available */ -#cmakedefine01 RCC_ENABLE_LZMA - /* Define if RCC is using tflite */ #cmakedefine RCC_HAVE_TFLITE /* Define if we want to check profile consistency in lit tests */ #cmakedefine RCC_ENABLE_PROFCHECK -/* Define to 1 if you have the <sysexits.h> header file. */ -#cmakedefine HAVE_SYSEXITS_H ${HAVE_SYSEXITS_H} - /* Define if building libRCC shared library */ #cmakedefine RCC_BUILD_RCC_DYLIB -/* Define if building RCC with BUILD_SHARED_LIBS */ -#cmakedefine RCC_BUILD_SHARED_LIBS - -/* Define if exporting RCC public interface for shared library */ -#cmakedefine RCC_ENABLE_RCC_EXPORT_ANNOTATIONS - /* Define if exporting RCC-C public interface for shared library */ #cmakedefine RCC_ENABLE_RCC_C_EXPORT_ANNOTATIONS -/* Define if building RCC with RCC_FORCE_USE_OLD_TOOLCHAIN_LIBS */ -#cmakedefine RCC_FORCE_USE_OLD_TOOLCHAIN ${RCC_FORCE_USE_OLD_TOOLCHAIN} - -/* Define if rcc_unreachable should be optimized with undefined behavior - * in non assert builds */ -#cmakedefine01 RCC_UNREACHABLE_OPTIMIZE - -/* Define if building RCC with RCC_ENABLE_IO_SANDBOX */ -#cmakedefine01 RCC_ENABLE_IO_SANDBOX - /* Define to 1 if you have the DIA SDK installed, and to 0 if you don't. */ #cmakedefine01 RCC_ENABLE_DIA_SDK /* Define if plugins enabled */ #cmakedefine RCC_ENABLE_PLUGINS -/* Define if logf128 is available */ -#cmakedefine RCC_HAS_LOGF128 - /* Define if building RCC with RCC_ENABLE_TELEMETRY */ #cmakedefine01 RCC_ENABLE_TELEMETRY @@ -152,7 +95,4 @@ coverage bugs, and to 0 otherwise. */ #cmakedefine01 RCC_ENABLE_DEBUGLOC_TRACKING_ORIGIN -/* Define to 1 to enable RCC OnDisk Content Addressable Storage */ -#cmakedefine01 RCC_ENABLE_ONDISK_CAS - #endif diff --git a/rcc/include/rcc/Support/Compiler.h b/rcc/include/rcc/Support/Compiler.h new file mode 100644 index 0000000..1076827 --- /dev/null +++ b/rcc/include/rcc/Support/Compiler.h @@ -0,0 +1,106 @@ +/* + RCC-Project + + Copyright (C) 2026 Richard Qin + + This file is part of RCC-Project. + + RCC-Project is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your option) any + later version. + + RCC-Project is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + RCC-Project; see the file COPYING. If not see + <http://www.gnu.org/licenses/>. +*/ + +//===-- rcc/Support/Compiler.h - RCC ABI support ---------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef RCC_SUPPORT_COMPILER_H +#define RCC_SUPPORT_COMPILER_H + +#include "core/compiler/Compiler.h" +#include "rcc/Config/rcc-config.h" + +/// RCC_EXTERNAL_VISIBILITY - classes, functions, and variables marked with +/// this attribute will be made public and visible outside of a shared library. +#if defined(RCC_BUILD_RCC_DYLIB) || defined(RCC_BUILD_SHARED_LIBS) +#define RCC_EXTERNAL_VISIBILITY LIBBASE_ATTRIBUTE_VISIBILITY_DEFAULT +#else +#define RCC_EXTERNAL_VISIBILITY +#endif + +/// RCC_LIBRARY_VISIBILITY - Mark symbols private to the RCC shared library. +#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \ + ((defined(__MINGW32__) || defined(__CYGWIN__)) && defined(__clang__))) +#define RCC_LIBRARY_VISIBILITY LIBBASE_ATTRIBUTE_VISIBILITY_HIDDEN +#if defined(__clang__) && __clang_major__ < 15 +#define RCC_LIBRARY_VISIBILITY_NAMESPACE [[gnu::visibility("hidden")]] +#else +#define RCC_LIBRARY_VISIBILITY_NAMESPACE LIBBASE_ATTRIBUTE_VISIBILITY_HIDDEN +#endif +#define RCC_ALWAYS_EXPORT LIBBASE_ATTRIBUTE_VISIBILITY_DEFAULT +#elif defined(_WIN32) +#define RCC_ALWAYS_EXPORT __declspec(dllexport) +#define RCC_LIBRARY_VISIBILITY +#define RCC_LIBRARY_VISIBILITY_NAMESPACE +#else +#define RCC_LIBRARY_VISIBILITY +#define RCC_ALWAYS_EXPORT +#define RCC_LIBRARY_VISIBILITY_NAMESPACE +#endif + +/// RCC_ABI is the main export macro for the RCC public interface. +/// RCC_ABI_EXPORT always exports a symbol from the defining library. +/// RCC_EXPORT_TEMPLATE marks explicit template instantiations. +/// RCC_TEMPLATE_ABI marks extern template declarations. +#ifndef RCC_ABI_GENERATING_ANNOTATIONS +#define RCC_ABI_NOT_EXPORTED +#if defined(RCC_ENABLE_RCC_EXPORT_ANNOTATIONS) && !defined(RCC_BUILD_STATIC) +#if defined(_WIN32) && !defined(__MINGW32__) +#if defined(RCC_EXPORTS) +#define RCC_ABI __declspec(dllexport) +#define RCC_TEMPLATE_ABI +#define RCC_EXPORT_TEMPLATE __declspec(dllexport) +#else +#define RCC_ABI __declspec(dllimport) +#define RCC_TEMPLATE_ABI __declspec(dllimport) +#define RCC_EXPORT_TEMPLATE +#endif +#define RCC_ABI_EXPORT __declspec(dllexport) +#elif __has_attribute(visibility) +#if defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ + defined(__MVS__) || defined(__CYGWIN__) +#define RCC_ABI LIBBASE_ATTRIBUTE_VISIBILITY_DEFAULT +#define RCC_TEMPLATE_ABI RCC_ABI +#define RCC_EXPORT_TEMPLATE +#define RCC_ABI_EXPORT RCC_ABI +#elif defined(__MACH__) || defined(__wasm__) || defined(__EMSCRIPTEN__) +#define RCC_ABI LIBBASE_ATTRIBUTE_VISIBILITY_DEFAULT +#define RCC_TEMPLATE_ABI +#define RCC_EXPORT_TEMPLATE +#define RCC_ABI_EXPORT RCC_ABI +#endif +#endif +#endif +#if !defined(RCC_ABI) +#define RCC_ABI +#define RCC_TEMPLATE_ABI +#define RCC_EXPORT_TEMPLATE +#define RCC_ABI_EXPORT +#endif +#define RCC_ABI_FOR_TEST RCC_ABI +#endif + +#endif |
