Skip to content

Commit 071f23e

Browse files
author
George Karpenkov
committed
Code review comments.
1 parent ce3f94b commit 071f23e

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

include/swift/Option/SanitizerOptions.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
#define SWIFT_OPTIONS_SANITIZER_OPTIONS_H
1515

1616
#include "swift/Basic/Sanitizers.h"
17-
#include "llvm/ADT/Triple.h"
1817
#include "llvm/ADT/STLExtras.h"
18+
#include "llvm/ADT/StringRef.h"
19+
#include "llvm/ADT/Triple.h"
1920
#include "llvm/Option/Arg.h"
2021
// FIXME: This include is just for llvm::SanitizerCoverageOptions. We should
2122
// split the header upstream so we don't include so much.
@@ -34,7 +35,7 @@ SanitizerKind parseSanitizerArgValues(
3435
const llvm::opt::Arg *A,
3536
const llvm::Triple &Triple,
3637
DiagnosticEngine &Diag,
37-
llvm::function_ref<bool(std::string)> sanitizerRuntimeLibExists);
38+
llvm::function_ref<bool(llvm::StringRef)> sanitizerRuntimeLibExists);
3839

3940
/// \brief Parses a -sanitize-coverage= argument's value.
4041
llvm::SanitizerCoverageOptions

lib/Driver/ToolChain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ bool
154154
ToolChain::sanitizerRuntimeLibExists(const ArgList &args,
155155
StringRef sanitizerName) const {
156156
// Assume no sanitizers are supported by default.
157-
// This method should be overriden by an platform-specific subclass.
157+
// This method should be overriden by a platform-specific subclass.
158158
return false;
159159
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
14221422
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_EQ)) {
14231423
Opts.Sanitize = parseSanitizerArgValues(
14241424
A, Triple, Diags,
1425-
/* sanitizerRuntimeLibExists= */[&](const StringRef libName) {
1425+
/* sanitizerRuntimeLibExists= */[](StringRef libName) {
14261426

14271427
// The driver has checked the existence of the library
14281428
// already.

lib/Option/SanitizerOptions.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
#include "swift/AST/DiagnosticsFrontend.h"
2222
#include "llvm/ADT/Optional.h"
2323
#include "llvm/ADT/STLExtras.h"
24+
#include "llvm/ADT/StringRef.h"
2425
#include "llvm/ADT/StringSwitch.h"
2526
#include "llvm/ADT/Triple.h"
2627

27-
#include <functional>
28-
2928
using namespace swift;
3029

3130
static StringRef toStringRef(const SanitizerKind kind) {
@@ -103,15 +102,15 @@ llvm::SanitizerCoverageOptions swift::parseSanitizerCoverageArgValue(
103102

104103
static bool isTSanSupported(
105104
const llvm::Triple &Triple,
106-
std::function<bool(std::string)> sanitizerRuntimeLibExists) {
105+
llvm::function_ref<bool(llvm::StringRef)> sanitizerRuntimeLibExists) {
107106

108107
return Triple.isArch64Bit() && sanitizerRuntimeLibExists("tsan");
109108
}
110109

111110
SanitizerKind swift::parseSanitizerArgValues(const llvm::opt::Arg *A,
112111
const llvm::Triple &Triple,
113112
DiagnosticEngine &Diags,
114-
llvm::function_ref<bool(std::string)> sanitizerRuntimeLibExists) {
113+
llvm::function_ref<bool(llvm::StringRef)> sanitizerRuntimeLibExists) {
115114
SanitizerKind kind = SanitizerKind::None;
116115

117116
// Find the sanitizer kind.

test/Driver/sanitizers.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
// REQUIRES: CPU=x86_64
2-
31
// RUN: %swiftc_driver -driver-print-jobs -sanitize=address -target x86_64-apple-macosx10.9 %s | %FileCheck -check-prefix=ASAN -check-prefix=ASAN_OSX %s
42
// RUN: %swiftc_driver -driver-print-jobs -sanitize=address -target x86_64-apple-ios7.1 %s | %FileCheck -check-prefix=ASAN -check-prefix=ASAN_IOSSIM %s
3+
// RUN: %swiftc_driver -driver-print-jobs -sanitize=address -target arm64-apple-ios7.1 %s | %FileCheck -check-prefix=ASAN -check-prefix=ASAN_IOS %s
54
// RUN: %swiftc_driver -driver-print-jobs -sanitize=address -target x86_64-apple-tvos9.0 %s | %FileCheck -check-prefix=ASAN -check-prefix=ASAN_tvOS_SIM %s
5+
// RUN: %swiftc_driver -driver-print-jobs -sanitize=address -target arm64-apple-tvos9.0 %s | %FileCheck -check-prefix=ASAN -check-prefix=ASAN_tvOS %s
66
// RUN: %swiftc_driver -driver-print-jobs -sanitize=address -target i386-apple-watchos2.0 %s | %FileCheck -check-prefix=ASAN -check-prefix=ASAN_watchOS_SIM %s
7+
// RUN: %swiftc_driver -driver-print-jobs -sanitize=address -target armv7k-apple-watchos2.0 %s | %FileCheck -check-prefix=ASAN -check-prefix=ASAN_watchOS %s
78
// RUN: not %swiftc_driver -driver-print-jobs -sanitize=address -target x86_64-unknown-linux-gnu %s 2>&1 | %FileCheck -check-prefix=ASAN_LINUX %s
89

910
// RUN: %swiftc_driver -driver-print-jobs -sanitize=thread -target x86_64-apple-macosx10.9 %s | %FileCheck -check-prefix=TSAN -check-prefix=TSAN_OSX %s
10-
// RUN: %swiftc_driver -driver-print-jobs -sanitize=thread -target x86_64-apple-ios7.1 %s | %FileCheck -check-prefix=TSAN -check-prefix=TSAN_IOSSIM %s
11-
// RUN: %swiftc_driver -driver-print-jobs -sanitize=thread -target x86_64-apple-tvos9.0 %s | %FileCheck -check-prefix=TSAN -check-prefix=TSAN_tvOS_SIM %s
11+
// RUN: not %swiftc_driver -driver-print-jobs -sanitize=thread -target x86-apple-macosx10.9 %s 2>&1 | %FileCheck -check-prefix=TSAN_OSX_32 %s
12+
// RUN: not %swiftc_driver -driver-print-jobs -sanitize=thread -target x86_64-apple-ios7.1 %s 2>&1 | %FileCheck -check-prefix=TSAN_IOSSIM %s
13+
// RUN: not %swiftc_driver -driver-print-jobs -sanitize=thread -target arm64-apple-ios7.1 %s 2>&1 | %FileCheck -check-prefix=TSAN_IOS %s
14+
// RUN: not %swiftc_driver -driver-print-jobs -sanitize=thread -target x86_64-apple-tvos9.0 %s 2>&1 | %FileCheck -check-prefix=TSAN_tvOS_SIM %s
15+
// RUN: not %swiftc_driver -driver-print-jobs -sanitize=thread -target arm64-apple-tvos9.0 %s 2>&1 | %FileCheck -check-prefix=TSAN_tvOS %s
1216
// RUN: not %swiftc_driver -driver-print-jobs -sanitize=thread -target i386-apple-watchos2.0 %s 2>&1 | %FileCheck -check-prefix=TSAN_watchOS_SIM %s
17+
// RUN: not %swiftc_driver -driver-print-jobs -sanitize=thread -target armv7k-apple-watchos2.0 %s 2>&1 | %FileCheck -check-prefix=TSAN_watchOS %s
1318
// RUN: not %swiftc_driver -driver-print-jobs -sanitize=thread -target x86_64-unknown-linux-gnu %s 2>&1 | %FileCheck -check-prefix=TSAN_LINUX %s
1419

1520
// RUN: not %swiftc_driver -driver-print-jobs -sanitize=address,unknown %s 2>&1 | %FileCheck -check-prefix=BADARG %s
@@ -21,8 +26,11 @@
2126

2227
// ASAN_OSX: lib/swift/clang/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
2328
// ASAN_IOSSIM: lib/swift/clang/lib/darwin/libclang_rt.asan_iossim_dynamic.dylib
29+
// ASAN_IOS: lib/swift/clang/lib/darwin/libclang_rt.asan_ios_dynamic.dylib
2430
// ASAN_tvOS_SIM: lib/swift/clang/lib/darwin/libclang_rt.asan_tvossim_dynamic.dylib
31+
// ASAN_tvOS: lib/swift/clang/lib/darwin/libclang_rt.asan_tvos_dynamic.dylib
2532
// ASAN_watchOS_SIM: lib/swift/clang/lib/darwin/libclang_rt.asan_watchossim_dynamic.dylib
33+
// ASAN_watchOS: lib/swift/clang/lib/darwin/libclang_rt.asan_watchos_dynamic.dylib
2634
// ASAN_LINUX: unsupported option '-sanitize=address' for target 'x86_64-unknown-linux-gnu'
2735

2836
// ASAN: -rpath @executable_path
@@ -32,9 +40,12 @@
3240

3341
// TSAN_OSX: lib/swift/clang/lib/darwin/libclang_rt.tsan_osx_dynamic.dylib
3442
// TSAN_OSX_32: unsupported option '-sanitize=thread' for target 'x86-apple-macosx10.9'
35-
// TSAN_IOSSIM: lib/swift/clang/lib/darwin/libclang_rt.tsan_iossim_dynamic.dylib
36-
// TSAN_tvOS_SIM: lib/swift/clang/lib/darwin/libclang_rt.tsan_tvossim_dynamic.dylib
43+
// TSAN_IOSSIM: unsupported option '-sanitize=thread' for target 'x86_64-apple-ios7.1'
44+
// TSAN_IOS: unsupported option '-sanitize=thread' for target 'arm64-apple-ios7.1'
45+
// TSAN_tvOS_SIM: unsupported option '-sanitize=thread' for target 'x86_64-apple-tvos9.0'
46+
// TSAN_tvOS: unsupported option '-sanitize=thread' for target 'arm64-apple-tvos9.0'
3747
// TSAN_watchOS_SIM: unsupported option '-sanitize=thread' for target 'i386-apple-watchos2.0'
48+
// TSAN_watchOS: unsupported option '-sanitize=thread' for target 'armv7k-apple-watchos2.0'
3849
// TSAN_LINUX: unsupported option '-sanitize=thread' for target 'x86_64-unknown-linux-gnu'
3950

4051
// TSAN: -rpath @executable_path

test/Sanitizers/tsan.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// REQUIRES: CPU=x86_64
66
// REQUIRES: tsan_runtime
77

8+
// Make sure we can handle swifterror and don't bail during the LLVM
9+
// threadsanitizer pass.
10+
811
enum MyError : Error {
912
case A
1013
}

0 commit comments

Comments
 (0)