From 969ad17b6abe5c878354c2ffb7fef3af6aaa3122 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 27 Nov 2020 18:54:24 +0300 Subject: [PATCH] C: workaround for regression in MSVC compiler --- core/src/main/java/org/teavm/backend/c/CTarget.java | 1 + .../java/org/teavm/backend/c/generate/CallSiteGenerator.java | 2 +- .../java/org/teavm/backend/c/generate/ClassGenerator.java | 5 +++-- .../java/org/teavm/platform/plugin/MetadataCIntrinsic.java | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/teavm/backend/c/CTarget.java b/core/src/main/java/org/teavm/backend/c/CTarget.java index d54953131..cfafda9a8 100644 --- a/core/src/main/java/org/teavm/backend/c/CTarget.java +++ b/core/src/main/java/org/teavm/backend/c/CTarget.java @@ -609,6 +609,7 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { if (!incremental) { headerWriter.println("extern TeaVM_String* teavm_stringPool[];"); headerWriter.println("#define TEAVM_GET_STRING(i) teavm_stringPool[i]"); + headerWriter.println("#define TEAVM_GET_STRING_ADDRESS(i) (teavm_stringPool + i)"); includes.includePath("strings.h"); includes.includePath("stringhash.h"); diff --git a/core/src/main/java/org/teavm/backend/c/generate/CallSiteGenerator.java b/core/src/main/java/org/teavm/backend/c/generate/CallSiteGenerator.java index b01a195fc..c6814e7bb 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/CallSiteGenerator.java +++ b/core/src/main/java/org/teavm/backend/c/generate/CallSiteGenerator.java @@ -219,7 +219,7 @@ public class CallSiteGenerator { } private String getStringExpr(String s) { - return s != null ? "&TEAVM_GET_STRING(" + context.getStringPool().getStringIndex(s) + ")" : "NULL"; + return s != null ? "TEAVM_GET_STRING_ADDRESS(" + context.getStringPool().getStringIndex(s) + ")" : "NULL"; } static class HandlerContainer { diff --git a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java index a90d5f02b..bd1c5a768 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java +++ b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java @@ -837,7 +837,8 @@ public class ClassGenerator { String metadataName = nameOfType(type); String nameRef = metadataName != null - ? "(TeaVM_Object**) &TEAVM_GET_STRING(" + context.getStringPool().getStringIndex(metadataName) + ")" + ? "(TeaVM_Object**) TEAVM_GET_STRING_ADDRESS(" + + context.getStringPool().getStringIndex(metadataName) + ")" : "NULL"; String superTypeFunction = context.getNames().forSupertypeFunction(type); @@ -854,7 +855,7 @@ public class ClassGenerator { simpleName = "NULL"; } else { int simpleNameIndex = context.getStringPool().getStringIndex(simpleName); - simpleName = "(TeaVM_Object**) &TEAVM_GET_STRING(" + simpleNameIndex + ")"; + simpleName = "(TeaVM_Object**) TEAVM_GET_STRING_ADDRESS(" + simpleNameIndex + ")"; } includes.includePath("strings.h"); diff --git a/platform/src/main/java/org/teavm/platform/plugin/MetadataCIntrinsic.java b/platform/src/main/java/org/teavm/platform/plugin/MetadataCIntrinsic.java index 70c751755..b62f85d2c 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/MetadataCIntrinsic.java +++ b/platform/src/main/java/org/teavm/platform/plugin/MetadataCIntrinsic.java @@ -65,7 +65,7 @@ class MetadataCIntrinsic implements Generator { } else if (value instanceof String) { int stringIndex = context.stringPool().getStringIndex((String) value); context.includes().includePath("strings.h"); - context.writerBefore().print("(TeaVM_Object**) &TEAVM_GET_STRING(" + stringIndex + ")"); + context.writerBefore().print("(TeaVM_Object**) TEAVM_GET_STRING_ADDRESS(" + stringIndex + ")"); } else if (value instanceof Boolean) { context.writerBefore().print((Boolean) value ? "1" : "0"); } else if (value instanceof Integer) { @@ -238,7 +238,7 @@ class MetadataCIntrinsic implements Generator { if (key == null) { context.writerBefore().print("{ NULL, NULL }"); } else { - context.writerBefore().print("{ &TEAVM_GET_STRING(" + context.writerBefore().print("{ TEAVM_GET_STRING_ADDRESS(" + context.stringPool().getStringIndex(key) + "), "); writeValue(context, resourceMap.get(key)); context.writerBefore().print("}");