From 394588a1a65203966a23c645357aef6f900f3c17 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Fri, 4 May 2018 22:19:32 +0000 Subject: [analyzer] Invalidate union regions properly. Don't hesitate to load later. We weren't invalidating our unions correctly. The previous behavior in invalidateRegionsWorker::VisitCluster() was to direct-bind an UnknownVal to the union (at offset 0). For that reason we were never actually loading default bindings from our unions, because there never was any default binding to load, and the value that is presumed when there's no default binding to load is usually completely incorrect (eg. UndefinedVal for stack unions). The new behavior is to default-bind a conjured symbol (of irrelevant type) to the union that's being invalidated, similarly to what we do for structures and classes. Then it becomes safe to load the value properly. Differential Revision: https://reviews.llvm.org/D45241 llvm-svn: 331563 --- clang/lib/StaticAnalyzer/Core/RegionStore.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'clang/lib/StaticAnalyzer/Core') diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp index d4624c089da..8f3205675d9 100644 --- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp @@ -230,11 +230,6 @@ Optional RegionBindingsRef::getDirectBinding(const MemRegion *R) const { } Optional RegionBindingsRef::getDefaultBinding(const MemRegion *R) const { - if (R->isBoundable()) - if (const TypedValueRegion *TR = dyn_cast(R)) - if (TR->getValueType()->isUnionType()) - return UnknownVal(); - return Optional::create(lookup(R, BindingKey::Default)); } @@ -1099,7 +1094,7 @@ void invalidateRegionsWorker::VisitCluster(const MemRegion *baseR, return; } - if (T->isStructureOrClassType()) { + if (T->isRecordType()) { // Invalidate the region by setting its default value to // conjured symbol. The type of the symbol is irrelevant. DefinedOrUnknownSVal V = svalBuilder.conjureSymbolVal(baseR, Ex, LCtx, -- cgit v1.2.3