Skip to content

Commit 7894673

Browse files
authored
Merge pull request #688 from github/michaelrfairhurst/fix-autosar-a1-1-2-on-gcc-detect-suppress-warning-flag
Detect compilations with no warnings when '-w' flag is present.
2 parents a51fff7 + aa94583 commit 7894673

12 files changed

+36
-8
lines changed

Diff for: change_notes/2024-9-20-a1-1-2-improvements.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A1-1-2` - `CompilerWarningLevelNotInCompliance.ql`:
2+
- Report non-compliance for compilations that use the error-suppressing `-w` flag.

Diff for: cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
import cpp
1919
import codingstandards.cpp.autosar
2020

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

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

2530
from File f
2631
where
2732
not isExcluded(f, ToolchainPackage::compilerWarningLevelNotInComplianceQuery()) and
28-
exists(Compilation c | f = c.getAFileCompiled() |
29-
not hasResponseFileArgument(c) and
30-
not hasWarningOption(c)
31-
)
33+
exists(CompilationWithNoWarnings c | f = c.getAFileCompiled() | not hasResponseFileArgument(c))
3234
select f, "No warning-level options were used in the compilation of '" + f.getBaseName() + "'."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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'. |

Diff for: cpp/autosar/test/rules/A1-1-2.2/CompilerWarningLevelNotInCompliance.expected.clang

Whitespace-only changes.

Diff for: cpp/autosar/test/rules/A1-1-2.2/CompilerWarningLevelNotInCompliance.expected.gcc

Whitespace-only changes.

Diff for: cpp/autosar/test/rules/A1-1-2.2/CompilerWarningLevelNotInCompliance.expected.qcc

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

Diff for: cpp/autosar/test/rules/A1-1-2/CompilerWarningLevelNotInCompliance.expected.clang

Whitespace-only changes.

Diff for: cpp/autosar/test/rules/A1-1-2/CompilerWarningLevelNotInCompliance.expected.gcc

Whitespace-only changes.

Diff for: cpp/autosar/test/rules/A1-1-2/CompilerWarningLevelNotInCompliance.expected.qcc

Whitespace-only changes.

Diff for: cpp/autosar/test/rules/A1-1-2/Wall.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
// semmle-extractor-options: --clang -std=c++14 -Wall
2-
// COMPLIANT
2+
// COMPLIANT
3+
4+
// NOTE: When tested with `codeql test run`, the test extractor provides `-w`
5+
// which overrides `-Wall` and causes this test case to be non-compliant.
6+
//
7+
// However, when tested with our compiler matrix tests, this test db is built
8+
// via `codeql database create --command="..."`, and the `-w` flag will NOT be
9+
// used. This means the `-Wall` flag is active and the test case is compliant.
10+
//
11+
// Therefore, the .expected file for this test expects non-compliance, and the
12+
// .expected.gcc and .expected.clang files expect this test to be compliant.

0 commit comments

Comments
 (0)