]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_codegen_llvm/src/intrinsic.rs
Rollup merge of #103439 - Nilstrieb:help-me-with-my-macro, r=estebank
[rust.git] / compiler / rustc_codegen_llvm / src / intrinsic.rs
index 825011941a24117a00f65638cc53e5efc2100d27..cf590a43826e53407aab00b691ad66fe0744a3cd 100644 (file)
@@ -340,17 +340,26 @@ fn codegen_intrinsic_call(
 
             sym::black_box => {
                 args[0].val.store(self, result);
-
+                let result_val_span = [result.llval];
                 // We need to "use" the argument in some way LLVM can't introspect, and on
                 // targets that support it we can typically leverage inline assembly to do
                 // this. LLVM's interpretation of inline assembly is that it's, well, a black
                 // box. This isn't the greatest implementation since it probably deoptimizes
                 // more than we want, but it's so far good enough.
+                //
+                // For zero-sized types, the location pointed to by the result may be
+                // uninitialized. Do not "use" the result in this case; instead just clobber
+                // the memory.
+                let (constraint, inputs): (&str, &[_]) = if result.layout.is_zst() {
+                    ("~{memory}", &[])
+                } else {
+                    ("r,~{memory}", &result_val_span)
+                };
                 crate::asm::inline_asm_call(
                     self,
                     "",
-                    "r,~{memory}",
-                    &[result.llval],
+                    constraint,
+                    inputs,
                     self.type_void(),
                     true,
                     false,