Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
5090 Discussions

Inspector "Uninitialized Partial Memory Access" false positive with padded structures

Steve_H
Novice
621 Views

We have been hitting a problem using Inspector under Linux when building the code with GCC (FYI, building with Clang and MSVC does not seem to suffer from the same problem.) I think that this (or something similar) was raised 12+ years ago here: https://community.intel.com/t5/Analyzers/Uninitialized-memory-access-in-struct-member-padding/m-p/788410/highlight/true#M1060 but none of the workarounds mentioned there are possible as the structures that we are using are not under our control (so we can't manually pad) and we are not using malloc or new.

A minimal reproducer is:

 

#include <iostream>
#include <ostream>
#include <memory>

struct Foo
{
   char a, b, c;
   // A padding byte will be inserted here to align the following int
   int d;
};

int main()
{
   auto pFoo = std::make_unique<Foo>();
   Foo pOtherFoo;

   pOtherFoo = *pFoo;

   std::cout << pOtherFoo.d << std::endl;

   return 0;
}
​

 

Building this with g++ repro.cpp using gcc 10.2.1 (under Debian Bullseye) and then running Inspector on the a.out produced reports "Invalid partial memory access" on the structure assignment.

I think that this is because std::make_unique performs value-initialization, which results in default-initialization on this structure... and default-initialization makes no guarantees about initializing padding.

I've confirmed that by adding a user-defined (no-op) constructor to the structure (so the structure must be zero-initialized instead of default-initialized, which does guarantee that padding is filled with zeros) and Inspector no longer reports the problem.

We could suppress the issue type globally (individual suppressions would be too difficult to maintain) but it has caught the occasional issue in the past, so I would rather find a solution to this issue, if possible.

Thanks in advance for you help,

Steve.

 

 

0 Kudos
1 Solution
clevels
Moderator
268 Views

Intel Inspector is no longer included in the Intel® HPC Toolkit. It continues to be downloadable as a standalone package and it will be discontinued in 2025 or later.  Customers who have purchased Intel® Priority Support will continue to receive support. Please see Intel Inspector deprecation article for more information. 


View solution in original post

0 Kudos
2 Replies
yuzhang3_intel
Moderator
579 Views

Thanks for reporting the issue and providing the reproducer. We will investigate and give an update then.

0 Kudos
clevels
Moderator
269 Views

Intel Inspector is no longer included in the Intel® HPC Toolkit. It continues to be downloadable as a standalone package and it will be discontinued in 2025 or later.  Customers who have purchased Intel® Priority Support will continue to receive support. Please see Intel Inspector deprecation article for more information. 


0 Kudos
Reply