[clang] Do not try to store block declarations as methods of a C++ struct.

Summary:
This was causing a crash, because when trying to create a procname from a block at that point we don't have the block return type, which is needed for the name. I don't understand why BlockDecl doesn't contain the type, but I looked again and it doesn't (also in clang). So in general we need to pass it from the context, but that's not possible in this case.
Also, one could argue that such a block is not a method from the struct, since it's just a block that is assigned to a field as initialization.

Reviewed By: skcho

Differential Revision: D17575197

fbshipit-source-id: 3974ead3f
master
Dulma Churchill 5 years ago committed by Facebook Github Bot
parent 7ec2830d92
commit 0eccdb25dc

@ -682,8 +682,7 @@ and get_struct_methods struct_decl tenv =
| CXXConstructorDecl _ | CXXConstructorDecl _
| CXXConversionDecl _ | CXXConversionDecl _
| CXXDestructorDecl _ | CXXDestructorDecl _
| ObjCMethodDecl _ | ObjCMethodDecl _ ->
| BlockDecl _ ->
Some (procname_from_decl ~tenv decl) Some (procname_from_decl ~tenv decl)
| _ -> | _ ->
None ) None )

@ -10,7 +10,7 @@ CLANG_OPTIONS = -c $(OBJCPP_CLANG_OPTIONS)
INFER_OPTIONS = INFER_OPTIONS =
SOURCES = \ SOURCES = \
$(wildcard */*.mm) \ $(wildcard *.mm) $(wildcard */*.mm) \
include $(TESTS_DIR)/clang-frontend.make include $(TESTS_DIR)/clang-frontend.make
include $(TESTS_DIR)/objc.make include $(TESTS_DIR)/objc.make

@ -0,0 +1,18 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
typedef BOOL (^ExperimentBlock)(void);
struct Configuration {
ExperimentBlock block = ^{
return NO;
};
};
int main() { return 0; }

@ -0,0 +1,14 @@
/* @generated */
digraph cfg {
"main.fad58de7366495db4650cfefac2fcd61_1" [label="1: Start main\nFormals: \nLocals: \n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_1" -> "main.fad58de7366495db4650cfefac2fcd61_3" ;
"main.fad58de7366495db4650cfefac2fcd61_2" [label="2: Exit main \n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_3" [label="3: Return Stmt \n *&return:int=0 [line 18, column 14]\n APPLY_ABSTRACTION; [line 18, column 14]\n " shape="box"]
"main.fad58de7366495db4650cfefac2fcd61_3" -> "main.fad58de7366495db4650cfefac2fcd61_2" ;
}
Loading…
Cancel
Save