This is an archive of the discontinued LLVM Phabricator instance.

SemaDeclCXX.cpp: Make -Wglobal-constructors more forgiving.
AbandonedPublic

Authored by ygribov on Jan 22 2015, 1:38 AM.

Details

Summary

This patch liberalizes -Wglobal-constructors to not emit warning if constructor is likely to be optimized away. This covers important LinkerInitialized idiom used e.g. in libsanitizer and Chromium:

enum LinkerInitialized { LINKER_INITIALIZED };
class Mutex {
public:
  inline Mutex(base::LinkerInitialized) {}
};
Mutex mu(LINKER_INITIALIZED);  // Will be optimized away

No regressions in check-all.

Diff Detail

Event Timeline

ygribov updated this revision to Diff 18596.Jan 22 2015, 1:38 AM
ygribov retitled this revision from to SemaDeclCXX.cpp: Make -Wglobal-constructors more forgiving..
ygribov updated this object.
ygribov edited the test plan for this revision. (Show Details)
ygribov added reviewers: rsmith, eli.friedman.
ygribov added a subscriber: Unknown Object (MLST).
thakis added a subscriber: thakis.Jan 22 2015, 8:38 AM

You can't know that all compilers will optimize this away, can you?

You can't know that all compilers will optimize this away, can you?

Sure, even Clang won't optimize this at -O0. Basically this patch weakens the check to make a common programming idiom warning-free.

ygribov added a subscriber: kcc.Jan 22 2015, 10:47 PM

As pointed out by David Blaikie in cfe-commits, this can be fixed in user code via constexpr so patch is probably not very important.

ygribov abandoned this revision.Jan 27 2015, 12:08 AM