extra check in ReplaceUsesOfNonProtoTypeWithRealFunction() ?


I noticed this code in lib/CodeGen/CodeGenModule.cpp

  for (llvm::Value::use_iterator UI = OldFn->use_begin(), E = OldFn->use_end();
       UI != E; ) {
    // TODO: Do invokes ever occur in C code? If so, we should handle them too.
    llvm::CallInst *CI = dyn_cast<llvm::CallInst>(*UI++);
    if (!CI) continue;

For safety, I think it should also check:

    if (UI.getOperandNo() != 0) continue;

(so that a use of OldFn as an argument in a call isn't mistaken for a
call to OldFn). However, I can't test this change, because I can't
construct any test case that causes
ReplaceUsesOfNonProtoTypeWithRealFunction() to be called. I've been
trying things like:

int f(); /* declaration with no prototype */
int g() { return f(3); }
int f(int i) { return 3; } /* definition */

When is this function supposed to be called?


You're right, I added this in r72869. I think this is possible to trigger, but I didn't try to make a testcase. Thanks Jay,