C++: add test for placement new with cast

This commit is contained in:
Robert Marsh
2020-05-28 16:36:01 -07:00
parent 732da9cc4c
commit 56d0762380
8 changed files with 81 additions and 0 deletions

View File

@@ -10483,6 +10483,35 @@ ir.cpp:
# 1315| 2: [VariableAccess] y
# 1315| Type = [IntType] int
# 1315| ValueCategory = prvalue(load)
# 1318| [Operator,TopLevelFunction] void* operator new(size_t, void*)
# 1318| params:
# 1318| 0: [Parameter] p#0
# 1318| Type = [CTypedefType,Size_t] size_t
# 1318| 1: [Parameter] p#1
# 1318| Type = [VoidPointerType] void *
# 1320| [TopLevelFunction] void f(int*)
# 1320| params:
# 1320| 0: [Parameter] p
# 1320| Type = [IntPointerType] int *
# 1321| body: [Block] { ... }
# 1322| 0: [ExprStmt] ExprStmt
# 1322| 0: [NewExpr] new
# 1322| Type = [IntPointerType] int *
# 1322| ValueCategory = prvalue
# 1322| 0: [FunctionCall] call to operator new
# 1322| Type = [VoidPointerType] void *
# 1322| ValueCategory = prvalue
# 1322| 0: [ErrorExpr] <error expr>
# 1322| Type = [LongType] unsigned long
# 1322| ValueCategory = prvalue
# 1322| 1: [CStyleCast] (void *)...
# 1322| Conversion = [PointerConversion] pointer conversion
# 1322| Type = [VoidPointerType] void *
# 1322| ValueCategory = prvalue
# 1322| expr: [VariableAccess] p
# 1322| Type = [IntPointerType] int *
# 1322| ValueCategory = prvalue(load)
# 1323| 1: [ReturnStmt] return ...
perf-regression.cpp:
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
# 4| params:

View File

@@ -10,7 +10,10 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.cpp:1322:8:1322:8 | Convert: (void *)... |
ambiguousSuccessors
| ir.cpp:1322:8:1322:8 | Load: p | Goto | 2 | ir.cpp:1322:3:1322:13 | Call: new |
| ir.cpp:1322:8:1322:8 | Load: p | Goto | 2 | ir.cpp:1322:8:1322:8 | Convert: (void *)... |
unexplainedLoop
unnecessaryPhiInstruction
memoryOperandDefinitionIsUnmodeled

View File

@@ -10,7 +10,10 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.cpp:1322:8:1322:8 | Convert: (void *)... |
ambiguousSuccessors
| ir.cpp:1322:8:1322:8 | Load: p | Goto | 2 | ir.cpp:1322:3:1322:13 | Call: new |
| ir.cpp:1322:8:1322:8 | Load: p | Goto | 2 | ir.cpp:1322:8:1322:8 | Convert: (void *)... |
unexplainedLoop
unnecessaryPhiInstruction
memoryOperandDefinitionIsUnmodeled

View File

@@ -1315,4 +1315,11 @@ int shortCircuitConditional(int x, int y) {
return predicateA() && predicateB() ? x : y;
}
void *operator new(size_t, void *) noexcept;
void f(int* p)
{
new (p) int;
}
// semmle-extractor-options: -std=c++17 --clang

View File

@@ -10,7 +10,10 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.cpp:1322:8:1322:8 | Convert: (void *)... |
ambiguousSuccessors
| ir.cpp:1322:8:1322:8 | Load: p | Goto | 2 | ir.cpp:1322:3:1322:13 | Call: new |
| ir.cpp:1322:8:1322:8 | Load: p | Goto | 2 | ir.cpp:1322:8:1322:8 | Convert: (void *)... |
unexplainedLoop
unnecessaryPhiInstruction
memoryOperandDefinitionIsUnmodeled

View File

@@ -7369,6 +7369,36 @@ ir.cpp:
# 1314| v1314_10(void) = AliasedUse : ~m?
# 1314| v1314_11(void) = ExitFunction :
# 1320| void f(int*)
# 1320| Block 0
# 1320| v1320_1(void) = EnterFunction :
# 1320| mu1320_2(unknown) = AliasedDefinition :
# 1320| mu1320_3(unknown) = InitializeNonLocal :
# 1320| r1320_4(glval<int *>) = VariableAddress[p] :
# 1320| mu1320_5(int *) = InitializeParameter[p] : &:r1320_4
# 1320| r1320_6(int *) = Load : &:r1320_4, ~m?
# 1320| mu1320_7(unknown) = InitializeIndirection[p] : &:r1320_6
# 1322| r1322_1(glval<unknown>) = FunctionAddress[operator new] :
# 1322| r1322_2(unsigned long) = Constant[4] :
# 1322| r1322_3(glval<int *>) = VariableAddress[p] :
# 1322| r1322_4(int *) = Load : &:r1322_3, ~m?
#-----| Goto -> Block 1
#-----| Goto -> Block 2
# 1322| Block 1
# 1322| r1322_5(void *) = Convert : r1322_4
# 1322| Block 2
# 1322| r1322_6(void *) = Call : func:r1322_1, 0:r1322_2, 1:r1322_4
# 1322| mu1322_7(unknown) = ^CallSideEffect : ~m?
# 1322| mu1322_8(unknown) = ^InitializeDynamicAllocation : &:r1322_6
# 1322| r1322_9(int *) = Convert : r1322_6
# 1323| v1323_1(void) = NoOp :
# 1320| v1320_8(void) = ReturnIndirection[p] : &:r1320_6, ~m?
# 1320| v1320_9(void) = ReturnVoid :
# 1320| v1320_10(void) = AliasedUse : ~m?
# 1320| v1320_11(void) = ExitFunction :
perf-regression.cpp:
# 6| void Big::Big()
# 6| Block 0

View File

@@ -10,7 +10,10 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.cpp:1322:8:1322:8 | Convert: (void *)... |
ambiguousSuccessors
| ir.cpp:1322:8:1322:8 | Load: p | Goto | 2 | ir.cpp:1322:3:1322:13 | Call: new |
| ir.cpp:1322:8:1322:8 | Load: p | Goto | 2 | ir.cpp:1322:8:1322:8 | Convert: (void *)... |
unexplainedLoop
unnecessaryPhiInstruction
memoryOperandDefinitionIsUnmodeled

View File

@@ -10,7 +10,10 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.cpp:1322:8:1322:8 | Convert: (void *)... |
ambiguousSuccessors
| ir.cpp:1322:8:1322:8 | Load: p | Goto | 2 | ir.cpp:1322:3:1322:13 | Call: new |
| ir.cpp:1322:8:1322:8 | Load: p | Goto | 2 | ir.cpp:1322:8:1322:8 | Convert: (void *)... |
unexplainedLoop
unnecessaryPhiInstruction
memoryOperandDefinitionIsUnmodeled