Teach CFGImplicitDtor::getDestructorDecl() about arrays of objects with destructors.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126910 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Analysis/CFG.h b/include/clang/Analysis/CFG.h
index 992b32a..03beba5 100644
--- a/include/clang/Analysis/CFG.h
+++ b/include/clang/Analysis/CFG.h
@@ -129,8 +129,8 @@
}
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();
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp
index fc50071..6d8d5c5 100644
--- a/lib/Analysis/CFG.cpp
+++ b/lib/Analysis/CFG.cpp
@@ -2772,7 +2772,8 @@
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 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 @@
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();
}
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp
index 84efbd5..710f5ef 100644
--- a/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/lib/Sema/AnalysisBasedWarnings.cpp
@@ -137,7 +137,7 @@
// 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;
diff --git a/test/SemaCXX/return-noreturn.cpp b/test/SemaCXX/return-noreturn.cpp
index 4fb3732..5f044ca 100644
--- a/test/SemaCXX/return-noreturn.cpp
+++ b/test/SemaCXX/return-noreturn.cpp
@@ -39,3 +39,7 @@
const PR9380& flatKey = PR9380_B(aKey);
}
+// Array of objects with destructors. This is purely a coverage test case.
+void test_array() {
+ PR9380 a[2];
+}