Hi Eli and All ,
We added the support to rename the function name ,i.e something like “func” to “test_func” for any function we append the string “test_”,hence modified the code @ @ lib/Sema/SemaDecl.cpp like
static FunctionDecl* CreateNewFunctionDecl(Sema &SemaRef, Declarator &D,
DeclContext *DC, QualType &R,
TypeSourceInfo *TInfo,
StorageClass SC,
bool &IsVirtualOkay){
DeclarationNameInfo NameInfo = SemaRef.GetNameForDeclarator(D);
DeclarationName Name = NameInfo.getName();
std::string ExtPreRef;
SmallString<32> Str;
StringRef EP = (“Test_” + Name.getAsString()).toStringRef(Str);
const IdentifierInfo &test = SemaRef.PP.getIdentifierTable().get(EP);
DeclarationName ExternName(&test);
SemaRef.ExternPrefixMap[Name.getAsString()] = ExternName;
NameInfo.setName(ExternName);
FunctionDecl *NewFD = nullptr;
bool isInline = D.getDeclSpec().isInlineSpecified();
}
testcase.c
int foo();
int bar();
int bar()
{
return 1;
}
int foo()
{
return foo() + bar();
}
int (*ptr) ();
int main()
{
ptr = bar;
return ptr();
}
we we try to compile the source testcase.c ,we ended up with the below warnings and error.
test.c:12:9: warning: implicit declaration of function ‘foo’ is invalid in C99 [-Wimplicit-function-declaration]
return foo() + bar();
^
DefinefooFound:foo
test.c:12:17: warning: implicit declaration of function ‘bar’ is invalid in C99 [-Wimplicit-function-declaration]
return foo() + bar();
^
DefinebarFound:bar
DefinemainCome
maintest.c:19:6: error: assigning to ‘int (*)()’ from incompatible type ‘’
ptr = Test_list_bar;
^ ~~~~~~~~~~~~~
test.c:12:17: note: candidate function
return foo() + bar();
to overcome the above issue ,we modified the source @ lib/Sema/SemaExpr.cpp ,i.e
ExprResult
Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
SourceLocation TemplateKWLoc, UnqualifiedId &Id,
bool HasTrailingLParen, bool IsAddressOfOperand,
std::unique_ptr CCC,
bool IsInlineAsmIdentifier, Token *KeywordReplacement) {
assert(!(IsAddressOfOperand && HasTrailingLParen) &&
“cannot be direct & operand and have a trailing lparen”);
if (SS.isInvalid())
return ExprError();
TemplateArgumentListInfo TemplateArgsBuffer;
// Decompose the UnqualifiedId into the following data.
DeclarationNameInfo NameInfo;
const TemplateArgumentListInfo TemplateArgs;
DecomposeUnqualifiedId(Id, TemplateArgsBuffer, NameInfo, TemplateArgs);
/ This Map will have functions that are renamed ,Key is Function Name and Value is the DeclarationName of renamed function.*/
if(this->ExternPrefixMap.count( NameInfo.getName().getAsString()) == 1){
auto ExternName = this->ExternPrefixMap.find(NameInfo.getName().getAsString());
if(ExternName != this->ExternPrefixMap.end()){
NameInfo.setName(this->ExternPrefixMap[NameInfo.getName().getAsString()]);
}
}
DeclarationName Name = NameInfo.getName();
IdentifierInfo *II = Name.getAsIdentifierInfo();
SourceLocation NameLoc = NameInfo.getLoc();
}
But ,we ended up with errors like ,
test.c:12:9: error: use of undeclared identifier ‘Test_foo’; did you mean ‘Test_foo’?
return foo() + bar();
^~~
Test_foo
test.c:10:5: note: ‘Test_foo’ declared here
int foo()
^
test.c:12:17: error: use of undeclared identifier ‘Test_bar’; did you mean ‘Test_bar’?
return foo() + bar();
^~~
Test_bar
test.c:5:5: note: ‘Test_bar’ declared here
int bar()
^
maintest.c:19:6: error: assigning to ‘int (*)()’ from incompatible type ‘’
ptr = bar;
debugging the same ,any inputs or suggestions or comments here ,will be highly appreciated .
Thank you
~Umesh