Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsoundness: const declared objects are writable #366

Open
docprofsky opened this issue Jul 30, 2023 · 0 comments
Open

Unsoundness: const declared objects are writable #366

docprofsky opened this issue Jul 30, 2023 · 0 comments

Comments

@docprofsky
Copy link

VeriFast produces unit-fraction heap chunks for const-qualified variables, allowing them to be written to. This is inconsistent with C11 §6.7.3 paragraph 6 and creates an unsoundness with both GCC and Clang.

Below is a demonstration of the problem and a link to Compiler Explorer showing the output of GCC and Clang.
https://godbolt.org/z/5j74EPMrG

#include <assert.h>

void char_set(char *a)
//@ requires character(a, _);
//@ ensures character(a, 'b');
{
  a[0] = 'b';
}

int main(void)
//@ requires true;
//@ ensures true;
{
  const char z = 0;
  char_set((char *)&z);
  assert(z == 'b');

  return 0;
}

Output of verification, compilation, and execution:

$ ~/verifast-21.04-152-g6ba67172/bin/verifast const2.c && gcc -std=c11 -O3 -Wall -Wextra -Wpedantic -Werror const2.c && ./a.out
const2.c
0 errors found (4 statements verified)
Linking...
Program linked successfully.
a.out: const2.c:16: main: Assertion `z == 'b'' failed.
Aborted (core dumped)
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

No branches or pull requests

1 participant