[llvm] [SelectionDAG] Not issue TRAP node if naked function (PR #132147)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 2 03:23:27 PDT 2025


nikic wrote:

> > So if we change the return type of naked to i32,
> > ```
> > define dso_local i32 @naked() naked "frame-pointer"="all" {
> >   call void @main()
> >   unreachable
> > }
> > ```
> 
> Can we just say you're not allowed to do this? Anything other than an inline asm statement in a naked function has dubious semantics. Even on x86, the generated code for the given example is broken.

Yes, I don't think this is legal code and should really be rejected by the IR verifier. I know that both Rust and Clang essentially limit the contents of naked functions to inline asm. See: https://github.com/llvm/llvm-project/blob/2426ac647f33451a92833ab752d74d16ab3330ed/clang/lib/Sema/SemaDecl.cpp#L16530-L16554

https://github.com/llvm/llvm-project/pull/132147


More information about the llvm-commits mailing list