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

David Blaikie dblaikie at gmail.com
Fri Apr 11 08:59:28 PDT 2014


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.

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