diff --git a/infer/tests/codetoanalyze/cpp/bufferoverrun/global.cpp b/infer/tests/codetoanalyze/cpp/bufferoverrun/global.cpp index e884aa79f..e7fab752e 100644 --- a/infer/tests/codetoanalyze/cpp/bufferoverrun/global.cpp +++ b/infer/tests/codetoanalyze/cpp/bufferoverrun/global.cpp @@ -11,6 +11,12 @@ void access_constant_global_Bad() { a[ConstantGlobal[0]] = 3; } +void access_via_assignment_constant_global_Bad_FN() { + int a[5]; + const int* arr = ConstantGlobal; + a[arr[0]] = 3; +} + static int StaticGlobal[][3] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; diff --git a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp index 9d24d2354..1b8359b17 100644 --- a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp +++ b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp @@ -232,6 +232,9 @@ codetoanalyze/objc/performance/mutable_copy_test.m, MyMutableObj.objects, 5, On codetoanalyze/objc/performance/mutable_copy_test.m, MyMutableObj.setMObjects:, 3, OnUIThread:false, [] codetoanalyze/objc/performance/mutable_copy_test.m, loop_over_mutable_copy_linear, 31 + 3 ⋅ b->_mObjects->elements.length.ub + 3 ⋅ (b->_mObjects->elements.length.ub + 1), OnUIThread:false, [{b->_mObjects->elements.length.ub + 1},Loop,{b->_mObjects->elements.length.ub},Loop] codetoanalyze/objc/performance/purity.m, loop, 6006 + 1000 ⋅ |fun_ptr|, OnUIThread:false, [] +codetoanalyze/objc/performance/struct_test.m, __infer_globals_initializer_mSpecs, 4, OnUIThread:false, [] +codetoanalyze/objc/performance/struct_test.m, const_struct_field_read_constant_FP, 4 + mSpecs.fileName->strlen.ub, OnUIThread:false, [{mSpecs.fileName->strlen.ub},Modeled call to NSString.stringWithUTF8String:] +codetoanalyze/objc/performance/struct_test.m, loop_array_struct_constant, 9, OnUIThread:false, [] codetoanalyze/objc/performance/switch_continue.m, test_switch_FN, 600, OnUIThread:false, [] codetoanalyze/objc/performance/switch_continue.m, unroll_loop, 15 + (n - 1) + 11 ⋅ (max(1, n)), OnUIThread:false, [{max(1, n)},Loop,{n - 1},Loop] codetoanalyze/objc/performance/two_loops_symbolic.m, nop, 1, OnUIThread:false, [] diff --git a/infer/tests/codetoanalyze/objc/performance/struct_test.m b/infer/tests/codetoanalyze/objc/performance/struct_test.m new file mode 100644 index 000000000..1374e3f06 --- /dev/null +++ b/infer/tests/codetoanalyze/objc/performance/struct_test.m @@ -0,0 +1,32 @@ +/* + * 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 + +typedef struct MSpec_t { + const char* fileName; +} MSpec; + +#define SPEC_FILE_NAME(name) .fileName = (name), + +static const MSpec mSpecs[] = { + {SPEC_FILE_NAME("api")}, + {SPEC_FILE_NAME("graph")}, + {SPEC_FILE_NAME("disk")}, + {SPEC_FILE_NAME("io")}, +}; + +void const_struct_field_read_constant_FP() { + MSpec spec = mSpecs[0]; + NSString* fileName = + @(spec.fileName); // filename is constant, so this should be O(1) +} + +void loop_array_struct_constant() { + const MSpec* const endSpec = ((const MSpec*)mSpecs) + ARRAY_COUNT(mSpecs); + for (const MSpec* spec = (const MSpec*)mSpecs; spec < endSpec; spec++) { + } +}