Yes, you do need to declare your religion, mostly to know if you're not Jewish. But other stories about arbitrary arrests and executions of foreigners for reasons like religion and so forth are urban myths.
Well, the same goes for Iran, as there are also urban myths.
As much as I dislike Ayatollah Khomeini, when he came to power he declared that Christian and Jewish (yes, there is Jewish minority in Iran since hundreds of years) shall not be oppressed in any way. The unlucky exception are, of course, Baha'i followers.