Skip to content

Fix errors and warnings build swift/clangImporter using MSVC on Windows #5950

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
Nov 30, 2016
Merged

Fix errors and warnings build swift/clangImporter using MSVC on Windows #5950

merged 1 commit into from
Nov 30, 2016

Conversation

hughbe
Copy link
Contributor

@hughbe hughbe commented Nov 28, 2016

No description provided.

#pragma mark Internal data structures
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty awful. Does MSVC really not ignore pragmas it doesn't understand? If so, maybe we should just use comments instead. @DougGregor, @milseman, any opinions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It reports warnings. The reason why I didn't do if defined(__clang__) is because MSVC is the only guy out of the lot not to simply ignore

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you disable the unknown pragma warning when building with MSVC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can... I'm personally not a fan of disabling warnings, they exist for a reason. That said, considering MSVC is "pretty awful", it could make sense

Copy link
Contributor

Choose a reason for hiding this comment

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

Not every warning exists for a practical reason for all projects. #pragma mark is a pretty common de-facto standard for IDE navigation, and it would be impractical to guard every use of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I've updated #5904 to silence the warning, and updated this PR to remove all of these ifdefs

@@ -618,8 +621,12 @@ static bool isAccessibilityConformingContext(const clang::DeclContext *ctx) {

bool
importer::shouldImportPropertyAsAccessors(const clang::ObjCPropertyDecl *prop) {
// TODO (hughbe/MSVC): fix an error using SwiftImportPropertyAsAccessorsAttr
// Fails with: "SwiftImportPropertyAsAccessorsAttr" is not a member of 'clang'
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure you're using swift-clang's 'stable' branch and not upstream Clang?

Copy link
Contributor Author

@hughbe hughbe Nov 28, 2016

Choose a reason for hiding this comment

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

Ah yes, this would be it. I'll remove this workaround and make sure I'm not breaking my build

@@ -1094,7 +1094,7 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
// Objective-C categories and extensions don't have names, despite
// being "named" declarations.
if (isa<clang::ObjCCategoryDecl>(D))
return {};
return ImportedName();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm okay with this change, but is it really necessary? This seems like a pretty common C++11 feature that will keep slipping in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'm sorry: MSVC reports errors for each construct, no idea why!

@@ -563,6 +563,9 @@ OptionalTypeKind importer::translateNullability(clang::NullabilityKind kind) {
case clang::NullabilityKind::Unspecified:
return OptionalTypeKind::OTK_ImplicitlyUnwrappedOptional;
}

// Work around MSVC warning: not all control paths return a value
llvm_unreachable("All switch cases are covered");
Copy link
Member

Choose a reason for hiding this comment

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

All of these make me think that we really need an LLVM_MSVC_UNREACHABLE macro that expands to llvm_unreachable("silence MSVC warnings") on MSVC and expands to nothing elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could argue this is good practice even outside of MSVC, since switch exhaustiveness isn't necessarily guaranteed covering all of an enum's constants (unless it happens to have exactly a power of two contiguously-valued elements).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right - what I've done is removed the // Work around MSVC warning comments as well, and made the messages more descriptive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've also removed the pragma mark ifdefs

Copy link
Contributor

Choose a reason for hiding this comment

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

We did this in Clang for a long time too to handle older GCCs that didn't have -Wswitch-enum. It'll be hard to get back in the habit but it doesn't seem like it needs to be MSVC-specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, by the end of my flurry of PRs, there shouldn't be any left :) The habit thing still remains

@jrose-apple
Copy link
Contributor

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit 071ec47 into swiftlang:master Nov 30, 2016
@hughbe hughbe deleted the clangimporter-msvc branch December 15, 2016 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants