summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2014-05-19 10:02:29 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-05-20 11:17:22 +0200
commit8d54796bf152499ecbe61788be64c9035f725dfa (patch)
tree9516219cf8e60bdd46597e522ca4e9fde9b8f407 /compilerplugins
parente4740dbecfce958c2c707d8cc92e6dbe52f4b71b (diff)
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>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/passstuffbyref.cxx34
1 files changed, 20 insertions, 14 deletions
diff --git a/compilerplugins/clang/passstuffbyref.cxx b/compilerplugins/clang/passstuffbyref.cxx
index c4951e82ca7c..7ad891728238 100644
--- a/compilerplugins/clang/passstuffbyref.cxx
+++ b/compilerplugins/clang/passstuffbyref.cxx
@@ -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") {
- report(
- DiagnosticsEngine::Warning,
- "passing OUString by value, rather pass by reference .e.g. 'const OUString&'",
- pvDecl->getSourceRange().getBegin())
- << pvDecl->getSourceRange();
+
+ bool bFound = false;
+ if (typeName == "class rtl::OUString" ||
+ typeName == "class rtl::OString" ||
+ typeName.find("class com::sun::star::uno::Sequence") == 0) {
+ bFound = true;
}
- 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();
+
+ 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;
+ }
+ }
}
- else if (typeName.find("class com::sun::star::uno::Sequence") == 0) {
+
+ if (bFound) {
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;
}