This is an archive of the discontinued LLVM Phabricator instance.

[clang] Set the error-bit for ill-formed semantic InitListExpr.
ClosedPublic

Authored by hokein on Jul 20 2020, 12:53 AM.

Details

Summary

When a semantic checking fails on a syntactic InitListExpr, we will
get an ill-formed semantic InitListExpr (e.g. some inits are nullptr),
using this semantic InitListExpr in clang (without setting the err-bits) is crashy.

Diff Detail

Event Timeline

hokein created this revision.Jul 20 2020, 12:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2020, 12:53 AM
sammccall accepted this revision.Jul 20 2020, 1:02 AM
sammccall added inline comments.
clang/lib/Sema/SemaInit.cpp
965

Can we have a clang test for this? If nothing else, an AST-dump test should be able to capture this, right?

If we can turn it into a real clang crash, we may be able to get this on the release branch.

This revision is now accepted and ready to land.Jul 20 2020, 1:02 AM
sammccall added inline comments.Jul 20 2020, 1:03 AM
clang/include/clang/AST/Expr.h
4697

Hmm, actually hardcoding the error->VI relationship seems like a smell here...
I'm not sure what the best fix is though, any ideas?

hokein marked 2 inline comments as done.Jul 20 2020, 1:18 AM
hokein added inline comments.
clang/include/clang/AST/Expr.h
4697

yeah, this is duplicated with the one in computeDependence(RecoveryExpr).

ideas:

  1. making this markError public method in Expr and use it computeDependence, so that we have a single place.
  2. add an alias ErrorDependent = Error | ValueInstantiation in the enum ExprDependence

any preference? personally, I'd prefer 2.

clang/lib/Sema/SemaInit.cpp
965

I tried it, but no luck to get such testcase :(

ast-dump doesn't really help, it just dumps the syntactic form, not the semantic form.

another option will be to write an unittest in AST, implementing a RAV to retrieve the semantic form of the ini-list-expr, and check the error-bit.

hokein updated this revision to Diff 279227.Jul 20 2020, 6:41 AM

add "ErrorDependent" alias to ExprDependence enum.

This revision was automatically updated to reflect the committed changes.