Skip to content

Commit 336b15c

Browse files
author
Hana Dusíková
committed
auto detection of HEAD of gcc to disable trampolining and old style literals
1 parent 645a767 commit 336b15c

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

cpp-20-check.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ if echo "" | $1 -std=c++2a -E -x c++ - 2>/dev/null 1>/dev/null; then
44
if [ -z "$VERSION" ]; then
55
echo "-std=c++2a";
66
else
7-
echo "-std=c++2a -DEXPERIMENTAL_GCC_9";
7+
# -DCTRE_ENABLE_TRAMPOLINING_ON_GCC9
8+
echo "-std=c++2a";
89
fi
910
else
1011
echo "-std=c++17";

include/ctll/parser.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
#include <limits>
1010

11+
// this is disabling TRAMPOLINING for GCC9 which causes ICE
12+
#if __GNUC__ == 9 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 0
13+
#ifndef CTRE_ENABLE_TRAMPOLINING_ON_GCC9
14+
#define CTRE_DISABLE_TRAMPOLINING 1
15+
#endif
16+
#endif
17+
1118
namespace ctll {
1219

1320

@@ -21,7 +28,7 @@ struct placeholder { };
2128

2229
template <size_t> using index_placeholder = placeholder;
2330

24-
#ifdef EXPERIMENTAL_GCC_9
31+
#ifdef CTRE_DISABLE_TRAMPOLINING
2532
template <size_t, typename, typename Subject, decision Decision> struct results {
2633
constexpr operator bool() const noexcept {
2734
return Decision == decision::accept;
@@ -39,7 +46,7 @@ template <typename Grammar, ctll::basic_fixed_string input, typename ActionSelec
3946
using Actions = ctll::conditional<IgnoreUnknownActions, ignore_unknown<ActionSelector>, identity<ActionSelector>>;
4047
using grammar = augment_grammar<Grammar>;
4148

42-
#ifndef EXPERIMENTAL_GCC_9
49+
#ifndef CTRE_DISABLE_TRAMPOLINING
4350
template <size_t Pos, typename Stack, typename Subject, decision Decision> struct results {
4451
constexpr inline CTLL_FORCE_INLINE operator bool() const noexcept {
4552
return Decision == decision::accept;
@@ -101,7 +108,7 @@ template <typename Grammar, ctll::basic_fixed_string input, typename ActionSelec
101108
// if rule is pop_input => move to next character
102109
template <size_t Pos, typename Terminal, typename Stack, typename Subject>
103110
static constexpr auto move(ctll::pop_input, Terminal, Stack, Subject) noexcept {
104-
#ifdef EXPERIMENTAL_GCC_9
111+
#ifdef CTRE_DISABLE_TRAMPOLINING
105112
return decide<Pos+1>(Stack(), Subject());
106113
#else
107114
return results<Pos+1, Stack, Subject, decision::undecided>();
@@ -121,7 +128,7 @@ template <typename Grammar, ctll::basic_fixed_string input, typename ActionSelec
121128
// and push string without the character (quick LL(1))
122129
template <size_t Pos, auto V, typename... Content, typename Stack, typename Subject>
123130
static constexpr auto move(push<term<V>, Content...>, term<V>, Stack stack, Subject) noexcept {
124-
#ifdef EXPERIMENTAL_GCC_9
131+
#ifdef CTRE_DISABLE_TRAMPOLINING
125132
return decide<Pos+1>(push_front(list<Content...>(), stack), Subject());
126133
#else
127134
return results<Pos+1, decltype(push_front(list<Content...>(), stack)), Subject, decision::undecided>();
@@ -131,7 +138,7 @@ template <typename Grammar, ctll::basic_fixed_string input, typename ActionSelec
131138
// and push string without the character (quick LL(1))
132139
template <size_t Pos, auto V, typename... Content, auto T, typename Stack, typename Subject>
133140
static constexpr auto move(push<anything, Content...>, term<T>, Stack stack, Subject) noexcept {
134-
#ifdef EXPERIMENTAL_GCC_9
141+
#ifdef CTRE_DISABLE_TRAMPOLINING
135142
return decide<Pos+1>(push_front(list<Content...>(), stack), Subject());
136143
#else
137144
return results<Pos+1, decltype(push_front(list<Content...>(), stack)), Subject, decision::undecided>();
@@ -150,7 +157,7 @@ template <typename Grammar, ctll::basic_fixed_string input, typename ActionSelec
150157

151158
// in case that semantic action is error => reject input
152159
if constexpr (std::is_same_v<ctll::reject, decltype(subject)>) {
153-
#ifndef EXPERIMENTAL_GCC_9
160+
#ifndef CTRE_DISABLE_TRAMPOLINING
154161
return results<Pos, Stack, Subject, decision::reject>();
155162
#else
156163
return results<Pos, Stack, Subject, decision::reject>();
@@ -166,7 +173,7 @@ template <typename Grammar, ctll::basic_fixed_string input, typename ActionSelec
166173
}
167174
}
168175

169-
#ifndef EXPERIMENTAL_GCC_9
176+
#ifndef CTRE_DISABLE_TRAMPOLINING
170177
// trampolines with folded expression
171178
template <typename Subject, size_t... Pos> static constexpr auto trampoline_decide(Subject, std::index_sequence<Pos...>) noexcept {
172179
// parse everything for first char and than for next and next ...

include/ctre/literals.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace literals {
3030
#ifdef __INTEL_COMPILER
3131
// not enable literals
3232
#elif defined __GNUC__
33-
#ifndef EXPERIMENTAL_GCC_9
33+
#if not(__GNUC__ == 9 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 0)
3434
#define CTRE_ENABLE_LITERALS
3535
#endif
3636
#endif

tests/many-of-same-proto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <ctre.hpp>
22
using namespace ctre::test_literals;
33

4-
#ifndef EXPERIMENTAL_GCC_9 // fixed
4+
#if not(__GNUC__ == 9 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 0)
55
#define CTRE_TEST(pattern) static_assert(pattern ## _ctre_test)
66
#else
77

tests/matching2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <ctre.hpp>
22
#include <string_view>
33

4-
#ifndef EXPERIMENTAL_GCC_9 // fixed
4+
#if not(__GNUC__ == 9 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 0)
55
#define CTRE_CREATE(pattern) (pattern ## _ctre)
66
#define CTRE_SYNTAX(pattern) (pattern ## _ctre_syntax)
77
#else

tests/parsing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
using namespace ctre::test_literals;
44

5-
#ifndef EXPERIMENTAL_GCC_9 // fixed
5+
#if not(__GNUC__ == 9 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 0)
66
#define CTRE_TEST(pattern) (pattern ## _ctre_test)
77
#else
88

tests/trampoline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "ctre.hpp"
22

33
// GCC9 is crashing with ICE on trampolining mechanism
4-
#ifndef EXPERIMENTAL_GCC_9
4+
#if not(__GNUC__ == 9 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 0)
55

66
static constexpr inline auto pattern = ctll::basic_fixed_string{"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((x)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))"};
77

0 commit comments

Comments
 (0)