Skip to content

Model or conservatively approximate inline assembly - #8937

Open
tautschnig wants to merge 23 commits into
diffblue:developfrom
tautschnig:fix-6374-inline-asm-doc
Open

tautschnig wants to merge 23 commits into
diffblue:developfrom
tautschnig:fix-6374-inline-asm-doc

Conversation

@tautschnig

@tautschnig tautschnig commented Mar 30, 2026 •

Copy link
Copy Markdown
Collaborator

The remove_asm pass used to drop every inline assembly statement that contains an instruction it does not model, so any effect of the statement was lost: a property depending on an output operand, on memory written through a pointer operand, or on memory changed behind a "memory" clobber could be reported as holding when it does not (#6374). This PR documents what is modeled, makes the modeled instructions precise, and replaces the dropping by a conservative approximation.

Commits:

  1. Symex: havocking a string literal has no effect. __CPROVER_havoc_object on a pointer to a string literal failed an invariant in havoc_rec. This was a pre-existing bug; the approximation below hits it for any char * operand. The same commit is also proposed separately in Symex: havocking a string literal has no effect #9496; once that is merged, it drops out of this PR.

  2. C front end: asm blocks that form a function body are gcc-style. void asm f() { mov eax, eax } (gcc -fasm-blocks) produced a statement without a flavor, which made remove_asm fail the invariant "unexpected assembler flavor".

  3. Goto conversion: make side effects in asm operands explicit. Side effects in operands, such as "=m"(*f()), were kept inside the statement and lost with it.

  4. remove_asm: model barriers and x87 control word operands precisely.

    • fstcw %0; fldcw %1 used to pass %0 to both helpers. Each instruction now uses the operand it refers to.
    • dmb ishld and dmb ishst used to be full fences, which prunes weak-memory behaviours. They now order loads, respectively stores, only.
    • Fences with operands they don't take are no longer modeled (Power sync 1 is lwsync).
    • Power hwsync and eieio and the no-ops nop, pause and yield are now modeled.
    • The two copies of the library-call helper are merged, and make_fence takes four orderings plus one cumulativity flag instead of eight positional flags.
  5. remove_asm: approximate assembly that is not modeled conservatively. The new asm_approximationt does the following, in this order:

    1. It evaluates the input and in-out operands, so --pointer-check and the other checks apply to them.
    2. It records the output addresses and the pointers among the operands before anything changes. Pointers include arrays (which decay), pointers cast to integers ((uintptr_t)&x), and pointer members of structs and unions.
    3. It havocs what those pointers point to.
    4. With a "memory" clobber, and for basic assembly, it havocs all objects of static lifetime, what pointers among them point to, and the address-taken locals of the enclosing function.
    5. It havocs the outputs.
    6. It havocs the rounding mode (constrained to 0..3).

    MSVC blocks havoc every local variable they name, including all shadowed candidates, and are treated as clobbering memory. Each approximated statement prints a warning saying what was havocked.

  6. Document the modeling and approximation of inline assembly. This rewrites doc/cprover-manual/modeling-inline-asm.md for the new semantics, including the limitations listed below.

  7. remove_asm: model stmxcsr and ldmxcsr. C libraries implement fegetround and fesetround with these (for example, FreeBSD's fenv.h). Once approximated, they made the rounding mode nondeterministic, and Float-no-simp9 failed on FreeBSD. They are now modeled like fstcw and fldcw: the rounding mode is bits 13 and 14 of the SSE control and status register, and stmxcsr stores nondeterministic values in the other bits.

Known limitations, also listed in the manual page:

  • Objects reachable only through other pointers keep their values. Examples are heap objects not pointed to by an operand or a static, and a caller's locals.
  • Statics added by linking the CPROVER library afterwards are not havocked.
  • asm goto still always falls through. A follow-up PR adds the dispatch.
  • Unmodeled statements are not atomic and are not fences.
  • With a "memory" clobber, the approximation emits one assignment per static object, so its cost grows with the number of statics.

Tests:

  • inline_asm_dropped becomes inline_asm_approximation. Each of its assertions marked "fails" holds when the statement is dropped.
  • New tests: inline_asm_approximation_msvc (preprocessed input, as preprocessing for --winx64 fails on non-x86 hosts), inline_asm_approximation_rounding_mode (no-new-smt, because the incremental SMT back-end runs out of memory on the float division), inline_asm_fpu_control_word, inline_asm_mxcsr, cbmc-library/__asm_stmxcsr, cbmc-library/__asm_ldmxcsr, asm_block_function_body, asm_operand_side_effects, and havoc_object_string_literal.
  • inline_asm_modeling now also covers the barrier options, eieio and the no-ops, and it no longer uses the invalid lock; mfence.

Fixes: #6374

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig self-assigned this Mar 30, 2026
Copilot AI review requested due to automatic review settings March 30, 2026 18:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds user documentation describing which inline-assembly instructions CBMC’s remove_asm pass recognizes and how they are translated, and links it from the manual index (Fixes #6374).

Changes:

  • Added a new manual page documenting supported inline-asm instructions and limitations.
  • Linked the new inline-asm documentation page from the manual index.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
doc/cprover-manual/modeling-inline-asm.md New page documenting remove_asm inline-asm support and limitations.
doc/cprover-manual/index.md Adds a TOC entry pointing to the new inline-asm documentation page.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +20
| `lfence` | Load memory fence |
| `sfence` | Store memory fence |

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table states lfence/sfence are load/store fences, but CBMC currently models __asm_lfence and __asm_sfence as a full __CPROVER_fence (same as mfence) in src/ansi-c/library/x86_assembler.c. Please update the documented effect (or adjust the underlying model if the intent is to distinguish them).

Suggested change
| `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 uses AI. Check for mistakes.
Comment on lines +23 to +24
| `xchg` / `xchgl` | Exchange; wrapped in atomic section with full fence |
| `lock` prefix | Wraps the following instruction in an atomic section with full fence |

Copilot AI Mar 30, 2026

Copy link

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 uses AI. Check for mistakes.
Comment on lines +6 to +10
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.

Copilot AI Mar 30, 2026

Copy link

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.cpp any unknown instruction sets unknown=true and 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.

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +46
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.

Copilot AI Mar 30, 2026

Copy link

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).

Suggested change
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 uses AI. Check for mistakes.
Comment on lines +56 to +58
- 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.

Copilot AI Mar 30, 2026

Copy link

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.

Suggested change
- 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.

Copilot uses AI. Check for mistakes.
@codecov

codecov Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.84627% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.41%. Comparing base (3e1f386) to head (ca672d3).
⚠️ Report is 36 commits behind head on develop.

Files with missing lines Patch % Lines
src/assembler/remove_asm.cpp 92.67% 29 Missing ⚠️
src/assembler/asm_approximation.cpp 94.20% 12 Missing ⚠️
src/analyses/invariant_set.cpp 0.00% 2 Missing ⚠️
src/ansi-c/parser.y 71.42% 2 Missing ⚠️
src/analyses/constant_propagator.cpp 75.00% 1 Missing ⚠️
src/ansi-c/goto-conversion/goto_asm.cpp 93.75% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8937      +/-   ##
===========================================
+ Coverage    81.29%   81.41%   +0.11%     
===========================================
  Files         1725     1729       +4     
  Lines       191680   192195     +515     
  Branches        73       74       +1     
===========================================
+ Hits        155835   156469     +634     
+ Misses       35845    35726     -119     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tautschnig
tautschnig force-pushed the fix-6374-inline-asm-doc branch 3 times, most recently from 96a4f97 to 936d4be Compare June 12, 2026 07:49
@tautschnig tautschnig assigned kroening and unassigned tautschnig Jun 16, 2026
@tautschnig
tautschnig force-pushed the fix-6374-inline-asm-doc branch from 936d4be to dbfa5ee Compare November 16, 2026 07:59
@tautschnig tautschnig changed the title Document supported inline assembly instructions Model or conservatively approximate inline assembly Nov 16, 2026
@tautschnig
tautschnig force-pushed the fix-6374-inline-asm-doc branch 3 times, most recently from 43dafb8 to 8e81849 Compare November 17, 2026 13:32
tautschnig and others added 9 commits November 27, 2026 14:33
__CPROVER_havoc_object(p) with p pointing to a string literal failed the
invariant "Attempted to symex havoc applied to unsupported expression", as
dereferencing p yields the literal itself: a string constant for a narrow
string literal, and an array for a wide or Unicode string literal or for
the part of any literal that a pointer into its middle refers to.

String literals and other constants are not objects whose value can
change, so there is nothing to havoc. Use
goto_symex_statet::is_read_only_object, which symex_assign uses to ignore
writes to such objects, to recognise them.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Add doc/cprover-manual/modeling-inline-asm.md describing how CBMC's remove_asm
pass translates inline assembly: x86 fences (mfence/lfence/sfence) and the FP
control word (fstcw/fnstcw/fldcw), ARM barriers (dmb/dsb/isb), Power
synchronisation (sync/lwsync/isync), and the lock prefix. The page documents
the actual behaviour, including that lfence/sfence are modeled identically to
mfence, that isb/isync are empty fences, that xchg and lock-prefixed
read-modify-write instructions are not modeled (dropped), that an
inline-assembly statement containing any unrecognized instruction is dropped
in its entirety (including recognized siblings), that output operands are not
assigned nondeterministic values, and that MSVC-style asm only models the x86
subset. Link the new page from the manual index.

Add regression tests regression/cbmc/inline_asm_{modeling,dropped} that pin
these documented contracts against the goto program shown by
cbmc --show-goto-functions, so the documentation and remove_asm.cpp cannot
drift silently.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
remove_asm replaces an entire inline-assembly statement with skip whenever it
contains an instruction that is not modeled, silently discarding any modeled
instructions in the same statement. Emit a warning identifying the source
location so users are not left silently relying on un-modeled assembly.

Update the inline-assembly manual page and the inline_asm_dropped regression
test to reflect the new diagnostic.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
process_instruction_gcc and process_instruction_msc shared near-identical
scaffolding: parsing the assembly text, handling the lock prefix and xchg,
wrapping locked instructions in an atomic section with a full fence, and
dropping the whole statement when an instruction is not recognized. Extract
this into a shared process_asm helper parameterized by a per-flavor command
handler (handle_gcc_command / handle_msc_command), and replace the repeated
by-hand fence construction with a make_fence helper.

No change in behavior; the inline_asm_modeling and inline_asm_dropped
regression tests pin the emitted goto program.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
With gcc's -fasm-blocks (and in CodeWarrior style), a function body may be
an assembly block, as in `void asm f() { mov eax, eax }`. The parser
produced an asm statement without a flavor for these, which made
remove_asm fail the invariant "unexpected assembler flavor". Give these
statements the gcc flavor and the operand layout of gcc-style statements
without operands, as already done for `__asm__ { ... }` blocks.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The operands of a gcc-style inline assembly statement are evaluated
before the statement executes, but goto conversion copied the statement
including any side effects in its operands, such as function calls or
assignments. remove_asm then either dropped those side effects together
with the statement or emitted instructions with side-effect expressions in
them. Clean the output and input operands as for any other expression, so
that the side effects become explicit instructions before the statement.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Several modeled instructions were translated without looking at their
operands:

- `fstcw %0; fldcw %1` passed the first operand of the statement to both
  library models, so fldcw loaded the control word from `%0`. Resolve the
  `%N` operand reference of each instruction instead, and treat any other
  operand (a register, `%[name]`, an explicit address) as not modeled.
  MSVC-style blocks naming a variable that is shadowed are not modeled
  either, rather than picking one of the candidates.
- ARM `dmb ishld` and `dmb ishst` were full fences. A fence that is stronger
  than the hardware's prunes behaviours that weak-memory instrumentation
  needs to consider. Options ending in `ld` now order loads before loads
  and stores, options ending in `st` order stores before stores, and other
  unknown options are not modeled.
- Fences and `isb` with operands they do not take (e.g. Power `sync 1`,
  which is `lwsync`) are not modeled.

Also model Power `hwsync` and `eieio`, and the no-ops `nop`, `pause`, and
`yield`. Merge the two copies of the library call helper, and replace the
eight positional flags of make_fence by the four orderings plus a single
cumulativity flag (all existing users set cumulativity for all of the
orderings they set, or for none).

process_asm now returns the first instruction that is not modeled instead
of emitting the warning, to let callers handle that case.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
An inline assembly statement containing an instruction that is not
modeled was removed, so that its effects were lost: any property that
depends on an output operand, on memory written through a pointer
operand, or on memory changed behind a "memory" clobber could be reported
as holding although it does not (see diffblue#6374).

Replace such statements by a conservative approximation (in the new
asm_approximationt):

1. the input operands, and the in-out operands, are read, so that they are
   subject to the usual checks;
2. the addresses of the outputs, and the pointers found in the input and
   in-out operands (pointer operands, arrays decaying to pointers, pointers
   cast to integers, pointer members of structs and unions) are recorded
   in temporaries before anything changes;
3. the objects these pointers point to are havocked;
4. with a "memory" clobber, and for basic assembly without any operands or
   clobbers, the objects of static lifetime, the objects that pointers
   among them point to, and the address-taken local variables of the
   enclosing function are havocked;
5. the outputs are havocked, at their recorded addresses;
6. the rounding mode is havocked, as the statement may write the control
   registers of the floating-point unit.

MSVC-style blocks have no operand interface: every local variable named in
the block (all of them, if the name is shadowed) is treated as an output
and pointer operand, and the block as having a "memory" clobber.

Objects reachable only through other pointers (heap objects not pointed to
by an operand or an object of static lifetime, or a caller's local
variables) keep their values, which the warning now printed for each
approximated statement says.

Fixes: diffblue#6374

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Describe the instructions remove_asm now models, including the barrier
options, and the conservative approximation of statements with
instructions that are not modeled, together with its limitations.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig and others added 14 commits December 1, 2026 23:00
The C library's fegetround and fesetround (for example, FreeBSD's fenv.h)
read and write the rounding mode with stmxcsr and ldmxcsr, which were
approximated: the rounding mode then became nondeterministic, so that
Float-no-simp9 failed on FreeBSD.

Model them like fstcw and fldcw, via library functions: the rounding mode
is bits 13 and 14 of the SSE control and status register (with the same
encoding as __CPROVER_rounding_mode). The other bits of the register (the
exception flags and masks, flush-to-zero, and denormals-are-zero) are not
modeled: stmxcsr stores nondeterministic values in them.

inline_asm_approximation_rounding_mode now uses fxrstor, which remains
approximated. The results of inline_asm_mxcsr were validated natively on
x86-64.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
When all instructions of a gcc-style statement were modeled, remove_asm
emitted only their translation, so the output operands kept their old
values. On hardware, an output receives the register that the compiler
chose for it: `asm("" : "=r"(x) : "0"(y))` (the Linux kernel's RELOC_HIDE
and OPTIMIZER_HIDE_VAR) sets x to y, and `asm("nop" : "=a"(z) : "a"(w))`
sets z to w, but CBMC proved x == 0 and z == 0. The manual's claim that an
empty template does nothing was wrong for statements with outputs.

After the translation of the instructions, remove_asm now assigns each
output with an `=` constraint that no modeled instruction writes (the
operand of fstcw, fnstcw, and stmxcsr is written):
- the value of the input that is tied to it by a matching constraint (its
  number, or its symbolic name in brackets), if the types are the same or
  are integer, enumeration, or pointer types of the same width;
- otherwise a nondeterministic value.
In-out operands keep their values. As for the approximation, the inputs and
the addresses of the outputs are recorded before the instructions, so that
`"=r"(p), "=r"(q) : "0"(q), "1"(p)` swaps p and q.

To resolve symbolic names, the parser keeps them in ID_identifier of the
operands, as the commit "C front end: keep the symbolic names of asm
operands" of a later change does with the same lines.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
In gcc mode, `__asm { mov x, 1 }` (Clang and Apple gcc -fasm-blocks) and
asm blocks that form a function body, as in `void asm f(int *p) { ... }`,
had the gcc flavor without operands. remove_asm thus approximated them as
gcc-style basic assembly, which changes objects of static lifetime and
address-taken local variables only, and CBMC proved that x is unchanged
(it is 1 with clang-18 -fasm-blocks) and that f does not write *p.

These blocks use Intel syntax and name the C variables they access, as
MSVC blocks do. Give them the msc flavor (with the text as only operand),
so that remove_asm changes the local variables and parameters they name and
the objects these point to. asm_block_function_body now checks that the
object a parameter of such a function points to may change; asm_block_gcc
checks blocks in braces.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The assembler lexer of remove_asm treated '#' as the start of a comment
anywhere. On ARM and AArch64, '#' starts a comment only at the start of a
line or statement; elsewhere it introduces an immediate. With --arch arm64,
`dmb #11; str %w1, [%0]` thus lost the store, and the statement was
modeled as a fence only: CBMC proved that the stored-to object is
unchanged. `dmb #9` (ishld) became a full fence, which prunes weak-memory
behaviours.

The parser now knows whether '#' starts a comment anywhere, which is the
case on x86 (and for MSVC-style blocks), Power, MIPS, RISC-V, s390, and
LoongArch, as GNU as and llvm-mc agree. For other targets, including ARM
and AArch64, '#' starts a comment at the start of a line or statement only
and is a token otherwise, which at worst makes a statement approximated.
The immediate forms of the dmb, dsb, and isb options are mapped to the
named options; reserved values are not modeled.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
__asm_lfence and __asm_sfence, which remove_asm calls for lfence and
sfence, were full fences like __asm_mfence. A full fence orders stores
before later loads, which neither instruction does: in a store-buffering
test with lfence or sfence between the store and the load in each thread,
x86 hardware exhibits r0 == 0 && r1 == 0 (observed 111 and 1968240 times,
respectively, in 2e6 runs), but CBMC with --mm tso proved that it cannot
happen.

lfence now orders loads before later loads and stores (RR, RW), and sfence
stores before later stores (WW). The new cbmc-concurrency test
asm_x86_fences_sb checks store buffering with each of the three fences,
and the cbmc-library tests of __asm_lfence and __asm_sfence, which were
KNOWNBUG placeholders that included a header that does not exist, now pin
the fences.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
`dsb ishst` (and dsb with any other option ending in st) was modeled like
`dmb ishst`: as a fence that orders stores before later stores only. Unlike
a dmb, a dsb waits for the accesses it orders to complete before any later
instruction executes, so the stores before it are also ordered before the
loads after it. The weaker fence admitted store buffering across dsb ishst,
which the architecture forbids.

dsb with a st option now also orders stores before later loads (WW and WR,
cumulative); dmb with a st option is unchanged. The new cbmc-concurrency
test asm_arm_dsb_st_sb checks store buffering with dsb ishst and dmb
ishst, and inline_asm_modeling pins both fences.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The scanner of remove_asm returns `s.a` as one identifier, as it allows
'.' in identifiers. For an MSVC-style block that is approximated, such as
`__asm { mov s.a, 1 }` with --winx64, the lookup of the local variables
the block names thus found nothing for `s.a`, and CBMC proved s.a == 0.
The name up to the first '.' is now looked up, so s is changed.

The operand of an MSVC-style fstcw, fnstcw, fldcw, stmxcsr, or ldmxcsr
was looked up preferring a unique local variable over a global variable,
even if that local variable is not in scope at the block: with a local cw
in an earlier block and `__asm { fnstcw cw }` referring to the global cw,
CBMC wrote the dead local (reporting a dead-object failure) and proved that
the global is unchanged. CBMC does not know which variables are in scope,
so the instruction is now modeled only if there is exactly one variable of
that name among the local variables and parameters of the function and the
global variables; otherwise the block is approximated.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
__asm_fstcw and __asm_fnstcw stored the rounding mode in bits 10 and 11 of
the x87 control word and 0 in all other bits. The other bits are the
exception masks and the precision control, which are 0x037f initially on
x86 hardware, so CBMC proved, for example, that `(cw & 0x300) == 0` after
`fnstcw %0`, which fails on hardware.

The other bits are now nondeterministic, as __asm_stmxcsr already does for
the bits of the SSE control and status register other than the rounding
mode. inline_asm_fpu_control_word checks this, and the cbmc-library test
of __asm_fnstcw, a KNOWNBUG placeholder that included a header that does
not exist, now checks the rounding mode like the test of __asm_fstcw.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
abstract_environmentt::havoc, which the variable-sensitivity domain uses
for calls of functions without a body and for writes through pointers it
cannot resolve, removed all variables from the environment, as a variable
that is not in it is top. A merge, however, only merges the variables that
both environments have, and keeps the others. When the path that jumps
over `opaque(&m)` reached the label first, m kept the value 0 after the
merge, and goto-analyzer --vsd reported `m == 0` as holding.

havoc now replaces each value by top instead, so the merge results in top.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The approximation of inline assembly assigns nondeterministic values to the
objects that its pointer operands point to with havoc_object. The constant
propagation, interval, and variable-sensitivity domains ignored that
statement, so goto-analyzer --constants and --vsd proved that k is
unchanged after `asm volatile("movl $1, (%0)" : : "r"(&k))`, as they did
after `__CPROVER_havoc_object(&k)`. invariant_sett threw an exception for
the statement. goto-instrument --constant-propagator, which uses the
constant propagation domain, replaced the assertion `k == 0` after
`__CPROVER_havoc_object(&k)` by true.

These domains do not track what pointers point to, so treat the statement
as changing anything a pointer may point to:
- constant propagation forgets the values of the objects of static lifetime
  and of the address-taken variables, as for calls of functions without a
  body;
- the interval and variable-sensitivity domains forget all values;
- invariant sets forget all invariants.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The C++ parser (Parser::rGCCAsmStatement) parses the outputs, inputs, and
clobbers of gcc-style inline assembly, but discards them. remove_asm thus
treats such a statement as basic assembly: an output of an approximated
statement, as in `asm volatile("movl $1, %0" : "=r"(out))`, is not
changed, and CBMC proves `out == 0`, which fails with g++. Likewise, an
output tied to an input keeps its value.

Fixing the C++ parser is left to other work on it. Add a KNOWNBUG test
that documents the problem, and list it among the limitations in the
manual.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
process_asm turned a lock prefix, and xchg, into an atomic section with a
full fence around the instruction. As none of the instructions that take a
lock prefix is modeled, nor is xchg, such a statement was approximated and
the atomic section discarded; the scaffolding only produced output for a
lock prefix on a modeled instruction, as in `lock; nop` or `lock; mfence`,
which is invalid (it raises an invalid-opcode exception) and was translated
into an atomic section with a full fence.

Remove the scaffolding. A lock prefix is now the command of its
instruction, which is not modeled, so statements with it are approximated
and the warning names it.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
inline_asm_modeling checked that each expected fence occurs somewhere in
the goto program, so a statement translated into the fence of another one
(several statements translate into the same fences) went unnoticed, and the
fences in the bodies of the x86 fence helpers were not checked at all. The
test now matches the instruction that each statement's line is translated
into, and the bodies of __asm_mfence, __asm_lfence, and __asm_sfence. It
also covers dsb ishld and hwsync.

In the manual, the description of lwsync as "all fences except
write-after-read" read backwards; it now says what lwsync orders. The
manual now also says that CBMC has a single rounding mode, which fldcw
sets although, on x86-64, float and double arithmetic uses the SSE
rounding mode, which fldcw does not change; the KNOWNBUG test
inline_asm_fldcw_sse documents the resulting wrong proof.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
For an output whose address depends on the program state, such as
arr[idx] next to the output idx in

  asm("" : "=r"(idx), "=r"(arr[idx]) : "0"(1), "1"(9));

compilers differ in whether they compute the address before or after
writing the other outputs: GCC at -O0 stores 9 to arr[1], GCC at -O2 and
Clang to arr[0]. Both the assignment of the outputs of a statement whose
instructions are all modeled and the approximation of other statements
used the address before the statement only, so CBMC proved properties
that the code compiled by GCC at -O0 violates.

Approximate a statement whose instructions are all modeled if it has more
than one output and one of them has an address that depends on the program
state. The approximation now assigns such outputs nondeterministic values
both at the address before and at the address after the statement.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig
tautschnig force-pushed the fix-6374-inline-asm-doc branch from 8e81849 to ca672d3 Compare December 2, 2026 06:21
@tautschnig
tautschnig requested a review from martin-cs as a code owner December 2, 2026 06:21

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document what inline asm is supported

3 participants