12
12
#include " clang/Basic/DiagnosticLex.h"
13
13
#include " clang/Basic/DiagnosticSema.h"
14
14
#include " clang/Basic/FileManager.h"
15
+ #include " clang/Basic/SourceLocation.h"
15
16
#include " clang/Basic/SourceManager.h"
16
17
#include " llvm/ADT/ArrayRef.h"
17
18
#include " llvm/ADT/IntrusiveRefCntPtr.h"
20
21
#include " llvm/Support/VirtualFileSystem.h"
21
22
#include " gmock/gmock.h"
22
23
#include " gtest/gtest.h"
24
+ #include < memory>
23
25
#include < optional>
24
26
#include < vector>
25
27
@@ -196,7 +198,17 @@ class SuppressionMappingTest : public testing::Test {
196
198
return CaptureConsumer.StoredDiags ;
197
199
}
198
200
201
+ SourceLocation locForFile (llvm::StringRef FileName) {
202
+ auto Buf = MemoryBuffer::getMemBuffer (" " , FileName);
203
+ SourceManager &SM = Diags.getSourceManager ();
204
+ FileID FooID = SM.createFileID (std::move (Buf));
205
+ return SM.getLocForStartOfFile (FooID);
206
+ }
207
+
199
208
private:
209
+ FileManager FM{{}, FS};
210
+ SourceManager SM{Diags, FM};
211
+
200
212
class CaptureDiagnosticConsumer : public DiagnosticConsumer {
201
213
public:
202
214
std::vector<StoredDiagnostic> StoredDiags;
@@ -255,9 +267,9 @@ TEST_F(SuppressionMappingTest, SuppressesGroup) {
255
267
clang::ProcessWarningOptions (Diags, Diags.getDiagnosticOptions (), *FS);
256
268
EXPECT_THAT (diags (), IsEmpty ());
257
269
258
- EXPECT_TRUE (
259
- Diags.isSuppressedViaMapping (diag::warn_unused_function, " foo.cpp " ));
260
- EXPECT_FALSE (Diags.isSuppressedViaMapping (diag::warn_deprecated, " foo.cpp " ));
270
+ SourceLocation FooLoc = locForFile ( " foo.cpp " );
271
+ EXPECT_TRUE ( Diags.isSuppressedViaMapping (diag::warn_unused_function, FooLoc ));
272
+ EXPECT_FALSE (Diags.isSuppressedViaMapping (diag::warn_deprecated, FooLoc ));
261
273
}
262
274
263
275
TEST_F (SuppressionMappingTest, EmitCategoryIsExcluded) {
@@ -271,10 +283,10 @@ TEST_F(SuppressionMappingTest, EmitCategoryIsExcluded) {
271
283
clang::ProcessWarningOptions (Diags, Diags.getDiagnosticOptions (), *FS);
272
284
EXPECT_THAT (diags (), IsEmpty ());
273
285
274
- EXPECT_TRUE (
275
- Diags. isSuppressedViaMapping (diag::warn_unused_function, " bar.cpp" ));
276
- EXPECT_FALSE (
277
- Diags. isSuppressedViaMapping (diag::warn_unused_function, " foo.cpp" ));
286
+ EXPECT_TRUE (Diags. isSuppressedViaMapping (diag::warn_unused_function,
287
+ locForFile ( " bar.cpp" ) ));
288
+ EXPECT_FALSE (Diags. isSuppressedViaMapping (diag::warn_unused_function,
289
+ locForFile ( " foo.cpp" ) ));
278
290
}
279
291
280
292
TEST_F (SuppressionMappingTest, LongestMatchWins) {
@@ -289,12 +301,12 @@ TEST_F(SuppressionMappingTest, LongestMatchWins) {
289
301
clang::ProcessWarningOptions (Diags, Diags.getDiagnosticOptions (), *FS);
290
302
EXPECT_THAT (diags (), IsEmpty ());
291
303
304
+ EXPECT_TRUE (Diags.isSuppressedViaMapping (
305
+ diag::warn_unused_function, locForFile (" clang/lib/Basic/foo.h" )));
306
+ EXPECT_FALSE (Diags.isSuppressedViaMapping (
307
+ diag::warn_unused_function, locForFile (" clang/lib/Sema/bar.h" )));
292
308
EXPECT_TRUE (Diags.isSuppressedViaMapping (diag::warn_unused_function,
293
- " clang/lib/Basic/foo.h" ));
294
- EXPECT_FALSE (Diags.isSuppressedViaMapping (diag::warn_unused_function,
295
- " clang/lib/Sema/bar.h" ));
296
- EXPECT_TRUE (Diags.isSuppressedViaMapping (diag::warn_unused_function,
297
- " clang/lib/Sema/foo.h" ));
309
+ locForFile (" clang/lib/Sema/foo.h" )));
298
310
}
299
311
300
312
TEST_F (SuppressionMappingTest, IsIgnored) {
@@ -308,9 +320,7 @@ TEST_F(SuppressionMappingTest, IsIgnored) {
308
320
clang::ProcessWarningOptions (Diags, Diags.getDiagnosticOptions (), *FS);
309
321
ASSERT_THAT (diags (), IsEmpty ());
310
322
311
- FileManager FM ({}, FS);
312
- SourceManager SM (Diags, FM);
313
-
323
+ SourceManager &SM = Diags.getSourceManager ();
314
324
auto ClangID =
315
325
SM.createFileID (llvm::MemoryBuffer::getMemBuffer (" " , " clang/foo.h" ));
316
326
auto NonClangID =
0 commit comments