Skip to content

Commit 3740572

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents cf5c9b2 + 08ab7ea commit 3740572

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,8 @@ func testNulls() {
176176
let _: Int = DEPRECATED_ONE // expected-error {{use of unresolved identifier 'DEPRECATED_ONE'}}
177177
let _: Int = OKAY_TYPED_ONE // expected-error {{cannot convert value of type 'okay_t' (aka 'UInt32') to specified type 'Int'}}
178178
}
179+
180+
func testHeaderGuard() {
181+
_ = IS_HEADER_GUARD // expected-error {{use of unresolved identifier 'IS_HEADER_GUARD'}}
182+
_ = LOOKS_LIKE_HEADER_GUARD_BUT_IS_USEFUL_CONSTANT
183+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifndef IS_HEADER_GUARD
2+
#define IS_HEADER_GUARD
3+
#endif

test/Inputs/clang-importer-sdk/usr/include/macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <macros_impl.h>
22
#include <macros_private_impl.h>
3+
#include <header_guard.h>
4+
#include <not_a_header_guard.h>
35

46
// Get Clang's NULL.
57
#include <stddef.h>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifndef LOOKS_LIKE_HEADER_GUARD_BUT_IS_USEFUL_CONSTANT
2+
#define LOOKS_LIKE_HEADER_GUARD_BUT_IS_USEFUL_CONSTANT 0xcafe
3+
#endif

0 commit comments

Comments
 (0)