Skip to content

Commit 6808222

Browse files
committed
Use ASTContext rather than Sema in BoundsAttributedTypeLoc
1 parent e12afda commit 6808222

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

clang/include/clang/AST/TypeLoc.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "clang/AST/NestedNameSpecifierBase.h"
2020
#include "clang/AST/TemplateBase.h"
2121
#include "clang/AST/TypeBase.h"
22-
#include "clang/Basic/IdentifierTable.h"
2322
#include "clang/Basic/LLVM.h"
2423
#include "clang/Basic/SourceLocation.h"
2524
#include "clang/Basic/Specifiers.h"
@@ -43,7 +42,6 @@ class ObjCInterfaceDecl;
4342
class ObjCProtocolDecl;
4443
class ObjCTypeParamDecl;
4544
class ParmVarDecl;
46-
class Sema;
4745
class TemplateTypeParmDecl;
4846
class UnqualTypeLoc;
4947
class UnresolvedUsingTypenameDecl;
@@ -1320,8 +1318,8 @@ class BoundsAttributedTypeLoc
13201318
void setAttrRange(SourceRange Range) { getLocalData()->Range = Range; }
13211319
SourceRange getAttrRange() const { return getLocalData()->Range; }
13221320

1323-
StringRef getAttrNameAsWritten(Sema &S) const;
1324-
SourceRange getAttrNameRange(Sema &S) const;
1321+
StringRef getAttrNameAsWritten(const ASTContext &Ctx) const;
1322+
SourceRange getAttrNameRange(const ASTContext &Ctx) const;
13251323

13261324
unsigned getLocalDataSize() const { return sizeof(BoundsAttributedLocInfo); }
13271325
};

clang/lib/Sema/SemaBoundsSafety.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
///
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "clang/AST/ASTContext.h"
1516
#include "clang/AST/Decl.h"
1617
#include "clang/AST/Expr.h"
1718
#include "clang/AST/StmtVisitor.h"
@@ -243,25 +244,25 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes,
243244

244245
// FIXME: for some reason diagnostics highlight the end character, while
245246
// getSourceText() does not include the end character.
246-
static SourceRange getAttrNameRangeImpl(Sema &S, SourceLocation Begin,
247+
static SourceRange getAttrNameRangeImpl(const ASTContext &Ctx, SourceLocation Begin,
247248
bool IsForDiagnostics) {
248-
SourceManager &SM = S.getSourceManager();
249+
const SourceManager &SM = Ctx.getSourceManager();
249250
SourceLocation TokenStart = Begin;
250251
while (TokenStart.isMacroID())
251252
TokenStart = SM.getImmediateExpansionRange(TokenStart).getBegin();
252253
unsigned Offset = IsForDiagnostics ? 1 : 0;
253-
SourceLocation End = S.getLocForEndOfToken(TokenStart, Offset);
254+
SourceLocation End = Lexer::getLocForEndOfToken(TokenStart, Offset, SM, Ctx.getLangOpts());
254255
return {TokenStart, End};
255256
}
256257

257-
StringRef BoundsAttributedTypeLoc::getAttrNameAsWritten(Sema &S) const {
258-
SourceRange Range = getAttrNameRangeImpl(S, getAttrRange().getBegin(), false);
258+
StringRef BoundsAttributedTypeLoc::getAttrNameAsWritten(const ASTContext &Ctx) const {
259+
SourceRange Range = getAttrNameRangeImpl(Ctx, getAttrRange().getBegin(), false);
259260
CharSourceRange NameRange = CharSourceRange::getCharRange(Range);
260-
return Lexer::getSourceText(NameRange, S.getSourceManager(), S.getLangOpts());
261+
return Lexer::getSourceText(NameRange, Ctx.getSourceManager(), Ctx.getLangOpts());
261262
}
262263

263-
SourceRange BoundsAttributedTypeLoc::getAttrNameRange(Sema &S) const {
264-
return getAttrNameRangeImpl(S, getAttrRange().getBegin(), true);
264+
SourceRange BoundsAttributedTypeLoc::getAttrNameRange(const ASTContext &Ctx) const {
265+
return getAttrNameRangeImpl(Ctx, getAttrRange().getBegin(), true);
265266
}
266267

267268
static TypeSourceInfo *getTSI(const Decl *D) {
@@ -333,9 +334,9 @@ static void EmitIncompleteCountedByPointeeNotes(Sema &S,
333334
<< CATy->isOrNull();
334335
return;
335336
}
336-
SourceRange AttrSrcRange = CATL.getAttrNameRange(S);
337+
SourceRange AttrSrcRange = CATL.getAttrNameRange(S.getASTContext());
337338

338-
StringRef Spelling = CATL.getAttrNameAsWritten(S);
339+
StringRef Spelling = CATL.getAttrNameAsWritten(S.getASTContext());
339340
StringRef FixedSpelling =
340341
llvm::StringSwitch<StringRef>(Spelling)
341342
.Case("__counted_by", "__sized_by")

0 commit comments

Comments
 (0)