diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp --- a/clang/lib/Lex/PPDirectives.cpp +++ b/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 Candidates = { "if", "ifdef", "ifndef", "elif", "else", "endif" }; diff --git a/clang/test/Preprocessor/suggest-typoed-directive.S b/clang/test/Preprocessor/suggest-typoed-directive.S new file mode 100644 --- /dev/null +++ b/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