This fixes the crash from https://github.com/llvm/llvm-project/issues/53742
CXXNewExpr::getArraySize() may return a llvm::Optional<> pointing to a nullptr.
Differential D119525
[clang] Fix crash when array size is missing in initializer tbaeder on Feb 10 2022, 11:38 PM. Authored by
Details This fixes the crash from https://github.com/llvm/llvm-project/issues/53742 CXXNewExpr::getArraySize() may return a llvm::Optional<> pointing to a nullptr.
Diff Detail
Event TimelineComment Actions This is a pretty big gotcha at best and I feel like getArraySize() should return None in that case instead... thoughts? Comment Actions I think it is a gotcha -- some places protect against a null pointer (https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/TreeTransform.h#L11923 and https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/StmtPrinter.cpp#L2138) while other places assume the pointer isn't null (https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGExprCXX.cpp#L731 and https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ExprConstant.cpp#L9431). So I think a better approach is to fix up the interface so it doesn't return nullptr rather than play whack-a-mole forever with the API (and fix up the places currently checking for nullptr explicitly).
Comment Actions LGTM aside from some minor nits. Can you also add a release note for the change?
Comment Actions Would this go in the "libclang" section in clang/docs/ReleaseNotes.rst? Or somewhere else? Comment Actions Nope, I'd add a new section titled "Bug Fixes" after "Major New Features" and then add it there. Comment Actions Continues to LGTM, though I had a recommendation for the release note. Feel free to land when you'd like.
|
Just added a reference to the bug that was fixed.