<div dir="ltr"><div>I'd imagine you can tweak clang's CodeGen to add a Metadata node to all `llvm::Function`s clang emits that basically says whether or not the code appeared in a system header. SourceManager::isInSystemHeader should help you figure out what's where. You'll probably need special handling for generated code, like `__cxx_global_var_init`</div><div><br></div><div>I offer no guarantees about the LLVM community accepting this patch, though :)</div><div><br></div><div>To Mehdi's point, inlining can make things materially more difficult.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 5, 2020 at 10:16 AM Jacob Carlborg via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2020-02-04 17:24, Sunil via llvm-dev wrote:<br>
> Say, I have the following program:<br>
> <br>
>     #include <iostream><br>
>     int main(){<br>
>       std::cout << "hello\n";<br>
>       return 0;<br>
>     }<br>
> <br>
> After generating llvm bitcode using the following command:<br>
>        $ clang++ -c -emit-llvm -O -Xclang -disable-llvm-passes a.cpp<br>
> the bitcode has the following function with define.<br>
> __cxx_global_var_init<br>
>     main<br>
>     _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc<br>
> _ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate<br>
>     _ZNSt11char_traitsIcE6lengthEPKc<br>
>     _ZStorSt12_Ios_IostateS_<br>
>     _ZNKSt9basic_iosIcSt11char_traitsIcEE7rdstateEv<br>
>     _GLOBAL__sub_I_a.cpp<br>
> <br>
> In a pass, I want to know what are the functions defined by the user e.g <br>
> 'main' and what are not e.g. other than 'main'.<br>
<br>
Perhaps you can check where a function is defined and treat all <br>
functions defined in a file passed to the compiler as user defined and <br>
all other as system defined. Not sure if that's good enough for you.<br>
<br>
-- <br>
/Jacob Carlborg<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>