diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index e3b10cd68..24d4849bd 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -3263,6 +3263,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s -> no_op_trans trans_state.succ_nodes (* vector instructions for OpenCL etc. we basically ignore these for now; just translate the sub-expressions *) + | ObjCAvailabilityCheckExpr (_, _, expr_info, _) + -> trans_into_undefined_expr trans_state expr_info | ExtVectorElementExpr (_, stmts, _) | ShuffleVectorExpr (_, stmts, _) | UserDefinedLiteral (_, stmts, _) @@ -3305,7 +3307,6 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s | MSPropertySubscriptExpr _ | NoInitExpr _ | OMPArraySectionExpr _ - | ObjCAvailabilityCheckExpr _ | ObjCIsaExpr _ | ObjCSubscriptRefExpr _ | UnresolvedLookupExpr _ diff --git a/infer/tests/codetoanalyze/objc/errors/Makefile b/infer/tests/codetoanalyze/objc/errors/Makefile index 9f7d8d9ab..d4bd3b86c 100644 --- a/infer/tests/codetoanalyze/objc/errors/Makefile +++ b/infer/tests/codetoanalyze/objc/errors/Makefile @@ -48,6 +48,7 @@ SOURCES_DEFAULT = \ shared/memory_leaks_benchmark/MemoryLeakExample.m \ shared/memory_leaks_benchmark/RetainReleaseExample.m \ shared/memory_leaks_benchmark/arc_methods.m \ + shared/npe/Available_expr.m \ shared/npe/Nonnull_attribute_example.m \ shared/property/GetterExample.m \ shared/property/PropertyAttributes.m \ diff --git a/infer/tests/codetoanalyze/objc/errors/issues.exp b/infer/tests/codetoanalyze/objc/errors/issues.exp index d9f5ebc4c..a4112d32c 100644 --- a/infer/tests/codetoanalyze/objc/errors/issues.exp +++ b/infer/tests/codetoanalyze/objc/errors/issues.exp @@ -125,4 +125,5 @@ codetoanalyze/objc/shared/memory_leaks_benchmark/MemoryLeakExample.m, MemoryLeak codetoanalyze/objc/shared/memory_leaks_benchmark/MemoryLeakExample.m, MemoryLeakExample_test1NoLeak, 2, Assert_failure, [start of procedure test1NoLeak] codetoanalyze/objc/shared/memory_leaks_benchmark/MemoryLeakExample.m, MemoryLeakExample_test2:, 1, MEMORY_LEAK, [start of procedure test2:] codetoanalyze/objc/shared/memory_leaks_benchmark/MemoryLeakExample.m, MemoryLeakExample_test2NoLeak, 2, Assert_failure, [start of procedure test2NoLeak] +codetoanalyze/objc/shared/npe/Available_expr.m, Available_expr_test_no_bug, 3, NULL_DEREFERENCE, [start of procedure test_no_bug,Condition is true] codetoanalyze/objc/shared/npe/Nonnull_attribute_example.m, NonnullC_initWithCoder:and:, 2, UNINITIALIZED_VALUE, [start of procedure initWithCoder:and:,start of procedure getA,return from a call to NonnullA_getA] diff --git a/infer/tests/codetoanalyze/objc/frontend/arc/Makefile b/infer/tests/codetoanalyze/objc/frontend/arc/Makefile index 8ce137692..63c37920b 100644 --- a/infer/tests/codetoanalyze/objc/frontend/arc/Makefile +++ b/infer/tests/codetoanalyze/objc/frontend/arc/Makefile @@ -26,6 +26,7 @@ SOURCES = \ ../shared/block/BlockVar.m \ ../shared/memory_leaks_benchmark/ArcExample.m \ ../shared/memory_leaks_benchmark/arc_methods.m \ + ../shared/npe/Available_expr.m \ ../shared/npe/Nonnull_attribute_example.m \ include $(TESTS_DIR)/clang-frontend.make diff --git a/infer/tests/codetoanalyze/objc/shared/npe/Available_expr.m b/infer/tests/codetoanalyze/objc/shared/npe/Available_expr.m new file mode 100644 index 000000000..e0cb736c7 --- /dev/null +++ b/infer/tests/codetoanalyze/objc/shared/npe/Available_expr.m @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#import + +@interface Available_expr : NSObject + +@end + +@implementation Available_expr + +- (int)test_no_bug { + int* p = NULL; + if (@available(macOS 10.13, iOS 11.0, *)) { + return *p; + } + return 0; +} + +@end diff --git a/infer/tests/codetoanalyze/objc/shared/npe/Available_expr.m.dot b/infer/tests/codetoanalyze/objc/shared/npe/Available_expr.m.dot new file mode 100644 index 000000000..4bbc7c3cb --- /dev/null +++ b/infer/tests/codetoanalyze/objc/shared/npe/Available_expr.m.dot @@ -0,0 +1,35 @@ +/* @generated */ +digraph iCFG { +"test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_1" [label="1: Start Available_expr_test_no_bug\nFormals: self:Available_expr*\nLocals: p:int* \n DECLARE_LOCALS(&return,&p); [line 17]\n " color=yellow style=filled] + + + "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_1" -> "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_8" ; +"test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_2" [label="2: Exit Available_expr_test_no_bug \n " color=yellow style=filled] + + +"test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_3" [label="3: Return Stmt \n *&return:int=0 [line 22]\n " shape="box"] + + + "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_3" -> "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_2" ; +"test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_4" [label="4: + \n " ] + + + "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_4" -> "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_3" ; +"test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_5" [label="5: Prune (true branch) \n PRUNE(n$0, true); [line 19]\n " shape="invhouse"] + + + "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_5" -> "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_7" ; +"test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_6" [label="6: Prune (false branch) \n PRUNE(!n$0, false); [line 19]\n " shape="invhouse"] + + + "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_6" -> "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_4" ; +"test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_7" [label="7: Return Stmt \n n$1=*&p:int* [line 20]\n n$2=*n$1:int [line 20]\n *&return:int=n$2 [line 20]\n " shape="box"] + + + "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_7" -> "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_2" ; +"test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_8" [label="8: DeclStmt \n *&p:int*=null [line 18]\n " shape="box"] + + + "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_8" -> "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_5" ; + "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_8" -> "test_no_bug#Available_expr#instance.a4aa786abeb2b17541abfe8ecf02c88f_6" ; +}