[PATCH] D148274: [clang] Fix overly aggressive lifetime checks for parenthesized aggregate initialization

Alan Zhao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 14 16:43:06 PDT 2023


ayzhao added inline comments.


================
Comment at: clang/include/clang/Sema/Initialization.h:509
   bool isImplicitMemberInitializer() const {
-    return getKind() == EK_Member && Variable.IsImplicitFieldInit;
+    return (getKind() == EK_Member || getKind() == EK_ParenAggInitMember) &&
+           Variable.IsImplicitFieldInit;
----------------
shafik wrote:
> Does this really apply? It looks like this function is only used in `canPerformArrayCopy`
Reverted.

Also reverted `isDefaultMemberInitializer` since this is never true for `EK_ParenAggInitMember`


================
Comment at: clang/lib/Sema/SemaInit.cpp:583
+              EK == InitializedEntity::EK_Member ||
+              EK == InitializedEntity::EK_ParenAggInitMember)
             SemaRef.Diag(Entity.getDecl()->getLocation(),
----------------
shafik wrote:
> I don't see a test triggering this diagnostic for parens init.
Removed since this is part of `InitListChecker` and `InitializedEntity::EK_ParenAggInitMember` does not get created when an `InitListExpr` is created.


================
Comment at: clang/lib/Sema/SemaInit.cpp:597
+          EK == InitializedEntity::EK_Member ||
+          EK == InitializedEntity::EK_ParenAggInitMember)
         SemaRef.Diag(Entity.getDecl()->getLocation(),
----------------
shafik wrote:
> I don't see a test triggering this diagnostic for parens init.
Removed.


================
Comment at: clang/lib/Sema/SemaInit.cpp:5332
+        if (Arg)
+          IS.Diagnose(S, SubEntity, SubKind, Arg);
+        else
----------------
shafik wrote:
> Do we have tests that trigger this diagnostic and the one right below?
Yes:

* For when `Arg` is non-null (failing to initializing members with provided argument): https://github.com/llvm/llvm-project/blob/af78197857115716802189ef073f83cdac9ede15/clang/test/SemaCXX/paren-list-agg-init.cpp#L96-L97
* For when `Arg` is null (failing to value or default-initialize a member): https://github.com/llvm/llvm-project/blob/af78197857115716802189ef073f83cdac9ede15/clang/test/SemaCXX/paren-list-agg-init.cpp#L132-L133 (diagnostics have been fixed in this patch, see [my comment](https://reviews.llvm.org/D148274#4266575) in `SemaCXX/paren-list-agg-init.cpp`).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148274/new/

https://reviews.llvm.org/D148274



More information about the cfe-commits mailing list