diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp index d4624c089da7..8f3205675d9d 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, diff --git a/clang/test/Analysis/unions.cpp b/clang/test/Analysis/unions.cpp index 2758cdaa26b3..2d6d0ae4a0db 100644 --- a/clang/test/Analysis/unions.cpp +++ b/clang/test/Analysis/unions.cpp @@ -79,8 +79,7 @@ namespace PR17596 { IntOrString vv; vv.i = 5; uu = vv; - // FIXME: Should be true. - clang_analyzer_eval(uu.i == 5); // expected-warning{{UNKNOWN}} + clang_analyzer_eval(uu.i == 5); // expected-warning{{TRUE}} } void testInvalidation() { @@ -106,3 +105,20 @@ namespace PR17596 { clang_analyzer_eval(uu.s[0] == 'a'); // expected-warning{{UNKNOWN}} } } + +namespace assume_union_contents { +union U { + int x; +}; + +U get(); + +void test() { + U u = get(); + int y = 0; + if (u.x) + y = 1; + if (u.x) + y = 1 / y; // no-warning +} +} // end namespace assume_union_contents