There were two assertions in DefaultArgStorage::setInherited previously. It requires the DefaultArgument is either empty or an argument value. It would crash if it has a pointer refers to the previous declaration or contains a chain to the previous declaration.
But there are edge cases could hit them actually. One is InheritDefaultArguments.cppm that I found recently (there is another issue in the driver: https://github.com/llvm/llvm-project/issues/56327). Another one is pr31469.cpp, which was created fives years ago.
This patch tries to fix the two failures by handling full cases in DefaultArgStorage::setInherited.
This is guaranteed to not introduce any breaking change since it lives in the path we wouldn't touch before. And the added assertions for sameness should keep the correctness. But this is really fundamental, it would be better if someone else would like to take a look.