From 4991acc29ead05453c8ca45164d3b3684bc66f6f Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Tue, 23 Apr 2019 02:50:38 +0000 Subject: [analyzer] PR41335: Fix crash when no-store event is in a body-farmed function. Stuffing invalid source locations (such as those in functions produced by body farms) into path diagnostics causes crashes. Fix a typo in a nearby function name. Differential Revision: https://reviews.llvm.org/D60808 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358945 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Analysis/OSAtomic_mac.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/Analysis/OSAtomic_mac.c (limited to 'test/Analysis/OSAtomic_mac.c') diff --git a/test/Analysis/OSAtomic_mac.c b/test/Analysis/OSAtomic_mac.c new file mode 100644 index 0000000000..a69d98078e --- /dev/null +++ b/test/Analysis/OSAtomic_mac.c @@ -0,0 +1,20 @@ +// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection \ +// RUN: -analyzer-output=text -verify %s + +int OSAtomicCompareAndSwapPtrBarrier(*, *, **); +int OSAtomicCompareAndSwapPtrBarrier() { + // There is some body in the actual header, + // but we should trust our BodyFarm instead. +} + +int *invalidSLocOnRedecl() { + int *b; // expected-note{{'b' declared without an initial value}} + + OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // no-crash + // FIXME: We don't really need these notes. + // expected-note@-2{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}} + // expected-note@-3{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}} + + return b; // expected-warning{{Undefined or garbage value returned to caller}} + // expected-note@-1{{Undefined or garbage value returned to caller}} +} -- cgit v1.2.3 From 959aef71a5366689e5ef2b835b9ca968767addf3 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Tue, 23 Apr 2019 02:56:00 +0000 Subject: [analyzer] Unbreak body farms in presence of multiple declarations. When growing a body on a body farm, it's essential to use the same redeclaration of the function that's going to be used during analysis. Otherwise our ParmVarDecls won't match the ones that are used to identify argument regions. This boils down to trusting the reasoning in AnalysisDeclContext. We shouldn't canonicalize the declaration before farming the body because it makes us not obey the sophisticated decision-making process of AnalysisDeclContext. Differential Revision: https://reviews.llvm.org/D60899 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358946 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Analysis/OSAtomic_mac.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'test/Analysis/OSAtomic_mac.c') diff --git a/test/Analysis/OSAtomic_mac.c b/test/Analysis/OSAtomic_mac.c index a69d98078e..b09c71f6c6 100644 --- a/test/Analysis/OSAtomic_mac.c +++ b/test/Analysis/OSAtomic_mac.c @@ -8,13 +8,20 @@ int OSAtomicCompareAndSwapPtrBarrier() { } int *invalidSLocOnRedecl() { - int *b; // expected-note{{'b' declared without an initial value}} - + // Was crashing when trying to throw a report about returning an uninitialized + // value to the caller. FIXME: We should probably still throw that report, + // something like "The "compare" part of CompareAndSwap depends on an + // undefined value". + int *b; OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // no-crash - // FIXME: We don't really need these notes. - // expected-note@-2{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}} - // expected-note@-3{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}} + return b; +} - return b; // expected-warning{{Undefined or garbage value returned to caller}} - // expected-note@-1{{Undefined or garbage value returned to caller}} +void testThatItActuallyWorks() { + void *x = 0; + int res = OSAtomicCompareAndSwapPtrBarrier(0, &x, &x); + clang_analyzer_eval(res); // expected-warning{{TRUE}} + // expected-note@-1{{TRUE}} + clang_analyzer_eval(x == &x); // expected-warning{{TRUE}} + // expected-note@-1{{TRUE}} } -- cgit v1.2.3