Skip to content

Commit e8ad64c

Browse files
Work around compiler bug affecting partial_checked.c test.
1 parent cd6cccb commit e8ad64c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

clang/lib/3C/Utils.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,25 @@ SourceRange getDeclSourceRangeWithAnnotations(
615615
SR = VD->DeclaratorDecl::getSourceRange();
616616
else
617617
SR = D->getSourceRange();
618-
SourceLocation OldEnd = SR.getEnd();
618+
if (!SR.isValid())
619+
return SR;
620+
SourceLocation DeclEnd = SR.getEnd();
621+
622+
// Partial workaround for a compiler bug where if D has certain checked
623+
// pointer types such as `_Ptr<int *(void)>` (seen in the partial_checked.c
624+
// regression test), D->getSourceRange() returns only the _Ptr token (TODO:
625+
// file an issue). Always extend the range at least through the name (given by
626+
// D->getLocation()). That fixes the `_Ptr<int *(void)> x` case but not cases
627+
// with additional syntax after the name, such as `_Ptr<int *(void)> x[10]`.
628+
SourceLocation DeclLoc = D->getLocation();
629+
if (SM.isBeforeInTranslationUnit(DeclEnd, DeclLoc))
630+
DeclEnd = DeclLoc;
631+
619632
SourceLocation AnnotationsEnd = getCheckedCAnnotationsEnd(D);
620633
if (AnnotationsEnd.isValid() &&
621-
(!OldEnd.isValid() ||
622-
SM.isBeforeInTranslationUnit(OldEnd, AnnotationsEnd)))
623-
SR.setEnd(AnnotationsEnd);
634+
SM.isBeforeInTranslationUnit(DeclEnd, AnnotationsEnd))
635+
DeclEnd = AnnotationsEnd;
636+
637+
SR.setEnd(DeclEnd);
624638
return SR;
625639
}

0 commit comments

Comments
 (0)