1 //===-- ParsedASTTests.cpp ------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // These tests cover clangd's logic to build a TU, which generally uses the APIs
10 // in ParsedAST and Preamble, via the TestTU helper.
12 //===----------------------------------------------------------------------===//
14 #include "../../clang-tidy/ClangTidyCheck.h"
15 #include "../../clang-tidy/ClangTidyModule.h"
16 #include "../../clang-tidy/ClangTidyModuleRegistry.h"
18 #include "CompileCommands.h"
21 #include "Diagnostics.h"
23 #include "ParsedAST.h"
25 #include "SourceCode.h"
28 #include "TidyProvider.h"
29 #include "support/Context.h"
30 #include "clang/AST/DeclTemplate.h"
31 #include "clang/Basic/FileEntry.h"
32 #include "clang/Basic/SourceLocation.h"
33 #include "clang/Basic/SourceManager.h"
34 #include "clang/Basic/TokenKinds.h"
35 #include "clang/Lex/PPCallbacks.h"
36 #include "clang/Tooling/Syntax/Tokens.h"
37 #include "llvm/ADT/StringRef.h"
38 #include "llvm/Testing/Annotations/Annotations.h"
39 #include "llvm/Testing/Support/Error.h"
40 #include "gmock/gmock-matchers.h"
41 #include "gmock/gmock.h"
42 #include "gtest/gtest.h"
51 using ::testing::AllOf
;
52 using ::testing::Contains
;
53 using ::testing::ElementsAre
;
54 using ::testing::ElementsAreArray
;
55 using ::testing::IsEmpty
;
57 MATCHER_P(declNamed
, Name
, "") {
58 if (NamedDecl
*ND
= dyn_cast
<NamedDecl
>(arg
))
59 if (ND
->getName() == Name
)
61 if (auto *Stream
= result_listener
->stream()) {
62 llvm::raw_os_ostream
OS(*Stream
);
68 MATCHER_P(declKind
, Kind
, "") {
69 if (NamedDecl
*ND
= dyn_cast
<NamedDecl
>(arg
))
70 if (ND
->getDeclKindName() == llvm::StringRef(Kind
))
72 if (auto *Stream
= result_listener
->stream()) {
73 llvm::raw_os_ostream
OS(*Stream
);
79 // Matches if the Decl has template args equal to ArgName. If the decl is a
80 // NamedDecl and ArgName is an empty string it also matches.
81 MATCHER_P(withTemplateArgs
, ArgName
, "") {
82 if (const FunctionDecl
*FD
= dyn_cast
<FunctionDecl
>(arg
)) {
83 if (const auto *Args
= FD
->getTemplateSpecializationArgs()) {
84 std::string SpecializationArgs
;
85 // Without the PrintingPolicy "bool" will be printed as "_Bool".
87 PrintingPolicy
Policy(LO
);
88 Policy
.adjustForCPlusPlus();
89 for (const auto &Arg
: Args
->asArray()) {
90 if (SpecializationArgs
.size() > 0)
91 SpecializationArgs
+= ",";
92 SpecializationArgs
+= Arg
.getAsType().getAsString(Policy
);
94 if (Args
->size() == 0)
95 return ArgName
== SpecializationArgs
;
96 return ArgName
== "<" + SpecializationArgs
+ ">";
99 if (const NamedDecl
*ND
= dyn_cast
<NamedDecl
>(arg
))
100 return printTemplateSpecializationArgs(*ND
) == ArgName
;
104 MATCHER_P(pragmaTrivia
, P
, "") { return arg
.Trivia
== P
; }
107 Inclusion Actual
= testing::get
<0>(arg
);
108 Inclusion Expected
= testing::get
<1>(arg
);
109 return std::tie(Actual
.HashLine
, Actual
.Written
) ==
110 std::tie(Expected
.HashLine
, Expected
.Written
);
113 TEST(ParsedASTTest
, TopLevelDecls
) {
121 template <typename> bool X = true;
123 auto AST
= TU
.build();
124 EXPECT_THAT(AST
.getLocalTopLevelDecls(),
125 testing::UnorderedElementsAreArray(
126 {AllOf(declNamed("main"), declKind("Function")),
127 AllOf(declNamed("X"), declKind("VarTemplate"))}));
130 TEST(ParsedASTTest
, DoesNotGetIncludedTopDecls
) {
132 TU
.HeaderCode
= R
"cpp(
133 #define LL void foo(){}
146 auto AST
= TU
.build();
147 EXPECT_THAT(AST
.getLocalTopLevelDecls(), ElementsAre(declNamed("main")));
150 TEST(ParsedASTTest
, DoesNotGetImplicitTemplateTopDecls
) {
160 auto AST
= TU
.build();
161 EXPECT_THAT(AST
.getLocalTopLevelDecls(),
162 ElementsAre(declNamed("f"), declNamed("s")));
166 GetsExplicitInstantiationAndSpecializationTemplateTopDecls
) {
169 template <typename T>
173 template void f(double);
185 double d = foo<double>;
193 auto AST
= TU
.build();
195 AST
.getLocalTopLevelDecls(),
196 ElementsAreArray({AllOf(declNamed("f"), withTemplateArgs("")),
197 AllOf(declNamed("f"), withTemplateArgs("<bool>")),
198 AllOf(declNamed("f"), withTemplateArgs("<double>")),
199 AllOf(declNamed("V"), withTemplateArgs("")),
200 AllOf(declNamed("V"), withTemplateArgs("<T *>")),
201 AllOf(declNamed("V"), withTemplateArgs("<bool>")),
202 AllOf(declNamed("foo"), withTemplateArgs("")),
203 AllOf(declNamed("i"), withTemplateArgs("")),
204 AllOf(declNamed("d"), withTemplateArgs("")),
205 AllOf(declNamed("foo"), withTemplateArgs("<T *>")),
206 AllOf(declNamed("foo"), withTemplateArgs("<bool>"))}));
209 TEST(ParsedASTTest
, IgnoresDelayedTemplateParsing
) {
210 auto TU
= TestTU::withCode(R
"cpp(
211 template <typename T> void xxx() {
215 TU
.ExtraArgs
.push_back("-fdelayed-template-parsing");
216 auto AST
= TU
.build();
217 EXPECT_EQ(Decl::Var
, findUnqualifiedDecl(AST
, "yyy").getKind());
220 TEST(ParsedASTTest
, TokensAfterPreamble
) {
222 TU
.AdditionalFiles
["foo.h"] = R
"(
229 // error-ok: invalid syntax, just examining token stream
233 auto AST
= TU
.build();
234 const syntax::TokenBuffer
&T
= AST
.getTokens();
235 const auto &SM
= AST
.getSourceManager();
237 ASSERT_GT(T
.expandedTokens().size(), 2u);
238 // Check first token after the preamble.
239 EXPECT_EQ(T
.expandedTokens().front().text(SM
), "first_token");
240 // Last token is always 'eof'.
241 EXPECT_EQ(T
.expandedTokens().back().kind(), tok::eof
);
242 // Check the token before 'eof'.
243 EXPECT_EQ(T
.expandedTokens().drop_back().back().text(SM
), "last_token");
245 // The spelled tokens for the main file should have everything.
246 auto Spelled
= T
.spelledTokens(SM
.getMainFileID());
247 ASSERT_FALSE(Spelled
.empty());
248 EXPECT_EQ(Spelled
.front().kind(), tok::hash
);
249 EXPECT_EQ(Spelled
.back().text(SM
), "last_token");
252 TEST(ParsedASTTest
, NoCrashOnTokensWithTidyCheck
) {
254 // this check runs the preprocessor, we need to make sure it does not break
255 // our recording logic.
256 TU
.ClangTidyProvider
= addTidyChecks("modernize-use-trailing-return-type");
257 TU
.Code
= "inline int foo() {}";
259 auto AST
= TU
.build();
260 const syntax::TokenBuffer
&T
= AST
.getTokens();
261 const auto &SM
= AST
.getSourceManager();
263 ASSERT_GT(T
.expandedTokens().size(), 7u);
264 // Check first token after the preamble.
265 EXPECT_EQ(T
.expandedTokens().front().text(SM
), "inline");
266 // Last token is always 'eof'.
267 EXPECT_EQ(T
.expandedTokens().back().kind(), tok::eof
);
268 // Check the token before 'eof'.
269 EXPECT_EQ(T
.expandedTokens().drop_back().back().text(SM
), "}");
272 TEST(ParsedASTTest
, CanBuildInvocationWithUnknownArgs
) {
274 FS
.Files
= {{testPath("foo.cpp"), "void test() {}"}};
275 // Unknown flags should not prevent a build of compiler invocation.
278 Inputs
.CompileCommand
.CommandLine
= {"clang", "-fsome-unknown-flag",
279 testPath("foo.cpp")};
280 IgnoreDiagnostics IgnoreDiags
;
281 EXPECT_NE(buildCompilerInvocation(Inputs
, IgnoreDiags
), nullptr);
283 // Unknown forwarded to -cc1 should not a failure either.
284 Inputs
.CompileCommand
.CommandLine
= {
285 "clang", "-Xclang", "-fsome-unknown-flag", testPath("foo.cpp")};
286 EXPECT_NE(buildCompilerInvocation(Inputs
, IgnoreDiags
), nullptr);
289 TEST(ParsedASTTest
, CollectsMainFileMacroExpansions
) {
290 llvm::Annotations
TestCase(R
"cpp(
291 #define ^MACRO_ARGS(X, Y) X Y
294 // Macro arguments included.
295 ^MACRO_ARGS(^MACRO_ARGS(^MACRO_EXP(int), E), ^ID(= 2));
297 // Macro names inside other macros not included.
298 #define ^MACRO_ARGS2(X, Y) X Y
303 // Macros from token concatenations not included.
304 #define ^CONCAT(X) X##A()
305 #define ^PREPEND(X) MACRO##X()
306 #define ^MACROA() 123
307 int G = ^CONCAT(MACRO);
310 // Macros included not from preamble not included.
313 int printf(const char*, ...);
315 #define ^assert(COND) if (!(COND)) { printf("%s
", #COND); exit(0); }
318 // Includes macro expansions in arguments that are expressions
325 #define ^MULTIPLE_DEFINITION 1
326 #undef ^MULTIPLE_DEFINITION
328 #define ^MULTIPLE_DEFINITION 2
329 #undef ^MULTIPLE_DEFINITION
331 auto TU
= TestTU::withCode(TestCase
.code());
332 TU
.HeaderCode
= R
"cpp(
334 #define MACRO_EXP(X) ID(X)
337 TU
.AdditionalFiles
["foo.inc"] = R
"cpp(
342 ParsedAST AST
= TU
.build();
343 std::vector
<size_t> MacroExpansionPositions
;
344 for (const auto &SIDToRefs
: AST
.getMacros().MacroRefs
) {
345 for (const auto &R
: SIDToRefs
.second
)
346 MacroExpansionPositions
.push_back(R
.StartOffset
);
348 for (const auto &R
: AST
.getMacros().UnknownMacros
)
349 MacroExpansionPositions
.push_back(R
.StartOffset
);
351 MacroExpansionPositions
,
352 testing::UnorderedElementsAreArray(TestCase
.points()));
355 MATCHER_P(withFileName
, Inc
, "") { return arg
.FileName
== Inc
; }
357 TEST(ParsedASTTest
, PatchesAdditionalIncludes
) {
358 llvm::StringLiteral ModifiedContents
= R
"cpp(
367 // Build expected ast with symbols coming from headers.
369 TU
.Filename
= "foo.cpp";
370 TU
.AdditionalFiles
["foo.h"] = "void foo();";
371 TU
.AdditionalFiles
["sub/baz.h"] = "void baz();";
372 TU
.AdditionalFiles
["sub/aux.h"] = "void aux();";
373 TU
.ExtraArgs
= {"-I" + testPath("sub")};
374 TU
.Code
= ModifiedContents
.str();
375 auto ExpectedAST
= TU
.build();
377 // Build preamble with no includes.
381 auto Inputs
= TU
.inputs(FS
);
382 auto CI
= buildCompilerInvocation(Inputs
, Diags
);
384 buildPreamble(testPath("foo.cpp"), *CI
, Inputs
, true, nullptr);
385 ASSERT_TRUE(EmptyPreamble
);
386 EXPECT_THAT(EmptyPreamble
->Includes
.MainFileIncludes
, IsEmpty());
388 // Now build an AST using empty preamble and ensure patched includes worked.
389 TU
.Code
= ModifiedContents
.str();
390 Inputs
= TU
.inputs(FS
);
391 auto PatchedAST
= ParsedAST::build(testPath("foo.cpp"), Inputs
, std::move(CI
),
393 ASSERT_TRUE(PatchedAST
);
395 // Ensure source location information is correct, including resolved paths.
396 EXPECT_THAT(PatchedAST
->getIncludeStructure().MainFileIncludes
,
398 eqInc(), ExpectedAST
.getIncludeStructure().MainFileIncludes
));
399 // Ensure file proximity signals are correct.
400 auto &SM
= PatchedAST
->getSourceManager();
401 auto &FM
= SM
.getFileManager();
402 // Copy so that we can use operator[] to get the children.
403 IncludeStructure Includes
= PatchedAST
->getIncludeStructure();
404 auto MainFE
= FM
.getFile(testPath("foo.cpp"));
406 auto MainID
= Includes
.getID(*MainFE
);
407 auto AuxFE
= FM
.getFile(testPath("sub/aux.h"));
409 auto AuxID
= Includes
.getID(*AuxFE
);
410 EXPECT_THAT(Includes
.IncludeChildren
[*MainID
], Contains(*AuxID
));
413 TEST(ParsedASTTest
, PatchesDeletedIncludes
) {
415 TU
.Filename
= "foo.cpp";
417 auto ExpectedAST
= TU
.build();
419 // Build preamble with no includes.
420 TU
.Code
= R
"cpp(#include <foo.h>)cpp";
423 auto Inputs
= TU
.inputs(FS
);
424 auto CI
= buildCompilerInvocation(Inputs
, Diags
);
425 auto BaselinePreamble
=
426 buildPreamble(testPath("foo.cpp"), *CI
, Inputs
, true, nullptr);
427 ASSERT_TRUE(BaselinePreamble
);
428 EXPECT_THAT(BaselinePreamble
->Includes
.MainFileIncludes
,
429 ElementsAre(testing::Field(&Inclusion::Written
, "<foo.h>")));
431 // Now build an AST using additional includes and check that locations are
434 Inputs
= TU
.inputs(FS
);
435 auto PatchedAST
= ParsedAST::build(testPath("foo.cpp"), Inputs
, std::move(CI
),
436 {}, BaselinePreamble
);
437 ASSERT_TRUE(PatchedAST
);
439 // Ensure source location information is correct.
440 EXPECT_THAT(PatchedAST
->getIncludeStructure().MainFileIncludes
,
442 eqInc(), ExpectedAST
.getIncludeStructure().MainFileIncludes
));
443 // Ensure file proximity signals are correct.
444 auto &SM
= ExpectedAST
.getSourceManager();
445 auto &FM
= SM
.getFileManager();
446 // Copy so that we can getOrCreateID().
447 IncludeStructure Includes
= ExpectedAST
.getIncludeStructure();
448 auto MainFE
= FM
.getFileRef(testPath("foo.cpp"));
449 ASSERT_THAT_EXPECTED(MainFE
, llvm::Succeeded());
450 auto MainID
= Includes
.getOrCreateID(*MainFE
);
451 auto &PatchedFM
= PatchedAST
->getSourceManager().getFileManager();
452 IncludeStructure PatchedIncludes
= PatchedAST
->getIncludeStructure();
453 auto PatchedMainFE
= PatchedFM
.getFileRef(testPath("foo.cpp"));
454 ASSERT_THAT_EXPECTED(PatchedMainFE
, llvm::Succeeded());
455 auto PatchedMainID
= PatchedIncludes
.getOrCreateID(*PatchedMainFE
);
456 EXPECT_EQ(Includes
.includeDepth(MainID
)[MainID
],
457 PatchedIncludes
.includeDepth(PatchedMainID
)[PatchedMainID
]);
460 // Returns Code guarded by #ifndef guards
461 std::string
guard(llvm::StringRef Code
) {
462 static int GuardID
= 0;
463 std::string GuardName
= ("GUARD_" + llvm::Twine(++GuardID
)).str();
464 return llvm::formatv("#ifndef {0}\n#define {0}\n{1}\n#endif\n", GuardName
,
468 std::string
once(llvm::StringRef Code
) {
469 return llvm::formatv("#pragma once\n{0}\n", Code
);
472 bool mainIsGuarded(const ParsedAST
&AST
) {
473 const auto &SM
= AST
.getSourceManager();
474 OptionalFileEntryRef MainFE
= SM
.getFileEntryRefForID(SM
.getMainFileID());
475 return AST
.getPreprocessor()
476 .getHeaderSearchInfo()
477 .isFileMultipleIncludeGuarded(*MainFE
);
480 MATCHER_P(diag
, Desc
, "") {
481 return llvm::StringRef(arg
.Message
).contains(Desc
);
484 // Check our understanding of whether the main file is header guarded or not.
485 TEST(ParsedASTTest
, HeaderGuards
) {
487 TU
.ImplicitHeaderGuard
= false;
490 EXPECT_FALSE(mainIsGuarded(TU
.build()));
492 TU
.Code
= guard(";");
493 EXPECT_TRUE(mainIsGuarded(TU
.build()));
496 EXPECT_TRUE(mainIsGuarded(TU
.build()));
502 EXPECT_FALSE(mainIsGuarded(TU
.build())); // FIXME: true
511 EXPECT_FALSE(mainIsGuarded(TU
.build()));
514 // Check our handling of files that include themselves.
515 // Ideally we allow this if the file has header guards.
517 // Note: the semicolons (empty statements) are significant!
518 // - they force the preamble to end and the body to begin. Directives can have
519 // different effects in the preamble vs main file (which we try to hide).
520 // - if the preamble would otherwise cover the whole file, a trailing semicolon
521 // forces their sizes to be different. This is significant because the file
522 // size is part of the lookup key for HeaderFileInfo, and we don't want to
523 // rely on the preamble's HFI being looked up when parsing the main file.
524 TEST(ParsedASTTest
, HeaderGuardsSelfInclude
) {
525 // Disable include cleaner diagnostics to prevent them from interfering with
526 // other diagnostics.
528 Cfg
.Diagnostics
.MissingIncludes
= Config::IncludesPolicy::None
;
529 Cfg
.Diagnostics
.UnusedIncludes
= Config::IncludesPolicy::None
;
530 WithContextValue
Ctx(Config::Key
, std::move(Cfg
));
533 TU
.ImplicitHeaderGuard
= false;
534 TU
.Filename
= "self.h";
537 #include "self
.h
" // error-ok
540 auto AST
= TU
.build();
541 EXPECT_THAT(AST
.getDiagnostics(),
542 ElementsAre(diag("recursively when building a preamble")));
543 EXPECT_FALSE(mainIsGuarded(AST
));
547 #include "self
.h
" // error-ok
550 EXPECT_THAT(AST
.getDiagnostics(), ElementsAre(diag("nested too deeply")));
551 EXPECT_FALSE(mainIsGuarded(AST
));
559 EXPECT_THAT(AST
.getDiagnostics(), IsEmpty());
560 EXPECT_TRUE(mainIsGuarded(AST
));
568 EXPECT_THAT(AST
.getDiagnostics(), IsEmpty());
569 EXPECT_TRUE(mainIsGuarded(AST
));
577 EXPECT_THAT(AST
.getDiagnostics(), IsEmpty());
578 EXPECT_TRUE(mainIsGuarded(AST
));
583 #include "self
.h
" // error-ok: FIXME, this would be nice to support
588 EXPECT_THAT(AST
.getDiagnostics(),
589 ElementsAre(diag("recursively when building a preamble")));
590 EXPECT_TRUE(mainIsGuarded(AST
));
600 EXPECT_THAT(AST
.getDiagnostics(), IsEmpty());
601 EXPECT_TRUE(mainIsGuarded(AST
));
603 // Guarded too late...
605 #include "self
.h
" // error-ok
612 EXPECT_THAT(AST
.getDiagnostics(),
613 ElementsAre(diag("recursively when building a preamble")));
614 EXPECT_FALSE(mainIsGuarded(AST
));
617 #include "self
.h
" // error-ok
624 EXPECT_THAT(AST
.getDiagnostics(),
625 ElementsAre(diag("recursively when building a preamble")));
626 EXPECT_FALSE(mainIsGuarded(AST
));
636 EXPECT_THAT(AST
.getDiagnostics(), IsEmpty());
637 EXPECT_FALSE(mainIsGuarded(AST
));
640 #include "self
.h
" // error-ok
645 EXPECT_THAT(AST
.getDiagnostics(),
646 ElementsAre(diag("recursively when building a preamble")));
647 EXPECT_TRUE(mainIsGuarded(AST
));
650 #include "self
.h
" // error-ok
655 EXPECT_THAT(AST
.getDiagnostics(),
656 ElementsAre(diag("recursively when building a preamble")));
657 EXPECT_TRUE(mainIsGuarded(AST
));
660 // Tests how we handle common idioms for splitting a header-only library
661 // into interface and implementation files (e.g. *.h vs *.inl).
662 // These files mutually include each other, and need careful handling of include
663 // guards (which interact with preambles).
664 TEST(ParsedASTTest
, HeaderGuardsImplIface
) {
665 std::string Interface
= R
"cpp(
666 // error-ok: we assert on diagnostics explicitly
667 template <class T> struct Traits {
672 std::string Implementation
= R
"cpp(
673 // error-ok: we assert on diagnostics explicitly
675 template <class T> unsigned Traits<T>::size() {
681 TU
.ImplicitHeaderGuard
= false; // We're testing include guard handling!
682 TU
.ExtraArgs
.push_back("-xc++-header");
684 // Editing the interface file, which is include guarded (easy case).
685 // We mostly get this right via PP if we don't recognize the include guard.
686 TU
.Filename
= "iface.h";
687 TU
.Code
= guard(Interface
);
688 TU
.AdditionalFiles
= {{"impl.h", Implementation
}};
689 auto AST
= TU
.build();
690 EXPECT_THAT(AST
.getDiagnostics(), IsEmpty());
691 EXPECT_TRUE(mainIsGuarded(AST
));
692 // Slightly harder: the `#pragma once` is part of the preamble, and we
693 // need to transfer it to the main file's HeaderFileInfo.
694 TU
.Code
= once(Interface
);
696 EXPECT_THAT(AST
.getDiagnostics(), IsEmpty());
697 EXPECT_TRUE(mainIsGuarded(AST
));
699 // Editing the implementation file, which is not include guarded.
700 TU
.Filename
= "impl.h";
701 TU
.Code
= Implementation
;
702 TU
.AdditionalFiles
= {{"iface.h", guard(Interface
)}};
704 // The diagnostic is unfortunate in this case, but correct per our model.
705 // Ultimately the include is skipped and the code is parsed correctly though.
706 EXPECT_THAT(AST
.getDiagnostics(),
707 ElementsAre(diag("in included file: main file cannot be included "
708 "recursively when building a preamble")));
709 EXPECT_FALSE(mainIsGuarded(AST
));
710 // Interface is pragma once guarded, same thing.
711 TU
.AdditionalFiles
= {{"iface.h", once(Interface
)}};
713 EXPECT_THAT(AST
.getDiagnostics(),
714 ElementsAre(diag("in included file: main file cannot be included "
715 "recursively when building a preamble")));
716 EXPECT_FALSE(mainIsGuarded(AST
));
719 TEST(ParsedASTTest
, DiscoversPragmaMarks
) {
721 TU
.AdditionalFiles
["Header.h"] = R
"(
722 #pragma mark - Something API
724 #pragma mark Something else
728 #pragma mark In Preamble
729 #pragma mark - Something Impl
730 int something() { return 1; }
733 auto AST
= TU
.build();
735 EXPECT_THAT(AST
.getMarks(), ElementsAre(pragmaTrivia(" In Preamble"),
736 pragmaTrivia(" - Something Impl"),
737 pragmaTrivia(" End")));
740 TEST(ParsedASTTest
, GracefulFailureOnAssemblyFile
) {
741 std::string Filename
= "TestTU.S";
742 std::string Code
= R
"S(
748 // The rest is a simplified version of TestTU::build().
749 // Don't call TestTU::build() itself because it would assert on
750 // failure to build an AST.
752 std::string FullFilename
= testPath(Filename
);
753 FS
.Files
[FullFilename
] = Code
;
755 auto &Argv
= Inputs
.CompileCommand
.CommandLine
;
757 Argv
.push_back(FullFilename
);
758 Inputs
.CompileCommand
.Filename
= FullFilename
;
759 Inputs
.CompileCommand
.Directory
= testRoot();
760 Inputs
.Contents
= Code
;
763 auto CI
= buildCompilerInvocation(Inputs
, Diags
);
764 assert(CI
&& "Failed to build compilation invocation.");
765 auto AST
= ParsedAST::build(FullFilename
, Inputs
, std::move(CI
), {}, nullptr);
767 EXPECT_FALSE(AST
.has_value())
768 << "Should not try to build AST for assembly source file";
772 } // namespace clangd