diff options
| author | Ted Kremenek <kremenek@apple.com> | 2010-08-19 00:52:13 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2010-08-19 00:52:13 +0000 |
| commit | 50e0105f1c11c00f26528d58480228c66c7ab270 (patch) | |
| tree | fa0e5ff6dcf42a9dddc36462cd18d71169c55a18 /clang/lib | |
| parent | 5295ce8120b978e931b2084416ccd0f4222fb79e (diff) | |
| download | bcm5719-llvm-50e0105f1c11c00f26528d58480228c66c7ab270.tar.gz bcm5719-llvm-50e0105f1c11c00f26528d58480228c66c7ab270.zip | |
Add warning for functions/blocks that have attribute 'noreturn' but return a non-void result. (<rdar://problem/7562925>)
llvm-svn: 111492
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index accd7e63ed8..e3628c1d5f0 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1833,6 +1833,14 @@ static void HandleObjCGCTypeAttribute(QualType &Type, Type = S.Context.getObjCGCQualType(Type, GCAttr); } +static QualType GetResultType(QualType T) { + if (const PointerType *PT = T->getAs<PointerType>()) + T = PT->getPointeeType(); + else if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) + T = BT->getPointeeType(); + return T->getAs<FunctionType>()->getResultType(); +} + /// Process an individual function attribute. Returns true if the /// attribute does not make sense to apply to this type. bool ProcessFnAttr(Sema &S, QualType &Type, const AttributeList &Attr) { @@ -1849,7 +1857,12 @@ bool ProcessFnAttr(Sema &S, QualType &Type, const AttributeList &Attr) { && !Type->isBlockPointerType() && !Type->isFunctionType()) return true; - + + if (!GetResultType(Type)->isVoidType()) { + S.Diag(Attr.getLoc(), diag::warn_noreturn_function_has_nonvoid_result) + << (Type->isBlockPointerType() ? /* blocks */ 1 : /* functions */ 0); + } + // Otherwise we can process right away. Type = S.Context.getNoReturnType(Type); return false; |

