+static int
+verify_tabref(int type, int row, struct castr *ca, int idx, long val)
+{
+ int tabno = ca->ca_table;
+ struct castr *ca_sym = ef_cadef(tabno);
+ int i;
+
+ if (ca->ca_flags & NSC_BITS) {
+ /* symbol set */
+ if (CANT_HAPPEN(ca_sym != symbol_ca))
+ return -1;
+ for (i = 0; i < (int)sizeof(long) * 8; i++) {
+ if (val & (1L << i)) {
+ if (!symbol_by_value(1L << i, ef_ptr(tabno, 0))) {
+ verify_fail(type, row, ca, idx,
+ "bit %d is not in symbol table %s",
+ i, ef_nameof(tabno));
+ return -1;
+ }
+ }
+ }
+ } else if (ca_sym == symbol_ca) {
+ /* symbol */
+ if (!symbol_by_value(val, ef_ptr(tabno, 0))) {
+ verify_fail(type, row, ca, idx,
+ "value %ld is not in symbol table %s",
+ val, ef_nameof(tabno));
+ return -1;
+ }
+ } else {
+ /* table index */
+ if (val >= ef_nelem(tabno) || val < -1) {
+ verify_fail(type, row, ca, idx,
+ "value %ld indexes table %s out of bounds 0..%d",
+ val, ef_nameof(tabno), ef_nelem(tabno));
+ return -1;
+ }
+ }
+ return 0;
+}
+