[cfe-dev] [llvm-dev] DeclarationName and the StringRef.
Friedman, Eli via cfe-dev
cfe-dev at lists.llvm.org
Wed Jan 4 10:55:50 PST 2017
On 1/4/2017 3:07 AM, Umesh Kalappa wrote:
> 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 '<overloaded function type>'
> ptr = Test_list_bar;
> ^ ~~~~~~~~~~~~~
> test.c:12:17: note: candidate function
> return foo() + bar();
Hang on, lets take a step back at this point. Why are you doing this?
If you don't want the function to have a different name, don't rename it.
If you need to change the name of a function in the generated
IR/assembly without changing the semantic name, you can use the __asm__
attribute (as in `int f() __asm__("test_f");`).
-Eli
--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
More information about the cfe-dev
mailing list