Skip to content

Commit 9fa2c23

Browse files
committed
Merge branch 'main' into modernize-packs
2 parents b5258e7 + 76d1b9d commit 9fa2c23

30 files changed

+416
-232
lines changed

.github/workflows/code-scanning-pack-gen.yml

Lines changed: 3 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -33,135 +33,6 @@ jobs:
3333
jq --compact-output '.supported_environment | {include: .}' supported_codeql_configs.json
3434
)"
3535
36-
create-code-scanning-pack-anon:
37-
name: Create anonymous Code Scanning pack
38-
needs: prepare-code-scanning-pack-matrix
39-
runs-on: ubuntu-20.04-xl
40-
strategy:
41-
fail-fast: false
42-
matrix: ${{ fromJSON(needs.prepare-code-scanning-pack-matrix.outputs.matrix) }}
43-
steps:
44-
- uses: actions/checkout@v2
45-
46-
- name: Cache CodeQL
47-
id: cache-codeql
48-
uses: actions/cache@v2.1.3
49-
with:
50-
path: ${{ github.workspace }}/codeql_home
51-
key: codeql-home-${{ matrix.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library }}
52-
53-
- name: Install CodeQL
54-
if: steps.cache-codeql.outputs.cache-hit != 'true'
55-
uses: ./.github/actions/install-codeql
56-
with:
57-
codeql-cli-version: ${{ matrix.codeql_cli }}
58-
codeql-stdlib-version: ${{ matrix.codeql_standard_library }}
59-
codeql-home: ${{ github.workspace }}/codeql_home
60-
add-to-path: false
61-
62-
- name: Install CodeQL packs
63-
uses: ./.github/actions/install-codeql-packs
64-
with:
65-
cli_path: ${{ github.workspace }}/codeql_home/codeql
66-
67-
- name: Install Python
68-
uses: actions/setup-python@v4
69-
with:
70-
python-version: "3.9"
71-
72-
- name: Anonymising and pre-compiling queries
73-
env:
74-
CODEQL_HOME: ${{ github.workspace }}/codeql_home
75-
run: |
76-
PATH=$PATH:$CODEQL_HOME/codeql
77-
pip install -r scripts/requirements.txt
78-
find rule_packages/cpp -name '*.json' -exec basename {} .json \; | xargs --max-procs "$XARGS_MAX_PROCS" --max-args 1 python scripts/generate_rules/generate_package_files.py -a cpp
79-
find rule_packages/c -name '*.json' -exec basename {} .json \; | xargs --max-procs "$XARGS_MAX_PROCS" --max-args 1 python scripts/generate_rules/generate_package_files.py --skip-shared-test-generation -a c
80-
81-
echo "Remove help files that cannot be freely distributed"
82-
find cpp/autosar/src/rules -name "*.md" -delete
83-
find c/misra/src/rules -name "*.md" -delete
84-
85-
codeql query compile --threads 0 cpp
86-
codeql query compile --threads 0 c
87-
cd ..
88-
zip -r codeql-coding-standards/code-scanning-cpp-query-pack-anon.zip codeql-coding-standards/c/ codeql-coding-standards/cpp/ codeql-coding-standards/.codeqlmanifest.json codeql-coding-standards/supported_codeql_configs.json codeql-coding-standards/scripts/deviations codeql-coding-standards/scripts/reports
89-
90-
- name: Upload GHAS Query Pack
91-
uses: actions/upload-artifact@v2
92-
with:
93-
name: code-scanning-cpp-query-pack-anon.zip
94-
path: code-scanning-cpp-query-pack-anon.zip
95-
96-
- name: Create LGTM query pack
97-
env:
98-
CODEQL_HOME: ${{ github.workspace }}/codeql_home
99-
run: |
100-
PATH=$PATH:$CODEQL_HOME/codeql
101-
mkdir -p lgtm-cpp-query-pack
102-
function copy_queries_for_pack {
103-
for q in $(codeql resolve queries $2/$1/src/codeql-suites/$1-default.qls)
104-
do
105-
copy_from_root_name="${q%.*}"
106-
copy_to_root_name=$(realpath --relative-to "./$2/$1/src/" "$copy_from_root_name")
107-
query_dir=$(dirname "lgtm-cpp-query-pack/$copy_to_root_name")
108-
mkdir -p "$query_dir"
109-
# Copy each selected ql file
110-
cp "$copy_from_root_name.ql" "lgtm-cpp-query-pack/$copy_to_root_name.ql"
111-
done
112-
}
113-
114-
echo "Copying autosar-default queries (CPP)"
115-
copy_queries_for_pack "autosar" "cpp"
116-
echo "Copying cert-default queries (CPP)"
117-
copy_queries_for_pack "cert" "cpp"
118-
119-
echo "Copying misra-default queries (C)"
120-
copy_queries_for_pack "misra" "c"
121-
echo "Copying cert-default queries (C)"
122-
copy_queries_for_pack "cert" "c"
123-
124-
125-
# Now copy all the .qll files
126-
lgtm_pack_dir=$(realpath lgtm-cpp-query-pack)
127-
for query_pack in autosar cert common
128-
do
129-
echo "Copying $query_pack qll files"
130-
pushd cpp/$query_pack/src
131-
for query_library in $(find . -name \*.qll)
132-
do
133-
qll_dir=$(dirname "$lgtm_pack_dir/$query_library")
134-
echo "Making $qll_dir"
135-
mkdir -p "$qll_dir"
136-
cp "$query_library" "$lgtm_pack_dir/$query_library"
137-
done
138-
popd
139-
done
140-
141-
142-
for query_pack in misra cert common
143-
do
144-
echo "Copying $query_pack qll files"
145-
pushd c/$query_pack/src
146-
for query_library in $(find . -name \*.qll)
147-
do
148-
qll_dir=$(dirname "$lgtm_pack_dir/$query_library")
149-
echo "Making $qll_dir"
150-
mkdir -p "$qll_dir"
151-
cp "$query_library" "$lgtm_pack_dir/$query_library"
152-
done
153-
popd
154-
done
155-
156-
cd lgtm-cpp-query-pack
157-
zip -9 -r ../lgtm-cpp-query-pack-anon.zip *
158-
159-
- name: Upload LGTM query pack
160-
uses: actions/upload-artifact@v2
161-
with:
162-
name: lgtm-cpp-query-pack-anon.zip
163-
path: lgtm-cpp-query-pack-anon.zip
164-
16536
create-code-scanning-pack:
16637
name: Create Code Scanning pack
16738
needs: prepare-code-scanning-pack-matrix
@@ -194,6 +65,8 @@ jobs:
19465
cli_path: ${{ github.workspace }}/codeql_home/codeql
19566

19667
- name: Checkout external help files
68+
continue-on-error: true
69+
id: checkout-external-help-files
19770
uses: actions/checkout@v2
19871
with:
19972
ssh-key: ${{ secrets.CODEQL_CODING_STANDARDS_HELP_KEY }}
@@ -202,6 +75,7 @@ jobs:
20275
path: external-help-files
20376

20477
- name: Include external help files
78+
if: ${{ steps.checkout-external-help-files.outcome == 'success' }}
20579
run: |
20680
pushd external-help-files
20781
find . -name '*.md' -exec rsync -av --relative {} "$GITHUB_WORKSPACE" \;
@@ -224,68 +98,3 @@ jobs:
22498
with:
22599
name: code-scanning-cpp-query-pack.zip
226100
path: code-scanning-cpp-query-pack.zip
227-
228-
- name: Create LGTM query pack
229-
env:
230-
CODEQL_HOME: ${{ github.workspace }}/codeql_home
231-
run: |
232-
PATH=$PATH:$CODEQL_HOME/codeql
233-
mkdir -p lgtm-cpp-query-pack
234-
function copy_queries_for_pack {
235-
for rule_dir in $(codeql resolve queries $2/$1/src/codeql-suites/$1-default.qls | xargs -L1 dirname | uniq)
236-
do
237-
copy_to_root="lgtm-cpp-query-pack/$(realpath --relative-to "./$2/$1/src/" "$rule_dir")"
238-
mkdir -p "$copy_to_root"
239-
# Copy each selected ql file, plus the related files
240-
find "$rule_dir" -name '*.ql' -o -name '*.c' -name '*.cpp' -o -name '*.png' -exec cp -n {} "$copy_to_root" \;
241-
done
242-
}
243-
echo "Copying autosar-default queries (CPP)"
244-
copy_queries_for_pack "autosar" "cpp"
245-
echo "Copying cert-default queries (CPP)"
246-
copy_queries_for_pack "cert" "cpp"
247-
248-
echo "Copying misra-default queries (C)"
249-
copy_queries_for_pack "misra" "c"
250-
echo "Copying cert-default queries (C)"
251-
copy_queries_for_pack "cert" "c"
252-
253-
254-
# Now copy all the .qll files
255-
lgtm_pack_dir=$(realpath lgtm-cpp-query-pack)
256-
for query_pack in autosar cert common
257-
do
258-
echo "Copying $query_pack qll files"
259-
pushd cpp/$query_pack/src
260-
for query_library in $(find . -name \*.qll)
261-
do
262-
qll_dir=$(dirname "$lgtm_pack_dir/$query_library")
263-
echo "Making $qll_dir"
264-
mkdir -p "$qll_dir"
265-
cp "$query_library" "$lgtm_pack_dir/$query_library"
266-
done
267-
popd
268-
done
269-
270-
for query_pack in misra cert common
271-
do
272-
echo "Copying $query_pack qll files"
273-
pushd c/$query_pack/src
274-
for query_library in $(find . -name \*.qll)
275-
do
276-
qll_dir=$(dirname "$lgtm_pack_dir/$query_library")
277-
echo "Making $qll_dir"
278-
mkdir -p "$qll_dir"
279-
cp "$query_library" "$lgtm_pack_dir/$query_library"
280-
done
281-
popd
282-
done
283-
284-
cd lgtm-cpp-query-pack
285-
zip -9 -r ../lgtm-cpp-query-pack.zip *
286-
287-
- name: Upload LGTM query pack
288-
uses: actions/upload-artifact@v2
289-
with:
290-
name: lgtm-cpp-query-pack.zip
291-
path: lgtm-cpp-query-pack.zip

.vscode/tasks.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,11 @@
221221
"Pointers",
222222
"Preprocessor1",
223223
"Preprocessor2",
224+
"Preprocessor3",
225+
"Preprocessor4",
224226
"IntegerConversion",
225227
"Expressions",
226-
"DeadCode"
228+
"DeadCode",
227229
"VirtualFunctions"
228230
]
229231
},
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import cpp
2+
3+
/** Module to reason about keywords in standards C90, C99 and C11. */
4+
module Keywords {
5+
/** Holds if `s` is a keyword. */
6+
predicate isKeyword(string s) {
7+
s = "auto"
8+
or
9+
s = "break"
10+
or
11+
s = "case"
12+
or
13+
s = "char"
14+
or
15+
s = "const"
16+
or
17+
s = "continue"
18+
or
19+
s = "default"
20+
or
21+
s = "do"
22+
or
23+
s = "double"
24+
or
25+
s = "else"
26+
or
27+
s = "enum"
28+
or
29+
s = "extern"
30+
or
31+
s = "float"
32+
or
33+
s = "for"
34+
or
35+
s = "goto"
36+
or
37+
s = "if"
38+
or
39+
s = "inline"
40+
or
41+
s = "int"
42+
or
43+
s = "long"
44+
or
45+
s = "register"
46+
or
47+
s = "restrict"
48+
or
49+
s = "return"
50+
or
51+
s = "short"
52+
or
53+
s = "signed"
54+
or
55+
s = "sizeof"
56+
or
57+
s = "static"
58+
or
59+
s = "struct"
60+
or
61+
s = "switch"
62+
or
63+
s = "typedef"
64+
or
65+
s = "union"
66+
or
67+
s = "unsigned"
68+
or
69+
s = "void"
70+
or
71+
s = "volatile"
72+
or
73+
s = "while"
74+
or
75+
s = "_Alignas"
76+
or
77+
s = "_Alignof"
78+
or
79+
s = "_Atomic"
80+
or
81+
s = "_Bool"
82+
or
83+
s = "_Complex"
84+
or
85+
s = "_Generic"
86+
or
87+
s = "_Imaginary"
88+
or
89+
s = "_Noreturn"
90+
or
91+
s = "_Static_assert"
92+
or
93+
s = "_Thread_local"
94+
}
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.c:5:3:11:3 | MACROFUNCTION(X) | Invocation of macro MACROFUNCTION includes a token "#else" that could be confused for an argument preprocessor directive. |
2+
| test.c:5:3:11:3 | MACROFUNCTION(X) | Invocation of macro MACROFUNCTION includes a token "#endif" that could be confused for an argument preprocessor directive. |
3+
| test.c:5:3:11:3 | MACROFUNCTION(X) | Invocation of macro MACROFUNCTION includes a token "#if NOTDEFINEDMACRO" that could be confused for an argument preprocessor directive. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.preprocessingdirectivewithinmacroargument.PreprocessingDirectiveWithinMacroArgument
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <string.h>
2+
#define MACROFUNCTION(X) strlen(X)
3+
4+
void f() {
5+
MACROFUNCTION(
6+
#if NOTDEFINEDMACRO // NON_COMPLIANT
7+
"longstringtest!test!"
8+
#else // NON_COMPLIANT
9+
"shortstring"
10+
#endif // NON_COMPLIANT
11+
);
12+
13+
MACROFUNCTION("alright"); // COMPLIANT
14+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id c/misra/macro-defined-with-the-same-name-as-keyword
3+
* @name RULE-20-4: A macro shall not be defined with the same name as a keyword
4+
* @description Redefinition of keywords is confusing and in the case where the standard library is
5+
* included where that keyword is defined, the redefinition will result in undefined
6+
* behaviour.
7+
* @kind problem
8+
* @precision very-high
9+
* @problem.severity warning
10+
* @tags external/misra/id/rule-20-4
11+
* correctness
12+
* readability
13+
* maintainability
14+
* external/misra/obligation/required
15+
*/
16+
17+
import cpp
18+
import codingstandards.c.misra
19+
import codingstandards.c.Keywords
20+
21+
from Macro m, string name
22+
where
23+
not isExcluded(m, Preprocessor4Package::macroDefinedWithTheSameNameAsKeywordQuery()) and
24+
m.hasName(name) and
25+
Keywords::isKeyword(name)
26+
select m, "Redefinition of keyword '" + name + "'."

0 commit comments

Comments
 (0)