Skip to content
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

Warn if RequiresXXXCode is placed on an entrypoint #110185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MichalStrehovsky
Copy link
Member

Fixes #109811.

Motivated by real-world first party code that did this :(.

Cc @dotnet/illink

Fixes dotnet#109811.

Motivated by real-world first party code that did this :(.
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@@ -128,6 +128,11 @@ internal static MessageContainer CreateErrorMessage(MessageOrigin? origin, Diagn
if (context.IsWarningSubcategorySuppressed(subcategory))
return null;

// If the warning comes from compiler-generated code, it would not be actionable. The assumption is that
// compiler-generated code doesn't have issues.
if (origin.MemberDefinition is MethodDesc originMethod && originMethod.GetTypicalMethodDefinition() is not EcmaMethod)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ILC generates a method that calls user's main (after initializing the environment). It was triggering a warning if Main has RUC

@@ -203,5 +203,27 @@ public static bool IsConstructor ([NotNullWhen (returnValue: true)] this ISymbol

public static bool IsStaticConstructor ([NotNullWhen (returnValue: true)] this ISymbol? symbol)
=> (symbol as IMethodSymbol)?.MethodKind == MethodKind.StaticConstructor;

public static bool IsEntryPoint (this IMethodSymbol methodSymbol, Compilation compilation)
=> methodSymbol.Name is WellKnownMemberNames.EntryPointMethodName or WellKnownMemberNames.TopLevelStatementsEntryPointMethodName &&
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how Roslyn does it in same named method. It might be overly broad in edge cases. Not sure how much we care, it's pretty niche.

Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, my only nit is that it might be nice to have separate messages for UCO and Main, but I don't feel strongly about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn if RequiresXXXCode is placed on UnmanagedCallersOnly method with entrypoint
2 participants