diff options
author | Malcolm Parsons <malcolm.parsons@gmail.com> | 2016-10-21 21:13:56 +0000 |
---|---|---|
committer | Malcolm Parsons <malcolm.parsons@gmail.com> | 2016-10-21 21:13:56 +0000 |
commit | 57c09c8e23ec30c61d31fbb89f97c27413c3e8fe (patch) | |
tree | 1f341355f3b7684916e1b203733f6cec3e53ca94 /clang/include | |
parent | 8659d16631fdd1ff519a25d6867ddd9dbda8aea9 (diff) | |
download | bcm5719-llvm-57c09c8e23ec30c61d31fbb89f97c27413c3e8fe.tar.gz bcm5719-llvm-57c09c8e23ec30c61d31fbb89f97c27413c3e8fe.zip |
[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
Diffstat (limited to 'clang/include')
-rw-r--r-- | clang/include/clang/AST/TypeLoc.h | 17 | ||||
-rw-r--r-- | clang/include/clang/Sema/DeclSpec.h | 6 |
2 files changed, 17 insertions, 6 deletions
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<UnqualTypeLoc, BuiltinLocInfo> { 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; } |