Skip to content

ParseSIL: prevent _weakLinked on COFF targets #21798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,8 @@ WARNING(attr_renamed_warning, none,
"'@%0' has been renamed to '@%1'", (StringRef, StringRef))
ERROR(attr_name_close_match, none,
"no attribute named '@%0'; did you mean '@%1'?", (StringRef, StringRef))
ERROR(attr_unsupported_on_target, none,
"attribute '%0' is unsupported on target '%1'", (StringRef, StringRef))

// availability
ERROR(attr_availability_platform,none,
Expand Down
10 changes: 9 additions & 1 deletion lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,15 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
!isInSILMode()) {
diagnose(Loc, diag::only_allowed_in_sil, AttrName);
DiscardAttribute = true;
}
}

if (Context.LangOpts.Target.isOSBinFormatCOFF()) {
if (DK == DAK_WeakLinked) {
diagnose(Loc, diag::attr_unsupported_on_target, AttrName,
Context.LangOpts.Target.str());
DiscardAttribute = true;
}
}

// Filled in during parsing. If there is a duplicate
// diagnostic this can be used for better error presentation.
Expand Down
7 changes: 6 additions & 1 deletion lib/ParseSIL/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,12 @@ static bool parseDeclSILOptional(bool *isTransparent,
else if (isGlobalInit && SP.P.Tok.getText() == "global_init")
*isGlobalInit = true;
else if (isWeakLinked && SP.P.Tok.getText() == "_weakLinked")
*isWeakLinked = true;
if (M.getASTContext().LangOpts.Target.isOSBinFormatCOFF())
SP.P.diagnose(SP.P.Tok, diag::attr_unsupported_on_target,
SP.P.Tok.getText(),
M.getASTContext().LangOpts.Target.str());
else
*isWeakLinked = true;
else if (inlineStrategy && SP.P.Tok.getText() == "noinline")
*inlineStrategy = NoInline;
else if (optimizationMode && SP.P.Tok.getText() == "Onone")
Expand Down
10 changes: 10 additions & 0 deletions test/IRGen/weakLinked.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %swift -target x86_64-unknown-windows-msvc -emit-ir -verify %s

sil_stage canonical

// expected-error@+1{{attribute '_weakLinked' is unsupported on target 'x86_64-unknown-windows-msvc'}}
sil [_weakLinked] @f : $@convention(thin) () -> () {
%unit = tuple()
return %unit : $()
}

5 changes: 5 additions & 0 deletions test/Parse/weakLinked.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %swift -target x86_64-unknown-windows-msvc -parse-stdlib -typecheck -verify %s

// expected-error@+1{{attribute '_weakLinked' is unsupported on target 'x86_64-unknown-windows-msvc'}}
@_weakLinked func f() { }