This revision was automatically updated to reflect the committed changes. Closed by commit rL285640: [analyzer] Allow undefined values in performTrivialCopy. (authored by dergachev).
Changed prior to commit: https://reviews.llvm.org/D25727?vs=74994&id=76482#toc Repository: rL LLVM https://reviews.llvm.org/D25727 Files: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp cfe/trunk/test/Analysis/uninit-vals.cpp Index: cfe/trunk/test/Analysis/uninit-vals.cpp =================================================================== --- cfe/trunk/test/Analysis/uninit-vals.cpp +++ cfe/trunk/test/Analysis/uninit-vals.cpp @@ -0,0 +1,34 @@ +// 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 +} +} + Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -65,7 +65,7 @@ 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);
Index: cfe/trunk/test/Analysis/uninit-vals.cpp =================================================================== --- cfe/trunk/test/Analysis/uninit-vals.cpp +++ cfe/trunk/test/Analysis/uninit-vals.cpp @@ -0,0 +1,34 @@ +// 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 +} +} + Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -65,7 +65,7 @@ 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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits