Skip to content

Commit 9538ac7

Browse files
authored
account for non-existing locations
1 parent d626745 commit 9538ac7

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/Operand.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,15 @@ class ThisArgumentOperand extends ArgumentOperand {
416416
// in most cases the def location makes more sense, but in some corner cases it
417417
// does not have a location: in those cases we fall back to the use location
418418
override Language::Location getLocation() {
419-
if not this.getAnyDef().getLocation() instanceof Language::UnknownLocation
420-
then result = this.getAnyDef().getLocation()
421-
else result = this.getUse().getLocation()
419+
result = selectLocation(this.getAnyDef().getLocation(), this.getUse().getLocation())
420+
}
421+
422+
private Language::Location selectLocation(
423+
Language::Location preferred, Language::Location fallback
424+
) {
425+
if not exists(preferred) or preferred instanceof Language::UnknownLocation
426+
then result = fallback
427+
else result = preferred
422428
}
423429
}
424430

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/Operand.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,15 @@ class ThisArgumentOperand extends ArgumentOperand {
416416
// in most cases the def location makes more sense, but in some corner cases it
417417
// does not have a location: in those cases we fall back to the use location
418418
override Language::Location getLocation() {
419-
if not this.getAnyDef().getLocation() instanceof Language::UnknownLocation
420-
then result = this.getAnyDef().getLocation()
421-
else result = this.getUse().getLocation()
419+
result = selectLocation(this.getAnyDef().getLocation(), this.getUse().getLocation())
420+
}
421+
422+
private Language::Location selectLocation(
423+
Language::Location preferred, Language::Location fallback
424+
) {
425+
if not exists(preferred) or preferred instanceof Language::UnknownLocation
426+
then result = fallback
427+
else result = preferred
422428
}
423429
}
424430

cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/Operand.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,15 @@ class ThisArgumentOperand extends ArgumentOperand {
416416
// in most cases the def location makes more sense, but in some corner cases it
417417
// does not have a location: in those cases we fall back to the use location
418418
override Language::Location getLocation() {
419-
if not this.getAnyDef().getLocation() instanceof Language::UnknownLocation
420-
then result = this.getAnyDef().getLocation()
421-
else result = this.getUse().getLocation()
419+
result = selectLocation(this.getAnyDef().getLocation(), this.getUse().getLocation())
420+
}
421+
422+
private Language::Location selectLocation(
423+
Language::Location preferred, Language::Location fallback
424+
) {
425+
if not exists(preferred) or preferred instanceof Language::UnknownLocation
426+
then result = fallback
427+
else result = preferred
422428
}
423429
}
424430

csharp/ql/src/experimental/ir/implementation/raw/Operand.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,15 @@ class ThisArgumentOperand extends ArgumentOperand {
416416
// in most cases the def location makes more sense, but in some corner cases it
417417
// does not have a location: in those cases we fall back to the use location
418418
override Language::Location getLocation() {
419-
if not this.getAnyDef().getLocation() instanceof Language::UnknownLocation
420-
then result = this.getAnyDef().getLocation()
421-
else result = this.getUse().getLocation()
419+
result = selectLocation(this.getAnyDef().getLocation(), this.getUse().getLocation())
420+
}
421+
422+
private Language::Location selectLocation(
423+
Language::Location preferred, Language::Location fallback
424+
) {
425+
if not exists(preferred) or preferred instanceof Language::UnknownLocation
426+
then result = fallback
427+
else result = preferred
422428
}
423429
}
424430

csharp/ql/src/experimental/ir/implementation/unaliased_ssa/Operand.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,15 @@ class ThisArgumentOperand extends ArgumentOperand {
416416
// in most cases the def location makes more sense, but in some corner cases it
417417
// does not have a location: in those cases we fall back to the use location
418418
override Language::Location getLocation() {
419-
if not this.getAnyDef().getLocation() instanceof Language::UnknownLocation
420-
then result = this.getAnyDef().getLocation()
421-
else result = this.getUse().getLocation()
419+
result = selectLocation(this.getAnyDef().getLocation(), this.getUse().getLocation())
420+
}
421+
422+
private Language::Location selectLocation(
423+
Language::Location preferred, Language::Location fallback
424+
) {
425+
if not exists(preferred) or preferred instanceof Language::UnknownLocation
426+
then result = fallback
427+
else result = preferred
422428
}
423429
}
424430

0 commit comments

Comments
 (0)