Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile errors with g++ 11.2.1_p20211127 #9

Closed
Sembiance opened this issue Jan 2, 2022 · 8 comments
Closed

compile errors with g++ 11.2.1_p20211127 #9

Sembiance opened this issue Jan 2, 2022 · 8 comments

Comments

@Sembiance
Copy link
Contributor

I got the following compile error with g++ 11.2.1_p20211127

/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/hypercard_dasm.cc: In function ‘int main(int, char**)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/hypercard_dasm.cc:1220:74: error: cannot bind packed field ‘header.BlockHeader::id’ to ‘int&’
 1220 |         backgrounds.emplace(piecewise_construct, forward_as_tuple(header.id),
      |                                                                   ~~~~~~~^~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/hypercard_dasm.cc:1224:68: error: cannot bind packed field ‘header.BlockHeader::id’ to ‘int&’
 1224 |         cards.emplace(piecewise_construct, forward_as_tuple(header.id),
      |                                                             ~~~~~~~^~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/hypercard_dasm.cc:1228:70: error: cannot bind packed field ‘header.BlockHeader::id’ to ‘int&’
 1228 |         bitmaps.emplace(piecewise_construct, forward_as_tuple(header.id),
      |                                                               ~~~~~~~^~

Which led me to this report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36566

Also got this error:

/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/RealmzLib.cc: In member function ‘void ComplexEncounter::byteswap()’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/RealmzLib.cc:810:53: error: iteration 5 invokes undefined behavior [-Werror=aggressive-loop-optimizations]
  810 |     this->item_codes[x] = bswap16(this->item_codes[x]);
      |                                   ~~~~~~~~~~~~~~~~~~^
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/RealmzLib.cc:809:21: note: within this loop
  809 |   for (int x = 0; x < 10; x++) {
      |                   ~~^~~~

That and some other errors led me to this patch to fix the issues:

diff -Naur a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt	2022-01-01 19:29:02.196919666 -0500
+++ b/CMakeLists.txt	2022-01-01 19:29:31.827894405 -0500
@@ -12,7 +12,7 @@
 if (MSVC)
     add_compile_options(/W4 /WX)
 else()
-    add_compile_options(-Wall -Wextra -Werror)
+    add_compile_options(-Wall -Wextra -Werror -Wno-strict-aliasing -Wno-unused-result -Wno-overflow -Wno-maybe-uninitialized -Wno-format -Wno-aggressive-loop-optimizations)
 endif()
 
 include_directories("/usr/local/include")
diff -Naur a/src/hypercard_dasm.cc b/src/hypercard_dasm.cc
--- a/src/hypercard_dasm.cc	2022-01-01 19:29:15.748908114 -0500
+++ b/src/hypercard_dasm.cc	2022-01-01 19:24:45.749129132 -0500
@@ -1201,6 +1201,7 @@
     size_t block_offset = r.where();
     BlockHeader header = r.get_sw<BlockHeader>(false);
     size_t block_end = block_offset + header.size;
+    const int& header_id(header.id);
 
     if (dump_raw_blocks) {
       string type_str = string_for_resource_type(header.type);
@@ -1217,15 +1218,15 @@
         stack_format = stack->format;
         break;
       case 0x424B4744: // BKGD
-        backgrounds.emplace(piecewise_construct, forward_as_tuple(header.id),
+        backgrounds.emplace(piecewise_construct, forward_as_tuple(header_id),
             forward_as_tuple(r, stack_format));
         break;
       case 0x43415244: // CARD
-        cards.emplace(piecewise_construct, forward_as_tuple(header.id),
+        cards.emplace(piecewise_construct, forward_as_tuple(header_id),
             forward_as_tuple(r, stack_format));
         break;
       case 0x424D4150: // BMAP
-        bitmaps.emplace(piecewise_construct, forward_as_tuple(header.id),
+        bitmaps.emplace(piecewise_construct, forward_as_tuple(header_id),
             forward_as_tuple(r, stack_format));
         break;
@fuzziqersoftware
Copy link
Owner

Thanks for the report. The RealmzLib error was actually a legit bug; I'm surprised I never caught it.

I've added some of the -Wno flags to CMakeLists, but I find maybe-uninitialized, no-format, and no-aggressive-loop-optimizations useful during my work, so I've left them enabled. If the build still produces errors, could you post the full output here and I'll fix all the necessary cases?

I'm hoping to set up some kind of CI here in the near future, so my use of a somewhat-permissive compiler won't cause problems for others anymore.

@Sembiance
Copy link
Contributor Author

Thanks for the changes. Current code results in error:

/home/sembiance/Assorted/resource_dasm/src/hypercard_dasm.cc:1290:51: error: format ‘%llX’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Werror=format=]
 1290 |       fprintf(f.get(), "-- patterns[%zu]: 0x%016llX\n", x, stack->patterns[x]);
      |                                             ~~~~~~^        ~~~~~~~~~~~~~~~~~~
      |                                                   |                         |
      |                                                   long long unsigned int    uint64_t {aka long unsigned int}
      |                                             %016lX

@fuzziqersoftware
Copy link
Owner

Fixed that just now. (Why are the length codes different on different systems? Sigh...)

@Sembiance
Copy link
Contributor Author

Errors:

/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/QuickDrawEngine.cc: In member function ‘Image QuickDrawEngine::pict_decode_smc(const PictQuickTimeImageDescription&, const std::vector<ColorTableEntry>&, const string&)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/QuickDrawEngine.cc:787:19: error: ‘prev_y1’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  787 |           ret.blit(ret, x, y, 4, 4, prev_x2, prev_y2);
      |           ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/QuickDrawEngine.cc:787:19: error: ‘prev_x1’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

and

/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/ResourceFile.cc: In member function ‘std::string ResourceFile::decompress_resource(const string&, uint64_t)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/ResourceFile.cc:655:21: error: ‘entry_r2’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  655 |         regs.r[2].u = entry_r2;
      |         ~~~~~~~~~~~~^~~~~~~~~~

@fuzziqersoftware
Copy link
Owner

Fixed these as well.

@Sembiance
Copy link
Contributor Author

Compiles great now.

You can safely remove flag -Wno-overflow. Code compiles fine without that, I included that by mistake earlier, sorry.

If you remove -Wno-unused-result I get the error:

/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/dc_dasm.cc: In function ‘std::vector<ResourceEntry> load_index(FILE*)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/dc_dasm.cc:312:8: error: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  312 |   fread(&h, sizeof(ResourceHeader), 1, f);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/dc_dasm.cc:316:8: error: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  316 |   fread(e.data(), sizeof(ResourceEntry), h.resource_count, f);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And if you remove -Wno-strict-aliasing I get the errors:

/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc: In member function ‘uint32_t M68KEmulator::read(const M68KEmulator::ResolvedAddress&, uint8_t)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc:326:15: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  326 |       return *reinterpret_cast<uint16_t*>(&this->regs.d[addr.addr].u);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc:336:15: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  336 |       return *reinterpret_cast<uint16_t*>(&this->regs.a[addr.addr]);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc: In member function ‘void M68KEmulator::write(const M68KEmulator::ResolvedAddress&, uint32_t, uint8_t)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc:369:8: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  369 |       *reinterpret_cast<uint16_t*>(&this->regs.d[addr.addr].u) = value;
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc:379:8: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  379 |       *reinterpret_cast<uint16_t*>(&this->regs.a[addr.addr]) = value;
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc: In member function ‘void M68KEmulator::exec_5(uint16_t)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc:1698:29: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 1698 |         uint16_t& target = *reinterpret_cast<uint16_t*>(&this->regs.d[Xn].u);
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc: In member function ‘void M68KEmulator::exec_E(uint16_t)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc:2434:29: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2434 |         uint16_t& target = *reinterpret_cast<uint16_t*>(&this->regs.d[Xn].u);
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/M68KEmulator.cc:2471:39: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2471 |             int16_t& signed_target = *reinterpret_cast<int16_t*>(&this->regs.d[Xn].u);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@fuzziqersoftware
Copy link
Owner

Great - thanks for the help!

@Sembiance
Copy link
Contributor Author

By the way, just wanted to say, THANK YOU very much for creating this software. I'm working on a project to help preserve some of our digital history and this being able to extract the resources from resource forks is quite invaluable for old MacOS files.

THANKS!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants