llvm/clang/unittests/Basic/SanitizersTest.cpp
Jan Svoboda 40c261c41c [clang][cli] Generate and round-trip language options
This patch implements generation of remaining language options and tests it by performing parse-generate-parse round trip (on by default for assert builds, off otherwise).

This patch also correctly reports failures in `parseSanitizerKinds`, which is necessary for emitting diagnostics when an invalid sanitizer is passed to `-fsanitize=` during round-trip.

This patch also removes TableGen marshalling classes from two options:
* `fsanitize_blacklist` When parsing: it's first initialized via the generated code, but then also changed by manually written code, which is confusing.
* `fopenmp` When parsing: it's first initialized via generated code, but then conditionally changed by manually written code. This is also confusing. Moreover, we need to do some extra checks when generating it, which would be really cumbersome in TableGen. (Specifically, not emitting it when `-fopenmp-simd` was present.)

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D95793
2021-02-09 10:18:55 +01:00

50 lines
1.7 KiB
C++

//===- unittests/Basic/SanitizersTest.cpp - Test Sanitizers ---------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "clang/Basic/Sanitizers.h"
#include "gmock/gmock-matchers.h"
#include "gtest/gtest.h"
using namespace clang;
using testing::Contains;
using testing::Not;
TEST(SanitizersTest, serializeSanitizers) {
SanitizerSet Set;
Set.set(parseSanitizerValue("memory", false), true);
Set.set(parseSanitizerValue("nullability-arg", false), true);
SmallVector<StringRef, 4> Serialized;
serializeSanitizerSet(Set, Serialized);
ASSERT_EQ(Serialized.size(), 2u);
ASSERT_THAT(Serialized, Contains("memory"));
ASSERT_THAT(Serialized, Contains("nullability-arg"));
}
TEST(SanitizersTest, serializeSanitizersIndividual) {
SanitizerSet Set;
Set.set(parseSanitizerValue("memory", false), true);
Set.set(parseSanitizerValue("nullability-arg", false), true);
Set.set(parseSanitizerValue("nullability-assign", false), true);
Set.set(parseSanitizerValue("nullability-return", false), true);
SmallVector<StringRef, 4> Serialized;
serializeSanitizerSet(Set, Serialized);
ASSERT_EQ(Serialized.size(), 4u);
ASSERT_THAT(Serialized, Contains("memory"));
ASSERT_THAT(Serialized, Contains("nullability-arg"));
ASSERT_THAT(Serialized, Contains("nullability-assign"));
ASSERT_THAT(Serialized, Contains("nullability-return"));
// Individual sanitizers don't get squashed into a single group.
ASSERT_THAT(Serialized, Not(Contains("nullability")));
}