c - Why is clang optimizing out my array even when using -O0 flag? -


i trying debug following c program using gdb:

// program generate user specified number of  // fibonacci numbers using variable length arrays // chapter 7  program 8   2013-07-14  #include <stdio.h>  int main(void) {     int i, numfibs;     printf("how many fibonacci numbers want (between 1 , 75)?\n");     scanf("%i", &numfibs);      if (numfibs < 1 || numfibs > 75)     {         printf("between 1 , 75 remember?\n");         return 1;     }      unsigned long long int fibonacci[numfibs];      fibonacci[0] = 0;  // definition     fibonacci[1] = 1;  // definition      for(i = 2; < numfibs; i++)         fibonacci[i] = fibonacci[i-2] + fibonacci[i-1];      for(i = 0; < numfibs; i++)         printf("%llu ", fibonacci[i]);      printf("\n");      return 0; } 

the issue having when trying compile code using: clang -ggdb3 -o0 -wall -werror 7_8_fibonaccivarlengtharrays.c

when try run gdb on a.out file created , stepping through program execution. anytime after fibonacci[] array decalared , type: info locals result says fibonacci <value optimized out> (until after first iteration of loop) results in fibonacci holding address 0xbffff128 rest of program (but dereferencing address not appear contain meaningful data).

i confused why clang appears optimizing out array when -o0 flag used?

i can use gcc compile code , value displays expected when using gdb.... thoughts?

thank you.

you don't mention version of clang using. tried both 3.2 , recent svn install (3.4).

the code generated 2 versions looks pretty similar me, debugging information different. clang 3.2 (which comes default ubuntu 13.04 install) produces error when try examine fibonacci in gdb:

fibonacci = <error reading variable fibonacci (dwarf-2 expression error: dw_op_reg operations must used either alone or in conjunction dw_op_piece or dw_op_bit_piece.)> 

in code compiled clang 3.4, works fine. in neither case array "optimized out"; it's allocated on stack.

so suspect oddity you're seeing has more emission of debugging information actual code.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -