-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathDuplicateInlineFunctionDefinitions.ql
More file actions
53 lines (46 loc) · 1.75 KB
/
DuplicateInlineFunctionDefinitions.ql
File metadata and controls
53 lines (46 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @id cpp/misra/duplicate-inline-function-definitions
* @name RULE-6-2-3: The source code used to implement an entity shall appear only once
* @description Implementing an entity in multiple source locations increases the risk of ODR
* violations and undefined behavior.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/rule-6-2-3
* correctness
* maintainability
* scope/system
* external/misra/enforcement/decidable
* external/misra/obligation/required
*/
import cpp
import codingstandards.cpp.misra
import codingstandards.cpp.types.Compatible
class RelevantDeclaration extends FunctionDeclarationEntry {
Function function;
RelevantDeclaration() {
isDefinition() and
function = getDeclaration() and
function.isInline()
}
string getQualifiedName() { result = function.getQualifiedName() }
}
predicate interestedInFunctions(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
not f1 = f2 and
exists(RelevantDeclaration d1, RelevantDeclaration d2 |
f1 = d1 and
f2 = d2 and
d1.getQualifiedName() = d2.getQualifiedName() and
not f1.getFile() = f2.getFile()
)
}
module FunDeclEquiv =
FunctionDeclarationTypeEquivalence<TypesCompatibleConfig, interestedInFunctions/2>;
from RelevantDeclaration d1, RelevantDeclaration d2
where
not isExcluded([d1, d2], Declarations8Package::duplicateInlineFunctionDefinitionsQuery()) and
interestedInFunctions(d1, d2) and
FunDeclEquiv::equalParameterTypes(d1, d2) and
d1.getFile().getAbsolutePath() < d2.getFile().getAbsolutePath()
select d1, "Inline function '" + d1.getName() + "' is implemented in multiple files: $@ and $@.",
d1, d1.getFile().getBaseName(), d2, d2.getFile().getBaseName()