Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

clean up list of disabled warnings.#18318

Merged
sandreenko merged 7 commits into
dotnet:masterfrom
sandreenko:cleanWarningsList
Jun 15, 2018
Merged

clean up list of disabled warnings.#18318
sandreenko merged 7 commits into
dotnet:masterfrom
sandreenko:cleanWarningsList

Conversation

@sandreenko
Copy link
Copy Markdown

@sandreenko sandreenko commented Jun 5, 2018

contributes to #18128

Sergey Andreenko added 4 commits June 5, 2018 14:46
@sandreenko sandreenko force-pushed the cleanWarningsList branch 2 times, most recently from f3cac22 to 85b1478 Compare June 6, 2018 04:39
_ASSERTE(((INT32)(UINT32)n) >= 0);
_ASSERTE((base > 0) && (base < BITS_PER_SIZE_T));
size_t numEncodings = 1 << base;
size_t numEncodings = size_t{ 1 } << base;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The previous line checks that base is lower then BITS_PER_SIZE_T, on TARGET_64 it would be 64.
So then if 32 < base < 64 it would produce the wrong result in the old variant.

Comment thread src/vm/methodtablebuilder.cpp Outdated
DWORD j;

if (IS_ALIGNED(dwCumulativeInstanceFieldPos, 1<<(i+1)))
size_t alignment = size_t{ 1 } << i;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There is VS bug that keep showing this warning even when you have an explicit cast to size_t:
size_t alignment = static_cast<size_t>(1 << I); , the issue was reported.

but there is not harm to declare 1 as size_t.

@sandreenko
Copy link
Copy Markdown
Author

As usual please review per commit.

Sergey Andreenko added 2 commits June 6, 2018 10:31
@sandreenko sandreenko force-pushed the cleanWarningsList branch from 3f2dcfa to 257cc07 Compare June 6, 2018 18:07
@sandreenko sandreenko changed the title [WIP] clean up list of disabled warnings. clean up list of disabled warnings. Jun 6, 2018
@sandreenko
Copy link
Copy Markdown
Author

This simple PR affects non only jit, so I am not sure who can review it.
cc @dotnet/jit-contrib .

@CarolEidt
Copy link
Copy Markdown

This simple PR affects non only jit, so I am not sure who can review it.

Perhaps @janvorli or @jkotas

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Jun 7, 2018

What does size_t{ 1 } do? Why is it better than the old fashioned (size_t)1?

Comment thread src/jit/emitarm64.cpp Outdated
if (loByte == 0xFF)
{
imm8 |= (1 << pos);
imm8 |= (size_t{1} << pos);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The cast here is not necessary, the pos is guaranteed to be less than 8. Doesn't hurt to have it here though. Maybe use ssize_t here to match the target variable type?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, you are right, I have missed the diff between ssize_t and size_t.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed

Comment thread src/jit/emitarm64.cpp Outdated
for (unsigned b = 0; b < 8; b++)
{
if (imm & (1 << b))
if (imm & (size_t{1} << b))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The case is not necessary, the loop goes from 0 to 7.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You are right, but because imm has type of ssize_t there is implicit conversion from int to ssize_t here. It generates warning C4334 ('operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?), https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4334), that was disabled before.

The right thing to do here is to right:
if (imm & static_cast<ssize_t>(1 << b)) , but it also generates warnings, I think it is VC++ compiler issue and I have reported it.

Comment thread src/jit/emitarm64.cpp Outdated
{
printf("*");
emitDispImm(1 << imm, false);
emitDispImm(size_t{1} << imm, false);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The cast is not necessary here, the function asserts at the beginning:
assert((imm >= 0) && (imm <= 4));.
Moreover, the emitDispImm parameter type is int.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

void emitter::emitDispImm(ssize_t imm, bool addComma, bool alwaysHex /* =false */)

DWORD j;

if (IS_ALIGNED(dwCumulativeInstanceFieldPos, 1<<(i+1)))
if (IS_ALIGNED(dwCumulativeInstanceFieldPos, size_t{ 1 } << (i + 1)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The cast is not necessary here, the I goes from 0 to MAX_LOG2_PRIMITIVE_FIELD_SIZE which is 3


// Place the field
dwCumulativeInstanceFieldPos = (DWORD)ALIGN_UP(dwCumulativeInstanceFieldPos, 1 << i);
dwCumulativeInstanceFieldPos = (DWORD)ALIGN_UP(dwCumulativeInstanceFieldPos, size_t{ 1 } << i);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The cast is not necessary here, the I goes from 0 to MAX_LOG2_PRIMITIVE_FIELD_SIZE which is 3

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VS team agreed that static_cast<size_t>(1 << I) should not produce the warning, but I think the fix will get some time, so it is better to go with the current solution.

@sandreenko
Copy link
Copy Markdown
Author

What does size_t{ 1 } do? Why is it better than the old fashioned (size_t)1?

(size_t)1 is old-style C cast, that is not the best thing to use.
size_t{ 1 } is brace initialization (since C++11), it prevents narrowing conversions (with compile time errors) and is recommended to create constant literals.

@sandreenko
Copy link
Copy Markdown
Author

Any additional comments for this PR?

Copy link
Copy Markdown

@briansull briansull left a comment

Choose a reason for hiding this comment

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

Looks Good

@sandreenko sandreenko merged commit 1c8c96e into dotnet:master Jun 15, 2018
@sandreenko sandreenko deleted the cleanWarningsList branch June 15, 2018 01:33
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* delete warnings that do not longer exist

For example C4171 was deleted after VS 6.0 (https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa233011(v=vs.60))

* delete C4206 fromm the list

because its default value is 4, so this line is useless.

* reenable warning as error.

* enable warning C4430

and fix places that trigger it.

* fix C4334

* format the list

* fix ssize_t


Commit migrated from dotnet/coreclr@1c8c96e
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants