[cfe-dev] Calling main() is ub based optimizations

Mehdi Amini via cfe-dev cfe-dev at lists.llvm.org
Sat Nov 12 10:09:48 PST 2016


main is marked as “norecurse” in C++ and not in C:

$ echo "int main() {}" | clang -x c - -emit-llvm -o - -S | grep recurse
$ echo "int main() {}" | clang -x c++ - -emit-llvm -o - -S | grep recurse
; Function Attrs: norecurse nounwind ssp uwtable
attributes #0 = { norecurse nounwind ssp uwtable ...

— 
Mehdi

> On Nov 12, 2016, at 1:58 AM, Piotr Padlewski via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hey,
> I have question. Does clang take advantage of the fact that calling main or taking address of main function in C++ is undefined behavior?
> I've heard that some compilers do so and AFAIRC I've heard that it was important to some benchmarks.
> I guess compiler can assume the values of globals after calling main, because it knows that it is the first function called after initializing them.
> 
> Is there any optimization that do this in clang?
> 
> Piotr
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list