Skip to content

Commit 249a6a7

Browse files
committed
[Frontend] Remove reference to uninitialized ASTContext
Certain actions do not initialize `ASTContext`, eg. `TypecheckModuleFromInterface`. But `performAction` was always grabbing a `ASTContext&`. With `_GLIBCXX_ASSERTIONS` and `_LIBCPP_ENABLE_ASSERTIONS` now enabled in an asserts build, this hits an assert in `unique_ptr::operator*` that checks for a null deref.
1 parent d8e5cd9 commit 249a6a7

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,11 +1269,10 @@ static bool performAction(CompilerInstance &Instance,
12691269
int &ReturnValue,
12701270
FrontendObserver *observer) {
12711271
const auto &opts = Instance.getInvocation().getFrontendOptions();
1272-
auto &Context = Instance.getASTContext();
12731272
switch (Instance.getInvocation().getFrontendOptions().RequestedAction) {
12741273
// MARK: Trivial Actions
12751274
case FrontendOptions::ActionType::NoneAction:
1276-
return Context.hadError();
1275+
return Instance.getASTContext().hadError();
12771276
case FrontendOptions::ActionType::PrintVersion:
12781277
return printSwiftVersion(Instance.getInvocation());
12791278
case FrontendOptions::ActionType::PrintFeature:
@@ -1332,7 +1331,7 @@ static bool performAction(CompilerInstance &Instance,
13321331
}, /*runDespiteErrors=*/true);
13331332
case FrontendOptions::ActionType::DumpInterfaceHash:
13341333
getPrimaryOrMainSourceFile(Instance).dumpInterfaceHash(llvm::errs());
1335-
return Context.hadError();
1334+
return Instance.getASTContext().hadError();
13361335
case FrontendOptions::ActionType::EmitImportedModules:
13371336
return emitImportedModules(Instance.getMainModule(), opts);
13381337

@@ -1372,7 +1371,7 @@ static bool performAction(CompilerInstance &Instance,
13721371
}
13731372

13741373
assert(false && "Unhandled case in performCompile!");
1375-
return Context.hadError();
1374+
return Instance.getASTContext().hadError();
13761375
}
13771376

13781377
/// Performs the compile requested by the user.

0 commit comments

Comments
 (0)