diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 58d213e15..ecfb93e7e 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -3483,12 +3483,14 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s floatingLiteral_trans trans_state expr_info float_string | CXXScalarValueInitExpr (_, _, expr_info) -> cxxScalarValueInitExpr_trans trans_state expr_info - | ObjCBoxedExpr (stmt_info, stmts, info, boxed_expr_info) -> ( - match boxed_expr_info.Clang_ast_t.obei_boxing_method with - | Some sel -> - objCBoxedExpr_trans trans_state info sel stmt_info stmts - | None -> - assert false ) + | ObjCBoxedExpr (stmt_info, stmts, info, boxed_expr_info) -> + (* Sometimes clang does not return a boxing method (a name of function to apply), e.g., + [@("str")]. In that case, it uses "unknownSelector:" instead of giving up the + translation. *) + let sel = + Option.value boxed_expr_info.Clang_ast_t.obei_boxing_method ~default:"unknownSelector:" + in + objCBoxedExpr_trans trans_state info sel stmt_info stmts | ObjCArrayLiteral (stmt_info, stmts, expr_info, array_literal_info) -> objCArrayLiteral_trans trans_state expr_info stmt_info stmts array_literal_info | ObjCDictionaryLiteral (stmt_info, stmts, expr_info, dict_literal_info) -> diff --git a/infer/tests/codetoanalyze/objc/frontend/boxing/Boxing.m b/infer/tests/codetoanalyze/objc/frontend/boxing/Boxing.m index 5e6d47dba..06bf80733 100644 --- a/infer/tests/codetoanalyze/objc/frontend/boxing/Boxing.m +++ b/infer/tests/codetoanalyze/objc/frontend/boxing/Boxing.m @@ -42,4 +42,10 @@ ; } +- (NSString*)getString { + NSString* s = @("hello world"); + return s; + ; +} + @end diff --git a/infer/tests/codetoanalyze/objc/frontend/boxing/Boxing.m.dot b/infer/tests/codetoanalyze/objc/frontend/boxing/Boxing.m.dot index 00ac8b8e9..cc66682f4 100644 --- a/infer/tests/codetoanalyze/objc/frontend/boxing/Boxing.m.dot +++ b/infer/tests/codetoanalyze/objc/frontend/boxing/Boxing.m.dot @@ -98,4 +98,19 @@ digraph cfg { "getS#Boxing#instance.97ccd331527b54376eb9b2b822cb25a3_4" -> "getS#Boxing#instance.97ccd331527b54376eb9b2b822cb25a3_3" ; +"getString#Boxing#instance.0cdd84065923a1c621289a9de4707559_1" [label="1: Start Boxing::getString\nFormals: self:Boxing*\nLocals: s:NSString* \n " color=yellow style=filled] + + + "getString#Boxing#instance.0cdd84065923a1c621289a9de4707559_1" -> "getString#Boxing#instance.0cdd84065923a1c621289a9de4707559_4" ; +"getString#Boxing#instance.0cdd84065923a1c621289a9de4707559_2" [label="2: Exit Boxing::getString \n " color=yellow style=filled] + + +"getString#Boxing#instance.0cdd84065923a1c621289a9de4707559_3" [label="3: Return Stmt \n n$19=*&s:NSString* [line 47, column 10]\n *&return:NSString*=n$19 [line 47, column 3]\n " shape="box"] + + + "getString#Boxing#instance.0cdd84065923a1c621289a9de4707559_3" -> "getString#Boxing#instance.0cdd84065923a1c621289a9de4707559_2" ; +"getString#Boxing#instance.0cdd84065923a1c621289a9de4707559_4" [label="4: DeclStmt \n VARIABLE_DECLARED(s:NSString*); [line 46, column 3]\n n$20=_fun_NSString::unknownSelector:(\"hello world\":char*) [line 46, column 17]\n *&s:NSString*=n$20 [line 46, column 3]\n " shape="box"] + + + "getString#Boxing#instance.0cdd84065923a1c621289a9de4707559_4" -> "getString#Boxing#instance.0cdd84065923a1c621289a9de4707559_3" ; }