Cherry-picking commits from master to 2.066 branch

[REG2.066a] Issue 13187 - Function wrongly deduced as pure