Repository navigation
Disallow duplicated extern declarations #12707
Description
Activity
This would disallow duplicate functions with different signatures, but still allow duplicate with the same?
I thought identical duplicates are ok because
make check-fastneeds them. Some rpass tests use same extern fn then they are combined into one crate.- added a commit that references this issue
on Mar 9, 2014 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
byvalattribute.cc #12762:
it contains a patch to suppress llvm assertion error above.Not really.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 toobjc_msgSend.)Traige: Still getting the same failure as @rprichard , but I'm also on x86-64. Does this fail everywhere now?
On x86-64 as well, does not reproduce with
--crate-type libandrustc 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.- addedC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.
on Jul 20, 2017 Triage: no change
- addedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
on Jan 12, 2020 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?
objc_msgSendis 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.- added a commit that references this issue
on Jan 22, 2024 objc_msgSendis 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).
Currently rustc accepts this, but I think it should be disallowed to reduce potential mistakes.