Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -569,7 +569,7 @@ // Add ObjC ARC final-cleanup optimizations. This is done as part of the // "codegen" passes so that it isn't run multiple times when there is // inlining happening. - if (LangOpts.ObjCAutoRefCount && + if (TheModule->getModuleFlag("Objective-C ARC") && CodeGenOpts.OptimizationLevel > 0) PM->add(createObjCARCContractPass()); Index: lib/CodeGen/CGObjCMac.cpp =================================================================== --- lib/CodeGen/CGObjCMac.cpp +++ lib/CodeGen/CGObjCMac.cpp @@ -4284,6 +4284,12 @@ } } + // Add ObjCAutoRefCount as a module flag + if (CGM.getLangOpts().ObjCAutoRefCount) { + Mod.addModuleFlag(llvm::Module::Error, + "Objective-C ARC", 1u); + } + // Indicate whether we're compiling this to run on a simulator. const llvm::Triple &Triple = CGM.getTarget().getTriple(); if (Triple.isiOS() && Index: test/CodeGen/arc-passes.m =================================================================== --- /dev/null +++ test/CodeGen/arc-passes.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s -check-prefix=NO-ARC +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -emit-obj -O3 %s -o /dev/null -mllvm -debug-pass=Arguments 2>&1 | FileCheck %s -check-prefix=ARC-PASS +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-obj -O3 %s -o /dev/null -mllvm -debug-pass=Arguments 2>&1 | FileCheck %s -check-prefix=NO-ARC-PASS + +// CHECK: !{i32 1, !"Objective-C ARC", i32 1} +// NO-ARC-NOT: !{i32 1, !"Objective-C ARC", i32 1} +// ARC-PASS: -objc-arc-contract +// NO-ARC-PASS-NOT: -objc-arc-contract + +void test() { +}