Deleted Added
full compact
SemaExpr.cpp (195099) SemaExpr.cpp (195341)
1//===--- SemaExpr.cpp - Semantic Analysis for Expressions -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 25 unchanged lines hidden (view full) ---

34/// it might warn if a deprecated or unavailable declaration is being
35/// used, or produce an error (and return true) if a C++0x deleted
36/// function is being used.
37///
38/// \returns true if there was an error (this declaration cannot be
39/// referenced), false otherwise.
40bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
41 // See if the decl is deprecated.
1//===--- SemaExpr.cpp - Semantic Analysis for Expressions -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 25 unchanged lines hidden (view full) ---

34/// it might warn if a deprecated or unavailable declaration is being
35/// used, or produce an error (and return true) if a C++0x deleted
36/// function is being used.
37///
38/// \returns true if there was an error (this declaration cannot be
39/// referenced), false otherwise.
40bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
41 // See if the decl is deprecated.
42 if (D->getAttr<DeprecatedAttr>(Context)) {
42 if (D->getAttr()) {
43 // Implementing deprecated stuff requires referencing deprecated
44 // stuff. Don't warn if we are implementing a deprecated
45 // construct.
46 bool isSilenced = false;
47
48 if (NamedDecl *ND = getCurFunctionOrMethodDecl()) {
49 // If this reference happens *in* a deprecated function or method, don't
50 // warn.
43 // Implementing deprecated stuff requires referencing deprecated
44 // stuff. Don't warn if we are implementing a deprecated
45 // construct.
46 bool isSilenced = false;
47
48 if (NamedDecl *ND = getCurFunctionOrMethodDecl()) {
49 // If this reference happens *in* a deprecated function or method, don't
50 // warn.
51 isSilenced = ND->getAttr<DeprecatedAttr>(Context);
51 isSilenced = ND->getAttr();
52
53 // If this is an Objective-C method implementation, check to see if the
54 // method was deprecated on the declaration, not the definition.
55 if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(ND)) {
56 // The semantic decl context of a ObjCMethodDecl is the
57 // ObjCImplementationDecl.
58 if (ObjCImplementationDecl *Impl
59 = dyn_cast<ObjCImplementationDecl>(MD->getParent())) {
60
52
53 // If this is an Objective-C method implementation, check to see if the
54 // method was deprecated on the declaration, not the definition.
55 if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(ND)) {
56 // The semantic decl context of a ObjCMethodDecl is the
57 // ObjCImplementationDecl.
58 if (ObjCImplementationDecl *Impl
59 = dyn_cast<ObjCImplementationDecl>(MD->getParent())) {
60
61 MD = Impl->getClassInterface()->getMethod(Context,
62 MD->getSelector(),
61 MD = Impl->getClassInterface()->getMethod(MD->getSelector(),
63 MD->isInstanceMethod());
62 MD->isInstanceMethod());
64 isSilenced |= MD && MD->getAttr<DeprecatedAttr>(Context);
63 isSilenced |= MD && MD->getAttr();
65 }
66 }
67 }
68
69 if (!isSilenced)
70 Diag(Loc, diag::warn_deprecated) << D->getDeclName();
71 }
72
73 // See if this is a deleted function.
74 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
75 if (FD->isDeleted()) {
76 Diag(Loc, diag::err_deleted_function_use);
77 Diag(D->getLocation(), diag::note_unavailable_here) << true;
78 return true;
79 }
80 }
81
82 // See if the decl is unavailable
64 }
65 }
66 }
67
68 if (!isSilenced)
69 Diag(Loc, diag::warn_deprecated) << D->getDeclName();
70 }
71
72 // See if this is a deleted function.
73 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
74 if (FD->isDeleted()) {
75 Diag(Loc, diag::err_deleted_function_use);
76 Diag(D->getLocation(), diag::note_unavailable_here) << true;
77 return true;
78 }
79 }
80
81 // See if the decl is unavailable
83 if (D->getAttr<UnavailableAttr>(Context)) {
82 if (D->getAttr()) {
84 Diag(Loc, diag::warn_unavailable) << D->getDeclName();
85 Diag(D->getLocation(), diag::note_unavailable_here) << 0;
86 }
87
88 return false;
89}
90
91/// DiagnoseSentinelCalls - This routine checks on method dispatch calls
92/// (and other functions in future), which have been declared with sentinel
93/// attribute. It warns if call does not have the sentinel argument.
94///
95void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
96 Expr **Args, unsigned NumArgs)
97{
83 Diag(Loc, diag::warn_unavailable) << D->getDeclName();
84 Diag(D->getLocation(), diag::note_unavailable_here) << 0;
85 }
86
87 return false;
88}
89
90/// DiagnoseSentinelCalls - This routine checks on method dispatch calls
91/// (and other functions in future), which have been declared with sentinel
92/// attribute. It warns if call does not have the sentinel argument.
93///
94void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
95 Expr **Args, unsigned NumArgs)
96{
98 const SentinelAttr *attr = D->getAttr<SentinelAttr>(Context);
97 const SentinelAttr *attr = D->getAttr();
99 if (!attr)
100 return;
101 int sentinelPos = attr->getSentinel();
102 int nullPos = attr->getNullPos();
103
104 // FIXME. ObjCMethodDecl and FunctionDecl need be derived from the same common
105 // base class. Then we won't be needing two versions of the same code.
106 unsigned int i = 0;

--- 561 unchanged lines hidden (view full) ---

668 RecordDecl *Record) {
669 assert(Record->isAnonymousStructOrUnion() &&
670 "Record must be an anonymous struct or union!");
671
672 // FIXME: Once Decls are directly linked together, this will be an O(1)
673 // operation rather than a slow walk through DeclContext's vector (which
674 // itself will be eliminated). DeclGroups might make this even better.
675 DeclContext *Ctx = Record->getDeclContext();
98 if (!attr)
99 return;
100 int sentinelPos = attr->getSentinel();
101 int nullPos = attr->getNullPos();
102
103 // FIXME. ObjCMethodDecl and FunctionDecl need be derived from the same common
104 // base class. Then we won't be needing two versions of the same code.
105 unsigned int i = 0;

--- 561 unchanged lines hidden (view full) ---

667 RecordDecl *Record) {
668 assert(Record->isAnonymousStructOrUnion() &&
669 "Record must be an anonymous struct or union!");
670
671 // FIXME: Once Decls are directly linked together, this will be an O(1)
672 // operation rather than a slow walk through DeclContext's vector (which
673 // itself will be eliminated). DeclGroups might make this even better.
674 DeclContext *Ctx = Record->getDeclContext();
676 for (DeclContext::decl_iterator D = Ctx->decls_begin(Context),
677 DEnd = Ctx->decls_end(Context);
675 for (DeclContext::decl_iterator D = Ctx->decls_begin(),
676 DEnd = Ctx->decls_end();
678 D != DEnd; ++D) {
679 if (*D == Record) {
680 // The object for the anonymous struct/union directly
681 // follows its type in the list of declarations.
682 ++D;
683 assert(D != DEnd && "Missing object for anonymous record");
684 assert(!cast<NamedDecl>(*D)->getDeclName() && "Decl should be unnamed");
685 return *D;

--- 186 unchanged lines hidden (view full) ---

872 // There are two cases to handle here. 1) scoped lookup could have failed,
873 // in which case we should look for an ivar. 2) scoped lookup could have
874 // found a decl, but that decl is outside the current instance method (i.e.
875 // a global variable). In these two cases, we do a lookup for an ivar with
876 // this name, if the lookup sucedes, we replace it our current decl.
877 if (D == 0 || D->isDefinedOutsideFunctionOrMethod()) {
878 ObjCInterfaceDecl *IFace = getCurMethodDecl()->getClassInterface();
879 ObjCInterfaceDecl *ClassDeclared;
677 D != DEnd; ++D) {
678 if (*D == Record) {
679 // The object for the anonymous struct/union directly
680 // follows its type in the list of declarations.
681 ++D;
682 assert(D != DEnd && "Missing object for anonymous record");
683 assert(!cast<NamedDecl>(*D)->getDeclName() && "Decl should be unnamed");
684 return *D;

--- 186 unchanged lines hidden (view full) ---

871 // There are two cases to handle here. 1) scoped lookup could have failed,
872 // in which case we should look for an ivar. 2) scoped lookup could have
873 // found a decl, but that decl is outside the current instance method (i.e.
874 // a global variable). In these two cases, we do a lookup for an ivar with
875 // this name, if the lookup sucedes, we replace it our current decl.
876 if (D == 0 || D->isDefinedOutsideFunctionOrMethod()) {
877 ObjCInterfaceDecl *IFace = getCurMethodDecl()->getClassInterface();
878 ObjCInterfaceDecl *ClassDeclared;
880 if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(Context, II,
881 ClassDeclared)) {
879 if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(II, ClassDeclared)) {
882 // Check if referencing a field with __attribute__((deprecated)).
883 if (DiagnoseUseOfDecl(IV, Loc))
884 return ExprError();
885
886 // If we're referencing an invalid decl, just return this as a silent
887 // error node. The error diagnostic was already emitted on the decl.
888 if (IV->isInvalidDecl())
889 return ExprError();

--- 20 unchanged lines hidden (view full) ---

910 SelfExpr.takeAs<Expr>(), true, true));
911 }
912 }
913 }
914 else if (getCurMethodDecl()->isInstanceMethod()) {
915 // We should warn if a local variable hides an ivar.
916 ObjCInterfaceDecl *IFace = getCurMethodDecl()->getClassInterface();
917 ObjCInterfaceDecl *ClassDeclared;
880 // Check if referencing a field with __attribute__((deprecated)).
881 if (DiagnoseUseOfDecl(IV, Loc))
882 return ExprError();
883
884 // If we're referencing an invalid decl, just return this as a silent
885 // error node. The error diagnostic was already emitted on the decl.
886 if (IV->isInvalidDecl())
887 return ExprError();

--- 20 unchanged lines hidden (view full) ---

908 SelfExpr.takeAs<Expr>(), true, true));
909 }
910 }
911 }
912 else if (getCurMethodDecl()->isInstanceMethod()) {
913 // We should warn if a local variable hides an ivar.
914 ObjCInterfaceDecl *IFace = getCurMethodDecl()->getClassInterface();
915 ObjCInterfaceDecl *ClassDeclared;
918 if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(Context, II,
919 ClassDeclared)) {
916 if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(II, ClassDeclared)) {
920 if (IV->getAccessControl() != ObjCIvarDecl::Private ||
921 IFace == ClassDeclared)
922 Diag(Loc, diag::warn_ivar_use_hidden) << IV->getDeclName();
923 }
924 }
925 // Needed to implement property "super.method" notation.
926 if (D == 0 && II->isStr("super")) {
927 QualType T;

--- 40 unchanged lines hidden (view full) ---

968 else if (Name.getNameKind() == DeclarationName::CXXOperatorName ||
969 Name.getNameKind() == DeclarationName::CXXConversionFunctionName)
970 return ExprError(Diag(Loc, diag::err_undeclared_use)
971 << Name.getAsString());
972 else
973 return ExprError(Diag(Loc, diag::err_undeclared_var_use) << Name);
974 }
975 }
917 if (IV->getAccessControl() != ObjCIvarDecl::Private ||
918 IFace == ClassDeclared)
919 Diag(Loc, diag::warn_ivar_use_hidden) << IV->getDeclName();
920 }
921 }
922 // Needed to implement property "super.method" notation.
923 if (D == 0 && II->isStr("super")) {
924 QualType T;

--- 40 unchanged lines hidden (view full) ---

965 else if (Name.getNameKind() == DeclarationName::CXXOperatorName ||
966 Name.getNameKind() == DeclarationName::CXXConversionFunctionName)
967 return ExprError(Diag(Loc, diag::err_undeclared_use)
968 << Name.getAsString());
969 else
970 return ExprError(Diag(Loc, diag::err_undeclared_var_use) << Name);
971 }
972 }
973
974 if (VarDecl *Var = dyn_cast<VarDecl>(D)) {
975 // Warn about constructs like:
976 // if (void *X = foo()) { ... } else { X }.
977 // In the else block, the pointer is always false.
978
979 // FIXME: In a template instantiation, we don't have scope
980 // information to check this property.
981 if (Var->isDeclaredInCondition() && Var->getType()->isScalarType()) {
982 Scope *CheckS = S;
983 while (CheckS) {
984 if (CheckS->isWithinElse() &&
985 CheckS->getControlParent()->isDeclScope(DeclPtrTy::make(Var))) {
986 if (Var->getType()->isBooleanType())
987 ExprError(Diag(Loc, diag::warn_value_always_false)
988 << Var->getDeclName());
989 else
990 ExprError(Diag(Loc, diag::warn_value_always_zero)
991 << Var->getDeclName());
992 break;
993 }
994
995 // Move up one more control parent to check again.
996 CheckS = CheckS->getControlParent();
997 if (CheckS)
998 CheckS = CheckS->getParent();
999 }
1000 }
1001 } else if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) {
1002 if (!getLangOptions().CPlusPlus && !Func->hasPrototype()) {
1003 // C99 DR 316 says that, if a function type comes from a
1004 // function definition (without a prototype), that type is only
1005 // used for checking compatibility. Therefore, when referencing
1006 // the function, we pretend that we don't have the full function
1007 // type.
1008 if (DiagnoseUseOfDecl(Func, Loc))
1009 return ExprError();
976
1010
1011 QualType T = Func->getType();
1012 QualType NoProtoType = T;
1013 if (const FunctionProtoType *Proto = T->getAsFunctionProtoType())
1014 NoProtoType = Context.getFunctionNoProtoType(Proto->getResultType());
1015 return BuildDeclRefExpr(Func, NoProtoType, Loc, false, false, SS);
1016 }
1017 }
1018
1019 return BuildDeclarationNameExpr(Loc, D, HasTrailingLParen, SS, isAddressOfOperand);
1020}
1021
1022/// \brief Complete semantic analysis for a reference to the given declaration.
1023Sema::OwningExprResult
1024Sema::BuildDeclarationNameExpr(SourceLocation Loc, NamedDecl *D,
1025 bool HasTrailingLParen,
1026 const CXXScopeSpec *SS,
1027 bool isAddressOfOperand) {
1028 assert(D && "Cannot refer to a NULL declaration");
1029 DeclarationName Name = D->getDeclName();
1030
977 // If this is an expression of the form &Class::member, don't build an
978 // implicit member ref, because we want a pointer to the member in general,
979 // not any specific instance's member.
980 if (isAddressOfOperand && SS && !SS->isEmpty() && !HasTrailingLParen) {
981 DeclContext *DC = computeDeclContext(*SS);
982 if (D && isa<CXXRecordDecl>(DC)) {
983 QualType DType;
984 if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {

--- 107 unchanged lines hidden (view full) ---

1092 return BuildDeclRefExpr(Template, Context.OverloadTy, Loc,
1093 false, false, SS);
1094 ValueDecl *VD = cast<ValueDecl>(D);
1095
1096 // Check whether this declaration can be used. Note that we suppress
1097 // this check when we're going to perform argument-dependent lookup
1098 // on this function name, because this might not be the function
1099 // that overload resolution actually selects.
1031 // If this is an expression of the form &Class::member, don't build an
1032 // implicit member ref, because we want a pointer to the member in general,
1033 // not any specific instance's member.
1034 if (isAddressOfOperand && SS && !SS->isEmpty() && !HasTrailingLParen) {
1035 DeclContext *DC = computeDeclContext(*SS);
1036 if (D && isa<CXXRecordDecl>(DC)) {
1037 QualType DType;
1038 if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {

--- 107 unchanged lines hidden (view full) ---

1146 return BuildDeclRefExpr(Template, Context.OverloadTy, Loc,
1147 false, false, SS);
1148 ValueDecl *VD = cast<ValueDecl>(D);
1149
1150 // Check whether this declaration can be used. Note that we suppress
1151 // this check when we're going to perform argument-dependent lookup
1152 // on this function name, because this might not be the function
1153 // that overload resolution actually selects.
1154 bool ADL = getLangOptions().CPlusPlus && (!SS || !SS->isSet()) &&
1155 HasTrailingLParen;
1100 if (!(ADL && isa<FunctionDecl>(VD)) && DiagnoseUseOfDecl(VD, Loc))
1101 return ExprError();
1102
1156 if (!(ADL && isa<FunctionDecl>(VD)) && DiagnoseUseOfDecl(VD, Loc))
1157 return ExprError();
1158
1103 if (VarDecl *Var = dyn_cast<VarDecl>(VD)) {
1104 // Warn about constructs like:
1105 // if (void *X = foo()) { ... } else { X }.
1106 // In the else block, the pointer is always false.
1107
1108 // FIXME: In a template instantiation, we don't have scope
1109 // information to check this property.
1110 if (Var->isDeclaredInCondition() && Var->getType()->isScalarType()) {
1111 Scope *CheckS = S;
1112 while (CheckS) {
1113 if (CheckS->isWithinElse() &&
1114 CheckS->getControlParent()->isDeclScope(DeclPtrTy::make(Var))) {
1115 if (Var->getType()->isBooleanType())
1116 ExprError(Diag(Loc, diag::warn_value_always_false)
1117 << Var->getDeclName());
1118 else
1119 ExprError(Diag(Loc, diag::warn_value_always_zero)
1120 << Var->getDeclName());
1121 break;
1122 }
1123
1124 // Move up one more control parent to check again.
1125 CheckS = CheckS->getControlParent();
1126 if (CheckS)
1127 CheckS = CheckS->getParent();
1128 }
1129 }
1130 } else if (FunctionDecl *Func = dyn_cast<FunctionDecl>(VD)) {
1131 if (!getLangOptions().CPlusPlus && !Func->hasPrototype()) {
1132 // C99 DR 316 says that, if a function type comes from a
1133 // function definition (without a prototype), that type is only
1134 // used for checking compatibility. Therefore, when referencing
1135 // the function, we pretend that we don't have the full function
1136 // type.
1137 QualType T = Func->getType();
1138 QualType NoProtoType = T;
1139 if (const FunctionProtoType *Proto = T->getAsFunctionProtoType())
1140 NoProtoType = Context.getFunctionNoProtoType(Proto->getResultType());
1141 return BuildDeclRefExpr(VD, NoProtoType, Loc, false, false, SS);
1142 }
1143 }
1144
1145 // Only create DeclRefExpr's for valid Decl's.
1146 if (VD->isInvalidDecl())
1147 return ExprError();
1148
1149 // If the identifier reference is inside a block, and it refers to a value
1150 // that is outside the block, create a BlockDeclRefExpr instead of a
1151 // DeclRefExpr. This ensures the value is treated as a copy-in snapshot when
1152 // the block is formed.
1153 //
1154 // We do not do this for things like enum constants, global variables, etc,
1155 // as they do not get snapshotted.
1156 //
1157 if (CurBlock && ShouldSnapshotBlockValueReference(CurBlock, VD)) {
1158 MarkDeclarationReferenced(Loc, VD);
1159 QualType ExprTy = VD->getType().getNonReferenceType();
1160 // The BlocksAttr indicates the variable is bound by-reference.
1159 // Only create DeclRefExpr's for valid Decl's.
1160 if (VD->isInvalidDecl())
1161 return ExprError();
1162
1163 // If the identifier reference is inside a block, and it refers to a value
1164 // that is outside the block, create a BlockDeclRefExpr instead of a
1165 // DeclRefExpr. This ensures the value is treated as a copy-in snapshot when
1166 // the block is formed.
1167 //
1168 // We do not do this for things like enum constants, global variables, etc,
1169 // as they do not get snapshotted.
1170 //
1171 if (CurBlock && ShouldSnapshotBlockValueReference(CurBlock, VD)) {
1172 MarkDeclarationReferenced(Loc, VD);
1173 QualType ExprTy = VD->getType().getNonReferenceType();
1174 // The BlocksAttr indicates the variable is bound by-reference.
1161 if (VD->getAttr<BlocksAttr>(Context))
1175 if (VD->getAttr())
1162 return Owned(new (Context) BlockDeclRefExpr(VD, ExprTy, Loc, true));
1163 // This is to record that a 'const' was actually synthesize and added.
1164 bool constAdded = !ExprTy.isConstQualified();
1165 // Variable will be bound by-copy, make it const within the closure.
1166
1167 ExprTy.addConst();
1168 return Owned(new (Context) BlockDeclRefExpr(VD, ExprTy, Loc, false,
1169 constAdded));

--- 135 unchanged lines hidden (view full) ---

1305 Ty = Context.DoubleTy;
1306 else
1307 Ty = Context.LongDoubleTy;
1308
1309 const llvm::fltSemantics &Format = Context.getFloatTypeSemantics(Ty);
1310
1311 // isExact will be set by GetFloatValue().
1312 bool isExact = false;
1176 return Owned(new (Context) BlockDeclRefExpr(VD, ExprTy, Loc, true));
1177 // This is to record that a 'const' was actually synthesize and added.
1178 bool constAdded = !ExprTy.isConstQualified();
1179 // Variable will be bound by-copy, make it const within the closure.
1180
1181 ExprTy.addConst();
1182 return Owned(new (Context) BlockDeclRefExpr(VD, ExprTy, Loc, false,
1183 constAdded));

--- 135 unchanged lines hidden (view full) ---

1319 Ty = Context.DoubleTy;
1320 else
1321 Ty = Context.LongDoubleTy;
1322
1323 const llvm::fltSemantics &Format = Context.getFloatTypeSemantics(Ty);
1324
1325 // isExact will be set by GetFloatValue().
1326 bool isExact = false;
1313 Res = new (Context) FloatingLiteral(Literal.GetFloatValue(Format, &isExact),
1314 &isExact, Ty, Tok.getLocation());
1327 llvm::APFloat Val = Literal.GetFloatValue(Format, &isExact);
1328 Res = new (Context) FloatingLiteral(Val, isExact, Ty, Tok.getLocation());
1315
1316 } else if (!Literal.isIntegerLiteral()) {
1317 return ExprError();
1318 } else {
1319 QualType Ty;
1320
1321 // long long is a C99 feature.
1322 if (!getLangOptions().C99 && !getLangOptions().CPlusPlus0x &&

--- 661 unchanged lines hidden (view full) ---

1984 return VT; // should never get here (a typedef type should always be found).
1985}
1986
1987static Decl *FindGetterNameDeclFromProtocolList(const ObjCProtocolDecl*PDecl,
1988 IdentifierInfo &Member,
1989 const Selector &Sel,
1990 ASTContext &Context) {
1991
1329
1330 } else if (!Literal.isIntegerLiteral()) {
1331 return ExprError();
1332 } else {
1333 QualType Ty;
1334
1335 // long long is a C99 feature.
1336 if (!getLangOptions().C99 && !getLangOptions().CPlusPlus0x &&

--- 661 unchanged lines hidden (view full) ---

1998 return VT; // should never get here (a typedef type should always be found).
1999}
2000
2001static Decl *FindGetterNameDeclFromProtocolList(const ObjCProtocolDecl*PDecl,
2002 IdentifierInfo &Member,
2003 const Selector &Sel,
2004 ASTContext &Context) {
2005
1992 if (ObjCPropertyDecl *PD = PDecl->FindPropertyDeclaration(Context, &Member))
2006 if (ObjCPropertyDecl *PD = PDecl->FindPropertyDeclaration(&Member))
1993 return PD;
2007 return PD;
1994 if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Context, Sel))
2008 if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Sel))
1995 return OMD;
1996
1997 for (ObjCProtocolDecl::protocol_iterator I = PDecl->protocol_begin(),
1998 E = PDecl->protocol_end(); I != E; ++I) {
1999 if (Decl *D = FindGetterNameDeclFromProtocolList(*I, Member, Sel,
2000 Context))
2001 return D;
2002 }
2003 return 0;
2004}
2005
2006static Decl *FindGetterNameDecl(const ObjCObjectPointerType *QIdTy,
2007 IdentifierInfo &Member,
2008 const Selector &Sel,
2009 ASTContext &Context) {
2010 // Check protocols on qualified interfaces.
2011 Decl *GDecl = 0;
2012 for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(),
2013 E = QIdTy->qual_end(); I != E; ++I) {
2009 return OMD;
2010
2011 for (ObjCProtocolDecl::protocol_iterator I = PDecl->protocol_begin(),
2012 E = PDecl->protocol_end(); I != E; ++I) {
2013 if (Decl *D = FindGetterNameDeclFromProtocolList(*I, Member, Sel,
2014 Context))
2015 return D;
2016 }
2017 return 0;
2018}
2019
2020static Decl *FindGetterNameDecl(const ObjCObjectPointerType *QIdTy,
2021 IdentifierInfo &Member,
2022 const Selector &Sel,
2023 ASTContext &Context) {
2024 // Check protocols on qualified interfaces.
2025 Decl *GDecl = 0;
2026 for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(),
2027 E = QIdTy->qual_end(); I != E; ++I) {
2014 if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(Context, &Member)) {
2028 if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(&Member)) {
2015 GDecl = PD;
2016 break;
2017 }
2018 // Also must look for a getter name which uses property syntax.
2029 GDecl = PD;
2030 break;
2031 }
2032 // Also must look for a getter name which uses property syntax.
2019 if (ObjCMethodDecl *OMD = (*I)->getInstanceMethod(Context, Sel)) {
2033 if (ObjCMethodDecl *OMD = (*I)->getInstanceMethod(Sel)) {
2020 GDecl = OMD;
2021 break;
2022 }
2023 }
2024 if (!GDecl) {
2025 for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(),
2026 E = QIdTy->qual_end(); I != E; ++I) {
2027 // Search in the protocol-qualifier list of current protocol.

--- 9 unchanged lines hidden (view full) ---

2037/// all base class implementations.
2038///
2039ObjCMethodDecl *Sema::FindMethodInNestedImplementations(
2040 const ObjCInterfaceDecl *IFace,
2041 const Selector &Sel) {
2042 ObjCMethodDecl *Method = 0;
2043 if (ObjCImplementationDecl *ImpDecl
2044 = LookupObjCImplementation(IFace->getIdentifier()))
2034 GDecl = OMD;
2035 break;
2036 }
2037 }
2038 if (!GDecl) {
2039 for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(),
2040 E = QIdTy->qual_end(); I != E; ++I) {
2041 // Search in the protocol-qualifier list of current protocol.

--- 9 unchanged lines hidden (view full) ---

2051/// all base class implementations.
2052///
2053ObjCMethodDecl *Sema::FindMethodInNestedImplementations(
2054 const ObjCInterfaceDecl *IFace,
2055 const Selector &Sel) {
2056 ObjCMethodDecl *Method = 0;
2057 if (ObjCImplementationDecl *ImpDecl
2058 = LookupObjCImplementation(IFace->getIdentifier()))
2045 Method = ImpDecl->getInstanceMethod(Context, Sel);
2059 Method = ImpDecl->getInstanceMethod(Sel);
2046
2047 if (!Method && IFace->getSuperClass())
2048 return FindMethodInNestedImplementations(IFace->getSuperClass(), Sel);
2049 return Method;
2050}
2051
2052Action::OwningExprResult
2053Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,

--- 142 unchanged lines hidden (view full) ---

2196 diag::err_typecheck_member_reference_unknown)
2197 << DeclarationName(&Member) << int(OpKind == tok::arrow));
2198 }
2199
2200 // Handle access to Objective-C instance variables, such as "Obj->ivar" and
2201 // (*Obj).ivar.
2202 if (const ObjCInterfaceType *IFTy = BaseType->getAsObjCInterfaceType()) {
2203 ObjCInterfaceDecl *ClassDeclared;
2060
2061 if (!Method && IFace->getSuperClass())
2062 return FindMethodInNestedImplementations(IFace->getSuperClass(), Sel);
2063 return Method;
2064}
2065
2066Action::OwningExprResult
2067Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,

--- 142 unchanged lines hidden (view full) ---

2210 diag::err_typecheck_member_reference_unknown)
2211 << DeclarationName(&Member) << int(OpKind == tok::arrow));
2212 }
2213
2214 // Handle access to Objective-C instance variables, such as "Obj->ivar" and
2215 // (*Obj).ivar.
2216 if (const ObjCInterfaceType *IFTy = BaseType->getAsObjCInterfaceType()) {
2217 ObjCInterfaceDecl *ClassDeclared;
2204 if (ObjCIvarDecl *IV = IFTy->getDecl()->lookupInstanceVariable(Context,
2205 &Member,
2218 if (ObjCIvarDecl *IV = IFTy->getDecl()->lookupInstanceVariable(&Member,
2206 ClassDeclared)) {
2207 // If the decl being referenced had an error, return an error for this
2208 // sub-expr without emitting another error, in order to avoid cascading
2209 // error cases.
2210 if (IV->isInvalidDecl())
2211 return ExprError();
2212
2213 // Check whether we can reference this field.

--- 43 unchanged lines hidden (view full) ---

2257 // pointer to a (potentially qualified) interface type.
2258 const PointerType *PTy;
2259 const ObjCInterfaceType *IFTy;
2260 if (OpKind == tok::period && (PTy = BaseType->getAsPointerType()) &&
2261 (IFTy = PTy->getPointeeType()->getAsObjCInterfaceType())) {
2262 ObjCInterfaceDecl *IFace = IFTy->getDecl();
2263
2264 // Search for a declared property first.
2219 ClassDeclared)) {
2220 // If the decl being referenced had an error, return an error for this
2221 // sub-expr without emitting another error, in order to avoid cascading
2222 // error cases.
2223 if (IV->isInvalidDecl())
2224 return ExprError();
2225
2226 // Check whether we can reference this field.

--- 43 unchanged lines hidden (view full) ---

2270 // pointer to a (potentially qualified) interface type.
2271 const PointerType *PTy;
2272 const ObjCInterfaceType *IFTy;
2273 if (OpKind == tok::period && (PTy = BaseType->getAsPointerType()) &&
2274 (IFTy = PTy->getPointeeType()->getAsObjCInterfaceType())) {
2275 ObjCInterfaceDecl *IFace = IFTy->getDecl();
2276
2277 // Search for a declared property first.
2265 if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(Context,
2266 &Member)) {
2278 if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(&Member)) {
2267 // Check whether we can reference this property.
2268 if (DiagnoseUseOfDecl(PD, MemberLoc))
2269 return ExprError();
2270 QualType ResTy = PD->getType();
2271 Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
2279 // Check whether we can reference this property.
2280 if (DiagnoseUseOfDecl(PD, MemberLoc))
2281 return ExprError();
2282 QualType ResTy = PD->getType();
2283 Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
2272 ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Context, Sel);
2284 ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Sel);
2273 if (DiagnosePropertyAccessorMismatch(PD, Getter, MemberLoc))
2274 ResTy = Getter->getResultType();
2275 return Owned(new (Context) ObjCPropertyRefExpr(PD, ResTy,
2276 MemberLoc, BaseExpr));
2277 }
2278
2279 // Check protocols on qualified interfaces.
2280 for (ObjCInterfaceType::qual_iterator I = IFTy->qual_begin(),
2281 E = IFTy->qual_end(); I != E; ++I)
2285 if (DiagnosePropertyAccessorMismatch(PD, Getter, MemberLoc))
2286 ResTy = Getter->getResultType();
2287 return Owned(new (Context) ObjCPropertyRefExpr(PD, ResTy,
2288 MemberLoc, BaseExpr));
2289 }
2290
2291 // Check protocols on qualified interfaces.
2292 for (ObjCInterfaceType::qual_iterator I = IFTy->qual_begin(),
2293 E = IFTy->qual_end(); I != E; ++I)
2282 if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(Context,
2283 &Member)) {
2294 if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(&Member)) {
2284 // Check whether we can reference this property.
2285 if (DiagnoseUseOfDecl(PD, MemberLoc))
2286 return ExprError();
2287
2288 return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
2289 MemberLoc, BaseExpr));
2290 }
2291
2292 // If that failed, look for an "implicit" property by seeing if the nullary
2293 // selector is implemented.
2294
2295 // FIXME: The logic for looking up nullary and unary selectors should be
2296 // shared with the code in ActOnInstanceMessage.
2297
2298 Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
2295 // Check whether we can reference this property.
2296 if (DiagnoseUseOfDecl(PD, MemberLoc))
2297 return ExprError();
2298
2299 return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
2300 MemberLoc, BaseExpr));
2301 }
2302
2303 // If that failed, look for an "implicit" property by seeing if the nullary
2304 // selector is implemented.
2305
2306 // FIXME: The logic for looking up nullary and unary selectors should be
2307 // shared with the code in ActOnInstanceMessage.
2308
2309 Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
2299 ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Context, Sel);
2310 ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Sel);
2300
2301 // If this reference is in an @implementation, check for 'private' methods.
2302 if (!Getter)
2303 Getter = FindMethodInNestedImplementations(IFace, Sel);
2304
2305 // Look through local category implementations associated with the class.
2306 if (!Getter) {
2307 for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Getter; i++) {
2308 if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
2311
2312 // If this reference is in an @implementation, check for 'private' methods.
2313 if (!Getter)
2314 Getter = FindMethodInNestedImplementations(IFace, Sel);
2315
2316 // Look through local category implementations associated with the class.
2317 if (!Getter) {
2318 for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Getter; i++) {
2319 if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
2309 Getter = ObjCCategoryImpls[i]->getInstanceMethod(Context, Sel);
2320 Getter = ObjCCategoryImpls[i]->getInstanceMethod(Sel);
2310 }
2311 }
2312 if (Getter) {
2313 // Check if we can reference this property.
2314 if (DiagnoseUseOfDecl(Getter, MemberLoc))
2315 return ExprError();
2316 }
2317 // If we found a getter then this may be a valid dot-reference, we
2318 // will look for the matching setter, in case it is needed.
2319 Selector SetterSel =
2320 SelectorTable::constructSetterName(PP.getIdentifierTable(),
2321 PP.getSelectorTable(), &Member);
2321 }
2322 }
2323 if (Getter) {
2324 // Check if we can reference this property.
2325 if (DiagnoseUseOfDecl(Getter, MemberLoc))
2326 return ExprError();
2327 }
2328 // If we found a getter then this may be a valid dot-reference, we
2329 // will look for the matching setter, in case it is needed.
2330 Selector SetterSel =
2331 SelectorTable::constructSetterName(PP.getIdentifierTable(),
2332 PP.getSelectorTable(), &Member);
2322 ObjCMethodDecl *Setter = IFace->lookupInstanceMethod(Context, SetterSel);
2333 ObjCMethodDecl *Setter = IFace->lookupInstanceMethod(SetterSel);
2323 if (!Setter) {
2324 // If this reference is in an @implementation, also check for 'private'
2325 // methods.
2326 Setter = FindMethodInNestedImplementations(IFace, SetterSel);
2327 }
2328 // Look through local category implementations associated with the class.
2329 if (!Setter) {
2330 for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Setter; i++) {
2331 if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
2334 if (!Setter) {
2335 // If this reference is in an @implementation, also check for 'private'
2336 // methods.
2337 Setter = FindMethodInNestedImplementations(IFace, SetterSel);
2338 }
2339 // Look through local category implementations associated with the class.
2340 if (!Setter) {
2341 for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Setter; i++) {
2342 if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
2332 Setter = ObjCCategoryImpls[i]->getInstanceMethod(Context, SetterSel);
2343 Setter = ObjCCategoryImpls[i]->getInstanceMethod(SetterSel);
2333 }
2334 }
2335
2336 if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
2337 return ExprError();
2338
2339 if (Getter || Setter) {
2340 QualType PType;

--- 44 unchanged lines hidden (view full) ---

2385 // Handle properties on ObjC 'Class' types.
2386 if (OpKind == tok::period && (BaseType == Context.getObjCClassType())) {
2387 // Also must look for a getter name which uses property syntax.
2388 Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
2389 if (ObjCMethodDecl *MD = getCurMethodDecl()) {
2390 ObjCInterfaceDecl *IFace = MD->getClassInterface();
2391 ObjCMethodDecl *Getter;
2392 // FIXME: need to also look locally in the implementation.
2344 }
2345 }
2346
2347 if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
2348 return ExprError();
2349
2350 if (Getter || Setter) {
2351 QualType PType;

--- 44 unchanged lines hidden (view full) ---

2396 // Handle properties on ObjC 'Class' types.
2397 if (OpKind == tok::period && (BaseType == Context.getObjCClassType())) {
2398 // Also must look for a getter name which uses property syntax.
2399 Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
2400 if (ObjCMethodDecl *MD = getCurMethodDecl()) {
2401 ObjCInterfaceDecl *IFace = MD->getClassInterface();
2402 ObjCMethodDecl *Getter;
2403 // FIXME: need to also look locally in the implementation.
2393 if ((Getter = IFace->lookupClassMethod(Context, Sel))) {
2404 if ((Getter = IFace->lookupClassMethod(Sel))) {
2394 // Check the use of this method.
2395 if (DiagnoseUseOfDecl(Getter, MemberLoc))
2396 return ExprError();
2397 }
2398 // If we found a getter then this may be a valid dot-reference, we
2399 // will look for the matching setter, in case it is needed.
2400 Selector SetterSel =
2401 SelectorTable::constructSetterName(PP.getIdentifierTable(),
2402 PP.getSelectorTable(), &Member);
2405 // Check the use of this method.
2406 if (DiagnoseUseOfDecl(Getter, MemberLoc))
2407 return ExprError();
2408 }
2409 // If we found a getter then this may be a valid dot-reference, we
2410 // will look for the matching setter, in case it is needed.
2411 Selector SetterSel =
2412 SelectorTable::constructSetterName(PP.getIdentifierTable(),
2413 PP.getSelectorTable(), &Member);
2403 ObjCMethodDecl *Setter = IFace->lookupClassMethod(Context, SetterSel);
2414 ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel);
2404 if (!Setter) {
2405 // If this reference is in an @implementation, also check for 'private'
2406 // methods.
2407 Setter = FindMethodInNestedImplementations(IFace, SetterSel);
2408 }
2409 // Look through local category implementations associated with the class.
2410 if (!Setter) {
2411 for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Setter; i++) {
2412 if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
2415 if (!Setter) {
2416 // If this reference is in an @implementation, also check for 'private'
2417 // methods.
2418 Setter = FindMethodInNestedImplementations(IFace, SetterSel);
2419 }
2420 // Look through local category implementations associated with the class.
2421 if (!Setter) {
2422 for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Setter; i++) {
2423 if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
2413 Setter = ObjCCategoryImpls[i]->getClassMethod(Context, SetterSel);
2424 Setter = ObjCCategoryImpls[i]->getClassMethod(SetterSel);
2414 }
2415 }
2416
2417 if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
2418 return ExprError();
2419
2420 if (Getter || Setter) {
2421 QualType PType;

--- 197 unchanged lines hidden (view full) ---

2619 isa<CXXMethodDecl>(
2620 cast<FunctionTemplateDecl>(MemDecl)->getTemplatedDecl())))
2621 return Owned(BuildCallToMemberFunction(S, Fn, LParenLoc, Args, NumArgs,
2622 CommaLocs, RParenLoc));
2623 }
2624 }
2625
2626 // If we're directly calling a function, get the appropriate declaration.
2425 }
2426 }
2427
2428 if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
2429 return ExprError();
2430
2431 if (Getter || Setter) {
2432 QualType PType;

--- 197 unchanged lines hidden (view full) ---

2630 isa<CXXMethodDecl>(
2631 cast<FunctionTemplateDecl>(MemDecl)->getTemplatedDecl())))
2632 return Owned(BuildCallToMemberFunction(S, Fn, LParenLoc, Args, NumArgs,
2633 CommaLocs, RParenLoc));
2634 }
2635 }
2636
2637 // If we're directly calling a function, get the appropriate declaration.
2627 DeclRefExpr *DRExpr = NULL;
2638 // Also, in C++, keep track of whether we should perform argument-dependent
2639 // lookup and whether there were any explicitly-specified template arguments.
2628 Expr *FnExpr = Fn;
2629 bool ADL = true;
2640 Expr *FnExpr = Fn;
2641 bool ADL = true;
2642 bool HasExplicitTemplateArgs = 0;
2643 const TemplateArgument *ExplicitTemplateArgs = 0;
2644 unsigned NumExplicitTemplateArgs = 0;
2630 while (true) {
2631 if (ImplicitCastExpr *IcExpr = dyn_cast<ImplicitCastExpr>(FnExpr))
2632 FnExpr = IcExpr->getSubExpr();
2633 else if (ParenExpr *PExpr = dyn_cast<ParenExpr>(FnExpr)) {
2634 // Parentheses around a function disable ADL
2635 // (C++0x [basic.lookup.argdep]p1).
2636 ADL = false;
2637 FnExpr = PExpr->getSubExpr();
2638 } else if (isa<UnaryOperator>(FnExpr) &&
2639 cast<UnaryOperator>(FnExpr)->getOpcode()
2640 == UnaryOperator::AddrOf) {
2641 FnExpr = cast<UnaryOperator>(FnExpr)->getSubExpr();
2645 while (true) {
2646 if (ImplicitCastExpr *IcExpr = dyn_cast<ImplicitCastExpr>(FnExpr))
2647 FnExpr = IcExpr->getSubExpr();
2648 else if (ParenExpr *PExpr = dyn_cast<ParenExpr>(FnExpr)) {
2649 // Parentheses around a function disable ADL
2650 // (C++0x [basic.lookup.argdep]p1).
2651 ADL = false;
2652 FnExpr = PExpr->getSubExpr();
2653 } else if (isa<UnaryOperator>(FnExpr) &&
2654 cast<UnaryOperator>(FnExpr)->getOpcode()
2655 == UnaryOperator::AddrOf) {
2656 FnExpr = cast<UnaryOperator>(FnExpr)->getSubExpr();
2642 } else if ((DRExpr = dyn_cast<DeclRefExpr>(FnExpr))) {
2657 } else if (DeclRefExpr *DRExpr = dyn_cast<DeclRefExpr>(FnExpr)) {
2643 // Qualified names disable ADL (C++0x [basic.lookup.argdep]p1).
2644 ADL &= !isa<QualifiedDeclRefExpr>(DRExpr);
2658 // Qualified names disable ADL (C++0x [basic.lookup.argdep]p1).
2659 ADL &= !isa<QualifiedDeclRefExpr>(DRExpr);
2660 NDecl = dyn_cast<NamedDecl>(DRExpr->getDecl());
2645 break;
2646 } else if (UnresolvedFunctionNameExpr *DepName
2647 = dyn_cast<UnresolvedFunctionNameExpr>(FnExpr)) {
2648 UnqualifiedName = DepName->getName();
2649 break;
2661 break;
2662 } else if (UnresolvedFunctionNameExpr *DepName
2663 = dyn_cast<UnresolvedFunctionNameExpr>(FnExpr)) {
2664 UnqualifiedName = DepName->getName();
2665 break;
2666 } else if (TemplateIdRefExpr *TemplateIdRef
2667 = dyn_cast<TemplateIdRefExpr>(FnExpr)) {
2668 NDecl = TemplateIdRef->getTemplateName().getAsTemplateDecl();
2669 HasExplicitTemplateArgs = true;
2670 ExplicitTemplateArgs = TemplateIdRef->getTemplateArgs();
2671 NumExplicitTemplateArgs = TemplateIdRef->getNumTemplateArgs();
2672
2673 // C++ [temp.arg.explicit]p6:
2674 // [Note: For simple function names, argument dependent lookup (3.4.2)
2675 // applies even when the function name is not visible within the
2676 // scope of the call. This is because the call still has the syntactic
2677 // form of a function call (3.4.1). But when a function template with
2678 // explicit template arguments is used, the call does not have the
2679 // correct syntactic form unless there is a function template with
2680 // that name visible at the point of the call. If no such name is
2681 // visible, the call is not syntactically well-formed and
2682 // argument-dependent lookup does not apply. If some such name is
2683 // visible, argument dependent lookup applies and additional function
2684 // templates may be found in other namespaces.
2685 //
2686 // The summary of this paragraph is that, if we get to this point and the
2687 // template-id was not a qualified name, then argument-dependent lookup
2688 // is still possible.
2689 if (TemplateIdRef->getQualifier())
2690 ADL = false;
2691 break;
2650 } else {
2651 // Any kind of name that does not refer to a declaration (or
2652 // set of declarations) disables ADL (C++0x [basic.lookup.argdep]p3).
2653 ADL = false;
2654 break;
2655 }
2656 }
2657
2658 OverloadedFunctionDecl *Ovl = 0;
2659 FunctionTemplateDecl *FunctionTemplate = 0;
2692 } else {
2693 // Any kind of name that does not refer to a declaration (or
2694 // set of declarations) disables ADL (C++0x [basic.lookup.argdep]p3).
2695 ADL = false;
2696 break;
2697 }
2698 }
2699
2700 OverloadedFunctionDecl *Ovl = 0;
2701 FunctionTemplateDecl *FunctionTemplate = 0;
2660 if (DRExpr) {
2661 FDecl = dyn_cast<FunctionDecl>(DRExpr->getDecl());
2662 if ((FunctionTemplate = dyn_cast<FunctionTemplateDecl>(DRExpr->getDecl())))
2702 if (NDecl) {
2703 FDecl = dyn_cast<FunctionDecl>(NDecl);
2704 if ((FunctionTemplate = dyn_cast<FunctionTemplateDecl>(NDecl)))
2663 FDecl = FunctionTemplate->getTemplatedDecl();
2664 else
2705 FDecl = FunctionTemplate->getTemplatedDecl();
2706 else
2665 FDecl = dyn_cast<FunctionDecl>(DRExpr->getDecl());
2666 Ovl = dyn_cast<OverloadedFunctionDecl>(DRExpr->getDecl());
2667 NDecl = dyn_cast<NamedDecl>(DRExpr->getDecl());
2707 FDecl = dyn_cast<FunctionDecl>(NDecl);
2708 Ovl = dyn_cast<OverloadedFunctionDecl>(NDecl);
2668 }
2669
2670 if (Ovl || FunctionTemplate ||
2671 (getLangOptions().CPlusPlus && (FDecl || UnqualifiedName))) {
2672 // We don't perform ADL for implicit declarations of builtins.
2673 if (FDecl && FDecl->getBuiltinID(Context) && FDecl->isImplicit())
2674 ADL = false;
2675
2676 // We don't perform ADL in C.
2677 if (!getLangOptions().CPlusPlus)
2678 ADL = false;
2679
2680 if (Ovl || FunctionTemplate || ADL) {
2709 }
2710
2711 if (Ovl || FunctionTemplate ||
2712 (getLangOptions().CPlusPlus && (FDecl || UnqualifiedName))) {
2713 // We don't perform ADL for implicit declarations of builtins.
2714 if (FDecl && FDecl->getBuiltinID(Context) && FDecl->isImplicit())
2715 ADL = false;
2716
2717 // We don't perform ADL in C.
2718 if (!getLangOptions().CPlusPlus)
2719 ADL = false;
2720
2721 if (Ovl || FunctionTemplate || ADL) {
2681 FDecl = ResolveOverloadedCallFn(Fn, DRExpr? DRExpr->getDecl() : 0,
2682 UnqualifiedName, LParenLoc, Args,
2683 NumArgs, CommaLocs, RParenLoc, ADL);
2722 FDecl = ResolveOverloadedCallFn(Fn, NDecl, UnqualifiedName,
2723 HasExplicitTemplateArgs,
2724 ExplicitTemplateArgs,
2725 NumExplicitTemplateArgs,
2726 LParenLoc, Args, NumArgs, CommaLocs,
2727 RParenLoc, ADL);
2684 if (!FDecl)
2685 return ExprError();
2686
2687 // Update Fn to refer to the actual function selected.
2688 Expr *NewFn = 0;
2689 if (QualifiedDeclRefExpr *QDRExpr
2728 if (!FDecl)
2729 return ExprError();
2730
2731 // Update Fn to refer to the actual function selected.
2732 Expr *NewFn = 0;
2733 if (QualifiedDeclRefExpr *QDRExpr
2690 = dyn_cast_or_null<QualifiedDeclRefExpr>(DRExpr))
2734 = dyn_cast<QualifiedDeclRefExpr>(FnExpr))
2691 NewFn = new (Context) QualifiedDeclRefExpr(FDecl, FDecl->getType(),
2692 QDRExpr->getLocation(),
2693 false, false,
2694 QDRExpr->getQualifierRange(),
2695 QDRExpr->getQualifier());
2696 else
2697 NewFn = new (Context) DeclRefExpr(FDecl, FDecl->getType(),
2698 Fn->getSourceRange().getBegin());

--- 46 unchanged lines hidden (view full) ---

2745 return ExprError();
2746 } else {
2747 assert(isa<FunctionNoProtoType>(FuncT) && "Unknown FunctionType!");
2748
2749 if (FDecl) {
2750 // Check if we have too few/too many template arguments, based
2751 // on our knowledge of the function definition.
2752 const FunctionDecl *Def = 0;
2735 NewFn = new (Context) QualifiedDeclRefExpr(FDecl, FDecl->getType(),
2736 QDRExpr->getLocation(),
2737 false, false,
2738 QDRExpr->getQualifierRange(),
2739 QDRExpr->getQualifier());
2740 else
2741 NewFn = new (Context) DeclRefExpr(FDecl, FDecl->getType(),
2742 Fn->getSourceRange().getBegin());

--- 46 unchanged lines hidden (view full) ---

2789 return ExprError();
2790 } else {
2791 assert(isa<FunctionNoProtoType>(FuncT) && "Unknown FunctionType!");
2792
2793 if (FDecl) {
2794 // Check if we have too few/too many template arguments, based
2795 // on our knowledge of the function definition.
2796 const FunctionDecl *Def = 0;
2753 if (FDecl->getBody(Context, Def) && NumArgs != Def->param_size()) {
2797 if (FDecl->getBody(Def) && NumArgs != Def->param_size()) {
2754 const FunctionProtoType *Proto =
2755 Def->getType()->getAsFunctionProtoType();
2756 if (!Proto || !(Proto->isVariadic() && NumArgs >= Def->param_size())) {
2757 Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments)
2758 << (NumArgs > Def->param_size()) << FDecl << Fn->getSourceRange();
2759 }
2760 }
2761 }

--- 93 unchanged lines hidden (view full) ---

2855 // GCC struct/union extension: allow cast to self.
2856 // FIXME: Check that the cast destination type is complete.
2857 Diag(TyR.getBegin(), diag::ext_typecheck_cast_nonscalar)
2858 << castType << castExpr->getSourceRange();
2859 } else if (castType->isUnionType()) {
2860 // GCC cast to union extension
2861 RecordDecl *RD = castType->getAsRecordType()->getDecl();
2862 RecordDecl::field_iterator Field, FieldEnd;
2798 const FunctionProtoType *Proto =
2799 Def->getType()->getAsFunctionProtoType();
2800 if (!Proto || !(Proto->isVariadic() && NumArgs >= Def->param_size())) {
2801 Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments)
2802 << (NumArgs > Def->param_size()) << FDecl << Fn->getSourceRange();
2803 }
2804 }
2805 }

--- 93 unchanged lines hidden (view full) ---

2899 // GCC struct/union extension: allow cast to self.
2900 // FIXME: Check that the cast destination type is complete.
2901 Diag(TyR.getBegin(), diag::ext_typecheck_cast_nonscalar)
2902 << castType << castExpr->getSourceRange();
2903 } else if (castType->isUnionType()) {
2904 // GCC cast to union extension
2905 RecordDecl *RD = castType->getAsRecordType()->getDecl();
2906 RecordDecl::field_iterator Field, FieldEnd;
2863 for (Field = RD->field_begin(Context), FieldEnd = RD->field_end(Context);
2907 for (Field = RD->field_begin(), FieldEnd = RD->field_end();
2864 Field != FieldEnd; ++Field) {
2865 if (Context.getCanonicalType(Field->getType()).getUnqualifiedType() ==
2866 Context.getCanonicalType(castExpr->getType()).getUnqualifiedType()) {
2867 Diag(TyR.getBegin(), diag::ext_typecheck_cast_to_union)
2868 << castExpr->getSourceRange();
2869 break;
2870 }
2871 }

--- 54 unchanged lines hidden (view full) ---

2926 << VectorTy << Ty << R;
2927
2928 return false;
2929}
2930
2931bool Sema::CheckExtVectorCast(SourceRange R, QualType DestTy, QualType SrcTy) {
2932 assert(DestTy->isExtVectorType() && "Not an extended vector type!");
2933
2908 Field != FieldEnd; ++Field) {
2909 if (Context.getCanonicalType(Field->getType()).getUnqualifiedType() ==
2910 Context.getCanonicalType(castExpr->getType()).getUnqualifiedType()) {
2911 Diag(TyR.getBegin(), diag::ext_typecheck_cast_to_union)
2912 << castExpr->getSourceRange();
2913 break;
2914 }
2915 }

--- 54 unchanged lines hidden (view full) ---

2970 << VectorTy << Ty << R;
2971
2972 return false;
2973}
2974
2975bool Sema::CheckExtVectorCast(SourceRange R, QualType DestTy, QualType SrcTy) {
2976 assert(DestTy->isExtVectorType() && "Not an extended vector type!");
2977
2934 // If SrcTy is also an ExtVectorType, the types must be identical unless
2935 // lax vector conversions is enabled.
2936 if (SrcTy->isExtVectorType()) {
2937 if (getLangOptions().LaxVectorConversions &&
2938 Context.getTypeSize(DestTy) == Context.getTypeSize(SrcTy))
2939 return false;
2940 if (DestTy != SrcTy)
2941 return Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
2942 << DestTy << SrcTy << R;
2943 return false;
2944 }
2945
2946 // If SrcTy is a VectorType, then only the total size must match.
2978 // If SrcTy is a VectorType, the total size must match to explicitly cast to
2979 // an ExtVectorType.
2947 if (SrcTy->isVectorType()) {
2948 if (Context.getTypeSize(DestTy) != Context.getTypeSize(SrcTy))
2949 return Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
2950 << DestTy << SrcTy << R;
2951 return false;
2952 }
2953
2980 if (SrcTy->isVectorType()) {
2981 if (Context.getTypeSize(DestTy) != Context.getTypeSize(SrcTy))
2982 return Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
2983 << DestTy << SrcTy << R;
2984 return false;
2985 }
2986
2954 // All scalar -> ext vector "c-style" casts are legal; the appropriate
2987 // All non-pointer scalars can be cast to ExtVector type. The appropriate
2955 // conversion will take place first from scalar to elt type, and then
2956 // splat from elt type to vector.
2988 // conversion will take place first from scalar to elt type, and then
2989 // splat from elt type to vector.
2990 if (SrcTy->isPointerType())
2991 return Diag(R.getBegin(),
2992 diag::err_invalid_conversion_between_vector_and_scalar)
2993 << DestTy << SrcTy << R;
2957 return false;
2958}
2959
2960Action::OwningExprResult
2961Sema::ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
2962 SourceLocation RParenLoc, ExprArg Op) {
2963 assert((Ty != 0) && (Op.get() != 0) &&
2964 "ActOnCastExpr(): missing type or expr");

--- 72 unchanged lines hidden (view full) ---

3037 return LHSTy;
3038 }
3039 if ((RHSTy->isPointerType() || RHSTy->isBlockPointerType() ||
3040 Context.isObjCObjectPointerType(RHSTy)) &&
3041 LHS->isNullPointerConstant(Context)) {
3042 ImpCastExprToType(LHS, RHSTy); // promote the null to a pointer.
3043 return RHSTy;
3044 }
2994 return false;
2995}
2996
2997Action::OwningExprResult
2998Sema::ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
2999 SourceLocation RParenLoc, ExprArg Op) {
3000 assert((Ty != 0) && (Op.get() != 0) &&
3001 "ActOnCastExpr(): missing type or expr");

--- 72 unchanged lines hidden (view full) ---

3074 return LHSTy;
3075 }
3076 if ((RHSTy->isPointerType() || RHSTy->isBlockPointerType() ||
3077 Context.isObjCObjectPointerType(RHSTy)) &&
3078 LHS->isNullPointerConstant(Context)) {
3079 ImpCastExprToType(LHS, RHSTy); // promote the null to a pointer.
3080 return RHSTy;
3081 }
3082 // Handle block pointer types.
3083 if (LHSTy->isBlockPointerType() || RHSTy->isBlockPointerType()) {
3084 if (!LHSTy->isBlockPointerType() || !RHSTy->isBlockPointerType()) {
3085 if (LHSTy->isVoidPointerType() || RHSTy->isVoidPointerType()) {
3086 QualType destType = Context.getPointerType(Context.VoidTy);
3087 ImpCastExprToType(LHS, destType);
3088 ImpCastExprToType(RHS, destType);
3089 return destType;
3090 }
3091 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
3092 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3093 return QualType();
3094 }
3095 // We have 2 block pointer types.
3096 if (Context.getCanonicalType(LHSTy) == Context.getCanonicalType(RHSTy)) {
3097 // Two identical block pointer types are always compatible.
3098 return LHSTy;
3099 }
3100 // The block pointer types aren't identical, continue checking.
3101 QualType lhptee = LHSTy->getAsBlockPointerType()->getPointeeType();
3102 QualType rhptee = RHSTy->getAsBlockPointerType()->getPointeeType();
3045
3103
3046 const PointerType *LHSPT = LHSTy->getAsPointerType();
3047 const PointerType *RHSPT = RHSTy->getAsPointerType();
3048 const BlockPointerType *LHSBPT = LHSTy->getAsBlockPointerType();
3049 const BlockPointerType *RHSBPT = RHSTy->getAsBlockPointerType();
3104 if (!Context.typesAreCompatible(lhptee.getUnqualifiedType(),
3105 rhptee.getUnqualifiedType())) {
3106 Diag(QuestionLoc, diag::warn_typecheck_cond_incompatible_pointers)
3107 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3108 // In this situation, we assume void* type. No especially good
3109 // reason, but this is what gcc does, and we do have to pick
3110 // to get a consistent AST.
3111 QualType incompatTy = Context.getPointerType(Context.VoidTy);
3112 ImpCastExprToType(LHS, incompatTy);
3113 ImpCastExprToType(RHS, incompatTy);
3114 return incompatTy;
3115 }
3116 // The block pointer types are compatible.
3117 ImpCastExprToType(LHS, LHSTy);
3118 ImpCastExprToType(RHS, LHSTy);
3119 return LHSTy;
3120 }
3121 // Need to handle "id<xx>" explicitly. Unlike "id", whose canonical type
3122 // evaluates to "struct objc_object *" (and is handled above when comparing
3123 // id with statically typed objects).
3124 if (LHSTy->isObjCQualifiedIdType() || RHSTy->isObjCQualifiedIdType()) {
3125 // GCC allows qualified id and any Objective-C type to devolve to
3126 // id. Currently localizing to here until clear this should be
3127 // part of ObjCQualifiedIdTypesAreCompatible.
3128 if (ObjCQualifiedIdTypesAreCompatible(LHSTy, RHSTy, true) ||
3129 (LHSTy->isObjCQualifiedIdType() &&
3130 Context.isObjCObjectPointerType(RHSTy)) ||
3131 (RHSTy->isObjCQualifiedIdType() &&
3132 Context.isObjCObjectPointerType(LHSTy))) {
3133 // FIXME: This is not the correct composite type. This only happens to
3134 // work because id can more or less be used anywhere, however this may
3135 // change the type of method sends.
3050
3136
3051 // Handle the case where both operands are pointers before we handle null
3052 // pointer constants in case both operands are null pointer constants.
3053 if ((LHSPT || LHSBPT) && (RHSPT || RHSBPT)) { // C99 6.5.15p3,6
3137 // FIXME: gcc adds some type-checking of the arguments and emits
3138 // (confusing) incompatible comparison warnings in some
3139 // cases. Investigate.
3140 QualType compositeType = Context.getObjCIdType();
3141 ImpCastExprToType(LHS, compositeType);
3142 ImpCastExprToType(RHS, compositeType);
3143 return compositeType;
3144 }
3145 }
3146 // Check constraints for Objective-C object pointers types.
3147 if (Context.isObjCObjectPointerType(LHSTy) &&
3148 Context.isObjCObjectPointerType(RHSTy)) {
3149
3150 if (Context.getCanonicalType(LHSTy) == Context.getCanonicalType(RHSTy)) {
3151 // Two identical object pointer types are always compatible.
3152 return LHSTy;
3153 }
3154 // No need to check for block pointer types or qualified id types (they
3155 // were handled above).
3156 assert((LHSTy->isPointerType() && RHSTy->isPointerType()) &&
3157 "Sema::CheckConditionalOperands(): Unexpected type");
3158 QualType lhptee = LHSTy->getAsPointerType()->getPointeeType();
3159 QualType rhptee = RHSTy->getAsPointerType()->getPointeeType();
3160
3161 QualType compositeType = LHSTy;
3162
3163 // If both operands are interfaces and either operand can be
3164 // assigned to the other, use that type as the composite
3165 // type. This allows
3166 // xxx ? (A*) a : (B*) b
3167 // where B is a subclass of A.
3168 //
3169 // Additionally, as for assignment, if either type is 'id'
3170 // allow silent coercion. Finally, if the types are
3171 // incompatible then make sure to use 'id' as the composite
3172 // type so the result is acceptable for sending messages to.
3173
3174 // FIXME: Consider unifying with 'areComparableObjCPointerTypes'.
3175 // It could return the composite type.
3176 const ObjCInterfaceType* LHSIface = lhptee->getAsObjCInterfaceType();
3177 const ObjCInterfaceType* RHSIface = rhptee->getAsObjCInterfaceType();
3178 if (LHSIface && RHSIface &&
3179 Context.canAssignObjCInterfaces(LHSIface, RHSIface)) {
3180 compositeType = LHSTy;
3181 } else if (LHSIface && RHSIface &&
3182 Context.canAssignObjCInterfaces(RHSIface, LHSIface)) {
3183 compositeType = RHSTy;
3184 } else if (Context.isObjCIdStructType(lhptee) ||
3185 Context.isObjCIdStructType(rhptee)) {
3186 compositeType = Context.getObjCIdType();
3187 } else {
3188 Diag(QuestionLoc, diag::ext_typecheck_cond_incompatible_operands)
3189 << LHSTy << RHSTy
3190 << LHS->getSourceRange() << RHS->getSourceRange();
3191 QualType incompatTy = Context.getObjCIdType();
3192 ImpCastExprToType(LHS, incompatTy);
3193 ImpCastExprToType(RHS, incompatTy);
3194 return incompatTy;
3195 }
3196 // The object pointer types are compatible.
3197 ImpCastExprToType(LHS, compositeType);
3198 ImpCastExprToType(RHS, compositeType);
3199 return compositeType;
3200 }
3201 // Check constraints for C object pointers types (C99 6.5.15p3,6).
3202 if (LHSTy->isPointerType() && RHSTy->isPointerType()) {
3054 // get the "pointed to" types
3203 // get the "pointed to" types
3055 QualType lhptee = (LHSPT ? LHSPT->getPointeeType()
3056 : LHSBPT->getPointeeType());
3057 QualType rhptee = (RHSPT ? RHSPT->getPointeeType()
3058 : RHSBPT->getPointeeType());
3204 QualType lhptee = LHSTy->getAsPointerType()->getPointeeType();
3205 QualType rhptee = RHSTy->getAsPointerType()->getPointeeType();
3059
3060 // ignore qualifiers on void (C99 6.5.15p3, clause 6)
3206
3207 // ignore qualifiers on void (C99 6.5.15p3, clause 6)
3061 if (lhptee->isVoidType()
3062 && (RHSBPT || rhptee->isIncompleteOrObjectType())) {
3208 if (lhptee->isVoidType() && rhptee->isIncompleteOrObjectType()) {
3063 // Figure out necessary qualifiers (C99 6.5.15p6)
3064 QualType destPointee=lhptee.getQualifiedType(rhptee.getCVRQualifiers());
3065 QualType destType = Context.getPointerType(destPointee);
3066 ImpCastExprToType(LHS, destType); // add qualifiers if necessary
3067 ImpCastExprToType(RHS, destType); // promote to void*
3068 return destType;
3069 }
3209 // Figure out necessary qualifiers (C99 6.5.15p6)
3210 QualType destPointee=lhptee.getQualifiedType(rhptee.getCVRQualifiers());
3211 QualType destType = Context.getPointerType(destPointee);
3212 ImpCastExprToType(LHS, destType); // add qualifiers if necessary
3213 ImpCastExprToType(RHS, destType); // promote to void*
3214 return destType;
3215 }
3070 if (rhptee->isVoidType()
3071 && (LHSBPT || lhptee->isIncompleteOrObjectType())) {
3216 if (rhptee->isVoidType() && lhptee->isIncompleteOrObjectType()) {
3072 QualType destPointee=rhptee.getQualifiedType(lhptee.getCVRQualifiers());
3073 QualType destType = Context.getPointerType(destPointee);
3074 ImpCastExprToType(LHS, destType); // add qualifiers if necessary
3075 ImpCastExprToType(RHS, destType); // promote to void*
3076 return destType;
3077 }
3078
3217 QualType destPointee=rhptee.getQualifiedType(lhptee.getCVRQualifiers());
3218 QualType destType = Context.getPointerType(destPointee);
3219 ImpCastExprToType(LHS, destType); // add qualifiers if necessary
3220 ImpCastExprToType(RHS, destType); // promote to void*
3221 return destType;
3222 }
3223
3079 bool sameKind = (LHSPT && RHSPT) || (LHSBPT && RHSBPT);
3080 if (sameKind
3081 && Context.getCanonicalType(LHSTy) == Context.getCanonicalType(RHSTy)) {
3224 if (Context.getCanonicalType(LHSTy) == Context.getCanonicalType(RHSTy)) {
3082 // Two identical pointer types are always compatible.
3083 return LHSTy;
3084 }
3225 // Two identical pointer types are always compatible.
3226 return LHSTy;
3227 }
3085
3086 QualType compositeType = LHSTy;
3087
3088 // If either type is an Objective-C object type then check
3089 // compatibility according to Objective-C.
3090 if (Context.isObjCObjectPointerType(LHSTy) ||
3091 Context.isObjCObjectPointerType(RHSTy)) {
3092 // If both operands are interfaces and either operand can be
3093 // assigned to the other, use that type as the composite
3094 // type. This allows
3095 // xxx ? (A*) a : (B*) b
3096 // where B is a subclass of A.
3097 //
3098 // Additionally, as for assignment, if either type is 'id'
3099 // allow silent coercion. Finally, if the types are
3100 // incompatible then make sure to use 'id' as the composite
3101 // type so the result is acceptable for sending messages to.
3102
3103 // FIXME: Consider unifying with 'areComparableObjCPointerTypes'.
3104 // It could return the composite type.
3105 const ObjCInterfaceType* LHSIface = lhptee->getAsObjCInterfaceType();
3106 const ObjCInterfaceType* RHSIface = rhptee->getAsObjCInterfaceType();
3107 if (LHSIface && RHSIface &&
3108 Context.canAssignObjCInterfaces(LHSIface, RHSIface)) {
3109 compositeType = LHSTy;
3110 } else if (LHSIface && RHSIface &&
3111 Context.canAssignObjCInterfaces(RHSIface, LHSIface)) {
3112 compositeType = RHSTy;
3113 } else if (Context.isObjCIdStructType(lhptee) ||
3114 Context.isObjCIdStructType(rhptee)) {
3115 compositeType = Context.getObjCIdType();
3116 } else if (LHSBPT || RHSBPT) {
3117 if (!sameKind
3118 || !Context.typesAreCompatible(lhptee.getUnqualifiedType(),
3119 rhptee.getUnqualifiedType()))
3120 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
3121 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3122 return QualType();
3123 } else {
3124 Diag(QuestionLoc, diag::ext_typecheck_cond_incompatible_operands)
3125 << LHSTy << RHSTy
3126 << LHS->getSourceRange() << RHS->getSourceRange();
3127 QualType incompatTy = Context.getObjCIdType();
3128 ImpCastExprToType(LHS, incompatTy);
3129 ImpCastExprToType(RHS, incompatTy);
3130 return incompatTy;
3131 }
3132 } else if (!sameKind
3133 || !Context.typesAreCompatible(lhptee.getUnqualifiedType(),
3134 rhptee.getUnqualifiedType())) {
3228 if (!Context.typesAreCompatible(lhptee.getUnqualifiedType(),
3229 rhptee.getUnqualifiedType())) {
3135 Diag(QuestionLoc, diag::warn_typecheck_cond_incompatible_pointers)
3136 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3137 // In this situation, we assume void* type. No especially good
3138 // reason, but this is what gcc does, and we do have to pick
3139 // to get a consistent AST.
3140 QualType incompatTy = Context.getPointerType(Context.VoidTy);
3141 ImpCastExprToType(LHS, incompatTy);
3142 ImpCastExprToType(RHS, incompatTy);
3143 return incompatTy;
3144 }
3145 // The pointer types are compatible.
3146 // C99 6.5.15p6: If both operands are pointers to compatible types *or* to
3147 // differently qualified versions of compatible types, the result type is
3148 // a pointer to an appropriately qualified version of the *composite*
3149 // type.
3150 // FIXME: Need to calculate the composite type.
3151 // FIXME: Need to add qualifiers
3230 Diag(QuestionLoc, diag::warn_typecheck_cond_incompatible_pointers)
3231 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3232 // In this situation, we assume void* type. No especially good
3233 // reason, but this is what gcc does, and we do have to pick
3234 // to get a consistent AST.
3235 QualType incompatTy = Context.getPointerType(Context.VoidTy);
3236 ImpCastExprToType(LHS, incompatTy);
3237 ImpCastExprToType(RHS, incompatTy);
3238 return incompatTy;
3239 }
3240 // The pointer types are compatible.
3241 // C99 6.5.15p6: If both operands are pointers to compatible types *or* to
3242 // differently qualified versions of compatible types, the result type is
3243 // a pointer to an appropriately qualified version of the *composite*
3244 // type.
3245 // FIXME: Need to calculate the composite type.
3246 // FIXME: Need to add qualifiers
3152 ImpCastExprToType(LHS, compositeType);
3153 ImpCastExprToType(RHS, compositeType);
3154 return compositeType;
3247 ImpCastExprToType(LHS, LHSTy);
3248 ImpCastExprToType(RHS, LHSTy);
3249 return LHSTy;
3155 }
3250 }
3156
3251
3157 // GCC compatibility: soften pointer/integer mismatch.
3158 if (RHSTy->isPointerType() && LHSTy->isIntegerType()) {
3159 Diag(QuestionLoc, diag::warn_typecheck_cond_pointer_integer_mismatch)
3160 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3161 ImpCastExprToType(LHS, RHSTy); // promote the integer to a pointer.
3162 return RHSTy;
3163 }
3164 if (LHSTy->isPointerType() && RHSTy->isIntegerType()) {
3165 Diag(QuestionLoc, diag::warn_typecheck_cond_pointer_integer_mismatch)
3166 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3167 ImpCastExprToType(RHS, LHSTy); // promote the integer to a pointer.
3168 return LHSTy;
3169 }
3170
3252 // GCC compatibility: soften pointer/integer mismatch.
3253 if (RHSTy->isPointerType() && LHSTy->isIntegerType()) {
3254 Diag(QuestionLoc, diag::warn_typecheck_cond_pointer_integer_mismatch)
3255 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3256 ImpCastExprToType(LHS, RHSTy); // promote the integer to a pointer.
3257 return RHSTy;
3258 }
3259 if (LHSTy->isPointerType() && RHSTy->isIntegerType()) {
3260 Diag(QuestionLoc, diag::warn_typecheck_cond_pointer_integer_mismatch)
3261 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3262 ImpCastExprToType(RHS, LHSTy); // promote the integer to a pointer.
3263 return LHSTy;
3264 }
3265
3171 // Need to handle "id<xx>" explicitly. Unlike "id", whose canonical type
3172 // evaluates to "struct objc_object *" (and is handled above when comparing
3173 // id with statically typed objects).
3174 if (LHSTy->isObjCQualifiedIdType() || RHSTy->isObjCQualifiedIdType()) {
3175 // GCC allows qualified id and any Objective-C type to devolve to
3176 // id. Currently localizing to here until clear this should be
3177 // part of ObjCQualifiedIdTypesAreCompatible.
3178 if (ObjCQualifiedIdTypesAreCompatible(LHSTy, RHSTy, true) ||
3179 (LHSTy->isObjCQualifiedIdType() &&
3180 Context.isObjCObjectPointerType(RHSTy)) ||
3181 (RHSTy->isObjCQualifiedIdType() &&
3182 Context.isObjCObjectPointerType(LHSTy))) {
3183 // FIXME: This is not the correct composite type. This only happens to
3184 // work because id can more or less be used anywhere, however this may
3185 // change the type of method sends.
3186
3187 // FIXME: gcc adds some type-checking of the arguments and emits
3188 // (confusing) incompatible comparison warnings in some
3189 // cases. Investigate.
3190 QualType compositeType = Context.getObjCIdType();
3191 ImpCastExprToType(LHS, compositeType);
3192 ImpCastExprToType(RHS, compositeType);
3193 return compositeType;
3194 }
3195 }
3196
3197 // Otherwise, the operands are not compatible.
3198 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
3199 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3200 return QualType();
3201}
3202
3203/// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
3204/// in the case of a the GNU conditional expr extension.

--- 175 unchanged lines hidden (view full) ---

3380 // Relax integer conversions like we do for pointers below.
3381 if (rhsType->isIntegerType())
3382 return IntToPointer;
3383 if (lhsType->isIntegerType())
3384 return PointerToInt;
3385 return IncompatibleObjCQualifiedId;
3386 }
3387
3266 // Otherwise, the operands are not compatible.
3267 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
3268 << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
3269 return QualType();
3270}
3271
3272/// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
3273/// in the case of a the GNU conditional expr extension.

--- 175 unchanged lines hidden (view full) ---

3449 // Relax integer conversions like we do for pointers below.
3450 if (rhsType->isIntegerType())
3451 return IntToPointer;
3452 if (lhsType->isIntegerType())
3453 return PointerToInt;
3454 return IncompatibleObjCQualifiedId;
3455 }
3456
3457 // Allow scalar to ExtVector assignments, and assignments of an ExtVector type
3458 // to the same ExtVector type.
3459 if (lhsType->isExtVectorType()) {
3460 if (rhsType->isExtVectorType())
3461 return lhsType == rhsType ? Compatible : Incompatible;
3462 if (!rhsType->isVectorType() && rhsType->isArithmeticType())
3463 return Compatible;
3464 }
3465
3388 if (lhsType->isVectorType() || rhsType->isVectorType()) {
3466 if (lhsType->isVectorType() || rhsType->isVectorType()) {
3389 // For ExtVector, allow vector splats; float -> <n x float>
3390 if (const ExtVectorType *LV = lhsType->getAsExtVectorType())
3391 if (LV->getElementType() == rhsType)
3392 return Compatible;
3393
3394 // If we are allowing lax vector conversions, and LHS and RHS are both
3395 // vectors, the total size only needs to be the same. This is a bitcast;
3396 // no bits are changed but the result type is different.
3397 if (getLangOptions().LaxVectorConversions &&
3398 lhsType->isVectorType() && rhsType->isVectorType()) {
3399 if (Context.getTypeSize(lhsType) == Context.getTypeSize(rhsType))
3400 return IncompatibleVectors;
3401 }

--- 85 unchanged lines hidden (view full) ---

3487
3488Sema::AssignConvertType
3489Sema::CheckTransparentUnionArgumentConstraints(QualType ArgType, Expr *&rExpr) {
3490 QualType FromType = rExpr->getType();
3491
3492 // If the ArgType is a Union type, we want to handle a potential
3493 // transparent_union GCC extension.
3494 const RecordType *UT = ArgType->getAsUnionType();
3467 // If we are allowing lax vector conversions, and LHS and RHS are both
3468 // vectors, the total size only needs to be the same. This is a bitcast;
3469 // no bits are changed but the result type is different.
3470 if (getLangOptions().LaxVectorConversions &&
3471 lhsType->isVectorType() && rhsType->isVectorType()) {
3472 if (Context.getTypeSize(lhsType) == Context.getTypeSize(rhsType))
3473 return IncompatibleVectors;
3474 }

--- 85 unchanged lines hidden (view full) ---

3560
3561Sema::AssignConvertType
3562Sema::CheckTransparentUnionArgumentConstraints(QualType ArgType, Expr *&rExpr) {
3563 QualType FromType = rExpr->getType();
3564
3565 // If the ArgType is a Union type, we want to handle a potential
3566 // transparent_union GCC extension.
3567 const RecordType *UT = ArgType->getAsUnionType();
3495 if (!UT || !UT->getDecl()->hasAttr<TransparentUnionAttr>(Context))
3568 if (!UT || !UT->getDecl()->hasAttr())
3496 return Incompatible;
3497
3498 // The field to initialize within the transparent union.
3499 RecordDecl *UD = UT->getDecl();
3500 FieldDecl *InitField = 0;
3501 // It's compatible if the expression matches any of the fields.
3569 return Incompatible;
3570
3571 // The field to initialize within the transparent union.
3572 RecordDecl *UD = UT->getDecl();
3573 FieldDecl *InitField = 0;
3574 // It's compatible if the expression matches any of the fields.
3502 for (RecordDecl::field_iterator it = UD->field_begin(Context),
3503 itend = UD->field_end(Context);
3575 for (RecordDecl::field_iterator it = UD->field_begin(),
3576 itend = UD->field_end();
3504 it != itend; ++it) {
3505 if (it->getType()->isPointerType()) {
3506 // If the transparent union contains a pointer type, we allow:
3507 // 1) void pointer
3508 // 2) null pointer constant
3509 if (FromType->isPointerType())
3510 if (FromType->getAsPointerType()->getPointeeType()->isVoidType()) {
3511 ImpCastExprToType(rExpr, it->getType());

--- 100 unchanged lines hidden (view full) ---

3612 if (const VectorType *RV = rhsType->getAsVectorType())
3613 if (LV->getElementType() == RV->getElementType() &&
3614 LV->getNumElements() == RV->getNumElements()) {
3615 return lhsType->isExtVectorType() ? lhsType : rhsType;
3616 }
3617 }
3618 }
3619
3577 it != itend; ++it) {
3578 if (it->getType()->isPointerType()) {
3579 // If the transparent union contains a pointer type, we allow:
3580 // 1) void pointer
3581 // 2) null pointer constant
3582 if (FromType->isPointerType())
3583 if (FromType->getAsPointerType()->getPointeeType()->isVoidType()) {
3584 ImpCastExprToType(rExpr, it->getType());

--- 100 unchanged lines hidden (view full) ---

3685 if (const VectorType *RV = rhsType->getAsVectorType())
3686 if (LV->getElementType() == RV->getElementType() &&
3687 LV->getNumElements() == RV->getNumElements()) {
3688 return lhsType->isExtVectorType() ? lhsType : rhsType;
3689 }
3690 }
3691 }
3692
3620 // If the lhs is an extended vector and the rhs is a scalar of the same type
3621 // or a literal, promote the rhs to the vector type.
3622 if (const ExtVectorType *V = lhsType->getAsExtVectorType()) {
3623 QualType eltType = V->getElementType();
3624
3625 if ((eltType->getAsBuiltinType() == rhsType->getAsBuiltinType()) ||
3626 (eltType->isIntegerType() && isa<IntegerLiteral>(rex)) ||
3627 (eltType->isFloatingType() && isa<FloatingLiteral>(rex))) {
3628 ImpCastExprToType(rex, lhsType);
3629 return lhsType;
3630 }
3693 // Canonicalize the ExtVector to the LHS, remember if we swapped so we can
3694 // swap back (so that we don't reverse the inputs to a subtract, for instance.
3695 bool swapped = false;
3696 if (rhsType->isExtVectorType()) {
3697 swapped = true;
3698 std::swap(rex, lex);
3699 std::swap(rhsType, lhsType);
3631 }
3700 }
3632
3633 // If the rhs is an extended vector and the lhs is a scalar of the same type,
3634 // promote the lhs to the vector type.
3635 if (const ExtVectorType *V = rhsType->getAsExtVectorType()) {
3636 QualType eltType = V->getElementType();
3637
3638 if ((eltType->getAsBuiltinType() == lhsType->getAsBuiltinType()) ||
3639 (eltType->isIntegerType() && isa<IntegerLiteral>(lex)) ||
3640 (eltType->isFloatingType() && isa<FloatingLiteral>(lex))) {
3641 ImpCastExprToType(lex, rhsType);
3642 return rhsType;
3701
3702 // Handle the case of an ext vector and scalar.
3703 if (const ExtVectorType *LV = lhsType->getAsExtVectorType()) {
3704 QualType EltTy = LV->getElementType();
3705 if (EltTy->isIntegralType() && rhsType->isIntegralType()) {
3706 if (Context.getIntegerTypeOrder(EltTy, rhsType) >= 0) {
3707 ImpCastExprToType(rex, lhsType);
3708 if (swapped) std::swap(rex, lex);
3709 return lhsType;
3710 }
3643 }
3711 }
3712 if (EltTy->isRealFloatingType() && rhsType->isScalarType() &&
3713 rhsType->isRealFloatingType()) {
3714 if (Context.getFloatingTypeOrder(EltTy, rhsType) >= 0) {
3715 ImpCastExprToType(rex, lhsType);
3716 if (swapped) std::swap(rex, lex);
3717 return lhsType;
3718 }
3719 }
3644 }
3720 }
3645
3646 // You cannot convert between vector values of different size.
3721
3722 // Vectors of different size or scalar and non-ext-vector are errors.
3647 Diag(Loc, diag::err_typecheck_vector_not_convertable)
3648 << lex->getType() << rex->getType()
3649 << lex->getSourceRange() << rex->getSourceRange();
3650 return QualType();
3651}
3652
3653inline QualType Sema::CheckMultiplyDivideOperands(
3654 Expr *&lex, Expr *&rex, SourceLocation Loc, bool isCompAssign)

--- 374 unchanged lines hidden (view full) ---

4029 // when handling null pointer constants. One day, we can consider making them
4030 // errors (when -pedantic-errors is enabled).
4031 if (lType->isPointerType() && rType->isPointerType()) { // C99 6.5.8p2
4032 QualType LCanPointeeTy =
4033 Context.getCanonicalType(lType->getAsPointerType()->getPointeeType());
4034 QualType RCanPointeeTy =
4035 Context.getCanonicalType(rType->getAsPointerType()->getPointeeType());
4036
3723 Diag(Loc, diag::err_typecheck_vector_not_convertable)
3724 << lex->getType() << rex->getType()
3725 << lex->getSourceRange() << rex->getSourceRange();
3726 return QualType();
3727}
3728
3729inline QualType Sema::CheckMultiplyDivideOperands(
3730 Expr *&lex, Expr *&rex, SourceLocation Loc, bool isCompAssign)

--- 374 unchanged lines hidden (view full) ---

4105 // when handling null pointer constants. One day, we can consider making them
4106 // errors (when -pedantic-errors is enabled).
4107 if (lType->isPointerType() && rType->isPointerType()) { // C99 6.5.8p2
4108 QualType LCanPointeeTy =
4109 Context.getCanonicalType(lType->getAsPointerType()->getPointeeType());
4110 QualType RCanPointeeTy =
4111 Context.getCanonicalType(rType->getAsPointerType()->getPointeeType());
4112
4113 if (rType->isFunctionPointerType() || lType->isFunctionPointerType()) {
4114 if (isRelational) {
4115 Diag(Loc, diag::ext_typecheck_ordered_comparison_of_function_pointers)
4116 << lType << rType << lex->getSourceRange() << rex->getSourceRange();
4117 }
4118 }
4119 if (((!LHSIsNull || isRelational) && LCanPointeeTy->isVoidType()) !=
4120 ((!RHSIsNull || isRelational) && RCanPointeeTy->isVoidType())) {
4121 Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers)
4122 << lType << rType << lex->getSourceRange() << rex->getSourceRange();
4123 }
4037 // Simple check: if the pointee types are identical, we're done.
4038 if (LCanPointeeTy == RCanPointeeTy)
4039 return ResultTy;
4040
4041 if (getLangOptions().CPlusPlus) {
4042 // C++ [expr.rel]p2:
4043 // [...] Pointer conversions (4.10) and qualification
4044 // conversions (4.4) are performed on pointer operands (or on

--- 96 unchanged lines hidden (view full) ---

4141 << lType << rType << lex->getSourceRange() << rex->getSourceRange();
4142 ImpCastExprToType(rex, lType);
4143 return ResultTy;
4144 }
4145 }
4146 }
4147 if ((lType->isPointerType() || lType->isObjCQualifiedIdType()) &&
4148 rType->isIntegerType()) {
4124 // Simple check: if the pointee types are identical, we're done.
4125 if (LCanPointeeTy == RCanPointeeTy)
4126 return ResultTy;
4127
4128 if (getLangOptions().CPlusPlus) {
4129 // C++ [expr.rel]p2:
4130 // [...] Pointer conversions (4.10) and qualification
4131 // conversions (4.4) are performed on pointer operands (or on

--- 96 unchanged lines hidden (view full) ---

4228 << lType << rType << lex->getSourceRange() << rex->getSourceRange();
4229 ImpCastExprToType(rex, lType);
4230 return ResultTy;
4231 }
4232 }
4233 }
4234 if ((lType->isPointerType() || lType->isObjCQualifiedIdType()) &&
4235 rType->isIntegerType()) {
4149 if (!RHSIsNull)
4236 if (isRelational)
4237 Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer)
4238 << lType << rType << lex->getSourceRange() << rex->getSourceRange();
4239 else if (!RHSIsNull)
4150 Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
4151 << lType << rType << lex->getSourceRange() << rex->getSourceRange();
4152 ImpCastExprToType(rex, lType); // promote the integer to pointer
4153 return ResultTy;
4154 }
4155 if (lType->isIntegerType() &&
4156 (rType->isPointerType() || rType->isObjCQualifiedIdType())) {
4240 Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
4241 << lType << rType << lex->getSourceRange() << rex->getSourceRange();
4242 ImpCastExprToType(rex, lType); // promote the integer to pointer
4243 return ResultTy;
4244 }
4245 if (lType->isIntegerType() &&
4246 (rType->isPointerType() || rType->isObjCQualifiedIdType())) {
4157 if (!LHSIsNull)
4247 if (isRelational)
4248 Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer)
4249 << lType << rType << lex->getSourceRange() << rex->getSourceRange();
4250 else if (!LHSIsNull)
4158 Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
4159 << lType << rType << lex->getSourceRange() << rex->getSourceRange();
4160 ImpCastExprToType(lex, rType); // promote the integer to pointer
4161 return ResultTy;
4162 }
4163 // Handle block pointers.
4164 if (!isRelational && RHSIsNull
4165 && lType->isBlockPointerType() && rType->isIntegerType()) {

--- 1055 unchanged lines hidden (view full) ---

5221
5222 // The parameter list is optional, if there was none, assume ().
5223 if (!T->isFunctionType())
5224 T = Context.getFunctionType(T, NULL, 0, 0, 0);
5225
5226 CurBlock->hasPrototype = true;
5227 CurBlock->isVariadic = false;
5228 // Check for a valid sentinel attribute on this block.
4251 Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
4252 << lType << rType << lex->getSourceRange() << rex->getSourceRange();
4253 ImpCastExprToType(lex, rType); // promote the integer to pointer
4254 return ResultTy;
4255 }
4256 // Handle block pointers.
4257 if (!isRelational && RHSIsNull
4258 && lType->isBlockPointerType() && rType->isIntegerType()) {

--- 1055 unchanged lines hidden (view full) ---

5314
5315 // The parameter list is optional, if there was none, assume ().
5316 if (!T->isFunctionType())
5317 T = Context.getFunctionType(T, NULL, 0, 0, 0);
5318
5319 CurBlock->hasPrototype = true;
5320 CurBlock->isVariadic = false;
5321 // Check for a valid sentinel attribute on this block.
5229 if (CurBlock->TheDecl->getAttr<SentinelAttr>(Context)) {
5322 if (CurBlock->TheDecl->getAttr()) {
5230 Diag(ParamInfo.getAttributes()->getLoc(),
5231 diag::warn_attribute_sentinel_not_variadic) << 1;
5232 // FIXME: remove the attribute.
5233 }
5234 QualType RetTy = T.getTypePtr()->getAsFunctionType()->getResultType();
5235
5236 // Do not allow returning a objc interface by-value.
5237 if (RetTy->isObjCInterfaceType()) {

--- 32 unchanged lines hidden (view full) ---

5270 for (BlockDecl::param_iterator AI = CurBlock->TheDecl->param_begin(),
5271 E = CurBlock->TheDecl->param_end(); AI != E; ++AI)
5272 // If this has an identifier, add it to the scope stack.
5273 if ((*AI)->getIdentifier())
5274 PushOnScopeChains(*AI, CurBlock->TheScope);
5275
5276 // Check for a valid sentinel attribute on this block.
5277 if (!CurBlock->isVariadic &&
5323 Diag(ParamInfo.getAttributes()->getLoc(),
5324 diag::warn_attribute_sentinel_not_variadic) << 1;
5325 // FIXME: remove the attribute.
5326 }
5327 QualType RetTy = T.getTypePtr()->getAsFunctionType()->getResultType();
5328
5329 // Do not allow returning a objc interface by-value.
5330 if (RetTy->isObjCInterfaceType()) {

--- 32 unchanged lines hidden (view full) ---

5363 for (BlockDecl::param_iterator AI = CurBlock->TheDecl->param_begin(),
5364 E = CurBlock->TheDecl->param_end(); AI != E; ++AI)
5365 // If this has an identifier, add it to the scope stack.
5366 if ((*AI)->getIdentifier())
5367 PushOnScopeChains(*AI, CurBlock->TheScope);
5368
5369 // Check for a valid sentinel attribute on this block.
5370 if (!CurBlock->isVariadic &&
5278 CurBlock->TheDecl->getAttr<SentinelAttr>(Context)) {
5371 CurBlock->TheDecl->getAttr()) {
5279 Diag(ParamInfo.getAttributes()->getLoc(),
5280 diag::warn_attribute_sentinel_not_variadic) << 1;
5281 // FIXME: remove the attribute.
5282 }
5283
5284 // Analyze the return type.
5285 QualType T = GetTypeForDeclarator(ParamInfo, CurScope);
5286 QualType RetTy = T->getAsFunctionType()->getResultType();

--- 315 unchanged lines hidden (view full) ---

5602 MethodDecl->getOverloadedOperator() == OO_Equal) {
5603 if (!MethodDecl->isUsed())
5604 DefineImplicitOverloadedAssign(Loc, MethodDecl);
5605 }
5606 }
5607 if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
5608 // Implicit instantiation of function templates and member functions of
5609 // class templates.
5372 Diag(ParamInfo.getAttributes()->getLoc(),
5373 diag::warn_attribute_sentinel_not_variadic) << 1;
5374 // FIXME: remove the attribute.
5375 }
5376
5377 // Analyze the return type.
5378 QualType T = GetTypeForDeclarator(ParamInfo, CurScope);
5379 QualType RetTy = T->getAsFunctionType()->getResultType();

--- 315 unchanged lines hidden (view full) ---

5695 MethodDecl->getOverloadedOperator() == OO_Equal) {
5696 if (!MethodDecl->isUsed())
5697 DefineImplicitOverloadedAssign(Loc, MethodDecl);
5698 }
5699 }
5700 if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
5701 // Implicit instantiation of function templates and member functions of
5702 // class templates.
5610 if (!Function->getBody(Context)) {
5703 if (!Function->getBody()) {
5611 // FIXME: distinguish between implicit instantiations of function
5612 // templates and explicit specializations (the latter don't get
5613 // instantiated, naturally).
5614 if (Function->getInstantiatedFromMemberFunction() ||
5615 Function->getPrimaryTemplate())
5704 // FIXME: distinguish between implicit instantiations of function
5705 // templates and explicit specializations (the latter don't get
5706 // instantiated, naturally).
5707 if (Function->getInstantiatedFromMemberFunction() ||
5708 Function->getPrimaryTemplate())
5616 PendingImplicitInstantiations.push(std::make_pair(Function, Loc));
5709 PendingImplicitInstantiations.push_back(std::make_pair(Function, Loc));
5617 }
5618
5619
5620 // FIXME: keep track of references to static functions
5621 Function->setUsed(true);
5622 return;
5623 }
5624
5625 if (VarDecl *Var = dyn_cast<VarDecl>(D)) {
5626 (void)Var;
5627 // FIXME: implicit template instantiation
5628 // FIXME: keep track of references to static data?
5629 D->setUsed(true);
5630 }
5631}
5632
5710 }
5711
5712
5713 // FIXME: keep track of references to static functions
5714 Function->setUsed(true);
5715 return;
5716 }
5717
5718 if (VarDecl *Var = dyn_cast<VarDecl>(D)) {
5719 (void)Var;
5720 // FIXME: implicit template instantiation
5721 // FIXME: keep track of references to static data?
5722 D->setUsed(true);
5723 }
5724}
5725