Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit c9cecf5

Browse files
committed
[Sema] Suppress diags in overload resolution.
We were emitting diagnostics from our shiny new C-only overload resolution mode. This patch attempts to silence all such diagnostics. This fixes PR26085. Differential Revision: http://reviews.llvm.org/D16159 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257710 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7362708 commit c9cecf5

File tree

6 files changed

+191
-101
lines changed

6 files changed

+191
-101
lines changed

include/clang/Sema/Sema.h

+12-8
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,8 @@ class Sema {
22292229
bool CheckPointerConversion(Expr *From, QualType ToType,
22302230
CastKind &Kind,
22312231
CXXCastPath& BasePath,
2232-
bool IgnoreBaseAccess);
2232+
bool IgnoreBaseAccess,
2233+
bool Diagnose = true);
22332234
bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
22342235
bool InOverloadResolution,
22352236
QualType &ConvertedType);
@@ -5388,7 +5389,8 @@ class Sema {
53885389
unsigned AmbigiousBaseConvID,
53895390
SourceLocation Loc, SourceRange Range,
53905391
DeclarationName Name,
5391-
CXXCastPath *BasePath);
5392+
CXXCastPath *BasePath,
5393+
bool IgnoreAccess = false);
53925394

53935395
std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
53945396

@@ -7514,14 +7516,15 @@ class Sema {
75147516
ObjCMethodDecl *&ClassMethod,
75157517
ObjCMethodDecl *&InstanceMethod,
75167518
TypedefNameDecl *&TDNDecl,
7517-
bool CfToNs);
7518-
7519+
bool CfToNs, bool Diagnose = true);
7520+
75197521
bool CheckObjCBridgeRelatedConversions(SourceLocation Loc,
75207522
QualType DestType, QualType SrcType,
7521-
Expr *&SrcExpr);
7522-
7523-
bool ConversionToObjCStringLiteralCheck(QualType DstType, Expr *&SrcExpr);
7524-
7523+
Expr *&SrcExpr, bool Diagnose = true);
7524+
7525+
bool ConversionToObjCStringLiteralCheck(QualType DstType, Expr *&SrcExpr,
7526+
bool Diagnose = true);
7527+
75257528
bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
75267529

75277530
/// \brief Check whether the given new method is a valid override of the
@@ -8613,6 +8616,7 @@ class Sema {
86138616
ARCConversionResult CheckObjCARCConversion(SourceRange castRange,
86148617
QualType castType, Expr *&op,
86158618
CheckedConversionKind CCK,
8619+
bool Diagnose = true,
86168620
bool DiagnoseCFAudited = false,
86178621
BinaryOperatorKind Opc = BO_PtrMemD
86188622
);

lib/Sema/SemaDeclCXX.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -1742,13 +1742,18 @@ void Sema::BuildBasePathArray(const CXXBasePaths &Paths,
17421742
/// otherwise. Loc is the location where this routine should point to
17431743
/// if there is an error, and Range is the source range to highlight
17441744
/// if there is an error.
1745+
///
1746+
/// If either InaccessibleBaseID or AmbigiousBaseConvID are 0, then the
1747+
/// diagnostic for the respective type of error will be suppressed, but the
1748+
/// check for ill-formed code will still be performed.
17451749
bool
17461750
Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
17471751
unsigned InaccessibleBaseID,
17481752
unsigned AmbigiousBaseConvID,
17491753
SourceLocation Loc, SourceRange Range,
17501754
DeclarationName Name,
1751-
CXXCastPath *BasePath) {
1755+
CXXCastPath *BasePath,
1756+
bool IgnoreAccess) {
17521757
// First, determine whether the path from Derived to Base is
17531758
// ambiguous. This is slightly more expensive than checking whether
17541759
// the Derived to Base conversion exists, because here we need to
@@ -1761,7 +1766,7 @@ Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
17611766
(void)DerivationOkay;
17621767

17631768
if (!Paths.isAmbiguous(Context.getCanonicalType(Base).getUnqualifiedType())) {
1764-
if (InaccessibleBaseID) {
1769+
if (!IgnoreAccess) {
17651770
// Check that the base class can be accessed.
17661771
switch (CheckBaseClassAccess(Loc, Base, Derived, Paths.front(),
17671772
InaccessibleBaseID)) {
@@ -1810,12 +1815,10 @@ Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
18101815
SourceLocation Loc, SourceRange Range,
18111816
CXXCastPath *BasePath,
18121817
bool IgnoreAccess) {
1813-
return CheckDerivedToBaseConversion(Derived, Base,
1814-
IgnoreAccess ? 0
1815-
: diag::err_upcast_to_inaccessible_base,
1816-
diag::err_ambiguous_derived_to_base_conv,
1817-
Loc, Range, DeclarationName(),
1818-
BasePath);
1818+
return CheckDerivedToBaseConversion(
1819+
Derived, Base, diag::err_upcast_to_inaccessible_base,
1820+
diag::err_ambiguous_derived_to_base_conv, Loc, Range, DeclarationName(),
1821+
BasePath, IgnoreAccess);
18191822
}
18201823

18211824

lib/Sema/SemaExpr.cpp

+22-17
Original file line numberDiff line numberDiff line change
@@ -7354,11 +7354,14 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS,
73547354
LHSType->isBlockPointerType()) &&
73557355
RHS.get()->isNullPointerConstant(Context,
73567356
Expr::NPC_ValueDependentIsNull)) {
7357-
CastKind Kind;
7358-
CXXCastPath Path;
7359-
CheckPointerConversion(RHS.get(), LHSType, Kind, Path, false);
7360-
if (ConvertRHS)
7361-
RHS = ImpCastExprToType(RHS.get(), LHSType, Kind, VK_RValue, &Path);
7357+
if (Diagnose || ConvertRHS) {
7358+
CastKind Kind;
7359+
CXXCastPath Path;
7360+
CheckPointerConversion(RHS.get(), LHSType, Kind, Path,
7361+
/*IgnoreBaseAccess=*/false, Diagnose);
7362+
if (ConvertRHS)
7363+
RHS = ImpCastExprToType(RHS.get(), LHSType, Kind, VK_RValue, &Path);
7364+
}
73627365
return Compatible;
73637366
}
73647367

@@ -7376,8 +7379,8 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS,
73767379
}
73777380

73787381
Expr *PRE = RHS.get()->IgnoreParenCasts();
7379-
if (ObjCProtocolExpr *OPE = dyn_cast<ObjCProtocolExpr>(PRE)) {
7380-
ObjCProtocolDecl *PDecl = OPE->getProtocol();
7382+
if (Diagnose && isa<ObjCProtocolExpr>(PRE)) {
7383+
ObjCProtocolDecl *PDecl = cast<ObjCProtocolExpr>(PRE)->getProtocol();
73817384
if (PDecl && !PDecl->hasDefinition()) {
73827385
Diag(PRE->getExprLoc(), diag::warn_atprotocol_protocol) << PDecl->getName();
73837386
Diag(PDecl->getLocation(), diag::note_entity_declared_at) << PDecl;
@@ -7399,11 +7402,11 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS,
73997402
Expr *E = RHS.get();
74007403
if (getLangOpts().ObjCAutoRefCount)
74017404
CheckObjCARCConversion(SourceRange(), Ty, E, CCK_ImplicitConversion,
7402-
DiagnoseCFAudited);
7405+
Diagnose, DiagnoseCFAudited);
74037406
if (getLangOpts().ObjC1 &&
7404-
(CheckObjCBridgeRelatedConversions(E->getLocStart(),
7405-
LHSType, E->getType(), E) ||
7406-
ConversionToObjCStringLiteralCheck(LHSType, E))) {
7407+
(CheckObjCBridgeRelatedConversions(E->getLocStart(), LHSType,
7408+
E->getType(), E, Diagnose) ||
7409+
ConversionToObjCStringLiteralCheck(LHSType, E, Diagnose))) {
74077410
RHS = E;
74087411
return Compatible;
74097412
}
@@ -8961,8 +8964,9 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,
89618964
else {
89628965
Expr *E = RHS.get();
89638966
if (getLangOpts().ObjCAutoRefCount)
8964-
CheckObjCARCConversion(SourceRange(), LHSType, E, CCK_ImplicitConversion, false,
8965-
Opc);
8967+
CheckObjCARCConversion(SourceRange(), LHSType, E,
8968+
CCK_ImplicitConversion, /*Diagnose=*/true,
8969+
/*DiagnoseCFAudited=*/false, Opc);
89668970
RHS = ImpCastExprToType(E, LHSType,
89678971
LPT ? CK_BitCast :CK_CPointerToObjCPointerCast);
89688972
}
@@ -11830,8 +11834,8 @@ ExprResult Sema::ActOnGNUNullExpr(SourceLocation TokenLoc) {
1183011834
return new (Context) GNUNullExpr(Ty, TokenLoc);
1183111835
}
1183211836

11833-
bool
11834-
Sema::ConversionToObjCStringLiteralCheck(QualType DstType, Expr *&Exp) {
11837+
bool Sema::ConversionToObjCStringLiteralCheck(QualType DstType, Expr *&Exp,
11838+
bool Diagnose) {
1183511839
if (!getLangOpts().ObjC1)
1183611840
return false;
1183711841

@@ -11857,8 +11861,9 @@ Sema::ConversionToObjCStringLiteralCheck(QualType DstType, Expr *&Exp) {
1185711861
StringLiteral *SL = dyn_cast<StringLiteral>(SrcExpr);
1185811862
if (!SL || !SL->isAscii())
1185911863
return false;
11860-
Diag(SL->getLocStart(), diag::err_missing_atsign_prefix)
11861-
<< FixItHint::CreateInsertion(SL->getLocStart(), "@");
11864+
if (Diagnose)
11865+
Diag(SL->getLocStart(), diag::err_missing_atsign_prefix)
11866+
<< FixItHint::CreateInsertion(SL->getLocStart(), "@");
1186211867
Exp = BuildObjCStringLiteral(SL->getLocStart(), SL).get();
1186311868
return true;
1186411869
}

0 commit comments

Comments
 (0)