[PATCH] D138780: [include-cleaner] Minor fixes to parseIWYUPragma:
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 28 01:36:23 PST 2022
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a subscriber: kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
- remove assert that can fail for input `/\<newline>* */`
- assert was also checking the wrong condition: that the prefix *differed* from either `//` or from `/*`. Avoid use of strncmp where we can.
- add a comment that the brittleness of the text matching is intentional
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138780
Files:
clang-tools-extra/include-cleaner/lib/Record.cpp
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===================================================================
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -144,9 +144,13 @@
// FIXME: this is a mirror of clang::clangd::parseIWYUPragma, move to libTooling
// to share the code?
static llvm::Optional<StringRef> parseIWYUPragma(const char *Text) {
- assert(strncmp(Text, "//", 2) || strncmp(Text, "/*", 2));
+ // Skip the comment start, // or /*.
+ if (Text[0] != '/' || (Text[1] != '/' && Text[1] != '*'))
+ return llvm::None;
+ Text += 2;
+
+ // Per spec, direcitves are whitespace- and case-sensitive.
constexpr llvm::StringLiteral IWYUPragma = " IWYU pragma: ";
- Text += 2; // Skip the comment start, // or /*.
if (strncmp(Text, IWYUPragma.data(), IWYUPragma.size()))
return llvm::None;
Text += IWYUPragma.size();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138780.478157.patch
Type: text/x-patch
Size: 920 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221128/4efbc066/attachment.bin>
More information about the cfe-commits
mailing list