enhance pass-by-ref plugin to detect large arguments

Detect arguments larger than 64 chars passed by value.

Change-Id: I9b0ea9ccb99d115984a26eab67c9cf6afd5f6cae
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Noel Grandin
2014-05-19 10:02:29 +02:00
committed by Stephan Bergmann
parent e4740dbecf
commit 8d54796bf1
75 changed files with 137 additions and 129 deletions

View File

@@ -8,6 +8,7 @@
*/
#include <string>
#include <set>
#include "plugin.hxx"
@@ -46,27 +47,32 @@ bool PassStuffByRef::VisitFunctionDecl(const FunctionDecl * functionDecl) {
continue;
}
string typeName = t1.getUnqualifiedType().getCanonicalType().getAsString();
if (typeName == "class rtl::OUString") {
bool bFound = false;
if (typeName == "class rtl::OUString" ||
typeName == "class rtl::OString" ||
typeName.find("class com::sun::star::uno::Sequence") == 0) {
bFound = true;
}
if (!bFound && !t1->isIncompleteType()) {
const clang::Type* type = t1.getTypePtrOrNull();
if (type != nullptr) {
clang::CharUnits size = compiler.getASTContext().getTypeSizeInChars(type);
if (size.getQuantity() > 64) {
bFound = true;
}
}
}
if (bFound) {
report(
DiagnosticsEngine::Warning,
"passing OUString by value, rather pass by reference .e.g. 'const OUString&'",
pvDecl->getSourceRange().getBegin())
<< pvDecl->getSourceRange();
}
else if (typeName == "class rtl::OString") {
report(
DiagnosticsEngine::Warning,
"passing OString by value, rather pass by reference .e.g. 'const OString&'",
pvDecl->getSourceRange().getBegin())
<< pvDecl->getSourceRange();
}
else if (typeName.find("class com::sun::star::uno::Sequence") == 0) {
report(
DiagnosticsEngine::Warning,
"passing css::uno::Sequence by value, rather pass by reference .e.g. 'const css::uno::Sequence&' " + typeName,
"passing " + typeName + " by value, rather pass by reference .e.g. 'const " + typeName + "&'",
pvDecl->getSourceRange().getBegin())
<< pvDecl->getSourceRange();
}
}
return true;
}