<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 18, 2015 at 8:28 AM, Martin J. O'Riordan <span dir="ltr"><<a href="mailto:martin.oriordan@movidius.com" target="_blank">martin.oriordan@movidius.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-IE" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">Let’s say for example I have:<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">#include <stddef.h><u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">#include “myfile.h”<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">int main() {<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">  foo(NULL);<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">}<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">and “</span><span style="font-family:"Courier New";color:black">myfile.h</span><span style="font-family:"Book Antiqua",serif;color:#943634">” has:<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">extern void foo(); // Tentative declaration<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">When fully pre-processed this will have ‘</span><span style="font-family:"Courier New";color:black"><stddef.h></span><span style="font-family:"Book Antiqua",serif;color:#943634">’ and “</span><span style="font-family:"Courier New";color:black">myfile.h</span><span style="font-family:"Book Antiqua",serif;color:#943634">” fully expanded.  If in the case my definition of </span><span style="font-family:"Courier New";color:black">NULL</span><span style="font-family:"Book Antiqua",serif;color:#943634"> is just ‘</span><span style="font-family:"Courier New";color:black">0</span><span style="font-family:"Book Antiqua",serif;color:#943634">’, then this becomes:<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "myfile.c"<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "<built-in>" 1<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "<built-in>" 3<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 306 "<built-in>" 3<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "<command line>" 1<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "<built-in>" 2<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "myfile.c" 2<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "<<i>path-to-stdinc</i>>/stddef.h" 1 3 4<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 51 "<<i>path-to-stdinc</i>>/stddef.h" 3 4<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">typedef int ptrdiff_t;<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 62 "<<i>path-to-stdinc</i>>/stddef.h" 3 4<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">typedef unsigned int size_t;<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 90 "<<i>path-to-stdinc</i>>/stddef.h" 3 4<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">typedef unsigned char wchar_t;<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 118 "<<i>path-to-stdinc</i>>/stddef.h" 3 4<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "<<i>path-to-stdinc</i>>/__stddef_max_align_t.h" 1 3 4<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 35 "<<i>path-to-stdinc</i>>/__stddef_max_align_t.h" 3 4<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">typedef struct {<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">  long long __clang_max_align_nonce1<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">      __attribute__((__aligned__(__alignof__(long long))));<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">  long double __clang_max_align_nonce2<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">      __attribute__((__aligned__(__alignof__(long double))));<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">} max_align_t;<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 119 "<<i>path-to-stdinc</i>>/stddef.h" 2 3 4<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "myfile.c" 2<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "./myfile.h" 1<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">extern void foo();<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 2 "myfile.c" 2<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">int main() {<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">  foo(0);<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">}</span><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">But what I would really like is something like:<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "myfile.c"<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "<built-in>" 1<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "<built-in>" 3<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 306 "<built-in>" 3<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "<command line>" 1<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "<built-in>" 2<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "myfile.c" 2<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black;background:yellow">#include <stddef.h></span><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "myfile.c" 2<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 1 "./myfile.h" 1<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">extern void foo();<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"># 2 "myfile.c" 2<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">int main() {<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">  foo(<span style="background:yellow">NULL</span>);<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">}</span><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">The example is contrived, but assume that ‘</span><span style="font-family:"Courier New";color:black">int</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ is 32-bit, ‘</span><span style="font-family:"Courier New";color:black">void*</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ is 64-bit and the actual definition of ‘</span><span style="font-family:"Courier New";color:black">void foo()</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ takes a pointer argument, then the original code in ‘</span><span style="font-family:"Courier New";color:black"><stddef.h></span><span style="font-family:"Book Antiqua",serif;color:#943634">’ is wrong, and while debugging I realise “hey, I should have defined</span><span style="font-family:"Courier New";color:black"> NULL </span><span style="font-family:"Book Antiqua",serif;color:#943634">to be ‘</span><span style="font-family:"Courier New";color:black">((void*)0)</span><span style="font-family:"Book Antiqua",serif;color:#943634">’”.  If my test-case contained all of the user code pre-processed but not the system includes, then I can quickly evaluate the fix.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">This is a really trivialised example, in practice bug reports are usually much larger.  And this example assumes I have a bug in the definition of </span><span style="font-family:"Courier New";color:black">NULL</span><span style="font-family:"Book Antiqua",serif;color:#943634">, which is unlikely, but in the real-world I may be updating the set of headers for the system includes from one version to a newer version, or I might have decided that I would prefer to distribute ‘</span><span style="font-family:"Courier New";color:black">uClibc</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ headers instead of ‘</span><span style="font-family:"Courier New";color:black">newlib</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ headers, but I want to keep my test cases valid in the context of the revised system header files. <u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">Having an option to allow this kind of partial pre-processing could be very useful.  I can write scripts which can collapse the expanded header back into the ‘</span><span style="font-family:"Courier New";color:black">#include <stddef.h></span><span style="font-family:"Book Antiqua",serif;color:#943634">’ from the normal pre-processed file, but I can’t undo the expansion of the macros it contains such as </span><span style="font-family:"Courier New";color:black">NULL</span><span style="font-family:"Book Antiqua",serif;color:#943634"> in this case.  I could also write an external tool to do this, but it would be hard to ensure that it accurately mimics the search paths for CLang and there is plenty of opportunity for error and divergence over time.  And integrated option would not have this problem.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">I’m not proposing the addition of such an option, but was curious if CLang already had such a feature that I had missed when browsing the huge number of options, especially since some options have no help text associated with them and are invisible to either ‘</span><span style="font-family:"Courier New";color:black">--help</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ or ‘</span><span style="font-family:"Courier New";color:black">--help-hidden</span><span style="font-family:"Book Antiqua",serif;color:#943634">’.</span></p></div></div></blockquote><div><br></div><div>Right - we don't. I don't think we'd object to having one, we just haven't had a need for one so no one's done the work.<br><br>- Dave</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-IE" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u><u></u></span></p><span class=""><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">Thanks,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">            MartinO - Movidius Ltd.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634"><u></u> <u></u></span></p></span><p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> David Blaikie [mailto:<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>] <br><b>Sent:</b> 18 November 2015 15:49<br><b>To:</b> Martin J. O'Riordan <<a href="mailto:martin.oriordan@movidius.com" target="_blank">martin.oriordan@movidius.com</a>><br><b>Cc:</b> Clang Dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>><br><b>Subject:</b> Re: [cfe-dev] Partial Pre-processing Question<u></u><u></u></span></p><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">On Wed, Nov 18, 2015 at 6:48 AM, Martin J. O'Riordan via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif">I am wondering if there is some hidden option or mechanism in CLang that I can use to pre-process like ‘</span><span style="font-family:"Courier New"">-E</span><span style="font-family:"Book Antiqua",serif">’ or ‘</span><span style="font-family:"Courier New"">-frewrite-includes</span><span style="font-family:"Book Antiqua",serif">’, but which does not expand the headers from the system include directories?</span><u></u><u></u></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif">There are often times when I would like this type of capability, so that I can create test-cases for reported bug, but have them remain valid with future revisions of the compiler and its supporting headers and libraries.  It is not uncommon for a new version of a system header (ISO C, ISO C++, or our own extended headers) to have changes that are not 100% compatible with the results of the expanded result of an older version.</span><u></u><u></u></p></div></div></blockquote><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">I'm not quite following what you've said here /\ - if the test case has fully preprocessed code then it won't have any system headers to conflict with updated system headers, no? It'll be standalone. I've certainly found these sort of test cases to be fairly robust - but I usually do the reduction (as Yaron was mentioning) up-front, so I may not've run into the situations you're describing. Given how much the compiler has to be robust to user code backwards compatibility, I'd be surprised it it's often the case that a system header used a feature that the compiler soon became incapable of processing.<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif">The headers belonging to the programmer and their source need to be expanded, but I would like to retain the unexpanded system headers, and in particular not expand the macros defined in a system header, and leave the system headers as ‘</span><span style="font-family:"Courier New"">#include <<i>sysheadername</i>></span><span style="font-family:"Book Antiqua",serif">’.</span><u></u><u></u></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif">Thanks,</span><u></u><u></u></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif">            MartinO - Movidius Ltd.</span><u></u><u></u></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif"> </span><u></u><u></u></p></div></div><p class="MsoNormal" style="margin-bottom:12.0pt"><br>_______________________________________________<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><u></u><u></u></p></blockquote></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div></div></blockquote></div><br></div></div>