Repository navigation
Model or conservatively approximate inline assembly - #8937
tautschnig wants to merge 23 commits into
Conversation
There was a problem hiding this comment.
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.
| | `lfence` | Load memory fence | | ||
| | `sfence` | Store memory fence | |
There was a problem hiding this comment.
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).
| | `lfence` | Load memory fence | | |
| | `sfence` | Store memory fence | | |
| | `lfence` | Full memory fence (modeled same as `mfence`) | | |
| | `sfence` | Full memory fence (modeled same as `mfence`) | |
| | `xchg` / `xchgl` | Exchange; wrapped in atomic section with full fence | | ||
| | `lock` prefix | Wraps the following instruction in an atomic section with full fence | |
There was a problem hiding this comment.
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).
| 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. |
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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`. |
| - 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. |
There was a problem hiding this comment.
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. |
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
96a4f97 to
936d4be
Compare
936d4be to
dbfa5ee
Compare
43dafb8 to
8e81849
Compare
__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>
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>
8e81849 to
ca672d3
Compare
The
remove_asmpass 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:
Symex: havocking a string literal has no effect.
__CPROVER_havoc_objecton a pointer to a string literal failed an invariant inhavoc_rec. This was a pre-existing bug; the approximation below hits it for anychar *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.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 maderemove_asmfail the invariant "unexpected assembler flavor".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.remove_asm: model barriers and x87 control word operands precisely.
fstcw %0; fldcw %1used to pass%0to both helpers. Each instruction now uses the operand it refers to.dmb ishldanddmb ishstused to be full fences, which prunes weak-memory behaviours. They now order loads, respectively stores, only.sync 1islwsync).hwsyncandeieioand the no-opsnop,pauseandyieldare now modeled.make_fencetakes four orderings plus one cumulativity flag instead of eight positional flags.remove_asm: approximate assembly that is not modeled conservatively. The new
asm_approximationtdoes the following, in this order:--pointer-checkand the other checks apply to them.(uintptr_t)&x), and pointer members of structs and unions."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.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.
Document the modeling and approximation of inline assembly. This rewrites
doc/cprover-manual/modeling-inline-asm.mdfor the new semantics, including the limitations listed below.remove_asm: model stmxcsr and ldmxcsr. C libraries implement
fegetroundandfesetroundwith these (for example, FreeBSD'sfenv.h). Once approximated, they made the rounding mode nondeterministic, andFloat-no-simp9failed on FreeBSD. They are now modeled likefstcwandfldcw: the rounding mode is bits 13 and 14 of the SSE control and status register, andstmxcsrstores nondeterministic values in the other bits.Known limitations, also listed in the manual page:
asm gotostill always falls through. A follow-up PR adds the dispatch."memory"clobber, the approximation emits one assignment per static object, so its cost grows with the number of statics.Tests:
inline_asm_droppedbecomesinline_asm_approximation. Each of its assertions marked "fails" holds when the statement is dropped.inline_asm_approximation_msvc(preprocessed input, as preprocessing for--winx64fails 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, andhavoc_object_string_literal.inline_asm_modelingnow also covers the barrier options,eieioand the no-ops, and it no longer uses the invalidlock; mfence.Fixes: #6374