r259591 - ObjCXX: fix a crash during typo correction.
Manman Ren via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 2 14:23:04 PST 2016
Author: mren
Date: Tue Feb 2 16:23:03 2016
New Revision: 259591
URL: http://llvm.org/viewvc/llvm-project?rev=259591&view=rev
Log:
ObjCXX: fix a crash during typo correction.
For ObjCXX, we can create a CastExpr with Kind being CK_UserDefinedConversion
and SubExpr being BlockExpr. Specifically one can return BlockExpr from
BuildCXXMemberCallExpr and the result can be used to build a CastExpr.
Fix the assumption in CastExpr::getSubExprAsWritten that SubExpr can only
be CXXMemberCallExpr.
rdar://problem/24364077
Added:
cfe/trunk/test/SemaObjCXX/block-for-lambda-conversion.mm
Modified:
cfe/trunk/lib/AST/Expr.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=259591&r1=259590&r2=259591&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Feb 2 16:23:03 2016
@@ -1744,8 +1744,13 @@ Expr *CastExpr::getSubExprAsWritten() {
// subexpression describing the call; strip it off.
if (E->getCastKind() == CK_ConstructorConversion)
SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0);
- else if (E->getCastKind() == CK_UserDefinedConversion)
- SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument();
+ else if (E->getCastKind() == CK_UserDefinedConversion) {
+ assert((isa<CXXMemberCallExpr>(SubExpr) ||
+ isa<BlockExpr>(SubExpr)) &&
+ "Unexpected SubExpr for CK_UserDefinedConversion.");
+ if (isa<CXXMemberCallExpr>(SubExpr))
+ SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument();
+ }
// If the subexpression we're left with is an implicit cast, look
// through that, too.
Added: cfe/trunk/test/SemaObjCXX/block-for-lambda-conversion.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/block-for-lambda-conversion.mm?rev=259591&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/block-for-lambda-conversion.mm (added)
+++ cfe/trunk/test/SemaObjCXX/block-for-lambda-conversion.mm Tue Feb 2 16:23:03 2016
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -std=c++11 %s
+
+enum NSEventType {
+ NSEventTypeFlagsChanged = 12
+};
+
+enum NSEventMask {
+ NSEventMaskLeftMouseDown = 1
+};
+
+static const NSEventType NSFlagsChanged = NSEventTypeFlagsChanged;
+
+ at interface NSObject
+ at end
+ at interface NSEvent : NSObject {
+}
++ (nullable id)
+addMonitor:(NSEventMask)mask handler:(NSEvent *_Nullable (^)(NSEvent *))block;
+ at end
+
+void test(id weakThis) {
+ id m_flagsChangedEventMonitor = [NSEvent
+ addMonitor:NSFlagsChangedMask //expected-error {{use of undeclared identifier 'NSFlagsChangedMask'}}
+ handler:[weakThis](NSEvent *flagsChangedEvent) {
+ return flagsChangedEvent;
+ }];
+}
More information about the cfe-commits
mailing list