mirror of
https://github.com/github/codeql.git
synced 2026-05-14 11:19:27 +02:00
C/C++: Add test for const folding of global vars
This commit is contained in:
22
cpp/ql/test/library-tests/ir/address_constant_folding/test.c
Normal file
22
cpp/ql/test/library-tests/ir/address_constant_folding/test.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#define NULL ((void*)0)
|
||||
|
||||
int global_var;
|
||||
|
||||
void test_address_null_comparison(int param_var) {
|
||||
int local_var;
|
||||
|
||||
if (&global_var == NULL) {} // $ MISSING: VariableAddress=global_var
|
||||
if (&global_var != NULL) {} // $ MISSING: VariableAddress=global_var
|
||||
if (&global_var) {} // $ VariableAddress=global_var
|
||||
if (!&global_var) {} // $ MISSING: VariableAddress=global_var
|
||||
|
||||
if (&local_var == NULL) {} // $ VariableAddress=local_var
|
||||
if (&local_var != NULL) {} // $ VariableAddress=local_var
|
||||
if (&local_var) {} // $ VariableAddress=local_var
|
||||
if (!&local_var) {} // $ VariableAddress=local_var
|
||||
|
||||
if (¶m_var == NULL) {} // $ VariableAddress=param_var
|
||||
if (¶m_var != NULL) {} // $ VariableAddress=param_var
|
||||
if (¶m_var) {} // $ VariableAddress=param_var
|
||||
if (!¶m_var) {} // $ VariableAddress=param_var
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import cpp
|
||||
private import utils.test.InlineExpectationsTest
|
||||
private import semmle.code.cpp.ir.IR
|
||||
|
||||
module VariableAddressTest implements TestSig {
|
||||
string getARelevantTag() { result = "VariableAddress" }
|
||||
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(VariableAddressInstruction vai |
|
||||
not vai.getAst() instanceof DeclarationEntry and
|
||||
not vai.getAst() instanceof Parameter and
|
||||
tag = "VariableAddress" and
|
||||
value = vai.getAstVariable().getName() and
|
||||
element = vai.toString() and
|
||||
location = vai.getLocation()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<VariableAddressTest>
|
||||
Reference in New Issue
Block a user