This is an archive of the discontinued LLVM Phabricator instance.

[WIP][AST] NFC: Introduce new class GenericSelectionExpr::Association
AbandonedPublic

Authored by riccibruno on Jan 23 2019, 6:15 AM.

Details

Summary

Introduce GenericSelectionExpr::Association which wraps an association
expression and its TypeSourceInfo. Add the boilerplate necessary to use
ranges of Associations.

Additionally pack GenericSelectionExpr by tail-allocating the array of
selection expressions and TypeSourceInfo.

Note that this is just a draft following D56959.

Diff Detail

Repository
rC Clang

Event Timeline

riccibruno created this revision.Jan 23 2019, 6:15 AM

This is looking great! I've got some comments, mostly nits. Just to double-check, have you verified that these changes do not break any existing tests (in clang or clang-tools-extra)?

include/clang/AST/Expr.h
5026

~0U instead of -1u so it doesn't suggest a weird type mismatch?

5030

parenthese -> parenthesis

5034

They are (in order):

5039

expression -> expressions

5043

I think it would be good to put a comment here like "Add one to account for the controlling expression; the remainder are the associated expressions."

5094

It seems like this should be pretty trivial to make into a random access iterator, or am I missing something?

5097

Cute, but I suspect this may come back to bite us at some point. For instance, if someone thinks they're working with a real pointer, they're likely to expect pointer arithmetic to work when it won't (at least they'll get compile errors though).

5101

This should return reference instead.

5104

This should return pointer instead.

5106–5108

Use ++Foo for each of these?

5186

std::numeric_limits<unsigned>::max()?

5208

Do we need to use reinterpret_cast here, or can this be done through llvm's casting machinery instead?

5219

Spurious parens can be removed.

lib/AST/Expr.cpp
3791

Spurious parens.

3794

Spurious parens.

3816

Spurious parens.

lib/Sema/SemaExprObjC.cpp
4339

This should probably be spelled assoc to be consistent with the surrounding code.

lib/Sema/SemaPseudoObject.cpp
148

Probably have to go with assoc here.

149

This should be renamed regardless; probably assocExpr

lib/Serialization/ASTReaderStmt.cpp
1027

Spurious parens.

1040

Spurious semi-colon.

steveire added a comment.EditedJan 23 2019, 7:31 AM

Thanks for doing this!

It would be easier to review (now and in the future!) if you split it into at least 3 commits

  • Refactor use trailing objects without introducing the Association class
  • The change to use bitfields and Stmt.h
  • Introduce new class GenericSelectionExpr::Association

Thanks,

Stephen

riccibruno marked 13 inline comments as done.Jan 23 2019, 7:42 AM

This is looking great! I've got some comments, mostly nits. Just to double-check, have you verified that these changes do not break any existing tests (in clang or clang-tools-extra)?

I ran the usual assert build/asan+assert build/msan+assert build.
To be clear I know that there are some changes required but I just wanted to put it out here to get
some feedback on the basic idea (which is to use some kind of proxy iterator).

Some added comments inline.

include/clang/AST/Expr.h
5026

Yes indeed (or std::numeric_limits<unsigned>::max() as suggested below).

5043

Will do.

5094

Indeed, at the cost of some boilerplate. I can totally do this but from what I understood the motivation was to use this in ranges, and for this a forward iterator is good enough (although see the next comment)

5097

Hmm, but pointer is just the return type of operator-> no ? Is it actually required to behave like a pointer ? The only requirement I can find is that It->x must be equivalent to (*It).x, which is true here.

Also looking at the requirements for forward iterators I think that this iterator should actually be downgraded to an input iterator, because of the requirement that reference = T&.

5101

yes

5104

yes

5108

yes

5186

yes

5208

I believe that it is needed, because Stmt ** is not otherwise convertible to Expr **. This is all over the place in the statement/expression nodes, and indeed it depends on the layout of Expr and Stmt.

5219

From the precedence rules yes, but I thought that some gcc bots were
warning about this (or maybe I am mistaken and this is in an other situation)

lib/Sema/SemaPseudoObject.cpp
148

Will do.

149

Will do.

lib/Serialization/ASTReaderStmt.cpp
1040

Oups.

riccibruno marked an inline comment as done.Jan 23 2019, 7:51 AM
riccibruno added inline comments.
include/clang/AST/Expr.h
5208

Ugh ignore the comment about the layout. I was thinking about the reinterpret_casts between Stmt * and Expr * in Stmt.h

Thanks for doing this!

It would be easier to review (now and in the future!) if you split it into at least 3 commits

  • Refactor use trailing objects without introducing the Association class
  • The change to use bitfields and Stmt.h
  • Introduce new class GenericSelectionExpr::Association

Thanks,

Stephen

Is it okay if I split it into:

  1. llvm::TrailingObjects + bit-fields of Stmt
  2. Introduce GenericSelectionExpr::Association

since using llvm::TrailingObjects and using the bit-fields of Stmt are closely related
and come under the title "[AST] Pack GenericSelectionExpr".

Thanks for doing this!

It would be easier to review (now and in the future!) if you split it into at least 3 commits

  • Refactor use trailing objects without introducing the Association class
  • The change to use bitfields and Stmt.h
  • Introduce new class GenericSelectionExpr::Association

Thanks,

Stephen

Is it okay if I split it into:

  1. llvm::TrailingObjects + bit-fields of Stmt
  2. Introduce GenericSelectionExpr::Association

since using llvm::TrailingObjects and using the bit-fields of Stmt are closely related
and come under the title "[AST] Pack GenericSelectionExpr".

I didn't realize that, so your proposal sounds good to me!

riccibruno marked 18 inline comments as done.

Thanks for doing this!

It would be easier to review (now and in the future!) if you split it into at least 3 commits

  • Refactor use trailing objects without introducing the Association class
  • The change to use bitfields and Stmt.h
  • Introduce new class GenericSelectionExpr::Association

Thanks,

Stephen

Is it okay if I split it into:

  1. llvm::TrailingObjects + bit-fields of Stmt
  2. Introduce GenericSelectionExpr::Association

since using llvm::TrailingObjects and using the bit-fields of Stmt are closely related
and come under the title "[AST] Pack GenericSelectionExpr".

I didn't realize that, so your proposal sounds good to me!

Split into D57104 and D57106

riccibruno abandoned this revision.Jan 23 2019, 1:05 PM
riccibruno marked 2 inline comments as done.

Closed in favor of D57104 and D57106.