ivmai / bdwgc

The Boehm-Demers-Weiser conservative C/C++ Garbage Collector (bdwgc, also known as bdw-gc, boehm-gc, libgc)
https://www.hboehm.info/gc/
Other
2.98k stars 407 forks source link

Failure of gc tests with asymptote on Mac running Mojave #273

Closed ivmai closed 5 years ago

ivmai commented 5 years ago

Asymptote depends on boehmgc and libatomic_ops. Version 7.6.0 worked for everyone, version 8.0.4 works for most, but not with clang on macOS and FreeBSD (reverting to an older gc works). The boehmgc compiles, but then the source using it fails with the error mentioned below.

The error message is too cryptic for me to understand.

Thank you very much, Mojca

c++ -Wall -DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -DUSEGC -D_THREAD_SAFE -pthread -DFFTWPP_SINGLE_THREAD -I. -Igc-8.0.4/include -I/usr/include/tirpc -std=c++11 -g -O3 -o settings.o -c settings.cc In file included from settings.cc:18: In file included from ./common.h:35: In file included from ./memory.h:13: /usr/include/c++/v1/map:1561:65: error: no viable conversion from 'gc_allocator *>>' to 'const gc_allocator>' alloc_traits::select_on_container_copyconstruction(m.tree.alloc()))

^~~~~ ./memory.h:148:14: note: in instantiation of member function 'std::1::multimap std::1::less sym::symbol>, gc_allocator trans::tyEntry > > >::multimap' requested here GC_CONTAINER(multimap); ^ ./env.h:61:8: note: in instantiation of member function 'sym::table::collapseScope' requested here te.collapseScope(); ve.collapseScope(); ^ gc-8.0.4/include/gc_allocator.h:152:3: note: candidate constructor not viable: no known conversion from 'std::1::tree sym::symbol, trans::tyEntry >, std::1::map_value_compare std::1::value_type, std::1::less, true>, gc_allocator > > >::allocator_type' (aka 'gc_allocator trans::tyEntry > >') to 'const gc_allocator sym::symbol, trans::tyEntry *> > &' for 1st argument gc_allocator(const gc_allocator&) GC_NOEXCEPT {} ^ /usr/include/c++/v1/memory:1603:69: note: passing argument to parameter '__a' here select_on_container_copy_construction(const allocator_type& a) ^ 1 error generated.

ivmai commented 5 years ago

It turned out that the issue is observed starting from v7.6.2. The relevant commit which brings the issue is 243f500e4

ivmai commented 5 years ago

+ @mojca

ivmai commented 5 years ago

Trying compilation with v7.6.2 in two variants modifying include/gc_allocator.h:

  1. "if (__cplusplus >= 201103L) || defined(CPPCHECK)" -> "if 1"
  2. "if (__cplusplus >= 201103L) || defined(CPPCHECK)" -> "if 0"

The "if 1" test failed, and the "if 0" test worked.

ivmai commented 5 years ago

About __cplusplus value. Reported variants:

ivmai commented 5 years ago

With the below small patch, asymptote compiles with ./configure CXXFLAGS=-ansi again.

diff --git a/shaders.cc b/shaders.cc
index e6c3f074..46bb4c7f 100644
--- a/shaders.cc
+++ b/shaders.cc
@@ -16,7 +16,7 @@
 GLuint createShaders(GLchar const* src, int shaderType)
 {
     GLuint shader = glCreateShader(shaderType);
-    glShaderSource(shader, 1, &src, nullptr);
+    glShaderSource(shader, 1, &src, NULL);
     glCompileShader(shader);

     GLint status;
@@ -32,9 +32,10 @@ GLuint createShaders(GLchar const* src, int shaderType)

         glGetShaderInfoLog(shader, length, &length, msg.data());

-        for(GLchar const& cha : msg)
+        size_t n=msg.size();
+        for(size_t i=0; i < n; ++i) 
         {
-            std::cerr << cha;
+          std::cerr << msg[i];
         }

         std::cerr << std::endl << "GL Compile error" << std::endl;
@@ -48,7 +49,7 @@ GLuint createShaderFile(std::string file, int shaderType, size_t Nlights,
                         size_t Nmaterials,  bool explicitcolor)
 {
     std::ifstream shaderFile;
-    shaderFile.open(file);
+    shaderFile.open(file.c_str());
     std::stringstream shaderSrc;

     shaderSrc << "#version 130" << "\r\n";
diff --git a/shaders.h b/shaders.h
index d249f746..6e239162 100644
--- a/shaders.h
+++ b/shaders.h
@@ -16,7 +16,6 @@
 #endif

 #include <string>
-#include <unordered_set>

 GLuint createShaders(GLchar const *src, int shaderType);
 GLuint createShaderFile(std::string file, int shaderType, size_t Nlights,
ivmai commented 5 years ago

Reported by Mojca:

On the latest macOS with 1997xx default it doesn't work by default, or rather:

On FreeBSD with clang 6 it also breaks against 8.0.4 in pretty much the same way.

On Mac OS X 10.6 with clang 7 I got it working last week with GC 8.0.4 (it was broken with 8.0.2), but I can no longer reproduce this.

We definitely need to do more testing on our end, but at least now I know how to test further and where to pay extra attention, I just need more time.

ivmai commented 5 years ago

@mojca wrote:

On the latest macOS with 1997xx default it doesn't work by default

Hmm. There was a report that replacing "if (cplusplus >= 201103L) || defined(CPPCHECK)" to "if 0" fixes the issue (works). On your host cplusplus >= 201103L is false (thus the whole "if" condition is 0).

sgf commented 4 years ago

about cplusplus seems do not work default on MSVC (Need [Add /Zc:cplusplus or /Zc:__cplusplus- to the Additional options: pane.](https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=vs-2019) ) or

if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)

 //C++17 specific stuff here

endif

ivmai commented 4 years ago

about __cplusplus seems do not work default on MSVC

I've created #314