Handle out-of-date identifiers in macros

After adopting the stable/20221013 clang branch, ClangImporter started seeing out-of-date identifiers in macros where it previously never had. Force these identifiers to update themselves before we read the macro definition out of them.

Fixes rdar://104456939.
This commit is contained in:
Becca Royal-Gordon
2023-01-26 13:26:14 -08:00
parent 00090f5e14
commit ced4cb0681
3 changed files with 16 additions and 0 deletions

View File

@@ -472,6 +472,15 @@ static ValueDecl *importMacro(ClangImporter::Implementation &impl,
if (tok.is(clang::tok::identifier)) {
auto clangID = tok.getIdentifierInfo();
if (clangID->isOutOfDate())
// Update the identifier with macro definitions subsequently loaded from
// a module/AST file. We're supposed to use
// Preprocessor::HandleIdentifier() to do that, but that method does too
// much to call it here. Instead, we call getLeafModuleMacros() for its
// side effect of calling updateOutOfDateIdentifier().
// FIXME: clang should give us a better way to do this.
(void)impl.getClangPreprocessor().getLeafModuleMacros(clangID);
// If it's an identifier that is itself a macro, look into that macro.
if (clangID->hasMacroDefinition()) {
auto isNilMacro =

View File

@@ -1,4 +1,5 @@
@import ObjectiveC;
#import <stdbool.h>
@class NSArray;
@@ -11,3 +12,5 @@
+ (nonnull MyPredicate *)and:(nonnull NSArray *)subpredicates;
+ (nonnull MyPredicate *)or:(nonnull NSArray *)subpredicates;
@end
#define MY_TRUE true

View File

@@ -58,3 +58,7 @@ let not = MyPredicate.not()
let and = MyPredicate.and([])
let or = MyPredicate.or([not, and])
// When a bridging header macro refers to a macro imported from another module,
// do we actually find the other module's macro definition, or do we just fail
// to import it?
if MY_TRUE == 1 {}