From: Douglas Gregor Date: Sat, 10 Sep 2011 00:56:20 +0000 (+0000) Subject: Fix a diagnostics crasher with -Wmissing-noreturn in Objective-C X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3321093f6ead084427eb4a6621832fc4ee2f5de;p=clang Fix a diagnostics crasher with -Wmissing-noreturn in Objective-C methods, and improve the diagnostic slightly along the way. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139446 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index bd18b2f63f..58bfbcfd28 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -236,7 +236,7 @@ def err_maybe_falloff_nonvoid_block : Error< def err_falloff_nonvoid_block : Error< "control reaches end of non-void block">; def warn_suggest_noreturn_function : Warning< - "function %0 could be declared with attribute 'noreturn'">, + "%select{function|method}0 %1 could be declared with attribute 'noreturn'">, InGroup>, DefaultIgnore; def warn_suggest_noreturn_block : Warning< "block could be declared with attribute 'noreturn'">, diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 823cbf74f5..30b6b0c8e3 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -382,7 +382,10 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body, if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn) { if (const FunctionDecl *FD = dyn_cast(D)) { S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn) - << FD; + << 0 << FD; + } else if (const ObjCMethodDecl *MD = dyn_cast(D)) { + S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn) + << 1 << MD; } else { S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn); } diff --git a/test/SemaObjC/return.m b/test/SemaObjC/return.m index 88e6e6381e..4e70bde1ed 100644 --- a/test/SemaObjC/return.m +++ b/test/SemaObjC/return.m @@ -39,3 +39,12 @@ NSString *rdar_4289832() { // no-warning } } +void exit(int) __attribute__((noreturn)); +@interface rdar10098695 +@end + +@implementation rdar10098695 +- (void)method { // expected-warning{{method 'method' could be declared with attribute 'noreturn'}} + exit(1); +} +@end