<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial">I'm learning the clang source code,try to understand how llvm translate .cpp to .ll<br>when I read the CodeGenModule.cpp<br><br>02271   if (GV->getType()->getElementType() != Ty) {<br>02272     // If the types mismatch then we have to rewrite the definition.<br>02273     assert(GV->isDeclaration() && "Shouldn't replace non-declaration");<br>02274 <br>02275     // F is the Function* for the one with the wrong type, we must make a new<br>02276     // Function* and update everything that used F (a declaration) with the new<br>02277     // Function* (which will be a definition).<br>02278     //<br>02279     // This happens if there is a prototype for a function<br>02280     // (e.g. "int f()") and then a definition of a different type<br>02281     // (e.g. "int f(int x)").  Move the old function aside so that it<br>02282     // doesn't interfere with GetAddrOfFunction.<br>02283     GV->setName(StringRef());<br>02284     auto *NewFn = cast<llvm::Function>(GetAddrOfFunction(GD, Ty));<br>02285 <br>02286     // This might be an implementation of a function without a<br>02287     // prototype, in which case, try to do special replacement of<br>02288     // calls which match the new prototype.  The really key thing here<br>02289     // is that we also potentially drop arguments from the call site<br>02290     // so as to make a direct call, which makes the inliner happier<br>02291     // and suppresses a number of optimizer warnings (!) about<br>02292     // dropping arguments.<br>02293     if (!GV->use_empty()) {<br>02294       ReplaceUsesOfNonProtoTypeWithRealFunction(GV, NewFn);<br>02295       GV->removeDeadConstantUsers();<br>02296     }<br>02297 <br>02298     // Replace uses of F with the Function we will endow with a body.<br>02299     if (!GV->use_empty()) {<br>02300       llvm::Constant *NewPtrForOldDecl =<br>02301           llvm::ConstantExpr::getBitCast(NewFn, GV->getType());<br>02302       GV->replaceAllUsesWith(NewPtrForOldDecl);<br>02303     }<br>02304 <br>02305     // Ok, delete the old function now, which is dead.<br>02306     GV->eraseFromParent();<br>02307 <br>02308     GV = NewFn;<br>02309   }<br><br><br>I have a test <br><br><br>//aa.c<br><br><br>#include <stdio.h><br><br>void fun(int a,int b);<br><br>void fun()<br>{<br>        printf("no parameters\n");<br>}<br>int main()<br>{<br>        fun();<br>        return 0;<br>}<br><br><br>compiler using clang <br><br><br>aa.c:11:6: error: too few arguments to function call, expected 2, have 0<br>        fun();<br>        ~~~ ^<br>aa.c:5:1: note: 'fun' declared here<br>void fun()<br>^<br>1 error generated.<br><br>This Is it right?</div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>