<div dir="ltr">Hi Eli and All ,<div><br></div><div>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 </div><div><br></div><div> static FunctionDecl* CreateNewFunctionDecl(Sema &SemaRef, Declarator &D,</div><div>                                           DeclContext *DC, QualType &R,</div><div>                                           TypeSourceInfo *TInfo,</div><div>                                           StorageClass SC,</div><div>                                           bool &IsVirtualOkay){</div><div><div> DeclarationNameInfo NameInfo = SemaRef.GetNameForDeclarator(D);</div><div> DeclarationName Name = NameInfo.getName();</div><div> std::string ExtPreRef;</div><div> </div><div>  SmallString<32> Str;</div><div>  StringRef EP = ("Test_" + Name.getAsString()).toStringRef(Str);</div><div>  const IdentifierInfo &test = SemaRef.PP.getIdentifierTable().get(EP);</div><div>  DeclarationName ExternName(&test);</div><div>   SemaRef.ExternPrefixMap[Name.getAsString()] = ExternName;</div><div>  NameInfo.setName(ExternName);</div><div><br></div><div><div> FunctionDecl *NewFD = nullptr;</div><div> bool isInline = D.getDeclSpec().isInlineSpecified();</div></div></div><div><br></div><div>}</div><div><br></div><div>testcase.c </div><div><br></div><div><div>int foo();</div><div>int bar();</div><div><br></div><div><br></div><div>int bar()</div><div>{</div><div> return 1;</div><div>}</div><div><br></div><div><br></div><div>int foo()</div><div>{</div><div>        return foo() + bar();</div><div>}</div><div><br></div><div>int (*ptr) ();</div><div><br></div><div>int main()</div><div>{</div><div>        ptr =  bar;</div><div>        return ptr();</div><div>}</div><div><br></div></div><div><br></div><div>we we try to compile the source testcase.c ,we ended up with the below warnings and error.</div><div><br></div><div><div>test.c:12:9: warning: implicit declaration of function 'foo' is invalid in C99 [-Wimplicit-function-declaration]</div><div>        return foo() + bar();</div><div>               ^</div><div>DefinefooFound:foo</div><div>test.c:12:17: warning: implicit declaration of function 'bar' is invalid in C99 [-Wimplicit-function-declaration]</div><div>        return foo() + bar();</div><div>                       ^</div><div>DefinebarFound:bar</div><div>DefinemainCome </div><div>maintest.c:19:6: error: assigning to 'int (*)()' from incompatible type '<overloaded function type>'</div><div>        ptr = Test_list_bar;</div><div>            ^ ~~~~~~~~~~~~~</div><div>test.c:12:17: note: candidate function</div><div>        return foo() + bar();</div></div><div><br></div><div><br></div><div>to overcome the above issue ,we modified the source @ lib/Sema/SemaExpr.cpp ,i.e </div><div><br></div><div><div>ExprResult</div><div>Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,</div><div>                        SourceLocation TemplateKWLoc, UnqualifiedId &Id,</div><div>                        bool HasTrailingLParen, bool IsAddressOfOperand,</div><div>                        std::unique_ptr<CorrectionCandidateCallback> CCC,</div><div>                        bool IsInlineAsmIdentifier, Token *KeywordReplacement) {</div><div>  assert(!(IsAddressOfOperand && HasTrailingLParen) &&</div><div>         "cannot be direct & operand and have a trailing lparen");</div><div>  if (SS.isInvalid())</div><div>    return ExprError();</div><div><br></div><div>  TemplateArgumentListInfo TemplateArgsBuffer;</div><div><br></div><div>  // Decompose the UnqualifiedId into the following data.</div><div>  DeclarationNameInfo NameInfo;</div><div>  const TemplateArgumentListInfo *TemplateArgs;</div><div>  DecomposeUnqualifiedId(Id, TemplateArgsBuffer, NameInfo, TemplateArgs);</div><div>  /* This Map will have functions that are renamed ,Key is Function Name and Value is the DeclarationName of renamed function.*/</div><div>   if(this->ExternPrefixMap.count( NameInfo.getName().getAsString()) == 1){</div><div>                auto ExternName = this->ExternPrefixMap.find(NameInfo.getName().getAsString());</div><div>                if(ExternName != this->ExternPrefixMap.end()){</div><div>                        NameInfo.setName(this->ExternPrefixMap[NameInfo.getName().getAsString()]);</div><div>                }</div><div>        }</div><div>  DeclarationName Name = NameInfo.getName();</div><div>  IdentifierInfo *II = Name.getAsIdentifierInfo();</div><div>  SourceLocation NameLoc = NameInfo.getLoc();</div></div><div>}</div><div><br></div><div><br></div><div>But ,we ended up with errors like ,</div><div><br></div><div><br></div><div><div>test.c:12:9: error: use of undeclared identifier 'Test_foo'; did you mean 'Test_foo'?</div><div>        return foo() + bar();</div><div>               ^~~</div><div>               Test_foo</div><div>test.c:10:5: note: 'Test_foo' declared here</div><div>int foo()</div><div>    ^</div><div>test.c:12:17: error: use of undeclared identifier 'Test_bar'; did you mean 'Test_bar'?</div><div>        return foo() + bar();</div><div>                       ^~~</div><div>                       Test_bar</div><div>test.c:5:5: note: 'Test_bar' declared here</div><div>int bar()</div><div>    ^</div><div> </div><div>maintest.c:19:6: error: assigning to 'int (*)()' from incompatible type '<overloaded function type>'</div><div>        ptr = bar;</div></div><div><br></div><div><br></div><div>debugging the same ,any inputs or suggestions or comments  here ,will be highly appreciated .</div><div><br></div><div>Thank you </div><div>~Umesh</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 21, 2016 at 11:34 PM, Friedman, Eli <span dir="ltr"><<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000"><span class="">
    <div class="m_3399977209515877663moz-cite-prefix">On 12/21/2016 5:01 AM, Umesh Kalappa
      via llvm-dev wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div>To context was ,</div>
        <div><br>
        </div>
        Basic requirement was to append extra string to the decl name
         and update all his references to the updated name. ,
        <div><br>
        </div>
        <div>So we are constructing  the DeclarationName  instance as
          stated below code snap.</div>
        <div>and from DeclarationName instance ,we are constructing  the
          DeclarationNameInfo and same info used to create decl spec
          with FunctionDecl::Create () .</div>
        <div><br>
        </div>
        <div>Question is ,</div>
        <div><br>
        </div>
        <div>How do ,someone instantiate   the DeclarationName instance
          using StringRef ,because in the current trunk code snap ,we
          see that the DeclarationName can be constructed using the
          IdentifierInfo or Objc Selector or CXXOperatorId  etc as
          argument in the constructor .</div>
        <div><br>
        </div>
        <div>The code i.e</div>
        <div> </div>
        <div>
          <div>void appendExtern(StringRef Sr)</div>
          <div>{</div>
          <div> char *ExternChar = const_cast<char *> (Sr.data());<br>
          </div>
          <div>
            <div> *Ptr =reinterpret_cast<void *>(ExternChar);</div>
            <div> </div>
            <div>  this->ExternName = DeclarationName::getFromOpaque<wbr>Ptr(Ptr);</div>
          </div>
          <div><br>
          </div>
          <div>}</div>
        </div>
        <div><br>
        </div>
        <div>the above is kind of hack ,may result in dangling memory
          references ,Any thoughts  on this  ?<br>
        </div>
        <div><br>
        </div>
        <div>we thought to change the DeclarationName class ,with adding
          new DeclarationName constructor ,that construct
          the DeclarationName instance by StringRef as argument.
          i.e DeclarationName(StringRef Sr) ;</div>
        <div><br>
        </div>
        <div>Before doing this ,we thought to check with community for
          better alternative / suggestions .</div>
        <br>
      </div>
    </blockquote>
    <br></span>
    Usually it's better to send questions about the clang frontend to
    just cfe-dev, rather than llvm-dev.<br>
    <p>You can use IdentifierTable::get to get an IdentifierInfo for an
      arbitrary string, then make a DeclarationName from that.</p><span class="HOEnZb"><font color="#888888">
    <p>-Eli<br>
    </p>
    <pre class="m_3399977209515877663moz-signature" cols="72">-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project</pre>
  </font></span></div>

</blockquote></div><br></div>