Accessing FunctionDecl from clang::Expr

Hello All,

I am trying to find the clang::FunctionDecl relevant to a return expression (clang::Expr). For example consider following function;

  1. int foo(int a, int b) {
  2. int k;
  3. int d = 5 * k;
  4. return d;
  5. }

I have an expression (clang::Expr type) relevant to line 6 (return statement). From that I want to access the function declaration (clang::FunctionDecl) where return statement resides (i.e. foo).

Further I need to access declarations relevant to lines 3 and 4. I believe I can access name declarations relevant to lines 3 and 4 once I have access to FunctionDecl.

Could you please advise how to access clang::FunctionDecl from clang::Expr ?

Thank you in advance.