Skip to content

Disallow duplicated extern declarations #12707

Description

@klutzy
mod a {
    extern {
        fn func();
    }
}

mod b {
    extern {
        fn func(i: i8); // different signature
    }
}

Currently rustc accepts this, but I think it should be disallowed to reduce potential mistakes.

Activity

  1. brson commented on Mar 5, 2014

    @brson
    Contributor

    This would disallow duplicate functions with different signatures, but still allow duplicate with the same?

  2. klutzy commented on Mar 5, 2014

    @klutzy
    ContributorAuthor

    I thought identical duplicates are ok because make check-fast needs them. Some rpass tests use same extern fn then they are combined into one crate.

  3. klutzy commented on Mar 10, 2014

    @klutzy
    ContributorAuthor

    Modified test case causing llvm assertion error on x64:

    mod a {
        extern {
            fn func(); // declare void @func() unnamed_addr
        }
    }
    
    mod b {
        struct S {
            a: u64,
            b: u64,
            c: u64,
        }
    
        extern {
            fn func(s: S); // declare void @func(%"struct.b::S"* byval) unnamed_addr
        }
    }
    rustc: /media/a/lime/src/rust/src/llvm/include/llvm/Support/Casting.h:240:typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::Argument; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type = llvm::Argument*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
    

    In the case, argument has byval attribute.

  4. klutzy commented on Mar 10, 2014

    @klutzy
    ContributorAuthor

    cc #12762: it contains a patch to suppress llvm assertion error above. Not really.

  5. rprichard commented on Oct 17, 2014

    @rprichard
    Contributor

    klutzy's test case is causing a different error now on 64-bit Linux:

    Attribute after last parameter!
    void ()* @func
    LLVM ERROR: Broken module found, compilation aborted!
    

    Are duplicate declarations useful/necessary for calling functions like objc_msgSend? IIRC, that function isn't really varargs -- the prototype varies depending upon which ObjC method is invoked. (I discovered this GitHub issue because I did something similar to objc_msgSend.)

  6. steveklabnik commented on Dec 31, 2015

    @steveklabnik
    Contributor

    Traige: Still getting the same failure as @rprichard , but I'm also on x86-64. Does this fail everywhere now?

  7. Mark-Simulacrum commented on Apr 15, 2017

    @Mark-Simulacrum
    Member

    On x86-64 as well, does not reproduce with --crate-type lib and rustc 1.18.0-nightly (bbdaad0dc 2017-04-14). Going to presume the assertions are fixed, but the original issue (multiple externs with the same name) isn't, so leaving open.

  8. steveklabnik commented on Sep 24, 2018

    @steveklabnik
    Contributor

    Triage: no change

  9. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jan 12, 2020
  10. BurgundyWillow commented on Dec 9, 2020

    @BurgundyWillow

    The rustc compiler does throw warnings when we use two conflicting function signatures in extern declarations. So, shall we change this to disallow it and instead throw an error?

  11. bjorn3 commented on May 31, 2023

    @bjorn3
    Member

    objc_msgSend is declared with multiple signatures in libstd. The signature of this function depends on the message sent. It forwards all arguments to the called method. Declaring it as a vararg function is not valid in AArch64 due to ABI differences.

  12. added 2 commits that reference this issue on Jan 22, 2024
  13. added a commit that references this issue on Jan 22, 2024
  14. madsmtm commented on Jan 22, 2024

    @madsmtm
    Member

    objc_msgSend is declared with multiple signatures in libstd. The signature of this function depends on the message sent. It forwards all arguments to the called method. Declaring it as a vararg function is not valid in AArch64 due to ABI differences.

    Since #117910, this is no longer true, instead we explicitly cast the function pointer (which is arguably the more correct behaviour, at least it's what the C headers also declare and expect you to do).

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

    A-FFIArea: Foreign function interface (FFI)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions