• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SRI-CSL / yices2 / 44167754935

17 Nov 2026 08:17PM UTC coverage: 71.322% (+0.003%) from 71.319%
44167754935

Pull #697

github

web-flow
Merge 10b1dd050 into ccdf89988
Pull Request #697: Integrate Yices 2.8.0 licensing and release fixes into master

96243 of 134941 relevant lines covered (71.32%)

1720253.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/parser_utils/term_stack_error.c
1
/*
2
 * Copyright (c) 2026, SRI International
3
 * SPDX-License-Identifier: BSD-3-Clause
4
 */
5

6
/*
7
 * ERROR MESSAGES/DIAGNOSIS ON EXCEPTION RAISED BY TERM STACK
8
 */
9

10
#if defined(CYGWIN) || defined(MINGW)
11
#ifndef __YICES_DLLSPEC__
12
#define __YICES_DLLSPEC__ __declspec(dllexport)
13
#endif
14
#endif
15

16
#include <stdint.h>
17
#include <stdbool.h>
18
#include <inttypes.h>
19
#include <assert.h>
20

21
#include "api/yices_error.h"
22
#include "frontend/yices/yices_tstack_ops.h"
23
#include "parser_utils/term_stack_error.h"
24

25
#include "yices.h"
26
#include "yices_exit_codes.h"
27

28

29
/*
30
 * Error messages
31
 */
32
static const char * const code2string[NUM_TSTACK_ERRORS] = {
33
  "no error",
34
  "internal error",
35
  "operation not supported",
36
  "undefined term",
37
  "undefined type",
38
  "undefined type macro",
39
  "invalid rational format",
40
  "invalid float format",
41
  "invalid bitvector binary format",
42
  "invalid bitvector hexadecimal format",
43
  "cannot redefine type",
44
  "cannot redefine term",
45
  "cannot redefine type macro",
46
  "duplicate name",
47
  "duplicate variable name",
48
  "duplicate type name",
49
  "invalid operation",
50
  "wrong number of arguments",
51
  "constant too large",
52
  "exponent must be non-negative",
53
  "constant is not an integer",
54
  "string required",
55
  "symbol required",
56
  "numerical constant required",
57
  "type required",
58
  "error in arithmetic operation",
59
  "division by zero",
60
  "divisor is not a constant",
61
  "size must be positive",
62
  "bitvectors have incompatible sizes",
63
  "number cannot be converted to a bitvector",
64
  "error in bitvector arithmetic operation",
65
  "error in bitvector operation",
66
  "invalid finite field constant",
67
  "invalid finite field order",
68
  "incompatible finite field sizes",
69
  "incompatible types in define",
70
  "strings are not terms",
71
  "variable values are not matching",
72
  "not a constant",
73
  "not a variable",
74
  "yices error",
75
};
76

77

78
/*
79
 * Translation of term-stack opcodes to string.
80
 *
81
 * We use two tables because some operators have a different name in
82
 * the SMT-LIB notation and in the Yices language.
83
 */
84
static const char * const opcode2smt_string[NUM_BASE_OPCODES] = {
85
  "no_op",
86

87
  "define-type",
88
  "define",
89

90
  "bind",
91
  "var declaration",
92
  "type-var declaration",  // for SMT2
93
  "let",
94

95
  "bitvector type",
96
  "finite field type", // not in SMT2
97
  "scalar type",   // not in SMT
98
  "tuple type",    // not in SMT
99
  "function type",
100
  "macro application",  // for SMT2
101

102
  "function application",
103
  "if-then-else",
104
  "equality",
105
  "disequality",
106
  "distinct",
107
  "not",
108
  "or",
109
  "and",
110
  "xor",
111
  "iff",
112
  "implies",
113
  "mk-tuple", // not in SMT
114
  "select",   // not in SMT
115
  "tuple update", // not in SMT
116
  "store",
117
  "forall",
118
  "exists",
119
  "lambda",  // not in SMT
120

121
  "addition",
122
  "subtraction",
123
  "negation",
124
  "multiplication",
125
  "division",
126
  "exponentiation", // not in SMT
127
  "inequality",
128
  "inequality",
129
  "inequality",
130
  "inequality",
131

132
  "bv constant",
133
  "bvadd",
134
  "bvsub",
135
  "bvmul",
136
  "bvneg",
137
  "bvpow",   // not in SMT
138
  "bvudiv",
139
  "bvurem",
140
  "bvsdiv",
141
  "bvsrem",
142
  "bvsmod",
143

144
  "bvnot",
145
  "bvand",
146
  "bvor",
147
  "bvxor",
148
  "bvnand",
149
  "bvnor",
150
  "bvxnor",
151

152
  "shift_left0",
153
  "shift_left1",
154
  "shift_right0",
155
  "shift_right1",
156
  "ashift_right",
157
  "rotate_left",
158
  "rotate_right",
159

160
  "bvshl",
161
  "bvlshr",
162
  "bvashr",
163

164
  "extract",
165
  "concat",
166
  "repeat",
167
  "sign_extend",
168
  "zero_extend",
169

170
  "bvredand",
171
  "bvredor",
172
  "bvcomp",
173

174
  "bitvector inequality",
175
  "bitvector inequality",
176
  "bitvector inequality",
177
  "bitvector inequality",
178
  "bitvector inequality",
179
  "bitvector inequality",
180
  "bitvector inequality",
181
  "bitvector inequality",
182

183
  "bool-to-bv",  // not in SMT
184
  "bit",         // not in SMT
185

186
  "floor",       // not in SMT
187
  "ceil",        // not in SMT
188
  "abs",         // not in SMT
189
  "div",         // not in SMT
190
  "mod",         // not in SMT
191
  "divides",     // not in SMT
192
  "is_int",      // not in SMT
193

194
  "ff constant", // not in SMT
195
  "ff.add",      // not in SMT
196
  "ff.mul",      // not in SMT
197

198
  "build term",
199
  "build type",
200
};
201

202

203

204
/*
205
 * Translate opcode to string: Yices version has more opcodes
206
 */
207
static const char * const opcode2yices_string[NUM_YICES_OPCODES] = {
208
  "no_op",
209

210
  "define-type",
211
  "define",
212

213
  "bind",
214
  "var declaration",
215
  "type-var declaration",  // SMT2 only
216
  "let",
217

218
  "bitvector type",
219
  "finite field type",
220
  "scalar type",
221
  "tuple type",
222
  "function type",
223
  "type-macro application", // SMT2
224

225
  "function application",
226
  "if-then-else",
227
  "equality",
228
  "disequality",
229
  "distinct",
230
  "not",
231
  "or",
232
  "and",
233
  "xor",
234
  "<=>",
235
  "=>",
236
  "mk-tuple",
237
  "select",
238
  "tuple update",
239
  "update",
240
  "forall",
241
  "exists",
242
  "lambda",
243

244
  "addition",
245
  "subtraction",
246
  "negation",
247
  "multiplication",
248
  "division",
249
  "exponentiation",
250
  "inequality",
251
  "inequality",
252
  "inequality",
253
  "inequality",
254

255
  "mk-bv",
256
  "bv-add",
257
  "bv-sub",
258
  "bv-mul",
259
  "bv-neg",
260
  "bv-pow",
261
  "bv-udiv",
262
  "bv-urem",
263
  "bv-sdiv",
264
  "bv-srem",
265
  "bv-smod",
266

267
  "bv-not",
268
  "bv-and",
269
  "bv-or",
270
  "bv-xor",
271
  "bv-nand",
272
  "bv-nor",
273
  "bv-xnor",
274

275
  "bv-shift-left0",
276
  "bv-shift-left1",
277
  "bv-shift-right0",
278
  "bv-shift-right1",
279
  "bv-ashift-right",
280
  "bv-rotate-left",
281
  "bv-rotate-right",
282

283
  "bv-shl",
284
  "bv-lshr",
285
  "bv-ashr",
286

287
  "bv-extract",
288
  "bv-concat",
289
  "bv-repeat",
290
  "bv-sign-extend",
291
  "bv-zero-extend",
292

293
  "bv-redand",
294
  "bv-redor",
295
  "bv-comp",
296

297
  "bitvector inequality",
298
  "bitvector inequality",
299
  "bitvector inequality",
300
  "bitvector inequality",
301
  "bitvector inequality",
302
  "bitvector inequality",
303
  "bitvector inequality",
304
  "bitvector inequality",
305

306
  "bool-to-bv",
307
  "bit",
308

309
  "floor",
310
  "ceil",
311
  "abs",
312
  "div",
313
  "mod",
314
  "divides",
315
  "is_int",
316

317
  "ff constant",
318
  "ff-add",
319
  "ff-mul",
320

321
  "build term",
322
  "build type",
323

324
  // commands in yices_tstack_ops.h
325
  "define-type",
326
  "define",
327
  "exit",
328
  "assert",
329
  "check",
330
  "show-model",
331
  "eval",
332
  "push",
333
  "pop",
334
  "reset",
335
  "echo",
336
  "include",
337
  "set-param",
338
  "show-param",
339
  "show-params",
340
  "show-stats",
341
  "reset-stats",
342
  "set-timeout",
343
  "show-timeout",
344
  "help",
345
  "ef-solve",
346
  "export-to-dimacs",
347
  "show-implicant",
348
  "dump-context",
349
};
350

351

352

353

354
/*
355
 * BUG in Yices: Print an error message then exit
356
 */
357
void report_bug(const char *s) {
×
358
  fprintf(stderr, "\n*************************************************************\n");
×
359
  fprintf(stderr, "FATAL ERROR: %s\n\n", s);
×
360
  fprintf(stderr, "Please report this bug to yices-bugs@csl.sri.com.\n");
×
361
  fprintf(stderr, "To help us diagnose this problem, please include the\n"
×
362
                  "following information in your bug report:\n\n");
363
  fprintf(stderr, "  Yices version: %s\n", yices_version);
×
364
  fprintf(stderr, "  Build date: %s\n", yices_build_date);
×
365
  fprintf(stderr, "  Platform: %s (%s)\n", yices_build_arch, yices_build_mode);
×
366
  fprintf(stderr, "\n");
×
367
  fprintf(stderr, "Thank you for your help.\n");
×
368
  fprintf(stderr, "*************************************************************\n\n");
×
369
  fflush(stderr);
×
370

371
  exit(YICES_EXIT_INTERNAL_ERROR);
×
372
}
373

374

375

376

377
/*
378
 * Error reported by term_api:
379
 * - tstack->error_op = operation being executed
380
 * - tstack->error_loc = location of the argument expression (approximative)
381
 *   that triggered the error
382
 * - opcode2string = either opcoode2yicse_string or opecode2smt_string
383
 */
384
static void yices_error(FILE *f, const char *name, tstack_t *tstack, const char * const opcode2string[]) {
×
385
  if (name != NULL) {
×
386
    fprintf(f, "%s: ", name);
×
387
  }
388
  fprintf(f, "error in %s, line %"PRId32", column %"PRId32": ",
×
389
          opcode2string[tstack->error_op], tstack->error_loc.line, tstack->error_loc.column);
×
390

391
  print_error(f);
×
392
}
×
393

394

395

396
/*
397
 * Print an error message for the given exception
398
 */
399
static void base_term_stack_error(FILE *f, const char *name, tstack_t *tstack, tstack_error_t exception, const char * const opcode2string[]) {
×
400
  assert(exception != TSTACK_NO_ERROR);
401

402
  if (exception == TSTACK_YICES_ERROR) {
×
403
    yices_error(f, name, tstack, opcode2string);
×
404
    return;
×
405
  }
406

407
  if (name == NULL) {
×
408
    fprintf(f, "Error: %s ", code2string[exception]);
×
409
  } else {
410
    fprintf(f, "%s: %s ", name, code2string[exception]);
×
411
  }
412

413
  switch (exception) {
×
414
  case TSTACK_INTERNAL_ERROR:
×
415
  case TSTACK_INVALID_OP:
416
  case TSTACK_NOT_A_SYMBOL:
417
  case TSTACK_NOT_A_TYPE:
418
  case TSTACK_STRINGS_ARE_NOT_TERMS:  // should never be raised by the yices or smt1 parser
419
    fprintf(f, "Internal exception: opcode = %"PRId32"\n", (int32_t) tstack->error_op);
×
420
    report_bug("Term-stack error");
×
421
    break;
422

423
  case TSTACK_INVALID_FRAME:
×
424
  case TSTACK_NONPOSITIVE_BVSIZE:
425
    fprintf(f, "in %s (line %"PRId32", column %"PRId32")\n",
×
426
            opcode2string[tstack->error_op], tstack->error_loc.line, tstack->error_loc.column);
×
427
    break;
×
428

429
  case TSTACK_OP_NOT_IMPLEMENTED:
×
430
    fprintf(f, "(%s)\n", opcode2string[tstack->error_op]);
×
431
    break;
×
432

433
  case TSTACK_UNDEF_TERM:
×
434
  case TSTACK_UNDEF_TYPE:
435
  case TSTACK_UNDEF_MACRO:
436
  case TSTACK_DUPLICATE_SCALAR_NAME:
437
  case TSTACK_DUPLICATE_VAR_NAME:
438
  case TSTACK_DUPLICATE_TYPE_VAR_NAME:
439
  case TSTACK_RATIONAL_FORMAT:
440
  case TSTACK_FLOAT_FORMAT:
441
  case TSTACK_BVBIN_FORMAT:
442
  case TSTACK_BVHEX_FORMAT:
443
  case TSTACK_TYPENAME_REDEF:
444
  case TSTACK_TERMNAME_REDEF:
445
  case TSTACK_MACRO_REDEF:
446
    fprintf(f, "%s (line %"PRId32", column %"PRId32")\n",
×
447
            tstack->error_string, tstack->error_loc.line, tstack->error_loc.column);
448
    break;
×
449

450
  case TSTACK_INTEGER_OVERFLOW:
×
451
  case TSTACK_NEGATIVE_EXPONENT:
452
  case TSTACK_NOT_AN_INTEGER:
453
  case TSTACK_NOT_A_STRING:
454
  case TSTACK_NOT_A_RATIONAL:
455
  case TSTACK_ARITH_ERROR:
456
  case TSTACK_DIVIDE_BY_ZERO:
457
  case TSTACK_NON_CONSTANT_DIVISOR:
458
  case TSTACK_INVALID_BVCONSTANT:
459
  case TSTACK_INVALID_FFCONSTANT:
460
  case TSTACK_INCOMPATIBLE_BVSIZES:
461
  case TSTACK_BVARITH_ERROR:
462
  case TSTACK_BVLOGIC_ERROR:
463
  case TSTACK_TYPE_ERROR_IN_DEFTERM:
464
  case TSTACK_VARIABLES_VALUES_NOT_MATCHING:
465
    fprintf(f, "(line %"PRId32", column %"PRId32")\n",
×
466
            tstack->error_loc.line, tstack->error_loc.column);
467
    break;
×
468

469
  default:
×
470
    fprintf(f, "Invalid error code: %"PRId32"\n", (int32_t) exception);
×
471
    report_bug("Term-stack error");
×
472
    break;
473
  }
474
}
475

476

477
/*
478
 * Error codes defined in yices_types:
479
 *   0 to  99 --> reserved for basic errors in term/type construction
480
 * 100 to 299 --> reserved for parser errors
481
 * 300 to 399 --> reserved for errors in context operations
482
 * 400 to ... --> other error codes
483
 *
484
 * The term_stack should only trigger error codes in the range [0..99]
485
 * (more exactly in the range [0 .. BAD_TYPE_DECREF].
486
 * We assign a severity to these errors, as defined below.
487
 */
488
#define NUM_YICES_ERRORS (BAD_TYPE_DECREF+1)
489

490
/*
491
 * Severity of an error:
492
 * - severity 0: means caused by incorrect input
493
 * - severity 1: means bug in SMT parser or something related
494
 * - severity 2: means bug in term_stack or Yices parser
495
 */
496
static const uint8_t severity[NUM_YICES_ERRORS] = {
497
  2, // YICES_NO_ERROR (should never be raised)
498
  2, // INVALID_TYPE
499
  2, // INVALID_TERM
500
  2, // INVALID_CONSTANT_INDEX (bug in scalar-type construction)
501
  2, // INVALID_VAR_INDEX (bug in declare-var)
502
  1, // INVALID_TUPLE_INDEX (no tuples in SMT-LIB)
503
  2, // INVALID_RATIONAL_FORMAT (raised by yices_parse_rational, which is not used in term_stack)
504
  2, // INVALID_FLOAT_FORMAT (raised by yices_parse_float, which is not used in term_stack)
505
  2, // INVALID_BVBIN_FORMAT (raised by yices_parse_bvbin)
506
  2, // INVALID_BVHEX_FORMAT (raised by yices_parse_bvhex)
507
  0, // INVALID_BITSHIFT
508
  0, // INVALID_BVEXTRACT
509
  0, // INVALID_BITEXTRACT
510
  0, // TOO_MANY_ARGUMENTS
511
  0, // TOO_MANY_VARS,
512
  0, // MAX_BVSIZE_EXCEEDED
513
  0, // DEGREE_OVERFLOW
514
  0, // DIVISION_BY_ZERO
515
  0, // POS_INT_REQUIRED
516
  0, // NONNEG_INT_REQUIREF
517
  2, // SCALAR_OR_UTYPE_REQUIRED (bug in scalar-type construction)
518
  0, // FUNCTION_REQUIRED
519
  1, // TUPLE_REQUIRED (no tuples in SMT-LIB)
520
  2, // VARIABLE_REQUIRED (bug in term_stack)
521
  0, // ARITHTERM_REQUIRED
522
  0, // BITVECTOR_REQUIRED
523
  0, // SCALAR_TERM_REQUIRED
524
  0, // WRONG_NUMBER_OF_ARGUMENTS
525
  0, // TYPE_MISMATCH
526
  0, // INCOMPATIBLE_TYPES
527
  2, // DUPLICATE_VARIABLE (bug in term_stack).
528
  0, // INCOMPATIBLE_BVSIZES
529
  2, // EMPTY_BITVECTOR
530
  2, // ARITHCONSTANT_REQUIRED (should never be raised by term stack, see eval_mk_div)
531
  2, // INVALID_MACRO (bug in term_stack)
532
  0, // TOO_MANY_MACRO_PARAMS (used for SMT-LIB 2)
533
  2, // TYPE_VAR_REQUIRED (bug in term_stack)
534
  0, // DUPLICATE_TYPE_VAR (used in SMT-LIB 2)
535
  2, // BVTYPE_REQUIRED (not used anywhere)
536
  2, // BAD_TERM_DECREF (not used by term_stack)
537
  2, // BAD_TYPE_DECREF (not used by term_stack)
538
};
539

540

541
/*
542
 * Check for fatal errors in YICES
543
 * - return true if the error is a bug
544
 */
545
static inline bool fatal_error(error_code_t error) {
×
546
  return severity[error] >= 2;
×
547
}
548

549
/*
550
 * Check for fatal errors in SMT-LIB
551
 * - return true if the error involve operations that do not exist in SMT-LIB
552
 */
553
static inline bool fatal_smt_error(error_code_t error) {
×
554
  return severity[error] >= 1;
×
555
}
556

557

558

559
/*
560
 * Print an error message on stream f for the given exception.
561
 * - if name is non- NULL, the error message is
562
 *   'name: message ...'
563
 * - if name is NULL the error message is
564
 *   'Error: message ...'
565
 * The term-stack location, top-operator, etc. are used to help locate the error.
566
 *
567
 * Abort and print a request for a bug report if the error is
568
 * internal to Yices.
569
 */
570
void term_stack_error(FILE *f, const char *name, tstack_t *tstack, tstack_error_t exception) {
×
571
  base_term_stack_error(f, name, tstack, exception, opcode2yices_string);
×
572
  if (exception == TSTACK_YICES_ERROR && fatal_error(yices_error_code())) {
×
573
    report_bug("Internal error");
×
574
  }
575
}
×
576

577

578
/*
579
 * Same thing but also abort for exceptions that should not occur in
580
 * SMT-LIB input (e.g., error codes involving tuples).
581
 */
582
void term_stack_smt_error(FILE *f, const char *name, tstack_t *tstack, tstack_error_t exception) {
×
583
  base_term_stack_error(f, name, tstack, exception, opcode2smt_string);
×
584
  if (exception == TSTACK_YICES_ERROR && fatal_smt_error(yices_error_code())) {
×
585
    report_bug("Internal error (SMT-LIB)");
×
586
  }
587
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc