Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect compilations with no warnings when '-w' flag is present. #688

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions change_notes/2024-9-20-a1-1-2-improvements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A1-1-2` - `CompilerWarningLevelNotInCompliance.ql`:
- Report non-compliance for compilations that use the error-suppressing `-w` flag.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
import cpp
import codingstandards.cpp.autosar

predicate hasResponseFileArgument(Compilation c) { c.getAnArgument().matches("@%") }
class CompilationWithNoWarnings extends Compilation {
CompilationWithNoWarnings() {
getAnArgument() = "-w" or
not getAnArgument().regexpMatch("-W[\\w=-]+")
}
}

predicate hasWarningOption(Compilation c) { c.getAnArgument().regexpMatch("-W[\\w=-]+") }
predicate hasResponseFileArgument(Compilation c) { c.getAnArgument().matches("@%") }

from File f
where
not isExcluded(f, ToolchainPackage::compilerWarningLevelNotInComplianceQuery()) and
exists(Compilation c | f = c.getAFileCompiled() |
not hasResponseFileArgument(c) and
not hasWarningOption(c)
)
exists(CompilationWithNoWarnings c | f = c.getAFileCompiled() | not hasResponseFileArgument(c))
select f, "No warning-level options were used in the compilation of '" + f.getBaseName() + "'."
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| Wcast-function-type.cpp:0:0:0:0 | Wcast-function-type.cpp | No warning-level options were used in the compilation of 'Wcast-function-type.cpp'. |
14 changes: 13 additions & 1 deletion cpp/autosar/test/rules/A1-1-2.2/Wcast-function-type.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
// semmle-extractor-options: --clang -std=c++14 -Wcast-function-type
// COMPLIANT
// COMPLIANT

// NOTE: When tested with `codeql test run`, the test extractor provides `-w`
// which overrides `-Wcast-function-type` and causes this test case to be
// non-compliant.
//
// However, when tested with our compiler matrix tests, this test db is built
// via `codeql database create --command="..."`, and the `-w` flag will NOT be
// used. This means the `-Wcast-function-type` flag is active and the test case
// is compliant.
//
// Therefore, the .expected file for this test expects non-compliance, and the
// .expected.gcc and .expected.clang files expect this test to be compliant.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| Wall.cpp:0:0:0:0 | Wall.cpp | No warning-level options were used in the compilation of 'Wall.cpp'. |
12 changes: 11 additions & 1 deletion cpp/autosar/test/rules/A1-1-2/Wall.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
// semmle-extractor-options: --clang -std=c++14 -Wall
// COMPLIANT
// COMPLIANT

// NOTE: When tested with `codeql test run`, the test extractor provides `-w`
// which overrides `-Wall` and causes this test case to be non-compliant.
//
// However, when tested with our compiler matrix tests, this test db is built
// via `codeql database create --command="..."`, and the `-w` flag will NOT be
// used. This means the `-Wall` flag is active and the test case is compliant.
//
// Therefore, the .expected file for this test expects non-compliance, and the
// .expected.gcc and .expected.clang files expect this test to be compliant.
Loading