Skip to content

We shouldn't be able to tail-call #[track_caller] functions #145321

Closed as duplicate

Description

@compiler-errors

I tried this code:

struct Struct;

fn foo<T: ?Sized>(t: &T) -> usize {
    become bar(t);
}

#[track_caller]
fn bar<T: ?Sized>(_: &T) -> usize {
    456
}

fn main() {
    assert_eq!(foo(&Struct), 456);
}

I expected to see: Not sure actually.

Instead, LLVM's opt --passes=verify fails b/c we're performing a tail call with an incompatible signature.

Meta

rustc --version --verbose:

whatever is nightly on august 12, 2025

Not really an ICE per se, but a llvm bug. It doesn't show up on nightly b/c llvm is not built with debug assertions, I think, but it does show up when you pass the generated llvm to opt. I did this in alive2.

I think we need to rework how tail calls handle both pre-mono and post-mono #[track_caller] :3

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    C-bugCategory: This is a bug.
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Aug 12, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 12, 2025
  3. compiler-errors commented on Aug 12, 2025

    @compiler-errors
    ContributorAuthor

    cc #145270 (comment)

    I think the problem with #[track_caller] is deeper than this -- specifically, I think we actually need to disallow calling #[track_caller] functions altogether (which I think we can only check for during monomorphization), or at least we need to be adjusting such calls to a "reify shim" when monomorphizing those tail calls, though I think that ends up leading to us pushing a stack frame which seems not good.

  4. lqd commented on Aug 12, 2025

    @lqd
    Member

    waffle has #144865 where these are linted as not doing anything until we can check for them post/during mono.

  5. compiler-errors commented on Aug 12, 2025

    @compiler-errors
    ContributorAuthor

    gamer

  6. compiler-errors commented on Aug 12, 2025

    @compiler-errors
    ContributorAuthor

    Duplicate of #144755 then

  7. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-explicit_tail_calls`#![feature(explicit_tail_calls)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions