-
For debugging purposes and trying to understand how CodeQL worked, I have a simple cpp file from which I create 2 Code QL databases (the only difference being the #include <iostream>
#define NDEBUG
#include <cassert>
int main(){
int* a = nullptr;
assert(a != nullptr);
std::cout << "program didn't stopped" << std::endl;
} On which I run 2 requests This request return a result for both databases : import cpp
import semmle.code.cpp.commons.Assertions
from Assertion assert
select assert This request only return a result when NDEBUG is not defined import cpp
import semmle.code.cpp.commons.Assertions
from Assertion assert
select assert, assert.getAsserted() I didn't understand at first and after some searching I found that In #ifdef NDEBUG
#define assert(expression) ((void)0) So now seing this I don't even understand how CodeQL is able to know there's a assertion if NDEBUG is defined. That means CodeQL HAS to look at source code before preprocessor invocation. And if so, why doesn't it also grab the Expression inside ? Another thing that I find weird is that Assertion does NOT inherit from ControlFlowNode (which I guess make sens because a macro could theorically expand to a complex code branching ?) but that doesn't change the fact that I want to know the position of the assert() and dominance relation relative to other control flow element such as VariableAccess. And the "Location" (position in file) is completely irrelevant to that extent. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @ayosten, Thanks for your question.
Not quite. We simply record the macro invocations that affect the code/expression that ends up in your database.
Because the expression in not in the database when the code is compile with
This is because macro invocations, which is what all What you likely want to do is something along the lines of:
where |
Beta Was this translation helpful? Give feedback.
Hi @ayosten,
Thanks for your question.
Not quite. We simply record the macro invocations that affect the code/expression that ends up in your database.
Because the expression in not in the database when the code is compile with
NDEBUG
, instead there will be a((void)0)
in the database at the location of the assert. The((void)0)
statement will be the one to which the macro invocation is attached, or the be more precise:((void)0)
is generate…