Skip to content

Commit 53744b9

Browse files
committed
Fix errors and warnings building swift/remote on Windows using MSVC
1 parent d8f08d4 commit 53744b9

File tree

8 files changed

+98
-15
lines changed

8 files changed

+98
-15
lines changed

include/swift/Basic/Unreachable.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===--- Unreachable.h - Implements swift_unrachable ------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines swift_unreachable, an LLVM-independent implementation of
14+
// llvm_unreachable.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_BASIC_UNREACHABLE_H
19+
#define SWIFT_BASIC_UNREACHABLE_H
20+
21+
#include <assert.h>
22+
#include <stdlib.h>
23+
24+
#ifdef __GNUC__
25+
#define SWIFT_ATTRIBUTE_NORETURN __attribute__((noreturn))
26+
#elif defined(_MSC_VER)
27+
#define SWIFT_ATTRIBUTE_NORETURN __declspec(noreturn)
28+
#else
29+
#define SWIFT_ATTRIBUTE_NORETURN
30+
#endif
31+
32+
SWIFT_ATTRIBUTE_NORETURN
33+
inline static void swift_unreachable(const char* msg) {
34+
assert(false && msg);
35+
(void)msg;
36+
abort();
37+
}
38+
39+
#endif // SWIFT_BASIC_UNREACHABLE_H

include/swift/Remote/Failure.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/Remote/RemoteAddress.h"
2222

2323
#include "llvm/Support/Compiler.h"
24+
#include "llvm/Support/ErrorHandling.h"
2425
#include <cassert>
2526
#include <string>
2627
#include <cstring>
@@ -107,6 +108,8 @@ class Failure {
107108
case Kind::KIND: return TEXT;
108109
#include "swift/Remote/FailureKinds.def"
109110
}
111+
112+
llvm_unreachable("Unhandled FailureKind in switch.");
110113
}
111114

112115
union ArgStorage {

include/swift/Remote/InProcessMemoryReader.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
#include "swift/Remote/MemoryReader.h"
2121

22-
#include <memory>
23-
#include <dlfcn.h>
22+
#include <cstring>
2423

2524
namespace swift {
2625
namespace remote {
@@ -36,10 +35,7 @@ class InProcessMemoryReader final : public MemoryReader {
3635
return sizeof(size_t);
3736
}
3837

39-
RemoteAddress getSymbolAddress(const std::string &name) override {
40-
auto pointer = dlsym(RTLD_DEFAULT, name.c_str());
41-
return RemoteAddress(pointer);
42-
}
38+
RemoteAddress getSymbolAddress(const std::string &name) override;
4339

4440
bool readString(RemoteAddress address, std::string &dest) override {
4541
dest = address.getLocalPointer<char>();

include/swift/Remote/MetadataReader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/Remote/MemoryReader.h"
2222
#include "swift/Basic/Demangle.h"
2323
#include "swift/Basic/LLVM.h"
24+
#include "swift/Basic/Unreachable.h"
2425

2526
#include <vector>
2627
#include <unordered_map>
@@ -761,6 +762,8 @@ class MetadataReader {
761762
return BuiltOpaque;
762763
}
763764
}
765+
766+
swift_unreachable("Unhandled MetadataKind in switch");
764767
}
765768

766769
BuiltType readTypeFromMangledName(const char *MangledTypeName,
@@ -1259,4 +1262,3 @@ namespace llvm {
12591262
}
12601263

12611264
#endif // SWIFT_REFLECTION_READER_H
1262-

lib/RemoteAST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_swift_library(swiftRemoteAST STATIC
22
RemoteAST.cpp
3+
InProcessMemoryReader.cpp
34
LINK_LIBRARIES
45
swiftSema swiftIRGen)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===--- InProcessMemoryReader.cpp - Reads local memory ---------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file implements the abstract interface for working with remote memory.
14+
// This method cannot be implemented in the header, as we must avoid importing
15+
// <windows.h> in a header, which causes conflicts with Swift definitions.
16+
//
17+
//===----------------------------------------------------------------------===//
18+
19+
#include "swift/Remote/InProcessMemoryReader.h"
20+
21+
#if defined(_WIN32)
22+
#define WIN32_LEAN_AND_MEAN
23+
#define NOMINMAX
24+
#include <windows.h>
25+
#else
26+
#include <dlfcn.h>
27+
#endif
28+
29+
using namespace swift;
30+
using namespace swift::remote;
31+
32+
RemoteAddress InProcessMemoryReader::getSymbolAddress(const std::string &name) {
33+
#if defined(_WIN32)
34+
auto pointer = GetProcAddress(GetModuleHandle(NULL), name.c_str());
35+
#else
36+
auto pointer = dlsym(RTLD_DEFAULT, name.c_str());
37+
#endif
38+
return RemoteAddress(pointer);
39+
}

lib/RemoteAST/RemoteAST.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,11 @@ class RemoteASTContextImpl {
699699
return getBuilder().getFailureAsResult<T>(Failure::Unknown);
700700
}
701701

702+
template <class T, class KindTy, class... ArgTys>
703+
Result<T> fail(KindTy kind, ArgTys &&...args) {
704+
return Result<T>::emplaceFailure(kind, std::forward<ArgTys>(args)...);
705+
}
706+
702707
private:
703708
virtual RemoteASTTypeBuilder &getBuilder() = 0;
704709
virtual MemoryReader &getReader() = 0;
@@ -716,11 +721,6 @@ class RemoteASTContextImpl {
716721
return IRGen.get();
717722
}
718723

719-
template <class T, class KindTy, class... ArgTys>
720-
Result<T> fail(KindTy kind, ArgTys &&...args) {
721-
return Result<T>::emplaceFailure(kind, std::forward<ArgTys>(args)...);
722-
}
723-
724724
Result<uint64_t>
725725
getOffsetOfField(Type type, NominalTypeDecl *typeDecl,
726726
RemoteAddress optMetadata, StringRef memberName) {

stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "swift/Basic/Unreachable.h"
1314
#include "swift/Reflection/ReflectionContext.h"
1415
#include "swift/Reflection/TypeLowering.h"
1516
#include "swift/Remote/CMemoryReader.h"
@@ -20,7 +21,7 @@ using namespace swift::reflection;
2021
using namespace swift::remote;
2122

2223
using NativeReflectionContext
23-
= ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>;
24+
= swift::reflection::ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>;
2425

2526
uint16_t
2627
swift_reflection_getSupportedMetadataVersion() {
@@ -45,12 +46,12 @@ swift_reflection_createReflectionContext(void *ReaderContext,
4546

4647
auto Reader = std::make_shared<CMemoryReader>(ReaderImpl);
4748
auto Context
48-
= new ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>(Reader);
49+
= new swift::reflection::ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>(Reader);
4950
return reinterpret_cast<SwiftReflectionContextRef>(Context);
5051
}
5152

5253
void swift_reflection_destroyReflectionContext(SwiftReflectionContextRef ContextRef) {
53-
auto Context = reinterpret_cast<ReflectionContext<InProcess> *>(ContextRef);
54+
auto Context = reinterpret_cast<swift::reflection::ReflectionContext<InProcess> *>(ContextRef);
5455
delete Context;
5556
}
5657

@@ -175,6 +176,8 @@ swift_layout_kind_t getTypeInfoKind(const TypeInfo &TI) {
175176
}
176177
}
177178
}
179+
180+
swift_unreachable("Unhandled TypeInfoKind in switch");
178181
}
179182

180183
static swift_typeinfo_t convertTypeInfo(const TypeInfo *TI) {

0 commit comments

Comments
 (0)