`A7-1-7`: Exclude expression statements in macros
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
Research direction
Inspect the A7-1-7 query and the bracketing around macro-expanded declarations and expression statements. Use the provided foo(a, b) C++ example to examine how locations are assigned during macro expansion. Done means the example is excluded as compliant without incorrectly removing unrelated expression statements.
Written by the indexing model from the issue text.
Description
Affected rules
A7-1-7
Description
Macro expansion can cause multiple expressions and statements to appear at the same location. We exclude macro expanded declarations, I think we should do the same for expression statements.
Reviewing the query, I think this is actually caused by a bracketing issue:
not isAffectedByMacro() and
// MISSING OPENING BRACKET HERE
exists(Declaration d |
...
)
or
this instanceof ExprStmt and
not exists(ForStmt f | f.getInitialization().getAChild*() = this) and
not exists(LambdaExpression l | l.getLambdaFunction().getBlock().getAChild*() = this)
// MISSING CLOSED BRACKET HERE
There's also an interesting thing happening here with locations - as we might expect such macro expansions to by the not l1 = l2 line in the select clause:
exists(Location l1, Location l2 |
e1.getLocation() = l1 and
e2.getLocation() = l2 and
not l1 = l2 and
....
The reason this doesn't exclude this case is that when we expand the macro, we may provide different locations for the expressions and statements within, if we can associate them with a specific macro parameter.
Example
#define foo(x, y) \
x++; \
y++;
void test_macro() {
int a = 1;
int b = 1;
foo(a, b); // COMPLIANT
}
- Dominant language
- CodeQL
- Stars
- 227
- Forks
- 82
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 9
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from github/codeql-coding-standards
-
false positive/false negative Stardard-MISRA-C++
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
github/codeql-coding-standards#1172 ·
-
Difficulty-Low false positive/false negative false-negative Impact-Low Standard-MISRA-C
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty-Medium false positive/false negative false-positive Impact-Medium Standard-CERT-C
Difficulty 4/5 3-5 days Newbie friendliness 48/100
github/codeql-coding-standards#1200 ·
-
`RULE-0-0-1`: "unreachable statement" false positives due to over-pruning of the control-flow graph Openfalse positive/false negative
Difficulty 4/5 3-5 days Newbie friendliness 48/100
github/codeql-coding-standards#1190 ·
-
false positive/false negative
Difficulty 3/5 1-2 days Newbie friendliness 65/100
github/codeql-coding-standards#1175 ·
All issues in github/codeql-coding-standards
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ScoopInstaller/Nonportable#639 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ScoopInstaller/Extras#18800 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
uqbar-project/website-wollok-ts#84 · 2 comments ·
-
on hold T: core-bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100