[PATCH] D25363: Store a SourceRange for multi-token builtin types
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 7 04:39:18 PDT 2016
malcolm.parsons created this revision.
malcolm.parsons added a reviewer: Prazek.
malcolm.parsons added a subscriber: cfe-commits.
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();
https://reviews.llvm.org/D25363
Files:
include/clang/AST/TypeLoc.h
lib/Sema/DeclSpec.cpp
lib/Sema/SemaType.cpp
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -4920,10 +4920,10 @@
// Try to have a meaningful source location.
if (TL.getWrittenSignSpec() != TSS_unspecified)
// Sign spec loc overrides the others (e.g., 'unsigned long').
- TL.setBuiltinLoc(DS.getTypeSpecSignLoc());
+ TL.setBuiltinLocStart(DS.getTypeSpecSignLoc());
else if (TL.getWrittenWidthSpec() != TSW_unspecified)
// Width spec loc overrides type spec loc (e.g., 'short int').
- TL.setBuiltinLoc(DS.getTypeSpecWidthLoc());
+ TL.setBuiltinLocStart(DS.getTypeSpecWidthLoc());
}
}
void VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
Index: lib/Sema/DeclSpec.cpp
===================================================================
--- lib/Sema/DeclSpec.cpp
+++ lib/Sema/DeclSpec.cpp
@@ -618,6 +618,8 @@
else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
TypeSpecWidth = W;
+ // Remember location of the last 'long'
+ TSTLoc = Loc;
return false;
}
Index: include/clang/AST/TypeLoc.h
===================================================================
--- include/clang/AST/TypeLoc.h
+++ include/clang/AST/TypeLoc.h
@@ -510,7 +510,7 @@
struct BuiltinLocInfo {
- SourceLocation BuiltinLoc;
+ SourceRange BuiltinRange;
};
/// \brief Wrapper for source info for builtin types.
@@ -520,10 +520,17 @@
BuiltinLocInfo> {
public:
SourceLocation getBuiltinLoc() const {
- return getLocalData()->BuiltinLoc;
+ return getLocalData()->BuiltinRange.getBegin();
}
void setBuiltinLoc(SourceLocation Loc) {
- getLocalData()->BuiltinLoc = Loc;
+ getLocalData()->BuiltinRange = {Loc, Loc};
+ }
+ void setBuiltinLocStart(SourceLocation Loc) {
+ if (getLocalData()->BuiltinRange.getEnd().isValid()) {
+ getLocalData()->BuiltinRange.setBegin(Loc);
+ } else {
+ setBuiltinLoc(Loc);
+ }
}
SourceLocation getNameLoc() const { return getBuiltinLoc(); }
@@ -552,7 +559,7 @@
}
SourceRange getLocalSourceRange() const {
- return SourceRange(getBuiltinLoc(), getBuiltinLoc());
+ return getLocalData()->BuiltinRange;
}
TypeSpecifierSign getWrittenSignSpec() const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25363.73915.patch
Type: text/x-patch
Size: 2414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161007/5d042a9f/attachment.bin>
More information about the cfe-commits
mailing list