Always preserve user-written comments in assembly

This commit is contained in:
Trevor Gross 2024-06-21 14:01:15 -05:00
parent 6292b2af62
commit 64a3bd84d8
2 changed files with 14 additions and 1 deletions

View File

@ -436,7 +436,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
Options.FunctionSections = FunctionSections; Options.FunctionSections = FunctionSections;
Options.UniqueSectionNames = UniqueSectionNames; Options.UniqueSectionNames = UniqueSectionNames;
Options.MCOptions.AsmVerbose = AsmComments; 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; Options.MCOptions.ABIName = ABIStr;
if (SplitDwarfFile) { if (SplitDwarfFile) {
Options.MCOptions.SplitDwarfFile = SplitDwarfFile; Options.MCOptions.SplitDwarfFile = SplitDwarfFile;

View File

@ -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") };
}