Skip to content

Commit 71a6b5d

Browse files
C++/C#: Fix some duplicate IRType problems, and add a sanity test
1 parent f871c72 commit 71a6b5d

File tree

13 files changed

+41
-1
lines changed

13 files changed

+41
-1
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/IRType.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,14 @@ module IRTypeSanity {
248248
strictcount(type.getCanonicalLanguageType()) > 1 and
249249
message = "Type has multiple canonical `LanguageType`s: " + concat(type.getCanonicalLanguageType().toString(), ", ")
250250
}
251+
252+
query predicate missingIRType(Language::LanguageType type, string message) {
253+
not exists(type.getIRType()) and
254+
message = "`LanguageType` does not have a corresponding `IRType`."
255+
}
256+
257+
query predicate multipleIRTypes(Language::LanguageType type, string message) {
258+
strictcount(type.getIRType()) > 1 and
259+
message = "`LanguageType` " + type.getAQlClass() + " has multiple `IRType`s: " + concat(type.getIRType().toString(), ", ")
260+
}
251261
}

cpp/ql/src/semmle/code/cpp/ir/internal/CppType.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private class CppUnknownOpaqueType extends CppType, TUnknownOpaqueType {
263263
}
264264

265265
override final IROpaqueType getIRType() {
266-
result.getByteSize() = byteSize
266+
result.getByteSize() = byteSize and result.getTag() instanceof UnknownType
267267
}
268268

269269
override predicate hasType(Type type, boolean isGLValue) {

cpp/ql/test/library-tests/ir/ir/aliased_ssa_sanity.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ backEdgeCountMismatch
1515
useNotDominatedByDefinition
1616
missingCanonicalLanguageType
1717
multipleCanonicalLanguageTypes
18+
missingIRType
19+
multipleIRTypes

cpp/ql/test/library-tests/ir/ir/raw_sanity.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ backEdgeCountMismatch
1515
useNotDominatedByDefinition
1616
missingCanonicalLanguageType
1717
multipleCanonicalLanguageTypes
18+
missingIRType
19+
multipleIRTypes

cpp/ql/test/library-tests/ir/ir/unaliased_ssa_sanity.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ backEdgeCountMismatch
1515
useNotDominatedByDefinition
1616
missingCanonicalLanguageType
1717
multipleCanonicalLanguageTypes
18+
missingIRType
19+
multipleIRTypes

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_sanity.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ backEdgeCountMismatch
1515
useNotDominatedByDefinition
1616
missingCanonicalLanguageType
1717
multipleCanonicalLanguageTypes
18+
missingIRType
19+
multipleIRTypes

cpp/ql/test/library-tests/ir/ssa/unaliased_ssa_sanity.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ backEdgeCountMismatch
1515
useNotDominatedByDefinition
1616
missingCanonicalLanguageType
1717
multipleCanonicalLanguageTypes
18+
missingIRType
19+
multipleIRTypes

cpp/ql/test/library-tests/syntax-zoo/aliased_ssa_sanity.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,3 +546,5 @@ backEdgeCountMismatch
546546
useNotDominatedByDefinition
547547
missingCanonicalLanguageType
548548
multipleCanonicalLanguageTypes
549+
missingIRType
550+
multipleIRTypes

cpp/ql/test/library-tests/syntax-zoo/raw_sanity.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,3 +694,5 @@ useNotDominatedByDefinition
694694
| vla.c:14:74:14:79 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | vla.c:11:6:11:16 | IR: vla_typedef | void vla_typedef() |
695695
missingCanonicalLanguageType
696696
multipleCanonicalLanguageTypes
697+
missingIRType
698+
multipleIRTypes

cpp/ql/test/library-tests/syntax-zoo/unaliased_ssa_sanity.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,5 @@ backEdgeCountMismatch
555555
useNotDominatedByDefinition
556556
missingCanonicalLanguageType
557557
multipleCanonicalLanguageTypes
558+
missingIRType
559+
multipleIRTypes

0 commit comments

Comments
 (0)