Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3962202
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:04:04+00:00 2026-05-20T03:04:04+00:00

Now that LLVM’s AnnotationManager is gone (it disappeared in the 2.6 release, I think?),

  • 0

Now that LLVM’s AnnotationManager is gone (it disappeared in the 2.6 release, I think?), how can I get the annotations for specific functions, globals, and instructions?

(For example, I have bitcode compiled from C void myFunction(__attribute__((annotate("foo"))) int var) — given an Argument * reference to this int var argument, how might I determine which annotate attributes are attached to it?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:04:05+00:00Added an answer on May 20, 2026 at 3:04 am

    To get annotations for a specific function, traverse the entry BasicBlock of the function to find its calls to the @llvm.var.annotation intrinsic, as follows:

    Module *module;
    
    [...]
    
    std::string getGlobalVariableString(std::string name)
    {
        // assumption: the zeroth operand of a Value::GlobalVariableVal is the actual Value
        Value *v = module->getNamedValue(name)->getOperand(0);
        if(v->getValueID() == Value::ConstantArrayVal)
        {
            ConstantArray *ca = (ConstantArray *)v;
            return ca->getAsString();
        }
    
        return "";
    }
    
    void dumpFunctionArgAnnotations(std::string funcName)
    {
        std::map<Value *,Argument*> mapValueToArgument;
    
        Function *func = module->getFunction(funcName);
        if(!func)
        {
            std::cout << "no function by that name.\n";
            return;
        }
    
        std::cout << funcName << "() ====================\n";
    
    
        // assumption: @llvm.var.annotation calls are always in the function's entry block.
        BasicBlock *b = &func->getEntryBlock();
    
    
        // run through entry block first to build map of pointers to arguments
        for(BasicBlock::iterator it = b->begin();it!=b->end();++it)
        {
            Instruction *inst = it;
            if(inst->getOpcode()!=Instruction::Store)
                continue;
    
            // `store` operands: http://llvm.org/docs/LangRef.html#i_store
            mapValueToArgument[inst->getOperand(1)] = (Argument *)inst->getOperand(0);
        }
    
    
        // run through entry block a second time, to associate annotations with arguments
        for(BasicBlock::iterator it = b->begin();it!=b->end();++it)
        {
            Instruction *inst = it;
            if(inst->getOpcode()!=Instruction::Call)
                continue;
    
            // assumption: Instruction::Call's operands are the function arguments, followed by the function name
            Value *calledFunction = inst->getOperand(inst->getNumOperands()-1);
            if(calledFunction->getName().str() != "llvm.var.annotation")
                continue;
    
            // `llvm.var.annotation` operands: http://llvm.org/docs/LangRef.html#int_var_annotation
    
            Value *annotatedValue = inst->getOperand(0);
            if(annotatedValue->getValueID() != Value::InstructionVal + Instruction::BitCast)
                continue;
            Argument *a = mapValueToArgument[annotatedValue->getUnderlyingObject()];
            if(!a)
                continue;
    
            Value *annotation = inst->getOperand(1);
            if(annotation->getValueID() != Value::ConstantExprVal)
                continue;
            ConstantExpr *ce = (ConstantExpr *)annotation;
            if(ce->getOpcode() != Instruction::GetElementPtr)
                continue;
    
            // `ConstantExpr` operands: http://llvm.org/docs/LangRef.html#constantexprs
            Value *gv = ce->getOperand(0);
    
            if(gv->getValueID() != Value::GlobalVariableVal)
                continue;
    
            std::cout << "    argument " << a->getType()->getDescription() << " " << a->getName().str()
                << " has annotation \"" << getGlobalVariableString(gv->getName().str()) << "\"\n";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now that the canvas tag is starting to get hardware execration [acceleration - thanks
Now that I know I can no longer communicate with Twitter mashups out there,
Now that I know C++ I want to get into desktop application that have
Now that Google App Engine natively supports Django 1.0, I updated with the following
Now that http://github.com/why/hpricot/wikis/home no longer exists.
Now that I am using it for backend processing of csv files, and the
Now that I have decided upon Firebird , with the help of StackOverflow :),
Now that ASP.NET MVC 2 is out , I tried to install it on
Now that Google Earth has been released for Android 2.1, does anyone know what,
Now that I have a read-only application working, I am working on the insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.