Sema.cpp revision 8c84571f3e262569ba51d107db7ab31a23de79b3
1//===--- Sema.cpp - AST Builder and Semantic Analysis Implementation ------===// 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//===----------------------------------------------------------------------===// 9// 10// This file implements the actions class which performs semantic analysis and 11// builds an AST out of a parse stream. 12// 13//===----------------------------------------------------------------------===// 14 15#include "clang/Sema/SemaInternal.h" 16#include "clang/Sema/DelayedDiagnostic.h" 17#include "TargetAttributesSema.h" 18#include "llvm/ADT/DenseMap.h" 19#include "llvm/ADT/SmallSet.h" 20#include "llvm/ADT/APFloat.h" 21#include "clang/Sema/CXXFieldCollector.h" 22#include "clang/Sema/ExternalSemaSource.h" 23#include "clang/Sema/ObjCMethodList.h" 24#include "clang/Sema/PrettyDeclStackTrace.h" 25#include "clang/Sema/Scope.h" 26#include "clang/Sema/ScopeInfo.h" 27#include "clang/Sema/SemaConsumer.h" 28#include "clang/AST/ASTContext.h" 29#include "clang/AST/ASTDiagnostic.h" 30#include "clang/AST/DeclCXX.h" 31#include "clang/AST/DeclObjC.h" 32#include "clang/AST/Expr.h" 33#include "clang/Lex/Preprocessor.h" 34#include "clang/Basic/PartialDiagnostic.h" 35#include "clang/Basic/TargetInfo.h" 36using namespace clang; 37using namespace sema; 38 39FunctionScopeInfo::~FunctionScopeInfo() { } 40 41void FunctionScopeInfo::Clear(unsigned NumErrors) { 42 HasBranchProtectedScope = false; 43 HasBranchIntoScope = false; 44 HasIndirectGoto = false; 45 46 LabelMap.clear(); 47 SwitchStack.clear(); 48 Returns.clear(); 49 NumErrorsAtStartOfFunction = NumErrors; 50} 51 52BlockScopeInfo::~BlockScopeInfo() { } 53 54void Sema::ActOnTranslationUnitScope(Scope *S) { 55 TUScope = S; 56 PushDeclContext(S, Context.getTranslationUnitDecl()); 57 58 VAListTagName = PP.getIdentifierInfo("__va_list_tag"); 59 60 if (!Context.isInt128Installed() && // May be set by ASTReader. 61 PP.getTargetInfo().getPointerWidth(0) >= 64) { 62 TypeSourceInfo *TInfo; 63 64 // Install [u]int128_t for 64-bit targets. 65 TInfo = Context.getTrivialTypeSourceInfo(Context.Int128Ty); 66 PushOnScopeChains(TypedefDecl::Create(Context, CurContext, 67 SourceLocation(), 68 &Context.Idents.get("__int128_t"), 69 TInfo), TUScope); 70 71 TInfo = Context.getTrivialTypeSourceInfo(Context.UnsignedInt128Ty); 72 PushOnScopeChains(TypedefDecl::Create(Context, CurContext, 73 SourceLocation(), 74 &Context.Idents.get("__uint128_t"), 75 TInfo), TUScope); 76 Context.setInt128Installed(); 77 } 78 79 80 if (!PP.getLangOptions().ObjC1) return; 81 82 // Built-in ObjC types may already be set by ASTReader (hence isNull checks). 83 if (Context.getObjCSelType().isNull()) { 84 // Create the built-in typedef for 'SEL'. 85 QualType SelT = Context.getPointerType(Context.ObjCBuiltinSelTy); 86 TypeSourceInfo *SelInfo = Context.getTrivialTypeSourceInfo(SelT); 87 TypedefDecl *SelTypedef 88 = TypedefDecl::Create(Context, CurContext, SourceLocation(), 89 &Context.Idents.get("SEL"), SelInfo); 90 PushOnScopeChains(SelTypedef, TUScope); 91 Context.setObjCSelType(Context.getTypeDeclType(SelTypedef)); 92 Context.ObjCSelRedefinitionType = Context.getObjCSelType(); 93 } 94 95 // Synthesize "@class Protocol; 96 if (Context.getObjCProtoType().isNull()) { 97 ObjCInterfaceDecl *ProtocolDecl = 98 ObjCInterfaceDecl::Create(Context, CurContext, SourceLocation(), 99 &Context.Idents.get("Protocol"), 100 SourceLocation(), true); 101 Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); 102 PushOnScopeChains(ProtocolDecl, TUScope, false); 103 } 104 // Create the built-in typedef for 'id'. 105 if (Context.getObjCIdType().isNull()) { 106 QualType T = Context.getObjCObjectType(Context.ObjCBuiltinIdTy, 0, 0); 107 T = Context.getObjCObjectPointerType(T); 108 TypeSourceInfo *IdInfo = Context.getTrivialTypeSourceInfo(T); 109 TypedefDecl *IdTypedef 110 = TypedefDecl::Create(Context, CurContext, SourceLocation(), 111 &Context.Idents.get("id"), IdInfo); 112 PushOnScopeChains(IdTypedef, TUScope); 113 Context.setObjCIdType(Context.getTypeDeclType(IdTypedef)); 114 Context.ObjCIdRedefinitionType = Context.getObjCIdType(); 115 } 116 // Create the built-in typedef for 'Class'. 117 if (Context.getObjCClassType().isNull()) { 118 QualType T = Context.getObjCObjectType(Context.ObjCBuiltinClassTy, 0, 0); 119 T = Context.getObjCObjectPointerType(T); 120 TypeSourceInfo *ClassInfo = Context.getTrivialTypeSourceInfo(T); 121 TypedefDecl *ClassTypedef 122 = TypedefDecl::Create(Context, CurContext, SourceLocation(), 123 &Context.Idents.get("Class"), ClassInfo); 124 PushOnScopeChains(ClassTypedef, TUScope); 125 Context.setObjCClassType(Context.getTypeDeclType(ClassTypedef)); 126 Context.ObjCClassRedefinitionType = Context.getObjCClassType(); 127 } 128} 129 130Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, 131 bool CompleteTranslationUnit, 132 CodeCompleteConsumer *CodeCompleter) 133 : TheTargetAttributesSema(0), 134 LangOpts(pp.getLangOptions()), PP(pp), Context(ctxt), Consumer(consumer), 135 Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()), 136 ExternalSource(0), CodeCompleter(CodeCompleter), CurContext(0), 137 PackContext(0), VisContext(0), ParsingDeclDepth(0), 138 IdResolver(pp.getLangOptions()), CXXTypeInfoDecl(0), MSVCGuidDecl(0), 139 GlobalNewDeleteDeclared(false), 140 CompleteTranslationUnit(CompleteTranslationUnit), 141 NumSFINAEErrors(0), SuppressAccessChecking(false), 142 NonInstantiationEntries(0), CurrentInstantiationScope(0), TyposCorrected(0), 143 AnalysisWarnings(*this) 144{ 145 TUScope = 0; 146 if (getLangOptions().CPlusPlus) 147 FieldCollector.reset(new CXXFieldCollector()); 148 149 // Tell diagnostics how to render things from the AST library. 150 PP.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument, 151 &Context); 152 153 ExprEvalContexts.push_back( 154 ExpressionEvaluationContextRecord(PotentiallyEvaluated, 0)); 155 156 FunctionScopes.push_back(new FunctionScopeInfo(Diags.getNumErrors())); 157} 158 159void Sema::Initialize() { 160 // Tell the AST consumer about this Sema object. 161 Consumer.Initialize(Context); 162 163 // FIXME: Isn't this redundant with the initialization above? 164 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer)) 165 SC->InitializeSema(*this); 166 167 // Tell the external Sema source about this Sema object. 168 if (ExternalSemaSource *ExternalSema 169 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource())) 170 ExternalSema->InitializeSema(*this); 171} 172 173Sema::~Sema() { 174 if (PackContext) FreePackedContext(); 175 if (VisContext) FreeVisContext(); 176 delete TheTargetAttributesSema; 177 178 // Kill all the active scopes. 179 for (unsigned I = 1, E = FunctionScopes.size(); I != E; ++I) 180 delete FunctionScopes[I]; 181 if (FunctionScopes.size() == 1) 182 delete FunctionScopes[0]; 183 184 // Tell the SemaConsumer to forget about us; we're going out of scope. 185 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer)) 186 SC->ForgetSema(); 187 188 // Detach from the external Sema source. 189 if (ExternalSemaSource *ExternalSema 190 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource())) 191 ExternalSema->ForgetSema(); 192} 193 194/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. 195/// If there is already an implicit cast, merge into the existing one. 196/// The result is of the given category. 197void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, 198 CastKind Kind, ExprValueKind VK, 199 const CXXCastPath *BasePath) { 200 QualType ExprTy = Context.getCanonicalType(Expr->getType()); 201 QualType TypeTy = Context.getCanonicalType(Ty); 202 203 if (ExprTy == TypeTy) 204 return; 205 206 if (Expr->getType()->isPointerType() && Ty->isPointerType()) { 207 QualType ExprBaseType = cast<PointerType>(ExprTy)->getPointeeType(); 208 QualType BaseType = cast<PointerType>(TypeTy)->getPointeeType(); 209 if (ExprBaseType.getAddressSpace() != BaseType.getAddressSpace()) { 210 Diag(Expr->getExprLoc(), diag::err_implicit_pointer_address_space_cast) 211 << Expr->getSourceRange(); 212 } 213 } 214 215 // If this is a derived-to-base cast to a through a virtual base, we 216 // need a vtable. 217 if (Kind == CK_DerivedToBase && 218 BasePathInvolvesVirtualBase(*BasePath)) { 219 QualType T = Expr->getType(); 220 if (const PointerType *Pointer = T->getAs<PointerType>()) 221 T = Pointer->getPointeeType(); 222 if (const RecordType *RecordTy = T->getAs<RecordType>()) 223 MarkVTableUsed(Expr->getLocStart(), 224 cast<CXXRecordDecl>(RecordTy->getDecl())); 225 } 226 227 if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) { 228 if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) { 229 ImpCast->setType(Ty); 230 ImpCast->setValueKind(VK); 231 return; 232 } 233 } 234 235 Expr = ImplicitCastExpr::Create(Context, Ty, Kind, Expr, BasePath, VK); 236} 237 238ExprValueKind Sema::CastCategory(Expr *E) { 239 Expr::Classification Classification = E->Classify(Context); 240 return Classification.isRValue() ? VK_RValue : 241 (Classification.isLValue() ? VK_LValue : VK_XValue); 242} 243 244/// \brief Used to prune the decls of Sema's UnusedFileScopedDecls vector. 245static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) { 246 if (D->isUsed()) 247 return true; 248 249 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 250 // UnusedFileScopedDecls stores the first declaration. 251 // The declaration may have become definition so check again. 252 const FunctionDecl *DeclToCheck; 253 if (FD->hasBody(DeclToCheck)) 254 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 255 256 // Later redecls may add new information resulting in not having to warn, 257 // so check again. 258 DeclToCheck = FD->getMostRecentDeclaration(); 259 if (DeclToCheck != FD) 260 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 261 } 262 263 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 264 // UnusedFileScopedDecls stores the first declaration. 265 // The declaration may have become definition so check again. 266 const VarDecl *DeclToCheck = VD->getDefinition(); 267 if (DeclToCheck) 268 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 269 270 // Later redecls may add new information resulting in not having to warn, 271 // so check again. 272 DeclToCheck = VD->getMostRecentDeclaration(); 273 if (DeclToCheck != VD) 274 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 275 } 276 277 return false; 278} 279 280/// ActOnEndOfTranslationUnit - This is called at the very end of the 281/// translation unit when EOF is reached and all but the top-level scope is 282/// popped. 283void Sema::ActOnEndOfTranslationUnit() { 284 // At PCH writing, implicit instantiations and VTable handling info are 285 // stored and performed when the PCH is included. 286 if (CompleteTranslationUnit) 287 while (1) { 288 // C++: Perform implicit template instantiations. 289 // 290 // FIXME: When we perform these implicit instantiations, we do not 291 // carefully keep track of the point of instantiation (C++ [temp.point]). 292 // This means that name lookup that occurs within the template 293 // instantiation will always happen at the end of the translation unit, 294 // so it will find some names that should not be found. Although this is 295 // common behavior for C++ compilers, it is technically wrong. In the 296 // future, we either need to be able to filter the results of name lookup 297 // or we need to perform template instantiations earlier. 298 PerformPendingInstantiations(); 299 300 /// If DefinedUsedVTables ends up marking any virtual member 301 /// functions it might lead to more pending template 302 /// instantiations, which is why we need to loop here. 303 if (!DefineUsedVTables()) 304 break; 305 } 306 307 // Remove file scoped decls that turned out to be used. 308 UnusedFileScopedDecls.erase(std::remove_if(UnusedFileScopedDecls.begin(), 309 UnusedFileScopedDecls.end(), 310 std::bind1st(std::ptr_fun(ShouldRemoveFromUnused), 311 this)), 312 UnusedFileScopedDecls.end()); 313 314 if (!CompleteTranslationUnit) { 315 TUScope = 0; 316 return; 317 } 318 319 // Check for #pragma weak identifiers that were never declared 320 // FIXME: This will cause diagnostics to be emitted in a non-determinstic 321 // order! Iterating over a densemap like this is bad. 322 for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator 323 I = WeakUndeclaredIdentifiers.begin(), 324 E = WeakUndeclaredIdentifiers.end(); I != E; ++I) { 325 if (I->second.getUsed()) continue; 326 327 Diag(I->second.getLocation(), diag::warn_weak_identifier_undeclared) 328 << I->first; 329 } 330 331 // C99 6.9.2p2: 332 // A declaration of an identifier for an object that has file 333 // scope without an initializer, and without a storage-class 334 // specifier or with the storage-class specifier static, 335 // constitutes a tentative definition. If a translation unit 336 // contains one or more tentative definitions for an identifier, 337 // and the translation unit contains no external definition for 338 // that identifier, then the behavior is exactly as if the 339 // translation unit contains a file scope declaration of that 340 // identifier, with the composite type as of the end of the 341 // translation unit, with an initializer equal to 0. 342 llvm::SmallSet<VarDecl *, 32> Seen; 343 for (unsigned i = 0, e = TentativeDefinitions.size(); i != e; ++i) { 344 VarDecl *VD = TentativeDefinitions[i]->getActingDefinition(); 345 346 // If the tentative definition was completed, getActingDefinition() returns 347 // null. If we've already seen this variable before, insert()'s second 348 // return value is false. 349 if (VD == 0 || VD->isInvalidDecl() || !Seen.insert(VD)) 350 continue; 351 352 if (const IncompleteArrayType *ArrayT 353 = Context.getAsIncompleteArrayType(VD->getType())) { 354 if (RequireCompleteType(VD->getLocation(), 355 ArrayT->getElementType(), 356 diag::err_tentative_def_incomplete_type_arr)) { 357 VD->setInvalidDecl(); 358 continue; 359 } 360 361 // Set the length of the array to 1 (C99 6.9.2p5). 362 Diag(VD->getLocation(), diag::warn_tentative_incomplete_array); 363 llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true); 364 QualType T = Context.getConstantArrayType(ArrayT->getElementType(), 365 One, ArrayType::Normal, 0); 366 VD->setType(T); 367 } else if (RequireCompleteType(VD->getLocation(), VD->getType(), 368 diag::err_tentative_def_incomplete_type)) 369 VD->setInvalidDecl(); 370 371 // Notify the consumer that we've completed a tentative definition. 372 if (!VD->isInvalidDecl()) 373 Consumer.CompleteTentativeDefinition(VD); 374 375 } 376 377 // Output warning for unused file scoped decls. 378 for (llvm::SmallVectorImpl<const DeclaratorDecl*>::iterator 379 I = UnusedFileScopedDecls.begin(), 380 E = UnusedFileScopedDecls.end(); I != E; ++I) { 381 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) { 382 const FunctionDecl *DiagD; 383 if (!FD->hasBody(DiagD)) 384 DiagD = FD; 385 Diag(DiagD->getLocation(), 386 isa<CXXMethodDecl>(DiagD) ? diag::warn_unused_member_function 387 : diag::warn_unused_function) 388 << DiagD->getDeclName(); 389 } else { 390 const VarDecl *DiagD = cast<VarDecl>(*I)->getDefinition(); 391 if (!DiagD) 392 DiagD = cast<VarDecl>(*I); 393 Diag(DiagD->getLocation(), diag::warn_unused_variable) 394 << DiagD->getDeclName(); 395 } 396 } 397 398 TUScope = 0; 399} 400 401 402//===----------------------------------------------------------------------===// 403// Helper functions. 404//===----------------------------------------------------------------------===// 405 406DeclContext *Sema::getFunctionLevelDeclContext() { 407 DeclContext *DC = CurContext; 408 409 while (isa<BlockDecl>(DC) || isa<EnumDecl>(DC)) 410 DC = DC->getParent(); 411 412 return DC; 413} 414 415/// getCurFunctionDecl - If inside of a function body, this returns a pointer 416/// to the function decl for the function being parsed. If we're currently 417/// in a 'block', this returns the containing context. 418FunctionDecl *Sema::getCurFunctionDecl() { 419 DeclContext *DC = getFunctionLevelDeclContext(); 420 return dyn_cast<FunctionDecl>(DC); 421} 422 423ObjCMethodDecl *Sema::getCurMethodDecl() { 424 DeclContext *DC = getFunctionLevelDeclContext(); 425 return dyn_cast<ObjCMethodDecl>(DC); 426} 427 428NamedDecl *Sema::getCurFunctionOrMethodDecl() { 429 DeclContext *DC = getFunctionLevelDeclContext(); 430 if (isa<ObjCMethodDecl>(DC) || isa<FunctionDecl>(DC)) 431 return cast<NamedDecl>(DC); 432 return 0; 433} 434 435Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() { 436 if (!this->Emit()) 437 return; 438 439 // If this is not a note, and we're in a template instantiation 440 // that is different from the last template instantiation where 441 // we emitted an error, print a template instantiation 442 // backtrace. 443 if (!SemaRef.Diags.isBuiltinNote(DiagID) && 444 !SemaRef.ActiveTemplateInstantiations.empty() && 445 SemaRef.ActiveTemplateInstantiations.back() 446 != SemaRef.LastTemplateInstantiationErrorContext) { 447 SemaRef.PrintInstantiationStack(); 448 SemaRef.LastTemplateInstantiationErrorContext 449 = SemaRef.ActiveTemplateInstantiations.back(); 450 } 451} 452 453Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation Loc, unsigned DiagID) { 454 if (isSFINAEContext()) { 455 switch (Diagnostic::getDiagnosticSFINAEResponse(DiagID)) { 456 case Diagnostic::SFINAE_Report: 457 // Fall through; we'll report the diagnostic below. 458 break; 459 460 case Diagnostic::SFINAE_SubstitutionFailure: 461 // Count this failure so that we know that template argument deduction 462 // has failed. 463 ++NumSFINAEErrors; 464 // Fall through 465 466 case Diagnostic::SFINAE_Suppress: 467 // Suppress this diagnostic. 468 Diags.setLastDiagnosticIgnored(); 469 return SemaDiagnosticBuilder(*this); 470 } 471 } 472 473 DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID); 474 return SemaDiagnosticBuilder(DB, *this, DiagID); 475} 476 477Sema::SemaDiagnosticBuilder 478Sema::Diag(SourceLocation Loc, const PartialDiagnostic& PD) { 479 SemaDiagnosticBuilder Builder(Diag(Loc, PD.getDiagID())); 480 PD.Emit(Builder); 481 482 return Builder; 483} 484 485/// \brief Determines the active Scope associated with the given declaration 486/// context. 487/// 488/// This routine maps a declaration context to the active Scope object that 489/// represents that declaration context in the parser. It is typically used 490/// from "scope-less" code (e.g., template instantiation, lazy creation of 491/// declarations) that injects a name for name-lookup purposes and, therefore, 492/// must update the Scope. 493/// 494/// \returns The scope corresponding to the given declaraion context, or NULL 495/// if no such scope is open. 496Scope *Sema::getScopeForContext(DeclContext *Ctx) { 497 498 if (!Ctx) 499 return 0; 500 501 Ctx = Ctx->getPrimaryContext(); 502 for (Scope *S = getCurScope(); S; S = S->getParent()) { 503 // Ignore scopes that cannot have declarations. This is important for 504 // out-of-line definitions of static class members. 505 if (S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) 506 if (DeclContext *Entity = static_cast<DeclContext *> (S->getEntity())) 507 if (Ctx == Entity->getPrimaryContext()) 508 return S; 509 } 510 511 return 0; 512} 513 514/// \brief Enter a new function scope 515void Sema::PushFunctionScope() { 516 if (FunctionScopes.size() == 1) { 517 // Use the "top" function scope rather than having to allocate 518 // memory for a new scope. 519 FunctionScopes.back()->Clear(getDiagnostics().getNumErrors()); 520 FunctionScopes.push_back(FunctionScopes.back()); 521 return; 522 } 523 524 FunctionScopes.push_back( 525 new FunctionScopeInfo(getDiagnostics().getNumErrors())); 526} 527 528void Sema::PushBlockScope(Scope *BlockScope, BlockDecl *Block) { 529 FunctionScopes.push_back(new BlockScopeInfo(getDiagnostics().getNumErrors(), 530 BlockScope, Block)); 531} 532 533void Sema::PopFunctionOrBlockScope() { 534 FunctionScopeInfo *Scope = FunctionScopes.pop_back_val(); 535 assert(!FunctionScopes.empty() && "mismatched push/pop!"); 536 if (FunctionScopes.back() != Scope) 537 delete Scope; 538} 539 540/// \brief Determine whether any errors occurred within this function/method/ 541/// block. 542bool Sema::hasAnyErrorsInThisFunction() const { 543 return getCurFunction()->NumErrorsAtStartOfFunction 544 != getDiagnostics().getNumErrors(); 545} 546 547BlockScopeInfo *Sema::getCurBlock() { 548 if (FunctionScopes.empty()) 549 return 0; 550 551 return dyn_cast<BlockScopeInfo>(FunctionScopes.back()); 552} 553 554// Pin this vtable to this file. 555ExternalSemaSource::~ExternalSemaSource() {} 556 557std::pair<ObjCMethodList, ObjCMethodList> 558ExternalSemaSource::ReadMethodPool(Selector Sel) { 559 return std::pair<ObjCMethodList, ObjCMethodList>(); 560} 561 562void PrettyDeclStackTraceEntry::print(llvm::raw_ostream &OS) const { 563 SourceLocation Loc = this->Loc; 564 if (!Loc.isValid() && TheDecl) Loc = TheDecl->getLocation(); 565 if (Loc.isValid()) { 566 Loc.print(OS, S.getSourceManager()); 567 OS << ": "; 568 } 569 OS << Message; 570 571 if (TheDecl && isa<NamedDecl>(TheDecl)) { 572 std::string Name = cast<NamedDecl>(TheDecl)->getNameAsString(); 573 if (!Name.empty()) 574 OS << " '" << Name << '\''; 575 } 576 577 OS << '\n'; 578} 579