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