[clang] [libc] [llvm] [compiler-rt] [clang-tools-extra] [libcxx] [flang] [C23] Complete support for WG14 N2508 (PR #71398)

2023-11-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -299,6 +299,12 @@ def note_missing_selector_name : Note<
 def note_force_empty_selector_name : Note<
   "or insert whitespace before ':' to use %0 as parameter name "
   "and have an empty entry in the selector">;
+def ext_c_label_followed_by_declaration : ExtWarn<
+  "label followed by a declaration is a C23 extension">,
+  InGroup;
+def warn_c23_compat_label_followed_by_declaration : Warning<
+  "label followed by a declaration is incompatible with C standards before "
+  "C23">, InGroup, DefaultIgnore;

Fznamznon wrote:

I can't find tests that would check that these messages are emitted. Are they 
coming?

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


[llvm] [clang] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-06 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/70829

>From ac30780250875802d13450d17e6959f9e2ad3a70 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 31 Oct 2023 09:27:51 -0700
Subject: [PATCH 1/2] [clang] Fix false positive -Wmissing-field-initializer
 for anonymous unions

Normally warning is not reported when a field has default initializer.
Do so for anonymous unions with default initializers as well.
No release note since it is a regression in clang 18.

Fixes https://github.com/llvm/llvm-project/issues/70384
---
 clang/lib/Sema/SemaInit.cpp   | 99 +++
 .../SemaCXX/cxx2a-initializer-aggregates.cpp  | 66 -
 2 files changed, 122 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ec796def96ad3d8..881e67587e430e7 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -349,17 +349,13 @@ class InitListChecker {
   bool SubobjectIsDesignatorContext, unsigned &Index,
   InitListExpr *StructuredList,
   unsigned &StructuredIndex);
-  bool CheckDesignatedInitializer(const InitializedEntity &Entity,
-  InitListExpr *IList, DesignatedInitExpr *DIE,
-  unsigned DesigIdx,
-  QualType &CurrentObjectType,
-  RecordDecl::field_iterator *NextField,
-  llvm::APSInt *NextElementIndex,
-  unsigned &Index,
-  InitListExpr *StructuredList,
-  unsigned &StructuredIndex,
-  bool FinishSubobjectInit,
-  bool TopLevelObject);
+  bool CheckDesignatedInitializer(
+  const InitializedEntity &Entity, InitListExpr *IList,
+  DesignatedInitExpr *DIE, unsigned DesigIdx, QualType &CurrentObjectType,
+  RecordDecl::field_iterator *NextField, llvm::APSInt *NextElementIndex,
+  unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex,
+  bool FinishSubobjectInit, bool TopLevelObject,
+  llvm::SmallPtrSetImpl *InitializedFields = nullptr);
   InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
QualType CurrentObjectType,
InitListExpr *StructuredList,
@@ -2248,7 +2244,8 @@ void InitListChecker::CheckStructUnionTypes(
   // the next field that we'll be initializing.
   bool DesignatedInitFailed = CheckDesignatedInitializer(
   Entity, IList, DIE, 0, DeclType, &Field, nullptr, Index,
-  StructuredList, StructuredIndex, true, TopLevelObject);
+  StructuredList, StructuredIndex, true, TopLevelObject,
+  &InitializedFields);
   if (DesignatedInitFailed)
 hadError = true;
 
@@ -2256,7 +2253,6 @@ void InitListChecker::CheckStructUnionTypes(
   DesignatedInitExpr::Designator *D = DIE->getDesignator(0);
   if (!VerifyOnly && D->isFieldDesignator()) {
 FieldDecl *F = D->getFieldDecl();
-InitializedFields.insert(F);
 if (!DesignatedInitFailed) {
   QualType ET = SemaRef.Context.getBaseElementType(F->getType());
   if (checkDestructorReference(ET, InitLoc, SemaRef)) {
@@ -2365,21 +2361,43 @@ void InitListChecker::CheckStructUnionTypes(
   !RD->isUnion()) {
 // It is possible we have one or more unnamed bitfields remaining.
 // Find first (if any) named field and emit warning.
-for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
-   : Field,
-end = RD->field_end();
- it != end; ++it) {
-  if (HasDesignatedInit && InitializedFields.count(*it))
-continue;
+auto MissingFieldCheck = [&](const RecordDecl *Record,
+ RecordDecl::field_iterator StartField,
+ auto &&MissingFieldCheck) -> bool {
+  FieldDecl *FirstUninitialized = nullptr;
+  for (RecordDecl::field_iterator it = StartField,
+  end = Record->field_end();
+   it != end; ++it) {
+bool AllSet = false;
+if (it->isAnonymousStructOrUnion()) {
+  RecordDecl *RDAnon = it->getType()->getAsRecordDecl();
+  AllSet = MissingFieldCheck(RDAnon, RDAnon->field_begin(),
+ MissingFieldCheck);
+}
+
+if ((HasDesignatedInit && InitializedFields.count(*it)) ||
+it->hasInClassInitializer() || AllSet) {
+  if (Record->isUnion())
+return true;
+  continue;
+}
 
-  if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&

[clang-tools-extra] [clang] [llvm] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -2537,19 +2555,13 @@ class FieldInitializerValidatorCCC final : public 
CorrectionCandidateCallback {
 /// actually be initialized.

Fznamznon wrote:

I removed addition of `InitializedFields` parameter, so probably it makes sense 
to update the comment comment in a separate patch.

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


[clang-tools-extra] [clang] [llvm] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-06 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> I wonder if it would make sense to move the checking for this warning here, 
> to the else case in line 725

Thanks for the suggestion, I gave it a try.

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


[llvm] [clang-tools-extra] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-07 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/70829

>From ac30780250875802d13450d17e6959f9e2ad3a70 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 31 Oct 2023 09:27:51 -0700
Subject: [PATCH 1/3] [clang] Fix false positive -Wmissing-field-initializer
 for anonymous unions

Normally warning is not reported when a field has default initializer.
Do so for anonymous unions with default initializers as well.
No release note since it is a regression in clang 18.

Fixes https://github.com/llvm/llvm-project/issues/70384
---
 clang/lib/Sema/SemaInit.cpp   | 99 +++
 .../SemaCXX/cxx2a-initializer-aggregates.cpp  | 66 -
 2 files changed, 122 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ec796def96ad3d8..881e67587e430e7 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -349,17 +349,13 @@ class InitListChecker {
   bool SubobjectIsDesignatorContext, unsigned &Index,
   InitListExpr *StructuredList,
   unsigned &StructuredIndex);
-  bool CheckDesignatedInitializer(const InitializedEntity &Entity,
-  InitListExpr *IList, DesignatedInitExpr *DIE,
-  unsigned DesigIdx,
-  QualType &CurrentObjectType,
-  RecordDecl::field_iterator *NextField,
-  llvm::APSInt *NextElementIndex,
-  unsigned &Index,
-  InitListExpr *StructuredList,
-  unsigned &StructuredIndex,
-  bool FinishSubobjectInit,
-  bool TopLevelObject);
+  bool CheckDesignatedInitializer(
+  const InitializedEntity &Entity, InitListExpr *IList,
+  DesignatedInitExpr *DIE, unsigned DesigIdx, QualType &CurrentObjectType,
+  RecordDecl::field_iterator *NextField, llvm::APSInt *NextElementIndex,
+  unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex,
+  bool FinishSubobjectInit, bool TopLevelObject,
+  llvm::SmallPtrSetImpl *InitializedFields = nullptr);
   InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
QualType CurrentObjectType,
InitListExpr *StructuredList,
@@ -2248,7 +2244,8 @@ void InitListChecker::CheckStructUnionTypes(
   // the next field that we'll be initializing.
   bool DesignatedInitFailed = CheckDesignatedInitializer(
   Entity, IList, DIE, 0, DeclType, &Field, nullptr, Index,
-  StructuredList, StructuredIndex, true, TopLevelObject);
+  StructuredList, StructuredIndex, true, TopLevelObject,
+  &InitializedFields);
   if (DesignatedInitFailed)
 hadError = true;
 
@@ -2256,7 +2253,6 @@ void InitListChecker::CheckStructUnionTypes(
   DesignatedInitExpr::Designator *D = DIE->getDesignator(0);
   if (!VerifyOnly && D->isFieldDesignator()) {
 FieldDecl *F = D->getFieldDecl();
-InitializedFields.insert(F);
 if (!DesignatedInitFailed) {
   QualType ET = SemaRef.Context.getBaseElementType(F->getType());
   if (checkDestructorReference(ET, InitLoc, SemaRef)) {
@@ -2365,21 +2361,43 @@ void InitListChecker::CheckStructUnionTypes(
   !RD->isUnion()) {
 // It is possible we have one or more unnamed bitfields remaining.
 // Find first (if any) named field and emit warning.
-for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
-   : Field,
-end = RD->field_end();
- it != end; ++it) {
-  if (HasDesignatedInit && InitializedFields.count(*it))
-continue;
+auto MissingFieldCheck = [&](const RecordDecl *Record,
+ RecordDecl::field_iterator StartField,
+ auto &&MissingFieldCheck) -> bool {
+  FieldDecl *FirstUninitialized = nullptr;
+  for (RecordDecl::field_iterator it = StartField,
+  end = Record->field_end();
+   it != end; ++it) {
+bool AllSet = false;
+if (it->isAnonymousStructOrUnion()) {
+  RecordDecl *RDAnon = it->getType()->getAsRecordDecl();
+  AllSet = MissingFieldCheck(RDAnon, RDAnon->field_begin(),
+ MissingFieldCheck);
+}
+
+if ((HasDesignatedInit && InitializedFields.count(*it)) ||
+it->hasInClassInitializer() || AllSet) {
+  if (Record->isUnion())
+return true;
+  continue;
+}
 
-  if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&

[clang-tools-extra] [llvm] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-07 Thread Mariya Podchishchaeva via cfe-commits


@@ -727,6 +729,44 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 if (hadError || VerifyOnly) {
   // Do nothing
 } else if (Init < NumInits) {

Fznamznon wrote:

Yes, we still warn for this case.

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


[clang-tools-extra] [llvm] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-07 Thread Mariya Podchishchaeva via cfe-commits


@@ -465,7 +460,8 @@ class InitListChecker {
   void FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
const InitializedEntity &ParentEntity,
InitListExpr *ILE, bool &RequiresSecondPass,
-   bool FillWithNoInit = false);
+   bool FillWithNoInit = false,
+   bool MaybeEmitMFIWarning = true);

Fznamznon wrote:

Okay, I changed the name.

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


[clang-tools-extra] [llvm] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-07 Thread Mariya Podchishchaeva via cfe-commits


@@ -802,9 +842,19 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
 }
   }
 } else {
+  InitListExpr *SForm =
+  ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm();
   // The fields beyond ILE->getNumInits() are default initialized, so in
   // order to leave them uninitialized, the ILE is expanded and the extra
   // fields are then filled with NoInitExpr.
+
+  // Some checks that required for MFI warning are bound to how many
+  // elements the initializer list originally was provided, perform them
+  // before the list is expanded
+  bool MaybeEmitMFIWarning =
+  !SForm->isIdiomaticZeroInitializer(SemaRef.getLangOpts()) &&
+  ILE->getNumInits() &&
+  !(hasAnyDesignatedInits(SForm) && !SemaRef.getLangOpts().CPlusPlus);

Fznamznon wrote:

Reversed the order.
It seems clang emulates this GCC behavior for 10+ years and changing that can 
be a disruptive change, I wanted to avoid that.
I added a FIXME highlighting the problem though.

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


[clang-tools-extra] [llvm] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-07 Thread Mariya Podchishchaeva via cfe-commits


@@ -727,6 +729,44 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 if (hadError || VerifyOnly) {
   // Do nothing
 } else if (Init < NumInits) {
+  if (MaybeEmitMFIWarning) {
+auto CheckAnonMember = [&](const FieldDecl *FD,
+   auto &&CheckAnonMember) -> bool {
+  FieldDecl *FirstUninitialized = nullptr;
+  RecordDecl *RD = FD->getType()->getAsRecordDecl();
+  assert(RD && "Not anonymous member checked?");
+  for (auto *F : RD->fields()) {
+bool AllSet = false;
+if (F->isAnonymousStructOrUnion())
+  AllSet = CheckAnonMember(F, CheckAnonMember);
+
+if (AllSet || F->hasInClassInitializer()) {
+  if (RD->isUnion())
+return true;
+  continue;
+}
+
+if (!F->isUnnamedBitfield() &&
+!F->getType()->isIncompleteArrayType() &&
+!F->isAnonymousStructOrUnion() && !FirstUninitialized)
+  FirstUninitialized = F;
+  }
+
+  if (FirstUninitialized) {
+SemaRef.Diag(Loc, diag::warn_missing_field_initializers)
+<< FirstUninitialized;
+return false;

Fznamznon wrote:

Thanks for the catch, fixed and added a test case.

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


[clang-tools-extra] [llvm] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-07 Thread Mariya Podchishchaeva via cfe-commits


@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,reorder 
-Wno-c99-designator -Werror=reorder-init-list -Wno-initializer-overrides
 // RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,override 
-Wno-c99-designator -Wno-reorder-init-list -Werror=initializer-overrides
 // RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected -Wno-c99-designator 
-Wno-reorder-init-list -Wno-initializer-overrides
-// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,wmissing 
-Wmissing-field-initializers -Wno-c99-designator -Wno-reorder-init-list 
-Wno-initializer-overrides
+// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,wmissing 
-Wmissing-field-initializers -Wno-c99-designator -Wno-reorder-init-list 
-Wno-initializer-overrides -D NON_PEDANTIC

Fznamznon wrote:

Ok, done. 

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


[compiler-rt] [libcxx] [libc] [llvm] [clang-tools-extra] [flang] [clang] [C23] Complete support for WG14 N2508 (PR #71398)

2023-11-07 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

LGTM, but someone else must approve.

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


[clang] [Clang][Sema] Fix qualifier restriction of overriden methods (PR #71696)

2023-11-08 Thread Mariya Podchishchaeva via cfe-commits


@@ -289,3 +289,29 @@ namespace PR8168 {
 static void foo() {} // expected-error{{'static' member function 'foo' 
overrides a virtual function}}
   };
 }
+
+namespace T13 {
+  class A {
+  public:
+virtual const int* foo(); // expected-note{{overridden virtual function is 
here}}
+  };
+
+  class B: public A {
+  public:
+virtual int* foo(); // expected-error{{return type of virtual function 
'foo' is not covariant with the return type of the function it overrides ('int 
*' has different qualifiers than 'const int *')}}
+  };
+}
+
+namespace T14 {
+  struct a {};
+
+  class A {
+  public:
+virtual const a* foo(); // expected-note{{overridden virtual function is 
here}}
+  };
+
+  class B: public A {
+  public:
+virtual volatile a* foo(); // expected-error{{return type of virtual 
function 'foo' is not covariant with the return type of the function it 
overrides (class type 'volatile a *' is more qualified than class type 'const a 
*')}}

Fznamznon wrote:

I guess technically volatile is not more qualified than const 
https://eel.is/c++draft/tab:basic.type.qualifier.rel, should we also emit `has 
different qualifiers` phrase here instead?

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


[clang] [Clang][Sema] Fix qualifier restriction of overriden methods (PR #71696)

2023-11-08 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

Perhaps also needs a release note.

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


[clang] [Clang][Sema] Fix qualifier restriction of overriden methods (PR #71696)

2023-11-08 Thread Mariya Podchishchaeva via cfe-commits

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


[compiler-rt] [libcxx] [clang-tools-extra] [llvm] [flang] [clang] [Clang][Sema] Fix qualifier restriction of overriden methods (PR #71696)

2023-11-14 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

LGTM, but someone else must approve. I added more folks for visibility.

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


[clang] [llvm] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-14 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/70829

>From ac30780250875802d13450d17e6959f9e2ad3a70 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 31 Oct 2023 09:27:51 -0700
Subject: [PATCH 1/4] [clang] Fix false positive -Wmissing-field-initializer
 for anonymous unions

Normally warning is not reported when a field has default initializer.
Do so for anonymous unions with default initializers as well.
No release note since it is a regression in clang 18.

Fixes https://github.com/llvm/llvm-project/issues/70384
---
 clang/lib/Sema/SemaInit.cpp   | 99 +++
 .../SemaCXX/cxx2a-initializer-aggregates.cpp  | 66 -
 2 files changed, 122 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ec796def96ad3d8..881e67587e430e7 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -349,17 +349,13 @@ class InitListChecker {
   bool SubobjectIsDesignatorContext, unsigned &Index,
   InitListExpr *StructuredList,
   unsigned &StructuredIndex);
-  bool CheckDesignatedInitializer(const InitializedEntity &Entity,
-  InitListExpr *IList, DesignatedInitExpr *DIE,
-  unsigned DesigIdx,
-  QualType &CurrentObjectType,
-  RecordDecl::field_iterator *NextField,
-  llvm::APSInt *NextElementIndex,
-  unsigned &Index,
-  InitListExpr *StructuredList,
-  unsigned &StructuredIndex,
-  bool FinishSubobjectInit,
-  bool TopLevelObject);
+  bool CheckDesignatedInitializer(
+  const InitializedEntity &Entity, InitListExpr *IList,
+  DesignatedInitExpr *DIE, unsigned DesigIdx, QualType &CurrentObjectType,
+  RecordDecl::field_iterator *NextField, llvm::APSInt *NextElementIndex,
+  unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex,
+  bool FinishSubobjectInit, bool TopLevelObject,
+  llvm::SmallPtrSetImpl *InitializedFields = nullptr);
   InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
QualType CurrentObjectType,
InitListExpr *StructuredList,
@@ -2248,7 +2244,8 @@ void InitListChecker::CheckStructUnionTypes(
   // the next field that we'll be initializing.
   bool DesignatedInitFailed = CheckDesignatedInitializer(
   Entity, IList, DIE, 0, DeclType, &Field, nullptr, Index,
-  StructuredList, StructuredIndex, true, TopLevelObject);
+  StructuredList, StructuredIndex, true, TopLevelObject,
+  &InitializedFields);
   if (DesignatedInitFailed)
 hadError = true;
 
@@ -2256,7 +2253,6 @@ void InitListChecker::CheckStructUnionTypes(
   DesignatedInitExpr::Designator *D = DIE->getDesignator(0);
   if (!VerifyOnly && D->isFieldDesignator()) {
 FieldDecl *F = D->getFieldDecl();
-InitializedFields.insert(F);
 if (!DesignatedInitFailed) {
   QualType ET = SemaRef.Context.getBaseElementType(F->getType());
   if (checkDestructorReference(ET, InitLoc, SemaRef)) {
@@ -2365,21 +2361,43 @@ void InitListChecker::CheckStructUnionTypes(
   !RD->isUnion()) {
 // It is possible we have one or more unnamed bitfields remaining.
 // Find first (if any) named field and emit warning.
-for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
-   : Field,
-end = RD->field_end();
- it != end; ++it) {
-  if (HasDesignatedInit && InitializedFields.count(*it))
-continue;
+auto MissingFieldCheck = [&](const RecordDecl *Record,
+ RecordDecl::field_iterator StartField,
+ auto &&MissingFieldCheck) -> bool {
+  FieldDecl *FirstUninitialized = nullptr;
+  for (RecordDecl::field_iterator it = StartField,
+  end = Record->field_end();
+   it != end; ++it) {
+bool AllSet = false;
+if (it->isAnonymousStructOrUnion()) {
+  RecordDecl *RDAnon = it->getType()->getAsRecordDecl();
+  AllSet = MissingFieldCheck(RDAnon, RDAnon->field_begin(),
+ MissingFieldCheck);
+}
+
+if ((HasDesignatedInit && InitializedFields.count(*it)) ||
+it->hasInClassInitializer() || AllSet) {
+  if (Record->isUnion())
+return true;
+  continue;
+}
 
-  if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&

[clang] [llvm] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-14 Thread Mariya Podchishchaeva via cfe-commits


@@ -727,6 +734,38 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 if (hadError || VerifyOnly) {
   // Do nothing
 } else if (Init < NumInits) {
+  if (WarnIfMissing) {
+auto CheckAnonMember = [&](const FieldDecl *FD,
+   auto &&CheckAnonMember) -> FieldDecl * {
+  FieldDecl *Uninitialized = nullptr;
+  RecordDecl *RD = FD->getType()->getAsRecordDecl();
+  assert(RD && "Not anonymous member checked?");
+  for (auto *F : RD->fields()) {
+if (F->isAnonymousStructOrUnion())
+  Uninitialized = CheckAnonMember(F, CheckAnonMember);
+else if (!F->isUnnamedBitfield() &&
+ !F->getType()->isIncompleteArrayType() && !Uninitialized 
&&
+ !F->hasInClassInitializer())
+  Uninitialized = F;
+
+if (RD->isUnion() && (F->hasInClassInitializer() || 
!Uninitialized))
+  return nullptr;
+  }

Fznamznon wrote:

Ok, done. Thanks for the catch!

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


[clang] [llvm] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-14 Thread Mariya Podchishchaeva via cfe-commits


@@ -654,11 +655,17 @@ void InitListChecker::FillInEmptyInitForBase(
   }
 }
 
-void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
-const InitializedEntity &ParentEntity,
-  InitListExpr *ILE,
-  bool &RequiresSecondPass,
-  bool FillWithNoInit) {
+static bool hasAnyDesignatedInits(const InitListExpr *IL) {
+  for (const Stmt *Init : *IL)
+if (isa_and_nonnull(Init))
+  return true;
+  return false;

Fznamznon wrote:

Ok, done.


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


[clang] [llvm] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-14 Thread Mariya Podchishchaeva via cfe-commits


@@ -727,6 +729,44 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 if (hadError || VerifyOnly) {
   // Do nothing
 } else if (Init < NumInits) {

Fznamznon wrote:

> Maybe consider changing the L674 condition to an assert(Init < NumInits) and 
> simplify this too?

I'm not sure I understand the suggestion. The condition on L674 looks like:
```
if (Init >= NumInits || !ILE->getInit(Init)) {
```
Even if I only remove `Init >= NumInits`, build of check-clang starts asserting 
with
```
Assertion `Init < getNumInits() && "Initializer access out of range!"'
```

Removing `!ILE->getInit(Init)` also doesn't seem logical to me since 
`FillInEmptyInitForField` is called for all fields in a record.

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


[clang] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-05 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/74512


Shadowing warning doesn't make much sense since field is not available in 
lambda's body without capturing this.

Fixes https://github.com/llvm/llvm-project/issues/71976

>From 169d962b64b8ae242c3a6d332677296cf7503839 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 5 Dec 2023 10:28:44 -0800
Subject: [PATCH] [clang] Avoid -Wshadow warning when init-capture named same
 as class field

Shadowing warning doesn't make much sense since field is not available
in lambda's body without capturing this.

Fixes https://github.com/llvm/llvm-project/issues/71976
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   |  8 +---
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 18 ++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 828dd10e3d6db..7ac81e16492d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -655,6 +655,9 @@ Bug Fixes in This Version
   Fixes (`#64467 `_)
 - Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are 
known non-negative constants.
   Fixes (`#18763 `_)
+- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
+  field.
+  Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f12424d33b7da..65d095b2431dd 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8395,10 +8395,11 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
-  if (isa(D) && isa(ShadowedDecl) && NewDC &&
-  isa(NewDC)) {
+  if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+if (!isa(ShadowedDecl))
+  return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
   // Try to avoid warnings for lambdas with an explicit capture list.
   const auto *LSI = cast(getCurFunction());
@@ -8416,7 +8417,8 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 }
   }
 
-  if (cast(ShadowedDecl)->hasLocalStorage()) {
+  if (const auto *VD = dyn_cast(ShadowedDecl);
+  VD && VD->hasLocalStorage()) {
 // A variable can't shadow a local variable in an enclosing scope, if
 // they are separated by a non-capturing declaration context.
 for (DeclContext *ParentDC = NewDC;
diff --git a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp 
b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
index bda6a65c02168..58af7a2e65c55 100644
--- a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -179,3 +179,21 @@ void f() {
 #endif
 }
 }
+
+namespace GH71976 {
+struct A {
+  int b = 5;
+  int foo() {
+return [b = b]() { return b; }();
+  }
+};
+
+struct B {
+  int a;
+  void foo() {
+auto b = [a = this->a] {
+
+};
+  }
+};
+}

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


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

Perhaps needs a release note.

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


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Mariya Podchishchaeva via cfe-commits


@@ -4952,7 +4952,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 std::make_pair(Function, PointOfInstantiation));
 } else if (TSK == TSK_ImplicitInstantiation) {
   if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() &&
-  !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc())) {
+  !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc()) &&
+  !Function->isVirtualAsWritten()) {

Fznamznon wrote:

Should we also check that it is pure? AFAIK `isVirtualAsWritten` returns true 
for function marked explicitly virtual. There is also `FunctionDecl::isPure()` 
to check that it is pure.

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


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Mariya Podchishchaeva via cfe-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+// expected-no-diagnostics
+
+namespace PR74016 {

Fznamznon wrote:

I think we normally call them GH when a bug was filed as a GitHub issue.
```suggestion
namespace GH74016 {
```

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


[clang] [clang] Substitute alias templates from correct context (PR #74335)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

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


[libc] [compiler-rt] [clang-tools-extra] [clang] [llvm] [flang] [libcxx] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/74512

>From 169d962b64b8ae242c3a6d332677296cf7503839 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 5 Dec 2023 10:28:44 -0800
Subject: [PATCH 1/2] [clang] Avoid -Wshadow warning when init-capture named
 same as class field

Shadowing warning doesn't make much sense since field is not available
in lambda's body without capturing this.

Fixes https://github.com/llvm/llvm-project/issues/71976
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   |  8 +---
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 18 ++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 828dd10e3d6db..7ac81e16492d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -655,6 +655,9 @@ Bug Fixes in This Version
   Fixes (`#64467 `_)
 - Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are 
known non-negative constants.
   Fixes (`#18763 `_)
+- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
+  field.
+  Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f12424d33b7da..65d095b2431dd 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8395,10 +8395,11 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
-  if (isa(D) && isa(ShadowedDecl) && NewDC &&
-  isa(NewDC)) {
+  if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+if (!isa(ShadowedDecl))
+  return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
   // Try to avoid warnings for lambdas with an explicit capture list.
   const auto *LSI = cast(getCurFunction());
@@ -8416,7 +8417,8 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 }
   }
 
-  if (cast(ShadowedDecl)->hasLocalStorage()) {
+  if (const auto *VD = dyn_cast(ShadowedDecl);
+  VD && VD->hasLocalStorage()) {
 // A variable can't shadow a local variable in an enclosing scope, if
 // they are separated by a non-capturing declaration context.
 for (DeclContext *ParentDC = NewDC;
diff --git a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp 
b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
index bda6a65c02168..58af7a2e65c55 100644
--- a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -179,3 +179,21 @@ void f() {
 #endif
 }
 }
+
+namespace GH71976 {
+struct A {
+  int b = 5;
+  int foo() {
+return [b = b]() { return b; }();
+  }
+};
+
+struct B {
+  int a;
+  void foo() {
+auto b = [a = this->a] {
+
+};
+  }
+};
+}

>From 3798e1f25a8d812c082ac5815c490eb9c7f67e62 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 6 Dec 2023 02:24:59 -0800
Subject: [PATCH 2/2] Apply comments

---
 clang/docs/ReleaseNotes.rst   | 4 ++--
 clang/lib/Sema/SemaDecl.cpp   | 1 +
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d1f3ed22cf2e..f5e0d4fa39737 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -661,8 +661,8 @@ Bug Fixes in This Version
 - Fixed false positive error emitted when templated alias inside a class
   used private members of the same class.
   Fixes (`#41693 `_)
-- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
-  field.
+- Clang's ``-Wshadow`` no longer warns when an init-capture is named the same 
as
+  a class field.
   Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 65d095b2431dd..f590d1b3ade81 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8398,6 +8398,7 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
   if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+// If it is not VarDecl then it can not shadow.
 if (!isa(ShadowedDecl))
   return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
diff --git a/clang/test/SemaCXX/warn-shadow-in-lam

[clang-tools-extra] [clang] [llvm] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Ping.

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


[flang] [llvm] [libcxx] [libcxxabi] [compiler-rt] [lldb] [libunwind] [mlir] [clang-tools-extra] [lld] [libc] [openmp] [clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/73099

>From 1d70b7726e7d1f11622a6d5c8246b0737e024c8d Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 19 Sep 2023 08:37:18 -0700
Subject: [PATCH 1/8] [C23] Implement N3018: The constexpr specifier for object
 definitions

The implementation mostly reuses C++ code paths where possible,
including narrowing check in order to provide diagnostic messages in
case initializer for constexpr variable is not exactly representable in
target type.

The following won't work due to lack of support for other features:
- Diagnosing of underspecified declarations involving constexpr
- Constexpr attached to compound literals

Also due to lack of support for char8_t some of examples with utf-8
strings don't work properly.
---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  16 +
 clang/include/clang/Basic/TokenKinds.def  |   2 +-
 clang/lib/AST/Decl.cpp|  16 +-
 clang/lib/AST/ExprConstant.cpp|  17 +-
 clang/lib/Parse/ParseDecl.cpp |   2 +
 clang/lib/Sema/SemaDecl.cpp   | 204 +++--
 clang/lib/Sema/SemaOverload.cpp   |  36 ++-
 clang/test/C/C2x/n3018.c  |  86 ++
 clang/test/Parser/c23-constexpr.c |   6 +
 clang/test/Sema/constexpr.c   | 275 ++
 clang/www/c_status.html   |   2 +-
 12 files changed, 627 insertions(+), 36 deletions(-)
 create mode 100644 clang/test/C/C2x/n3018.c
 create mode 100644 clang/test/Parser/c23-constexpr.c
 create mode 100644 clang/test/Sema/constexpr.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b65106b9106d4..cae1707f3e30f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -208,6 +208,7 @@ C23 Feature Support
 
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
+- Clang now supports ``N3018 The constexpr specifier for object definitions``.
 
 - Completed the implementation of
   `N2508 `_. We
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 990692c06d7d3..11f24583dc55a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2932,6 +2932,22 @@ def warn_private_extern : Warning<
 def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
+// C23 constexpr
+def err_c23_thread_local_constexpr : Error<
+  "thread-local storage is not allowed with constexpr">;
+def err_c23_extern_constexpr : Error<
+  "extern specifier is not allowed with constexpr">;
+def err_c23_constexpr_not_variable : Error<
+  "constexpr is only allowed in variable declarations">;
+def err_c23_constexpr_invalid_type : Error<
+  "constexpr variable cannot have type %0">;
+def err_c23_constexpr_init_not_representable : Error<
+  "constexpr initializer evaluates to %0 which is not exactly representable in 
type %1">;
+def err_c23_constexpr_init_type_mismatch : Error<
+  "constexpr initializer for type %0 is of type %1">;
+def err_c23_constexpr_pointer_not_null : Error<
+  "constexpr pointer initializer is not null">;
+
 // C++ Concepts
 def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<
   "concept declarations may only appear in global or namespace scope">;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3ab420821d82b..e9e8f59247662 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -393,7 +393,7 @@ CXX11_KEYWORD(alignas   , KEYC23)
 CXX11_UNARY_EXPR_OR_TYPE_TRAIT(alignof, AlignOf, KEYC23)
 CXX11_KEYWORD(char16_t  , KEYNOMS18)
 CXX11_KEYWORD(char32_t  , KEYNOMS18)
-CXX11_KEYWORD(constexpr , 0)
+CXX11_KEYWORD(constexpr , KEYC23)
 CXX11_KEYWORD(decltype  , 0)
 CXX11_KEYWORD(noexcept  , 0)
 CXX11_KEYWORD(nullptr   , KEYC23)
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3a..678a366ed29ad 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2461,7 +2461,7 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // OpenCL permits const integral variables to be used in constant
   // expressions, like in C++98.
-  if (!Lang.CPlusPlus && !Lang.OpenCL)
+  if (!Lang.CPlusPlus && !Lang.OpenCL && !Lang.C23)
 return false;
 
   // Function parameters are never usable in constant expressions.
@@ -2485,12 +2485,12 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // In C++, const, non-volatile var

[flang] [llvm] [libcxx] [libcxxabi] [compiler-rt] [lldb] [libunwind] [mlir] [clang-tools-extra] [lld] [libc] [openmp] [clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -14270,6 +14318,113 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind GetConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}
+
+static bool CheckC23ConstexprInitConversion(Sema &S, const Expr *Init) {
+  assert(S.getLangOpts().C23);
+  const Expr *InitNoCast = Init->IgnoreParenImpCasts();
+  StandardConversionSequence SCS;
+  SCS.setAsIdentityConversion();
+  auto FromType = InitNoCast->getType();
+  auto ToType = Init->getType();
+  SCS.setToType(0, FromType);
+  SCS.setToType(1, ToType);
+  SCS.Second = GetConversionKind(FromType, ToType);
+
+  APValue Value;
+  QualType PreNarrowingType;
+  // Reuse C++ narrowing check.
+  switch (SCS.getNarrowingKind(S.Context, Init, Value, PreNarrowingType,
+   /*IgnoreFloatToIntegralConversion*/ false)) {
+  // The value doesn't fit.
+  case NK_Constant_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_not_representable)
+<< Value.getAsString(S.Context, PreNarrowingType) << ToType;
+return true;
+
+  // Conversion to a narrower type.
+  case NK_Type_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_type_mismatch)
+<< ToType << FromType;
+return true;
+
+  // Since we only reuse narrowing check for C23 constexpr variables here, 
we're
+  // not really interested in these cases.
+  case NK_Dependent_Narrowing:
+  case NK_Variable_Narrowing:
+  case NK_Not_Narrowing:
+return false;
+  }
+  llvm_unreachable("unhandled case in switch");
+}
+
+static bool CheckC23ConstexprInitStringLiteral(const StringLiteral *SE,
+   Sema &SemaRef,
+   SourceLocation Loc) {
+  assert(SemaRef.getLangOpts().C23);
+  // String literals have the target type attached but underneath may contain
+  // values that don't really fit into the target type. Check that every
+  // character fits.
+  const ConstantArrayType *CAT =
+  SemaRef.Context.getAsConstantArrayType(SE->getType());
+  QualType CharType = CAT->getElementType();
+  uint32_t BitWidth = SemaRef.Context.getTypeSize(CharType);
+  bool isUnsigned = CharType->isUnsignedIntegerType();
+  llvm::APSInt Value(BitWidth, isUnsigned);
+  for (unsigned I = 0, N = SE->getLength(); I != N; ++I) {
+int64_t C = SE->getCodeUnitS(I, SemaRef.Context.getCharWidth());
+Value = C;
+if (Value != C) {
+  SemaRef.Diag(Loc, diag::err_c23_constexpr_init_not_representable)

Fznamznon wrote:

Yeah why not. Looks better this way

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


[flang] [llvm] [libcxx] [libcxxabi] [compiler-rt] [lldb] [libunwind] [mlir] [clang-tools-extra] [lld] [libc] [openmp] [clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -1914,6 +1914,17 @@ class StringLiteral final
 llvm_unreachable("Unsupported character width!");
   }
 
+  // Get code unit but preserve sign info.
+  int64_t getCodeUnitS(size_t I, uint64_t ByteWidth) const {

Fznamznon wrote:

It is a number of bits in byte, but ok

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


[clang-tools-extra] [compiler-rt] [llvm] [libc] [libcxx] [flang] [clang] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -8395,10 +8395,11 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
-  if (isa(D) && isa(ShadowedDecl) && NewDC &&
-  isa(NewDC)) {
+  if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+if (!isa(ShadowedDecl))

Fznamznon wrote:

You mean add a comment saying that it is a case when an init-capture references 
class field?

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


[clang] [clang] Substitute alias templates from correct context (PR #74335)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> Please provide one as soon as you can! In the meantime, we should probably 
> revert @Fznamznon

Ok, I'll prepare revert.

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


[clang] [clang] Substitute alias templates from correct context (PR #74335)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Ok, revert is done.
@metaflow , please provide the reproducer.

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


[openmp] [clang] [flang] [llvm] [libcxxabi] [libcxx] [libc] [clang-tools-extra] [mlir] [compiler-rt] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/74512

>From 169d962b64b8ae242c3a6d332677296cf7503839 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 5 Dec 2023 10:28:44 -0800
Subject: [PATCH 1/3] [clang] Avoid -Wshadow warning when init-capture named
 same as class field

Shadowing warning doesn't make much sense since field is not available
in lambda's body without capturing this.

Fixes https://github.com/llvm/llvm-project/issues/71976
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   |  8 +---
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 18 ++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 828dd10e3d6db..7ac81e16492d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -655,6 +655,9 @@ Bug Fixes in This Version
   Fixes (`#64467 `_)
 - Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are 
known non-negative constants.
   Fixes (`#18763 `_)
+- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
+  field.
+  Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f12424d33b7da..65d095b2431dd 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8395,10 +8395,11 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
-  if (isa(D) && isa(ShadowedDecl) && NewDC &&
-  isa(NewDC)) {
+  if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+if (!isa(ShadowedDecl))
+  return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
   // Try to avoid warnings for lambdas with an explicit capture list.
   const auto *LSI = cast(getCurFunction());
@@ -8416,7 +8417,8 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 }
   }
 
-  if (cast(ShadowedDecl)->hasLocalStorage()) {
+  if (const auto *VD = dyn_cast(ShadowedDecl);
+  VD && VD->hasLocalStorage()) {
 // A variable can't shadow a local variable in an enclosing scope, if
 // they are separated by a non-capturing declaration context.
 for (DeclContext *ParentDC = NewDC;
diff --git a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp 
b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
index bda6a65c02168..58af7a2e65c55 100644
--- a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -179,3 +179,21 @@ void f() {
 #endif
 }
 }
+
+namespace GH71976 {
+struct A {
+  int b = 5;
+  int foo() {
+return [b = b]() { return b; }();
+  }
+};
+
+struct B {
+  int a;
+  void foo() {
+auto b = [a = this->a] {
+
+};
+  }
+};
+}

>From 3798e1f25a8d812c082ac5815c490eb9c7f67e62 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 6 Dec 2023 02:24:59 -0800
Subject: [PATCH 2/3] Apply comments

---
 clang/docs/ReleaseNotes.rst   | 4 ++--
 clang/lib/Sema/SemaDecl.cpp   | 1 +
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d1f3ed22cf2e..f5e0d4fa39737 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -661,8 +661,8 @@ Bug Fixes in This Version
 - Fixed false positive error emitted when templated alias inside a class
   used private members of the same class.
   Fixes (`#41693 `_)
-- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
-  field.
+- Clang's ``-Wshadow`` no longer warns when an init-capture is named the same 
as
+  a class field.
   Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 65d095b2431dd..f590d1b3ade81 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8398,6 +8398,7 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
   if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+// If it is not VarDecl then it can not shadow.
 if (!isa(ShadowedDecl))
   return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
diff --git a/clang/test/SemaCXX/warn-shadow-in-lam

[llvm] [clang-tools-extra] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-12-07 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/70829

>From ac30780250875802d13450d17e6959f9e2ad3a70 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 31 Oct 2023 09:27:51 -0700
Subject: [PATCH 1/6] [clang] Fix false positive -Wmissing-field-initializer
 for anonymous unions

Normally warning is not reported when a field has default initializer.
Do so for anonymous unions with default initializers as well.
No release note since it is a regression in clang 18.

Fixes https://github.com/llvm/llvm-project/issues/70384
---
 clang/lib/Sema/SemaInit.cpp   | 99 +++
 .../SemaCXX/cxx2a-initializer-aggregates.cpp  | 66 -
 2 files changed, 122 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ec796def96ad3..881e67587e430 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -349,17 +349,13 @@ class InitListChecker {
   bool SubobjectIsDesignatorContext, unsigned &Index,
   InitListExpr *StructuredList,
   unsigned &StructuredIndex);
-  bool CheckDesignatedInitializer(const InitializedEntity &Entity,
-  InitListExpr *IList, DesignatedInitExpr *DIE,
-  unsigned DesigIdx,
-  QualType &CurrentObjectType,
-  RecordDecl::field_iterator *NextField,
-  llvm::APSInt *NextElementIndex,
-  unsigned &Index,
-  InitListExpr *StructuredList,
-  unsigned &StructuredIndex,
-  bool FinishSubobjectInit,
-  bool TopLevelObject);
+  bool CheckDesignatedInitializer(
+  const InitializedEntity &Entity, InitListExpr *IList,
+  DesignatedInitExpr *DIE, unsigned DesigIdx, QualType &CurrentObjectType,
+  RecordDecl::field_iterator *NextField, llvm::APSInt *NextElementIndex,
+  unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex,
+  bool FinishSubobjectInit, bool TopLevelObject,
+  llvm::SmallPtrSetImpl *InitializedFields = nullptr);
   InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
QualType CurrentObjectType,
InitListExpr *StructuredList,
@@ -2248,7 +2244,8 @@ void InitListChecker::CheckStructUnionTypes(
   // the next field that we'll be initializing.
   bool DesignatedInitFailed = CheckDesignatedInitializer(
   Entity, IList, DIE, 0, DeclType, &Field, nullptr, Index,
-  StructuredList, StructuredIndex, true, TopLevelObject);
+  StructuredList, StructuredIndex, true, TopLevelObject,
+  &InitializedFields);
   if (DesignatedInitFailed)
 hadError = true;
 
@@ -2256,7 +2253,6 @@ void InitListChecker::CheckStructUnionTypes(
   DesignatedInitExpr::Designator *D = DIE->getDesignator(0);
   if (!VerifyOnly && D->isFieldDesignator()) {
 FieldDecl *F = D->getFieldDecl();
-InitializedFields.insert(F);
 if (!DesignatedInitFailed) {
   QualType ET = SemaRef.Context.getBaseElementType(F->getType());
   if (checkDestructorReference(ET, InitLoc, SemaRef)) {
@@ -2365,21 +2361,43 @@ void InitListChecker::CheckStructUnionTypes(
   !RD->isUnion()) {
 // It is possible we have one or more unnamed bitfields remaining.
 // Find first (if any) named field and emit warning.
-for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
-   : Field,
-end = RD->field_end();
- it != end; ++it) {
-  if (HasDesignatedInit && InitializedFields.count(*it))
-continue;
+auto MissingFieldCheck = [&](const RecordDecl *Record,
+ RecordDecl::field_iterator StartField,
+ auto &&MissingFieldCheck) -> bool {
+  FieldDecl *FirstUninitialized = nullptr;
+  for (RecordDecl::field_iterator it = StartField,
+  end = Record->field_end();
+   it != end; ++it) {
+bool AllSet = false;
+if (it->isAnonymousStructOrUnion()) {
+  RecordDecl *RDAnon = it->getType()->getAsRecordDecl();
+  AllSet = MissingFieldCheck(RDAnon, RDAnon->field_begin(),
+ MissingFieldCheck);
+}
+
+if ((HasDesignatedInit && InitializedFields.count(*it)) ||
+it->hasInClassInitializer() || AllSet) {
+  if (Record->isUnion())
+return true;
+  continue;
+}
 
-  if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&
-   

[clang] [clang] Substitute alias templates from correct context (PR #74335)

2023-12-07 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Thanks, I reproduced the problem with
```

template  class shared_ptr {
T* data;
};

template  class cfftpass {
static shared_ptr make_pass();
};

template using Tcpass = shared_ptr>;

template Tcpass cfftpass::make_pass() { return 
Tcpass{};};
   
```

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


[clang] [clang] Crash when referencing capture in static lambda (PR #74661)

2023-12-07 Thread Mariya Podchishchaeva via cfe-commits


@@ -848,6 +848,10 @@ Miscellaneous Clang Crashes Fixed
   `Issue 41302 `_
 - Fixed a crash when ``-ast-dump=json`` was used for code using class
   template deduction guides.
+- Fixed a crash when a lambda marked as `static` referenced a captured variable

Fznamznon wrote:

```suggestion
- Fixed a crash when a lambda marked as ``static`` referenced a captured 
variable
```

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


[clang] [libcxx] [llvm] [compiler-rt] [mlir] [libcxxabi] [flang] [clang-tools-extra] [libc] [openmp] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/74512

>From 169d962b64b8ae242c3a6d332677296cf7503839 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 5 Dec 2023 10:28:44 -0800
Subject: [PATCH 1/3] [clang] Avoid -Wshadow warning when init-capture named
 same as class field

Shadowing warning doesn't make much sense since field is not available
in lambda's body without capturing this.

Fixes https://github.com/llvm/llvm-project/issues/71976
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   |  8 +---
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 18 ++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 828dd10e3d6db9..7ac81e16492d1f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -655,6 +655,9 @@ Bug Fixes in This Version
   Fixes (`#64467 `_)
 - Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are 
known non-negative constants.
   Fixes (`#18763 `_)
+- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
+  field.
+  Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f12424d33b7da2..65d095b2431ddd 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8395,10 +8395,11 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
-  if (isa(D) && isa(ShadowedDecl) && NewDC &&
-  isa(NewDC)) {
+  if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+if (!isa(ShadowedDecl))
+  return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
   // Try to avoid warnings for lambdas with an explicit capture list.
   const auto *LSI = cast(getCurFunction());
@@ -8416,7 +8417,8 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 }
   }
 
-  if (cast(ShadowedDecl)->hasLocalStorage()) {
+  if (const auto *VD = dyn_cast(ShadowedDecl);
+  VD && VD->hasLocalStorage()) {
 // A variable can't shadow a local variable in an enclosing scope, if
 // they are separated by a non-capturing declaration context.
 for (DeclContext *ParentDC = NewDC;
diff --git a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp 
b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
index bda6a65c02168b..58af7a2e65c559 100644
--- a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -179,3 +179,21 @@ void f() {
 #endif
 }
 }
+
+namespace GH71976 {
+struct A {
+  int b = 5;
+  int foo() {
+return [b = b]() { return b; }();
+  }
+};
+
+struct B {
+  int a;
+  void foo() {
+auto b = [a = this->a] {
+
+};
+  }
+};
+}

>From 3798e1f25a8d812c082ac5815c490eb9c7f67e62 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 6 Dec 2023 02:24:59 -0800
Subject: [PATCH 2/3] Apply comments

---
 clang/docs/ReleaseNotes.rst   | 4 ++--
 clang/lib/Sema/SemaDecl.cpp   | 1 +
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d1f3ed22cf2ea..f5e0d4fa397372 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -661,8 +661,8 @@ Bug Fixes in This Version
 - Fixed false positive error emitted when templated alias inside a class
   used private members of the same class.
   Fixes (`#41693 `_)
-- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
-  field.
+- Clang's ``-Wshadow`` no longer warns when an init-capture is named the same 
as
+  a class field.
   Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 65d095b2431ddd..f590d1b3ade819 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8398,6 +8398,7 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
   if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+// If it is not VarDecl then it can not shadow.
 if (!isa(ShadowedDecl))
   return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
diff --git a/clang/test/SemaCXX/warn-sha

[clang] fix issue 73559. (PR #74926)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

Could you please add a test, somewhere in `clang/test/Parser` (there is also a 
lot of other tests showing how it is done) and a release note to 
`clang/docs/ReleaseNotes.rst`, perhaps at the end of the list under `Bug Fixes 
in This Version` heading.

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


[clang] fix issue 73559. (PR #74926)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] fix issue 73559. (PR #74926)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits


@@ -2702,7 +2702,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
   Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
-if (TryAnnotateCXXScopeToken())
+if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())

Fznamznon wrote:

The caller is named `ParseCXXClassMemberDeclaration` so, I'm not sure it can 
and should be called outside of C++. Perhaps we should assert instead of 
checking that is its C++.

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


[mlir] [clang] [llvm] [libcxxabi] [clang-tools-extra] [libc] [compiler-rt] [openmp] [flang] [libcxx] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> The whole point of the shadowing warning is to avoid confusion about which 
> variable is actually used, which IMO could very well be the case here. 

In the case that is being fixed, a field is not available in lambda's body 
without capturing this, so there is no such confusion and no shadowing, I 
think. 
I have a concern, that probably in case when `this` is actually captured, with 
current implementation there will be no warning as well. Should it be? gcc 
doesn't give a warning in both cases.

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


[clang] [clang] Substitute alias templates from correct context (PR #75069)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/75069

Current context set to where alias was met, not where it is declared caused 
incorrect access check in case alias referenced private members of the parent 
class.
This is a recommit of 6b1aa31 with a slight modification in order to fix 
reported regression.

Fixes https://github.com/llvm/llvm-project/issues/41693

>From d0bfa140bdfa2be213151d4d17263bb60e6b46d3 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Mon, 11 Dec 2023 08:31:15 -0800
Subject: [PATCH] [clang] Substitute alias templates from correct context

Current context set to where alias was met, not where it is declared caused
incorrect access check in case alias referenced private members of the parent
class.
This is a recommit of 6b1aa31 with a slight modification in order to fix
reported regression.

Fixes https://github.com/llvm/llvm-project/issues/41693
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/Sema/Sema.h   |  2 +-
 clang/lib/Sema/SemaCXXScopeSpec.cpp   | 24 +--
 clang/lib/Sema/SemaTemplate.cpp   | 16 -
 .../CXX/temp/temp.decls/temp.alias/p3.cpp |  5 +-
 clang/test/SemaCXX/alias-template.cpp | 65 +++
 6 files changed, 105 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b4b5352a306c1c..1d460ae8375e88 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -677,6 +677,9 @@ Bug Fixes in This Version
   (`#62157 `_) and
   (`#64885 `_) and
   (`#65568 `_)
+- Fixed false positive error emitted when templated alias inside a class
+  used private members of the same class.
+  Fixes (`#41693 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f45e0a7d3d52d4..d8f4b01ee455f1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8738,7 +8738,7 @@ class Sema final {
  SourceLocation IILoc,
  bool DeducedTSTContext = true);
 
-
+  bool RebuildingTypesInCurrentInstantiation = false;
   TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
 SourceLocation Loc,
 DeclarationName Name);
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 44a40215b90dfb..b3b19b7ed7 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -30,6 +30,20 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
 return nullptr;
 
   const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
+  if (isa(Ty)) {
+if (auto *Record = dyn_cast(CurContext)) {
+  if (isa(Record) ||
+  Record->getDescribedClassTemplate()) {
+const Type *ICNT = Record->getTypeForDecl();
+QualType Injected =
+cast(ICNT)->getInjectedSpecializationType();
+
+if (Ty == Injected->getCanonicalTypeInternal().getTypePtr())
+  return Record;
+  }
+}
+  }
+
   if (const RecordType *RecordTy = dyn_cast(Ty)) {
 CXXRecordDecl *Record = cast(RecordTy->getDecl());
 if (!Record->isDependentContext() ||
@@ -37,10 +51,12 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
   return Record;
 
 return nullptr;
-  } else if (isa(Ty))
-return cast(Ty)->getDecl();
-  else
-return nullptr;
+  }
+
+  if (auto *ICNT = dyn_cast(Ty))
+return ICNT->getDecl();
+
+  return nullptr;
 }
 
 /// Compute the DeclContext that is associated with the given type.
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f10abeaba0d451..810a93f37d74e0 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -39,6 +39,7 @@
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/SaveAndRestore.h"
 
 #include 
 #include 
@@ -3990,9 +3991,16 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 if (Inst.isInvalid())
   return QualType();
 
-CanonType = SubstType(Pattern->getUnderlyingType(),
-  TemplateArgLists, AliasTemplate->getLocation(),
-  AliasTemplate->getDeclName());
+if (!RebuildingTypesInCurrentInstantiation) {
+  Sema::ContextRAII SavedContext(*this, Pattern->getDeclContext());
+  CanonType =
+  SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
+AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
+} 

[clang] [clang] Substitute alias templates from correct context (PR #75069)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> Can you point out the diff from the previous patch?

To fix the following case:
```
// Test case that regressed with the first iteration of the fix
template  class SP {
T* data;
};

template  class A {
static SP foo();
};

template using TRet = SP>;

template TRet A::foo() { return TRet{};}; // failed with 
error bc TRet and SP

  // had different canonical types due to my change.
```
I had to disable `Sema::CurContext` switch when the type is rebuilt by 
`Sema::RebuildTypeInCurrentInstantiation` routine since its whole point is to 
rebuild the type looking at it from different context. There is comment above 
definition of `Sema::RebuildTypeInCurrentInstantiation` explaining what it 
does. 

The concrete important diff is:
```
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8738,7 +8738,7 @@ public:
  SourceLocation IILoc,
  bool DeducedTSTContext = true);

-
+  bool RebuildingTypesInCurrentInstantiation = false;
   TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
 SourceLocation Loc,
 DeclarationName Name);

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 3157700607e0..810a93f37d74 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -39,6 +39,7 @@
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/SaveAndRestore.h"

 #include 
 #include 
@@ -3990,12 +3991,12 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 if (Inst.isInvalid())
   return QualType();

-{
-  bool ForLambdaCallOperator = false;
-  if (const auto *Rec = dyn_cast(Pattern->getDeclContext()))
-ForLambdaCallOperator = Rec->isLambda();
-  Sema::ContextRAII SavedContext(*this, Pattern->getDeclContext(),
- !ForLambdaCallOperator);
+if (!RebuildingTypesInCurrentInstantiation) {
+  Sema::ContextRAII SavedContext(*this, Pattern->getDeclContext());
+  CanonType =
+  SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
+AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
+} else {
   CanonType =
   SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
 AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
@@ -11399,6 +11400,8 @@ TypeSourceInfo 
*Sema::RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
   if (!T || !T->getType()->isInstantiationDependentType())
 return T;

+  llvm::SaveAndRestore DisableContextSwitchForTypeAliases(
+  RebuildingTypesInCurrentInstantiation, true);
   CurrentInstantiationRebuilder Rebuilder(*this, Loc, Name);
   return Rebuilder.TransformType(T);
 }

```

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


[llvm] [clang-tools-extra] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-20 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Ping.

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


[clang] [clang] Fix a bug with qualified name lookup into current instantiation (PR #73018)

2023-11-21 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/73018

Due to d0d2ee0e4bbe915d649e983c12d37bcfcf58823c clang doesn't perform qualified 
name lookup into the current instantiation when it has dependent bases, because 
of that `getTypeName` call always returns null for unknown specialization case. 
When there is a `typename` keyword, `DependentNameType` is constructed instead 
of simply returning null.
This change attempts to do the same in case of `typename` absence.

Fixes https://github.com/llvm/llvm-project/issues/13826

>From 0275f3ea50b3f410d2132d61ea406131de6c Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 21 Nov 2023 08:32:36 -0800
Subject: [PATCH] [clang] Fix a bug with qualified name lookup into current
 instantiation

Due to d0d2ee0e4bbe915d649e983c12d37bcfcf58823c clang doesn't perform qualified
name lookup into the current instantiation when it has dependent bases, because
of that `getTypeName` call always returns null for unknown specialization case.
When there is a `typename` keyword, `DependentNameType` is constructed instead
of simply returning null.
This change attempts to do the same in case of `typename` absence.

Fixes https://github.com/llvm/llvm-project/issues/13826
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   | 20 ---
 .../SemaTemplate/dependent-base-classes.cpp   | 14 +
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 157afd9e8629152..09ceb591d06eab5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -610,6 +610,9 @@ Bug Fixes in This Version
   inside a lambda. (`#61460 
`_)
 - Fix crash during instantiation of some class template specializations within 
class
   templates. Fixes (`#70375 
`_)
+- Fixed false positive error emitted by clang when performing qualified name
+  lookup and the current class instantiation has dependent bases.
+  Fixes (`#13826 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4e1857b931cc868..71003c1815c90e4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -442,7 +442,6 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, 
SourceLocation NameLoc,
   UsingShadowDecl *FoundUsingShadow = nullptr;
   switch (Result.getResultKind()) {
   case LookupResult::NotFound:
-  case LookupResult::NotFoundInCurrentInstantiation:
 if (CorrectedII) {
   TypeNameValidatorCCC CCC(/*AllowInvalid=*/true, isClassName,
AllowDeducedTemplate);
@@ -482,8 +481,23 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, 
SourceLocation NameLoc,
 }
   }
 }
-// If typo correction failed or was not performed, fall through
-[[fallthrough]];
+Result.suppressDiagnostics();
+return nullptr;
+  case LookupResult::NotFoundInCurrentInstantiation: {
+if (AllowImplicitTypename == ImplicitTypenameContext::Yes) {
+  QualType T;
+  T = Context.getDependentNameType(ElaboratedTypeKeyword::None,
+   SS->getScopeRep(), &II);
+  TypeLocBuilder TLB;
+  DependentNameTypeLoc TL = TLB.push(T);
+  TL.setElaboratedKeywordLoc(SourceLocation());
+  TL.setQualifierLoc(SS->getWithLocInContext(Context));
+  TL.setNameLoc(NameLoc);
+  return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T));
+}
+Result.suppressDiagnostics();
+return nullptr;
+  }
   case LookupResult::FoundOverloaded:
   case LookupResult::FoundUnresolvedValue:
 Result.suppressDiagnostics();
diff --git a/clang/test/SemaTemplate/dependent-base-classes.cpp 
b/clang/test/SemaTemplate/dependent-base-classes.cpp
index 09f475f8bde9183..92a37efaa7e73f6 100644
--- a/clang/test/SemaTemplate/dependent-base-classes.cpp
+++ b/clang/test/SemaTemplate/dependent-base-classes.cpp
@@ -130,3 +130,17 @@ namespace PR5812 {
 
   Derived di;
 }
+
+namespace GH13826 {
+template  struct A {
+  typedef int type;
+  struct B;
+};
+
+template  struct A::B : A {
+  B::type t;
+};
+
+A a;
+A::B b;
+}

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-22 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/73099

The implementation mostly reuses C++ code paths where possible, including 
narrowing check in order to provide diagnostic messages in case initializer for 
constexpr variable is not exactly representable in target type.

The following won't work due to lack of support for other features:
- Diagnosing of underspecified declarations involving constexpr
- Constexpr attached to compound literals

Also due to lack of support for char8_t some of examples with utf-8 strings 
don't work properly.

Fixes https://github.com/llvm/llvm-project/issues/64742

>From 1d70b7726e7d1f11622a6d5c8246b0737e024c8d Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 19 Sep 2023 08:37:18 -0700
Subject: [PATCH] [C23] Implement N3018: The constexpr specifier for object
 definitions

The implementation mostly reuses C++ code paths where possible,
including narrowing check in order to provide diagnostic messages in
case initializer for constexpr variable is not exactly representable in
target type.

The following won't work due to lack of support for other features:
- Diagnosing of underspecified declarations involving constexpr
- Constexpr attached to compound literals

Also due to lack of support for char8_t some of examples with utf-8
strings don't work properly.
---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  16 +
 clang/include/clang/Basic/TokenKinds.def  |   2 +-
 clang/lib/AST/Decl.cpp|  16 +-
 clang/lib/AST/ExprConstant.cpp|  17 +-
 clang/lib/Parse/ParseDecl.cpp |   2 +
 clang/lib/Sema/SemaDecl.cpp   | 204 +++--
 clang/lib/Sema/SemaOverload.cpp   |  36 ++-
 clang/test/C/C2x/n3018.c  |  86 ++
 clang/test/Parser/c23-constexpr.c |   6 +
 clang/test/Sema/constexpr.c   | 275 ++
 clang/www/c_status.html   |   2 +-
 12 files changed, 627 insertions(+), 36 deletions(-)
 create mode 100644 clang/test/C/C2x/n3018.c
 create mode 100644 clang/test/Parser/c23-constexpr.c
 create mode 100644 clang/test/Sema/constexpr.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b65106b9106d4d7..cae1707f3e30feb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -208,6 +208,7 @@ C23 Feature Support
 
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
+- Clang now supports ``N3018 The constexpr specifier for object definitions``.
 
 - Completed the implementation of
   `N2508 `_. We
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 990692c06d7d3a8..11f24583dc55a9b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2932,6 +2932,22 @@ def warn_private_extern : Warning<
 def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
+// C23 constexpr
+def err_c23_thread_local_constexpr : Error<
+  "thread-local storage is not allowed with constexpr">;
+def err_c23_extern_constexpr : Error<
+  "extern specifier is not allowed with constexpr">;
+def err_c23_constexpr_not_variable : Error<
+  "constexpr is only allowed in variable declarations">;
+def err_c23_constexpr_invalid_type : Error<
+  "constexpr variable cannot have type %0">;
+def err_c23_constexpr_init_not_representable : Error<
+  "constexpr initializer evaluates to %0 which is not exactly representable in 
type %1">;
+def err_c23_constexpr_init_type_mismatch : Error<
+  "constexpr initializer for type %0 is of type %1">;
+def err_c23_constexpr_pointer_not_null : Error<
+  "constexpr pointer initializer is not null">;
+
 // C++ Concepts
 def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<
   "concept declarations may only appear in global or namespace scope">;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3ab420821d82bfe..e9e8f59247662ea 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -393,7 +393,7 @@ CXX11_KEYWORD(alignas   , KEYC23)
 CXX11_UNARY_EXPR_OR_TYPE_TRAIT(alignof, AlignOf, KEYC23)
 CXX11_KEYWORD(char16_t  , KEYNOMS18)
 CXX11_KEYWORD(char32_t  , KEYNOMS18)
-CXX11_KEYWORD(constexpr , 0)
+CXX11_KEYWORD(constexpr , KEYC23)
 CXX11_KEYWORD(decltype  , 0)
 CXX11_KEYWORD(noexcept  , 0)
 CXX11_KEYWORD(nullptr   , KEYC23)
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3aba..678a366ed29ad78 100644
--- a/clang/lib/AST/Decl

[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-22 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

cc @to268 , GitHub doesn't let me add you to the reviewers list.

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


[clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-10-31 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/70829

Normally warning is not reported when a field has default initializer. Do so 
for anonymous unions with default initializers as well. No release note since 
it is a regression in clang 18.

Fixes https://github.com/llvm/llvm-project/issues/70384

>From ac30780250875802d13450d17e6959f9e2ad3a70 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 31 Oct 2023 09:27:51 -0700
Subject: [PATCH] [clang] Fix false positive -Wmissing-field-initializer for
 anonymous unions

Normally warning is not reported when a field has default initializer.
Do so for anonymous unions with default initializers as well.
No release note since it is a regression in clang 18.

Fixes https://github.com/llvm/llvm-project/issues/70384
---
 clang/lib/Sema/SemaInit.cpp   | 99 +++
 .../SemaCXX/cxx2a-initializer-aggregates.cpp  | 66 -
 2 files changed, 122 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ec796def96ad3d8..881e67587e430e7 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -349,17 +349,13 @@ class InitListChecker {
   bool SubobjectIsDesignatorContext, unsigned &Index,
   InitListExpr *StructuredList,
   unsigned &StructuredIndex);
-  bool CheckDesignatedInitializer(const InitializedEntity &Entity,
-  InitListExpr *IList, DesignatedInitExpr *DIE,
-  unsigned DesigIdx,
-  QualType &CurrentObjectType,
-  RecordDecl::field_iterator *NextField,
-  llvm::APSInt *NextElementIndex,
-  unsigned &Index,
-  InitListExpr *StructuredList,
-  unsigned &StructuredIndex,
-  bool FinishSubobjectInit,
-  bool TopLevelObject);
+  bool CheckDesignatedInitializer(
+  const InitializedEntity &Entity, InitListExpr *IList,
+  DesignatedInitExpr *DIE, unsigned DesigIdx, QualType &CurrentObjectType,
+  RecordDecl::field_iterator *NextField, llvm::APSInt *NextElementIndex,
+  unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex,
+  bool FinishSubobjectInit, bool TopLevelObject,
+  llvm::SmallPtrSetImpl *InitializedFields = nullptr);
   InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
QualType CurrentObjectType,
InitListExpr *StructuredList,
@@ -2248,7 +2244,8 @@ void InitListChecker::CheckStructUnionTypes(
   // the next field that we'll be initializing.
   bool DesignatedInitFailed = CheckDesignatedInitializer(
   Entity, IList, DIE, 0, DeclType, &Field, nullptr, Index,
-  StructuredList, StructuredIndex, true, TopLevelObject);
+  StructuredList, StructuredIndex, true, TopLevelObject,
+  &InitializedFields);
   if (DesignatedInitFailed)
 hadError = true;
 
@@ -2256,7 +2253,6 @@ void InitListChecker::CheckStructUnionTypes(
   DesignatedInitExpr::Designator *D = DIE->getDesignator(0);
   if (!VerifyOnly && D->isFieldDesignator()) {
 FieldDecl *F = D->getFieldDecl();
-InitializedFields.insert(F);
 if (!DesignatedInitFailed) {
   QualType ET = SemaRef.Context.getBaseElementType(F->getType());
   if (checkDestructorReference(ET, InitLoc, SemaRef)) {
@@ -2365,21 +2361,43 @@ void InitListChecker::CheckStructUnionTypes(
   !RD->isUnion()) {
 // It is possible we have one or more unnamed bitfields remaining.
 // Find first (if any) named field and emit warning.
-for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
-   : Field,
-end = RD->field_end();
- it != end; ++it) {
-  if (HasDesignatedInit && InitializedFields.count(*it))
-continue;
+auto MissingFieldCheck = [&](const RecordDecl *Record,
+ RecordDecl::field_iterator StartField,
+ auto &&MissingFieldCheck) -> bool {
+  FieldDecl *FirstUninitialized = nullptr;
+  for (RecordDecl::field_iterator it = StartField,
+  end = Record->field_end();
+   it != end; ++it) {
+bool AllSet = false;
+if (it->isAnonymousStructOrUnion()) {
+  RecordDecl *RDAnon = it->getType()->getAsRecordDecl();
+  AllSet = MissingFieldCheck(RDAnon, RDAnon->field_begin(),
+ MissingFieldCheck);
+}
+
+if ((HasDesignatedInit && Initializ

[clang] [clang] Substitute alias templates from correct context (PR #75069)

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/75069

>From d0bfa140bdfa2be213151d4d17263bb60e6b46d3 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Mon, 11 Dec 2023 08:31:15 -0800
Subject: [PATCH 1/2] [clang] Substitute alias templates from correct context

Current context set to where alias was met, not where it is declared caused
incorrect access check in case alias referenced private members of the parent
class.
This is a recommit of 6b1aa31 with a slight modification in order to fix
reported regression.

Fixes https://github.com/llvm/llvm-project/issues/41693
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/Sema/Sema.h   |  2 +-
 clang/lib/Sema/SemaCXXScopeSpec.cpp   | 24 +--
 clang/lib/Sema/SemaTemplate.cpp   | 16 -
 .../CXX/temp/temp.decls/temp.alias/p3.cpp |  5 +-
 clang/test/SemaCXX/alias-template.cpp | 65 +++
 6 files changed, 105 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b4b5352a306c1c..1d460ae8375e88 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -677,6 +677,9 @@ Bug Fixes in This Version
   (`#62157 `_) and
   (`#64885 `_) and
   (`#65568 `_)
+- Fixed false positive error emitted when templated alias inside a class
+  used private members of the same class.
+  Fixes (`#41693 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f45e0a7d3d52d4..d8f4b01ee455f1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8738,7 +8738,7 @@ class Sema final {
  SourceLocation IILoc,
  bool DeducedTSTContext = true);
 
-
+  bool RebuildingTypesInCurrentInstantiation = false;
   TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
 SourceLocation Loc,
 DeclarationName Name);
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 44a40215b90dfb..b3b19b7ed7 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -30,6 +30,20 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
 return nullptr;
 
   const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
+  if (isa(Ty)) {
+if (auto *Record = dyn_cast(CurContext)) {
+  if (isa(Record) ||
+  Record->getDescribedClassTemplate()) {
+const Type *ICNT = Record->getTypeForDecl();
+QualType Injected =
+cast(ICNT)->getInjectedSpecializationType();
+
+if (Ty == Injected->getCanonicalTypeInternal().getTypePtr())
+  return Record;
+  }
+}
+  }
+
   if (const RecordType *RecordTy = dyn_cast(Ty)) {
 CXXRecordDecl *Record = cast(RecordTy->getDecl());
 if (!Record->isDependentContext() ||
@@ -37,10 +51,12 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
   return Record;
 
 return nullptr;
-  } else if (isa(Ty))
-return cast(Ty)->getDecl();
-  else
-return nullptr;
+  }
+
+  if (auto *ICNT = dyn_cast(Ty))
+return ICNT->getDecl();
+
+  return nullptr;
 }
 
 /// Compute the DeclContext that is associated with the given type.
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f10abeaba0d451..810a93f37d74e0 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -39,6 +39,7 @@
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/SaveAndRestore.h"
 
 #include 
 #include 
@@ -3990,9 +3991,16 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 if (Inst.isInvalid())
   return QualType();
 
-CanonType = SubstType(Pattern->getUnderlyingType(),
-  TemplateArgLists, AliasTemplate->getLocation(),
-  AliasTemplate->getDeclName());
+if (!RebuildingTypesInCurrentInstantiation) {
+  Sema::ContextRAII SavedContext(*this, Pattern->getDeclContext());
+  CanonType =
+  SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
+AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
+} else {
+  CanonType =
+  SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
+AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
+}
 if (CanonType.isNull()) {
   // If this was enable_if and we failed to find the nested type
   // within enable_if

[libc] [libcxx] [flang] [clang] [libcxxabi] [compiler-rt] [openmp] [clang-tools-extra] [llvm] [mlir] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

@cor3ntin , @shafik WDYT about

> I have a concern, that probably in case when this is actually captured, with 
> current implementation of the patch there will be no warning as well.

Should we still emit shadowing warning in case lambda captured this and has an 
init-capture with the same name as a class field?

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


[compiler-rt] [clang] [lld] [llvm] [openmp] [clang-tools-extra] [libcxx] [lldb] [libc] [flang] [mlir] fix issue 73559. (PR #74926)

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits


@@ -3,3 +3,4 @@
 // PR9137
 void f0(int x) : {}; // expected-error{{expected function body after function 
declarator}}
 void f1(int x) try {}; // expected-error{{expected function body after 
function declarator}}
+::; // expected-error{{expected identifier or '('}}

Fznamznon wrote:

```suggestion

// GH73559
::; // expected-error{{expected identifier or '('}}
```

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


[flang] [llvm] [mlir] [openmp] [clang-tools-extra] [clang] [lldb] [libc] [lld] [compiler-rt] [libcxx] fix issue 73559. (PR #74926)

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits

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


[llvm] [openmp] [lld] [mlir] [lldb] [flang] [libc] [compiler-rt] [clang] [libcxx] [clang-tools-extra] fix issue 73559. (PR #74926)

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

The PR can be landed after a formal approval. Please see 
https://llvm.org/docs/CodeReview.html#lgtm-how-a-patch-is-accepted .

I gave a couple of NITs otherwise the patch looks ok to me. I'm a bit new here, 
so someone else should approve. I added more folks to reviewers list.

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


[compiler-rt] [clang-tools-extra] [libcxx] [lldb] [llvm] [openmp] [flang] [mlir] [clang] [libc] [lld] fix issue 73559. (PR #74926)

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits


@@ -641,6 +641,8 @@ Bug Fixes in This Version
   Fixes (`#67317 `_)
 - Clang now properly diagnoses use of stand-alone OpenMP directives after a
   label (including ``case`` or ``default`` labels).
+- Fix crash when using C++ only tokens like *::* in C compiler clang.

Fznamznon wrote:

```suggestion
- Fix crash when using C++ only tokens like ``::`` in C compiler clang.
```

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


[compiler-rt] [clang-tools-extra] [libcxx] [llvm] [libunwind] [lldb] [openmp] [libcxxabi] [flang] [mlir] [clang] [libc] [lld] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/73099

>From 1d70b7726e7d1f11622a6d5c8246b0737e024c8d Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 19 Sep 2023 08:37:18 -0700
Subject: [PATCH 1/9] [C23] Implement N3018: The constexpr specifier for object
 definitions

The implementation mostly reuses C++ code paths where possible,
including narrowing check in order to provide diagnostic messages in
case initializer for constexpr variable is not exactly representable in
target type.

The following won't work due to lack of support for other features:
- Diagnosing of underspecified declarations involving constexpr
- Constexpr attached to compound literals

Also due to lack of support for char8_t some of examples with utf-8
strings don't work properly.
---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  16 +
 clang/include/clang/Basic/TokenKinds.def  |   2 +-
 clang/lib/AST/Decl.cpp|  16 +-
 clang/lib/AST/ExprConstant.cpp|  17 +-
 clang/lib/Parse/ParseDecl.cpp |   2 +
 clang/lib/Sema/SemaDecl.cpp   | 204 +++--
 clang/lib/Sema/SemaOverload.cpp   |  36 ++-
 clang/test/C/C2x/n3018.c  |  86 ++
 clang/test/Parser/c23-constexpr.c |   6 +
 clang/test/Sema/constexpr.c   | 275 ++
 clang/www/c_status.html   |   2 +-
 12 files changed, 627 insertions(+), 36 deletions(-)
 create mode 100644 clang/test/C/C2x/n3018.c
 create mode 100644 clang/test/Parser/c23-constexpr.c
 create mode 100644 clang/test/Sema/constexpr.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b65106b9106d4..cae1707f3e30f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -208,6 +208,7 @@ C23 Feature Support
 
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
+- Clang now supports ``N3018 The constexpr specifier for object definitions``.
 
 - Completed the implementation of
   `N2508 `_. We
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 990692c06d7d3..11f24583dc55a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2932,6 +2932,22 @@ def warn_private_extern : Warning<
 def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
+// C23 constexpr
+def err_c23_thread_local_constexpr : Error<
+  "thread-local storage is not allowed with constexpr">;
+def err_c23_extern_constexpr : Error<
+  "extern specifier is not allowed with constexpr">;
+def err_c23_constexpr_not_variable : Error<
+  "constexpr is only allowed in variable declarations">;
+def err_c23_constexpr_invalid_type : Error<
+  "constexpr variable cannot have type %0">;
+def err_c23_constexpr_init_not_representable : Error<
+  "constexpr initializer evaluates to %0 which is not exactly representable in 
type %1">;
+def err_c23_constexpr_init_type_mismatch : Error<
+  "constexpr initializer for type %0 is of type %1">;
+def err_c23_constexpr_pointer_not_null : Error<
+  "constexpr pointer initializer is not null">;
+
 // C++ Concepts
 def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<
   "concept declarations may only appear in global or namespace scope">;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3ab420821d82b..e9e8f59247662 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -393,7 +393,7 @@ CXX11_KEYWORD(alignas   , KEYC23)
 CXX11_UNARY_EXPR_OR_TYPE_TRAIT(alignof, AlignOf, KEYC23)
 CXX11_KEYWORD(char16_t  , KEYNOMS18)
 CXX11_KEYWORD(char32_t  , KEYNOMS18)
-CXX11_KEYWORD(constexpr , 0)
+CXX11_KEYWORD(constexpr , KEYC23)
 CXX11_KEYWORD(decltype  , 0)
 CXX11_KEYWORD(noexcept  , 0)
 CXX11_KEYWORD(nullptr   , KEYC23)
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3a..678a366ed29ad 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2461,7 +2461,7 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // OpenCL permits const integral variables to be used in constant
   // expressions, like in C++98.
-  if (!Lang.CPlusPlus && !Lang.OpenCL)
+  if (!Lang.CPlusPlus && !Lang.OpenCL && !Lang.C23)
 return false;
 
   // Function parameters are never usable in constant expressions.
@@ -2485,12 +2485,12 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // In C++, const, non-volatile var

[compiler-rt] [clang-tools-extra] [libcxx] [llvm] [libunwind] [lldb] [openmp] [libcxxabi] [flang] [mlir] [clang] [libc] [lld] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits


@@ -0,0 +1,287 @@
+// RUN: %clang_cc1 -std=c2x -verify -triple x86_64 -pedantic -Wno-conversion 
-Wno-constant-conversion -Wno-div-by-zero %s
+
+// Check that constexpr only applies to variables.
+constexpr void f0() {} // expected-error {{'constexpr' can only be used in 
variable declarations}}
+constexpr const int f1() { return 0; } // expected-error {{'constexpr' can 
only be used in variable declarations}}
+
+constexpr struct S1 { int f; }; //expected-error {{struct cannot be marked 
constexpr}}
+constexpr struct S2 ; // expected-error {{struct cannot be marked constexpr}}
+constexpr union U1; // expected-error {{union cannot be marked constexpr}}
+constexpr union U2 {int a; float b;}; // expected-error {{union cannot be 
marked constexpr}}
+constexpr enum E1 {A = 1, B = 2} ; // expected-error {{enum cannot be marked 
constexpr}}
+struct S3 {
+  static constexpr int f = 0; // expected-error {{type name does not allow 
storage class}}
+  // expected-error@-1 {{type name does not allow constexpr}}
+  // expected-error@-2 {{expected ';' at end}}
+  constexpr int f1 = 0;
+  // expected-error@-1 {{type name does not allow constexpr}}
+  // expected-error@-2 {{expected ';' at end}}
+};
+
+constexpr; // expected-error {{'constexpr' can only be used in variable 
declarations}}
+constexpr int V1 = 3;
+constexpr float V2 = 7.0;
+int V3 = (constexpr)3; // expected-error {{expected expression}}
+
+void f2() {
+  constexpr int a = 0;
+  constexpr float b = 1.7f;
+}
+
+// Check how constexpr works with other storage-class specifiers.
+constexpr auto V4 = 1;
+constexpr static auto V5 = 1;
+constexpr static const auto V6 = 1;
+constexpr static const int V7 = 1;
+constexpr static int V8 = 1;

Fznamznon wrote:

Makes sense, thanks, done.

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


[clang-tools-extra] [llvm] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [clang] Substitute alias templates from correct context (PR #75069)

2023-12-12 Thread Mariya Podchishchaeva via cfe-commits

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


[clang-tools-extra] [flang] [llvm] [libc] [libunwind] [lldb] [openmp] [libcxxabi] [libcxx] [mlir] [compiler-rt] [clang] [lld] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-13 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Adding more reviewers since Aaron is on vacation...

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


[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-13 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/75332

Fixes https://github.com/llvm/llvm-project/issues/63151

>From d0a7276eb8014693656d3d931616d56ffe46730c Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 13 Dec 2023 04:25:12 -0800
Subject: [PATCH] [clang] Report narrowing conversions with const references

Fixes https://github.com/llvm/llvm-project/issues/63151
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaInit.cpp| 30 ++
 clang/test/SemaCXX/GH63151.cpp | 12 
 3 files changed, 33 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH63151.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 05d59d0da264f3..2aba1740a6b610 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -521,6 +521,9 @@ Improvements to Clang's diagnostics
   |   ~~~^
 
 - Clang now diagnoses definitions of friend function specializations, e.g. 
``friend void f<>(int) {}``.
+- Clang now diagnoses narrowing conversions involving const references.
+  (`#63151: `_).
+
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 4028b2d642b212..7ff1b55d1fcba0 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4432,7 +4432,8 @@ static void TryReferenceInitializationCore(Sema &S,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
-   InitializationSequence &Sequence);
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList);
 
 static void TryValueInitialization(Sema &S,
const InitializedEntity &Entity,
@@ -4486,7 +4487,8 @@ static void TryReferenceListInitialization(Sema &S,
 if (RefRelationship >= Sema::Ref_Related) {
   // Try to bind the reference here.
   TryReferenceInitializationCore(S, Entity, Kind, Initializer, cv1T1, T1,
- T1Quals, cv2T2, T2, T2Quals, Sequence);
+ T1Quals, cv2T2, T2, T2Quals, Sequence,
+ true);
   if (Sequence)
 Sequence.RewrapReferenceInitList(cv1T1, InitList);
   return;
@@ -4945,11 +4947,11 @@ static void CheckCXX98CompatAccessibleCopy(Sema &S,
Expr *CurInitExpr);
 
 /// Attempt reference initialization (C++0x [dcl.init.ref])
-static void TryReferenceInitialization(Sema &S,
-   const InitializedEntity &Entity,
+static void TryReferenceInitialization(Sema &S, const InitializedEntity 
&Entity,
const InitializationKind &Kind,
Expr *Initializer,
-   InitializationSequence &Sequence) {
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   QualType cv1T1 = DestType->castAs()->getPointeeType();
   Qualifiers T1Quals;
@@ -4967,7 +4969,8 @@ static void TryReferenceInitialization(Sema &S,
 
   // Delegate everything else to a subfunction.
   TryReferenceInitializationCore(S, Entity, Kind, Initializer, cv1T1, T1,
- T1Quals, cv2T2, T2, T2Quals, Sequence);
+ T1Quals, cv2T2, T2, T2Quals, Sequence,
+ TopLevelOfInitList);
 }
 
 /// Determine whether an expression is a non-referenceable glvalue (one to
@@ -4990,7 +4993,8 @@ static void TryReferenceInitializationCore(Sema &S,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
-   InitializationSequence &Sequence) {
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   SourceLocation DeclLoc = Initializer->getBeginLoc();
 
@@ -5264,7 +5268,8 @@ static void TryReferenceInitializationCore(Sema &S,
   Sequence.SetFailed(InitializationSequence::FK_ReferenceInitFailed);
 return;
   } else {
-Sequence.AddConversionSequenceStep(ICS, TempEntity.getType());
+Sequence.AddConversionSequenceStep(ICS, TempEntity.getType(),
+   TopLevelOfInitList);
   }
 
   //[...] If T1 is r

[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-13 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Formatting trouble is intentional.

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


[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-13 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/75332

>From d0a7276eb8014693656d3d931616d56ffe46730c Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 13 Dec 2023 04:25:12 -0800
Subject: [PATCH 1/2] [clang] Report narrowing conversions with const
 references

Fixes https://github.com/llvm/llvm-project/issues/63151
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaInit.cpp| 30 ++
 clang/test/SemaCXX/GH63151.cpp | 12 
 3 files changed, 33 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH63151.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 05d59d0da264f3..2aba1740a6b610 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -521,6 +521,9 @@ Improvements to Clang's diagnostics
   |   ~~~^
 
 - Clang now diagnoses definitions of friend function specializations, e.g. 
``friend void f<>(int) {}``.
+- Clang now diagnoses narrowing conversions involving const references.
+  (`#63151: `_).
+
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 4028b2d642b212..7ff1b55d1fcba0 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4432,7 +4432,8 @@ static void TryReferenceInitializationCore(Sema &S,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
-   InitializationSequence &Sequence);
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList);
 
 static void TryValueInitialization(Sema &S,
const InitializedEntity &Entity,
@@ -4486,7 +4487,8 @@ static void TryReferenceListInitialization(Sema &S,
 if (RefRelationship >= Sema::Ref_Related) {
   // Try to bind the reference here.
   TryReferenceInitializationCore(S, Entity, Kind, Initializer, cv1T1, T1,
- T1Quals, cv2T2, T2, T2Quals, Sequence);
+ T1Quals, cv2T2, T2, T2Quals, Sequence,
+ true);
   if (Sequence)
 Sequence.RewrapReferenceInitList(cv1T1, InitList);
   return;
@@ -4945,11 +4947,11 @@ static void CheckCXX98CompatAccessibleCopy(Sema &S,
Expr *CurInitExpr);
 
 /// Attempt reference initialization (C++0x [dcl.init.ref])
-static void TryReferenceInitialization(Sema &S,
-   const InitializedEntity &Entity,
+static void TryReferenceInitialization(Sema &S, const InitializedEntity 
&Entity,
const InitializationKind &Kind,
Expr *Initializer,
-   InitializationSequence &Sequence) {
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   QualType cv1T1 = DestType->castAs()->getPointeeType();
   Qualifiers T1Quals;
@@ -4967,7 +4969,8 @@ static void TryReferenceInitialization(Sema &S,
 
   // Delegate everything else to a subfunction.
   TryReferenceInitializationCore(S, Entity, Kind, Initializer, cv1T1, T1,
- T1Quals, cv2T2, T2, T2Quals, Sequence);
+ T1Quals, cv2T2, T2, T2Quals, Sequence,
+ TopLevelOfInitList);
 }
 
 /// Determine whether an expression is a non-referenceable glvalue (one to
@@ -4990,7 +4993,8 @@ static void TryReferenceInitializationCore(Sema &S,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
-   InitializationSequence &Sequence) {
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   SourceLocation DeclLoc = Initializer->getBeginLoc();
 
@@ -5264,7 +5268,8 @@ static void TryReferenceInitializationCore(Sema &S,
   Sequence.SetFailed(InitializationSequence::FK_ReferenceInitFailed);
 return;
   } else {
-Sequence.AddConversionSequenceStep(ICS, TempEntity.getType());
+Sequence.AddConversionSequenceStep(ICS, TempEntity.getType(),
+   TopLevelOfInitList);
   }
 
   //[...] If T1 is reference-related to T2, cv1 must be the
@@ -6228,7 +

[clang] [clang] Accept recursive non-dependent calls to functions with deduced return type (PR #75456)

2023-12-14 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/75456

Treat such calls as dependent since it is much easier to implement.

Fixes https://github.com/llvm/llvm-project/issues/71015

>From 0e190f131862dd8f4b07891c3ee712a0a163f936 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Thu, 14 Dec 2023 01:33:17 -0800
Subject: [PATCH] [clang] Accept recursive non-dependent calls to functions
 with deduced return type

Treat such calls as dependent since it is much easier to implement.

Fixes https://github.com/llvm/llvm-project/issues/71015
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/lib/AST/ComputeDependence.cpp   |  2 ++
 clang/lib/Sema/SemaOverload.cpp   | 18 ++
 .../SemaCXX/deduced-return-type-cxx14.cpp | 33 +++
 4 files changed, 56 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 05d59d0da264f3..9ffc7500414981 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -688,6 +688,9 @@ Bug Fixes in This Version
 - Fixed false positive error emitted when templated alias inside a class
   used private members of the same class.
   Fixes (`#41693 `_)
+- Clang now accepts recursive non-dependent calls to functions with deduced 
return
+  type.
+  Fixes (`#71015 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/ComputeDependence.cpp 
b/clang/lib/AST/ComputeDependence.cpp
index 097753fd3267b5..584b58473294be 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -603,6 +603,8 @@ ExprDependence clang::computeDependence(PredefinedExpr *E) {
 ExprDependence clang::computeDependence(CallExpr *E,
 llvm::ArrayRef PreArgs) {
   auto D = E->getCallee()->getDependence();
+  if (E->getType()->isDependentType())
+D |= ExprDependence::Type;
   for (auto *A : llvm::ArrayRef(E->getArgs(), E->getNumArgs())) {
 if (A)
   D |= A->getDependence();
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 5026e1d603e5ee..9fb767101e1eb7 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13994,6 +13994,24 @@ ExprResult Sema::BuildOverloadedCallExpr(Scope *S, 
Expr *Fn,
   OverloadCandidateSet::iterator Best;
   OverloadingResult OverloadResult =
   CandidateSet.BestViableFunction(*this, Fn->getBeginLoc(), Best);
+  FunctionDecl *FDecl = Best->Function;
+
+  // Model the case with a call to a templated function whose definition
+  // encloses the call and whose return type contains a placeholder type as if
+  // the UnresolvedLookupExpr was type-dependent.
+  if (OverloadResult == OR_Success && FDecl &&
+  FDecl->isTemplateInstantiation() &&
+  FDecl->getReturnType()->isUndeducedType()) {
+if (auto TP = FDecl->getTemplateInstantiationPattern(false)) {
+  if (TP->willHaveBody()) {
+CallExpr *CE =
+CallExpr::Create(Context, Fn, Args, Context.DependentTy, 
VK_PRValue,
+ RParenLoc, CurFPFeatureOverrides());
+result = CE;
+return result;
+  }
+}
+  }
 
   return FinishOverloadedCallExpr(*this, S, Fn, ULE, LParenLoc, Args, 
RParenLoc,
   ExecConfig, &CandidateSet, &Best,
diff --git a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp 
b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
index 6344d1df3fbaeb..1da597499d34f5 100644
--- a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
+++ b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
@@ -640,3 +640,36 @@ namespace PR46637 {
   template struct Y { T x; };
   Y auto> y; // expected-error {{'auto' not allowed in template 
argument}}
 }
+
+namespace GH71015 {
+
+// Check that there is no error in case a templated function is recursive and
+// has a placeholder return type.
+struct Node {
+  int value;
+  Node* left;
+  Node* right;
+};
+
+bool parse(const char*);
+Node* parsePrimaryExpr();
+
+auto parseMulExpr(auto node) { // cxx14-error {{'auto' not allowed in function 
prototype}}
+  if (node == nullptr) node = parsePrimaryExpr();
+  if (!parse("*")) return node;
+  return parseMulExpr(new Node{.left = node, .right = parsePrimaryExpr()});
+}
+
+template 
+auto parseMulExpr2(T node) {
+  if (node == nullptr) node = parsePrimaryExpr();
+  if (!parse("*")) return node;
+  return parseMulExpr2(new Node{.left = node, .right = parsePrimaryExpr()});
+}
+
+auto f(auto x) { // cxx14-error {{'auto' not allowed in function prototype}}
+  if (x == 0) return 0;
+  return f(1) + 1;
+}
+
+}

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


[clang] [clang] Accept recursive non-dependent calls to functions with deduced return type (PR #75456)

2023-12-14 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

This attempts to implement the approach described by @zygoloid in 
https://github.com/llvm/llvm-project/issues/71015#issuecomment-1828745626 .

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


[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-14 Thread Mariya Podchishchaeva via cfe-commits


@@ -10431,7 +10437,7 @@ static void DiagnoseNarrowingInInitList(Sema &S,
 : diag::warn_init_list_type_narrowing)
 << PostInit->getSourceRange()
 << PreNarrowingType.getLocalUnqualifiedType()
-<< EntityType.getLocalUnqualifiedType();
+<< EntityType.getLocalUnqualifiedType().getNonReferenceType();

Fznamznon wrote:

> Since this is supposed to remove local qualifiers, should the reference be 
> removed first? What happens with a const int & as is?

Perhaps makes sense. I only removed reference since it is already removed from 
the pre-narrowing-type and I was a bit inspired by gcc messages 
https://godbolt.org/z/Tcv17Wxhc . I could leave reference type it as is, then 
the messages will look like:

```

struct A { A(const unsigned &x) {} };

int foo(const int &aba) {
A a { -1 }; // constant expression evaluates to -1 which cannot be narrowed 
to type 'const unsigned int&'
A b { aba }; // non-constant-expression cannot be narrowed from type 'int' 
to 'const unsigned int' in initializer list
return 0;
}
```

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


[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-14 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-14 Thread Mariya Podchishchaeva via cfe-commits


@@ -10431,7 +10437,7 @@ static void DiagnoseNarrowingInInitList(Sema &S,
 : diag::warn_init_list_type_narrowing)
 << PostInit->getSourceRange()
 << PreNarrowingType.getLocalUnqualifiedType()
-<< EntityType.getLocalUnqualifiedType();
+<< EntityType.getLocalUnqualifiedType().getNonReferenceType();

Fznamznon wrote:

My guess is `getLocalUnqualifiedType` doesn't strip cv qualifiers from 
reference's pointee type, so we first should remove reference and then 
qualifiers to see plain `int` in the diagnostic.

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


[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-14 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/75332

>From d0a7276eb8014693656d3d931616d56ffe46730c Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 13 Dec 2023 04:25:12 -0800
Subject: [PATCH 1/3] [clang] Report narrowing conversions with const
 references

Fixes https://github.com/llvm/llvm-project/issues/63151
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaInit.cpp| 30 ++
 clang/test/SemaCXX/GH63151.cpp | 12 
 3 files changed, 33 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH63151.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 05d59d0da264f3..2aba1740a6b610 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -521,6 +521,9 @@ Improvements to Clang's diagnostics
   |   ~~~^
 
 - Clang now diagnoses definitions of friend function specializations, e.g. 
``friend void f<>(int) {}``.
+- Clang now diagnoses narrowing conversions involving const references.
+  (`#63151: `_).
+
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 4028b2d642b212..7ff1b55d1fcba0 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4432,7 +4432,8 @@ static void TryReferenceInitializationCore(Sema &S,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
-   InitializationSequence &Sequence);
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList);
 
 static void TryValueInitialization(Sema &S,
const InitializedEntity &Entity,
@@ -4486,7 +4487,8 @@ static void TryReferenceListInitialization(Sema &S,
 if (RefRelationship >= Sema::Ref_Related) {
   // Try to bind the reference here.
   TryReferenceInitializationCore(S, Entity, Kind, Initializer, cv1T1, T1,
- T1Quals, cv2T2, T2, T2Quals, Sequence);
+ T1Quals, cv2T2, T2, T2Quals, Sequence,
+ true);
   if (Sequence)
 Sequence.RewrapReferenceInitList(cv1T1, InitList);
   return;
@@ -4945,11 +4947,11 @@ static void CheckCXX98CompatAccessibleCopy(Sema &S,
Expr *CurInitExpr);
 
 /// Attempt reference initialization (C++0x [dcl.init.ref])
-static void TryReferenceInitialization(Sema &S,
-   const InitializedEntity &Entity,
+static void TryReferenceInitialization(Sema &S, const InitializedEntity 
&Entity,
const InitializationKind &Kind,
Expr *Initializer,
-   InitializationSequence &Sequence) {
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   QualType cv1T1 = DestType->castAs()->getPointeeType();
   Qualifiers T1Quals;
@@ -4967,7 +4969,8 @@ static void TryReferenceInitialization(Sema &S,
 
   // Delegate everything else to a subfunction.
   TryReferenceInitializationCore(S, Entity, Kind, Initializer, cv1T1, T1,
- T1Quals, cv2T2, T2, T2Quals, Sequence);
+ T1Quals, cv2T2, T2, T2Quals, Sequence,
+ TopLevelOfInitList);
 }
 
 /// Determine whether an expression is a non-referenceable glvalue (one to
@@ -4990,7 +4993,8 @@ static void TryReferenceInitializationCore(Sema &S,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
-   InitializationSequence &Sequence) {
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   SourceLocation DeclLoc = Initializer->getBeginLoc();
 
@@ -5264,7 +5268,8 @@ static void TryReferenceInitializationCore(Sema &S,
   Sequence.SetFailed(InitializationSequence::FK_ReferenceInitFailed);
 return;
   } else {
-Sequence.AddConversionSequenceStep(ICS, TempEntity.getType());
+Sequence.AddConversionSequenceStep(ICS, TempEntity.getType(),
+   TopLevelOfInitList);
   }
 
   //[...] If T1 is reference-related to T2, cv1 must be the
@@ -6228,7 +

[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-14 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> Looks like you got what I meant anyway, and we WERE just passionately 
> agreeing with eachother :) LGTM.

Thanks!
Probably I was being a bit slow, lol

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


[clang] [clang] Substitute alias templates from correct context (PR #75069)

2023-12-14 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

@rupprecht , no, this is not expected. Please feel free to revert since it is 
night in my time zone. Otherwise I will revert tomorrow.

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


[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-15 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-15 Thread Mariya Podchishchaeva via cfe-commits


@@ -685,6 +685,8 @@ Bug Fixes in This Version
   (`#62157 `_) and
   (`#64885 `_) and
   (`#65568 `_)
+- Fix an issue where clang doesn't respect detault template arguments that
+  are added in a later redeclaration for CTAD. (#69987 
`_)

Fznamznon wrote:

A little nit to align the style
```suggestion
  are added in a later redeclaration for CTAD.
  Fixes (#69987 `_)
```

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


[llvm] [clang] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-12-15 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

@mikaelholmen , thanks for the report. These warnings are kind of expected, 
there is no big difference between `struct S1 s01 = { 1, {1} };` and `struct S1 
s02 = { .d1.a = 1 };` in both cases field `b` of `d1` is not initialized. But 
they are not expected for C, since we aim to silence missing field initializer 
warning for designated initializers in C, just to match gcc behavior. It seems 
the patch broke this "silencing" for nested designators, I'll try to provide 
the fix shortly. If I'm not able, I'll revert. 

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


[clang] [clang] Fix unexpected warnings after a01307a (PR #75591)

2023-12-15 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/75591

a01307a broke silencing of -Wmissing-field-initializers warnings in C for 
nested designators. This fixes the issue.

>From 7d93f51878c495e245ce21d4be97c4ca7cddd404 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Fri, 15 Dec 2023 04:05:41 -0800
Subject: [PATCH] [clang] Fix unexpected warnings after a01307a

a01307a broke silencing of -Wmissing-field-initializers warnings in C for
nested designators. This fixes the issue.
---
 clang/lib/Sema/SemaInit.cpp  |  8 +++
 clang/test/Sema/missing-field-initializers.c | 23 
 2 files changed, 31 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index de0d92edb550dd..1cd2198503abaf 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -864,6 +864,14 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
   WarnIfMissingField &=
   SemaRef.getLangOpts().CPlusPlus || !hasAnyDesignatedInits(SForm);
 
+  if (OuterILE) {
+InitListExpr *OuterSForm = OuterILE->isSyntacticForm()
+   ? OuterILE
+   : OuterILE->getSyntacticForm();
+WarnIfMissingField &= SemaRef.getLangOpts().CPlusPlus ||
+  !hasAnyDesignatedInits(OuterSForm);
+  }
+
   unsigned NumElems = numStructUnionElements(ILE->getType());
   if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
 ++NumElems;
diff --git a/clang/test/Sema/missing-field-initializers.c 
b/clang/test/Sema/missing-field-initializers.c
index 8653591ff1187a..8dc8288ad92e6c 100644
--- a/clang/test/Sema/missing-field-initializers.c
+++ b/clang/test/Sema/missing-field-initializers.c
@@ -61,3 +61,26 @@ struct S {
 // f1, now we no longer issue that warning (note, this code is still unsafe
 // because of the buffer overrun).
 struct S s = {1, {1, 2}};
+
+struct S1 {
+  long int l;
+  struct  { int a, b; } d1;
+};
+
+struct S1 s01 = { 1, {1} }; // expected-warning {{missing field 'b' 
initializer}}
+struct S1 s02 = { .d1.a = 1 }; // designator avoids MFI warning
+
+union U1 {
+  long int l;
+  struct  { int a, b; } d1;
+};
+
+union U1 u01 = { 1 };
+union U1 u02 = { .d1.a = 1 }; // designator avoids MFI warning
+
+struct S2 {
+  long int l;
+  struct { int a, b; struct {int c; } d2; } d1;
+};
+
+struct S2 s22 = { .d1.d2.c = 1 }; // designator avoids MFI warning

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


[clang] [clang] Fix unexpected warnings after a01307a (PR #75591)

2023-12-15 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/75591

>From 7d93f51878c495e245ce21d4be97c4ca7cddd404 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Fri, 15 Dec 2023 04:05:41 -0800
Subject: [PATCH 1/2] [clang] Fix unexpected warnings after a01307a

a01307a broke silencing of -Wmissing-field-initializers warnings in C for
nested designators. This fixes the issue.
---
 clang/lib/Sema/SemaInit.cpp  |  8 +++
 clang/test/Sema/missing-field-initializers.c | 23 
 2 files changed, 31 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index de0d92edb550dd..1cd2198503abaf 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -864,6 +864,14 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
   WarnIfMissingField &=
   SemaRef.getLangOpts().CPlusPlus || !hasAnyDesignatedInits(SForm);
 
+  if (OuterILE) {
+InitListExpr *OuterSForm = OuterILE->isSyntacticForm()
+   ? OuterILE
+   : OuterILE->getSyntacticForm();
+WarnIfMissingField &= SemaRef.getLangOpts().CPlusPlus ||
+  !hasAnyDesignatedInits(OuterSForm);
+  }
+
   unsigned NumElems = numStructUnionElements(ILE->getType());
   if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
 ++NumElems;
diff --git a/clang/test/Sema/missing-field-initializers.c 
b/clang/test/Sema/missing-field-initializers.c
index 8653591ff1187a..8dc8288ad92e6c 100644
--- a/clang/test/Sema/missing-field-initializers.c
+++ b/clang/test/Sema/missing-field-initializers.c
@@ -61,3 +61,26 @@ struct S {
 // f1, now we no longer issue that warning (note, this code is still unsafe
 // because of the buffer overrun).
 struct S s = {1, {1, 2}};
+
+struct S1 {
+  long int l;
+  struct  { int a, b; } d1;
+};
+
+struct S1 s01 = { 1, {1} }; // expected-warning {{missing field 'b' 
initializer}}
+struct S1 s02 = { .d1.a = 1 }; // designator avoids MFI warning
+
+union U1 {
+  long int l;
+  struct  { int a, b; } d1;
+};
+
+union U1 u01 = { 1 };
+union U1 u02 = { .d1.a = 1 }; // designator avoids MFI warning
+
+struct S2 {
+  long int l;
+  struct { int a, b; struct {int c; } d2; } d1;
+};
+
+struct S2 s22 = { .d1.d2.c = 1 }; // designator avoids MFI warning

>From d779611237a5a4b8824c011a09639ff4f745fd23 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Fri, 15 Dec 2023 05:29:56 -0800
Subject: [PATCH 2/2] Add comment

---
 clang/lib/Sema/SemaInit.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 1cd2198503abaf..035eaae58965a4 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -865,6 +865,9 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
   SemaRef.getLangOpts().CPlusPlus || !hasAnyDesignatedInits(SForm);
 
   if (OuterILE) {
+// When nested designators are present, there might be two nested init
+// lists created and only outer will contain designated initializer
+// expression, so check outer list as well.
 InitListExpr *OuterSForm = OuterILE->isSyntacticForm()
? OuterILE
: OuterILE->getSyntacticForm();

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


[clang] [clang] Fix unexpected warnings after a01307a (PR #75591)

2023-12-15 Thread Mariya Podchishchaeva via cfe-commits


@@ -864,6 +864,14 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
   WarnIfMissingField &=
   SemaRef.getLangOpts().CPlusPlus || !hasAnyDesignatedInits(SForm);
 
+  if (OuterILE) {

Fznamznon wrote:

Okay, sure.

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


[clang] [clang] Fix unexpected warnings after a01307a (PR #75591)

2023-12-15 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> Ok, ideally this should be reviewed by someone who knows the code but it LGTM.

I know, but a lot of folks are now on vacation already. The change is not 
complicated, so I'll probably wait till green pre-commit, then leave it for 
post-commit review to resolve the issue.

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


[clang] [clang] Fix unexpected warnings after a01307a (PR #75591)

2023-12-15 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Ok, adding more reviewers. Please feel free to do post-commit review.

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


[clang] [clang] Fix unexpected warnings after a01307a (PR #75591)

2023-12-15 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-12-18 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

@mikaelholmen , I see. I'll revert both patches to unblock you and I'll think 
about the proper solution after the holidays.
Perhaps there should be wider discussion whether we should emulate GCC behavior 
regarding silencing of these warnings.
IMO, the warnings you're seeing are correct, there is no initializer for field 
`b`. It is emulating of possible gcc bug that this patch breaks.


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


[clang] [Clang] Fix a crash when incorrectly calling an explicit object member function template (PR #75913)

2023-12-19 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [Clang] Fix a crash when incorrectly calling an explicit object member function template (PR #75913)

2023-12-19 Thread Mariya Podchishchaeva via cfe-commits


@@ -253,7 +253,9 @@ static void diagnoseInstanceReference(Sema &SemaRef,
 SemaRef.Diag(Loc, diag::err_member_call_without_object)
 << Range << /*static*/ 0;
   else {
-const auto *Callee = dyn_cast(Rep);
+if (auto *Tpl = dyn_cast(Rep))

Fznamznon wrote:

Perhaps a const can be added here.

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


[clang] [Clang] Fix a crash when incorrectly calling an explicit object member function template (PR #75913)

2023-12-19 Thread Mariya Podchishchaeva via cfe-commits

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

LGTM with a little NIT

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


[clang-tools-extra] [llvm] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-23 Thread Mariya Podchishchaeva via cfe-commits


@@ -727,6 +729,44 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 if (hadError || VerifyOnly) {
   // Do nothing
 } else if (Init < NumInits) {

Fznamznon wrote:

It seems `Init < NumInits` is always true for non-`VerifyOnly` mode only for 
structs. So, removing lines `684-685, 704-707, 772-778` breaks a number of 
tests with unions. The assertion on line 676 confirms:
```
if (Init >= NumInits || !ILE->getInit(Init)) {
  if (const RecordType *RType = ILE->getType()->getAs())
if (!RType->getDecl()->isUnion())
  assert((Init < NumInits || VerifyOnly) &&
 "This ILE should have been expanded");
```
I can still put warning emission out of `Init < NumInits` check though if that 
seems more correct.

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


[clang-tools-extra] [llvm] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-23 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/70829

>From ac30780250875802d13450d17e6959f9e2ad3a70 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 31 Oct 2023 09:27:51 -0700
Subject: [PATCH 1/5] [clang] Fix false positive -Wmissing-field-initializer
 for anonymous unions

Normally warning is not reported when a field has default initializer.
Do so for anonymous unions with default initializers as well.
No release note since it is a regression in clang 18.

Fixes https://github.com/llvm/llvm-project/issues/70384
---
 clang/lib/Sema/SemaInit.cpp   | 99 +++
 .../SemaCXX/cxx2a-initializer-aggregates.cpp  | 66 -
 2 files changed, 122 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ec796def96ad3d8..881e67587e430e7 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -349,17 +349,13 @@ class InitListChecker {
   bool SubobjectIsDesignatorContext, unsigned &Index,
   InitListExpr *StructuredList,
   unsigned &StructuredIndex);
-  bool CheckDesignatedInitializer(const InitializedEntity &Entity,
-  InitListExpr *IList, DesignatedInitExpr *DIE,
-  unsigned DesigIdx,
-  QualType &CurrentObjectType,
-  RecordDecl::field_iterator *NextField,
-  llvm::APSInt *NextElementIndex,
-  unsigned &Index,
-  InitListExpr *StructuredList,
-  unsigned &StructuredIndex,
-  bool FinishSubobjectInit,
-  bool TopLevelObject);
+  bool CheckDesignatedInitializer(
+  const InitializedEntity &Entity, InitListExpr *IList,
+  DesignatedInitExpr *DIE, unsigned DesigIdx, QualType &CurrentObjectType,
+  RecordDecl::field_iterator *NextField, llvm::APSInt *NextElementIndex,
+  unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex,
+  bool FinishSubobjectInit, bool TopLevelObject,
+  llvm::SmallPtrSetImpl *InitializedFields = nullptr);
   InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
QualType CurrentObjectType,
InitListExpr *StructuredList,
@@ -2248,7 +2244,8 @@ void InitListChecker::CheckStructUnionTypes(
   // the next field that we'll be initializing.
   bool DesignatedInitFailed = CheckDesignatedInitializer(
   Entity, IList, DIE, 0, DeclType, &Field, nullptr, Index,
-  StructuredList, StructuredIndex, true, TopLevelObject);
+  StructuredList, StructuredIndex, true, TopLevelObject,
+  &InitializedFields);
   if (DesignatedInitFailed)
 hadError = true;
 
@@ -2256,7 +2253,6 @@ void InitListChecker::CheckStructUnionTypes(
   DesignatedInitExpr::Designator *D = DIE->getDesignator(0);
   if (!VerifyOnly && D->isFieldDesignator()) {
 FieldDecl *F = D->getFieldDecl();
-InitializedFields.insert(F);
 if (!DesignatedInitFailed) {
   QualType ET = SemaRef.Context.getBaseElementType(F->getType());
   if (checkDestructorReference(ET, InitLoc, SemaRef)) {
@@ -2365,21 +2361,43 @@ void InitListChecker::CheckStructUnionTypes(
   !RD->isUnion()) {
 // It is possible we have one or more unnamed bitfields remaining.
 // Find first (if any) named field and emit warning.
-for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
-   : Field,
-end = RD->field_end();
- it != end; ++it) {
-  if (HasDesignatedInit && InitializedFields.count(*it))
-continue;
+auto MissingFieldCheck = [&](const RecordDecl *Record,
+ RecordDecl::field_iterator StartField,
+ auto &&MissingFieldCheck) -> bool {
+  FieldDecl *FirstUninitialized = nullptr;
+  for (RecordDecl::field_iterator it = StartField,
+  end = Record->field_end();
+   it != end; ++it) {
+bool AllSet = false;
+if (it->isAnonymousStructOrUnion()) {
+  RecordDecl *RDAnon = it->getType()->getAsRecordDecl();
+  AllSet = MissingFieldCheck(RDAnon, RDAnon->field_begin(),
+ MissingFieldCheck);
+}
+
+if ((HasDesignatedInit && InitializedFields.count(*it)) ||
+it->hasInClassInitializer() || AllSet) {
+  if (Record->isUnion())
+return true;
+  continue;
+}
 
-  if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&

[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-23 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/73099

>From 1d70b7726e7d1f11622a6d5c8246b0737e024c8d Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 19 Sep 2023 08:37:18 -0700
Subject: [PATCH 1/2] [C23] Implement N3018: The constexpr specifier for object
 definitions

The implementation mostly reuses C++ code paths where possible,
including narrowing check in order to provide diagnostic messages in
case initializer for constexpr variable is not exactly representable in
target type.

The following won't work due to lack of support for other features:
- Diagnosing of underspecified declarations involving constexpr
- Constexpr attached to compound literals

Also due to lack of support for char8_t some of examples with utf-8
strings don't work properly.
---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  16 +
 clang/include/clang/Basic/TokenKinds.def  |   2 +-
 clang/lib/AST/Decl.cpp|  16 +-
 clang/lib/AST/ExprConstant.cpp|  17 +-
 clang/lib/Parse/ParseDecl.cpp |   2 +
 clang/lib/Sema/SemaDecl.cpp   | 204 +++--
 clang/lib/Sema/SemaOverload.cpp   |  36 ++-
 clang/test/C/C2x/n3018.c  |  86 ++
 clang/test/Parser/c23-constexpr.c |   6 +
 clang/test/Sema/constexpr.c   | 275 ++
 clang/www/c_status.html   |   2 +-
 12 files changed, 627 insertions(+), 36 deletions(-)
 create mode 100644 clang/test/C/C2x/n3018.c
 create mode 100644 clang/test/Parser/c23-constexpr.c
 create mode 100644 clang/test/Sema/constexpr.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b65106b9106d4d7..cae1707f3e30feb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -208,6 +208,7 @@ C23 Feature Support
 
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
+- Clang now supports ``N3018 The constexpr specifier for object definitions``.
 
 - Completed the implementation of
   `N2508 `_. We
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 990692c06d7d3a8..11f24583dc55a9b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2932,6 +2932,22 @@ def warn_private_extern : Warning<
 def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
+// C23 constexpr
+def err_c23_thread_local_constexpr : Error<
+  "thread-local storage is not allowed with constexpr">;
+def err_c23_extern_constexpr : Error<
+  "extern specifier is not allowed with constexpr">;
+def err_c23_constexpr_not_variable : Error<
+  "constexpr is only allowed in variable declarations">;
+def err_c23_constexpr_invalid_type : Error<
+  "constexpr variable cannot have type %0">;
+def err_c23_constexpr_init_not_representable : Error<
+  "constexpr initializer evaluates to %0 which is not exactly representable in 
type %1">;
+def err_c23_constexpr_init_type_mismatch : Error<
+  "constexpr initializer for type %0 is of type %1">;
+def err_c23_constexpr_pointer_not_null : Error<
+  "constexpr pointer initializer is not null">;
+
 // C++ Concepts
 def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<
   "concept declarations may only appear in global or namespace scope">;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3ab420821d82bfe..e9e8f59247662ea 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -393,7 +393,7 @@ CXX11_KEYWORD(alignas   , KEYC23)
 CXX11_UNARY_EXPR_OR_TYPE_TRAIT(alignof, AlignOf, KEYC23)
 CXX11_KEYWORD(char16_t  , KEYNOMS18)
 CXX11_KEYWORD(char32_t  , KEYNOMS18)
-CXX11_KEYWORD(constexpr , 0)
+CXX11_KEYWORD(constexpr , KEYC23)
 CXX11_KEYWORD(decltype  , 0)
 CXX11_KEYWORD(noexcept  , 0)
 CXX11_KEYWORD(nullptr   , KEYC23)
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3aba..678a366ed29ad78 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2461,7 +2461,7 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // OpenCL permits const integral variables to be used in constant
   // expressions, like in C++98.
-  if (!Lang.CPlusPlus && !Lang.OpenCL)
+  if (!Lang.CPlusPlus && !Lang.OpenCL && !Lang.C23)
 return false;
 
   // Function parameters are never usable in constant expressions.
@@ -2485,12 +2485,12 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // In C++, const, 

[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Ping.

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-29 Thread Mariya Podchishchaeva via cfe-commits


@@ -2932,6 +2932,22 @@ def warn_private_extern : Warning<
 def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
+// C23 constexpr
+def err_c23_thread_local_constexpr : Error<
+  "thread-local storage is not allowed with constexpr">;
+def err_c23_extern_constexpr : Error<
+  "extern specifier is not allowed with constexpr">;

Fznamznon wrote:

I'm not quite sure reusing `err_invalid_decl_spec_combination` will look clear 
enough, here is what I got while trying:
```
t3.c:2:1: error: cannot combine with previous 'extern' declaration specifier
2 | constexpr extern int V79 = 10;
  | ^ ~~

```
If that is still better, I can update it.

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-29 Thread Mariya Podchishchaeva via cfe-commits


@@ -4110,6 +4116,10 @@ static CompleteObject findCompleteObject(EvalInfo &Info, 
const Expr *E,
 }
 
 bool IsConstant = BaseType.isConstant(Info.Ctx);
+bool ConstexprVar = false;
+if (const auto *VD = dyn_cast_if_present(
+Info.EvaluatingDecl.dyn_cast()))
+  ConstexprVar = VD->isConstexpr();

Fznamznon wrote:

This is to check that an initializer for a `constexpr` variable in c23 can only 
reference other `constexpr` variables. Done since C++ allows things like
```
const int a = 0;
constexpr int b = a;
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-29 Thread Mariya Podchishchaeva via cfe-commits


@@ -14240,6 +14294,114 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind getConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}

Fznamznon wrote:

> I wonder if we should expose (some of) the logic of IsStandardConversion() 
> from SemaOverload.cpp

You mean part starting from
https://github.com/llvm/llvm-project/blob/af65379e383bac651f0868237e9086630b15ee0d/clang/lib/Sema/SemaOverload.cpp#L2074
 ?

If yes, how this will help better with the problem of adding new conversions?

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-29 Thread Mariya Podchishchaeva via cfe-commits


@@ -14240,6 +14294,114 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind getConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}
+
+static bool checkC23ConstexprInitConversion(Sema &S, const Expr *Init) {
+  assert(S.getLangOpts().C23);
+  const Expr *InitNoCast = Init->IgnoreImpCasts();
+  StandardConversionSequence SCS;
+  SCS.setAsIdentityConversion();
+  auto FromType = InitNoCast->getType();
+  auto ToType = Init->getType();
+  SCS.setToType(0, FromType);
+  SCS.setToType(1, ToType);
+  SCS.Second = getConversionKind(FromType, ToType);
+
+  APValue Value;
+  QualType PreNarrowingType;
+  // Reuse C++ narrowing check.
+  switch (SCS.getNarrowingKind(S.Context, Init, Value, PreNarrowingType,
+   /*IgnoreFloatToIntegralConversion*/ false)) {
+  // The value doesn't fit.
+  case NK_Constant_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_not_representable)
+<< Value.getAsString(S.Context, PreNarrowingType) << ToType;
+return true;
+
+  // Conversion to a narrower type.
+  case NK_Type_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_type_mismatch)
+<< ToType << FromType;
+return true;
+
+  // Since we only reuse narrowing check for C23 constexpr variables here, 
we're
+  // not really interested in these cases.
+  case NK_Dependent_Narrowing:
+  case NK_Variable_Narrowing:
+  case NK_Not_Narrowing:
+return false;
+  }
+  llvm_unreachable("unhandled case in switch");
+}
+
+static bool checkC23ConstexprInitStringLiteral(const StringLiteral *SE,
+   Sema &SemaRef,
+   SourceLocation Loc) {
+  assert(SemaRef.getLangOpts().C23);
+  // String literals have the target type attached but underneath may contain
+  // values that don't really fit into the target type. Check that every
+  // character fits.
+  const ConstantArrayType *CAT =
+  SemaRef.Context.getAsConstantArrayType(SE->getType());
+  QualType CharType = CAT->getElementType();
+  uint32_t BitWidth = SemaRef.Context.getTypeSize(CharType);
+  bool isUnsigned = CharType->isUnsignedIntegerType();
+  llvm::APSInt Value(BitWidth, isUnsigned);
+  const StringRef S = SE->getBytes();
+  for (unsigned I = 0, N = SE->getLength(); I != N; ++I) {
+Value = S[I];
+if (Value != S[I]) {
+  SemaRef.Diag(Loc, diag::err_c23_constexpr_init_not_representable)
+  << S[I] << CharType;

Fznamznon wrote:

I'm not sure? What I'm trying to do is catch an overflowing conversion which 
already happens in `getCodeUnit()`. Perhaps if I have to use `getCodeUnit()` 
there should be another check then?

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-29 Thread Mariya Podchishchaeva via cfe-commits


@@ -14397,17 +14559,21 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
   QualType baseType = Context.getBaseElementType(type);
   bool HasConstInit = true;
 
+  if (getLangOpts().C23 && var->isConstexpr() && !Init)
+Diag(var->getLocation(), diag::err_constexpr_var_requires_const_init)
+<< var;

Fznamznon wrote:

Yes, existing logic uses `InitializationSequence` code paths that are deeply 
tied to C++ initialization rules, modifying these for C didn't seem reasonable.

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-29 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-29 Thread Mariya Podchishchaeva via cfe-commits


@@ -9237,6 +9282,22 @@ static FunctionDecl *CreateNewFunctionDecl(Sema 
&SemaRef, Declarator &D,
   FunctionDecl *NewFD = nullptr;
   bool isInline = D.getDeclSpec().isInlineSpecified();
 
+  ConstexprSpecKind ConstexprKind = D.getDeclSpec().getConstexprSpecifier();
+  if (ConstexprKind == ConstexprSpecKind::Constinit ||
+  (SemaRef.getLangOpts().C23 &&
+   ConstexprKind == ConstexprSpecKind::Constexpr)) {
+
+if (SemaRef.getLangOpts().C23)
+  SemaRef.Diag(D.getDeclSpec().getConstexprSpecLoc(),
+   diag::err_c23_constexpr_not_variable);

Fznamznon wrote:

> Hmmm, I'm not certain we need to change anything here

Well, without that move for C we silently create `FunctionDecl` and exit 
whether it has `constexpr` specifier or not.

> it would be more clear to say that a function cannot be constexpr in C 
> instead of saying you declared something constexpr that isn't a variable. 
> WDYT?

I don't seem to have a problem with this particular message, for C++ similar 
invalid use cases clang says and does the same. But If that will help users, ok.
I also use `err_c23_constexpr_not_variable` message when diagnosing constexpr 
applied to a type declaration. Should I add more specific message for this case 
as well?

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


[llvm] [clang] [clang-tools-extra] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-29 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/73099

>From 1d70b7726e7d1f11622a6d5c8246b0737e024c8d Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 19 Sep 2023 08:37:18 -0700
Subject: [PATCH 1/5] [C23] Implement N3018: The constexpr specifier for object
 definitions

The implementation mostly reuses C++ code paths where possible,
including narrowing check in order to provide diagnostic messages in
case initializer for constexpr variable is not exactly representable in
target type.

The following won't work due to lack of support for other features:
- Diagnosing of underspecified declarations involving constexpr
- Constexpr attached to compound literals

Also due to lack of support for char8_t some of examples with utf-8
strings don't work properly.
---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  16 +
 clang/include/clang/Basic/TokenKinds.def  |   2 +-
 clang/lib/AST/Decl.cpp|  16 +-
 clang/lib/AST/ExprConstant.cpp|  17 +-
 clang/lib/Parse/ParseDecl.cpp |   2 +
 clang/lib/Sema/SemaDecl.cpp   | 204 +++--
 clang/lib/Sema/SemaOverload.cpp   |  36 ++-
 clang/test/C/C2x/n3018.c  |  86 ++
 clang/test/Parser/c23-constexpr.c |   6 +
 clang/test/Sema/constexpr.c   | 275 ++
 clang/www/c_status.html   |   2 +-
 12 files changed, 627 insertions(+), 36 deletions(-)
 create mode 100644 clang/test/C/C2x/n3018.c
 create mode 100644 clang/test/Parser/c23-constexpr.c
 create mode 100644 clang/test/Sema/constexpr.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b65106b9106d4d7..cae1707f3e30feb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -208,6 +208,7 @@ C23 Feature Support
 
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
+- Clang now supports ``N3018 The constexpr specifier for object definitions``.
 
 - Completed the implementation of
   `N2508 `_. We
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 990692c06d7d3a8..11f24583dc55a9b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2932,6 +2932,22 @@ def warn_private_extern : Warning<
 def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
+// C23 constexpr
+def err_c23_thread_local_constexpr : Error<
+  "thread-local storage is not allowed with constexpr">;
+def err_c23_extern_constexpr : Error<
+  "extern specifier is not allowed with constexpr">;
+def err_c23_constexpr_not_variable : Error<
+  "constexpr is only allowed in variable declarations">;
+def err_c23_constexpr_invalid_type : Error<
+  "constexpr variable cannot have type %0">;
+def err_c23_constexpr_init_not_representable : Error<
+  "constexpr initializer evaluates to %0 which is not exactly representable in 
type %1">;
+def err_c23_constexpr_init_type_mismatch : Error<
+  "constexpr initializer for type %0 is of type %1">;
+def err_c23_constexpr_pointer_not_null : Error<
+  "constexpr pointer initializer is not null">;
+
 // C++ Concepts
 def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<
   "concept declarations may only appear in global or namespace scope">;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3ab420821d82bfe..e9e8f59247662ea 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -393,7 +393,7 @@ CXX11_KEYWORD(alignas   , KEYC23)
 CXX11_UNARY_EXPR_OR_TYPE_TRAIT(alignof, AlignOf, KEYC23)
 CXX11_KEYWORD(char16_t  , KEYNOMS18)
 CXX11_KEYWORD(char32_t  , KEYNOMS18)
-CXX11_KEYWORD(constexpr , 0)
+CXX11_KEYWORD(constexpr , KEYC23)
 CXX11_KEYWORD(decltype  , 0)
 CXX11_KEYWORD(noexcept  , 0)
 CXX11_KEYWORD(nullptr   , KEYC23)
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3aba..678a366ed29ad78 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2461,7 +2461,7 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // OpenCL permits const integral variables to be used in constant
   // expressions, like in C++98.
-  if (!Lang.CPlusPlus && !Lang.OpenCL)
+  if (!Lang.CPlusPlus && !Lang.OpenCL && !Lang.C23)
 return false;
 
   // Function parameters are never usable in constant expressions.
@@ -2485,12 +2485,12 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // In C++, const, 

[clang] [lld] [libunwind] [mlir] [libc] [flang] [llvm] [libcxx] [openmp] [clang-tools-extra] [libcxxabi] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-29 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/73099

>From 1d70b7726e7d1f11622a6d5c8246b0737e024c8d Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 19 Sep 2023 08:37:18 -0700
Subject: [PATCH 1/5] [C23] Implement N3018: The constexpr specifier for object
 definitions

The implementation mostly reuses C++ code paths where possible,
including narrowing check in order to provide diagnostic messages in
case initializer for constexpr variable is not exactly representable in
target type.

The following won't work due to lack of support for other features:
- Diagnosing of underspecified declarations involving constexpr
- Constexpr attached to compound literals

Also due to lack of support for char8_t some of examples with utf-8
strings don't work properly.
---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  16 +
 clang/include/clang/Basic/TokenKinds.def  |   2 +-
 clang/lib/AST/Decl.cpp|  16 +-
 clang/lib/AST/ExprConstant.cpp|  17 +-
 clang/lib/Parse/ParseDecl.cpp |   2 +
 clang/lib/Sema/SemaDecl.cpp   | 204 +++--
 clang/lib/Sema/SemaOverload.cpp   |  36 ++-
 clang/test/C/C2x/n3018.c  |  86 ++
 clang/test/Parser/c23-constexpr.c |   6 +
 clang/test/Sema/constexpr.c   | 275 ++
 clang/www/c_status.html   |   2 +-
 12 files changed, 627 insertions(+), 36 deletions(-)
 create mode 100644 clang/test/C/C2x/n3018.c
 create mode 100644 clang/test/Parser/c23-constexpr.c
 create mode 100644 clang/test/Sema/constexpr.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b65106b9106d4d7..cae1707f3e30feb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -208,6 +208,7 @@ C23 Feature Support
 
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
+- Clang now supports ``N3018 The constexpr specifier for object definitions``.
 
 - Completed the implementation of
   `N2508 `_. We
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 990692c06d7d3a8..11f24583dc55a9b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2932,6 +2932,22 @@ def warn_private_extern : Warning<
 def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
+// C23 constexpr
+def err_c23_thread_local_constexpr : Error<
+  "thread-local storage is not allowed with constexpr">;
+def err_c23_extern_constexpr : Error<
+  "extern specifier is not allowed with constexpr">;
+def err_c23_constexpr_not_variable : Error<
+  "constexpr is only allowed in variable declarations">;
+def err_c23_constexpr_invalid_type : Error<
+  "constexpr variable cannot have type %0">;
+def err_c23_constexpr_init_not_representable : Error<
+  "constexpr initializer evaluates to %0 which is not exactly representable in 
type %1">;
+def err_c23_constexpr_init_type_mismatch : Error<
+  "constexpr initializer for type %0 is of type %1">;
+def err_c23_constexpr_pointer_not_null : Error<
+  "constexpr pointer initializer is not null">;
+
 // C++ Concepts
 def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<
   "concept declarations may only appear in global or namespace scope">;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3ab420821d82bfe..e9e8f59247662ea 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -393,7 +393,7 @@ CXX11_KEYWORD(alignas   , KEYC23)
 CXX11_UNARY_EXPR_OR_TYPE_TRAIT(alignof, AlignOf, KEYC23)
 CXX11_KEYWORD(char16_t  , KEYNOMS18)
 CXX11_KEYWORD(char32_t  , KEYNOMS18)
-CXX11_KEYWORD(constexpr , 0)
+CXX11_KEYWORD(constexpr , KEYC23)
 CXX11_KEYWORD(decltype  , 0)
 CXX11_KEYWORD(noexcept  , 0)
 CXX11_KEYWORD(nullptr   , KEYC23)
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3aba..678a366ed29ad78 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2461,7 +2461,7 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // OpenCL permits const integral variables to be used in constant
   // expressions, like in C++98.
-  if (!Lang.CPlusPlus && !Lang.OpenCL)
+  if (!Lang.CPlusPlus && !Lang.OpenCL && !Lang.C23)
 return false;
 
   // Function parameters are never usable in constant expressions.
@@ -2485,12 +2485,12 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // In C++, const, 

[compiler-rt] [llvm] [mlir] [clang] [clang-tools-extra] [clang] Fix a bug with qualified name lookup into current instantiation (PR #73018)

2023-11-29 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/73018

>From 0275f3ea50b3f410d2132d61ea406131de6c Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 21 Nov 2023 08:32:36 -0800
Subject: [PATCH 1/2] [clang] Fix a bug with qualified name lookup into current
 instantiation

Due to d0d2ee0e4bbe915d649e983c12d37bcfcf58823c clang doesn't perform qualified
name lookup into the current instantiation when it has dependent bases, because
of that `getTypeName` call always returns null for unknown specialization case.
When there is a `typename` keyword, `DependentNameType` is constructed instead
of simply returning null.
This change attempts to do the same in case of `typename` absence.

Fixes https://github.com/llvm/llvm-project/issues/13826
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   | 20 ---
 .../SemaTemplate/dependent-base-classes.cpp   | 14 +
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 157afd9e8629152..09ceb591d06eab5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -610,6 +610,9 @@ Bug Fixes in This Version
   inside a lambda. (`#61460 
`_)
 - Fix crash during instantiation of some class template specializations within 
class
   templates. Fixes (`#70375 
`_)
+- Fixed false positive error emitted by clang when performing qualified name
+  lookup and the current class instantiation has dependent bases.
+  Fixes (`#13826 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4e1857b931cc868..71003c1815c90e4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -442,7 +442,6 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, 
SourceLocation NameLoc,
   UsingShadowDecl *FoundUsingShadow = nullptr;
   switch (Result.getResultKind()) {
   case LookupResult::NotFound:
-  case LookupResult::NotFoundInCurrentInstantiation:
 if (CorrectedII) {
   TypeNameValidatorCCC CCC(/*AllowInvalid=*/true, isClassName,
AllowDeducedTemplate);
@@ -482,8 +481,23 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, 
SourceLocation NameLoc,
 }
   }
 }
-// If typo correction failed or was not performed, fall through
-[[fallthrough]];
+Result.suppressDiagnostics();
+return nullptr;
+  case LookupResult::NotFoundInCurrentInstantiation: {
+if (AllowImplicitTypename == ImplicitTypenameContext::Yes) {
+  QualType T;
+  T = Context.getDependentNameType(ElaboratedTypeKeyword::None,
+   SS->getScopeRep(), &II);
+  TypeLocBuilder TLB;
+  DependentNameTypeLoc TL = TLB.push(T);
+  TL.setElaboratedKeywordLoc(SourceLocation());
+  TL.setQualifierLoc(SS->getWithLocInContext(Context));
+  TL.setNameLoc(NameLoc);
+  return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T));
+}
+Result.suppressDiagnostics();
+return nullptr;
+  }
   case LookupResult::FoundOverloaded:
   case LookupResult::FoundUnresolvedValue:
 Result.suppressDiagnostics();
diff --git a/clang/test/SemaTemplate/dependent-base-classes.cpp 
b/clang/test/SemaTemplate/dependent-base-classes.cpp
index 09f475f8bde9183..92a37efaa7e73f6 100644
--- a/clang/test/SemaTemplate/dependent-base-classes.cpp
+++ b/clang/test/SemaTemplate/dependent-base-classes.cpp
@@ -130,3 +130,17 @@ namespace PR5812 {
 
   Derived di;
 }
+
+namespace GH13826 {
+template  struct A {
+  typedef int type;
+  struct B;
+};
+
+template  struct A::B : A {
+  B::type t;
+};
+
+A a;
+A::B b;
+}

>From 5f4b4b93ed52ca06451289c9d5054824186901e7 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 29 Nov 2023 10:47:38 -0800
Subject: [PATCH 2/2] Apply comments

---
 clang/lib/Sema/SemaDecl.cpp | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 71003c1815c90e4..7ac0d40a33c3126 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -483,21 +483,17 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, 
SourceLocation NameLoc,
 }
 Result.suppressDiagnostics();
 return nullptr;
-  case LookupResult::NotFoundInCurrentInstantiation: {
+  case LookupResult::NotFoundInCurrentInstantiation:
 if (AllowImplicitTypename == ImplicitTypenameContext::Yes) {
-  QualType T;
-  T = Context.getDependentNameType(ElaboratedTypeKeyword::None,
-   SS->getScopeRep(), &II);
+  QualType T = Context.getDependentNameType(ElaboratedTypeKeyword::None,
+   

[clang] [llvm] [compiler-rt] [mlir] [clang-tools-extra] [clang] Fix a bug with qualified name lookup into current instantiation (PR #73018)

2023-11-30 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-30 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Ping.

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


  1   2   3   4   5   6   7   8   9   >