summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-07-11 16:32:28 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-07-11 16:32:28 +0200
commit6f8d047519c8e80371a646ce4bad8f7304aab6ea (patch)
treef79b5a6cae706b3d4422a02bd109824eb8a2eeaa
parenttdf#97195 fix crash in diamond shape transition (diff)
downloadcore-6f8d047519c8e80371a646ce4bad8f7304aab6ea.tar.gz
core-6f8d047519c8e80371a646ce4bad8f7304aab6ea.zip
loplugin:salbool: Better heuristic to determine code shared between C and C++
Change-Id: I09c9c57d5adeb665cc2508fad9727085a3289bfb
-rw-r--r--compilerplugins/clang/salbool.cxx40
-rw-r--r--framework/inc/properties.h2
-rw-r--r--framework/inc/protocols.h4
-rw-r--r--include/cppuhelper/interfacecontainer.h4
-rw-r--r--sal/qa/osl/security/osl_Security_Const.h2
5 files changed, 39 insertions, 13 deletions
diff --git a/compilerplugins/clang/salbool.cxx b/compilerplugins/clang/salbool.cxx
index 4b123c77b020..e5e9754d7961 100644
--- a/compilerplugins/clang/salbool.cxx
+++ b/compilerplugins/clang/salbool.cxx
@@ -9,6 +9,7 @@
#include <algorithm>
#include <cassert>
+#include <limits>
#include <set>
#include <string>
@@ -144,14 +145,19 @@ public:
bool TraverseStaticAssertDecl(StaticAssertDecl * decl);
+ bool TraverseLinkageSpecDecl(LinkageSpecDecl * decl);
+
private:
bool isFromCIncludeFile(SourceLocation spellingLocation) const;
+ bool isSharedCAndCppCode(SourceLocation location) const;
+
bool isInSpecialMainFile(SourceLocation spellingLocation) const;
bool rewrite(SourceLocation location);
std::set<VarDecl const *> varDecls_;
+ unsigned int externCContexts_ = 0;
};
void SalBool::run() {
@@ -282,10 +288,9 @@ bool SalBool::VisitCStyleCastExpr(CStyleCastExpr * expr) {
StringRef name { Lexer::getImmediateMacroName(
loc, compiler.getSourceManager(), compiler.getLangOpts()) };
if (name == "sal_False" || name == "sal_True") {
- auto callLoc = compiler.getSourceManager().getSpellingLoc(
- compiler.getSourceManager().getImmediateMacroCallerLoc(
- loc));
- if (!isFromCIncludeFile(callLoc)) {
+ auto callLoc = compiler.getSourceManager()
+ .getImmediateMacroCallerLoc(loc);
+ if (!isSharedCAndCppCode(callLoc)) {
SourceLocation argLoc;
if (compat::isMacroArgExpansion(
compiler, expr->getLocStart(), &argLoc)
@@ -301,17 +306,19 @@ bool SalBool::VisitCStyleCastExpr(CStyleCastExpr * expr) {
}
bool b = name == "sal_True";
if (rewriter != nullptr) {
+ auto callSpellLoc = compiler.getSourceManager()
+ .getSpellingLoc(callLoc);
unsigned n = Lexer::MeasureTokenLength(
- callLoc, compiler.getSourceManager(),
+ callSpellLoc, compiler.getSourceManager(),
compiler.getLangOpts());
if (StringRef(
compiler.getSourceManager().getCharacterData(
- callLoc),
+ callSpellLoc),
n)
== name)
{
return replaceText(
- callLoc, n, b ? "true" : "false");
+ callSpellLoc, n, b ? "true" : "false");
}
}
report(
@@ -725,6 +732,15 @@ bool SalBool::TraverseStaticAssertDecl(StaticAssertDecl * decl) {
|| RecursiveASTVisitor::TraverseStaticAssertDecl(decl);
}
+bool SalBool::TraverseLinkageSpecDecl(LinkageSpecDecl * decl) {
+ assert(externCContexts_ != std::numeric_limits<unsigned int>::max()); //TODO
+ ++externCContexts_;
+ bool ret = RecursiveASTVisitor::TraverseLinkageSpecDecl(decl);
+ assert(externCContexts_ != 0);
+ --externCContexts_;
+ return ret;
+}
+
bool SalBool::isFromCIncludeFile(SourceLocation spellingLocation) const {
return !compiler.getSourceManager().isInMainFile(spellingLocation)
&& (StringRef(
@@ -733,6 +749,16 @@ bool SalBool::isFromCIncludeFile(SourceLocation spellingLocation) const {
.endswith(".h"));
}
+bool SalBool::isSharedCAndCppCode(SourceLocation location) const {
+ // Assume that code is intended to be shared between C and C++ if it comes
+ // from an include file ending in .h, and is either in an extern "C" context
+ // or the body of a macro definition:
+ return
+ isFromCIncludeFile(compiler.getSourceManager().getSpellingLoc(location))
+ && (externCContexts_ != 0
+ || compiler.getSourceManager().isMacroBodyExpansion(location));
+}
+
bool SalBool::isInSpecialMainFile(SourceLocation spellingLocation) const {
if (!compiler.getSourceManager().isInMainFile(spellingLocation)) {
return false;
diff --git a/framework/inc/properties.h b/framework/inc/properties.h
index 383225ffeece..78f4701b9412 100644
--- a/framework/inc/properties.h
+++ b/framework/inc/properties.h
@@ -157,7 +157,7 @@ class PropHelper
css::uno::Any& aOldValue ,
css::uno::Any& aChangedValue )
{
- bool bChanged = sal_False;
+ bool bChanged = false;
// clear return parameter to be sure, to put out only valid values ...
aOldValue.clear();
diff --git a/framework/inc/protocols.h b/framework/inc/protocols.h
index d729d6f72235..b93f292e0f15 100644
--- a/framework/inc/protocols.h
+++ b/framework/inc/protocols.h
@@ -82,7 +82,7 @@ class ProtocolCheck
*/
static bool isProtocol( const OUString& sURL, EProtocol eRequired )
{
- bool bRet = sal_False;
+ bool bRet = false;
switch(eRequired)
{
case E_PRIVATE:
@@ -116,7 +116,7 @@ class ProtocolCheck
bRet = sURL.startsWith(SPECIALPROTOCOL_NEWS);
break;
default:
- bRet = sal_False;
+ bRet = false;
break;
}
return bRet;
diff --git a/include/cppuhelper/interfacecontainer.h b/include/cppuhelper/interfacecontainer.h
index 07b296e5b7d2..2a88f39e5648 100644
--- a/include/cppuhelper/interfacecontainer.h
+++ b/include/cppuhelper/interfacecontainer.h
@@ -450,8 +450,8 @@ struct OBroadcastHelperVar
OBroadcastHelperVar( ::osl::Mutex & rMutex_ )
: rMutex( rMutex_ )
, aLC( rMutex_ )
- , bDisposed( sal_False )
- , bInDispose( sal_False )
+ , bDisposed( false )
+ , bInDispose( false )
{}
/**
diff --git a/sal/qa/osl/security/osl_Security_Const.h b/sal/qa/osl/security/osl_Security_Const.h
index 84619f0964b2..83dd21f31f14 100644
--- a/sal/qa/osl/security/osl_Security_Const.h
+++ b/sal/qa/osl/security/osl_Security_Const.h
@@ -51,7 +51,7 @@ const char pTestString[17] = "Sun Microsystems";
::rtl::OUString strUserName, strComputerName, strHomeDirectory;
::rtl::OUString strConfigDirectory, strUserID;
-bool isAdmin = sal_False;
+bool isAdmin = false;
#endif // INCLUDED_SAL_QA_OSL_SECURITY_OSL_SECURITY_CONST_H