[cfe-commits] r154956 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/CodeGenCXX/cxx11-exception-spec.cpp test/SemaTemplate/instantiate-exception-spec-cxx11.cpp

Douglas Gregor dgregor at apple.com
Tue Apr 17 16:02:46 PDT 2012


Approved.

Thanks, Richard.

Bill, you'll be handling the merge?

	- Doug

On Apr 17, 2012, at 3:35 PM, Richard Smith <richard at metafoo.co.uk> wrote:

> Hi Doug,
> 
> This change fixes a crash when building libc++ (introduced by the fix for libstdc++-4.7), so I'd like to request that it's ported to the 3.1 branch.
> 
> On Tue, Apr 17, 2012 at 3:30 PM, Richard Smith <richard-llvm at metafoo.co.uk> wrote:
> Author: rsmith
> Date: Tue Apr 17 17:30:01 2012
> New Revision: 154956
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=154956&view=rev
> Log:
> PR12569: Instantiate exception specifications of explicit instantiations
> and explicit specializations of function templates appropriately.
> 
> Modified:
>    cfe/trunk/lib/Sema/SemaDecl.cpp
>    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>    cfe/trunk/test/CodeGenCXX/cxx11-exception-spec.cpp
>    cfe/trunk/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
> 
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=154956&r1=154955&r2=154956&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Apr 17 17:30:01 2012
> @@ -7185,8 +7185,7 @@
>   }
>  }
> 
> -Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope,
> -                                         Declarator &D) {
> +Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
>   assert(getCurFunctionDecl() == 0 && "Function parsing confused");
>   assert(D.isFunctionDeclarator() && "Not a function declarator!");
>   Scope *ParentScope = FnBodyScope->getParent();
> @@ -7359,6 +7358,10 @@
>     }
>   }
> 
> +  // Ensure that the function's exception specification is instantiated.
> +  if (const FunctionProtoType *FPT = FD->getType()->getAs<FunctionProtoType>())
> +    ResolveExceptionSpec(D->getLocation(), FPT);
> +
>   // Checking attributes of current function definition
>   // dllimport attribute.
>   DLLImportAttr *DA = FD->getAttr<DLLImportAttr>();
> 
> Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=154956&r1=154955&r2=154956&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Apr 17 17:30:01 2012
> @@ -2377,7 +2377,16 @@
> 
>  void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
>                                     FunctionDecl *Decl) {
> -  FunctionDecl *Tmpl = Decl->getTemplateInstantiationPattern();
> +  // Find the template declaration which contains the exception specification.
> +  // Per [except.spec]p4, prefer the exception spec on the primary template
> +  // if this is an explicit instantiation.
> +  FunctionDecl *Tmpl = 0;
> +  if (Decl->getPrimaryTemplate())
> +    Tmpl = Decl->getPrimaryTemplate()->getTemplatedDecl();
> +  else if (FunctionDecl *MemTmpl = Decl->getInstantiatedFromMemberFunction())
> +    Tmpl = MemTmpl;
> +  else
> +    Tmpl = Decl->getTemplateInstantiationPattern();
>   assert(Tmpl && "can't instantiate non-template");
> 
>   if (Decl->getType()->castAs<FunctionProtoType>()->getExceptionSpecType()
> 
> Modified: cfe/trunk/test/CodeGenCXX/cxx11-exception-spec.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx11-exception-spec.cpp?rev=154956&r1=154955&r2=154956&view=diff
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/cxx11-exception-spec.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/cxx11-exception-spec.cpp Tue Apr 17 17:30:01 2012
> @@ -1,18 +1,66 @@
> -// RUN: %clang_cc1 -std=c++11 -verify -emit-llvm %s -o - | FileCheck %s
> +// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -verify -fexceptions -fcxx-exceptions -triple x86_64-linux-gnu | FileCheck %s
> 
> -template<typename T> void f() noexcept(sizeof(T) == 4);
> +void h();
> +
> +template<typename T> void f() noexcept(sizeof(T) == 4) { h(); }
> +
> +template<typename T> struct S {
> +  static void f() noexcept(sizeof(T) == 4) { h(); }
> +};
> +
> +// CHECK: define {{.*}} @_Z1fIsEvv() {
> +template<> void f<short>() { h(); }
> +// CHECK: define {{.*}} @_Z1fIA2_sEvv() nounwind {
> +template<> void f<short[2]>() noexcept { h(); }
> +
> +// CHECK: define {{.*}} @_ZN1SIsE1fEv()
> +// CHECK-NOT: nounwind
> +template<> void S<short>::f() { h(); }
> +// CHECK: define {{.*}} @_ZN1SIA2_sE1fEv() nounwind
> +template<> void S<short[2]>::f() noexcept { h(); }
> +
> +// CHECK: define {{.*}} @_Z1fIDsEvv() {
> +template void f<char16_t>();
> +// CHECK: define {{.*}} @_Z1fIA2_DsEvv() nounwind {
> +template void f<char16_t[2]>();
> +
> +// CHECK: define {{.*}} @_ZN1SIDsE1fEv()
> +// CHECK-NOT: nounwind
> +template void S<char16_t>::f();
> +// CHECK: define {{.*}} @_ZN1SIA2_DsE1fEv() nounwind
> +template void S<char16_t[2]>::f();
> 
>  void g() {
> -  // CHECK: declare void @_Z1fIiEvv() nounwind
> +  // CHECK: define {{.*}} @_Z1fIiEvv() nounwind {
>   f<int>();
> -  // CHECK: declare void @_Z1fIA2_iEvv()
> +  // CHECK: define {{.*}} @_Z1fIA2_iEvv() {
>   f<int[2]>();
> -  // CHECK: declare void @_Z1fIfEvv() nounwind
> +
> +  // CHECK: define {{.*}} @_ZN1SIiE1fEv() nounwind
> +  S<int>::f();
> +  // CHECK: define {{.*}} @_ZN1SIA2_iE1fEv()
> +  // CHECK-NOT: nounwind
> +  S<int[2]>::f();
> +
> +  // CHECK: define {{.*}} @_Z1fIfEvv() nounwind {
>   void (*f1)() = &f<float>;
> -  // CHECK: declare void @_Z1fIdEvv()
> +  // CHECK: define {{.*}} @_Z1fIdEvv() {
>   void (*f2)() = &f<double>;
> -  // CHECK: declare void @_Z1fIA4_cEvv() nounwind
> +
> +  // CHECK: define {{.*}} @_ZN1SIfE1fEv() nounwind
> +  void (*f3)() = &S<float>::f;
> +  // CHECK: define {{.*}} @_ZN1SIdE1fEv()
> +  // CHECK-NOT: nounwind
> +  void (*f4)() = &S<double>::f;
> +
> +  // CHECK: define {{.*}} @_Z1fIA4_cEvv() nounwind {
>   (void)&f<char[4]>;
> -  // CHECK: declare void @_Z1fIcEvv()
> +  // CHECK: define {{.*}} @_Z1fIcEvv() {
>   (void)&f<char>;
> +
> +  // CHECK: define {{.*}} @_ZN1SIA4_cE1fEv() nounwind
> +  (void)&S<char[4]>::f;
> +  // CHECK: define {{.*}} @_ZN1SIcE1fEv()
> +  // CHECK-NOT: nounwind
> +  (void)&S<char>::f;
>  }
> 
> Modified: cfe/trunk/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp?rev=154956&r1=154955&r2=154956&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp (original)
> +++ cfe/trunk/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp Tue Apr 17 17:30:01 2012
> @@ -105,3 +105,16 @@
> 
>   base<types> val = base<types>();
>  }
> +
> +namespace pr9485 {
> +  template <typename T> void f1(T) throw(typename T::exception); // expected-note {{candidate}}
> +  template <typename T> void f1(T, int = 0) throw(typename T::noitpecxe); // expected-note {{candidate}}
> +
> +  template <typename T> void f2(T) noexcept(T::throws); // expected-note {{candidate}}
> +  template <typename T> void f2(T, int = 0) noexcept(T::sworht); // expected-note {{candidate}}
> +
> +  void test() {
> +    f1(0); // expected-error {{ambiguous}}
> +    f2(0); // expected-error {{ambiguous}}
> +  }
> +}
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120417/6ae4c23c/attachment.html>


More information about the cfe-commits mailing list