From: Chris Lattner Date: Sun, 25 Oct 2009 22:43:07 +0000 (+0000) Subject: Fix PR5298 - -Wmissing-noreturn shouldn't warn if the function is already X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a128e84006fdabfda4b8bd04f09c2739ed7f824;p=clang Fix PR5298 - -Wmissing-noreturn shouldn't warn if the function is already declared noreturn. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85075 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 11dbf042f2..70cab66d87 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1150,6 +1150,7 @@ void Sema::CheckFallThroughForFunctionDef(Decl *D, Stmt *Body) { // which this code would then warn about. if (getDiagnostics().hasErrorOccurred()) return; + bool ReturnsVoid = false; bool HasNoReturn = false; if (FunctionDecl *FD = dyn_cast(D)) { @@ -1192,7 +1193,7 @@ void Sema::CheckFallThroughForFunctionDef(Decl *D, Stmt *Body) { Diag(Compound->getRBracLoc(), diag::warn_falloff_nonvoid_function); break; case NeverFallThrough: - if (ReturnsVoid) + if (ReturnsVoid && !HasNoReturn) Diag(Compound->getLBracLoc(), diag::warn_suggest_noreturn_function); break; } @@ -1214,7 +1215,7 @@ void Sema::CheckFallThroughForBlock(QualType BlockTy, Stmt *Body) { return; bool ReturnsVoid = false; bool HasNoReturn = false; - if (const FunctionType *FT = BlockTy->getPointeeType()->getAs()) { + if (const FunctionType *FT =BlockTy->getPointeeType()->getAs()){ if (FT->getResultType()->isVoidType()) ReturnsVoid = true; if (FT->getNoReturnAttr()) diff --git a/test/Sema/return-noreturn.c b/test/Sema/return-noreturn.c index e2452f407f..8868c9ee0a 100644 --- a/test/Sema/return-noreturn.c +++ b/test/Sema/return-noreturn.c @@ -27,3 +27,11 @@ __attribute__((__noreturn__)) void* test3(int arg) { __attribute__((__noreturn__)) void* test3_positive(int arg) { while (0) foo_test_3(); } // expected-warning{{function declared 'noreturn' should not return}} + + +// PR5298 - -Wmissing-noreturn shouldn't warn if the function is already +// declared noreturn. +void __attribute__((noreturn)) +test4() { + test2_positive(); +}