Merge pull request #3589 from rdmarsh2/ir-placement-new-consistency

C++: fix IR control flow for cast in placement new
This commit is contained in:
Mathias Vorreiter Pedersen
2020-05-30 13:27:34 +02:00
committed by GitHub
7 changed files with 62 additions and 10 deletions

View File

@@ -1698,7 +1698,8 @@ class TranslatedAllocatorCall extends TTranslatedAllocatorCall, TranslatedDirect
else
if index = 1 and expr.hasAlignedAllocation()
then result = getTranslatedExpr(expr.getAlignmentArgument())
else result = getTranslatedExpr(expr.getAllocatorCall().getArgument(index))
else
result = getTranslatedExpr(expr.getAllocatorCall().getArgument(index).getFullyConverted())
}
}

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

@@ -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

@@ -7369,6 +7369,30 @@ 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?
# 1322| r1322_5(void *) = Convert : r1322_4
# 1322| r1322_6(void *) = Call : func:r1322_1, 0:r1322_2, 1:r1322_5
# 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

@@ -39,7 +39,6 @@ instructionWithoutSuccessor
| condition_decls.cpp:26:23:26:24 | Chi: call to BoxedInt |
| condition_decls.cpp:41:22:41:23 | Chi: call to BoxedInt |
| condition_decls.cpp:48:52:48:53 | Chi: call to BoxedInt |
| cpp17.cpp:15:11:15:21 | Convert: (void *)... |
| misc.c:171:10:171:13 | Uninitialized: definition of str2 |
| misc.c:219:47:219:48 | InitializeIndirection: sp |
| ms_try_except.cpp:3:9:3:9 | Uninitialized: definition of x |
@@ -156,8 +155,6 @@ ambiguousSuccessors
| constructorinitializer.cpp:6:6:6:6 | Chi: f | Goto | 14 | pmcallexpr.cpp:7:5:7:5 | VariableAddress: definition of c |
| constructorinitializer.cpp:6:6:6:6 | Chi: f | Goto | 14 | staticmembercallexpr.cpp:7:4:7:4 | VariableAddress: definition of c |
| constructorinitializer.cpp:6:6:6:6 | Chi: f | Goto | 14 | staticmembercallexpr_args.cpp:8:6:8:6 | VariableAddress: definition of i |
| cpp17.cpp:15:19:15:21 | Load: ptr | Goto | 2 | cpp17.cpp:15:5:15:45 | Call: new |
| cpp17.cpp:15:19:15:21 | Load: ptr | Goto | 2 | cpp17.cpp:15:11:15:21 | Convert: (void *)... |
| defconstructornewexpr.cpp:3:6:3:6 | Chi: f | Goto | 14 | array_delete.cpp:6:12:6:24 | Constant: (Foo *)... |
| defconstructornewexpr.cpp:3:6:3:6 | Chi: f | Goto | 14 | assignexpr.cpp:7:4:7:4 | VariableAddress: definition of c |
| defconstructornewexpr.cpp:3:6:3:6 | Chi: f | Goto | 14 | constmemberaccess.cpp:7:5:7:5 | VariableAddress: definition of c |

View File

@@ -52,7 +52,6 @@ instructionWithoutSuccessor
| condition_decls.cpp:41:22:41:23 | IndirectMayWriteSideEffect: call to BoxedInt |
| condition_decls.cpp:48:52:48:53 | IndirectMayWriteSideEffect: call to BoxedInt |
| cpp17.cpp:15:5:15:45 | InitializeDynamicAllocation: new |
| cpp17.cpp:15:11:15:21 | Convert: (void *)... |
| enum.c:6:9:6:9 | Constant: (int)... |
| file://:0:0:0:0 | CompareNE: (bool)... |
| file://:0:0:0:0 | CompareNE: (bool)... |
@@ -208,8 +207,6 @@ ambiguousSuccessors
| constructorinitializer.cpp:6:6:6:6 | InitializeNonLocal: f | Goto | 14 | pmcallexpr.cpp:7:5:7:5 | VariableAddress: definition of c |
| constructorinitializer.cpp:6:6:6:6 | InitializeNonLocal: f | Goto | 14 | staticmembercallexpr.cpp:7:4:7:4 | VariableAddress: definition of c |
| constructorinitializer.cpp:6:6:6:6 | InitializeNonLocal: f | Goto | 14 | staticmembercallexpr_args.cpp:8:6:8:6 | VariableAddress: definition of i |
| cpp17.cpp:15:19:15:21 | Load: ptr | Goto | 2 | cpp17.cpp:15:5:15:45 | Call: new |
| cpp17.cpp:15:19:15:21 | Load: ptr | Goto | 2 | cpp17.cpp:15:11:15:21 | Convert: (void *)... |
| defconstructornewexpr.cpp:3:6:3:6 | InitializeNonLocal: f | Goto | 14 | array_delete.cpp:6:12:6:24 | Constant: (Foo *)... |
| defconstructornewexpr.cpp:3:6:3:6 | InitializeNonLocal: f | Goto | 14 | assignexpr.cpp:7:4:7:4 | VariableAddress: definition of c |
| defconstructornewexpr.cpp:3:6:3:6 | InitializeNonLocal: f | Goto | 14 | constmemberaccess.cpp:7:5:7:5 | VariableAddress: definition of c |

View File

@@ -39,7 +39,6 @@ instructionWithoutSuccessor
| condition_decls.cpp:26:23:26:24 | IndirectMayWriteSideEffect: call to BoxedInt |
| condition_decls.cpp:41:22:41:23 | IndirectMayWriteSideEffect: call to BoxedInt |
| condition_decls.cpp:48:52:48:53 | IndirectMayWriteSideEffect: call to BoxedInt |
| cpp17.cpp:15:11:15:21 | Convert: (void *)... |
| misc.c:171:10:171:13 | Uninitialized: definition of str2 |
| misc.c:219:47:219:48 | InitializeIndirection: sp |
| ms_try_except.cpp:3:9:3:9 | Uninitialized: definition of x |
@@ -156,8 +155,6 @@ ambiguousSuccessors
| constructorinitializer.cpp:6:6:6:6 | InitializeNonLocal: f | Goto | 14 | pmcallexpr.cpp:7:5:7:5 | VariableAddress: definition of c |
| constructorinitializer.cpp:6:6:6:6 | InitializeNonLocal: f | Goto | 14 | staticmembercallexpr.cpp:7:4:7:4 | VariableAddress: definition of c |
| constructorinitializer.cpp:6:6:6:6 | InitializeNonLocal: f | Goto | 14 | staticmembercallexpr_args.cpp:8:6:8:6 | VariableAddress: definition of i |
| cpp17.cpp:15:19:15:21 | Load: ptr | Goto | 2 | cpp17.cpp:15:5:15:45 | Call: new |
| cpp17.cpp:15:19:15:21 | Load: ptr | Goto | 2 | cpp17.cpp:15:11:15:21 | Convert: (void *)... |
| defconstructornewexpr.cpp:3:6:3:6 | InitializeNonLocal: f | Goto | 14 | array_delete.cpp:6:12:6:24 | Constant: (Foo *)... |
| defconstructornewexpr.cpp:3:6:3:6 | InitializeNonLocal: f | Goto | 14 | assignexpr.cpp:7:4:7:4 | VariableAddress: definition of c |
| defconstructornewexpr.cpp:3:6:3:6 | InitializeNonLocal: f | Goto | 14 | constmemberaccess.cpp:7:5:7:5 | VariableAddress: definition of c |