Skip to content

Some clang-tidy fixes - #72869

Merged
rschu1ze merged 3 commits into
ClickHouse:masterfrom
rschu1ze:tidy
Dec 12, 2024
Merged

rschu1ze merged 3 commits into
ClickHouse:masterfrom
rschu1ze:tidy

Conversation

@rschu1ze

@rschu1ze rschu1ze commented Dec 6, 2024 •

Copy link
Copy Markdown
Member

This PR enables a few clang-tidy checks, most notably:

  • modernize-macro-to-enum prohibits defining magic constants as macros (#define X 123): this increases type safety by a little bit
  • readability-isolate-declaration: which forces one declaration per line, e.g. int x, y = 0 is now disallowed (<-- and this example also shows the motivation for the check). All changed places in the code were okay, so the check effectively only makes the code a bit more "regular".
  • modernize-use-constraints: which suggests C++20 concepts instead of std::enable_if. Don't know why exactly but the check did not complain about the (few) enable_ifs in the codebase. It makes sense to have the check enabled regardless.
  • misc-confusable-identifiers: Complained only once about a template parameter In (which can be confused with ln, lol). Like before, it generally makes sense to have this check enabled.
  • a check about missing handling of self-assignment in operator= (one of the cert-* checks, don't remember which exactly). That's a potential performance issue (at least on a micro-benchmark level). Found a few places.

Besides that, I enabled a few checks clang-analyzer-cplusplus.PlacementNew', clang-analyzer-unix.Malloc, linuxkernel-*, openmp-* not because they are particularly useful or even apply to our codebase (Linux, OpenMP) but because they didn't find anything and for reducing the number of disabled checks in .clang-tidy.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-not-for-changelog This PR should not be mentioned in the changelog label Dec 6, 2024
@robot-clickhouse-ci-1

robot-clickhouse-ci-1 commented Dec 6, 2024 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit e8018fb with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help❌ failure
Successful checks
Check nameDescriptionStatus
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@rschu1ze
rschu1ze force-pushed the tidy branch 3 times, most recently from ec1b018 to 9133f43 Compare December 9, 2024 21:32
@robot-ch-test-poll2 robot-ch-test-poll2 added the submodule changed At least one submodule changed in this PR. label Dec 11, 2024
@rschu1ze
rschu1ze marked this pull request as ready for review December 11, 2024 19:22
@alexkats alexkats self-assigned this Dec 11, 2024
Comment thread src/Common/DateLUTImpl.h
Comment on lines +12 to 15
/// NOLINTBEGIN(modernize-macro-to-enum)
#define DATE_SECONDS_PER_DAY 86400 /// Number of seconds in a day, 60 * 60 * 24

#define DATE_LUT_MIN_YEAR 1900 /// 1900 since majority of financial organizations consider 1900 as an initial year.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, what's the issue with changing these to constexpr as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this case (and it is an exception in the codebase), it was mere laziness from my side. These constants are used in many places and one needs to find an appropriate data type. I'd be good with keeping it for now like this or fixing it in a follow-up (the PR is already quite big).

Comment on lines +12 to +19
/// NOLINTBEGIN(modernize-macro-to-enum)
#define MYSQLXX_DEFAULT_TIMEOUT 60
#define MYSQLXX_DEFAULT_RW_TIMEOUT 1800

/// Disable LOAD DATA LOCAL INFILE because it is insecure
#define MYSQLXX_DEFAULT_ENABLE_LOCAL_INFILE false
/// See https://dev.mysql.com/doc/c-api/5.7/en/c-api-auto-reconnect.html
/// NOLINTEND(modernize-macro-to-enum)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, what's the issue with changing these to constexpr as well here and in other mysqlxx files?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The MySQL stuff looks like copypasta of external code. We better don't mess with the code too much to make future upgrades easier.

#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
// NOLINTBEGIN(google-runtime-int,hicpp-use-nullptr,modernize-use-nullptr)
// NOLINTBEGIN(google-runtime-int,hicpp-use-nullptr,modernize-use-nullptr,modernize-macro-to-enum)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess, we should add this to HTMLCharacterReference.gperf and regenerate, otherwise it would be overwritten after the next regeneration

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agree. But could I do this in the follow-up PR that also fixes DateLUTImpl.h?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, sounds good to me

Comment on lines +29 to +30
/// NOLINTBEGIN(modernize-macro-to-enum)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess, we should add this to tldLookup.gperf and regenerate, otherwise it would be overwritten after the next regeneration

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yepp! --> Follow-up?

@rschu1ze
rschu1ze added this pull request to the merge queue Dec 12, 2024
Merged via the queue into ClickHouse:master with commit eaed771 Dec 12, 2024
@rschu1ze
rschu1ze deleted the tidy branch December 12, 2024 14:52
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Dec 12, 2024
This was referenced Dec 12, 2024
github-merge-queue Bot pushed a commit that referenced this pull request Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants