From d0858c7770812d2d45dc889e8a838fb4499c38a0 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Tue, 1 Aug 2017 07:06:00 -0700 Subject: [PATCH] [linters] Improve the to_string method for string constants Reviewed By: martinoluca Differential Revision: D5536440 fbshipit-source-id: 0f759d8 --- infer/src/clang/ctl_parser_types.ml | 4 ++++ .../tests/codetoanalyze/objc/linters/implicit_cast.m | 11 +++++++++++ infer/tests/codetoanalyze/objc/linters/issues.exp | 1 + 3 files changed, 16 insertions(+) diff --git a/infer/src/clang/ctl_parser_types.ml b/infer/src/clang/ctl_parser_types.ml index 8ac82a309..dfe8b2a4e 100644 --- a/infer/src/clang/ctl_parser_types.ml +++ b/infer/src/clang/ctl_parser_types.ml @@ -69,6 +69,10 @@ let rec ast_node_name an = match decl_ref.dr_name with Some name -> name.ni_name | None -> "" in ast_node_name (Stmt stmt) ^ "." ^ property_str + | Stmt StringLiteral (_, _, _, s) + -> s + | Stmt ObjCStringLiteral (_, [stmt], _) + -> "@" ^ ast_node_name (Stmt stmt) | _ -> "" diff --git a/infer/tests/codetoanalyze/objc/linters/implicit_cast.m b/infer/tests/codetoanalyze/objc/linters/implicit_cast.m index 94d7a85b6..4909c0664 100644 --- a/infer/tests/codetoanalyze/objc/linters/implicit_cast.m +++ b/infer/tests/codetoanalyze/objc/linters/implicit_cast.m @@ -51,4 +51,15 @@ extern NSString* const key; func_with_integer_param(self.p); } +typedef NS_ENUM(NSUInteger, MyEnum) { + MyEnumItem, +}; + +- (void)enum_param:(MyEnum)s { +} + +- (void)call_with_string { + [self enum_param:@"s"]; +} + @end diff --git a/infer/tests/codetoanalyze/objc/linters/issues.exp b/infer/tests/codetoanalyze/objc/linters/issues.exp index 133f4b351..0e134ef10 100644 --- a/infer/tests/codetoanalyze/objc/linters/issues.exp +++ b/infer/tests/codetoanalyze/objc/linters/issues.exp @@ -23,6 +23,7 @@ codetoanalyze/objc/linters/badpointer.m, bad6, 106, BAD_POINTER_COMPARISON, [] codetoanalyze/objc/linters/badpointer.m, bad7, 121, BAD_POINTER_COMPARISON, [] codetoanalyze/objc/linters/badpointer.m, bad8, 128, BAD_POINTER_COMPARISON, [] codetoanalyze/objc/linters/badpointer.m, bad9, 135, BAD_POINTER_COMPARISON, [] +codetoanalyze/objc/linters/implicit_cast.m, Implicit_cast_call_with_string, 62, POINTER_TO_INTEGRAL_IMPLICIT_CAST, [] codetoanalyze/objc/linters/implicit_cast.m, Implicit_cast_ivar_dictionary_item_call_funct_with_int, 47, POINTER_TO_INTEGRAL_IMPLICIT_CAST, [] codetoanalyze/objc/linters/implicit_cast.m, Implicit_cast_property_with_int, 51, POINTER_TO_INTEGRAL_IMPLICIT_CAST, [] codetoanalyze/objc/linters/implicit_cast.m, calling_funct_with_pointer, 17, POINTER_TO_INTEGRAL_IMPLICIT_CAST, []