diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1316,6 +1316,8 @@ static bool hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD); }; +raw_ostream &operator<<(raw_ostream &OS, QualType QT); + } // namespace clang namespace llvm { diff --git a/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h b/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h --- a/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h +++ b/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h @@ -169,8 +169,7 @@ std::string VisitElementRegion(const ElementRegion *R) { std::string Str; llvm::raw_string_ostream OS(Str); - OS << "element of type '" << R->getElementType().getAsString() - << "' with index "; + OS << "element of type '" << R->getElementType() << "' with index "; // For concrete index: omit type of the index integer. if (auto I = R->getIndex().getAs()) OS << I->getValue(); diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -3545,7 +3545,7 @@ auto CXXRD = dyn_cast(RD); PrintOffset(OS, Offset, IndentLevel); - OS << C.getTypeDeclType(const_cast(RD)).getAsString(); + OS << C.getTypeDeclType(const_cast(RD)); if (Description) OS << ' ' << Description; if (CXXRD && CXXRD->isEmpty()) @@ -3630,7 +3630,7 @@ const QualType &FieldType = C.getLangOpts().DumpRecordLayoutsCanonical ? Field.getType().getCanonicalType() : Field.getType(); - OS << FieldType.getAsString() << ' ' << Field << '\n'; + OS << FieldType << ' ' << Field << '\n'; } // Dump virtual bases. @@ -3696,7 +3696,7 @@ // in libFrontend. const ASTRecordLayout &Info = getASTRecordLayout(RD); - OS << "Type: " << getTypeDeclType(RD).getAsString() << "\n"; + OS << "Type: " << getTypeDeclType(RD) << "\n"; OS << "\nLayout: "; OS << "getReturnType().getCanonicalType().getAsString() - << "'): "; + << TI.Method->getReturnType().getCanonicalType() << "'): "; if (R.Virtual.Microsoft.VBPtrOffset) Out << "vbptr at offset " << R.Virtual.Microsoft.VBPtrOffset << ", "; if (R.Virtual.Microsoft.VBIndex) diff --git a/clang/lib/Analysis/AnalysisDeclContext.cpp b/clang/lib/Analysis/AnalysisDeclContext.cpp --- a/clang/lib/Analysis/AnalysisDeclContext.cpp +++ b/clang/lib/Analysis/AnalysisDeclContext.cpp @@ -352,7 +352,7 @@ for (const auto &P : FD->parameters()) { if (P != *FD->param_begin()) OS << ", "; - OS << P->getType().getAsString(); + OS << P->getType(); } OS << ')'; } diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -5610,12 +5610,10 @@ if (Optional CE = E.getAs()) { print_construction_context(OS, Helper, CE->getConstructionContext()); } - OS << ", " << CCE->getType().getAsString() << ")"; + OS << ", " << CCE->getType() << ")"; } else if (const CastExpr *CE = dyn_cast(S)) { - OS << " (" << CE->getStmtClassName() << ", " - << CE->getCastKindName() - << ", " << CE->getType().getAsString() - << ")"; + OS << " (" << CE->getStmtClassName() << ", " << CE->getCastKindName() + << ", " << CE->getType() << ")"; } // Expressions need a newline. diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -488,8 +488,8 @@ Value *Val = createValueUnlessSelfReferential(Type, Visited, /*Depth=*/0, CreatedValuesCount); if (CreatedValuesCount > MaxCompositeValueSize) { - llvm::errs() << "Attempting to initialize a huge value of type: " - << Type.getAsString() << "\n"; + llvm::errs() << "Attempting to initialize a huge value of type: " << Type + << '\n'; } return Val; } diff --git a/clang/lib/Sema/CodeCompleteConsumer.cpp b/clang/lib/Sema/CodeCompleteConsumer.cpp --- a/clang/lib/Sema/CodeCompleteConsumer.cpp +++ b/clang/lib/Sema/CodeCompleteConsumer.cpp @@ -621,8 +621,7 @@ std::stable_sort(Results, Results + NumResults); if (!Context.getPreferredType().isNull()) - OS << "PREFERRED-TYPE: " << Context.getPreferredType().getAsString() - << "\n"; + OS << "PREFERRED-TYPE: " << Context.getPreferredType() << '\n'; StringRef Filter = SemaRef.getPreprocessor().getCodeCompletionFilter(); // Print the completions. diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -3467,7 +3467,7 @@ D->printQualifiedName(OS); } - OS << " '" << getType().getAsString() << "'\n"; + OS << " '" << getType() << "'\n"; return Depth + 1; } @@ -9800,7 +9800,7 @@ break; } - OS << " [" << S->Type.getAsString() << ']'; + OS << " [" << S->Type << ']'; } OS << '\n'; diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -1046,23 +1046,20 @@ case MemRegion::CXXThisRegionKind: case MemRegion::CXXTempObjectRegionKind: os << "a C++ temp object of type " - << cast(MR)->getValueType().getAsString(); + << cast(MR)->getValueType(); return true; case MemRegion::NonParamVarRegionKind: - os << "a variable of type" - << cast(MR)->getValueType().getAsString(); + os << "a variable of type" << cast(MR)->getValueType(); return true; case MemRegion::ParamVarRegionKind: - os << "a parameter of type" - << cast(MR)->getValueType().getAsString(); + os << "a parameter of type" << cast(MR)->getValueType(); return true; case MemRegion::FieldRegionKind: - os << "a field of type " - << cast(MR)->getValueType().getAsString(); + os << "a field of type " << cast(MR)->getValueType(); return true; case MemRegion::ObjCIvarRegionKind: os << "an instance variable of type " - << cast(MR)->getValueType().getAsString(); + << cast(MR)->getValueType(); return true; default: return false; diff --git a/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp b/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp --- a/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp @@ -55,13 +55,11 @@ << *MethAncestor->getClassInterface() << "', defines the instance method '"; MethDerived->getSelector().print(os); - os << "' whose return type is '" - << ResDerived.getAsString() + os << "' whose return type is '" << ResDerived << "'. A method with the same name (same selector) is also defined in " "class '" - << *MethAncestor->getClassInterface() - << "' and has a return type of '" - << ResAncestor.getAsString() + << *MethAncestor->getClassInterface() << "' and has a return type of '" + << ResAncestor << "'. These two types are incompatible, and may result in undefined " "behavior for clients of these classes."; diff --git a/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp b/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp --- a/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp @@ -325,7 +325,7 @@ llvm::raw_svector_ostream os(sbuf); os << "Variable '" << drCond->getDecl()->getName() - << "' with floating point type '" << drCond->getType().getAsString() + << "' with floating point type '" << drCond->getType() << "' should not be used as a loop counter"; ranges.push_back(drCond->getSourceRange()); diff --git a/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp @@ -320,8 +320,7 @@ SmallString<256> Buf; llvm::raw_svector_ostream OS(Buf); - OS << "Pointer to inner buffer of '" << ObjTy.getAsString() - << "' obtained here"; + OS << "Pointer to inner buffer of '" << ObjTy << "' obtained here"; PathDiagnosticLocation Pos(S, BRC.getSourceManager(), N->getLocationContext()); return std::make_shared(Pos, OS.str(), true); diff --git a/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp @@ -273,7 +273,7 @@ os << (*I)->getName(); } } - os << " (type " << FieldChain.back()->getType().getAsString() << ")"; + os << " (type " << FieldChain.back()->getType() << ")"; // Note that this will fire for every translation unit that uses this // class. This is suboptimal, but at least scan-build will merge diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -3445,7 +3445,7 @@ allocation_state::getContainerObjRegion(statePrev, Sym); const auto *TypedRegion = cast(ObjRegion); QualType ObjTy = TypedRegion->getValueType(); - OS << "Inner buffer of '" << ObjTy.getAsString() << "' "; + OS << "Inner buffer of '" << ObjTy << "' "; if (N->getLocation().getKind() == ProgramPoint::PostImplicitCallKind) { OS << "deallocated by call to destructor"; diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp @@ -228,9 +228,9 @@ OS << '\'' << Callee->getIdentifier()->getName() << '\''; else OS << "call"; - OS << " is converted to a pointer of type '" - << PointeeType.getAsString() << "', which is incompatible with " - << "sizeof operand type '" << SizeofType.getAsString() << "'"; + OS << " is converted to a pointer of type '" << PointeeType + << "', which is incompatible with " + << "sizeof operand type '" << SizeofType << "'"; SmallVector Ranges; Ranges.push_back(i->AllocCall->getCallee()->getSourceRange()); Ranges.push_back(SFinder.Sizeofs[0]->getSourceRange()); diff --git a/clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp @@ -143,7 +143,7 @@ else OS << "Converting "; - OS << "a pointer value of type '" << ObjT.getAsString() << "' to a "; + OS << "a pointer value of type '" << ObjT << "' to a "; std::string EuphemismForPlain = "primitive"; std::string SuggestedApi = IsObjC ? (IsInteger ? "" : "-boolValue") diff --git a/clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp @@ -135,9 +135,9 @@ llvm::raw_svector_ostream Os(Buf); // Use "second" and "third" since users will expect 1-based indexing // for parameter names when mentioned in prose. - Os << " The "<< ((ArgNum == 1) ? "second" : "third") << " argument to '" - << Name << "' must be a C array of pointer-sized values, not '" - << Arg->getType().getAsString() << "'"; + Os << " The " << ((ArgNum == 1) ? "second" : "third") << " argument to '" + << Name << "' must be a C array of pointer-sized values, not '" + << Arg->getType() << "'"; PathDiagnosticLocation CELoc = PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC); diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp @@ -45,7 +45,7 @@ void RefVal::print(raw_ostream &Out) const { if (!T.isNull()) - Out << "Tracked " << T.getAsString() << " | "; + Out << "Tracked " << T << " | "; switch (getKind()) { default: llvm_unreachable("Invalid RefVal kind"); diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp --- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp @@ -261,14 +261,12 @@ } if (CurrV.getObjKind() == ObjKind::CF) { - os << "a Core Foundation object of type '" - << Sym->getType().getAsString() << "' with a "; + os << "a Core Foundation object of type '" << Sym->getType() << "' with a "; } else if (CurrV.getObjKind() == ObjKind::OS) { os << "an OSObject of type '" << findAllocatedObjectName(S, Sym->getType()) << "' with a "; } else if (CurrV.getObjKind() == ObjKind::Generalized) { - os << "an object of type '" << Sym->getType().getAsString() - << "' with a "; + os << "an object of type '" << Sym->getType() << "' with a "; } else { assert(CurrV.getObjKind() == ObjKind::ObjC); QualType T = Sym->getType(); @@ -276,8 +274,7 @@ os << "an Objective-C object with a "; } else { const ObjCObjectPointerType *PT = cast(T); - os << "an instance of " << PT->getPointeeType().getAsString() - << " with a "; + os << "an instance of " << PT->getPointeeType() << " with a "; } } diff --git a/clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp @@ -145,7 +145,7 @@ OS << '\'' << I->getSExtValue() << "\', which is"; OS << " greater or equal to the width of type '" - << B->getLHS()->getType().getAsString() << "'."; + << B->getLHS()->getType() << "'."; } else if (B->getOpcode() == BinaryOperatorKind::BO_Shl && C.isNegative(B->getLHS())) { OS << "The result of the left shift is undefined because the left " @@ -162,8 +162,7 @@ OS << "The result of the left shift is undefined due to shifting \'" << LHS->getSExtValue() << "\' by \'" << RHS->getZExtValue() << "\', which is unrepresentable in the unsigned version of " - << "the return type \'" << B->getLHS()->getType().getAsString() - << "\'"; + << "the return type \'" << B->getLHS()->getType() << "\'"; Ex = B->getLHS(); } else { OS << "The result of the '" diff --git a/clang/lib/StaticAnalyzer/Core/DynamicType.cpp b/clang/lib/StaticAnalyzer/Core/DynamicType.cpp --- a/clang/lib/StaticAnalyzer/Core/DynamicType.cpp +++ b/clang/lib/StaticAnalyzer/Core/DynamicType.cpp @@ -209,7 +209,7 @@ if (ToPrint->isAnyPointerType()) ToPrint = ToPrint->getPointeeType(); - Out << '\"' << ToPrint.getAsString() << "\", \"sub_classable\": " + Out << '\"' << ToPrint << "\", \"sub_classable\": " << (DTI.canBeASubClass() ? "true" : "false"); } return Out; @@ -217,9 +217,9 @@ static raw_ostream &printJson(const DynamicCastInfo &DCI, raw_ostream &Out, const char *NL, unsigned int Space, bool IsDot) { - return Out << "\"from\": \"" << DCI.from().getAsString() << "\", \"to\": \"" - << DCI.to().getAsString() << "\", \"kind\": \"" - << (DCI.succeeds() ? "success" : "fail") << "\""; + return Out << "\"from\": \"" << DCI.from() << "\", \"to\": \"" << DCI.to() + << "\", \"kind\": \"" << (DCI.succeeds() ? "success" : "fail") + << "\""; } template diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp --- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -480,7 +480,7 @@ } void CXXTempObjectRegion::dumpToStream(raw_ostream &os) const { - os << "temp_object{" << getValueType().getAsString() << ", " + os << "temp_object{" << getValueType() << ", " << "S" << Ex->getID(getContext()) << '}'; } @@ -497,8 +497,8 @@ } void ElementRegion::dumpToStream(raw_ostream &os) const { - os << "Element{" << superRegion << ',' - << Index << ',' << getElementType().getAsString() << '}'; + os << "Element{" << superRegion << ',' << Index << ',' << getElementType() + << '}'; } void FieldRegion::dumpToStream(raw_ostream &os) const { diff --git a/clang/lib/StaticAnalyzer/Core/SVals.cpp b/clang/lib/StaticAnalyzer/Core/SVals.cpp --- a/clang/lib/StaticAnalyzer/Core/SVals.cpp +++ b/clang/lib/StaticAnalyzer/Core/SVals.cpp @@ -401,7 +401,7 @@ else os << ", "; - os << (*I).getType().getAsString(); + os << I->getType(); } os << '}'; diff --git a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp --- a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp @@ -65,14 +65,13 @@ } void SymbolCast::dumpToStream(raw_ostream &os) const { - os << '(' << ToTy.getAsString() << ") ("; + os << '(' << ToTy << ") ("; Operand->dumpToStream(os); os << ')'; } void SymbolConjured::dumpToStream(raw_ostream &os) const { - os << getKindStr() << getSymbolID() << '{' << T.getAsString() << ", LC" - << LCtx->getID(); + os << getKindStr() << getSymbolID() << '{' << T << ", LC" << LCtx->getID(); if (S) os << ", S" << S->getID(LCtx->getDecl()->getASTContext()); else @@ -90,15 +89,13 @@ } void SymbolMetadata::dumpToStream(raw_ostream &os) const { - os << getKindStr() << getSymbolID() << '{' << getRegion() << ',' - << T.getAsString() << '}'; + os << getKindStr() << getSymbolID() << '{' << getRegion() << ',' << T << '}'; } void SymbolData::anchor() {} void SymbolRegionValue::dumpToStream(raw_ostream &os) const { - os << getKindStr() << getSymbolID() << '<' << getType().getAsString() << ' ' - << R << '>'; + os << getKindStr() << getSymbolID() << '<' << getType() << ' ' << R << '>'; } bool SymExpr::symbol_iterator::operator==(const symbol_iterator &X) const { diff --git a/clang/unittests/AST/ASTTraverserTest.cpp b/clang/unittests/AST/ASTTraverserTest.cpp --- a/clang/unittests/AST/ASTTraverserTest.cpp +++ b/clang/unittests/AST/ASTTraverserTest.cpp @@ -60,7 +60,7 @@ if (const auto *F = Init->getAnyMember()) { OS << " '" << F->getNameAsString() << "'"; } else if (auto const *TSI = Init->getTypeSourceInfo()) { - OS << " '" << TSI->getType().getAsString() << "'"; + OS << " '" << TSI->getType() << "'"; } } @@ -81,7 +81,7 @@ OS << "TemplateArgument"; switch (A.getKind()) { case TemplateArgument::Type: { - OS << " type " << A.getAsType().getAsString(); + OS << " type " << A.getAsType(); break; } default: