Skip to content

Commit

Permalink
Merge pull request #688 from github/michaelrfairhurst/fix-autosar-a1-…
Browse files Browse the repository at this point in the history
…1-2-on-gcc-detect-suppress-warning-flag

Detect compilations with no warnings when '-w' flag is present.
  • Loading branch information
lcartey authored Sep 25, 2024
2 parents a51fff7 + aa94583 commit 7894673
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 8 deletions.
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'. |
Empty file.
Empty file.
Empty file.
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'. |
Empty file.
Empty file.
Empty file.
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.

0 comments on commit 7894673

Please sign in to comment.