Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • F frama-c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 168
    • Issues 168
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
    • Model experiments
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • pub
  • frama-c
  • Issues
  • #537

Error with casted ternary statements

ID0002131: This issue was created automatically from Mantis Issue 2131. Further discussion may take place here.


Id Project Category View Due Date Updated
ID0002131 Frama-C Kernel public 2015-06-04 2016-01-26
Reporter Ian Assigned To yakobowski Resolution fixed
Priority normal Severity minor Reproducibility always
Platform - OS Ubuntu OS Version -
Product Version Frama-C Sodium Target Version - Fixed in Version Frama-C Magnesium

Description :

The following is a simplified version from an situation where macros created a statement (which had side effects, unlike this example).

1 void main() { 2 int p=0, i=0, j=0; 3 // (char)( p ? i : j ); // [kernel] user error: cannot cast from void to char 4 ( p ? i : j ); 5 }

When line three is uncommented, frama-c fails with the error noted. Inspecting the normalized version reveals a potential problem (line 3 is commented out).

frama-c void_cast.c -then -print [kernel] Parsing FRAMAC_SHARE/libc/__fc_builtin_for_normalization.i (no preprocessing) [kernel] Parsing void_cast.c (with preprocessing) /* Generated by Frama-C */ void main(void) { int p; int i; int j; p = 0; i = 0; j = 0; if (p) { if (i) ; } else if (j) ; return; }

As seen above, line 4 is normalized to if (p) { if (i) ; } else if (j) ;

Which has two potential problems. First, it is unclear why ‘i' and ‘j’ are wrapped in conditionals. Second, this structure may result in the ‘if’ statement being casted, instead of ‘i' or ‘j’, ultimately producing the observed error.

Running just the gcc preprocessor on the initial source file does not cause these transformations.

gcc -E void_cast.c

1 "void_cast.c"

1 ""

1 ""

1 "void_cast.c"

void main() { int p=0, i=0, j=0; (char)( p ? i : j ); ( p ? i : j ); }

Interestingly, adding an assignment produces a reasonable transformation. The program:

void main() { int p=0, i=0, j=0; char c = (char)( p ? i : j ); }

Is normalized to:

void main(void) { int p; int i; int j; char c; int tmp; p = 0; i = 0; j = 0; if (p) tmp = i; else tmp = j; c = (char)tmp; return; }

Steps To Reproduce :

Create file void_cast.c: void main() { int p=0, i=0, j=0; (char)( p ? i : j ); }

Run frama-c:

frama-c void_cast.c [kernel] Parsing FRAMAC_SHARE/libc/__fc_builtin_for_normalization.i (no preprocessing) [kernel] Parsing void_cast.c (with preprocessing) void_cast.c:3:[kernel] user error: cannot cast from void to char [kernel] user error: stopping on file "void_cast.c" that has errors. Add '-kernel-msg-key pp' for preprocessing command. [kernel] Frama-C aborted: invalid user input.

But expected frama-c to succeed since the program is accepted by gcc.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking