summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-04-29 11:08:37 +0200
committerStephan Bergmann <sbergman@redhat.com>2022-04-29 13:09:40 +0200
commit5b6bc8182bc1586facca5c3a019c9985e0d7b411 (patch)
treee6e9ec335ce052dc31976a2d48fdf2e5bb4ef251 /compilerplugins
parent779c01a9e1eb3ed176d57e1e04073e25aca34a64 (diff)
Use the false warning suppression mechanism for loplugin:fakebool
Change-Id: I6572e500edc1be845c28389b0a4d3ca258dbbecb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133593 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/fakebool.cxx57
1 files changed, 8 insertions, 49 deletions
diff --git a/compilerplugins/clang/fakebool.cxx b/compilerplugins/clang/fakebool.cxx
index 3d5120153d0b..80efa55bd432 100644
--- a/compilerplugins/clang/fakebool.cxx
+++ b/compilerplugins/clang/fakebool.cxx
@@ -213,8 +213,6 @@ public:
bool VisitValueDecl(ValueDecl const * decl);
- bool TraverseStaticAssertDecl(StaticAssertDecl * decl);
-
bool TraverseLinkageSpecDecl(LinkageSpecDecl * decl);
private:
@@ -222,8 +220,6 @@ private:
bool isSharedCAndCppCode(SourceLocation location) const;
- bool isInSpecialMainFile(SourceLocation spellingLocation) const;
-
bool rewrite(SourceLocation location, FakeBoolKind kind);
std::map<VarDecl const *, FakeBoolKind> varDecls_;
@@ -270,7 +266,7 @@ void FakeBool::run() {
}
}
}
- if (!rewrite(loc, fbk)) {
+ if (!(suppressWarningAt(loc) || rewrite(loc, fbk))) {
report(
DiagnosticsEngine::Warning,
"VarDecl, use \"bool\" instead of %0", loc)
@@ -312,7 +308,7 @@ void FakeBool::run() {
}
}
}
- if (!rewrite(loc, fbk)) {
+ if (!(suppressWarningAt(loc) || rewrite(loc, fbk))) {
report(
DiagnosticsEngine::Warning,
"FieldDecl, use \"bool\" instead of %0", loc)
@@ -561,6 +557,9 @@ bool FakeBool::VisitCStyleCastExpr(CStyleCastExpr * expr) {
// arguments to CPPUNIT_ASSERT_EQUAL:
return true;
}
+ if (suppressWarningAt(callLoc)) {
+ return true;
+ }
bool b = k == FBK_sal_Bool && name == "sal_True";
if (rewriter != nullptr) {
auto callSpellLoc = compiler.getSourceManager()
@@ -603,14 +602,10 @@ bool FakeBool::VisitCXXStaticCastExpr(CXXStaticCastExpr * expr) {
if (ignoreLocation(expr)) {
return true;
}
- auto const k = isFakeBool(expr->getType());
- if (k == FBK_No) {
+ if (isFakeBool(expr->getType()) == FBK_No) {
return true;
}
- if (k == FBK_sal_Bool
- && isInSpecialMainFile(
- compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc())))
- {
+ if (suppressWarningAt(expr->getBeginLoc())) {
return true;
}
report(
@@ -777,14 +772,7 @@ bool FakeBool::VisitVarDecl(VarDecl const * decl) {
if (k == FBK_No) {
return true;
}
- auto const loc = decl->getBeginLoc();
- if (k == FBK_sal_Bool
- && isInSpecialMainFile(
- compiler.getSourceManager().getSpellingLoc(loc)))
- {
- return true;
- }
- auto l = loc;
+ auto l = decl->getBeginLoc();
while (compiler.getSourceManager().isMacroArgExpansion(l)) {
l = compiler.getSourceManager().getImmediateMacroCallerLoc(l);
}
@@ -815,12 +803,6 @@ bool FakeBool::VisitFieldDecl(FieldDecl const * decl) {
if (!handler.isAllRelevantCodeDefined(decl)) {
return true;
}
- if (k == FBK_sal_Bool
- && isInSpecialMainFile(
- compiler.getSourceManager().getSpellingLoc(decl->getBeginLoc())))
- {
- return true;
- }
TagDecl const * td = dyn_cast<TagDecl>(decl->getDeclContext());
if (td == nullptr) {
//TODO: ObjCInterface
@@ -877,19 +859,6 @@ bool FakeBool::VisitValueDecl(ValueDecl const * decl) {
return true;
}
-bool FakeBool::TraverseStaticAssertDecl(StaticAssertDecl * decl) {
- // Ignore special code like
- //
- // static_cast<sal_Bool>(true) == sal_True
- //
- // inside static_assert in cppu/source/uno/check.cxx:
- return
- loplugin::isSamePathname(
- getFilenameOfLocation(decl->getLocation()),
- SRCDIR "/cppu/source/uno/check.cxx")
- || RecursiveASTVisitor::TraverseStaticAssertDecl(decl);
-}
-
bool FakeBool::TraverseLinkageSpecDecl(LinkageSpecDecl * decl) {
assert(externCContexts_ != std::numeric_limits<unsigned int>::max()); //TODO
++externCContexts_;
@@ -917,16 +886,6 @@ bool FakeBool::isSharedCAndCppCode(SourceLocation location) const {
|| compiler.getSourceManager().isMacroBodyExpansion(location));
}
-bool FakeBool::isInSpecialMainFile(SourceLocation spellingLocation) const {
- if (!compiler.getSourceManager().isInMainFile(spellingLocation)) {
- return false;
- }
- auto f = getFilenameOfLocation(spellingLocation);
- return loplugin::isSamePathname(f, SRCDIR "/cppu/qa/test_any.cxx")
- || loplugin::isSamePathname(f, SRCDIR "/cppu/source/uno/check.cxx");
- // TODO: the offset checks
-}
-
bool FakeBool::rewrite(SourceLocation location, FakeBoolKind kind) {
if (rewriter != nullptr) {
//TODO: "::sal_Bool" -> "bool", not "::bool"