r178735 - Fix linkage related crash.

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Apr 3 19:52:13 PDT 2013


Thanks to Richard Smith for the testcase.

On 3 April 2013 22:47, Rafael Espindola <rafael.espindola at gmail.com> wrote:
> Author: rafael
> Date: Wed Apr  3 21:47:57 2013
> New Revision: 178735
>
> URL: http://llvm.org/viewvc/llvm-project?rev=178735&view=rev
> Log:
> Fix linkage related crash.
>
> This test was exactly the opposite of what it should be. We should check if
> there old decl has linkage (where it makes sense) and if the new decl has
> the extern keyword.
>
> Modified:
>     cfe/trunk/lib/Sema/SemaDecl.cpp
>     cfe/trunk/test/SemaCXX/linkage2.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=178735&r1=178734&r2=178735&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Apr  3 21:47:57 2013
> @@ -2929,8 +2929,8 @@ void Sema::MergeVarDecl(VarDecl *New, Lo
>      Diag(Old->getLocation(), diag::note_previous_definition);
>      return New->setInvalidDecl();
>    }
> -  if (Old->hasExternalStorage() &&
> -      New->isLocalVarDecl() && !New->hasLinkage()) {
> +  if (Old->hasLinkage() && New->isLocalVarDecl() &&
> +      !New->hasExternalStorage()) {
>      Diag(New->getLocation(), diag::err_non_extern_extern) << New->getDeclName();
>      Diag(Old->getLocation(), diag::note_previous_definition);
>      return New->setInvalidDecl();
>
> Modified: cfe/trunk/test/SemaCXX/linkage2.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/linkage2.cpp?rev=178735&r1=178734&r2=178735&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/linkage2.cpp (original)
> +++ cfe/trunk/test/SemaCXX/linkage2.cpp Wed Apr  3 21:47:57 2013
> @@ -126,3 +126,11 @@ extern "C" {
>      void  __attribute__((overloadable)) test11_g(double);
>    }
>  }
> +
> +namespace test12 {
> +  const int n = 0;
> +  extern const int n;
> +  void f() {
> +    extern const int n;
> +  }
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list