Skip to content

Add a lint for asm blocks that should be marked volatile #11

@jeremydavis519

Description

@jeremydavis519

While we shouldn't make it impossible to write non-volatile ASM (maybe the programmer wants to allow compiler optimizations), we should give a warning whenever it looks like the compiler might elide an asm block.

According to https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Extended-Asm.html, a non-volatile asm block might be elided by GCC if

  • "all the output operands you specify are for th[e] purpose [of clobbering inputs] (and hence unused)"
  • "the memory affected [by a clobber] is not listed in the inputs or outputs of the asm, as the 'memory' clobber does not count as a side-effect of the asm"

One exception: "An asm instruction without any output operands will be treated identically to a volatile asm instruction." So no warning is needed in that case.

It's not clear to me right now how LLVM's rules for optimizing inline ASM compare to GCC's rules. I'll have to look into it before adding the lint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions