Custom Pragma before a function

Hi all,

I am trying to add a custom pragma before a function which can later move on to the IR as an attribute

The idea is something like this:

#pragma customPragma start foo1 27
int foo1(int a,int b){
//more code
}

I am currently following CES / clang-custom-pragma · GitLab and have successfully been able to add my custom pragma. However,having said current I can only support cases like the following

int foo1(int a,int b){
#pragma customPragma start foo1 27
//more code
}

However, if I declare the pragma immediately outside the function I get an error.

I reckon it is mainly because I have my pragma support in Parser::ParseStatementOrDeclarationAfterAttributes(…)

Is there a function/file that would allow support before function declarations/definitions?

Any help would be greatly appreciated.

Thanks and Regards
Anilava

You should check out Parser::ParseExternalDeclaration as it handles quite a few pragmas like that: llvm-project/Parser.cpp at main · llvm/llvm-project · GitHub

Thank you for this! I will look into it :smile:

1 Like