|
15 | 15 | #include "llvm/ADT/SmallVector.h" |
16 | 16 | #include "llvm/ADT/StringSwitch.h" |
17 | 17 | #include "llvm/Support/MathExtras.h" |
| 18 | +#include <algorithm> |
18 | 19 |
|
19 | 20 | using namespace clang; |
20 | 21 |
|
@@ -46,26 +47,20 @@ bool clang::parseSanitizerWeightedValue(StringRef Value, bool AllowGroups, |
46 | 47 | #include "clang/Basic/Sanitizers.def" |
47 | 48 | .Default(SanitizerMask()); |
48 | 49 |
|
49 | | - if (ParsedKind) { |
50 | | - size_t equalsIndex = Value.find_first_of('='); |
51 | | - if (equalsIndex != llvm::StringLiteral::npos) { |
52 | | - double arg; |
53 | | - if ((Value.size() > (equalsIndex + 1)) && |
54 | | - !Value.substr(equalsIndex + 1).getAsDouble(arg)) { |
55 | | - // AllowGroups is already taken into account for ParsedKind, |
56 | | - // hence we unconditionally expandSanitizerGroups. |
57 | | - SanitizerMask ExpandedKind = expandSanitizerGroups(ParsedKind); |
58 | | - |
59 | | - for (unsigned int i = 0; i < SanitizerKind::SO_Count; i++) |
60 | | - if (ExpandedKind & SanitizerMask::bitPosToMask(i)) |
61 | | - Cutoffs[i] = arg; |
62 | | - |
63 | | - return true; |
64 | | - } |
65 | | - } |
66 | | - } |
67 | | - |
68 | | - return false; |
| 50 | + if (!ParsedKind) |
| 51 | + return false; |
| 52 | + auto [N, W] = Value.split('='); |
| 53 | + double A; |
| 54 | + if (W.getAsDouble(A)) |
| 55 | + return false; |
| 56 | + float C = std::clamp()(A, 0.0, 1.0); |
| 57 | + // AllowGroups is already taken into account for ParsedKind, |
| 58 | + // hence we unconditionally expandSanitizerGroups. |
| 59 | + SanitizerMask ExpandedKind = expandSanitizerGroups(ParsedKind); |
| 60 | + for (unsigned int i = 0; i < SanitizerKind::SO_Count; i++) |
| 61 | + if (ExpandedKind & SanitizerMask::bitPosToMask(i)) |
| 62 | + Cutoffs[i] = C; |
| 63 | + return true; |
69 | 64 | } |
70 | 65 |
|
71 | 66 | void clang::serializeSanitizerSet(SanitizerSet Set, |
|
0 commit comments