This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Change to constructor homing debug info mode: skip constexpr constructed types
ClosedPublic

Authored by akhuang on Apr 3 2020, 2:11 PM.

Details

Summary

In constructor type homing mode sometimes complete debug info for constexpr
types was missing, because there was not a constructor emitted. This change
makes constructor type homing ignore constexpr types.

Diff Detail

Event Timeline

akhuang created this revision.Apr 3 2020, 2:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2020, 2:11 PM
rnk added inline comments.Apr 3 2020, 3:55 PM
clang/lib/CodeGen/CGDebugInfo.cpp
2264–2266

I'm not sure isLiteral is quite the right check. I think there are some ways to:

  • have a type that is not literal
  • construct it at compile time with the constexpr constructor
  • skip object destruction

I came up with this example:

struct ConstexprCtor {
  constexpr ConstexprCtor(int a, int b) : a(a + 1), b(b + 1) {}
  ~ConstexprCtor();
  int a, b;
};

[[clang::no_destroy]] ConstexprCtor static_gv{1, 2};

I tried to find other ways to construct a class in a constexpr context without running the destructor, but wasn't able to.

It would also be interesting to know if StringRef and ArrayRef are literal or not. Those seem like types that we would want to apply this optimization to, and they have constexpr constructors. Maybe we can find a way to apply the optimization by figuring out if a constexpr constructor has been evaluated. You could look at who calls Sema::MarkFunctionReferenced and see if there are any callbacks into the ASTConsumer around there.

This comment was removed by dblaikie.
dblaikie added inline comments.Apr 3 2020, 4:09 PM
clang/lib/CodeGen/CGDebugInfo.cpp
2264–2266

Was (well did, and then realized you'd covered it) going to say the same thing about "is literal type" probably being too narrow here. Testing for the presence of a non-copy/move ctor constexpr ctor I think would be the right test.

I'd say it'd be best to fix this broadly first, then in a separate patch/work try to find a way to get some types with constexpr ctors back in - as I think that's going to be extra tricky with optimizations, linkages, etc. Maybe not - but I think there's enough to discuss there that we shouldn't tie that discussion together with this correctness issue.

akhuang updated this revision to Diff 254942.Apr 3 2020, 4:24 PM

Change check to hasConstexprNonCopyMoveConstructor()

akhuang retitled this revision from [DebugInfo] Change to constructor homing debug info mode: skip literal types to [DebugInfo] Change to constructor homing debug info mode: skip constexpr constructed types.Apr 3 2020, 4:27 PM
akhuang marked an inline comment as done.Apr 3 2020, 4:45 PM
akhuang added inline comments.
clang/lib/CodeGen/CGDebugInfo.cpp
2264–2266

Sounds good! And yeah, I sort of started looking into how to not ignore all constexpr ctor types, makes sense to put it in a separate patch.

rnk accepted this revision.Apr 3 2020, 4:54 PM

Sounds good to me, lgtm

This revision is now accepted and ready to land.Apr 3 2020, 4:54 PM
This revision was automatically updated to reflect the committed changes.