Teach CFGImplicitDtor::getDestructorDecl() about arrays of objects with destructors.

llvm-svn: 126910
This commit is contained in:
Ted Kremenek 2011-03-03 01:21:32 +00:00
parent 1676a042e3
commit 8cfe207861
4 changed files with 14 additions and 6 deletions

View File

@ -129,8 +129,8 @@ protected:
}
public:
const CXXDestructorDecl *getDestructorDecl() const;
bool isNoReturn() const;
const CXXDestructorDecl *getDestructorDecl(ASTContext &astContext) const;
bool isNoReturn(ASTContext &astContext) const;
static bool classof(const CFGElement *E) {
Kind kind = E->getKind();

View File

@ -2772,7 +2772,8 @@ CFG* CFG::buildCFG(const Decl *D, Stmt* Statement, ASTContext *C,
return Builder.buildCFG(D, Statement, C, BO);
}
const CXXDestructorDecl *CFGImplicitDtor::getDestructorDecl() const {
const CXXDestructorDecl *
CFGImplicitDtor::getDestructorDecl(ASTContext &astContext) const {
switch (getKind()) {
case CFGElement::Invalid:
case CFGElement::Statement:
@ -2783,6 +2784,9 @@ const CXXDestructorDecl *CFGImplicitDtor::getDestructorDecl() const {
const VarDecl *var = cast<CFGAutomaticObjDtor>(this)->getVarDecl();
QualType ty = var->getType();
ty = ty.getNonReferenceType();
if (const ArrayType *arrayType = astContext.getAsArrayType(ty)) {
ty = arrayType->getElementType();
}
const RecordType *recordType = ty->getAs<RecordType>();
const CXXRecordDecl *classDecl =
cast<CXXRecordDecl>(recordType->getDecl());
@ -2804,8 +2808,8 @@ const CXXDestructorDecl *CFGImplicitDtor::getDestructorDecl() const {
return 0;
}
bool CFGImplicitDtor::isNoReturn() const {
if (const CXXDestructorDecl *cdecl = getDestructorDecl()) {
bool CFGImplicitDtor::isNoReturn(ASTContext &astContext) const {
if (const CXXDestructorDecl *cdecl = getDestructorDecl(astContext)) {
QualType ty = cdecl->getType();
return cast<FunctionType>(ty)->getNoReturnAttr();
}

View File

@ -137,7 +137,7 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) {
// FIXME: The right solution is to just sever the edges in the
// CFG itself.
if (const CFGImplicitDtor *iDtor = ri->getAs<CFGImplicitDtor>())
if (iDtor->isNoReturn()) {
if (iDtor->isNoReturn(AC.getASTContext())) {
hasNoReturnDtor = true;
HasFakeEdge = true;
break;

View File

@ -39,3 +39,7 @@ void test_PR9380(const PR9380& aKey) {
const PR9380& flatKey = PR9380_B(aKey);
}
// Array of objects with destructors. This is purely a coverage test case.
void test_array() {
PR9380 a[2];
}