[PATCH] D86310: [X86] Align i128 to 16 bytes in x86 datalayouts

2023-11-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Hi there,

This change seems to be causing assertion failure in clang when a struct 
contains a _BitInt with length longer than 128 - 
https://godbolt.org/z/4jTrW4fcP .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86310

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


[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-10-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

In D157879#4655321 , @rsmith wrote:

> This change has introduced a false positive for anonymous union members:
>
>   struct A {
>   int m;
>   union { int n = 0; };
>   };
>   
>   A a = A{.m = 0};
>
> now produces a false positive warning saying that the anonymous union member 
> in `A` is uninitialized.

Thanks! I've created https://github.com/llvm/llvm-project/issues/70444 and will 
figure something to fix this asap.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

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


[PATCH] D159279: [clang] Emit `Wformat` for bool value and char specifier confusion in scanf

2023-09-01 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe4e56f91df6a: [clang] Emit `Wformat` for bool value and char 
specifier confusion in scanf (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159279

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/FormatString.cpp
  clang/test/SemaCXX/format-strings-scanf.cpp


Index: clang/test/SemaCXX/format-strings-scanf.cpp
===
--- clang/test/SemaCXX/format-strings-scanf.cpp
+++ clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument 
has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the 
argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", , , , );
 scan("%hi %hu", , );
 scan("%i %u", , );
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. Fixes
+  (`#64987 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/format-strings-scanf.cpp
===
--- clang/test/SemaCXX/format-strings-scanf.cpp
+++ clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", , , , );
 scan("%hi %hu", , );
 scan("%i %u", , );
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. 

[PATCH] D159279: [clang] Emit `Wformat` for bool value and char specifier confusion in scanf

2023-09-01 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 555289.
Fznamznon added a comment.

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159279

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/FormatString.cpp
  clang/test/SemaCXX/format-strings-scanf.cpp


Index: clang/test/SemaCXX/format-strings-scanf.cpp
===
--- clang/test/SemaCXX/format-strings-scanf.cpp
+++ clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument 
has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the 
argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", , , , );
 scan("%hi %hu", , );
 scan("%i %u", , );
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. Fixes
+  (`#64987 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/format-strings-scanf.cpp
===
--- clang/test/SemaCXX/format-strings-scanf.cpp
+++ clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", , , , );
 scan("%hi %hu", , );
 scan("%i %u", , );
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. Fixes
+  (`#64987 `_)
 
 Bug Fixes to Compiler 

[PATCH] D159279: [clang] Emit `Wformat` for bool value and char specifier confusion in scanf

2023-08-31 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159279

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/FormatString.cpp
  clang/test/SemaCXX/format-strings-scanf.cpp


Index: clang/test/SemaCXX/format-strings-scanf.cpp
===
--- clang/test/SemaCXX/format-strings-scanf.cpp
+++ clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument 
has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the 
argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", , , , );
 scan("%hi %hu", , );
 scan("%i %u", , );
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -208,6 +208,9 @@
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. Fixes
+  (`#64987 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/format-strings-scanf.cpp
===
--- clang/test/SemaCXX/format-strings-scanf.cpp
+++ clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", , , , );
 scan("%hi %hu", , );
 scan("%i %u", , );
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -208,6 +208,9 @@
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. Fixes
+  (`#64987 

[PATCH] D158615: [clang] Emit an error if variable ends up with incomplete array type

2023-08-29 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbcc881161aeb: [clang] Emit an error if variable ends up with 
incomplete array type (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158615

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/gh37257.cpp


Index: clang/test/SemaCXX/gh37257.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/gh37257.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template
+T&& create();
+
+template
+void test() {
+  T t(create()...); // expected-error{{variable has incomplete type 
'int[]'}}
+  (void) t;
+}
+
+struct A;
+
+int main() {
+  test(); // expected-note {{in instantiation of function template 
specialization 'test' requested here}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13445,6 +13445,18 @@
 IsParenListInit = !InitSeq.steps().empty() &&
   InitSeq.step_begin()->Kind ==
   InitializationSequence::SK_ParenthesizedListInit;
+QualType VDeclType = VDecl->getType();
+if (Init && !Init->getType().isNull() &&
+!Init->getType()->isDependentType() && !VDeclType->isDependentType() &&
+Context.getAsIncompleteArrayType(VDeclType) &&
+Context.getAsIncompleteArrayType(Init->getType())) {
+  // Bail out if it is not possible to deduce array size from the
+  // initializer.
+  Diag(VDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
+  << VDeclType;
+  VDecl->setInvalidDecl();
+  return;
+}
   }
 
   // Check for self-references within variable initializers.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -189,6 +189,9 @@
   (`#64876 `_)
 - Fixed an assertion if a function has cleanups and fatal erors.
   (`#48974 `_)
+- Clang now emits an error if it is not possible to deduce array size for a
+  variable with incomplete array type.
+  (`#37257 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/gh37257.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/gh37257.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template
+T&& create();
+
+template
+void test() {
+  T t(create()...); // expected-error{{variable has incomplete type 'int[]'}}
+  (void) t;
+}
+
+struct A;
+
+int main() {
+  test(); // expected-note {{in instantiation of function template specialization 'test' requested here}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13445,6 +13445,18 @@
 IsParenListInit = !InitSeq.steps().empty() &&
   InitSeq.step_begin()->Kind ==
   InitializationSequence::SK_ParenthesizedListInit;
+QualType VDeclType = VDecl->getType();
+if (Init && !Init->getType().isNull() &&
+!Init->getType()->isDependentType() && !VDeclType->isDependentType() &&
+Context.getAsIncompleteArrayType(VDeclType) &&
+Context.getAsIncompleteArrayType(Init->getType())) {
+  // Bail out if it is not possible to deduce array size from the
+  // initializer.
+  Diag(VDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
+  << VDeclType;
+  VDecl->setInvalidDecl();
+  return;
+}
   }
 
   // Check for self-references within variable initializers.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -189,6 +189,9 @@
   (`#64876 `_)
 - Fixed an assertion if a function has cleanups and fatal erors.
   (`#48974 `_)
+- Clang now emits an error if it is not possible to deduce array size for a
+  variable with incomplete array type.
+  (`#37257 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158615: [clang] Emit an error if variable ends up with incomplete array type

2023-08-29 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

The failures in CI are unrelated and caused by another patch - 
https://reviews.llvm.org/D112921.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158615

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


[PATCH] D158615: [clang] Emit an error if variable ends up with incomplete array type

2023-08-29 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 554220.
Fznamznon added a comment.

Apply suggestion, rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158615

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/gh37257.cpp


Index: clang/test/SemaCXX/gh37257.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/gh37257.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template
+T&& create();
+
+template
+void test() {
+  T t(create()...); // expected-error{{variable has incomplete type 
'int[]'}}
+  (void) t;
+}
+
+struct A;
+
+int main() {
+  test(); // expected-note {{in instantiation of function template 
specialization 'test' requested here}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13445,6 +13445,18 @@
 IsParenListInit = !InitSeq.steps().empty() &&
   InitSeq.step_begin()->Kind ==
   InitializationSequence::SK_ParenthesizedListInit;
+QualType VDeclType = VDecl->getType();
+if (Init && !Init->getType().isNull() &&
+!Init->getType()->isDependentType() && !VDeclType->isDependentType() &&
+Context.getAsIncompleteArrayType(VDeclType) &&
+Context.getAsIncompleteArrayType(Init->getType())) {
+  // Bail out if it is not possible to deduce array size from the
+  // initializer.
+  Diag(VDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
+  << VDeclType;
+  VDecl->setInvalidDecl();
+  return;
+}
   }
 
   // Check for self-references within variable initializers.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,9 @@
   (`#64876 `_)
 - Fixed an assertion if a function has cleanups and fatal erors.
   (`#48974 `_)
+- Clang now emits an error if it is not possible to deduce array size for a
+  variable with incomplete array type.
+  (`#37257 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/gh37257.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/gh37257.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template
+T&& create();
+
+template
+void test() {
+  T t(create()...); // expected-error{{variable has incomplete type 'int[]'}}
+  (void) t;
+}
+
+struct A;
+
+int main() {
+  test(); // expected-note {{in instantiation of function template specialization 'test' requested here}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13445,6 +13445,18 @@
 IsParenListInit = !InitSeq.steps().empty() &&
   InitSeq.step_begin()->Kind ==
   InitializationSequence::SK_ParenthesizedListInit;
+QualType VDeclType = VDecl->getType();
+if (Init && !Init->getType().isNull() &&
+!Init->getType()->isDependentType() && !VDeclType->isDependentType() &&
+Context.getAsIncompleteArrayType(VDeclType) &&
+Context.getAsIncompleteArrayType(Init->getType())) {
+  // Bail out if it is not possible to deduce array size from the
+  // initializer.
+  Diag(VDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
+  << VDeclType;
+  VDecl->setInvalidDecl();
+  return;
+}
   }
 
   // Check for self-references within variable initializers.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,9 @@
   (`#64876 `_)
 - Fixed an assertion if a function has cleanups and fatal erors.
   (`#48974 `_)
+- Clang now emits an error if it is not possible to deduce array size for a
+  variable with incomplete array type.
+  (`#37257 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158827: [clang] Fix assertion fail when function has cleanups and fatal errors

2023-08-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5ade434a7e74: [clang] Fix assertion fail when function has 
cleanups and fatal errors (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D158827?vs=553420=553872#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158827

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/gh48974.cpp


Index: clang/test/SemaCXX/gh48974.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/gh48974.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -Werror=unused-parameter -Wfatal-errors -verify %s
+
+void a(int &) {} // expected-error{{unused parameter 's'}}
+
+void b() {
+  int sum = a(0);
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16013,6 +16013,7 @@
   // been leftover. This ensures that these temporaries won't be picked up
   // for deletion in some later function.
   if (hasUncompilableErrorOccurred() ||
+  hasAnyUnrecoverableErrorsInThisFunction() ||
   getDiagnostics().getSuppressAllDiagnostics()) {
 DiscardCleanupsInEvaluationContext();
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -187,6 +187,8 @@
 - Fix crash in __builtin_strncmp and related builtins when the size value
   exceeded the maximum value representable by int64_t. Fixes
   (`#64876 `_)
+- Fixed an assertion if a function has cleanups and fatal erors.
+  (`#48974 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/gh48974.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/gh48974.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -Werror=unused-parameter -Wfatal-errors -verify %s
+
+void a(int &) {} // expected-error{{unused parameter 's'}}
+
+void b() {
+  int sum = a(0);
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16013,6 +16013,7 @@
   // been leftover. This ensures that these temporaries won't be picked up
   // for deletion in some later function.
   if (hasUncompilableErrorOccurred() ||
+  hasAnyUnrecoverableErrorsInThisFunction() ||
   getDiagnostics().getSuppressAllDiagnostics()) {
 DiscardCleanupsInEvaluationContext();
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -187,6 +187,8 @@
 - Fix crash in __builtin_strncmp and related builtins when the size value
   exceeded the maximum value representable by int64_t. Fixes
   (`#64876 `_)
+- Fixed an assertion if a function has cleanups and fatal erors.
+  (`#48974 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158827: [clang] Fix assertion fail when function has cleanups and fatal errors

2023-08-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158827

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/gh48974.cpp


Index: clang/test/SemaCXX/gh48974.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/gh48974.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -Werror=unused-parameter -Wfatal-errors -verify %s
+
+void a(int &) {} // expected-error{{unused parameter 's'}}
+
+void b() {
+  int sum = a(0);
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16013,6 +16013,7 @@
   // been leftover. This ensures that these temporaries won't be picked up
   // for deletion in some later function.
   if (hasUncompilableErrorOccurred() ||
+  hasAnyUnrecoverableErrorsInThisFunction() ||
   getDiagnostics().getSuppressAllDiagnostics()) {
 DiscardCleanupsInEvaluationContext();
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -172,6 +172,8 @@
 - Clang now prints unnamed members in diagnostic messages instead of giving an
   empty ''. Fixes
   (`#63759 `_)
+- Fixed an assertion if a function has cleanups and fatal erors.
+  (`#48974 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/gh48974.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/gh48974.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -Werror=unused-parameter -Wfatal-errors -verify %s
+
+void a(int &) {} // expected-error{{unused parameter 's'}}
+
+void b() {
+  int sum = a(0);
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16013,6 +16013,7 @@
   // been leftover. This ensures that these temporaries won't be picked up
   // for deletion in some later function.
   if (hasUncompilableErrorOccurred() ||
+  hasAnyUnrecoverableErrorsInThisFunction() ||
   getDiagnostics().getSuppressAllDiagnostics()) {
 DiscardCleanupsInEvaluationContext();
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -172,6 +172,8 @@
 - Clang now prints unnamed members in diagnostic messages instead of giving an
   empty ''. Fixes
   (`#63759 `_)
+- Fixed an assertion if a function has cleanups and fatal erors.
+  (`#48974 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158526: [clang] Properly print unnamed members in diagnostics

2023-08-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf4c886b6aaea: [clang] Properly print unnamed members in 
diagnostics (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D158526?vs=552410=553128#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158526

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/AST/ast-dump-APValue-anon-union.cpp
  clang/test/CXX/special/class.dtor/p5-0x.cpp
  clang/test/Sema/transparent-union.c
  clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
  clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
  clang/test/SemaObjCXX/arc-0x.mm

Index: clang/test/SemaObjCXX/arc-0x.mm
===
--- clang/test/SemaObjCXX/arc-0x.mm
+++ clang/test/SemaObjCXX/arc-0x.mm
@@ -161,7 +161,7 @@
 
   struct S1 {
 union {
-  union { // expected-note {{copy constructor of 'S1' is implicitly deleted because field '' has a deleted copy constructor}} expected-note {{copy assignment operator of 'S1' is implicitly deleted because field '' has a deleted copy assignment operator}} expected-note 4 {{'S1' is implicitly deleted because field '' has a deleted}}
+  union { // expected-note-re {{copy constructor of 'S1' is implicitly deleted because field 'test_union::S1::(anonymous union at {{.*}})' has a deleted copy constructor}} expected-note-re {{copy assignment operator of 'S1' is implicitly deleted because field 'test_union::S1::(anonymous union at {{.*}})' has a deleted copy assignment operator}} expected-note-re 4 {{'S1' is implicitly deleted because field 'test_union::S1::(anonymous union at {{.*}})' has a deleted}}
 id f0; // expected-note-re 2 .*}} of '(anonymous union at {{.*}}' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 char f1;
   };
@@ -172,7 +172,7 @@
   struct S2 {
 union {
   // FIXME: the note should say 'f0' is causing the special functions to be deleted.
-  struct { // expected-note 6 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
+  struct { // expected-note-re 6 {{'S2' is implicitly deleted because variant field 'test_union::S2::(anonymous struct at {{.*}})' has a non-trivial}}
 id f0;
 int f1;
   };
@@ -194,8 +194,8 @@
   };
 
   static union { // expected-error {{call to implicitly-deleted default constructor of}}
-union { // expected-note-re {{default constructor of '(unnamed union at {{.*}}' is implicitly deleted because field '' has a deleted default constructor}}
-  union { // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because field '' has a deleted default constructor}}
+union { // expected-note-re {{default constructor of '(unnamed union at {{.*}}' is implicitly deleted because field 'test_union::(anonymous union at {{.*}})' has a deleted default constructor}}
+  union { // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because field 'test_union::(anonymous union at {{.*}})' has a deleted default constructor}}
 __weak id g1; // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because variant field 'g1' is an ObjC pointer}}
 int g2;
   };
Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -227,3 +227,23 @@
 .a = 1, // reorder-error {{field 'b' will be initialized after field 'a'}}
 };
 }
+
+namespace GH63759 {
+struct C {
+  int y = 1;
+  union {
+int a;
+short b;
+  };
+  int x = 1;
+};
+
+void foo() {
+  C c1 = {.x = 3, .a = 1}; // reorder-error-re {{ISO C++ requires field designators to be specified in declaration order; field 'x' will be initialized after field 'GH63759::C::(anonymous union at {{.*}})'}}
+   // reorder-note@-1 {{previous initialization for field 'x' is here}}
+
+  C c2 = {.a = 3, .y = 1}; // reorder-error-re {{ISO C++ requires field designators to be specified in declaration order; field 'GH63759::C::(anonymous union at {{.*}})' will be initialized after field 'y'}}
+   // reorder-note-re@-1 {{previous initialization for field 'GH63759::C::(anonymous union at {{.*}})' is here}}
+   //
+}
+}
Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -136,7 +136,7 @@
 
   template struct Test2 

[PATCH] D158671: [NFC][Clang] Fix static analyzer concerns

2023-08-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:610-612
   if (isa(Method)) {
 Name = Method->getNameAsString();
+if (cast(Method)->isExplicit())

Maybe we can just do this, so we don't `isa` two times.



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

https://reviews.llvm.org/D158671

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


[PATCH] D158615: [clang] Emit an error if variable ends up with incomplete array type

2023-08-23 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:13460
+  // initializer.
+  Diag(VDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
+  << VDeclType;

Not sure about the error message though, maybe it makes sense to add a message 
similar to `err_new_array_size_unknown_from_init` .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158615

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


[PATCH] D158615: [clang] Emit an error if variable ends up with incomplete array type

2023-08-23 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This adds an error if variable with incomplete type has initializer with
incomplete type, so it is not possible to deduce array size from
initializer.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158615

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/gh37257.cpp


Index: clang/test/SemaCXX/gh37257.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/gh37257.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template
+T&& create();
+
+template
+void test() {
+  T t(create()...); // expected-error{{variable has incomplete type 
'int[]'}}
+  (void) t;
+}
+
+struct A;
+
+int main() {
+  test(); // expected-note {{in instantiation of function template 
specialization 'test' requested here}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13449,6 +13449,21 @@
 IsParenListInit = !InitSeq.steps().empty() &&
   InitSeq.step_begin()->Kind ==
   InitializationSequence::SK_ParenthesizedListInit;
+QualType VDeclType = VDecl->getType();
+if (!VDeclType->isDependentType() &&
+Context.getAsIncompleteArrayType(VDeclType)) {
+  if (Init && !Init->getType().isNull() &&
+  !Init->getType()->isDependentType()) {
+if (Context.getAsIncompleteArrayType(Init->getType())) {
+  // Bail out if it is not possible to deduce array size from the
+  // initializer.
+  Diag(VDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
+  << VDeclType;
+  VDecl->setInvalidDecl();
+  return;
+}
+  }
+}
   }
 
   // Check for self-references within variable initializers.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -163,6 +163,9 @@
   ``await_suspend`` could be misoptimized, including accesses to the awaiter
   object itself.
   (`#56301 `_)
+- Clang now emits an error if it is not possible to deduce array size for a
+  variable with incomplete array type.
+  (`#37257 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/gh37257.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/gh37257.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template
+T&& create();
+
+template
+void test() {
+  T t(create()...); // expected-error{{variable has incomplete type 'int[]'}}
+  (void) t;
+}
+
+struct A;
+
+int main() {
+  test(); // expected-note {{in instantiation of function template specialization 'test' requested here}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13449,6 +13449,21 @@
 IsParenListInit = !InitSeq.steps().empty() &&
   InitSeq.step_begin()->Kind ==
   InitializationSequence::SK_ParenthesizedListInit;
+QualType VDeclType = VDecl->getType();
+if (!VDeclType->isDependentType() &&
+Context.getAsIncompleteArrayType(VDeclType)) {
+  if (Init && !Init->getType().isNull() &&
+  !Init->getType()->isDependentType()) {
+if (Context.getAsIncompleteArrayType(Init->getType())) {
+  // Bail out if it is not possible to deduce array size from the
+  // initializer.
+  Diag(VDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
+  << VDeclType;
+  VDecl->setInvalidDecl();
+  return;
+}
+  }
+}
   }
 
   // Check for self-references within variable initializers.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -163,6 +163,9 @@
   ``await_suspend`` could be misoptimized, including accesses to the awaiter
   object itself.
   (`#56301 `_)
+- Clang now emits an error if it is not possible to deduce array size for a
+  variable with incomplete array type.
+  (`#37257 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D158526: [clang] Properly print unnamed members in diagnostics

2023-08-23 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/include/clang/AST/Decl.h:3186
+
+  void printName(raw_ostream , const PrintingPolicy ) const override;
 };

shafik wrote:
> So it looks like w/o this we would end up using `NamedDecl::printName(...)` 
> is that right?
Right.



Comment at: clang/test/AST/ast-dump-APValue-anon-union.cpp:43
   // CHECK:  | `-VarDecl {{.*}}  col:{{.*}} u0b 'const 
U0':'const U0' constexpr listinit
-  // CHECK-NEXT:  |   |-value: Union . Union .f Float 3.141500e+00
+  // CHECK-NEXT:  |   |-value: Union .U0::(anonymous union at {{.*}}) Union .f 
Float 3.141500e+00
 

shafik wrote:
> I am curious what the rest of the diagnostic message from `anonymous union 
> at...` says.
It points to the source location of anonymous member definition, I'm seeing 
"/absolute/path/to/file/ast-dump-APValue-anon-union.cpp::20:3"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158526

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


[PATCH] D158526: [clang] Properly print unnamed members in diagnostics

2023-08-22 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Use member's type when printing.
This also fixes a bug in warning diagnostic for out of order
initialization with designated initializers so it points to a valid
source location when an anonymous member is being initialized.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158526

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/AST/ast-dump-APValue-anon-union.cpp
  clang/test/CXX/special/class.dtor/p5-0x.cpp
  clang/test/Sema/transparent-union.c
  clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
  clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
  clang/test/SemaObjCXX/arc-0x.mm

Index: clang/test/SemaObjCXX/arc-0x.mm
===
--- clang/test/SemaObjCXX/arc-0x.mm
+++ clang/test/SemaObjCXX/arc-0x.mm
@@ -161,7 +161,7 @@
 
   struct S1 {
 union {
-  union { // expected-note {{copy constructor of 'S1' is implicitly deleted because field '' has a deleted copy constructor}} expected-note {{copy assignment operator of 'S1' is implicitly deleted because field '' has a deleted copy assignment operator}} expected-note 4 {{'S1' is implicitly deleted because field '' has a deleted}}
+  union { // expected-note-re {{copy constructor of 'S1' is implicitly deleted because field 'test_union::S1::(anonymous union at {{.*}})' has a deleted copy constructor}} expected-note-re {{copy assignment operator of 'S1' is implicitly deleted because field 'test_union::S1::(anonymous union at {{.*}})' has a deleted copy assignment operator}} expected-note-re 4 {{'S1' is implicitly deleted because field 'test_union::S1::(anonymous union at {{.*}})' has a deleted}}
 id f0; // expected-note-re 2 .*}} of '(anonymous union at {{.*}}' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 char f1;
   };
@@ -172,7 +172,7 @@
   struct S2 {
 union {
   // FIXME: the note should say 'f0' is causing the special functions to be deleted.
-  struct { // expected-note 6 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
+  struct { // expected-note-re 6 {{'S2' is implicitly deleted because variant field 'test_union::S2::(anonymous struct at {{.*}})' has a non-trivial}}
 id f0;
 int f1;
   };
@@ -194,8 +194,8 @@
   };
 
   static union { // expected-error {{call to implicitly-deleted default constructor of}}
-union { // expected-note-re {{default constructor of '(unnamed union at {{.*}}' is implicitly deleted because field '' has a deleted default constructor}}
-  union { // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because field '' has a deleted default constructor}}
+union { // expected-note-re {{default constructor of '(unnamed union at {{.*}}' is implicitly deleted because field 'test_union::(anonymous union at {{.*}})' has a deleted default constructor}}
+  union { // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because field 'test_union::(anonymous union at {{.*}})' has a deleted default constructor}}
 __weak id g1; // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because variant field 'g1' is an ObjC pointer}}
 int g2;
   };
Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -227,3 +227,23 @@
 .a = 1, // reorder-error {{field 'b' will be initialized after field 'a'}}
 };
 }
+
+namespace GH63759 {
+struct C {
+  int y = 1;
+  union {
+int a;
+short b;
+  };
+  int x = 1;
+};
+
+void foo() {
+  C c1 = {.x = 3, .a = 1}; // reorder-error-re {{ISO C++ requires field designators to be specified in declaration order; field 'x' will be initialized after field 'GH63759::C::(anonymous union at {{.*}})'}}
+   // reorder-note@-1 {{previous initialization for field 'x' is here}}
+
+  C c2 = {.a = 3, .y = 1}; // reorder-error-re {{ISO C++ requires field designators to be specified in declaration order; field 'GH63759::C::(anonymous union at {{.*}})' will be initialized after field 'y'}}
+   // reorder-note-re@-1 {{previous initialization for field 'GH63759::C::(anonymous union at {{.*}})' is here}}
+   //
+}
+}
Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ 

[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-21 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91088978d712: [clang] Report missing designated initializers 
in C++ (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp

Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -4,6 +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
 
 
 namespace class_with_ctor {
@@ -49,15 +50,17 @@
 A a4 = {
   .x = 1, // override-note {{previous}}
   .x = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'y' initializer}}
 A a5 = {
   .y = 1, // override-note {{previous}}
   .y = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'x' initializer}}
 B b2 = {.a = 1}; // pedantic-error {{brace elision for designated initializer is a C99 extension}}
+ // wmissing-warning@-1 {{missing field 'y' initializer}}
 B b3 = {.a = 1, 2}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}}
 B b4 = {.a = 1, 2, 3}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}} expected-error {{excess elements}}
 B b5 = {.a = nullptr}; // expected-error {{cannot initialize}}
+   // wmissing-warning@-1 {{missing field 'y' initializer}}
 struct C { int :0, x, :0, y, :0; };
 C c = {
   .x = 1, // override-note {{previous}}
@@ -67,6 +70,13 @@
   .x = 1, // reorder-error {{declaration order}} override-error {{overrides prior initialization}} override-note {{previous}}
   .x = 1, // override-error {{overrides prior initialization}}
 };
+
+struct Foo { int a, b; };
+
+struct Foo foo0 = { 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo1 = { .a = 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo2 = { .b = 1 }; // wmissing-warning {{missing field 'a' initializer}}
+
 }
 
 namespace base_class {
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2252,6 +2252,8 @@
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
 
+  llvm::SmallPtrSet InitializedFields;
+
   while (Index < IList->getNumInits()) {
 Expr *Init = IList->getInit(Index);
 SourceLocation InitLoc = Init->getBeginLoc();
@@ -2267,20 +2269,23 @@
 
   // Handle this designated initializer. Field will be updated to
   // the next field that we'll be initializing.
-  if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
- DeclType, , nullptr, Index,
- StructuredList, StructuredIndex,
- true, TopLevelObject))
+  bool DesignatedInitFailed = CheckDesignatedInitializer(
+  Entity, IList, DIE, 0, DeclType, , nullptr, Index,
+  StructuredList, StructuredIndex, true, TopLevelObject);
+  if (DesignatedInitFailed)
 hadError = true;
-  else if (!VerifyOnly) {
-// Find the field named by the designated initializer.
-RecordDecl::field_iterator F = RD->field_begin();
-while (std::next(F) != Field)
-  ++F;
-QualType ET = SemaRef.Context.getBaseElementType(F->getType());
-if (checkDestructorReference(ET, InitLoc, SemaRef)) {
-  hadError = true;
-  return;
+
+  // Find the field named by the designated initializer.
+  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)) {
+hadError 

[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-21 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

The failure is unrelated, since the patch doesn't touch modules and I've seen 
the test failing for other patches as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

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


[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-21 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 551924.
Fznamznon added a comment.

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp

Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -4,6 +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
 
 
 namespace class_with_ctor {
@@ -49,15 +50,17 @@
 A a4 = {
   .x = 1, // override-note {{previous}}
   .x = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'y' initializer}}
 A a5 = {
   .y = 1, // override-note {{previous}}
   .y = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'x' initializer}}
 B b2 = {.a = 1}; // pedantic-error {{brace elision for designated initializer is a C99 extension}}
+ // wmissing-warning@-1 {{missing field 'y' initializer}}
 B b3 = {.a = 1, 2}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}}
 B b4 = {.a = 1, 2, 3}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}} expected-error {{excess elements}}
 B b5 = {.a = nullptr}; // expected-error {{cannot initialize}}
+   // wmissing-warning@-1 {{missing field 'y' initializer}}
 struct C { int :0, x, :0, y, :0; };
 C c = {
   .x = 1, // override-note {{previous}}
@@ -67,6 +70,13 @@
   .x = 1, // reorder-error {{declaration order}} override-error {{overrides prior initialization}} override-note {{previous}}
   .x = 1, // override-error {{overrides prior initialization}}
 };
+
+struct Foo { int a, b; };
+
+struct Foo foo0 = { 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo1 = { .a = 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo2 = { .b = 1 }; // wmissing-warning {{missing field 'a' initializer}}
+
 }
 
 namespace base_class {
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2252,6 +2252,8 @@
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
 
+  llvm::SmallPtrSet InitializedFields;
+
   while (Index < IList->getNumInits()) {
 Expr *Init = IList->getInit(Index);
 SourceLocation InitLoc = Init->getBeginLoc();
@@ -2267,20 +2269,23 @@
 
   // Handle this designated initializer. Field will be updated to
   // the next field that we'll be initializing.
-  if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
- DeclType, , nullptr, Index,
- StructuredList, StructuredIndex,
- true, TopLevelObject))
+  bool DesignatedInitFailed = CheckDesignatedInitializer(
+  Entity, IList, DIE, 0, DeclType, , nullptr, Index,
+  StructuredList, StructuredIndex, true, TopLevelObject);
+  if (DesignatedInitFailed)
 hadError = true;
-  else if (!VerifyOnly) {
-// Find the field named by the designated initializer.
-RecordDecl::field_iterator F = RD->field_begin();
-while (std::next(F) != Field)
-  ++F;
-QualType ET = SemaRef.Context.getBaseElementType(F->getType());
-if (checkDestructorReference(ET, InitLoc, SemaRef)) {
-  hadError = true;
-  return;
+
+  // Find the field named by the designated initializer.
+  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)) {
+hadError = true;
+return;
+  }
 }
   }
 
@@ -2288,7 +2293,8 @@
 
   // Disable check for missing fields 

[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-18 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 551460.
Fznamznon added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp

Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -4,6 +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
 
 
 namespace class_with_ctor {
@@ -49,15 +50,17 @@
 A a4 = {
   .x = 1, // override-note {{previous}}
   .x = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'y' initializer}}
 A a5 = {
   .y = 1, // override-note {{previous}}
   .y = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'x' initializer}}
 B b2 = {.a = 1}; // pedantic-error {{brace elision for designated initializer is a C99 extension}}
+ // wmissing-warning@-1 {{missing field 'y' initializer}}
 B b3 = {.a = 1, 2}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}}
 B b4 = {.a = 1, 2, 3}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}} expected-error {{excess elements}}
 B b5 = {.a = nullptr}; // expected-error {{cannot initialize}}
+   // wmissing-warning@-1 {{missing field 'y' initializer}}
 struct C { int :0, x, :0, y, :0; };
 C c = {
   .x = 1, // override-note {{previous}}
@@ -67,6 +70,13 @@
   .x = 1, // reorder-error {{declaration order}} override-error {{overrides prior initialization}} override-note {{previous}}
   .x = 1, // override-error {{overrides prior initialization}}
 };
+
+struct Foo { int a, b; };
+
+struct Foo foo0 = { 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo1 = { .a = 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo2 = { .b = 1 }; // wmissing-warning {{missing field 'a' initializer}}
+
 }
 
 namespace base_class {
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2252,6 +2252,8 @@
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
 
+  llvm::SmallPtrSet InitializedFields;
+
   while (Index < IList->getNumInits()) {
 Expr *Init = IList->getInit(Index);
 SourceLocation InitLoc = Init->getBeginLoc();
@@ -2267,20 +2269,23 @@
 
   // Handle this designated initializer. Field will be updated to
   // the next field that we'll be initializing.
-  if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
- DeclType, , nullptr, Index,
- StructuredList, StructuredIndex,
- true, TopLevelObject))
+  bool DesignatedInitFailed = CheckDesignatedInitializer(
+  Entity, IList, DIE, 0, DeclType, , nullptr, Index,
+  StructuredList, StructuredIndex, true, TopLevelObject);
+  if (DesignatedInitFailed)
 hadError = true;
-  else if (!VerifyOnly) {
-// Find the field named by the designated initializer.
-RecordDecl::field_iterator F = RD->field_begin();
-while (std::next(F) != Field)
-  ++F;
-QualType ET = SemaRef.Context.getBaseElementType(F->getType());
-if (checkDestructorReference(ET, InitLoc, SemaRef)) {
-  hadError = true;
-  return;
+
+  // Find the field named by the designated initializer.
+  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)) {
+hadError = true;
+return;
+  }
 }
   }
 
@@ -2288,7 +2293,8 @@
 
   // Disable check for missing fields when designators are used.
 

[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-17 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

In D157879#4594790 , @tbaeder wrote:

> Tangentially related: Now that we have this `InitializedFields` set, would it 
> be easy to add a warning for double-initialization of fields (that would also 
> trigger in C)?

Isn't a warning like this already in place - https://godbolt.org/z/E1dGsY3ze ? 
Or you meant something else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

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


[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-17 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon marked 3 inline comments as done.
Fznamznon added a comment.

> Thank you for working on this! The changes should come with a release note.

Thanks for feedback, I added a release note.

> Can we silence the diagnostic in these cases?

And this is done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

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


[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-17 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 551051.
Fznamznon added a comment.

Add a release note, apply feedback:

- Do not report invalid initializers as missing
- Fix wrong warning if record has bitfields


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp

Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -4,6 +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
 
 
 namespace class_with_ctor {
@@ -49,15 +50,17 @@
 A a4 = {
   .x = 1, // override-note {{previous}}
   .x = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'y' initializer}}
 A a5 = {
   .y = 1, // override-note {{previous}}
   .y = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'x' initializer}}
 B b2 = {.a = 1}; // pedantic-error {{brace elision for designated initializer is a C99 extension}}
+ // wmissing-warning@-1 {{missing field 'y' initializer}}
 B b3 = {.a = 1, 2}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}}
 B b4 = {.a = 1, 2, 3}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}} expected-error {{excess elements}}
 B b5 = {.a = nullptr}; // expected-error {{cannot initialize}}
+   // wmissing-warning@-1 {{missing field 'y' initializer}}
 struct C { int :0, x, :0, y, :0; };
 C c = {
   .x = 1, // override-note {{previous}}
@@ -67,6 +70,13 @@
   .x = 1, // reorder-error {{declaration order}} override-error {{overrides prior initialization}} override-note {{previous}}
   .x = 1, // override-error {{overrides prior initialization}}
 };
+
+struct Foo { int a, b; };
+
+struct Foo foo0 = { 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo1 = { .a = 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo2 = { .b = 1 }; // wmissing-warning {{missing field 'a' initializer}}
+
 }
 
 namespace base_class {
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2252,6 +2252,8 @@
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
 
+  llvm::SmallPtrSet InitializedFields;
+
   while (Index < IList->getNumInits()) {
 Expr *Init = IList->getInit(Index);
 SourceLocation InitLoc = Init->getBeginLoc();
@@ -2267,20 +2269,23 @@
 
   // Handle this designated initializer. Field will be updated to
   // the next field that we'll be initializing.
-  if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
- DeclType, , nullptr, Index,
- StructuredList, StructuredIndex,
- true, TopLevelObject))
+  bool DesignatedInitFailed = CheckDesignatedInitializer(
+  Entity, IList, DIE, 0, DeclType, , nullptr, Index,
+  StructuredList, StructuredIndex, true, TopLevelObject);
+  if (DesignatedInitFailed)
 hadError = true;
-  else if (!VerifyOnly) {
-// Find the field named by the designated initializer.
-RecordDecl::field_iterator F = RD->field_begin();
-while (std::next(F) != Field)
-  ++F;
-QualType ET = SemaRef.Context.getBaseElementType(F->getType());
-if (checkDestructorReference(ET, InitLoc, SemaRef)) {
-  hadError = true;
-  return;
+
+  // Find the field named by the designated initializer.
+  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)) {
+hadError = true;
+return;
+   

[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-14 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Prior to this change clang didn't emit missing-field-initializers
warning for designated initializers. The comments say that it is done to
match gcc behavior. However, gcc behaves so only for C. For C++ warnings
are emitted.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157879

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp

Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -4,6 +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
 
 
 namespace class_with_ctor {
@@ -49,15 +50,18 @@
 A a4 = {
   .x = 1, // override-note {{previous}}
   .x = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'y' initializer}}
 A a5 = {
   .y = 1, // override-note {{previous}}
   .y = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'x' initializer}}
 B b2 = {.a = 1}; // pedantic-error {{brace elision for designated initializer is a C99 extension}}
+ // wmissing-warning@-1 {{missing field 'y' initializer}}
 B b3 = {.a = 1, 2}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}}
 B b4 = {.a = 1, 2, 3}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}} expected-error {{excess elements}}
 B b5 = {.a = nullptr}; // expected-error {{cannot initialize}}
+   // wmissing-warning@-1 {{missing field 'y' initializer}}
+   // wmissing-warning@-2 {{missing field 'a' initializer}}
 struct C { int :0, x, :0, y, :0; };
 C c = {
   .x = 1, // override-note {{previous}}
@@ -66,7 +70,14 @@
   .y = 1, // override-error {{overrides prior initialization}} // reorder-note {{previous initialization for field 'y' is here}}
   .x = 1, // reorder-error {{declaration order}} override-error {{overrides prior initialization}} override-note {{previous}}
   .x = 1, // override-error {{overrides prior initialization}}
-};
+}; //wmissing-warning {{missing field 'x' initializer}}
+
+struct Foo { int a, b; };
+
+struct Foo foo0 = { 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo1 = { .a = 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo2 = { .b = 1 }; // wmissing-warning {{missing field 'a' initializer}}
+
 }
 
 namespace base_class {
@@ -215,5 +226,5 @@
 .c = 1, // reorder-error {{field 'd' will be initialized after field 'c'}} // reorder-note {{previous initialization for field 'c' is here}}
 .b = 1, // reorder-error {{field 'c' will be initialized after field 'b'}} // reorder-note {{previous initialization for field 'b' is here}}
 .a = 1, // reorder-error {{field 'b' will be initialized after field 'a'}}
-};
+}; // wmissing-warning {{missing field 'a' initializer}}
 }
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2252,6 +2252,8 @@
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
 
+  llvm::SmallPtrSet InitializedFields;
+
   while (Index < IList->getNumInits()) {
 Expr *Init = IList->getInit(Index);
 SourceLocation InitLoc = Init->getBeginLoc();
@@ -2277,6 +2279,7 @@
 RecordDecl::field_iterator F = RD->field_begin();
 while (std::next(F) != Field)
   ++F;
+InitializedFields.insert(*F);
 QualType ET = SemaRef.Context.getBaseElementType(F->getType());
 if (checkDestructorReference(ET, InitLoc, SemaRef)) {
   hadError = true;
@@ -2288,7 +2291,8 @@
 
   // Disable check for missing fields when designators are used.
   // This matches gcc behaviour.
-  CheckForMissingFields = false;
+  if (!SemaRef.getLangOpts().CPlusPlus)
+CheckForMissingFields = false;
   continue;
 }
 
@@ -2367,6 +2371,7 @@
 

[PATCH] D156993: [clang] Error on substitution failure within lambda body inside a requires-expression

2023-08-08 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG38cf47f037b2: [clang] Error on substitution failure within 
lambda body inside a requires… (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156993

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15839,7 +15839,7 @@
 https://cplusplus.github.io/CWG/issues/2672.html;>2672
 open
 Lambda body SFINAE is still required, contrary to intent and note
-Not resolved
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2673.html;>2673
Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -155,17 +155,24 @@
 
 template 
 concept lambda_works = requires {
-[]() { T::foo(); };
+[]() { T::foo(); }; // expected-error{{type 'int' cannot be used prior to '::'}}
+// expected-note@-1{{while substituting into a lambda expression here}}
+// expected-note@-2{{in instantiation of requirement here}}
+// expected-note@-4{{while substituting template arguments into constraint expression here}}
 };
 
-static_assert(!lambda_works);
+static_assert(!lambda_works); // expected-note {{while checking the satisfaction of concept 'lambda_works' requested here}}
 static_assert(lambda_works);
 
 template 
-int* func(T) requires requires { []() { T::foo(); }; };
+int* func(T) requires requires { []() { T::foo(); }; }; // expected-error{{type 'int' cannot be used prior to '::'}}
+// expected-note@-1{{while substituting into a lambda expression here}}
+// expected-note@-2{{in instantiation of requirement here}}
+// expected-note@-3{{while substituting template arguments into constraint expression here}}
 double* func(...);
 
-static_assert(__is_same(decltype(func(0)), double*));
+static_assert(__is_same(decltype(func(0)), double*)); // expected-note {{while checking constraint satisfaction for template 'func' required here}}
+  // expected-note@-1 {{in instantiation of function template specialization 'lambda_in_constraints::func'}}
 static_assert(__is_same(decltype(func(WithFoo())), int*));
 
 template 
Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -150,3 +150,24 @@
 
 J j = { "ghi" };  // expected-error {{no viable constructor or deduction guide}}
 }
+
+namespace dr2672 { // dr2672: 18 open
+template 
+void f(T) requires requires { []() { T::invalid; } (); }; // expected-error{{type 'int' cannot be used prior to '::'}}
+  // expected-note@-1{{while substituting into a lambda expression here}}
+  // expected-note@-2{{in instantiation of requirement here}}
+  // expected-note@-3{{while substituting template arguments into constraint expression here}}
+void f(...);
+
+template 
+void bar(T) requires requires {
+   decltype([]() -> T {})::foo();
+};
+void bar(...);
+
+void m() {
+  f(0); // expected-note {{while checking constraint satisfaction for template 'f' required here}}
+// expected-note@-1 {{in instantiation of function template specialization}}
+  bar(0);
+}
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1074,7 +1074,6 @@
   if (InNonInstantiationSFINAEContext)
 return std::optional(nullptr);
 
-  bool SawLambdaSubstitution = false;
   for (SmallVectorImpl::const_reverse_iterator
  Active = CodeSynthesisContexts.rbegin(),
  ActiveEnd = CodeSynthesisContexts.rend();
@@ -1101,10 +1100,8 @@
   // A lambda-expression appearing in a function type or a template
   // parameter is not considered part of the immediate context for the
   // purposes of template argument deduction.
-
-  // We need to check parents.
-  SawLambdaSubstitution = true;
-  break;
+  // CWG2672: A lambda-expression body is never in the immediate context.
+  return 

[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

2023-08-07 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/Sema/offsetof.c:79
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // 
expected-error{{no member named 'X2'}}
+

It probably makes sense to also add a test with static member of a class, like 
Aaron mentioned in GitHub - 
https://github.com/llvm/llvm-project/issues/64154#issuecomment-1653468938 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157201

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


[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-08-04 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf91092c449d: [clang] Do not crash on use of a variadic 
overloaded operator (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156244

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/overloaded-operator-decl.cpp

Index: clang/test/SemaCXX/overloaded-operator-decl.cpp
===
--- clang/test/SemaCXX/overloaded-operator-decl.cpp
+++ clang/test/SemaCXX/overloaded-operator-decl.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 struct X { 
   X();
   X(int); 
@@ -58,3 +59,67 @@
 A()(i);
   }
 }
+
+namespace GH42535 {
+class E {
+  E& operator=(const E& rhs, ...); // expected-error{{overloaded 'operator=' cannot be variadic}}
+  E& operator+=(const E& rhs, ...); // expected-error{{overloaded 'operator+=' cannot be variadic}}
+
+};
+void operator+(E, ...) {} // expected-error{{overloaded 'operator+' cannot be variadic}}
+void operator-(E, ...) {} // expected-error{{overloaded 'operator-' cannot be variadic}}
+void operator*(E, ...) {} // expected-error{{overloaded 'operator*' cannot be variadic}}
+void operator/(E, ...) {} // expected-error{{overloaded 'operator/' must be a binary operator}}
+void operator/(E, E, ...) {} // expected-error{{overloaded 'operator/' cannot be variadic}}
+void operator%(E, ...) {} // expected-error{{overloaded 'operator%' must be a binary operator}}
+void operator%(E, E, ...) {} // expected-error{{overloaded 'operator%' cannot be variadic}}
+E& operator++(E&, ...); // expected-error{{overloaded 'operator++' cannot be variadic}}
+E& operator--(E&, ...); // expected-error{{overloaded 'operator--' cannot be variadic}}
+bool operator<(const E& lhs, ...); // expected-error{{overloaded 'operator<' must be a binary operator}}
+bool operator<(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator>(const E& lhs, ...); // expected-error{{overloaded 'operator>' must be a binary operator}}
+bool operator>(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator>=(const E& lhs, ...); // expected-error{{overloaded 'operator>=' must be a binary operator}}
+bool operator>=(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator<=(const E& lhs, ...); // expected-error{{overloaded 'operator<=' must be a binary operator}}
+bool operator<=(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator==(const E& lhs, ...); // expected-error{{overloaded 'operator==' must be a binary operator}}
+bool operator==(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator!=(const E& lhs, ...); // expected-error{{overloaded 'operator!=' must be a binary operator}}
+bool operator!=(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator&&(const E& lhs, ...); // expected-error{{overloaded 'operator&&' must be a binary operator}}
+bool operator&&(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator||(const E& lhs, ...); // expected-error{{overloaded 'operator||' must be a binary operator}}
+bool operator||(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator>>(const E& lhs, ...); // expected-error{{overloaded 'operator>>' must be a binary operator}}
+bool operator>>(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator&(const E& lhs, ...); // expected-error{{cannot be variadic}}
+#if __cplusplus >= 202002L
+auto operator<=>(const E& lhs, ...);  // expected-error{{overloaded 'operator<=>' must be a binary operator}}
+#endif
+void d() {
+  E() + E();
+  E() - E();
+  E() * E();
+  E() / E();
+  E() % E();
+  ++E(); // expected-error{{cannot increment value of type 'E'}}
+  --E(); // expected-error{{cannot decrement value of type 'E'}}
+  E() < E();
+  E() > E();
+  E() <= E();
+  E() >= E();
+  E() == E();
+  E() != E();
+#if __cplusplus >= 202002L
+  E() <=> E();
+#endif
+  E e;
+  E e1 = e;
+  e += e1;
+  E() && E();
+  E() || E();
+  E() & E();
+  E() >> E();
+}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9850,7 +9850,7 @@
 }
 
 static bool haveSameParameterTypes(ASTContext , const FunctionDecl *F1,
-   const FunctionDecl *F2, unsigned NumParams) {
+   const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
 
@@ -9863,8 +9863,14 @@
 return 

[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-08-04 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Hmm, clang-format reports failure, but applying git-clang-format to the commit 
doesn't give me anything. It seems the whole SemaOverload.cpp file has broken 
formatting, maybe that is the reason for the failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156244

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


[PATCH] D156975: [NFC][clang] Fix static analyzer concerns

2023-08-03 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG25d6f9ddc191: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156975

Files:
  clang/include/clang/AST/APValue.h


Index: clang/include/clang/AST/APValue.h
===
--- clang/include/clang/AST/APValue.h
+++ clang/include/clang/AST/APValue.h
@@ -270,12 +270,16 @@
 APValue *Elts = nullptr;
 unsigned NumElts = 0;
 Vec() = default;
+Vec(const Vec &) = delete;
+Vec =(const Vec &) = delete;
 ~Vec() { delete[] Elts; }
   };
   struct Arr {
 APValue *Elts;
 unsigned NumElts, ArrSize;
 Arr(unsigned NumElts, unsigned ArrSize);
+Arr(const Arr &) = delete;
+Arr =(const Arr &) = delete;
 ~Arr();
   };
   struct StructData {
@@ -283,12 +287,16 @@
 unsigned NumBases;
 unsigned NumFields;
 StructData(unsigned NumBases, unsigned NumFields);
+StructData(const StructData &) = delete;
+StructData =(const StructData &) = delete;
 ~StructData();
   };
   struct UnionData {
 const FieldDecl *Field;
 APValue *Value;
 UnionData();
+UnionData(const UnionData &) = delete;
+UnionData =(const UnionData &) = delete;
 ~UnionData();
   };
   struct AddrLabelDiffData {


Index: clang/include/clang/AST/APValue.h
===
--- clang/include/clang/AST/APValue.h
+++ clang/include/clang/AST/APValue.h
@@ -270,12 +270,16 @@
 APValue *Elts = nullptr;
 unsigned NumElts = 0;
 Vec() = default;
+Vec(const Vec &) = delete;
+Vec =(const Vec &) = delete;
 ~Vec() { delete[] Elts; }
   };
   struct Arr {
 APValue *Elts;
 unsigned NumElts, ArrSize;
 Arr(unsigned NumElts, unsigned ArrSize);
+Arr(const Arr &) = delete;
+Arr =(const Arr &) = delete;
 ~Arr();
   };
   struct StructData {
@@ -283,12 +287,16 @@
 unsigned NumBases;
 unsigned NumFields;
 StructData(unsigned NumBases, unsigned NumFields);
+StructData(const StructData &) = delete;
+StructData =(const StructData &) = delete;
 ~StructData();
   };
   struct UnionData {
 const FieldDecl *Field;
 APValue *Value;
 UnionData();
+UnionData(const UnionData &) = delete;
+UnionData =(const UnionData &) = delete;
 ~UnionData();
   };
   struct AddrLabelDiffData {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156896: [NFC][clang] Fix static analyzer concerns

2023-08-03 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf887cb10acc9: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156896

Files:
  clang/include/clang/Tooling/Tooling.h


Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -267,6 +267,9 @@
 
   ~ToolInvocation();
 
+  ToolInvocation(const ToolInvocation &) = delete;
+  ToolInvocation =(const ToolInvocation &) = delete;
+
   /// Set a \c DiagnosticConsumer to use during driver command-line parsing and
   /// the action invocation itself.
   void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer) {


Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -267,6 +267,9 @@
 
   ~ToolInvocation();
 
+  ToolInvocation(const ToolInvocation &) = delete;
+  ToolInvocation =(const ToolInvocation &) = delete;
+
   /// Set a \c DiagnosticConsumer to use during driver command-line parsing and
   /// the action invocation itself.
   void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156993: [clang] Error on substitution failure within lambda body inside a requires-expression

2023-08-03 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> Can you add a test in dr26xx ?

Sure, done. Hope I updated cxx_dr_status in the right way. The script wasn't 
happy until I added "open" to the test comment.

> maybe we need a test like Because I think the intent is for that to work

Seems to be working if I got it right.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156993

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


[PATCH] D156993: [clang] Error on substitution failure within lambda body inside a requires-expression

2023-08-03 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 546837.
Fznamznon added a comment.

Rebase, apply feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156993

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15839,7 +15839,7 @@
 https://cplusplus.github.io/CWG/issues/2672.html;>2672
 open
 Lambda body SFINAE is still required, contrary to intent and note
-Not resolved
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2673.html;>2673
Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -155,17 +155,24 @@
 
 template 
 concept lambda_works = requires {
-[]() { T::foo(); };
+[]() { T::foo(); }; // expected-error{{type 'int' cannot be used prior to '::'}}
+// expected-note@-1{{while substituting into a lambda expression here}}
+// expected-note@-2{{in instantiation of requirement here}}
+// expected-note@-4{{while substituting template arguments into constraint expression here}}
 };
 
-static_assert(!lambda_works);
+static_assert(!lambda_works); // expected-note {{while checking the satisfaction of concept 'lambda_works' requested here}}
 static_assert(lambda_works);
 
 template 
-int* func(T) requires requires { []() { T::foo(); }; };
+int* func(T) requires requires { []() { T::foo(); }; }; // expected-error{{type 'int' cannot be used prior to '::'}}
+// expected-note@-1{{while substituting into a lambda expression here}}
+// expected-note@-2{{in instantiation of requirement here}}
+// expected-note@-3{{while substituting template arguments into constraint expression here}}
 double* func(...);
 
-static_assert(__is_same(decltype(func(0)), double*));
+static_assert(__is_same(decltype(func(0)), double*)); // expected-note {{while checking constraint satisfaction for template 'func' required here}}
+  // expected-note@-1 {{in instantiation of function template specialization 'lambda_in_constraints::func'}}
 static_assert(__is_same(decltype(func(WithFoo())), int*));
 
 template 
Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -150,3 +150,24 @@
 
 J j = { "ghi" };  // expected-error {{no viable constructor or deduction guide}}
 }
+
+namespace dr2672 { // dr2672: 18 open
+template 
+void f(T) requires requires { []() { T::invalid; } (); }; // expected-error{{type 'int' cannot be used prior to '::'}}
+  // expected-note@-1{{while substituting into a lambda expression here}}
+  // expected-note@-2{{in instantiation of requirement here}}
+  // expected-note@-3{{while substituting template arguments into constraint expression here}}
+void f(...);
+
+template 
+void bar(T) requires requires {
+   decltype([]() -> T {})::foo();
+};
+void bar(...);
+
+void m() {
+  f(0); // expected-note {{while checking constraint satisfaction for template 'f' required here}}
+// expected-note@-1 {{in instantiation of function template specialization}}
+  bar(0);
+}
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1074,7 +1074,6 @@
   if (InNonInstantiationSFINAEContext)
 return std::optional(nullptr);
 
-  bool SawLambdaSubstitution = false;
   for (SmallVectorImpl::const_reverse_iterator
  Active = CodeSynthesisContexts.rbegin(),
  ActiveEnd = CodeSynthesisContexts.rend();
@@ -1101,10 +1100,8 @@
   // A lambda-expression appearing in a function type or a template
   // parameter is not considered part of the immediate context for the
   // purposes of template argument deduction.
-
-  // We need to check parents.
-  SawLambdaSubstitution = true;
-  break;
+  // CWG2672: A lambda-expression body is never in the immediate context.
+  return std::nullopt;
 
 case CodeSynthesisContext::DefaultTemplateArgumentInstantiation:
 case 

[PATCH] D156993: [clang] Error on substitution failure within lambda body inside a requires-expression

2023-08-03 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Per CWG 2672 substitution failure within the body of a lambda inside a
requires-expression should be a hard error.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156993

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp


Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -155,17 +155,24 @@
 
 template 
 concept lambda_works = requires {
-[]() { T::foo(); };
+[]() { T::foo(); }; // expected-error{{type 'int' cannot be used prior to 
'::'}}
+// expected-note@-1{{while substituting into a lambda 
expression here}}
+// expected-note@-2{{in instantiation of requirement 
here}}
+// expected-note@-4{{while substituting template 
arguments into constraint expression here}}
 };
 
-static_assert(!lambda_works);
+static_assert(!lambda_works); // expected-note {{while checking the 
satisfaction of concept 'lambda_works' requested here}}
 static_assert(lambda_works);
 
 template 
-int* func(T) requires requires { []() { T::foo(); }; };
+int* func(T) requires requires { []() { T::foo(); }; }; // 
expected-error{{type 'int' cannot be used prior to '::'}}
+// 
expected-note@-1{{while substituting into a lambda expression here}}
+// 
expected-note@-2{{in instantiation of requirement here}}
+// 
expected-note@-3{{while substituting template arguments into constraint 
expression here}}
 double* func(...);
 
-static_assert(__is_same(decltype(func(0)), double*));
+static_assert(__is_same(decltype(func(0)), double*)); // expected-note {{while 
checking constraint satisfaction for template 'func' required here}}
+  // expected-note@-1 {{in 
instantiation of function template specialization 
'lambda_in_constraints::func'}}
 static_assert(__is_same(decltype(func(WithFoo())), int*));
 
 template 
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1074,7 +1074,6 @@
   if (InNonInstantiationSFINAEContext)
 return std::optional(nullptr);
 
-  bool SawLambdaSubstitution = false;
   for (SmallVectorImpl::const_reverse_iterator
  Active = CodeSynthesisContexts.rbegin(),
  ActiveEnd = CodeSynthesisContexts.rend();
@@ -1101,10 +1100,7 @@
   // A lambda-expression appearing in a function type or a template
   // parameter is not considered part of the immediate context for the
   // purposes of template argument deduction.
-
-  // We need to check parents.
-  SawLambdaSubstitution = true;
-  break;
+  return std::nullopt;
 
 case CodeSynthesisContext::DefaultTemplateArgumentInstantiation:
 case CodeSynthesisContext::PriorTemplateArgumentSubstitution:
@@ -1120,8 +1116,6 @@
   // We're either substituting explicitly-specified template arguments,
   // deduced template arguments. SFINAE applies unless we are in a lambda
   // expression, see [temp.deduct]p9.
-  if (SawLambdaSubstitution)
-return std::nullopt;
   [[fallthrough]];
 case CodeSynthesisContext::ConstraintSubstitution:
 case CodeSynthesisContext::RequirementInstantiation:
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -132,6 +132,10 @@
   (`#35574 _`) and
   (`#27224 _`).
 
+- Clang emits an error on substitution failure within lambda body inside a
+  requires-expression. This fixes:
+  (`#64138 _`).
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.


Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -155,17 +155,24 @@
 
 template 
 concept lambda_works = requires {
-[]() { T::foo(); };
+[]() { T::foo(); }; // expected-error{{type 'int' cannot be used prior to '::'}}
+// expected-note@-1{{while substituting into a lambda 

[PATCH] D156975: [NFC][clang] Fix static analyzer concerns

2023-08-03 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A bunch of classes in APValue free resources in the destructor but don't
have user-written copy c'tor or assignment operator, so copying them using
default ones can cause double free.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156975

Files:
  clang/include/clang/AST/APValue.h


Index: clang/include/clang/AST/APValue.h
===
--- clang/include/clang/AST/APValue.h
+++ clang/include/clang/AST/APValue.h
@@ -270,12 +270,16 @@
 APValue *Elts = nullptr;
 unsigned NumElts = 0;
 Vec() = default;
+Vec(const Vec &) = delete;
+Vec =(const Vec &) = delete;
 ~Vec() { delete[] Elts; }
   };
   struct Arr {
 APValue *Elts;
 unsigned NumElts, ArrSize;
 Arr(unsigned NumElts, unsigned ArrSize);
+Arr(const Arr &) = delete;
+Arr =(const Arr &) = delete;
 ~Arr();
   };
   struct StructData {
@@ -283,12 +287,16 @@
 unsigned NumBases;
 unsigned NumFields;
 StructData(unsigned NumBases, unsigned NumFields);
+StructData(const StructData &) = delete;
+StructData =(const StructData &) = delete;
 ~StructData();
   };
   struct UnionData {
 const FieldDecl *Field;
 APValue *Value;
 UnionData();
+UnionData(const UnionData &) = delete;
+UnionData =(const UnionData &) = delete;
 ~UnionData();
   };
   struct AddrLabelDiffData {


Index: clang/include/clang/AST/APValue.h
===
--- clang/include/clang/AST/APValue.h
+++ clang/include/clang/AST/APValue.h
@@ -270,12 +270,16 @@
 APValue *Elts = nullptr;
 unsigned NumElts = 0;
 Vec() = default;
+Vec(const Vec &) = delete;
+Vec =(const Vec &) = delete;
 ~Vec() { delete[] Elts; }
   };
   struct Arr {
 APValue *Elts;
 unsigned NumElts, ArrSize;
 Arr(unsigned NumElts, unsigned ArrSize);
+Arr(const Arr &) = delete;
+Arr =(const Arr &) = delete;
 ~Arr();
   };
   struct StructData {
@@ -283,12 +287,16 @@
 unsigned NumBases;
 unsigned NumFields;
 StructData(unsigned NumBases, unsigned NumFields);
+StructData(const StructData &) = delete;
+StructData =(const StructData &) = delete;
 ~StructData();
   };
   struct UnionData {
 const FieldDecl *Field;
 APValue *Value;
 UnionData();
+UnionData(const UnionData &) = delete;
+UnionData =(const UnionData &) = delete;
 ~UnionData();
   };
   struct AddrLabelDiffData {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156900: [NFC][clang] Fix static analyzer concerns

2023-08-03 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4bb3e073548: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156900

Files:
  clang/lib/AST/Interp/InterpState.h


Index: clang/lib/AST/Interp/InterpState.h
===
--- clang/lib/AST/Interp/InterpState.h
+++ clang/lib/AST/Interp/InterpState.h
@@ -39,6 +39,9 @@
 
   ~InterpState();
 
+  InterpState(const InterpState &) = delete;
+  InterpState =(const InterpState &) = delete;
+
   // Stack frame accessors.
   Frame *getSplitFrame() { return Parent.getCurrentFrame(); }
   Frame *getCurrentFrame() override;


Index: clang/lib/AST/Interp/InterpState.h
===
--- clang/lib/AST/Interp/InterpState.h
+++ clang/lib/AST/Interp/InterpState.h
@@ -39,6 +39,9 @@
 
   ~InterpState();
 
+  InterpState(const InterpState &) = delete;
+  InterpState =(const InterpState &) = delete;
+
   // Stack frame accessors.
   Frame *getSplitFrame() { return Parent.getCurrentFrame(); }
   Frame *getCurrentFrame() override;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156904: [NFC][clang] Fix static analyzer concerns

2023-08-03 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG962deded6c30: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156904

Files:
  clang/lib/Sema/IdentifierResolver.cpp


Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -60,6 +60,9 @@
 }
   }
 
+  IdDeclInfoMap(const IdDeclInfoMap &) = delete;
+  IdDeclInfoMap =(const IdDeclInfoMap &) = delete;
+
   /// Returns the IdDeclInfo associated to the DeclarationName.
   /// It creates a new IdDeclInfo if one was not created before for this id.
   IdDeclInfo [](DeclarationName Name);


Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -60,6 +60,9 @@
 }
   }
 
+  IdDeclInfoMap(const IdDeclInfoMap &) = delete;
+  IdDeclInfoMap =(const IdDeclInfoMap &) = delete;
+
   /// Returns the IdDeclInfo associated to the DeclarationName.
   /// It creates a new IdDeclInfo if one was not created before for this id.
   IdDeclInfo [](DeclarationName Name);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156904: [NFC][clang] Fix static analyzer concerns

2023-08-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

IdDeclInfoMap frees resources in the destructor but doesn't
have user-written copy c'tor or assignment operator, so copying it using
default ones can cause double free.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156904

Files:
  clang/lib/Sema/IdentifierResolver.cpp


Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -60,6 +60,9 @@
 }
   }
 
+  IdDeclInfoMap(const IdDeclInfoMap &) = delete;
+  IdDeclInfoMap =(const IdDeclInfoMap &) = delete;
+
   /// Returns the IdDeclInfo associated to the DeclarationName.
   /// It creates a new IdDeclInfo if one was not created before for this id.
   IdDeclInfo [](DeclarationName Name);


Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -60,6 +60,9 @@
 }
   }
 
+  IdDeclInfoMap(const IdDeclInfoMap &) = delete;
+  IdDeclInfoMap =(const IdDeclInfoMap &) = delete;
+
   /// Returns the IdDeclInfo associated to the DeclarationName.
   /// It creates a new IdDeclInfo if one was not created before for this id.
   IdDeclInfo [](DeclarationName Name);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156900: [NFC][clang] Fix static analyzer concerns

2023-08-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

InterpState frees resources in the destructor but doesn't
have user-written copy c'tor or assignment operator, so copying it using
default ones can cause double free.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156900

Files:
  clang/lib/AST/Interp/InterpState.h


Index: clang/lib/AST/Interp/InterpState.h
===
--- clang/lib/AST/Interp/InterpState.h
+++ clang/lib/AST/Interp/InterpState.h
@@ -39,6 +39,9 @@
 
   ~InterpState();
 
+  InterpState(const InterpState &) = delete;
+  InterpState =(const InterpState &) = delete;
+
   // Stack frame accessors.
   Frame *getSplitFrame() { return Parent.getCurrentFrame(); }
   Frame *getCurrentFrame() override;


Index: clang/lib/AST/Interp/InterpState.h
===
--- clang/lib/AST/Interp/InterpState.h
+++ clang/lib/AST/Interp/InterpState.h
@@ -39,6 +39,9 @@
 
   ~InterpState();
 
+  InterpState(const InterpState &) = delete;
+  InterpState =(const InterpState &) = delete;
+
   // Stack frame accessors.
   Frame *getSplitFrame() { return Parent.getCurrentFrame(); }
   Frame *getCurrentFrame() override;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156896: [NFC][clang] Fix static analyzer concerns

2023-08-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

ToolInvocation frees resources in the destructor but doesn't
have user-written copy c'tor or assignment operator, so copying it using
default ones can cause double free.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156896

Files:
  clang/include/clang/Tooling/Tooling.h


Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -267,6 +267,9 @@
 
   ~ToolInvocation();
 
+  ToolInvocation(const ToolInvocation &) = delete;
+  ToolInvocation =(const ToolInvocation &) = delete;
+
   /// Set a \c DiagnosticConsumer to use during driver command-line parsing and
   /// the action invocation itself.
   void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer) {


Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -267,6 +267,9 @@
 
   ~ToolInvocation();
 
+  ToolInvocation(const ToolInvocation &) = delete;
+  ToolInvocation =(const ToolInvocation &) = delete;
+
   /// Set a \c DiagnosticConsumer to use during driver command-line parsing and
   /// the action invocation itself.
   void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-08-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon marked an inline comment as done.
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/overloaded-operator-decl.cpp:64
+class E {};
+void operator+(E, ...) {} // expected-error{{overloaded 'operator+' cannot be 
variadic}}
+void d() { E() + E(); }

Fznamznon wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > cor3ntin wrote:
> > > > aaron.ballman wrote:
> > > > > Fznamznon wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > I think it might make sense to extend the test coverage for the 
> > > > > > > other operators you can overload, just to demonstrate we diagnose 
> > > > > > > them all consistently. WDYT?
> > > > > > Okay, while trying to add more test cases I discovered that 
> > > > > > following
> > > > > > ```
> > > > > > class E {};
> > > > > > bool operator<(const E& lhs, ...);
> > > > > > auto operator<=>(const E& lhs, ...);
> > > > > > 
> > > > > > void d() {
> > > > > >   E() < E();
> > > > > > }
> > > > > > ```
> > > > > > crashes even with the patch since there is code searching for best 
> > > > > > overload candidate that doesn't consider possibility for them 
> > > > > > making variadic.
> > > > > > The code around overloading is actually pretty inconsistent, 
> > > > > > somewhere invalid candidates are considered, and somewhere not, so 
> > > > > > I spent some time not knowing what to do.
> > > > > > I'm now inclined that we just shouldn't consider invalid candidates 
> > > > > > like @shafik 
> > > > > > suggests. WDYY?
> > > > > > 
> > > > > Overload resolution doesn't need to produce a candidate that's viable 
> > > > > to call; C++ lets you resolve to the "best viable function" only to 
> > > > > say "and that one wasn't good enough either." e.g., 
> > > > > http://eel.is/c++draft/over#match.general-3
> > > > > 
> > > > > I've not yet spotted anything in http://eel.is/c++draft/over that 
> > > > > says invalid declarations should/should not be added to the initial 
> > > > > candidate set. I *think* the intention is that if name lookup can 
> > > > > find the name, it goes into the candidate set. Then that set is 
> > > > > processed to remove functions that are not viable 
> > > > > (http://eel.is/c++draft/over.match.viable). Then we find the best 
> > > > > viable function from that set.
> > > > > 
> > > > > I think we should be keeping the function in the candidate set so 
> > > > > long as it matches the rules in 
> > > > > http://eel.is/c++draft/over.match.viable even if the function is 
> > > > > otherwise not viable. Otherwise, correcting an unrelated issue might 
> > > > > change overload resolution to find a completely different function. 
> > > > > e.g., in my example above, we'd select `void overloaded(int);` as the 
> > > > > best viable function, but when the user corrects the `float` 
> > > > > function, we'd change to call that instead. I think it's easier to 
> > > > > understand what's going on when picking the `float` overload to begin 
> > > > > with and saying "but we can't call that because it's busted".
> > > > > 
> > > > > CC @cor3ntin @hubert.reinterpretcast @rsmith for some extra opinions, 
> > > > > as I'm not certain if I'm interpreting the standard correctly or not.
> > > > I'm not sure how much the standardese matter here as the declaration of 
> > > > the operators are ill-formed anyway.
> > > > But from a QOI perspective, i think keeping in the set everything the 
> > > > users might reasonably expect to be considered makes sense to me, as it 
> > > > *should* lead to better diagnostics
> > > Thanks for the extra perspective! Yeah, I think that's what I've been 
> > > convincing myself of. Effectively:
> > > ```
> > > int overloaded(int);
> > > float overloaded(float) noexcept(error()); // error: invalid declaration
> > > 
> > > int main() {
> > >   (void)overloaded(1.0f); // #1
> > > }
> > > ```
> > > We're always going to get the invalid declaration diagnostic. The 
> > > question is whether we want a diagnostic at #1 that says "can't call this 
> > > overload" or whether we want #1 to have no diagnostic (because it picked 
> > > the `int` overload). From a purely diagnostic perspective, I think I can 
> > > see arguments either way. But if we change it slightly:
> > > ```
> > > template 
> > > constexpr int func() { return 0; }
> > > 
> > > template <>
> > > constexpr int func() { return 1; }
> > > 
> > > template <>
> > > constexpr int func() { return 2; }
> > > 
> > > int overloaded(int);
> > > float overloaded(float) noexcept(error()); // error: invalid declaration
> > > 
> > > static_assert(func(overloaded(1.0f)) == 2); // #1
> > > ```
> > > we still get the invalid declaration diagnostic, but now we get a failing 
> > > static assertion because we picked the `int` overload rather than the 
> > > `float` overload. I think this is clearly worse behavior than if we 
> > > issued an additional diagnostic at #1 saying that the overload we picked 
> > > (`float`) was invalid.
> > > 
> > 

[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-08-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 546445.
Fznamznon added a comment.

Rebase, add more test cases, fix assertion on variadic functions inside of
`haveSameParameterTypes`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156244

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/overloaded-operator-decl.cpp

Index: clang/test/SemaCXX/overloaded-operator-decl.cpp
===
--- clang/test/SemaCXX/overloaded-operator-decl.cpp
+++ clang/test/SemaCXX/overloaded-operator-decl.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 struct X { 
   X();
   X(int); 
@@ -58,3 +59,67 @@
 A()(i);
   }
 }
+
+namespace GH42535 {
+class E {
+  E& operator=(const E& rhs, ...); // expected-error{{overloaded 'operator=' cannot be variadic}}
+  E& operator+=(const E& rhs, ...); // expected-error{{overloaded 'operator+=' cannot be variadic}}
+
+};
+void operator+(E, ...) {} // expected-error{{overloaded 'operator+' cannot be variadic}}
+void operator-(E, ...) {} // expected-error{{overloaded 'operator-' cannot be variadic}}
+void operator*(E, ...) {} // expected-error{{overloaded 'operator*' cannot be variadic}}
+void operator/(E, ...) {} // expected-error{{overloaded 'operator/' must be a binary operator}}
+void operator/(E, E, ...) {} // expected-error{{overloaded 'operator/' cannot be variadic}}
+void operator%(E, ...) {} // expected-error{{overloaded 'operator%' must be a binary operator}}
+void operator%(E, E, ...) {} // expected-error{{overloaded 'operator%' cannot be variadic}}
+E& operator++(E&, ...); // expected-error{{overloaded 'operator++' cannot be variadic}}
+E& operator--(E&, ...); // expected-error{{overloaded 'operator--' cannot be variadic}}
+bool operator<(const E& lhs, ...); // expected-error{{overloaded 'operator<' must be a binary operator}}
+bool operator<(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator>(const E& lhs, ...); // expected-error{{overloaded 'operator>' must be a binary operator}}
+bool operator>(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator>=(const E& lhs, ...); // expected-error{{overloaded 'operator>=' must be a binary operator}}
+bool operator>=(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator<=(const E& lhs, ...); // expected-error{{overloaded 'operator<=' must be a binary operator}}
+bool operator<=(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator==(const E& lhs, ...); // expected-error{{overloaded 'operator==' must be a binary operator}}
+bool operator==(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator!=(const E& lhs, ...); // expected-error{{overloaded 'operator!=' must be a binary operator}}
+bool operator!=(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator&&(const E& lhs, ...); // expected-error{{overloaded 'operator&&' must be a binary operator}}
+bool operator&&(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator||(const E& lhs, ...); // expected-error{{overloaded 'operator||' must be a binary operator}}
+bool operator||(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator>>(const E& lhs, ...); // expected-error{{overloaded 'operator>>' must be a binary operator}}
+bool operator>>(const E& lhs, const E& rhs, ...); // expected-error{{cannot be variadic}}
+bool operator&(const E& lhs, ...); // expected-error{{cannot be variadic}}
+#if __cplusplus >= 202002L
+auto operator<=>(const E& lhs, ...);  // expected-error{{overloaded 'operator<=>' must be a binary operator}}
+#endif
+void d() {
+  E() + E();
+  E() - E();
+  E() * E();
+  E() / E();
+  E() % E();
+  ++E(); // expected-error{{cannot increment value of type 'E'}}
+  --E(); // expected-error{{cannot decrement value of type 'E'}}
+  E() < E();
+  E() > E();
+  E() <= E();
+  E() >= E();
+  E() == E();
+  E() != E();
+#if __cplusplus >= 202002L
+  E() <=> E();
+#endif
+  E e;
+  E e1 = e;
+  e += e1;
+  E() && E();
+  E() || E();
+  E() & E();
+  E() >> E();
+}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9850,7 +9850,7 @@
 }
 
 static bool haveSameParameterTypes(ASTContext , const FunctionDecl *F1,
-   const FunctionDecl *F2, unsigned NumParams) {
+   const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
 
@@ -9863,8 +9863,14 @@
 return F->getParamDecl(I++)->getType();
   };
 
+  unsigned F1NumParams = F1->getNumParams() + isa(F1);
+  

[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-08-01 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/overloaded-operator-decl.cpp:64
+class E {};
+void operator+(E, ...) {} // expected-error{{overloaded 'operator+' cannot be 
variadic}}
+void d() { E() + E(); }

cor3ntin wrote:
> aaron.ballman wrote:
> > cor3ntin wrote:
> > > aaron.ballman wrote:
> > > > Fznamznon wrote:
> > > > > aaron.ballman wrote:
> > > > > > I think it might make sense to extend the test coverage for the 
> > > > > > other operators you can overload, just to demonstrate we diagnose 
> > > > > > them all consistently. WDYT?
> > > > > Okay, while trying to add more test cases I discovered that following
> > > > > ```
> > > > > class E {};
> > > > > bool operator<(const E& lhs, ...);
> > > > > auto operator<=>(const E& lhs, ...);
> > > > > 
> > > > > void d() {
> > > > >   E() < E();
> > > > > }
> > > > > ```
> > > > > crashes even with the patch since there is code searching for best 
> > > > > overload candidate that doesn't consider possibility for them making 
> > > > > variadic.
> > > > > The code around overloading is actually pretty inconsistent, 
> > > > > somewhere invalid candidates are considered, and somewhere not, so I 
> > > > > spent some time not knowing what to do.
> > > > > I'm now inclined that we just shouldn't consider invalid candidates 
> > > > > like @shafik 
> > > > > suggests. WDYY?
> > > > > 
> > > > Overload resolution doesn't need to produce a candidate that's viable 
> > > > to call; C++ lets you resolve to the "best viable function" only to say 
> > > > "and that one wasn't good enough either." e.g., 
> > > > http://eel.is/c++draft/over#match.general-3
> > > > 
> > > > I've not yet spotted anything in http://eel.is/c++draft/over that says 
> > > > invalid declarations should/should not be added to the initial 
> > > > candidate set. I *think* the intention is that if name lookup can find 
> > > > the name, it goes into the candidate set. Then that set is processed to 
> > > > remove functions that are not viable 
> > > > (http://eel.is/c++draft/over.match.viable). Then we find the best 
> > > > viable function from that set.
> > > > 
> > > > I think we should be keeping the function in the candidate set so long 
> > > > as it matches the rules in http://eel.is/c++draft/over.match.viable 
> > > > even if the function is otherwise not viable. Otherwise, correcting an 
> > > > unrelated issue might change overload resolution to find a completely 
> > > > different function. e.g., in my example above, we'd select `void 
> > > > overloaded(int);` as the best viable function, but when the user 
> > > > corrects the `float` function, we'd change to call that instead. I 
> > > > think it's easier to understand what's going on when picking the 
> > > > `float` overload to begin with and saying "but we can't call that 
> > > > because it's busted".
> > > > 
> > > > CC @cor3ntin @hubert.reinterpretcast @rsmith for some extra opinions, 
> > > > as I'm not certain if I'm interpreting the standard correctly or not.
> > > I'm not sure how much the standardese matter here as the declaration of 
> > > the operators are ill-formed anyway.
> > > But from a QOI perspective, i think keeping in the set everything the 
> > > users might reasonably expect to be considered makes sense to me, as it 
> > > *should* lead to better diagnostics
> > Thanks for the extra perspective! Yeah, I think that's what I've been 
> > convincing myself of. Effectively:
> > ```
> > int overloaded(int);
> > float overloaded(float) noexcept(error()); // error: invalid declaration
> > 
> > int main() {
> >   (void)overloaded(1.0f); // #1
> > }
> > ```
> > We're always going to get the invalid declaration diagnostic. The question 
> > is whether we want a diagnostic at #1 that says "can't call this overload" 
> > or whether we want #1 to have no diagnostic (because it picked the `int` 
> > overload). From a purely diagnostic perspective, I think I can see 
> > arguments either way. But if we change it slightly:
> > ```
> > template 
> > constexpr int func() { return 0; }
> > 
> > template <>
> > constexpr int func() { return 1; }
> > 
> > template <>
> > constexpr int func() { return 2; }
> > 
> > int overloaded(int);
> > float overloaded(float) noexcept(error()); // error: invalid declaration
> > 
> > static_assert(func(overloaded(1.0f)) == 2); // #1
> > ```
> > we still get the invalid declaration diagnostic, but now we get a failing 
> > static assertion because we picked the `int` overload rather than the 
> > `float` overload. I think this is clearly worse behavior than if we issued 
> > an additional diagnostic at #1 saying that the overload we picked (`float`) 
> > was invalid.
> > 
> > https://godbolt.org/z/34aGMY43n
> > 
> > WDYT?
> Agreed. If i write an overload i presumably want the compiler to consider it, 
> even if I botched it. And apparently, the issue is not that we don't do that 
> but rather than we don't always do that. We should 

[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-07-31 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> I agree this is a bug in libc++ and we should fix it. As mentioned I'm not 
> too familiar with ranges.

Thanks! I submitted https://github.com/llvm/llvm-project/issues/64250 so we 
don't forget about it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/overloaded-operator-decl.cpp:64
+class E {};
+void operator+(E, ...) {} // expected-error{{overloaded 'operator+' cannot be 
variadic}}
+void d() { E() + E(); }

aaron.ballman wrote:
> I think it might make sense to extend the test coverage for the other 
> operators you can overload, just to demonstrate we diagnose them all 
> consistently. WDYT?
Okay, while trying to add more test cases I discovered that following
```
class E {};
bool operator<(const E& lhs, ...);
auto operator<=>(const E& lhs, ...);

void d() {
  E() < E();
}
```
crashes even with the patch since there is code searching for best overload 
candidate that doesn't consider possibility for them making variadic.
The code around overloading is actually pretty inconsistent, somewhere invalid 
candidates are considered, and somewhere not, so I spent some time not knowing 
what to do.
I'm now inclined that we just shouldn't consider invalid candidates like 
@shafik 
suggests. WDYY?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156244

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


[PATCH] D156406: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa457067d2c6b: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156406

Files:
  clang/include/clang/Sema/IdentifierResolver.h


Index: clang/include/clang/Sema/IdentifierResolver.h
===
--- clang/include/clang/Sema/IdentifierResolver.h
+++ clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@
   explicit IdentifierResolver(Preprocessor );
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver =(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 


Index: clang/include/clang/Sema/IdentifierResolver.h
===
--- clang/include/clang/Sema/IdentifierResolver.h
+++ clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@
   explicit IdentifierResolver(Preprocessor );
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver =(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156415: [NFC][analyzer] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9fe23fbb2318: [NFC][analyzer] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156415

Files:
  clang/include/clang/Analysis/CFGStmtMap.h


Index: clang/include/clang/Analysis/CFGStmtMap.h
===
--- clang/include/clang/Analysis/CFGStmtMap.h
+++ clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap =(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();


Index: clang/include/clang/Analysis/CFGStmtMap.h
===
--- clang/include/clang/Analysis/CFGStmtMap.h
+++ clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap =(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156405: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa623f4c78498: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156405

Files:
  clang/lib/Frontend/FrontendAction.cpp


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) 
=
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) =
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156415: [NFC][analyzer] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

The failures are unrelated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156415

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


[PATCH] D156406: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

The failures are unrelated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156406

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


[PATCH] D156405: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

The failures are unrelated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156405

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


[PATCH] D156415: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 545082.
Fznamznon added a comment.

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156415

Files:
  clang/include/clang/Analysis/CFGStmtMap.h


Index: clang/include/clang/Analysis/CFGStmtMap.h
===
--- clang/include/clang/Analysis/CFGStmtMap.h
+++ clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap =(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();


Index: clang/include/clang/Analysis/CFGStmtMap.h
===
--- clang/include/clang/Analysis/CFGStmtMap.h
+++ clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap =(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156406: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 545080.
Fznamznon added a comment.

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156406

Files:
  clang/include/clang/Sema/IdentifierResolver.h


Index: clang/include/clang/Sema/IdentifierResolver.h
===
--- clang/include/clang/Sema/IdentifierResolver.h
+++ clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@
   explicit IdentifierResolver(Preprocessor );
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver =(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 


Index: clang/include/clang/Sema/IdentifierResolver.h
===
--- clang/include/clang/Sema/IdentifierResolver.h
+++ clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@
   explicit IdentifierResolver(Preprocessor );
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver =(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156405: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 545079.
Fznamznon added a comment.

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156405

Files:
  clang/lib/Frontend/FrontendAction.cpp


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) 
=
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) =
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156237: Complete the implementation of P2361 Unevaluated string literals

2023-07-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:422
+  // There's nothing to suggest in here as we parsed a full expression.
+  // Instead fail and propogate the error since caller might have something
+  // the suggest, e.g. signature help in function call. Note that this is





Comment at: clang/lib/Parse/ParseDecl.cpp:433-434
+  SawError = true;
+  break;
+  SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
+} else {

Should it be

Also, probably else can be removed since there is break above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156237

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


[PATCH] D156415: [NFC][clang] Fix static analyzer concerns

2023-07-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a reviewer: NoQ.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

CFGStmtMap frees resources in the destructor but doesn't
have user-written copy c'tor or assignment operator, so copying it using
default ones can cause double free.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156415

Files:
  clang/include/clang/Analysis/CFGStmtMap.h


Index: clang/include/clang/Analysis/CFGStmtMap.h
===
--- clang/include/clang/Analysis/CFGStmtMap.h
+++ clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap =(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();


Index: clang/include/clang/Analysis/CFGStmtMap.h
===
--- clang/include/clang/Analysis/CFGStmtMap.h
+++ clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap =(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156406: [NFC][clang] Fix static analyzer concerns

2023-07-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

IdentifierResolver frees resources in the destructor but doesn't
have user-written copy c'tor or assignment operator, so copying it using
default ones can cause double free.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156406

Files:
  clang/include/clang/Sema/IdentifierResolver.h


Index: clang/include/clang/Sema/IdentifierResolver.h
===
--- clang/include/clang/Sema/IdentifierResolver.h
+++ clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@
   explicit IdentifierResolver(Preprocessor );
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver =(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 


Index: clang/include/clang/Sema/IdentifierResolver.h
===
--- clang/include/clang/Sema/IdentifierResolver.h
+++ clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@
   explicit IdentifierResolver(Preprocessor );
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver =(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156405: [NFC][clang] Fix static analyzer concerns

2023-07-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

DelegatingDeserializationListener frees resources in the destructor but doesn't
have user-written copy c'tor or assignment operator, so copying it using
default ones can cause double free.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156405

Files:
  clang/lib/Frontend/FrontendAction.cpp


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) 
=
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) =
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156337: [clang] Allow setting the uninitialized attribute on record

2023-07-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1906-1908
+  if (D.isConstexpr())
+// Note: constexpr already initializes everything correctly.
+trivialAutoVarInit = LangOptions::TrivialAutoVarInitKind::Uninitialized;

Should we have curly braces here?



Comment at: clang/lib/CodeGen/CGDecl.cpp:1909
+trivialAutoVarInit = LangOptions::TrivialAutoVarInitKind::Uninitialized;
+  else if (D.getAttr())
+trivialAutoVarInit = LangOptions::TrivialAutoVarInitKind::Uninitialized;





Comment at: clang/lib/Sema/SemaDeclAttr.cpp:8442
+  assert(((isa(D) &&
+   cast(D)->getStorageDuration() == SD_Automatic) ||
+  isa(D)) &&

AFAIK `cast` does `isa`, since it is already done here we can probably switch 
to `dyn_cast`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156337

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


[PATCH] D156222: [NFC][clang] Fix static analyzer concerns

2023-07-26 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcb63fa00d1f7: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156222

Files:
  clang/lib/Sema/TypeLocBuilder.h


Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -53,6 +53,9 @@
   delete[] Buffer;
   }
 
+  TypeLocBuilder(const TypeLocBuilder &) = delete;
+  TypeLocBuilder =(const TypeLocBuilder &) = delete;
+
   /// Ensures that this buffer has at least as much capacity as described.
   void reserve(size_t Requested) {
 if (Requested > Capacity)


Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -53,6 +53,9 @@
   delete[] Buffer;
   }
 
+  TypeLocBuilder(const TypeLocBuilder &) = delete;
+  TypeLocBuilder =(const TypeLocBuilder &) = delete;
+
   /// Ensures that this buffer has at least as much capacity as described.
   void reserve(size_t Requested) {
 if (Requested > Capacity)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-07-26 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> What do you mean with libstdc++ is fine?

What I mean is when I do (current patch is applied to clang):

  source/llvm-project/build/bin/clang++ -std=c++20 t.cpp -c // compilation 
succeeds

But when I do (libc++ is built together with clang)

  source/llvm-project/build/bin/clang++ -std=c++20 t.cpp -stdlib=libc++ -c
  t.cpp:4:15: error: static assertion failed due to requirement 
'!std::is_invocable_v'
  4 | static_assert(!std::is_invocable_v);
|   ^~~~
  1 error generated.



> Based on the bug and this patch I am correct that "transformation" of an 
> array of unknown bounds to anarray of known bounds only happens with an 
> explicit cast and not implicitly?

Yes, type is changed only for explicit casts.

> I have a strong suspicion that this patch changes the test to

Well technically it only changes explicit casts, so no.  With this patch this 
static assertion still fails

  static_assert(std::is_same::value);

What I'm seeing is that in libc++ there is a bunch of explicit static casts in 
`ranges::__crend::__fn` that endup transformed:

  namespace ranges {
  namespace __crend {   
 
  struct __fn {
template 
  requires is_lvalue_reference_v<_Tp&&> 
 
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp&& __t) const
  noexcept(noexcept(ranges::rend(static_cast&>(__t
  -> decltype(  ranges::rend(static_cast&>(__t)))  
  { return  ranges::rend(static_cast&>(__t)); }

 
template 
 
  requires is_rvalue_reference_v<_Tp&&> 
 
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp&& __t) const
  noexcept(noexcept(ranges::rend(static_cast(__t   
 
  -> decltype(  ranges::rend(static_cast(__t)))
  { return  ranges::rend(static_cast(__t)); }
  };
  } // namespace __crend

Is that expected?

Please note that other implementations would do the same transformation and 
that is the point of this bugfix:
https://godbolt.org/z/ff8f3YEbz


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[PATCH] D156222: [NFC][clang] Fix static analyzer concerns

2023-07-26 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 544262.
Fznamznon added a comment.

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156222

Files:
  clang/lib/Sema/TypeLocBuilder.h


Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -53,6 +53,9 @@
   delete[] Buffer;
   }
 
+  TypeLocBuilder(const TypeLocBuilder &) = delete;
+  TypeLocBuilder =(const TypeLocBuilder &) = delete;
+
   /// Ensures that this buffer has at least as much capacity as described.
   void reserve(size_t Requested) {
 if (Requested > Capacity)


Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -53,6 +53,9 @@
   delete[] Buffer;
   }
 
+  TypeLocBuilder(const TypeLocBuilder &) = delete;
+  TypeLocBuilder =(const TypeLocBuilder &) = delete;
+
   /// Ensures that this buffer has at least as much capacity as described.
   void reserve(size_t Requested) {
 if (Requested > Capacity)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-07-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:14001
+
+if (FnDecl->isInvalidDecl())
+  return ExprError();

Fznamznon wrote:
> shafik wrote:
> > Fznamznon wrote:
> > > shafik wrote:
> > > > shafik wrote:
> > > > > It feels a bit weird that we are succeeding in finding the best 
> > > > > viable function and what we find is invalid. 
> > > > It looks like we have a couple of test that generate the `cannot be 
> > > > variadic` diagnostic for overloads e.g. 
> > > > `clang/test/SemaCXX/overloaded-operator-decl.cpp` it might be worth 
> > > > looking into why they don't crash and this case does. 
> > > Yes, but it seems to be done this way in other places as well:
> > > https://github.com/llvm/llvm-project/blob/0478ef2d366c6f88678e37d54190dcdaa0ec69da/clang/lib/Sema/SemaOverload.cpp#L15145
> > >  .
> > I see that but that diagnostic looks like it is generated by the call to 
> > `CheckMemberOperatorAccess(...)` which is not really the same situation we 
> > have here.
> We crash when ask functiondecl its second parameter and it doesn't have it 
> when the call expression is formed.
> The cases from tests do not crash either because the operators are not used 
> or there is at least two parameters defined in declaration of operator.
> I see that but that diagnostic looks like it is generated by the call to 
> CheckMemberOperatorAccess(...) which is not really the same situation we have 
> here.

Is it? For me it seems there is a similar exit  inside of 
`BuildCallToObjectOfClassType` function whose description says:
```
/// BuildCallToObjectOfClassType - Build a call to an object of class
/// type (C++ [over.call.object]), which can end up invoking an
/// overloaded function call operator (@c operator()) or performing a
/// user-defined conversion on the object argument.
```

`CheckMemberOperatorAccess` is just a call above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156244

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


[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-07-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:14001
+
+if (FnDecl->isInvalidDecl())
+  return ExprError();

shafik wrote:
> Fznamznon wrote:
> > shafik wrote:
> > > shafik wrote:
> > > > It feels a bit weird that we are succeeding in finding the best viable 
> > > > function and what we find is invalid. 
> > > It looks like we have a couple of test that generate the `cannot be 
> > > variadic` diagnostic for overloads e.g. 
> > > `clang/test/SemaCXX/overloaded-operator-decl.cpp` it might be worth 
> > > looking into why they don't crash and this case does. 
> > Yes, but it seems to be done this way in other places as well:
> > https://github.com/llvm/llvm-project/blob/0478ef2d366c6f88678e37d54190dcdaa0ec69da/clang/lib/Sema/SemaOverload.cpp#L15145
> >  .
> I see that but that diagnostic looks like it is generated by the call to 
> `CheckMemberOperatorAccess(...)` which is not really the same situation we 
> have here.
We crash when ask functiondecl its second parameter and it doesn't have it when 
the call expression is formed.
The cases from tests do not crash either because the operators are not used or 
there is at least two parameters defined in declaration of operator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156244

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


[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-07-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:14001
+
+if (FnDecl->isInvalidDecl())
+  return ExprError();

shafik wrote:
> It feels a bit weird that we are succeeding in finding the best viable 
> function and what we find is invalid. 
Yes, but it seems to be done this way in other places as well:
https://github.com/llvm/llvm-project/blob/0478ef2d366c6f88678e37d54190dcdaa0ec69da/clang/lib/Sema/SemaOverload.cpp#L15145
 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156244

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


[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

2023-07-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Just exit instead.
Fixes https://github.com/llvm/llvm-project/issues/42535


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156244

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/overloaded-operator-decl.cpp


Index: clang/test/SemaCXX/overloaded-operator-decl.cpp
===
--- clang/test/SemaCXX/overloaded-operator-decl.cpp
+++ clang/test/SemaCXX/overloaded-operator-decl.cpp
@@ -58,3 +58,9 @@
 A()(i);
   }
 }
+
+namespace GH42535 {
+class E {};
+void operator+(E, ...) {} // expected-error{{overloaded 'operator+' cannot be 
variadic}}
+void d() { E() + E(); }
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -13997,6 +13997,10 @@
 std::swap(Args[0], Args[1]);
 
   if (FnDecl) {
+
+if (FnDecl->isInvalidDecl())
+  return ExprError();
+
 Expr *Base = nullptr;
 // We matched an overloaded operator. Build a call to that
 // operator.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -685,6 +685,8 @@
   (`#64005 _`)
 - Fix crash on nested templated class with template function call.
   (`#61159 _`)
+- Fix crash on use of a variadic overloaded operator.
+  (`#42535 _`)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/overloaded-operator-decl.cpp
===
--- clang/test/SemaCXX/overloaded-operator-decl.cpp
+++ clang/test/SemaCXX/overloaded-operator-decl.cpp
@@ -58,3 +58,9 @@
 A()(i);
   }
 }
+
+namespace GH42535 {
+class E {};
+void operator+(E, ...) {} // expected-error{{overloaded 'operator+' cannot be variadic}}
+void d() { E() + E(); }
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -13997,6 +13997,10 @@
 std::swap(Args[0], Args[1]);
 
   if (FnDecl) {
+
+if (FnDecl->isInvalidDecl())
+  return ExprError();
+
 Expr *Base = nullptr;
 // We matched an overloaded operator. Build a call to that
 // operator.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -685,6 +685,8 @@
   (`#64005 _`)
 - Fix crash on nested templated class with template function call.
   (`#61159 _`)
+- Fix crash on use of a variadic overloaded operator.
+  (`#42535 _`)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156222: [NFC][clang] Fix static analyzer concerns

2023-07-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

TypeLocBuilder frees resources in the destructor but doesn't have
user-written copy c'tor or assignment operator, so copying it using
default ones can cause double free.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156222

Files:
  clang/lib/Sema/TypeLocBuilder.h


Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -53,6 +53,9 @@
   delete[] Buffer;
   }
 
+  TypeLocBuilder(const TypeLocBuilder &) = delete;
+  TypeLocBuilder =(const TypeLocBuilder &) = delete;
+
   /// Ensures that this buffer has at least as much capacity as described.
   void reserve(size_t Requested) {
 if (Requested > Capacity)


Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -53,6 +53,9 @@
   delete[] Buffer;
   }
 
+  TypeLocBuilder(const TypeLocBuilder &) = delete;
+  TypeLocBuilder =(const TypeLocBuilder &) = delete;
+
   /// Ensures that this buffer has at least as much capacity as described.
   void reserve(size_t Requested) {
 if (Requested > Capacity)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156133: [NFC][clang] Fix static analyzer concerns

2023-07-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc5a13e2c7e4c: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156133

Files:
  clang/lib/CodeGen/EHScopeStack.h


Index: clang/lib/CodeGen/EHScopeStack.h
===
--- clang/lib/CodeGen/EHScopeStack.h
+++ clang/lib/CodeGen/EHScopeStack.h
@@ -278,6 +278,9 @@
   CGF(nullptr) {}
   ~EHScopeStack() { delete[] StartOfBuffer; }
 
+  EHScopeStack(const EHScopeStack &) = delete;
+  EHScopeStack =(const EHScopeStack &) = delete;
+
   /// Push a lazily-created cleanup on the stack.
   template  void pushCleanup(CleanupKind Kind, As... A) {
 static_assert(alignof(T) <= ScopeStackAlignment,


Index: clang/lib/CodeGen/EHScopeStack.h
===
--- clang/lib/CodeGen/EHScopeStack.h
+++ clang/lib/CodeGen/EHScopeStack.h
@@ -278,6 +278,9 @@
   CGF(nullptr) {}
   ~EHScopeStack() { delete[] StartOfBuffer; }
 
+  EHScopeStack(const EHScopeStack &) = delete;
+  EHScopeStack =(const EHScopeStack &) = delete;
+
   /// Push a lazily-created cleanup on the stack.
   template  void pushCleanup(CleanupKind Kind, As... A) {
 static_assert(alignof(T) <= ScopeStackAlignment,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-07-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> should we try to land that today?

I'm not sure. It causes failures in libc++ testing:

  Failed Tests (3):
llvm-libc++-shared.cfg.in :: std/ranges/range.access/end.pass.cpp
llvm-libc++-shared.cfg.in :: std/ranges/range.access/rbegin.pass.cpp
llvm-libc++-shared.cfg.in :: std/ranges/range.access/rend.pass.cpp

I haven't figured out why. Trying to compile:

  #include 
  
  using RangeCREndT = decltype(std::ranges::crend);
  static_assert(!std::is_invocable_v);

fails with this patch only using libc++, libstdc++ is fine. I'm not sure it is 
my misunderstanding, bug in the patch or bug in libc++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[PATCH] D155705: [clang] Fix specialization of non-templated member classes of class templates

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdcb8911316be: [clang] Fix specialization of non-templated 
member classes of class templates (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D155705?vs=543478=543598#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155705

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/gh61159.cpp


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+namespace GH61159 {
+template  struct X {
+  struct I;
+};
+
+template <> struct X::I {
+  template  constexpr int f() { return ct; };
+
+  int data = 3;
+};
+
+template  struct X::I {
+  template  constexpr T f() { return ct + 1; };
+  T data = 7;
+};
+
+static_assert(X::I{}.f<17>() == 17);
+static_assert(X::I{}.data == 3);
+static_assert(X::I{}.data == 7);
+static_assert(X::I{}.f<18>() == 19);
+
+template  struct Y {
+  struct I;
+};
+
+template <> struct Y {
+  struct I {
+template  constexpr int f() { return ct; };
+int data = 3;
+  };
+};
+
+static_assert(Y::I{}.f<17>() == 17);
+static_assert(Y::I{}.data == 3);
+
+} // namespace GH61159
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -258,6 +258,11 @@
/*Final=*/false);
   }
 
+  if (const MemberSpecializationInfo *MSInfo =
+  Rec->getMemberSpecializationInfo())
+if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+  return Response::Done();
+
   bool IsFriend = Rec->getFriendObjectKind() ||
   (Rec->getDescribedClassTemplate() &&
Rec->getDescribedClassTemplate()->getFriendObjectKind());
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -677,6 +677,8 @@
 - Invalidate BlockDecl with invalid ParmVarDecl. Remove redundant dump of
   BlockDecl's ParmVarDecl
   (`#64005 _`)
+- Fix crash on nested templated class with template function call.
+  (`#61159 _`)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+namespace GH61159 {
+template  struct X {
+  struct I;
+};
+
+template <> struct X::I {
+  template  constexpr int f() { return ct; };
+
+  int data = 3;
+};
+
+template  struct X::I {
+  template  constexpr T f() { return ct + 1; };
+  T data = 7;
+};
+
+static_assert(X::I{}.f<17>() == 17);
+static_assert(X::I{}.data == 3);
+static_assert(X::I{}.data == 7);
+static_assert(X::I{}.f<18>() == 19);
+
+template  struct Y {
+  struct I;
+};
+
+template <> struct Y {
+  struct I {
+template  constexpr int f() { return ct; };
+int data = 3;
+  };
+};
+
+static_assert(Y::I{}.f<17>() == 17);
+static_assert(Y::I{}.data == 3);
+
+} // namespace GH61159
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -258,6 +258,11 @@
/*Final=*/false);
   }
 
+  if (const MemberSpecializationInfo *MSInfo =
+  Rec->getMemberSpecializationInfo())
+if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+  return Response::Done();
+
   bool IsFriend = Rec->getFriendObjectKind() ||
   (Rec->getDescribedClassTemplate() &&
Rec->getDescribedClassTemplate()->getFriendObjectKind());
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -677,6 +677,8 @@
 - Invalidate BlockDecl with invalid ParmVarDecl. Remove redundant dump of
   BlockDecl's ParmVarDecl
   (`#64005 _`)
+- Fix crash on nested templated class with template function call.
+  (`#61159 _`)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list

[PATCH] D156133: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

EHScopeStack doesn't seem to be intended for copy. It frees memory in
the destructor and doesn't have user-written copy c'tor and assignment
operator, so delete them to avoid using default ones which would do
wrong.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156133

Files:
  clang/lib/CodeGen/EHScopeStack.h


Index: clang/lib/CodeGen/EHScopeStack.h
===
--- clang/lib/CodeGen/EHScopeStack.h
+++ clang/lib/CodeGen/EHScopeStack.h
@@ -278,6 +278,9 @@
   CGF(nullptr) {}
   ~EHScopeStack() { delete[] StartOfBuffer; }
 
+  EHScopeStack(const EHScopeStack &) = delete;
+  EHScopeStack =(const EHScopeStack &) = delete;
+
   /// Push a lazily-created cleanup on the stack.
   template  void pushCleanup(CleanupKind Kind, As... A) {
 static_assert(alignof(T) <= ScopeStackAlignment,


Index: clang/lib/CodeGen/EHScopeStack.h
===
--- clang/lib/CodeGen/EHScopeStack.h
+++ clang/lib/CodeGen/EHScopeStack.h
@@ -278,6 +278,9 @@
   CGF(nullptr) {}
   ~EHScopeStack() { delete[] StartOfBuffer; }
 
+  EHScopeStack(const EHScopeStack &) = delete;
+  EHScopeStack =(const EHScopeStack &) = delete;
+
   /// Push a lazily-created cleanup on the stack.
   template  void pushCleanup(CleanupKind Kind, As... A) {
 static_assert(alignof(T) <= ScopeStackAlignment,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155842: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0cb2906cdfb3: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155842

Files:
  clang/lib/Frontend/HeaderIncludeGen.cpp


Index: clang/lib/Frontend/HeaderIncludeGen.cpp
===
--- clang/lib/Frontend/HeaderIncludeGen.cpp
+++ clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback =(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,


Index: clang/lib/Frontend/HeaderIncludeGen.cpp
===
--- clang/lib/Frontend/HeaderIncludeGen.cpp
+++ clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback =(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155849: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcc928c683058: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155849

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,11 @@
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
+
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction , const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,11 @@
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
+
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction , const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155705: [clang] Fix specialization of non-templated member classes of class templates

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> Maybe we should think about tests that might exercise this code a bit more.

I tried adding more checks, but the patch fixes a specific case.
Do you have some examples in mind?
Please note that in order to test new change there should be an instantiation 
of nested non-template class inside of a templated class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155705

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


[PATCH] D156108: Rebase, extend the test a bit

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon abandoned this revision.
Fznamznon added a comment.

Miss click!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156108

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


[PATCH] D155705: [clang] Fix specialization of non-templated member classes of class templates

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 543478.
Fznamznon added a comment.

Rebase, extend the test a bit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155705

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/gh61159.cpp


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+namespace GH61159 {
+template  struct X {
+  struct I;
+};
+
+template <> struct X::I {
+  template  constexpr int f() { return ct; };
+
+  int data = 3;
+};
+
+template  struct X::I {
+  template  constexpr T f() { return ct + 1; };
+  T data = 7;
+};
+
+static_assert(X::I{}.f<17>() == 17);
+static_assert(X::I{}.data == 3);
+static_assert(X::I{}.data == 7);
+static_assert(X::I{}.f<18>() == 19);
+
+template  struct Y {
+  struct I;
+};
+
+template <> struct Y {
+  struct I {
+template  constexpr int f() { return ct; };
+int data = 3;
+  };
+};
+
+static_assert(Y::I{}.f<17>() == 17);
+static_assert(Y::I{}.data == 3);
+
+} // namespace GH61159
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -258,6 +258,11 @@
/*Final=*/false);
   }
 
+  if (const MemberSpecializationInfo *MSInfo =
+  Rec->getMemberSpecializationInfo())
+if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+  return Response::Done();
+
   bool IsFriend = Rec->getFriendObjectKind() ||
   (Rec->getDescribedClassTemplate() &&
Rec->getDescribedClassTemplate()->getFriendObjectKind());
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -670,6 +670,8 @@
 - Correcly diagnose jumps into statement expressions.
   This ensures the behavior of Clang is consistent with GCC.
   (`#63682 `_)
+- Fix crash on nested templated class with template function call.
+  (`#61159 _`)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+namespace GH61159 {
+template  struct X {
+  struct I;
+};
+
+template <> struct X::I {
+  template  constexpr int f() { return ct; };
+
+  int data = 3;
+};
+
+template  struct X::I {
+  template  constexpr T f() { return ct + 1; };
+  T data = 7;
+};
+
+static_assert(X::I{}.f<17>() == 17);
+static_assert(X::I{}.data == 3);
+static_assert(X::I{}.data == 7);
+static_assert(X::I{}.f<18>() == 19);
+
+template  struct Y {
+  struct I;
+};
+
+template <> struct Y {
+  struct I {
+template  constexpr int f() { return ct; };
+int data = 3;
+  };
+};
+
+static_assert(Y::I{}.f<17>() == 17);
+static_assert(Y::I{}.data == 3);
+
+} // namespace GH61159
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -258,6 +258,11 @@
/*Final=*/false);
   }
 
+  if (const MemberSpecializationInfo *MSInfo =
+  Rec->getMemberSpecializationInfo())
+if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+  return Response::Done();
+
   bool IsFriend = Rec->getFriendObjectKind() ||
   (Rec->getDescribedClassTemplate() &&
Rec->getDescribedClassTemplate()->getFriendObjectKind());
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -670,6 +670,8 @@
 - Correcly diagnose jumps into statement expressions.
   This ensures the behavior of Clang is consistent with GCC.
   (`#63682 `_)
+- Fix crash on nested templated class with template function call.
+  (`#61159 _`)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156108: Rebase, extend the test a bit

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156108

Files:
  clang/test/SemaTemplate/gh61159.cpp


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- clang/test/SemaTemplate/gh61159.cpp
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -1,21 +1,39 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 // expected-no-diagnostics
 
-
 namespace GH61159 {
-template
-struct X {
-  struct impl;
+template  struct X {
+  struct I;
 };
 
+template <> struct X::I {
+  template  constexpr int f() { return ct; };
+
+  int data = 3;
+};
 
-template <>
-struct X::impl {
-template
-int f() { return ct; };
+template  struct X::I {
+  template  constexpr T f() { return ct + 1; };
+  T data = 7;
 };
 
-void foo() {
-X::impl{}.f<17>();
-}
-}
+static_assert(X::I{}.f<17>() == 17);
+static_assert(X::I{}.data == 3);
+static_assert(X::I{}.data == 7);
+static_assert(X::I{}.f<18>() == 19);
+
+template  struct Y {
+  struct I;
+};
+
+template <> struct Y {
+  struct I {
+template  constexpr int f() { return ct; };
+int data = 3;
+  };
+};
+
+static_assert(Y::I{}.f<17>() == 17);
+static_assert(Y::I{}.data == 3);
+
+} // namespace GH61159


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- clang/test/SemaTemplate/gh61159.cpp
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -1,21 +1,39 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 // expected-no-diagnostics
 
-
 namespace GH61159 {
-template
-struct X {
-  struct impl;
+template  struct X {
+  struct I;
 };
 
+template <> struct X::I {
+  template  constexpr int f() { return ct; };
+
+  int data = 3;
+};
 
-template <>
-struct X::impl {
-template
-int f() { return ct; };
+template  struct X::I {
+  template  constexpr T f() { return ct + 1; };
+  T data = 7;
 };
 
-void foo() {
-X::impl{}.f<17>();
-}
-}
+static_assert(X::I{}.f<17>() == 17);
+static_assert(X::I{}.data == 3);
+static_assert(X::I{}.data == 7);
+static_assert(X::I{}.f<18>() == 19);
+
+template  struct Y {
+  struct I;
+};
+
+template <> struct Y {
+  struct I {
+template  constexpr int f() { return ct; };
+int data = 3;
+  };
+};
+
+static_assert(Y::I{}.f<17>() == 17);
+static_assert(Y::I{}.data == 3);
+
+} // namespace GH61159
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp:48
 
-struct InitWithLambda {
-int b = [](int error = undefined()) { // expected-error {{cannot take 
address of consteval function 'undefined' outside of an immediate invocation}}
+struct InitWithLambda { // expected-note {{'InitWithLambda' is an immediate 
constructor because the default initializer of 'b' contains a call to a 
consteval function 'undefined' and that call is not a constant expression}}
+int b = [](int error = undefined()) {  // expected-note {{undefined 
function 'undefined' cannot be used in a constant expression}}

cor3ntin wrote:
> Fznamznon wrote:
> > Maybe it makes sense to print `InitWithLambda::InitWithLambda` so it looks 
> > same as "call to immediate function ... is not a constant expression" 
> > message and makes it more obvious.
> I don't disagree but for some reason default constructors are printed that 
> way... I'd have to make the diagnostics even more complicated and it did not 
> feel worth it.
Ok, I see! Yes, I don't feel that making it more complicated is worth it too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

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


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Just a couple of NITs otherwise LGTM




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:2506
+
+  for (auto A : E->arguments())
+if (!getDerived().TraverseStmt(A))





Comment at: clang/lib/Sema/SemaDeclCXX.cpp:2546
   } Visitor(*this, FD);
-  Visitor.TraverseStmt(FD->getBody());
+  Visitor.TraverseDecl(const_cast(FD));
 }

Maybe it makes sense to drop `const` from `FD` parameter instead of doing a 
`const_cast`?



Comment at: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp:48
 
-struct InitWithLambda {
-int b = [](int error = undefined()) { // expected-error {{cannot take 
address of consteval function 'undefined' outside of an immediate invocation}}
+struct InitWithLambda { // expected-note {{'InitWithLambda' is an immediate 
constructor because the default initializer of 'b' contains a call to a 
consteval function 'undefined' and that call is not a constant expression}}
+int b = [](int error = undefined()) {  // expected-note {{undefined 
function 'undefined' cannot be used in a constant expression}}

Maybe it makes sense to print `InitWithLambda::InitWithLambda` so it looks same 
as "call to immediate function ... is not a constant expression" message and 
makes it more obvious.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

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


[PATCH] D155842: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 543420.
Fznamznon added a comment.

Rebase to maybe fix precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155842

Files:
  clang/lib/Frontend/HeaderIncludeGen.cpp


Index: clang/lib/Frontend/HeaderIncludeGen.cpp
===
--- clang/lib/Frontend/HeaderIncludeGen.cpp
+++ clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback =(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,


Index: clang/lib/Frontend/HeaderIncludeGen.cpp
===
--- clang/lib/Frontend/HeaderIncludeGen.cpp
+++ clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback =(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155849: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 543417.
Fznamznon added a comment.

Rebase, fix format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155849

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,11 @@
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
+
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction , const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,11 @@
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
+
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction , const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155846: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon abandoned this revision.
Fznamznon added a comment.

Oh shoot, I trusted the tool too much to not double check that the copy ctor is 
already deleted. Thank you for the catch and for the bug report.
I'll abandon this change then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155846

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


[PATCH] D155849: [NFC][clang] Fix static analyzer concerns

2023-07-20 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

OMPTransformDirectiveScopeRAII doesn't have user-written copy
constructor/assignment operator but it frees memory in the destructor.
Delete these members since doesn't seem that OMPTransformDirectiveScopeRAII
objects are intended for copy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155849

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,10 @@
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction , const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,10 @@
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction , const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155846: [NFC][clang] Fix static analyzer concerns

2023-07-20 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Preprocessor class can own and free resources in its destructor, but
doesn't have user-written copy constructor or assignment operator, hence
any copy attempt will use compiler-generated copy constructor and may
cause use-after-free problems.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155846

Files:
  clang/include/clang/Lex/Preprocessor.h


Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -1166,6 +1166,9 @@
 
   ~Preprocessor();
 
+  Preprocessor(const Preprocessor &) = delete;
+  Preprocessor =(const Preprocessor &) = delete;
+
   /// Initialize the preprocessor using information about the target.
   ///
   /// \param Target is owned by the caller and must remain valid for the


Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -1166,6 +1166,9 @@
 
   ~Preprocessor();
 
+  Preprocessor(const Preprocessor &) = delete;
+  Preprocessor =(const Preprocessor &) = delete;
+
   /// Initialize the preprocessor using information about the target.
   ///
   /// \param Target is owned by the caller and must remain valid for the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155842: [NFC][clang] Fix static analyzer concerns

2023-07-20 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

HeaderIncludesCallback and HeaderIncludesJSONCallback classes may own
resources and free them in the destructor. However they don't have copy
user-written constructors/assignment operators, so an attempt to copy a
HeaderIncludesCallback object will use compiler-generated copy
constructor which will only do dummy copy and afterwards there will be
use-after-free issues.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155842

Files:
  clang/lib/Frontend/HeaderIncludeGen.cpp


Index: clang/lib/Frontend/HeaderIncludeGen.cpp
===
--- clang/lib/Frontend/HeaderIncludeGen.cpp
+++ clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback =(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,


Index: clang/lib/Frontend/HeaderIncludeGen.cpp
===
--- clang/lib/Frontend/HeaderIncludeGen.cpp
+++ clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback =(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155705: [clang] Fix specialization of non-templated member classes of class templates

2023-07-20 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> Can you explain why the fix fixes the bug?

Sure, let me try. To be honest, I'm not very familiar with the code either, so 
I'll describe how I came to the fix. I'll be using added test 
`clang/test/SemaTemplate/gh61159.cpp` as example of failing code. The issue 
happens when instantiating `X::impl::f`.
So, the original assertion reported by 
https://github.com/llvm/llvm-project/issues/61159 happens in a function 
`Sema::BuildExpressionFromIntegralTemplateArgument`, because it expects 
non-type integral argument, but receives type argument:

  clang/lib/Sema/SemaTemplate.cpp
  7955Sema::BuildExpressionFromIntegralTemplateArgument(const 
TemplateArgument ,
  7956  SourceLocation 
Loc) {   
  7957  assert(Arg.getKind() == TemplateArgument::Integral &&   

  7958 "Operation is only valid for integral template 
arguments");
  
  (gdb) p Arg.dump()
  int  // that is type argument `int` from outer specialization of struct X.

So, let's see where the argument comes from, for this I went two frames of back 
upper, to function `TemplateInstantiator::TransformTemplateParmRefExpr`:

  clang/lib/Sema/SemaTemplateInstantiate.cpp
  1789  TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), 
NTTP->getPosition());
  
  NTTP is a NonTypeTemplateParmDecl that represents template parameter ct of 
function f
  (gdb) p NTTP->dump()
  NonTypeTemplateParmDecl 0x14b76380  col:18 referenced 
'int' depth 0 index 0 ct
  TemplateArgs is a MultiLevelTemplateArgumentList - data structure containing 
arguments for current instantiation 
  (gdb) p TemplateArgs.dump()
  NumRetainedOuterLevels: 0
  0: 
  1: <17>
  We see it has two arguments - "int" and "17", we should be processing "17" 
but instead end up with "int". Both have same indexes since there is only one 
argument possible, so they should have different depth. For "17" we have zero 
depth.
  (gdb) p NTTP->getDepth()
  $8 = 0

So, after that I went to the place where NonTypeTemplateParmDecl is created to 
see why it has depth "0" instead of "1".

  (gdb) b NonTypeTemplateParmDecl::Create
  (gdb) up several times to see where Depth parameters come from
  
  and it is here:
  clang/lib/Parse/ParseTemplate.cpp
  
  130 if (ParseTemplateParameters(TemplateParamScopes,  
  
  131 
CurTemplateDepthTracker.getDepth(), 
  132 TemplateParams, LAngleLoc, 
RAngleLoc)) {
  133   // Skip until the semi-colon or a '}'.  
  
  134   SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);  
  
  135   TryConsumeToken(tok::semi); 
  
  136   return nullptr; 
  
  137 } 
   
  
  CurTemplateDepthTracker.getDepth() is increased only if template parameter 
list of the declaration being parsed is not empty, i.e. when declaration we 
have is not an explicit specialization:
  
  139 ExprResult OptionalRequiresClauseConstraintER;
  140 if (!TemplateParams.empty()) {
  141   isSpecialization = false;   
  142   ++CurTemplateDepthTracker;  
  
  
  But this is exactly what we have! So we end up having zero depth for our 
NTTP.   

I tried increasing depth unconditionally but it broke handful of tests and 
seems zero depth for cases like this is on purpose so that is not the solution. 
So I figured similar test case which doesn't crash:

  template <>
  struct X {
struct impl {
  template
  int f() { return ct; };
   };
  };
  }

And went through the clang code that was failing for the original example:

  7954ExprResult
 
  7955Sema::BuildExpressionFromIntegralTemplateArgument(const 
TemplateArgument , 
  7956  SourceLocation 
Loc) {
  7957  assert(Arg.getKind() == TemplateArgument::Integral &&   
  
  
  (gdb) p Arg.dump()
  17 // correct!
  
  Let's go see corresponding NTTP and MultiLevelTemplateArgumentList :
  
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  1789  TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), 
NTTP->getPosition());
  
  (gdb) p NTTP->dump()
  NonTypeTemplateParmDecl 0x14b761b8  col:15 referenced 
'int' depth 0 index 0 ct // all same
  
  (gdb) p TemplateArgs.dump()
  NumRetainedOuterLevels: 0
  0: <17>
  
  TemplateArgs doesn't have "int" paramter at all so all is correct.

So, after 

[PATCH] D155705: [clang] Fix specialization of non-templated member classes of class templates

2023-07-19 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Explicit specialization doesn't increase depth of template parameters,
so need to be careful when gathering template parameters for
instantiation.
For the case:

  template
  struct X {
struct impl;
  };
  
  template <>
  struct X::impl {
  template
  int f() { return ct; };
  };

instantiation of `f` used to crash because type template parameter
`int` of explicit specialization was taken into account, but non-type
template parameter `ct` had zero depth and index so wrong parameter
ended up inside of a wrong handler.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155705

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/gh61159.cpp


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+
+namespace GH61159 {
+template
+struct X {
+  struct impl;
+};
+
+
+template <>
+struct X::impl {
+template
+int f() { return ct; };
+};
+
+void foo() {
+X::impl{}.f<17>();
+}
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -258,6 +258,11 @@
/*Final=*/false);
   }
 
+  if (const MemberSpecializationInfo *MSInfo =
+  Rec->getMemberSpecializationInfo())
+if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+  return Response::Done();
+
   bool IsFriend = Rec->getFriendObjectKind() ||
   (Rec->getDescribedClassTemplate() &&
Rec->getDescribedClassTemplate()->getFriendObjectKind());
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -652,6 +652,8 @@
   (`#63169 _`)
 - Fix crash when casting an object to an array type.
   (`#63758 _`)
+- Fix crash on nested templated class with template function call.
+  (`#61159 _`)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+
+namespace GH61159 {
+template
+struct X {
+  struct impl;
+};
+
+
+template <>
+struct X::impl {
+template
+int f() { return ct; };
+};
+
+void foo() {
+X::impl{}.f<17>();
+}
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -258,6 +258,11 @@
/*Final=*/false);
   }
 
+  if (const MemberSpecializationInfo *MSInfo =
+  Rec->getMemberSpecializationInfo())
+if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+  return Response::Done();
+
   bool IsFriend = Rec->getFriendObjectKind() ||
   (Rec->getDescribedClassTemplate() &&
Rec->getDescribedClassTemplate()->getFriendObjectKind());
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -652,6 +652,8 @@
   (`#63169 _`)
 - Fix crash when casting an object to an array type.
   (`#63758 _`)
+- Fix crash on nested templated class with template function call.
+  (`#61159 _`)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-07-19 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 541915.
Fznamznon added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -310,3 +310,23 @@
   constexpr S s(0); // beforecxx20-warning {{aggregate initialization of type 
'const S' from a parenthesized list of values is a C++20 extension}} \
 // expected-error {{constexpr variable 's' must be 
initialized by a constant expression}}
 }
+
+namespace gh62863 {
+int (&)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[2] = static_cast(42); // expected-error {{reference to 
type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+
+int (&)[] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[1] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[2] = (int[])(42); // expected-error {{reference to type 'int[2]' 
could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[3] = (int[3])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8853,6 +8853,18 @@
   }
 }
   }
+  if (isa(E)) {
+QualType DestType = E->getType();
+if (const auto *IAT = Context.getAsIncompleteArrayType(DestType)) {
+  // C++20 [expr.static.cast]p.4: ... If T is “array of unknown bound of 
U”,
+  // this direct-initialization defines the type of the expression as U[1]
+  QualType ResultType = Context.getConstantArrayType(
+  IAT->getElementType(),
+  llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1),
+  /*SizeExpr=*/nullptr, ArrayType::Normal, /*IndexTypeQuals=*/0);
+  E->setType(ResultType);
+}
+  }
 }
 
 QualType Sema::getCompletedType(Expr *E) {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -652,6 +652,8 @@
   (`#63169 _`)
 - Fix crash when casting an object to an array type.
   (`#63758 _`)
+- Fixed `static_cast` to array of unknown bound.
+  (`#62863 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -310,3 +310,23 @@
   constexpr S s(0); // beforecxx20-warning {{aggregate initialization of type 'const S' from a parenthesized list of values is a C++20 extension}} \
 // expected-error {{constexpr variable 's' must be initialized by a constant expression}}
 }
+
+namespace gh62863 {
+int (&)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[2] = static_cast(42); // expected-error {{reference to type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a parenthesized list of values is a C++20 extension}}
+
+int 

[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-19 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:18441
   SemaRef.Diag(ND->getLocation(), diag::note_declared_at);
+  if (auto Context =
+  SemaRef.InnermostDeclarationWithDelayedImmediateInvocations()) {

cor3ntin wrote:
> Fznamznon wrote:
> > I would prefer spelling type here.
> that's an 
> `std::optional`, 
> I'm not sure spelling it improved readability. But i can change it!
Uh, yeah, doesn't seem to be improving readability. NVM :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

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


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-19 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:2441
 bool Sema::CheckImmediateEscalatingFunctionDefinition(
-FunctionDecl *FD, bool HasImmediateEscalatingExpression) {
-  if (!FD->hasBody() || !getLangOpts().CPlusPlus20 ||
-  !FD->isImmediateEscalating())
+FunctionDecl *FD, const sema::FunctionScopeInfo *FSI) {
+  if (!getLangOpts().CPlusPlus20 || !FD->isImmediateEscalating())

Is there any logical value in passing `FunctionScopeInfo` instead of a bool 
flag?



Comment at: clang/lib/Sema/SemaExpr.cpp:6221
 
+  CXXThisScopeRAII This(*this, Field->getParent(), Qualifiers(),
+Field->getParent() != nullptr);

Could you please describe why this change is required?



Comment at: clang/lib/Sema/SemaExpr.cpp:18441
   SemaRef.Diag(ND->getLocation(), diag::note_declared_at);
+  if (auto Context =
+  SemaRef.InnermostDeclarationWithDelayedImmediateInvocations()) {

I would prefer spelling type here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

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


[PATCH] D155164: [clangd][NFC] Remove dead code

2023-07-13 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8b4a27f410ba: [clangd][NFC] Remove dead code (authored by 
Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155164

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -879,7 +879,6 @@
 Opts.ResourceDir = ResourceDir;
   Opts.BuildDynamicSymbolIndex = true;
   std::vector> IdxStack;
-  std::unique_ptr StaticIdx;
 #if CLANGD_ENABLE_REMOTE
   if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
 llvm::errs() << "remote-index-address and project-path have to be "
@@ -900,14 +899,7 @@
   Opts.ReferencesLimit = ReferencesLimit;
   Opts.Rename.LimitFiles = RenameFileLimit;
   auto PAI = createProjectAwareIndex(loadExternalIndex, Sync);
-  if (StaticIdx) {
-IdxStack.emplace_back(std::move(StaticIdx));
-IdxStack.emplace_back(
-std::make_unique(PAI.get(), IdxStack.back().get()));
-Opts.StaticIndex = IdxStack.back().get();
-  } else {
-Opts.StaticIndex = PAI.get();
-  }
+  Opts.StaticIndex = PAI.get();
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.MemoryCleanup = getMemoryCleanupFunction();
 
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -402,12 +402,6 @@
   if (!ExprType || ExprType->isVoidType())
 return false;
 
-  // Must know the type of the result in order to spell it, or instead use
-  // `auto` in C++.
-  if (!N->getDeclContext().getParentASTContext().getLangOpts().CPlusPlus11 &&
-  !ExprType)
-return false;
-
   // A plain reference to a name (e.g. variable) isn't  worth extracting.
   // FIXME: really? What if it's e.g. `std::is_same::value`?
   if (llvm::isa(E))


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -879,7 +879,6 @@
 Opts.ResourceDir = ResourceDir;
   Opts.BuildDynamicSymbolIndex = true;
   std::vector> IdxStack;
-  std::unique_ptr StaticIdx;
 #if CLANGD_ENABLE_REMOTE
   if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
 llvm::errs() << "remote-index-address and project-path have to be "
@@ -900,14 +899,7 @@
   Opts.ReferencesLimit = ReferencesLimit;
   Opts.Rename.LimitFiles = RenameFileLimit;
   auto PAI = createProjectAwareIndex(loadExternalIndex, Sync);
-  if (StaticIdx) {
-IdxStack.emplace_back(std::move(StaticIdx));
-IdxStack.emplace_back(
-std::make_unique(PAI.get(), IdxStack.back().get()));
-Opts.StaticIndex = IdxStack.back().get();
-  } else {
-Opts.StaticIndex = PAI.get();
-  }
+  Opts.StaticIndex = PAI.get();
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.MemoryCleanup = getMemoryCleanupFunction();
 
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -402,12 +402,6 @@
   if (!ExprType || ExprType->isVoidType())
 return false;
 
-  // Must know the type of the result in order to spell it, or instead use
-  // `auto` in C++.
-  if (!N->getDeclContext().getParentASTContext().getLangOpts().CPlusPlus11 &&
-  !ExprType)
-return false;
-
   // A plain reference to a name (e.g. variable) isn't  worth extracting.
   // FIXME: really? What if it's e.g. `std::is_same::value`?
   if (llvm::isa(E))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155164: [clangd][NFC] Remove dead code

2023-07-13 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

refactor/tweaks/ExtractVariable.cpp:
Condition (!C++ && !ExprType) is never true because if ExprType was null
we would early-exit earlier.

tool/ClangdMain.cpp:
StaticIdx variable is not initialized before check, so checking it
doesn't make sense.

Found by static analyzer tool.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155164

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -879,7 +879,6 @@
 Opts.ResourceDir = ResourceDir;
   Opts.BuildDynamicSymbolIndex = true;
   std::vector> IdxStack;
-  std::unique_ptr StaticIdx;
 #if CLANGD_ENABLE_REMOTE
   if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
 llvm::errs() << "remote-index-address and project-path have to be "
@@ -900,14 +899,7 @@
   Opts.ReferencesLimit = ReferencesLimit;
   Opts.Rename.LimitFiles = RenameFileLimit;
   auto PAI = createProjectAwareIndex(loadExternalIndex, Sync);
-  if (StaticIdx) {
-IdxStack.emplace_back(std::move(StaticIdx));
-IdxStack.emplace_back(
-std::make_unique(PAI.get(), IdxStack.back().get()));
-Opts.StaticIndex = IdxStack.back().get();
-  } else {
-Opts.StaticIndex = PAI.get();
-  }
+  Opts.StaticIndex = PAI.get();
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.MemoryCleanup = getMemoryCleanupFunction();
 
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -402,12 +402,6 @@
   if (!ExprType || ExprType->isVoidType())
 return false;
 
-  // Must know the type of the result in order to spell it, or instead use
-  // `auto` in C++.
-  if (!N->getDeclContext().getParentASTContext().getLangOpts().CPlusPlus11 &&
-  !ExprType)
-return false;
-
   // A plain reference to a name (e.g. variable) isn't  worth extracting.
   // FIXME: really? What if it's e.g. `std::is_same::value`?
   if (llvm::isa(E))


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -879,7 +879,6 @@
 Opts.ResourceDir = ResourceDir;
   Opts.BuildDynamicSymbolIndex = true;
   std::vector> IdxStack;
-  std::unique_ptr StaticIdx;
 #if CLANGD_ENABLE_REMOTE
   if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
 llvm::errs() << "remote-index-address and project-path have to be "
@@ -900,14 +899,7 @@
   Opts.ReferencesLimit = ReferencesLimit;
   Opts.Rename.LimitFiles = RenameFileLimit;
   auto PAI = createProjectAwareIndex(loadExternalIndex, Sync);
-  if (StaticIdx) {
-IdxStack.emplace_back(std::move(StaticIdx));
-IdxStack.emplace_back(
-std::make_unique(PAI.get(), IdxStack.back().get()));
-Opts.StaticIndex = IdxStack.back().get();
-  } else {
-Opts.StaticIndex = PAI.get();
-  }
+  Opts.StaticIndex = PAI.get();
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.MemoryCleanup = getMemoryCleanupFunction();
 
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -402,12 +402,6 @@
   if (!ExprType || ExprType->isVoidType())
 return false;
 
-  // Must know the type of the result in order to spell it, or instead use
-  // `auto` in C++.
-  if (!N->getDeclContext().getParentASTContext().getLangOpts().CPlusPlus11 &&
-  !ExprType)
-return false;
-
   // A plain reference to a name (e.g. variable) isn't  worth extracting.
   // FIXME: really? What if it's e.g. `std::is_same::value`?
   if (llvm::isa(E))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-07-12 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 539502.
Fznamznon added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -273,7 +273,6 @@
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a 
parenthesized list of values is a C++20 extension}}
 }
 
-
 namespace GH63278 {
 struct S {
   int a = 0;
@@ -294,3 +293,23 @@
 }
 
 }
+
+namespace gh62863 {
+int (&)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[2] = static_cast(42); // expected-error {{reference to 
type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+
+int (&)[] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[1] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[2] = (int[])(42); // expected-error {{reference to type 'int[2]' 
could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[3] = (int[3])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8853,6 +8853,18 @@
   }
 }
   }
+  if (isa(E)) {
+QualType DestType = E->getType();
+if (const auto *IAT = Context.getAsIncompleteArrayType(DestType)) {
+  // C++20 [expr.static.cast]p.4: ... If T is “array of unknown bound of 
U”,
+  // this direct-initialization defines the type of the expression as U[1]
+  QualType ResultType = Context.getConstantArrayType(
+  IAT->getElementType(),
+  llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1),
+  /*SizeExpr=*/nullptr, ArrayType::Normal, /*IndexTypeQuals=*/0);
+  E->setType(ResultType);
+}
+  }
 }
 
 QualType Sema::getCompletedType(Expr *E) {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -591,6 +591,8 @@
   (`#38717 _`).
 - Fix an assertion when using ``\u0024`` (``$``) as an identifier, by 
disallowing
   that construct (`#62133 
_`).
+- Fixed `static_cast` to array of unknown bound.
+  (`#62863 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -273,7 +273,6 @@
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
 }
 
-
 namespace GH63278 {
 struct S {
   int a = 0;
@@ -294,3 +293,23 @@
 }
 
 }
+
+namespace gh62863 {
+int (&)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[2] = static_cast(42); // expected-error {{reference to type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a parenthesized list of values is a C++20 extension}}
+
+int (&)[] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate 

[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-07-12 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[PATCH] D154689: [clang] Correct calculation of MemberExpr's dependence

2023-07-10 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa0130fc51cbc: [clang] Correct calculation of 
MemberExprs dependence (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154689

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp

Index: clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -306,3 +306,22 @@
 f(A()); // OK
   }
 }
+
+namespace GH48731 {
+template  using N = int;
+struct X { template void f(); };
+template decltype((X().f>(), ...)) x;
+template decltype(((new X())->f>(), ...)) y;
+
+struct A {};
+template using Tfoo = A;
+template void foo(A a) {
+  (a.~Tfoo(), ...);
+}
+
+struct B { operator int(); };
+template using Tbar = int;
+template void bar(B b) {
+  (b.operator Tbar(), ...);
+}
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1759,16 +1759,7 @@
   MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl,
NameInfo, T, VK, OK, NOUR);
 
-  // FIXME: remove remaining dependence computation to computeDependence().
-  auto Deps = E->getDependence();
   if (HasQualOrFound) {
-// FIXME: Wrong. We should be looking at the member declaration we found.
-if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent())
-  Deps |= ExprDependence::TypeValueInstantiation;
-else if (QualifierLoc &&
- QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())
-  Deps |= ExprDependence::Instantiation;
-
 E->MemberExprBits.HasQualifierOrFoundDecl = true;
 
 MemberExprNameQualifier *NQ =
@@ -1780,13 +1771,16 @@
   E->MemberExprBits.HasTemplateKWAndArgsInfo =
   TemplateArgs || TemplateKWLoc.isValid();
 
+  // FIXME: remove remaining dependence computation to computeDependence().
+  auto Deps = E->getDependence();
   if (TemplateArgs) {
 auto TemplateArgDeps = TemplateArgumentDependence::None;
 E->getTrailingObjects()->initializeFrom(
 TemplateKWLoc, *TemplateArgs,
 E->getTrailingObjects(), TemplateArgDeps);
-if (TemplateArgDeps & TemplateArgumentDependence::Instantiation)
-  Deps |= ExprDependence::Instantiation;
+for (const TemplateArgumentLoc  : TemplateArgs->arguments()) {
+  Deps |= toExprDependence(ArgLoc.getArgument().getDependence());
+}
   } else if (TemplateKWLoc.isValid()) {
 E->getTrailingObjects()->initializeFrom(
 TemplateKWLoc);
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -611,9 +611,24 @@
   return D;
 }
 
+static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
+  auto D = ExprDependence::None;
+  if (Name.isInstantiationDependent())
+D |= ExprDependence::Instantiation;
+  if (Name.containsUnexpandedParameterPack())
+D |= ExprDependence::UnexpandedPack;
+  return D;
+}
+
 ExprDependence clang::computeDependence(MemberExpr *E) {
-  auto *MemberDecl = E->getMemberDecl();
   auto D = E->getBase()->getDependence();
+  D |= getDependenceInExpr(E->getMemberNameInfo());
+
+  if (auto *NNS = E->getQualifier())
+D |= toExprDependence(NNS->getDependence() &
+  ~NestedNameSpecifierDependence::Dependent);
+
+  auto *MemberDecl = E->getMemberDecl();
   if (FieldDecl *FD = dyn_cast(MemberDecl)) {
 DeclContext *DC = MemberDecl->getDeclContext();
 // dyn_cast_or_null is used to handle objC variables which do not
@@ -723,15 +738,6 @@
   return D;
 }
 
-static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
-  auto D = ExprDependence::None;
-  if (Name.isInstantiationDependent())
-D |= ExprDependence::Instantiation;
-  if (Name.containsUnexpandedParameterPack())
-D |= ExprDependence::UnexpandedPack;
-  return D;
-}
-
 ExprDependence
 clang::computeDependence(OverloadExpr *E, bool KnownDependent,
  bool KnownInstantiationDependent,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -573,6 +573,9 @@
 - Stop evaluating a constant expression if the condition expression which in
   switch statement contains errors.
   (`#63453 _`)
+- Fixed false positive error diagnostic when pack expansion appears in template
+  

[PATCH] D154689: [clang] Correct calculation of MemberExpr's dependence

2023-07-10 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 538531.
Fznamznon added a comment.

Rebase, add tests for dependent NameInfo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154689

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp

Index: clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -306,3 +306,22 @@
 f(A()); // OK
   }
 }
+
+namespace GH48731 {
+template  using N = int;
+struct X { template void f(); };
+template decltype((X().f>(), ...)) x;
+template decltype(((new X())->f>(), ...)) y;
+
+struct A {};
+template using Tfoo = A;
+template void foo(A a) {
+  (a.~Tfoo(), ...);
+}
+
+struct B { operator int(); };
+template using Tbar = int;
+template void bar(B b) {
+  (b.operator Tbar(), ...);
+}
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1759,16 +1759,7 @@
   MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl,
NameInfo, T, VK, OK, NOUR);
 
-  // FIXME: remove remaining dependence computation to computeDependence().
-  auto Deps = E->getDependence();
   if (HasQualOrFound) {
-// FIXME: Wrong. We should be looking at the member declaration we found.
-if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent())
-  Deps |= ExprDependence::TypeValueInstantiation;
-else if (QualifierLoc &&
- QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())
-  Deps |= ExprDependence::Instantiation;
-
 E->MemberExprBits.HasQualifierOrFoundDecl = true;
 
 MemberExprNameQualifier *NQ =
@@ -1780,13 +1771,16 @@
   E->MemberExprBits.HasTemplateKWAndArgsInfo =
   TemplateArgs || TemplateKWLoc.isValid();
 
+  // FIXME: remove remaining dependence computation to computeDependence().
+  auto Deps = E->getDependence();
   if (TemplateArgs) {
 auto TemplateArgDeps = TemplateArgumentDependence::None;
 E->getTrailingObjects()->initializeFrom(
 TemplateKWLoc, *TemplateArgs,
 E->getTrailingObjects(), TemplateArgDeps);
-if (TemplateArgDeps & TemplateArgumentDependence::Instantiation)
-  Deps |= ExprDependence::Instantiation;
+for (const TemplateArgumentLoc  : TemplateArgs->arguments()) {
+  Deps |= toExprDependence(ArgLoc.getArgument().getDependence());
+}
   } else if (TemplateKWLoc.isValid()) {
 E->getTrailingObjects()->initializeFrom(
 TemplateKWLoc);
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -611,9 +611,24 @@
   return D;
 }
 
+static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
+  auto D = ExprDependence::None;
+  if (Name.isInstantiationDependent())
+D |= ExprDependence::Instantiation;
+  if (Name.containsUnexpandedParameterPack())
+D |= ExprDependence::UnexpandedPack;
+  return D;
+}
+
 ExprDependence clang::computeDependence(MemberExpr *E) {
-  auto *MemberDecl = E->getMemberDecl();
   auto D = E->getBase()->getDependence();
+  D |= getDependenceInExpr(E->getMemberNameInfo());
+
+  if (auto *NNS = E->getQualifier())
+D |= toExprDependence(NNS->getDependence() &
+  ~NestedNameSpecifierDependence::Dependent);
+
+  auto *MemberDecl = E->getMemberDecl();
   if (FieldDecl *FD = dyn_cast(MemberDecl)) {
 DeclContext *DC = MemberDecl->getDeclContext();
 // dyn_cast_or_null is used to handle objC variables which do not
@@ -723,15 +738,6 @@
   return D;
 }
 
-static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
-  auto D = ExprDependence::None;
-  if (Name.isInstantiationDependent())
-D |= ExprDependence::Instantiation;
-  if (Name.containsUnexpandedParameterPack())
-D |= ExprDependence::UnexpandedPack;
-  return D;
-}
-
 ExprDependence
 clang::computeDependence(OverloadExpr *E, bool KnownDependent,
  bool KnownInstantiationDependent,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -573,6 +573,9 @@
 - Stop evaluating a constant expression if the condition expression which in
   switch statement contains errors.
   (`#63453 _`)
+- Fixed false positive error diagnostic when pack expansion appears in template
+  parameters of a member expression.
+  (`#48731 `_)
 
 Bug Fixes to Compiler 

[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-07-07 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 538165.
Fznamznon added a comment.

Rebase, move the logic, modify c-style casts as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -273,7 +273,6 @@
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a 
parenthesized list of values is a C++20 extension}}
 }
 
-
 namespace GH63278 {
 struct S {
   int a = 0;
@@ -294,3 +293,23 @@
 }
 
 }
+
+namespace gh62863 {
+int (&)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[2] = static_cast(42); // expected-error {{reference to 
type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+
+int (&)[] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[1] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[2] = (int[])(42); // expected-error {{reference to type 'int[2]' 
could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[3] = (int[3])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8853,6 +8853,18 @@
   }
 }
   }
+  if (isa(E)) {
+QualType DestType = E->getType();
+if (const auto *IAT = Context.getAsIncompleteArrayType(DestType)) {
+  // C++20 [expr.static.cast]p.4: ... If T is “array of unknown bound of 
U”,
+  // this direct-initialization defines the type of the expression as U[1]
+  QualType ResultType = Context.getConstantArrayType(
+  IAT->getElementType(),
+  llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1),
+  /*SizeExpr=*/nullptr, ArrayType::Normal, /*IndexTypeQuals=*/0);
+  E->setType(ResultType);
+}
+  }
 }
 
 QualType Sema::getCompletedType(Expr *E) {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -573,6 +573,8 @@
 - Stop evaluating a constant expression if the condition expression which in
   switch statement contains errors.
   (`#63453 _`)
+- Fixed `static_cast` to array of unknown bound.
+  (`#62863 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -273,7 +273,6 @@
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
 }
 
-
 namespace GH63278 {
 struct S {
   int a = 0;
@@ -294,3 +293,23 @@
 }
 
 }
+
+namespace gh62863 {
+int (&)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[2] = static_cast(42); // expected-error {{reference to type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a parenthesized list of values is a C++20 extension}}
+
+int (&)[] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of 

[PATCH] D154689: [clang] Correct calculation of MemberExpr's dependence

2023-07-07 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

In D154689#4480249 , @cor3ntin wrote:

> I think this makes sense and it implements richard's suggestion. 
> However, it's missing a release note, can you add that before landing? 
> Thanks

Thank you for the review.
I think I added a release note here - 
https://reviews.llvm.org/D154689#change-RNUd6wICb9iD . Is something else needed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154689

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


[PATCH] D154689: [clang] Correct calculation of MemberExpr's dependence

2023-07-07 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/AST/Expr.cpp:1760
 
+  // FIXME: remove remaining dependence computation to computeDependence().
+  auto Deps = E->getDependence();

cor3ntin wrote:
> Maybe we should do that now, by passing `TemplateArgs` to computeDependence?
> 
> Otherwise there is a good chance that fixme never gets fixed !
`computeDependence` is called by the constructor of `MemberExpr` which doesn't 
accept template augments. In order to do that, I would need to modify the 
constructor of `MemberExpr`.
Is it still reasonable to do as a part of this fix?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154689

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


[PATCH] D154689: [clang] Correct calculation of MemberExpr's dependence

2023-07-07 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/AST/ComputeDependence.cpp:625
   auto D = E->getBase()->getDependence();
+  D |= getDependenceInExpr(E->getMemberNameInfo());
+

While implementing this patch I was following Richard's guide from 
https://github.com/llvm/llvm-project/issues/48731#issuecomment-1529150797 . The 
problem is, I didn't manage to write a test that would fail due to clang not 
taking into account `NameInfo` dependence. Turns out in most cases where it can 
be dependent either Base itself is dependent or 
CXXPseudoDestructorExpr/CXXDependentScopeMemberExpr is created inside the 
template function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154689

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


[PATCH] D154689: [clang] Correct calculation of MemberExpr's dependence

2023-07-07 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Due to incorrect calculation false positive diagnostics were emitted.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154689

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp

Index: clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -306,3 +306,10 @@
 f(A()); // OK
   }
 }
+
+namespace GH48731 {
+template  using N = int;
+struct X { template void f(); };
+template decltype((X().f>(), ...)) x;
+template decltype(((new X())->f>(), ...)) y;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1745,16 +1745,7 @@
   MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl,
NameInfo, T, VK, OK, NOUR);
 
-  // FIXME: remove remaining dependence computation to computeDependence().
-  auto Deps = E->getDependence();
   if (HasQualOrFound) {
-// FIXME: Wrong. We should be looking at the member declaration we found.
-if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent())
-  Deps |= ExprDependence::TypeValueInstantiation;
-else if (QualifierLoc &&
- QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())
-  Deps |= ExprDependence::Instantiation;
-
 E->MemberExprBits.HasQualifierOrFoundDecl = true;
 
 MemberExprNameQualifier *NQ =
@@ -1766,13 +1757,16 @@
   E->MemberExprBits.HasTemplateKWAndArgsInfo =
   TemplateArgs || TemplateKWLoc.isValid();
 
+  // FIXME: remove remaining dependence computation to computeDependence().
+  auto Deps = E->getDependence();
   if (TemplateArgs) {
 auto TemplateArgDeps = TemplateArgumentDependence::None;
 E->getTrailingObjects()->initializeFrom(
 TemplateKWLoc, *TemplateArgs,
 E->getTrailingObjects(), TemplateArgDeps);
-if (TemplateArgDeps & TemplateArgumentDependence::Instantiation)
-  Deps |= ExprDependence::Instantiation;
+for (const TemplateArgumentLoc  : TemplateArgs->arguments()) {
+  Deps |= toExprDependence(ArgLoc.getArgument().getDependence());
+}
   } else if (TemplateKWLoc.isValid()) {
 E->getTrailingObjects()->initializeFrom(
 TemplateKWLoc);
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -611,9 +611,24 @@
   return D;
 }
 
+static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
+  auto D = ExprDependence::None;
+  if (Name.isInstantiationDependent())
+D |= ExprDependence::Instantiation;
+  if (Name.containsUnexpandedParameterPack())
+D |= ExprDependence::UnexpandedPack;
+  return D;
+}
+
 ExprDependence clang::computeDependence(MemberExpr *E) {
-  auto *MemberDecl = E->getMemberDecl();
   auto D = E->getBase()->getDependence();
+  D |= getDependenceInExpr(E->getMemberNameInfo());
+
+  if (auto *NNS = E->getQualifier())
+D |= toExprDependence(NNS->getDependence() &
+  ~NestedNameSpecifierDependence::Dependent);
+
+  auto *MemberDecl = E->getMemberDecl();
   if (FieldDecl *FD = dyn_cast(MemberDecl)) {
 DeclContext *DC = MemberDecl->getDeclContext();
 // dyn_cast_or_null is used to handle objC variables which do not
@@ -723,15 +738,6 @@
   return D;
 }
 
-static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
-  auto D = ExprDependence::None;
-  if (Name.isInstantiationDependent())
-D |= ExprDependence::Instantiation;
-  if (Name.containsUnexpandedParameterPack())
-D |= ExprDependence::UnexpandedPack;
-  return D;
-}
-
 ExprDependence
 clang::computeDependence(OverloadExpr *E, bool KnownDependent,
  bool KnownInstantiationDependent,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -568,6 +568,9 @@
 - Clang now correctly evaluates ``__has_extension (cxx_defaulted_functions)``
   and ``__has_extension (cxx_default_function_template_args)`` to 1.
   (`#61758 `_)
+- Fixed false positive error diagnostic when pack expansion appears in template
+  parameters of a member expression.
+  (`#48731 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

  1   2   3   4   5   >