[PATCH] Don't mark declarations with mismatching exception specs as invalid in MS mode (PR18683)

Hans Wennborg hans at chromium.org
Mon Feb 3 16:08:05 PST 2014


Hi rsmith,

I wasn't sure where to put the test. The semantic aspect of this is tested in SemaCXX/MicrosoftExtensions.cpp, but I couldn't figure out how to check for this specific issue there, so I just created a pr file in CodeGenCXX.

http://llvm-reviews.chandlerc.com/D2681

Files:
  lib/Sema/SemaExceptionSpec.cpp
  test/CodeGenCXX/pr18661.cpp

Index: lib/Sema/SemaExceptionSpec.cpp
===================================================================
--- lib/Sema/SemaExceptionSpec.cpp
+++ lib/Sema/SemaExceptionSpec.cpp
@@ -182,9 +182,9 @@
   }
 
   // The failure was something other than an missing exception
-  // specification; return an error.
+  // specification; return an error, except in MS mode where this is a warning.
   if (!MissingExceptionSpecification)
-    return true;
+    return getLangOpts().MicrosoftExt ? false : true;
 
   const FunctionProtoType *NewProto =
     New->getType()->castAs<FunctionProtoType>();
@@ -302,10 +302,14 @@
     const FunctionProtoType *New, SourceLocation NewLoc) {
   unsigned DiagID = diag::err_mismatched_exception_spec;
   if (getLangOpts().MicrosoftExt)
-    DiagID = diag::warn_mismatched_exception_spec; 
-  return CheckEquivalentExceptionSpec(PDiag(DiagID),
-                                      PDiag(diag::note_previous_declaration),
-                                      Old, OldLoc, New, NewLoc);
+    DiagID = diag::warn_mismatched_exception_spec;
+  bool Result = CheckEquivalentExceptionSpec(PDiag(DiagID),
+      PDiag(diag::note_previous_declaration), Old, OldLoc, New, NewLoc);
+
+  // In Microsoft mode, mismatching exception specifications just cause a warning.
+  if (getLangOpts().MicrosoftExt)
+    return false;
+  return Result;
 }
 
 /// CheckEquivalentExceptionSpec - Check if the two types have compatible
Index: test/CodeGenCXX/pr18661.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/pr18661.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -fcxx-exceptions -fms-extensions -emit-llvm -o - | FileCheck %s
+
+extern "C" {
+  void f();
+
+  // In MS mode we don't validate the exception specification.
+  void f() throw() {
+  }
+}
+
+// PR18661: Clang would fail to emit function definition with mismatching
+// exception specification, even though it was just treated as a warning.
+
+// CHECK: define void @f()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2681.1.patch
Type: text/x-patch
Size: 2029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140203/f0bdb3c5/attachment.bin>


More information about the cfe-commits mailing list