[cfe-commits] r85195 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDecl.cpp test/SemaObjC/return.m
Mike Stump
mrs at apple.com
Mon Oct 26 18:59:06 PDT 2009
Author: mrs
Date: Mon Oct 26 20:59:05 2009
New Revision: 85195
URL: http://llvm.org/viewvc/llvm-project?rev=85195&view=rev
Log:
Refine noreturn handling. Fixes -Wmissing-noreturn so that it doesn't
complain that functions that have a return statement should be
declared noreturn. Fixed PR5286.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaObjC/return.m
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=85195&r1=85194&r2=85195&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon Oct 26 20:59:05 2009
@@ -988,7 +988,7 @@
void CheckCXXDefaultArguments(FunctionDecl *FD);
void CheckExtraCXXDefaultArguments(Declarator &D);
enum ControlFlowKind { NeverFallThrough = 0, MaybeFallThrough = 1,
- AlwaysFallThrough = 2 };
+ AlwaysFallThrough = 2, NeverFallThroughOrReturn = 3 };
ControlFlowKind CheckFallThrough(Stmt *);
Scope *getNonFieldDeclScope(Scope *S);
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=85195&r1=85194&r2=85195&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Oct 26 20:59:05 2009
@@ -1044,6 +1044,7 @@
/// Statement that should return a value.
///
/// \returns AlwaysFallThrough iff we always fall off the end of the statement,
+/// MaybeFallThroughOrReturn iff we might or might not fall off the end and
/// MaybeFallThrough iff we might or might not fall off the end and
/// NeverFallThrough iff we never fall off the end of the statement. We assume
/// that functions not marked noreturn will return.
@@ -1054,7 +1055,8 @@
// FIXME: They should never return 0, fix that, delete this code.
if (cfg == 0)
- return NeverFallThrough;
+ // FIXME: This should be NeverFallThrough
+ return NeverFallThroughOrReturn;
// The CFG leaves in dead things, and we don't want to dead code paths to
// confuse us, so we mark all live things first.
std::queue<CFGBlock*> workq;
@@ -1127,8 +1129,11 @@
if (NoReturnEdge == false)
HasPlainEdge = true;
}
- if (!HasPlainEdge)
- return NeverFallThrough;
+ if (!HasPlainEdge) {
+ if (HasLiveReturn)
+ return NeverFallThrough;
+ return NeverFallThroughOrReturn;
+ }
if (HasFakeEdge || HasLiveReturn)
return MaybeFallThrough;
// This says AlwaysFallThrough for calls to functions that are not marked
@@ -1192,10 +1197,12 @@
else if (!ReturnsVoid)
Diag(Compound->getRBracLoc(), diag::warn_falloff_nonvoid_function);
break;
- case NeverFallThrough:
+ case NeverFallThroughOrReturn:
if (ReturnsVoid && !HasNoReturn)
Diag(Compound->getLBracLoc(), diag::warn_suggest_noreturn_function);
break;
+ case NeverFallThrough:
+ break;
}
}
}
@@ -1243,10 +1250,12 @@
else if (!ReturnsVoid)
Diag(Compound->getRBracLoc(), diag::err_falloff_nonvoid_block);
break;
- case NeverFallThrough:
+ case NeverFallThroughOrReturn:
if (ReturnsVoid)
Diag(Compound->getLBracLoc(), diag::warn_suggest_noreturn_block);
break;
+ case NeverFallThrough:
+ break;
}
}
}
Modified: cfe/trunk/test/SemaObjC/return.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/return.m?rev=85195&r1=85194&r2=85195&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/return.m (original)
+++ cfe/trunk/test/SemaObjC/return.m Mon Oct 26 20:59:05 2009
@@ -1,6 +1,22 @@
-// RUN: clang-cc %s -fsyntax-only -verify
+// RUN: clang-cc %s -fsyntax-only -verify -Wmissing-noreturn
int test1() {
id a;
@throw a;
}
+
+// PR5286
+void test2(int a) {
+ while (1) {
+ if (a)
+ return;
+ }
+}
+
+// PR5286
+void test3(int a) { // expected-warning {{function could be attribute 'noreturn'}}
+ while (1) {
+ if (a)
+ @throw (id)0;
+ }
+}
More information about the cfe-commits
mailing list