[PATCH] D14148: [GlobalOpt] Demote globals to locals more aggressively

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 28 11:06:58 PDT 2015


On Wed, Oct 28, 2015 at 10:51 AM, Duncan P. N. Exon Smith <
dexonsmith at apple.com> wrote:

>
> > On 2015-Oct-28, at 08:59, David Majnemer <david.majnemer at gmail.com>
> wrote:
> >
> > majnemer added inline comments.
> >
> > ================
> > Comment at: lib/Transforms/IPO/GlobalOpt.cpp:1747
> > @@ +1746,3 @@
> > +
> > +// main() is known not to be recursive and to only be called once.
> > +static bool isFunctionMain(const Function *F) {
> > ----------------
> > This is not true if the program is not a C++ program.  `main` can be
> recursively called in C.  Also, the name `main` may be reused for a
> function other than the entry point if it is not a hosted program which
> would be important to LTO something like the Linux kernel.
> >
> > At the very least, we should check the functions prototype.
>
> Note that this "main" shortcut isn't new; that check has been around
> for quite some time.
>

If LLVM's stance is that it believes main cannot be called from within the
program, then we should make clang's -Wmain diagnose calls to main in C
language mode.  This would do nothing to help us in free-standing mode
though.

It isn't terribly hard for us to fix it the right way.  I would recommend
that we have some sort of entry-point attribute which clang would stick on
main if we are in C mode and -ffreestanding has not been specified.


>
> > ================
> > Comment at: lib/Transforms/IPO/GlobalOpt.cpp:1786
> > @@ +1785,3 @@
> > +    // FIXME: Deal with constantexpr bitcasts?
> > +    Instruction *I = dyn_cast<Instruction>(U);
> > +    if (!I)
> > ----------------
> > `auto *I`
> >
> > ================
> > Comment at: lib/Transforms/IPO/GlobalOpt.cpp:1803
> > @@ +1802,3 @@
> > +      for (auto *UU : I->users()) {
> > +        LoadInst *LI = dyn_cast<LoadInst>(UU);
> > +        if (!LI)
> > ----------------
> > `auto *LI`
> >
> >
> > Repository:
> >  rL LLVM
> >
> > http://reviews.llvm.org/D14148
> >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151028/ffb49f6b/attachment.html>


More information about the llvm-commits mailing list