Skip to content
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
10 changes: 9 additions & 1 deletion include/swift/AST/AnyFunctionRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ class AnyFunctionRef {
}
llvm_unreachable("unexpected AnyFunctionRef representation");
}


// Disable "only for use within the debugger" warning.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4996)
#endif
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
"only for use within the debugger") {
if (auto afd = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
Expand All @@ -171,6 +176,9 @@ class AnyFunctionRef {
llvm_unreachable("unexpected AnyFunctionRef representation");
}
};
#if defined(_MSC_VER)
#pragma warning(pop)
#endif

} // namespace swift

Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,11 @@ class alignas(1 << DeclAlignInBits) Decl {

// Make vanilla new/delete illegal for Decls.
void *operator new(size_t Bytes) = delete;

// Work around MSVC error: attempting to reference a deleted function.
Copy link
Contributor

Choose a reason for hiding this comment

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

What does MSVC consider a reference that Clang doesn't?

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 get the following error

error C2280: 'void *swift::AST::ModuleDecl::__delDtor(unsigned int)': attempting to reference a deleted function

The problem seems to be that MSVC generates this __delDtor intrinsic that I don't seem to have control over.

Copy link
Contributor Author

@hughbe hughbe Dec 9, 2016

Choose a reason for hiding this comment

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

Take a look at this link: https://msdn.microsoft.com/en-us/library/mt723604.aspx
There seems to be some mention of this error, but I'm not sure how applicable this is, so I'd appreciate your expertise

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, maybe you would then have to delete operator delete in all the subclasses too.

It's possible marking it virtual would work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, maybe you would then have to delete operator delete in all the subclasses too.

This doesn't work - it just changes the error message from

void swift::Decl::operator delete(void *)': attempting to reference a deleted function

to

void swift::ModuleDecl::operator delete(void *)': attempting to reference a deleted function

Making it virtual causes the error

'delete' cannot be a virtual function

Copy link
Contributor

Choose a reason for hiding this comment

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

All right, oh well. We can do the workaround.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like an MSVC bug. I presume the deleting destructor is part of its ABI, but that entry point seems like it ought to be transitively delete-d if operator delete is deleted.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can believe it's an MSVC bug, but I don't mind us working around it for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#if !defined(_MSC_VER) || defined(__clang__)
void operator delete(void *Data) = delete;
#endif

// Only allow allocation of Decls using the allocator in ASTContext
// or by doing a placement new.
Expand Down
16 changes: 16 additions & 0 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,27 @@ class TrailingCallArguments
return *static_cast<const Derived *>(this);
}

// Work around MSVC bug: can't infer llvm::trailing_objects_internal,
// even though we granted friend access to it.
size_t numTrailingObjects(
#if defined(_MSC_VER) && !defined(__clang__)
llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems really brittle. I still don't like it, but I don't have an alternative to play with right now.

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 hate this too, but seems to be the best I can figure out

Identifier>) const {
#else
typename TrailingObjects::template OverloadToken<Identifier>) const {
#endif
return asDerived().getNumArguments();
}

// Work around MSVC bug: can't infer llvm::trailing_objects_internal,
// even though we granted friend access to it.
size_t numTrailingObjects(
#if defined(_MSC_VER) && !defined(__clang__)
llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<
SourceLoc>) const {
#else
typename TrailingObjects::template OverloadToken<SourceLoc>) const {
#endif
return asDerived().hasArgumentLabelLocs()
? asDerived().getNumArguments()
: 0;
Expand Down Expand Up @@ -4447,6 +4461,8 @@ class ObjCSelectorExpr : public Expr {
case ObjCSelectorKind::Setter:
return true;
}

llvm_unreachable("Unhandled ObjcSelectorKind in switch.");
}

/// Whether this selector references a method.
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/GenericEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final

/// Make vanilla new/delete illegal.
void *operator new(size_t Bytes) = delete;
#if !defined(_MSC_VER) || defined(__clang__)
void operator delete(void *Data) = delete;
#endif

/// Only allow placement new.
void *operator new(size_t Bytes, void *Mem) {
Expand Down
12 changes: 11 additions & 1 deletion include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,11 @@ class ModuleDecl : public TypeDecl, public DeclContext {
private:
// Make placement new and vanilla new/delete illegal for Modules.
void *operator new(size_t Bytes) throw() = delete;

// Work around MSVC error: attempting to reference a deleted function.
#if !defined(_MSC_VER) && !defined(__clang__)
void operator delete(void *Data) throw() = delete;
#endif
void *operator new(size_t Bytes, void *Mem) throw() = delete;
public:
// Only allow allocation of Modules using the allocator in ASTContext
Expand All @@ -515,6 +519,8 @@ class ModuleDecl : public TypeDecl, public DeclContext {
unsigned Alignment = alignof(ModuleDecl));
};

static inline unsigned alignOfFileUnit();

/// A container for module-scope declarations that itself provides a scope; the
/// smallest unit of code organization.
///
Expand Down Expand Up @@ -741,8 +747,12 @@ class FileUnit : public DeclContext {
// Only allow allocation of FileUnits using the allocator in ASTContext
// or by doing a placement new.
void *operator new(size_t Bytes, ASTContext &C,
unsigned Alignment = alignof(FileUnit));
unsigned Alignment = alignOfFileUnit());
};

static inline unsigned alignOfFileUnit() {
return alignof(FileUnit&);
}

/// A file containing Swift source code.
///
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/ProtocolConformance.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {

// Make vanilla new/delete illegal for protocol conformances.
void *operator new(size_t bytes) = delete;

// Work around MSVC error: attempting to reference a deleted function.
#if !defined(_MSC_VER) || defined(__clang__)
void operator delete(void *data) = delete;
#endif

// Only allow allocation of protocol conformances using the allocator in
// ASTContext or by doing a placement new.
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/TypeMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class TypeMatcher {
cast<CLASS##Type>(secondType.getPointer()));
#include "swift/AST/TypeNodes.def"
}

llvm_unreachable("Unhandled TypeKind in switch.");
}

/// Honeypot to catch cases where we should redispatch the second type, but
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/TypeRepr.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ enum class TypeReprKind : uint8_t {

/// \brief Representation of a type as written in source.
class alignas(8) TypeRepr {
// Fix MSVC error: attempting to reference a deleted function.
#if !defined(_MSC_VER) || defined(__clang__)
TypeRepr(const TypeRepr&) = delete;
#endif
void operator=(const TypeRepr&) = delete;

class TypeReprBitfields {
Expand Down
16 changes: 15 additions & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ class ParameterTypeFlags {
NumBits = 3
};
OptionSet<ParameterFlags> value;
static_assert(NumBits < 8*sizeof(value), "overflowed");
static_assert(NumBits < 8*sizeof(OptionSet<ParameterFlags>), "overflowed");
Copy link
Contributor Author

Choose a reason for hiding this comment

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


ParameterTypeFlags(OptionSet<ParameterFlags, uint8_t> val) : value(val) {}

Expand Down Expand Up @@ -2255,6 +2255,8 @@ inline bool canBeCalledIndirectly(SILFunctionTypeRepresentation rep) {
case SILFunctionTypeRepresentation::WitnessMethod:
return true;
}

llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
}

/// Map a SIL function representation to the base language calling convention
Expand All @@ -2273,6 +2275,8 @@ getSILFunctionLanguage(SILFunctionTypeRepresentation rep) {
case SILFunctionTypeRepresentation::Closure:
return SILFunctionLanguage::Swift;
}

llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
}

/// AnyFunctionType - A function type has a single input and result, but
Expand Down Expand Up @@ -2357,6 +2361,8 @@ class AnyFunctionType : public TypeBase {
case SILFunctionTypeRepresentation::WitnessMethod:
return true;
}

llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
}

/// True if the function representation carries context.
Expand All @@ -2373,6 +2379,8 @@ class AnyFunctionType : public TypeBase {
case SILFunctionTypeRepresentation::Closure:
return false;
}

llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
}

// Note that we don't have setters. That is by design, use
Expand Down Expand Up @@ -3043,6 +3051,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
case Representation::WitnessMethod:
return true;
}

llvm_unreachable("Unhandled Representation in switch.");
}

bool hasGuaranteedSelfParam() const {
Expand All @@ -3058,6 +3068,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
case Representation::WitnessMethod:
return true;
}

llvm_unreachable("Unhandled Representation in switch.");
}

/// True if the function representation carries context.
Expand All @@ -3074,6 +3086,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
case Representation::Closure:
return false;
}

llvm_unreachable("Unhandled Representation in switch.");
}

// Note that we don't have setters. That is by design, use
Expand Down
14 changes: 14 additions & 0 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,16 @@ struct ASTContext::Implementation {
~Arena() {
for (auto &conformance : SpecializedConformances)
conformance.~SpecializedProtocolConformance();
// Work around MSVC warning: local variable is initialized but
// not referenced.
#if defined(_MSC_VER)
#pragma warning (disable: 4189)
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 seems to be a bug in MSVC: I've been trying hard to reproduce this came, but can't.

#endif
for (auto &conformance : InheritedConformances)
conformance.~InheritedProtocolConformance();
#if defined(_MSC_VER)
#pragma warning (default: 4189)
#endif

// Call the normal conformance destructors last since they could be
// referenced by the other conformance types.
Expand Down Expand Up @@ -536,6 +544,8 @@ EnumDecl *ASTContext::getOptionalDecl(OptionalTypeKind kind) const {
case OTK_Optional:
return getOptionalDecl();
}

llvm_unreachable("Unhandled OptionalTypeKind in switch.");
}

static EnumElementDecl *findEnumElement(EnumDecl *e, Identifier name) {
Expand Down Expand Up @@ -1714,6 +1724,8 @@ std::pair<unsigned, DeclName> swift::getObjCMethodDiagInfo(
// Normal method.
return { 4, func->getFullName() };
}

llvm_unreachable("Unhandled AccessorKind in switch.");
}

bool swift::fixDeclarationName(InFlightDiagnostic &diag, ValueDecl *decl,
Expand Down Expand Up @@ -3760,6 +3772,8 @@ ASTContext::getForeignRepresentationInfo(NominalTypeDecl *nominal,
case ForeignLanguage::ObjectiveC:
return entry;
}

llvm_unreachable("Unhandled ForeignLanguage in switch.");
}

bool ASTContext::isTypeBridgedInExternalModule(
Expand Down
10 changes: 6 additions & 4 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
#include "llvm/Support/CommandLine.h"

using namespace swift;
using namespace NewMangling;
using namespace swift::NewMangling;

std::string NewMangling::mangleTypeForDebugger(Type Ty, const DeclContext *DC) {
if (useNewMangling()) {
ASTMangler::ASTMangler NewMangler(/* DWARF */ true);
ASTMangler NewMangler(/* DWARF */ true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eeckstein PTAL, this changes your recently committed code - I think this was a case of Clang allowing something that perhaps isn't spec-ed C++?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this just looks like a mistake.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, it was

return NewMangler.mangleTypeForDebugger(Ty, DC);
}
Mangle::Mangler OldMangler(/* DWARF */ true);
Expand All @@ -50,7 +50,7 @@ std::string NewMangling::mangleTypeForDebugger(Type Ty, const DeclContext *DC) {

std::string NewMangling::mangleTypeAsUSR(Type Ty) {
if (useNewMangling()) {
ASTMangler::ASTMangler NewMangler;
ASTMangler NewMangler;
return NewMangler.mangleTypeAsUSR(Ty);
}
Mangle::Mangler OldMangler;
Expand Down Expand Up @@ -369,7 +369,7 @@ void ASTMangler::appendDeclName(const ValueDecl *decl) {
assert(!discriminator.empty());
assert(!isNonAscii(discriminator.str()) &&
"discriminator contains non-ASCII characters");
(void)isNonAscii;
(void)&isNonAscii;
assert(!clang::isDigit(discriminator.str().front()) &&
"not a valid identifier");

Expand All @@ -387,6 +387,8 @@ static const char *getMetatypeRepresentationOp(MetatypeRepresentation Rep) {
case MetatypeRepresentation::ObjC:
return "o";
}

llvm_unreachable("Unhandled MetatypeRepresentation in switch.");
}

static bool isStdlibType(const NominalTypeDecl *decl) {
Expand Down
4 changes: 3 additions & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ std::string ASTPrinter::sanitizeUtf8(StringRef Text) {
Builder.reserve(Text.size());
const UTF8* Data = reinterpret_cast<const UTF8*>(Text.begin());
const UTF8* End = reinterpret_cast<const UTF8*>(Text.end());
StringRef Replacement = "\ufffd";
StringRef Replacement = u8"\ufffd";
while (Data < End) {
auto Step = getNumBytesForUTF8(*Data);
if (Data + Step > End) {
Expand Down Expand Up @@ -612,6 +612,8 @@ static bool escapeKeywordInContext(StringRef keyword, PrintNameContext context){
case PrintNameContext::TupleElement:
return !canBeArgumentLabel(keyword);
}

llvm_unreachable("Unhandled PrintNameContext in switch.");
}

void ASTPrinter::printName(Identifier Name, PrintNameContext Context) {
Expand Down
Loading