From 1cc399b6625bbf17765a2d66206e10fd2101e08d Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Tue, 14 Mar 2023 13:52:58 -0700 Subject: [PATCH 01/16] Augment test.cpp --- cpp/autosar/test/rules/A5-2-6/test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cpp/autosar/test/rules/A5-2-6/test.cpp b/cpp/autosar/test/rules/A5-2-6/test.cpp index 9b7976ed23..06d08564d5 100644 --- a/cpp/autosar/test/rules/A5-2-6/test.cpp +++ b/cpp/autosar/test/rules/A5-2-6/test.cpp @@ -15,4 +15,20 @@ void f2(int p1, int p2) { if ((p1 > 0) || (p2 > 0)) { // COMPLIANT f1(); } + + struct Sample { + int x; + } sample; + + if ((p1 > 0 || + sample.x)) { // COMPLIANT: struct member accessors (.) are excluded + f1(); + } + + Sample *sample_ptr = &sample; + + if ((p1 > 0 || sample_ptr->x)) { // COMPLIANT: struct member accessors with + // dereference (->) are excluded + f1(); + } } \ No newline at end of file From 338c99c8e22ac7f0660c0997124ddfaf9f418c4b Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Tue, 14 Mar 2023 15:18:49 -0700 Subject: [PATCH 02/16] Reinforce A5-2-6 --- .../OperandsOfALogicalAndOrNotParenthesized.ql | 18 ++++++++++++------ cpp/autosar/test/rules/A5-2-6/test.cpp | 14 +++++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cpp/autosar/src/rules/A5-2-6/OperandsOfALogicalAndOrNotParenthesized.ql b/cpp/autosar/src/rules/A5-2-6/OperandsOfALogicalAndOrNotParenthesized.ql index dd63288587..6816c6ab1e 100644 --- a/cpp/autosar/src/rules/A5-2-6/OperandsOfALogicalAndOrNotParenthesized.ql +++ b/cpp/autosar/src/rules/A5-2-6/OperandsOfALogicalAndOrNotParenthesized.ql @@ -17,11 +17,17 @@ import cpp import codingstandards.cpp.autosar -from BinaryLogicalOperation op, BinaryOperation binop +from BinaryLogicalOperation op, Expr operand where not isExcluded(op, OrderOfEvaluationPackage::operandsOfALogicalAndOrNotParenthesizedQuery()) and - op.getAnOperand() = binop and - not exists(ParenthesisExpr p | p = binop.getFullyConverted()) and - // Exclude binary operations expanded by a macro. - not binop.isInMacroExpansion() -select op, "Binary $@ operand of logical operation is not parenthesized.", binop, "operator" + operand = op.getAnOperand() and + /* The operand is a built-in arithmetic/logic binary operation */ + if operand instanceof BinaryOperation + then + not exists(ParenthesisExpr p | p = operand.getFullyConverted()) and + // Exclude binary operations expanded by a macro. + not operand.isInMacroExpansion() + else + /* The operand should not be a field access operation */ + not operand instanceof FieldAccess +select op, "Binary $@ operand of logical operation is not parenthesized.", operand, "operator" diff --git a/cpp/autosar/test/rules/A5-2-6/test.cpp b/cpp/autosar/test/rules/A5-2-6/test.cpp index 06d08564d5..78359d8cbb 100644 --- a/cpp/autosar/test/rules/A5-2-6/test.cpp +++ b/cpp/autosar/test/rules/A5-2-6/test.cpp @@ -1,4 +1,5 @@ -extern void f1(); +// TODO: remove function body +extern void f1(){}; void f2(int p1, int p2) { if (p1 > 0 && p1 < 10) { // NON_COMPLIANT f1(); @@ -20,15 +21,18 @@ void f2(int p1, int p2) { int x; } sample; - if ((p1 > 0 || - sample.x)) { // COMPLIANT: struct member accessors (.) are excluded + if ((p1 > 0) || + sample.x) { // COMPLIANT: struct member accessors (.) are excluded f1(); } Sample *sample_ptr = &sample; - if ((p1 > 0 || sample_ptr->x)) { // COMPLIANT: struct member accessors with + if ((p1 > 0) || sample_ptr->x) { // COMPLIANT: struct member accessors with // dereference (->) are excluded f1(); } -} \ No newline at end of file +} + +// TODO: remove this +int main() { return 0; } \ No newline at end of file From 5fcb20a6d43bf86c6f7ccc60951d91ec7557a0bf Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Tue, 14 Mar 2023 16:38:50 -0700 Subject: [PATCH 03/16] Remove stuffs added temporarily --- cpp/autosar/test/rules/A5-2-6/test.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cpp/autosar/test/rules/A5-2-6/test.cpp b/cpp/autosar/test/rules/A5-2-6/test.cpp index 78359d8cbb..0649f7dbc9 100644 --- a/cpp/autosar/test/rules/A5-2-6/test.cpp +++ b/cpp/autosar/test/rules/A5-2-6/test.cpp @@ -1,5 +1,4 @@ -// TODO: remove function body -extern void f1(){}; +extern void f1(); void f2(int p1, int p2) { if (p1 > 0 && p1 < 10) { // NON_COMPLIANT f1(); @@ -32,7 +31,4 @@ void f2(int p1, int p2) { // dereference (->) are excluded f1(); } -} - -// TODO: remove this -int main() { return 0; } \ No newline at end of file +} \ No newline at end of file From c1dac085a2f8726a0a21573368ea5ee301263b9c Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Wed, 15 Mar 2023 11:27:28 -0700 Subject: [PATCH 04/16] Augment A15-4-4 --- cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql | 4 +++- cpp/autosar/test/rules/A15-4-4/test.cpp | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql b/cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql index 1857003826..1b0aa423af 100644 --- a/cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql +++ b/cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql @@ -31,5 +31,7 @@ where // Not compiler generated not f.isCompilerGenerated() and // The function is defined in this database - f.hasDefinition() + f.hasDefinition() and + // This function is not an overriden call operator of lambda expression + not exists(LambdaExpression lambda | lambda.getLambdaFunction() = f) select f, "Function " + f.getName() + " could be declared noexcept(true)." diff --git a/cpp/autosar/test/rules/A15-4-4/test.cpp b/cpp/autosar/test/rules/A15-4-4/test.cpp index 6834c7a8ce..f0b676373e 100644 --- a/cpp/autosar/test/rules/A15-4-4/test.cpp +++ b/cpp/autosar/test/rules/A15-4-4/test.cpp @@ -24,4 +24,10 @@ void test_indirect_throw() { // COMPLIANT - throws an exception indirectly class A { public: A() = delete; // COMPLIANT - deleted functions imply `noexcept(true)`. -}; \ No newline at end of file +}; + +/* Added for testing FP of embedded operator inside lambdas being reported */ +void lambda_example() noexcept { + auto with_capture = [=]() {}; + auto empty_capture = []() {}; +} \ No newline at end of file From d4adaa59dd6370475537b603b06be37f015f2e4d Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Wed, 15 Mar 2023 16:16:57 -0700 Subject: [PATCH 05/16] Augment A2-7-3 Remove testing of lambdas completely by removing the `and not ...` part. --- cpp/autosar/src/rules/A2-7-3/UndocumentedUserDefinedType.ql | 4 +--- .../test/rules/A2-7-3/UndocumentedUserDefinedType.expected | 1 - cpp/autosar/test/rules/A2-7-3/test.cpp | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cpp/autosar/src/rules/A2-7-3/UndocumentedUserDefinedType.ql b/cpp/autosar/src/rules/A2-7-3/UndocumentedUserDefinedType.ql index 54925718f2..247f3ef2a1 100644 --- a/cpp/autosar/src/rules/A2-7-3/UndocumentedUserDefinedType.ql +++ b/cpp/autosar/src/rules/A2-7-3/UndocumentedUserDefinedType.ql @@ -36,9 +36,7 @@ class DocumentableDeclaration extends Declaration { // Exclude instantiated template functions, which cannot reasonably be documented. not this.(Function).isFromTemplateInstantiation(_) and // Exclude anonymous lambda functions. - not exists(LambdaExpression lc | - lc.getLambdaFunction() = this and not lc.getEnclosingElement() instanceof Initializer - ) + not exists(LambdaExpression lc | lc.getLambdaFunction() = this) or this instanceof MemberVariable and declarationType = "member variable" and diff --git a/cpp/autosar/test/rules/A2-7-3/UndocumentedUserDefinedType.expected b/cpp/autosar/test/rules/A2-7-3/UndocumentedUserDefinedType.expected index 77ede66305..0ae42152f7 100644 --- a/cpp/autosar/test/rules/A2-7-3/UndocumentedUserDefinedType.expected +++ b/cpp/autosar/test/rules/A2-7-3/UndocumentedUserDefinedType.expected @@ -6,5 +6,4 @@ | test.cpp:78:6:78:6 | declaration of d | Declaration entry for function d is missing documentation. | | test.cpp:81:6:81:6 | definition of e | Declaration entry for function e is missing documentation. | | test.cpp:88:1:88:30 | definition of message_to_string_undocumented | Declaration entry for function message_to_string_undocumented is missing documentation. | -| test.cpp:113:14:113:14 | definition of operator() | Declaration entry for function operator() is missing documentation. | | test.cpp:160:21:160:24 | definition of kBar | Declaration entry for member variable kBar is missing documentation. | diff --git a/cpp/autosar/test/rules/A2-7-3/test.cpp b/cpp/autosar/test/rules/A2-7-3/test.cpp index b467e05c80..bc174d918d 100644 --- a/cpp/autosar/test/rules/A2-7-3/test.cpp +++ b/cpp/autosar/test/rules/A2-7-3/test.cpp @@ -110,7 +110,7 @@ std::string template_function_test() { // COMPLIANT /// @brief function assigned_lambda_test. int assigned_lambda_test() { - auto l = [](int x, int y) { return x + y; }; // NON_COMPLIANT + auto l = [](int x, int y) { return x + y; }; // COMPLIANT: We exclude lambdas. return l(2, 3); } @@ -160,4 +160,4 @@ template class A2_7_3 final { const std::string kBar{"bar"}; // NON_COMPLIANT }; /// @brief This is the instantiateA2_7_3 documentation -void instantiateA2_7_3() { A2_7_3 instance; } +void instantiateA2_7_3() { A2_7_3 instance; } \ No newline at end of file From 58f134f2701c51feb5f470b87acc14adf2e6a421 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Wed, 15 Mar 2023 17:13:27 -0700 Subject: [PATCH 06/16] Minor comment --- cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql b/cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql index 1b0aa423af..0226c20d30 100644 --- a/cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql +++ b/cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql @@ -32,6 +32,6 @@ where not f.isCompilerGenerated() and // The function is defined in this database f.hasDefinition() and - // This function is not an overriden call operator of lambda expression + // This function is not an overriden call operator of a lambda expression not exists(LambdaExpression lambda | lambda.getLambdaFunction() = f) select f, "Function " + f.getName() + " could be declared noexcept(true)." From 9dc1879d958f8daefbcf4db1429333c80cbdcdd7 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Wed, 15 Mar 2023 18:37:31 -0700 Subject: [PATCH 07/16] Add change notes for this batch --- change_notes/2023-03-15-fix-reported-fp-for-A0-1-1.md | 2 ++ change_notes/2023-03-15-fix-reported-fp-for-A15-4-4.md | 2 ++ change_notes/2023-03-15-fix-reported-fp-for-A2-7-3.md | 2 ++ change_notes/2023-03-15-fix-reported-fp-for-A5-2-6.md | 2 ++ 4 files changed, 8 insertions(+) create mode 100644 change_notes/2023-03-15-fix-reported-fp-for-A0-1-1.md create mode 100644 change_notes/2023-03-15-fix-reported-fp-for-A15-4-4.md create mode 100644 change_notes/2023-03-15-fix-reported-fp-for-A2-7-3.md create mode 100644 change_notes/2023-03-15-fix-reported-fp-for-A5-2-6.md diff --git a/change_notes/2023-03-15-fix-reported-fp-for-A0-1-1.md b/change_notes/2023-03-15-fix-reported-fp-for-A0-1-1.md new file mode 100644 index 0000000000..0f9960eb5e --- /dev/null +++ b/change_notes/2023-03-15-fix-reported-fp-for-A0-1-1.md @@ -0,0 +1,2 @@ +- `A0-1-1` - `UselessAssignment.ql`: + - Exclude cases where an access to a variable's field or member was not considered as a valid use of the variable. diff --git a/change_notes/2023-03-15-fix-reported-fp-for-A15-4-4.md b/change_notes/2023-03-15-fix-reported-fp-for-A15-4-4.md new file mode 100644 index 0000000000..c7cb61d2c9 --- /dev/null +++ b/change_notes/2023-03-15-fix-reported-fp-for-A15-4-4.md @@ -0,0 +1,2 @@ +- `A15-4-4` - `MissingNoExcept.ql` + - Exclude call operators embedded in a lambda expression from functions to be declared `noexcept` or `noexcept(false)`. diff --git a/change_notes/2023-03-15-fix-reported-fp-for-A2-7-3.md b/change_notes/2023-03-15-fix-reported-fp-for-A2-7-3.md new file mode 100644 index 0000000000..ce98bab27a --- /dev/null +++ b/change_notes/2023-03-15-fix-reported-fp-for-A2-7-3.md @@ -0,0 +1,2 @@ +- `A2-7-3` - `UndocumentedUserDefinedType.ql`: + - Exclude lambda functions from program elements to be documented. diff --git a/change_notes/2023-03-15-fix-reported-fp-for-A5-2-6.md b/change_notes/2023-03-15-fix-reported-fp-for-A5-2-6.md new file mode 100644 index 0000000000..eb54c71131 --- /dev/null +++ b/change_notes/2023-03-15-fix-reported-fp-for-A5-2-6.md @@ -0,0 +1,2 @@ +- `A5-2-6` - `OperandsOfALogicalAndOrNotParenthesized.ql`: + - Exclude deferencing field accessor (`->`) and field accessor (`.`) from binary operators in question. From 5c3ccd1629eab18a1ce7e89e4835c29b29178176 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Thu, 16 Mar 2023 12:09:15 -0700 Subject: [PATCH 08/16] Add more cases for FP --- cpp/autosar/test/rules/A0-1-1/test.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cpp/autosar/test/rules/A0-1-1/test.cpp b/cpp/autosar/test/rules/A0-1-1/test.cpp index 98c8058219..c86fd067e0 100644 --- a/cpp/autosar/test/rules/A0-1-1/test.cpp +++ b/cpp/autosar/test/rules/A0-1-1/test.cpp @@ -17,6 +17,9 @@ struct C { int m; }; +void sample1(int x){}; +void sample2(int y){}; + int test_useless_assignment(int &x, int p) { x = 0; // COMPLIANT - x is a reference parameter, so is visible by the caller int y = 0; // NON_COMPLIANT - never used @@ -49,7 +52,7 @@ int test_useless_assignment(int &x, int p) { A *a3 = new A; // NON_COMPLIANT - POD class, no constructor/destructor A *a4 = new A(); // NON_COMPLIANT - POD class, no constructor/destructor A *a5 = nullptr; // NON_COMPLIANT - null never read - A a6{}; // COMPLIANT - `m` assigned below + A a6{}; // COMPLIANT - `f` assigned below a6.f = 2; // COMPLIANT - we don't track the fields here, but we do track `a6`, // so we'd consider this used by the assignment below a6.f = 1; // NON_COMPLIANT - assignment into `f`, but `a6` is not used @@ -69,5 +72,14 @@ int test_useless_assignment(int &x, int p) { C *c4 = new C(); // COMPLIANT - this will call a constructor?? C *c5 = nullptr; // NON_COMPLIANT - null never read + A a7{1, 2}; // COMPLIANT - used in the `sample1` call below + sample1(a7.f + a7.f2); // COMPLIANT - object access is a valid use + + A *a8; // COMPLIANT - value not given at declaration + a8 = &a7; + sample2(a8->f); // COMPLIANT - object access is a valid use + return y; } + +int main() { return 0; } \ No newline at end of file From 423328b6b70f2c235de7116a628b0841496816b5 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Fri, 17 Mar 2023 16:41:26 -0700 Subject: [PATCH 09/16] Add supposed FP case --- cpp/autosar/test/rules/A0-1-1/test.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cpp/autosar/test/rules/A0-1-1/test.cpp b/cpp/autosar/test/rules/A0-1-1/test.cpp index c86fd067e0..ebfd74e2ac 100644 --- a/cpp/autosar/test/rules/A0-1-1/test.cpp +++ b/cpp/autosar/test/rules/A0-1-1/test.cpp @@ -20,6 +20,15 @@ struct C { void sample1(int x){}; void sample2(int y){}; +static void foo(B &b) noexcept { + b.g(); + B bar{}; + bar.g(); + B b2 = B(); + auto b3 = &b2; + b3->g(); +} + int test_useless_assignment(int &x, int p) { x = 0; // COMPLIANT - x is a reference parameter, so is visible by the caller int y = 0; // NON_COMPLIANT - never used @@ -75,9 +84,9 @@ int test_useless_assignment(int &x, int p) { A a7{1, 2}; // COMPLIANT - used in the `sample1` call below sample1(a7.f + a7.f2); // COMPLIANT - object access is a valid use - A *a8; // COMPLIANT - value not given at declaration - a8 = &a7; - sample2(a8->f); // COMPLIANT - object access is a valid use + // A *a8; // COMPLIANT - value not given at declaration + // a8 = &a7; + // sample2(a8->f); // COMPLIANT - object access is a valid use return y; } From 55962dc2e0fd0c5d0e867c0892080bb98476478f Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Mon, 20 Mar 2023 09:35:39 -0700 Subject: [PATCH 10/16] Add FP suspect case --- cpp/autosar/test/rules/A0-1-1/test.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cpp/autosar/test/rules/A0-1-1/test.cpp b/cpp/autosar/test/rules/A0-1-1/test.cpp index ebfd74e2ac..b02c56f7af 100644 --- a/cpp/autosar/test/rules/A0-1-1/test.cpp +++ b/cpp/autosar/test/rules/A0-1-1/test.cpp @@ -29,6 +29,18 @@ static void foo(B &b) noexcept { b3->g(); } +template void test() { + T t; + t.g(); +} + +template void call_test() { + // call it with type parameter B to trigger indexing + test(); +} + +void call_call_test() { call_test(); } + int test_useless_assignment(int &x, int p) { x = 0; // COMPLIANT - x is a reference parameter, so is visible by the caller int y = 0; // NON_COMPLIANT - never used From 845ba29654fa16b42ddcda9ef597446182e64713 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Mon, 20 Mar 2023 10:08:17 -0700 Subject: [PATCH 11/16] Another FP suspect case --- cpp/autosar/test/rules/A0-1-1/test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpp/autosar/test/rules/A0-1-1/test.cpp b/cpp/autosar/test/rules/A0-1-1/test.cpp index b02c56f7af..3319064b5b 100644 --- a/cpp/autosar/test/rules/A0-1-1/test.cpp +++ b/cpp/autosar/test/rules/A0-1-1/test.cpp @@ -27,6 +27,8 @@ static void foo(B &b) noexcept { B b2 = B(); auto b3 = &b2; b3->g(); + auto b2 = b; + b2.g(); } template void test() { From b9f0750c2006d618cbc54ab9f2e711bf69e153a2 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Wed, 22 Mar 2023 20:14:23 -0700 Subject: [PATCH 12/16] Add more FP suspect case --- cpp/autosar/test/rules/A0-1-1/options.clang | 1 - cpp/autosar/test/rules/A0-1-1/test.cpp | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) delete mode 100644 cpp/autosar/test/rules/A0-1-1/options.clang diff --git a/cpp/autosar/test/rules/A0-1-1/options.clang b/cpp/autosar/test/rules/A0-1-1/options.clang deleted file mode 100644 index 751f1364f6..0000000000 --- a/cpp/autosar/test/rules/A0-1-1/options.clang +++ /dev/null @@ -1 +0,0 @@ --Wall \ No newline at end of file diff --git a/cpp/autosar/test/rules/A0-1-1/test.cpp b/cpp/autosar/test/rules/A0-1-1/test.cpp index 3319064b5b..45cee07d65 100644 --- a/cpp/autosar/test/rules/A0-1-1/test.cpp +++ b/cpp/autosar/test/rules/A0-1-1/test.cpp @@ -27,8 +27,12 @@ static void foo(B &b) noexcept { B b2 = B(); auto b3 = &b2; b3->g(); - auto b2 = b; - b2.g(); + B &b4 = b; + b4.g(); + auto &b5 = *new B(); + b5.g(); + auto &b5 = new B(); + b5.g(); } template void test() { From 556a75797bc6b911ff9b150c0813f11872c85838 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Fri, 24 Mar 2023 10:36:45 -0700 Subject: [PATCH 13/16] Make test.cpp compile --- cpp/autosar/test/rules/A0-1-1/test.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cpp/autosar/test/rules/A0-1-1/test.cpp b/cpp/autosar/test/rules/A0-1-1/test.cpp index 45cee07d65..824d649c6a 100644 --- a/cpp/autosar/test/rules/A0-1-1/test.cpp +++ b/cpp/autosar/test/rules/A0-1-1/test.cpp @@ -31,8 +31,11 @@ static void foo(B &b) noexcept { b4.g(); auto &b5 = *new B(); b5.g(); - auto &b5 = new B(); - b5.g(); + /* Below causes a compile error (non-const reference when initialized should + * hold an lvalue) + */ + // auto &b6 = new B(); + // b6.g(); } template void test() { From 2c51ca11a32f090102aafeaee03de542321f3ae7 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Tue, 25 Apr 2023 11:22:56 -0700 Subject: [PATCH 14/16] Revert A5-2-6 --- .../OperandsOfALogicalAndOrNotParenthesized.ql | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/cpp/autosar/src/rules/A5-2-6/OperandsOfALogicalAndOrNotParenthesized.ql b/cpp/autosar/src/rules/A5-2-6/OperandsOfALogicalAndOrNotParenthesized.ql index 6816c6ab1e..dd63288587 100644 --- a/cpp/autosar/src/rules/A5-2-6/OperandsOfALogicalAndOrNotParenthesized.ql +++ b/cpp/autosar/src/rules/A5-2-6/OperandsOfALogicalAndOrNotParenthesized.ql @@ -17,17 +17,11 @@ import cpp import codingstandards.cpp.autosar -from BinaryLogicalOperation op, Expr operand +from BinaryLogicalOperation op, BinaryOperation binop where not isExcluded(op, OrderOfEvaluationPackage::operandsOfALogicalAndOrNotParenthesizedQuery()) and - operand = op.getAnOperand() and - /* The operand is a built-in arithmetic/logic binary operation */ - if operand instanceof BinaryOperation - then - not exists(ParenthesisExpr p | p = operand.getFullyConverted()) and - // Exclude binary operations expanded by a macro. - not operand.isInMacroExpansion() - else - /* The operand should not be a field access operation */ - not operand instanceof FieldAccess -select op, "Binary $@ operand of logical operation is not parenthesized.", operand, "operator" + op.getAnOperand() = binop and + not exists(ParenthesisExpr p | p = binop.getFullyConverted()) and + // Exclude binary operations expanded by a macro. + not binop.isInMacroExpansion() +select op, "Binary $@ operand of logical operation is not parenthesized.", binop, "operator" From ec602e3b87c564db018cdeecf02f6016727948cb Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Tue, 25 Apr 2023 11:57:42 -0700 Subject: [PATCH 15/16] Update .expected for A0-1-1 --- .../rules/A0-1-1/UselessAssignment.expected | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cpp/autosar/test/rules/A0-1-1/UselessAssignment.expected b/cpp/autosar/test/rules/A0-1-1/UselessAssignment.expected index b91ac0e0ce..bdd73be2eb 100644 --- a/cpp/autosar/test/rules/A0-1-1/UselessAssignment.expected +++ b/cpp/autosar/test/rules/A0-1-1/UselessAssignment.expected @@ -1,14 +1,14 @@ -| test.cpp:22:10:22:11 | 0 | Definition of $@ is unused. | test.cpp:22:7:22:7 | y | y | -| test.cpp:25:3:25:5 | ... ++ | Definition of $@ is unused. | test.cpp:24:7:24:7 | z | z | -| test.cpp:42:3:42:7 | ... = ... | Definition of $@ is unused. | test.cpp:20:41:20:41 | p | p | -| test.cpp:44:10:44:11 | 0 | Definition of $@ is unused. | test.cpp:44:7:44:8 | l3 | l3 | -| test.cpp:45:13:45:22 | new | Definition of $@ is unused. | test.cpp:45:8:45:9 | l4 | l4 | -| test.cpp:48:8:48:8 | {...} | Definition of $@ is unused. | test.cpp:48:5:48:6 | a2 | a2 | -| test.cpp:49:11:49:15 | new | Definition of $@ is unused. | test.cpp:49:6:49:7 | a3 | a3 | -| test.cpp:50:11:50:17 | new | Definition of $@ is unused. | test.cpp:50:6:50:7 | a4 | a4 | -| test.cpp:51:11:51:17 | 0 | Definition of $@ is unused. | test.cpp:51:6:51:7 | a5 | a5 | -| test.cpp:55:3:55:10 | ... = ... | Definition of $@ is unused. | test.cpp:52:5:52:6 | a6 | a6 | -| test.cpp:60:11:60:15 | new | Definition of $@ is unused. | test.cpp:60:6:60:7 | b3 | b3 | -| test.cpp:61:11:61:17 | new | Definition of $@ is unused. | test.cpp:61:6:61:7 | b4 | b4 | -| test.cpp:62:11:62:17 | 0 | Definition of $@ is unused. | test.cpp:62:6:62:7 | b5 | b5 | -| test.cpp:70:11:70:17 | 0 | Definition of $@ is unused. | test.cpp:70:6:70:7 | c5 | c5 | +| test.cpp:55:10:55:11 | 0 | Definition of $@ is unused. | test.cpp:55:7:55:7 | y | y | +| test.cpp:58:3:58:5 | ... ++ | Definition of $@ is unused. | test.cpp:57:7:57:7 | z | z | +| test.cpp:75:3:75:7 | ... = ... | Definition of $@ is unused. | test.cpp:53:41:53:41 | p | p | +| test.cpp:77:10:77:11 | 0 | Definition of $@ is unused. | test.cpp:77:7:77:8 | l3 | l3 | +| test.cpp:78:13:78:22 | new | Definition of $@ is unused. | test.cpp:78:8:78:9 | l4 | l4 | +| test.cpp:81:8:81:8 | {...} | Definition of $@ is unused. | test.cpp:81:5:81:6 | a2 | a2 | +| test.cpp:82:11:82:15 | new | Definition of $@ is unused. | test.cpp:82:6:82:7 | a3 | a3 | +| test.cpp:83:11:83:17 | new | Definition of $@ is unused. | test.cpp:83:6:83:7 | a4 | a4 | +| test.cpp:84:11:84:17 | 0 | Definition of $@ is unused. | test.cpp:84:6:84:7 | a5 | a5 | +| test.cpp:88:3:88:10 | ... = ... | Definition of $@ is unused. | test.cpp:85:5:85:6 | a6 | a6 | +| test.cpp:93:11:93:15 | new | Definition of $@ is unused. | test.cpp:93:6:93:7 | b3 | b3 | +| test.cpp:94:11:94:17 | new | Definition of $@ is unused. | test.cpp:94:6:94:7 | b4 | b4 | +| test.cpp:95:11:95:17 | 0 | Definition of $@ is unused. | test.cpp:95:6:95:7 | b5 | b5 | +| test.cpp:103:11:103:17 | 0 | Definition of $@ is unused. | test.cpp:103:6:103:7 | c5 | c5 | From ec79c886b80740e383fe0aa56a689311e4985199 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Wed, 26 Apr 2023 12:12:59 -0700 Subject: [PATCH 16/16] Remove change notes for A0-1-1 and A5-2-6 - A0-1-1: Couldn't repro, query file not touched at all - A5-2-6: Couldn't repro, file reverted to original --- change_notes/2023-03-15-fix-reported-fp-for-A0-1-1.md | 2 -- change_notes/2023-03-15-fix-reported-fp-for-A5-2-6.md | 2 -- 2 files changed, 4 deletions(-) delete mode 100644 change_notes/2023-03-15-fix-reported-fp-for-A0-1-1.md delete mode 100644 change_notes/2023-03-15-fix-reported-fp-for-A5-2-6.md diff --git a/change_notes/2023-03-15-fix-reported-fp-for-A0-1-1.md b/change_notes/2023-03-15-fix-reported-fp-for-A0-1-1.md deleted file mode 100644 index 0f9960eb5e..0000000000 --- a/change_notes/2023-03-15-fix-reported-fp-for-A0-1-1.md +++ /dev/null @@ -1,2 +0,0 @@ -- `A0-1-1` - `UselessAssignment.ql`: - - Exclude cases where an access to a variable's field or member was not considered as a valid use of the variable. diff --git a/change_notes/2023-03-15-fix-reported-fp-for-A5-2-6.md b/change_notes/2023-03-15-fix-reported-fp-for-A5-2-6.md deleted file mode 100644 index eb54c71131..0000000000 --- a/change_notes/2023-03-15-fix-reported-fp-for-A5-2-6.md +++ /dev/null @@ -1,2 +0,0 @@ -- `A5-2-6` - `OperandsOfALogicalAndOrNotParenthesized.ql`: - - Exclude deferencing field accessor (`->`) and field accessor (`.`) from binary operators in question.