Backporting fix for the issue reported in https://github.com/llvm/llvm-project/issues/99714 to release/19.x /cherry-pick [68df06a](https://github.com/llvm/llvm-project/commit/68df06a0b2998765cb0a41353fcf0919bbf57ddb)