diff options
Diffstat (limited to 'test/Analysis/inlining/false-positive-suppression.c')
-rw-r--r-- | test/Analysis/inlining/false-positive-suppression.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/test/Analysis/inlining/false-positive-suppression.c b/test/Analysis/inlining/false-positive-suppression.c index 20cc311..a836d9c 100644 --- a/test/Analysis/inlining/false-positive-suppression.c +++ b/test/Analysis/inlining/false-positive-suppression.c @@ -9,6 +9,8 @@ int *getNull() { return 0; } +int* getPtr(); + int *dynCastToInt(void *ptr) { if (opaquePropertyCheck(ptr)) return (int *)ptr; @@ -73,6 +75,15 @@ void testBranchReversed(void *p) { *casted = 1; // expected-warning {{Dereference of null pointer}} } +void testMultipleStore(void *p) { + int *casted = 0; + casted = dynCastToInt(p); + *casted = 1; +#ifndef SUPPRESSED + // expected-warning@-2 {{Dereference of null pointer}} +#endif +} + // -------------------------- // "Suppression suppression" @@ -182,3 +193,77 @@ void testAlwaysReturnNull(void *input) { #endif } +int derefArg(int *p) { + return *p; +#ifndef SUPPRESSED + // expected-warning@-2 {{Dereference of null pointer}} +#endif +} +void ternaryArg(char cond) { + static int x; + derefArg(cond ? &x : getNull()); +} + +int derefArgCast(char *p) { + return *p; +#ifndef SUPPRESSED + // expected-warning@-2 {{Dereference of null pointer}} +#endif +} +void ternaryArgCast(char cond) { + static int x; + derefArgCast((char*)((unsigned)cond ? &x : getNull())); +} + +int derefAssignment(int *p) { + return *p; +#ifndef SUPPRESSED + // expected-warning@-2 {{Dereference of null pointer}} +#endif +} + +void ternaryAssignment(char cond) { + static int x; + int *p = cond ? getNull() : getPtr(); + derefAssignment(p); +} + +int *retNull(char cond) { + static int x; + return cond ? &x : getNull(); +} +int ternaryRetNull(char cond) { + int *p = retNull(cond); + return *p; +#ifndef SUPPRESSED + // expected-warning@-2 {{Dereference of null pointer}} +#endif +} + +// Test suppression of nested conditional operators. +int testConditionalOperatorSuppress(int x) { + return *(x ? getNull() : getPtr()); +#ifndef SUPPRESSED + // expected-warning@-2 {{Dereference of null pointer}} +#endif +} +int testNestedConditionalOperatorSuppress(int x) { + return *(x ? (x ? getNull() : getPtr()) : getPtr()); +#ifndef SUPPRESSED + // expected-warning@-2 {{Dereference of null pointer}} +#endif +} +int testConditionalOperator(int x) { + return *(x ? 0 : getPtr()); // expected-warning {{Dereference of null pointer}} +} +int testNestedConditionalOperator(int x) { + return *(x ? (x ? 0 : getPtr()) : getPtr()); // expected-warning {{Dereference of null pointer}} +} + +int testConditionalOperatorSuppressFloatCond(float x) { + return *(x ? getNull() : getPtr()); +#ifndef SUPPRESSED + // expected-warning@-2 {{Dereference of null pointer}} +#endif +} + |