there is currently no roll/pitch compensation for altitude computed from sonar.
However if you really want/need this strongly depends on the opening angle of your sonar and the max roll/pitch angles you expect while using it.
Most sonars have a rather large opening angle and return the distance to the nearest object, so it is ok up to quite a bit of roll/pitch.
Compare that to e.g. a downwards pointing laser where you really have only one point and definitely want to compensate for roll/pitch.
Depending on your sonar (opening angle), it will actually be worse to compensate for attitude and assume you get only one point at the ground.
So doing it properly needs to take the characteristics of your sonar into account...