Rollup merge of #69379 - jumbatm:llvm-sigsegv, r=pnkfelix
Fail on multiple declarations of `main`. Closes #67946. Previously, when inserting the entry function, we only checked for duplicate _definitions_ of `main`. However, it's possible to cause problems even only having a duplicate _declaration_. For example, shadowing `main` using an extern block isn't caught by the current check, and causes an assertion failure down the line in in LLVM code. r? @pnkfelix
This commit is contained in:
commit
350491da19
@ -437,10 +437,10 @@ fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
// listing.
|
||||
let main_ret_ty = cx.tcx().erase_regions(&main_ret_ty.no_bound_vars().unwrap());
|
||||
|
||||
if cx.get_defined_value("main").is_some() {
|
||||
if cx.get_declared_value("main").is_some() {
|
||||
// FIXME: We should be smart and show a better diagnostic here.
|
||||
cx.sess()
|
||||
.struct_span_err(sp, "entry symbol `main` defined multiple times")
|
||||
.struct_span_err(sp, "entry symbol `main` declared multiple times")
|
||||
.help("did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead")
|
||||
.emit();
|
||||
cx.sess().abort_if_errors();
|
||||
|
@ -1,7 +1,7 @@
|
||||
// build-fail
|
||||
|
||||
//
|
||||
// error-pattern: entry symbol `main` defined multiple times
|
||||
// error-pattern: entry symbol `main` declared multiple times
|
||||
|
||||
// FIXME https://github.com/rust-lang/rust/issues/59774
|
||||
// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> ""
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: entry symbol `main` defined multiple times
|
||||
error: entry symbol `main` declared multiple times
|
||||
--> $DIR/dupe-symbols-7.rs:12:1
|
||||
|
|
||||
LL | fn main(){}
|
||||
|
12
src/test/ui/duplicate/dupe-symbols-8.rs
Normal file
12
src/test/ui/duplicate/dupe-symbols-8.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// build-fail
|
||||
// error-pattern: entry symbol `main` declared multiple times
|
||||
//
|
||||
// See #67946.
|
||||
|
||||
#![allow(warnings)]
|
||||
fn main() {
|
||||
extern "Rust" {
|
||||
fn main();
|
||||
}
|
||||
unsafe { main(); }
|
||||
}
|
15
src/test/ui/duplicate/dupe-symbols-8.stderr
Normal file
15
src/test/ui/duplicate/dupe-symbols-8.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error: entry symbol `main` declared multiple times
|
||||
--> $DIR/dupe-symbols-8.rs:7:1
|
||||
|
|
||||
LL | / fn main() {
|
||||
LL | | extern "Rust" {
|
||||
LL | | fn main();
|
||||
LL | | }
|
||||
LL | | unsafe { main(); }
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user