Skip to content

Commit bf13452

Browse files
authored
[clang][transformer] Change name range-selector to return Error instead of an invalid range.
Previously, when the text in selected range was different from the decl's name, `name` returned an invalid range, which could cause crashes if `name` was nested in other range selectors that assumed always valid ranges. With this change, `name` returns an `Error` if it can't get the range.
1 parent e2ad554 commit bf13452

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

clang/lib/Tooling/Transformer/RangeSelector.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,12 @@ RangeSelector transformer::name(std::string ID) {
205205
// `foo<int>` for which this range will be too short. Doing so will
206206
// require subcasing `NamedDecl`, because it doesn't provide virtual
207207
// access to the \c DeclarationNameInfo.
208-
if (tooling::getText(R, *Result.Context) != D->getName())
209-
return CharSourceRange();
208+
StringRef Text = tooling::getText(R, *Result.Context);
209+
if (Text != D->getName())
210+
return llvm::make_error<StringError>(
211+
llvm::errc::not_supported,
212+
"Failed to get the name range for the decl. Name is " +
213+
D->getName() + ", but range is " + Text);
210214
return R;
211215
}
212216
if (const auto *E = Node.get<DeclRefExpr>()) {

0 commit comments

Comments
 (0)