This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy][NFC] Split bugprone-exception-escape tests
ClosedPublic

Authored by PiotrZSL on Apr 16 2023, 3:14 AM.

Details

Summary

Split tests files into noexcept and throw().
This is preparation for a C++20 support in this check.

Diff Detail

Event Timeline

PiotrZSL created this revision.Apr 16 2023, 3:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 16 2023, 3:14 AM
PiotrZSL requested review of this revision.Apr 16 2023, 3:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 16 2023, 3:14 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
carlosgalvezp added inline comments.Apr 16 2023, 5:33 AM
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
267

I run into this often as well. If you don't want to get push back during review because of this I advice you to disable the automatic trailing whitespace removal for this project. Regular source code will be fixed via clang-format anyway. Alternatively you will be asked to fix it in (another) NFC patch :)

I personally don't mind a couple or two such fixes, but here there's a lot of them and really create noise, distracting from the actual patch.

555–558

Why this change?

PiotrZSL added inline comments.Apr 16 2023, 5:45 AM
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
267

Excuses...

555–558

this test file tests only noexcept, not throw.
i added throw 1 just so check would still see as an throw of integer type.

carlosgalvezp added inline comments.Apr 23 2023, 2:54 AM
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-throw.cpp
5

Please align comments

12

Please use 2 chars indentation. This can be configured in the IDE.

clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
267

Excuses for what?

555–558

Ack.

PiotrZSL updated this revision to Diff 516139.Apr 23 2023, 3:04 AM
PiotrZSL marked 2 inline comments as done.

Formating fixes

clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-throw.cpp
5

it is align, comment is for function, not for throw.

PiotrZSL updated this revision to Diff 516481.Apr 24 2023, 11:48 AM
PiotrZSL marked an inline comment as done.

Rebase

PiotrZSL marked an inline comment as done.Apr 24 2023, 11:50 AM
PiotrZSL marked an inline comment as done.
This comment was removed by isuckatcs.
isuckatcs added a comment.EditedApr 30 2023, 2:42 PM

Do we really want to split these two functions apart to different test files? Is this really NFC?

The way ExceptionEscapeCheck works is that it creates an ExceptionAnalyzer upon instantiation.

By the way upon looking at the constructor of the check I see that std::bad_alloc is always ignored.
Maybe we want to turn this into an option, so that users can enable it if they want.

ExceptionAnalyzer caches functions based on their FunctionDecl * in
std::map<const FunctionDecl *, ExceptionInfo> FunctionCache;.

The FunctionDecl lives in the AST of the translation unit, so the same function declaration in two
different translation units will have different FunctionDecl *s. Maybe ODRHash would be more
suitable to be used as key in the map.

By moving throwing functions into a different TU than non-throwing functions, I think the correctness
of the caching inside ExceptionAnalyzer no longer will be tested properly. Maybe this is something
we want to preserve.

PiotrZSL added a comment.EditedMay 1 2023, 4:44 AM

Do we really want to split these two functions apart to different test files? Is this really NFC?

Yes, throw specifier is removed in C++17, split allows to support C++17 and above in main test file

The way ExceptionEscapeCheck works is that it creates an ExceptionAnalyzer upon instantiation.

And ? This has nothing to do with test split.

By the way upon looking at the constructor of the check I see that std::bad_alloc is always ignored.
Maybe we want to turn this into an option, so that users can enable it if they want.

Not a scope of this change, please raise an issue on github if you want such feature, or implement it your self. I personally don't see an use-case for it.

ExceptionAnalyzer caches functions based on their FunctionDecl * in
std::map<const FunctionDecl *, ExceptionInfo> FunctionCache;.

The FunctionDecl lives in the AST of the translation unit, so the same function declaration in two
different translation units will have different FunctionDecl *s. Maybe ODRHash would be more
suitable to be used as key in the map.

By moving throwing functions into a different TU than non-throwing functions, I think the correctness
of the caching inside ExceptionAnalyzer no longer will be tested properly. Maybe this is something
we want to preserve.

Those tests never tested caching (not failing if you disable cache), and here cache will be executed on things
like recursion_helper anyway. I see no issue here.

Yes, throw specifier is removed in C++17, split allows to support C++17 and above in main test file

A lot of our test files uses macros to differentiate between specific C++ standards, why not do that here too?
There are only a few occurences of functions with throw().

#if __cplusplus  < 201703L
      // put functions with throw() here
#endif

Those tests never tested caching (not failing if you disable cache)

They weren't tested explicitly, but it still happened in the background by default.

@isuckatcs
Ifdefs are ugly, to avoid messing with multiple runs in same unit test, I decided to split into 2 test files (C++11 and above, and C++11,C++14).

And to be honest this change does nothing for caching (zero impact), let me explain:
super_throws_again alone won't be tested, because its not noexcept, it will be tested only once (no cache hit) when testing sub_throws_again.
Same goes for throwing_throw_nothing, its not called from anywhere, so there will be no hit into cache.

Simply code that were moved into new file didn't utilize cache before and now.

carlosgalvezp accepted this revision.May 7 2023, 9:46 AM

LGTM!

A lot of our test files uses macros to differentiate between specific C++ standards, why not do that here too?

It's not that easy, because the #ifdef lines do not remove the // CHECK comments, so to work around that it gets messy very easily. Splitting into 2 files seems to be common practice in other tests for easier maintenance and readability.

This revision is now accepted and ready to land.May 7 2023, 9:46 AM
This revision was automatically updated to reflect the committed changes.