[PATCH] D86892: Improve error handling for SmallVector programming errors.

Geoffrey Martin-Noble via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 31 13:04:54 PDT 2020


GMNGeoffrey added inline comments.


================
Comment at: llvm/lib/Support/ErrorHandling.cpp:172
   char OOMMessage[] = "LLVM ERROR: out of memory\n";
   ssize_t written = ::write(2, OOMMessage, strlen(OOMMessage));
+  written = ::write(2, Reason, strlen(Reason));
----------------
MaskRay wrote:
> If the return value is to be ignored, the variable can be removed, i.e. `(void)::write(...)`
Yeah I wasn't clear why this variable was here, but was just following the existing code. Happy to drop it.


================
Comment at: llvm/lib/Support/SmallVector.cpp:52
   if (MinCapacity > SizeTypeMax())
-    report_bad_alloc_error("SmallVector capacity overflow during allocation");
+    report_fatal_error("SmallVector unable to grow. Requested capacity (" +
+                       std::to_string(MinCapacity) +
----------------
MaskRay wrote:
> This can continue to use `report_bad_alloc_error` for a bit more context
I disagree. `report_bad_alloc_error` reports an OOM, which this is not. There is no amount of system memory that would make this not an error. The particular time we hit it, we'd accidentally passed a negative int to `SmallVector::reserve`. Having this reported as an OOM was confusing and I ended up wasting a bunch of debugging time trying to figure out what was using all our memory.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86892/new/

https://reviews.llvm.org/D86892



More information about the llvm-commits mailing list