Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc0a8253

Browse files
committed
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Statements
2 parents32c36fe +d268839 commitc0a8253

File tree

43 files changed

+1251
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1251
-44
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-`M5-2-2` -`PointerToAVirtualBaseClassCastToAPointer.ql`:
2+
- Report casts where the from or to types are typedefs to virtual base classes or derived classes.
3+
- Report casts to a reference type which is a derived type.
4+
- Report casts where the base class is the parent of a virtual base class.
5+
- The alert message has been updated to refer to the virtual base class derivation.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-`RULE-1-2`,`RULE-23-3`,`RULE-23-5`,`RULE-23-6`:
2+
- Results that occur in nested macro invocations are now reported in the macro that defines the contravening code, rather than the macro which is first expanded.
3+
- Results the occur in arguments to macro invocations are now reported in at the macro invocation site, instead of the macro definition site.

‎cpp/autosar/src/rules/A5-2-2/TraditionalCStyleCastsUsed.ql‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import cpp
1717
import codingstandards.cpp.autosar
1818
import codingstandards.cpp.Macro
19+
import codingstandards.cpp.CStyleCasts
1920

2021
/**
2122
* Gets the macro (if any) that generated the given `CStyleCast`.
@@ -61,18 +62,10 @@ Macro getGeneratedFrom(CStyleCast c) {
6162
* argument type is compatible with a single-argument constructor.
6263
*/
6364

64-
fromCStyleCastc,stringextraMessage,Locatablel,stringsupplementary
65+
fromExplicitUserDefinedCStyleCastc,stringextraMessage,Locatablel,stringsupplementary
6566
where
6667
notisExcluded(c, BannedSyntaxPackage::traditionalCStyleCastsUsedQuery())and
67-
notc.isImplicit()and
68-
notc.getType()instanceofUnknownTypeand
69-
// For casts in templates that occur on types related to a template parameter, the copy of th
70-
// cast in the uninstantiated template is represented as a `CStyleCast` even if in practice all
71-
// the instantiations represent it as a `ConstructorCall`. To avoid the common false positive case
72-
// of using the functional cast notation to call a constructor we exclude all `CStyleCast`s on
73-
// uninstantiated templates, and instead rely on reporting results within instantiations.
74-
notc.isFromUninstantiatedTemplate(_)and
75-
// Exclude casts created from macro invocations of macros defined by third parties
68+
// Not generated from a library macro
7669
notgetGeneratedFrom(c)instanceofLibraryMacroand
7770
// If the cast was generated from a user-provided macro, then report the macro that generated the
7871
// cast, as the macro itself may have generated the cast

‎cpp/autosar/src/rules/M5-2-2/PointerToAVirtualBaseClassCastToAPointer.ql‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18+
import codingstandards.cpp.rules.pointertoavirtualbaseclasscasttoapointer.PointerToAVirtualBaseClassCastToAPointer
1819

19-
fromCastcast,VirtualBaseClasscastFrom,ClasscastTo
20-
where
21-
notisExcluded(cast, PointersPackage::pointerToAVirtualBaseClassCastToAPointerQuery())and
22-
notcastinstanceofDynamicCastand
23-
castFrom=cast.getExpr().getType().(PointerType).getBaseType()and
24-
cast.getType().(PointerType).getBaseType()=castToand
25-
castTo=castFrom.getADerivedClass+()
26-
selectcast,
27-
"A pointer to virtual base class $@ is not cast to a pointer of derived class $@ using a dynamic_cast.",
28-
castFrom,castFrom.getName(),castTo,castTo.getName()
20+
classPointerToAVirtualBaseClassCastToAPointerQueryextendsPointerToAVirtualBaseClassCastToAPointerSharedQuery
21+
{
22+
PointerToAVirtualBaseClassCastToAPointerQuery(){
23+
this= PointersPackage::pointerToAVirtualBaseClassCastToAPointerQuery()
24+
}
25+
}

‎cpp/autosar/test/rules/A5-2-2/test.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include<string>
33
#include<utility>
44
intfoo() {return1; }
5-
5+
// A copy of 8.2,2 test.cpp, but with different cases compliant/non-compliant
66
voidtest_c_style_cast() {
77
double f =3.14;
88
std::uint32_t n1 = (std::uint32_t)f;// NON_COMPLIANT - C-style cast

‎cpp/autosar/test/rules/M5-2-2/PointerToAVirtualBaseClassCastToAPointer.expected‎

Whitespace-only changes.

‎cpp/autosar/test/rules/M5-2-2/PointerToAVirtualBaseClassCastToAPointer.qlref‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎cpp/autosar/test/rules/M5-2-2/test.cpp‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎cpp/common/src/codingstandards/cpp/AlertReporting.qll‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,28 @@ module MacroUnwrapper<ResultType ResultElement> {
1414
* Gets a macro invocation that applies to the result element.
1515
*/
1616
privateMacroInvocationgetAMacroInvocation(ResultElementre){
17-
result.getAnExpandedElement()=re
17+
result.getAnAffectedElement()=re
18+
}
19+
20+
privateMacroInvocationgetASubsumedMacroInvocation(ResultElementre){
21+
result=getAMacroInvocation(re)and
22+
// Only report cases where the element is not located at the macro expansion site
23+
// This means we'll report results in macro arguments in the macro argument
24+
// location, not within the macro itself.
25+
//
26+
// Do not join start column values.
27+
pragma[only_bind_out](result.getLocation().getStartColumn())=
28+
pragma[only_bind_out](re.getLocation().getStartColumn())
1829
}
1930

2031
/**
2132
* Gets the primary macro invocation that generated the result element.
33+
*
34+
* Does not hold for cases where the result element is located at a macro argument site.
2235
*/
2336
MacroInvocationgetPrimaryMacroInvocation(ResultElementre){
2437
exists(MacroInvocationmi|
25-
mi=getAMacroInvocation(re)and
38+
mi=getASubsumedMacroInvocation(re)and
2639
// No other more specific macro that expands to element
2740
notexists(MacroInvocationotherMi|
2841
otherMi=getAMacroInvocation(re)andotherMi.getParentInvocation()=mi
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import cpp
2+
import codingstandards.cpp.Macro
3+
4+
/**
5+
* A C-style cast that is explicitly user written and has a known target type.
6+
*/
7+
classExplicitUserDefinedCStyleCastextendsCStyleCast{
8+
ExplicitUserDefinedCStyleCast(){
9+
notthis.isImplicit()and
10+
notthis.getType()instanceofUnknownTypeand
11+
// For casts in templates that occur on types related to a template parameter, the copy of th
12+
// cast in the uninstantiated template is represented as a `CStyleCast` even if in practice all
13+
// the instantiations represent it as a `ConstructorCall`. To avoid the common false positive case
14+
// of using the functional cast notation to call a constructor we exclude all `CStyleCast`s on
15+
// uninstantiated templates, and instead rely on reporting results within instantiations.
16+
notthis.isFromUninstantiatedTemplate(_)
17+
}
18+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp