Skip to content

asm goto: jump to the label the statement chooses - #9499

Draft
tautschnig wants to merge 46 commits into
diffblue:developfrom
tautschnig:up/asm-goto
Draft

tautschnig wants to merge 46 commits into
diffblue:developfrom
tautschnig:up/asm-goto

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

Depends-on: #9497

An asm goto statement may jump to one of the C labels it lists. Goto
conversion kept it as an OTHER instruction, followed by the next
statement, so the jumps were lost: code after the labels was only reached
in other ways, and properties there could be reported as holding when they
do not.

Goto conversion now introduces a variable that the translation of the
statement sets to the (1-based) index of the label it jumps to, or to 0 if
it does not jump. After the statement, it dispatches on this variable
with ordinary gotos, which are converted like any other goto, so leaving
scopes is handled as usual. remove_asm sets the variable as follows:

  • for a statement whose instructions are all modeled, to 0, as none of the
    modeled instructions jumps;
  • for a statement that is approximated, to a nondeterministic value, so
    that it may jump to any of its labels or fall through.

The variable is the optional sixth operand of code_asm_gcct
(has_goto_target, goto_target, add_goto_target), not a named sub-tree.
Passes that rename the symbols of a function, such as goto-cc
--export-file-local-symbols for file-local functions, rename operands, but
not named sub-trees. With a named sub-tree, symbolic execution would fail to
find the variable in a renamed function, as the Linux kernel's static keys
(arch_static_branch) show. The test goto-cc-file-local/asm-goto covers
this.

The gotos have code of their own, which relies on the preceding fix to
finish_gotos: without it, valgrind reports a use-after-free in
finish_gotos for an asm goto that leaves a block with local variables.

Co-authored-by: Kiro kiro-agent@users.noreply.github.com

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a 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.

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.36340% with 85 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.56%. Comparing base (3e1f386) to head (29e8753).
⚠️ Report is 36 commits behind head on develop.

Files with missing lines Patch % Lines
src/assembler/remove_asm.cpp 93.01% 28 Missing ⚠️
src/goto-symex/symex_havoc_reachable.cpp 97.12% 16 Missing ⚠️
src/analyses/goto_rw.cpp 69.23% 12 Missing ⚠️
src/assembler/asm_approximation.cpp 94.48% 7 Missing ⚠️
src/goto-instrument/rw_set.cpp 79.16% 5 Missing ⚠️
src/pointer-analysis/reachable_objects.cpp 97.87% 3 Missing ⚠️
src/pointer-analysis/value_set_fi.cpp 89.28% 3 Missing ⚠️
src/analyses/invariant_set.cpp 0.00% 2 Missing ⚠️
src/ansi-c/parser.y 71.42% 2 Missing ⚠️
src/goto-programs/goto_program.cpp 80.00% 2 Missing ⚠️
... and 4 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9499      +/-   ##
===========================================
+ Coverage    81.29%   81.56%   +0.26%     
===========================================
  Files         1725     1732       +7     
  Lines       191680   193043    +1363     
  Branches        73       74       +1     
===========================================
+ Hits        155835   157448    +1613     
+ Misses       35845    35595     -250     

☔ 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 up/asm-goto branch 2 times, most recently from e668ae1 to 8e7b6a7 Compare November 17, 2026 13:32
tautschnig and others added 25 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>
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>
Add a havoc_reachable statement. Its operands are pointers, and its
arbitrary_memory flag says whether the objects of static lifetime and the
address-taken local variables of all functions on the call stack are also
roots. Symbolic execution computes the objects reachable from the roots
using the value set, following pointers stored in reachable objects
transitively. This includes heap objects and, through the dirty analysis,
a caller's local variables whose address has escaped. It then assigns
nondeterministic values to all of them.

The approximation of inline assembly will emit this statement. A static
pass cannot name heap objects or a caller's local variables, which is why
this is done in symbolic execution.

Assigning a nondeterministic value to a pointer would give it a value set
containing every object in the value set. That is imprecise: dereferencing
a pointer after the statement yields a case split over all objects, and
--pointer-check flags pointers that point nowhere. It is also costly, as
every such assignment visits the whole value set. Instead, each pointer
stored in a changed object is assigned a nondeterministic choice among:
- the pointers previously stored in the changed objects (its own first),
- the addresses of the reachable objects of a compatible type, and
- null.
The choice is restricted to at most 64 candidates. This models a statement
that relinks a list, and keeps dereferencing precise. Pointers in unions
and in arrays that are large or of non-constant size are assigned
arbitrary values.

Other analyses treat the statement like havoc_object: value sets and
dirty-variable analysis consider the operands only, and goto_rw records
writes to the objects the operands point to. As the dependencies of the
statement are only known during symbolic execution, the full slicer does
not slice programs that contain it.

The regression tests come with the use of the statement in remove_asm.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The approximation of inline assembly that is not modeled only changed the
objects that the pointer operands point to and, with a "memory" clobber,
the objects of static lifetime, the objects that pointers among them point
to, and the address-taken local variables of the enclosing function. Heap
objects more than one pointer away from these, such as the second node of
a list whose head is stored in a global variable, kept their values. So
did the local variables of a caller whose address has escaped.

Emit a havoc_reachable statement instead. Its roots are the pointer
operands and, for a "memory" clobber or basic assembly, all objects of
static lifetime and the address-taken local variables of all functions on
the call stack.

The new statement is evaluated before the outputs are assigned, while the
value sets still describe the state before the statement. The explicit
assignments to the objects of static lifetime are now done by the new
statement instead. They also caused symbolic execution time to grow
cubically with the number of statics: every nondeterministic pointer
assignment gives that pointer a value set of all objects, which the next
statement then has to havoc. For a program with 300 objects of static
lifetime (100 pointers and 100 structs with a pointer member) and two such
statements, cbmc took 363 seconds; it now takes 0.2 seconds, and symbolic
execution takes 10 seconds with 6000 objects of static lifetime.

Analyses other than symbolic execution ignore the new statement until the
following commits, which make them interpret it.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig and others added 21 commits December 1, 2026 23:00
goto_rw treated havoc_reachable like havoc_object of each operand: with a
"memory" clobber, which has no operands, the statement neither read nor
wrote anything. Analyses built on goto_rw, such as reaching definitions
and the dependence graph, thus considered the havocked objects unchanged.

With value sets (rw_range_set_value_sett), compute the reachable objects
like symbolic execution does:
- the roots are the operands and, with the arbitrary_memory flag, the
  objects of static lifetime and the address-taken local variables (as
  set by the new set_dirty, which reaching definitions and the dependence
  graph use);
- the closure follows the pointers stored in reachable objects using the
  value sets.
The statement reads the operands and the pointers it follows, and writes
the reachable objects that are symbols. Heap objects remain untracked, as
for all other instructions. Without value sets, it writes the objects the
operands point to and, with the arbitrary_memory flag, the objects of
static lifetime.

The closure is computed by the new find_reachable_objects. It works for
any pointer analysis, as it traverses objects with the type of the pointer
they are reached through. This handles dynamic objects, whose type the
static analyses do not know. Symbolic execution now shares the list of
objects of static lifetime and the pointer compatibility check with it.

The full slicer still does not slice programs that contain the statement.
The dependence graph does not track heap objects, so the instructions that
link heap objects would be sliced away, making the objects that the
statement changes unreachable. --full-slice already gets this wrong for
heap accesses without inline assembly (diffblue#260).

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The constant propagation, interval, variable-sensitivity, and invariant
set domains ignored havoc_reachable, or (invariant sets) threw an
exception. As remove_asm no longer assigns the objects of static lifetime
explicitly, goto-analyzer reported assertions about variables that
inline assembly may change as holding.

The domains do not track what pointers point to, so treat the statement as
changing everything it may reach:
- 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 flow-sensitive and flow-insensitive value-set analyses ignored
havoc_reachable. Their clients, such as goto-instrument's pointer
instrumentation and the reaching definitions of the dependence graph, so
assumed that the pointers inline assembly may change still point to what
they pointed to before.

Apply the same model as symbolic execution:
1. Find the objects reachable from the operands and, with the
   arbitrary_memory flag, from the objects of static lifetime and the
   objects whose address is stored anywhere. The value sets have no call
   stack, so the latter stand in for the address-taken local variables of
   the functions on the call stack.
2. Let each pointer stored in a reachable object in addition point to any
   reachable object of a compatible type, or be null.

reachable_pointer_value builds an expression with this value set for the
analyses to assign. With more than 64 candidate objects, the pointer may
point to an unknown object instead: listing every candidate makes each of
the pointers point to each of the objects. In a program with 6000 objects
of static lifetime and two such statements, --show-value-sets took 245
seconds instead of 31 seconds without the statements; it now takes 32
seconds.

Also update the manual page on what each tool does with approximated
inline assembly.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Each pointer stored in an object that havoc_reachable changes was assigned
a nondeterministic choice among at most 64 candidate values (its previous
value, the previous values of the other pointers of a compatible type, the
addresses of the reachable objects of a compatible type), and null. With
more candidates, the others were dropped, although the statement may store
any of them. For a program with 70 int variables of static lifetime and
`int *p = &g00`, `asm volatile("cli" ::: "memory")` followed by
`assert(p != &g69)` gave VERIFICATION SUCCESSFUL (the native program can
fail the assertion if the assembly stores &g69 in p).

Assign pointers with more than 64 candidates an arbitrary value instead,
as diffblue#8937 did. A nondeterministic pointer would have a value set of all
objects in the value set, which value_sett computes for each assignment by
visiting the value sets of all pointers, including those assigned an
arbitrary value before: the time grows quadratically with the number of
such pointers. For 900 objects of static lifetime (300 int, 300 int*, 300
structs with an int* member) and two statements, symex took 17 s instead of
1.6 s. Instead, the pointers are assigned temporaries that are never
assigned (and hence unconstrained), whose value set is computed once per
statement and shared. To make sharing effective, value_sett::make_union now
shares the map it adds to an empty one, and the computation of the
reachable objects visits each shared map once. Symex now takes 0.9 s on
this program.

With 6000 such objects of static lifetime, cbmc now takes 4 s and 290 MB
instead of 29 s and 2.3 GB (and reports s1.q != &g2, which the truncation
proved, as failing). Dereferencing a pointer with an arbitrary value
considers all objects: with an additional dereference of one of the
pointers after the statements, the program takes 40 s, mostly in
simplify_inequality_pointer_object.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Each pointer stored in an object that havoc_reachable changes was assigned
a choice among its previous value, the previous values of the other
pointers of a compatible type, the start addresses of the reachable objects
of a compatible type, and null. Pointer arithmetic and interior pointers
were thus excluded: for `int a[4]; int *gp = &a[0];`,
`asm volatile("addq $4, gp(%%rip)" ::: "memory"); assert(gp != &a[1]);`
gave VERIFICATION SUCCESSFUL, as did `assert(ip != &s.y)` after an
assembly statement that stores &s.y in `int *ip = &s.x`. Both assertions
fail natively.

Symbolic execution now also lets the pointer point to any position, given
by a nondeterministic offset, within the objects that these candidates
point into, provided that an object of the pointer's target type fits at
that position (an assumption on the result, guarded by the choice). Offsets
make dereferencing costly (byte_extract at a symbolic offset), so they are
only added to candidates that may point into an object larger than the
pointer's target type, or of unknown size. Pointers to objects of exactly
their target type, such as list nodes, are unchanged. The value-set
analyses now give the corresponding targets an unknown offset.

Variants evaluated (cbmc, default checks and --no-standard-checks):
- Unconstrained offsets: the regression test inline_asm_havoc_reachable
  gets spurious failures for the pointer checks of `head->data`, and a list
  of 8 heap nodes that the C code traverses after the assembly gets 12
  spurious pointer-check failures out of 29 properties.
- Offsets constrained to positions where the target type fits (with or
  without requiring a multiple of its size), for all candidates: no
  spurious failures, but the list traversal took 1.95 s instead of 0.20 s
  for 8 nodes, and 10.9 s instead of 1.0 s for 16 nodes.
- As committed (constrained, only for larger objects): the list traversal
  takes the same time as without offsets (0.20 s, 1.03 s). Four pointers
  into a static array of N ints dereferenced after the statement take
  1.7 s instead of 0.8 s for N = 256 and 7.0 s instead of 3.7 s for
  N = 1024. Dereferencing p0[1] in addition takes 13.9 s instead of 0.9 s
  for N = 256, and fails the bounds check, as the statement may have
  moved p0 to the last element.

The remaining assumption, now documented in the manual: the statement does
not store pointers one past the end of an object or to positions at which
an object of the target type does not fit, pointers to unreachable objects,
pointers into objects of another type that no pointer of a compatible type
pointed into, or pointers computed from integers.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The variable-sensitivity domain implements havoc_reachable (and writes
through pointers it does not know) by forgetting all values: havoc() clears
the map of the abstract environment. With --three-way-merge, the state after
a call is the caller's state with the values of the modified symbols taken
from the callee's end state, where abstract_environmentt::modified_symbols
only reports symbols that are in the map at the end of the callee. A havoc in
the callee was thus lost: for `g = 1; clobber();` with
`asm volatile("movl $0, g(%%rip)" ::: "memory")` in clobber,
`goto-analyzer --verify --vsd --three-way-merge` reported `assert(g == 1)` as
SUCCESS (natively, it fails). The same holds for `*p = 3` in a callee with an
unknown p (pre-existing).

Reporting the symbols that are in the map at the entry of the callee, but not
at its end, would not suffice: a variable that is unknown at the entry of the
callee (for example, because it has different values at two call sites, which
are merged) is in neither map, but may have a known value in the caller.
Instead, the abstract environment now records whether havoc() was applied
since the entry of the function (on any path: merging propagates it, the
transformer of a call clears it for the callee's entry state). If so, the
three-way merge havocs the caller's state before applying the modified
symbols, as without --three-way-merge, where the caller continues with the
callee's end state.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
rw_set, which the race check (--race-check), the interrupt instrumentation
(--isr), and the weak memory instrumentation use, ignored OTHER
instructions. Before havoc_reachable, the approximation of inline assembly
assigned the objects of static lifetime explicitly, and these assignments
were in the read/write sets. Now the writes of unmodeled assembly were
invisible: with a thread that runs `asm volatile("cli" ::: "memory")` and a
main function that writes g, `goto-instrument --race-check` followed by
cbmc reported no data race on g; with an interrupt handler that consists of
such a statement, `--isr` did not insert calls of the handler before main
reads a variable, and an assertion that the variable keeps its value held.

The read/write set of havoc_reachable now reads its operands and the
pointers stored in the reachable objects, and writes the reachable objects
that are symbols, using the value sets (as goto_rw does). The roots are the
operands and, with the arbitrary_memory flag (or if the operands have
unknown targets), the objects of static lifetime. The address-taken local
variables of the functions on the call stack are not roots: other threads
and interrupt handlers can only reach them through pointers, which the
closure follows. The race check now also instruments havoc_reachable.

The weak memory instrumentation (--mm) still ignores the statement, so its
writes become visible to other threads at once; the manual says so.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
`goto-analyzer --dependence-graph --show` crashed with a stack overflow
(SIGSEGV, unbounded recursion in value_set_fit::get_reference_set_sharing_rec)
on programs whose inline assembly has a "memory" clobber and that allocate
heap memory, for example `int **gpp; ... gpp = malloc(sizeof(int *));
asm volatile("cli" ::: "memory");` compiled with goto-cc.

The flow-insensitive value sets, which the reaching definitions of the
dependence graph use, store a variable's value as a reference (an object
of type #REF#) to the value set of another variable; such references may
form cycles, which value_set_fit::flatten handles. value_set_fit::
havoc_reachable collected the objects whose address is stored anywhere from
the raw value sets, and so took these references as objects. Assigning
their addresses to the pointers in the reachable objects then made the
value set analysis follow the cycles without end.

Skip references when collecting the objects whose address is stored
anywhere: the values they refer to are visited as entries of their own.
References to variables without a value set stand for these variables, as
in flatten_rec. Also, as the assignments of the flow-insensitive analysis
add to the previous values, no longer list the previous value of a pointer
(which made its value set refer to itself), and express the positions
within the objects it pointed to via these objects.

The new test (in goto-cc-goto-analyzer, as the crash needs a goto binary)
checks the dependencies of the statement on a program with heap objects.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
havoc_reachable splits each object it changes into the pointers it contains
and the remaining parts, and assigns each of them separately. The parts were
expressions such as a[i][j], an index or member expression of the whole
object. Reading such an expression (to record the previous value of a
pointer) renames it, and renaming the whole object expands it into all its
fields (field-sensitive symbolic execution has a symbol for each element),
once for each part. For `int *a[64][64]` of static lifetime and two
statements `asm volatile("cli" ::: "memory")`, cbmc took 164 s and 600 MB.
With one statement, symbolic execution took 80 s (2.7 s with a[32][32]).

Convert the parts to the symbols that field-sensitive symbolic execution
has for them (state.field_sensitivity.apply, for writing) before reading and
assigning them. cbmc now takes 1.3 s and 170 MB on the program with two
statements, and symbolic execution takes 0.5 s with one statement (0.1 s
with a[32][32]). The formula is unchanged (20572 steps for one statement).

The new test inline_asm_havoc_reachable_array has the program with one
statement; it exceeds a timeout of 20 s (test.pl -t 20) without this change.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Since "havoc_reachable: pointers may move within the objects they can
reach", a pointer that may point into an object larger than its target type
is assigned (among its other choices) a choice among its candidates plus a
nondeterministic offset, with an assumption, guarded by the choice, that an
object of the target type fits at the resulting position. The assumption
uses the object size and the pointer offset of that choice. This was slow on
arrays of structs that contain pointers: for 8 struct types, each with a
static array of 30 elements whose first element points to the second, and
two statements `asm volatile("cli" ::: "memory")`, cbmc took 21 s (61 s for
16 types; 2.9 s for 16 types and one statement).

Express the moved pointer instead relative to the objects that the
candidates may point into: the start of one of these objects (a choice with
constant sizes) plus a nondeterministic position of few bits if an object
of the target type fits there, and the start of the object otherwise. The
condition is part of the value rather than an assumption. The candidates
themselves remain choices. Candidates with unknown targets are moved within
the object they point to, using its object size, as before.

The position is a multiple of the alignment of the target type, as CBMC
lays out objects. Arbitrary byte positions made dereferencing slow: with
four pointers of static lifetime into an array of 256 int, dereferenced
after the statement, cbmc took 37 s instead of 1.4 s (and more than 600 s
instead of 12.5 s for 1024 int and an additional dereference of p0[1]). The
statement is thus assumed not to store misaligned pointers, which the
per-statement warning and the manual's limitations now state. Objects that
contain a packed struct or union, or a type whose given alignment is smaller
than that of its members, are exempt, as their members may be at any
position (in `struct __attribute__((packed)) { char c; int x; } ps[4]`,
ps[1].x is at offset 6): pointers are moved to arbitrary positions within
them. A smaller alignment given for the target type is used instead of its
natural one.

Measurements (cbmc with default options, wall-clock time, before -> after):
- 8 struct types with 30 elements each, two statements: 21 s -> 0.9 s;
  16 types: 61 s -> 1.9 s; 64 types: 9.1 s after.
- four pointers into int[256], dereferenced: 1.7 s -> 1.8 s; with p0[1]
  in addition: 12.6 s -> 1.8 s; int[1024] with p0[1]: 10.5 s -> 13.7 s.
- a list of 16 heap nodes traversed after the statement: 1.0 s both.

The new test inline_asm_havoc_reachable_alignment has the 8 struct types
(19.7 s before, 0.9 s after), and checks the misaligned pointer (which the
assumption excludes), the packed struct, and the reduced alignment.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Symbolic execution restricts each pointer stored in an object that
havoc_reachable changes to a choice among at most 64 candidate values, but
the number of such pointers was not bounded: the formula grows with the
number of pointers times their candidates. For 128 struct types, each with
a static array of 60 elements that contain a pointer to the struct type
(7680 pointers with 61 candidates each), and two statements
`asm volatile("cli" ::: "memory")`, cbmc ran out of memory (4 GB, after
47 s) in the propositional reduction. Also, finding the compatible
candidates of each pointer visited all candidates: 1920 pointers times 1984
candidates for 64 types with 30 elements each.

Once the pointers that one statement restricts to their candidates have
65536 candidate values in total, assign the remaining pointers arbitrary
values instead (which is sound, as for pointers with more than 64
candidates), and print a warning. The program above now takes 15 s and
1.4 GB. Index the candidates by the type they point to, plus the candidates
of type `void *` or `char *`, which are compatible with all pointers; the
order of the candidates is unchanged. 64 types with 30 elements take 8.3 s
instead of 9.1 s, 16 types 1.9 s as before.

The new test inline_asm_havoc_reachable_budget has 17 types with 63
elements (1071 pointers with 64 candidates each) and checks that the
pointers beyond the bound may point anywhere.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
havoc_reachable changes the objects that the value sets of the reachable
pointers point to. Two kinds of memory that C code accesses have no address
in the value sets, and kept their values:

- Dereferencing a pointer variable p whose target is not known (or invalid)
  yields its failed object p$object. For `int *gp = ext();` with a function
  ext without a body, `*gp = 1; asm volatile("cli" ::: "memory");` followed
  by `assert(*gp == 1)` gave VERIFICATION SUCCESSFUL (with
  --no-standard-checks), and likewise for a struct behind such a pointer,
  and for `"r"(gp + 1)` as an operand without a "memory" clobber.
- Memory at integer addresses, such as the memory-mapped register in
  `*(volatile int *)0x10000 = 1; asm volatile("movl $0, 0x10000" ::: "memory");
  assert(*(volatile int *)0x10000 == 1);`, which CBMC models as the array
  __CPROVER_memory. static_lifetime_objects excludes it, as it excludes all
  objects with the __CPROVER_ prefix. The assertion failed natively but held
  in CBMC.

Now the statement also changes the failed objects of the reachable pointer
variables (of the operands, and of the pointers computed from them by
pointer arithmetic and casts), also if they point to a constant type, and
follows the pointers stored in them. Failed objects are no candidate values
of pointers, as their address is not known, and neither are the previous
values of the pointers stored in them, as these are mostly not written: in
the test inline_asm_havoc_reachable, the failed object head$object of
`struct node *head` made `head` take the unknown value of head$object.next,
and dereferencing it failed. It changes __CPROVER_memory if the statement
may access arbitrary memory, or if a reachable pointer may point to an
integer address.

The message about pointers with unknown targets was a debug message, and
was printed for all of them. It is now a warning, printed only if an
operand whose targets are not known is no pointer variable (such as a
pointer read from memory that was not written). Dereferencing other
pointers with unknown targets (such as members) yields a fresh object each
time, so no value is kept. The manual describes this, and that the static
analyses do not take the statement to change these objects.

cbmc on a program with 3000 objects of static lifetime of each of int,
int * and a struct with an int * member, and two statements, takes 9.6 s
instead of 9.0 s.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
A pointer stored in an object that havoc_reachable changes, and that has
more than 64 candidate values, is assigned an arbitrary value: a temporary
that is never assigned, with the value set of a nondeterministic pointer,
which is the union of the objects in all value sets (and null). That union
lacks the reachable objects whose address no pointer holds, although the
statement may store their addresses. With 70 int variables of static
lifetime and `int *p = &g00`, `asm volatile("cli" ::: "memory")` followed
by `g69 = 0; *p = 1; assert(g69 == 0);` gave VERIFICATION SUCCESSFUL (with
--no-standard-checks; with the default checks, the assertion was UNKNOWN):
dereferencing p could not yield g69.

Add the reachable objects of a type compatible with the pointer's type (with
an unknown offset) to the shared value set: these are the objects whose
start addresses the pointer has as candidates when it is restricted to its
candidates. The shared value set is now computed once per statement and
target type. Adding all reachable objects instead made cbmc take 9.7 s
instead of 0.9 s on 300 objects of static lifetime of each of int, int *,
and a struct with an int * member (and 275 s instead of 35 s for 2000
each), as dereferencing an int * after the statement then considered the
pointers and structs as well. With compatible types only, the times are
unchanged (0.9 s, 35 s; 15 s for 128 struct types with 60 elements each).

The test inline_asm_havoc_reachable_candidates now writes through p.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
havoc_reachable splits the objects it changes into their pointers, which
are assigned a choice among candidate values or an arbitrary pointer, and
the other parts, which are assigned nondeterministic values. Unions, and
arrays of more than 64 elements or of a size that is not constant, are not
split, and were assigned a nondeterministic value as a whole. The value
set of a pointer in a union then had only an unknown target, which
dereferencing turns into a fresh object, and that of an element of a large
array kept its previous targets. For `union U { int *p; long l; } u;`,
`u.p = &x; asm volatile("cli" ::: "memory"); y = 0; *u.p = 5;` followed by
`assert(y == 0)` gave VERIFICATION SUCCESSFUL (with --no-standard-checks),
as did the same with `int *big[100]` instead of the union, although the
statement may store &y in u.p or in big[0].

After assigning such a part, also assign each pointer it contains an
arbitrary pointer, whose value set contains every object whose address is
stored anywhere and the reachable objects of a compatible type. For arrays,
the element at a nondeterministic index stands for all elements, as
assignments to array elements add to the value set. Members of unions are
accessed by byte extraction, as goto programs access them (rewrite_union).
The part's value remains nondeterministic, as the arbitrary pointers are
unconstrained. A warning is printed, as for pointers with more than 64
candidates. The manual already said that such pointers are assigned
arbitrary values.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The value set analyses give a pointer that havoc_reachable may change an
unknown target instead of listing more than 64 candidate objects, which no
test checked. Symbolic execution with path exploration (where the
statement is executed with the value set of each path) is checked by CI's
cbmc-paths-lifo profile, which runs all CORE tests of regression/cbmc with
--paths lifo, but not when running the suite with test.pl directly.

The new test show-value-sets-havoc-reachable-unknown (goto-instrument) has
70 int objects of static lifetime and a pointer to one of them: after the
statement, its value set is its previous target and unknown, while a
pointer with two candidates lists them. inline_asm_havoc_reachable now also
has a descriptor with --paths lifo, which pins the same verdicts.

The manual of the approximation that this series replaces said that objects
of static lifetime that are added when linking the CPROVER library are not
changed, which was true when the approximation assigned the objects of
static lifetime explicitly before linking. Symbolic execution now finds the
objects of static lifetime when it executes the statement, after linking,
and changes those of the library as well (for example, optind for getopt,
checked with cbmc on a program that reads optind before and after
`asm volatile("cli" ::: "memory")`), except those whose names start with
__CPROVER_. The manual dropped the sentence without saying this. It now
does, including that this excludes __CPROVER_errno, the model of errno, so
that the approximation assumes that the statement does not change errno.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
CI runs the CORE tests of regression/cbmc also with the new SMT backend
(--incremental-smt2-solver 'z3 --smt2 -in'), except those tagged
no-new-smt. With z3, inline_asm_havoc_reachable_array took 57 s and
inline_asm_havoc_reachable_budget 31 s (with the SAT backend: 1 s and
2.5 s; with --cprover-smt2: 5 s and 8 s). Both check what symbolic
execution generates, not the solver, so tag them no-new-smt.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
An asm goto statement may jump to one of the C labels it lists. Goto
conversion kept it as an OTHER instruction, followed by the next
statement, so the jumps were lost: code after the labels was only reached
in other ways, and properties there could be reported as holding when they
do not.

Goto conversion now introduces a variable that the translation of the
statement sets to the (1-based) index of the label it jumps to, or to 0 if
it does not jump. After the statement, it dispatches on this variable
with ordinary gotos, which are converted like any other goto, so leaving
scopes is handled as usual. remove_asm sets the variable as follows:
- for a statement whose instructions are all modeled, to 0, as none of the
  modeled instructions jumps;
- for a statement that is approximated, to a nondeterministic value, so
  that it may jump to any of its labels or fall through.

The variable is the optional sixth operand of code_asm_gcct
(has_goto_target, goto_target, add_goto_target), not a named sub-tree.
Passes that rename the symbols of a function, such as goto-cc
--export-file-local-symbols for file-local functions, rename operands, but
not named sub-trees. With a named sub-tree, symbolic execution would fail to
find the variable in a renamed function, as the Linux kernel's static keys
(arch_static_branch) show. The test goto-cc-file-local/asm-goto covers
this.

The gotos have code of their own, which relies on the fix to finish_gotos
of diffblue#9495: without it, valgrind reports a use-after-free in finish_gotos
for an asm goto that leaves a block with local variables.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The test asserted x <= 1 for the _Bool result of arch_static_branch, which
holds whether or not the asm goto jumps. It caught the crash of symbolic
execution when renaming the file-local symbols missed the variable that
selects the label, but not a dispatch that is lost, in which case control
always falls through to "return 0".

Add an assertion x == 0 that is expected to fail, as the approximated
statement may jump to l_yes, and pin the verdicts of both assertions. With
goto-cc and cbmc of the layer below (no asm goto handling), the new
assertion holds and the test fails.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Goto conversion lowers the jumps of an asm goto statement to ordinary
gotos so that leaving a scope is handled like for any other goto, but no
test covered an asm goto that leaves a block with local variables, or one
that jumps backwards.

The new test inline_asm_goto_scope has an asm goto that jumps out of a
block whose local y has escaped through a global pointer: a dereference
of that pointer after the jump fails with "dead object", which shows the
DEAD instructions on the jump path. A second asm goto jumps back to a
label before its block, forming a loop that is taken at most twice. Both
choose whether to jump from a nondeterministic operand, so the verdicts
do not depend on whether their instructions are modeled. The test runs
with --validate-goto-model --validate-ssa-equation. With cbmc of the
layer below (no asm goto handling), the jumps are lost and the test
fails.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
expr2c printed an asm goto statement as a plain asm statement, without
"goto" and the labels. Since goto conversion now dispatches on a variable
that the translation of the statement sets, goto-instrument --dump-c
produced, for asm goto("nop" : : : : out),

  unsigned int tmp_asm_goto_target;
  asm("nop" :  :  : );
  if(!(tmp_asm_goto_target == 1u))

so the dumped program lost the jumps of the statement and branched on a
variable that nothing assigns: compiled natively it reads an
indeterminate value, and compiled with goto-cc again the modeled "nop"
statement, which does not jump, may jump.

expr2c now prints "asm goto(...)" with the labels as the fifth list, and
still does not print the variable, which is internal to CBMC. In C the
statement jumps to the label directly, so dump-c also assigns 0 ("no
jump") to the variable before the statement, and the dispatch that
follows is only reached when the statement falls through.

The test goto-instrument/dump-asm-goto compiles the output of --dump-c
again and checks that a modeled asm goto still does not jump and that an
approximated one may still jump or fall through. It uses gcc-only syntax,
so the goto-instrument suite now excludes gcc-only tests on Windows, as
the cbmc suite does.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
convert_asm had grown to about 80 lines: it cleans side effects in the
operands, emits the OTHER instruction, and builds the dispatch on the
variable that selects the label an asm goto jumps to. Move the dispatch
into convert_asm_goto_dispatch, whose documentation states the
convention that the translation of the statement (remove_asm) relies on:
the variable holds the 1-based index of the label the statement jumps
to, or 0 if it does not jump.

No change in behaviour: goto-instrument --show-goto-functions and cbmc
--show-goto-functions print the same programs as before for the asm goto
regression tests and for an asm goto with two __label__ local labels.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant