mirror of
https://github.com/github/codeql.git
synced 2025-12-19 10:23:15 +01:00
31 lines
1000 B
Plaintext
31 lines
1000 B
Plaintext
import cpp
|
|
import experimental.semmle.code.cpp.semantic.analysis.ModulusAnalysis
|
|
import experimental.semmle.code.cpp.semantic.Semantic
|
|
import semmle.code.cpp.ir.IR as IR
|
|
import TestUtilities.InlineExpectationsTest
|
|
|
|
class ModulusAnalysisTest extends InlineExpectationsTest {
|
|
ModulusAnalysisTest() { this = "ModulusAnalysisTest" }
|
|
|
|
override string getARelevantTag() { result = "mod" }
|
|
|
|
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
|
exists(SemExpr e, IR::CallInstruction call |
|
|
call.getArgument(0) = e and
|
|
call.getStaticCallTarget().hasName("mod") and
|
|
tag = "mod" and
|
|
element = e.toString() and
|
|
location = e.getLocation() and
|
|
value = getAModString(e)
|
|
)
|
|
}
|
|
}
|
|
|
|
private string getAModString(SemExpr e) {
|
|
exists(SemBound b, int delta, int mod |
|
|
semExprModulus(e, b, delta, mod) and
|
|
result = b.toString() + "," + delta.toString() + "," + mod.toString() and
|
|
not (delta = 0 and mod = 0)
|
|
)
|
|
}
|