ualberta-smr/varclang

Seg fault when #if or #ifdef block skipped

mayshukla opened this issue · 2 comments

For example:

void foo() {
#ifdef A
  int i;
#else
  int i;
#if B
  int j;
#endif
#endif
}

Causes a seg fault.

Note that if the inner #if is evaluated true (e.g. #if B is changed to #if B==0 or #if !defined(B)) then there is no seg fault.

I think the reason for this bug is that an entry is pushed to the Preprocessor VariabilityStack every time an #if or #ifdef directive is encountered. However, when the body of an #if is skipped, the #endif is never encountered, so that entry is never popped from the stack.

Update: this bug also appears with skipping the body of an #ifdef.

For example, if you create a config file named config with the following contents:

A

Then run it on the following test program:

void foo() {
#ifdef A
  int i;
#else
  int i;
#ifdef this_macro_name_is_not_in_the_config_file
  int j;
#endif
#endif
}

You also get a seg fault.

This is also due to an imbalance in the VariabilityStack.