Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning fixes. #885

Merged
merged 1 commit into from
Feb 16, 2016
Merged

Conversation

robertsipka
Copy link
Contributor

ISO C99 doesn’t support unnamed structs/unions.
Comparison of distinct pointer types lacks a cast.
Dereferencing type-punned pointer will break strict-aliasing rules.

There is still a warning with gcc-4.8.4. (it's supported with gcc 4.9.2.):
type of bit-field ‘ext’ is a GCC extension
In C99, gcc issues a warning with -pedantic but it is permitted to have an implementation defined type for the bit-field.

@@ -75,7 +75,8 @@ vm_stack_context_abort (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
ecma_collection_chunk_t *chunk_p = MEM_CP_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
current);

ecma_free_value (*(ecma_value_t *) chunk_p->data, true);
lit_utf8_byte_t *data_ptr = chunk_p->data;
Copy link
Member

Choose a reason for hiding this comment

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

Is the introduction of this temporary variable really needed? Cannot the expression be kept in one line as before? (2 more similar constructs below.)

Copy link
Member

Choose a reason for hiding this comment

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

Good point.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is an alignment problem, perhaps a double casting could help:

ecma_free_value (*(ecma_value_t *) (void *) chunk_p->data, true);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The chaining type casts doesn't help. The following warning: 'dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]' is still persist in this cases.

@robertsipka
Copy link
Contributor Author

In this case accessing data at 'chunk_p->data' through a pointer to a different type leads the following error: 'Dereferencing type-punned pointer will break strict-aliasing rules'.
The crucial difference is that I store the real data in a variable of the correct type, and only after having allocated that variable what I treat as an ecma_value_t, which is allowed.
Maybe it's not the best solution, but it is an exception to 'type punning'.

@LaszloLango
Copy link
Contributor

@robertsipka, please add -Werror=pedantic to the build to avoid these warnings in the future.

@LaszloLango LaszloLango added bug Undesired behaviour critical Raises security concerns labels Feb 16, 2016
@akosthekiss
Copy link
Member

@robertsipka does chaining type casts not help? Something like * (ecma_value_t *) ((lit_utf8_byte_t *) chunk_p->data)?

@robertsipka
Copy link
Contributor Author

Sadly, no. This solution would lead to the same error.

@akosthekiss
Copy link
Member

@robertsipka Too bad. But thanks for trying. Ok with me then.

@robertsipka
Copy link
Contributor Author

@LaszloLango: Yes, it would be correct way. The remained problem is with the error 'type of bit-field ‘base_cp’ is a GCC extension', as I mentioned in the first comment.
My possible solutions:
1, Use __ extension __ before every 'defined' type of bit-field ‘ext’.
2, Use #pragma GCC diagnostic ignored "-pedantic" before it, which is ugly, I think.

@robertsipka robertsipka force-pushed the warning_fixes branch 2 times, most recently from d471a74 to 2c376ba Compare February 16, 2016 10:30
@robertsipka
Copy link
Contributor Author

@LaszloLango: I've modified the patch, and rebased with master.

mem_cpointer_t getter_p : ECMA_POINTER_FIELD_WIDTH; /**< pointer to getter object */
mem_cpointer_t setter_p : ECMA_POINTER_FIELD_WIDTH; /**< pointer to setter object */
__extension__ mem_cpointer_t getter_p : ECMA_POINTER_FIELD_WIDTH; /**< pointer to getter object */
__extension__ mem_cpointer_t setter_p : ECMA_POINTER_FIELD_WIDTH; /**< pointer to setter object */
Copy link
Member

Choose a reason for hiding this comment

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

Is this working on other compilers not just GCC? On the long run perhaps an unsigned int will also do.

Copy link
Member

Choose a reason for hiding this comment

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

The following could work somewhere in jrt.h where the attributes are defined.

#ifndef __GNUC__
#define __extension__
#endif

But do note that right now we have no compiler specific ifdefs in the core code base.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks good to me, thanks, I'll define this __ extension __.

@LaszloLango
Copy link
Contributor

@robertsipka, thanks. Good to me, but let's wait the review of @zherczeg

ISO C99 doesn’t support unnamed structs/unions.
Comparison of distinct pointer types lacks a cast.
Dereferencing type-punned pointer will break strict-aliasing rules.
Type of bit-field ‘ext’ is a GCC extension.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka [email protected]
@robertsipka
Copy link
Contributor Author

Thanks for the comments, I've updated the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Undesired behaviour critical Raises security concerns
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants