This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Fix ignoring expression return values
ClosedPublic

Authored by tbaeder on Oct 15 2022, 12:58 AM.

Details

Summary

Randomly noticed this. We need to honor DiscardResult here.

Diff Detail

Event Timeline

tbaeder created this revision.Oct 15 2022, 12:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 15 2022, 12:58 AM
tbaeder requested review of this revision.Oct 15 2022, 12:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 15 2022, 12:58 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tbaeder updated this revision to Diff 468001.Oct 15 2022, 2:57 AM
tbaeder retitled this revision from [clang][Interp] Fix ignoring unary operators and This exprs to [clang][Interp] Fix ignoring expression return values.
tbaeder updated this revision to Diff 468006.Oct 15 2022, 3:55 AM
aaron.ballman added inline comments.Oct 18 2022, 6:16 AM
clang/test/AST/Interp/records.cpp
208

Hmmm, this feels related to the discarded value results changes, but it might be a test case for a different scenario as well, so take this or leave it:

struct S {
  int &Ref;
  constexpr S(int &R) : Ref(R) { Ref = 0; }
  constexpr ~S() { Ref = 12; }
};

constexpr S get_s(int &i) { return S{i}; }

constexpr int func() {
  int i = 1;
  {
    get_s(i);
  }
  return i;
}

static_assert(func() == 12);

The idea behind the test is -- we construct the S object but discard its results in the compound block, but the dtor still runs as expected.

tbaeder added inline comments.Oct 18 2022, 11:47 PM
clang/test/AST/Interp/records.cpp
208

I think this would trigger the TODO I added, since this is a RVO function but we have nowhere to write the return value.

This revision is now accepted and ready to land.Oct 20 2022, 8:20 AM
This revision was landed with ongoing or failed builds.Oct 28 2022, 7:51 AM
This revision was automatically updated to reflect the committed changes.