Skip to content

Commit b272173

Browse files
committed
[Clang][Frontend] Fix a crash when -Wdocumentation is used
This commit resolves a crash issue in Clang's frontend caused while using the `-Wdocumentation` compiler flag. The flaw was due to the lack of necessary checks before the extraction of text between the comment and the declaration in the `ASTContext.cpp` file. Specifically, there was no verification to ensure that the second component of the declaration location's decomposition is not less than the comment's end offset. This could lead to an invalid length being passed to the `StringRef` constructor, triggering the crash. I have added a check to prevent this crash from occurring. Fixes llvm#68524.
1 parent 32f7197 commit b272173

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ RawComment *ASTContext::getRawCommentForDeclNoCacheImpl(
344344
if (Invalid)
345345
return nullptr;
346346

347+
if (DeclLocDecomp.second < CommentEndOffset)
348+
return nullptr;
349+
347350
// Extract text between the comment and declaration.
348351
StringRef Text(Buffer + CommentEndOffset,
349352
DeclLocDecomp.second - CommentEndOffset);

0 commit comments

Comments
 (0)