Skip to content

Commit c260d3e

Browse files
committed
Always preserve user-written comments in assembly
1 parent cf2df68 commit c260d3e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
436436
Options.FunctionSections = FunctionSections;
437437
Options.UniqueSectionNames = UniqueSectionNames;
438438
Options.MCOptions.AsmVerbose = AsmComments;
439-
Options.MCOptions.PreserveAsmComments = AsmComments;
439+
// Always preserve comments that were written by the user
440+
Options.MCOptions.PreserveAsmComments = true;
440441
Options.MCOptions.ABIName = ABIStr;
441442
if (SplitDwarfFile) {
442443
Options.MCOptions.SplitDwarfFile = SplitDwarfFile;

tests/assembly/asm-comments.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ assembly-output: emit-asm
2+
// Check that comments in assembly get passed
3+
4+
#![crate_type = "lib"]
5+
6+
// CHECK-LABEL: test_comments:
7+
#[no_mangle]
8+
pub fn test_comments() {
9+
// CHECK: example comment
10+
unsafe { core::arch::asm!("nop // example comment") };
11+
}

0 commit comments

Comments
 (0)