Skip to content

C++: resolveElement #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cpp/ql/src/AlertSuppression.ql
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class SuppressionComment extends CppStyleComment {
*/
class SuppressionScope extends @comment {
SuppressionScope() {
this instanceof SuppressionComment
mkElement(this) instanceof SuppressionComment
}

/** Gets a suppression comment with this scope. */
SuppressionComment getSuppressionComment() {
result = this
result = mkElement(this)
}

/**
Expand All @@ -72,7 +72,7 @@ class SuppressionScope extends @comment {
* [LGTM locations](https://lgtm.com/help/ql/locations).
*/
predicate hasLocationInfo(string filepath, int startline, int startcolumn, int endline, int endcolumn) {
this.(SuppressionComment).covers(filepath, startline, startcolumn, endline, endcolumn)
mkElement(this).(SuppressionComment).covers(filepath, startline, startcolumn, endline, endcolumn)
}

/** Gets a textual representation of this element. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import cpp

string kindstr(Class c)
{
exists(int kind | usertypes(c, _, kind) |
exists(int kind | usertypes(unresolveElement(c), _, kind) |
(kind = 1 and result = "Struct") or
(kind = 2 and result = "Class") or
(kind = 6 and result = "Template class")
Expand Down Expand Up @@ -48,37 +48,38 @@ predicate masterVde(VariableDeclarationEntry master, VariableDeclarationEntry vd

class VariableDeclarationGroup extends @var_decl {
VariableDeclarationGroup() {
not previousVde(_, this)
not previousVde(_, mkElement(this))
}
Class getClass() {
vdeInfo(this, result, _, _)
vdeInfo(mkElement(this), result, _, _)
}

// pragma[noopt] since otherwise the two locationInfo relations get join-ordered
// after each other
pragma[noopt]
predicate hasLocationInfo(string path, int startline, int startcol, int endline, int endcol) {
exists(VariableDeclarationEntry last, Location lstart, Location lend |
masterVde(this, last) and
exists(Element thisElement, VariableDeclarationEntry last, Location lstart, Location lend |
thisElement = mkElement(this) and
masterVde(thisElement, last) and
this instanceof VariableDeclarationGroup and
not previousVde(last, _) and
exists(VariableDeclarationEntry vde | vde=this and vde instanceof VariableDeclarationEntry and vde.getLocation() = lstart) and
exists(VariableDeclarationEntry vde | vde=mkElement(this) and vde instanceof VariableDeclarationEntry and vde.getLocation() = lstart) and
last.getLocation() = lend and
lstart.hasLocationInfo(path, startline, startcol, _, _) and
lend.hasLocationInfo(path, _, _, endline, endcol)
)
}

string toString() {
if previousVde(this, _) then
if previousVde(mkElement(this), _) then
result = "group of "
+ strictcount(string name
| exists(VariableDeclarationEntry vde
| masterVde(this, vde) and
| masterVde(mkElement(this), vde) and
name = vde.getName()))
+ " fields here"
else
result = "declaration of " + this.(VariableDeclarationEntry).getVariable().getName()
result = "declaration of " + mkElement(this).(VariableDeclarationEntry).getVariable().getName()
}
}

Expand Down
5 changes: 1 addition & 4 deletions cpp/ql/src/CPython/Extensions.qll
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ import CPython.ArgParse


/* Root class of all 'C' objects */
abstract class CObject extends @element {
abstract class CObject extends Element {

abstract string getTrapID();

/** Gets a textual representation of this element. */
abstract string toString();
}


Expand Down
2 changes: 1 addition & 1 deletion cpp/ql/src/Likely Bugs/Format/SnprintfOverflow.ql
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ predicate flowsToDefImpl(
or
// `x++`
exists (CrementOperation crem
| def = crem and
| mkElement(def) = crem and
crem.getOperand() = v.getAnAccess() and
flowsToExpr(source, crem.getOperand(), pathMightOverflow))
or
Expand Down
2 changes: 1 addition & 1 deletion cpp/ql/src/Metrics/Dependencies/ExternalDependencies.qll
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Library extends LibraryT {
result = lib.getAFile()
) or exists(@external_package ep |
this = LibraryTExternalPackage(ep, _, _) and
header_to_external_package(result, ep)
header_to_external_package(unresolveElement(result), ep)
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/ql/src/Metrics/Files/FCommentRatio.ql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
import cpp

from File f, int comments, int total
where f.fromSource() and numlines(f, total, _, comments) and total > 0
where f.fromSource() and numlines(unresolveElement(f), total, _, comments) and total > 0
select f, 100.0 * (comments.(float) / total.(float)) as ratio
order by ratio desc
4 changes: 2 additions & 2 deletions cpp/ql/src/PointsTo/PreparedStagedPointsTo.ql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

import semmle.code.cpp.pointsto.PointsTo

select count(int set, Element location | setlocations(set, location)),
count(int set, Element element | pointstosets(set, element))
select count(int set, Element location | setlocations(set, unresolveElement(location))),
count(int set, Element element | pointstosets(set, unresolveElement(element)))

2 changes: 1 addition & 1 deletion cpp/ql/src/Security/CWE/CWE-764/LockFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ predicate tryLockCondition(VariableAccess access,
(cond = call.getParent*() and
cond.isCondition() and
failNode = cond.getASuccessor() and
failNode instanceof BasicBlockWithReturn))
unresolveElement(failNode) instanceof BasicBlockWithReturn))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cpp/ql/src/Security/CWE/CWE-764/UnreleasedLock.ql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ predicate failedLock(MutexType t, BasicBlock lockblock, BasicBlock failblock) {
exists (ControlFlowNode lock |
lock = lockblock.getEnd() and
lock = t.getLockAccess() and
lock.getAFalseSuccessor() = failblock
lock.getAFalseSuccessor() = mkElement(failblock)
)
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/ql/src/external/CodeDuplication.qll
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class SimilarBlock extends Copy, @similarity

FunctionDeclarationEntry sourceMethod() {
result.isDefinition() and
exists(result.getLocation()) and numlines(result.getFunction(),_,_,_)
exists(result.getLocation()) and numlines(unresolveElement(result.getFunction()),_,_,_)
}

int numberOfSourceMethods(Class c) {
Expand Down
6 changes: 3 additions & 3 deletions cpp/ql/src/external/VCS.qll
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Commit extends @svnentry {
string getMessage() { svnentrymsg(this, result) }

string getAnAffectedFilePath(string action) {
exists(File rawFile | svnaffectedfiles(this, rawFile, action) |
exists(File rawFile | svnaffectedfiles(this, unresolveElement(rawFile), action) |
result = rawFile.getAbsolutePath()
)
}
Expand All @@ -34,7 +34,7 @@ class Commit extends @svnentry {
File getAnAffectedFile(string action) {
// Workaround for incorrect keys in SVN data
exists(File svnFile | svnFile.getAbsolutePath() = result.getAbsolutePath() |
svnaffectedfiles(this,svnFile,action)
svnaffectedfiles(this,unresolveElement(svnFile),action)
)
and exists(result.getMetrics().getNumberOfLinesOfCode())
}
Expand All @@ -44,7 +44,7 @@ class Commit extends @svnentry {
private predicate churnForFile(File f, int added, int deleted) {
// Workaround for incorrect keys in SVN data
exists(File svnFile | svnFile.getAbsolutePath() = f.getAbsolutePath() |
svnchurn(this,svnFile,added,deleted)
svnchurn(this,unresolveElement(svnFile),added,deleted)
)
and exists(f.getMetrics().getNumberOfLinesOfCode())
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/ql/src/jsf/4.10 Classes/AV Rule 88.ql
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ An approximation of this definition is classes with pure virtual functions and l
*/
class InterfaceClass extends Class {
InterfaceClass() {
exists(MemberFunction m | m.getDeclaringType() = this and not compgenerated(m))
exists(MemberFunction m | m.getDeclaringType() = this and not compgenerated(unresolveElement(m)))
and
forall(MemberFunction m | m.getDeclaringType() = this and not compgenerated(m) | m instanceof PureVirtualFunction)
forall(MemberFunction m | m.getDeclaringType() = this and not compgenerated(unresolveElement(m)) | m instanceof PureVirtualFunction)
and
count(MemberVariable v | v.getDeclaringType() = this) < 3
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/ql/src/jsf/4.25 Expressions/AV Rule 204.ql
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ where impureExprInDisallowedContext(e) and
not e.isCompilerGenerated() and
// A few cases that are always ok
not e instanceof Conversion and
not exists(@ctorinit ci | e = ci) and
not exists(@dtordestruct dd | e = dd) and
not exists(@ctorinit ci | e = mkElement(ci)) and
not exists(@dtordestruct dd | e = mkElement(dd)) and
// Avoid flagging nested expressions
not impureExprInDisallowedContext(e.getParent+())
select e.findRootCause(), "AV Rule 204: A single operation with side-effects shall only be used in certain contexts."
2 changes: 1 addition & 1 deletion cpp/ql/src/semmle/code/cpp/AutogeneratedFile.qll
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AutogeneratedFile extends File {
cached AutogeneratedFile() {
exists(int limit, int head |
head <= 5 and
limit = max(int line | locations_default(_, this, head, _, line, _)) + 5
limit = max(int line | locations_default(_, underlyingElement(this), head, _, line, _)) + 5
|
exists (Comment c | c.getFile() = this and c.getLocation().getStartLine() <= limit and isAutogeneratedComment(c))
)
Expand Down
Loading