-
Notifications
You must be signed in to change notification settings - Fork 286
Document supported inline assembly instructions #8937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||||||||||||||||||||||||||||
| [CPROVER Manual TOC](../../) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ## Modeling Inline Assembly | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| CBMC supports GCC-style (`asm`/`__asm__`) and MSVC-style (`__asm {}`) | ||||||||||||||||||||||||||||||||
| inline assembly syntax. During verification, the `remove_asm` pass | ||||||||||||||||||||||||||||||||
| translates recognized instructions into equivalent goto-program | ||||||||||||||||||||||||||||||||
| operations. **Unrecognized instructions are silently removed**, which | ||||||||||||||||||||||||||||||||
| may lead to unsound results if the assembly has side effects that | ||||||||||||||||||||||||||||||||
| matter for the property being verified. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ### Supported Instructions | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| #### x86 | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| | Instruction | Effect in CBMC | | ||||||||||||||||||||||||||||||||
| |---|---| | ||||||||||||||||||||||||||||||||
| | `mfence` | Full memory fence | | ||||||||||||||||||||||||||||||||
| | `lfence` | Load memory fence | | ||||||||||||||||||||||||||||||||
| | `sfence` | Store memory fence | | ||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+20
|
||||||||||||||||||||||||||||||||
| | `lfence` | Load memory fence | | |
| | `sfence` | Store memory fence | | |
| | `lfence` | Full memory fence (modeled same as `mfence`) | | |
| | `sfence` | Full memory fence (modeled same as `mfence`) | |
Copilot
AI
Mar 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xchg/xchgl and the lock prefix are listed as supported and “wrapped in an atomic section with full fence”, but remove_asm doesn’t actually translate these instructions: xchg only flips an internal x86_32_locked_atomic flag and then is treated as unknown, causing the whole asm statement to be dropped. Please either remove these from the supported list or clarify their current behavior (or implement proper modeling).
Copilot
AI
Mar 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The claim that output operands are assigned nondeterministic values when an instruction is not otherwise modeled doesn’t match remove_asm: for unknown instructions the asm statement is turned into skip with no assignments, and for modeled fences (e.g., mfence) outputs aren’t written either. Please update this section to reflect the actual behavior (outputs only change when the modeled helper writes through an output pointer, e.g., fstcw/fnstcw/fldcw).
| For GCC extended assembly, CBMC processes the output (`=r`, `+r`) and | |
| input (`r`, `m`) operand lists. Output operands are assigned | |
| nondeterministic values when the instruction is not otherwise modeled. | |
| For GCC extended assembly, CBMC parses the output (`=r`, `+r`) and | |
| input (`r`, `m`) operand lists, but in most cases the operands do not | |
| directly influence the generated goto program. For recognized fence | |
| instructions (for example, `mfence`, `lfence`, `sfence`, `dmb`), the | |
| inline assembly is replaced by appropriate fence operations and the | |
| C-level output operands are not written. For unrecognized instructions, | |
| the entire asm statement is removed (translated to `skip`) with no | |
| assignments to outputs and no introduction of nondeterministic values. | |
| Output operands only have an effect when the modeled helper for a | |
| particular instruction reads or writes through a memory operand | |
| (pointer) associated with that output, such as in the handling of | |
| `fstcw` / `fnstcw` / `fldcw`, which map to `__CPROVER_rounding_mode`. |
Copilot
AI
Mar 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The limitations section says MSVC-style __asm support is “the same as for GCC-style”, and mentions atomics “beyond lock/xchg”. In remove_asm.cpp, MSVC-style modeling only covers the x86 *f?stcw, fldcw, and *fence instructions (no ARM/Power, and no effective lock/xchg modeling). Please adjust these bullets to match the actual supported subset.
| - Complex atomic operations beyond `lock`/`xchg` are not modeled. | |
| - MSVC-style `__asm` blocks are parsed but instruction support is the | |
| same as for GCC-style. | |
| - For GCC-style inline assembly, complex atomic operations beyond the | |
| basic `lock`/`xchg` patterns listed above are not modeled as single | |
| atomic operations. | |
| - MSVC-style `__asm` blocks are parsed; currently only the x86 | |
| `mfence`/`lfence`/`sfence`, `fstcw`/`fnstcw`, and `fldcw` instructions | |
| are modeled. ARM/Power instructions and `lock`-prefixed / `xchg` | |
| instructions are not modeled for MSVC-style inline assembly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This says “Unrecognized instructions are silently removed”, but in
src/assembler/remove_asm.cppany unknown instruction setsunknown=trueand then the pass discards all translated instructions for that asm statement (even ones it recognized earlier). Consider clarifying that an asm statement containing any unrecognized instruction is dropped entirely.