Skip to content

Commit 327c4b3

Browse files
authored
Merge pull request #20058 from jketema/typeid-test
C++: Add test showing that the IR translation for `typeid` is broken
2 parents 9c3e275 + 477edd2 commit 327c4b3

10 files changed

+100
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50174,3 +50174,42 @@ try_except.cpp:
5017450174
# 52| Type = [IntType] int
5017550175
# 52| ValueCategory = prvalue(load)
5017650176
# 54| getStmt(2): [ReturnStmt] return ...
50177+
type_info_test.cpp:
50178+
# 3| [TopLevelFunction] void type_info_test(int)
50179+
# 3| <params>:
50180+
# 3| getParameter(0): [Parameter] x
50181+
# 3| Type = [IntType] int
50182+
# 3| getEntryPoint(): [BlockStmt] { ... }
50183+
# 4| getStmt(0): [DeclStmt] declaration
50184+
# 4| getDeclarationEntry(0): [VariableDeclarationEntry] definition of t1
50185+
# 4| Type = [LValueReferenceType] const type_info &
50186+
# 4| getVariable().getInitializer(): [Initializer] initializer for t1
50187+
# 4| getExpr(): [TypeidOperator] typeid ...
50188+
# 4| Type = [SpecifiedType] const type_info
50189+
# 4| ValueCategory = lvalue
50190+
# 4| getExpr(): [VariableAccess] x
50191+
# 4| Type = [IntType] int
50192+
# 4| ValueCategory = lvalue
50193+
# 4| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
50194+
# 4| Type = [LValueReferenceType] const type_info &
50195+
# 4| ValueCategory = prvalue
50196+
# 5| getStmt(1): [DeclStmt] declaration
50197+
# 5| getDeclarationEntry(0): [VariableDeclarationEntry] definition of t2
50198+
# 5| Type = [LValueReferenceType] const type_info &
50199+
# 5| getVariable().getInitializer(): [Initializer] initializer for t2
50200+
# 5| getExpr(): [TypeidOperator] typeid ...
50201+
# 5| Type = [SpecifiedType] const type_info
50202+
# 5| ValueCategory = lvalue
50203+
# 5| getExpr().getFullyConverted(): [ReferenceToExpr] (reference to)
50204+
# 5| Type = [LValueReferenceType] const type_info &
50205+
# 5| ValueCategory = prvalue
50206+
# 6| getStmt(2): [ReturnStmt] return ...
50207+
typeinfo:
50208+
# 4| [CopyAssignmentOperator] std::type_info& std::type_info::operator=(std::type_info const&)
50209+
# 4| <params>:
50210+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
50211+
#-----| Type = [LValueReferenceType] const type_info &
50212+
# 4| [MoveAssignmentOperator] std::type_info& std::type_info::operator=(std::type_info&&)
50213+
# 4| <params>:
50214+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
50215+
#-----| Type = [RValueReferenceType] type_info &&

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39973,3 +39973,14 @@ try_except.cpp:
3997339973

3997439974
# 44| Block 7
3997539975
# 44| v44_10(void) = Unreached :
39976+
39977+
type_info_test.cpp:
39978+
# 3| void type_info_test(int)
39979+
# 3| Block 0
39980+
# 3| v3_1(void) = EnterFunction :
39981+
# 3| m3_2(unknown) = AliasedDefinition :
39982+
# 3| m3_3(unknown) = InitializeNonLocal :
39983+
# 3| m3_4(unknown) = Chi : total:m3_2, partial:m3_3
39984+
# 3| r3_5(glval<int>) = VariableAddress[x] :
39985+
# 3| m3_6(int) = InitializeParameter[x] : &:r3_5
39986+
# 4| r4_1(glval<type_info &>) = VariableAddress[t1] :

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| type_info_test.cpp:4:25:4:26 | VariableAddress: definition of t1 | Instruction 'VariableAddress: definition of t1' has no successors in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| type_info_test.cpp:4:25:4:26 | VariableAddress: definition of t1 | Instruction 'VariableAddress: definition of t1' has no successors in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
missingOperand
2+
| type_info_test.cpp:4:30:4:38 | CopyValue: (reference to) | Instruction 'CopyValue' is missing an expected operand with tag 'Unary' in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
3+
| type_info_test.cpp:5:30:5:40 | CopyValue: (reference to) | Instruction 'CopyValue' is missing an expected operand with tag 'Unary' in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
24
unexpectedOperand
35
duplicateOperand
46
missingPhiOperand
57
missingOperandType
68
duplicateChiOperand
79
sideEffectWithoutPrimary
810
instructionWithoutSuccessor
11+
| type_info_test.cpp:4:25:4:26 | VariableAddress: definition of t1 | Instruction 'VariableAddress: definition of t1' has no successors in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
12+
| type_info_test.cpp:4:37:4:37 | VariableAddress: x | Instruction 'VariableAddress: x' has no successors in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
13+
| type_info_test.cpp:5:25:5:26 | VariableAddress: definition of t2 | Instruction 'VariableAddress: definition of t2' has no successors in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
914
ambiguousSuccessors
1015
unexplainedLoop
1116
unnecessaryPhiInstruction
@@ -21,6 +26,8 @@ lostReachability
2126
backEdgeCountMismatch
2227
useNotDominatedByDefinition
2328
| ir.cpp:1535:8:1535:8 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:1535:8:1535:8 | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() |
29+
| type_info_test.cpp:4:25:4:26 | Address | Operand 'Address' is not dominated by its definition in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
30+
| type_info_test.cpp:5:25:5:26 | Address | Operand 'Address' is not dominated by its definition in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
2431
switchInstructionWithoutDefaultEdge
2532
notMarkedAsConflated
2633
wronglyMarkedAsConflated

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38102,3 +38102,29 @@ try_except.cpp:
3810238102
# 54| v54_1(void) = NoOp :
3810338103
# 44| v44_9(void) = ReturnVoid :
3810438104
#-----| Goto -> Block 1
38105+
38106+
type_info_test.cpp:
38107+
# 3| void type_info_test(int)
38108+
# 3| Block 0
38109+
# 3| v3_1(void) = EnterFunction :
38110+
# 3| mu3_2(unknown) = AliasedDefinition :
38111+
# 3| mu3_3(unknown) = InitializeNonLocal :
38112+
# 3| r3_4(glval<int>) = VariableAddress[x] :
38113+
# 3| mu3_5(int) = InitializeParameter[x] : &:r3_4
38114+
# 4| r4_1(glval<type_info &>) = VariableAddress[t1] :
38115+
38116+
# 4| Block 1
38117+
# 4| r4_2(glval<int>) = VariableAddress[x] :
38118+
38119+
# 4| Block 2
38120+
# 4| r4_3(type_info &) = CopyValue :
38121+
# 4| mu4_4(type_info &) = Store[t1] : &:r4_1, r4_3
38122+
# 5| r5_1(glval<type_info &>) = VariableAddress[t2] :
38123+
38124+
# 5| Block 3
38125+
# 5| r5_2(type_info &) = CopyValue :
38126+
# 5| mu5_3(type_info &) = Store[t2] : &:r5_1, r5_2
38127+
# 6| v6_1(void) = NoOp :
38128+
# 3| v3_6(void) = ReturnVoid :
38129+
# 3| v3_7(void) = AliasedUse : ~m?
38130+
# 3| v3_8(void) = ExitFunction :
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <typeinfo>
2+
3+
void type_info_test(int x) {
4+
const std::type_info &t1 = typeid(x);
5+
const std::type_info &t2 = typeid(int);
6+
}
7+
8+
// semmle-extractor-options: -I.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
namespace std{
4+
class type_info {};
5+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| type_info_test.cpp:4:25:4:26 | VariableAddress: definition of t1 | Instruction 'VariableAddress: definition of t1' has no successors in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| type_info_test.cpp:4:25:4:26 | VariableAddress: definition of t1 | Instruction 'VariableAddress: definition of t1' has no successors in function '$@'. | type_info_test.cpp:3:6:3:19 | void type_info_test(int) | void type_info_test(int) |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

0 commit comments

Comments
 (0)