Make clang -cc1 disable Objective-C exceptions by default, and add a -fobjc-exceptions flag to turn them on.

Update all tests accordingly.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126177 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 17fd41a..8d56a42 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -420,7 +420,7 @@
   HelpText<"Enable support for exception handling">;
 def fsjlj_exceptions : Flag<"-fsjlj-exceptions">,
   HelpText<"Use SjLj style exceptions">;
-def fno_objc_exceptions : Flag<"-fno-objc-exceptions">,
+def fobjc_exceptions : Flag<"-fobjc-exceptions">,
   HelpText<"Disable Objective-C exceptions">;
 def ffreestanding : Flag<"-ffreestanding">,
   HelpText<"Assert that the compilation takes place in a freestanding environment">;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 2f264e5..9f4a0bc 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1546,10 +1546,10 @@
       CmdArgs.push_back("-fobjc-default-synthesize-properties");
     }
 
-    // -fobjc-exceptions is default.
-    if (!Args.hasFlag(options::OPT_fobjc_exceptions, 
-                      options::OPT_fno_objc_exceptions))
-      CmdArgs.push_back("-fno-objc-exceptions");
+    // -fno-objc-exceptions is default.
+    if (IsRewriter || Args.hasFlag(options::OPT_fobjc_exceptions, 
+                                   options::OPT_fno_objc_exceptions))
+      CmdArgs.push_back("-fobjc-exceptions");
   }
 
   if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 915634b..d510b5b 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1460,7 +1460,7 @@
   if (Args.hasArg(OPT_fno_threadsafe_statics))
     Opts.ThreadsafeStatics = 0;
   Opts.Exceptions = Args.hasArg(OPT_fexceptions);
-  Opts.ObjCExceptions = !Args.hasArg(OPT_fno_objc_exceptions);
+  Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);
   Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
   Opts.Blocks = Args.hasArg(OPT_fblocks);
   Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char);
@@ -1490,7 +1490,7 @@
   Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
   Opts.PICLevel = Args.getLastArgIntValue(OPT_pic_level, 0, Diags);
   Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
-  Opts.ObjCExceptions = !Args.hasArg(OPT_fno_objc_exceptions);
+  Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);
   Opts.Static = Args.hasArg(OPT_static_define);
   Opts.DumpRecordLayouts = Args.hasArg(OPT_fdump_record_layouts);
   Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts);
diff --git a/test/CodeGenObjC/blocks-4.m b/test/CodeGenObjC/blocks-4.m
index d945ed4..f2d6e21 100644
--- a/test/CodeGenObjC/blocks-4.m
+++ b/test/CodeGenObjC/blocks-4.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm -fblocks -o %t %s
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm -fobjc-exceptions -fblocks -o %t %s
 // rdar://7590273
 
 void EXIT(id e);
diff --git a/test/CodeGenObjC/exceptions-nonfragile.m b/test/CodeGenObjC/exceptions-nonfragile.m
index 57ed1d9..280b5d4 100644
--- a/test/CodeGenObjC/exceptions-nonfragile.m
+++ b/test/CodeGenObjC/exceptions-nonfragile.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fexceptions -O2 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fexceptions -fobjc-exceptions -O2 -o - %s | FileCheck %s
 
 // rdar://problem/8535238
 // CHECK: declare void @objc_exception_rethrow()
diff --git a/test/CodeGenObjC/exceptions.m b/test/CodeGenObjC/exceptions.m
index 31805cb..d378f84 100644
--- a/test/CodeGenObjC/exceptions.m
+++ b/test/CodeGenObjC/exceptions.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fexceptions -O2 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fexceptions -fobjc-exceptions -O2 -o - %s | FileCheck %s
 //
 // <rdar://problem/7471679> [irgen] [eh] Exception code built with clang (x86_64) crashes
 
diff --git a/test/CodeGenObjC/gnu-exceptions.m b/test/CodeGenObjC/gnu-exceptions.m
index 6790a29..7f3ae9d 100644
--- a/test/CodeGenObjC/gnu-exceptions.m
+++ b/test/CodeGenObjC/gnu-exceptions.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -fexceptions -fgnu-runtime -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -fexceptions -fobjc-exceptions -fgnu-runtime -o - %s | FileCheck %s
 
 void opaque(void);
 void log(int i);
diff --git a/test/CodeGenObjC/metadata_symbols.m b/test/CodeGenObjC/metadata_symbols.m
index 3163946..d864229 100644
--- a/test/CodeGenObjC/metadata_symbols.m
+++ b/test/CodeGenObjC/metadata_symbols.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -emit-llvm -fexceptions -o %t %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -emit-llvm -fexceptions -fobjc-exceptions -o %t %s
 // RUN: FileCheck -check-prefix=CHECK-X86_64 < %t %s
 // RUN: grep '@"OBJC_EHTYPE_$_EH3"' %t | count 3
 
@@ -12,7 +12,7 @@
 // CHECK-X86_64: define internal void @"\01-[A im0]"
 // CHECK-X86_64: define internal void @"\01-[A(Cat) im1]"
 
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fvisibility hidden -emit-llvm -o %t %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fobjc-exceptions -fvisibility hidden -emit-llvm -o %t %s
 // RUN: FileCheck -check-prefix=CHECK-X86_64-HIDDEN < %t %s
 
 // CHECK-X86_64-HIDDEN: @"OBJC_CLASS_$_A" = hidden global {{.*}}, section "__DATA, __objc_data", align 8
@@ -23,7 +23,7 @@
 // CHECK-X86_64-HIDDEN: define internal void @"\01-[A im0]"
 // CHECK-X86_64-HIDDEN: define internal void @"\01-[A(Cat) im1]"
 
-// RUN: %clang_cc1 -triple armv6-apple-darwin10 -target-abi apcs-gnu -fobjc-nonfragile-abi -emit-llvm -o %t %s
+// RUN: %clang_cc1 -triple armv6-apple-darwin10 -target-abi apcs-gnu -fobjc-nonfragile-abi -fobjc-exceptions -emit-llvm -o %t %s
 // RUN: FileCheck -check-prefix=CHECK-ARMV6 < %t %s
 
 // CHECK-ARMV6: @"OBJC_CLASS_$_A" = global {{.*}}, section "__DATA, __objc_data", align 4
diff --git a/test/CodeGenObjC/nested-rethrow.m b/test/CodeGenObjC/nested-rethrow.m
index 627b913..af5154a 100644
--- a/test/CodeGenObjC/nested-rethrow.m
+++ b/test/CodeGenObjC/nested-rethrow.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm -fobjc-exceptions %s -o - | FileCheck %s
 
 
 extern int printf(const char*, ...);
diff --git a/test/CodeGenObjC/rdr-6732143-dangling-block-reference.m b/test/CodeGenObjC/rdr-6732143-dangling-block-reference.m
index b4d21a3..fd812dd 100644
--- a/test/CodeGenObjC/rdr-6732143-dangling-block-reference.m
+++ b/test/CodeGenObjC/rdr-6732143-dangling-block-reference.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-llvm %s -o -
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-llvm -fobjc-exceptions %s -o -
 
 void f0(id x) {
   @synchronized (x) {      
diff --git a/test/CodeGenObjC/try.m b/test/CodeGenObjC/try.m
index 884e33a..ba79d62 100644
--- a/test/CodeGenObjC/try.m
+++ b/test/CodeGenObjC/try.m
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -S -o - -triple=i686-apple-darwin9
-// RUN: %clang_cc1 %s -S -o - -triple=x86_64-apple-darwin9
+// RUN: %clang_cc1 %s -fobjc-exceptions -S -o - -triple=i686-apple-darwin9
+// RUN: %clang_cc1 %s -fobjc-exceptions -S -o - -triple=x86_64-apple-darwin9
 
 // rdar://6757213 - Don't crash if the internal proto for
 // __objc_personality_v0 mismatches with an actual one.
diff --git a/test/CodeGenObjC/unwind-fn.m b/test/CodeGenObjC/unwind-fn.m
index 5bfc7dc..5e4a7a5 100644
--- a/test/CodeGenObjC/unwind-fn.m
+++ b/test/CodeGenObjC/unwind-fn.m
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fobjc-nonfragile-abi -emit-llvm -fexceptions -o - %s | FileCheck --check-prefix=DEFAULT_EH %s
-// RUN: %clang_cc1 -fsjlj-exceptions -fobjc-nonfragile-abi -fexceptions -emit-llvm -o - %s | FileCheck --check-prefix=SJLJ_EH %s
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -emit-llvm -fexceptions -fobjc-exceptions -o - %s | FileCheck --check-prefix=DEFAULT_EH %s
+// RUN: %clang_cc1 -fsjlj-exceptions -fobjc-nonfragile-abi -fexceptions -fobjc-exceptions -emit-llvm -o - %s | FileCheck --check-prefix=SJLJ_EH %s
 
 // DEFAULT_EH: declare void @_Unwind_Resume_or_Rethrow(i8*)
 // SJLJ_EH: declare void @_Unwind_SjLj_Resume_or_Rethrow(i8*)
diff --git a/test/Coverage/ast-printing.m b/test/Coverage/ast-printing.m
index d9c97d4..81c3a6b 100644
--- a/test/Coverage/ast-printing.m
+++ b/test/Coverage/ast-printing.m
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only %s
-// RUN: %clang_cc1 -ast-print %s
-// RUN: %clang_cc1 -ast-dump %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-exceptions %s
+// RUN: %clang_cc1 -ast-print -fobjc-exceptions %s
+// RUN: %clang_cc1 -ast-dump -fobjc-exceptions %s
 
 #include "objc-language-features.inc"
diff --git a/test/Coverage/codegen-gnu.m b/test/Coverage/codegen-gnu.m
index 6e7790d..432637c 100644
--- a/test/Coverage/codegen-gnu.m
+++ b/test/Coverage/codegen-gnu.m
@@ -1,3 +1,3 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown -fgnu-runtime -emit-llvm -o %t %s
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fobjc-exceptions -fgnu-runtime -emit-llvm -o %t %s
 
 #include "objc-language-features.inc"
diff --git a/test/Coverage/codegen-next.m b/test/Coverage/codegen-next.m
index 978b443..8f6645d 100644
--- a/test/Coverage/codegen-next.m
+++ b/test/Coverage/codegen-next.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -o %t %s
-// RUN: %clang_cc1 -g -emit-llvm -o %t %s
+// RUN: %clang_cc1 -emit-llvm -fobjc-exceptions -o %t %s
+// RUN: %clang_cc1 -g -emit-llvm -fobjc-exceptions -o %t %s
 
 #include "objc-language-features.inc"
diff --git a/test/Driver/rewrite-objc.m b/test/Driver/rewrite-objc.m
index ac77d79..e3d2c0f 100644
--- a/test/Driver/rewrite-objc.m
+++ b/test/Driver/rewrite-objc.m
@@ -3,7 +3,7 @@
 // TEST0: clang{{.*}}" "-cc1"
 // TEST0: "-rewrite-objc"
 // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency instead.
-// TEST0: "-fmessage-length" "0" "-fdiagnostics-show-option"
+// TEST0: "-fmessage-length" "0" "-fobjc-exceptions" "-fdiagnostics-show-option"
 // TEST0: rewrite-objc.m"
 
 // RUN: not %clang -ccc-no-clang -ccc-host-triple unknown -rewrite-objc %s -o - -### 2>&1 | \
diff --git a/test/PCH/objc_stmts.m b/test/PCH/objc_stmts.m
index ed7466a..3bc728c 100644
--- a/test/PCH/objc_stmts.m
+++ b/test/PCH/objc_stmts.m
@@ -1,11 +1,11 @@
 // Test this without pch.
-// RUN: %clang_cc1 -include %S/objc_stmts.h -emit-llvm -o - %s
-// RUN: %clang_cc1 -include %S/objc_stmts.h -ast-dump -o - %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -include %S/objc_stmts.h -emit-llvm -fobjc-exceptions -o - %s
+// RUN: %clang_cc1 -include %S/objc_stmts.h -ast-dump -fobjc-exceptions -o - %s 2>&1 | FileCheck %s
 
 // Test with pch.
-// RUN: %clang_cc1 -x objective-c -emit-pch -o %t %S/objc_stmts.h
-// RUN: %clang_cc1 -include-pch %t -emit-llvm -o - %s 
-// RUN: %clang_cc1 -include-pch %t -ast-dump -o - %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -x objective-c -emit-pch -fobjc-exceptions -o %t %S/objc_stmts.h
+// RUN: %clang_cc1 -include-pch %t -emit-llvm -fobjc-exceptions -o - %s 
+// RUN: %clang_cc1 -include-pch %t -ast-dump -fobjc-exceptions -o - %s 2>&1 | FileCheck %s
 
 // CHECK: catch parm = "A *a"
 // CHECK: catch parm = "B *b"
diff --git a/test/Parser/objc-try-catch-1.m b/test/Parser/objc-try-catch-1.m
index 7193691..a3220eb 100644
--- a/test/Parser/objc-try-catch-1.m
+++ b/test/Parser/objc-try-catch-1.m
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -verify -x objective-c++ %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions -x objective-c++ %s
 void * proc();
 
 @interface NSConstantString
diff --git a/test/Rewriter/finally.m b/test/Rewriter/finally.m
index 7d160cf..ab5d838 100644
--- a/test/Rewriter/finally.m
+++ b/test/Rewriter/finally.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -rewrite-objc -verify %s -o -
+// RUN: %clang_cc1 -rewrite-objc -fobjc-exceptions -verify %s -o -
 
 int main() {
   @try {
diff --git a/test/Rewriter/rewrite-eh.m b/test/Rewriter/rewrite-eh.m
index 5bc80b5..9045f7f 100644
--- a/test/Rewriter/rewrite-eh.m
+++ b/test/Rewriter/rewrite-eh.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -rewrite-objc -o - %s
+// RUN: %clang_cc1 -rewrite-objc -fobjc-exceptions -o - %s
 // rdar://7522880
 
 @interface NSException
diff --git a/test/Rewriter/rewrite-try-catch.m b/test/Rewriter/rewrite-try-catch.m
index d0c6d2a..5e7b3cf 100644
--- a/test/Rewriter/rewrite-try-catch.m
+++ b/test/Rewriter/rewrite-try-catch.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -rewrite-objc %s -o -
+// RUN: %clang_cc1 -rewrite-objc -fobjc-exceptions %s -o -
 
 @interface Foo @end
 @interface GARF @end
diff --git a/test/SemaObjC/catch-stmt.m b/test/SemaObjC/catch-stmt.m
index ef1da37..dcb4764 100644
--- a/test/SemaObjC/catch-stmt.m
+++ b/test/SemaObjC/catch-stmt.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -fobjc-exceptions %s
 @interface A @end
 @protocol P;
 
diff --git a/test/SemaObjC/invalid-code.m b/test/SemaObjC/invalid-code.m
index 7a642fb..9b7f2c8 100644
--- a/test/SemaObjC/invalid-code.m
+++ b/test/SemaObjC/invalid-code.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fobjc-exceptions
 
 // rdar://6124613
 void test1() {
diff --git a/test/SemaObjC/no-objc-exceptions.m b/test/SemaObjC/no-objc-exceptions.m
index 78419a2..d47f51a 100644
--- a/test/SemaObjC/no-objc-exceptions.m
+++ b/test/SemaObjC/no-objc-exceptions.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fno-objc-exceptions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
 
 void f() {
   @throw @"Hello"; // expected-error {{cannot use '@throw' with Objective-C exceptions disabled}}
diff --git a/test/SemaObjC/property-6.m b/test/SemaObjC/property-6.m
index 72beb67..933a4f0 100644
--- a/test/SemaObjC/property-6.m
+++ b/test/SemaObjC/property-6.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s
 # 1 "<command line>"
 # 1 "/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h" 1 3
 typedef signed char BOOL;
diff --git a/test/SemaObjC/rdar6248119.m b/test/SemaObjC/rdar6248119.m
index 6b120b2..046992c 100644
--- a/test/SemaObjC/rdar6248119.m
+++ b/test/SemaObjC/rdar6248119.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only %s -verify
+// RUN: %clang_cc1 -fsyntax-only %s -verify -fobjc-exceptions
 // Test case for: 
 //   <rdar://problem/6248119> @finally doesn't introduce a new scope
 
diff --git a/test/SemaObjC/return.m b/test/SemaObjC/return.m
index 116abd1..3a626e3 100644
--- a/test/SemaObjC/return.m
+++ b/test/SemaObjC/return.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify -Wmissing-noreturn
+// RUN: %clang_cc1 %s -fsyntax-only -verify -Wmissing-noreturn -fobjc-exceptions
 
 int test1() {
   id a;
diff --git a/test/SemaObjC/scope-check.m b/test/SemaObjC/scope-check.m
index bba321e..3f474be 100644
--- a/test/SemaObjC/scope-check.m
+++ b/test/SemaObjC/scope-check.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s
 
 @class A, B, C;
 
diff --git a/test/SemaObjC/stmts.m b/test/SemaObjC/stmts.m
index d1e2ad3..d452db8 100644
--- a/test/SemaObjC/stmts.m
+++ b/test/SemaObjC/stmts.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only -fobjc-exceptions
 
 struct some_struct;
 
diff --git a/test/SemaObjC/try-catch.m b/test/SemaObjC/try-catch.m
index 01fc4f4..da06eca 100644
--- a/test/SemaObjC/try-catch.m
+++ b/test/SemaObjC/try-catch.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s
 typedef signed char BOOL;
 typedef struct _NSZone NSZone;
 
diff --git a/test/SemaObjC/warn-unused-exception-param.m b/test/SemaObjC/warn-unused-exception-param.m
index f649f8c..221e16f 100644
--- a/test/SemaObjC/warn-unused-exception-param.m
+++ b/test/SemaObjC/warn-unused-exception-param.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wunused-exception-parameter %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions -Wunused-exception-parameter %s
 void  f0() {
   @try {} @catch(id a) {} // expected-warning{{unused exception parameter 'a'}}
 }
diff --git a/test/SemaObjCXX/instantiate-stmt.mm b/test/SemaObjCXX/instantiate-stmt.mm
index 5e8ec61..ff72858 100644
--- a/test/SemaObjCXX/instantiate-stmt.mm
+++ b/test/SemaObjCXX/instantiate-stmt.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s
 
 @interface NSException
 @end