[PATCH] D125727: Avoid suggesting typoed directives in `.S` files

Ken Matsui via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 16 14:26:08 PDT 2022


ken-matsui created this revision.
ken-matsui added a reviewer: aaron.ballman.
Herald added a project: All.
ken-matsui requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch is itended to avoid suggesting typoed directives in `.S` files to support the cases of `#` directives treated as comments or various pseudo-ops. The feature is implemented in https://reviews.llvm.org/D124726. Fixes: https://reviews.llvm.org/D124726#3516346.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125727

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/suggest-typoed-directive.S


Index: clang/test/Preprocessor/suggest-typoed-directive.S
===================================================================
--- /dev/null
+++ clang/test/Preprocessor/suggest-typoed-directive.S
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -S %s -o %t
+
+// expected-no-diagnostics
+
+#ifdef UNDEFINED
+#id
+#ifd
+#ifde
+#elf
+#elsif
+#elseif
+#elfidef
+#elfindef
+#elfinndef
+#els
+#endi
+#endif
+
+#ifdef UNDEFINED
+# in in order to perform
+#endif
+
+#ifdef UNDEFINED
+#i
+#endif
+
+#if special_compiler
+#special_compiler_directive
+#endif
Index: clang/lib/Lex/PPDirectives.cpp
===================================================================
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -481,6 +481,10 @@
 void Preprocessor::SuggestTypoedDirective(const Token &Tok,
                                           StringRef Directive,
                                           const SourceLocation &EndLoc) const {
+  // If this is a `.S` file, treat unknown # directives as non-preprocessor
+  // directives.
+  if (getLangOpts().AsmPreprocessor) return;
+
   std::vector<StringRef> Candidates = {
       "if", "ifdef", "ifndef", "elif", "else", "endif"
   };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125727.429854.patch
Type: text/x-patch
Size: 1207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220516/980d49f5/attachment.bin>


More information about the cfe-commits mailing list