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

Update files and clang-tidy config to pass with clang-tidy-20 #4691

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Dec 16, 2024

Disables three new warnings because they lean more towards style conflicts than fixes. I've brought these up on #style.

Other than that, mostly fixing basic issues, and things that clang-tidy-20 seems to fire where clang-tiday-16 didn't. One particular curious case is llvm::StringLiteral::data() uses, which are flagged as not strictly null-terminated; I'm switching to const char* in those spots which matches llvm::formatv's format argument, but feels worse.

I'm removing run_clang_tidy.py here because I'm observing it give fewer warnings than bazel build --config=clang-tidy -k //toolchain/.... The latter matches how we enforce in GitHub actions (and also caches results, and suppresses output for files that have no issues), so I'm dropping the bespoke script.

@jonmeow
Copy link
Contributor Author

jonmeow commented Dec 16, 2024

Based on #4691 to get a better delta for .clang-tidy

Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

Most of these look good, a few things that might be worth suppressing (comments in line).

@@ -294,7 +295,7 @@ auto FileTestAutoupdater::StartSplitFile() -> void {
AddCheckLines(stdout_, /*to_file_end=*/false);
}

++non_check_line_;
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't really seem like an improvement to me... Could we disable this one too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be sure you have context, this is bugprone-pointer-arithmetic-on-polymorphic-object. I'm hesitant to disable the bugprone warning due to what it's looking for, are you sure we don't want it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought of a better fix here, with final

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see. It's about the polymorphic class!

Yeah, I think final is better here. I think std::advance would be just as bug prone as the ++. But the final is a pretty nice improvement.

ASSERT_FALSE(simd_buffer.has_errors());
EXPECT_THAT(simd_buffer.comments_size(), Eq(1));
}
}

TEST_F(LexerTest, MultipleComments) {
constexpr llvm::StringLiteral Format = R"(
Copy link
Contributor

Choose a reason for hiding this comment

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

Specifically for StringLiteral, I think we should fix it to have a c_str() method. Would it make sense to disable the tidy until that lands in LLVM and we pull it back in?

I agree with you that this seems like a net negative change.

Copy link
Contributor Author

@jonmeow jonmeow Dec 17, 2024

Choose a reason for hiding this comment

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

To be sure, I was mainly trying to clarify the edits -- I think it's probably worth keeping on. In particular, the warning in testing/file_test/file_test_base.cpp seems like an improvement, and this spot seems more neutral to me. (the closest negative for me was in kind_pattern, since its use is distant from the forward declaration)

Noting the uncertainty of future changes to upstream, how about a TODO to switch instead of disabling? TBH I'd actually prefer for formatv to take llvm::StringLiteral, over .c_str

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, makes sense!

Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

LG, thanks!

@@ -294,7 +295,7 @@ auto FileTestAutoupdater::StartSplitFile() -> void {
AddCheckLines(stdout_, /*to_file_end=*/false);
}

++non_check_line_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see. It's about the polymorphic class!

Yeah, I think final is better here. I think std::advance would be just as bug prone as the ++. But the final is a pretty nice improvement.

ASSERT_FALSE(simd_buffer.has_errors());
EXPECT_THAT(simd_buffer.comments_size(), Eq(1));
}
}

TEST_F(LexerTest, MultipleComments) {
constexpr llvm::StringLiteral Format = R"(
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, makes sense!

@chandlerc chandlerc added this pull request to the merge queue Dec 17, 2024
Merged via the queue into carbon-language:trunk with commit c832d52 Dec 17, 2024
8 checks passed
@jonmeow jonmeow deleted the llvm-20-tidy branch December 17, 2024 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants