Skip to content

Commit 45e01ce

Browse files
ken-matsuinickdesaulniers
authored andcommitted
[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
1 parent 7694442 commit 45e01ce

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

clang/lib/Lex/PPDirectives.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,10 @@ Optional<unsigned> Preprocessor::getSkippedRangeForExcludedConditionalBlock(
481481
void Preprocessor::SuggestTypoedDirective(const Token &Tok,
482482
StringRef Directive,
483483
const SourceLocation &EndLoc) const {
484+
// If this is a `.S` file, treat unknown # directives as non-preprocessor
485+
// directives.
486+
if (getLangOpts().AsmPreprocessor) return;
487+
484488
std::vector<StringRef> Candidates = {
485489
"if", "ifdef", "ifndef", "elif", "else", "endif"
486490
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
3+
// expected-no-diagnostics
4+
5+
#ifdef UNDEFINED
6+
#id
7+
#ifd
8+
#ifde
9+
#elf
10+
#elsif
11+
#elseif
12+
#elfidef
13+
#elfindef
14+
#elfinndef
15+
#els
16+
#endi
17+
#endif
18+
19+
#ifdef UNDEFINED
20+
# in in order to perform
21+
#endif
22+
23+
#ifdef UNDEFINED
24+
#i
25+
#endif
26+
27+
#if special_compiler
28+
#special_compiler_directive
29+
#endif

0 commit comments

Comments
 (0)