Skip to content

Unexpected verification result about nested struct initialization #3653

Closed

Description

@muchang
#include <assert.h>

typedef int T[];

struct f { int w; T x; };

static struct f f = { 4, { 0, 1, 2, 3 } };

int main()
{
  int i;
  for (i = 0; i < f.w; ++i)
  {
     if (f.x[i] != i)
        { assert(0);} 
  }
 return 0; 
}

CBMC version: 5.10
Operating system: Ubuntu 18.04
Exact command line resulting in the issue: cbmc <file.c>
What behaviour did you expect: result in SUCCESS (proofed by compiling with gcc and executing)
What happened instead: [main.assertion.1] assertion 0: FAILURE

Activity

  1. added a commit that references this issue on Jan 6, 2019
  2. kroening commented on Jan 6, 2019

    @kroening
    Collaborator

    Many thanks; I've made a PR with a test for this as PR #3695.

  3. added a commit that references this issue on Jan 6, 2019
  4. tautschnig commented on Mar 8, 2021

    @tautschnig
    Collaborator

    What behaviour do we actually expect here? Looking at the C standard, this is explicitly called out as invalid (paragraph 21/Example 2 in "6.7.2.1 Structure and union specifiers" in C11). Is the desired bug fix for us to reject this during type checking?

  5. kroening commented on Mar 8, 2021

    @kroening
    Collaborator

    This might be a gcc/clang extension, but the documentation doesn't seem to be clear about that.

  6. tautschnig commented on Mar 8, 2021

    @tautschnig
    Collaborator

    It seems to work with GCC and MSVC, Clang rejects the program.

  7. SaswatPadhi commented on Aug 20, 2021

    @SaswatPadhi
    Contributor

    This appears to be a bug even with the latest (5.36) version.

  8. added a commit that references this issue on Feb 11, 2022
    a31b08c
  9. added a commit that references this issue on Feb 14, 2022
    da76ab4
  10. added 2 commits that reference this issue on Feb 26, 2022
    4965d64
    b16c7d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions