Commit c309dc6
authored
[Clang][Sema] placement new initializes typedef array with correct size (#83124)
When in-place new-ing a local variable of an array of trivial type, the
generated code calls 'memset' with the correct size of the array,
earlier it was generating size (squared of the typedef array + size).
The cause: `typedef TYPE TArray[8]; TArray x;` The type of declarator is
Tarray[8] and in `SemaExprCXX.cpp::BuildCXXNew` we check if it's of
typedef and of constant size then we get the original type and it works
fine for non-dependent cases.
But in case of template we do `TreeTransform.h:TransformCXXNEWExpr` and
there we again check the allocated type which is TArray[8] and it stays
that way, so ArraySize=(Tarray[8] type, alloc Tarray[8*type]) so the
squared size allocation.
ArraySize gets calculated earlier in `TreeTransform.h` so that
`if(!ArraySize)` condition was failing.
fix: I changed that condition to `if(ArraySize)`.
Fixes #414411 parent d4602a9 commit c309dc6
File tree
3 files changed
+35
-1
lines changed- clang
- docs
- lib/Sema
- test/SemaCXX
3 files changed
+35
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
539 | 539 | | |
540 | 540 | | |
541 | 541 | | |
| 542 | + | |
| 543 | + | |
542 | 544 | | |
543 | 545 | | |
544 | 546 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12802 | 12802 | | |
12803 | 12803 | | |
12804 | 12804 | | |
| 12805 | + | |
| 12806 | + | |
| 12807 | + | |
| 12808 | + | |
| 12809 | + | |
| 12810 | + | |
| 12811 | + | |
| 12812 | + | |
| 12813 | + | |
| 12814 | + | |
| 12815 | + | |
| 12816 | + | |
| 12817 | + | |
12805 | 12818 | | |
12806 | 12819 | | |
12807 | 12820 | | |
| |||
12863 | 12876 | | |
12864 | 12877 | | |
12865 | 12878 | | |
12866 | | - | |
12867 | 12879 | | |
12868 | 12880 | | |
12869 | 12881 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments