diff options
Diffstat (limited to 'test/Analysis')
76 files changed, 4275 insertions, 155 deletions
diff --git a/test/Analysis/CFNumber.c b/test/Analysis/CFNumber.c index 544644a747dc5..4725f90f1a2f3 100644 --- a/test/Analysis/CFNumber.c +++ b/test/Analysis/CFNumber.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-checker=macosx.CFNumber -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-checker=macosx.CFNumber -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-checker=macosx.CFNumber -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-checker=macosx.CFNumber -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s typedef signed long CFIndex; typedef const struct __CFAllocator * CFAllocatorRef; diff --git a/test/Analysis/MissingDealloc.m b/test/Analysis/MissingDealloc.m index bfd968a9a1a6f..d7aaa99be70e2 100644 --- a/test/Analysis/MissingDealloc.m +++ b/test/Analysis/MissingDealloc.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-missing-dealloc '-DIBOutlet=__attribute__((iboutlet))' %s -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-checker=cocoa.experimental.Dealloc '-DIBOutlet=__attribute__((iboutlet))' %s -verify typedef signed char BOOL; @protocol NSObject - (BOOL)isEqual:(id)object; diff --git a/test/Analysis/NSString.m b/test/Analysis/NSString.m index fa81b3d95da90..c5f7a4569a5bc 100644 --- a/test/Analysis/NSString.m +++ b/test/Analysis/NSString.m @@ -1,13 +1,13 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=cocoa.NilArg -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=cocoa.NilArg -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=cocoa.NilArg -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=cocoa.NilArg -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s // ==-- FIXME: -analyzer-store=basic fails on this file (false negatives). --== -// NOTWORK: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s && -// NOTWORK: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s && -// NOTWORK: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s && -// NOTWORK: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s +// NOTWORK: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=cocoa.NilArg -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s && +// NOTWORK: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=cocoa.NilArg -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s && +// NOTWORK: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=cocoa.NilArg -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s && +// NOTWORK: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=cocoa.NilArg -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from diff --git a/test/Analysis/NSWindow.m b/test/Analysis/NSWindow.m index 34e6c68b85011..c386adf3f0852 100644 --- a/test/Analysis/NSWindow.m +++ b/test/Analysis/NSWindow.m @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.DeadStores -analyzer-store=basic -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.DeadStores -analyzer-store=basic -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.DeadStores -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.DeadStores -analyzer-store=region -analyzer-constraints=range -verify %s // These declarations were reduced using Delta-Debugging from Foundation.h // on Mac OS X. The test cases are below. diff --git a/test/Analysis/ObjCRetSigs.m b/test/Analysis/ObjCRetSigs.m index a76d7b979ee00..5a912a8089840 100644 --- a/test/Analysis/ObjCRetSigs.m +++ b/test/Analysis/ObjCRetSigs.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-methodsigs -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-checker=cocoa.MethodSigs -verify %s int printf(const char *, ...); diff --git a/test/Analysis/PR2978.m b/test/Analysis/PR2978.m index 1ed138e45d13b..ac3ef790cabde 100644 --- a/test/Analysis/PR2978.m +++ b/test/Analysis/PR2978.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-missing-dealloc %s -verify +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-checker=cocoa.experimental.Dealloc %s -verify // Tests for the checker which checks missing/extra ivar 'release' calls // in dealloc. diff --git a/test/Analysis/additive-folding.c b/test/Analysis/additive-folding.c index e4a565133968f..096ffb9a5059d 100644 --- a/test/Analysis/additive-folding.c +++ b/test/Analysis/additive-folding.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -verify -analyzer-constraints=basic %s -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -verify -analyzer-constraints=range %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -analyzer-checker=core.experimental.UnreachableCode -verify -analyzer-constraints=basic %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -analyzer-checker=core.experimental.UnreachableCode -verify -analyzer-constraints=range %s // These are used to trigger warnings. typedef typeof(sizeof(int)) size_t; @@ -183,14 +183,14 @@ void tautologyGT (unsigned a) { void tautologyGE (unsigned a) { char* b = malloc(1); - if (a >= 0) + if (a >= 0) // expected-warning{{always true}} free(b); return; // no-warning } void tautologyLT (unsigned a) { char* b = malloc(1); - if (a < 0) + if (a < 0) // expected-warning{{always false}} return; // expected-warning{{never executed}} free(b); } diff --git a/test/Analysis/analyzer-stats.c b/test/Analysis/analyzer-stats.c new file mode 100644 index 0000000000000..d8dde23d67090 --- /dev/null +++ b/test/Analysis/analyzer-stats.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks -analyzer-stats %s + +int foo(); + +int test() { // expected-warning{{Total CFGBlocks}} + int a = 1; + a = 34 / 12; + + if (foo()) + return a; + + a /= 4; + return a; +} diff --git a/test/Analysis/array-struct-region.c b/test/Analysis/array-struct-region.c index dabd25bb1f507..8162200b0aca3 100644 --- a/test/Analysis/array-struct-region.c +++ b/test/Analysis/array-struct-region.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-checks -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-checks -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-checks -analyzer-experimental-internal-checks -analyzer-checker=core.experimental.UnreachableCode -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-checks -analyzer-experimental-internal-checks -analyzer-checker=core.experimental.UnreachableCode -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s int string_literal_init() { char a[] = "abc"; diff --git a/test/Analysis/array-struct.c b/test/Analysis/array-struct.c index 3e46a0a62235f..df9e9786fff3b 100644 --- a/test/Analysis/array-struct.c +++ b/test/Analysis/array-struct.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.CastToStruct -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.CastToStruct -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.CastToStruct -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.CastToStruct -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s struct s { int data; diff --git a/test/Analysis/auto-obj-dtors-cfg-output.cpp b/test/Analysis/auto-obj-dtors-cfg-output.cpp new file mode 100644 index 0000000000000..4bcfccd120e20 --- /dev/null +++ b/test/Analysis/auto-obj-dtors-cfg-output.cpp @@ -0,0 +1,835 @@ +// RUN: %clang_cc1 -fexceptions -analyze -analyzer-checker=debug.DumpCFG -cfg-add-implicit-dtors %s 2>&1 | FileCheck %s +// XPASS: * + +class A { +public: + A() {} + ~A() {} + operator int() const { return 1; } +}; + +extern const bool UV; + +void test_const_ref() { + A a; + const A& b = a; + const A& c = A(); +} + +void test_array() { + A a[2]; + A b[0]; +} + +void test_scope() { + A a; + { A c; + A d; + } + A b; +} + +void test_return() { + A a; + A b; + if (UV) return; + A c; +} + +void test_goto() { + A a; +l0: + A b; + { A a; + if (UV) goto l0; + if (UV) goto l1; + A b; + } +l1: + A c; +} + +void test_if_implicit_scope() { + A a; + if (A b = a) + A c; + else A c; +} + +void test_if_jumps() { + A a; + if (A b = a) { + A c; + if (UV) return; + A d; + } else { + A c; + if (UV) return; + A d; + } + A e; +} + +void test_while_implicit_scope() { + A a; + while (A b = a) + A c; +} + +void test_while_jumps() { + A a; + while (A b = a) { + A c; + if (UV) break; + if (UV) continue; + if (UV) return; + A d; + } + A e; +} + +void test_do_implicit_scope() { + do A a; + while (UV); +} + +void test_do_jumps() { + A a; + do { + A b; + if (UV) break; + if (UV) continue; + if (UV) return; + A c; + } while (UV); + A d; +} + +void test_switch_implicit_scope() { + A a; + switch (A b = a) + A c; +} + +void test_switch_jumps() { + A a; + switch (A b = a) { + case 0: { + A c; + if (UV) break; + if (UV) return; + A f; + } + case 1: + break; + } + A g; +} + +void test_for_implicit_scope() { + for (A a; A b = a; ) + A c; +} + +void test_for_jumps() { + A a; + for (A b; A c = b; ) { + A d; + if (UV) break; + if (UV) continue; + if (UV) return; + A e; + } + A f; +} + +void test_catch_const_ref() { + try { + } catch (const A& e) { + } +} + +void test_catch_copy() { + try { + } catch (A e) { + } +} + +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: 3: const A &b = a; +// CHECK: 4: A() +// CHECK: 5: const A &c = A(); +// CHECK: 6: [B1.5].~A() (Implicit destructor) +// CHECK: 7: [B1.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: +// CHECK: 2: A a[2]; +// CHECK: 3: +// CHECK: 4: A b[0]; +// CHECK: 5: [B1.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: 3: +// CHECK: 4: A c; +// CHECK: 5: +// CHECK: 6: A d; +// CHECK: 7: [B1.6].~A() (Implicit destructor) +// CHECK: 8: [B1.4].~A() (Implicit destructor) +// CHECK: 9: +// CHECK: 10: A b; +// CHECK: 11: [B1.10].~A() (Implicit destructor) +// CHECK: 12: [B1.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B4 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B3 +// CHECK: [ B1 ] +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: [B1.2].~A() (Implicit destructor) +// CHECK: 4: [B3.4].~A() (Implicit destructor) +// CHECK: 5: [B3.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B3 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: return; +// CHECK: 2: [B3.4].~A() (Implicit destructor) +// CHECK: 3: [B3.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B3 +// CHECK: Successors (1): B0 +// CHECK: [ B3 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: 3: +// CHECK: 4: A b; +// CHECK: 5: UV +// CHECK: T: if [B3.5] +// CHECK: Predecessors (1): B4 +// CHECK: Successors (2): B2 B1 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (2): B1 B2 +// CHECK: Successors (0): +// CHECK: [ B8 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B7 +// CHECK: [ B1 ] +// CHECK: l1: +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: [B1.2].~A() (Implicit destructor) +// CHECK: 4: [B6.2].~A() (Implicit destructor) +// CHECK: 5: [B7.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B2 B3 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: +// CHECK: 2: A b; +// CHECK: 3: [B2.2].~A() (Implicit destructor) +// CHECK: 4: [B6.4].~A() (Implicit destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: [B6.4].~A() (Implicit destructor) +// CHECK: T: goto l1; +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B4 ] +// CHECK: 1: UV +// CHECK: T: if [B4.1] +// CHECK: Predecessors (1): B6 +// CHECK: Successors (2): B3 B2 +// CHECK: [ B5 ] +// CHECK: 1: [B6.4].~A() (Implicit destructor) +// CHECK: 2: [B6.2].~A() (Implicit destructor) +// CHECK: T: goto l0; +// CHECK: Predecessors (1): B6 +// CHECK: Successors (1): B6 +// CHECK: [ B6 ] +// CHECK: l0: +// CHECK: 1: +// CHECK: 2: A b; +// CHECK: 3: +// CHECK: 4: A a; +// CHECK: 5: UV +// CHECK: T: if [B6.5] +// CHECK: Predecessors (2): B7 B5 +// CHECK: Successors (2): B5 B4 +// CHECK: [ B7 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: Predecessors (1): B8 +// CHECK: Successors (1): B6 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B5 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B4 +// CHECK: [ B1 ] +// CHECK: 1: [B4.4].~A() (Implicit destructor) +// CHECK: 2: [B4.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B2 B3 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: [B2.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: [B3.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B4 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: 3: a +// CHECK: 4: if ([B4.6]) +// CHECK:[B3.2]else +// CHECK:[B2.2] 5: b.operator int() +// CHECK: 6: [B4.5] +// CHECK: T: if [B4.6] +// CHECK: Predecessors (1): B5 +// CHECK: Successors (2): B3 B2 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B9 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B8 +// CHECK: [ B1 ] +// CHECK: 1: [B8.4].~A() (Implicit destructor) +// CHECK: 2: +// CHECK: 3: A e; +// CHECK: 4: [B1.3].~A() (Implicit destructor) +// CHECK: 5: [B8.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B2 B5 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: +// CHECK: 2: A d; +// CHECK: 3: [B2.2].~A() (Implicit destructor) +// CHECK: 4: [B4.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: return; +// CHECK: 2: [B4.2].~A() (Implicit destructor) +// CHECK: 3: [B8.4].~A() (Implicit destructor) +// CHECK: 4: [B8.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B0 +// CHECK: [ B4 ] +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: UV +// CHECK: T: if [B4.3] +// CHECK: Predecessors (1): B8 +// CHECK: Successors (2): B3 B2 +// CHECK: [ B5 ] +// CHECK: 1: +// CHECK: 2: A d; +// CHECK: 3: [B5.2].~A() (Implicit destructor) +// CHECK: 4: [B7.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B1 +// CHECK: [ B6 ] +// CHECK: 1: return; +// CHECK: 2: [B7.2].~A() (Implicit destructor) +// CHECK: 3: [B8.4].~A() (Implicit destructor) +// CHECK: 4: [B8.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B0 +// CHECK: [ B7 ] +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: UV +// CHECK: T: if [B7.3] +// CHECK: Predecessors (1): B8 +// CHECK: Successors (2): B6 B5 +// CHECK: [ B8 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: 3: a +// CHECK: 4: if ([B8.6]) { +// CHECK:[B7.2] if ([B7.3]) +// CHECK:[B6.1][B5.2]} else { +// CHECK:[B4.2] if ([B4.3]) +// CHECK:[B3.1][B2.2]} +// CHECK: 5: b.operator int() +// CHECK: 6: [B8.5] +// CHECK: T: if [B8.6] +// CHECK: Predecessors (1): B9 +// CHECK: Successors (2): B7 B4 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (3): B1 B3 B6 +// CHECK: Successors (0): +// CHECK: [ B6 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B5 +// CHECK: [ B1 ] +// CHECK: 1: [B2.2].~A() (Implicit destructor) +// CHECK: 2: [B5.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: a +// CHECK: 2: while ([B2.4]) +// CHECK:[B4.2] 3: b.operator int() +// CHECK: 4: [B2.3] +// CHECK: T: while [B2.4] +// CHECK: Predecessors (2): B3 B5 +// CHECK: Successors (2): B4 B1 +// CHECK: [ B3 ] +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B2 +// CHECK: [ B4 ] +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: [B4.2].~A() (Implicit destructor) +// CHECK: 4: [B2.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B3 +// CHECK: [ B5 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: Predecessors (1): B6 +// CHECK: Successors (1): B2 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B12 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B11 +// CHECK: [ B1 ] +// CHECK: 1: [B2.2].~A() (Implicit destructor) +// CHECK: 2: +// CHECK: 3: A e; +// CHECK: 4: [B1.3].~A() (Implicit destructor) +// CHECK: 5: [B11.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B9 B2 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: a +// CHECK: 2: while ([B2.4]) +// CHECK: { +// CHECK:[B10.2] if ([B10.3]) +// CHECK: break; +// CHECK: if ([B8.1]) +// CHECK: continue; +// CHECK: if ([B6.1]) +// CHECK:[B5.1][B4.2] } +// CHECK: 3: b.operator int() +// CHECK: 4: [B2.3] +// CHECK: T: while [B2.4] +// CHECK: Predecessors (2): B3 B11 +// CHECK: Successors (2): B10 B1 +// CHECK: [ B3 ] +// CHECK: Predecessors (2): B4 B7 +// CHECK: Successors (1): B2 +// CHECK: [ B4 ] +// CHECK: 1: +// CHECK: 2: A d; +// CHECK: 3: [B4.2].~A() (Implicit destructor) +// CHECK: 4: [B10.2].~A() (Implicit destructor) +// CHECK: 5: [B2.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B6 +// CHECK: Successors (1): B3 +// CHECK: [ B5 ] +// CHECK: 1: return; +// CHECK: 2: [B10.2].~A() (Implicit destructor) +// CHECK: 3: [B2.2].~A() (Implicit destructor) +// CHECK: 4: [B11.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B6 +// CHECK: Successors (1): B0 +// CHECK: [ B6 ] +// CHECK: 1: UV +// CHECK: T: if [B6.1] +// CHECK: Predecessors (1): B8 +// CHECK: Successors (2): B5 B4 +// CHECK: [ B7 ] +// CHECK: 1: [B10.2].~A() (Implicit destructor) +// CHECK: 2: [B2.2].~A() (Implicit destructor) +// CHECK: T: continue; +// CHECK: Predecessors (1): B8 +// CHECK: Successors (1): B3 +// CHECK: [ B8 ] +// CHECK: 1: UV +// CHECK: T: if [B8.1] +// CHECK: Predecessors (1): B10 +// CHECK: Successors (2): B7 B6 +// CHECK: [ B9 ] +// CHECK: 1: [B10.2].~A() (Implicit destructor) +// CHECK: T: break; +// CHECK: Predecessors (1): B10 +// CHECK: Successors (1): B1 +// CHECK: [ B10 ] +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: UV +// CHECK: T: if [B10.3] +// CHECK: Predecessors (1): B2 +// CHECK: Successors (2): B9 B8 +// CHECK: [ B11 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: Predecessors (1): B12 +// CHECK: Successors (1): B2 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (2): B1 B5 +// CHECK: Successors (0): +// CHECK: [ B4 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B2 +// CHECK: [ B1 ] +// CHECK: 1: UV +// CHECK: T: do ... while [B1.1] +// CHECK: Predecessors (1): B2 +// CHECK: Successors (2): B3 B0 +// CHECK: [ B2 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: 3: [B2.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B3 B4 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (1): B2 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B12 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B11 +// CHECK: [ B1 ] +// CHECK: 1: +// CHECK: 2: A d; +// CHECK: 3: [B1.2].~A() (Implicit destructor) +// CHECK: 4: [B11.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B8 B2 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: UV +// CHECK: T: do ... while [B2.1] +// CHECK: Predecessors (2): B3 B6 +// CHECK: Successors (2): B10 B1 +// CHECK: [ B3 ] +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: [B3.2].~A() (Implicit destructor) +// CHECK: 4: [B9.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B5 +// CHECK: Successors (1): B2 +// CHECK: [ B4 ] +// CHECK: 1: return; +// CHECK: 2: [B9.2].~A() (Implicit destructor) +// CHECK: 3: [B11.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B5 +// CHECK: Successors (1): B0 +// CHECK: [ B5 ] +// CHECK: 1: UV +// CHECK: T: if [B5.1] +// CHECK: Predecessors (1): B7 +// CHECK: Successors (2): B4 B3 +// CHECK: [ B6 ] +// CHECK: 1: [B9.2].~A() (Implicit destructor) +// CHECK: T: continue; +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B2 +// CHECK: [ B7 ] +// CHECK: 1: UV +// CHECK: T: if [B7.1] +// CHECK: Predecessors (1): B9 +// CHECK: Successors (2): B6 B5 +// CHECK: [ B8 ] +// CHECK: 1: [B9.2].~A() (Implicit destructor) +// CHECK: T: break; +// CHECK: Predecessors (1): B9 +// CHECK: Successors (1): B1 +// CHECK: [ B9 ] +// CHECK: 1: +// CHECK: 2: A b; +// CHECK: 3: UV +// CHECK: T: if [B9.3] +// CHECK: Predecessors (2): B10 B11 +// CHECK: Successors (2): B8 B7 +// CHECK: [ B10 ] +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B9 +// CHECK: [ B11 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: Predecessors (1): B12 +// CHECK: Successors (1): B9 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (2): B1 B4 +// CHECK: Successors (0): +// CHECK: [ B4 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B2 +// CHECK: [ B1 ] +// CHECK: 1: [B2.4].~A() (Implicit destructor) +// CHECK: 2: [B2.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B3 B2 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: 3: a +// CHECK: 4: switch ([B2.5]) +// CHECK:[B3.2] 5: b.operator int() +// CHECK: T: switch [B2.5] +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: [B3.2].~A() (Implicit destructor) +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B9 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B2 +// CHECK: [ B1 ] +// CHECK: 1: [B2.4].~A() (Implicit destructor) +// CHECK: 2: +// CHECK: 3: A g; +// CHECK: 4: [B1.3].~A() (Implicit destructor) +// CHECK: 5: [B2.2].~A() (Implicit destructor) +// CHECK: Predecessors (3): B3 B7 B2 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: 3: a +// CHECK: 4: switch ([B2.5]) { +// CHECK: case 0: +// CHECK: { +// CHECK:[B8.2] if ([B8.3]) +// CHECK: break; +// CHECK: if ([B6.1]) +// CHECK:[B5.1][B4.2] } +// CHECK: case 1: +// CHECK: break; +// CHECK:} +// CHECK: 5: b.operator int() +// CHECK: T: switch [B2.5] +// CHECK: Predecessors (1): B9 +// CHECK: Successors (3): B3 B8 +// CHECK: B1 +// CHECK: [ B3 ] +// CHECK: case 1: +// CHECK: T: break; +// CHECK: Predecessors (2): B2 B4 +// CHECK: Successors (1): B1 +// CHECK: [ B4 ] +// CHECK: 1: +// CHECK: 2: A f; +// CHECK: 3: [B4.2].~A() (Implicit destructor) +// CHECK: 4: [B8.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B6 +// CHECK: Successors (1): B3 +// CHECK: [ B5 ] +// CHECK: 1: return; +// CHECK: 2: [B8.2].~A() (Implicit destructor) +// CHECK: 3: [B2.4].~A() (Implicit destructor) +// CHECK: 4: [B2.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B6 +// CHECK: Successors (1): B0 +// CHECK: [ B6 ] +// CHECK: 1: UV +// CHECK: T: if [B6.1] +// CHECK: Predecessors (1): B8 +// CHECK: Successors (2): B5 B4 +// CHECK: [ B7 ] +// CHECK: 1: [B8.2].~A() (Implicit destructor) +// CHECK: T: break; +// CHECK: Predecessors (1): B8 +// CHECK: Successors (1): B1 +// CHECK: [ B8 ] +// CHECK: case 0: +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: UV +// CHECK: T: if [B8.3] +// CHECK: Predecessors (1): B2 +// CHECK: Successors (2): B7 B6 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (2): B1 B5 +// CHECK: Successors (0): +// CHECK: [ B6 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B5 +// CHECK: [ B1 ] +// CHECK: 1: [B2.2].~A() (Implicit destructor) +// CHECK: 2: [B5.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: a +// CHECK: 2: for (A a; [B2.4];) +// CHECK:[B4.2] 3: b.operator int() +// CHECK: 4: [B2.3] +// CHECK: T: for (...; [B2.4]; ) +// CHECK: Predecessors (2): B3 B5 +// CHECK: Successors (2): B4 B1 +// CHECK: [ B3 ] +// CHECK: 1: [B2.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B2 +// CHECK: [ B4 ] +// CHECK: 1: +// CHECK: 2: A c; +// CHECK: 3: [B4.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B3 +// CHECK: [ B5 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: Predecessors (1): B6 +// CHECK: Successors (1): B2 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B12 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B11 +// CHECK: [ B1 ] +// CHECK: 1: [B2.2].~A() (Implicit destructor) +// CHECK: 2: [B11.4].~A() (Implicit destructor) +// CHECK: 3: +// CHECK: 4: A f; +// CHECK: 5: [B1.4].~A() (Implicit destructor) +// CHECK: 6: [B11.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B9 B2 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: b +// CHECK: 2: for (A b; [B2.4];) { +// CHECK:[B10.2] if ([B10.3]) +// CHECK: break; +// CHECK: if ([B8.1]) +// CHECK: continue; +// CHECK: if ([B6.1]) +// CHECK:[B5.1][B4.2]} +// CHECK: 3: c.operator int() +// CHECK: 4: [B2.3] +// CHECK: T: for (...; [B2.4]; ) +// CHECK: Predecessors (2): B3 B11 +// CHECK: Successors (2): B10 B1 +// CHECK: [ B3 ] +// CHECK: 1: [B2.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B4 B7 +// CHECK: Successors (1): B2 +// CHECK: [ B4 ] +// CHECK: 1: +// CHECK: 2: A e; +// CHECK: 3: [B4.2].~A() (Implicit destructor) +// CHECK: 4: [B10.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B6 +// CHECK: Successors (1): B3 +// CHECK: [ B5 ] +// CHECK: 1: return; +// CHECK: 2: [B10.2].~A() (Implicit destructor) +// CHECK: 3: [B2.2].~A() (Implicit destructor) +// CHECK: 4: [B11.4].~A() (Implicit destructor) +// CHECK: 5: [B11.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B6 +// CHECK: Successors (1): B0 +// CHECK: [ B6 ] +// CHECK: 1: UV +// CHECK: T: if [B6.1] +// CHECK: Predecessors (1): B8 +// CHECK: Successors (2): B5 B4 +// CHECK: [ B7 ] +// CHECK: 1: [B10.2].~A() (Implicit destructor) +// CHECK: T: continue; +// CHECK: Predecessors (1): B8 +// CHECK: Successors (1): B3 +// CHECK: [ B8 ] +// CHECK: 1: UV +// CHECK: T: if [B8.1] +// CHECK: Predecessors (1): B10 +// CHECK: Successors (2): B7 B6 +// CHECK: [ B9 ] +// CHECK: 1: [B10.2].~A() (Implicit destructor) +// CHECK: T: break; +// CHECK: Predecessors (1): B10 +// CHECK: Successors (1): B1 +// CHECK: [ B10 ] +// CHECK: 1: +// CHECK: 2: A d; +// CHECK: 3: UV +// CHECK: T: if [B10.3] +// CHECK: Predecessors (1): B2 +// CHECK: Successors (2): B9 B8 +// CHECK: [ B11 ] +// CHECK: 1: +// CHECK: 2: A a; +// CHECK: 3: +// CHECK: 4: A b; +// CHECK: Predecessors (1): B12 +// CHECK: Successors (1): B2 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (2): B1 B5 +// CHECK: Successors (0): +// CHECK: [ B3 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B0 +// CHECK: [ B1 ] +// CHECK: T: try ... +// CHECK: Predecessors (0): +// CHECK: Successors (2): B2 B0 +// CHECK: [ B2 ] +// CHECK: catch (const A &e): +// CHECK: Predecessors (1): B1 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (3): B2 B1 B3 +// CHECK: Successors (0): +// CHECK: [ B3 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B0 +// CHECK: [ B1 ] +// CHECK: T: try ... +// CHECK: Predecessors (0): +// CHECK: Successors (2): B2 B0 +// CHECK: [ B2 ] +// CHECK: catch (A e): +// CHECK: 1: .~A() (Implicit destructor) +// CHECK: Predecessors (1): B1 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (3): B2 B1 B3 +// CHECK: Successors (0): diff --git a/test/Analysis/base-init.cpp b/test/Analysis/base-init.cpp new file mode 100644 index 0000000000000..800763b25b499 --- /dev/null +++ b/test/Analysis/base-init.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -analyzer-inline-call -cfg-add-initializers -verify %s + +class A { + int x; +public: + A(); + int getx() const { + return x; + } +}; + +A::A() : x(0) { +} + +class B : public A { + int y; +public: + B(); +}; + +B::B() { +} + +void f() { + B b; + if (b.getx() != 0) { + int *p = 0; + *p = 0; // no-warning + } +} diff --git a/test/Analysis/blocks.m b/test/Analysis/blocks.m index b05b198c5489c..e18d7cfb7be6b 100644 --- a/test/Analysis/blocks.m +++ b/test/Analysis/blocks.m @@ -73,7 +73,7 @@ void test1(NSString *format, ...) { void test2() { static int y = 0; int x; - ^{ y = x + 1; }(); // expected-warning{{Variable 'x' is captured by block with a garbage value}} + ^{ y = x + 1; }(); // expected-warning{{Variable 'x' is uninitialized when captured by block}} } void test2_b() { @@ -86,5 +86,5 @@ void test2_b() { void test2_c() { typedef void (^myblock)(void); - myblock f = ^() { f(); }; // expected-warning{{Variable 'f' is captured by block with a garbage value}} + myblock f = ^() { f(); }; // expected-warning{{Variable 'f' is uninitialized when captured by block}} }
\ No newline at end of file diff --git a/test/Analysis/bstring.c b/test/Analysis/bstring.c index ffe420f725171..eb235430aac05 100644 --- a/test/Analysis/bstring.c +++ b/test/Analysis/bstring.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s -// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s -// RUN: %clang_cc1 -analyze -DVARIANT -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s -// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -DVARIANT -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.CString -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-checker=core.experimental.CString -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s +// RUN: %clang_cc1 -analyze -DVARIANT -analyzer-checker=core.experimental.CString -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -DVARIANT -analyzer-checker=core.experimental.CString -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s //===----------------------------------------------------------------------=== // Declarations diff --git a/test/Analysis/chroot.c b/test/Analysis/chroot.c new file mode 100644 index 0000000000000..5b98a7197408a --- /dev/null +++ b/test/Analysis/chroot.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-checker=unix.experimental.Chroot -analyzer-store region -verify %s + +extern int chroot(const char* path); +extern int chdir(const char* path); + +void foo(void) { +} + +void f1(void) { + chroot("/usr/local"); // root changed. + foo(); // expected-warning {{No call of chdir("/") immediately after chroot}} +} + +void f2(void) { + chroot("/usr/local"); // root changed. + chdir("/"); // enter the jail. + foo(); // no-warning +} + +void f3(void) { + chroot("/usr/local"); // root changed. + chdir("../"); // change working directory, still out of jail. + foo(); // expected-warning {{No call of chdir("/") immediately after chroot}} +} diff --git a/test/Analysis/complex.c b/test/Analysis/complex.c index bb2b2fe7292e7..1a33349960fb3 100644 --- a/test/Analysis/complex.c +++ b/test/Analysis/complex.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify -Wno-unreachable-code %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -Wno-unreachable-code %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -Wno-unreachable-code %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify -Wno-unreachable-code -ffreestanding %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -Wno-unreachable-code -ffreestanding %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -Wno-unreachable-code -ffreestanding %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -Wno-unreachable-code -ffreestanding %s #include <stdint.h> diff --git a/test/Analysis/conditional-op-missing-lhs.c b/test/Analysis/conditional-op-missing-lhs.c index 86882a5ac4b60..e738964194d9b 100644 --- a/test/Analysis/conditional-op-missing-lhs.c +++ b/test/Analysis/conditional-op-missing-lhs.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -warn-uninit-values -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-checker=core.DeadStores -warn-uninit-values -verify %s void f1() { diff --git a/test/Analysis/constant-folding.c b/test/Analysis/constant-folding.c index 9191a9e0578ec..bb339f6957a1d 100644 --- a/test/Analysis/constant-folding.c +++ b/test/Analysis/constant-folding.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-experimental-checks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-checker=core.experimental.UnreachableCode -analyzer-check-objc-mem -analyzer-experimental-checks -verify %s // Trigger a warning if the analyzer reaches this point in the control flow. #define WARN ((void)*(char*)0) diff --git a/test/Analysis/cxx-crashes.cpp b/test/Analysis/cxx-crashes.cpp new file mode 100644 index 0000000000000..c9775df7e2d06 --- /dev/null +++ b/test/Analysis/cxx-crashes.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -verify %s + +int f1(char *dst) { + char *p = dst + 4; + char *q = dst + 3; + return !(q >= p); +} + +long f2(char *c) { + return long(c) & 1; +} + +bool f3() { + return !false; +} + +void *f4(int* w) { + return reinterpret_cast<void*&>(w); +} + +namespace { + +struct A { }; +struct B { + operator A() { return A(); } +}; + +A f(char *dst) { + B b; + return b; +} + +} + +namespace { + +struct S { + void *p; +}; + +void *f(S* w) { + return &reinterpret_cast<void*&>(*w); +} + +} diff --git a/test/Analysis/dead-stores.c b/test/Analysis/dead-stores.c index 57d5d112d717b..7fc0f0464d727 100644 --- a/test/Analysis/dead-stores.c +++ b/test/Analysis/dead-stores.c @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-check-dead-stores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.DeadStores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -analyzer-checker=core.DeadStores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -analyzer-checker=core.DeadStores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -analyzer-checker=core.DeadStores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-checker=core.DeadStores -fblocks -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s void f1() { int k, y; // expected-warning{{unused variable 'k'}} expected-warning{{unused variable 'y'}} @@ -13,7 +13,7 @@ void f1() { void f2(void *b) { char *c = (char*)b; // no-warning char *d = b+1; // expected-warning {{never read}} expected-warning{{unused variable 'd'}} - printf("%s", c); // expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \ + printf("%s", c); // expected-warning{{implicitly declaring C library function 'printf' with type 'int (const char *, ...)'}} \ // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}} } @@ -44,10 +44,11 @@ void f5() { } +// int f6() { int x = 4; - ++x; // expected-warning{{never read}} + ++x; // no-warning return 1; } @@ -75,9 +76,11 @@ int f7d(int *p) { return 1; } +// Don't warn for dead stores in nested expressions. We have yet +// to see a real bug in this scenario. int f8(int *p) { extern int *baz(); - if ((p = baz())) // expected-warning{{Although the value}} + if ((p = baz())) // no-warning return 1; return 0; } @@ -148,9 +151,11 @@ void f15(unsigned x, unsigned y) { int z[count]; // expected-warning{{unused variable 'z'}} } +// Don't warn for dead stores in nested expressions. We have yet +// to see a real bug in this scenario. int f16(int x) { x = x * 2; - x = sizeof(int [x = (x || x + 1) * 2]) // expected-warning{{Although the value stored to 'x' is used}} expected-warning{{The left operand to '*' is always 1}} + x = sizeof(int [x = (x || x + 1) * 2]) // expected-warning{{The left operand to '+' is always 0}} expected-warning{{The left operand to '*' is always 1}} ? 5 : 8; return x; } @@ -171,11 +176,35 @@ int f18() { x = 10; // expected-warning{{Value stored to 'x' is never read}} while (1) x = 10; // expected-warning{{Value stored to 'x' is never read}} + // unreachable. do - x = 10; // expected-warning{{Value stored to 'x' is never read}} + x = 10; // no-warning while (1); + return (x = 10); // no-warning +} + +int f18_a() { + int x = 0; // no-warning + return (x = 10); // no-warning +} + +void f18_b() { + int x = 0; // no-warning + if (1) + x = 10; // expected-warning{{Value stored to 'x' is never read}} +} + +void f18_c() { + int x = 0; + while (1) + x = 10; // expected-warning{{Value stored to 'x' is never read}} +} - return (x = 10); // expected-warning{{Although the value stored to 'x' is used in the enclosing expression, the value is never actually read from 'x'}} +void f18_d() { + int x = 0; // no-warning + do + x = 10; // expected-warning{{Value stored to 'x' is never read}} + while (1); } // PR 3514: false positive `dead initialization` warning for init to global @@ -203,7 +232,7 @@ void halt() __attribute__((noreturn)); int f21() { int x = 4; - ++x; // expected-warning{{never read}} + x = x + 1; // expected-warning{{never read}} if (1) { halt(); (void)x; @@ -235,7 +264,7 @@ void f22() { int y19 = 4; int y20 = 4; - ++x; // expected-warning{{never read}} + x = x + 1; // expected-warning{{never read}} ++y1; ++y2; ++y3; @@ -486,3 +515,16 @@ void rdar8320674(s_rdar8320674 *z, unsigned y, s2_rdar8320674 *st, int m) }while (--m); } +// Avoid dead stores resulting from an assignment (and use) being unreachable. +void rdar8405222_aux(int i); +void rdar8405222() { + const int show = 0; + int i = 0; + + if (show) + i = 5; // no-warning + + if (show) + rdar8405222_aux(i); +} + diff --git a/test/Analysis/dead-stores.cpp b/test/Analysis/dead-stores.cpp index b21ffad6c5f07..59a48bada1b30 100644 --- a/test/Analysis/dead-stores.cpp +++ b/test/Analysis/dead-stores.cpp @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -verify -Wno-unreachable-code %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -analyzer-check-dead-stores -verify -Wno-unreachable-code %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -analyzer-check-dead-stores -verify -Wno-unreachable-code %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -analyzer-check-dead-stores -verify -Wno-unreachable-code %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-check-dead-stores -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -fexceptions -analyze -analyzer-experimental-internal-checks -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -fexceptions -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -fexceptions -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -fexceptions -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code %s +// RUN: %clang_cc1 -fexceptions -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-checker=core.DeadStores -verify -Wno-unreachable-code %s //===----------------------------------------------------------------------===// // Basic dead store checking (but in C++ mode). @@ -12,7 +12,7 @@ int j; void test1() { int x = 4; - ++x; // expected-warning{{never read}} + x = x + 1; // expected-warning{{never read}} switch (j) { case 1: @@ -69,11 +69,11 @@ void test2_b() { //===----------------------------------------------------------------------===// void test3_a(int x) { - ++x; // expected-warning{{never read}} + x = x + 1; // expected-warning{{never read}} } void test3_b(int &x) { - ++x; // no-warninge + x = x + 1; // no-warninge } void test3_c(int x) { @@ -100,3 +100,15 @@ static void test_new(unsigned n) { char **p = new char* [n]; // expected-warning{{never read}} } +//===----------------------------------------------------------------------===// +// Dead stores in namespaces. +//===----------------------------------------------------------------------===// + +namespace foo { + int test_4(int x) { + x = 2; // expected-warning{{Value stored to 'x' is never read}} + x = 2; + return x; + } +} + diff --git a/test/Analysis/dead-stores.m b/test/Analysis/dead-stores.m index 701e5802b25e5..00c9e53d25256 100644 --- a/test/Analysis/dead-stores.m +++ b/test/Analysis/dead-stores.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-checker=core.DeadStores -verify %s typedef signed char BOOL; typedef unsigned int NSUInteger; @@ -41,3 +41,38 @@ void DeadStoreTest(NSObject *anObject) { void rdar_7631278(NSObject *x) { x = ((void*)0); } + +// This test case issuing a bogus warning for the declaration of 'isExec' +// because the compound statement for the @synchronized was being visited +// twice by the LiveVariables analysis. +BOOL baz_rdar8527823(); +void foo_rdar8527823(); +@interface RDar8527823 +- (void) bar_rbar8527823; +@end +@implementation RDar8527823 +- (void) bar_rbar8527823 +{ + @synchronized(self) { + BOOL isExec = baz_rdar8527823(); // no-warning + if (isExec) foo_rdar8527823(); + } +} +@end + +// Don't flag dead stores to assignments to self within a nested assignment. +@interface Rdar7947686 +- (id) init; +@end + +@interface Rdar7947686_B : Rdar7947686 +- (id) init; +@end + +@implementation Rdar7947686_B +- (id) init { + id x = (self = [super init]); // no-warning + return x; +} +@end + diff --git a/test/Analysis/derived-to-base.cpp b/test/Analysis/derived-to-base.cpp new file mode 100644 index 0000000000000..2a9244ef34b21 --- /dev/null +++ b/test/Analysis/derived-to-base.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region %s + +class A { +protected: + int x; +}; + +class B : public A { +public: + void f(); +}; + +void B::f() { + x = 3; +} diff --git a/test/Analysis/dtor.cpp b/test/Analysis/dtor.cpp new file mode 100644 index 0000000000000..ea5b04684d7f6 --- /dev/null +++ b/test/Analysis/dtor.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -analyzer-inline-call -cfg-add-implicit-dtors -verify %s + +class A { +public: + ~A() { + int *x = 0; + *x = 3; // expected-warning{{Dereference of null pointer}} + } +}; + +int main() { + A a; +} diff --git a/test/Analysis/dtors-in-dtor-cfg-output.cpp b/test/Analysis/dtors-in-dtor-cfg-output.cpp new file mode 100644 index 0000000000000..7765483180030 --- /dev/null +++ b/test/Analysis/dtors-in-dtor-cfg-output.cpp @@ -0,0 +1,60 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -cfg-add-implicit-dtors %s 2>&1 | FileCheck %s +// XPASS: * + +class A { +public: + ~A() {} +}; + +class B : public virtual A { +public: + ~B() {} +}; + +class C : public virtual A { +public: + ~C() {} +}; + +class TestOrder : public C, public B, public virtual A { + A a; + int i; + A *p; +public: + ~TestOrder(); +}; + +TestOrder::~TestOrder() {} + +class TestArray { + A a[2]; + A b[0]; +public: + ~TestArray(); +}; + +TestArray::~TestArray() {} + +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: this->a.~A() (Member object destructor) +// CHECK: 2: ~B() (Base object destructor) +// CHECK: 3: ~C() (Base object destructor) +// CHECK: 4: ~A() (Base object destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: this->a.~A() (Member object destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): diff --git a/test/Analysis/exercise-ps.c b/test/Analysis/exercise-ps.c index 0a95b7055601c..196b67936a9ce 100644 --- a/test/Analysis/exercise-ps.c +++ b/test/Analysis/exercise-ps.c @@ -19,6 +19,6 @@ void_typedef f2_helper(); static void f2(void *buf) { F12_typedef* x; x = f2_helper(); - memcpy((&x[1]), (buf), 1); // expected-warning{{implicitly declaring C library function 'memcpy' with type 'void *(void *, void const *}} \ + memcpy((&x[1]), (buf), 1); // expected-warning{{implicitly declaring C library function 'memcpy' with type 'void *(void *, const void *}} \ // expected-note{{please include the header <string.h> or explicitly provide a declaration for 'memcpy'}} } diff --git a/test/Analysis/fields.c b/test/Analysis/fields.c index c97d4f82cdc0b..0827f3dbad18d 100644 --- a/test/Analysis/fields.c +++ b/test/Analysis/fields.c @@ -17,3 +17,13 @@ void f() { struct s a; int *p = &(a.n) + 1; } + +typedef struct { + int x,y; +} Point; + +Point getit(void); +void test() { + Point p; + (void)(p = getit()).x; +} diff --git a/test/Analysis/idempotent-operations-limited-loops.c b/test/Analysis/idempotent-operations-limited-loops.c new file mode 100644 index 0000000000000..e4c34cdead35d --- /dev/null +++ b/test/Analysis/idempotent-operations-limited-loops.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -analyzer-max-loop 3 -verify %s +// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -analyzer-max-loop 4 -verify %s +// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps %s -verify + +void always_warning() { int *p = 0; *p = 0xDEADBEEF; } // expected-warning{{Dereference of null pointer (loaded from variable 'p')}} + +// This test case previously caused a bogus idempotent operation warning +// due to us not properly culling warnings due to incomplete analysis of loops. +int pr8403() +{ + int i; + for(i=0; i<10; i++) + { + int j; + for(j=0; j+1<i; j++) + { + } + } + return 0; +} + diff --git a/test/Analysis/idempotent-operations.c b/test/Analysis/idempotent-operations.c index 5c9a59d736166..b47394c1626bc 100644 --- a/test/Analysis/idempotent-operations.c +++ b/test/Analysis/idempotent-operations.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-check-idempotent-operations -verify %s +// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -verify %s // Basic tests @@ -187,3 +187,50 @@ int false7() { return a; } + +// Check truncations do not flag as self-assignments +void false8() { + int a = 10000000; + a = (short)a; // no-warning + test(a); +} + +// This test case previously flagged a warning at 'b == c' because the +// analyzer previously allowed 'UnknownVal' as the index for ElementRegions. +typedef struct RDar8431728_F { + int RDar8431728_A; + unsigned char *RDar8431728_B; + int RDar8431728_E[6]; +} RDar8431728_D; +static inline int RDar8431728_C(RDar8431728_D * s, int n, + unsigned char **RDar8431728_B_ptr) { + int xy, wrap, pred, a, b, c; + + xy = s->RDar8431728_E[n]; + wrap = s->RDar8431728_A; + + a = s->RDar8431728_B[xy - 1]; + b = s->RDar8431728_B[xy - 1 - wrap]; + c = s->RDar8431728_B[xy - wrap]; + + if (b == c) { // no-warning + pred = a; + } else { + pred = c; + } + + *RDar8431728_B_ptr = &s->RDar8431728_B[xy]; + + return pred; +} + +// <rdar://problem/8601243> - Don't warn on pointer arithmetic. This +// is often idiomatic. +unsigned rdar8601243_aux(unsigned n); +void rdar8601243() { + char arr[100]; + char *start = arr; + start = start + rdar8601243_aux(sizeof(arr) - (arr - start)); // no-warning + (void) start; +} + diff --git a/test/Analysis/idempotent-operations.cpp b/test/Analysis/idempotent-operations.cpp index c5d1ceb8aff02..c213dc690e440 100644 --- a/test/Analysis/idempotent-operations.cpp +++ b/test/Analysis/idempotent-operations.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-check-idempotent-operations -verify %s +// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -verify %s // C++ specific false positives diff --git a/test/Analysis/idempotent-operations.m b/test/Analysis/idempotent-operations.m new file mode 100644 index 0000000000000..a77e2cbf8719a --- /dev/null +++ b/test/Analysis/idempotent-operations.m @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -verify %s + +typedef signed char BOOL; +typedef unsigned long NSUInteger; +typedef struct _NSZone NSZone; +@protocol NSObject - (BOOL)isEqual:(id)object; +@end + +@interface NSObject {} + @property int locked; + @property(nonatomic, readonly) NSObject *media; +@end + +// <rdar://problem/8725041> - Don't flag idempotent operation warnings when +// a method may invalidate an instance variable. +@interface Rdar8725041 : NSObject { + id _attribute; +} + - (void) method2; +@end + +@implementation Rdar8725041 +- (BOOL) method1 { + BOOL needsUpdate = (BOOL)0; + id oldAttribute = _attribute; + [self method2]; + needsUpdate |= (_attribute != oldAttribute); // no-warning + return needsUpdate; +} + +- (void) method2 +{ + _attribute = ((void*)0); +} +@end + +// Test that the idempotent operations checker works in the prescence +// of property expressions. +void pr9116(NSObject *placeholder) { + int x = placeholder.media.locked = placeholder ? 1 : 0; +} + diff --git a/test/Analysis/initializer.cpp b/test/Analysis/initializer.cpp new file mode 100644 index 0000000000000..2fa3a9eb86a7b --- /dev/null +++ b/test/Analysis/initializer.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -cfg-add-initializers -verify %s + +class A { + int x; +public: + A(); +}; + +A::A() : x(0) { + if (x != 0) { + int *p = 0; + *p = 0; // no-warning + } +} diff --git a/test/Analysis/initializers-cfg-output.cpp b/test/Analysis/initializers-cfg-output.cpp new file mode 100644 index 0000000000000..5c5d51494749d --- /dev/null +++ b/test/Analysis/initializers-cfg-output.cpp @@ -0,0 +1,94 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -cfg-add-initializers %s 2>&1 | FileCheck %s +// XPASS: * + +class A { +public: + A() {} + A(int i) {} +}; + +class B : public virtual A { +public: + B() {} + B(int i) : A(i) {} +}; + +class C : public virtual A { +public: + C() {} + C(int i) : A(i) {} +}; + +class TestOrder : public C, public B, public A { + int i; + int& r; +public: + TestOrder(); +}; + +TestOrder::TestOrder() + : r(i), B(), i(), C() { + A a; +} + +class TestControlFlow { + int x, y, z; +public: + TestControlFlow(bool b); +}; + +TestControlFlow::TestControlFlow(bool b) + : y(b ? 0 : 1) + , x(0) + , z(y) { + int v; +} + +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: +// CHECK: 2: A([B1.1]) (Base initializer) +// CHECK: 3: +// CHECK: 4: C([B1.3]) (Base initializer) +// CHECK: 5: +// CHECK: 6: B([B1.5]) (Base initializer) +// CHECK: 7: +// CHECK: 8: A([B1.7]) (Base initializer) +// CHECK: 9: i(/*implicit*/int()) (Member initializer) +// CHECK: 10: r(this->i) (Member initializer) +// CHECK: 11: +// CHECK: 12: A a; +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B5 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B4 +// CHECK: [ B1 ] +// CHECK: 1: [B4.2] ? [B2.1] : [B3.1] +// CHECK: 2: y([B1.1]) (Member initializer) +// CHECK: 3: z(this->y) (Member initializer) +// CHECK: 4: int v; +// CHECK: Predecessors (2): B2 B3 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: 0 +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: 1 +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B4 ] +// CHECK: 1: x(0) (Member initializer) +// CHECK: 2: b +// CHECK: T: [B4.2] ? ... : ... +// CHECK: Predecessors (1): B5 +// CHECK: Successors (2): B2 B3 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): diff --git a/test/Analysis/inline.c b/test/Analysis/inline.c index 50c1a54d1016c..d7a599a76545a 100644 --- a/test/Analysis/inline.c +++ b/test/Analysis/inline.c @@ -1,14 +1,14 @@ // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-inline-call -analyzer-store region -verify %s -int f1() { +int test1_f1() { int y = 1; y++; return y; } -void f2() { +void test1_f2() { int x = 1; - x = f1(); + x = test1_f1(); if (x == 1) { int *p = 0; *p = 3; // no-warning @@ -18,3 +18,13 @@ void f2() { *p = 3; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}} } } + +// Test that inlining works when the declared function has less arguments +// than the actual number in the declaration. +void test2_f1() {} +int test2_f2(); + +void test2_f3() { + test2_f1(test2_f2()); // expected-warning{{too many arguments in call to 'test2_f1'}} +} + diff --git a/test/Analysis/lvalue.cpp b/test/Analysis/lvalue.cpp new file mode 100644 index 0000000000000..f19c59d9d2586 --- /dev/null +++ b/test/Analysis/lvalue.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s + +int f1() { + int x = 0, y = 1; + return x += y; // Should bind a location to 'x += y'. No crash. +} diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index e443150e1fbb8..fdfccab204cef 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-experimental-checks -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-checker=core.experimental.UnreachableCode -analyzer-check-objc-mem -analyzer-experimental-checks -analyzer-store=region -verify %s typedef __typeof(sizeof(int)) size_t; void *malloc(size_t); void free(void *); diff --git a/test/Analysis/method-call.cpp b/test/Analysis/method-call.cpp index 47f14447d6bd0..b5b81e3402a1a 100644 --- a/test/Analysis/method-call.cpp +++ b/test/Analysis/method-call.cpp @@ -1,8 +1,10 @@ // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-inline-call -analyzer-store region -verify %s +// XFAIL: * + struct A { int x; A(int a) { x = a; } - int getx() { return x; } + int getx() const { return x; } }; void f1() { @@ -16,3 +18,24 @@ void f1() { } } +void f2() { + const A &x = A(3); + if (x.getx() == 3) { + int *p = 0; + *p = 3; // expected-warning{{Dereference of null pointer}} + } else { + int *p = 0; + *p = 3; // no-warning + } +} + +void f3() { + const A &x = (A)3; + if (x.getx() == 3) { + int *p = 0; + *p = 3; // expected-warning{{Dereference of null pointer}} + } else { + int *p = 0; + *p = 3; // no-warning + } +} diff --git a/test/Analysis/misc-ps-64.m b/test/Analysis/misc-ps-64.m index 0dbd6cb948b38..f65673eea24fa 100644 --- a/test/Analysis/misc-ps-64.m +++ b/test/Analysis/misc-ps-64.m @@ -14,7 +14,7 @@ typedef unsigned char Boolean; typedef const struct __CFDictionary * CFDictionaryRef; extern Boolean CFDictionaryGetValueIfPresent(CFDictionaryRef theDict, const void *key, const void **value); -static void shazam(NSUInteger i, unsigned char **out); +void shazam(NSUInteger i, unsigned char **out); void rdar_6440393_1(NSDictionary *dict) { NSInteger x = 0; diff --git a/test/Analysis/misc-ps-region-store.cpp b/test/Analysis/misc-ps-region-store.cpp index bfa5e5cbb9b07..1dba09d76ddc4 100644 --- a/test/Analysis/misc-ps-region-store.cpp +++ b/test/Analysis/misc-ps-region-store.cpp @@ -159,3 +159,84 @@ int r8375510(R8375510 x, R8375510 y) { for (; ; x++) { } } +// PR8419 -- this used to crash. + +class String8419 { + public: + char& get(int n); + char& operator[](int n); +}; + +char& get8419(); + +void Test8419() { + String8419 s; + ++(s.get(0)); + get8419()--; // used to crash + --s[0]; // used to crash + s[0] &= 1; // used to crash + s[0]++; // used to crash +} + +// PR8426 -- this used to crash. + +void Use(void* to); + +template <class T> class Foo { + ~Foo(); + struct Bar; + Bar* bar_; +}; + +template <class T> Foo<T>::~Foo() { + Use(bar_); + T::DoSomething(); + bar_->Work(); +} + +// PR8427 -- this used to crash. + +class Dummy {}; + +bool operator==(Dummy, int); + +template <typename T> +class Foo2 { + bool Bar(); +}; + +template <typename T> +bool Foo2<T>::Bar() { + return 0 == T(); +} + +// PR8433 -- this used to crash. + +template <typename T> +class Foo3 { + public: + void Bar(); + void Baz(); + T value_; +}; + +template <typename T> +void Foo3<T>::Bar() { + Baz(); + value_(); +} + +//===---------------------------------------------------------------------===// +// Handle misc. C++ constructs. +//===---------------------------------------------------------------------===// + +namespace fum { + int i = 3; +}; + +void test_namespace() { + // Previously triggered a crash. + using namespace fum; + int x = i; +} + diff --git a/test/Analysis/misc-ps-region-store.m b/test/Analysis/misc-ps-region-store.m index a4e0d0bfa6166..b35a834c33525 100644 --- a/test/Analysis/misc-ps-region-store.m +++ b/test/Analysis/misc-ps-region-store.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -DTEST_64 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-checker=core.experimental.CastToStruct -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -DTEST_64 -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-checker=core.experimental.CastToStruct -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s typedef long unsigned int size_t; void *memcpy(void *, const void *, size_t); @@ -394,7 +394,7 @@ void rdar_7332673_test1() { int rdar_7332673_test2_aux(char *x); void rdar_7332673_test2() { char *value; - if ( rdar_7332673_test2_aux(value) != 1 ) {} // expected-warning{{Pass-by-value argument in function call is undefined}} + if ( rdar_7332673_test2_aux(value) != 1 ) {} // expected-warning{{Function call argument is an uninitialized value}} } //===----------------------------------------------------------------------===// @@ -671,7 +671,7 @@ typedef void (^RDar_7462324_Callback)(id obj); builder = ^(id object) { id x; if (object) { - builder(x); // expected-warning{{Pass-by-value argument in function call is undefined}} + builder(x); // expected-warning{{Function call argument is an uninitialized value}} } }; builder(target); @@ -1103,16 +1103,18 @@ void pr8015_C() { } } -// FIXME: This is a false positive due to not reasoning about symbolic -// array indices correctly. Discussion in PR 8015. +// Tests that we correctly handle that 'number' is perfectly constrained +// after 'if (nunber == 0)', allowing us to resolve that +// numbers[number] == numbers[0]. void pr8015_D_FIXME() { int number = pr8015_A(); const char *numbers[] = { "zero" }; if (number == 0) { - if (numbers[number] == numbers[0]) + if (numbers[number] == numbers[0]) // expected-warning{{Both operands to '==' always have the same value}} return; + // Unreachable. int *p = 0; - *p = 0xDEADBEEF; // expected-warning{{Dereference of null pointer}} + *p = 0xDEADBEEF; // no-warnng } } @@ -1140,3 +1142,98 @@ void pr8015_F_FIXME() { } } +// PR 8141. Previously the statement expression in the for loop caused +// the CFG builder to crash. +struct list_pr8141 +{ + struct list_pr8141 *tail; +}; + +struct list_pr8141 * +pr8141 (void) { + struct list_pr8141 *items; + for (;; items = ({ do { } while (0); items->tail; })) // expected-warning{{Dereference of undefined pointer value}} + { + } +} + +// Don't crash when building the CFG. +void do_not_crash(int x) { + while (x - ({do {} while (0); x; })) { + } +} + +// <rdar://problem/8424269> - Handle looking at the size of a VLA in +// ArrayBoundChecker. Nothing intelligent (yet); just don't crash. +typedef struct RDar8424269_A { + int RDar8424269_C; +} RDar8424269_A; +static void RDar8424269_B(RDar8424269_A *p, unsigned char *RDar8424269_D, + const unsigned char *RDar8424269_E, int RDar8424269_F, + int b_w, int b_h, int dx, int dy) { + int x, y, b, r, l; + unsigned char tmp2t[3][RDar8424269_F * (32 + 8)]; + unsigned char *tmp2 = tmp2t[0]; + if (p && !p->RDar8424269_C) + b = 15; + tmp2 = tmp2t[1]; + if (b & 2) { // expected-warning{{The left operand of '&' is a garbage value}} + for (y = 0; y < b_h; y++) { + for (x = 0; x < b_w + 1; x++) { + int am = 0; + tmp2[x] = am; + } + } + } + tmp2 = tmp2t[2]; +} + +// <rdar://problem/8642434> - Handle transparent unions with the AttrNonNullChecker. +typedef union { + struct rdar_8642434_typeA *_dq; +} +rdar_8642434_typeB __attribute__((transparent_union)); + +__attribute__((visibility("default"))) __attribute__((__nonnull__)) __attribute__((__nothrow__)) +void rdar_8642434_funcA(rdar_8642434_typeB object); + +void rdar_8642434_funcB(struct rdar_8642434_typeA *x, struct rdar_8642434_typeA *y) { + rdar_8642434_funcA(x); + if (!y) + rdar_8642434_funcA(y); // expected-warning{{Null pointer passed as an argument to a 'nonnull' parameter}} +} + +// <rdar://problem/8848957> - Handle loads and stores from a symbolic index +// into array without warning about an uninitialized value being returned. +// While RegionStore can't fully reason about this example, it shouldn't +// warn here either. +typedef struct s_test_rdar8848957 { + int x, y, z; +} s_test_rdar8848957; + +s_test_rdar8848957 foo_rdar8848957(); +int rdar8848957(int index) { + s_test_rdar8848957 vals[10]; + vals[index] = foo_rdar8848957(); + return vals[index].x; // no-warning +} + +// PR 9049 - crash on symbolicating unions. This test exists solely to +// test that the analyzer doesn't crash. +typedef struct pr9048_cdev *pr9048_cdev_t; +typedef union pr9048_abstracted_disklabel { void *opaque; } pr9048_disklabel_t; +struct pr9048_diskslice { pr9048_disklabel_t ds_label; }; +struct pr9048_diskslices { + int dss_secmult; + struct pr9048_diskslice dss_slices[16]; +}; +void pr9048(pr9048_cdev_t dev, struct pr9048_diskslices * ssp, unsigned int slice) +{ + pr9048_disklabel_t lp; + struct pr9048_diskslice *sp; + sp = &ssp->dss_slices[slice]; + if (ssp->dss_secmult == 1) { + } else if ((lp = sp->ds_label).opaque != ((void *) 0)) { + } +} + diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m index 4fbaa49c11682..45b44b7412c95 100644 --- a/test/Analysis/misc-ps.m +++ b/test/Analysis/misc-ps.m @@ -1,12 +1,12 @@ // NOTE: Use '-fobjc-gc' to test the analysis being run twice, and multiple reports are not issued. -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -fobjc-gc -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -fobjc-gc -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -analyzer-checker=core.experimental.CastToStruct -analyzer-checker=cocoa.AtSync -analyzer-store=basic -fobjc-gc -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -analyzer-checker=core.experimental.CastToStruct -analyzer-checker=cocoa.AtSync -analyzer-store=basic -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -analyzer-checker=core.experimental.CastToStruct -analyzer-checker=cocoa.AtSync -analyzer-store=region -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -analyzer-checker=core.experimental.CastToStruct -analyzer-checker=cocoa.AtSync -analyzer-store=region -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -analyzer-checker=core.experimental.CastToStruct -analyzer-checker=cocoa.AtSync -analyzer-store=basic -fobjc-gc -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -analyzer-checker=core.experimental.CastToStruct -analyzer-checker=cocoa.AtSync -analyzer-store=basic -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -analyzer-checker=core.experimental.CastToStruct -analyzer-checker=cocoa.AtSync -analyzer-store=region -analyzer-constraints=basic -verify -fblocks -Wno-unreachable-code %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -analyzer-checker=core.experimental.CastToStruct -analyzer-checker=cocoa.AtSync -analyzer-store=region -analyzer-constraints=range -verify -fblocks -Wno-unreachable-code %s #ifndef __clang_analyzer__ #error __clang__analyzer__ not defined @@ -794,7 +794,7 @@ int test_uninit_branch_c(void) { void test_bad_call_aux(int x); void test_bad_call(void) { int y; - test_bad_call_aux(y); // expected-warning{{Pass-by-value argument in function call is undefined}} + test_bad_call_aux(y); // expected-warning{{Function call argument is an uninitialized value}} } @interface TestBadArg {} @@ -803,7 +803,7 @@ void test_bad_call(void) { void test_bad_msg(TestBadArg *p) { int y; - [p testBadArg:y]; // expected-warning{{Pass-by-value argument in message expression is undefined}} + [p testBadArg:y]; // expected-warning{{Argument in message expression is an uninitialized value}} } //===----------------------------------------------------------------------===// @@ -822,7 +822,7 @@ struct trie { struct kwset { struct trie *trie; - unsigned char delta[10]; + unsigned char y[10]; struct trie* next[10]; int d; }; @@ -837,9 +837,9 @@ void f(kwset_t *kws, char const *p, char const *q) { register char const *end = p; register char const *lim = q; register int d = 1; - register unsigned char const *delta = kws->delta; + register unsigned char const *y = kws->y; - d = delta[c = (end+=d)[-1]]; // no-warning + d = y[c = (end+=d)[-1]]; // no-warning trie = next[c]; } @@ -1068,3 +1068,168 @@ void pr8050(struct PR8050 **arg) *arg = malloc(1); } +// <rdar://problem/5880430> Switch on enum should not consider default case live +// if all enum values are covered +enum Cases { C1, C2, C3, C4 }; +void test_enum_cases(enum Cases C) { + switch (C) { + case C1: + case C2: + case C4: + case C3: + return; + } + int *p = 0; + *p = 0xDEADBEEF; // no-warning +} + +void test_enum_cases_positive(enum Cases C) { + switch (C) { // expected-warning{{enumeration value 'C4' not handled in switch}} + case C1: + case C2: + case C3: + return; + } + int *p = 0; + *p = 0xDEADBEEF; // expected-warning{{Dereference of null pointer}} +} + +// <rdar://problem/6351970> rule request: warn if synchronization mutex can be nil +void rdar6351970() { + id x = 0; + @synchronized(x) {} // expected-warning{{Nil value used as mutex for @synchronized() (no synchronization will occur)}} +} + +void rdar6351970_b(id x) { + if (!x) + @synchronized(x) {} // expected-warning{{Nil value used as mutex for @synchronized() (no synchronization will occur)}} +} + +void rdar6351970_c() { + id x; + @synchronized(x) {} // expected-warning{{Uninitialized value used as mutex for @synchronized}} +} + +@interface Rdar8578650 +- (id) foo8578650; +@end + +void rdar8578650(id x) { + @synchronized (x) { + [x foo8578650]; + } + // At this point we should assume that 'x' is not nil, not + // the inverse. + @synchronized (x) { // no-warning + } +} + +// <rdar://problem/6352035> rule request: direct structure member access null pointer dereference +@interface RDar6352035 { + int c; +} +- (void)foo; +- (void)bar; +@end + +@implementation RDar6352035 +- (void)foo { + RDar6352035 *friend = 0; + friend->c = 7; // expected-warning{{Instance variable access (via 'friend') results in a null pointer dereference}} +} +- (void)bar { + self = 0; + c = 7; // expected-warning{{Instance variable access (via 'self') results in a null pointer dereference}} +} +@end + +// PR 8149 - GNU statement expression in condition of ForStmt. +// This previously triggered an assertion failure in CFGBuilder. +void pr8149(void) { + for (; ({ do { } while (0); 0; });) { } +} + +// PR 8458 - Make sure @synchronized doesn't crash with properties. +@interface PR8458 {} +@property(readonly) id lock; +@end + +static +void __PR8458(PR8458 *x) { + @synchronized(x.lock) {} // no-warning +} + +// PR 8440 - False null dereference during store to array-in-field-in-global. +// This test case previously resulted in a bogus null deref warning from +// incorrect lazy symbolication logic in RegionStore. +static struct { + int num; + char **data; +} saved_pr8440; + +char *foo_pr8440(); +char **bar_pr8440(); +void baz_pr8440(int n) +{ + saved_pr8440.num = n; + if (saved_pr8440.data) + return; + saved_pr8440.data = bar_pr8440(); + for (int i = 0 ; i < n ; i ++) + saved_pr8440.data[i] = foo_pr8440(); // no-warning +} + +// Support direct accesses to non-null memory. Reported in: +// PR 5272 +// <rdar://problem/6839683> +int test_direct_address_load() { + int *p = (int*) 0x4000; + return *p; // no-warning +} + +void pr5272_test() { + struct pr5272 { int var2; }; + (*(struct pr5272*)0xBC000000).var2 = 0; // no-warning + (*(struct pr5272*)0xBC000000).var2 += 2; // no-warning +} + +// Support casting the return value of function to another different type +// This previously caused a crash, although we likely need more precise +// reasoning here. <rdar://problem/8663544> +void* rdar8663544(); +typedef struct {} Val8663544; +Val8663544 bazR8663544() { + Val8663544(*func) () = (Val8663544(*) ()) rdar8663544; + return func(); +} + +// PR 8619 - Handle ternary expressions with a call to a noreturn function. +// This previously resulted in a crash. +void pr8619_noreturn(int x) __attribute__((noreturn)); + +void pr8619(int a, int b, int c) { + a ?: pr8619_noreturn(b || c); +} + + +// PR 8646 - crash in the analyzer when handling unions. +union pr8648_union { + signed long long pr8648_union_field; +}; +void pr8648() { + long long y; + union pr8648_union x = { .pr8648_union_field = 0LL }; + y = x.pr8648_union_field; + + union pr8648_union z; + z = (union pr8648_union) { .pr8648_union_field = 0LL }; + + union pr8648_union w; + w = ({ (union pr8648_union) { .pr8648_union_field = 0LL }; }); + + // crash, no assignment + (void) ({ (union pr8648_union) { .pr8648_union_field = 0LL }; }).pr8648_union_field; + + // crash with assignment + y = ({ (union pr8648_union) { .pr8648_union_field = 0LL }; }).pr8648_union_field; +} diff --git a/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret-region.m b/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret-region.m new file mode 100644 index 0000000000000..4c754fb951ad6 --- /dev/null +++ b/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret-region.m @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=range -analyzer-store=region -verify %s + +// <rdar://problem/6888289> - This test case shows that a nil instance +// variable can possibly be initialized by a method. +typedef struct RDar6888289_data { + long data[100]; +} RDar6888289_data; + +@interface RDar6888289 +{ + RDar6888289 *x; +} +- (RDar6888289_data) test; +- (RDar6888289_data) test2; +- (void) invalidate; +- (RDar6888289_data) getData; +@end + +@implementation RDar6888289 +- (RDar6888289_data) test { + if (!x) + [self invalidate]; + return [x getData]; +} +- (RDar6888289_data) test2 { + if (!x) {} + return [x getData]; // expected-warning{{The receiver of message 'getData' is nil and returns a value of type 'RDar6888289_data' that will be garbage}} +} + +- (void) invalidate { + x = self; +} + +- (RDar6888289_data) getData { + return (RDar6888289_data) { 0 }; +} +@end + diff --git a/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m b/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m index 5f5187194dab5..6c8f525eb375b 100644 --- a/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m +++ b/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m @@ -2,11 +2,14 @@ // RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin8 %s // RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin9 %s // RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin9 %s +// RUN: %clang_cc1 -triple thumbv6-apple-darwin4.0.0-iphoneos -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin9 %s +// RUN: %clang_cc1 -triple thumbv6-apple-darwin4.0.0-iphoneos -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin9 %s @interface MyClass {} - (void *)voidPtrM; - (int)intM; - (long long)longlongM; +- (unsigned long long)unsignedLongLongM; - (double)doubleM; - (long double)longDoubleM; - (void)voidM; @@ -15,6 +18,7 @@ - (void *)voidPtrM { return (void *)0; } - (int)intM { return 0; } - (long long)longlongM { return 0; } +- (unsigned long long)unsignedLongLongM { return 0; } - (double)doubleM { return 0.0; } - (long double)longDoubleM { return 0.0; } - (void)voidM {} @@ -30,20 +34,20 @@ void createFoo() { void createFoo2() { MyClass *obj = 0; - long double ld = [obj longDoubleM]; // expected-warning{{The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage}} + long double ld = [obj longDoubleM]; } void createFoo3() { MyClass *obj; obj = 0; - long long ll = [obj longlongM]; // expected-warning{{The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage}} + long long ll = [obj longlongM]; } void createFoo4() { MyClass *obj = 0; - double d = [obj doubleM]; // expected-warning{{The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage}} + double d = [obj doubleM]; } void createFoo5() { @@ -52,16 +56,23 @@ void createFoo5() { double d = [obj doubleM]; // no-warning } +void createFoo6() { + MyClass *obj; + obj = 0; + + unsigned long long ull = [obj unsignedLongLongM]; +} + void handleNilPruneLoop(MyClass *obj) { if (!!obj) return; // Test if [obj intM] evaluates to 0, thus pruning the entire loop. for (int i = 0; i < [obj intM]; i++) { - long long j = [obj longlongM]; // no-warning + long long j = [obj longlongM]; } - long long j = [obj longlongM]; // expected-warning{{The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage}} + long long j = [obj longlongM]; } int handleVoidInComma() { @@ -72,11 +83,16 @@ int handleVoidInComma() { int marker(void) { // control reaches end of non-void function } -// CHECK-darwin8: control reaches end of non-void function + // CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage // CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage // CHECK-darwin8: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage +// CHECK-darwin8: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage // CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage -// CHECK-darwin8: 5 warnings generated -// CHECK-darwin9: control reaches end of non-void function +// CHECK-darwin9-NOT: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage +// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage +// CHECK-darwin9-NOT: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage +// CHECK-darwin9-NOT: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage +// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage // CHECK-darwin9: 1 warning generated + diff --git a/test/Analysis/null-deref-ps.c b/test/Analysis/null-deref-ps.c index 8daa845068189..5db4923cd34d3 100644 --- a/test/Analysis/null-deref-ps.c +++ b/test/Analysis/null-deref-ps.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -verify %s -analyzer-constraints=basic -analyzer-store=basic -Wreturn-type -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -verify %s -analyzer-constraints=range -analyzer-store=basic -Wreturn-type -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-no-purge-dead -verify %s -Wreturn-type -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s -Wreturn-type +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -verify %s -analyzer-constraints=basic -analyzer-store=basic -Wreturn-type +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -verify %s -analyzer-constraints=range -analyzer-store=basic -Wreturn-type +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-no-purge-dead -verify %s -Wreturn-type +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=core.experimental.IdempotentOps -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s -Wreturn-type typedef unsigned uintptr_t; @@ -26,7 +26,7 @@ int f2(struct foo_struct* p) { if (p) p->x = 1; - return p->x++; // expected-warning{{Field access results in a dereference of a null pointer (loaded from variable 'p')}} + return p->x++; // expected-warning{{Access to field 'x' results in a dereference of a null pointer (loaded from variable 'p')}} } int f3(char* x) { @@ -36,7 +36,7 @@ int f3(char* x) { if (x) return x[i - 1]; - return x[i+1]; // expected-warning{{Dereference of null pointer}} + return x[i+1]; // expected-warning{{Array access (from variable 'x') results in a null pointer dereference}} } int f3_b(char* x) { @@ -46,7 +46,7 @@ int f3_b(char* x) { if (x) return x[i - 1]; - return x[i+1]++; // expected-warning{{Dereference of null pointer}} + return x[i+1]++; // expected-warning{{Array access (from variable 'x') results in a null pointer dereference}} } int f4(int *p) { @@ -237,7 +237,7 @@ int* f10(int* p, signed char x, int y) { // Test case from <rdar://problem/6407949> void f11(unsigned i) { int *x = 0; - if (i >= 0) { + if (i >= 0) { // expected-warning{{always true}} // always true } else { *x = 42; // no-warning @@ -288,7 +288,7 @@ void pr4759_aux(int *p) __attribute__((nonnull)); void pr4759() { int *p; - pr4759_aux(p); // expected-warning{{undefined}} + pr4759_aux(p); // expected-warning{{Function call argument is an uninitialized value}} } diff --git a/test/Analysis/operator-calls.cpp b/test/Analysis/operator-calls.cpp new file mode 100644 index 0000000000000..892a1ab0769f6 --- /dev/null +++ b/test/Analysis/operator-calls.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-experimental-checks -verify %s +struct X0 { }; +bool operator==(const X0&, const X0&); + +// PR7287 +struct test { int a[2]; }; + +void t2() { + test p = {{1,2}}; + test q; + q = p; +} + +bool PR7287(X0 a, X0 b) { + return operator==(a, b); +} diff --git a/test/Analysis/out-of-bounds.c b/test/Analysis/out-of-bounds.c new file mode 100644 index 0000000000000..b8d6e442ff571 --- /dev/null +++ b/test/Analysis/out-of-bounds.c @@ -0,0 +1,148 @@ +// RUN: %clang_cc1 -Wno-array-bounds -analyze -analyzer-check-objc-mem -analyzer-check-buffer-overflows -verify %s + +// Tests doing an out-of-bounds access after the end of an array using: +// - constant integer index +// - constant integer size for buffer +void test1(int x) { + int buf[100]; + buf[100] = 1; // expected-warning{{Out of bound memory access}} +} + +void test1_ok(int x) { + int buf[100]; + buf[99] = 1; // no-warning +} + +const char test1_strings_underrun(int x) { + const char *mystr = "mary had a little lamb"; + return mystr[-1]; // expected-warning{{Out of bound memory access}} +} + +const char test1_strings_overrun(int x) { + const char *mystr = "mary had a little lamb"; + return mystr[1000]; // expected-warning{{Out of bound memory access}} +} + +const char test1_strings_ok(int x) { + const char *mystr = "mary had a little lamb"; + return mystr[5]; // no-warning +} + +// Tests doing an out-of-bounds access after the end of an array using: +// - indirect pointer to buffer +// - constant integer index +// - constant integer size for buffer +void test1_ptr(int x) { + int buf[100]; + int *p = buf; + p[101] = 1; // expected-warning{{Out of bound memory access}} +} + +void test1_ptr_ok(int x) { + int buf[100]; + int *p = buf; + p[99] = 1; // no-warning +} + +// Tests doing an out-of-bounds access before the start of an array using: +// - indirect pointer to buffer, manipulated using simple pointer arithmetic +// - constant integer index +// - constant integer size for buffer +void test1_ptr_arith(int x) { + int buf[100]; + int *p = buf; + p = p + 100; + p[0] = 1; // expected-warning{{Out of bound memory access}} +} + +void test1_ptr_arith_ok(int x) { + int buf[100]; + int *p = buf; + p = p + 99; + p[0] = 1; // no-warning +} + +void test1_ptr_arith_bad(int x) { + int buf[100]; + int *p = buf; + p = p + 99; + p[1] = 1; // expected-warning{{Out of bound memory access}} +} + +void test1_ptr_arith_ok2(int x) { + int buf[100]; + int *p = buf; + p = p + 99; + p[-1] = 1; // no-warning +} + +// Tests doing an out-of-bounds access before the start of an array using: +// - constant integer index +// - constant integer size for buffer +void test2(int x) { + int buf[100]; + buf[-1] = 1; // expected-warning{{Out of bound memory access}} +} + +// Tests doing an out-of-bounds access before the start of an array using: +// - indirect pointer to buffer +// - constant integer index +// - constant integer size for buffer +void test2_ptr(int x) { + int buf[100]; + int *p = buf; + p[-1] = 1; // expected-warning{{Out of bound memory access}} +} + +// ** FIXME ** Doesn't work yet because we don't support pointer arithmetic. +// Tests doing an out-of-bounds access before the start of an array using: +// - indirect pointer to buffer, manipulated using simple pointer arithmetic +// - constant integer index +// - constant integer size for buffer +void test2_ptr_arith(int x) { + int buf[100]; + int *p = buf; + --p; + p[0] = 1; // no-warning +} + +// Tests doing an out-of-bounds access before the start of a multi-dimensional +// array using: +// - constant integer indices +// - constant integer sizes for the array +void test2_multi(int x) { + int buf[100][100]; + buf[0][-1] = 1; // expected-warning{{Out of bound memory access}} +} + +// Tests doing an out-of-bounds access before the start of a multi-dimensional +// array using: +// - constant integer indices +// - constant integer sizes for the array +void test2_multi_b(int x) { + int buf[100][100]; + buf[-1][0] = 1; // expected-warning{{Out of bound memory access}} +} + +void test2_multi_ok(int x) { + int buf[100][100]; + buf[0][0] = 1; // no-warning +} + +// *** FIXME *** +// We don't get a warning here yet because our symbolic constraint solving +// doesn't handle: (symbol * constant) < constant +void test3(int x) { + int buf[100]; + if (x < 0) + buf[x] = 1; +} + +// *** FIXME *** +// We don't get a warning here yet because our symbolic constraint solving +// doesn't handle: (symbol * constant) < constant +void test4(int x) { + int buf[100]; + if (x > 99) + buf[x] = 1; +} diff --git a/test/Analysis/outofbound.c b/test/Analysis/outofbound.c index ed51dc6ac06ae..3b261bbb5ca82 100644 --- a/test/Analysis/outofbound.c +++ b/test/Analysis/outofbound.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-experimental-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s +// RUN: %clang_cc1 -Wno-array-bounds -analyze -analyzer-experimental-internal-checks -analyzer-experimental-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s typedef __typeof(sizeof(int)) size_t; void *malloc(size_t); diff --git a/test/Analysis/plist-output-alternate.m b/test/Analysis/plist-output-alternate.m new file mode 100644 index 0000000000000..12697b4c6c8d8 --- /dev/null +++ b/test/Analysis/plist-output-alternate.m @@ -0,0 +1,1014 @@ +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-output=plist -o - %s | FileCheck %s + +void test_null_init(void) { + int *p = 0; + *p = 0xDEADBEEF; +} + +void test_null_assign(void) { + int *p; + p = 0; + *p = 0xDEADBEEF; +} + +void test_null_assign_transitive(void) { + int *p; + p = 0; + int *q = p; + *q = 0xDEADBEEF; +} + +void test_null_cond(int *p) { + if (!p) { + *p = 0xDEADBEEF; + } +} + +void test_null_cond_transitive(int *q) { + if (!q) { + int *p = q; + *p = 0xDEADBEEF; + } +} + +void test_null_field(void) { + struct s { int *p; } x; + x.p = 0; + *(x.p) = 0xDEADBEEF; +} + +// <rdar://problem/8331641> leak reports should not show paths that end with exit() (but ones that don't end with exit()) +void panic() __attribute__((noreturn)); +enum { kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2, kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4, kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6, kCFNumberCharType = 7, kCFNumberShortType = 8, kCFNumberIntType = 9, kCFNumberLongType = 10, kCFNumberLongLongType = 11, kCFNumberFloatType = 12, kCFNumberDoubleType = 13, kCFNumberCFIndexType = 14, kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16, kCFNumberMaxType = 16 }; +typedef const struct __CFAllocator * CFAllocatorRef; +extern const CFAllocatorRef kCFAllocatorDefault; +typedef signed long CFIndex; +typedef CFIndex CFNumberType; +typedef const struct __CFNumber * CFNumberRef; + +extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr); + +void rdar8331641(int x) { + signed z = 1; + CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); // expected-warning{{leak}} + if (x) + panic(); + (void) value; +} + +// CHECK: <?xml version="1.0" encoding="UTF-8"?> +// CHECK: <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +// CHECK: <plist version="1.0"> +// CHECK: <dict> +// CHECK: <key>files</key> +// CHECK: <array> +// CHECK: </array> +// CHECK: <key>diagnostics</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>path</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>4</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>4</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>4</integer> +// CHECK: <key>col</key><integer>8</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Variable 'p' initialized to a null pointer value</string> +// CHECK: <key>message</key> +// CHECK: <string>Variable 'p' initialized to a null pointer value</string> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>4</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>4</integer> +// CHECK: <key>col</key><integer>8</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>5</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>5</integer> +// CHECK: <key>col</key><integer>4</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>5</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>5</integer> +// CHECK: <key>col</key><integer>4</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>5</integer> +// CHECK: <key>col</key><integer>4</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: <key>message</key> +// CHECK: <string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>description</key><string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: <key>category</key><string>Logic error</string> +// CHECK: <key>type</key><string>Dereference of null pointer</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>5</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>path</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>9</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>9</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>10</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>10</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>10</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>10</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>10</integer> +// CHECK: <key>col</key><integer>7</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Null pointer value stored to 'p'</string> +// CHECK: <key>message</key> +// CHECK: <string>Null pointer value stored to 'p'</string> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>10</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>10</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>11</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>11</integer> +// CHECK: <key>col</key><integer>4</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>11</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>11</integer> +// CHECK: <key>col</key><integer>4</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>11</integer> +// CHECK: <key>col</key><integer>4</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: <key>message</key> +// CHECK: <string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>description</key><string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: <key>category</key><string>Logic error</string> +// CHECK: <key>type</key><string>Dereference of null pointer</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>11</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>path</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>15</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>15</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>17</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>17</integer> +// CHECK: <key>col</key><integer>8</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>17</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>17</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>17</integer> +// CHECK: <key>col</key><integer>8</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Variable 'q' initialized to a null pointer value</string> +// CHECK: <key>message</key> +// CHECK: <string>Variable 'q' initialized to a null pointer value</string> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>17</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>17</integer> +// CHECK: <key>col</key><integer>8</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>18</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>18</integer> +// CHECK: <key>col</key><integer>4</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>18</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>18</integer> +// CHECK: <key>col</key><integer>4</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>18</integer> +// CHECK: <key>col</key><integer>4</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Dereference of null pointer (loaded from variable 'q')</string> +// CHECK: <key>message</key> +// CHECK: <string>Dereference of null pointer (loaded from variable 'q')</string> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>description</key><string>Dereference of null pointer (loaded from variable 'q')</string> +// CHECK: <key>category</key><string>Logic error</string> +// CHECK: <key>type</key><string>Dereference of null pointer</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>18</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>path</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>22</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>22</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>23</integer> +// CHECK: <key>col</key><integer>5</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>23</integer> +// CHECK: <key>col</key><integer>6</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>23</integer> +// CHECK: <key>col</key><integer>5</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>23</integer> +// CHECK: <key>col</key><integer>6</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>23</integer> +// CHECK: <key>col</key><integer>6</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: <key>message</key> +// CHECK: <string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>description</key><string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: <key>category</key><string>Logic error</string> +// CHECK: <key>type</key><string>Dereference of null pointer</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>23</integer> +// CHECK: <key>col</key><integer>5</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>path</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>28</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>28</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>29</integer> +// CHECK: <key>col</key><integer>5</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>29</integer> +// CHECK: <key>col</key><integer>10</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>29</integer> +// CHECK: <key>col</key><integer>5</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>29</integer> +// CHECK: <key>col</key><integer>5</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>29</integer> +// CHECK: <key>col</key><integer>10</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Variable 'p' initialized to a null pointer value</string> +// CHECK: <key>message</key> +// CHECK: <string>Variable 'p' initialized to a null pointer value</string> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>29</integer> +// CHECK: <key>col</key><integer>5</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>29</integer> +// CHECK: <key>col</key><integer>10</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>30</integer> +// CHECK: <key>col</key><integer>5</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>30</integer> +// CHECK: <key>col</key><integer>6</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>30</integer> +// CHECK: <key>col</key><integer>5</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>30</integer> +// CHECK: <key>col</key><integer>6</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>30</integer> +// CHECK: <key>col</key><integer>6</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: <key>message</key> +// CHECK: <string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>description</key><string>Dereference of null pointer (loaded from variable 'p')</string> +// CHECK: <key>category</key><string>Logic error</string> +// CHECK: <key>type</key><string>Dereference of null pointer</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>30</integer> +// CHECK: <key>col</key><integer>5</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>path</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>35</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>35</integer> +// CHECK: <key>col</key><integer>8</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>35</integer> +// CHECK: <key>col</key><integer>10</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>35</integer> +// CHECK: <key>col</key><integer>10</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>35</integer> +// CHECK: <key>col</key><integer>10</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>35</integer> +// CHECK: <key>col</key><integer>10</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>37</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>37</integer> +// CHECK: <key>col</key><integer>8</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>37</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>37</integer> +// CHECK: <key>col</key><integer>7</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>37</integer> +// CHECK: <key>col</key><integer>7</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Dereference of null pointer (loaded from field 'p')</string> +// CHECK: <key>message</key> +// CHECK: <string>Dereference of null pointer (loaded from field 'p')</string> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>description</key><string>Dereference of null pointer (loaded from field 'p')</string> +// CHECK: <key>category</key><string>Logic error</string> +// CHECK: <key>type</key><string>Dereference of null pointer</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>37</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>path</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>52</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>52</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>23</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>82</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>23</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>23</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>82</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Call to function 'CFNumberCreate' returns a Core Foundation object with a +1 retain count (owning reference)</string> +// CHECK: <key>message</key> +// CHECK: <string>Call to function 'CFNumberCreate' returns a Core Foundation object with a +1 retain count (owning reference)</string> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>23</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>53</integer> +// CHECK: <key>col</key><integer>82</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>54</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>54</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>54</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>54</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>56</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>56</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>control</string> +// CHECK: <key>edges</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>start</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>56</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>56</integer> +// CHECK: <key>col</key><integer>3</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>end</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>57</integer> +// CHECK: <key>col</key><integer>1</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>57</integer> +// CHECK: <key>col</key><integer>1</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>kind</key><string>event</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>57</integer> +// CHECK: <key>col</key><integer>1</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>57</integer> +// CHECK: <key>col</key><integer>1</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>57</integer> +// CHECK: <key>col</key><integer>1</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: <key>extended_message</key> +// CHECK: <string>Object allocated on line 53 and stored into 'value' is not referenced later in this execution path and has a retain count of +1 (object leaked)</string> +// CHECK: <key>message</key> +// CHECK: <string>Object allocated on line 53 and stored into 'value' is not referenced later in this execution path and has a retain count of +1 (object leaked)</string> +// CHECK: </dict> +// CHECK: </array> +// CHECK: <key>description</key><string>Potential leak of an object allocated on line 53 and stored into 'value'</string> +// CHECK: <key>category</key><string>Memory (Core Foundation/Objective-C)</string> +// CHECK: <key>type</key><string>Leak of returned object</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>57</integer> +// CHECK: <key>col</key><integer>1</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </plist> diff --git a/test/Analysis/plist-output.m b/test/Analysis/plist-output.m index 95faa06a06334..ec4f770cb2454 100644 --- a/test/Analysis/plist-output.m +++ b/test/Analysis/plist-output.m @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-output=plist -o - %s | FileCheck %s +// XFAIL: * void test_null_init(void) { int *p = 0; diff --git a/test/Analysis/properties.m b/test/Analysis/properties.m new file mode 100644 index 0000000000000..ce8faf52736a6 --- /dev/null +++ b/test/Analysis/properties.m @@ -0,0 +1,145 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s + +typedef signed char BOOL; +typedef unsigned int NSUInteger; +typedef struct _NSZone NSZone; +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; +@protocol NSObject - (BOOL)isEqual:(id)object; @end +@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end +@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end +@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end +@interface NSObject <NSObject> {} ++(id)alloc; +-(id)init; +-(id)autorelease; +-(id)copy; +-(id)retain; +@end +@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> +- (NSUInteger)length; +-(id)initWithFormat:(NSString *)f,...; +-(BOOL)isEqualToString:(NSString *)s; ++ (id)string; +@end +@interface NSNumber : NSObject {} ++(id)alloc; +-(id)initWithInteger:(int)i; +@end + +// rdar://6946338 + +@interface Test1 : NSObject { + NSString *text; +} +-(id)myMethod; +@property (nonatomic, assign) NSString *text; +@end + + +@implementation Test1 + +@synthesize text; + +-(id)myMethod { + Test1 *cell = [[[Test1 alloc] init] autorelease]; + + NSString *string1 = [[NSString alloc] initWithFormat:@"test %f", 0.0]; // expected-warning {{Potential leak}} + cell.text = string1; + + return cell; +} + +@end + + +// rdar://8824416 + +@interface MyNumber : NSObject +{ + NSNumber* _myNumber; +} + +- (id)initWithNumber:(NSNumber *)number; + +@property (nonatomic, readonly) NSNumber* myNumber; +@property (nonatomic, readonly) NSNumber* newMyNumber; + +@end + +@implementation MyNumber +@synthesize myNumber=_myNumber; + +- (id)initWithNumber:(NSNumber *)number +{ + self = [super init]; + + if ( self ) + { + _myNumber = [number copy]; + } + + return self; +} + +- (NSNumber*)newMyNumber +{ + if ( _myNumber ) + return [_myNumber retain]; + + return [[NSNumber alloc] initWithInteger:1]; +} + +- (id)valueForUndefinedKey:(NSString*)key +{ + id value = 0; + + if ([key isEqualToString:@"MyIvarNumberAsPropertyOverReleased"]) + value = self.myNumber; // _myNumber will be over released, since the value returned from self.myNumber is not retained. + else if ([key isEqualToString:@"MyIvarNumberAsPropertyOk"]) + value = [self.myNumber retain]; // this line fixes the over release + else if ([key isEqualToString:@"MyIvarNumberAsNewMyNumber"]) + value = self.newMyNumber; // this one is ok, since value is returned retained + else + value = [[NSNumber alloc] initWithInteger:0]; + + return [value autorelease]; // expected-warning {{Object sent -autorelease too many times}} +} + +@end + +NSNumber* numberFromMyNumberProperty(MyNumber* aMyNumber) +{ + NSNumber* result = aMyNumber.myNumber; + + return [result autorelease]; // expected-warning {{Object sent -autorelease too many times}} +} + + +// rdar://6611873 + +@interface Person : NSObject { + NSString *_name; +} +@property (retain) NSString * name; +@end + +@implementation Person +@synthesize name = _name; +@end + +void rdar6611873() { + Person *p = [[[Person alloc] init] autorelease]; + + p.name = [[NSString string] retain]; // expected-warning {{leak}} + p.name = [[NSString alloc] init]; // expected-warning {{leak}} +} + +@interface SubPerson : Person +-(NSString *)foo; +@end + +@implementation SubPerson +-(NSString *)foo { + return super.name; +} +@end diff --git a/test/Analysis/ptr-arith.c b/test/Analysis/ptr-arith.c index 0c2e221398216..044d72aeef160 100644 --- a/test/Analysis/ptr-arith.c +++ b/test/Analysis/ptr-arith.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -triple x86_64-apple-darwin9 %s -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -triple i686-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.FixedAddr -analyzer-checker=core.experimental.PointerArithm -analyzer-checker=core.experimental.PointerSub -analyzer-check-objc-mem -analyzer-store=region -verify -triple x86_64-apple-darwin9 %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.FixedAddr -analyzer-checker=core.experimental.PointerArithm -analyzer-checker=core.experimental.PointerSub -analyzer-check-objc-mem -analyzer-store=region -verify -triple i686-apple-darwin9 %s // Used to trigger warnings for unreachable paths. #define WARN do { int a, b; int c = &b-&a; } while (0) diff --git a/test/Analysis/rdar-6442306-1.m b/test/Analysis/rdar-6442306-1.m index dfe9b722d13fe..0d35f23328ad1 100644 --- a/test/Analysis/rdar-6442306-1.m +++ b/test/Analysis/rdar-6442306-1.m @@ -16,7 +16,7 @@ typedef struct { double __Foo_READSWAP__double(double*); static __inline__ bar_return_t -__Beeble_check__Request__SetPortalSize_t(__attribute__((__unused__)) __Request__SetPortalSize_t *In0P) { +__Beeble_check__Request__SetPortalSize_t(__Request__SetPortalSize_t *In0P) { if (In0P->Foo.int_rep != Foo_record.int_rep) { do { int __i__, __C__ = (2); diff --git a/test/Analysis/rdar-6540084.m b/test/Analysis/rdar-6540084.m index dd0181099ee73..d6a03b6f9880e 100644 --- a/test/Analysis/rdar-6540084.m +++ b/test/Analysis/rdar-6540084.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-dead-stores -verify %s +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-checker=core.DeadStores -verify %s // // This test exercises the live variables analysis (LiveVariables.cpp). // The case originally identified a non-termination bug. diff --git a/test/Analysis/refcnt_naming.m b/test/Analysis/refcnt_naming.m index 9defce2735ef0..7299001051c86 100644 --- a/test/Analysis/refcnt_naming.m +++ b/test/Analysis/refcnt_naming.m @@ -11,6 +11,10 @@ typedef signed char BOOL; @class NSArray, NSString, NSURL; @interface NamingTest : NSObject {} +-(NSObject*)copyPhoto; +-(NSObject*)mutableCopyPhoto; +-(NSObject*)mutable; +-(NSObject*)mutableCopying; -(NSObject*)photocopy; // read as "photocopy" -(NSObject*)photoCopy; // read as "photo Copy" -(NSObject*)__blebPRCopy; // read as "bleb PRCopy" @@ -26,7 +30,9 @@ typedef signed char BOOL; } - (NSURL *)myMethod:(NSString *)inString; - (NSURL *)getMethod:(NSString*)inString; -- (void)addObject:(id)X; +- (NSURL *)getMethod2:(NSString*)inString; +- (void)addObject:(id) __attribute__((ns_consumed)) X; +- (void)addObject2:(id) X; @end @implementation MyClass @@ -44,10 +50,21 @@ typedef signed char BOOL; return url; // no-warning } +- (NSURL *)getMethod2:(NSString *)inString +{ + NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0); // expected-warning{{leak}} + [self addObject2:url]; + return url; +} + void testNames(NamingTest* x) { + [x copyPhoto]; // expected-warning{{leak}} + [x mutableCopyPhoto]; // expected-warning{{leak}} + [x mutable]; // no-warning + [x mutableCopying]; // no-warning [x photocopy]; // no-warning - [x photoCopy]; // expected-warning{{leak}} - [x __blebPRCopy]; // expected-warning{{leak}} + [x photoCopy]; // no-warning + [x __blebPRCopy]; // no-warning [x __blebPRcopy]; // no-warning [x new_theprefixdoescount]; // expected-warning{{leak}} [x newestAwesomeStuff]; // no-warning @@ -59,4 +76,10 @@ void testNames(NamingTest* x) { myObject = X; } +- (void)addObject2:(id)X +{ + myObject = X; +} + @end + diff --git a/test/Analysis/reference.cpp b/test/Analysis/reference.cpp index f1694163a20c9..51c8aae66c1ec 100644 --- a/test/Analysis/reference.cpp +++ b/test/Analysis/reference.cpp @@ -1,9 +1,10 @@ // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s + typedef typeof(sizeof(int)) size_t; void malloc (size_t); void f1() { - int const &i = 3; + int const &i = 3; // <--- **FIXME** This is currently not being modeled correctly. int b = i; int *p = 0; diff --git a/test/Analysis/retain-release-gc-only.m b/test/Analysis/retain-release-gc-only.m index 8995d5f364f14..6f1dd92df9971 100644 --- a/test/Analysis/retain-release-gc-only.m +++ b/test/Analysis/retain-release-gc-only.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -verify -fobjc-gc-only -fblocks %s -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -fobjc-gc-only -fblocks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=cocoa.NSAutoreleasePool -analyzer-check-objc-mem -analyzer-store=basic -verify -fobjc-gc-only -fblocks %s +// RUN: %clang_cc1 -analyze -analyzer-checker=cocoa.NSAutoreleasePool -analyzer-check-objc-mem -analyzer-store=region -fobjc-gc-only -fblocks -verify %s //===----------------------------------------------------------------------===// // Header stuff. diff --git a/test/Analysis/retain-release-region-store.m b/test/Analysis/retain-release-region-store.m index 7b9855473dce9..05b91fcf5c567 100644 --- a/test/Analysis/retain-release-region-store.m +++ b/test/Analysis/retain-release-region-store.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -analyzer-max-loop 6 -verify %s //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index 064165aaf9e1e..81e015f5fc447 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem -analyzer-store=basic -fblocks -verify %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem -analyzer-store=region -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=macosx.CFRetainRelease -analyzer-checker=cocoa.ClassRelease -analyzer-check-objc-mem -analyzer-store=basic -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=macosx.CFRetainRelease -analyzer-checker=cocoa.ClassRelease -analyzer-check-objc-mem -analyzer-store=region -fblocks -verify %s #if __has_feature(attribute_ns_returns_retained) #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained)) @@ -13,6 +13,15 @@ #if __has_feature(attribute_cf_returns_not_retained) #define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained)) #endif +#if __has_feature(attribute_ns_consumes_self) +#define NS_CONSUMES_SELF __attribute__((ns_consumes_self)) +#endif +#if __has_feature(attribute_ns_consumed) +#define NS_CONSUMED __attribute__((ns_consumed)) +#endif +#if __has_feature(attribute_cf_consumed) +#define CF_CONSUMED __attribute__((cf_consumed)) +#endif //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from Mac OS X headers: @@ -703,7 +712,7 @@ typedef CFTypeRef OtherRef; NSString *_foo; } - (id)initReturningNewClass; -- (id)initReturningNewClassBad; +- (id)_initReturningNewClassBad; - (id)initReturningNewClassBad2; @end @@ -716,7 +725,7 @@ typedef CFTypeRef OtherRef; self = [[RDar6320065Subclass alloc] init]; // no-warning return self; } -- (id)initReturningNewClassBad { +- (id)_initReturningNewClassBad { [self release]; [[RDar6320065Subclass alloc] init]; // expected-warning {{leak}} return self; @@ -762,13 +771,13 @@ int RDar6320065_test() { @end @implementation RDar6859457 -- (NSString*) NoCopyString { return [[NSString alloc] init]; } // no-warning -- (NSString*) noCopyString { return [[NSString alloc] init]; } // no-warning +- (NSString*) NoCopyString { return [[NSString alloc] init]; } // expected-warning{{leak}} +- (NSString*) noCopyString { return [[NSString alloc] init]; } // expected-warning{{leak}} @end void test_RDar6859457(RDar6859457 *x, void *bytes, NSUInteger dataLength) { - [x NoCopyString]; // expected-warning{{leak}} - [x noCopyString]; // expected-warning{{leak}} + [x NoCopyString]; // no-warning + [x noCopyString]; // no-warning [NSData dataWithBytesNoCopy:bytes length:dataLength]; // no-warning [NSData dataWithBytesNoCopy:bytes length:dataLength freeWhenDone:1]; // no-warning } @@ -1210,10 +1219,13 @@ typedef NSString* MyStringTy; - (MyStringTy) returnsAnOwnedTypedString NS_RETURNS_RETAINED; // no-warning - (NSString*) newString NS_RETURNS_NOT_RETAINED; // no-warning - (NSString*) newStringNoAttr; -- (int) returnsAnOwnedInt NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' attribute only applies to functions or methods that return a pointer or Objective-C object}} +- (int) returnsAnOwnedInt NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' attribute only applies to methods that return an Objective-C object}} +- (id) pseudoInit NS_CONSUMES_SELF NS_RETURNS_RETAINED; ++ (void) consume:(id) NS_CONSUMED x; ++ (void) consume2:(id) CF_CONSUMED x; @end -static int ownership_attribute_doesnt_go_here NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' attribute only applies to function or method types}} +static int ownership_attribute_doesnt_go_here NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' attribute only applies to functions and methods}} void test_attr_1(TestOwnershipAttr *X) { NSString *str = [X returnsAnOwnedString]; // expected-warning{{leak}} @@ -1228,6 +1240,37 @@ void test_attr1c(TestOwnershipAttr *X) { NSString *str2 = [X newStringNoAttr]; // expected-warning{{leak}} } +void testattr2_a() { + TestOwnershipAttr *x = [TestOwnershipAttr alloc]; // expected-warning{{leak}} +} + +void testattr2_b() { + TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit]; // expected-warning{{leak}} +} + +void testattr2_c() { + TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit]; // no-warning + [x release]; +} + +void testattr3() { + TestOwnershipAttr *x = [TestOwnershipAttr alloc]; // no-warning + [TestOwnershipAttr consume:x]; + TestOwnershipAttr *y = [TestOwnershipAttr alloc]; // no-warning + [TestOwnershipAttr consume2:y]; +} + +void consume_ns(id NS_CONSUMED x); +void consume_cf(id CF_CONSUMED x); + +void testattr4() { + TestOwnershipAttr *x = [TestOwnershipAttr alloc]; // no-warning + consume_ns(x); + TestOwnershipAttr *y = [TestOwnershipAttr alloc]; // no-warning + consume_cf(y); +} + + @interface MyClassTestCFAttr : NSObject {} - (NSDate*) returnsCFRetained CF_RETURNS_RETAINED; - (CFDateRef) returnsCFRetainedAsCF CF_RETURNS_RETAINED; @@ -1367,3 +1410,46 @@ void r8272168() { GetAClassThatImplementsProt_R8272168(); } +// Test case for <rdar://problem/8356342>, which in the past triggered +// a false positive. +@interface RDar8356342 +- (NSDate*) rdar8356342:(NSDate *)inValue; +@end + +@implementation RDar8356342 +- (NSDate*) rdar8356342:(NSDate*)inValue { + NSDate *outValue = inValue; + if (outValue == 0) + outValue = [[NSDate alloc] init]; // no-warning + + if (outValue != inValue) + [outValue autorelease]; + + return outValue; +} +@end + +// <rdar://problem/8724287> - This test case previously crashed because +// of a bug in BugReporter. +extern const void *CFDictionaryGetValue(CFDictionaryRef theDict, const void *key); +typedef struct __CFError * CFErrorRef; +extern const CFStringRef kCFErrorUnderlyingErrorKey; +extern CFDictionaryRef CFErrorCopyUserInfo(CFErrorRef err); + +static void rdar_8724287(CFErrorRef error) +{ + CFErrorRef error_to_dump; + + error_to_dump = error; + while (error_to_dump != ((void*)0)) { + CFDictionaryRef info; + + info = CFErrorCopyUserInfo(error_to_dump); // expected-warning{{Potential leak of an object allocated on line 1447 and stored into 'info'}} + + if (info != ((void*)0)) { + } + + error_to_dump = (CFErrorRef) CFDictionaryGetValue(info, kCFErrorUnderlyingErrorKey); + } +} + diff --git a/test/Analysis/security-syntax-checks-no-emit.c b/test/Analysis/security-syntax-checks-no-emit.c index 7a71235a2c791..f129e8a8e5acb 100644 --- a/test/Analysis/security-syntax-checks-no-emit.c +++ b/test/Analysis/security-syntax-checks-no-emit.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i686-pc-linux-gnu -analyze -analyzer-check-security-syntactic %s -verify +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -analyze -analyzer-checker=core.experimental.SecuritySyntactic %s -verify // This file complements 'security-syntax-checks.m', but tests that we omit // specific checks on platforms where they don't make sense. diff --git a/test/Analysis/security-syntax-checks.m b/test/Analysis/security-syntax-checks.m index 8dd859a4c4f3a..bac6ee89df905 100644 --- a/test/Analysis/security-syntax-checks.m +++ b/test/Analysis/security-syntax-checks.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-check-security-syntactic %s -verify +// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=core.experimental.SecuritySyntactic %s -verify // <rdar://problem/6336718> rule request: floating point used as loop // condition (FLP30-C, FLP-30-CPP) diff --git a/test/Analysis/self-init.m b/test/Analysis/self-init.m new file mode 100644 index 0000000000000..b8c2c3e8d9848 --- /dev/null +++ b/test/Analysis/self-init.m @@ -0,0 +1,165 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-checker=cocoa.SelfInit %s -verify + +@class NSZone, NSCoder; +@protocol NSObject +@end +@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; +@end +@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; +@end +@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; +@end +@interface NSObject <NSObject> {} ++ (id)allocWithZone:(NSZone *)zone; ++ (id)alloc; +- (void)dealloc; +-(id)class; +-(id)init; +-(id)release; +@end +@interface NSProxy <NSObject> {} +@end + +//#import "Foundation/NSObject.h" +typedef unsigned NSUInteger; +typedef int NSInteger; + +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; +@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> +- (NSUInteger)length; ++ (id)stringWithUTF8String:(const char *)nullTerminatedCString; +@end extern NSString * const NSBundleDidLoadNotification; +@interface NSAssertionHandler : NSObject {} ++ (NSAssertionHandler *)currentHandler; +- (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...; +@end +extern NSString * const NSConnectionReplyMode; + +@interface NSBundle : NSObject ++(id)loadNibNamed:(NSString*)s owner:(id)o; +@end + +void log(void *obj); +extern void *somePtr; + +@class MyObj; +static id _commonInit(MyObj *self) { + return self; +} + +@interface MyObj : NSObject { + id myivar; + int myint; +} +-(id)_init; +-(id)initWithSomething:(int)x; +-(void)doSomething; +@end + +@interface MyProxyObj : NSProxy {} +-(id)init; +@end + +@implementation MyObj + +-(id)init { + do { if (!((somePtr != 0))) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:"init.m"] lineNumber:21 description:(@"Invalid parameter not satisfying: %s"), ("x != 0"), (0), (0), (0), (0)]; } } while(0); + return [self initWithSomething:0]; +} + +-(id)init2 { + self = [self initWithSomething:0]; + return self; +} + +-(id)init3 { + log([self class]); + return [self initWithSomething:0]; +} + +-(id)init4 { + self = [super init]; + if (self) { + log(&self); + } + return self; +} + +- (id)initWithSomething:(int)x { + if ((self = [super init])) + myint = x; + return self; +} + +-(id)_init { + myivar = 0; + return self; +} + +-(id)init5 { + [NSBundle loadNibNamed:@"Window" owner:self]; + return [self initWithSomething:0]; +} + +-(id)init6 { + [NSBundle loadNibNamed:@"Window" owner:myivar]; // no-warning + return [self initWithSomething:0]; +} + +-(id)init7 { + if (0 != (self = [self _init])) + myivar = 0; + return self; +} + +-(id)init8 { + if ((self = [super init])) { + log(&self); + myivar = 0; + } + return self; +} + +-(id)init9 { + [self doSomething]; + return self; // no-warning +} + +-(id)init10 { + myivar = 0; // no-warning + return self; +} + +-(id)init11 { + return self; // no-warning +} + +-(id)init12 { + [super init]; + return self; // expected-warning {{Returning 'self'}} +} + +-(id)init13 { + if (self == [super init]) { + myivar = 0; // expected-warning {{Instance variable used}} + } + return self; // expected-warning {{Returning 'self'}} +} + +-(id)init14 { + if (!(self = [super init])) + return 0; + if (!(self = _commonInit(self))) + return 0; + return self; +} + +-(void)doSomething {} + +@end + +@implementation MyProxyObj + +- (id)init { return self; } + +@end diff --git a/test/Analysis/sizeofpointer.c b/test/Analysis/sizeofpointer.c index 82fda04114d23..6d0a2c4d2c26b 100644 --- a/test/Analysis/sizeofpointer.c +++ b/test/Analysis/sizeofpointer.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -warn-sizeof-pointer -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.SizeofPtr -verify %s struct s { }; diff --git a/test/Analysis/stack-addr-ps.c b/test/Analysis/stack-addr-ps.c index 342b3b1430a20..0ee8434080851 100644 --- a/test/Analysis/stack-addr-ps.c +++ b/test/Analysis/stack-addr-ps.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -fblocks -verify %s -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -fblocks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-checker=core.StackAddrLeak -analyzer-store=basic -fblocks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-checker=core.StackAddrLeak -analyzer-store=region -fblocks -verify %s int* f1() { int x = 0; diff --git a/test/Analysis/stack-addr-ps.cpp b/test/Analysis/stack-addr-ps.cpp index 593ba1df94d34..0c1ffba4f8c5c 100644 --- a/test/Analysis/stack-addr-ps.cpp +++ b/test/Analysis/stack-addr-ps.cpp @@ -6,3 +6,89 @@ const int& g() { int s; return s; // expected-warning{{reference to stack memory associated with local variable 's' returned}} } + +const int& g2() { + int s1; + int &s2 = s1; // expected-note {{binding reference variable 's2' here}} + return s2; // expected-warning {{reference to stack memory associated with local variable 's1' returned}} +} + +const int& g3() { + int s1; + int &s2 = s1; // expected-note {{binding reference variable 's2' here}} + int &s3 = s2; // expected-note {{binding reference variable 's3' here}} + return s3; // expected-warning {{reference to stack memory associated with local variable 's1' returned}} +} + +int get_value(); + +const int &get_reference1() { return get_value(); } // expected-warning {{returning reference to local temporary}} + +const int &get_reference2() { + const int &x = get_value(); // expected-note {{binding reference variable 'x' here}} + return x; // expected-warning {{returning reference to local temporary}} +} + +const int &get_reference3() { + const int &x1 = get_value(); // expected-note {{binding reference variable 'x1' here}} + const int &x2 = x1; // expected-note {{binding reference variable 'x2' here}} + return x2; // expected-warning {{returning reference to local temporary}} +} + +int global_var; +int *f1() { + int &y = global_var; + return &y; +} + +int *f2() { + int x1; + int &x2 = x1; // expected-note {{binding reference variable 'x2' here}} + return &x2; // expected-warning {{address of stack memory associated with local variable 'x1' returned}} +} + +int *f3() { + int x1; + int *const &x2 = &x1; // expected-note {{binding reference variable 'x2' here}} + return x2; // expected-warning {{address of stack memory associated with local variable 'x1' returned}} +} + +const int *f4() { + const int &x1 = get_value(); // expected-note {{binding reference variable 'x1' here}} + const int &x2 = x1; // expected-note {{binding reference variable 'x2' here}} + return &x2; // expected-warning {{returning address of local temporary}} +} + +struct S { + int x; +}; + +int *mf() { + S s1; + S &s2 = s1; // expected-note {{binding reference variable 's2' here}} + int &x = s2.x; // expected-note {{binding reference variable 'x' here}} + return &x; // expected-warning {{address of stack memory associated with local variable 's1' returned}} +} + +void *lf() { + label: + void *const &x = &&label; // expected-note {{binding reference variable 'x' here}} + return x; // expected-warning {{returning address of label, which is local}} +} + +typedef void (^bptr)(void); + +bptr bf(int j) { + __block int i; + const bptr &qq = ^{ i=0; }; // expected-note {{binding reference variable 'qq' here}} + return qq; // expected-error {{returning block that lives on the local stack}} +} + +template <typename T> +struct TS { + int *get(); + int *m() { + int *&x = get(); + return x; + } +}; diff --git a/test/Analysis/stackaddrleak.c b/test/Analysis/stackaddrleak.c index 39808ed873c80..359e482c8cff7 100644 --- a/test/Analysis/stackaddrleak.c +++ b/test/Analysis/stackaddrleak.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-checker=core.StackAddrLeak -analyzer-store region -verify %s char const *p; diff --git a/test/Analysis/stream.c b/test/Analysis/stream.c index 73bbc13cfbbc4..7dfd49b39dc01 100644 --- a/test/Analysis/stream.c +++ b/test/Analysis/stream.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -analyzer-store region -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-checker=unix.experimental.Stream -analyzer-store region -verify %s typedef __typeof__(sizeof(int)) size_t; typedef struct _IO_FILE FILE; @@ -77,3 +77,9 @@ FILE *f9(void) { void pr7831(FILE *fp) { fclose(fp); // no-warning } + +// PR 8081 - null pointer crash when 'whence' is not an integer constant +void pr8081(FILE *stream, long offset, int whence) { + fseek(stream, offset, whence); +} + diff --git a/test/Analysis/string.c b/test/Analysis/string.c index 35ed7106f745b..baf48930d7e8c 100644 --- a/test/Analysis/string.c +++ b/test/Analysis/string.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s -// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s -// RUN: %clang_cc1 -analyze -DVARIANT -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s -// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -DVARIANT -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.CString -analyzer-checker=core.experimental.UnreachableCode -analyzer-check-objc-mem -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-checker=core.experimental.CString -analyzer-checker=core.experimental.UnreachableCode -analyzer-check-objc-mem -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -DVARIANT -analyzer-checker=core.experimental.CString -analyzer-checker=core.experimental.UnreachableCode -analyzer-check-objc-mem -analyzer-store=region -verify %s +// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -DVARIANT -analyzer-checker=core.experimental.CString -analyzer-checker=core.experimental.UnreachableCode -analyzer-check-objc-mem -analyzer-store=region -verify %s //===----------------------------------------------------------------------=== // Declarations diff --git a/test/Analysis/temp-obj-dtors-cfg-output.cpp b/test/Analysis/temp-obj-dtors-cfg-output.cpp new file mode 100644 index 0000000000000..5ed782c690a1d --- /dev/null +++ b/test/Analysis/temp-obj-dtors-cfg-output.cpp @@ -0,0 +1,591 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -cfg-add-implicit-dtors -cfg-add-initializers %s 2>&1 | FileCheck %s +// XPASS: * + +class A { +public: + A() {} + ~A() {} + + static A make() { return A(); } + + operator bool() { return false; } + operator int() { return 0; } +}; + +class B { +public: + B() {} + ~B() {} + + operator bool() { return true; } + operator int() { return 1; } + operator A() { return A(); } +}; + +void foo(int); +void foo(bool); +void foo(const A&); + +void test_binary() { + int a = int(A()) + int(B()); + foo(int(A()) + int(B())); + int b; +} + +void test_and() { + bool a = A() && B(); + foo(A() && B()); + int b; +} + +void test_or() { + bool a = A() || B(); + foo(A() || B()); + int b; +} + +void test_cond() { + A a = B() ? A() : A(B()); + if (B()) { foo(0); } else { foo(0); } + int b; +} + +void test_cond_cref() { + const A& a = B() ? A() : A(B()); + foo(B() ? A() : A(B())); + int b; +} + +void test_cond_implicit() { + A a = A() ?: A(); + int b; +} + +void test_cond_implicit_cref() { + const A& a = A() ?: A(); + foo(A() ?: A()); + int b; +} + +void test_copy_init() { + A a = A(); + int b; +} + +void test_cref_init() { + const A& a = A(); + foo(A()); + int b; +} + +void test_call_copy_init() { + A a = A::make(); + int b; +} + +void test_call_cref_init() { + const A& a = A::make(); + foo(A::make()); + int b; +} + +void test_assign() { + int a; + a = A(); + int b; +} + +class TestCtorInits { + int a; + int b; +public: + TestCtorInits(); +}; + +TestCtorInits::TestCtorInits() + : a(int(A()) + int(B())) + , b() {} + +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: A() +// CHECK: 2: [B1.1].operator int() +// CHECK: 3: B() +// CHECK: 4: [B1.3].operator int() +// CHECK: 5: int a = int(A().operator int()) + int(B().operator int()); +// CHECK: 6: ~B() (Temporary object destructor) +// CHECK: 7: ~A() (Temporary object destructor) +// CHECK: 8: A() +// CHECK: 9: [B1.8].operator int() +// CHECK: 10: B() +// CHECK: 11: [B1.10].operator int() +// CHECK: 12: foo(int([B1.9]) + int([B1.11])) +// CHECK: 13: ~B() (Temporary object destructor) +// CHECK: 14: ~A() (Temporary object destructor) +// CHECK: 15: int b; +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B10 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B8 +// CHECK: [ B1 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: int b; +// CHECK: Predecessors (2): B2 B3 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: ~B() (Temporary object destructor) +// CHECK: Predecessors (1): B3 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: [B4.3] && [B5.2] +// CHECK: 2: foo([B3.1]) +// CHECK: T: [B4.3] && ... +// CHECK: Predecessors (2): B5 B4 +// CHECK: Successors (2): B2 B1 +// CHECK: [ B4 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: A() +// CHECK: 3: [B4.2].operator _Bool() +// CHECK: T: [B4.3] && ... +// CHECK: Predecessors (2): B6 B7 +// CHECK: Successors (2): B5 B3 +// CHECK: [ B5 ] +// CHECK: 1: B() +// CHECK: 2: [B5.1].operator _Bool() +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B3 +// CHECK: [ B6 ] +// CHECK: 1: ~B() (Temporary object destructor) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B4 +// CHECK: [ B7 ] +// CHECK: 1: [B8.2] && [B9.2] +// CHECK: 2: bool a = A().operator _Bool() && B().operator _Bool(); +// CHECK: T: [B8.2] && ... +// CHECK: Predecessors (2): B9 B8 +// CHECK: Successors (2): B6 B4 +// CHECK: [ B8 ] +// CHECK: 1: A() +// CHECK: 2: [B8.1].operator _Bool() +// CHECK: T: [B8.2] && ... +// CHECK: Predecessors (1): B10 +// CHECK: Successors (2): B9 B7 +// CHECK: [ B9 ] +// CHECK: 1: B() +// CHECK: 2: [B9.1].operator _Bool() +// CHECK: Predecessors (1): B8 +// CHECK: Successors (1): B7 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B10 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B8 +// CHECK: [ B1 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: int b; +// CHECK: Predecessors (2): B2 B3 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: ~B() (Temporary object destructor) +// CHECK: Predecessors (1): B3 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: [B4.3] || [B5.2] +// CHECK: 2: foo([B3.1]) +// CHECK: T: [B4.3] || ... +// CHECK: Predecessors (2): B5 B4 +// CHECK: Successors (2): B1 B2 +// CHECK: [ B4 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: A() +// CHECK: 3: [B4.2].operator _Bool() +// CHECK: T: [B4.3] || ... +// CHECK: Predecessors (2): B6 B7 +// CHECK: Successors (2): B3 B5 +// CHECK: [ B5 ] +// CHECK: 1: B() +// CHECK: 2: [B5.1].operator _Bool() +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B3 +// CHECK: [ B6 ] +// CHECK: 1: ~B() (Temporary object destructor) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B4 +// CHECK: [ B7 ] +// CHECK: 1: [B8.2] || [B9.2] +// CHECK: 2: bool a = A().operator _Bool() || B().operator _Bool(); +// CHECK: T: [B8.2] || ... +// CHECK: Predecessors (2): B9 B8 +// CHECK: Successors (2): B4 B6 +// CHECK: [ B8 ] +// CHECK: 1: A() +// CHECK: 2: [B8.1].operator _Bool() +// CHECK: T: [B8.2] || ... +// CHECK: Predecessors (1): B10 +// CHECK: Successors (2): B7 B9 +// CHECK: [ B9 ] +// CHECK: 1: B() +// CHECK: 2: [B9.1].operator _Bool() +// CHECK: Predecessors (1): B8 +// CHECK: Successors (1): B7 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B11 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B10 +// CHECK: [ B1 ] +// CHECK: 1: int b; +// CHECK: 2: [B7.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B2 B3 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: foo(0) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: foo(0) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B4 ] +// CHECK: 1: ~B() (Temporary object destructor) +// CHECK: 2: B() +// CHECK: 3: [B4.2].operator _Bool() +// CHECK: 4: ~B() (Temporary object destructor) +// CHECK: T: if [B4.3] +// CHECK: Predecessors (2): B5 B6 +// CHECK: Successors (2): B3 B2 +// CHECK: [ B5 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: ~A() (Temporary object destructor) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B4 +// CHECK: [ B6 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: ~A() (Temporary object destructor) +// CHECK: 3: ~A() (Temporary object destructor) +// CHECK: 4: ~B() (Temporary object destructor) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B4 +// CHECK: [ B7 ] +// CHECK: 1: [B10.2] ? [B8.2] : [B9.3] +// CHECK: 2: A a = B().operator _Bool() ? A() : A(B().operator A()); +// CHECK: T: [B10.2] ? ... : ... +// CHECK: Predecessors (2): B8 B9 +// CHECK: Successors (2): B5 B6 +// CHECK: [ B8 ] +// CHECK: 1: A() +// CHECK: 2: [B8.1] (BindTemporary) +// CHECK: Predecessors (1): B10 +// CHECK: Successors (1): B7 +// CHECK: [ B9 ] +// CHECK: 1: B() +// CHECK: 2: [B9.1].operator A() +// CHECK: 3: A([B9.2]) (BindTemporary) +// CHECK: Predecessors (1): B10 +// CHECK: Successors (1): B7 +// CHECK: [ B10 ] +// CHECK: 1: B() +// CHECK: 2: [B10.1].operator _Bool() +// CHECK: T: [B10.2] ? ... : ... +// CHECK: Predecessors (1): B11 +// CHECK: Successors (2): B8 B9 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B14 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B13 +// CHECK: [ B1 ] +// CHECK: 1: ~B() (Temporary object destructor) +// CHECK: 2: int b; +// CHECK: 3: [B10.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B2 B3 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: ~A() (Temporary object destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: ~A() (Temporary object destructor) +// CHECK: 3: ~A() (Temporary object destructor) +// CHECK: 4: ~B() (Temporary object destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B4 ] +// CHECK: 1: [B7.3] ? [B5.2] : [B6.3] +// CHECK: 2: foo([B4.1]) +// CHECK: T: [B7.3] ? ... : ... +// CHECK: Predecessors (2): B5 B6 +// CHECK: Successors (2): B2 B3 +// CHECK: [ B5 ] +// CHECK: 1: A() +// CHECK: 2: [B5.1] (BindTemporary) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B4 +// CHECK: [ B6 ] +// CHECK: 1: B() +// CHECK: 2: [B6.1].operator A() +// CHECK: 3: A([B6.2]) (BindTemporary) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B4 +// CHECK: [ B7 ] +// CHECK: 1: ~B() (Temporary object destructor) +// CHECK: 2: B() +// CHECK: 3: [B7.2].operator _Bool() +// CHECK: T: [B7.3] ? ... : ... +// CHECK: Predecessors (2): B8 B9 +// CHECK: Successors (2): B5 B6 +// CHECK: [ B8 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: Predecessors (1): B10 +// CHECK: Successors (1): B7 +// CHECK: [ B9 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: ~A() (Temporary object destructor) +// CHECK: 3: ~B() (Temporary object destructor) +// CHECK: Predecessors (1): B10 +// CHECK: Successors (1): B7 +// CHECK: [ B10 ] +// CHECK: 1: [B13.2] ? [B11.2] : [B12.3] +// CHECK: 2: const A &a = B().operator _Bool() ? A() : A(B().operator A()); +// CHECK: T: [B13.2] ? ... : ... +// CHECK: Predecessors (2): B11 B12 +// CHECK: Successors (2): B8 B9 +// CHECK: [ B11 ] +// CHECK: 1: A() +// CHECK: 2: [B11.1] (BindTemporary) +// CHECK: Predecessors (1): B13 +// CHECK: Successors (1): B10 +// CHECK: [ B12 ] +// CHECK: 1: B() +// CHECK: 2: [B12.1].operator A() +// CHECK: 3: A([B12.2]) (BindTemporary) +// CHECK: Predecessors (1): B13 +// CHECK: Successors (1): B10 +// CHECK: [ B13 ] +// CHECK: 1: B() +// CHECK: 2: [B13.1].operator _Bool() +// CHECK: T: [B13.2] ? ... : ... +// CHECK: Predecessors (1): B14 +// CHECK: Successors (2): B11 B12 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B8 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B7 +// CHECK: [ B1 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: int b; +// CHECK: 3: [B4.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B2 B3 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: ~A() (Temporary object destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B4 ] +// CHECK: 1: [B7.2] ?: [B6.2] +// CHECK: 2: A a = A() ?: A(); +// CHECK: T: [B7.3] ? ... : ... +// CHECK: Predecessors (2): B5 B6 +// CHECK: Successors (2): B2 B3 +// CHECK: [ B5 ] +// CHECK: 1: +// CHECK: 2: [B5.1] (BindTemporary) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B4 +// CHECK: [ B6 ] +// CHECK: 1: A() +// CHECK: 2: [B6.1] (BindTemporary) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B4 +// CHECK: [ B7 ] +// CHECK: 1: A() +// CHECK: 2: [B7.1] (BindTemporary) +// CHECK: 3: .operator _Bool() +// CHECK: T: [B7.3] ? ... : ... +// CHECK: Predecessors (1): B8 +// CHECK: Successors (2): B5 B6 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B13 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B12 +// CHECK: [ B1 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: int b; +// CHECK: 3: [B9.2].~A() (Implicit destructor) +// CHECK: Predecessors (2): B2 B3 +// CHECK: Successors (1): B0 +// CHECK: [ B2 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B3 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: ~A() (Temporary object destructor) +// CHECK: Predecessors (1): B4 +// CHECK: Successors (1): B1 +// CHECK: [ B4 ] +// CHECK: 1: [B7.3] ?: [B6.2] +// CHECK: 2: foo([B4.1]) +// CHECK: T: [B7.4] ? ... : ... +// CHECK: Predecessors (2): B5 B6 +// CHECK: Successors (2): B2 B3 +// CHECK: [ B5 ] +// CHECK: 1: +// CHECK: 2: [B5.1] (BindTemporary) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B4 +// CHECK: [ B6 ] +// CHECK: 1: A() +// CHECK: 2: [B6.1] (BindTemporary) +// CHECK: Predecessors (1): B7 +// CHECK: Successors (1): B4 +// CHECK: [ B7 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: A() +// CHECK: 3: [B7.2] (BindTemporary) +// CHECK: 4: .operator _Bool() +// CHECK: T: [B7.4] ? ... : ... +// CHECK: Predecessors (2): B9 B8 +// CHECK: Successors (2): B5 B6 +// CHECK: [ B8 ] +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: Predecessors (1): B9 +// CHECK: Successors (1): B7 +// CHECK: [ B9 ] +// CHECK: 1: [B12.2] ?: [B11.2] +// CHECK: 2: const A &a = A() ?: A(); +// CHECK: T: [B12.3] ? ... : ... +// CHECK: Predecessors (2): B10 B11 +// CHECK: Successors (2): B7 B8 +// CHECK: [ B10 ] +// CHECK: 1: +// CHECK: 2: [B10.1] (BindTemporary) +// CHECK: Predecessors (1): B12 +// CHECK: Successors (1): B9 +// CHECK: [ B11 ] +// CHECK: 1: A() +// CHECK: 2: [B11.1] (BindTemporary) +// CHECK: Predecessors (1): B12 +// CHECK: Successors (1): B9 +// CHECK: [ B12 ] +// CHECK: 1: A() +// CHECK: 2: [B12.1] (BindTemporary) +// CHECK: 3: .operator _Bool() +// CHECK: T: [B12.3] ? ... : ... +// CHECK: Predecessors (1): B13 +// CHECK: Successors (2): B10 B11 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: A() +// CHECK: 2: A a = A(); +// CHECK: 3: ~A() (Temporary object destructor) +// CHECK: 4: int b; +// CHECK: 5: [B1.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: A() +// CHECK: 2: const A &a = A(); +// CHECK: 3: A() +// CHECK: 4: foo([B1.3]) +// CHECK: 5: ~A() (Temporary object destructor) +// CHECK: 6: int b; +// CHECK: 7: [B1.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: A::make() +// CHECK: 2: A a = A::make(); +// CHECK: 3: ~A() (Temporary object destructor) +// CHECK: 4: int b; +// CHECK: 5: [B1.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: A::make() +// CHECK: 2: const A &a = A::make(); +// CHECK: 3: A::make() +// CHECK: 4: foo([B1.3]) +// CHECK: 5: ~A() (Temporary object destructor) +// CHECK: 6: int b; +// CHECK: 7: [B1.2].~A() (Implicit destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: int a; +// CHECK: 2: A() +// CHECK: 3: [B1.2].operator int() +// CHECK: 4: a = [B1.3] +// CHECK: 5: ~A() (Temporary object destructor) +// CHECK: 6: int b; +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: A() +// CHECK: 2: [B1.1].operator int() +// CHECK: 3: B() +// CHECK: 4: [B1.3].operator int() +// CHECK: 5: a(int([B1.2]) + int([B1.4])) (Member initializer) +// CHECK: 6: ~B() (Temporary object destructor) +// CHECK: 7: ~A() (Temporary object destructor) +// CHECK: 8: b(/*implicit*/int()) (Member initializer) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0): diff --git a/test/Analysis/uninit-msg-expr.m b/test/Analysis/uninit-msg-expr.m index 4061150ec5538..a8e2f1b655925 100644 --- a/test/Analysis/uninit-msg-expr.m +++ b/test/Analysis/uninit-msg-expr.m @@ -42,7 +42,7 @@ extern NSString * const NSUndoManagerCheckpointNotification; unsigned f1() { NSString *aString; - return [aString length]; // expected-warning {{Receiver in message expression is a garbage value}} + return [aString length]; // expected-warning {{Receiver in message expression is an uninitialized value}} } unsigned f2() { @@ -53,5 +53,5 @@ unsigned f2() { void f3() { NSMutableArray *aArray = [NSArray array]; NSString *aString; - [aArray addObject:aString]; // expected-warning {{Pass-by-value argument in message expression is undefined.}} + [aArray addObject:aString]; // expected-warning {{Argument in message expression is an uninitialized value}} } diff --git a/test/Analysis/uninit-ps-rdar6145427.m b/test/Analysis/uninit-ps-rdar6145427.m index 1409dbd1df5e3..ccaf2e8105bf8 100644 --- a/test/Analysis/uninit-ps-rdar6145427.m +++ b/test/Analysis/uninit-ps-rdar6145427.m @@ -30,7 +30,7 @@ extern NSString * const NSUndoManagerCheckpointNotification; int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - id someUnintializedPointer = [someUnintializedPointer objectAtIndex:0]; // expected-warning{{Receiver in message expression is a garbage value}} + id someUnintializedPointer = [someUnintializedPointer objectAtIndex:0]; // expected-warning{{Receiver in message expression is an uninitialized value}} NSLog(@"%@", someUnintializedPointer); [pool drain]; return 0; diff --git a/test/Analysis/uninit-vals-ps-region.m b/test/Analysis/uninit-vals-ps-region.m index 751e91ba8627c..2b3b027657f64 100644 --- a/test/Analysis/uninit-vals-ps-region.m +++ b/test/Analysis/uninit-vals-ps-region.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -analyzer-check-idempotent-operations -verify %s +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -analyzer-checker=core.experimental.IdempotentOps -verify %s struct s { int data; diff --git a/test/Analysis/uninit-vals-ps.c b/test/Analysis/uninit-vals-ps.c index 4abd413ae5d59..9e53fbc34881a 100644 --- a/test/Analysis/uninit-vals-ps.c +++ b/test/Analysis/uninit-vals-ps.c @@ -15,7 +15,7 @@ int f1_a(struct FPRec* foo) { int f1_b() { int x; - return bar(x)+1; // expected-warning{{Pass-by-value argument in function call is undefined.}} + return bar(x)+1; // expected-warning{{Function call argument is an uninitialized value}} } int f2() { diff --git a/test/Analysis/uninit-vals.c b/test/Analysis/uninit-vals.c index b0769ba6bce1e..e4395e8486611 100644 --- a/test/Analysis/uninit-vals.c +++ b/test/Analysis/uninit-vals.c @@ -32,7 +32,7 @@ void f6(int i) { int x; for (i = 0 ; i < 10; i++) printf("%d",x++); // expected-warning {{use of uninitialized variable}} \ - // expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \ + // expected-warning{{implicitly declaring C library function 'printf' with type 'int (const char *, ...)'}} \ // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}} } diff --git a/test/Analysis/unix-fns.c b/test/Analysis/unix-fns.c index 9d036ac7b5c60..9f5362d184ff0 100644 --- a/test/Analysis/unix-fns.c +++ b/test/Analysis/unix-fns.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem %s -analyzer-store=region -fblocks -verify -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem %s -analyzer-store=basic -fblocks -verify +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem -analyzer-checker=unix.API -analyzer-checker=macosx.API %s -analyzer-store=region -fblocks -verify +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem -analyzer-checker=unix.API -analyzer-checker=macosx.API %s -analyzer-store=basic -fblocks -verify struct _opaque_pthread_once_t { long __sig; @@ -8,6 +8,9 @@ struct _opaque_pthread_once_t { typedef struct _opaque_pthread_once_t __darwin_pthread_once_t; typedef __darwin_pthread_once_t pthread_once_t; int pthread_once(pthread_once_t *, void (*)(void)); +typedef long unsigned int __darwin_size_t; +typedef __darwin_size_t size_t; +void *malloc(size_t); typedef void (^dispatch_block_t)(void); typedef long dispatch_once_t; @@ -50,3 +53,17 @@ void test_pthread_once_neg() { static pthread_once_t pred = {0x30B1BCBA, {0}}; pthread_once(&pred, test_pthread_once_aux); // no-warning } + +// PR 2899 - warn of zero-sized allocations to malloc(). +void pr2899() { + char* foo = malloc(0); // expected-warning{{Call to 'malloc' has an allocation size of 0 bytes}} + for (unsigned i = 0; i < 100; i++) { + foo[i] = 0; + } +} +void pr2899_nowarn(size_t size) { + char* foo = malloc(size); // no-warning + for (unsigned i = 0; i < 100; i++) { + foo[i] = 0; + } +} diff --git a/test/Analysis/unreachable-code-path.c b/test/Analysis/unreachable-code-path.c index 071532739cbe7..52e6d3df2c015 100644 --- a/test/Analysis/unreachable-code-path.c +++ b/test/Analysis/unreachable-code-path.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-experimental-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -verify -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.UnreachableCode -analyzer-check-objc-mem -analyzer-checker=core.DeadStores -verify -analyzer-opt-analyze-nested-blocks -Wno-unused-value %s extern void foo(int a); @@ -93,8 +93,8 @@ void test9(unsigned a) { switch (a) { if (a) // expected-warning{{never executed}} foo(a + 5); // no-warning - else // no-warning - foo(a); // no-warning + else // no-warning + foo(a); // no-warning case 1: case 2: break; @@ -102,3 +102,23 @@ void test9(unsigned a) { break; } } + +// Tests from flow-sensitive version +void test10() { + goto c; + d: + goto e; // expected-warning {{never executed}} + c: ; + int i; + return; + goto b; // expected-warning {{never executed}} + goto a; // expected-warning {{never executed}} + b: + i = 1; // no-warning + a: + i = 2; // no-warning + goto f; + e: + goto d; + f: ; +} diff --git a/test/Analysis/unused-ivars.m b/test/Analysis/unused-ivars.m index 14c43a86c4086..b43ae18694dde 100644 --- a/test/Analysis/unused-ivars.m +++ b/test/Analysis/unused-ivars.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fblocks -analyze -analyzer-check-objc-unused-ivars %s -verify +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fblocks -analyze -analyzer-checker=cocoa.UnusedIvars %s -verify //===--- BEGIN: Delta-debugging reduced headers. --------------------------===// @@ -95,4 +95,16 @@ int radar_7254495(RDar7254495 *a) { @implementation RDar7353683 @end +//===----------------------------------------------------------------------===// +// <rdar://problem/8481311> Unused bitfield ivars trigger cause weird +// diagnostic: "Instance variable '' in class…" +//===----------------------------------------------------------------------===// +@interface RDar8481311 { +@private + unsigned bitfield:1; // expected-warning {{Instance variable 'bitfield' in class 'RDar8481311' is never used}} +} +@end + +@implementation RDar8481311 +@end |