summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc/src/common.rs
diff options
context:
space:
mode:
authorErik Desjardins <erikdesjardins@users.noreply.github.com>2022-03-04 23:14:38 -0500
committerErik Desjardins <erikdesjardins@users.noreply.github.com>2022-03-06 12:28:46 -0500
commite1a4bf6492ea235b19fe1b390116b1973749466f (patch)
treef396b88cfccaac7fcb0c76bb4c77581391b1701c /compiler/rustc_codegen_gcc/src/common.rs
parent69f11fff33f68701d222639a1a5ae991605ec3ab (diff)
downloadrust-e1a4bf6492ea235b19fe1b390116b1973749466f.tar.gz
rust-e1a4bf6492ea235b19fe1b390116b1973749466f.zip
cleanup: remove unused ability to have LLVM null-terminate const strings
Diffstat (limited to 'compiler/rustc_codegen_gcc/src/common.rs')
-rw-r--r--compiler/rustc_codegen_gcc/src/common.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/compiler/rustc_codegen_gcc/src/common.rs b/compiler/rustc_codegen_gcc/src/common.rs
index 5851826147d..3c0dad13dea 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))