This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix bugprone-assert-side-effect to actually give warnings
ClosedPublic

Authored by carlosgalvezp on May 7 2023, 10:12 AM.

Details

Summary

Some time ago a patch was merged to disable all clang-tidy warnings
from system macros. This led to bugprone-assert-side-effect
silently no longer working, since the warnings came from a system
macro. The problem was not detected because the fake assert functions
were implemented in the same file as the test, instead of being a
system include like it's done in the real world.

Move the assert to a proper system header, and fix the code to
warn at the correct location.

This patch is breakdown from https://reviews.llvm.org/D147081
by PiotrZSL.

Fixes https://github.com/llvm/llvm-project/issues/62314

Diff Detail

Event Timeline

carlosgalvezp created this revision.May 7 2023, 10:12 AM
Herald added a project: Restricted Project. · View Herald Transcript
carlosgalvezp requested review of this revision.May 7 2023, 10:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2023, 10:12 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gribozavr2 accepted this revision.May 8 2023, 9:44 AM
gribozavr2 added a subscriber: gribozavr2.
gribozavr2 added inline comments.
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h
2

There should be no need to define the function (the real header wouldn't either).

clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
1–2

Perhaps a more reliable (or a "belt and suspenders") way would be to add the following pragma to the header:

#pragma clang system_header

This way I believe it would not matter whether the header is found through -isystem or not.

This revision is now accepted and ready to land.May 8 2023, 9:44 AM
This revision was automatically updated to reflect the committed changes.
carlosgalvezp marked 2 inline comments as done.

Thanks for the review! Fixed your comments before landing.