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,10 @@ TEST_F(SuppressionMappingTest, SuppressesGroup) {
255
267
clang::ProcessWarningOptions (Diags, Diags.getDiagnosticOptions (), *FS);
256
268
EXPECT_THAT (diags (), IsEmpty ());
257
269
270
+ SourceLocation FooLoc = locForFile (" foo.cpp" );
258
271
EXPECT_TRUE (
259
- Diags.isSuppressedViaMapping (diag::warn_unused_function, " foo.cpp " ));
260
- EXPECT_FALSE (Diags.isSuppressedViaMapping (diag::warn_deprecated, " foo.cpp " ));
272
+ Diags.isSuppressedViaMapping (diag::warn_unused_function, FooLoc ));
273
+ EXPECT_FALSE (Diags.isSuppressedViaMapping (diag::warn_deprecated, FooLoc ));
261
274
}
262
275
263
276
TEST_F (SuppressionMappingTest, EmitCategoryIsExcluded) {
@@ -271,10 +284,10 @@ TEST_F(SuppressionMappingTest, EmitCategoryIsExcluded) {
271
284
clang::ProcessWarningOptions (Diags, Diags.getDiagnosticOptions (), *FS);
272
285
EXPECT_THAT (diags (), IsEmpty ());
273
286
274
- EXPECT_TRUE (
275
- Diags. isSuppressedViaMapping (diag::warn_unused_function, " bar.cpp" ));
276
- EXPECT_FALSE (
277
- Diags. isSuppressedViaMapping (diag::warn_unused_function, " foo.cpp" ));
287
+ EXPECT_TRUE (Diags. isSuppressedViaMapping (diag::warn_unused_function,
288
+ locForFile ( " bar.cpp" ) ));
289
+ EXPECT_FALSE (Diags. isSuppressedViaMapping (diag::warn_unused_function,
290
+ locForFile ( " foo.cpp" ) ));
278
291
}
279
292
280
293
TEST_F (SuppressionMappingTest, LongestMatchWins) {
@@ -289,12 +302,12 @@ TEST_F(SuppressionMappingTest, LongestMatchWins) {
289
302
clang::ProcessWarningOptions (Diags, Diags.getDiagnosticOptions (), *FS);
290
303
EXPECT_THAT (diags (), IsEmpty ());
291
304
305
+ EXPECT_TRUE (Diags.isSuppressedViaMapping (
306
+ diag::warn_unused_function, locForFile (" clang/lib/Basic/foo.h" )));
307
+ EXPECT_FALSE (Diags.isSuppressedViaMapping (
308
+ diag::warn_unused_function, locForFile (" clang/lib/Sema/bar.h" )));
292
309
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" ));
310
+ locForFile (" clang/lib/Sema/foo.h" )));
298
311
}
299
312
300
313
TEST_F (SuppressionMappingTest, IsIgnored) {
@@ -308,9 +321,7 @@ TEST_F(SuppressionMappingTest, IsIgnored) {
308
321
clang::ProcessWarningOptions (Diags, Diags.getDiagnosticOptions (), *FS);
309
322
ASSERT_THAT (diags (), IsEmpty ());
310
323
311
- FileManager FM ({}, FS);
312
- SourceManager SM (Diags, FM);
313
-
324
+ SourceManager &SM = Diags.getSourceManager ();
314
325
auto ClangID =
315
326
SM.createFileID (llvm::MemoryBuffer::getMemBuffer (" " , " clang/foo.h" ));
316
327
auto NonClangID =
0 commit comments