<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><b>From:</b> cfe-dev [mailto:cfe-dev-bounces@lists.llvm.org]
<b>On Behalf Of </b>Manuel Klimek via cfe-dev<br>
<b>Sent:</b> Wednesday, April 18, 2018 6:26 AM<br>
<b>To:</b> Milian Wolff <mail@milianw.de><br>
<b>Cc:</b> Clang Dev <cfe-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [cfe-dev] clangd/libclang: how to emulate other compilers?<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">On Tue, Apr 17, 2018 at 8:02 PM Milian Wolff via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal" style="margin-left:.5in">Hey all,<br>
<br>
how does clangd or other users of the libclang handle situations where you <br>
want to parse code that is dependent on a certain other compiler or compiler <br>
environment? The most common scenario being embedded projects that rely on the <br>
compiler-builtin defines and include paths to find the sysroot include paths <br>
and such.<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">I'm not sure I understand what you mean - do you mean the compiler has builtins that clang doesn't provide and relies on their existence?<o:p></o:p></p>
<p class="MsoNormal">Yes.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Generally, you'll want to use the builtin defines and includes from clang (at the point at which you compiled libclang), but the standard library and so forth that the system is using. Clang should be able to find
 that given the right flags.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Well, no. The plan for a lot of us is to use clangd with projects that use gcc as the compiler. We need to be able to reach out to gcc to ask it what the built-ins are. We’ll then need to convince clang to parse in the same manner. Given
 all the variants of compilers that we need to be able to support in our various IDE’s, it’s already something we’ve gotten quite use to.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal" style="margin-left:.5in">For KDevelop, which is using libclang, we have tried to build a sort of
<br>
emulation layer that originally yielded good results. The approach is as <br>
followed:<br>
<br>
1) We use the actual compiler that is used to compile a given project, e.g. <br>
gcc, arm-none-eabi-gcc, ...<br>
<br>
2) We take this compiler and query it for its builtin defines:<br>
/usr/bin/gcc -xc++ -std=c++11 -dM -E - < /dev/null<br>
<br>
3) And also query the include paths:<br>
/usr/bin/gcc -xc++ -std=c++11 -v -E - < /dev/null<br>
<br>
4) Then for the libclang calls to clang_parseTranslationUnit2 we pass `-<br>
nostdinc -nostdinc++` followed by the defines and includes we got from 2) and <br>
3).<br>
<br>
Now, for simply things this actually worked quite well. But once you include a <br>
file that heavily relies on the compiler, such as all the SIMD intrinsic <br>
headers, you are easily drowning in parse errors. And once you have too many <br>
parse errors, clang will just give up. We have tried to workaround this via <br>
compatibility headers such as [1], but it keeps breaking.<br>
<br>
More recently, we now also got bug reports where the user system has clang3 <br>
and they use that to to compile the code, but then download a KDevelop <br>
AppImage built against libclang v5 (e.g. via AppImage). Once again this easily <br>
yields tons of parse errors when encountering system headers that are using <br>
intrinsics specific to clang v3.<br>
<br>
I am now thinking about removing the emulation layer described above. But then <br>
it will be essentially impossible to work on a lot of embedded projects which <br>
rely on the cross compiler defines and include paths...<br>
<br>
So, once again - how do other users of libclang handle this scenario? What is <br>
the plan for clangd in this regard?<br>
<br>
Thanks<br>
-- <br>
Milian Wolff<br>
<a href="mailto:mail@milianw.de" target="_blank">mail@milianw.de</a><br>
<a href="http://milianw.de" target="_blank">http://milianw.de</a>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</body>
</html>