Skip to content

Commit 6648add

Browse files
committed
Add error messages to invariants/static asserts
Some static asserts/invariants just had "" as an error message.
1 parent d7bb1d4 commit 6648add

File tree

6 files changed

+33
-16
lines changed

6 files changed

+33
-16
lines changed

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class method_handle_infot : public structured_pool_entryt
414414
}
415415
case method_handle_kindt::REF_invokeInterface:
416416
{
417-
INVARIANT(ref_entry.get_tag() == CONSTANT_InterfaceMethodref, "");
417+
INVARIANT(ref_entry.get_tag() == CONSTANT_InterfaceMethodref, "4.4.8");
418418
break;
419419
}
420420
}

src/solvers/floatbv/float_bv.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,9 @@ void float_bvt::normalization_shift(
893893
if_exprt(prefix_is_zero, shifted, fraction);
894894

895895
// add corresponding weight to exponent
896-
INVARIANT(d < (signed int)exponent_bits, "");
896+
INVARIANT(
897+
d < (signed int)exponent_bits,
898+
"depth must be smaller than exponent bits");
897899

898900
exponent_delta=
899901
bitor_exprt(exponent_delta,

src/solvers/floatbv/float_utils.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ literalt float_utilst::relation(
578578
else if(rel==relt::GE)
579579
return relation(src2, relt::LE, src1); // swapped
580580

581-
INVARIANT(rel == relt::EQ || rel == relt::LT || rel == relt::LE, "");
581+
PRECONDITION(rel == relt::EQ || rel == relt::LT || rel == relt::LE);
582582

583583
// special cases: -0 and 0 are equal
584584
literalt is_zero1=is_zero(src1);
@@ -797,7 +797,8 @@ void float_utilst::normalization_shift(bvt &fraction, bvt &exponent)
797797
for(int d=depth-1; d>=0; d--)
798798
{
799799
std::size_t distance=(1<<d);
800-
INVARIANT(fraction.size() > distance, "");
800+
INVARIANT(
801+
fraction.size() > distance, "fraction must be larger than distance");
801802

802803
// check if first 'distance'-many bits are zeros
803804
const bvt prefix=bv_utils.extract_msb(fraction, distance);
@@ -812,7 +813,9 @@ void float_utilst::normalization_shift(bvt &fraction, bvt &exponent)
812813
bv_utils.select(prefix_is_zero, shifted, fraction);
813814

814815
// add corresponding weight to exponent
815-
INVARIANT(d < (signed)exponent_delta.size(), "");
816+
INVARIANT(
817+
d < (signed)exponent_delta.size(),
818+
"depth must be smaller than exponent size");
816819
exponent_delta[d]=prefix_is_zero;
817820
}
818821

@@ -1209,7 +1212,7 @@ float_utilst::unbiased_floatt float_utilst::unpack(const bvt &src)
12091212
result.fraction.push_back(is_normal(src)); // add hidden bit
12101213

12111214
result.exponent=get_exponent(src);
1212-
INVARIANT(result.exponent.size() == spec.e, "");
1215+
CHECK_RETURN(result.exponent.size() == spec.e);
12131216

12141217
// unbias the exponent
12151218
literalt denormal=bv_utils.is_zero(result.exponent);

src/util/small_map.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class small_mapt
7373
}
7474

7575
private:
76-
static_assert(std::is_unsigned<Ind>::value, "");
76+
static_assert(std::is_unsigned<Ind>::value, "Ind should be an unsigned type");
7777

7878
typedef Ind index_fieldt;
7979

@@ -167,7 +167,7 @@ class small_mapt
167167

168168
static const std::size_t NUM = Num;
169169

170-
static_assert(NUM >= 2, "");
170+
static_assert(NUM >= 2, "NUM should be at least 2");
171171

172172
static constexpr std::size_t num_bits(const std::size_t n)
173173
{
@@ -187,9 +187,11 @@ class small_mapt
187187

188188
static const index_fieldt MASK = ((index_fieldt)1 << BITS) - 1;
189189

190-
static_assert(S_BITS <= N_BITS, "");
190+
static_assert(S_BITS <= N_BITS, "S_BITS should be no larger than N_BITS");
191191

192-
static_assert(std::numeric_limits<unsigned>::digits >= BITS, "");
192+
static_assert(
193+
std::numeric_limits<unsigned>::digits >= BITS,
194+
"BITS must fit into an unsigned");
193195

194196
// Internal
195197

src/util/small_shared_two_way_ptr.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ class small_shared_two_way_ptrt final
3838

3939
typedef small_shared_two_way_pointeet<use_countt> pointeet;
4040

41-
static_assert(std::is_base_of<pointeet, U>::value, "");
42-
static_assert(std::is_base_of<pointeet, V>::value, "");
41+
static_assert(
42+
std::is_base_of<pointeet, U>::value,
43+
"pointeet must be a base of U");
44+
static_assert(
45+
std::is_base_of<pointeet, V>::value,
46+
"pointeet must be a base of V");
4347

4448
small_shared_two_way_ptrt() = default;
4549

@@ -217,7 +221,7 @@ template <typename Num>
217221
class small_shared_two_way_pointeet
218222
{
219223
public:
220-
static_assert(std::is_unsigned<Num>::value, "");
224+
static_assert(std::is_unsigned<Num>::value, "Num must be an unsigned type");
221225

222226
static const int bit_idx = std::numeric_limits<Num>::digits - 1;
223227
static const Num mask = ~((Num)1 << bit_idx);

src/util/validate_helpers.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ enum class validation_modet;
1717
template <typename Base, typename T>
1818
struct call_checkt
1919
{
20-
static_assert(std::is_base_of<Base, T>::value, "");
20+
static_assert(
21+
std::is_base_of<Base, T>::value,
22+
"T should be derived from Base");
2123

2224
void operator()(const Base &base, const validation_modet vm)
2325
{
@@ -28,7 +30,9 @@ struct call_checkt
2830
template <typename Base, typename T>
2931
struct call_validatet
3032
{
31-
static_assert(std::is_base_of<Base, T>::value, "");
33+
static_assert(
34+
std::is_base_of<Base, T>::value,
35+
"T should be derived from Base");
3236

3337
void
3438
operator()(const Base &base, const namespacet &ns, const validation_modet vm)
@@ -40,7 +44,9 @@ struct call_validatet
4044
template <typename Base, typename T>
4145
struct call_validate_fullt
4246
{
43-
static_assert(std::is_base_of<Base, T>::value, "");
47+
static_assert(
48+
std::is_base_of<Base, T>::value,
49+
"T should be derived from Base");
4450

4551
void
4652
operator()(const Base &base, const namespacet &ns, const validation_modet vm)

0 commit comments

Comments
 (0)