Skip to content
Snippets Groups Projects
Commit 5faafe70 authored by Artem Dergachev's avatar Artem Dergachev
Browse files

[analyzer] Allow undefined values in performTrivialCopy.

Reading from a garbage pointer should be modeled as garbage,
and performTrivialCopy should be able to deal with any SVal input.

Patch by Ilya Palachev!

Differential Revision: https://reviews.llvm.org/D25727


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285640 91177308-0d34-0410-b5e6-96231b3b80d8
parent 8d342030
No related branches found
No related tags found
No related merge requests found
......@@ -65,7 +65,7 @@ void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
if (Optional<Loc> L = V.getAs<Loc>())
V = Pred->getState()->getSVal(*L);
else
assert(V.isUnknown());
assert(V.isUnknownOrUndef());
const Expr *CallExpr = Call.getOriginExpr();
evalBind(Dst, CallExpr, Pred, ThisVal, V, true);
......
// RUN: %clang_cc1 -analyze -analyzer-checker=core.builtin -verify -DCHECK_FOR_CRASH %s
// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
#ifdef CHECK_FOR_CRASH
// expected-no-diagnostics
#endif
namespace PerformTrivialCopyForUndefs {
struct A {
int x;
};
struct B {
A a;
};
struct C {
B b;
};
void foo() {
C c1;
C *c2;
#ifdef CHECK_FOR_CRASH
// If the value of variable is not defined and checkers that check undefined
// values are not enabled, performTrivialCopy should be able to handle the
// case with undefined values, too.
c1.b.a = c2->b.a;
#else
c1.b.a = c2->b.a; // expected-warning{{Function call argument is an uninitialized value}}
#endif
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment