Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRFairhurst committed Dec 19, 2024
1 parent ae63dcb commit 8403a4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
24 changes: 11 additions & 13 deletions c/misra/src/rules/RULE-13-2/UnsequencedAtomicReads.ql
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,20 @@ class AtomicAccessInFullExpressionOrdering extends Ordering::Configuration {

/**
* A read of a variable specified as `_Atomic`.
*
*
* Note, it may be accessed directly, or by passing its address into the std atomic functions.
*/
class AtomicVariableAccess extends VariableAccess {
pragma[noinline]
AtomicVariableAccess() {
getTarget().getType().hasSpecifier("atomic")
}
AtomicVariableAccess() { getTarget().getType().hasSpecifier("atomic") }

/* Get the `atomic_<read|write>()` call this VarAccess occurs in. */
FunctionCall getAtomicFunctionCall() {
exists(AddressOfExpr addrParent, FunctionCall fc |
fc.getTarget().getName().matches("__c11_atomic%") and
addrParent = fc.getArgument(0) and
addrParent.getAnOperand() = this
and result = fc
addrParent.getAnOperand() = this and
result = fc
)
}

Expand All @@ -59,8 +57,8 @@ class AtomicVariableAccess extends VariableAccess {
result = getAtomicFunctionCall().getArgument(1)
or
exists(AssignExpr assign |
assign.getLValue() = this
and result = assign.getRValue()
assign.getLValue() = this and
result = assign.getRValue()
)
}

Expand All @@ -75,8 +73,8 @@ class AtomicVariableAccess extends VariableAccess {
}

from
AtomicAccessInFullExpressionOrdering config, FullExpr e, Variable v,
AtomicVariableAccess va1, AtomicVariableAccess va2
AtomicAccessInFullExpressionOrdering config, FullExpr e, Variable v, AtomicVariableAccess va1,
AtomicVariableAccess va2
where
not isExcluded(e, SideEffects3Package::unsequencedAtomicReadsQuery()) and
e = va1.(ConstituentExpr).getFullExpr() and
Expand All @@ -89,6 +87,6 @@ where
TaintTracking::localTaint(DataFlow::exprNode(va2.getARead()), DataFlow::exprNode(write))
) and
// Impose an ordering, show the first access.
va1.getLocation().isBefore(va2.getLocation(), _)
select e, "Atomic variable $@ has a $@ that is unsequenced with $@.",
v, v.getName(), va1, "previous read", va2, "another read"
va1.getLocation().isBefore(va2.getLocation(), _)
select e, "Atomic variable $@ has a $@ that is unsequenced with $@.", v, v.getName(), va1,
"previous read", va2, "another read"
8 changes: 4 additions & 4 deletions c/misra/test/rules/RULE-13-2/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ void unsequenced_sideeffects2() {

void atomics() {
_Atomic int a1, a2;
int l3 = a1 + a2; // COMPLIANT
int l4 = a1 + a1; // NON_COMPLIANT
a1 = a1 + 1; // COMPLIANT
int l3 = a1 + a2; // COMPLIANT
int l4 = a1 + a1; // NON_COMPLIANT
a1 = a1 + 1; // COMPLIANT
atomic_load(&a1) + atomic_load(&a1); // NON_COMPLIANT
atomic_load(&a1) + atomic_load(&a2); // COMPLIANT
atomic_store(&a1, atomic_load(&a1)); // COMPLIANT
atomic_store(&a1, a1); // COMPLIANT
atomic_store(&a1, a1); // COMPLIANT
}

0 comments on commit 8403a4b

Please sign in to comment.