<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <br>
    <div class="moz-forward-container"><br>
      <br>
      -------- Original Message --------
      <table class="moz-email-headers-table" cellpadding="0"
        cellspacing="0" border="0">
        <tbody>
          <tr>
            <th nowrap="nowrap" valign="BASELINE" align="RIGHT">Subject:
            </th>
            <td>Re: r170406 - in /cfe/trunk: lib/AST/Decl.cpp
              lib/Sema/SemaDecl.cpp test/Index/linkage.c</td>
          </tr>
          <tr>
            <th nowrap="nowrap" valign="BASELINE" align="RIGHT">Date: </th>
            <td>Wed, 19 Dec 2012 16:22:18 -0800</td>
          </tr>
          <tr>
            <th nowrap="nowrap" valign="BASELINE" align="RIGHT">From: </th>
            <td>Reed Kotler <a class="moz-txt-link-rfc2396E" href="mailto:rkotler@mips.com"><rkotler@mips.com></a></td>
          </tr>
          <tr>
            <th nowrap="nowrap" valign="BASELINE" align="RIGHT">To: </th>
            <td>Rafael Espíndola <a class="moz-txt-link-rfc2396E" href="mailto:rafael.espindola@gmail.com"><rafael.espindola@gmail.com></a></td>
          </tr>
          <tr>
            <th nowrap="nowrap" valign="BASELINE" align="RIGHT">CC: </th>
            <td><a class="moz-txt-link-abbreviated" href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a>
              <a class="moz-txt-link-rfc2396E" href="mailto:llvm-commits@cs.uiuc.edu"><llvm-commits@cs.uiuc.edu></a></td>
          </tr>
        </tbody>
      </table>
      <br>
      <br>
      <pre>This patch causes the following conformance test to fail.
It prints out 0 == 99 instead of 99 = 99

static int i = 99;

extern int i;

static void foo() {
  extern int i;

  printf("%i = 99\n", i);
}

int main() {
  foo();
}

On 12/17/2012 08:18 PM, Rafael Espindola wrote:
> Author: rafael
> Date: Mon Dec 17 22:18:55 2012
> New Revision: 170406
>
> URL: <a class="moz-txt-link-freetext" href="http://llvm.org/viewvc/llvm-project?rev=170406&view=rev">http://llvm.org/viewvc/llvm-project?rev=170406&view=rev</a>
> Log:
> Merge storage classes even when contexts don't match.
>
> This fixes the storage class of extern decls that are merged with file level
> statics. The patch also fixes the linkage computation so that they are
> considered internal.
>
> Modified:
>      cfe/trunk/lib/AST/Decl.cpp
>      cfe/trunk/lib/Sema/SemaDecl.cpp
>      cfe/trunk/test/Index/linkage.c
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL: <a class="moz-txt-link-freetext" href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=170406&r1=170405&r2=170406&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=170406&r1=170405&r2=170406&view=diff</a>
> ==============================================================================
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Mon Dec 17 22:18:55 2012
> @@ -786,12 +786,16 @@
>       }
>
>       if (const VarDecl *Var = dyn_cast<VarDecl>(D))
> -      if (Var->getStorageClass() == SC_Extern ||
> -          Var->getStorageClass() == SC_PrivateExtern) {
> +      if (Var->getStorageClassAsWritten() == SC_Extern ||
> +          Var->getStorageClassAsWritten() == SC_PrivateExtern) {
>           if (Var->isInAnonymousNamespace() &&
>               !Var->getDeclContext()->isExternCContext())
>             return LinkageInfo::uniqueExternal();
>
> +        // This is an "extern int foo;" which got merged with a file static.
> +        if (Var->getStorageClass() == SC_Static)
> +          return LinkageInfo::internal();
> +
>           LinkageInfo LV;
>           if (Var->getStorageClass() == SC_PrivateExtern)
>             LV.mergeVisibility(HiddenVisibility, true);
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: <a class="moz-txt-link-freetext" href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=170406&r1=170405&r2=170406&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=170406&r1=170405&r2=170406&view=diff</a>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Dec 17 22:18:55 2012
> @@ -2616,8 +2616,7 @@
>     // specified at the prior declaration.
>     // FIXME. revisit this code.
>     if (New->hasExternalStorage() &&
> -      Old->getLinkage() == InternalLinkage &&
> -      New->getDeclContext() == Old->getDeclContext())
> +      Old->getLinkage() == InternalLinkage)
>       New->setStorageClass(Old->getStorageClass());
>
>     // Merge "used" flag.
>
> Modified: cfe/trunk/test/Index/linkage.c
> URL: <a class="moz-txt-link-freetext" href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/linkage.c?rev=170406&r1=170405&r2=170406&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/linkage.c?rev=170406&r1=170405&r2=170406&view=diff</a>
> ==============================================================================
> --- cfe/trunk/test/Index/linkage.c (original)
> +++ cfe/trunk/test/Index/linkage.c Mon Dec 17 22:18:55 2012
> @@ -13,6 +13,12 @@
>
>   void ena(int (*dio)(int tria));
>
> +static int test2;
> +void f16(void) {
> +  extern int test2;
> +}
> +
> +
>   // CHECK: EnumDecl=Baz:3:6 (Definition)linkage=External
>   // CHECK: EnumConstantDecl=Qux:3:12 (Definition)linkage=External
>   // CHECK: VarDecl=x:4:5linkage=External
> @@ -28,3 +34,5 @@
>   // CHECK: FunctionDecl=ena:14:6linkage=External
>   // CHECK: ParmDecl=dio:14:16 (Definition)linkage=NoLinkage
>   // CHECK: ParmDecl=tria:14:25 (Definition)linkage=NoLinkage
> +// CHECK: VarDecl=test2{{.*}}linkage=Internal
> +// CHECK: VarDecl=test2{{.*}}linkage=Internal
>

</pre>
      <br>
      <br>
    </div>
    <br>
  </body>
</html>