Skip to content

[ClangImporter] In shouldIgnoreMacro() Use Preprocessor::getSpellingOfSingleCharacterNumericConstant() for determining if a macro is '1' #27432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/ClangImporter/ImportName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1728,13 +1728,14 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
}

/// Returns true if it is expected that the macro is ignored.
static bool shouldIgnoreMacro(StringRef name, const clang::MacroInfo *macro) {
static bool shouldIgnoreMacro(StringRef name, const clang::MacroInfo *macro,
clang::Preprocessor &PP) {
// Ignore include guards. Try not to ignore definitions of useful constants,
// which may end up looking like include guards.
if (macro->isUsedForHeaderGuard() && macro->getNumTokens() == 1) {
auto tok = macro->tokens()[0];
if (tok.isLiteral()
&& StringRef(tok.getLiteralData(), tok.getLength()) == "1")
if (tok.is(clang::tok::numeric_constant) && tok.getLength() == 1 &&
PP.getSpellingOfSingleCharacterNumericConstant(tok) == '1')
return true;
}

Expand All @@ -1760,14 +1761,15 @@ static bool shouldIgnoreMacro(StringRef name, const clang::MacroInfo *macro) {

bool ClangImporter::shouldIgnoreMacro(StringRef Name,
const clang::MacroInfo *Macro) {
return ::shouldIgnoreMacro(Name, Macro);
return ::shouldIgnoreMacro(Name, Macro, Impl.getClangPreprocessor());
}

Identifier
NameImporter::importMacroName(const clang::IdentifierInfo *clangIdentifier,
const clang::MacroInfo *macro) {
// If we're supposed to ignore this macro, return an empty identifier.
if (::shouldIgnoreMacro(clangIdentifier->getName(), macro))
if (::shouldIgnoreMacro(clangIdentifier->getName(), macro,
getClangPreprocessor()))
return Identifier();

// No transformation is applied to the name.
Expand Down