HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.17k stars 654 forks source link

[cpp] weird crash/corruption with Dynamic and Visual Studio 2015 #5567

Open nadako opened 8 years ago

nadako commented 8 years ago

The following crashes for me on Windows if compiled with VS2015 (aka version 19 aka version 14). @Simn couldn't reproduce it with the previous one (Using MSVC version: 18). Interestingly, if we replace those "hello" strings with empty strings ("") it doesn't crash, but prints some rubbish instead.

class Main {
    static function f(v:Dynamic) {
        f2("hello" + Std.string(v) + "hello");
    }

    @:pure(false) static function f2(v:String) {
        trace(v);
    }

    static function main(){
        f("s");
    }
}
nadako commented 8 years ago

could be a hxcpp problem, but i'm not sure

nadako commented 8 years ago

btw, adding -debug makes it work

Gama11 commented 8 years ago

I seem to be unable to reproduce this (same MVSC version - C/C++ Optimizing Compiler Version 19.00.23506). Both Main.exe and Main-debug.exe output helloshello when I run them.

You don't have any special or anything activated right? Latest Haxe (cbee676) and Hxcpp?

nadako commented 8 years ago

wow, that's really weird... i don't think i have anything special in my system, but i'll check again later today.

Gama11 commented 8 years ago

Do you have the exact same MSVC version? 19.00.23506? Who knows, with how strange this is it might be a bug that was already fixed in my version.

It outputs the exact version as well, but a bit later (if you have HXCPP_VERBOSE defined).

hughsando commented 8 years ago

I could not reproduce it either, but the symptoms sound like I might be returning a reference to a local variable that has gone out of scope somewhere. Maybe with things are less optimized, this might not matter.

On Tue, Aug 30, 2016 at 5:52 PM, Gama11 notifications@github.com wrote:

Do you have the exact same MSVC version? 19.00.23506? Who knows, with how strange this is it might be a bug that was already fixed in my version.

It outputs that one as well, but a bit later (if you have HXCPP_VERBOSE defined).

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/haxe/issues/5567#issuecomment-243390142, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlp1h7NsSwX6zQ51vzpK37RseOdnWTeks5qk_1LgaJpZM4Jvys4 .

hughsando commented 8 years ago

There is not actually a lot of code going on here - just String operator+(String). https://github.com/HaxeFoundation/hxcpp/blob/master/src/String.cpp#L1083

You could try debgging in here with something like: printf("operator+ %s %s\n", s, inRHS.s);

The other thing is the cache, you can check with: haxelib run hxcpp cache list