[cfe-commits] r91827 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjCXX/function-pointer-void-star.mm
Fariborz Jahanian
fjahanian at apple.com
Mon Dec 21 10:19:17 PST 2009
Author: fjahanian
Date: Mon Dec 21 12:19:17 2009
New Revision: 91827
URL: http://llvm.org/viewvc/llvm-project?rev=91827&view=rev
Log:
Allow comparison of 'void *' with function pointer
as a g++ extension (fixes radar 7481987).
Added:
cfe/trunk/test/SemaObjCXX/function-pointer-void-star.mm
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=91827&r1=91826&r2=91827&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Dec 21 12:19:17 2009
@@ -5170,7 +5170,18 @@
if (getLangOptions().CPlusPlus) {
if (LCanPointeeTy == RCanPointeeTy)
return ResultTy;
-
+ if (!isRelational &&
+ (LCanPointeeTy->isVoidType() || RCanPointeeTy->isVoidType())) {
+ // Valid unless comparison between non-null pointer and function pointer
+ // This is a gcc extension compatibility comparison.
+ if ((LCanPointeeTy->isFunctionType() || RCanPointeeTy->isFunctionType())
+ && !LHSIsNull && !RHSIsNull) {
+ Diag(Loc, diag::ext_typecheck_comparison_of_fptr_to_void)
+ << lType << rType << lex->getSourceRange() << rex->getSourceRange();
+ ImpCastExprToType(rex, lType, CastExpr::CK_BitCast);
+ return ResultTy;
+ }
+ }
// C++ [expr.rel]p2:
// [...] Pointer conversions (4.10) and qualification
// conversions (4.4) are performed on pointer operands (or on
Added: cfe/trunk/test/SemaObjCXX/function-pointer-void-star.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/function-pointer-void-star.mm?rev=91827&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/function-pointer-void-star.mm (added)
+++ cfe/trunk/test/SemaObjCXX/function-pointer-void-star.mm Mon Dec 21 12:19:17 2009
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+extern "C" id (*_dealloc)(id) ;
+
+void foo() {
+ extern void *_original_dealloc;
+ if (_dealloc == _original_dealloc) { }
+ if (_dealloc != _original_dealloc) { }
+}
More information about the cfe-commits
mailing list