This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add bugprone-allocation-bool-conversion
Needs ReviewPublic

Authored by PiotrZSL on Aug 5 2023, 2:42 AM.

Details

Summary

Detects cases where the result of a resource allocation is used as a bool.

Fixes: #64461

Diff Detail

Event Timeline

PiotrZSL created this revision.Aug 5 2023, 2:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2023, 2:42 AM
Herald added a subscriber: xazax.hun. · View Herald Transcript
PiotrZSL requested review of this revision.Aug 5 2023, 2:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2023, 2:42 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Shouldn't C-style allocation be checked too? Same for custom allocators via configuration option.

Same for file, threads and other resources allocation.

Shouldn't C-style allocation be checked too? Same for custom allocators via configuration option.

In theory it could, but in such case name of check would need to change...

Shouldn't C-style allocation be checked too? Same for custom allocators via configuration option.

In theory it could, but in such case name of check would need to change...

Something like bugprone-resource-bool-conversion should be generic enough.

Shouldn't C-style allocation be checked too? Same for custom allocators via configuration option.

In theory it could, but in such case name of check would need to change...

Something like bugprone-resource-bool-conversion should be generic enough.

Maybe bugprone-allocation-bool-conversion?

PiotrZSL updated this revision to Diff 547523.Aug 5 2023, 11:46 PM
PiotrZSL retitled this revision from [clang-tidy] Add bugprone-new-bool-conversion to [clang-tidy] Add bugprone-allocation-bool-conversion.
PiotrZSL edited the summary of this revision. (Show Details)

Change check anme, add configuration option.

Eugene.Zelenko added inline comments.Aug 6 2023, 7:48 AM
clang-tools-extra/clang-tidy/bugprone/AllocationBoolConversionCheck.cpp
25 ↗(On Diff #547523)

POSIX open, openat, creat, pthread_create should be added too.

60 ↗(On Diff #547523)

Should be merged together.

PiotrZSL updated this revision to Diff 547587.Aug 6 2023, 8:06 AM
PiotrZSL marked an inline comment as done.

Formating + fix tests

clang-tools-extra/clang-tidy/bugprone/AllocationBoolConversionCheck.cpp
25 ↗(On Diff #547523)

Those return integers, not pointers. Check is for pointers only, but probably could be extended to integers if we go into this direction.

PiotrZSL planned changes to this revision.Aug 6 2023, 11:08 AM

TODO: Fix CI, Add support for allocators that return 'integer', hardcode most of functions, change config into AdditionalAllocationFunctions

PiotrZSL updated this revision to Diff 548554.Aug 9 2023, 3:52 AM
PiotrZSL marked an inline comment as done.

Rebase, add support for integer returnign functions, fixes in tests.