Skip to content

Commit 9d41b0c

Browse files
author
thk123
committed
Disable nested exception printing for Windows
Due to bug in the VS2013 C++ compiler, using std::rethrow_if_nested or std::nested_exception is not supported. This disables trying to unwrap the exception and just prints a warning saying the nested exceptionc couldn't be printed. Don't use noexcept directly, pull both part of the nested exception into a separate file to handle discrepancies.
1 parent b866015 commit 9d41b0c

6 files changed

+71
-8
lines changed

src/goto-symex/equation_conversion_exceptions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class guard_conversion_exceptiont : public std::runtime_error
4040
{
4141
}
4242

43-
const char *what() const noexcept override
43+
const char *what() const optional_noexcept override
4444
{
4545
return error_message.c_str();
4646
}

src/goto-symex/symex_target_equation.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#include "symex_target_equation.h"
1313

1414
#include <util/std_expr.h>
15+
#include <util/throw_with_nested.h>
1516
#include <util/unwrap_nested_exception.h>
1617

1718
#include <langapi/language_util.h>
@@ -437,7 +438,7 @@ void symex_target_equationt::convert_guards(
437438
}
438439
catch(const bitvector_conversion_exceptiont &conversion_exception)
439440
{
440-
std::throw_with_nested(guard_conversion_exceptiont(step, ns));
441+
util_throw_with_nested(guard_conversion_exceptiont(step, ns));
441442
}
442443
}
443444
}

src/solvers/flattening/boolbv_byte_extract.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414
#include <util/byte_operators.h>
1515
#include <util/endianness_map.h>
1616
#include <util/std_expr.h>
17+
#include <util/throw_with_nested.h>
1718

1819
#include "bv_conversion_exceptions.h"
1920
#include "flatten_byte_extract_exceptions.h"
@@ -51,7 +52,7 @@ bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
5152
}
5253
catch(const flatten_byte_extract_exceptiont &byte_extract_flatten_exception)
5354
{
54-
std::throw_with_nested(
55+
util_throw_with_nested(
5556
bitvector_conversion_exceptiont("Can't convert byte_extraction", expr));
5657
}
5758
}

src/solvers/flattening/flatten_byte_extract_exceptions.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class non_const_array_sizet : public flatten_byte_extract_exceptiont
4040
computed_error_message = error_message.str();
4141
}
4242

43-
const char *what() const noexcept override
43+
const char *what() const optional_noexcept override
4444
{
4545
return computed_error_message.c_str();
4646
}
@@ -73,7 +73,7 @@ class non_byte_alignedt : public flatten_byte_extract_exceptiont
7373
computed_error_message = error_message.str();
7474
}
7575

76-
const char *what() const noexcept override
76+
const char *what() const optional_noexcept override
7777
{
7878
return computed_error_message.c_str();
7979
}
@@ -103,7 +103,7 @@ class non_constant_widtht : public flatten_byte_extract_exceptiont
103103
computed_error_message = error_message.str();
104104
}
105105

106-
const char *what() const noexcept override
106+
const char *what() const optional_noexcept override
107107
{
108108
return computed_error_message.c_str();
109109
}
@@ -130,7 +130,7 @@ class non_const_byte_extraction_sizet : public flatten_byte_extract_exceptiont
130130
computed_error_message = error_message.str();
131131
}
132132

133-
const char *what() const noexcept override
133+
const char *what() const optional_noexcept override
134134
{
135135
return computed_error_message.c_str();
136136
}

src/util/throw_with_nested.h

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*******************************************************************\
2+
3+
Module: util
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_UTIL_THROW_WITH_NESTED_H
10+
#define CPROVER_UTIL_THROW_WITH_NESTED_H
11+
12+
#include <exception>
13+
14+
#ifdef _MSC_VER
15+
#include <stdexcept>
16+
// TODO(tkiley): Nested exception logging not supported on windows due to a bug
17+
// TODO(tkiley): in MSVC++ Compiler (diffblue/cbmc#2104):
18+
// TODO(tkiley): https://blogs.msdn.microsoft.com/vcblog/2016/01/22/vs-2015-update-2s-stl-is-c17-so-far-feature-complete
19+
20+
#define DISABLE_NESTED_EXCEPTIONS
21+
22+
class non_nested_exception_support : public std::runtime_error
23+
{
24+
public:
25+
non_nested_exception_support()
26+
: std::runtime_error("Nested exception printing not supported on Windows")
27+
{
28+
}
29+
};
30+
31+
#endif
32+
33+
template <class T>
34+
#ifdef __GNUC__
35+
__attribute__((noreturn))
36+
#endif
37+
void util_throw_with_nested(T &&t)
38+
{
39+
#ifndef DISABLE_NESTED_EXCEPTIONS
40+
std::throw_with_nested(t);
41+
#else
42+
throw t;
43+
#endif
44+
}
45+
46+
template <class E>
47+
void util_rethrow_if_nested(const E &e)
48+
{
49+
#ifndef DISABLE_NESTED_EXCEPTIONS
50+
std::rethrow_if_nested(e);
51+
#else
52+
// Check we've not already thrown the non_nested_support_exception
53+
if(!dynamic_cast<const non_nested_exception_support *>(&e))
54+
{
55+
throw non_nested_exception_support();
56+
}
57+
#endif
58+
}
59+
60+
#endif // CPROVER_UTIL_THROW_WITH_NESTED_H

src/util/unwrap_nested_exception.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Diffblue Ltd.
1010
#include "invariant.h"
1111
#include "string_utils.h"
1212
#include "suffix.h"
13+
#include "throw_with_nested.h"
1314

1415
#include <sstream>
1516
#include <vector>
@@ -32,7 +33,7 @@ std::string unwrap_exception(const std::exception &e, int level)
3233

3334
try
3435
{
35-
std::rethrow_if_nested(e);
36+
util_rethrow_if_nested(e);
3637
}
3738
catch(const std::exception &e)
3839
{

0 commit comments

Comments
 (0)