From 92379ae02314bcdd7b9f8d3afee48e95742bdfff Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Fri, 26 Jan 2024 01:06:29 -0500 Subject: [PATCH 1/3] A5-0-2: exclude compiler generated conditions --- .../cpp/rules/nonbooleanifstmt/NonBooleanIfStmt.qll | 2 ++ .../rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll | 2 ++ 2 files changed, 4 insertions(+) diff --git a/cpp/common/src/codingstandards/cpp/rules/nonbooleanifstmt/NonBooleanIfStmt.qll b/cpp/common/src/codingstandards/cpp/rules/nonbooleanifstmt/NonBooleanIfStmt.qll index 18346a8159..bd84597a44 100644 --- a/cpp/common/src/codingstandards/cpp/rules/nonbooleanifstmt/NonBooleanIfStmt.qll +++ b/cpp/common/src/codingstandards/cpp/rules/nonbooleanifstmt/NonBooleanIfStmt.qll @@ -14,6 +14,8 @@ query predicate problems(Expr condition, string message) { not isExcluded(condition, getQuery()) and exists(IfStmt ifStmt, Type explicitConversionType | condition = ifStmt.getCondition() and + //exclude any generated conditions + not condition.isCompilerGenerated() and not ifStmt.isFromUninstantiatedTemplate(_) and explicitConversionType = condition.getExplicitlyConverted().getUnderlyingType() and not explicitConversionType instanceof BoolType and diff --git a/cpp/common/src/codingstandards/cpp/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll b/cpp/common/src/codingstandards/cpp/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll index f1ee555406..c342811c52 100644 --- a/cpp/common/src/codingstandards/cpp/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll +++ b/cpp/common/src/codingstandards/cpp/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll @@ -16,6 +16,8 @@ query predicate problems(Loop loopStmt, string message) { condition = loopStmt.getCondition() and explicitConversionType = condition.getExplicitlyConverted().getType().getUnspecifiedType() and not explicitConversionType instanceof BoolType and + //exclude any generated conditions + not condition.isCompilerGenerated() and message = "Iteration condition has non boolean type " + explicitConversionType + "." ) } From f353c4ba6430714f3a08fc94bcc8795b602258de Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Fri, 26 Jan 2024 01:16:37 -0500 Subject: [PATCH 2/3] A5-0-2: add missing changenote --- change_notes/2024-01-26-exclusion-a5-0-2.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 change_notes/2024-01-26-exclusion-a5-0-2.md diff --git a/change_notes/2024-01-26-exclusion-a5-0-2.md b/change_notes/2024-01-26-exclusion-a5-0-2.md new file mode 100644 index 0000000000..f7fa5c5074 --- /dev/null +++ b/change_notes/2024-01-26-exclusion-a5-0-2.md @@ -0,0 +1,2 @@ +`A5-0-2`: `cpp/autosar/non-boolean-if-condition`, `cpp/autosar/non-boolean-iteration-condition` + - Exclude compiler generated conditions. \ No newline at end of file From 8f945f5cd829e3610d6eb027187c878ef156b844 Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Tue, 6 Feb 2024 13:17:01 -0500 Subject: [PATCH 3/3] Update change_notes/2024-01-26-exclusion-a5-0-2.md Co-authored-by: Remco Vermeulen --- change_notes/2024-01-26-exclusion-a5-0-2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2024-01-26-exclusion-a5-0-2.md b/change_notes/2024-01-26-exclusion-a5-0-2.md index f7fa5c5074..33d8113774 100644 --- a/change_notes/2024-01-26-exclusion-a5-0-2.md +++ b/change_notes/2024-01-26-exclusion-a5-0-2.md @@ -1,2 +1,2 @@ -`A5-0-2`: `cpp/autosar/non-boolean-if-condition`, `cpp/autosar/non-boolean-iteration-condition` +`A5-0-2` - `NonBooleanIfStmt.qll`, `NonBooleanIterationStmt.qll`: - Exclude compiler generated conditions. \ No newline at end of file