[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-13 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

Thanks for the approval, could you land this for me?

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


[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-10 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

I am not sure what causes the build failure here.

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


[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-07 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/91119

>From 78a2afab67eef9a8a05ced89df0aadb56a2ec2b8 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 5 May 2024 18:05:00 +0530
Subject: [PATCH] [clang][analyzer] Check for label location bindings in
 `DereferenceChecker`

Resolves #89264
---
 .../Checkers/DereferenceChecker.cpp   | 15 ++-
 clang/test/Analysis/gh-issue-89185.c  |  7 +++
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
index 1cebfbbee77da..0355eede75eae 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -31,11 +31,13 @@ class DereferenceChecker
 : public Checker< check::Location,
   check::Bind,
   EventDispatcher > {
-  enum DerefKind { NullPointer, UndefinedPointerValue };
+  enum DerefKind { NullPointer, UndefinedPointerValue, AddressOfLabel };
 
   BugType BT_Null{this, "Dereference of null pointer", categories::LogicError};
   BugType BT_Undef{this, "Dereference of undefined pointer value",
categories::LogicError};
+  BugType BT_Label{this, "Dereference of the address of a label",
+   categories::LogicError};
 
   void reportBug(DerefKind K, ProgramStateRef State, const Stmt *S,
  CheckerContext ) const;
@@ -167,6 +169,11 @@ void DereferenceChecker::reportBug(DerefKind K, 
ProgramStateRef State,
 DerefStr1 = " results in an undefined pointer dereference";
 DerefStr2 = " results in a dereference of an undefined pointer value";
 break;
+  case DerefKind::AddressOfLabel:
+BT = _Label;
+DerefStr1 = " results in an undefined pointer dereference";
+DerefStr2 = " results in a dereference of an address of a label";
+break;
   };
 
   // Generate an error node.
@@ -287,6 +294,12 @@ void DereferenceChecker::checkBind(SVal L, SVal V, const 
Stmt *S,
   if (V.isUndef())
 return;
 
+  // One should never write to label addresses.
+  if (auto Label = L.getAs()) {
+reportBug(DerefKind::AddressOfLabel, C.getState(), S, C);
+return;
+  }
+
   const MemRegion *MR = L.getAsRegion();
   const TypedValueRegion *TVR = dyn_cast_or_null(MR);
   if (!TVR)
diff --git a/clang/test/Analysis/gh-issue-89185.c 
b/clang/test/Analysis/gh-issue-89185.c
index 8a907f198a5fd..27456e7efe885 100644
--- a/clang/test/Analysis/gh-issue-89185.c
+++ b/clang/test/Analysis/gh-issue-89185.c
@@ -7,8 +7,7 @@ void clang_analyzer_dump_ptr(char*);
 void binding_to_label_loc() {
   char *b = &
 MyLabel:
-  *b = 0; // no-crash
-  clang_analyzer_dump_ptr(b); // expected-warning {{&}}
-  clang_analyzer_dump(*b); // expected-warning {{Unknown}}
-  // FIXME: We should never reach here, as storing to a label is invalid.
+  *b = 0; // expected-warning {{Dereference of the address of a label}}
+  clang_analyzer_dump_ptr(b);
+  clang_analyzer_dump(*b);
 }

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


[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-07 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/91119

>From 5c7712d1841664a9424b98abdd22d7967d00913f Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 5 May 2024 18:05:00 +0530
Subject: [PATCH] [clang][analyzer] Check for label location bindings in
 `DereferenceChecker`

Resolves #89264
---
 .../StaticAnalyzer/Checkers/DereferenceChecker.cpp | 14 +-
 clang/test/Analysis/gh-issue-89185.c   |  7 +++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
index 1cebfbbee77da..b335cb511546b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -31,11 +31,12 @@ class DereferenceChecker
 : public Checker< check::Location,
   check::Bind,
   EventDispatcher > {
-  enum DerefKind { NullPointer, UndefinedPointerValue };
+  enum DerefKind { NullPointer, UndefinedPointerValue, AddressOfLabel };
 
   BugType BT_Null{this, "Dereference of null pointer", categories::LogicError};
   BugType BT_Undef{this, "Dereference of undefined pointer value",
categories::LogicError};
+  BugType BT_Label{this, "Dereference of the address of a label", 
categories::LogicError};
 
   void reportBug(DerefKind K, ProgramStateRef State, const Stmt *S,
  CheckerContext ) const;
@@ -167,6 +168,11 @@ void DereferenceChecker::reportBug(DerefKind K, 
ProgramStateRef State,
 DerefStr1 = " results in an undefined pointer dereference";
 DerefStr2 = " results in a dereference of an undefined pointer value";
 break;
+  case DerefKind::AddressOfLabel:
+BT = _Label;
+DerefStr1 = " results in an undefined pointer dereference";
+DerefStr2 = " results in a dereference of an address of a label";
+break;
   };
 
   // Generate an error node.
@@ -287,6 +293,12 @@ void DereferenceChecker::checkBind(SVal L, SVal V, const 
Stmt *S,
   if (V.isUndef())
 return;
 
+  // One should never write to label addresses.
+  if (auto Label = L.getAs()) {
+reportBug(DerefKind::AddressOfLabel, C.getState(), S, C);
+return;
+  }
+
   const MemRegion *MR = L.getAsRegion();
   const TypedValueRegion *TVR = dyn_cast_or_null(MR);
   if (!TVR)
diff --git a/clang/test/Analysis/gh-issue-89185.c 
b/clang/test/Analysis/gh-issue-89185.c
index 8a907f198a5fd..27456e7efe885 100644
--- a/clang/test/Analysis/gh-issue-89185.c
+++ b/clang/test/Analysis/gh-issue-89185.c
@@ -7,8 +7,7 @@ void clang_analyzer_dump_ptr(char*);
 void binding_to_label_loc() {
   char *b = &
 MyLabel:
-  *b = 0; // no-crash
-  clang_analyzer_dump_ptr(b); // expected-warning {{&}}
-  clang_analyzer_dump(*b); // expected-warning {{Unknown}}
-  // FIXME: We should never reach here, as storing to a label is invalid.
+  *b = 0; // expected-warning {{Dereference of the address of a label}}
+  clang_analyzer_dump_ptr(b);
+  clang_analyzer_dump(*b);
 }

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


[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-06 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

Should we introduce a new Kind in `DerefKind`?

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


[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-05 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

@steakhal 

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


[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-05 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/91119

>From dcc23f7751ba2ceb281a9b027907dbf849ba65c6 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 5 May 2024 18:05:00 +0530
Subject: [PATCH] [clang][analyzer] Check for label location bindings in
 `DereferenceChecker`

Resolves #89264
---
 .../StaticAnalyzer/Checkers/DereferenceChecker.cpp  |  8 
 clang/test/Analysis/Issue89264.c| 13 +
 2 files changed, 21 insertions(+)
 create mode 100644 clang/test/Analysis/Issue89264.c

diff --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
index 1cebfbbee77dae..2d23d23c6c82ba 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -287,6 +287,14 @@ void DereferenceChecker::checkBind(SVal L, SVal V, const 
Stmt *S,
   if (V.isUndef())
 return;
 
+  // One should never write to label addresses.
+  if (auto Label = L.getAs()) {
+llvm::errs() << "WRITING TO LABEL: " << L << "\n";
+llvm::errs() << "Fatal Error: " << "Dereference of the address of a label"
+ << "\n";
+return;
+  }
+
   const MemRegion *MR = L.getAsRegion();
   const TypedValueRegion *TVR = dyn_cast_or_null(MR);
   if (!TVR)
diff --git a/clang/test/Analysis/Issue89264.c b/clang/test/Analysis/Issue89264.c
new file mode 100644
index 00..1592bc20ee56f2
--- /dev/null
+++ b/clang/test/Analysis/Issue89264.c
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
+
+void clang_analyzer_dump(char);
+void clang_analyzer_dump_ptr(char*);
+
+// https://github.com/llvm/llvm-project/issues/89185
+void binding_to_label_loc() {
+  char *b = &
+MyLabel:
+  *b = 0; // no-crash
+  clang_analyzer_dump_ptr(b); // expected-warning {{&}}
+  clang_analyzer_dump(*b); // expected-warning {{Unknown}}
+}

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


[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-05 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/91119

>From c1d62262d2545e4999f08f2ba28a12c71789926f Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 5 May 2024 18:05:00 +0530
Subject: [PATCH] [clang][analyzer] Check for label location bindings in
 `DereferenceChecker`

Resolves #89264
---
 .../StaticAnalyzer/Checkers/DereferenceChecker.cpp  |  9 +
 clang/test/Analysis/Issue89264.c| 13 +
 2 files changed, 22 insertions(+)
 create mode 100644 clang/test/Analysis/Issue89264.c

diff --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
index 1cebfbbee77dae..36593d84dac583 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -287,6 +287,15 @@ void DereferenceChecker::checkBind(SVal L, SVal V, const 
Stmt *S,
   if (V.isUndef())
 return;
 
+  // One should never write to label addresses.
+  if (auto Label = L.getAs()) {
+llvm::errs() << "WRITING TO LABEL: " << L << "\n";
+llvm::errs() << "Fatal Error: "
+ << "Dereference of the address of a label"
+ << "\n";
+return;
+  }
+
   const MemRegion *MR = L.getAsRegion();
   const TypedValueRegion *TVR = dyn_cast_or_null(MR);
   if (!TVR)
diff --git a/clang/test/Analysis/Issue89264.c b/clang/test/Analysis/Issue89264.c
new file mode 100644
index 00..1592bc20ee56f2
--- /dev/null
+++ b/clang/test/Analysis/Issue89264.c
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
+
+void clang_analyzer_dump(char);
+void clang_analyzer_dump_ptr(char*);
+
+// https://github.com/llvm/llvm-project/issues/89185
+void binding_to_label_loc() {
+  char *b = &
+MyLabel:
+  *b = 0; // no-crash
+  clang_analyzer_dump_ptr(b); // expected-warning {{&}}
+  clang_analyzer_dump(*b); // expected-warning {{Unknown}}
+}

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


[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-05 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 created 
https://github.com/llvm/llvm-project/pull/91119

Resolves #89264

Values should not be stored in addresses of labels, this throws a fatal error 
when this happens.

>From 36b1ee31d8d740cdbee6a1787d7ef81d6abeb8ad Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 5 May 2024 18:05:00 +0530
Subject: [PATCH] [clang][analyzer] Check for label location bindings in
 `DereferenceChecker`

Resolves #89264
---
 .../StaticAnalyzer/Checkers/DereferenceChecker.cpp  |  7 +++
 clang/test/Analysis/Issue89264.c| 13 +
 2 files changed, 20 insertions(+)
 create mode 100644 clang/test/Analysis/Issue89264.c

diff --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
index 1cebfbbee77dae..a1770e15ad7d52 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -286,6 +286,13 @@ void DereferenceChecker::checkBind(SVal L, SVal V, const 
Stmt *S,
   // If we're binding to a reference, check if the value is known to be null.
   if (V.isUndef())
 return;
+
+  // One should never write to label addresses.
+  if (auto Label = L.getAs()) {
+llvm::errs() << "WRITING TO LABEL: " << L << "\n";
+llvm::errs() << "Fatal Error: " << "Dereference of the address of a label" 
<< "\n";
+return;
+  }
 
   const MemRegion *MR = L.getAsRegion();
   const TypedValueRegion *TVR = dyn_cast_or_null(MR);
diff --git a/clang/test/Analysis/Issue89264.c b/clang/test/Analysis/Issue89264.c
new file mode 100644
index 00..1592bc20ee56f2
--- /dev/null
+++ b/clang/test/Analysis/Issue89264.c
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
+
+void clang_analyzer_dump(char);
+void clang_analyzer_dump_ptr(char*);
+
+// https://github.com/llvm/llvm-project/issues/89185
+void binding_to_label_loc() {
+  char *b = &
+MyLabel:
+  *b = 0; // no-crash
+  clang_analyzer_dump_ptr(b); // expected-warning {{&}}
+  clang_analyzer_dump(*b); // expected-warning {{Unknown}}
+}

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


[clang] [clang] Fix crash when inheriting from a cv-qualified type (PR #70594)

2024-04-02 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

@shafik 
Could you land this for me?

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


[clang] [clang] Fix crash when inheriting from a cv-qualified type (PR #70594)

2024-04-02 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/70594

>From caabd75b0223408ad62baff3d9d6d7f7d78c4c7f Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 29 Oct 2023 18:37:17 +0530
Subject: [PATCH] [clang] Fix a crash in debug mode

Resolves Issue #35603

This bug was caused due to the assertions being too strict,
loosened by stripping qualifiers from the base class but not
from the type of the initializer.

Added Release Notes for the same.
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/Sema/GH70594.cpp| 28 
 3 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/GH70594.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a84ff16a1e4d4..d5ce54e185600c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -486,6 +486,9 @@ Bug Fixes to C++ Support
 - Fixed a bug that prevented member function templates of class templates 
declared with a deduced return type
   from being explicitly specialized for a given implicit instantiation of the 
class template.
 
+- Fix crash when inheriting from a cv-qualified type. Fixes:
+  (`#35603 `_)
+
 Bug Fixes to AST Handling
 ^
 - Clang now properly preserves ``FoundDecls`` within a ``ConceptReference``. 
(#GH82628)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0058e86519985e..88c8eaf6ef9b6e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6456,7 +6456,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue ,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/GH70594.cpp b/clang/test/Sema/GH70594.cpp
new file mode 100644
index 00..ce98e9b12b5cba
--- /dev/null
+++ b/clang/test/Sema/GH70594.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};
+
+struct Int {};
+
+template 
+struct __tuple_leaf : _Hp {
+  constexpr __tuple_leaf() : _Hp() {}
+};
+
+constexpr __tuple_leaf t;

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


[clang] [clang] Fix crash when inheriting from a cv-qualified type (PR #70594)

2024-04-02 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/70594

>From f2a9a4137d39dd9f3896c64f41d5700774ec9204 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 29 Oct 2023 18:37:17 +0530
Subject: [PATCH] [clang] Fix a crash in debug mode

Resolves Issue #35603

This bug was caused due to the assertions being too strict,
loosened by stripping qualifiers from the base class but not
from the type of the initializer.

Added Release Notes for the same.
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/Sema/GH70594.cpp| 28 
 3 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/GH70594.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 93cc5291e2391fb..07aad91e3e2b322 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -390,6 +390,9 @@ Bug Fixes to C++ Support
 - Fixed a crash while checking constraints of a trailing requires-expression 
of a lambda, that the
   expression references to an entity declared outside of the lambda. (#GH64808)
 
+- Fix crash when inheriting from a cv-qualified type. Fixes:
+  (`#35603 `_)
+
 Bug Fixes to AST Handling
 ^
 - Clang now properly preserves ``FoundDecls`` within a ``ConceptReference``. 
(#GH82628)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7137efb7876de2b..753bbcc94db4f44 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6453,7 +6453,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue ,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/GH70594.cpp b/clang/test/Sema/GH70594.cpp
new file mode 100644
index 000..ce98e9b12b5cba3
--- /dev/null
+++ b/clang/test/Sema/GH70594.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};
+
+struct Int {};
+
+template 
+struct __tuple_leaf : _Hp {
+  constexpr __tuple_leaf() : _Hp() {}
+};
+
+constexpr __tuple_leaf t;

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


[clang] [clang] Clang should detect illegal copy constructor with template class as its parameter (PR #81251)

2024-02-29 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

I have removed this entirely, although it still may not be optimal, it did 
reduce few more test failures:

```C++
Constructor->getTemplateSpecializationKind() !=
  TSK_ImplicitInstantiation
```

Any particular suggestions apart from updating the tests?

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


[clang] [clang] Clang should detect illegal copy constructor with template class as its parameter (PR #81251)

2024-02-25 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/81251

>From bf51e9dfb160ec32b3f3a7d052c1da24f06a Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Fri, 9 Feb 2024 19:20:39 +0530
Subject: [PATCH] [clang] Clang should detect illegal copy constructor with
 template class as its parameter

Resolves #80963
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaDeclCXX.cpp |  4 +---
 clang/test/SemaCXX/GH81251.cpp | 17 +
 3 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH81251.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 529dd783ab7382..d30e13b0b1b62c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -281,6 +281,8 @@ Bug Fixes to C++ Support
   a requires-clause lie at the same depth as those of the surrounding lambda. 
This,
   in turn, results in the wrong template argument substitution during 
constraint checking.
   (`#78524 `_)
+- Clang now detects illegal copy constructor with template class as its 
parameter.
+  Fixes (`#80963 https://github.com/llvm/llvm-project/issues/80963>`_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7c009d9c8ec093..622bf0c258f138 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10921,9 +10921,7 @@ void Sema::CheckConstructor(CXXConstructorDecl 
*Constructor) {
   //   either there are no other parameters or else all other
   //   parameters have default arguments.
   if (!Constructor->isInvalidDecl() &&
-  Constructor->hasOneParamOrDefaultArgs() &&
-  Constructor->getTemplateSpecializationKind() !=
-  TSK_ImplicitInstantiation) {
+  Constructor->hasOneParamOrDefaultArgs()) {
 QualType ParamType = Constructor->getParamDecl(0)->getType();
 QualType ClassTy = Context.getTagDeclType(ClassDecl);
 if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) {
diff --git a/clang/test/SemaCXX/GH81251.cpp b/clang/test/SemaCXX/GH81251.cpp
new file mode 100644
index 00..a3e0ba07728dcc
--- /dev/null
+++ b/clang/test/SemaCXX/GH81251.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template < class T, class V > struct A
+{
+A ();
+A (A &);
+A (A < V,T >);
+// expected-error@-1 {{copy constructor must pass its first argument by 
reference}}
+};
+
+void f ()
+{
+A  (A < int, int >());
+// expected-note@-1 {{in instantiation of template class 'A' 
requested here}}
+
+A  (A < int, double >());
+}

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


[clang] [clang] Clang should detect illegal copy constructor with template class as its parameter (PR #81251)

2024-02-25 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/81251

>From 4bb6d4d1b5a813bc3a60c1bc6aab97ea863bd261 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Fri, 9 Feb 2024 19:20:39 +0530
Subject: [PATCH] [clang] Clang should detect illegal copy constructor with
 template class as its parameter

Resolves #80963
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaDeclCXX.cpp |  4 +---
 clang/test/SemaCXX/GH81251.cpp | 17 +
 3 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH81251.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 529dd783ab7382..4c46c9bae78313 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -281,6 +281,8 @@ Bug Fixes to C++ Support
   a requires-clause lie at the same depth as those of the surrounding lambda. 
This,
   in turn, results in the wrong template argument substitution during 
constraint checking.
   (`#78524 `_)
+- Clang now detects illegal copy constructor with template class as its 
parameter.
+  Fixes (`#80963 https://github.com/llvm/llvm-project/issues/80963`_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7c009d9c8ec093..622bf0c258f138 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10921,9 +10921,7 @@ void Sema::CheckConstructor(CXXConstructorDecl 
*Constructor) {
   //   either there are no other parameters or else all other
   //   parameters have default arguments.
   if (!Constructor->isInvalidDecl() &&
-  Constructor->hasOneParamOrDefaultArgs() &&
-  Constructor->getTemplateSpecializationKind() !=
-  TSK_ImplicitInstantiation) {
+  Constructor->hasOneParamOrDefaultArgs()) {
 QualType ParamType = Constructor->getParamDecl(0)->getType();
 QualType ClassTy = Context.getTagDeclType(ClassDecl);
 if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) {
diff --git a/clang/test/SemaCXX/GH81251.cpp b/clang/test/SemaCXX/GH81251.cpp
new file mode 100644
index 00..a3e0ba07728dcc
--- /dev/null
+++ b/clang/test/SemaCXX/GH81251.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template < class T, class V > struct A
+{
+A ();
+A (A &);
+A (A < V,T >);
+// expected-error@-1 {{copy constructor must pass its first argument by 
reference}}
+};
+
+void f ()
+{
+A  (A < int, int >());
+// expected-note@-1 {{in instantiation of template class 'A' 
requested here}}
+
+A  (A < int, double >());
+}

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


[clang] [clang] Clang should detect illegal copy constructor with template class as its parameter (PR #81251)

2024-02-25 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/81251

>From 5c5a91dbdf7239025d7bc5961afc0f375d3b1627 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Fri, 9 Feb 2024 19:20:39 +0530
Subject: [PATCH] [clang] Clang should detect illegal copy constructor with
 template class as its parameter

Resolves #80963
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaDeclCXX.cpp |  4 +---
 clang/test/SemaCXX/GH81251.cpp | 17 +
 3 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH81251.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 529dd783ab7382..8bd80a199ed3b0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -281,6 +281,9 @@ Bug Fixes to C++ Support
   a requires-clause lie at the same depth as those of the surrounding lambda. 
This,
   in turn, results in the wrong template argument substitution during 
constraint checking.
   (`#78524 `_)
+  (`#782154 `_`)
+- Clang now detects illegal copy constructor with template class as its 
parameter.
+  Fixes (`#80963 https://github.com/llvm/llvm-project/issues/80963`_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7c009d9c8ec093..622bf0c258f138 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10921,9 +10921,7 @@ void Sema::CheckConstructor(CXXConstructorDecl 
*Constructor) {
   //   either there are no other parameters or else all other
   //   parameters have default arguments.
   if (!Constructor->isInvalidDecl() &&
-  Constructor->hasOneParamOrDefaultArgs() &&
-  Constructor->getTemplateSpecializationKind() !=
-  TSK_ImplicitInstantiation) {
+  Constructor->hasOneParamOrDefaultArgs()) {
 QualType ParamType = Constructor->getParamDecl(0)->getType();
 QualType ClassTy = Context.getTagDeclType(ClassDecl);
 if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) {
diff --git a/clang/test/SemaCXX/GH81251.cpp b/clang/test/SemaCXX/GH81251.cpp
new file mode 100644
index 00..a3e0ba07728dcc
--- /dev/null
+++ b/clang/test/SemaCXX/GH81251.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template < class T, class V > struct A
+{
+A ();
+A (A &);
+A (A < V,T >);
+// expected-error@-1 {{copy constructor must pass its first argument by 
reference}}
+};
+
+void f ()
+{
+A  (A < int, int >());
+// expected-note@-1 {{in instantiation of template class 'A' 
requested here}}
+
+A  (A < int, double >());
+}

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


[clang] [clang] Clang should detect illegal copy constructor with template class as its parameter (PR #81251)

2024-02-25 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/81251

>From 7c58bd55bdd5c9a9cc838fec35e957f7952b2b52 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Fri, 9 Feb 2024 19:20:39 +0530
Subject: [PATCH] [clang] Clang should detect illegal copy constructor with
 template class as its parameter

Resolves #80963
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaDeclCXX.cpp |  4 +---
 clang/test/SemaCXX/GH81251.cpp | 17 +
 3 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH81251.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 649ad655905af2..fb213714e636ea 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -267,6 +267,8 @@ Bug Fixes to C++ Support
   was only accepted at namespace scope but not at local function scope.
 - Clang no longer tries to call consteval constructors at runtime when they 
appear in a member initializer.
   (`#782154 `_`)
+- Clang now detects illegal copy constructor with template class as its 
parameter.
+  Fixes (`#80963 https://github.com/llvm/llvm-project/issues/80963`_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 79263bc3ff671d..5ac250d60c9a36 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10921,9 +10921,7 @@ void Sema::CheckConstructor(CXXConstructorDecl 
*Constructor) {
   //   either there are no other parameters or else all other
   //   parameters have default arguments.
   if (!Constructor->isInvalidDecl() &&
-  Constructor->hasOneParamOrDefaultArgs() &&
-  Constructor->getTemplateSpecializationKind() !=
-  TSK_ImplicitInstantiation) {
+  Constructor->hasOneParamOrDefaultArgs()) {
 QualType ParamType = Constructor->getParamDecl(0)->getType();
 QualType ClassTy = Context.getTagDeclType(ClassDecl);
 if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) {
diff --git a/clang/test/SemaCXX/GH81251.cpp b/clang/test/SemaCXX/GH81251.cpp
new file mode 100644
index 00..a3e0ba07728dcc
--- /dev/null
+++ b/clang/test/SemaCXX/GH81251.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template < class T, class V > struct A
+{
+A ();
+A (A &);
+A (A < V,T >);
+// expected-error@-1 {{copy constructor must pass its first argument by 
reference}}
+};
+
+void f ()
+{
+A  (A < int, int >());
+// expected-note@-1 {{in instantiation of template class 'A' 
requested here}}
+
+A  (A < int, double >());
+}

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


[clang] [clang] Clang should detect illegal copy constructor with template class as its parameter (PR #81251)

2024-02-25 Thread Rajveer Singh Bharadwaj via cfe-commits

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


[clang] [clang] Fix crash when inheriting from a cv-qualified type (PR #70594)

2024-02-22 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/70594

>From a27a6858e44047bc0ff55485355932259e2f9358 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 29 Oct 2023 18:37:17 +0530
Subject: [PATCH] [clang] Fix a crash in debug mode

Resolves Issue #35603

This bug was caused due to the assertions being too strict,
loosened by stripping qualifiers from the base class but not
from the type of the initializer.

Added Release Notes for the same.
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/Sema/GH70594.cpp| 19 +++
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/GH70594.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 649ad655905af23..5087ec04fc17ded 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -268,6 +268,9 @@ Bug Fixes to C++ Support
 - Clang no longer tries to call consteval constructors at runtime when they 
appear in a member initializer.
   (`#782154 `_`)
 
+- Fix crash when inheriting from a cv-qualified type. Fixes:
+  (`#35603 `_)
+
 Bug Fixes to AST Handling
 ^
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fcf8f6591a79234..28709fb2556d3f7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6421,7 +6421,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue ,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/GH70594.cpp b/clang/test/Sema/GH70594.cpp
new file mode 100644
index 000..853552108ec2b67
--- /dev/null
+++ b/clang/test/Sema/GH70594.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};

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


[clang] [clang] [SemaCXX] Disallow deducing "this" on operator `new` and `delete` (PR #82251)

2024-02-21 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

Considering the PR sounds good to you, yes it would be great to have it merged.

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


[clang] [clang] [SemaCXX] Disallow deducing "this" on operator `new` and `delete` (PR #82251)

2024-02-21 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

> @Rajveer100 you need us to merge that for you?

I am not sure what you meant by this?

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


[clang] [clang] [SemaCXX] Disallow deducing "this" on operator `new` and `delete` (PR #82251)

2024-02-21 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/82251

>From 05dbfac2043c22bdb73d5f09221421209bfe1f22 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Mon, 19 Feb 2024 19:29:48 +0530
Subject: [PATCH] [clang] [SemaCXX] Disallow deducing "this" on operator `new`
 and `delete`

Resolves Issue #82249
---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaDeclCXX.cpp | 4 +++-
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 4 
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 649ad655905af2..213a864d25dcae 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -254,6 +254,8 @@ Bug Fixes to C++ Support
   Fixes (`#68490 `_)
 - Fix a crash when trying to call a varargs function that also has an explicit 
object parameter.
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
+- Reject explicit object parameters on `new` and `delete` operators.
+  Fixes (`#82249 ` _)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
 - Clang now classifies aggregate initialization in C++17 and newer as constant
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 79263bc3ff671d..7c009d9c8ec093 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11395,7 +11395,9 @@ void Sema::CheckExplicitObjectMemberFunction(Declarator 
,
 << ExplicitObjectParam->getSourceRange();
   }
 
-  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static) {
+  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+  (D.getContext() == clang::DeclaratorContext::Member &&
+   D.isStaticMember())) {
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*static=*/0 << IsLambda;
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 30131d6adc4db0..b8ddb9ad300034 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -16,6 +16,10 @@ struct S {
 static void f(this auto); // expected-error{{an explicit object parameter 
cannot appear in a static function}}
 virtual void f(this S); // expected-error{{an explicit object parameter 
cannot appear in a virtual function}}
 
+// new and delete are implicitly static
+void *operator new(this unsigned long); // expected-error{{an explicit 
object parameter cannot appear in a static function}}
+void operator delete(this void*); // expected-error{{an explicit object 
parameter cannot appear in a static function}}
+
 void g(this auto) const; // expected-error{{explicit object member 
function cannot have 'const' qualifier}}
 void h(this auto) &; // expected-error{{explicit object member function 
cannot have '&' qualifier}}
 void i(this auto) &&; // expected-error{{explicit object member function 
cannot have '&&' qualifier}}

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


[clang] [clang] [SemaCXX] Disallow deducing "this" on operator `new` and `delete` (PR #82251)

2024-02-21 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

@cor3ntin 
I have mistakenly added a merge commit, let me fix that.


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


[clang] [clang] [SemaCXX] Disallow deducing "this" on operator `new` and `delete` (PR #82251)

2024-02-21 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/82251

>From 05dbfac2043c22bdb73d5f09221421209bfe1f22 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Mon, 19 Feb 2024 19:29:48 +0530
Subject: [PATCH] [clang] [SemaCXX] Disallow deducing "this" on operator `new`
 and `delete`

Resolves Issue #82249
---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaDeclCXX.cpp | 4 +++-
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 4 
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 649ad655905af2..213a864d25dcae 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -254,6 +254,8 @@ Bug Fixes to C++ Support
   Fixes (`#68490 `_)
 - Fix a crash when trying to call a varargs function that also has an explicit 
object parameter.
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
+- Reject explicit object parameters on `new` and `delete` operators.
+  Fixes (`#82249 ` _)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
 - Clang now classifies aggregate initialization in C++17 and newer as constant
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 79263bc3ff671d..7c009d9c8ec093 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11395,7 +11395,9 @@ void Sema::CheckExplicitObjectMemberFunction(Declarator 
,
 << ExplicitObjectParam->getSourceRange();
   }
 
-  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static) {
+  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+  (D.getContext() == clang::DeclaratorContext::Member &&
+   D.isStaticMember())) {
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*static=*/0 << IsLambda;
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 30131d6adc4db0..b8ddb9ad300034 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -16,6 +16,10 @@ struct S {
 static void f(this auto); // expected-error{{an explicit object parameter 
cannot appear in a static function}}
 virtual void f(this S); // expected-error{{an explicit object parameter 
cannot appear in a virtual function}}
 
+// new and delete are implicitly static
+void *operator new(this unsigned long); // expected-error{{an explicit 
object parameter cannot appear in a static function}}
+void operator delete(this void*); // expected-error{{an explicit object 
parameter cannot appear in a static function}}
+
 void g(this auto) const; // expected-error{{explicit object member 
function cannot have 'const' qualifier}}
 void h(this auto) &; // expected-error{{explicit object member function 
cannot have '&' qualifier}}
 void i(this auto) &&; // expected-error{{explicit object member function 
cannot have '&&' qualifier}}

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


[clang] [clang] [SemaCXX] Disallow deducing "this" on operator `new` and `delete` (PR #82251)

2024-02-19 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/82251

>From 05dbfac2043c22bdb73d5f09221421209bfe1f22 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Mon, 19 Feb 2024 19:29:48 +0530
Subject: [PATCH] [clang] [SemaCXX] Disallow deducing "this" on operator `new`
 and `delete`

Resolves Issue #82249
---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaDeclCXX.cpp | 4 +++-
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 4 
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 649ad655905af2..213a864d25dcae 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -254,6 +254,8 @@ Bug Fixes to C++ Support
   Fixes (`#68490 `_)
 - Fix a crash when trying to call a varargs function that also has an explicit 
object parameter.
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
+- Reject explicit object parameters on `new` and `delete` operators.
+  Fixes (`#82249 ` _)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
 - Clang now classifies aggregate initialization in C++17 and newer as constant
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 79263bc3ff671d..7c009d9c8ec093 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11395,7 +11395,9 @@ void Sema::CheckExplicitObjectMemberFunction(Declarator 
,
 << ExplicitObjectParam->getSourceRange();
   }
 
-  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static) {
+  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+  (D.getContext() == clang::DeclaratorContext::Member &&
+   D.isStaticMember())) {
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*static=*/0 << IsLambda;
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 30131d6adc4db0..b8ddb9ad300034 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -16,6 +16,10 @@ struct S {
 static void f(this auto); // expected-error{{an explicit object parameter 
cannot appear in a static function}}
 virtual void f(this S); // expected-error{{an explicit object parameter 
cannot appear in a virtual function}}
 
+// new and delete are implicitly static
+void *operator new(this unsigned long); // expected-error{{an explicit 
object parameter cannot appear in a static function}}
+void operator delete(this void*); // expected-error{{an explicit object 
parameter cannot appear in a static function}}
+
 void g(this auto) const; // expected-error{{explicit object member 
function cannot have 'const' qualifier}}
 void h(this auto) &; // expected-error{{explicit object member function 
cannot have '&' qualifier}}
 void i(this auto) &&; // expected-error{{explicit object member function 
cannot have '&&' qualifier}}

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


[clang] [clang] [SemaCXX] Disallow deducing "this" on operator `new` and `delete` (PR #82251)

2024-02-19 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/82251

>From 8fd5e1bb55a778c778bc8829199318661e4d4573 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Mon, 19 Feb 2024 19:29:48 +0530
Subject: [PATCH] [clang] [SemaCXX] Disallow deducing "this" on operator `new`
 and `delete`

Resolves Issue #82249
---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaDeclCXX.cpp | 4 +++-
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 4 
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 649ad655905af2..2c6a3180f818ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -254,6 +254,8 @@ Bug Fixes to C++ Support
   Fixes (`#68490 `_)
 - Fix a crash when trying to call a varargs function that also has an explicit 
object parameter.
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
+- Reject explicit object parameters on implicitly static member functions.
+  Fixes (`#82249 ` _)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
 - Clang now classifies aggregate initialization in C++17 and newer as constant
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 79263bc3ff671d..7c009d9c8ec093 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11395,7 +11395,9 @@ void Sema::CheckExplicitObjectMemberFunction(Declarator 
,
 << ExplicitObjectParam->getSourceRange();
   }
 
-  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static) {
+  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+  (D.getContext() == clang::DeclaratorContext::Member &&
+   D.isStaticMember())) {
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*static=*/0 << IsLambda;
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 30131d6adc4db0..b8ddb9ad300034 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -16,6 +16,10 @@ struct S {
 static void f(this auto); // expected-error{{an explicit object parameter 
cannot appear in a static function}}
 virtual void f(this S); // expected-error{{an explicit object parameter 
cannot appear in a virtual function}}
 
+// new and delete are implicitly static
+void *operator new(this unsigned long); // expected-error{{an explicit 
object parameter cannot appear in a static function}}
+void operator delete(this void*); // expected-error{{an explicit object 
parameter cannot appear in a static function}}
+
 void g(this auto) const; // expected-error{{explicit object member 
function cannot have 'const' qualifier}}
 void h(this auto) &; // expected-error{{explicit object member function 
cannot have '&' qualifier}}
 void i(this auto) &&; // expected-error{{explicit object member function 
cannot have '&&' qualifier}}

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


[clang] [clang] [SemaCXX] Disallow deducing "this" on operator `new` and `delete` (PR #82251)

2024-02-19 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 created 
https://github.com/llvm/llvm-project/pull/82251

Resolves Issue #82249

As described in the issue, any deallocation function for a `class X` is a 
static member (even if not explicitly declared static).

>From 3ad4e85144739e16be13a4d5641b24d1a7e5b00b Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Mon, 19 Feb 2024 19:29:48 +0530
Subject: [PATCH] [clang] [SemaCXX] Disallow deducing "this" on operator `new`
 and `delete`

Resolves Issue #82249
---
 clang/lib/Sema/SemaDeclCXX.cpp | 4 +++-
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 4 
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ab8a967b06a456..7a7b544d82b640 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11391,7 +11391,9 @@ void Sema::CheckExplicitObjectMemberFunction(Declarator 
,
 << ExplicitObjectParam->getSourceRange();
   }
 
-  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static) {
+  if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+  (D.getContext() == clang::DeclaratorContext::Member &&
+   D.isStaticMember())) {
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*static=*/0 << IsLambda;
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index aab35828096a8e..530f8bf6af1b6b 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -16,6 +16,10 @@ struct S {
 static void f(this auto); // expected-error{{an explicit object parameter 
cannot appear in a static function}}
 virtual void f(this S); // expected-error{{an explicit object parameter 
cannot appear in a virtual function}}
 
+// new and delete are implicitly static
+void *operator new(this unsigned long); // expected-error{{an explicit 
object parameter cannot appear in a static function}}
+void operator delete(this void*); // expected-error{{an explicit object 
parameter cannot appear in a static function}}
+
 void g(this auto) const; // expected-error{{explicit object member 
function cannot have 'const' qualifier}}
 void h(this auto) &; // expected-error{{explicit object member function 
cannot have '&' qualifier}}
 void i(this auto) &&; // expected-error{{explicit object member function 
cannot have '&&' qualifier}}

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


[clang] [clang] Fix crash when inheriting from a cv-qualified type (PR #70594)

2024-02-10 Thread Rajveer Singh Bharadwaj via cfe-commits

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2024-02-09 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

@shafik 
Could you let me know if there are any more changes that are needed here?

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


[clang] [clang] Clang should detect illegal copy constructor with template class as its parameter (PR #81251)

2024-02-09 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

@cor3ntin @shafik 

I am not quite sure if this is the intended fix, also I will check the few 
other failing tests once the _CI_ completes its job.

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


[clang] [clang] Clang should detect illegal copy constructor with template class as its parameter (PR #81251)

2024-02-09 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 created 
https://github.com/llvm/llvm-project/pull/81251

Resolves Issue #80963

As described in the snippet of the issue, `A` is correctly detected while 
it fails to reject in other cases.

>From c931dd64e63817619c6b7f649828580b3fb2e6ec Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Fri, 9 Feb 2024 19:20:39 +0530
Subject: [PATCH] [clang] Clang should detect illegal copy constructor with
 template class as its parameter

Resolves Issue #80963
---
 clang/lib/Sema/SemaDeclCXX.cpp |  2 +-
 clang/test/SemaCXX/GH80963.cpp | 15 +++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/GH80963.cpp

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ab8a967b06a456..9778679ee40d47 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10918,7 +10918,7 @@ void Sema::CheckConstructor(CXXConstructorDecl 
*Constructor) {
   //   parameters have default arguments.
   if (!Constructor->isInvalidDecl() &&
   Constructor->hasOneParamOrDefaultArgs() &&
-  Constructor->getTemplateSpecializationKind() !=
+  Constructor->getTemplateSpecializationKind() ==
   TSK_ImplicitInstantiation) {
 QualType ParamType = Constructor->getParamDecl(0)->getType();
 QualType ClassTy = Context.getTagDeclType(ClassDecl);
diff --git a/clang/test/SemaCXX/GH80963.cpp b/clang/test/SemaCXX/GH80963.cpp
new file mode 100644
index 00..55779e6ff191b7
--- /dev/null
+++ b/clang/test/SemaCXX/GH80963.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template < class T, class V > struct A
+{
+A ();
+A (A &);
+A (A < V,T >);
+// expected-error@-1 {{copy constructor must pass its first argument by 
reference}}
+};
+
+void f ()
+{
+A  (A < int, int >());
+// expected-note@-1 {{in instantiation of template class 'A' 
requested here}}
+}

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2024-01-13 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/70594

>From 864bd0ef7b6bbb0bc1502ef5884ae3c261d3b156 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 29 Oct 2023 18:37:17 +0530
Subject: [PATCH] [clang] Fix a crash in debug mode

Resolves Issue #35603

This bug was caused due to the assertions being too strict,
loosened by stripping qualifiers from the base class but not
from the type of the initializer.

Added Release Notes for the same.
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/Sema/GH35603.cpp| 19 +++
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/GH35603.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cbce1be159437..7183dc447b67fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -918,6 +918,9 @@ Bug Fixes to C++ Support
   (`#57410 `_) and
   (`#76604 `_)
 
+- Fix crash when inheriting from a cv-qualified type. Fixes:
+  (`#35603 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f6aeee1a4e935d..3ad66604255924 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6417,7 +6417,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue ,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/GH35603.cpp b/clang/test/Sema/GH35603.cpp
new file mode 100644
index 00..853552108ec2b6
--- /dev/null
+++ b/clang/test/Sema/GH35603.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2024-01-01 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

@cor3ntin 
Could you help me in closing this?

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-12-06 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/70594

>From 1923c212515033dbb92f09c6d11cd2b679261459 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 29 Oct 2023 18:37:17 +0530
Subject: [PATCH] [clang] Fix a crash in debug mode

Resolves Issue #35603

This bug was caused due to the assertions being too strict,
loosened by stripping qualifiers from the base class but not
from the type of the initializer.

Added Release Notes for the same.
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/Sema/GH35603.cpp| 19 +++
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/GH35603.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2595737e8b3b1..25cdc31b0caa6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -670,6 +670,9 @@ Bug Fixes to C++ Support
   default initializing a base class in a constant expression context. Fixes:
   (`#69890 `_)
 
+- Fix crash when inheriting from a cv-qualified type. Fixes:
+  (`#35603 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5947805f9576f..07f0a12385b46 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6431,7 +6431,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue ,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/GH35603.cpp b/clang/test/Sema/GH35603.cpp
new file mode 100644
index 0..853552108ec2b
--- /dev/null
+++ b/clang/test/Sema/GH35603.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-12-02 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

@cor3ntin 
Could you describe the format of the `release note` briefly so I can `amend` my 
`commit` accordingly?

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-12-02 Thread Rajveer Singh Bharadwaj via cfe-commits

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-10-31 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

Why are `clang-format` changes showing up for changes not committed by me?

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-10-31 Thread Rajveer Singh Bharadwaj via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {

Rajveer100 wrote:

In the `godbolt` links, the compilers seem to be two different versions of 
`clang`, one being a `trunk` and other is an `assertion trunk`?

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-10-31 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/70594

>From efea75d1ae4a1da80b16b3e743a15a82b5f8d971 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 29 Oct 2023 18:37:17 +0530
Subject: [PATCH] [clang] Fix a crash in debug mode

Resolves Issue #35603

This bug was caused due to the assertions being too strict,
loosened by stripping qualifiers from the base class but not
from the type of the initializer.
---
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/Sema/GH35603.cpp| 19 +++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/GH35603.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5947805f9576ff8..07f0a12385b46e9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6431,7 +6431,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue ,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/GH35603.cpp b/clang/test/Sema/GH35603.cpp
new file mode 100644
index 000..853552108ec2b67
--- /dev/null
+++ b/clang/test/Sema/GH35603.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-10-29 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 created 
https://github.com/llvm/llvm-project/pull/70594

Resolves Issue #35603

This change makes the `assertion` less strict in `debug` builds by stripping 
qualifiers from the base class and ignoring them. I hope `weakened` assertions 
don't affect other cases where such `errors` are intended to be `caught` by the 
compiler. 

>From 6c5fda81d4d9c5cda677cb84fffaa8bf5c2bb6ac Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 29 Oct 2023 18:37:17 +0530
Subject: [PATCH] [clang] Fix clang++ crash on assertions when compiling source

Resolves Issue #35603
---
 clang/lib/AST/ExprConstant.cpp  |  2 +-
 clang/test/Sema/assertion-crash.cpp | 19 +++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/assertion-crash.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5947805f9576ff8..07f0a12385b46e9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6431,7 +6431,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue ,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/assertion-crash.cpp 
b/clang/test/Sema/assertion-crash.cpp
new file mode 100644
index 000..853552108ec2b67
--- /dev/null
+++ b/clang/test/Sema/assertion-crash.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};

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