mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SILGen: Avoid expanding #line directives with invalid source locations.
Synthesized stub constructors contain `#line` directives and under certain circumstances these directives can have invalid source locations. SILGen would trigger an assert (or invoke UB in non-asserts builds) when attempting to expand these directives into literal values. Check the source location for validity before translating the location to a location in the outermost source file. Resolves rdar://121971741
This commit is contained in:
@@ -2179,13 +2179,14 @@ buildBuiltinLiteralArgs(SILGenFunction &SGF, SGFContext C,
|
||||
|
||||
case MagicIdentifierLiteralExpr::Line:
|
||||
case MagicIdentifierLiteralExpr::Column: {
|
||||
auto Loc = getLocInOutermostSourceFile(SGF.getSourceManager(),
|
||||
magicLiteral->getStartLoc());
|
||||
unsigned Value = 0;
|
||||
if (Loc.isValid()) {
|
||||
Value = magicLiteral->getKind() == MagicIdentifierLiteralExpr::Line
|
||||
? ctx.SourceMgr.getPresumedLineAndColumnForLoc(Loc).first
|
||||
: ctx.SourceMgr.getPresumedLineAndColumnForLoc(Loc).second;
|
||||
if (auto Loc = magicLiteral->getStartLoc()) {
|
||||
Loc = getLocInOutermostSourceFile(SGF.getSourceManager(), Loc);
|
||||
if (Loc.isValid()) {
|
||||
Value = magicLiteral->getKind() == MagicIdentifierLiteralExpr::Line
|
||||
? ctx.SourceMgr.getPresumedLineAndColumnForLoc(Loc).first
|
||||
: ctx.SourceMgr.getPresumedLineAndColumnForLoc(Loc).second;
|
||||
}
|
||||
}
|
||||
|
||||
auto silTy = SILType::getBuiltinIntegerLiteralType(ctx);
|
||||
|
||||
Reference in New Issue
Block a user