]> granicus.if.org Git - clang/commitdiff
Fix several bugs with #pragma clang arc_cf_code_audited and macros.
authorJohn McCall <rjmccall@apple.com>
Tue, 18 Oct 2011 00:44:04 +0000 (00:44 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 18 Oct 2011 00:44:04 +0000 (00:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142324 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPLexerChange.cpp
test/SemaObjC/arc-cf.m

index da6c8aa589e03ce39464fe00801bdc4102b46f1a..dc6536427a214c49aed33cdd331b8d7d2c72fb24 100644 (file)
@@ -237,8 +237,11 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
     }
   }
 
-  // Complain about reaching an EOF within arc_cf_code_audited.
-  if (PragmaARCCFCodeAuditedLoc.isValid()) {
+  // Complain about reaching a true EOF within arc_cf_code_audited.
+  // We don't want to complain about reaching the end of a macro
+  // instantiation or a _Pragma.
+  if (PragmaARCCFCodeAuditedLoc.isValid() &&
+      !isEndOfMacro && CurLexer && !CurLexer->Is_PragmaLexer) {
     Diag(PragmaARCCFCodeAuditedLoc, diag::err_pp_eof_in_arc_cf_code_audited);
 
     // Recover by leaving immediately.
index c1df3e0489f1d582bf875aaaf00a74cc2c1f9cd7..b9a44d9e68c40fef3cf5f9a283ab30201cde28d6 100644 (file)
@@ -18,3 +18,22 @@ void test1() {
   x = (id) CFMakeString1();
   x = (id) CFCreateString1(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{__bridge_transfer to transfer}}
 }
+
+#define CF_AUDIT_BEGIN _Pragma("clang arc_cf_code_audited begin")
+#define CF_AUDIT_END _Pragma("clang arc_cf_code_audited end")
+#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
+#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
+
+CF_AUDIT_BEGIN
+extern CFStringRef CFMakeString2(void);
+extern CFStringRef CFCreateString2(void) CF_RETURNS_NOT_RETAINED;
+extern CFStringRef CFMakeString3(void) CF_RETURNS_RETAINED;
+extern CFStringRef CFCreateString3(void);
+CF_AUDIT_END
+void test2() {
+  id x;
+  x = (id) CFMakeString2();
+  x = (id) CFCreateString2();
+  x = (id) CFMakeString3(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{__bridge_transfer to transfer}}
+  x = (id) CFCreateString3(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{__bridge_transfer to transfer}}
+}