Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2bb79c

Browse files
lewissbakerLewis Baker
authored andcommitted
Disable some tests under MSVC x86 optimised build variants.
Compiler is generating bad code for these tests under Visual Studio 15 Update 5.
1 parent 7a900c1 commit d2bb79c

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

include/cppcoro/config.hpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,50 @@
6868
/////////////////////////////////////////////////////////////////////////////
6969
// CPU Detection
7070

71+
/// \def CPPCORO_CPU_X86
72+
/// Defined to 1 if target CPU is of x86 family.
73+
#if CPPCORO_COMPILER_MSVC
74+
# if defined(_M_IX86)
75+
# define CPPCORO_CPU_X86 1
76+
# endif
77+
#elif CPPCORO_COMPILER_GCC || CPPCORO_COMPILER_CLANG
78+
# if defined(__i386__)
79+
# define CPPCORO_CPU_X86 1
80+
# endif
81+
#endif
82+
#if !defined(CPPCORO_CPU_X86)
83+
# define CPPCORO_CPU_X86 0
84+
#endif
85+
86+
/// \def CPPCORO_CPU_X64
87+
/// Defined to 1 if the target CPU is x64 family.
88+
#if CPPCORO_COMPILER_MSVC
89+
# if defined(_M_X64)
90+
# define CPPCORO_CPU_X64 1
91+
# endif
92+
#elif CPPCORO_COMPILER_GCC || CPPCORO_COMPILER_CLANG
93+
# if defined(__x86_64__)
94+
# define CPPCORO_CPU_X64 1
95+
# endif
96+
#endif
97+
#if !defined(CPPCORO_CPU_X64)
98+
# define CPPCORO_CPU_X64 0
99+
#endif
100+
101+
/// \def CPPCORO_CPU_32BIT
102+
/// Defined if compiling for a 32-bit CPU architecture.
103+
#if CPPCORO_CPU_X86
104+
# define CPPCORO_CPU_32BIT 1
105+
#else
106+
# define CPPCORO_CPU_32BIT 0
107+
#endif
108+
109+
/// \def CPPCORO_CPU_64BIT
110+
/// Defined if compiling for a 64-bit CPU architecture.
111+
#if CPPCORO_CPU_X64
112+
# define CPPCORO_CPU_64BIT 1
113+
#else
114+
# define CPPCORO_CPU_64BIT 0
115+
#endif
116+
71117
#endif

test/ip_endpoint_tests.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licenced under MIT license. See LICENSE.txt for details.
44
///////////////////////////////////////////////////////////////////////////////
55

6+
#include <cppcoro/config.hpp>
67
#include <cppcoro/net/ip_endpoint.hpp>
78

89
#include "doctest/doctest.h"
@@ -11,7 +12,20 @@ TEST_SUITE_BEGIN("ip_endpoint");
1112

1213
using namespace cppcoro::net;
1314

14-
TEST_CASE("to_string")
15+
namespace
16+
{
17+
constexpr bool isMsvc15_5X86Optimised =
18+
#if CPPCORO_COMPILER_MSVC && CPPCORO_CPU_X86 && _MSC_VER == 1912 && defined(CPPCORO_RELEASE_OPTIMISED)
19+
true;
20+
#else
21+
false;
22+
#endif
23+
}
24+
25+
// BUG: Skip this test under MSVC 15.5 x86 optimised builds due to a compiler bug
26+
// that generates bad code.
27+
// See https://developercommunity.visualstudio.com/content/problem/177151/bad-code-generation-under-x86-optimised-for-stdopt.html
28+
TEST_CASE("to_string" * doctest::skip{ isMsvc15_5X86Optimised })
1529
{
1630
ip_endpoint a = ipv4_endpoint{ ipv4_address{ 192, 168, 2, 254 }, 80 };
1731
ip_endpoint b = ipv6_endpoint{
@@ -22,7 +36,7 @@ TEST_CASE("to_string")
2236
CHECK(b.to_string() == "[2001:db8:85a3::8a2e:370:7334]:22");
2337
}
2438

25-
TEST_CASE("from_string")
39+
TEST_CASE("from_string" * doctest::skip{ isMsvc15_5X86Optimised })
2640
{
2741
CHECK(ip_endpoint::from_string("") == std::nullopt);
2842
CHECK(ip_endpoint::from_string("[foo]:123") == std::nullopt);

test/ipv6_endpoint_tests.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licenced under MIT license. See LICENSE.txt for details.
44
///////////////////////////////////////////////////////////////////////////////
55

6+
#include <cppcoro/config.hpp>
67
#include <cppcoro/net/ipv6_endpoint.hpp>
78

89
#include "doctest/doctest.h"
@@ -11,13 +12,25 @@ TEST_SUITE_BEGIN("ipv6_endpoint");
1112

1213
using namespace cppcoro::net;
1314

14-
TEST_CASE("to_string")
15+
namespace
16+
{
17+
constexpr bool isMsvc15_5X86Optimised =
18+
#if CPPCORO_COMPILER_MSVC && CPPCORO_CPU_X86 && _MSC_VER == 1912 && defined(CPPCORO_RELEASE_OPTIMISED)
19+
true;
20+
#else
21+
false;
22+
#endif
23+
}
24+
25+
// BUG: MSVC 15.5 x86 optimised builds generates bad code
26+
TEST_CASE("to_string" * doctest::skip{ isMsvc15_5X86Optimised })
1527
{
1628
CHECK(ipv6_endpoint{ ipv6_address{ 0x20010db885a30000, 0x00008a2e03707334 }, 80 }.to_string() ==
1729
"[2001:db8:85a3::8a2e:370:7334]:80");
1830
}
1931

20-
TEST_CASE("from_string")
32+
// BUG: MSVC 15.5 x86 optimised builds generates bad code
33+
TEST_CASE("from_string" * doctest::skip{ isMsvc15_5X86Optimised })
2134
{
2235
CHECK(ipv6_endpoint::from_string("") == std::nullopt);
2336
CHECK(ipv6_endpoint::from_string(" ") == std::nullopt);

0 commit comments

Comments
 (0)