This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Avoid global constructor in LLDBLog.cpp
AbandonedPublic

Authored by JDevlieghere on Mar 7 2022, 1:53 PM.

Details

Reviewers
labath
Summary

Avoid a static initializer for Log::Channel in LLDBLog.cpp

Diff Detail

Event Timeline

JDevlieghere created this revision.Mar 7 2022, 1:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2022, 1:53 PM
JDevlieghere requested review of this revision.Mar 7 2022, 1:53 PM

The class has a constexpr constructor. I thought that would be enough to avoid runtime initialization. Is this being flagged by something?

The class has a constexpr constructor. I thought that would be enough to avoid runtime initialization. Is this being flagged by something?

It is getting flagged by -Wglobal-constructor but you're right, it's constexpr and therefore shouldn't. Might be a bug in clang. I'll try to repro with ToT.

shafik added a subscriber: shafik.Mar 8 2022, 2:04 PM

The class has a constexpr constructor. I thought that would be enough to avoid runtime initialization. Is this being flagged by something?

It is getting flagged by -Wglobal-constructor but you're right, it's constexpr and therefore shouldn't. Might be a bug in clang. I'll try to repro with ToT.

I wonder if for ArrayRef the copy constructor does not look constexpr and so if you change it to constexpr static if it will be ill-formed, that would mean it is not really constant initialization and therefore that would make it dynamic since it also not static initialization since you are calling a constructor.

labath added a comment.Mar 9 2022, 4:13 AM

Amusingly enough, the problem is the custom operator| used for bitmask enums. D121281 ought to fix that (by making the function constexpr).

JDevlieghere abandoned this revision.Mar 9 2022, 9:31 AM

Amusingly enough, the problem is the custom operator| used for bitmask enums. D121281 ought to fix that (by making the function constexpr).

Great, thanks!