Skip to content

Commit 79bf498

Browse files
committed
Automatically add name-anon-globals
If no-prepopulat-passes and ThinLTO buffers are used, automatically add name-anon-globals, instead of forcing the user to specify it explicitly.
1 parent 7785834 commit 79bf498

File tree

5 files changed

+6
-29
lines changed

5 files changed

+6
-29
lines changed

src/librustc_codegen_llvm/back/write.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,6 @@ pub(crate) unsafe fn optimize(
346346
}
347347

348348
let mut extra_passes = Vec::new();
349-
let mut have_name_anon_globals_pass = false;
350-
351349
for pass_name in &config.passes {
352350
if pass_name == "lint" {
353351
// Linting should also be performed early, directly on the generated IR.
@@ -360,10 +358,6 @@ pub(crate) unsafe fn optimize(
360358
} else {
361359
diag_handler.warn(&format!("unknown pass `{}`, ignoring", pass_name));
362360
}
363-
364-
if pass_name == "name-anon-globals" {
365-
have_name_anon_globals_pass = true;
366-
}
367361
}
368362

369363
add_sanitizer_passes(config, &mut extra_passes);
@@ -389,33 +383,17 @@ pub(crate) unsafe fn optimize(
389383
llvm::LLVMPassManagerBuilderPopulateModulePassManager(b, mpm);
390384
});
391385

392-
have_name_anon_globals_pass = have_name_anon_globals_pass || prepare_for_thin_lto;
393386
if using_thin_buffers && !prepare_for_thin_lto {
394387
llvm::LLVMRustAddPass(mpm, find_pass("name-anon-globals").unwrap());
395-
have_name_anon_globals_pass = true;
396388
}
397389
} else {
398390
// If we don't use the standard pipeline, directly populate the MPM
399391
// with the extra passes.
400392
for pass in extra_passes {
401393
llvm::LLVMRustAddPass(mpm, pass);
402394
}
403-
}
404-
405-
if using_thin_buffers && !have_name_anon_globals_pass {
406-
// As described above, this will probably cause an error in LLVM
407-
if config.no_prepopulate_passes {
408-
diag_handler.err(
409-
"The current compilation is going to use thin LTO buffers \
410-
without running LLVM's NameAnonGlobals pass. \
411-
This will likely cause errors in LLVM. Consider adding \
412-
-C passes=name-anon-globals to the compiler command line.",
413-
);
414-
} else {
415-
bug!(
416-
"We are using thin LTO buffers without running the NameAnonGlobals pass. \
417-
This will likely cause errors in LLVM and should never happen."
418-
);
395+
if using_thin_buffers {
396+
llvm::LLVMRustAddPass(mpm, find_pass("name-anon-globals").unwrap());
419397
}
420398
}
421399
}

src/test/codegen/target-cpu-on-functions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// "target-cpu" attribute in LLVM.
33

44
// no-prefer-dynamic
5-
// ignore-tidy-linelength
6-
// compile-flags: -C no-prepopulate-passes -C panic=abort -C linker-plugin-lto -Cpasses=name-anon-globals
5+
// compile-flags: -C no-prepopulate-passes -C panic=abort -C linker-plugin-lto
76

87
#![crate_type = "staticlib"]
98

src/test/ui/feature-gates/feature-gate-unwind-attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-wasm32-bare compiled with panic=abort by default
2-
// compile-flags: -C no-prepopulate-passes -Cpasses=name-anon-globals
2+
// compile-flags: -C no-prepopulate-passes
33

44
#![crate_type = "lib"]
55

src/test/ui/issues/issue-18804/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// aux-build:lib.rs
1111

1212
// rust-lang/rust#56772: nikic says we need this to be proper test.
13-
// compile-flags: -C no-prepopulate-passes -C passes=name-anon-globals
13+
// compile-flags: -C no-prepopulate-passes
1414

1515
extern crate lib;
1616

src/test/ui/issues/issue-38226.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
// Need -Cno-prepopulate-passes to really disable inlining, otherwise the faulty
88
// code gets optimized out:
9-
// compile-flags: -Cno-prepopulate-passes -Cpasses=name-anon-globals
9+
// compile-flags: -Cno-prepopulate-passes
1010

1111
extern crate issue_38226_aux;
1212

0 commit comments

Comments
 (0)