Skip to content

Commit aa38c27

Browse files
committed
---
yaml --- r: 347368 b: refs/heads/master c: dffedaa h: refs/heads/master
1 parent 06be74d commit aa38c27

File tree

5 files changed

+81
-57
lines changed

5 files changed

+81
-57
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0bc795bb8df64f4ba133d4228acb54fa3dd6b669
2+
refs/heads/master: dffedaa1888ef755e9e933a2cf0bb0185aa31c47
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===--- Sanitizers.def - Swift Sanitizers ß----------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 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 the sanitizers supported by Swift.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SANITIZER
18+
#error "Define SANITIZER prior to including this file!"
19+
#endif
20+
21+
// SANITIZER(enum_bit, kind, name, file)
22+
23+
SANITIZER(0, Address, address, asan)
24+
SANITIZER(1, Thread, thread, tsan)
25+
SANITIZER(2, Undefined, undefined, ubsan)
26+
SANITIZER(3, Fuzzer, fuzzer, fuzzer)
27+
28+
#undef SANITIZER

trunk/include/swift/Basic/Sanitizers.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ namespace swift {
1717

1818
// Enabling bitwise masking.
1919
enum class SanitizerKind : unsigned {
20-
Address = 1 << 1,
21-
Thread = 1 << 2,
22-
Fuzzer = 1 << 3,
23-
Undefined = 1 << 4
20+
#define SANITIZER(enum_bit, kind, name, file) kind = (1 << enum_bit),
21+
#include "Sanitizers.def"
2422
};
2523

2624
} // end namespace swift

trunk/lib/Option/SanitizerOptions.cpp

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,27 @@ using namespace swift;
3131

3232
static StringRef toStringRef(const SanitizerKind kind) {
3333
switch (kind) {
34-
case SanitizerKind::Address:
35-
return "address";
36-
case SanitizerKind::Thread:
37-
return "thread";
38-
case SanitizerKind::Fuzzer:
39-
return "fuzzer";
40-
case SanitizerKind::Undefined:
41-
return "undefined";
34+
#define SANITIZER(_, kind, name, file) \
35+
case SanitizerKind::kind: return #name;
36+
#include "swift/Basic/Sanitizers.def"
4237
}
43-
llvm_unreachable("Unsupported sanitizer");
38+
llvm_unreachable("Unknown sanitizer");
4439
}
4540

46-
static const char* toFileName(const SanitizerKind kind) {
41+
static StringRef toFileName(const SanitizerKind kind) {
4742
switch (kind) {
48-
case SanitizerKind::Address:
49-
return "asan";
50-
case SanitizerKind::Thread:
51-
return "tsan";
52-
case SanitizerKind::Fuzzer:
53-
return "fuzzer";
54-
case SanitizerKind::Undefined:
55-
return "ubsan";
43+
#define SANITIZER(_, kind, name, file) \
44+
case SanitizerKind::kind: return #file;
45+
#include "swift/Basic/Sanitizers.def"
5646
}
57-
llvm_unreachable("Unsupported sanitizer");
47+
llvm_unreachable("Unknown sanitizer");
48+
}
49+
50+
static Optional<SanitizerKind> parse(const char* arg) {
51+
return llvm::StringSwitch<Optional<SanitizerKind>>(arg)
52+
#define SANITIZER(_, kind, name, file) .Case(#name, SanitizerKind::kind)
53+
#include "swift/Basic/Sanitizers.def"
54+
.Default(None);
5855
}
5956

6057
llvm::SanitizerCoverageOptions swift::parseSanitizerCoverageArgValue(
@@ -133,35 +130,34 @@ OptionSet<SanitizerKind> swift::parseSanitizerArgValues(
133130
OptionSet<SanitizerKind> sanitizerSet;
134131

135132
// Find the sanitizer kind.
136-
for (int i = 0, n = A->getNumValues(); i != n; ++i) {
137-
auto kind = llvm::StringSwitch<Optional<SanitizerKind>>(A->getValue(i))
138-
.Case("address", SanitizerKind::Address)
139-
.Case("thread", SanitizerKind::Thread)
140-
.Case("fuzzer", SanitizerKind::Fuzzer)
141-
.Case("undefined", SanitizerKind::Undefined)
142-
.Default(None);
143-
bool isShared = kind && *kind != SanitizerKind::Fuzzer;
144-
if (!kind) {
133+
for (const char *arg : A->getValues()) {
134+
Optional<SanitizerKind> optKind = parse(arg);
135+
136+
// Unrecognized sanitizer option
137+
if (!optKind.hasValue()) {
145138
Diags.diagnose(SourceLoc(), diag::error_unsupported_option_argument,
146-
A->getOption().getPrefixedName(), A->getValue(i));
139+
A->getOption().getPrefixedName(), arg);
140+
continue;
141+
}
142+
SanitizerKind kind = optKind.getValue();
143+
144+
// Support is determined by existance of the sanitizer library.
145+
auto fileName = toFileName(kind);
146+
bool isShared = (kind != SanitizerKind::Fuzzer);
147+
bool sanitizerSupported = sanitizerRuntimeLibExists(fileName, isShared);
148+
149+
// TSan is explicitly not supported for 32 bits.
150+
if (kind == SanitizerKind::Thread && !Triple.isArch64Bit())
151+
sanitizerSupported = false;
152+
153+
if (!sanitizerSupported) {
154+
SmallString<128> b;
155+
Diags.diagnose(SourceLoc(), diag::error_unsupported_opt_for_target,
156+
(A->getOption().getPrefixedName() + toStringRef(kind))
157+
.toStringRef(b),
158+
Triple.getTriple());
147159
} else {
148-
// Support is determined by existance of the sanitizer library.
149-
bool sanitizerSupported =
150-
sanitizerRuntimeLibExists(toFileName(*kind), isShared);
151-
152-
// TSan is explicitly not supported for 32 bits.
153-
if (*kind == SanitizerKind::Thread && !Triple.isArch64Bit())
154-
sanitizerSupported = false;
155-
156-
if (!sanitizerSupported) {
157-
SmallString<128> b;
158-
Diags.diagnose(SourceLoc(), diag::error_unsupported_opt_for_target,
159-
(A->getOption().getPrefixedName() + toStringRef(*kind))
160-
.toStringRef(b),
161-
Triple.getTriple());
162-
} else {
163-
sanitizerSet |= *kind;
164-
}
160+
sanitizerSet |= kind;
165161
}
166162
}
167163

@@ -191,10 +187,12 @@ OptionSet<SanitizerKind> swift::parseSanitizerArgValues(
191187

192188
std::string swift::getSanitizerList(const OptionSet<SanitizerKind> &Set) {
193189
std::string list;
194-
if (Set & SanitizerKind::Address) list += "address,";
195-
if (Set & SanitizerKind::Thread) list += "thread,";
196-
if (Set & SanitizerKind::Fuzzer) list += "fuzzer,";
197-
if (Set & SanitizerKind::Undefined) list += "undefined,";
198-
if (!list.empty()) list.pop_back(); // Remove last comma
190+
#define SANITIZER(_, kind, name, file) \
191+
if (Set & SanitizerKind::kind) list += #name ",";
192+
#include "swift/Basic/Sanitizers.def"
193+
194+
if (!list.empty())
195+
list.pop_back(); // Remove last comma
196+
199197
return list;
200198
}

trunk/test/Driver/sanitizers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106

107107
// UBSAN: -rpath @executable_path
108108

109-
// MULTIPLE_SAN_LINUX: -fsanitize=address,fuzzer,undefined
109+
// MULTIPLE_SAN_LINUX: -fsanitize=address,undefined,fuzzer
110110

111111
// BADARG: unsupported argument 'unknown' to option '-sanitize='
112112
// INCOMPATIBLESANITIZERS: argument '-sanitize=address' is not allowed with '-sanitize=thread'

0 commit comments

Comments
 (0)