Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Created using spr 1.3.4
  • Loading branch information
vitalybuka committed Jul 26, 2024
2 parents 7211bcd + c6d8bf4 commit f8ac356
Show file tree
Hide file tree
Showing 37 changed files with 1,284 additions and 272 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-asset-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
var fs = require('fs');
var body = ''
if (fs.existsSync('./comment')) {
body = JSON.parse(fs.readFileSync('./comment')) + "\n\n";
body = fs.readFileSync('./comment') + "\n\n";
}
body = body + `\n\nhttps://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
Expand Down
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ Improvements to Clang's diagnostics

- Clang now diagnoses undefined behavior in constant expressions more consistently. This includes invalid shifts, and signed overflow in arithmetic.

- -Wdangling-assignment-gsl is enabled by default.

Improvements to Clang's time-trace
----------------------------------

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10131,7 +10131,7 @@ def warn_dangling_lifetime_pointer : Warning<
InGroup<DanglingGsl>;
def warn_dangling_lifetime_pointer_assignment : Warning<"object backing the "
"pointer %0 will be destroyed at the end of the full-expression">,
InGroup<DanglingAssignmentGsl>, DefaultIgnore;
InGroup<DanglingAssignmentGsl>;
def warn_new_dangling_initializer_list : Warning<
"array backing "
"%select{initializer list subobject of the allocated object|"
Expand Down
16 changes: 3 additions & 13 deletions libc/cmake/modules/LLVMLibCLibraryRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,9 @@ function(add_bitcode_entrypoint_library target_name base_target_name)
list(APPEND objects ${object})
endforeach()

set(output ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.bc)
add_custom_command(
OUTPUT ${output}
COMMAND ${LIBC_LLVM_LINK} ${objects} -o ${output}
DEPENDS ${all_deps} ${base_target_name}
COMMENT "Linking LLVM-IR bitcode for ${base_target_name}"
COMMAND_EXPAND_LISTS
)
add_custom_target(${target_name} DEPENDS ${output} ${all_deps})
set_target_properties(${target_name} PROPERTIES TARGET_OBJECT ${output})
if(TARGET llvm-link)
add_dependencies(${target_name} llvm-link)
endif()
add_executable(${target_name} ${objects})
target_link_options(${target_name} PRIVATE
"-r" "-nostdlib" "-flto" "-Wl,--lto-emit-llvm" "-march= ")
endfunction(add_bitcode_entrypoint_library)

# A rule to build a library from a collection of entrypoint objects.
Expand Down
30 changes: 2 additions & 28 deletions libc/cmake/modules/prepare_libc_gpu_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,10 @@ if(LIBC_TARGET_TRIPLE)
set(CMAKE_REQUIRED_FLAGS "--target=${LIBC_TARGET_TRIPLE}")
endif()
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib -nostdlib")
elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
set(CMAKE_REQUIRED_FLAGS
"${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
endif()

# Identify the program used to package multiple images into a single binary.
get_filename_component(compiler_path ${CMAKE_CXX_COMPILER} DIRECTORY)
if(TARGET clang-offload-packager)
get_target_property(LIBC_CLANG_OFFLOAD_PACKAGER clang-offload-packager LOCATION)
else()
find_program(LIBC_CLANG_OFFLOAD_PACKAGER
NAMES clang-offload-packager NO_DEFAULT_PATH
PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
if(NOT LIBC_CLANG_OFFLOAD_PACKAGER)
message(FATAL_ERROR "Cannot find the 'clang-offload-packager' for the GPU "
"build")
endif()
endif()

# Identify llvm-link program so we can merge the output IR into a single blob.
if(TARGET llvm-link)
get_target_property(LIBC_LLVM_LINK llvm-link LOCATION)
else()
find_program(LIBC_LLVM_LINK
NAMES llvm-link NO_DEFAULT_PATH
PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
if(NOT LIBC_LLVM_LINK)
message(FATAL_ERROR "Cannot find 'llvm-link' for the GPU build")
endif()
"${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument -nostdlib")
endif()

# Optionally set up a job pool to limit the number of GPU tests run in parallel.
Expand Down
27 changes: 9 additions & 18 deletions libc/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ foreach(archive IN ZIP_LISTS
PROPERTIES
OUTPUT_NAME ${archive_1}.bc
)
list(APPEND added_gpu_bitcode_targets ${archive_1}bitcode)
list(APPEND added_bitcode_targets ${archive_1}bitcode)
endif()
endforeach()

Expand All @@ -61,24 +61,13 @@ install(
COMPONENT libc
)

if(LIBC_TARGET_OS_IS_GPU)
set(gpu_install_dir lib${LLVM_LIBDIR_SUFFIX})
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
set(gpu_install_dir lib${LLVM_LIBDIR_SUFFIX}/${LLVM_HOST_TRIPLE})
endif()
install(
TARGETS ${added_gpu_archive_targets}
ARCHIVE DESTINATION ${gpu_install_dir}
COMPONENT libc
foreach(file ${added_bitcode_targets})
install(FILES $<TARGET_FILE:${file}>
DESTINATION ${LIBC_INSTALL_LIBRARY_DIR}
RENAME $<TARGET_PROPERTY:${file},OUTPUT_NAME>
COMPONENT libc
)
foreach(file ${added_gpu_bitcode_targets})
install(FILES $<TARGET_PROPERTY:${file},TARGET_OBJECT>
DESTINATION ${LIBC_INSTALL_LIBRARY_DIR}
RENAME $<TARGET_PROPERTY:${file},OUTPUT_NAME>
COMPONENT libc
)
endforeach()
endif()
endforeach()

if(NOT LIBC_TARGET_OS_IS_BAREMETAL)
# For now we will disable libc-startup installation for baremetal. The
Expand All @@ -93,13 +82,15 @@ endif()

add_custom_target(install-libc
DEPENDS ${added_archive_targets}
${added_bitcode_targets}
${startup_target}
${header_install_target}
COMMAND "${CMAKE_COMMAND}"
-DCMAKE_INSTALL_COMPONENT=libc
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
add_custom_target(install-libc-stripped
DEPENDS ${added_archive_targets}
${added_bitcode_targets}
${startup_target}
${header_install_target}
COMMAND "${CMAKE_COMMAND}"
Expand Down
15 changes: 14 additions & 1 deletion libcxx/include/__atomic/atomic_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD

#if _LIBCPP_STD_VER >= 20

// These types are required to make __atomic_is_always_lock_free work across GCC and Clang.
// The purpose of this trick is to make sure that we provide an object with the correct alignment
// to __atomic_is_always_lock_free, since that answer depends on the alignment.
template <size_t _Alignment>
struct __alignment_checker_type {
alignas(_Alignment) char __data;
};

template <size_t _Alignment>
struct __get_aligner_instance {
static constexpr __alignment_checker_type<_Alignment> __instance{};
};

template <class _Tp>
struct __atomic_ref_base {
protected:
Expand Down Expand Up @@ -105,7 +118,7 @@ struct __atomic_ref_base {
// that the pointer is going to be aligned properly at runtime because that is a (checked) precondition
// of atomic_ref's constructor.
static constexpr bool is_always_lock_free =
__atomic_always_lock_free(sizeof(_Tp), reinterpret_cast<void*>(-required_alignment));
__atomic_always_lock_free(sizeof(_Tp), &__get_aligner_instance<required_alignment>::__instance);

_LIBCPP_HIDE_FROM_ABI bool is_lock_free() const noexcept { return __atomic_is_lock_free(sizeof(_Tp), __ptr_); }

Expand Down
165 changes: 165 additions & 0 deletions libcxx/test/std/atomics/atomics.lockfree/is_always_lock_free.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: c++03, c++11, c++14

// <atomic>
//
// template <class T>
// class atomic;
//
// static constexpr bool is_always_lock_free;

#include <atomic>
#include <cassert>
#include <cstddef>

#include "test_macros.h"
#include "atomic_helpers.h"

template <typename T>
void check_always_lock_free(std::atomic<T> const& a) {
using InfoT = LockFreeStatusInfo<T>;

constexpr std::same_as<const bool> decltype(auto) is_always_lock_free = std::atomic<T>::is_always_lock_free;

// If we know the status of T for sure, validate the exact result of the function.
if constexpr (InfoT::status_known) {
constexpr LockFreeStatus known_status = InfoT::value;
if constexpr (known_status == LockFreeStatus::always) {
static_assert(is_always_lock_free, "is_always_lock_free is inconsistent with known lock-free status");
assert(a.is_lock_free() && "is_lock_free() is inconsistent with known lock-free status");
} else if constexpr (known_status == LockFreeStatus::never) {
static_assert(!is_always_lock_free, "is_always_lock_free is inconsistent with known lock-free status");
assert(!a.is_lock_free() && "is_lock_free() is inconsistent with known lock-free status");
} else {
assert(a.is_lock_free() || !a.is_lock_free()); // This is kinda dumb, but we might as well call the function once.
}
}

// In all cases, also sanity-check it based on the implication always-lock-free => lock-free.
if (is_always_lock_free) {
std::same_as<bool> decltype(auto) is_lock_free = a.is_lock_free();
assert(is_lock_free);
}
ASSERT_NOEXCEPT(a.is_lock_free());
}

#define CHECK_ALWAYS_LOCK_FREE(T) \
do { \
typedef T type; \
type obj{}; \
std::atomic<type> a(obj); \
check_always_lock_free(a); \
} while (0)

void test() {
char c = 'x';
check_always_lock_free(std::atomic<char>(c));

int i = 0;
check_always_lock_free(std::atomic<int>(i));

float f = 0.f;
check_always_lock_free(std::atomic<float>(f));

int* p = &i;
check_always_lock_free(std::atomic<int*>(p));

CHECK_ALWAYS_LOCK_FREE(bool);
CHECK_ALWAYS_LOCK_FREE(char);
CHECK_ALWAYS_LOCK_FREE(signed char);
CHECK_ALWAYS_LOCK_FREE(unsigned char);
#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
CHECK_ALWAYS_LOCK_FREE(char8_t);
#endif
CHECK_ALWAYS_LOCK_FREE(char16_t);
CHECK_ALWAYS_LOCK_FREE(char32_t);
CHECK_ALWAYS_LOCK_FREE(wchar_t);
CHECK_ALWAYS_LOCK_FREE(short);
CHECK_ALWAYS_LOCK_FREE(unsigned short);
CHECK_ALWAYS_LOCK_FREE(int);
CHECK_ALWAYS_LOCK_FREE(unsigned int);
CHECK_ALWAYS_LOCK_FREE(long);
CHECK_ALWAYS_LOCK_FREE(unsigned long);
CHECK_ALWAYS_LOCK_FREE(long long);
CHECK_ALWAYS_LOCK_FREE(unsigned long long);
CHECK_ALWAYS_LOCK_FREE(std::nullptr_t);
CHECK_ALWAYS_LOCK_FREE(void*);
CHECK_ALWAYS_LOCK_FREE(float);
CHECK_ALWAYS_LOCK_FREE(double);
CHECK_ALWAYS_LOCK_FREE(long double);
#if __has_attribute(vector_size) && defined(_LIBCPP_VERSION)
CHECK_ALWAYS_LOCK_FREE(int __attribute__((vector_size(1 * sizeof(int)))));
CHECK_ALWAYS_LOCK_FREE(int __attribute__((vector_size(2 * sizeof(int)))));
CHECK_ALWAYS_LOCK_FREE(int __attribute__((vector_size(4 * sizeof(int)))));
CHECK_ALWAYS_LOCK_FREE(int __attribute__((vector_size(16 * sizeof(int)))));
CHECK_ALWAYS_LOCK_FREE(int __attribute__((vector_size(32 * sizeof(int)))));
CHECK_ALWAYS_LOCK_FREE(float __attribute__((vector_size(1 * sizeof(float)))));
CHECK_ALWAYS_LOCK_FREE(float __attribute__((vector_size(2 * sizeof(float)))));
CHECK_ALWAYS_LOCK_FREE(float __attribute__((vector_size(4 * sizeof(float)))));
CHECK_ALWAYS_LOCK_FREE(float __attribute__((vector_size(16 * sizeof(float)))));
CHECK_ALWAYS_LOCK_FREE(float __attribute__((vector_size(32 * sizeof(float)))));
CHECK_ALWAYS_LOCK_FREE(double __attribute__((vector_size(1 * sizeof(double)))));
CHECK_ALWAYS_LOCK_FREE(double __attribute__((vector_size(2 * sizeof(double)))));
CHECK_ALWAYS_LOCK_FREE(double __attribute__((vector_size(4 * sizeof(double)))));
CHECK_ALWAYS_LOCK_FREE(double __attribute__((vector_size(16 * sizeof(double)))));
CHECK_ALWAYS_LOCK_FREE(double __attribute__((vector_size(32 * sizeof(double)))));
#endif // __has_attribute(vector_size) && defined(_LIBCPP_VERSION)
CHECK_ALWAYS_LOCK_FREE(struct Empty{});
CHECK_ALWAYS_LOCK_FREE(struct OneInt { int i; });
CHECK_ALWAYS_LOCK_FREE(struct IntArr2 { int i[2]; });
CHECK_ALWAYS_LOCK_FREE(struct FloatArr3 { float i[3]; });
CHECK_ALWAYS_LOCK_FREE(struct LLIArr2 { long long int i[2]; });
CHECK_ALWAYS_LOCK_FREE(struct LLIArr4 { long long int i[4]; });
CHECK_ALWAYS_LOCK_FREE(struct LLIArr8 { long long int i[8]; });
CHECK_ALWAYS_LOCK_FREE(struct LLIArr16 { long long int i[16]; });
CHECK_ALWAYS_LOCK_FREE(struct Padding {
char c; /* padding */
long long int i;
});
CHECK_ALWAYS_LOCK_FREE(union IntFloat {
int i;
float f;
});
CHECK_ALWAYS_LOCK_FREE(enum class CharEnumClass : char{foo});

// C macro and static constexpr must be consistent.
enum class CharEnumClass : char { foo };
static_assert(std::atomic<bool>::is_always_lock_free == (2 == ATOMIC_BOOL_LOCK_FREE), "");
static_assert(std::atomic<char>::is_always_lock_free == (2 == ATOMIC_CHAR_LOCK_FREE), "");
static_assert(std::atomic<CharEnumClass>::is_always_lock_free == (2 == ATOMIC_CHAR_LOCK_FREE), "");
static_assert(std::atomic<signed char>::is_always_lock_free == (2 == ATOMIC_CHAR_LOCK_FREE), "");
static_assert(std::atomic<unsigned char>::is_always_lock_free == (2 == ATOMIC_CHAR_LOCK_FREE), "");
#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
static_assert(std::atomic<char8_t>::is_always_lock_free == (2 == ATOMIC_CHAR8_T_LOCK_FREE), "");
#endif
static_assert(std::atomic<char16_t>::is_always_lock_free == (2 == ATOMIC_CHAR16_T_LOCK_FREE), "");
static_assert(std::atomic<char32_t>::is_always_lock_free == (2 == ATOMIC_CHAR32_T_LOCK_FREE), "");
static_assert(std::atomic<wchar_t>::is_always_lock_free == (2 == ATOMIC_WCHAR_T_LOCK_FREE), "");
static_assert(std::atomic<short>::is_always_lock_free == (2 == ATOMIC_SHORT_LOCK_FREE), "");
static_assert(std::atomic<unsigned short>::is_always_lock_free == (2 == ATOMIC_SHORT_LOCK_FREE), "");
static_assert(std::atomic<int>::is_always_lock_free == (2 == ATOMIC_INT_LOCK_FREE), "");
static_assert(std::atomic<unsigned int>::is_always_lock_free == (2 == ATOMIC_INT_LOCK_FREE), "");
static_assert(std::atomic<long>::is_always_lock_free == (2 == ATOMIC_LONG_LOCK_FREE), "");
static_assert(std::atomic<unsigned long>::is_always_lock_free == (2 == ATOMIC_LONG_LOCK_FREE), "");
static_assert(std::atomic<long long>::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE), "");
static_assert(std::atomic<unsigned long long>::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE), "");
static_assert(std::atomic<void*>::is_always_lock_free == (2 == ATOMIC_POINTER_LOCK_FREE), "");
static_assert(std::atomic<std::nullptr_t>::is_always_lock_free == (2 == ATOMIC_POINTER_LOCK_FREE), "");

#if TEST_STD_VER >= 20
static_assert(std::atomic_signed_lock_free::is_always_lock_free, "");
static_assert(std::atomic_unsigned_lock_free::is_always_lock_free, "");
#endif
}

int main(int, char**) {
test();
return 0;
}
Loading

0 comments on commit f8ac356

Please sign in to comment.