Fix access of constant values in enumerations. foreign-abi
authorNot Zed <notzed@gmail.com>
Tue, 11 Jul 2023 03:47:21 +0000 (13:17 +0930)
committerNot Zed <notzed@gmail.com>
Tue, 11 Jul 2023 03:47:21 +0000 (13:17 +0930)
The documentation is unclear and what worked in gcc 12 no longer works.

src/notzed.nativez/native/export.cc

index d8b183b..d5eca37 100644 (file)
@@ -778,7 +778,7 @@ static void export_type(tree type, const char *names) {
                        for (tree v = TYPE_VALUES(target); v != NULL; v = TREE_CHAIN (v)) {
                                generate("\t{ name => '%s', value => '%ld' },\n",
                                        IDENTIFIER_POINTER(TREE_PURPOSE(v)),
-                                       tree_to_shwi(TREE_VALUE(v)));
+                                       tree_to_shwi(DECL_INITIAL(TREE_VALUE(v))));
                        }
                        generate("]},\n");
                        break;
@@ -973,7 +973,7 @@ static void export_type(tree type, const char *names) {
                for (tree v = TYPE_VALUES(type); v != NULL; v = TREE_CHAIN (v)) {
                        generate("\t{ name => '%s', value => '%ld' },\n",
                                IDENTIFIER_POINTER(TREE_PURPOSE(v)),
-                               tree_to_shwi(TREE_VALUE(v)));
+                               tree_to_shwi(DECL_INITIAL(TREE_VALUE(v))));
                }
                generate("]},\n");
                break;