summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/store/constantfunction.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/store/constantfunction.cxx')
-rw-r--r--compilerplugins/clang/store/constantfunction.cxx87
1 files changed, 46 insertions, 41 deletions
diff --git a/compilerplugins/clang/store/constantfunction.cxx b/compilerplugins/clang/store/constantfunction.cxx
index fd429ac686fc..943cc7d87606 100644
--- a/compilerplugins/clang/store/constantfunction.cxx
+++ b/compilerplugins/clang/store/constantfunction.cxx
@@ -21,50 +21,20 @@ namespace {
class ConstantFunction:
public RecursiveASTVisitor<ConstantFunction>, public loplugin::Plugin
{
- StringRef getFilename(SourceLocation loc);
+ StringRef getFilename(const FunctionDecl* functionDecl);
public:
explicit ConstantFunction(InstantiationData const & data): Plugin(data) {}
void run() override
{
// these files crash clang-3.5 somewhere in the isEvaluatable/EvaluateAsXXX stuff
- FileID mainFileID = compiler.getSourceManager().getMainFileID();
- if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getDir()->getName(), "sc/source/core/data") != 0) {
- return;
- }
- if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getDir()->getName(), "sc/source/ui/app") != 0) {
- return;
- }
- if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getDir()->getName(), "sc/qa/unit") != 0) {
- return;
- }
- if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getName(), "docuno.cxx") != 0) {
- return;
- }
- if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getName(), "viewdata.cxx") != 0) {
- return;
- }
- if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getName(), "calcoptionsdlg.cxx") != 0) {
- return;
- }
- if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getDir()->getName(), "sc/source/core/opencl") != 0) {
- return;
- }
- if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getDir()->getName(), "sc/source/core/tool") != 0) {
- return;
- }
- if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getDir()->getName(), "sc/source/core/tool") != 0) {
- return;
- }
- if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getDir()->getName(), "desktop/source/lib") != 0) {
- return;
- }
+/* FileID mainFileID = compiler.getSourceManager().getMainFileID();
if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getName(), "bootstrapfixture.cxx") != 0) {
return;
}
if (strstr(compiler.getSourceManager().getFileEntryForID(mainFileID)->getName(), "gtk3gtkinst.cxx") != 0) {
return;
- }
+ }*/
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
@@ -72,9 +42,9 @@ public:
bool VisitFunctionDecl(const FunctionDecl *);
};
-StringRef ConstantFunction::getFilename(SourceLocation loc)
+StringRef ConstantFunction::getFilename(const FunctionDecl* functionDecl)
{
- SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(loc);
+ SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(functionDecl->getCanonicalDecl()->getNameInfo().getLoc());
StringRef name { compiler.getSourceManager().getFilename(spellingLocation) };
return name;
}
@@ -90,12 +60,15 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) {
if (!pFunctionDecl->hasBody()) {
return true;
}
+ if (!pFunctionDecl->isThisDeclarationADefinition()) {
+ return true;
+ }
// stuff declared extern-C is almost always used as a some kind of callback
if (pFunctionDecl->isExternC()) {
return true;
}
- StringRef aFileName = getFilename(pFunctionDecl->getLocStart());
+ StringRef aFileName = getFilename(pFunctionDecl);
// various tests in here are empty stubs under Linux
if (aFileName.startswith(SRCDIR "/sal/qa/")) {
@@ -128,7 +101,7 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) {
return true;
}
// salplug runtime-loading mechanism at work
- if (getFilename(pFunctionDecl->getCanonicalDecl()->getLocStart()) == SRCDIR "/vcl/inc/salinst.hxx") {
+ if (aFileName == SRCDIR "/vcl/inc/salinst.hxx") {
return true;
}
// lots of callbacks here
@@ -144,7 +117,7 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) {
return true;
}
// used by code generated by python
- if (getFilename(pFunctionDecl->getCanonicalDecl()->getLocStart()) == SRCDIR "/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx") {
+ if (aFileName == SRCDIR "/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx") {
return true;
}
// this test just test the include of some headers
@@ -178,7 +151,7 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) {
if (isa<CXXConstructorDecl>(pFunctionDecl) || isa<CXXDestructorDecl>(pFunctionDecl) || isa<CXXConversionDecl>(pFunctionDecl)) {
return true;
}
- SourceLocation canonicalLoc = pFunctionDecl->getCanonicalDecl()->getLocStart();
+ SourceLocation canonicalLoc = pFunctionDecl->getCanonicalDecl()->getNameInfo().getLoc();
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(canonicalLoc))) {
return true;
}
@@ -433,6 +406,28 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) {
if (aFunctionName == "clipboard_owner_init") {
return true;
}
+ // returns sizeof(struct) vcl/source/gdi/dibtools.cxx
+ if (aFunctionName == "getDIBV5HeaderSize") {
+ return true;
+ }
+ // windows only
+ if (aFunctionName == "InitAccessBridge") {
+ return true;
+ }
+ // callbacks
+ if (aFunctionName == "disabled_initSystray" || aFunctionName == "disabled_deInitSystray") {
+ return true;
+ }
+ // behind a BREAKPAD option
+ if (aFunctionName == "desktop::(anonymous namespace)::crashReportInfoExists") {
+ return true;
+ }
+ // LOK stuff
+ if (aFunctionName == "doc_getTileMode") {
+ return true;
+ }
+
+
std::string aImmediateMacro = "";
if (compiler.getSourceManager().isMacroBodyExpansion(pFunctionDecl->getLocStart()) ) {
@@ -456,6 +451,11 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) {
if (!pReturnStmt) {
return true;
}
+ if (const UnaryOperator* unaryOp = dyn_cast<UnaryOperator>(pReturnStmt->getRetValue())) {
+ if (unaryOp->getOpcode() == UO_AddrOf) {
+ return true;
+ }
+ }
if (pReturnStmt->getRetValue() != nullptr) {
// && !pReturnStmt->getRetValue()->isEvaluatable(compiler.getASTContext())) {
bool aBoolResult;
@@ -484,8 +484,13 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) {
DiagnosticsEngine::Warning,
aMessage,
pFunctionDecl->getLocStart())
- << pFunctionDecl->getSourceRange()
- << pFunctionDecl->getCanonicalDecl()->getSourceRange();
+ << pFunctionDecl->getSourceRange();
+ if (pFunctionDecl != pFunctionDecl->getCanonicalDecl())
+ report(
+ DiagnosticsEngine::Note,
+ aMessage,
+ pFunctionDecl->getCanonicalDecl()->getLocStart())
+ << pFunctionDecl->getCanonicalDecl()->getSourceRange();
return true;
}