Skip to content

Commit c895ad5

Browse files
VergeChristritao
authored andcommitted
Initial commit supporting Clang 19
1 parent 9a4c48d commit c895ad5

File tree

8 files changed

+214
-239
lines changed

8 files changed

+214
-239
lines changed

build/llvm/LLVM-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6eb36aed86ea276695697093eb8136554c29286b
1+
cd708029e0b2869e80abe31ddb175f7c35361f90

build/llvm/LLVM.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ function cmake(gen, conf, builddir, options)
263263
.. ' -DLLVM_INCLUDE_TESTS=false'
264264
.. ' -DLLVM_ENABLE_LIBEDIT=false'
265265
.. ' -DLLVM_ENABLE_LIBXML2=false'
266+
.. ' -DLLVM_ENABLE_HIP=false'
267+
.. ' -DLLVM_ENABLE_MLGO=false'
266268
.. ' -DLLVM_ENABLE_TERMINFO=false'
267269
.. ' -DLLVM_ENABLE_ZLIB=false'
268270
.. ' -DLLVM_ENABLE_ZSTD=false'
@@ -326,7 +328,7 @@ function cmake(gen, conf, builddir, options)
326328
.. ' -DLLVM_TOOL_LLVM_MODEXTRACT_BUILD=false'
327329
.. ' -DLLVM_TOOL_LLVM_MT_BUILD=false'
328330
.. ' -DLLVM_TOOL_LLVM_NM_BUILD=false'
329-
.. ' -DLLVM_TOOL_LLVM_OBJCOPY_BUILD=false'
331+
.. ' -DLLVM_TOOL_LLVM_OBJCOPY_BUILD=true'
330332
.. ' -DLLVM_TOOL_LLVM_OBJDUMP_BUILD=false'
331333
.. ' -DLLVM_TOOL_LLVM_OPT_FUZZER_BUILD=false'
332334
.. ' -DLLVM_TOOL_LLVM_OPT_REPORT_BUILD=false'
@@ -366,7 +368,8 @@ function cmake(gen, conf, builddir, options)
366368
.. ' -DLLVM_TOOL_VERIFY_USELISTORDER_BUILD=false'
367369
.. ' -DLLVM_TOOL_VFABI_DEMANGLE_FUZZER_BUILD=false'
368370
.. ' -DLLVM_TOOL_XCODE_TOOLCHAIN_BUILD=false'
369-
.. ' -DLLVM_TOOL_YAML2OBJ_BUILD=false'
371+
.. ' -DLLVM_TOOL_YAML2OBJ_BUILD=true'
372+
.. ' -DLLVM_TOOL_LLVM_OBJCOPY_BUILD=true'
370373
.. ' -DLLVM_HAVE_LIBXAR=false'
371374
.. ' -DCLANG_BUILD_EXAMPLES=false '
372375
.. ' -DCLANG_BUILD_TOOLS=false'
@@ -376,6 +379,8 @@ function cmake(gen, conf, builddir, options)
376379
.. ' -DCLANG_INCLUDE_TESTS=false'
377380
.. ' -DCLANG_TOOL_AMDGPU_ARCH_BUILD=false'
378381
.. ' -DCLANG_TOOL_APINOTES_TEST_BUILD=false'
382+
.. ' -DCLANG_ENABLE_HIP=false'
383+
.. ' -DCLANG_ENABLE_API_NOTES=false'
379384
.. ' -DCLANG_TOOL_ARCMT_TEST_BUILD=false'
380385
.. ' -DCLANG_TOOL_CLANG_CHECK_BUILD=false'
381386
.. ' -DCLANG_TOOL_CLANG_DIFF_BUILD=false'

src/CppParser/ASTNameMangler.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,18 @@ std::string ASTNameMangler::GetMangledStructor(const NamedDecl* ND, unsigned Str
9999
return FrontendBuf;
100100
}
101101

102-
std::string ASTNameMangler::GetMangledThunk(const CXXMethodDecl* MD, const ThunkInfo& T, bool /*ElideOverrideInfo*/) const
102+
std::string ASTNameMangler::GetMangledThunk(const CXXMethodDecl* MD, const ThunkInfo& T, bool ElideOverrideInfo) const
103103
{
104104
std::string FrontendBuf;
105105
llvm::raw_string_ostream FOS(FrontendBuf);
106106

107107
// TODO: Enable `ElideOverrideInfo` param if clang is updated to 19
108-
MC->mangleThunk(MD, T, /*ElideOverrideInfo,*/ FOS);
109108

109+
#if LLVM_VERSION_MAJOR >= 19
110+
MC->mangleThunk(MD, T, ElideOverrideInfo, FOS);
111+
#else
112+
MC->mangleThunk(MD, T, FOS);
113+
#endif
110114
return FrontendBuf;
111115
}
112116

src/CppParser/Comments.cpp

Lines changed: 115 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -49,41 +49,22 @@ RawComment* Parser::WalkRawComment(const clang::RawComment* RC)
4949
}
5050

5151
static InlineCommandComment::RenderKind
52-
ConvertRenderKind(clang::comments::InlineCommandComment::RenderKind Kind)
52+
ConvertRenderKind(std::string Kind)
5353
{
5454
using namespace clang::comments;
55-
switch (Kind)
56-
{
57-
case clang::comments::InlineCommandComment::RenderNormal:
58-
return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderNormal;
59-
case clang::comments::InlineCommandComment::RenderBold:
60-
return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderBold;
61-
case clang::comments::InlineCommandComment::RenderMonospaced:
62-
return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderMonospaced;
63-
case clang::comments::InlineCommandComment::RenderEmphasized:
64-
return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderEmphasized;
65-
case clang::comments::InlineCommandComment::RenderAnchor:
66-
return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderAnchor;
67-
}
55+
if (Kind == "b")
56+
return AST::InlineCommandComment::RenderKind::RenderBold;
57+
else if (Kind == "c")
58+
return AST::InlineCommandComment::RenderKind::RenderMonospaced;
59+
else if (Kind == "a")
60+
return AST::InlineCommandComment::RenderKind::RenderAnchor;
61+
else if (Kind == "e")
62+
return AST::InlineCommandComment::RenderKind::RenderEmphasized;
63+
else
64+
return AST::InlineCommandComment::RenderKind::RenderNormal;
6865
llvm_unreachable("Unknown render kind");
6966
}
7067

71-
static ParamCommandComment::PassDirection
72-
ConvertParamPassDirection(clang::comments::ParamCommandComment::PassDirection Dir)
73-
{
74-
using namespace clang::comments;
75-
switch (Dir)
76-
{
77-
case clang::comments::ParamCommandComment::In:
78-
return CppSharp::CppParser::AST::ParamCommandComment::PassDirection::In;
79-
case clang::comments::ParamCommandComment::Out:
80-
return CppSharp::CppParser::AST::ParamCommandComment::PassDirection::Out;
81-
case clang::comments::ParamCommandComment::InOut:
82-
return CppSharp::CppParser::AST::ParamCommandComment::PassDirection::InOut;
83-
}
84-
llvm_unreachable("Unknown parameter pass direction");
85-
}
86-
8768
static void HandleInlineContent(const clang::comments::InlineContentComment* CK,
8869
InlineContentComment* IC)
8970
{
@@ -102,158 +83,120 @@ static void HandleBlockCommand(const clang::comments::BlockCommandComment* CK,
10283
}
10384
}
10485

105-
static Comment* ConvertCommentBlock(clang::comments::Comment* C)
86+
static Comment* ConvertCommentBlock(clang::comments::Comment* C, clang::CompilerInstance* CI)
10687
{
10788
using namespace clang;
10889
using clang::comments::Comment;
10990

11091
// This needs to have an underscore else we get an ICE under VS2012.
111-
CppSharp::CppParser::AST::Comment* _Comment = 0;
112-
113-
switch (C->getCommentKind())
92+
CppSharp::CppParser::AST::Comment* _Comment = nullptr;
93+
auto kind = C->getCommentKind();
94+
if (auto CK = dyn_cast<const comments::FullComment>(C))
11495
{
115-
case Comment::FullCommentKind:
116-
{
117-
auto CK = cast<clang::comments::FullComment>(C);
118-
auto FC = new FullComment();
119-
_Comment = FC;
120-
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
121-
{
122-
auto Content = ConvertCommentBlock(*I);
123-
FC->Blocks.push_back(static_cast<BlockContentComment*>(Content));
124-
}
125-
break;
126-
}
127-
case Comment::BlockCommandCommentKind:
128-
{
129-
auto CK = cast<const clang::comments::BlockCommandComment>(C);
130-
auto BC = new BlockCommandComment();
131-
_Comment = BC;
132-
HandleBlockCommand(CK, BC);
133-
BC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph()));
134-
break;
135-
}
136-
case Comment::ParamCommandCommentKind:
137-
{
138-
auto CK = cast<clang::comments::ParamCommandComment>(C);
139-
auto PC = new ParamCommandComment();
140-
_Comment = PC;
141-
HandleBlockCommand(CK, PC);
142-
PC->direction = ConvertParamPassDirection(CK->getDirection());
143-
if (CK->isParamIndexValid() && !CK->isVarArgParam())
144-
PC->paramIndex = CK->getParamIndex();
145-
PC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph()));
146-
break;
147-
}
148-
case Comment::TParamCommandCommentKind:
149-
{
150-
auto CK = cast<clang::comments::TParamCommandComment>(C);
151-
_Comment = new TParamCommandComment();
152-
auto TC = new TParamCommandComment();
153-
_Comment = TC;
154-
HandleBlockCommand(CK, TC);
155-
if (CK->isPositionValid())
156-
for (unsigned I = 0, E = CK->getDepth(); I != E; ++I)
157-
TC->Position.push_back(CK->getIndex(I));
158-
TC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph()));
159-
break;
160-
}
161-
case Comment::VerbatimBlockCommentKind:
162-
{
163-
auto CK = cast<clang::comments::VerbatimBlockComment>(C);
164-
auto VB = new VerbatimBlockComment();
165-
_Comment = VB;
166-
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
167-
{
168-
auto Line = ConvertCommentBlock(*I);
169-
VB->Lines.push_back(static_cast<VerbatimBlockLineComment*>(Line));
170-
}
171-
break;
172-
}
173-
case Comment::VerbatimLineCommentKind:
174-
{
175-
auto CK = cast<clang::comments::VerbatimLineComment>(C);
176-
auto VL = new VerbatimLineComment();
177-
_Comment = VL;
178-
VL->text = CK->getText().str();
179-
break;
180-
}
181-
case Comment::ParagraphCommentKind:
182-
{
183-
auto CK = cast<clang::comments::ParagraphComment>(C);
184-
auto PC = new ParagraphComment();
185-
_Comment = PC;
186-
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
187-
{
188-
auto Content = ConvertCommentBlock(*I);
189-
PC->Content.push_back(static_cast<InlineContentComment*>(Content));
190-
}
191-
PC->isWhitespace = CK->isWhitespace();
192-
break;
193-
}
194-
case Comment::HTMLStartTagCommentKind:
195-
{
196-
auto CK = cast<clang::comments::HTMLStartTagComment>(C);
197-
auto TC = new HTMLStartTagComment();
198-
_Comment = TC;
199-
HandleInlineContent(CK, TC);
200-
TC->tagName = CK->getTagName().str();
201-
for (unsigned I = 0, E = CK->getNumAttrs(); I != E; ++I)
202-
{
203-
auto A = CK->getAttr(I);
204-
auto Attr = HTMLStartTagComment::Attribute();
205-
Attr.name = A.Name.str();
206-
Attr.value = A.Value.str();
207-
TC->Attributes.push_back(Attr);
208-
}
209-
break;
210-
}
211-
case Comment::HTMLEndTagCommentKind:
212-
{
213-
auto CK = cast<clang::comments::HTMLEndTagComment>(C);
214-
auto TC = new HTMLEndTagComment();
215-
_Comment = TC;
216-
HandleInlineContent(CK, TC);
217-
TC->tagName = CK->getTagName().str();
218-
break;
219-
}
220-
case Comment::TextCommentKind:
221-
{
222-
auto CK = cast<clang::comments::TextComment>(C);
223-
auto TC = new TextComment();
224-
_Comment = TC;
225-
HandleInlineContent(CK, TC);
226-
TC->text = CK->getText().str();
227-
break;
228-
}
229-
case Comment::InlineCommandCommentKind:
96+
auto FC = new FullComment();
97+
_Comment = FC;
98+
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
99+
FC->Blocks.push_back(static_cast<BlockContentComment*>(ConvertCommentBlock(*I, CI)));
100+
}
101+
else if (auto CK = dyn_cast<const comments::BlockCommandComment>(C))
102+
{
103+
auto BC = new BlockCommandComment();
104+
_Comment = BC;
105+
HandleBlockCommand(CK, BC);
106+
BC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph(), CI));
107+
}
108+
else if (auto CK = dyn_cast<const comments::ParamCommandComment>(C))
109+
{
110+
auto PC = new ParamCommandComment();
111+
_Comment = PC;
112+
HandleBlockCommand(CK, PC);
113+
if (CK->isParamIndexValid() && !CK->isVarArgParam())
114+
PC->paramIndex = CK->getParamIndex();
115+
PC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph(), CI));
116+
}
117+
else if (auto CK = dyn_cast<const comments::TParamCommandComment>(C))
118+
{
119+
auto TC = new TParamCommandComment();
120+
_Comment = TC;
121+
HandleBlockCommand(CK, TC);
122+
if (CK->isPositionValid())
123+
for (unsigned I = 0, E = CK->getDepth(); I != E; ++I)
124+
TC->Position.push_back(CK->getIndex(I));
125+
TC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph(), CI));
126+
}
127+
else if (auto CK = dyn_cast<const comments::VerbatimBlockComment>(C))
128+
{
129+
auto VB = new VerbatimBlockComment();
130+
_Comment = VB;
131+
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
132+
VB->Lines.push_back(static_cast<VerbatimBlockLineComment*>(ConvertCommentBlock(*I, CI)));
133+
}
134+
else if (auto CK = dyn_cast<const comments::VerbatimLineComment>(C))
135+
{
136+
auto VL = new VerbatimLineComment();
137+
_Comment = VL;
138+
VL->text = CK->getText().str();
139+
}
140+
else if (auto CK = dyn_cast<const comments::ParagraphComment>(C))
141+
{
142+
auto PC = new ParagraphComment();
143+
_Comment = PC;
144+
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
145+
PC->Content.push_back(static_cast<InlineContentComment*>(ConvertCommentBlock(*I, CI)));
146+
PC->isWhitespace = CK->isWhitespace();
147+
}
148+
else if (auto CK = dyn_cast<const comments::HTMLStartTagComment>(C))
149+
{
150+
auto TC = new HTMLStartTagComment();
151+
_Comment = TC;
152+
HandleInlineContent(CK, TC);
153+
TC->tagName = CK->getTagName().str();
154+
for (unsigned I = 0, E = CK->getNumAttrs(); I != E; ++I)
230155
{
231-
auto CK = cast<clang::comments::InlineCommandComment>(C);
232-
auto IC = new InlineCommandComment();
233-
_Comment = IC;
234-
HandleInlineContent(CK, IC);
235-
IC->commandId = CK->getCommandID();
236-
IC->commentRenderKind = ConvertRenderKind(CK->getRenderKind());
237-
for (unsigned I = 0, E = CK->getNumArgs(); I != E; ++I)
238-
{
239-
auto Arg = InlineCommandComment::Argument();
240-
Arg.text = CK->getArgText(I).str();
241-
IC->Arguments.push_back(Arg);
242-
}
243-
break;
156+
auto A = CK->getAttr(I);
157+
auto Attr = HTMLStartTagComment::Attribute();
158+
Attr.name = A.Name.str();
159+
Attr.value = A.Value.str();
160+
TC->Attributes.push_back(Attr);
244161
}
245-
case Comment::VerbatimBlockLineCommentKind:
162+
}
163+
else if (auto CK = dyn_cast<const comments::HTMLEndTagComment>(C))
164+
{
165+
auto TC = new HTMLEndTagComment();
166+
_Comment = TC;
167+
HandleInlineContent(CK, TC);
168+
TC->tagName = CK->getTagName().str();
169+
}
170+
else if (auto CK = dyn_cast<const comments::TextComment>(C))
171+
{
172+
auto TC = new TextComment();
173+
_Comment = TC;
174+
HandleInlineContent(CK, TC);
175+
TC->text = CK->getText().str();
176+
}
177+
else if (auto CK = dyn_cast<const comments::InlineCommandComment>(C))
178+
{
179+
auto IC = new InlineCommandComment();
180+
_Comment = IC;
181+
HandleInlineContent(CK, IC);
182+
IC->commandId = CK->getCommandID();
183+
184+
IC->commentRenderKind = ConvertRenderKind(CK->getCommandName(CI->getASTContext().getCommentCommandTraits()).str());
185+
for (unsigned I = 0, E = CK->getNumArgs(); I != E; ++I)
246186
{
247-
auto CK = cast<clang::comments::VerbatimBlockLineComment>(C);
248-
auto VL = new VerbatimBlockLineComment();
249-
_Comment = VL;
250-
VL->text = CK->getText().str();
251-
break;
187+
auto Arg = InlineCommandComment::Argument();
188+
Arg.text = CK->getArgText(I).str();
189+
IC->Arguments.push_back(Arg);
252190
}
253-
case Comment::NoCommentKind: return nullptr;
254-
default:
255-
llvm_unreachable("Unknown comment kind");
256191
}
192+
else if (auto CK = dyn_cast<const comments::VerbatimBlockLineComment>(C))
193+
{
194+
auto VL = new VerbatimBlockLineComment();
195+
_Comment = VL;
196+
VL->text = CK->getText().str();
197+
}
198+
else
199+
llvm_unreachable("Unknown comment kind");
257200

258201
assert(_Comment && "Invalid comment instance");
259202
return _Comment;
@@ -272,7 +215,7 @@ void Parser::HandleComments(const clang::Decl* D, Declaration* Decl)
272215

273216
if (clang::comments::FullComment* FC = RC->parse(c->getASTContext(), &c->getPreprocessor(), D))
274217
{
275-
auto CB = static_cast<FullComment*>(ConvertCommentBlock(FC));
218+
auto CB = static_cast<FullComment*>(ConvertCommentBlock(FC, c.get()));
276219
RawComment->fullCommentBlock = CB;
277220
}
278221
}

src/CppParser/Link.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ bool Parser::LinkWindows(const CppLinkerOptions* LinkerOptions,
7070
}
7171

7272
const Triple& Triple = c->getTarget().getTriple();
73-
driver::Driver D("", Triple.str(), c->getDiagnostics());
73+
clang::driver::Driver D("", Triple.str(), c->getDiagnostics());
7474
opt::InputArgList Args(0, 0);
75-
driver::toolchains::MSVCToolChain TC(D, Triple, Args);
75+
clang::driver::toolchains::MSVCToolChain TC(D, Triple, Args);
7676

7777
std::vector<std::string> LibraryPaths;
7878
LibraryPaths.push_back("-libpath:" + TC.getSubDirectoryPath(

0 commit comments

Comments
 (0)