PR35815: Separate out the ns-consumed diagnostic into an error and

a warning

This commit separates out the warn_nsconsumed_attribute_mismatch and
warn_nsreturns_retained_attribute_mismatch diagnostic into a warning and error.
This is needed to avoid a module import regression introduced by r313717 that
turned these errors into warnings and started promoting them only when needed,
which caused an error when importing a module as it had different warning
settings.

rdar://36265651

llvm-svn: 321775
This commit is contained in:
Alex Lorenz 2018-01-03 23:52:42 +00:00
parent f2b2169ded
commit 26d282fc5f
4 changed files with 36 additions and 13 deletions

View File

@ -8300,12 +8300,16 @@ def err_c99_array_usage_cxx : Error<
"feature, not permitted in C++">;
def err_type_unsupported : Error<
"%0 is not supported on this target">;
def warn_nsconsumed_attribute_mismatch : Warning<
def err_nsconsumed_attribute_mismatch : Error<
"overriding method has mismatched ns_consumed attribute on its"
" parameter">, InGroup<NSConsumedMismatch>;
def warn_nsreturns_retained_attribute_mismatch : Warning<
" parameter">;
def err_nsreturns_retained_attribute_mismatch : Error<
"overriding method has mismatched ns_returns_%select{not_retained|retained}0"
" attributes">, InGroup<NSReturnsMismatch>;
" attributes">;
def warn_nsconsumed_attribute_mismatch : Warning<
err_nsconsumed_attribute_mismatch.Text>, InGroup<NSConsumedMismatch>;
def warn_nsreturns_retained_attribute_mismatch : Warning<
err_nsreturns_retained_attribute_mismatch.Text>, InGroup<NSReturnsMismatch>;
def note_getter_unavailable : Note<
"or because setter is declared here, but no getter method %0 is found">;

View File

@ -156,23 +156,23 @@ void Sema::CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
Diag(Overridden->getLocation(),
diag::note_related_result_type_overridden);
}
if (getLangOpts().ObjCAutoRefCount) {
Diags.setSeverity(diag::warn_nsreturns_retained_attribute_mismatch,
diag::Severity::Error, SourceLocation());
Diags.setSeverity(diag::warn_nsconsumed_attribute_mismatch,
diag::Severity::Error, SourceLocation());
}
if ((NewMethod->hasAttr<NSReturnsRetainedAttr>() !=
Overridden->hasAttr<NSReturnsRetainedAttr>())) {
Diag(NewMethod->getLocation(),
diag::warn_nsreturns_retained_attribute_mismatch) << 1;
getLangOpts().ObjCAutoRefCount
? diag::err_nsreturns_retained_attribute_mismatch
: diag::warn_nsreturns_retained_attribute_mismatch)
<< 1;
Diag(Overridden->getLocation(), diag::note_previous_decl) << "method";
}
if ((NewMethod->hasAttr<NSReturnsNotRetainedAttr>() !=
Overridden->hasAttr<NSReturnsNotRetainedAttr>())) {
Diag(NewMethod->getLocation(),
diag::warn_nsreturns_retained_attribute_mismatch) << 0;
getLangOpts().ObjCAutoRefCount
? diag::err_nsreturns_retained_attribute_mismatch
: diag::warn_nsreturns_retained_attribute_mismatch)
<< 0;
Diag(Overridden->getLocation(), diag::note_previous_decl) << "method";
}
@ -185,7 +185,10 @@ void Sema::CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
ParmVarDecl *newDecl = (*ni);
if (newDecl->hasAttr<NSConsumedAttr>() !=
oldDecl->hasAttr<NSConsumedAttr>()) {
Diag(newDecl->getLocation(), diag::warn_nsconsumed_attribute_mismatch);
Diag(newDecl->getLocation(),
getLangOpts().ObjCAutoRefCount
? diag::err_nsconsumed_attribute_mismatch
: diag::warn_nsconsumed_attribute_mismatch);
Diag(oldDecl->getLocation(), diag::note_previous_decl) << "parameter";
}

View File

@ -0,0 +1,3 @@
module empty {
header "empty.h"
}

View File

@ -0,0 +1,13 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -fobjc-arc -verify -fblocks -triple x86_64-apple-darwin10.0.0 -DOBJCARC %s
// rdar://36265651
@interface A
-(void) m:(id)p; // expected-note {{parameter declared here}}
@end
@interface B : A
-(void) m:(__attribute__((ns_consumed)) id)p; // expected-error {{overriding method has mismatched ns_consumed attribute on its parameter}}
@end
@import empty;