|
28 | 28 | #include "clang/AST/Decl.h"
|
29 | 29 | #include "clang/AST/DeclObjC.h"
|
30 | 30 | #include "clang/AST/Type.h"
|
| 31 | +#include "clang/Sema/Sema.h" |
31 | 32 | #include "clang/Basic/TargetInfo.h"
|
32 | 33 | #include "IRGenModule.h"
|
33 | 34 |
|
@@ -226,18 +227,14 @@ clang::CanQualType GenClangType::visitStructType(CanStructType type) {
|
226 | 227 | }
|
227 | 228 |
|
228 | 229 | static clang::CanQualType getClangBuiltinTypeFromTypedef(
|
229 |
| - const clang::ASTContext &context, StringRef typedefName) { |
230 |
| - auto identifier = &context.Idents.get(typedefName); |
231 |
| - auto lookup = context.getTranslationUnitDecl()->lookup(identifier); |
| 230 | + clang::Sema &sema, StringRef typedefName) { |
| 231 | + auto &context = sema.getASTContext(); |
232 | 232 |
|
233 |
| - clang::TypedefDecl *typedefDecl = nullptr; |
234 |
| - for (auto found : lookup) { |
235 |
| - auto foundTypedef = dyn_cast<clang::TypedefDecl>(found); |
236 |
| - if (!foundTypedef) |
237 |
| - continue; |
238 |
| - typedefDecl = foundTypedef; |
239 |
| - break; |
240 |
| - } |
| 233 | + auto identifier = &context.Idents.get(typedefName); |
| 234 | + auto found = sema.LookupSingleName(sema.TUScope, identifier, |
| 235 | + clang::SourceLocation(), |
| 236 | + clang::Sema::LookupOrdinaryName); |
| 237 | + auto typedefDecl = dyn_cast_or_null<clang::TypedefDecl>(found); |
241 | 238 | if (!typedefDecl)
|
242 | 239 | return {};
|
243 | 240 |
|
@@ -285,17 +282,18 @@ ClangTypeConverter::reverseBuiltinTypeMapping(IRGenModule &IGM,
|
285 | 282 | CanType swiftType = getNamedSwiftType(stdlib, swiftName);
|
286 | 283 | if (!swiftType) return;
|
287 | 284 |
|
| 285 | + auto &sema = IGM.Context.getClangModuleLoader()->getClangSema(); |
288 | 286 | // Handle Int and UInt specially. On Apple platforms, these correspond to
|
289 | 287 | // the NSInteger and NSUInteger typedefs, so map them back to those typedefs
|
290 | 288 | // if they're available, to ensure we get consistent ObjC @encode strings.
|
291 | 289 | if (swiftType->getAnyNominal() == IGM.Context.getIntDecl()) {
|
292 |
| - if (auto NSIntegerTy = getClangBuiltinTypeFromTypedef(ctx, "NSInteger")) { |
| 290 | + if (auto NSIntegerTy = getClangBuiltinTypeFromTypedef(sema, "NSInteger")){ |
293 | 291 | Cache.insert({swiftType, NSIntegerTy});
|
294 | 292 | return;
|
295 | 293 | }
|
296 | 294 | } else if (swiftType->getAnyNominal() == IGM.Context.getUIntDecl()) {
|
297 | 295 | if (auto NSUIntegerTy =
|
298 |
| - getClangBuiltinTypeFromTypedef(ctx, "NSUInteger")) { |
| 296 | + getClangBuiltinTypeFromTypedef(sema, "NSUInteger")) { |
299 | 297 | Cache.insert({swiftType, NSUIntegerTy});
|
300 | 298 | return;
|
301 | 299 | }
|
|
0 commit comments