Thread: UB or GCC bug or ??

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    4,183

    UB or GCC bug or ??

    I am building KiCAD using MinGW64 GCC 12.1 and I am getting a build error that gives no information. I traced the KiCAD code to an 60 thousand line git commit. Glancing though the patch I saw this line and wonder is it valid. The rest of the code looked okay or too complex for me to understand.

    Code:
    enum class BITMAPS : unsigned int;
    UB: Undefined Behavior

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by stahta01 View Post
    I am building KiCAD using MinGW64 GCC 12.1 and I am getting a build error that gives no information. I traced the KiCAD code to an 60 thousand line git commit. Glancing though the patch I saw this line and wonder is it valid. The rest of the code looked okay or too complex for me to understand.

    Code:
    enum class BITMAPS : unsigned int;
    UB: Undefined Behavior

    Tim S.
    Just noticed that one line is repeated 7 times in 7 different header files.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    enum class BITMAPS : unsigned int;
    I am guessing that is like a forward class declaration because I found where the definition is done. I am a C programmer not really a C++ programmer.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Enumeration declaration - cppreference.com
    Scroll down to Scoped enumerations
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Salem: Thank you for the link.
    Looks like I am going to try a few trial and error fixes.
    If one fixes the build issue, I will post here with the patch that fixed the issues. Because I am thinking it is likely UB or Compiler bug, but, it might be a MSYS2 MINGW64 build system error.

    I just wish the git commit was smaller that 60 thousand lines that triggered the problem. But, it is less than 100 lines in the cpp file that likely has the cause in it. I hope it is not an header issue; too many headers were edited for my simple trial and error method to find the issue.

    Tim S.
    Last edited by stahta01; 06-02-2022 at 11:10 AM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Link to the file that has what appears to be a silent GCC build error.
    kicad-source-mirror/bitmap.cpp at master * KiCad/kicad-source-mirror * GitHub

    My current trial and error fix is removing the static_cast from line below.
    Code:
    SCALED_BITMAP_ID id = { static_cast<BITMAPS>( aBitmap ), scale };
    Edit: I am calling GCC failing to build the file with no error message being output to be a possible silent GCC bug.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    The static_cast looks to be the trigger; the build made it passed the silent error point.

    Once, the build completes and I run the kicad command and it works will post the simple patch.

    I have had so many times where it looked fixed; but, was not to not be sure it is fixed.

    Edit: I was wrong some reason it took longer to fail this time.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Traced the problem to this header kicad-source-mirror/bitmap_info.h at master * KiCad/kicad-source-mirror * GitHub

    Looks like am wxWidgets wxString related issue. I was able to duplicate the problem in a minimal wxWidgets sample by adding bitmap_info.h and bitmaps_list.h.

    If the number of entries in g_BitmapInfo is reduced the silent error goes away.
    Or if wxString type is replaced with std::string the silent error goes away.
    Edit: I also removed wxT macros when using std::string

    So, likely an wxWidgets library problem.

    Tim S.
    Last edited by stahta01; 06-02-2022 at 11:42 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    The wxWidgets expert said the problem is likely a resource issue, likely memory, suffered by the MinGW64 GCC Compiler.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Tags for this Thread