A value is assigned to itself
What it finds
p->len = p->len;, a[i] = a[i];: assigning something to itself does nothing, and usually stands for an assignment to something else, as p->len = len.
A plain variable assigned to itself, x = x;, is left alone: it is a common way to silence a compiler's warning about an unused parameter or a variable that may be used before it is set.
Every name in the target must be declared in the file, so that no macro hides a call or a different object behind it. Writing a volatile object back to itself can be the point, as with a hardware register, so the type of the target must show that it is not volatile. Targets that call something, which may be a macro, are left alone, and so is everything given to a macro.
From the rule's source, self_assignment.rs.
#define REG(p) ((p)->ctrl) struct point { int x; int y; volatile int status; int cells[4];}; struct regs; void move(struct point *p, struct point q, int x, int *v, struct regs *r, int i){ p->x = p->x;tx0 reports: p->x is assigned to itself q.y = q.y;tx0 reports: q.y is assigned to itself p->cells[i] = p->cells[i];tx0 reports: p->cells[i] is assigned to itself *v = *v;tx0 reports: *v is assigned to itself p->x = x; x = x; p->status = p->status; r->ctrl = r->ctrl; REG(p) = REG(p); p->cells[i++] = p->cells[i++]; p->x += p->x;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/c:self-assignment" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/c:self-assignment] reason="..."tx0 explain tx0/c:self-assignment shows the same in the terminal. Found a false positive? Report it.