diff options
| author | bors <bors@rust-lang.org> | 2022-03-07 02:07:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-03-07 02:07:36 +0000 |
| commit | 3d1eaf4b6203ab0168da5b99049942385aa753e0 (patch) | |
| tree | 01949fcb8930cd6b7da3b2099253d68427872e36 /compiler/rustc_codegen_gcc | |
| parent | 8876ca3dd46b99fe7e6ad937f11493d37996231e (diff) | |
| parent | e1a4bf6492ea235b19fe1b390116b1973749466f (diff) | |
| download | rust-3d1eaf4b6203ab0168da5b99049942385aa753e0.tar.gz rust-3d1eaf4b6203ab0168da5b99049942385aa753e0.zip | |
Auto merge of #94638 - erikdesjardins:noextranull, r=nagisa
cleanup: remove unused ability to have LLVM null-terminate const strings (and the copied function in rustc_codegen_gcc) Noticed this while writing https://github.com/rust-lang/rust/pull/94450#issuecomment-1059687348. r? `@nagisa`
Diffstat (limited to 'compiler/rustc_codegen_gcc')
| -rw-r--r-- | compiler/rustc_codegen_gcc/src/common.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_codegen_gcc/src/context.rs | 4 |
2 files changed, 8 insertions, 16 deletions
diff --git a/compiler/rustc_codegen_gcc/src/common.rs b/compiler/rustc_codegen_gcc/src/common.rs index a80b8e5b76c..d1ff15367c3 100644 --- a/compiler/rustc_codegen_gcc/src/common.rs +++ b/compiler/rustc_codegen_gcc/src/common.rs @@ -26,18 +26,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { bytes_in_context(self, bytes) } - fn const_cstr(&self, symbol: Symbol, _null_terminated: bool) -> LValue<'gcc> { - // TODO(antoyo): handle null_terminated. - if let Some(&value) = self.const_cstr_cache.borrow().get(&symbol) { - return value; - } - - let global = self.global_string(symbol.as_str()); - - self.const_cstr_cache.borrow_mut().insert(symbol, global); - global - } - fn global_string(&self, string: &str) -> LValue<'gcc> { // TODO(antoyo): handle non-null-terminated strings. let string = self.context.new_string_literal(&*string); @@ -171,8 +159,12 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { } fn const_str(&self, s: Symbol) -> (RValue<'gcc>, RValue<'gcc>) { - let len = s.as_str().len(); - let cs = self.const_ptrcast(self.const_cstr(s, false).get_address(None), + let s_str = s.as_str(); + let str_global = *self.const_str_cache.borrow_mut().entry(s).or_insert_with(|| { + self.global_string(s_str) + }); + let len = s_str.len(); + let cs = self.const_ptrcast(str_global.get_address(None), self.type_ptr_to(self.layout_of(self.tcx.types.str_).gcc_type(self, true)), ); (cs, self.const_usize(len as u64)) diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index dfcd1b62312..6c1dce969f0 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -85,7 +85,7 @@ pub struct CodegenCx<'gcc, 'tcx> { pub const_globals: RefCell<FxHashMap<RValue<'gcc>, RValue<'gcc>>>, /// Cache of constant strings, - pub const_cstr_cache: RefCell<FxHashMap<Symbol, LValue<'gcc>>>, + pub const_str_cache: RefCell<FxHashMap<Symbol, LValue<'gcc>>>, /// Cache of globals. pub globals: RefCell<FxHashMap<String, RValue<'gcc>>>, @@ -195,7 +195,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { function_instances: Default::default(), vtables: Default::default(), const_globals: Default::default(), - const_cstr_cache: Default::default(), + const_str_cache: Default::default(), globals: Default::default(), scalar_types: Default::default(), types: Default::default(), |
