[cfe-commits] r118641 - /cfe/trunk/www/compatibility.html

Daniel Dunbar daniel at zuster.org
Tue Nov 9 14:45:16 PST 2010


Author: ddunbar
Date: Tue Nov  9 16:45:16 2010
New Revision: 118641

URL: http://llvm.org/viewvc/llvm-project?rev=118641&view=rev
Log:
Add a compat note about how Clang doesn't zero-initialize __block local variables.

Modified:
    cfe/trunk/www/compatibility.html

Modified: cfe/trunk/www/compatibility.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/compatibility.html?rev=118641&r1=118640&r2=118641&view=diff
==============================================================================
--- cfe/trunk/www/compatibility.html (original)
+++ cfe/trunk/www/compatibility.html Tue Nov  9 16:45:16 2010
@@ -35,6 +35,7 @@
       <li><a href="#vector_builtins">"missing" vector __builtin functions</a></li>
       <li><a href="#lvalue-cast">Lvalue casts</a></li>
       <li><a href="#blocks-in-protected-scope">Jumps to within <tt>__block</tt> variable scope</a></li>
+      <li><a href="#block-variable-initialization">Non-initialization of <tt>__block</tt> variables</a></li>
     </ul>
   </li>
   <li><a href="#objective-c">Objective-C compatibility</a>
@@ -223,6 +224,29 @@
 where they are used.</p>
 
 <!-- ======================================================================= -->
+<h3 id="block-variable-initialization">Non-initialization of <tt>__block</tt>
+variables</h3>
+<!-- ======================================================================= -->
+
+<p>In the following example code, the <tt>x</tt> variable is used before it is
+defined:</p>
+<pre>
+int f0() {
+  __block int x;
+  return ^(){ return x; }();
+}
+</pre>
+
+<p>By an accident of implementation, GCC and llvm-gcc unintentionally always
+zero initialized <tt>__block</tt> variables. However, any program which depends
+on this behavior is relying on unspecified compiler behavior. Programs must
+explicitly initialize all local block variables before they are used, as with
+other local variables.</p>
+
+<p>Clang does not zero initialize local block variables, and programs which rely
+on such behavior will most likely break when built with Clang.</p>
+
+<!-- ======================================================================= -->
 <h2 id="objective-c">Objective-C compatibility</h3>
 <!-- ======================================================================= -->
 





More information about the cfe-commits mailing list