Skip to content

Commit 64a3bd8

Browse files
committed
Always preserve user-written comments in assembly
1 parent 6292b2a commit 64a3bd8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-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

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

0 commit comments

Comments
 (0)