[clang] Mark an ObjCIvarDecl as invalid if its type contains errors (PR #68001)

2023-10-02 Thread Akira Hatanaka via cfe-commits

ahatanak wrote:

The commit fixed an assertion that was failing in SemaInit.cpp. 

Assertion failed: (Kind.getKind() == InitializationKind::IK_Copy || 
Kind.isExplicitCast() || Kind.getKind() == InitializationKind::IK_DirectList), 
function Perform, file SemaInit.cpp, line 8607.

The assertion in `InitializationSequence::Perform` was failing because an ivar 
that had an invalid type wasn't marked as invalid (`ivar0[Count]` in the test 
case). `Sema::SetIvarInitializers`, which calls 
`InitializationSequence::Perform` to initialize ivars, should have skipped the 
invalid ivar, but it wasn't because the ivar wasn't marked as invalid.

There's no github issue for this fix.

https://github.com/llvm/llvm-project/pull/68001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Mark an ObjCIvarDecl as invalid if its type contains errors (PR #68001)

2023-10-02 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

The PR description could have used more details. Was this fixing a crash bug, a 
conformance issue, lack of diagnostic etc What is the new behavior would also 
be helpful.

Was there a bug report linked to this fix? Is so that should be linked in the 
description.

If we are fixing a bug we should also include an entry in the Release notes.

https://github.com/llvm/llvm-project/pull/68001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Mark an ObjCIvarDecl as invalid if its type contains errors (PR #68001)

2023-10-02 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak closed 
https://github.com/llvm/llvm-project/pull/68001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Mark an ObjCIvarDecl as invalid if its type contains errors (PR #68001)

2023-10-02 Thread Ravi Kandhadai via cfe-commits

https://github.com/ravikandhadai approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/68001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Mark an ObjCIvarDecl as invalid if its type contains errors (PR #68001)

2023-10-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

This fixes an assertion failure in InitializationSequence::Perform.

---
Full diff: https://github.com/llvm/llvm-project/pull/68001.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaDecl.cpp (+3) 
- (modified) clang/test/SemaObjCXX/ivar-struct.mm (+15-2) 


``diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9c2f1e83ed3fbe9..de6023105253f03 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18622,6 +18622,9 @@ Decl *Sema::ActOnIvar(Scope *S, SourceLocation 
DeclStart, Declarator &D,
   ObjCIvarDecl *NewID = ObjCIvarDecl::Create(
   Context, EnclosingContext, DeclStart, Loc, II, T, TInfo, ac, BitWidth);
 
+  if (T->containsErrors())
+NewID->setInvalidDecl();
+
   if (II) {
 NamedDecl *PrevDecl = LookupSingleName(S, II, Loc, LookupMemberName,
ForVisibleRedeclaration);
diff --git a/clang/test/SemaObjCXX/ivar-struct.mm 
b/clang/test/SemaObjCXX/ivar-struct.mm
index c8c9ca9cbbf04f9..4a039a98abea6c1 100644
--- a/clang/test/SemaObjCXX/ivar-struct.mm
+++ b/clang/test/SemaObjCXX/ivar-struct.mm
@@ -1,8 +1,21 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s
 @interface A {
   struct X {
 int x, y;
   } X;
 }
 @end
+
+static const uint32_t Count = 16; // expected-error {{unknown type name 
'uint32_t'}}
+
+struct S0 {
+  S0();
+};
+
+@interface C0
+@end
+
+@implementation C0 {
+  S0 ivar0[Count];
+}
+@end

``




https://github.com/llvm/llvm-project/pull/68001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Mark an ObjCIvarDecl as invalid if its type contains errors (PR #68001)

2023-10-02 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak created 
https://github.com/llvm/llvm-project/pull/68001

This fixes an assertion failure in InitializationSequence::Perform.

>From 82f68bfe98ab0bebf6d1c33a09645aaa55326c2b Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Mon, 2 Oct 2023 09:03:00 -0700
Subject: [PATCH] Mark an ObjCIvarDecl as invalid if its type contains errors

This fixes an assertion failure in InitializationSequence::Perform.
---
 clang/lib/Sema/SemaDecl.cpp  |  3 +++
 clang/test/SemaObjCXX/ivar-struct.mm | 17 +++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9c2f1e83ed3fbe9..de6023105253f03 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18622,6 +18622,9 @@ Decl *Sema::ActOnIvar(Scope *S, SourceLocation 
DeclStart, Declarator &D,
   ObjCIvarDecl *NewID = ObjCIvarDecl::Create(
   Context, EnclosingContext, DeclStart, Loc, II, T, TInfo, ac, BitWidth);
 
+  if (T->containsErrors())
+NewID->setInvalidDecl();
+
   if (II) {
 NamedDecl *PrevDecl = LookupSingleName(S, II, Loc, LookupMemberName,
ForVisibleRedeclaration);
diff --git a/clang/test/SemaObjCXX/ivar-struct.mm 
b/clang/test/SemaObjCXX/ivar-struct.mm
index c8c9ca9cbbf04f9..4a039a98abea6c1 100644
--- a/clang/test/SemaObjCXX/ivar-struct.mm
+++ b/clang/test/SemaObjCXX/ivar-struct.mm
@@ -1,8 +1,21 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s
 @interface A {
   struct X {
 int x, y;
   } X;
 }
 @end
+
+static const uint32_t Count = 16; // expected-error {{unknown type name 
'uint32_t'}}
+
+struct S0 {
+  S0();
+};
+
+@interface C0
+@end
+
+@implementation C0 {
+  S0 ivar0[Count];
+}
+@end

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits