I'm unsure between "I'd ask whoever gave it to you" and "I'd ask whomever gave it to you". As usual, I tried substituting 'he' and 'him' to see which fits, but neither fits both halves (it could be "I'd ask him" or "he gave it to you"). Which takes priority?
The clause containing "who" takes priority, that is, the second part of the sentence (..."whoever gave it to you.").
He gave it to you; thus "who" is correct. You wouldn't say "him gave it to you."
Who = the use of "he"; whom = the use of "him"
Where it gets tricky is in a sentence like this (when deciding to use "whoever/whomever"):
Give the position to the most-qualified candidate, whoever/whomever it may be.
Give the position to him. Give the position to he.
You would think "Give the position to him" is correct (in determining the correct choice), but, in this case, it is not.
Obviously, "Give the position to he" is also wrong.
What to do?
It may be he who is the most-qualified candidate, because he (not him) is the most-qualified candidate; thus "whoever" is correct in:
Give the position to the most-qualified candidate, whoever it may be.