From 2e3ccc75187600c10ebdfa5cb62b538c987d1b00 Mon Sep 17 00:00:00 2001 From: Scott McKay Date: Mon, 10 Aug 2020 17:54:11 +1000 Subject: [PATCH] Change order of some checks to workaround a linker issue when /LTCG:incremental is set. (#4713) --- .../test/providers/provider_test_utils.cc | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/onnxruntime/test/providers/provider_test_utils.cc b/onnxruntime/test/providers/provider_test_utils.cc index fd731fc142..687a63f339 100644 --- a/onnxruntime/test/providers/provider_test_utils.cc +++ b/onnxruntime/test/providers/provider_test_utils.cc @@ -91,11 +91,12 @@ void Check(const OpTester::Data& expected_data, #endif for (int i = 0; i < size; ++i) { - if (std::isinf(expected[i])) { // Test infinity for equality - EXPECT_EQ(expected[i], output[i]) << "i:" << i; - } else if (std::isnan(expected[i])) { - EXPECT_TRUE(std::isnan(output[i])) << "Expected output " << i - << " to be NaN"; + // NOTE: Check isnan first to work around MSVC linker bug when /LTCG:incremental is specified. + // If the isinf check is first the isnan check and branch gets omitted + if (std::isnan(expected[i])) { + EXPECT_TRUE(std::isnan(output[i])) << "Expected NaN. i:" << i << ", provider_type: " << provider_type; + } else if (std::isinf(expected[i])) { // Test infinity for equality + EXPECT_EQ(expected[i], output[i]) << "Expected infinity. i:" << i << ", provider_type: " << provider_type; } else { if (!has_abs_err && !has_rel_err) { // the default for existing tests @@ -142,11 +143,12 @@ void InternalNumericalCheck(const OpTester::Data& expected_data, #endif for (int i = 0; i < size; ++i) { - if (std::isinf(expected[i])) { // Test infinity for equality - EXPECT_EQ(expected[i], output[i]) << "i:" << i; - } else if (std::isnan(expected[i])) { - EXPECT_TRUE(std::isnan(output[i])) << "Expected output " << i - << " to be NaN"; + // NOTE: Check isnan first to work around MSVC linker bug when /LTCG:incremental is specified. + // If the isinf check is first the isnan check and branch gets omitted + if (std::isnan(expected[i])) { + EXPECT_TRUE(std::isnan(output[i])) << "Expected NaN. i:" << i << ", provider_type: " << provider_type; + } else if (std::isinf(expected[i])) { // Test infinity for equality + EXPECT_EQ(expected[i], output[i]) << "Expected infinity. i:" << i << ", provider_type: " << provider_type; } else { if (!has_abs_err && !has_rel_err) { // the default for existing tests