diff --git a/clang/www/compatibility.html b/clang/www/compatibility.html index 4ad5bc018a1ac06ed50a19150dede04737dfca1a..8ac7d7de82c4520cc311abc9f8b741c78e8aae17 100644 --- a/clang/www/compatibility.html +++ b/clang/www/compatibility.html @@ -33,6 +33,7 @@
  • Objective-C compatibility @@ -134,6 +135,55 @@ example, one could use:

    addr = (float *)val; + +

    Jumps to within __block variable scope

    + + +

    Clang disallows jumps into the scope of a __block variable, similar +to the manner in which both GCC and Clang disallow jumps into the scope of +variables which have user defined constructors (in C++).

    + +

    Variables marked with __block require special runtime initialization +before they can be used. A jump into the scope of a __block variable +would bypass this initialization and therefore the variable cannot safely be +used.

    + +

    For example, consider the following code fragment:

    + +
    +int f0(int c) {
    +  if (c)
    +    goto error;
    +
    +  __block int x;
    +  x = 1;
    +  return x;
    +
    + error:
    +  x = 0;
    +  return x;
    +}
    +
    + +

    GCC accepts this code, but it will crash at runtime along the error path, +because the runtime setup for the storage backing the x variable will +not have been initialized. Clang rejects this code with a hard error:

    + +
    +t.c:3:5: error: goto into protected scope
    +    goto error;
    +    ^
    +t.c:5:15: note: jump bypasses setup of __block variable
    +  __block int x;
    +              ^
    +
    + +

    Some instances of this construct may be safe if the variable is never used +after the jump target, however the protected scope checker does not check the +uses of the varaible, only the scopes in which it is visible. You should rewrite +your code to put the __block variables in a scope which is only visible +where they are used.

    +

    Objective-C compatibility