Revision tags: llvmorg-21-init, llvmorg-19.1.7, llvmorg-19.1.6, llvmorg-19.1.5 |
|
#
26baa009 |
| 29-Nov-2024 |
Haojian Wu <hokein.wu@gmail.com> |
[clang] Diagnose dangling references for parenthesized aggregate initialization. (#117690)
Unlike brace initialization, the parenthesized aggregate initialization
in C++20 does not extend the lifet
[clang] Diagnose dangling references for parenthesized aggregate initialization. (#117690)
Unlike brace initialization, the parenthesized aggregate initialization
in C++20 does not extend the lifetime of a temporary object bound to a
reference in an aggreate. This can lead to dangling references:
```
struct A { const int& r; };
A a1(1); // well-formed, but results in a dangling reference.
```
With this patch, clang will diagnose this common dangling issues.
Fixes #101957
show more ...
|
Revision tags: llvmorg-19.1.4, llvmorg-19.1.3, llvmorg-19.1.2, llvmorg-19.1.1, llvmorg-19.1.0, llvmorg-19.1.0-rc4, llvmorg-19.1.0-rc3, llvmorg-19.1.0-rc2, llvmorg-19.1.0-rc1, llvmorg-20-init |
|
#
554febd3 |
| 17-Jul-2024 |
Mital Ashok <mital@mitalashok.co.uk> |
[Clang] Fix some assertions not looking through type sugar (#92299)
Fixes #92284
Co-authored-by: cor3ntin <corentinjabot@gmail.com>
|
#
b9ad0b68 |
| 20-Jun-2024 |
Mariya Podchishchaeva <mariya.podchishchaeva@intel.com> |
[clang] Fix `static_cast` to array of unknown bound (#96041)
Per P1975R0 an expression like static_cast<U[]>(...) defines the type of
the expression as U[1].
Fixes https://github.com/llvm/llvm-p
[clang] Fix `static_cast` to array of unknown bound (#96041)
Per P1975R0 an expression like static_cast<U[]>(...) defines the type of
the expression as U[1].
Fixes https://github.com/llvm/llvm-project/issues/62863
show more ...
|
Revision tags: llvmorg-18.1.8, llvmorg-18.1.7, llvmorg-18.1.6, llvmorg-18.1.5, llvmorg-18.1.4, llvmorg-18.1.3, llvmorg-18.1.2, llvmorg-18.1.1, llvmorg-18.1.0, llvmorg-18.1.0-rc4, llvmorg-18.1.0-rc3, llvmorg-18.1.0-rc2, llvmorg-18.1.0-rc1, llvmorg-19-init |
|
#
02a33b72 |
| 05-Jan-2024 |
Mark de Wever <koraq@xs4all.nl> |
"Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (#76833)
…te initialization" (#76272)""
With updates the libc++ tests.
This reverts commit 2205d23 and relands
86dc6e1 a
"Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (#76833)
…te initialization" (#76272)""
With updates the libc++ tests.
This reverts commit 2205d23 and relands
86dc6e1 and
7ab16fb.
Original commit was reverted because of failing libc++ tests, see #76232
for the discussion.
The errors in the tests are spurious in the first place (coming from
initialization of invalid classes), so update the tests to match new
behavior that does not show those errors.
The original patch was written by @ilya-biryukov
To fix the CI two libc++ tests are temporary disabled for clang-18.
show more ...
|
#
cba217a9 |
| 03-Jan-2024 |
Mark de Wever <koraq@xs4all.nl> |
Revert "Reapply "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (#76272)"
This reverts commit 02347fc7191ff4d073f439dde6523add3f5496de.
These changes break the libc++
Revert "Reapply "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (#76272)"
This reverts commit 02347fc7191ff4d073f439dde6523add3f5496de.
These changes break the libc++ CI again. I'll look at a better solution later.
show more ...
|
#
02347fc7 |
| 02-Jan-2024 |
Ilya Biryukov <ibiryukov@google.com> |
Reapply "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (#76272)
With updates the libc++ tests.
This reverts commit 2205d2334f3c859ad9f6c65ed950bfb3bb6f7cbe and relan
Reapply "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (#76272)
With updates the libc++ tests.
This reverts commit 2205d2334f3c859ad9f6c65ed950bfb3bb6f7cbe and relands 86dc6e15f22610bbb53eb4efda0a178ecefc933a and 7ab16fb5207fe187ab999f882069bd632d2e68e5.
Original commit was reverted because of failing libc++ tests, see #76232 for the discussion.
The errors in the tests are spurious in the first place (coming from initialization of invalid classes), so update the tests to match new behavior that does not show those errors.
show more ...
|
#
2205d233 |
| 22-Dec-2023 |
Vitaly Buka <vitalybuka@google.com> |
Revert "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (#76272)
Reverts llvm/llvm-project#76232 and
7ab16fb5207fe187ab999f882069bd632d2e68e5 to recover build bots.
Revert "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (#76272)
Reverts llvm/llvm-project#76232 and
7ab16fb5207fe187ab999f882069bd632d2e68e5 to recover build bots.
Breaks libc++ tests, details in #76232
#76228
show more ...
|
#
7ab16fb5 |
| 22-Dec-2023 |
Ilya Biryukov <ibiryukov@google.com> |
[Sema] Update test for previous change
The warning for C++20 extension does not fire in on specific instance because conversion now fails as class is invalid because of an invalid member.
The new b
[Sema] Update test for previous change
The warning for C++20 extension does not fire in on specific instance because conversion now fails as class is invalid because of an invalid member.
The new behavior is expected, so updating the test accordingly
show more ...
|
Revision tags: llvmorg-17.0.6, llvmorg-17.0.5, llvmorg-17.0.4 |
|
#
84a3aadf |
| 20-Oct-2023 |
Aaron Ballman <aaron@aaronballman.com> |
Diagnose use of VLAs in C++ by default
Reapplication of 7339c0f782d5c70e0928f8991b0c05338a90c84c with a fix for a crash involving arrays without a size expression.
Clang supports VLAs in C++ as an
Diagnose use of VLAs in C++ by default
Reapplication of 7339c0f782d5c70e0928f8991b0c05338a90c84c with a fix for a crash involving arrays without a size expression.
Clang supports VLAs in C++ as an extension, but we currently only warn on their use when you pass -Wvla, -Wvla-extension, or -pedantic. However, VLAs as they're expressed in C have been considered by WG21 and rejected, are easy to use accidentally to the surprise of users (e.g., https://ddanilov.me/default-non-standard-features/), and they have potential security implications beyond constant-size arrays (https://wiki.sei.cmu.edu/confluence/display/c/ARR32-C.+Ensure+size+arguments+for+variable+length+arrays+are+in+a+valid+range). C++ users should strongly consider using other functionality such as std::vector instead.
This seems like sufficiently compelling evidence to warn users about VLA use by default in C++ modes. This patch enables the -Wvla-extension diagnostic group in C++ language modes by default, and adds the warning group to -Wall in GNU++ language modes. The warning is still opt-in in C language modes, where support for VLAs is somewhat less surprising to users.
RFC: https://discourse.llvm.org/t/rfc-diagnosing-use-of-vlas-in-c/73109 Fixes https://github.com/llvm/llvm-project/issues/62836 Differential Revision: https://reviews.llvm.org/D156565
show more ...
|
#
f5043f46 |
| 20-Oct-2023 |
Aaron Ballman <aaron@aaronballman.com> |
Revert "Diagnose use of VLAs in C++ by default"
This reverts commit 7339c0f782d5c70e0928f8991b0c05338a90c84c.
Breaks bots: https://lab.llvm.org/buildbot/#/builders/139/builds/51875 https://lab.llvm
Revert "Diagnose use of VLAs in C++ by default"
This reverts commit 7339c0f782d5c70e0928f8991b0c05338a90c84c.
Breaks bots: https://lab.llvm.org/buildbot/#/builders/139/builds/51875 https://lab.llvm.org/buildbot/#/builders/164/builds/45262
show more ...
|
#
7339c0f7 |
| 20-Oct-2023 |
Aaron Ballman <aaron@aaronballman.com> |
Diagnose use of VLAs in C++ by default
Clang supports VLAs in C++ as an extension, but we currently only warn on their use when you pass -Wvla, -Wvla-extension, or -pedantic. However, VLAs as they'r
Diagnose use of VLAs in C++ by default
Clang supports VLAs in C++ as an extension, but we currently only warn on their use when you pass -Wvla, -Wvla-extension, or -pedantic. However, VLAs as they're expressed in C have been considered by WG21 and rejected, are easy to use accidentally to the surprise of users (e.g., https://ddanilov.me/default-non-standard-features/), and they have potential security implications beyond constant-size arrays (https://wiki.sei.cmu.edu/confluence/display/c/ARR32-C.+Ensure+size+arguments+for+variable+length+arrays+are+in+a+valid+range). C++ users should strongly consider using other functionality such as std::vector instead.
This seems like sufficiently compelling evidence to warn users about VLA use by default in C++ modes. This patch enables the -Wvla-extension diagnostic group in C++ language modes by default, and adds the warning group to -Wall in GNU++ language modes. The warning is still opt-in in C language modes, where support for VLAs is somewhat less surprising to users.
RFC: https://discourse.llvm.org/t/rfc-diagnosing-use-of-vlas-in-c/73109 Fixes https://github.com/llvm/llvm-project/issues/62836 Differential Revision: https://reviews.llvm.org/D156565
show more ...
|
Revision tags: llvmorg-17.0.3, llvmorg-17.0.2, llvmorg-17.0.1, llvmorg-17.0.0, llvmorg-17.0.0-rc4, llvmorg-17.0.0-rc3, llvmorg-17.0.0-rc2, llvmorg-17.0.0-rc1 |
|
#
311f725d |
| 27-Jul-2023 |
Timm Bäder <tbaeder@redhat.com> |
[clang][Interp] Create only globals when initializing a global variable
For this code:
struct O { int &&j; };
O o1(0);
The generated AST for the initializer of o1 is:
VarDecl 0x62100006ab08 <a
[clang][Interp] Create only globals when initializing a global variable
For this code:
struct O { int &&j; };
O o1(0);
The generated AST for the initializer of o1 is:
VarDecl 0x62100006ab08 <array.cpp:119:3, col:9> col:5 o1 'O':'O' parenlistinit `-ExprWithCleanups 0x62100006b250 <col:7, col:9> 'O':'O' `-CXXParenListInitExpr 0x62100006b210 <col:7, col:9> 'O':'O' `-MaterializeTemporaryExpr 0x62100006b1f0 <col:8> 'int' xvalue `-IntegerLiteral 0x62100006abd0 <col:8> 'int' 0
Before this patch, we create a local temporary variable for the MaterializeTemporaryExpr and destroy it again when destroying the EvalEmitter we create to interpret the initializer. However, since O::j is a reference, this reference now points to a local variable that doesn't exist anymore.
Differential Revision: https://reviews.llvm.org/D156453
show more ...
|
Revision tags: llvmorg-18-init |
|
#
64cfcde3 |
| 18-Jul-2023 |
Corentin Jabot <corentinjabot@gmail.com> |
[Clang] Fix the location of default init expressions
Default member initializations constructed from a parenthesized aggregate initialization should be constructed at the location of the left paren,
[Clang] Fix the location of default init expressions
Default member initializations constructed from a parenthesized aggregate initialization should be constructed at the location of the left paren, to be consistent with brace initialization. Otherwise we get diagmostics and source_location in the wrong places.
Fixes #63903
Reviewed By: aaron.ballman, #clang-language-wg
Differential Revision: https://reviews.llvm.org/D155573
show more ...
|
#
fe0116ab |
| 17-Jul-2023 |
Alan Zhao <ayzhao@google.com> |
[clang] Fix a crash when casting to an array type
In C++20, if Clang fails to perform constructor overload on a RecordType, then Clang will try to perform parentesized aggregate initialization. If t
[clang] Fix a crash when casting to an array type
In C++20, if Clang fails to perform constructor overload on a RecordType, then Clang will try to perform parentesized aggregate initialization. If that fails and the initialization was attempted as part of a cast, then we should get the diagnostics from the failed constructor overload attempt. However, we don't attempt constructor overloading for arrays, so previously, if we try to diagnose an overloaded cast for a parenthesized aggregate initialization of an array, we crash. To fix this, we now exit tryDiagnoseOverloadedCast(...) for failed parentesized list initialization if the destination type is an array.
Fixes #63758
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D155523
show more ...
|
#
1bc7f3fb |
| 05-Jul-2023 |
Corentin Jabot <corentinjabot@gmail.com> |
[Clang] Fix a crash when trying to initialize an invalid aggregate.
We did not return an error when failing to producing a valid expression when performing the initialization of an aggregate initial
[Clang] Fix a crash when trying to initialize an invalid aggregate.
We did not return an error when failing to producing a valid expression when performing the initialization of an aggregate initialized with a parenthesized list of expressions.
This is a regression introduced in Clang 17.
Fixes #63278
Reviewed By: aaron.ballman, #clang-language-wg
Differential Revision: https://reviews.llvm.org/D154486
show more ...
|
Revision tags: llvmorg-16.0.6, llvmorg-16.0.5 |
|
#
1cf5188c |
| 30-May-2023 |
Alan Zhao <ayzhao@google.com> |
[clang] Fix crash when passing a braced-init list to a parentehsized aggregate init expression
The previous code incorrectly assumed that we would never call warnBracedScalarInit(...) with a EK_Pare
[clang] Fix crash when passing a braced-init list to a parentehsized aggregate init expression
The previous code incorrectly assumed that we would never call warnBracedScalarInit(...) with a EK_ParenAggInitMember. This patch fixes the bug by warning when a scalar member is initialized via a braced-init list when performing a parentehsized aggregate initialization. This behavior is consistent with parentehsized list aggregate initialization.
Fixes #63008
Reviewed By: shafik
Differential Revision: https://reviews.llvm.org/D151763
show more ...
|
Revision tags: llvmorg-16.0.4, llvmorg-16.0.3, llvmorg-16.0.2 |
|
#
9b4faa11 |
| 13-Apr-2023 |
Alan Zhao <ayzhao@google.com> |
[clang] Fix overly aggressive lifetime checks for parenthesized aggregate initialization
Before this patch, initialized class members would have the LifetimeKind LK_MemInitializer, which does not al
[clang] Fix overly aggressive lifetime checks for parenthesized aggregate initialization
Before this patch, initialized class members would have the LifetimeKind LK_MemInitializer, which does not allow for binding a temporary to a reference. Binding to a temporary however is allowed in parenthesized aggregate initialization, even if it leads to a dangling reference. To fix this, we create a new EntityKind, EK_ParenAggInitMember, which has LifetimeKind LK_FullExpression.
This patch does *not* attempt to diagnose dangling references as a result of using this feature.
This patch also refactors TryOrBuildParenListInitialization(...) to accomodate creating different InitializedEntity objects.
Fixes #61567
[0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html
Reviewed By: shafik
Differential Revision: https://reviews.llvm.org/D148274
show more ...
|
#
7417e9d7 |
| 26-Apr-2023 |
Alan Zhao <ayzhao@google.com> |
[clang] Fix a crash with parenthesized aggregate initialization and base classes
When calling InitializeBase(...), TryOrBuidlParenListInit(...) needs to pass in the parent entity; otherwise, we erro
[clang] Fix a crash with parenthesized aggregate initialization and base classes
When calling InitializeBase(...), TryOrBuidlParenListInit(...) needs to pass in the parent entity; otherwise, we erroneously try to cast CurContext to a CXXConstructorDecl[0], which can't be done since we're performing aggregate initialization, not constructor initialization.
Field initialization is not affected, but this patch still adds some tests for it.
Fixes 62296
[0]: https://github.com/llvm/llvm-project/blob/33d6bd1c667456f7f4a9d338a7996a30a3af50a3/clang/lib/Sema/SemaAccess.cpp#L1696
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D149301
show more ...
|
Revision tags: llvmorg-16.0.1 |
|
#
7df3c71b |
| 20-Mar-2023 |
Alan Zhao <ayzhao@google.com> |
[clang] Fix 2 bugs with parenthesized aggregate initialization
* Fix an issue where temporaries initialized via parenthesized aggregate initialization don't get destroyed. * Fix an issue where agg
[clang] Fix 2 bugs with parenthesized aggregate initialization
* Fix an issue where temporaries initialized via parenthesized aggregate initialization don't get destroyed. * Fix an issue where aggregate initialization omits calls to class members' move constructors after a TreeTransform. This occurs because the CXXConstructExpr wrapping the call to the move constructor gets unboxed during a TreeTransform of the wrapping FunctionalCastExpr (as with a InitListExpr), but unlike InitListExpr, we dont reperform the InitializationSequence for the list's expressions to regenerate the CXXConstructExpr. This patch fixes this bug by treating CXXParenListInitExpr identically to InitListExpr in this regard.
Fixes #61145
Reviewed By: rsmith
Differential Revision: https://reviews.llvm.org/D146465
show more ...
|
Revision tags: llvmorg-16.0.0, llvmorg-16.0.0-rc4, llvmorg-16.0.0-rc3, llvmorg-16.0.0-rc2, llvmorg-16.0.0-rc1, llvmorg-17-init, llvmorg-15.0.7 |
|
#
95a4c0c8 |
| 04-Jan-2023 |
Alan Zhao <ayzhao@google.com> |
[clang] Reland parenthesized aggregate init patches
This commit relands the patches for implementing P0960R3 and P1975R0, which describe initializing aggregates via a parenthesized list.
The reland
[clang] Reland parenthesized aggregate init patches
This commit relands the patches for implementing P0960R3 and P1975R0, which describe initializing aggregates via a parenthesized list.
The relanded commits are:
* 40c52159d3ee - P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values * c77a91bb7ba7 - Remove overly restrictive aggregate paren init logic * 32d7aae04fdb - Fix a clang crash on invalid code in C++20 mode
This patch also fixes a crash in the original implementation. Previously, if the input tried to call an implicitly deleted copy or move constructor of a union, we would then try to initialize the union by initializing it's first element with a reference to a union. This behavior is incorrect (we should fail to initialize) and if the type of the first element has a constructor with a single template typename parameter, then Clang will explode. This patch fixes that issue by checking that constructor overload resolution did not result in a deleted function before attempting parenthesized aggregate initialization.
Additionally, this patch also includes D140159, which contains some minor fixes made in response to code review comments in the original implementation that were made after that patch was submitted.
Co-authored-by: Sheng <ox59616e@gmail.com>
Fixes #54040, Fixes #59675
Reviewed By: ilya-biryukov
Differential Revision: https://reviews.llvm.org/D141546
show more ...
|
Revision tags: llvmorg-15.0.6, llvmorg-15.0.5, llvmorg-15.0.4, llvmorg-15.0.3, working, llvmorg-15.0.2 |
|
#
40c52159 |
| 03-Oct-2022 |
Alan Zhao <ayzhao@google.com> |
[clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values
This patch implements P0960R3, which allows initialization of aggregates via parentheses.
As an
[clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values
This patch implements P0960R3, which allows initialization of aggregates via parentheses.
As an example:
``` struct S { int i, j; }; S s1(1, 1);
int arr1[2](1, 2); ```
This patch also implements P1975R0, which fixes the wording of P0960R3 for single-argument parenthesized lists so that statements like the following are allowed:
``` S s2(1); S s3 = static_cast<S>(1); S s4 = (S)1;
int (&&arr2)[] = static_cast<int[]>(1); int (&&arr3)[2] = static_cast<int[2]>(1); ```
This patch was originally authored by @0x59616e and completed by @ayzhao.
Fixes #54040, Fixes #54041
Co-authored-by: Sheng <ox59616e@gmail.com>
Full write up : https://discourse.llvm.org/t/c-20-rfc-suggestion-desired-regarding-the-implementation-of-p0960r3/63744
Reviewed By: ilya-biryukov
Differential Revision: https://reviews.llvm.org/D129531
show more ...
|