[analyzer] CStringChecker: Fix a crash on C++ overloads of standard functions.
authorArtem Dergachev <artem.dergachev@gmail.com>
Wed, 19 Dec 2018 21:50:46 +0000 (21:50 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 19 Dec 2018 21:50:46 +0000 (21:50 +0000)
commitbe2c0c1968475eb066d0a906d58d062e2115c1f8
treef14f2dc6484fc284472693b4c0736b964cb62b91
parented3ef4171173999be0f40e6fb7f5e60f5613b597
[analyzer] CStringChecker: Fix a crash on C++ overloads of standard functions.

It turns out that it's not all that uncommon to have a C++ override of, say,
memcpy that receives a structure (or two) by reference (or by value, if it's
being copied from) and copies memory from it (or into it, if it's passed
by reference). In this case the argument will be of structure type (recall that
expressions of reference type do not exist: instead, C++ classifies expressions
into prvalues and lvalues and xvalues).

In this scenario we crash because we are trying to assume that, say,
a memory region is equal to an empty CompoundValue (the non-lazy one; this is
what makeZeroVal() return for compound types and it represents prvalue of
an object that is initialized with an empty initializer list).

Add defensive checks.

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

rdar://problem/45366551

llvm-svn: 349682
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp