[LLVMdev] Does a recursive call have side effects?

Andrew Trick atrick at apple.com
Fri Mar 8 17:35:06 PST 2013


Currently LLVM removes infinite recursion in readnone functions as dead code. I assume this falls under the same language rules that allow removal of infinite loops. But I need to be certain. Can someone confirm? Standard citations welcome.

Otherwise this is wrong:

  bool mayHaveSideEffects() const {
    return mayWriteToMemory() || mayThrow() || !mayReturn();
  }

Note: For non-C support, it would be nice to have another attribute, maynotreturn (in C everything is mustreturn by default). In theory, if we had that, the C frontend could use it for potentially recursive calls, forcing the optimizer to either prove it's not recursive or consider it to have side effects. But if the function had nontrivial loops, the optimizer won't be able to remove the attribute. In practice, I think we just want to hide behind the standard with the old undefined behavior excuse and tell people who want infinite recursion to dereference a volatile.

-Andy



More information about the llvm-dev mailing list