diff --git a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp @@ -298,8 +298,11 @@ DefinedOrUnknownSVal SizeIsKnown = SVB.evalEQ(State, DynSize, *ArraySizeNL); State = State->assume(SizeIsKnown, true); - // Assume should not fail at this point. - assert(State); + // State may not be valid since constraints do not comprehend expressions + // used for VLAs. If State is null, just silently return. + // See https://bugs.llvm.org/show_bug.cgi?id=47272. + if (!State) + return; } // Remember our assumptions! diff --git a/clang/test/Analysis/vla.c b/clang/test/Analysis/vla.c --- a/clang/test/Analysis/vla.c +++ b/clang/test/Analysis/vla.c @@ -151,3 +151,22 @@ foo(); } } // no-crash + + +// https://bugs.llvm.org/show_bug.cgi?id=47272 +// similar to the above case, just different enough to have not +// been covered. +// Just don't crash. +int bb; +int c() { + int d = 0; + int sum = 0; + while (bb) { + int count = bb - d; + int e[count]; + if (count > 4) + sum++; + d++; + } + return sum; +} // no-crash