summaryrefslogtreecommitdiffstats
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-10-20 12:48:09 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-10-20 15:39:38 +0200
commit283a9790bffa6536f4c26bd31d85f815bc64dd08 (patch)
treec65ac7fe50fbea809dd765c24edbb47b57adea2b /compilerplugins
parentAzul is just another OpenJDK variant (diff)
downloadcore-283a9790bffa6536f4c26bd31d85f815bc64dd08.tar.gz
core-283a9790bffa6536f4c26bd31d85f815bc64dd08.zip
loplugin:indentation check for indent inside block
look for places where the statements inside a block are not indented Change-Id: I0cbfa7e0b6fb194b2aff6fa7e070fb907d70ca2f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123885 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/indentation.cxx45
-rw-r--r--compilerplugins/clang/test/indentation.cxx10
2 files changed, 41 insertions, 14 deletions
diff --git a/compilerplugins/clang/indentation.cxx b/compilerplugins/clang/indentation.cxx
index 345b33a5bd63..2dda32f8174c 100644
--- a/compilerplugins/clang/indentation.cxx
+++ b/compilerplugins/clang/indentation.cxx
@@ -345,8 +345,8 @@ void Indentation::checkCompoundStmtBraces(const Stmt* parentStmt, const Compound
if (invalid1)
return;
- auto startBraceLoc = compat::getBeginLoc(compoundStmt);
- auto endBraceLoc = compat::getEndLoc(compoundStmt);
+ auto startBraceLoc = compoundStmt->getLBracLoc();
+ auto endBraceLoc = compoundStmt->getRBracLoc();
unsigned beginColumn = SM.getPresumedColumnNumber(startBraceLoc, &invalid1);
unsigned beginLine = SM.getPresumedLineNumber(startBraceLoc, &invalid2);
if (invalid1 || invalid2)
@@ -384,21 +384,38 @@ void Indentation::checkCompoundStmtBraces(const Stmt* parentStmt, const Compound
endBraceLoc);
report(DiagnosticsEngine::Note, "statement beginning here", parentBeginLoc);
}
+ return;
}
- else
+
+ if (parentColumn != beginColumn)
{
- if (parentColumn != beginColumn)
- {
- report(DiagnosticsEngine::Warning,
- "start brace not aligned with beginning of parent statement", startBraceLoc);
- report(DiagnosticsEngine::Note, "statement beginning here", parentBeginLoc);
- }
- else if (beginColumn != endColumn)
- {
- report(DiagnosticsEngine::Warning, "start and end brace not aligned", endBraceLoc);
- report(DiagnosticsEngine::Note, "start brace here", startBraceLoc);
- }
+ report(DiagnosticsEngine::Warning,
+ "start brace not aligned with beginning of parent statement", startBraceLoc);
+ report(DiagnosticsEngine::Note, "statement beginning here", parentBeginLoc);
+ }
+ else if (beginColumn != endColumn)
+ {
+ report(DiagnosticsEngine::Warning, "start and end brace not aligned", endBraceLoc);
+ report(DiagnosticsEngine::Note, "start brace here", startBraceLoc);
}
+
+ /** now check that lines inside the compoundstmt are indented */
+ if (!compoundStmt->size())
+ return;
+ auto firstStmt = compoundStmt->body_front();
+ if (isa<LabelStmt>(firstStmt))
+ return;
+ auto firstStmtLoc = compat::getBeginLoc(firstStmt);
+ unsigned firstStmtBeginColumn = SM.getPresumedColumnNumber(firstStmtLoc, &invalid1);
+ if (invalid1)
+ return;
+ if (firstStmtBeginColumn > beginColumn)
+ return;
+ StringRef fn = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(firstStmtLoc));
+ // this is doing code generation, so the weird layout is deliberate
+ if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/core/opencl/"))
+ return;
+ report(DiagnosticsEngine::Warning, "body inside brace not indented", firstStmtLoc);
}
bool Indentation::VisitSwitchStmt(SwitchStmt const* switchStmt)
diff --git a/compilerplugins/clang/test/indentation.cxx b/compilerplugins/clang/test/indentation.cxx
index 8ef6d2c03653..71b8c6f61e5a 100644
--- a/compilerplugins/clang/test/indentation.cxx
+++ b/compilerplugins/clang/test/indentation.cxx
@@ -101,4 +101,14 @@ void attr_bad() {
}
#endif
+void xxx();
+void test5(bool x)
+{
+ if (x)
+ {
+ xxx(); // expected-error {{body inside brace not indented [loplugin:indentation]}}
+ }
+}
+
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */