[analyzer] Trust global initializers when analyzing main().
authorArtem Dergachev <artem.dergachev@gmail.com>
Wed, 28 Aug 2019 18:44:32 +0000 (18:44 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 28 Aug 2019 18:44:32 +0000 (18:44 +0000)
commit8b2a39e9377ea38f69c27e78964a11e992881d4f
treebad25fa87ec734a74d398a20122fd653c08bfe4c
parent83d2f0e7993a376c5ffb65e5760e58e72d27daee
[analyzer] Trust global initializers when analyzing main().

If the global variable has an initializer, we'll ignore it because we're usually
not analyzing the program from the beginning, which means that the global
variable may have changed before we start our analysis.

However when we're analyzing main() as the top-level function, we can rely
on global initializers to still be valid. At least in C; in C++ we have global
constructors that can still break this logic.

This patch allows the Static Analyzer to load constant initializers from
global variables if the top-level function of the current analysis is main().

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

llvm-svn: 370244
clang/lib/StaticAnalyzer/Core/RegionStore.cpp
clang/test/Analysis/main.c [new file with mode: 0644]
clang/test/Analysis/main.cpp [new file with mode: 0644]