Skip to content

Commit

Permalink
Merge pull request #40310 from gartung/gartung-SA-constcast-assert-fix
Browse files Browse the repository at this point in the history
Utilities/StaticAnalysers: Fix assert in ConstCast and ConstCastAway checkers.
  • Loading branch information
cmsbuild authored Dec 14, 2022
2 parents 44827dc + 733719d commit 52c0dac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 8 additions & 3 deletions Utilities/StaticAnalyzers/src/ConstCastAwayChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <clang/AST/ExprCXX.h>
#include <clang/AST/Attr.h>
#include <clang/AST/ParentMap.h>
#include <clang/AST/Stmt.h>

#include <memory>

Expand Down Expand Up @@ -35,9 +36,13 @@ namespace clangcms {
}
if (P && isa<DeclStmt>(P)) {
const DeclStmt *DS = dyn_cast_or_null<DeclStmt>(P);
if (DS && (hasSpecificAttr<CMSSaAllowAttr>(DS->getSingleDecl()->getAttrs()) ||
hasSpecificAttr<CMSThreadSafeAttr>(DS->getSingleDecl()->getAttrs())))
return;
if (DS) {
for (auto D : DS->decls()) {
if (hasSpecificAttr<CMSSaAllowAttr>(D->getAttrs()) || hasSpecificAttr<CMSThreadSafeAttr>(D->getAttrs())) {
return;
}
}
}
}

const Expr *SE = CE->getSubExpr();
Expand Down
10 changes: 7 additions & 3 deletions Utilities/StaticAnalyzers/src/ConstCastChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ namespace clangcms {
}
if (P && isa<DeclStmt>(P)) {
const DeclStmt *DS = dyn_cast_or_null<DeclStmt>(P);
if (DS && (hasSpecificAttr<CMSSaAllowAttr>(DS->getSingleDecl()->getAttrs()) ||
hasSpecificAttr<CMSThreadSafeAttr>(DS->getSingleDecl()->getAttrs())))
return;
if (DS) {
for (auto D : DS->decls()) {
if (hasSpecificAttr<CMSSaAllowAttr>(D->getAttrs()) || hasSpecificAttr<CMSThreadSafeAttr>(D->getAttrs())) {
return;
}
}
}
}

const Expr *SE = CE->getSubExprAsWritten();
Expand Down

0 comments on commit 52c0dac

Please sign in to comment.