Skip to content

Commit 0646cf6

Browse files
authored
Turn opmask_with_dsts()/is_evex_mask condition into an assertion. (#7159)
Clean up instr_disassemble_opnds_noimplicit() a bit by turning conditions that are always true into assertions. opmask_with_dsts() covers both Intel and AT&T syntax, non-x86 syntaxes should never have is_evex_mask == true, and DR syntax should never get into this function, so if there is an evex mask we can be sure opmask_with_dsts() is true. Assert that.
1 parent 3676061 commit 0646cf6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

core/ir/disassemble_shared.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,13 @@ dsts_first(void)
177177
DYNAMO_OPTION(disasm_mask));
178178
}
179179

180+
#ifdef DEBUG
180181
static inline bool
181182
opmask_with_dsts(void)
182183
{
183184
return TESTANY(DR_DISASM_INTEL | DR_DISASM_ATT, DYNAMO_OPTION(disasm_mask));
184185
}
186+
#endif
185187

186188
static void
187189
internal_instr_disassemble(char *buf, size_t bufsz, size_t *sofar DR_PARAM_INOUT,
@@ -1035,7 +1037,9 @@ instr_disassemble_opnds_noimplicit(char *buf, size_t bufsz, size_t *sofar DR_PAR
10351037
*/
10361038
optype = 0;
10371039
});
1038-
bool is_evex_mask = optype_is_evex_mask_arch(optype) && opmask_with_dsts();
1040+
bool is_evex_mask = optype_is_evex_mask_arch(optype);
1041+
CLIENT_ASSERT(!is_evex_mask || opmask_with_dsts(),
1042+
"Anything here with evex mask should be opmask_with_dsts()");
10391043
if (!is_evex_mask) {
10401044
print_to_buffer(buf, bufsz, sofar, "");
10411045
printing = opnd_disassemble_noimplicit(buf, bufsz, sofar, dcontext, instr,
@@ -1077,7 +1081,9 @@ instr_disassemble_opnds_noimplicit(char *buf, size_t bufsz, size_t *sofar DR_PAR
10771081
(i == 0 && opnd_is_reg(opnd) && reg_is_fp(opnd_get_reg(opnd))));
10781082
});
10791083
if (print) {
1080-
bool is_evex_mask = optype_is_evex_mask_arch(optype) && opmask_with_dsts();
1084+
bool is_evex_mask = optype_is_evex_mask_arch(optype);
1085+
CLIENT_ASSERT(!is_evex_mask || opmask_with_dsts(),
1086+
"Anything here with evex mask should be opmask_with_dsts()");
10811087
print_to_buffer(buf, bufsz, sofar, is_evex_mask ? " {" : "");
10821088
prev = opnd_disassemble_noimplicit(buf, bufsz, sofar, dcontext, instr, optype,
10831089
opnd, prev && !is_evex_mask,
@@ -1088,12 +1094,14 @@ instr_disassemble_opnds_noimplicit(char *buf, size_t bufsz, size_t *sofar DR_PAR
10881094
}
10891095
if (is_evex_mask_pending) {
10901096
int mask_index = 0;
1091-
opnd = instr_get_src(instr, mask_index);
10921097
CLIENT_ASSERT(IF_X86_ELSE(true, false), "evex mask can only exist for x86.");
1093-
optype = instr_info_opnd_type(info, !dsts_first(), mask_index);
1098+
CLIENT_ASSERT(opmask_with_dsts(),
1099+
"Anything here with evex mask should be opmask_with_dsts()");
1100+
opnd = instr_get_src(instr, mask_index);
10941101
CLIENT_ASSERT(!instr_is_opmask(instr) && opnd_is_reg(opnd) &&
1095-
reg_is_opmask(opnd_get_reg(opnd)) && opmask_with_dsts(),
1102+
reg_is_opmask(opnd_get_reg(opnd)),
10961103
"evex mask must always be the first source.");
1104+
optype = instr_info_opnd_type(info, !dsts_first(), mask_index);
10971105
print_to_buffer(buf, bufsz, sofar, " {");
10981106
opnd_disassemble_noimplicit(buf, bufsz, sofar, dcontext, instr, optype, opnd,
10991107
false, multiple_encodings, dsts_first(), &mask_index);

0 commit comments

Comments
 (0)