[cfe-commits] r124280 - in /cfe/trunk: lib/Sema/AnalysisBasedWarnings.cpp test/SemaCXX/warn-missing-noreturn.cpp
Ted Kremenek
kremenek at apple.com
Tue Jan 25 20:49:52 PST 2011
Author: kremenek
Date: Tue Jan 25 22:49:52 2011
New Revision: 124280
URL: http://llvm.org/viewvc/llvm-project?rev=124280&view=rev
Log:
Teach -Wreturn-type that destructors can appear
after a 'return' in a CFGBlock. This accidentally
was working before, but the false assumption that
'return' always appeared at the end of the block
was uncovered by a recent change.
Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=124280&r1=124279&r2=124280&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Jan 25 22:49:52 2011
@@ -121,26 +121,29 @@
const CFGBlock& B = **I;
if (!live[B.getBlockID()])
continue;
- if (B.size() == 0) {
+
+ // Destructors can appear after the 'return' in the CFG. This is
+ // normal. We need to look pass the destructors for the return
+ // statement (if it exists).
+ CFGBlock::const_reverse_iterator ri = B.rbegin(), re = B.rend();
+ for ( ; ri != re ; ++ri) {
+ CFGElement CE = *ri;
+ if (isa<CFGStmt>(CE))
+ break;
+ }
+
+ // No more CFGElements in the block?
+ if (ri == re) {
if (B.getTerminator() && isa<CXXTryStmt>(B.getTerminator())) {
HasAbnormalEdge = true;
continue;
}
-
// A labeled empty statement, or the entry block...
HasPlainEdge = true;
continue;
}
- CFGElement CE = B[B.size()-1];
-
- if (!isa<CFGStmt>(CE)) {
- HasPlainEdge = true;
- continue;
- }
- CFGStmt CS = CE.getAs<CFGStmt>();
- if (!CS.isValid())
- continue;
+ CFGStmt CS = cast<CFGStmt>(*ri);
Stmt *S = CS.getStmt();
if (isa<ReturnStmt>(S)) {
HasLiveReturn = true;
Modified: cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp?rev=124280&r1=124279&r2=124280&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp Tue Jan 25 22:49:52 2011
@@ -93,3 +93,13 @@
rdar8875247 f;
} // expected-warning{{control reaches end of non-void function}}
+struct rdar8875247_B {
+ rdar8875247_B();
+ ~rdar8875247_B();
+};
+
+rdar8875247_B test_rdar8875247_B() {
+ rdar8875247_B f;
+ return f;
+} // no-warning
+
More information about the cfe-commits
mailing list