LLVM : How to use “getAddrLabelSymbol” properly?

Hi, everyone. Now I’m trying to figure out how to use the “GetAddrLabelSymbol” method under LLVM 8.0, I want to use GetAddrLabelSymbol to get the symbol of the basic block, however,The assertion failed when I write pass as follows and run it.

virtual  bool runOnMachineFunction(MachineFunction &MF){
MachineModuleInfo &MMI = MF.getMMI();
const function &F = MF.getFunction();
for(const auto &BB:F)
{
    MCSymbol *Sym = MMI.llvm::MachineModuleInfo::getAddressLabelSymbol(&BB);
 }

I follow the definition to see the hasAddressaken function, but I don’t understand the meaning of other than direct branch and swit here.After adding this function, all base blocks execute continue directly.

virtual  bool runOnMachineFunction(MachineFunction &MF){
MachineModuleInfo &MMI = MF.getMMI();
const function &F = MF.getFunction();
for(const auto &BB:F)
{
    if(!BB->hasAddressTaken())
    { continue;}
    MCSymbol *Sym = MMI.llvm::MachineModuleInfo::getAddressLabelSymbol(&BB);
 }

What am I supposed to do?

I think that basic blocks do not have associated symbols unless the linker needs them, and the linker will only need them if the address of the basic block is used by your program (as the error message says). If you look at the language reference, there is a section “Addresses of Basic Blocks” explaining how your program can use the address and for what. (The short version is only for computed goto and inline assembly, by my reading.) Do you want symbols for something else?

Yes, I need the symbols associated with the base block to get the address of the corresponding base block in the output binary. This does not seem to be the same address at compile time.
I looked at the definition of hasAddressaken and said, "Returns true if there are any uses of this basic block other than direct branches, switches, etc. " I can’t fully understand the “other than direct branches, switches” , whether I can do this: By inserting a CALL command into each base block, the effect of that base block will include indirect branching, and hasAddressStaken will return true to implement GetAddressLabelSymbol. I am a LLVM freshman, the questions what I asked maybe basic and illogical. Thank you very much for your patient reply.