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

Rajveer Singh Bharadwaj via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 13 01:05:09 PST 2024


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

>From 864bd0ef7b6bbb0bc1502ef5884ae3c261d3b156 Mon Sep 17 00:00:00 2001
From: Rajveer <rajveer.developer at icloud.com>
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 <https://github.com/llvm/llvm-project/issues/57410>`_) and
   (`#76604 <https://github.com/llvm/llvm-project/issues/57410>`_)
 
+- Fix crash when inheriting from a cv-qualified type. Fixes:
+  (`#35603 <https://github.com/llvm/llvm-project/issues/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 &This,
       // 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 00000000000000..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() {}
+};



More information about the cfe-commits mailing list