Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dialect macros _CCCL_NO_RTTI and _CCCL_NO_TYPEID #2578

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmake/CCCLBuildCompilerTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(CCCL_KNOWN_CXX_DIALECTS 11 14 17 20)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded)

option(CCCL_ENABLE_EXCEPTIONS "Enable exceptions within CCCL libraries." ON)
option(CCCL_ENABLE_RTTI "Enable RTTI within CCCL libraries." ON)
option(CCCL_ENABLE_WERROR "Treat warnings as errors for CCCL targets." ON)

function(cccl_build_compiler_interface interface_target cuda_compile_options cxx_compile_options compile_defs)
Expand Down Expand Up @@ -60,6 +61,10 @@ function(cccl_build_compiler_targets)
list(APPEND cxx_compile_definitions "CCCL_DISABLE_EXCEPTIONS")
endif()

if (NOT CCCL_ENABLE_RTTI)
list(APPEND cxx_compile_definitions "CCCL_DISABLE_RTTI")
endif()

if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
list(APPEND cuda_compile_options "--use-local-env")
list(APPEND cxx_compile_options "/bigobj")
Expand Down
1 change: 1 addition & 0 deletions libcudacxx/include/cuda/__cccl_config
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cuda/std/__cccl/extended_floating_point.h> // IWYU pragma: export
#include <cuda/std/__cccl/preprocessor.h> // IWYU pragma: export
#include <cuda/std/__cccl/ptx_isa.h> // IWYU pragma: export
#include <cuda/std/__cccl/rtti.h> // IWYU pragma: export
#include <cuda/std/__cccl/sequence_access.h> // IWYU pragma: export
#include <cuda/std/__cccl/system_header.h> // IWYU pragma: export
#include <cuda/std/__cccl/unreachable.h> // IWYU pragma: export
Expand Down
75 changes: 75 additions & 0 deletions libcudacxx/include/cuda/std/__cccl/rtti.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// Part of libcu++, the C++ Standard Library for your entire system,
// 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
// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#ifndef __CCCL_RTTI_H
#define __CCCL_RTTI_H

#include <cuda/std/__cccl/compiler.h>
#include <cuda/std/__cccl/system_header.h>

#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header

// NOTE: some compilers support the `typeid` feature but not the `dynamic_cast`
// feature. This is why we have separate macros for each.

#ifndef _CCCL_NO_RTTI
# if defined(CCCL_DISABLE_RTTI) // Escape hatch for users to manually disable RTTI
# define _CCCL_NO_RTTI
# elif defined(_CCCL_COMPILER_ICC)
# if __RTTI == 0 && __INTEL_RTTI__ == 0 && __GXX_RTTI == 0 && _CPPRTTI == 0
miscco marked this conversation as resolved.
Show resolved Hide resolved
# define _CCCL_NO_RTTI
# endif
# elif defined(_CCCL_COMPILER_NVRTC)
# define _CCCL_NO_RTTI
# elif defined(_CCCL_COMPILER_MSVC)
# if _CPPRTTI == 0
# define _CCCL_NO_RTTI
# endif
# elif defined(_CCCL_COMPILER_CLANG)
# if !__has_feature(cxx_rtti)
# define _CCCL_NO_RTTI
# endif
# else
# if __GXX_RTTI == 0 && __cpp_rtti == 0
# define _CCCL_NO_RTTI
# endif
# endif
#endif // !_CCCL_NO_RTTI

#ifndef _CCCL_NO_TYPEID
# if defined(CCCL_DISABLE_RTTI) // CCCL_DISABLE_RTTI disables typeid also
# define _CCCL_NO_TYPEID
# elif defined(_CCCL_COMPILER_ICC)
// when emulating MSVC, typeid is available even when RTTI is disabled
# if !defined(_MSC_VER) && __RTTI == 0 && __INTEL_RTTI__ == 0 && __GXX_RTTI == 0 && _CPPRTTI == 0
# define _CCCL_NO_TYPEID
# endif
# elif defined(_CCCL_COMPILER_NVRTC)
# define _CCCL_NO_TYPEID
# elif defined(_CCCL_COMPILER_MSVC)
// No-op, MSVC always supports typeid even when RTTI is disabled
# elif defined(_CCCL_COMPILER_CLANG)
# if !__has_feature(cxx_rtti)
# define _CCCL_NO_TYPEID
# endif
# else
# if __GXX_RTTI == 0 && __cpp_rtti == 0
# define _CCCL_NO_TYPEID
# endif
# endif
#endif // !_CCCL_NO_TYPEID

#endif // __CCCL_RTTI_H
38 changes: 19 additions & 19 deletions libcudacxx/include/cuda/std/__functional/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ class __base<_Rp(_ArgTypes...)>
virtual void destroy() noexcept = 0;
virtual void destroy_deallocate() noexcept = 0;
virtual _Rp operator()(_ArgTypes&&...) = 0;
# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI
virtual const void* target(const type_info&) const noexcept = 0;
virtual const type_info& target_type() const noexcept = 0;
# endif // _LIBCUDACXX_NO_RTTI
# endif // _CCCL_NO_RTTI
};

// __func implements __base for a given functor type.
Expand Down Expand Up @@ -304,10 +304,10 @@ class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> : public __base<_Rp(_ArgTypes...)>
virtual void destroy() noexcept;
virtual void destroy_deallocate() noexcept;
virtual _Rp operator()(_ArgTypes&&... __arg);
# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI
virtual const void* target(const type_info&) const noexcept;
virtual const type_info& target_type() const noexcept;
# endif // _LIBCUDACXX_NO_RTTI
# endif // _CCCL_NO_RTTI
};

template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
Expand Down Expand Up @@ -350,7 +350,7 @@ _Rp __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&&... __arg)
return __f_(_CUDA_VSTD::forward<_ArgTypes>(__arg)...);
}

# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI

template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
const void* __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const noexcept
Expand All @@ -368,7 +368,7 @@ const type_info& __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const noe
return typeid(_Fp);
}

# endif // _LIBCUDACXX_NO_RTTI
# endif // _CCCL_NO_RTTI

// __value_func creates a value-type from a __func.

Expand Down Expand Up @@ -561,7 +561,7 @@ class __value_func<_Rp(_ArgTypes...)>
return __f_ != nullptr;
}

# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI
_LIBCUDACXX_HIDE_FROM_ABI const type_info& target_type() const noexcept
{
if (__f_ == nullptr)
Expand All @@ -580,7 +580,7 @@ class __value_func<_Rp(_ArgTypes...)>
}
return (const _Tp*) __f_->target(typeid(_Tp));
}
# endif // _LIBCUDACXX_NO_RTTI
# endif // _CCCL_NO_RTTI
};

// Storage for a functor object, to be used with __policy to manage copy and
Expand Down Expand Up @@ -628,7 +628,7 @@ struct __policy
nullptr,
nullptr,
true,
# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI
&typeid(void)
# else
nullptr
Expand Down Expand Up @@ -658,7 +658,7 @@ struct __policy
&__large_clone<_Fun>,
&__large_destroy<_Fun>,
false,
# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI
&typeid(typename _Fun::_Target)
# else
nullptr
Expand All @@ -674,7 +674,7 @@ struct __policy
nullptr,
nullptr,
false,
# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI
&typeid(typename _Fun::_Target)
# else
nullptr
Expand Down Expand Up @@ -880,7 +880,7 @@ class __policy_func<_Rp(_ArgTypes...)>
return !__policy_->__is_null;
}

# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI
_LIBCUDACXX_HIDE_FROM_ABI const type_info& target_type() const noexcept
{
return *__policy_->__type_info;
Expand All @@ -902,7 +902,7 @@ class __policy_func<_Rp(_ArgTypes...)>
return reinterpret_cast<const _Tp*>(&__buf_.__small);
}
}
# endif // _LIBCUDACXX_NO_RTTI
# endif // _CCCL_NO_RTTI
};

# if defined(_LIBCUDACXX_HAS_BLOCKS_RUNTIME)
Expand Down Expand Up @@ -963,7 +963,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base
return _CUDA_VSTD::__invoke(__f_, _CUDA_VSTD::forward<_ArgTypes>(__arg)...);
}

# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI
virtual const void* target(type_info const& __ti) const noexcept
{
if (__ti == typeid(__func::__block_type))
Expand All @@ -977,7 +977,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base
{
return typeid(__func::__block_type);
}
# endif // _LIBCUDACXX_NO_RTTI
# endif // _CCCL_NO_RTTI
};

# endif // _LIBCUDACXX_HAS_EXTENSION_BLOCKS
Expand Down Expand Up @@ -1075,14 +1075,14 @@ class _CCCL_TYPE_VISIBILITY_DEFAULT function<_Rp(_ArgTypes...)>
// function invocation:
_Rp operator()(_ArgTypes...) const;

# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI
// function target access:
const type_info& target_type() const noexcept;
template <typename _Tp>
_Tp* target() noexcept;
template <typename _Tp>
const _Tp* target() const noexcept;
# endif // _LIBCUDACXX_NO_RTTI
# endif // _CCCL_NO_RTTI
};

# if _CCCL_STD_VER > 2014
Expand Down Expand Up @@ -1265,7 +1265,7 @@ _Rp function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
return __f_(_CUDA_VSTD::forward<_ArgTypes>(__arg)...);
}

# ifndef _LIBCUDACXX_NO_RTTI
# ifndef _CCCL_NO_RTTI

template <class _Rp, class... _ArgTypes>
const type_info& function<_Rp(_ArgTypes...)>::target_type() const noexcept
Expand All @@ -1287,7 +1287,7 @@ const _Tp* function<_Rp(_ArgTypes...)>::target() const noexcept
return __f_.template target<_Tp>();
}

# endif // _LIBCUDACXX_NO_RTTI
# endif // _CCCL_NO_RTTI

template <class _Rp, class... _ArgTypes>
_LIBCUDACXX_HIDE_FROM_ABI bool operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) noexcept
Expand Down
6 changes: 0 additions & 6 deletions libcudacxx/include/cuda/std/detail/libcxx/include/__config
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,6 @@ typedef __char32_t char32_t;
# define _LIBCUDACXX_HAS_NO_WCHAR_H
# endif // _LIBCUDACXX_HAS_NO_WCHAR_H

// Try to find out if RTTI is disabled.
// g++ and cl.exe have RTTI on by default and define a macro when it is.
# ifndef _LIBCUDACXX_NO_RTTI
# define _LIBCUDACXX_NO_RTTI
# endif // !_LIBCUDACXX_NO_RTTI

# ifndef _LIBCUDACXX_NODEBUG_TYPE
# if defined(__cuda_std__)
# define _LIBCUDACXX_NODEBUG_TYPE
Expand Down
2 changes: 1 addition & 1 deletion thrust/thrust/mr/memory_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class memory_resource<void*>

virtual bool do_is_equal(const THRUST_STD_MR_NS::memory_resource& other) const noexcept override
{
# ifdef THRUST_HAS_DYNAMIC_CAST
# ifndef _CCCL_NO_RTTI
auto mr_resource = dynamic_cast<memory_resource<>*>(&other);
return mr_resource && do_is_equal(*mr_resource);
# else
Expand Down
Loading