From 57c09c8e23ec30c61d31fbb89f97c27413c3e8fe Mon Sep 17 00:00:00 2001 From: Malcolm Parsons Date: Fri, 21 Oct 2016 21:13:56 +0000 Subject: [Sema] Store a SourceRange for multi-token builtin types Summary: clang-tidy's modernize-use-auto check uses the SourceRange of a TypeLoc when replacing the type with auto. This was producing the wrong result for multi-token builtin types like long long: -long long *ll = new long long(); +auto long *ll = new long long(); Reviewers: alexfh, hokein, rsmith, Prazek, aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25363 llvm-svn: 284885 --- clang/include/clang/AST/TypeLoc.h | 17 +++++++++++++---- clang/include/clang/Sema/DeclSpec.h | 6 ++++-- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'clang/include') diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h index d7dcb2db460..7de666838d4 100644 --- a/clang/include/clang/AST/TypeLoc.h +++ b/clang/include/clang/AST/TypeLoc.h @@ -512,7 +512,7 @@ private: struct BuiltinLocInfo { - SourceLocation BuiltinLoc; + SourceRange BuiltinRange; }; /// \brief Wrapper for source info for builtin types. @@ -522,10 +522,19 @@ class BuiltinTypeLoc : public ConcreteTypeLoc { public: SourceLocation getBuiltinLoc() const { - return getLocalData()->BuiltinLoc; + return getLocalData()->BuiltinRange.getBegin(); } void setBuiltinLoc(SourceLocation Loc) { - getLocalData()->BuiltinLoc = Loc; + getLocalData()->BuiltinRange = Loc; + } + void expandBuiltinRange(SourceRange Range) { + SourceRange &BuiltinRange = getLocalData()->BuiltinRange; + if (!BuiltinRange.getBegin().isValid()) { + BuiltinRange = Range; + } else { + BuiltinRange.setBegin(std::min(Range.getBegin(), BuiltinRange.getBegin())); + BuiltinRange.setEnd(std::max(Range.getEnd(), BuiltinRange.getEnd())); + } } SourceLocation getNameLoc() const { return getBuiltinLoc(); } @@ -554,7 +563,7 @@ public: } SourceRange getLocalSourceRange() const { - return SourceRange(getBuiltinLoc(), getBuiltinLoc()); + return getLocalData()->BuiltinRange; } TypeSpecifierSign getWrittenSignSpec() const { diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index 8f5bd04f112..9c0b9ec440e 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -380,7 +380,8 @@ private: SourceRange Range; SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc; - SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc; + SourceRange TSWRange; + SourceLocation TSCLoc, TSSLoc, TSTLoc, AltiVecLoc; /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union, /// typename, then this is the location of the named type (if present); /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and @@ -503,7 +504,8 @@ public: SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } - SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; } + SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); } + SourceRange getTypeSpecWidthRange() const { return TSWRange; } SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; } SourceLocation getTypeSpecSignLoc() const { return TSSLoc; } SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; } -- cgit v1.2.3