[cfe-commits] r141141 - in /cfe/trunk: lib/AST/ASTContext.cpp lib/Sema/SemaExpr.cpp test/Sema/initialize-noreturn.c
Fariborz Jahanian
fjahanian at apple.com
Tue Oct 4 17:05:35 PDT 2011
Author: fjahanian
Date: Tue Oct 4 19:05:34 2011
New Revision: 141141
URL: http://llvm.org/viewvc/llvm-project?rev=141141&view=rev
Log:
c: assignment/init of a function pointer whose function(s)
return to one which does not return (has noreturn attribute)
should warn as it is an unsafe assignment. // rdar://10095762
c++ already handles this. This is the c version.
Added:
cfe/trunk/test/Sema/initialize-noreturn.c
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=141141&r1=141140&r2=141141&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Oct 4 19:05:34 2011
@@ -5543,13 +5543,13 @@
if (lbaseInfo.getProducesResult() != rbaseInfo.getProducesResult())
return QualType();
- // It's noreturn if either type is.
- // FIXME: some uses, e.g. conditional exprs, really want this to be 'both'.
- bool NoReturn = lbaseInfo.getNoReturn() || rbaseInfo.getNoReturn();
- if (NoReturn != lbaseInfo.getNoReturn())
+ // functypes which return are preferred over those that do not.
+ if (lbaseInfo.getNoReturn() && !rbaseInfo.getNoReturn())
allLTypes = false;
- if (NoReturn != rbaseInfo.getNoReturn())
+ else if (!lbaseInfo.getNoReturn() && rbaseInfo.getNoReturn())
allRTypes = false;
+ // FIXME: some uses, e.g. conditional exprs, really want this to be 'both'.
+ bool NoReturn = lbaseInfo.getNoReturn() || rbaseInfo.getNoReturn();
FunctionType::ExtInfo einfo = lbaseInfo.withNoReturn(NoReturn);
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=141141&r1=141140&r2=141141&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Oct 4 19:05:34 2011
@@ -5277,6 +5277,9 @@
// General pointer incompatibility takes priority over qualifiers.
return Sema::IncompatiblePointer;
}
+ if (!S.getLangOptions().CPlusPlus &&
+ S.IsNoReturnConversion(ltrans, rtrans, ltrans))
+ return Sema::IncompatiblePointer;
return ConvTy;
}
Added: cfe/trunk/test/Sema/initialize-noreturn.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/initialize-noreturn.c?rev=141141&view=auto
==============================================================================
--- cfe/trunk/test/Sema/initialize-noreturn.c (added)
+++ cfe/trunk/test/Sema/initialize-noreturn.c Tue Oct 4 19:05:34 2011
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// rdar://10095762
+
+typedef void (*Fn_noret)(void) __attribute__((noreturn));
+typedef void (*Fn_ret)(void);
+
+void foo(void);
+void foo_noret(void) __attribute__((noreturn));
+
+void test() {
+ Fn_noret fn2 = &foo; // expected-warning {{incompatible pointer types initializing 'Fn_noret'}}
+ Fn_noret fn3 = &foo_noret;
+ Fn_ret fn4 = &foo_noret;
+ Fn_ret fn5 = &foo;
+}
+
More information about the cfe-commits
mailing list