"std::_debug_memset" is not declared

271 views Asked by At

I'm working on GCC119 from the compile farm. The machine is AIX 7.1, POWER8 with IBM XLC 13.1. I'm trying to use the debug heap:

gcc119$ cat test.cxx
#include <altivec.h>
#undef vector
#undef pixel
#undef bool

#include <cstdlib>

int main(int argc, char* argv[])
{
  unsigned char x[32];
  std::memset(x, 0x00, 32);

  return 0;
}

A compile results in:

gcc119$ xlC -DDEBUG -g3 -O0 -qheapdebug -qro test.cxx -o test.exe
"test.cxx", line 11.3: 1540-0130 (S) "std::_debug_memset" is not declared.

Both <cstring> and <string.h> result in the error. I also tried including <cstdlib> and <stdlib.h>, and they resulted in the same error.

The Optimization and Programming Guide manual has a good discussion of debugging memory functions, but the treatment is C only. It does not appear to treat C++.

How does one use debug heaps in a C++ program?


gcc119$ oslevel -s
7200-00-01-1543

gcc119$ xlC -qversion
IBM XL C/C++ for AIX, V13.1.3 (5725-C72, 5765-J07)
Version: 13.01.0003.0004
2

There are 2 answers

1
user10688376 On

You should try including <string.h> instead and using unqualified memset. According to the IBM XL C/C++ Programming Guide, _debug_memset lives in string.h. So the question becomes, shouldn't <cstring> make it available via std::? In the IBM XL C/C++ Standard Library reference, it shows all of the using declarations, and the debug functions are not there.

namespace std
{
using ::size_t; using ::memcmp; using ::memcpy; using ::memmove;
using ::memset; using ::strcat; using ::strcmp; using ::strcoll;
using ::strcpy; using ::strcspn; using ::strerror; using ::strlen;
using ::strncat; using ::strncmp; using ::strncpy; using ::strspn;
using ::strtok; using ::strxfrm;
}
0
jww On

Based on @user10688376's observation here's what I've come up with. I think it is technically undefined behavior because I am not allowed to put symbols like _debug_memset and _debug_memcpy in the std namespace. At this point potential UB is better than a failed compile and no testing.

#if defined(_AIX) && (defined(__xlc__) || defined(__xlC__) || defined(__ibmxl__))
# if defined(__DEBUG_ALLOC__)
namespace std {
  using ::_debug_memset;
  using ::_debug_memcpy;
}
# endif
#endif

_AIX is used because it identifies the operating system. Debug heaps are not available on the Linux gear. (Some IBM XLC compilers run on Linux, too).

__xlc__ and __xlC__ are used to detect IBM XLC compiler 13.0 and earlier. This compiler is built completely by IBM.

__ibmxl__ is used to detect IBM XLC compiler 13.1 and later. This compiler uses a Clang front-end and IBM back-end. I think this is the "LLC" compiler referred to in LLVM Review 21078.

__DEBUG_ALLOC__ is used because the compiler sets it for -qheapdebug.