Fix regression in -Wreturn-type caused by not

handling all CFGElement kinds.  While writing
the test case, it turned out that return-noreturn.cpp
wasn't actually testing anything since it has the wrong -W
flag.  That uncovered another regression with
the handling of destructors marked noreturn.  WIP.

llvm-svn: 124238
This commit is contained in:
Ted Kremenek 2011-01-25 22:50:47 +00:00
parent ccc9963e34
commit ebe6260137
3 changed files with 30 additions and 27 deletions

View File

@ -132,21 +132,12 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) {
continue;
}
CFGElement CE = B[B.size()-1];
if (CFGInitializer CI = CE.getAs<CFGInitializer>()) {
// A base or member initializer.
HasPlainEdge = true;
continue;
}
if (CFGMemberDtor MD = CE.getAs<CFGMemberDtor>()) {
// A member destructor.
HasPlainEdge = true;
continue;
}
if (CFGBaseDtor BD = CE.getAs<CFGBaseDtor>()) {
// A base destructor.
if (!isa<CFGStmt>(CE)) {
HasPlainEdge = true;
continue;
}
CFGStmt CS = CE.getAs<CFGStmt>();
if (!CS.isValid())
continue;

View File

@ -0,0 +1,18 @@
// RUN: %clang_cc1 %s -fsyntax-only -verify -Wreturn-type -Wno-unreachable-code
// XFAIL: *
// A destructor may be marked noreturn and should still influence the CFG.
namespace PR6884 {
struct abort_struct {
abort_struct() {} // Make this non-POD so the destructor is invoked.
~abort_struct() __attribute__((noreturn));
};
int f() {
abort_struct();
}
int f2() {
abort_struct s;
}
}

View File

@ -1,17 +1,11 @@
// RUN: %clang_cc1 %s -fsyntax-only -verify -Wmissing-noreturn -Wno-unreachable-code
// RUN: %clang_cc1 %s -fsyntax-only -verify -Wreturn-type -Wno-unreachable-code
// A destructor may be marked noreturn and should still influence the CFG.
namespace PR6884 {
struct abort_struct {
abort_struct() {} // Make this non-POD so the destructor is invoked.
~abort_struct() __attribute__((noreturn));
};
// <rdar://problem/8875247> - Properly handle CFGs with destructors.
struct rdar8875247 {
~rdar8875247 ();
};
void rdar8875247_aux();
int f() {
abort_struct();
}
int f2() {
abort_struct s;
}
}
int rdar8875247_test() {
rdar8875247 f;
} // expected-warning{{control reaches end of non-void function}}