minimum function ir

Can I create a "naked" function that has only inline assembler and no return IR for example?

If I create just a function will an empty basic block, it's core dumps.

I'm debugging it now.

Seems that you have to have at least a return instruction.

Is that a bug?

Why can't I do the return myself if it's all inline assembly code.

It's not hard for me to suppress the return in "naked" functions.

Hello Reed,

Basic blocks need to end with a terminator instruction.
There is an “unreachable” terminator instruction, whose documentation says:
“the presence of this instruction indicates some higher level knowledge that the end of the block cannot be reached.”

(see include/llvm/IR/Instructions.h).

I’ve been able to suppress the return using this. I’m not completely clear if this would be the right use for your scenario.


This is the right thing to do. If your inline assembly always transfers
code out of the block, then the end of the block is indeed unreachable. You
do need to ensure that the asm expression has the "sideeffect" attribute so
that it doesn't get optimized away.


Cool. That worked for me.

So I think that clang should replace "return instruction" with "unreachable instruction" if the "naked" attribute is present.

The only issue here is that targets need to declare whether they support "naked".