Skip to content

Fix errors and warnings building swift/SIL on Windows using MSVC #5954

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, 2017
Merged

Fix errors and warnings building swift/SIL on Windows using MSVC #5954

merged 1 commit into from
Jan 11, 2017

Conversation

hughbe
Copy link
Contributor

@hughbe hughbe commented Nov 28, 2016

Various control path warnings
Various deleted function errors
Various sign warnings
Various function argument missing warnings
Relies on apple/swift-llvm#33 but PRs can be merged in any order

@hughbe hughbe changed the title Fix errors and warnings building libSwiftSIL on Windows using MSVC Fix errors and warnings building swift/SIL on Windows using MSVC Nov 28, 2016
@@ -28,8 +28,11 @@ class SILAllocated {
void *operator new(size_t) = delete;
void *operator new[](size_t) = delete;

// Work around MSVC error: attempting to reference a deleted function.
#if !defined(_MSC_VER) || defined(__clang__)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is as a result of an MSVC ABI bug

Copy link
Contributor Author

Choose a reason for hiding this comment

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

... That has been fixed in VS 2017 :D

size_t numTrailingObjects(
#if defined(_MSC_VER) && !defined(__clang__)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There it is again, the horrible hack.

@@ -1210,8 +1212,8 @@ TypeConverter::~TypeConverter() {
void *TypeLowering::operator new(size_t size, TypeConverter &tc,
IsDependent_t dependent) {
return dependent
? tc.DependentBPA.Allocate(size, alignof(TypeLowering))
: tc.IndependentBPA.Allocate(size, alignof(TypeLowering));
? tc.DependentBPA.Allocate(size, alignof(TypeLowering&))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes the "cannot instantiate abstract class" error seen in #5948. The error happens for each alignof(TypeLowering) check. @jrose-apple FYI

2>C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): error C2259: 'swift::Lowering::TypeLowering': cannot instantiate abstract class
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: due to following members:
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'swift::SILValue swift::Lowering::TypeLowering::emitLoadOfCopy(swift::SILBuilder &,swift::SILLocation,swift::SILValue,swift::IsTake_t) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(194): note: see declaration of 'swift::Lowering::TypeLowering::emitLoadOfCopy'
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'void swift::Lowering::TypeLowering::emitStoreOfCopy(swift::SILBuilder &,swift::SILLocation,swift::SILValue,swift::SILValue,swift::IsInitialization_t) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(207): note: see declaration of 'swift::Lowering::TypeLowering::emitStoreOfCopy'
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'void swift::Lowering::TypeLowering::emitStore(swift::SILBuilder &,swift::SILLocation,swift::SILValue,swift::SILValue,swift::StoreOwnershipQualifier) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(218): note: see declaration of 'swift::Lowering::TypeLowering::emitStore'
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'swift::SILValue swift::Lowering::TypeLowering::emitLoad(swift::SILBuilder &,swift::SILLocation,swift::SILValue,swift::LoadOwnershipQualifier) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(225): note: see declaration of 'swift::Lowering::TypeLowering::emitLoad'
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'void swift::Lowering::TypeLowering::emitCopyInto(swift::SILBuilder &,swift::SILLocation,swift::SILValue,swift::SILValue,swift::IsTake_t,swift::IsInitialization_t) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(230): note: see declaration of 'swift::Lowering::TypeLowering::emitCopyInto'
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'void swift::Lowering::TypeLowering::emitDestroyAddress(swift::SILBuilder &,swift::SILLocation,swift::SILValue) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(240): note: see declaration of 'swift::Lowering::TypeLowering::emitDestroyAddress'
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'void swift::Lowering::TypeLowering::emitDestroyRValue(swift::SILBuilder &,swift::SILLocation,swift::SILValue) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(246): note: see declaration of 'swift::Lowering::TypeLowering::emitDestroyRValue'
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'void swift::Lowering::TypeLowering::emitLoweredDestroyValue(swift::SILBuilder &,swift::SILLocation,swift::SILValue,swift::Lowering::TypeLowering::LoweringStyle) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(254): note: see declaration of 'swift::Lowering::TypeLowering::emitLoweredDestroyValue'
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'void swift::Lowering::TypeLowering::emitDestroyValue(swift::SILBuilder &,swift::SILLocation,swift::SILValue) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(290): note: see declaration of 'swift::Lowering::TypeLowering::emitDestroyValue'
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'swift::SILValue swift::Lowering::TypeLowering::emitLoweredCopyValue(swift::SILBuilder &,swift::SILLocation,swift::SILValue,swift::Lowering::TypeLowering::LoweringStyle) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(296): note: see declaration of 'swift::Lowering::TypeLowering::emitLoweredCopyValue'
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SIL\TypeLowering.cpp(1215): note: 'swift::SILValue swift::Lowering::TypeLowering::emitCopyValue(swift::SILBuilder &,swift::SILLocation,swift::SILValue) const': is abstract
2> C:\Users\Lukey\Documents\GitHub\my-swift\swift\include\swift/SIL/TypeLowering.h(324): note: see declaration of 'swift::Lowering::TypeLowering::emitCopyValue'

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as we have a complete type, it seems to be doing the right thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, good to know.

@hughbe
Copy link
Contributor Author

hughbe commented Dec 22, 2016

@jckarter PTAL if you have time and are not on holiday. I don't think I should add llvm_unreachable to the deleted methods here, as I'm fairly sure MSVC would call them, resulting in assertions when the code is executed

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4521)
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the warning legitimate, or an MSVC bug? Can we slap an enable_if on a generic constructor somewhere to avoid formally having multiple copy ctors?

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'm inclined to think this is an MSVC bug. I think it is related to
The line SILOpenedArchetypesTracker &operator = (const SILOpenedArchetypesTracker &) = delete; but have been unable to put a repo together.

I'm not surre I fully understand the enable_if comment you made, sorry

Copy link
Contributor

Choose a reason for hiding this comment

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

I was referring to the not-uncommon situation where there's a formal copy constructor and a generic constructor that could also be called with a const T & argument, thereby also potentially fulfilling the role of copy constructor.

@slavapestov slavapestov self-assigned this Jan 11, 2017
@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor

@jckarter Does this LGTM?

@hughbe
Copy link
Contributor Author

hughbe commented Jan 11, 2017

I need to add an enable_if to a generic copy constructor to fix an MSVC warning that I've silenced. I think considering this PR has been around for a while and is decently large, it would be good to get this merged in, and then I can deal with the MSVC warning in another PR. It also keeps getting merge conflicts, so would be good to stop having to deal with that!

typename TrailingBase::template OverloadToken<Operand>) const {
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to consolidate the workaround in a single typedef somewhere, without the conditional.

// Equivalent to `typename TrailingBase::template OverloadToken<Operand>`.
// We have to fully elaborate the type because of an MSVC bug.
using OperandOverloadToken 
  = llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<Operand>;

void operator delete(void *Ptr, size_t) = delete;
#endif
Copy link
Contributor

@jckarter jckarter Jan 11, 2017

Choose a reason for hiding this comment

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

It might be nice to consolidate these into a compatibility macro in a swift/Basic header:

#if !defined(_MSC_VER) || defined(__clang__)
# define SWIFT_DELETE_OPERATOR_DELETE(...) \
  void operator delete(__VA_ARGS__) = delete
#else
// Due to an MSVC bug, deleting an operator delete
// also causes the destructor to be deleted.
# define SWIFT_DELETE_OPERATOR_DELETE(...)  
#endif

@jckarter
Copy link
Contributor

I think we should avoid conditionals where possible by consolidating the repeated cases into compatibility macros. Other than that, LGTM.

@slavapestov
Copy link
Contributor

@hughbe Do you mind making the cleanup suggested by @jckarter in a separate patch?

@slavapestov slavapestov merged commit 5c0afe9 into swiftlang:master Jan 11, 2017
@hughbe
Copy link
Contributor Author

hughbe commented Jan 11, 2017

Fine by me thanks for getting this in

@hughbe hughbe deleted the sil-msvc branch January 11, 2017 23:55
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