compilerplugins: enhance "badstatics" plugin to find members
Finds static variables of types that have bad non-static members. Change-Id: I81ee940580c0f043feb543840ea4d3dd27734202
This commit is contained in:
@@ -25,23 +25,68 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*static*/ std::pair<bool, FieldDecl const*> isBadStaticType(
|
||||||
|
QualType const& rType, FieldDecl const*const pCurrentFieldDecl)
|
||||||
|
{
|
||||||
|
QualType const pCanonical(rType.getUnqualifiedType().getCanonicalType());
|
||||||
|
RecordType const*const pRecordType(pCanonical->getAs<RecordType>());
|
||||||
|
if (!pRecordType) {
|
||||||
|
return std::make_pair(false, nullptr);
|
||||||
|
}
|
||||||
|
auto const type(pCanonical.getAsString());
|
||||||
|
if ( type == "class Image"
|
||||||
|
|| type == "class Bitmap"
|
||||||
|
|| type == "class BitmapEx"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return std::make_pair(true, pCurrentFieldDecl);
|
||||||
|
}
|
||||||
|
RecordDecl const*const pDefinition(pRecordType->getDecl()->getDefinition());
|
||||||
|
assert(pDefinition);
|
||||||
|
CXXRecordDecl const*const pDecl(dyn_cast<CXXRecordDecl>(pDefinition));
|
||||||
|
assert(pDecl);
|
||||||
|
for (auto it = pDecl->field_begin(); it != pDecl->field_end(); ++it) {
|
||||||
|
auto const ret(isBadStaticType((*it)->getType(), *it));
|
||||||
|
if (ret.first) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto it = pDecl->bases_begin(); it != pDecl->bases_end(); ++it) {
|
||||||
|
auto const ret(isBadStaticType((*it).getType(), pCurrentFieldDecl));
|
||||||
|
if (ret.first) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto it = pDecl->vbases_begin(); it != pDecl->vbases_end(); ++it) {
|
||||||
|
auto const ret(isBadStaticType((*it).getType(), pCurrentFieldDecl));
|
||||||
|
if (ret.first) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::make_pair(false, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
bool VisitVarDecl(VarDecl const*const pVarDecl)
|
bool VisitVarDecl(VarDecl const*const pVarDecl)
|
||||||
{
|
{
|
||||||
if (ignoreLocation(pVarDecl)) {
|
if (ignoreLocation(pVarDecl)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pVarDecl->hasGlobalStorage()) {
|
if (pVarDecl->hasGlobalStorage()
|
||||||
auto const type(pVarDecl->getType().getUnqualifiedType().getCanonicalType().getAsString());
|
&& pVarDecl->isThisDeclarationADefinition())
|
||||||
if ( type == "class Image"
|
{
|
||||||
|| type == "class Bitmap"
|
auto const ret(isBadStaticType(pVarDecl->getType(), nullptr));
|
||||||
|| type == "class BitmapEx"
|
if (ret.first) {
|
||||||
)
|
|
||||||
{
|
|
||||||
report(DiagnosticsEngine::Warning,
|
report(DiagnosticsEngine::Warning,
|
||||||
"bad static variable causes crash on shutdown",
|
"bad static variable causes crash on shutdown",
|
||||||
pVarDecl->getLocation())
|
pVarDecl->getLocation())
|
||||||
<< pVarDecl->getSourceRange();
|
<< pVarDecl->getSourceRange();
|
||||||
|
if (ret.second != nullptr) {
|
||||||
|
report(DiagnosticsEngine::Remark,
|
||||||
|
"... due to this member",
|
||||||
|
ret.second->getLocation())
|
||||||
|
<< ret.second->getSourceRange();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -944,12 +944,11 @@ sal_uInt32 WinMtfOutput::SetRasterOp( sal_uInt32 nRasterOp )
|
|||||||
if ( nRasterOp != mnRop )
|
if ( nRasterOp != mnRop )
|
||||||
{
|
{
|
||||||
mnRop = nRasterOp;
|
mnRop = nRasterOp;
|
||||||
static WinMtfFillStyle aNopFillStyle;
|
|
||||||
static WinMtfLineStyle aNopLineStyle;
|
static WinMtfLineStyle aNopLineStyle;
|
||||||
|
|
||||||
if ( mbNopMode && ( nRasterOp != R2_NOP ) )
|
if ( mbNopMode && ( nRasterOp != R2_NOP ) )
|
||||||
{ // changing modes from R2_NOP so set pen and brush
|
{ // changing modes from R2_NOP so set pen and brush
|
||||||
maFillStyle = aNopFillStyle;
|
maFillStyle = m_NopFillStyle;
|
||||||
maLineStyle = aNopLineStyle;
|
maLineStyle = aNopLineStyle;
|
||||||
mbNopMode = false;
|
mbNopMode = false;
|
||||||
}
|
}
|
||||||
@@ -968,7 +967,7 @@ sal_uInt32 WinMtfOutput::SetRasterOp( sal_uInt32 nRasterOp )
|
|||||||
meRasterOp = ROP_OVERPAINT;
|
meRasterOp = ROP_OVERPAINT;
|
||||||
if( !mbNopMode )
|
if( !mbNopMode )
|
||||||
{
|
{
|
||||||
aNopFillStyle = maFillStyle;
|
m_NopFillStyle = maFillStyle;
|
||||||
aNopLineStyle = maLineStyle;
|
aNopLineStyle = maLineStyle;
|
||||||
maFillStyle = WinMtfFillStyle( Color( COL_TRANSPARENT ), true );
|
maFillStyle = WinMtfFillStyle( Color( COL_TRANSPARENT ), true );
|
||||||
maLineStyle = WinMtfLineStyle( Color( COL_TRANSPARENT ), true );
|
maLineStyle = WinMtfLineStyle( Color( COL_TRANSPARENT ), true );
|
||||||
|
@@ -545,6 +545,7 @@ class WinMtfOutput
|
|||||||
WinMtfLineStyle maLineStyle;
|
WinMtfLineStyle maLineStyle;
|
||||||
WinMtfFillStyle maLatestFillStyle;
|
WinMtfFillStyle maLatestFillStyle;
|
||||||
WinMtfFillStyle maFillStyle;
|
WinMtfFillStyle maFillStyle;
|
||||||
|
WinMtfFillStyle m_NopFillStyle;
|
||||||
vcl::Font maLatestFont;
|
vcl::Font maLatestFont;
|
||||||
vcl::Font maFont;
|
vcl::Font maFont;
|
||||||
sal_uInt32 mnLatestTextAlign;
|
sal_uInt32 mnLatestTextAlign;
|
||||||
|
Reference in New Issue
Block a user