d.zobnin.bugzilla created this revision.
d.zobnin.bugzilla added reviewers: doug.gregor, rjmccall.
d.zobnin.bugzilla added a subscriber: cfe-commits.

If new function is missing empty exception specification "throw()" and 
"throw()" came from system header, don't emit errors. It is already implemented 
in Clang, but taking into account only last redeclaration of a function. Look 
for declaration in system header up to the first declaration in redeclaration 
chain, as GCC seems to do.

This patch enables compilation of Facebook/ds2 application.

http://reviews.llvm.org/D18657

Files:
  lib/Sema/SemaExceptionSpec.cpp
  test/SemaCXX/Inputs/malloc.h
  test/SemaCXX/builtin-exception-spec.cpp

Index: lib/Sema/SemaExceptionSpec.cpp
===================================================================
--- lib/Sema/SemaExceptionSpec.cpp
+++ lib/Sema/SemaExceptionSpec.cpp
@@ -254,9 +254,15 @@
   // to many libc functions as an optimization. Unfortunately, that
   // optimization isn't permitted by the C++ standard, so we're forced
   // to work around it here.
-  if (MissingEmptyExceptionSpecification && NewProto &&
-      (Old->getLocation().isInvalid() ||
-       Context.getSourceManager().isInSystemHeader(Old->getLocation())) &&
+  bool IsFromSystemHeader = false;
+  for (const FunctionDecl *Prev = Old; Prev; Prev = Prev->getPreviousDecl())
+    if (Prev->getLocation().isInvalid() ||
+        Context.getSourceManager().isInSystemHeader(Prev->getLocation())) {
+      IsFromSystemHeader = true;
+      break;
+    }
+
+  if (MissingEmptyExceptionSpecification && NewProto && IsFromSystemHeader &&
       Old->isExternC()) {
     New->setType(Context.getFunctionType(
         NewProto->getReturnType(), NewProto->getParamTypes(),
Index: test/SemaCXX/builtin-exception-spec.cpp
===================================================================
--- test/SemaCXX/builtin-exception-spec.cpp
+++ test/SemaCXX/builtin-exception-spec.cpp
@@ -4,4 +4,7 @@
 
 extern "C" {
 void *malloc(__SIZE_TYPE__);
+
+void MyFunc() __attribute__((__weak__));
+void MyFunc() { return; }
 }
Index: test/SemaCXX/Inputs/malloc.h
===================================================================
--- test/SemaCXX/Inputs/malloc.h
+++ test/SemaCXX/Inputs/malloc.h
@@ -1,3 +1,5 @@
 extern "C" {
 extern void *malloc (__SIZE_TYPE__ __size) throw () __attribute__ 
((__malloc__)) ;
+
+void MyFunc() throw();
 }


Index: lib/Sema/SemaExceptionSpec.cpp
===================================================================
--- lib/Sema/SemaExceptionSpec.cpp
+++ lib/Sema/SemaExceptionSpec.cpp
@@ -254,9 +254,15 @@
   // to many libc functions as an optimization. Unfortunately, that
   // optimization isn't permitted by the C++ standard, so we're forced
   // to work around it here.
-  if (MissingEmptyExceptionSpecification && NewProto &&
-      (Old->getLocation().isInvalid() ||
-       Context.getSourceManager().isInSystemHeader(Old->getLocation())) &&
+  bool IsFromSystemHeader = false;
+  for (const FunctionDecl *Prev = Old; Prev; Prev = Prev->getPreviousDecl())
+    if (Prev->getLocation().isInvalid() ||
+        Context.getSourceManager().isInSystemHeader(Prev->getLocation())) {
+      IsFromSystemHeader = true;
+      break;
+    }
+
+  if (MissingEmptyExceptionSpecification && NewProto && IsFromSystemHeader &&
       Old->isExternC()) {
     New->setType(Context.getFunctionType(
         NewProto->getReturnType(), NewProto->getParamTypes(),
Index: test/SemaCXX/builtin-exception-spec.cpp
===================================================================
--- test/SemaCXX/builtin-exception-spec.cpp
+++ test/SemaCXX/builtin-exception-spec.cpp
@@ -4,4 +4,7 @@
 
 extern "C" {
 void *malloc(__SIZE_TYPE__);
+
+void MyFunc() __attribute__((__weak__));
+void MyFunc() { return; }
 }
Index: test/SemaCXX/Inputs/malloc.h
===================================================================
--- test/SemaCXX/Inputs/malloc.h
+++ test/SemaCXX/Inputs/malloc.h
@@ -1,3 +1,5 @@
 extern "C" {
 extern void *malloc (__SIZE_TYPE__ __size) throw () __attribute__ ((__malloc__)) ;
+
+void MyFunc() throw();
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to