Skip to content

Validation for AtomicRMW and cmpxchg#1092

Merged
dschuff merged 8 commits intomasterfrom
valid_atomic_rmw
Jul 15, 2017
Merged

Validation for AtomicRMW and cmpxchg#1092
dschuff merged 8 commits intomasterfrom
valid_atomic_rmw

Conversation

@dschuff
Copy link
Member

@dschuff dschuff commented Jul 13, 2017

Also fix cases where fail() had the arguments backwards. Wasn't an error because lol templates.
Also fix printModuleComponent template to SFINAE on Expression* so we properly get the specialized version.

@dschuff dschuff mentioned this pull request Jul 13, 2017

// Print anything that can be streamed to an ostream
template <typename T>
template <typename T,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the indentation change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason, just leftover from a previous edit. de-intented.

template <typename T>
template <typename T,
typename std::enable_if<
!std::is_base_of<Expression, typename std::remove_pointer<T>::type>::value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is starting to feel rather complicated. perhaps we should rethink the printing code?

e.g. in llvm I believe they support printing of objects, not pointers, which maybe makes things simpler (so you need to do cerr << *x instead of just x etc.).?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like that idea, but in this case I think it wouldn't change much; it would just remove the need for the remove_ptr bit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'm hoping with a larger refactoring we could remove the need for all of this printing code. Perhaps we can leave it for another PR. But iiuc, the issue here is to pass the option of printing the types, then we could have an API like this:

std::cerr << FullTypePrinter(expr)

which would print it with the full type. And so we could end up with just cerr << [..] for everything, and without these new templates and function calls?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with something like that you'd have the same problem, i.e. you want it to be transparent to the caller (e.g. a template like fail) whether you are dealing with an expr (in which case you want to wrap it with FullTypePrinter) or not (in which case you don't). So IIUC to do that you'd have to specialize/overload/templatize FullTypePrinter similarly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do the wrapping in the calls to fail but yeah, maybe that's no better.

switch (curr->type) {
case i32:
case i64:
case unreachable:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other code uses {, } when body is on another line, also in switch cases. How about just putting it on the same line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like case i32: case i64: case unreachable: break;?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest

case i32:
case i64:
case unreachable: break;

or

case i32:
case i64:
case unreachable: {
  break;
}

since both appear elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like option A, so I'll do B

validateMemBytes(curr->bytes, curr->type, curr);
shouldBeEqualOrFirstIsUnreachable(curr->ptr->type, i32, curr, "AtomicRMW pointer type must be i32");
shouldBeEqualOrFirstIsUnreachable(curr->value->type, curr->type, curr, "AtomicRMW result type must match operand");
switch (curr->type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: helper function? bool isTypeIntOrUnreachable(WasmType t)? The switch/default/fail is just odd enough to be not totally obvious.
Or bool shouldBeIntegerOrUnreachable(WasmType, Expression*, const char*) to match the shouldBeEquals

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dschuff dschuff merged commit 8b97aba into master Jul 15, 2017
@dschuff dschuff deleted the valid_atomic_rmw branch September 6, 2017 17:12
@dschuff dschuff mentioned this pull request Sep 7, 2018
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants