Skip to content

Fix Main - ignore warning 6101#2471

Merged
vhvb1989 merged 6 commits intoAzure:mainfrom
vhvb1989:fix-main-build
Jun 23, 2021
Merged

Fix Main - ignore warning 6101#2471
vhvb1989 merged 6 commits intoAzure:mainfrom
vhvb1989:fix-main-build

Conversation

@vhvb1989
Copy link
Copy Markdown
Member

@vhvb1989 vhvb1989 commented Jun 23, 2021

fixes: #2354

@vhvb1989 vhvb1989 changed the title Fix Main - ignore warning Fix Main - ignore warning 6101 Jun 23, 2021
@vhvb1989 vhvb1989 self-assigned this Jun 23, 2021
@vhvb1989 vhvb1989 added Azure.Core Client This issue points to a problem in the data-plane of the library. KeyVault labels Jun 23, 2021
@vhvb1989
Copy link
Copy Markdown
Member Author

/azp run cpp - core

@vhvb1989 vhvb1989 added this to the [2021] July milestone Jun 23, 2021
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Member

@RickWinter RickWinter left a comment

Choose a reason for hiding this comment

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

This warning is a great one to keep as it checks for unitialized memory. Why do we need to disable it?

Comment thread sdk/core/azure-core/CMakeLists.txt Outdated
# - C6285: (<non-zero constant> || <non-zero constant>) -> VBProject static analysis on Functional header:
# _Is_large, regression from VS version 19.28.29915.0 to 19.29.30037.0
target_compile_options(azure-core PUBLIC /wd6285)
target_compile_options(azure-core PUBLIC /wd6285 /wd6101)
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.

Can you add a comment in the source that describes what /wd6101 does?

# warning C6101: Returning uninitialized memory
#      https://docs.microsoft.com/en-us/cpp/code-quality/c6101?view=msvc-160

Copy link
Copy Markdown
Contributor

@ahsonkhan ahsonkhan left a comment

Choose a reason for hiding this comment

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

I had the same question, where is this warning coming from?

@vhvb1989
Copy link
Copy Markdown
Member Author

@ahsonkhan

Windows Kits\10\include\10.0.19041.0\um\ws2tcpip.h(968): warning C6101: Returning uninitialized memory '*Mtu'. A successful path through the function does not set the named Out parameter. : Lines: 968, 973, 974, 975, 976, 978, 979, 994, 968

@ahsonkhan
Copy link
Copy Markdown
Contributor

ahsonkhan commented Jun 23, 2021

Windows Kits\10\include\10.0.19041.0\um\ws2tcpip.h(968): warning C6101: Returning uninitialized memory '*Mtu'. A successful path through the function does not set the named Out parameter. : Lines: 968, 973, 974, 975, 976, 978, 979, 994, 968

What code in our SDK source is triggering this? Were you able to find/drill into the specific source file that we own?

@vhvb1989
Copy link
Copy Markdown
Member Author

/azp run cpp - core

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@vhvb1989
Copy link
Copy Markdown
Member Author

/azp run cpp - core

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines -13 to -14
uint8_t buffer[chunk];
uint8_t buffer2[chunk];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, what was the bug here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

MSVC complains or throw a warning saying that the method is allocating memory in the stack beyond the limit. That's due to creating two arrays of 1M each, resulting in 2MB stack allocation.
Updating the arrays to a vector would use heap for the 2MB

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

if (MSVC)
# Disable warnings
# - C6326: Google comparisons
target_compile_options(azure-perf-unit-test PUBLIC /wd6326)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you point to an example of our source that triggered this warning?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We have this warning disabling in azure-core-tests as well and other test packages,
MSCV warns you when we do something like ASSERT_EQ(a, b) where a is a size_t const and b is size_t as well. MSVC will say that you are just comparing two constants as 4 == 2 or something like that. Because ASSER_EQ macro grom gtest ends up checking something like if(VALUE == OTHER_VALUE) => if(4 == 2).

# _Is_large, regression from VS version 19.28.29915.0 to 19.29.30037.0
target_compile_options(azure-core PUBLIC /wd6285)
# - C6101: Returning uninitialized memory '*Mtu' -> libcurl calling WSAGetIPUserMtu from WS2tcpip.h
target_compile_options(azure-core PUBLIC /wd6101)
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.

Is there a cpp file for which, when being compiled, this warning gets emitted? If so, it is better to disable the warning via "... ifdef _MSC_VER, pragma warning disable".

If there's a header which includes the 3rd party header file that generates the warning, it also is better to disable as "... ifdef _MSC_VER, pragma warnings push, pragma warning disable, include <3rd party>, ifdef MSC pragma pop"

Copy link
Copy Markdown
Contributor

@ahsonkhan ahsonkhan Jun 23, 2021

Choose a reason for hiding this comment

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

@vhvb1989 Is this warning only coming from libcurl cpp file? Can you share where it is coming from (which line of code)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

@ahsonkhan ahsonkhan left a comment

Choose a reason for hiding this comment

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

Since this is to unblock main, it's fine to check this in as a stop gap for now.

It would be nicer to scope the warning to only where we know it is a false positive, rather than across the board, since it seems like a useful warning to keep.

@vhvb1989 vhvb1989 requested review from a team and danieljurek as code owners June 23, 2021 23:16
@vhvb1989
Copy link
Copy Markdown
Member Author

/azp run cpp - core

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

- template: /eng/pipelines/templates/steps/cmake-build.yml
parameters:
GenerateArgs: $(CmakeArgs)
BuildArgs: "$(BuildArgs)"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@danieljurek - I am not the expert here, can you review/speak to this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was not causing Main to be broken, but it was missing to add the build args from the test matrix ( -v and --parallel )

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.

This looks good to me. In the case of the Ubuntu and Windows 2019 machines, the VMs have 2 cores. For I/O bound operations, like building, the process can complete faster with a degree of parallelism that is greater than the number of cores.

In the case of cmake-build.yml this parameter is inserted into the build command line: https://github.com/Azure/azure-sdk-for-cpp/blob/main/eng/pipelines/templates/steps/cmake-build.yml#L20

BuildArgs is a variable and its value is set in the matrix above (if the value is not set somewhere then it is an empty string).

The template syntax:

 cmake --build . ${{ parameters.BuildArgs }}

After template substitution becomes:

 cmake --build . $(BuildArgs)

In the case of MacOS_x64_with_unit_test in the matrix:

 cmake --build . -j 4

According to cmake documentation for the -j parameter:

The CMAKE_BUILD_PARALLEL_LEVEL environment variable, if set, specifies a default parallel level when this option is not given.

Another way to get this outcome is to use the CMAKE_BUILD_PARALLEL_LEVEL.

Either approach will get the same effects. It might be easier to use the command line approach taken in this PR as, if the command line is logged, one can copy and paste the logged command line locally. Otherwise one would have to dig through and reassemble the state of the environment variables at build time starting at the matrix and working up to the job level (in the event that there are some global variables defined)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Core Client This issue points to a problem in the data-plane of the library. KeyVault

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable /wd6285 after compiler bug is fixed

5 participants