Skip to content

Commit 7be7640

Browse files
authored
Merge pull request #15741 from MathiasVP/fix-ir-inconsistencies-from-returning-routine-types
C++: Fix IR inconsistencies from routine types
2 parents 0358e81 + b8c141f commit 7be7640

File tree

6 files changed

+70
-2
lines changed

6 files changed

+70
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ private int getTypeSizeWorkaround(Type type) {
1111
exists(Type unspecifiedType |
1212
unspecifiedType = type.getUnspecifiedType() and
1313
(
14-
unspecifiedType instanceof FunctionReferenceType and
14+
(unspecifiedType instanceof FunctionReferenceType or unspecifiedType instanceof RoutineType) and
1515
result = getPointerSize()
1616
or
1717
exists(PointerToMemberType ptmType |
@@ -176,7 +176,7 @@ private IRType getIRTypeForPRValue(Type type) {
176176
isPointerIshType(unspecifiedType) and
177177
result.(IRAddressType).getByteSize() = getTypeSize(unspecifiedType)
178178
or
179-
unspecifiedType instanceof FunctionPointerIshType and
179+
(unspecifiedType instanceof FunctionPointerIshType or unspecifiedType instanceof RoutineType) and
180180
result.(IRFunctionAddressType).getByteSize() = getTypeSize(type)
181181
or
182182
unspecifiedType instanceof VoidType and result instanceof IRVoidType

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18076,6 +18076,25 @@ ir.cpp:
1807618076
# 2317| getQualifier(): [VariableAccess] s
1807718077
# 2317| Type = [Struct] String
1807818078
# 2317| ValueCategory = lvalue
18079+
# 2320| [CopyAssignmentOperator] return_routine_type::HasVoidToIntFunc& return_routine_type::HasVoidToIntFunc::operator=(return_routine_type::HasVoidToIntFunc const&)
18080+
# 2320| <params>:
18081+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
18082+
#-----| Type = [LValueReferenceType] const HasVoidToIntFunc &
18083+
# 2320| [MoveAssignmentOperator] return_routine_type::HasVoidToIntFunc& return_routine_type::HasVoidToIntFunc::operator=(return_routine_type::HasVoidToIntFunc&&)
18084+
# 2320| <params>:
18085+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
18086+
#-----| Type = [RValueReferenceType] HasVoidToIntFunc &&
18087+
# 2322| [MemberFunction] void return_routine_type::HasVoidToIntFunc::VoidToInt(int)
18088+
# 2322| <params>:
18089+
# 2322| getParameter(0): [Parameter] (unnamed parameter 0)
18090+
# 2322| Type = [IntType] int
18091+
# 2327| [TopLevelFunction] return_routine_type::VoidToIntMemberFunc return_routine_type::GetVoidToIntFunc()
18092+
# 2327| <params>:
18093+
# 2328| getEntryPoint(): [BlockStmt] { ... }
18094+
# 2329| getStmt(0): [ReturnStmt] return ...
18095+
# 2329| getExpr(): [FunctionAccess] VoidToInt
18096+
# 2329| Type = [RoutineType] ..()(..)
18097+
# 2329| ValueCategory = prvalue
1807918098
perf-regression.cpp:
1808018099
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
1808118100
# 4| <params>:

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14579,6 +14579,20 @@ ir.cpp:
1457914579
# 2314| v2314_6(void) = AliasedUse : ~m2317_5
1458014580
# 2314| v2314_7(void) = ExitFunction :
1458114581

14582+
# 2327| return_routine_type::VoidToIntMemberFunc return_routine_type::GetVoidToIntFunc()
14583+
# 2327| Block 0
14584+
# 2327| v2327_1(void) = EnterFunction :
14585+
# 2327| m2327_2(unknown) = AliasedDefinition :
14586+
# 2327| m2327_3(unknown) = InitializeNonLocal :
14587+
# 2327| m2327_4(unknown) = Chi : total:m2327_2, partial:m2327_3
14588+
# 2329| r2329_1(glval<..:: *>) = VariableAddress[#return] :
14589+
# 2329| r2329_2(..()(..)) = FunctionAddress[VoidToInt] :
14590+
# 2329| m2329_3(..:: *) = Store[#return] : &:r2329_1, r2329_2
14591+
# 2327| r2327_5(glval<..:: *>) = VariableAddress[#return] :
14592+
# 2327| v2327_6(void) = ReturnValue : &:r2327_5, m2329_3
14593+
# 2327| v2327_7(void) = AliasedUse : m2327_3
14594+
# 2327| v2327_8(void) = ExitFunction :
14595+
1458214596
perf-regression.cpp:
1458314597
# 6| void Big::Big()
1458414598
# 6| Block 0

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,4 +2316,19 @@ void VoidReturnDestructors() {
23162316
return VoidFunc();
23172317
}
23182318

2319+
namespace return_routine_type {
2320+
struct HasVoidToIntFunc
2321+
{
2322+
void VoidToInt(int);
2323+
};
2324+
2325+
typedef void (HasVoidToIntFunc::*VoidToIntMemberFunc)(int);
2326+
2327+
static VoidToIntMemberFunc GetVoidToIntFunc()
2328+
{
2329+
return &HasVoidToIntFunc::VoidToInt;
2330+
}
2331+
2332+
}
2333+
23192334
// semmle-extractor-options: -std=c++20 --clang

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12029,6 +12029,13 @@
1202912029
| ir.cpp:2317:1:2317:1 | ChiTotal | total:m2316_4 |
1203012030
| ir.cpp:2317:1:2317:1 | SideEffect | m2315_8 |
1203112031
| ir.cpp:2317:1:2317:1 | SideEffect | ~m2316_4 |
12032+
| ir.cpp:2327:32:2327:47 | Address | &:r2327_5 |
12033+
| ir.cpp:2327:32:2327:47 | ChiPartial | partial:m2327_3 |
12034+
| ir.cpp:2327:32:2327:47 | ChiTotal | total:m2327_2 |
12035+
| ir.cpp:2327:32:2327:47 | Load | m2329_3 |
12036+
| ir.cpp:2327:32:2327:47 | SideEffect | m2327_3 |
12037+
| ir.cpp:2329:9:2329:44 | Address | &:r2329_1 |
12038+
| ir.cpp:2329:16:2329:43 | StoreValue | r2329_2 |
1203212039
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
1203312040
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
1203412041
| perf-regression.cpp:6:3:6:5 | Address | &:r6_7 |

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13510,6 +13510,19 @@ ir.cpp:
1351013510
# 2314| v2314_5(void) = AliasedUse : ~m?
1351113511
# 2314| v2314_6(void) = ExitFunction :
1351213512

13513+
# 2327| return_routine_type::VoidToIntMemberFunc return_routine_type::GetVoidToIntFunc()
13514+
# 2327| Block 0
13515+
# 2327| v2327_1(void) = EnterFunction :
13516+
# 2327| mu2327_2(unknown) = AliasedDefinition :
13517+
# 2327| mu2327_3(unknown) = InitializeNonLocal :
13518+
# 2329| r2329_1(glval<..:: *>) = VariableAddress[#return] :
13519+
# 2329| r2329_2(..()(..)) = FunctionAddress[VoidToInt] :
13520+
# 2329| mu2329_3(..:: *) = Store[#return] : &:r2329_1, r2329_2
13521+
# 2327| r2327_4(glval<..:: *>) = VariableAddress[#return] :
13522+
# 2327| v2327_5(void) = ReturnValue : &:r2327_4, ~m?
13523+
# 2327| v2327_6(void) = AliasedUse : ~m?
13524+
# 2327| v2327_7(void) = ExitFunction :
13525+
1351313526
perf-regression.cpp:
1351413527
# 6| void Big::Big()
1351513528
# 6| Block 0

0 commit comments

Comments
 (0)