This patch adds an option to the Normal Map and Bump nodes that will automatically reduce the strength of the effect if using the full strength would result in invalid reflections and therefore black spots for the given incoming direction.
The result is not perfect of course, but definitely better than black spots.
This patch is WIP, for example, the OSL implementation is missing - but it should be good enough for some initial testing.
The initial idea came from this comment by @Miki (MeshLogic), but the actual approach is different afaics.
A quick example:
Old:
New:

