[cfe-commits] Fwd: Re: r170406 - in /cfe/trunk: lib/AST/Decl.cpp lib/Sema/SemaDecl.cpp test/Index/linkage.c
reed kotler
rkotler at mips.com
Wed Dec 19 17:22:06 PST 2012
-------- Original Message --------
Subject: Re: r170406 - in /cfe/trunk: lib/AST/Decl.cpp
lib/Sema/SemaDecl.cpp test/Index/linkage.c
Date: Wed, 19 Dec 2012 16:22:18 -0800
From: Reed Kotler <rkotler at mips.com>
To: Rafael EspĂndola <rafael.espindola at gmail.com>
CC: llvm-commits at cs.uiuc.edu <llvm-commits at cs.uiuc.edu>
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: http://llvm.org/viewvc/llvm-project?rev=170406&view=rev
> 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: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=170406&r1=170405&r2=170406&view=diff
> ==============================================================================
> --- 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: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=170406&r1=170405&r2=170406&view=diff
> ==============================================================================
> --- 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: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/linkage.c?rev=170406&r1=170405&r2=170406&view=diff
> ==============================================================================
> --- 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121219/876b0f41/attachment.html>
More information about the cfe-commits
mailing list