about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2024-06-21 14:01:15 -0500
committerTrevor Gross <tmgross@umich.edu>2024-07-02 21:41:59 -0400
commit64a3bd84d83a6138b6e7db82a53199246f292e53 (patch)
treedfcd3fb1a474a3edc7acbb6759e3aa17f1d0d604
parent6292b2af620dbd771ebb687c3a93c69ba8f97268 (diff)
downloadrust-64a3bd84d83a6138b6e7db82a53199246f292e53.tar.gz
rust-64a3bd84d83a6138b6e7db82a53199246f292e53.zip
Always preserve user-written comments in assembly
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp3
-rw-r--r--tests/assembly/asm-comments.rs12
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
index c4cfc0b6dc6..a868c56c4e6 100644
--- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
@@ -436,7 +436,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
   Options.FunctionSections = FunctionSections;
   Options.UniqueSectionNames = UniqueSectionNames;
   Options.MCOptions.AsmVerbose = AsmComments;
-  Options.MCOptions.PreserveAsmComments = AsmComments;
+  // Always preserve comments that were written by the user
+  Options.MCOptions.PreserveAsmComments = true;
   Options.MCOptions.ABIName = ABIStr;
   if (SplitDwarfFile) {
     Options.MCOptions.SplitDwarfFile = SplitDwarfFile;
diff --git a/tests/assembly/asm-comments.rs b/tests/assembly/asm-comments.rs
new file mode 100644
index 00000000000..557009975dd
--- /dev/null
+++ b/tests/assembly/asm-comments.rs
@@ -0,0 +1,12 @@
+//@ assembly-output: emit-asm
+//@ only-x86_64
+// Check that comments in assembly get passed
+
+#![crate_type = "lib"]
+
+// CHECK-LABEL: test_comments:
+#[no_mangle]
+pub fn test_comments() {
+    // CHECK: example comment
+    unsafe { core::arch::asm!("nop // example comment") };
+}