aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaType.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-08-19 00:52:13 +0000
committerTed Kremenek <kremenek@apple.com>2010-08-19 00:52:13 +0000
commit58f281f7d54976f23ed4fa23a10ff1ab9c7037fe (patch)
tree03322efd0175fe7850fae03b7a3d1f683a8bc63c /lib/Sema/SemaType.cpp
parentb56c1cc8ca593f832ca58d682876259c2ed9bec2 (diff)
Add warning for functions/blocks that have attribute 'noreturn' but return a non-void result. (<rdar://problem/7562925>)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111492 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaType.cpp')
-rw-r--r--lib/Sema/SemaType.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index accd7e63ed..e3628c1d5f 100644
--- a/lib/Sema/SemaType.cpp
+++ b/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;