0

During frama-c kernel parsing, got "User Eror: invalid global intializer tmp". The source compile fine with gcc. It has something to do with frama-c using 'tmp' variable for conditional operator with memory location. Any idea on how to get around this error without changing the source code? The streamline version of the code is copy below.

If I hard code the conditional expression as in FILL_OK macro then it's okay. If I move lines 8-15 into main() then it's okay.

#define FILL_OK() {.a = 0 == 0 ? 0 : 1 }
#define FILL_NOK() {.a = 0 == flag ? 0 : 1 }

typedef struct {
     int a;
} a_st;

int flag = 0;

a_st buff_b[] =
{
    FILL_OK(),
    FILL_NOK(),
};

int main()
{
    return(0);
}

Copy of command line and error output:

frama-c -val main0.c

[kernel] Parsing main0.c (with preprocessing)
[kernel] main0.c:10: User Error: 
  invalid global initializer tmp

                             {/*()  <- flag
                              Calls:

                              */

                              if (0 == flag) 
                                tmp = 0;
                              else 
                                tmp = 1;}
[kernel] User Error: stopping on file "main0.c" that has errors. Add '-kernel-msg-key pp'
  for preprocessing command.
[kernel] Frama-C aborted: invalid user input.
ratt
  • 115
  • 5
  • 2
    Which version of `gcc` are you using? With mine (8.2.1), `FILL_NOK` is only accepted in case `flag` is made `const`. Otherwise, you get `error: initializer element is not constant`. That said, even with a `const` `flag`, the code is rejected by Frama-C, for the reasons given by @byako below – Virgile Dec 26 '18 at 17:22
  • @ratt I'm afraid the code you posted has an error, I am unable to compile it with any version of GCC or Clang that I have. If there is a specific version in which it works, or specific command-line options, please add them to the question. – anol Jan 08 '19 at 08:09

1 Answers1

1

There is currently no way to make this code accepted as is by Frama-C, as the "language" for expressions inside initializers requires each initializer to be a constant. The less invasive code modification that I can find would be to transform flag into a macro.

byako
  • 3,372
  • 2
  • 21
  • 36