This is an archive of the discontinued LLVM Phabricator instance.

[clang] disable implicit moves when not in CPlusPLus
ClosedPublic

Authored by mizvekov on Sep 11 2021, 4:18 PM.

Details

Summary

See PR51842.

This fixes an assert firing in the static analyzer, triggered by implicit moves
in blocks in C mode:

This also simplifies the AST a little bit when compiling non C++ code,
as the xvalue implicit casts are not inserted.

We keep and test that the nrvo flag is still being set on the VarDecls,
as that is still a bit beneficial while not really making anything
more complicated.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Diff Detail

Event Timeline

mizvekov created this revision.Sep 11 2021, 4:18 PM
mizvekov published this revision for review.Sep 11 2021, 4:51 PM
mizvekov added a reviewer: NoQ.
Herald added a project: Restricted Project. · View Herald TranscriptSep 11 2021, 4:51 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
NoQ accepted this revision.Sep 13 2021, 12:36 PM

Thanks a lot!! This seems to take care of my issues.

Can you also include the following test case somewhere into, say, test/Analysis/blocks-nrvo.c? It crashes without this patch.

// RUN: %clang_analyze_cc1 -w -analyzer-checker=core -fblocks -verify %s

// expected-no-diagnostics

typedef struct {
  int x;
} S;

void foo() {
  ^{
    S s;
    return s; // no-crash
  };
}
This revision is now accepted and ready to land.Sep 13 2021, 12:36 PM
mizvekov updated this revision to Diff 372434.Sep 14 2021, 1:39 AM
mizvekov edited the summary of this revision. (Show Details)

include repro for analyzer crash.

This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Sep 15 2021, 2:03 PM

Is it possible that this disabled this for Objective-C++ too?

Is it possible that this disabled this for Objective-C++ too?

As far as I understand, CPlusPLus will be set on ObjectiveC++ as well, and I think we do have test coverage there, but I haven't personally manually tested this.
Do you see any indications this is a problem?

Yes, https://bugs.chromium.org/p/chromium/issues/detail?id=1250052 I haven't yet verified it's definitely due to this change, but it's the most related-looking change in the regression range.

Yes, https://bugs.chromium.org/p/chromium/issues/detail?id=1250052 I haven't yet verified it's definitely due to this change, but it's the most related-looking change in the regression range.

Okay, I assumed any regressions here would be covered by at least clang\test\SemaObjCXX\block-capture.mm, but it's possible the test invocation is wrong.
We definitely need to improve the test coverage for ObjC++ if we missed this otherwise :-(

I bet my issue is due to D108243 and not this change. Sorry for the noise!