Skip to content

Commit cca2872

Browse files
Fix issue SR-9482.
Solution based on the outline in the issue description. Also fixes the corresponding rdar://problem/46644027.
1 parent 5830413 commit cca2872

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/ClangImporter/ImportName.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,9 +1729,14 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
17291729

17301730
/// Returns true if it is expected that the macro is ignored.
17311731
static bool shouldIgnoreMacro(StringRef name, const clang::MacroInfo *macro) {
1732-
// Ignore include guards.
1733-
if (macro->isUsedForHeaderGuard())
1734-
return true;
1732+
// Ignore include guards. Try not to ignore definitions of useful constants,
1733+
// which may end up looking like include guards.
1734+
if (macro->isUsedForHeaderGuard() && macro->getNumTokens() == 1) {
1735+
auto tok = macro->tokens()[0];
1736+
if (tok.isLiteral()
1737+
&& StringRef(tok.getLiteralData(), tok.getLength()) == "1")
1738+
return true;
1739+
}
17351740

17361741
// If there are no tokens, there is nothing to convert.
17371742
if (macro->tokens_empty())

test/ClangImporter/macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,5 @@ func testNulls() {
179179

180180
func testHeaderGuard() {
181181
_ = IS_HEADER_GUARD // expected-error {{use of unresolved identifier 'IS_HEADER_GUARD'}}
182-
_ = LOOKS_LIKE_HEADER_GUARD_BUT_IS_USEFUL_CONSTANT // expected-error {{use of unresolved identifier 'LOOKS_LIKE_HEADER_GUARD_BUT_IS_USEFUL_CONSTANT'}}
182+
_ = LOOKS_LIKE_HEADER_GUARD_BUT_IS_USEFUL_CONSTANT
183183
}

0 commit comments

Comments
 (0)