Skip to content

Commit 0683d4c

Browse files
Address feedback.
1 parent d214ba7 commit 0683d4c

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

c/misra/src/rules/RULE-8-15/RedeclarationOfObjectWithUnmatchedAlignment.ql

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,10 @@
1515

1616
import cpp
1717
import codingstandards.c.misra
18-
19-
predicate lexicallyEqualExpr(Expr a, Expr b) {
20-
a.toString() = b.toString() and
21-
a.getNumChild() = b.getNumChild() and
22-
forall(Expr aChild, Expr bChild, int i |
23-
aChild = a.getChild(i) and
24-
bChild = b.getChild(i) and
25-
i < a.getNumChild()
26-
|
27-
lexicallyEqualExpr(aChild, bChild)
28-
)
29-
}
18+
import semmle.code.cpp.valuenumbering.HashCons
3019

3120
predicate lexicallyEqual(AttributeArgument a, AttributeArgument b) {
32-
lexicallyEqualExpr(a.getValueConstant(), b.getValueConstant()) or
21+
hashCons(a.getValueConstant()) = hashCons(b.getValueConstant()) or
3322
a.getValueType() = b.getValueType()
3423
}
3524

c/misra/src/rules/RULE-8-15/RedeclarationOfObjectWithoutAlignment.ql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ newtype TAttributeDeclLocation =
4646
* This should give us a highly reliable means of finding which attributes are
4747
* associated with which `DeclarationEntry`s.
4848
*
49-
* One note of caution: the associated `Variable` must be treated with caution,
50-
* as there are multiple instances of that `Variable` if it is declared
51-
* multiple times, they equal each other, and `getLocation()` on each variable
52-
* returns every location result. This class must act on `DeclarationEntry`s to
49+
* One note of caution: the location of the associated `Variable` must be
50+
* treated with caution, as calls to `getLocation()` on a redeclared `Variable`
51+
* can return multiple results. This class must act on `DeclarationEntry`s to
5352
* deliver reliable results.
5453
*/
5554
class DeclarationEntryAttribute extends Attribute {

c/misra/src/rules/RULE-8-17/MoreThanOneAlignmentSpecifierOnDeclaration.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ where
2020
not isExcluded(v, AlignmentPackage::moreThanOneAlignmentSpecifierOnDeclarationQuery()) and
2121
first = v.getAnAttribute() and
2222
last = v.getAnAttribute() and
23-
first != last and
23+
not first = last and
2424
first.hasName("_Alignas") and
2525
last.hasName("_Alignas") and
26+
// Handle double reporting: the first Attribute should really be first, and the last Attribute
27+
// should really be last. This implies the first is before the last. This approach also ensures
28+
// a single result for variables that have more than two alignment specifiers.
2629
not exists(Attribute beforeFirst |
2730
beforeFirst.getLocation().isBefore(first.getLocation(), _) and
2831
v.getAnAttribute() = beforeFirst

0 commit comments

Comments
 (0)