[cfe-dev] On preserving unused file-local definitions at -O0

Eric Christopher echristo at gmail.com
Fri Apr 11 16:28:12 PDT 2014


On Fri, Apr 11, 2014 at 8:59 AM, David Blaikie <dblaikie at gmail.com> wrote:
> Clang fails a bunch of the GDB testsuite because clang optimizes* away
> file-local (namespace scope static) functions and variables at -O0.
>
> I sent a patch to the GDB mailing list to 'fix' these tests by using
> non-static functions/variables, or marking them used with
> __attribute__((used)). While there's precedent for both, I've had one
> reply pushing back a little that Clang should change behavior here and
> produce code for these unused definitions.
>
> Before I go back to the GDB mailing list and say that Clang will not
> change its behavior here, I figured I'd just put it out there and ask.
> If it comes to it I can file a bug, resolve it as "won't fix"/"by
> design"/"invalid", and then mark these GDB tests as KFAIL against that
> bug if the two communities can't come to an agreement about the
> correct behavior here.
>
> It's only been hours since I posted to GDB so the opinion expressed
> isn't the only one or necessarily the will of the GDB community, but I
> wanted to cover all my bases by having the conversation here too
> before I go representing the Clang community opinion over there.
>

Mostly this is what __attribute__((used)) is to be used for, anything
else is just relying on iffy behavior. That said, the attribute is a
compiler specific workaround to say "please keep this dead code" and
most compilers will have something similar - I don't think the
debugger should be relying upon it for tests. :p

-eric

> For myself I think there's some merit to this and realize there's
> continuous tension between -O0 used for debugging ("don't make my code
> hard to debug") and -O0 used for JIT or similar situations ("give me
> code as quickly as possible"). At some point these things may need to
> be split (-Og or some other approach) I would guess, though so long as
> Clang's -O0 leans towards "give me code quickly" we'll need to do
> something about the GDB tests that assume -O0 for debugging fidelity.
>
> * it's a very cheap optimization - in the sense that we just don't do
> any IRGen for them because we see they're unreferenced



More information about the cfe-dev mailing list