Semantic Information while parsing AST

I want to use the information in Sema::UndefinedButUsed while parsing the AST using ASTConsumer.
How do I get the Semantic information? I tried to initialize the SemanticConsumer but to no avail.

Hello all,
Does clang keep track of the undeclared identifiers in the Sema phase or does it emit diagnostics and continue?
I am trying to implement dynamic scoping using shallow access method and libtooling in clang. For that I need track and rename undeclared identifiers.
For now I have created my own data structure in Sema class and to load undeclared identifiers in it but ideally I would like this to be more of a stand alone tool.
Is there a better way to accomplish this?