Index: clang/lib/Frontend/Rewrite/InclusionRewriter.cpp =================================================================== --- clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -527,16 +527,28 @@ PP.LookUpIdentifierInfo(RawToken); if (RawToken.is(tok::identifier)) { + // Try to handle macros in the form of + // '#define QT_HAS_INCLUDE(x) __has_include(x)'. + const Token *ExpandedToken = &RawToken; + if (const MacroInfo *macroInfo = + PP.getMacroInfo(RawToken.getIdentifierInfo())) { + if (macroInfo->getNumTokens() > 0 && + macroInfo->getReplacementToken(0).is(tok::identifier)) { + ExpandedToken = ¯oInfo->getReplacementToken(0); + } + } + bool HasFile; SourceLocation Loc = RawToken.getLocation(); // Rewrite __has_include(x) - if (RawToken.getIdentifierInfo()->isStr("__has_include")) { + if (ExpandedToken->getIdentifierInfo()->isStr( + "__has_include")) { if (!HandleHasInclude(FileId, RawLex, nullptr, RawToken, HasFile)) continue; // Rewrite __has_include_next(x) - } else if (RawToken.getIdentifierInfo()->isStr( + } else if (ExpandedToken->getIdentifierInfo()->isStr( "__has_include_next")) { if (DirLookup) ++DirLookup; Index: clang/test/Frontend/rewrite-includes-has-include-macro.c =================================================================== --- /dev/null +++ clang/test/Frontend/rewrite-includes-has-include-macro.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -verify -E -frewrite-includes %s -o - | FileCheck -strict-whitespace %s +// expected-no-diagnostics + +#define MACRO_HAS_INCLUDE(x) __has_include(x) +#if MACRO_HAS_INCLUDE() +#endif + +// CHECK: #define MACRO_HAS_INCLUDE(x) __has_include(x) +// CHECK-NEXT: #if (0)/*MACRO_HAS_INCLUDE()*/ +// CHECK-NEXT: #endif