Skip to content

Commit 053e172

Browse files
committed
Merge branch 'main' into 13332-codeql-model-editor-csharp
2 parents 897786d + 65ec809 commit 053e172

40 files changed

+12411
-2900
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,6 +2359,47 @@ class TranslatedDestructorFieldDestruction extends TranslatedNonConstantExpr, St
23592359
private TranslatedExpr getDestructorCall() { result = getTranslatedExpr(expr.getExpr()) }
23602360
}
23612361

2362+
/**
2363+
* The IR translation of a vacuous destructor call. That is, an expression that
2364+
* looks like a destructor call, but has no effect.
2365+
*
2366+
* Note that, even though there's no destructor call, we should still evaluate
2367+
* the qualifier.
2368+
*/
2369+
class TranslatedVacuousDestructorCall extends TranslatedNonConstantExpr {
2370+
override VacuousDestructorCall expr;
2371+
2372+
override Instruction getInstructionSuccessorInternal(InstructionTag tag, EdgeKind kind) { none() }
2373+
2374+
final TranslatedExpr getQualifier() {
2375+
result = getTranslatedExpr(expr.getQualifier().getFullyConverted())
2376+
}
2377+
2378+
override Instruction getFirstInstruction(EdgeKind kind) {
2379+
result = this.getQualifier().getFirstInstruction(kind)
2380+
}
2381+
2382+
override Instruction getChildSuccessorInternal(TranslatedElement child, EdgeKind kind) {
2383+
child = this.getQualifier() and
2384+
result = this.getParent().getChildSuccessor(this, kind)
2385+
}
2386+
2387+
override TranslatedElement getChildInternal(int id) {
2388+
id = 0 and
2389+
result = this.getQualifier()
2390+
}
2391+
2392+
override Instruction getResult() { none() }
2393+
2394+
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
2395+
none()
2396+
}
2397+
2398+
override Instruction getALastInstructionInternal() {
2399+
result = this.getQualifier().getALastInstruction()
2400+
}
2401+
}
2402+
23622403
/**
23632404
* The IR translation of the `?:` operator. This class has the portions of the implementation that
23642405
* are shared between the standard three-operand form (`a ? b : c`) and the GCC-extension

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: 863 additions & 683 deletions
Large diffs are not rendered by default.

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

Lines changed: 958 additions & 779 deletions
Large diffs are not rendered by default.

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,6 +2189,26 @@ void static_variable_with_destructor_3() {
21892189

21902190
static ClassWithDestructor global_class_with_destructor;
21912191

2192+
namespace vacuous_destructor_call {
2193+
template<typename T>
2194+
T& get(T& t) { return t; }
2195+
2196+
template<typename T>
2197+
void call_destructor(T& t) {
2198+
get(t).~T();
2199+
}
2200+
2201+
void non_vacuous_destructor_call() {
2202+
ClassWithDestructor c;
2203+
call_destructor(c);
2204+
}
2205+
2206+
void vacuous_destructor_call() {
2207+
int i;
2208+
call_destructor(i);
2209+
}
2210+
}
2211+
21922212
void TryCatchDestructors(bool b) {
21932213
try {
21942214
String s;
@@ -2296,4 +2316,19 @@ void VoidReturnDestructors() {
22962316
return VoidFunc();
22972317
}
22982318

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+
22992334
// semmle-extractor-options: -std=c++20 --clang

0 commit comments

Comments
 (0)