sml icon indicating copy to clipboard operation
sml copied to clipboard

Segmentation fault in guard with Mingw64 GCC, debug build

Open nbonnec opened this issue 2 years ago • 4 comments

Code

#include <sml.hpp>

namespace {

struct Event {
	bool pressed;
};

struct Guard1 {
	[[nodiscard]] bool operator()(const Event& e) const {
		return e.pressed;
	}
} guard1;

struct Guard2 {
	[[nodiscard]] bool operator()(const Event& e) const {
		return true;
	}
} guard2;

struct Guard3 {
	[[nodiscard]] bool operator()(const Event& e) const {
		return true;
	}
} guard3;

}// namespace

namespace sml = boost::sml;

struct Fsm {

	struct State {};

	auto operator()() const {
		using namespace boost::sml;

		return make_transition_table(
			// clang-format off
		   *state<State> + event<Event>[guard1 && guard2 && guard3] = state<State>
			// clang-format on
		);
	}
};

int main() {
	boost::sml::sm<Fsm> fsm{};
	fsm.process_event(Event{});
}

Expected Behavior

No segmentation fault.

Actual Behavior

Segmentation fault when accessing the pressed field in Guard1.

Process finished with exit code -1073741819 (0xC0000005)

image

Event address is still ok in front::transition::execute: image

But in front::call::execute it gets corrupted: image

If I remove one of the guard, it works fine.

Steps to Reproduce the Problem

  1. use gcc from MSYS2, gcc --version gcc.exe (Rev2, Built by MSYS2 project) 12.1.0
  2. build with -g -std=gnu++20
  3. run

Specifications

  • Version: 1.1.4, 1.1.5
  • Platform: Windows, GCC 12.1.0 (MSYS2 mingw-w64-x86_64-gcc)

nbonnec avatar Jul 08 '22 10:07 nbonnec

Hey @kris-jusiak we also experience a similar behavior in our application, so i think we can confirm, can you look into this? However we are using clang and run on linux.

mechatheo avatar Sep 22 '22 12:09 mechatheo

Hey, will take a look, thanks for bringing it up to my attention

krzysztof-jusiak avatar Sep 22 '22 13:09 krzysztof-jusiak

so it's only on mingw, correct? can't repro on gcc12.1 - https://godbolt.org/z/jos7h78vq

krzysztof-jusiak avatar Sep 22 '22 13:09 krzysztof-jusiak

With mingw-clang, it seems to work.

nbonnec avatar Sep 27 '22 15:09 nbonnec