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

Address all remaining clang-tidy errors #16956

Merged
merged 17 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
38 changes: 31 additions & 7 deletions cpp/.clang-tidy
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
---
# Notes on disabled checks
# ------------------------
# modernize-use-equals-default:
# auto-fix is broken (doesn't insert =default correctly)
# modernize-concat-nested-namespaces:
# auto-fix is broken (can delete code)
# modernize-use-trailing-return-type:
# Purely stylistic, no benefit to rewriting everything
# modernize-use-bool-literals:
# Our tests use int flags for validity masks extensively and we prefer that
# clang-analyzer-cplusplus.NewDeleteLeaks:
# This check has numerous bugs, see
# https://github.com/llvm/llvm-project/issues?q=is%3Aissue+is%3Aopen+newdeleteleaks
# We encounter at least
# https://github.com/llvm/llvm-project/issues/60896
# https://github.com/llvm/llvm-project/issues/69602
# clang-analyzer-optin.core.EnumCastOutOfRange
# We use enums as flags in multiple cases and this check makes ORing flags invalid
# clang-analyzer-optin.cplusplus.UninitializedObject'
# There is an error in nanoarrow that none of the clang-tidy filters (i.e.
# header-filter and exclude-header-filter are able to properly avoid. This
# merits further investigation
#
# We need to verify that broken checks are still broken
Checks:
'modernize-*,
-modernize-use-equals-default,
-modernize-concat-nested-namespaces,
-modernize-use-trailing-return-type,
-modernize-use-bool-literals'

# -modernize-use-equals-default # auto-fix is broken (doesn't insert =default correctly)
# -modernize-concat-nested-namespaces # auto-fix is broken (can delete code)
# -modernize-use-trailing-return-type # just a preference
-modernize-use-bool-literals,
clang-analyzer-*,
-clang-analyzer-cplusplus.NewDeleteLeaks,
-clang-analyzer-optin.core.EnumCastOutOfRange,
-clang-analyzer-optin.cplusplus.UninitializedObject'

WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
HeaderFilterRegex: '.*cudf/cpp/(src|include|tests).*'
ExcludeHeaderFilterRegex: '.*(Message_generated.h|Schema_generated.h|brotli_dict.hpp|unbz2.hpp|cxxopts.hpp).*'
FormatStyle: none
CheckOptions:
- key: modernize-loop-convert.MaxCopySize
Expand Down
8 changes: 5 additions & 3 deletions cpp/cmake/thirdparty/get_nanoarrow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@

# This function finds nanoarrow and sets any additional necessary environment variables.
function(find_and_configure_nanoarrow)
include(${rapids-cmake-dir}/cpm/package_override.cmake)

set(cudf_patch_dir "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/patches")
rapids_cpm_package_override("${cudf_patch_dir}/nanoarrow_override.json")

# Currently we need to always build nanoarrow so we don't pickup a previous installed version
set(CPM_DOWNLOAD_nanoarrow ON)
rapids_cpm_find(
nanoarrow 0.6.0.dev
GLOBAL_TARGETS nanoarrow
CPM_ARGS
GIT_REPOSITORY https://github.com/apache/arrow-nanoarrow.git
GIT_TAG 1e2664a70ec14907409cadcceb14d79b9670bcdb
GIT_SHALLOW FALSE
OPTIONS "BUILD_SHARED_LIBS OFF" "NANOARROW_NAMESPACE cudf"
)
set_target_properties(nanoarrow PROPERTIES POSITION_INDEPENDENT_CODE ON)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
diff --git a/src/nanoarrow/common/inline_buffer.h b/src/nanoarrow/common/inline_buffer.h
index caa6be4..70ec8a2 100644
--- a/src/nanoarrow/common/inline_buffer.h
+++ b/src/nanoarrow/common/inline_buffer.h
@@ -347,7 +347,7 @@ static inline void _ArrowBitsUnpackInt32(const uint8_t word, int32_t* out) {
}

static inline void _ArrowBitmapPackInt8(const int8_t* values, uint8_t* out) {
- *out = (uint8_t)(values[0] | ((values[1] + 0x1) & 0x2) | ((values[2] + 0x3) & 0x4) |
+ *out = (uint8_t)(values[0] | ((values[1] + 0x1) & 0x2) | ((values[2] + 0x3) & 0x4) | // NOLINT
((values[3] + 0x7) & 0x8) | ((values[4] + 0xf) & 0x10) |
((values[5] + 0x1f) & 0x20) | ((values[6] + 0x3f) & 0x40) |
((values[7] + 0x7f) & 0x80));
@@ -471,13 +471,13 @@ static inline void ArrowBitsSetTo(uint8_t* bits, int64_t start_offset, int64_t l
// set bits within a single byte
const uint8_t only_byte_mask =
i_end % 8 == 0 ? first_byte_mask : (uint8_t)(first_byte_mask | last_byte_mask);
- bits[bytes_begin] &= only_byte_mask;
+ bits[bytes_begin] &= only_byte_mask; // NOLINT
bits[bytes_begin] |= (uint8_t)(fill_byte & ~only_byte_mask);
return;
}

// set/clear trailing bits of first byte
- bits[bytes_begin] &= first_byte_mask;
+ bits[bytes_begin] &= first_byte_mask; // NOLINT
bits[bytes_begin] |= (uint8_t)(fill_byte & ~first_byte_mask);

if (bytes_end - bytes_begin > 2) {
@@ -637,7 +637,7 @@ static inline void ArrowBitmapAppendInt8Unsafe(struct ArrowBitmap* bitmap,
n_remaining -= n_full_bytes * 8;
if (n_remaining > 0) {
// Zero out the last byte
- *out_cursor = 0x00;
+ *out_cursor = 0x00; // NOLINT
for (int i = 0; i < n_remaining; i++) {
ArrowBitSetTo(bitmap->buffer.data, out_i_cursor++, values_cursor[i]);
}
18 changes: 18 additions & 0 deletions cpp/cmake/thirdparty/patches/nanoarrow_override.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

{
"packages" : {
"nanoarrow" : {
"version" : "0.6.0.dev",
"git_url" : "https://github.com/apache/arrow-nanoarrow.git",
"git_tag" : "1e2664a70ec14907409cadcceb14d79b9670bcdb",
"git_shallow" : false,
"patches" : [
{
"file" : "${current_json_dir}/nanoarrow_clang_tidy_compliance.diff",
"issue" : "https://github.com/apache/arrow-nanoarrow/issues/537",
"fixed_in" : ""
}
]
}
}
}
2 changes: 1 addition & 1 deletion cpp/include/cudf/table/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class table {
std::vector<column_view> columns(std::distance(begin, end));
std::transform(
begin, end, columns.begin(), [this](auto index) { return _columns.at(index)->view(); });
return table_view(columns);
return table_view{columns};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/cudf/table/table_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class table_view : public detail::table_view_base<column_view> {
{
std::vector<column_view> columns(std::distance(begin, end));
std::transform(begin, end, columns.begin(), [this](auto index) { return this->column(index); });
return table_view(columns);
return table_view{columns};
}

/**
Expand Down
10 changes: 5 additions & 5 deletions cpp/src/binaryop/binaryop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ std::pair<rmm::device_buffer, size_type> scalar_col_valid_mask_and(
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
if (col.is_empty()) return std::pair(rmm::device_buffer{0, stream, mr}, 0);
if (col.is_empty()) return {rmm::device_buffer{0, stream, mr}, 0};

if (not s.is_valid(stream)) {
return std::pair(cudf::detail::create_null_mask(col.size(), mask_state::ALL_NULL, stream, mr),
col.size());
return {cudf::detail::create_null_mask(col.size(), mask_state::ALL_NULL, stream, mr),
col.size()};
} else if (s.is_valid(stream) and col.nullable()) {
return std::pair(cudf::detail::copy_bitmask(col, stream, mr), col.null_count());
return {cudf::detail::copy_bitmask(col, stream, mr), col.null_count()};
} else {
return std::pair(rmm::device_buffer{0, stream, mr}, 0);
return {rmm::device_buffer{0, stream, mr}, 0};
}
}

Expand Down
14 changes: 7 additions & 7 deletions cpp/src/copying/pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ column_view deserialize_column(serialized_column serial_column,
? reinterpret_cast<bitmask_type const*>(base_ptr + serial_column.null_mask_offset)
: nullptr;

return column_view(serial_column.type,
serial_column.size,
data_ptr,
null_mask_ptr,
serial_column.null_count,
0,
children);
return {serial_column.type,
serial_column.size,
data_ptr,
null_mask_ptr,
serial_column.null_count,
0,
children};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/groupby/sort/aggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ std::pair<std::unique_ptr<table>, std::vector<aggregation_result>> groupby::sort

auto results = detail::extract_results(requests, cache, stream, mr);

return std::pair(helper().unique_keys(stream, mr), std::move(results));
return {helper().unique_keys(stream, mr), std::move(results)};
}
} // namespace groupby
} // namespace cudf
2 changes: 1 addition & 1 deletion cpp/src/groupby/sort/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ std::pair<std::unique_ptr<table>, std::vector<aggregation_result>> groupby::sort

auto results = detail::extract_results(requests, cache, stream, mr);

return std::pair(helper().sorted_keys(stream, mr), std::move(results));
return {helper().sorted_keys(stream, mr), std::move(results)};
}
} // namespace groupby
} // namespace cudf
5 changes: 3 additions & 2 deletions cpp/src/io/avro/avro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "avro.hpp"

#include <array>
#include <cstring>
#include <unordered_map>

Expand Down Expand Up @@ -53,7 +54,7 @@ std::string container::get_encoded()
}();
auto const s = reinterpret_cast<char const*>(m_cur);
m_cur += len;
return std::string(s, len);
return {s, len};
}

/**
Expand Down Expand Up @@ -302,7 +303,7 @@ bool schema_parser::parse(std::vector<schema_entry>& schema, std::string const&
// Empty schema
if (json_str == "[]") return true;

char depthbuf[MAX_SCHEMA_DEPTH];
std::array<char, MAX_SCHEMA_DEPTH> depthbuf;
int depth = 0, parent_idx = -1, entry_idx = -1;
json_state_e state = state_attrname;
std::string str;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/io/orc/orc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class ProtobufReader {

private:
template <int index>
friend class FunctionSwitchImpl;
friend struct FunctionSwitchImpl;

void skip_bytes(size_t bytecnt)
{
Expand Down
6 changes: 4 additions & 2 deletions cpp/src/io/parquet/compact_protocol_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ class parquet_field_string : public parquet_field {
* @return True if field types mismatch or if the process of reading a
* string fails
*/
struct parquet_field_string_list : public parquet_field_list<std::string, FieldType::BINARY> {
class parquet_field_string_list : public parquet_field_list<std::string, FieldType::BINARY> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ELI5: Why was this change required? Isn't the old version a valid equivalent?

Is it because of (the equivalent of) the Google Style Guide stating that structs need to be POD/passive objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this was necessary because the header file declares this object as a class instead of a struct. We could equivalently have changed the header to use struct instead, but the two should be aligned because under certain compilers (Windows) the results could be ABI-incompatible. See https://clang.llvm.org/docs/DiagnosticsReference.html#wmismatched-tags

public:
parquet_field_string_list(int f, std::vector<std::string>& v) : parquet_field_list(f, v)
{
auto const read_value = [&val = v](uint32_t i, CompactProtocolReader* cpr) {
Expand Down Expand Up @@ -396,8 +397,9 @@ class parquet_field_binary : public parquet_field {
* @return True if field types mismatch or if the process of reading a
* binary fails
*/
struct parquet_field_binary_list
class parquet_field_binary_list
: public parquet_field_list<std::vector<uint8_t>, FieldType::BINARY> {
public:
parquet_field_binary_list(int f, std::vector<std::vector<uint8_t>>& v) : parquet_field_list(f, v)
{
auto const read_value = [&val = v](uint32_t i, CompactProtocolReader* cpr) {
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/io/parquet/predicate_pushdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class stats_expression_converter : public ast::detail::expression_transformer {
}
}
_stats_expr = std::reference_wrapper<ast::expression const>(_operators.back());
return std::reference_wrapper<ast::expression const>(_operators.back());
return {_operators.back()};
}

/**
Expand Down Expand Up @@ -531,7 +531,7 @@ std::reference_wrapper<ast::expression const> named_to_reference_converter::visi
auto col_index = col_index_it->second;
_col_ref.emplace_back(col_index);
_stats_expr = std::reference_wrapper<ast::expression const>(_col_ref.back());
return std::reference_wrapper<ast::expression const>(_col_ref.back());
return {_col_ref.back()};
}

std::reference_wrapper<ast::expression const> named_to_reference_converter::visit(
Expand All @@ -546,7 +546,7 @@ std::reference_wrapper<ast::expression const> named_to_reference_converter::visi
_operators.emplace_back(op, new_operands.front());
}
_stats_expr = std::reference_wrapper<ast::expression const>(_operators.back());
return std::reference_wrapper<ast::expression const>(_operators.back());
return {_operators.back()};
}

std::vector<std::reference_wrapper<ast::expression const>>
Expand Down
6 changes: 4 additions & 2 deletions cpp/src/io/utilities/data_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class file_sink : public data_sink {
}
}

~file_sink() override { flush(); }
// Marked as NOLINT because we are calling a virtual method in the destructor
~file_sink() override { flush(); } // NOLINT

void host_write(void const* data, size_t size) override
{
Expand Down Expand Up @@ -114,7 +115,8 @@ class host_buffer_sink : public data_sink {
public:
explicit host_buffer_sink(std::vector<char>* buffer) : buffer_(buffer) {}

~host_buffer_sink() override { flush(); }
// Marked as NOLINT because we are calling a virtual method in the destructor
~host_buffer_sink() override { flush(); } // NOLINT

void host_write(void const* data, size_t size) override
{
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/io/utilities/hostdevice_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class hostdevice_span {
template <typename C,
// Only supported containers of types convertible to T
std::enable_if_t<std::is_convertible_v<
std::remove_pointer_t<decltype(std::declval<C&>().host_ptr())> (*)[],
T (*)[]>>* = nullptr>
std::remove_pointer_t<decltype(std::declval<C&>().host_ptr())> (*)[], // NOLINT
T (*)[]>>* = nullptr> // NOLINT
constexpr hostdevice_span(C& in) : hostdevice_span(in.host_ptr(), in.device_ptr(), in.size())
{
}
Expand All @@ -54,8 +54,8 @@ class hostdevice_span {
template <typename C,
// Only supported containers of types convertible to T
std::enable_if_t<std::is_convertible_v<
std::remove_pointer_t<decltype(std::declval<C&>().host_ptr())> (*)[],
T (*)[]>>* = nullptr>
std::remove_pointer_t<decltype(std::declval<C&>().host_ptr())> (*)[], // NOLINT
T (*)[]>>* = nullptr> // NOLINT
constexpr hostdevice_span(C const& in)
: hostdevice_span(in.host_ptr(), in.device_ptr(), in.size())
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/jit/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ std::string ptx_parser::remove_nonalphanumeric(std::string const& src)
auto l = std::find_if(f, out.end(), [](auto c) { return is_white(c) || c == ']'; });
std::replace_if(
f, l, [](auto c) { return !isalnum(c) && c != '_'; }, '_');
return std::string(f, l);
return {f, l};
}

std::string ptx_parser::register_type_to_contraint(std::string const& src)
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/strings/regex/regexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ std::unique_ptr<reprog_device, std::function<void(reprog_device*)>> reprog_devic
delete d_buffer;
};

return std::unique_ptr<reprog_device, std::function<void(reprog_device*)>>(d_prog, deleter);
return {d_prog, deleter};
}

void reprog_device::destroy() { delete this; }
Expand Down
13 changes: 11 additions & 2 deletions cpp/src/utilities/host_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,19 @@ class fixed_pinned_pool_memory_resource {
return !operator==(other);
}

friend void get_property(fixed_pinned_pool_memory_resource const&,
// clang-tidy will complain about this function because it is completely
// unused at runtime and only exist for tag introspection by CCCL, so we
// ignore linting. This masks a real issue if we ever want to compile with
// clang, though, which is that the function will actually be compiled out by
// clang. If cudf were ever to try to support clang as a compile we would
vyasr marked this conversation as resolved.
Show resolved Hide resolved
// need to force the compiler to emit this symbol. The same goes for the
// other get_property definitions in this file.
friend void get_property(fixed_pinned_pool_memory_resource const&, // NOLINT
cuda::mr::device_accessible) noexcept
{
}

friend void get_property(fixed_pinned_pool_memory_resource const&,
friend void get_property(fixed_pinned_pool_memory_resource const&, // NOLINT
cuda::mr::host_accessible) noexcept
{
}
Expand Down Expand Up @@ -235,7 +242,9 @@ class new_delete_memory_resource {

bool operator!=(new_delete_memory_resource const& other) const { return !operator==(other); }

// NOLINTBEGIN
friend void get_property(new_delete_memory_resource const&, cuda::mr::host_accessible) noexcept {}
// NOLINTEND
};

static_assert(cuda::mr::resource_with<new_delete_memory_resource, cuda::mr::host_accessible>,
Expand Down
Loading
Loading