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:
Dylan DPC 2020-02-28 01:55:35 +01:00 committed by GitHub
commit 350491da19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 4 deletions

View File

@ -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();

View File

@ -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" -> ""

View File

@ -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(){}

View 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(); }
}

View 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