-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Conversation
@@ -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__) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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__) |
There was a problem hiding this comment.
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&)) |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, good to know.
@jckarter PTAL if you have time and are not on holiday. I don't think I should add |
#if defined(_MSC_VER) | ||
#pragma warning(push) | ||
#pragma warning(disable: 4521) | ||
#endif |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@swift-ci Please smoke test |
@jckarter Does this LGTM? |
I need to add an |
typename TrailingBase::template OverloadToken<Operand>) const { | ||
#endif |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
I think we should avoid conditionals where possible by consolidating the repeated cases into compatibility macros. Other than that, LGTM. |
Fine by me thanks for getting this in |
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