[clang] Avoid suggesting typoed directives in .S files

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.

Reviewed By: nickdesaulniers

Differential Revision: https://reviews.llvm.org/D125727
This commit is contained in:
Ken Matsui 2022-05-16 15:36:54 -07:00 committed by Nick Desaulniers
parent 7694442011
commit 45e01ce5fe
2 changed files with 33 additions and 0 deletions

View File

@ -481,6 +481,10 @@ Optional<unsigned> Preprocessor::getSkippedRangeForExcludedConditionalBlock(
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"
};

View File

@ -0,0 +1,29 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// 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