Merge branch 'master' into cpp340a

This commit is contained in:
Ziemowit Laski
2019-04-03 17:52:46 -07:00
76 changed files with 745 additions and 308 deletions

View File

@@ -2,7 +2,7 @@
* @name Hub classes
* @description Shows coupling between classes. Large, red, boxes are hub types that depend on many other classes
* and are depended on by many other classes.
* @kind treemap
* @kind table
* @id cpp/architecture/hub-classes
* @treemap.warnOn highValues
* @tags maintainability

View File

@@ -10,6 +10,7 @@
*/
import cpp
import semmle.code.cpp.commons.Exclusions
Stmt getNextRealStmt(Block b, int i) {
result = b.getStmt(i + 1) and
@@ -30,4 +31,6 @@ where b.getStmt(i) = js
// the next statement isn't a loop that can be jumped into
and not exists (LabelStmt ls | s.(Loop).getStmt().getAChild*() = ls)
and not exists (SwitchCase sc | s.(Loop).getStmt().getAChild*() = sc)
// no preprocessor logic applies
and not functionContainsPreprocCode(js.getEnclosingFunction())
select js, "This statement makes $@ unreachable.", s, s.toString()

View File

@@ -12,5 +12,4 @@ import cpp
from Function f, int c
where c = f.getMetrics().getCyclomaticComplexity() and
c > 20
select f, c as CyclomaticComplexity,
"AV Rule 3: All functions shall have a cyclomatic complexity number of 20 or less."
select f, "AV Rule 3: All functions shall have a cyclomatic complexity number of 20 or less."

View File

@@ -3,6 +3,7 @@
* @description The assignment operator shall handle self-assignment correctly.
* @kind problem
* @id cpp/jsf/av-rule-81
* @precision low
* @problem.severity error
* @tags correctness
* external/jsf
@@ -77,4 +78,4 @@ where hasResource(op.getDeclaringType())
and not exists(op.getASelfEqualityTest())
and not exists(op.getASwapCall())
and exists(op.getADeleteExpr())
select op
select op, "AV Rule 81: The assignment operator shall handle self-assignment correctly."

View File

@@ -1,7 +1,7 @@
/**
* @name AST Sanity Check
* @description Performs sanity checks on the Abstract Syntax Tree. This query should have no results.
* @kind problem
* @kind table
* @id cpp/ast-sanity-check
*/

View File

@@ -23,11 +23,15 @@ private bindingset[comment] predicate autogeneratedComment(string comment) {
// changes made in this file will be lost
"(changes made in this file will be lost)|" +
// do not edit/modify
// do not edit/modify (not mid-sentence)
"(^ do(n't|nt| not) (hand-?)?(edit|modify))|" +
"(! do(n't|nt| not) (hand-?)?(edit|modify))" and
"(! do(n't|nt| not) (hand-?)?(edit|modify))|" +
// do not edit/modify + generated
"(do(n't|nt| not) (hand-?)?(edit|modify).*generated)|" +
"(generated.*do(n't|nt| not) (hand-?)?(edit|modify))" and
comment.regexpMatch("(?si).*(" +
// replace `generated` with a regexp that also catches things like
// `auto-generated`.

View File

@@ -58,3 +58,16 @@ predicate functionContainsDisabledCode(Function f) {
)
)
}
/**
* Holds if the function `f` contains code that could be excluded by the preprocessor.
*/
predicate functionContainsPreprocCode(Function f) {
// `f` contains a preprocessor branch
exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int fBlockStartLine, int fBlockEndLine |
functionLocation(f, file, fBlockStartLine, fBlockEndLine) and
pbdLocation(pbd, file, pbdStartLine) and
pbdStartLine <= fBlockEndLine and
pbdStartLine >= fBlockStartLine
)
}

View File

@@ -572,9 +572,8 @@ class FormatLiteral extends Literal {
((len="hh" and result instanceof IntType)
or (len="h" and result instanceof IntType)
or (len="l" and result = this.getLongType())
or ((len="ll" or len="q")
or ((len="ll" or len="L" or len="q")
and result instanceof LongLongType)
or (len="L" and result instanceof IntType) // doesn't affect integral conversion
or (len="j" and result = this.getIntmax_t())
or ((len="z" or len="Z")
and (result = this.getSize_t() or result = this.getSsize_t()))
@@ -599,9 +598,8 @@ class FormatLiteral extends Literal {
((len="hh" and result instanceof CharType)
or (len="h" and result instanceof ShortType)
or (len="l" and result = this.getLongType())
or ((len="ll" or len="q")
or ((len="ll" or len="L" or len="q")
and result instanceof LongLongType)
or (len="L" and result instanceof IntType) // doesn't affect integral conversion
or (len="j" and result = this.getIntmax_t())
or ((len="z" or len="Z")
and (result = this.getSize_t() or result = this.getSsize_t()))
@@ -622,7 +620,7 @@ class FormatLiteral extends Literal {
*/
FloatingPointType getFloatingPointConversion(int n) {
exists(string len | len = this.getLength(n) and
if len="L" then
if (len="L" or len="ll") then
result instanceof LongDoubleType
else
result instanceof DoubleType)
@@ -638,7 +636,7 @@ class FormatLiteral extends Literal {
(len="hh" and base instanceof CharType)
or (len="h" and base instanceof ShortType)
or (len="l" and base = this.getLongType())
or (len="ll" and base instanceof LongLongType)
or ((len="ll" or len="L") and base instanceof LongLongType)
or (len="q" and base instanceof LongLongType)
)
and base.isSigned() and base = result.getBaseType()

View File

@@ -1,7 +1,7 @@
/**
* @name IR Sanity Check
* @description Performs sanity checks on the Intermediate Representation. This query should have no results.
* @kind problem
* @kind table
* @id cpp/ir-sanity-check
*/

View File

@@ -1,7 +1,7 @@
/**
* @name Aliased SSA IR Sanity Check
* @description Performs sanity checks on the Intermediate Representation. This query should have no results.
* @kind problem
* @kind table
* @id cpp/aliased-ssa-ir-sanity-check
*/

View File

@@ -1,7 +1,7 @@
/**
* @name Raw IR Sanity Check
* @description Performs sanity checks on the Intermediate Representation. This query should have no results.
* @kind problem
* @kind table
* @id cpp/raw-ir-sanity-check
*/

View File

@@ -1,7 +1,7 @@
/**
* @name SSA IR Sanity Check
* @description Performs sanity checks on the Intermediate Representation. This query should have no results.
* @kind problem
* @kind table
* @id cpp/ssa-ir-sanity-check
*/

View File

@@ -1,7 +1,7 @@
/**
* @name Padding Sanity Check
* @description Performs sanity checks for the padding library. This query should have no results.
* @kind problem
* @kind table
* @id cpp/padding-sanity-check
*/