summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEugene Zelenko <eugene.zelenko@gmail.com>2018-04-05 21:09:03 +0000
committerEugene Zelenko <eugene.zelenko@gmail.com>2018-04-05 21:09:03 +0000
commiteb25fa3277eb94e38a0ba814de906904f2e6ea17 (patch)
tree3756fe00ae579fad7bcd3f62c5524f0d1cd086ff /lib
parent783fea130264748edda5b25f17019543c458b20f (diff)
downloadclang-eb25fa3277eb94e38a0ba814de906904f2e6ea17.tar.gz
[Sema] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329346 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/CodeCompleteConsumer.cpp20
-rw-r--r--lib/Sema/DeclSpec.cpp39
-rw-r--r--lib/Sema/IdentifierResolver.cpp22
-rw-r--r--lib/Sema/SemaFixItUtils.cpp29
4 files changed, 66 insertions, 44 deletions
diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp
index d012e55e3d..f88ee1a97a 100644
--- a/lib/Sema/CodeCompleteConsumer.cpp
+++ b/lib/Sema/CodeCompleteConsumer.cpp
@@ -285,11 +285,11 @@ CodeCompletionString::CodeCompletionString(const Chunk *Chunks,
assert(NumChunks <= 0xffff);
assert(NumAnnotations <= 0xffff);
- Chunk *StoredChunks = reinterpret_cast<Chunk *>(this + 1);
+ auto *StoredChunks = reinterpret_cast<Chunk *>(this + 1);
for (unsigned I = 0; I != NumChunks; ++I)
StoredChunks[I] = Chunks[I];
- const char **StoredAnnotations = reinterpret_cast<const char **>(StoredChunks + NumChunks);
+ const auto **StoredAnnotations = reinterpret_cast<const char **>(StoredChunks + NumChunks);
for (unsigned I = 0; I != NumAnnotations; ++I)
StoredAnnotations[I] = Annotations[I];
}
@@ -340,14 +340,14 @@ const char *CodeCompletionAllocator::CopyString(const Twine &String) {
// FIXME: It would be more efficient to teach Twine to tell us its size and
// then add a routine there to fill in an allocated char* with the contents
// of the string.
- char *Mem = (char *)Allocate(Ref.size() + 1, 1);
+ auto *Mem = (char *)Allocate(Ref.size() + 1, 1);
std::copy(Ref.begin(), Ref.end(), Mem);
Mem[Ref.size()] = 0;
return Mem;
}
StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) {
- const NamedDecl *ND = dyn_cast<NamedDecl>(DC);
+ const auto *ND = dyn_cast<NamedDecl>(DC);
if (!ND)
return {};
@@ -364,7 +364,7 @@ StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) {
// Find the interesting names.
SmallVector<const DeclContext *, 2> Contexts;
while (DC && !DC->isFunctionOrMethod()) {
- if (const NamedDecl *ND = dyn_cast<NamedDecl>(DC)) {
+ if (const auto *ND = dyn_cast<NamedDecl>(DC)) {
if (ND->getIdentifier())
Contexts.push_back(DC);
}
@@ -384,10 +384,10 @@ StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) {
}
const DeclContext *CurDC = Contexts[I-1];
- if (const ObjCCategoryImplDecl *CatImpl = dyn_cast<ObjCCategoryImplDecl>(CurDC))
+ if (const auto *CatImpl = dyn_cast<ObjCCategoryImplDecl>(CurDC))
CurDC = CatImpl->getCategoryDecl();
- if (const ObjCCategoryDecl *Cat = dyn_cast<ObjCCategoryDecl>(CurDC)) {
+ if (const auto *Cat = dyn_cast<ObjCCategoryDecl>(CurDC)) {
const ObjCInterfaceDecl *Interface = Cat->getClassInterface();
if (!Interface) {
// Assign an empty StringRef but with non-null data to distinguish
@@ -413,7 +413,7 @@ CodeCompletionString *CodeCompletionBuilder::TakeString() {
sizeof(CodeCompletionString) + sizeof(Chunk) * Chunks.size() +
sizeof(const char *) * Annotations.size(),
alignof(CodeCompletionString));
- CodeCompletionString *Result
+ auto *Result
= new (Mem) CodeCompletionString(Chunks.data(), Chunks.size(),
Priority, Availability,
Annotations.data(), Annotations.size(),
@@ -463,7 +463,7 @@ void CodeCompletionBuilder::addParentContext(const DeclContext *DC) {
if (DC->isFunctionOrMethod())
return;
- const NamedDecl *ND = dyn_cast<NamedDecl>(DC);
+ const auto *ND = dyn_cast<NamedDecl>(DC);
if (!ND)
return;
@@ -655,7 +655,7 @@ void CodeCompletionResult::computeCursorKindAndAvailability(bool Accessible) {
break;
}
- if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(Declaration))
+ if (const auto *Function = dyn_cast<FunctionDecl>(Declaration))
if (Function->isDeleted())
Availability = CXAvailability_NotAvailable;
diff --git a/lib/Sema/DeclSpec.cpp b/lib/Sema/DeclSpec.cpp
index 2fad5a18ba..292898cbf0 100644
--- a/lib/Sema/DeclSpec.cpp
+++ b/lib/Sema/DeclSpec.cpp
@@ -1,4 +1,4 @@
-//===--- DeclSpec.cpp - Declaration Specifier Semantic Analysis -----------===//
+//===- DeclSpec.cpp - Declaration Specifier Semantic Analysis -------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -13,20 +13,35 @@
#include "clang/Sema/DeclSpec.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/Expr.h"
#include "clang/AST/LocInfoType.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/ExceptionSpecificationType.h"
+#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/OpenCLOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
+#include "clang/Sema/AttributeList.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaDiagnostic.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/ErrorHandling.h"
+#include <cassert>
#include <cstring>
-using namespace clang;
+#include <utility>
+using namespace clang;
void UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) {
assert(TemplateId && "NULL template-id annotation?");
@@ -135,14 +150,14 @@ void CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) {
SourceLocation CXXScopeSpec::getLastQualifierNameLoc() const {
if (!Builder.getRepresentation())
- return SourceLocation();
+ return {};
return Builder.getTemporary().getLocalBeginLoc();
}
NestedNameSpecifierLoc
CXXScopeSpec::getWithLocInContext(ASTContext &Context) const {
if (!Builder.getRepresentation())
- return NestedNameSpecifierLoc();
+ return {};
return Builder.getWithLocInContext(Context);
}
@@ -289,7 +304,7 @@ void Declarator::setDecompositionBindings(
Name.EndLocation = RSquareLoc;
// Allocate storage for bindings and stash them away.
- if (Bindings.size()) {
+ if (!Bindings.empty()) {
if (!InlineStorageUsed &&
Bindings.size() <= llvm::array_lengthof(InlineBindings)) {
BindingGroup.Bindings = InlineBindings;
@@ -306,8 +321,8 @@ void Declarator::setDecompositionBindings(
}
bool Declarator::isDeclarationOfFunction() const {
- for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
- switch (DeclTypeInfo[i].Kind) {
+ for (const auto &i : DeclTypeInfo) {
+ switch (i.Kind) {
case DeclaratorChunk::Function:
return true;
case DeclaratorChunk::Paren:
@@ -373,7 +388,7 @@ bool Declarator::isDeclarationOfFunction() const {
if (QT.isNull())
return false;
- if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT))
+ if (const auto *LIT = dyn_cast<LocInfoType>(QT))
QT = LIT->getType();
if (QT.isNull())
@@ -407,7 +422,6 @@ bool DeclSpec::hasTagDefinition() const {
/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
/// declaration specifier includes.
-///
unsigned DeclSpec::getParsedSpecifiers() const {
unsigned Res = 0;
if (StorageClassSpec != SCS_unspecified ||
@@ -482,7 +496,6 @@ const char *DeclSpec::getSpecifierName(TSC C) {
llvm_unreachable("Unknown typespec!");
}
-
const char *DeclSpec::getSpecifierName(TSS S) {
switch (S) {
case TSS_unspecified: return "unspecified";
@@ -777,16 +790,14 @@ bool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
bool DeclSpec::SetTypePipe(bool isPipe, SourceLocation Loc,
const char *&PrevSpec, unsigned &DiagID,
const PrintingPolicy &Policy) {
-
if (TypeSpecType != TST_unspecified) {
PrevSpec = DeclSpec::getSpecifierName((TST)TypeSpecType, Policy);
DiagID = diag::err_invalid_decl_spec_combination;
return true;
}
- if (isPipe) {
+ if (isPipe)
TypeSpecPipe = TSP_pipe;
- }
return false;
}
@@ -975,7 +986,7 @@ void DeclSpec::SaveWrittenBuiltinSpecs() {
writtenBS.Type = getTypeSpecType();
// Search the list of attributes for the presence of a mode attribute.
writtenBS.ModeAttr = false;
- AttributeList* attrs = getAttributes().getList();
+ AttributeList *attrs = getAttributes().getList();
while (attrs) {
if (attrs->getKind() == AttributeList::AT_Mode) {
writtenBS.ModeAttr = true;
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp
index f31c5174bf..1b3487d4c4 100644
--- a/lib/Sema/IdentifierResolver.cpp
+++ b/lib/Sema/IdentifierResolver.cpp
@@ -147,7 +147,7 @@ void IdentifierResolver::AddDecl(NamedDecl *D) {
if (IdentifierInfo *II = Name.getAsIdentifierInfo())
updatingIdentifier(*II);
- void *Ptr = Name.getFETokenInfo<void>();
+ auto *Ptr = Name.getFETokenInfo<void>();
if (!Ptr) {
Name.setFETokenInfo(D);
@@ -159,7 +159,7 @@ void IdentifierResolver::AddDecl(NamedDecl *D) {
if (isDeclPtr(Ptr)) {
Name.setFETokenInfo(nullptr);
IDI = &(*IdDeclInfos)[Name];
- NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
+ auto *PrevD = static_cast<NamedDecl *>(Ptr);
IDI->AddDecl(PrevD);
} else
IDI = toIdDeclInfo(Ptr);
@@ -172,7 +172,7 @@ void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) {
if (IdentifierInfo *II = Name.getAsIdentifierInfo())
updatingIdentifier(*II);
- void *Ptr = Name.getFETokenInfo<void>();
+ auto *Ptr = Name.getFETokenInfo<void>();
if (!Ptr) {
AddDecl(D);
@@ -184,7 +184,7 @@ void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) {
// as appropriate.
if (Pos == iterator()) {
// Add the new declaration before the existing declaration.
- NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
+ auto *PrevD = static_cast<NamedDecl *>(Ptr);
RemoveDecl(PrevD);
AddDecl(D);
AddDecl(PrevD);
@@ -213,7 +213,7 @@ void IdentifierResolver::RemoveDecl(NamedDecl *D) {
if (IdentifierInfo *II = Name.getAsIdentifierInfo())
updatingIdentifier(*II);
- void *Ptr = Name.getFETokenInfo<void>();
+ auto *Ptr = Name.getFETokenInfo<void>();
assert(Ptr && "Didn't find this decl on its identifier's chain!");
@@ -232,11 +232,11 @@ IdentifierResolver::begin(DeclarationName Name) {
if (IdentifierInfo *II = Name.getAsIdentifierInfo())
readingIdentifier(*II);
- void *Ptr = Name.getFETokenInfo<void>();
+ auto *Ptr = Name.getFETokenInfo<void>();
if (!Ptr) return end();
if (isDeclPtr(Ptr))
- return iterator(static_cast<NamedDecl*>(Ptr));
+ return iterator(static_cast<NamedDecl *>(Ptr));
IdDeclInfo *IDI = toIdDeclInfo(Ptr);
@@ -304,7 +304,7 @@ bool IdentifierResolver::tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name){
if (IdentifierInfo *II = Name.getAsIdentifierInfo())
readingIdentifier(*II);
- void *Ptr = Name.getFETokenInfo<void>();
+ auto *Ptr = Name.getFETokenInfo<void>();
if (!Ptr) {
Name.setFETokenInfo(D);
@@ -314,7 +314,7 @@ bool IdentifierResolver::tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name){
IdDeclInfo *IDI;
if (isDeclPtr(Ptr)) {
- NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
+ auto *PrevD = static_cast<NamedDecl *>(Ptr);
switch (compareDeclarations(PrevD, D)) {
case DMK_Different:
@@ -397,7 +397,7 @@ void IdentifierResolver::updatingIdentifier(IdentifierInfo &II) {
/// It creates a new IdDeclInfo if one was not created before for this id.
IdentifierResolver::IdDeclInfo &
IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) {
- void *Ptr = Name.getFETokenInfo<void>();
+ auto *Ptr = Name.getFETokenInfo<void>();
if (Ptr) return *toIdDeclInfo(Ptr);
@@ -415,7 +415,7 @@ IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) {
void IdentifierResolver::iterator::incrementSlowCase() {
NamedDecl *D = **this;
- void *InfoPtr = D->getDeclName().getFETokenInfo<void>();
+ auto *InfoPtr = D->getDeclName().getFETokenInfo<void>();
assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?");
IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
diff --git a/lib/Sema/SemaFixItUtils.cpp b/lib/Sema/SemaFixItUtils.cpp
index 714fbedf09..3cc26c0938 100644
--- a/lib/Sema/SemaFixItUtils.cpp
+++ b/lib/Sema/SemaFixItUtils.cpp
@@ -1,4 +1,4 @@
-//===--- SemaFixItUtils.cpp - Sema FixIts ---------------------------------===//
+//===- SemaFixItUtils.cpp - Sema FixIts -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -11,12 +11,24 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/Sema/SemaFixItUtils.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclarationName.h"
+#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
+#include "clang/AST/Type.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Sema.h"
-#include "clang/Sema/SemaFixItUtils.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include <cassert>
+#include <string>
using namespace clang;
@@ -91,7 +103,7 @@ bool ConversionFixItGenerator::tryToFixConversion(const Expr *FullExpr,
// Check if the argument needs to be dereferenced:
// (type * -> type) or (type * -> type &).
- if (const PointerType *FromPtrTy = dyn_cast<PointerType>(FromQTy)) {
+ if (const auto *FromPtrTy = dyn_cast<PointerType>(FromQTy)) {
OverloadFixItKind FixKind = OFIK_Dereference;
bool CanConvert = CompareTypes(
@@ -103,7 +115,7 @@ bool ConversionFixItGenerator::tryToFixConversion(const Expr *FullExpr,
isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull))
return false;
- if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(Expr)) {
+ if (const auto *UO = dyn_cast<UnaryOperator>(Expr)) {
if (UO->getOpcode() == UO_AddrOf) {
FixKind = OFIK_RemoveTakeAddress;
Hints.push_back(FixItHint::CreateRemoval(
@@ -136,8 +148,7 @@ bool ConversionFixItGenerator::tryToFixConversion(const Expr *FullExpr,
CanConvert = CompareTypes(S.Context.getPointerType(FromQTy), ToQTy,
S, Begin, VK_RValue);
if (CanConvert) {
-
- if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(Expr)) {
+ if (const auto *UO = dyn_cast<UnaryOperator>(Expr)) {
if (UO->getOpcode() == UO_Deref) {
FixKind = OFIK_RemoveDereference;
Hints.push_back(FixItHint::CreateRemoval(
@@ -171,7 +182,7 @@ static std::string getScalarZeroExpressionForType(
// Suggest "0" for non-enumeration scalar types, unless we can find a
// better initializer.
if (T.isEnumeralType())
- return std::string();
+ return {};
if ((T.isObjCObjectPointerType() || T.isBlockPointerType()) &&
isMacroDefined(S, Loc, "nil"))
return "nil";
@@ -208,12 +219,12 @@ Sema::getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const {
const CXXRecordDecl *RD = T->getAsCXXRecordDecl();
if (!RD || !RD->hasDefinition())
- return std::string();
+ return {};
if (LangOpts.CPlusPlus11 && !RD->hasUserProvidedDefaultConstructor())
return "{}";
if (RD->isAggregate())
return " = {}";
- return std::string();
+ return {};
}
std::string