As a warlock with the Fiend pact you gain Dark One's Blessing:
Starting at 1st level, when you reduce a hostile creature to 0 hit points, you gain temporary hit points equal to your Charisma modifier + your warlock level (minimum o f 1).
Say you have an item or a spell like Armor of Agathys that damages enemies when they attack you (so auto damage with no save for them and no attack roll for you).
Lets assume you have 1 Temp Hit Point, and get damaged for 5. If that auto damage kills the enemy, and you gain THP from Dark One's Blessing, would you take 4 damage from your real HP or four off the top of the new THP gain?