Jump to content

Use SystemC with Clang under Windows - fix Pointer corruption


Hadrian2002

Recommended Posts

Hi,

I just tried to use clang under windows to compile some SystemC projects and I experienced a pointer corruption of the instance pointer for the execution of a sc_thread. After some debugging I discovered, that the "hack" for older VS++ compilers referring to the macro "SC_USE_MEMBER_FUNC_PTR"  (see https://github.com/accellera-official/systemc/blob/604182509559ae42c34e878f508bae7c18abbbd6/src/sysc/kernel/sc_process.h#L120) will create working simulation binaries with clang (i.e. actually not defining the macro is doing the trick).

I actually also realized, that clang under Windows is not officially supported, which explains that it have not arisen yet. Nonetheless, adding here an additional compiler detection macro would be easy and would add (although quite untested) clang support for windows. I tried my fix for clang 10 and clang 12. I got the impression, that clang sometime in the past adapted to the "bad" msvc behavior and did not change it, although msvc got standard compliant. 

The fix for this problem would be quite easy:

#if defined(_MSC_VER) && !defined(__clang__)
#if ( _MSC_VER > 1200 )
#   define SC_USE_MEMBER_FUNC_PTR
#endif
#elif defined(_WIN32) && defined(__clang__)
//do not define SC_USE_MEMBER_FUNC_PTR
#else
#   define SC_USE_MEMBER_FUNC_PTR
#endif

 

Additionally, I would propose to throw a warning in the CMakeLists, if using an unsupported compiler.

Do you like to get PullRequest on github?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...