<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div><br>RFC-0x0000<br><br>For clang release mode compiles: <br><br>Should (automatic) local variables be initialized to 0 for the programmer?<br><br>---------------------------------------------------------------------------<br><br>Consider:<br><br> main()<br> {<br> int a;<br><br> printf("a: %d\n",a);<br> }<br><br>Run:<br> ./a.out<br><br> a: XXX<br> <br><br>----------------------------------------------------------------------------<br><br>What is XXX? <br><br> 0? <br><br> or garbage?<br><br>----------------------------------------------------------------------------<br><br>I
was fiddling about with clang and gcc one night and found that gcc release mode ALWAYS initializes local variables to zero (evidently diverging from standards documents).<br><br>For <br><br> gcc debug,<br> clang release,<br> clang release for bitcode and run through lli,<br> clang debug,<br> clang debug for bitcode and run through lli,<br><br>local variables are NOT initialized to 0.<br><br>(Caveat #0: this is not a question about standards such as C99... this is about runtime compatibility with the existing code base which was developed using gcc and the reasonable expectations that software has when compiled with clang...)<br><br>(Caveat #1: this assumes x86 32 bit code generation.... I have not tested x64 or other target cpus)<br><br>(Caveat #2: both STATIC globals and STATIC local variables ARE SET TO 0 AUTOMATICALLY BY ALL compilers and build
types)<br><br><br><br>Why this is so for gcc release mode, I offer the following hypothesis:<br><br> A) There is a lot of crappy code out there...<br> B) The crappy code is in a lot of useful and ubiquitous tools (see GNU/linux et al)<br> C) These tools are always compiled in release mode for packaging in larger distributions (see ubuntu, redhat, etc..)<br> D) The compiler used is gcc....<br> E) The crappy code assumes locals are 0 and runs happily in hundreds of scripts and commands on your very own computer.<br><br><br>Why this interests the clang/llvm community, I offer the following:<br><br> A) It would be nice to drop in clang instead of gcc (duh)<br> B) No one wants to fix a bunch of crappy code (even with the great static analysis we get from clang) (duh huh)<br> C) the insidiousness of the test results
for release mode binaries as described further below.... (it's a good one)<br><br><br>IMHO... For debug mode, you obviously want the behaviour of not setting locals to 0 because it does help to find cheesy code and there is clang static analysis anyway....<br><br><br>So here is my Request For Comment Question:<br><br> Q: Should clang release mode emulate gcc behaviour and set (automatic) local variables to 0 if not explicitly initialized by the programmer? <br><br><br>Before answering!!!! Please consider the insidious bug I detail below which shows how the reasonable expectation of many existing programs could be broken....<br><br><br>I hope this stirs up some interesting conversation...<br><br>(and part of me hopes I am somehow being incredibly stupid and that the bugs I detail below are somehow a figment of my imagination...<br>if that proves to be the case, less than polite comments on my programming ability are
invited)<br><br><br>Sincerely,<br><br>Daniel Chapiesky<br><br>------------------------------------------------------------------------------<br>------------------------------------------------------------------------------<br><br>I wrote the attached testkit: local_var_test<br><br>It is a simple C program and shell script.<br><br>The script compiles the program using gcc and clang in the various modes, runs thems, and stores the results.<br><br>I have included the results from my own system in ./my_results_on_ubuntu_x86<br><br>It will create a ./bin and ./results directory and run each version of the program leaving the results for you to check out.<br><br>The test checks:<br><br> the stack from invocation of main()<br> the stack of a function called with no arguments: test_function_A()<br> the stack of a function called with arguments: test_function_B()<br> the stack as A() and B()
are interleaved with each other in a loop.<br><br> for the hell of it I threw in C() also, which tests initialization of statics.<br><br><br>For my test runs, the reference compilers were:<br><br> clang version 1.1 (branches/release_27 1089) [The 2.7 tarball as reference)<br> Target: i386-pc-linux-gnu<br> Thread model: posix<br><br> gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) [The gcc from Ubuntu as reference - NOT the llvm-gcc]<br> Target: i486-linux-gnu<br> Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu<br> Thread model: posix<br><br><br>llvm-gcc was not used (as I do not...)<br><br><br>The basic code fragment used for testing was:<br><br> static int result = 0; // 0 - success , 1 - failure (bash exit status rules)<br><br> void test_function_A()<br> {<br> unsigned long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;<br><br> unsigned long AA,BB,CC,DD;<br><br> AA = 0x01;<br> BB = 0xFF01;<br>
CC = 0x01AA01;<br> DD = 0xFF01AA01;<br><br> printf("test_function_A() - 26 local ints - all should be 0\n");<br> printf("\ta: %lu\tb: %lu\tc: %lu\td: %lu\te: %lu\n",a,b,c,d,e);<br> printf("\tf: %lu\tg: %lu\th: %lu\ti: %lu\tj: %lu\n",f,g,h,i,j);<br> printf("\tk: %lu\tl: %lu\tm: %lu\tn: %lu\to: %lu\n",k,l,m,n,o);<br> printf("\tp: %lu\tq: %lu\tr: %lu\ts: %lu\tt: %lu\n",p,q,r,s,t);<br> printf("\tu: %lu\tv: %lu\tw: %lu\tx: %lu\ty: %lu\n",u,v,w,x,y);<br> printf("\tz: %lu\n\n",z);<br><br> if (a || b || c || d || e || f || g || h || i || j || k || l || m || n || o || p || q || r || s || t || u || v || w || x || z)
{<br> printf("******* local variable was not zero! ****************\n");<br> result = 1; // 0 - success , 1 - failure (bash exit status rules)<br> }<br><br> printf("\tLocal assigned variables:\n");<br> printf("\t\tAA: %0lX should be 0x01\n",AA);<br> printf("\t\tBB: %0lX should be 0xff01\n",BB);<br> printf("\t\tCC: %0lX should be 0x01aa01\n",CC);<br> printf("\t\tDD: %0lX should be 0xff01aa01\n",DD);<br><br> if ((AA != 0x01) || (BB !=0xFF01) || (CC != 0x01AA01) || (DD != 0xFF01AA01)) {<br> printf("******* assigned variable was not
assigned value! ****************\n");<br> result = 1; // 0 - success , 1 - failure (bash exit status rules)<br> }<br><br> }<br><br><br>A summary of the results (as taken directly from output files) were:<br><br> GCC Release<br><br> main() - 26 local ints - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br>
p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> GCC Debug<br><br> main() - 26 local ints - all should be 0<br> a: 3086260336 b: 134516041 c: 3215293832 d: 134524916 e: 3086053364<br> f: 134513384 g: 3215293800 h: 134524916 i: 3085799897 j: 3085070158<br> k: 3215295786 l:
0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 3086204928 x: 0 y: 0<br> z: 0<br><br> ******* local variable was not zero! ****************<br><br> Clang Release<br><br> main() - 26 local ints - all should be 0<br> a: 41 b: 41 c: 41 d: 41 e: 41<br> f: 31 g: 31 h:
31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br> ******* local variable was not zero! ****************<br><br> Clang Debug<br><br> main() - 26 local ints - all should be 0<br> a: 134516425 b: 3214154872 c:
134524916 d: 3087020020 e: 134513348<br> f: 3214154840 g: 134524916 h: 3086766553 i: 3086036814 j: 3214161198<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 3087171584 w: 0 x: 0 y: 0<br> z: 0<br><br> ******* local variable was not zero!
****************<br><br>------------------------------------------------------------------------------------------------<br><br><br> ************************************************************************************************<br> ************************* INSIDIOUS BUG ALERT !!! **********************************************<br> ************************* INSIDIOUS BUG ALERT !!! **********************************************<br> ************************* INSIDIOUS BUG ALERT !!! (at least I think it is....) *****************<br> ************************************************************************************************<br><br><br>Here are the results from the compile and run shell script:<br><br> ./bin does not exist... making it...woooo<br> ./results does not exist... making it...woooo<br><br> Compiling
test with GNU gcc (debug mode)<br> Compiling test with GNU gcc (release mode)<br> Compiling test with clang (debug mode for native)<br> Compiling test with clang (release mode for native)<br> Compiling test with clang (debug BC mode for lli)<br> Compiling test with clang (release BC mode for lli)<br><br> *** gcc debug does not init locals to 0<br><br> !!! gcc release does init locals to 0<br><br> *** clang debug does not init locals to 0<br><br> !!! clang release does init locals to 0<br><br> *** clang debug BC does not init locals to 0<br><br> !!! clang release BC does init locals to 0<br><br><br>The shell script is reporting THAT CLANG RELEASE MODE DOES INIT LOCALS TO 0!!!!????!!!????????? ? ? ?<br><br><br><br>In
release mode, the code fragment:<br><br> printf("\tz: %lu\n\n",z);<br><br> if (a || b || c || d || e || f || g || h || i || j || k || l || m || n || o || p || q || r || s || t || u || v || w || x || z) {<br> printf("******* local variable was not zero! ****************\n");<br> }<br><br> printf("\tLocal assigned variables:\n");<br><br><br>becomes<br><br> printf("\tz: %lu\n\n",z);<br><br> // removed - if (a || b || c || d || e || f || g || h || i || j || k || l || m || n || o || p || q || r || s || t || u || v || w || x || z) {<br> // removed - printf("******* local variable was not zero!
****************\n");<br> // removed - result = 1; // 0 - success , 1 - failure (bash exit status rules)<br> // removed - }<br><br> printf("\tLocal assigned variables:\n");<br><br><br>because the compiler assumes all variables are 0 and can evaluate the the above statement away.... <br>the variable "result" never gets set to 1 and the shell script never gets to say that things went wrong....<br><br><br>Insidious Bug Part 1: ******************************************************************************************<br>Unfortunately, even though the compiler assumes all variables are 0.... they are, in fact, not guaranteed to be:<br>****************************************************************************************************************<br><br><br>Clang Release<br><br> main() - 26 local
ints - all should be 0<br> a: 41 b: 41 c: 41 d: 41 e: 41<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z:
31<br><br><br>---------------------------------------------------------------------------------------------------------------------------<br><br><br>I realized I wanted a little better output for the shell script, so I modified it to send some<br>messages to stderr. You now get...<br><br><br> ./bin does not exist... making it...woooo<br> ./results does not exist... making it...woooo<br><br> Compiling test with GNU gcc (debug mode)<br> Compiling test with GNU gcc (release mode)<br> Compiling test with clang (debug mode for native)<br> Compiling test with clang (release mode for native)<br> Compiling test with clang (debug BC mode for lli)<br> Compiling test with clang (release BC mode for lli)<br><br> ./bin/local_var_test_gnu_gcc_debug [3086 garbage 51316836134519012] should be
[00000000000000000000000000]<br> *** gcc debug does not init locals to 0<br><br> ./bin/local_var_test_gnu_gcc_release [00000000000000000000000000] should be [00000000000000000000000000]<br> !!! gcc release does init locals to 0<br><br> ./bin/local_var_test_clang_debug [30870 garbage 70855683085656992] should be [00000000000000000000000000]<br> *** clang debug does not init locals to 0<br><br> ./bin/local_var_test_clang_release [3086079 garbage 3086079328] should be [00000000000000000000000000]<br> !!! clang release does init locals to 0<br><br> ./bin/local_var_test_clang_debug_BC [03084344160 garbage 12883872] should be [00000000000000000000000000]<br> *** clang debug BC does not init locals to 0<br><br> ./bin/local_var_test_clang_release_BC [3086 garbage 403086067040] should
be [00000000000000000000000000]<br> !!! clang release BC does init locals to 0<br><br><br>Insidious Bug Part 2: *********************************************************************************************<br>Note that gcc release does output the block of 0's and the others fool the shell script with clever optimizations.<br>*******************************************************************************************************************<br><br><br><br>-----------------------------------------------------------------------------<br><br>The complete gcc release run results were:<br><br><br> ./bin/local_var_test_gnu_gcc_release<br><br> main() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g:
0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be
0xff01aa01<br><br><br> == test A ========================<br> test_function_A() call # 1<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z:
0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br> test_function_A() call # 0<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n:
0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br><br><br> == test B ========================<br> test_function_B(32,64,128,256,512) call # 1<br><br> test_function_B() - 26 local unsigned
longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br>
BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br> arg_b 64 should be 64<br> arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br> test_function_B(32,64,128,256,512) call # 0<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c:
0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be
0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br> arg_b 64 should be 64<br> arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br><br><br> == test A + B ========================<br><br> interleaved test_function_A() call # 3<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br>
f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD:
FF01AA01 should be 0xff01aa01<br><br><br> interleaved test_function_B(32,64,128,256,512) call # 3<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br>
Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br> arg_b 64 should be 64<br> arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br><br> interleaved test_function_A() call # 2<br><br>
test_function_A() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be
0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br><br> interleaved test_function_B(32,64,128,256,512) call # 2<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r:
0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br> arg_b 64 should be 64<br> arg_c 128 should be
128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br><br> interleaved test_function_A() call # 1<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0
w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br><br> interleaved test_function_B(32,64,128,256,512) call # 1<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j:
0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br>
arg_a 32 should be 32<br> arg_b 64 should be 64<br> arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br><br> interleaved test_function_A() call # 0<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o:
0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br><br> interleaved test_function_B(32,64,128,256,512) call # 0<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a:
0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br>
CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br> arg_b 64 should be 64<br> arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br><br><br><br><br><br> == test C (statics) ========================<br> test_function_C() - 26 static unsigned longs - all should be 0<br> s_a: 0 s_b: 0 s_c: 0 s_d: 0 s_e:
0<br> s_f: 0 s_g: 0 s_h: 0 s_i: 0 s_j: 0<br> s_k: 0 s_l: 0 s_m: 0 s_n: 0 s_o: 0<br> s_p: 0 s_q: 0 s_r: 0 s_s: 0 s_t: 0<br> s_u: 0 s_v: 0 s_w: 0 s_x: 0 s_y: 0<br> s_z: 0<br><br><br> local static unsigned longs - all should be 0:<br> local_s_a: 0 should be 0<br> local_s_b: 0 should be 0<br>
local_s_c: 0 should be 0<br> local_s_d: 0 should be 0<br><br> static assigned variables:<br> s_AA: 1 should be 0x01<br> s_BB: FF01 should be 0xff01<br> s_CC: 1AA01 should be 0x01aa01<br> s_DD: FF01AA01 should be 0xff01aa01<br><br><br><br><br><br><br> == test D (structures) ========================<br> test_function_D() - 26 local unsigned longs in a structure - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h:
0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be
0xff01aa01<br><br><br><br><br><br><br> == test E (should always succeed) ========================<br> test_function_E() - 26 local unsigned longs - explicitly set to 0 - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g: 0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z:
0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br><br><br>-----------------------------------------------------------------------------<br><br><br>The complete clang release run results were:<br><br>NOTE that the message "******* local variable was not zero! ****************" does not appear in the<br>output because that printf was optimized away into the ether....<br><br><br> ./bin/local_var_test_clang_release<br><br> main() - 26 local unsigned longs - all should be 0<br> a: 51 b:
51 c: 51 d: 51 e: 51<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br>
CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br><br> == test A ========================<br> test_function_A() call # 1<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br>
u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br> test_function_A() call # 0<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g: 31 h:
31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be
0xff01aa01<br><br><br><br> == test B ========================<br> test_function_B(32,64,128,256,512) call # 1<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y:
31<br> z: 31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br> arg_b 64 should be 64<br> arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be
512<br><br> test_function_B(32,64,128,256,512) call # 0<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br>
Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br> arg_b 64 should be 64<br> arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br><br><br> == test A + B
========================<br><br> interleaved test_function_A() call # 3<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br>
Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br><br> interleaved test_function_B(32,64,128,256,512) call # 3<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31
n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br>
arg_b 64 should be 64<br> arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br><br> interleaved test_function_A() call # 2<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31
r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br><br> interleaved test_function_B(32,64,128,256,512) call # 2<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d:
62 e: 62<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be
0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br> arg_b 64 should be 64<br> arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br><br> interleaved test_function_A() call # 1<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g:
31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be
0xff01aa01<br><br><br> interleaved test_function_B(32,64,128,256,512) call # 1<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z:
31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br> arg_b 64 should be 64<br> arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br><br> interleaved test_function_A() call #
0<br><br> test_function_A() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br> Local assigned variables:<br>
AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br><br> interleaved test_function_B(32,64,128,256,512) call # 0<br><br> test_function_B() - 26 local unsigned longs - all should be 0<br> a: 62 b: 62 c: 62 d: 62 e: 62<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p:
31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v: 31 w: 31 x: 31 y: 31<br> z: 31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br> Argument variables:<br> arg_a 32 should be 32<br> arg_b 64 should be 64<br>
arg_c 128 should be 128<br> arg_d 256 should be 256<br> arg_e 512 should be 512<br><br><br><br><br><br><br> == test C (statics) ========================<br> test_function_C() - 26 static unsigned longs - all should be 0<br> s_a: 0 s_b: 0 s_c: 0 s_d: 0 s_e: 0<br> s_f: 0 s_g: 0 s_h: 0 s_i: 0 s_j: 0<br> s_k: 0 s_l: 0 s_m: 0 s_n: 0 s_o: 0<br> s_p: 0 s_q: 0 s_r: 0
s_s: 0 s_t: 0<br> s_u: 0 s_v: 0 s_w: 0 s_x: 0 s_y: 0<br> s_z: 0<br><br><br> local static unsigned longs - all should be 0:<br> local_s_a: 0 should be 0<br> local_s_b: 0 should be 0<br> local_s_c: 0 should be 0<br> local_s_d: 0 should be 0<br><br> static assigned variables:<br> s_AA: 1 should be 0x01<br> s_BB: FF01 should be 0xff01<br>
s_CC: 1AA01 should be 0x01aa01<br> s_DD: FF01AA01 should be 0xff01aa01<br><br><br><br><br><br><br> == test D (structures) ========================<br> test_function_D() - 26 local unsigned longs in a structure - all should be 0<br> a: 77 b: 77 c: 77 d: 77 e: 77<br> f: 31 g: 31 h: 31 i: 31 j: 31<br> k: 31 l: 31 m: 31 n: 31 o: 31<br> p: 31 q: 31 r: 31 s: 31 t: 31<br> u: 31 v:
31 w: 31 x: 31 y: 31<br> z: 31<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be 0xff01aa01<br><br><br><br><br><br><br> == test E (should always succeed) ========================<br> test_function_E() - 26 local unsigned longs - explicitly set to 0 - all should be 0<br> a: 0 b: 0 c: 0 d: 0 e: 0<br> f: 0 g:
0 h: 0 i: 0 j: 0<br> k: 0 l: 0 m: 0 n: 0 o: 0<br> p: 0 q: 0 r: 0 s: 0 t: 0<br> u: 0 v: 0 w: 0 x: 0 y: 0<br> z: 0<br><br> Local assigned variables:<br> AA: 1 should be 0x01<br> BB: FF01 should be 0xff01<br> CC: 1AA01 should be 0x01aa01<br> DD: FF01AA01 should be
0xff01aa01<br><br><br><br>------------------------------------------------------------------------------<br><br>Pure conjecture: I was thinking about those guys who compiled netBSD with clang.... Did they experience any problems with<br> tools being buggy? Or did they use llvm-gcc which I assume does do the init to 0 for locals???<br><br>------------------------------------------------------------------------------<br><br><br><br><br><br><br><br><br><br><br></div>
</div><br>
</body></html>