[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-07-29 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@topperc, could you please have a look at this patch 

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


[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-07-31 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/100110

>From 33cfa736bb19c6c8ef2d214ecafbc50605eea5eb Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Wed, 31 Jul 2024 13:37:34 +0300
Subject: [PATCH] [RISCV] full support for riscv_rvv_vector_bits attribute

---
 clang/include/clang/AST/Type.h|   4 +
 clang/lib/AST/ASTContext.cpp  |  33 +++-
 clang/lib/AST/ItaniumMangle.cpp   |  26 ++-
 clang/lib/AST/JSONNodeDumper.cpp  |   3 +
 clang/lib/AST/TextNodeDumper.cpp  |   3 +
 clang/lib/AST/TypePrinter.cpp |   6 +
 clang/lib/CodeGen/Targets/RISCV.cpp   |  22 ++-
 clang/lib/Sema/SemaExpr.cpp   |  13 +-
 clang/lib/Sema/SemaType.cpp   |  18 +-
 .../attr-riscv-rvv-vector-bits-less-8-call.c  | 178 ++
 .../attr-riscv-rvv-vector-bits-less-8-cast.c  | 123 
 .../attr-rvv-vector-bits-bitcast-less-8.c | 106 +++
 .../RISCV/attr-rvv-vector-bits-globals.c  |  36 ++--
 .../RISCV/attr-rvv-vector-bits-types.c|  78 
 .../riscv-mangle-rvv-fixed-vectors.cpp|  20 +-
 clang/test/Sema/attr-riscv-rvv-vector-bits.c  |  18 +-
 16 files changed, 587 insertions(+), 100 deletions(-)
 create mode 100644 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
 create mode 100644 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-cast.c
 create mode 100644 
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-bitcast-less-8.c

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 25defea58c2dc..a9a87ac5837f1 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3981,6 +3981,10 @@ enum class VectorKind {
 
   /// is RISC-V RVV fixed-length mask vector
   RVVFixedLengthMask,
+
+  RVVFixedLengthMask_1,
+  RVVFixedLengthMask_2,
+  RVVFixedLengthMask_4
 };
 
 /// Represents a GCC generic vector type. This type is created using
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7af9ea7105bb0..1b7aed3b9dba8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1983,7 +1983,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) 
const {
   // Adjust the alignment for fixed-length SVE predicates.
   Align = 16;
 else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
- VT->getVectorKind() == VectorKind::RVVFixedLengthMask)
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_4)
   // Adjust the alignment for fixed-length RVV vectors.
   Align = std::min(64, Width);
 break;
@@ -9896,7 +9899,13 @@ bool ASTContext::areCompatibleVectorTypes(QualType 
FirstVec,
   First->getVectorKind() != VectorKind::RVVFixedLengthData &&
   Second->getVectorKind() != VectorKind::RVVFixedLengthData &&
   First->getVectorKind() != VectorKind::RVVFixedLengthMask &&
-  Second->getVectorKind() != VectorKind::RVVFixedLengthMask)
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_1 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_1 &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_2 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_2 &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_4 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_4)
 return true;
 
   return false;
@@ -10014,7 +10023,25 @@ bool ASTContext::areCompatibleRVVTypes(QualType 
FirstType,
   BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
   return FirstType->isRVVVLSBuiltinType() &&
  Info.ElementType == BoolTy &&
- getTypeSize(SecondType) == getRVVTypeSize(*this, BT);
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT)));
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+  return FirstType->isRVVVLSBuiltinType() &&
+ Info.ElementType == BoolTy &&
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT) * 8));
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+  return FirstType->isRVVVLSBuiltinType() &&
+ Info.ElementType == BoolTy &&
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT)) * 4);
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+

[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-07-31 Thread Vladislav Belov via cfe-commits


@@ -572,1483 +1121,44 @@ void f() {
 
//===--===//
 // Structs and unions
 
//===--===//
-// CHECK-64:  %struct.struct_int8m1 = type { <8 x i8> }

vbe-sc wrote:

Done

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


[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-07-31 Thread Vladislav Belov via cfe-commits


@@ -176,477 +177,3110 @@ typedef vbool1_t fixed_bool1_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fi
 typedef vbool2_t fixed_bool2_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/2)));
 typedef vbool4_t fixed_bool4_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/4)));
 typedef vbool8_t fixed_bool8_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/8)));
-#if __riscv_v_fixed_vlen >= 128
 typedef vbool16_t fixed_bool16_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/16)));
-#endif
-#if __riscv_v_fixed_vlen >= 256
 typedef vbool32_t fixed_bool32_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/32)));
-#endif
-#if __riscv_v_fixed_vlen >= 512
 typedef vbool64_t fixed_bool64_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/64)));
-#endif
 
 template  struct S {};
 
-// CHECK-64: _Z2f11SI9__RVV_VLSIu14__rvv_int8m1_tLj64EEE

vbe-sc wrote:

Many thanks for your comment: it allowed me to understand this test and find an 
improvement in `clang/./lib/AST/ItaniumMangle.cpp` for my patch. 
Fixed

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


[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-08-05 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@topperc, ping




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


[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-08-06 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/100110

>From 2dba8f9f90369f79f97fc5efb1272b75d61d36b2 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Wed, 31 Jul 2024 13:37:34 +0300
Subject: [PATCH] [RISCV] full support for riscv_rvv_vector_bits attribute

---
 clang/include/clang/AST/Type.h|   4 +
 clang/lib/AST/ASTContext.cpp  |  33 +++-
 clang/lib/AST/ItaniumMangle.cpp   |  26 ++-
 clang/lib/AST/JSONNodeDumper.cpp  |   3 +
 clang/lib/AST/TextNodeDumper.cpp  |   3 +
 clang/lib/AST/TypePrinter.cpp |   6 +
 clang/lib/CodeGen/Targets/RISCV.cpp   |  22 ++-
 clang/lib/Sema/SemaExpr.cpp   |  13 +-
 clang/lib/Sema/SemaType.cpp   |  18 +-
 .../attr-riscv-rvv-vector-bits-less-8-call.c  | 178 ++
 .../attr-riscv-rvv-vector-bits-less-8-cast.c  | 123 
 .../attr-rvv-vector-bits-bitcast-less-8.c | 106 +++
 .../RISCV/attr-rvv-vector-bits-globals.c  |  36 ++--
 .../RISCV/attr-rvv-vector-bits-types.c|  78 
 .../riscv-mangle-rvv-fixed-vectors.cpp|  18 +-
 clang/test/Sema/attr-riscv-rvv-vector-bits.c  |  18 +-
 16 files changed, 586 insertions(+), 99 deletions(-)
 create mode 100644 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
 create mode 100644 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-cast.c
 create mode 100644 
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-bitcast-less-8.c

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 25defea58c2dc..a9a87ac5837f1 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3981,6 +3981,10 @@ enum class VectorKind {
 
   /// is RISC-V RVV fixed-length mask vector
   RVVFixedLengthMask,
+
+  RVVFixedLengthMask_1,
+  RVVFixedLengthMask_2,
+  RVVFixedLengthMask_4
 };
 
 /// Represents a GCC generic vector type. This type is created using
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7af9ea7105bb0..1b7aed3b9dba8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1983,7 +1983,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) 
const {
   // Adjust the alignment for fixed-length SVE predicates.
   Align = 16;
 else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
- VT->getVectorKind() == VectorKind::RVVFixedLengthMask)
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_4)
   // Adjust the alignment for fixed-length RVV vectors.
   Align = std::min(64, Width);
 break;
@@ -9896,7 +9899,13 @@ bool ASTContext::areCompatibleVectorTypes(QualType 
FirstVec,
   First->getVectorKind() != VectorKind::RVVFixedLengthData &&
   Second->getVectorKind() != VectorKind::RVVFixedLengthData &&
   First->getVectorKind() != VectorKind::RVVFixedLengthMask &&
-  Second->getVectorKind() != VectorKind::RVVFixedLengthMask)
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_1 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_1 &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_2 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_2 &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_4 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_4)
 return true;
 
   return false;
@@ -10014,7 +10023,25 @@ bool ASTContext::areCompatibleRVVTypes(QualType 
FirstType,
   BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
   return FirstType->isRVVVLSBuiltinType() &&
  Info.ElementType == BoolTy &&
- getTypeSize(SecondType) == getRVVTypeSize(*this, BT);
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT)));
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+  return FirstType->isRVVVLSBuiltinType() &&
+ Info.ElementType == BoolTy &&
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT) * 8));
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+  return FirstType->isRVVVLSBuiltinType() &&
+ Info.ElementType == BoolTy &&
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT)) * 4);
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+ 

[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-08-06 Thread Vladislav Belov via cfe-commits


@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -triple riscv64-none-linux-gnu %s -emit-llvm -o - \
 // RUN:  -target-feature +f -target-feature +d -target-feature +zfh \
 // RUN:  -target-feature +zve64d -target-feature +zvfh -mvscale-min=1 \
-// RUN:   -mvscale-max=1 | FileCheck %s --check-prefix=CHECK-64
+// RUN:   -mvscale-max=1 | FileCheck %s --check-prefix=CHECK-64 

vbe-sc wrote:

Done

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


[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-08-06 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/100110

>From 2dba8f9f90369f79f97fc5efb1272b75d61d36b2 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Wed, 31 Jul 2024 13:37:34 +0300
Subject: [PATCH] [RISCV] full support for riscv_rvv_vector_bits attribute

---
 clang/include/clang/AST/Type.h|   4 +
 clang/lib/AST/ASTContext.cpp  |  33 +++-
 clang/lib/AST/ItaniumMangle.cpp   |  26 ++-
 clang/lib/AST/JSONNodeDumper.cpp  |   3 +
 clang/lib/AST/TextNodeDumper.cpp  |   3 +
 clang/lib/AST/TypePrinter.cpp |   6 +
 clang/lib/CodeGen/Targets/RISCV.cpp   |  22 ++-
 clang/lib/Sema/SemaExpr.cpp   |  13 +-
 clang/lib/Sema/SemaType.cpp   |  18 +-
 .../attr-riscv-rvv-vector-bits-less-8-call.c  | 178 ++
 .../attr-riscv-rvv-vector-bits-less-8-cast.c  | 123 
 .../attr-rvv-vector-bits-bitcast-less-8.c | 106 +++
 .../RISCV/attr-rvv-vector-bits-globals.c  |  36 ++--
 .../RISCV/attr-rvv-vector-bits-types.c|  78 
 .../riscv-mangle-rvv-fixed-vectors.cpp|  18 +-
 clang/test/Sema/attr-riscv-rvv-vector-bits.c  |  18 +-
 16 files changed, 586 insertions(+), 99 deletions(-)
 create mode 100644 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
 create mode 100644 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-cast.c
 create mode 100644 
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-bitcast-less-8.c

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 25defea58c2dc..a9a87ac5837f1 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3981,6 +3981,10 @@ enum class VectorKind {
 
   /// is RISC-V RVV fixed-length mask vector
   RVVFixedLengthMask,
+
+  RVVFixedLengthMask_1,
+  RVVFixedLengthMask_2,
+  RVVFixedLengthMask_4
 };
 
 /// Represents a GCC generic vector type. This type is created using
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7af9ea7105bb0..1b7aed3b9dba8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1983,7 +1983,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) 
const {
   // Adjust the alignment for fixed-length SVE predicates.
   Align = 16;
 else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
- VT->getVectorKind() == VectorKind::RVVFixedLengthMask)
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_4)
   // Adjust the alignment for fixed-length RVV vectors.
   Align = std::min(64, Width);
 break;
@@ -9896,7 +9899,13 @@ bool ASTContext::areCompatibleVectorTypes(QualType 
FirstVec,
   First->getVectorKind() != VectorKind::RVVFixedLengthData &&
   Second->getVectorKind() != VectorKind::RVVFixedLengthData &&
   First->getVectorKind() != VectorKind::RVVFixedLengthMask &&
-  Second->getVectorKind() != VectorKind::RVVFixedLengthMask)
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_1 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_1 &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_2 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_2 &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_4 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_4)
 return true;
 
   return false;
@@ -10014,7 +10023,25 @@ bool ASTContext::areCompatibleRVVTypes(QualType 
FirstType,
   BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
   return FirstType->isRVVVLSBuiltinType() &&
  Info.ElementType == BoolTy &&
- getTypeSize(SecondType) == getRVVTypeSize(*this, BT);
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT)));
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+  return FirstType->isRVVVLSBuiltinType() &&
+ Info.ElementType == BoolTy &&
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT) * 8));
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+  return FirstType->isRVVVLSBuiltinType() &&
+ Info.ElementType == BoolTy &&
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT)) * 4);
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+ 

[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-05 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc created 
https://github.com/llvm/llvm-project/pull/114978

Currently the following example is a compilation failure: 
```
template struct A {
typedef int M;
struct B {
  typedef void M;
  struct C;
};
};

template struct A::B::C : A {
M m; // void or int ?
};
```

According to the point 13.8.3.2

```
A dependent base class is a base class that is a dependent type and is not the 
current instantiation.
Note 2 : A base class can be the current instantiation in the case of a nested 
class naming an enclosing class as a base.
```

The base class `A` is the current instantiation, because `C` is a nested class 
for an enclosing class `A`, it's is the not-dependent base class and we need 
to search the names through its scope.

This patch makes this example compile

>From 4eb7be671dee117f8185423b177c014edd310b48 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 13 -
 clang/test/CXX/drs/cwg5xx.cpp|  8 ++--
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..049532f942d051 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -169,6 +169,9 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 // Find the record of the base class subobjects for this type.
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
+bool isCurrentInstantiation = false;
+if (auto *TST = BaseSpec.getType()->getAs())
+  isCurrentInstantiation = TST->isCurrentInstantiation();
 
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
@@ -176,7 +179,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +248,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +268,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+if (auto *RT = BaseSpec.getType()->getAs())
+  BaseRecord = cast(RT->getDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..b283684aef2f7e 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,21 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct A::B::D : A {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
   };

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-05 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From 0c2363cb2ab24d0b4d9998943772f9105437579e Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 13 -
 clang/test/CXX/drs/cwg5xx.cpp|  8 ++--
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..049532f942d051 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -169,6 +169,9 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 // Find the record of the base class subobjects for this type.
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
+bool isCurrentInstantiation = false;
+if (auto *TST = BaseSpec.getType()->getAs())
+  isCurrentInstantiation = TST->isCurrentInstantiation();
 
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
@@ -176,7 +179,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +248,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +268,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+if (auto *RT = BaseSpec.getType()->getAs())
+  BaseRecord = cast(RT->getDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..b283684aef2f7e 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,21 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct A::B::D : A {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
   };

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-11 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> @vbe-sc I can later today or tomorrow.

That's would be great, thank you!

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-12 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@sdkrystian ping

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-10 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@sdkrystian, could you please take a look? 

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-06 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@Endilll, please, could you take a look? 
Also, do you have any ideas why the Win pipeline fails with checkout failure? 
How can I fix it? 

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-07 Thread Vladislav Belov via cfe-commits


@@ -265,8 +268,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+if (auto *RT = BaseSpec.getType()->getAs())
+  BaseRecord = cast(RT->getDecl());

vbe-sc wrote:

This is almost same. To be correct, we need to replace the first variant with 
```c++
BaseRecord = cast(BaseSpec.getType()->getAsRecordDecl());
```

All in all, thanks for this comment. Fixed

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-07 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From 66f3465737a99a002310b707f7783698adef253a Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 10 +-
 clang/test/CXX/drs/cwg5xx.cpp|  8 ++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..9b1bcaa88e129e 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -169,6 +169,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 // Find the record of the base class subobjects for this type.
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
+bool isCurrentInstantiation = isa(BaseType);
 
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
@@ -176,7 +177,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +246,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +266,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..b283684aef2f7e 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,21 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct A::B::D : A {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
   };

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-07 Thread Vladislav Belov via cfe-commits


@@ -169,14 +169,18 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 // Find the record of the base class subobjects for this type.
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
+bool isCurrentInstantiation = false;
+if (auto *TST = BaseSpec.getType()->getAs())
+  isCurrentInstantiation = TST->isCurrentInstantiation();

vbe-sc wrote:

You are right, thanks.
I've accepted your changes 

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-06 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> > @Endilll, please, could you take a look?
> 
> My knowledge of wording about templates is not deep enough, unfortunately.

Could you, please, suggest someone who can review this part?

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-08 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@sdkrystian, please, could you take a look?

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-11-29 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@cor3ntin, FYI: we reverted the patch you merged before. This is the second 
attempt

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-21 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@sdkrystian, can you, please, re-review this patch? It seems like I fixed your 
test

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-27 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

Such an example causes a failure in my patch

```c++
template  
class X {
public:
  X() = default;
  virtual ~X() = default;

  virtual int foo(int x, int y, T &entry) = 0;

  void bar() {
struct Processor : public X {
  Processor() : X() {}

  int foo(int, int, T &) override {
return 42;
  }
};
  }
};
```

The output 
```
llvm-project/clang/lib/AST/DeclCXX.cpp:2508: void 
clang::CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *): Assertion 
`!MD->getParent()->isDependentContext() && "Can't add an overridden method to a 
class template!"' failed.
```

The problem case is class definition nested to the method. 
I'm working on investigation and fixing this issue  

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-11-28 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc created 
https://github.com/llvm/llvm-project/pull/118003

Unlike the previous version, this patch also removes an unnecessary assert that 
causes Clang to crash when compiling such tests. (clang/lib/AST/DeclCXX.cpp)

https://lab.llvm.org/buildbot/#/builders/52/builds/4021

```c++
template  
class X {
public:
  X() = default;
  virtual ~X() = default;

  virtual int foo(int x, int y, T &entry) = 0;

  void bar() {
struct Y : public X {
  Y() : X() {}

  int foo(int, int, T &) override {
return 42;
  }
};
  }
};
```

the assertions: 

```c++
llvm-project/clang/lib/AST/DeclCXX.cpp:2508: void 
clang::CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *): Assertion 
`!MD->getParent()->isDependentContext() && "Can't add an overridden method to a 
class template!"' failed.
```

I believe that this assert is unnecessary and contradicts the logic of this 
patch. After its removal, Clang was successfully built using itself, and all 
tests passed.

>From 63f64a3d62af8cf93ecdb3af6c50a243b0ed12b5 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/docs/ReleaseNotes.rst  |  3 ++
 clang/lib/AST/CXXInheritance.cpp | 18 
 clang/lib/AST/DeclCXX.cpp|  2 --
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 clang/www/cxx_dr_status.html |  2 +-
 5 files changed, 62 insertions(+), 11 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2ecd19bdc39448..c3bb3ea69b03ea 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,9 @@ Resolutions to C++ Defect Reports
   by default.
   (`CWG2521: User-defined literals and reserved identifiers 
`_).
 
+- Fix name lookup for a dependent base class that is the current 
instantiation.  
+  (`CWG591: When a dependent base class is the current instantiation 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index aefc06e9197cfb..10b8d524ff8978 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -134,7 +134,7 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback 
BaseMatches) const {
 return false;
 
   CXXRecordDecl *Base =
-cast_or_null(Ty->getDecl()->getDefinition());
+  cast_if_present(Ty->getDecl()->getDefinition());
   if (!Base ||
   (Base->isDependentContext() &&
!Base->isCurrentInstantiation(Record))) {
@@ -169,13 +169,21 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = isa(BaseType);
+if (!isCurrentInstantiation) {
+  if (auto *BaseRecord = cast_if_present(
+  BaseSpec.getType()->getAsRecordDecl()))
+isCurrentInstantiation = BaseRecord->isDependentContext() &&
+ BaseRecord->isCurrentInstantiation(Record);
+}
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -243,9 +251,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -264,8 +271,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index f2f2835641245e..af73c658d6a0c5 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -2602,8 +2602,6 @@ bool CXXMethodDecl::isMoveAssignmentOperator() const {
 
 void CXXMethodDecl::addOverriddenMethod(const CXXMethodDe

[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-11-28 Thread Vladislav Belov via cfe-commits

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-11-28 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@erichkeane, @nikic This is the second version of this patch. I’m not entirely 
sure if my suggestion regarding the redundant assertion is correct, but I’d 
like to share some thoughts on the clang build time regression:

According to the actual implementation of `CXXRecordDecl::lookupInBases`: 

```
  // FIXME: This is an O(N^2) algorithm, but DPG doesn't see an easy
  // way to make it any faster.
```

My patch enforces additional lookups through the bases (as required by the C++ 
standard), so worse performance is expected regardless. It might be possible to 
limit this algorithm or improve its efficiency, but at the moment, I don’t see 
a viable way to achieve this.

Do you have any thoughts on the assertion I removed?

Do you have any suggestions or concern? Thanks

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-11-28 Thread Vladislav Belov via cfe-commits


@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes

vbe-sc wrote:

Done

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-27 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

```c++
void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) {
  assert(MD->isCanonicalDecl() && "Method is not canonical!");
  assert(!MD->getParent()->isDependentContext() &&
 "Can't add an overridden method to a class template!");
```

It seems to me that the second assertion is not really a requirement. @mizvekov 
, can you please comment on this statement?

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-11-28 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/118003

>From 98583ff617a4d527041c683e98904ed063467c50 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/docs/ReleaseNotes.rst  |  3 ++
 clang/lib/AST/CXXInheritance.cpp | 18 
 clang/lib/AST/DeclCXX.cpp|  2 --
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 clang/www/cxx_dr_status.html |  2 +-
 5 files changed, 62 insertions(+), 11 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2ecd19bdc39448..c3bb3ea69b03ea 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,9 @@ Resolutions to C++ Defect Reports
   by default.
   (`CWG2521: User-defined literals and reserved identifiers 
`_).
 
+- Fix name lookup for a dependent base class that is the current 
instantiation.  
+  (`CWG591: When a dependent base class is the current instantiation 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index aefc06e9197cfb..10b8d524ff8978 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -134,7 +134,7 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback 
BaseMatches) const {
 return false;
 
   CXXRecordDecl *Base =
-cast_or_null(Ty->getDecl()->getDefinition());
+  cast_if_present(Ty->getDecl()->getDefinition());
   if (!Base ||
   (Base->isDependentContext() &&
!Base->isCurrentInstantiation(Record))) {
@@ -169,13 +169,21 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = isa(BaseType);
+if (!isCurrentInstantiation) {
+  if (auto *BaseRecord = cast_if_present(
+  BaseSpec.getType()->getAsRecordDecl()))
+isCurrentInstantiation = BaseRecord->isDependentContext() &&
+ BaseRecord->isCurrentInstantiation(Record);
+}
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -243,9 +251,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -264,8 +271,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index f2f2835641245e..af73c658d6a0c5 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -2602,8 +2602,6 @@ bool CXXMethodDecl::isMoveAssignmentOperator() const {
 
 void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) {
   assert(MD->isCanonicalDecl() && "Method is not canonical!");
-  assert(!MD->getParent()->isDependentContext() &&
- "Can't add an overridden method to a class template!");
   assert(MD->isVirtual() && "Method is not virtual!");
 
   getASTContext().addOverriddenMethod(this, MD);
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..91a76fd2adbb6a 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: 20
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
+};
+  };
+
+  template struct G {
+struct B {
+  typedef int M;
+  struct C {
+typedef void M;
+struct 

[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-11-28 Thread Vladislav Belov via cfe-commits


@@ -3599,7 +3599,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/591.html";>591
 CD4
 When a dependent base class is the current instantiation
-No
+Yes

vbe-sc wrote:

Done

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-19 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From d17588af72f845b758a03637c84752dde733200c Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/docs/ReleaseNotes.rst  |  3 ++
 clang/lib/AST/CXXInheritance.cpp | 18 
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 clang/www/cxx_dr_status.html |  2 +-
 4 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a8830a5658c7da..b9f06f2047539a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -268,6 +268,9 @@ Resolutions to C++ Defect Reports
   by default.
   (`CWG2521: User-defined literals and reserved identifiers 
`_).
 
+- Clang now make correct name lookup when dependent base class is the current 
instantiation.
+  (`CWG591: When a dependent base class is the current instantiation 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..6d71cb206aa188 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -135,7 +135,7 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback 
BaseMatches) const {
 return false;
 
   CXXRecordDecl *Base =
-cast_or_null(Ty->getDecl()->getDefinition());
+  cast_if_present(Ty->getDecl()->getDefinition());
   if (!Base ||
   (Base->isDependentContext() &&
!Base->isCurrentInstantiation(Record))) {
@@ -170,13 +170,21 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = isa(BaseType);
+if (!isCurrentInstantiation) {
+  if (auto *BaseRecord = cast_if_present(
+  BaseSpec.getType()->getAsRecordDecl()))
+isCurrentInstantiation = BaseRecord->isDependentContext() &&
+ BaseRecord->isCurrentInstantiation(Record);
+}
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +252,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +272,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..0d53a9d07d76de 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
+};
+  };
+
+  template struct G {
+struct B {
+  typedef int M;
+  struct C {
+typedef void M;
+struct D;
+  };
+};
+  };
+
+  template struct H {
+template struct B {
+  typedef int M;
+  template struct C {
+typedef void M;
+struct D;
+struct P;
+  };
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct G::B::C::D : B {
+M m;
+  };
+
+  template
+  template
+  template
+  struct H::B::C::D : B {
+M m;
+  };
+
+  template struct A::B::D : A {
+M m;
+// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
+  };
+
+  template
+  template
+  template
+  struct H::B::C:

[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-19 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> Can you add a release note

I added a release note as you asked

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-18 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From 2f7c7634ae22e53c5ffd645c5d544b36d108a25b Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 18 
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 clang/www/cxx_dr_status.html |  2 +-
 3 files changed, 59 insertions(+), 9 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..590f3b0499d120 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -135,7 +135,7 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback 
BaseMatches) const {
 return false;
 
   CXXRecordDecl *Base =
-cast_or_null(Ty->getDecl()->getDefinition());
+  cast_if_present(Ty->getDecl()->getDefinition());
   if (!Base ||
   (Base->isDependentContext() &&
!Base->isCurrentInstantiation(Record))) {
@@ -170,13 +170,21 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = isa(BaseType);
+if (!isCurrentInstantiation) {
+  if (auto *BaseRecord = cast_or_null(
+  BaseSpec.getType()->getAsRecordDecl()))
+isCurrentInstantiation = BaseRecord->isDependentContext() &&
+ BaseRecord->isCurrentInstantiation(Record);
+}
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +252,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +272,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..0d53a9d07d76de 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
+};
+  };
+
+  template struct G {
+struct B {
+  typedef int M;
+  struct C {
+typedef void M;
+struct D;
+  };
+};
+  };
+
+  template struct H {
+template struct B {
+  typedef int M;
+  template struct C {
+typedef void M;
+struct D;
+struct P;
+  };
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct G::B::C::D : B {
+M m;
+  };
+
+  template
+  template
+  template
+  struct H::B::C::D : B {
+M m;
+  };
+
+  template struct A::B::D : A {
+M m;
+// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
+  };
+
+  template
+  template
+  template
+  struct H::B::C::P : B {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
   };
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 186f7cc0ace546..c773c58fac4d0f 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -3599,7 +3599,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/591.html";>591
 CD4
 When a dependent base class is the current instantiation
-No
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/592.html";>592

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm

[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-18 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From e2e490717b1abe440556f2d8c439b3ee18b31642 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 18 
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 clang/www/cxx_dr_status.html |  2 +-
 3 files changed, 59 insertions(+), 9 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..6d71cb206aa188 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -135,7 +135,7 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback 
BaseMatches) const {
 return false;
 
   CXXRecordDecl *Base =
-cast_or_null(Ty->getDecl()->getDefinition());
+  cast_if_present(Ty->getDecl()->getDefinition());
   if (!Base ||
   (Base->isDependentContext() &&
!Base->isCurrentInstantiation(Record))) {
@@ -170,13 +170,21 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = isa(BaseType);
+if (!isCurrentInstantiation) {
+  if (auto *BaseRecord = cast_if_present(
+  BaseSpec.getType()->getAsRecordDecl()))
+isCurrentInstantiation = BaseRecord->isDependentContext() &&
+ BaseRecord->isCurrentInstantiation(Record);
+}
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +252,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +272,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..0d53a9d07d76de 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
+};
+  };
+
+  template struct G {
+struct B {
+  typedef int M;
+  struct C {
+typedef void M;
+struct D;
+  };
+};
+  };
+
+  template struct H {
+template struct B {
+  typedef int M;
+  template struct C {
+typedef void M;
+struct D;
+struct P;
+  };
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct G::B::C::D : B {
+M m;
+  };
+
+  template
+  template
+  template
+  struct H::B::C::D : B {
+M m;
+  };
+
+  template struct A::B::D : A {
+M m;
+// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
+  };
+
+  template
+  template
+  template
+  struct H::B::C::P : B {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
   };
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 186f7cc0ace546..c773c58fac4d0f 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -3599,7 +3599,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/591.html";>591
 CD4
 When a dependent base class is the current instantiation
-No
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/592.html";>592

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.l

[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-18 Thread Vladislav Belov via cfe-commits


@@ -170,13 +170,21 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = isa(BaseType);
+if (!isCurrentInstantiation) {
+  if (auto *BaseRecord = cast_or_null(

vbe-sc wrote:

Yes, you are right. Fixed here and in the other part of the code because there 
is the same case.



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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-16 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From 0de2ff271efd672bae0b4974c404149da79ff747 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 14 ++
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 2 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..b2e77037c10c72 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -170,13 +170,19 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = false;
+if (auto *BaseRecord =
+cast(BaseSpec.getType()->getAsRecordDecl()))
+  isCurrentInstantiation = BaseRecord->isDependentContext() &&
+   BaseRecord->isCurrentInstantiation(Record);
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +250,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +270,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..0d53a9d07d76de 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
+};
+  };
+
+  template struct G {
+struct B {
+  typedef int M;
+  struct C {
+typedef void M;
+struct D;
+  };
+};
+  };
+
+  template struct H {
+template struct B {
+  typedef int M;
+  template struct C {
+typedef void M;
+struct D;
+struct P;
+  };
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct G::B::C::D : B {
+M m;
+  };
+
+  template
+  template
+  template
+  struct H::B::C::D : B {
+M m;
+  };
+
+  template struct A::B::D : A {
+M m;
+// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
+  };
+
+  template
+  template
+  template
+  struct H::B::C::P : B {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
   };

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-16 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From 11c24e5592bfdf8849bb415580d37a6f545e4952 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 14 ++
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 2 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..b2e77037c10c72 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -170,13 +170,19 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = false;
+if (auto *BaseRecord =
+cast(BaseSpec.getType()->getAsRecordDecl()))
+  isCurrentInstantiation = BaseRecord->isDependentContext() &&
+   BaseRecord->isCurrentInstantiation(Record);
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +250,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +270,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..0d53a9d07d76de 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
+};
+  };
+
+  template struct G {
+struct B {
+  typedef int M;
+  struct C {
+typedef void M;
+struct D;
+  };
+};
+  };
+
+  template struct H {
+template struct B {
+  typedef int M;
+  template struct C {
+typedef void M;
+struct D;
+struct P;
+  };
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct G::B::C::D : B {
+M m;
+  };
+
+  template
+  template
+  template
+  struct H::B::C::D : B {
+M m;
+  };
+
+  template struct A::B::D : A {
+M m;
+// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
+  };
+
+  template
+  template
+  template
+  struct H::B::C::P : B {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
   };

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-16 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From 11c24e5592bfdf8849bb415580d37a6f545e4952 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 14 ++
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 2 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..b2e77037c10c72 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -170,13 +170,19 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = false;
+if (auto *BaseRecord =
+cast(BaseSpec.getType()->getAsRecordDecl()))
+  isCurrentInstantiation = BaseRecord->isDependentContext() &&
+   BaseRecord->isCurrentInstantiation(Record);
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +250,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +270,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..0d53a9d07d76de 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
+};
+  };
+
+  template struct G {
+struct B {
+  typedef int M;
+  struct C {
+typedef void M;
+struct D;
+  };
+};
+  };
+
+  template struct H {
+template struct B {
+  typedef int M;
+  template struct C {
+typedef void M;
+struct D;
+struct P;
+  };
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct G::B::C::D : B {
+M m;
+  };
+
+  template
+  template
+  template
+  struct H::B::C::D : B {
+M m;
+  };
+
+  template struct A::B::D : A {
+M m;
+// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
+  };
+
+  template
+  template
+  template
+  struct H::B::C::P : B {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
   };

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-16 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From 5a48960ab73890b10381b4e7ebd32d3f66246bdd Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 16 +++
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 2 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..7961dbc0c7c8a3 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -170,13 +170,21 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = isa(BaseType);
+if (!isCurrentInstantiation) {
+  if (auto *BaseRecord = cast_or_null(
+  BaseSpec.getType()->getAsRecordDecl()))
+isCurrentInstantiation = BaseRecord->isDependentContext() &&
+ BaseRecord->isCurrentInstantiation(Record);
+}
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +252,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +272,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..0d53a9d07d76de 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
+};
+  };
+
+  template struct G {
+struct B {
+  typedef int M;
+  struct C {
+typedef void M;
+struct D;
+  };
+};
+  };
+
+  template struct H {
+template struct B {
+  typedef int M;
+  template struct C {
+typedef void M;
+struct D;
+struct P;
+  };
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct G::B::C::D : B {
+M m;
+  };
+
+  template
+  template
+  template
+  struct H::B::C::D : B {
+M m;
+  };
+
+  template struct A::B::D : A {
+M m;
+// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
+  };
+
+  template
+  template
+  template
+  struct H::B::C::P : B {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
   };

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-16 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> I don't think this patch fixes the following case:
> 
> ```c++
> template 
> struct A 
> {
> struct B 
> {
> using X = int;
> 
> struct C
> {
> using X = void;
> 
> struct D;
> };
> };
> };
> 
> template 
> struct A::B::C::D : B
> {
> X x; // error: field has incomplete type 'X' (aka 'void')
> };
> ```
> 
> Regardless, this patch should probably include this as a test.

Many thanks for your answer! You're right, this test failed with this patch, 
but I've already fixed it (see the new changes).
Moreover, I have added more tests that should and shouldn't compile.

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-17 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From f3b8ee95f1b3759f7d0dbc12f856a13ca9f01e0f Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 16 +++
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 2 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..3edc1f54837deb 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -170,13 +170,21 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = isa(BaseType);
+if (!isCurrentInstantiation) {
+  if (auto *BaseRecord =
+  cast(BaseSpec.getType()->getAsRecordDecl()))
+isCurrentInstantiation = BaseRecord->isDependentContext() &&
+ BaseRecord->isCurrentInstantiation(Record);
+}
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +252,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +272,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..0d53a9d07d76de 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
+};
+  };
+
+  template struct G {
+struct B {
+  typedef int M;
+  struct C {
+typedef void M;
+struct D;
+  };
+};
+  };
+
+  template struct H {
+template struct B {
+  typedef int M;
+  template struct C {
+typedef void M;
+struct D;
+struct P;
+  };
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct G::B::C::D : B {
+M m;
+  };
+
+  template
+  template
+  template
+  struct H::B::C::D : B {
+M m;
+  };
+
+  template struct A::B::D : A {
+M m;
+// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
+  };
+
+  template
+  template
+  template
+  struct H::B::C::P : B {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
   };

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-15 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> Please wait for a week before pinging someone again.
> 
> I think this is fine to merge as is, if you want to go ahead. We can always 
> do post commit review later.

Sorry, I didn't know.
Let's do it this way you want 

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-14 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@sdkrystian, could you, please, take a look? We are about to merge this 

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-24 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@cor3ntin could you, please, re-review this patch and resolve the comments if 
everything is ok?

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-26 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/114978

>From 6564e20ae7fc69849b6787afa12f68b712f4df12 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Tue, 5 Nov 2024 15:46:57 +0300
Subject: [PATCH] [clang] Fix name lookup for dependent bases

---
 clang/docs/ReleaseNotes.rst  |  3 ++
 clang/lib/AST/CXXInheritance.cpp | 18 
 clang/test/CXX/drs/cwg5xx.cpp| 48 ++--
 clang/www/cxx_dr_status.html |  2 +-
 4 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a8830a5658c7da..76ad2e2cf6b641 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -268,6 +268,9 @@ Resolutions to C++ Defect Reports
   by default.
   (`CWG2521: User-defined literals and reserved identifiers 
`_).
 
+- Fix name lookup for a dependent base class that is the current 
instantiation.  
+  (`CWG591: When a dependent base class is the current instantiation 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index eb265a872c1259..6d71cb206aa188 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -135,7 +135,7 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback 
BaseMatches) const {
 return false;
 
   CXXRecordDecl *Base =
-cast_or_null(Ty->getDecl()->getDefinition());
+  cast_if_present(Ty->getDecl()->getDefinition());
   if (!Base ||
   (Base->isDependentContext() &&
!Base->isCurrentInstantiation(Record))) {
@@ -170,13 +170,21 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 QualType BaseType =
 Context.getCanonicalType(BaseSpec.getType()).getUnqualifiedType();
 
+bool isCurrentInstantiation = isa(BaseType);
+if (!isCurrentInstantiation) {
+  if (auto *BaseRecord = cast_if_present(
+  BaseSpec.getType()->getAsRecordDecl()))
+isCurrentInstantiation = BaseRecord->isDependentContext() &&
+ BaseRecord->isCurrentInstantiation(Record);
+}
 // C++ [temp.dep]p3:
 //   In the definition of a class template or a member of a class template,
 //   if a base class of the class template depends on a template-parameter,
 //   the base class scope is not examined during unqualified name lookup
 //   either at the point of definition of the class template or member or
 //   during an instantiation of the class tem- plate or member.
-if (!LookupInDependent && BaseType->isDependentType())
+if (!LookupInDependent &&
+(BaseType->isDependentType() && !isCurrentInstantiation))
   continue;
 
 // Determine whether we need to visit this base class at all,
@@ -244,9 +252,8 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 return FoundPath;
   }
 } else if (VisitBase) {
-  CXXRecordDecl *BaseRecord;
+  CXXRecordDecl *BaseRecord = nullptr;
   if (LookupInDependent) {
-BaseRecord = nullptr;
 const TemplateSpecializationType *TST =
 BaseSpec.getType()->getAs();
 if (!TST) {
@@ -265,8 +272,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = nullptr;
 }
   } else {
-BaseRecord = cast(
-BaseSpec.getType()->castAs()->getDecl());
+BaseRecord = 
cast(BaseSpec.getType()->getAsRecordDecl());
   }
   if (BaseRecord &&
   lookupInBases(Context, BaseRecord, BaseMatches, LookupInDependent)) {
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index ed0c7159dfc889..0d53a9d07d76de 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1178,17 +1178,61 @@ namespace cwg590 { // cwg590: yes
   template typename A::B::C A::B::C::f(A::B::C) {}
 }
 
-namespace cwg591 { // cwg591: no
+namespace cwg591 { // cwg591: yes
   template struct A {
 typedef int M;
 struct B {
   typedef void M;
   struct C;
+  struct D;
+};
+  };
+
+  template struct G {
+struct B {
+  typedef int M;
+  struct C {
+typedef void M;
+struct D;
+  };
+};
+  };
+
+  template struct H {
+template struct B {
+  typedef int M;
+  template struct C {
+typedef void M;
+struct D;
+struct P;
+  };
 };
   };
 
   template struct A::B::C : A {
-// FIXME: Should find member of non-dependent base class A.
+M m;
+  };
+
+  template struct G::B::C::D : B {
+M m;
+  };
+
+  template
+  template
+  template
+  struct H::B::C::D : B {
+M m;
+  };
+
+  template struct A::B::D : A {
+M m;
+// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
+  };
+
+  template
+  template
+  template
+  struct H::B::C::P : B {
  

[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-26 Thread Vladislav Belov via cfe-commits


@@ -268,6 +268,9 @@ Resolutions to C++ Defect Reports
   by default.
   (`CWG2521: User-defined literals and reserved identifiers 
`_).
 
+- Clang now make correct name lookup when dependent base class is the current 
instantiation.

vbe-sc wrote:

Fixed, thanks

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-26 Thread Vladislav Belov via cfe-commits


@@ -268,6 +268,9 @@ Resolutions to C++ Defect Reports
   by default.
   (`CWG2521: User-defined literals and reserved identifiers 
`_).
 
+- Clang now make correct name lookup when dependent base class is the current 
instantiation.

vbe-sc wrote:

Could we merge this? 

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


[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-08 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/119024

>From ce758d5e8cf958edbfffeee8fe4c978011554b53 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Fri, 6 Dec 2024 23:06:01 +0300
Subject: [PATCH] [clang][NFC] Fix cast for injected types in case name lookup
 for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 12 ++--
 clang/test/CXX/drs/cwg5xx.cpp|  9 +
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 10b8d524ff8978..ee5775837d5355 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -368,8 +368,8 @@ bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier 
*Specifier,
   const CXXRecordDecl *BaseRecord) {
   assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
  "User data for FindBaseClass is not canonical!");
-  return Specifier->getType()->castAs()->getDecl()
-->getCanonicalDecl() == BaseRecord;
+  return cast(Specifier->getType()->getAsRecordDecl())
+ ->getCanonicalDecl() == BaseRecord;
 }
 
 bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
@@ -378,8 +378,8 @@ bool CXXRecordDecl::FindVirtualBaseClass(const 
CXXBaseSpecifier *Specifier,
   assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
  "User data for FindBaseClass is not canonical!");
   return Specifier->isVirtual() &&
- Specifier->getType()->castAs()->getDecl()
-->getCanonicalDecl() == BaseRecord;
+ cast(Specifier->getType()->getAsRecordDecl())
+ ->getCanonicalDecl() == BaseRecord;
 }
 
 static bool isOrdinaryMember(const NamedDecl *ND) {
@@ -692,7 +692,7 @@ AddIndirectPrimaryBases(const CXXRecordDecl *RD, ASTContext 
&Context,
"Cannot get indirect primary bases for class with dependent 
bases.");
 
 const CXXRecordDecl *BaseDecl =
-  cast(I.getType()->castAs()->getDecl());
+cast(I.getType()->getAsRecordDecl());
 
 // Only bases with virtual bases participate in computing the
 // indirect primary virtual base classes.
@@ -714,7 +714,7 @@ 
CXXRecordDecl::getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const {
"Cannot get indirect primary bases for class with dependent 
bases.");
 
 const CXXRecordDecl *BaseDecl =
-  cast(I.getType()->castAs()->getDecl());
+cast(I.getType()->getAsRecordDecl());
 
 // Only bases with virtual bases participate in computing the
 // indirect primary virtual base classes.
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index 91a76fd2adbb6a..9a5a2f49db66b2 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1209,6 +1209,11 @@ namespace cwg591 { // cwg591: 20
 };
   };
 
+  template  struct M {
+class P;
+int M;
+  };
+
   template struct A::B::C : A {
 M m;
   };
@@ -1224,6 +1229,10 @@ namespace cwg591 { // cwg591: 20
 M m;
   };
 
+  template class M::P : M {
+int foo() { (void) M; }
+  };
+
   template struct A::B::D : A {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}

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


[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-08 Thread Vladislav Belov via cfe-commits


@@ -368,8 +368,8 @@ bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier 
*Specifier,
   const CXXRecordDecl *BaseRecord) {
   assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
  "User data for FindBaseClass is not canonical!");
-  return Specifier->getType()->castAs()->getDecl()
-->getCanonicalDecl() == BaseRecord;
+  return (cast(Specifier->getType()->getAsRecordDecl())
+  ->getCanonicalDecl()) == BaseRecord;

vbe-sc wrote:

Fixed.

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


[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-08 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> Can you confirm this is a fix for #118003 ? In which case we do not need 
> changelog entry

Yes, you are right

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-12-06 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> I was creducing it (well, cvise-ing). Here's a reproducer:
> 
> ```
> template  struct MozPromise {
>   class Private;
> 
> private:
>   void *mMagic4;
> };
> template 
> struct MozPromise::Private
> : MozPromise {
>   void SetTaskPriority() { mMagic4 }
> }
> ```

Thanks, I'll investigate with it 

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-12-06 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> I'm hitting an assertion on some Firefox code after this landed:
> 
> ```
> clang++: /tmp/llvm/llvm/include/llvm/Support/Casting.h:566: decltype(auto) 
> llvm::cast(const From &) [To = cl
> ang::RecordType, From = clang::QualType]: Assertion `isa(Val) && 
> "cast() argument of incompatible ty
> pe!"' failed.
> (...)
> 1.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:1348:5 
>  pc-linux-gnu/dist/include/mozilla/MozPromise.h:1348:38>: current parser token 
> '&&'
> 2.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:48:1: 
> parsing namespace 'mozilla'
> 3.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:1339:1: 
> parsing struct/union/class body 'mozilla::MozPromise::Private'
> 4.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:1347:75: 
> parsing function body 'mozilla::MozPromise::Private::Resolve'
> 5.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:1347:75: in 
> compound statement ('{}')
> 6.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:1348:5 
> :
>  in compound statement ('{}')
>   #0 0x7f5c64d183f9 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
> /tmp/llvm/llvm/lib/Support/Unix/Signals.inc:723:11
>   #1 0x7f5c64d188ab PrintStackTraceSignalHandler(void*) 
> /tmp/llvm/llvm/lib/Support/Unix/Signals.inc:798:1 
>   #2 0x7f5c64d16b6f llvm::sys::RunSignalHandlers() 
> /tmp/llvm/llvm/lib/Support/Signals.cpp:105:5
>   #3 0x7f5c64d17d69 llvm::sys::CleanupOnSignal(unsigned long) 
> /tmp/llvm/llvm/lib/Support/Unix/Signals.inc:368:1
>   #4 0x7f5c64bca842 (anonymous 
> namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) 
> /tmp/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:0:7
>   #5 0x7f5c64bcaba6 CrashRecoverySignalHandler(int) 
> /tmp/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:391:1
>   #6 0x7f5c62e5b050 (/lib/x86_64-linux-gnu/libc.so.6+0x3c050)
>   #7 0x7f5c62ea9ebc __pthread_kill_implementation 
> ./nptl/pthread_kill.c:44:76
>   #8 0x7f5c62e5afb2 raise ./signal/../sysdeps/posix/raise.c:27:6
>   #9 0x7f5c62e45472 abort ./stdlib/abort.c:81:7
>  #10 0x7f5c62e45395 _nl_load_domain ./intl/loadmsgcat.c:1177:9
>  #11 0x7f5c62e53eb2 (/lib/x86_64-linux-gnu/libc.so.6+0x34eb2)
>  #12 0x7f5c72cbf024 decltype(auto) llvm::cast clang::QualType>(clang::QualType const&) 
> /tmp/llvm/llvm/include/llvm/Support/Casting.h:567:43
>  #13 0x7f5c72cbaaa9 clang::RecordType const* 
> clang::Type::castAs() const 
> /tmp/llvm/obj/tools/clang/include/clang/AST/TypeNodes.inc:96:1
>  #14 0x7f5c730e72ca 
> clang::CXXRecordDecl::FindBaseClass(clang::CXXBaseSpecifier const*, 
> clang::CXXBasePath&, clang::CXXRecordDecl const*) 
> /tmp/llvm/clang/lib/AST/CXXInheritance.cpp:371:32
>  #15 0x7f5c730e868c 
> clang::CXXRecordDecl::isDerivedFrom(clang::CXXRecordDecl const*, 
> clang::CXXBasePaths&) const::$_0::operator()(clang::CXXBaseSpecifier const*, 
> clang::CXXBasePath&) const /tmp/llvm/clang/lib/AST/CXXInheritance.cpp:83:16
>  #16 0x7f5c730e8625 bool llvm::function_ref const*, 
> clang::CXXBasePath&)>::callback_fn  const*, clang::CXXBasePaths&) const::$_0>(long, clang::CXXBaseSpecifier 
> const*, clang::CXXBasePath&) 
> /tmp/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
>  #17 0x7f5c730e9cd9 llvm::function_ref const*, clang::CXXBasePath&)>::operator()(clang::CXXBaseSpecifier const*, 
> clang::CXXBasePath&) const 
> /tmp/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
>  #18 0x7f5c730e6e5e 
> clang::CXXBasePaths::lookupInBases(clang::ASTContext&, clang::CXXRecordDecl 
> const*, llvm::function_ref clang::CXXBasePath&)>, bool) /tmp/llvm/clang/lib/AST/CXXInheritance.cpp:242:9
>  #19 0x7f5c730e6586 
> clang::CXXRecordDecl::lookupInBases(llvm::function_ref (clang::CXXBaseSpecifier const*, clang::CXXBasePath&)>, clang::CXXBasePaths&, 
> bool) const /tmp/llvm/clang/lib/AST/CXXInheritance.cpp:314:7
>  #20 0x7f5c730e650e 
> clang::CXXRecordDecl::isDerivedFrom(clang::CXXRecordDecl const*, 
> clang::CXXBasePaths&) const /tmp/llvm/clang/lib/AST/CXXInheritance.cpp:80:3
>  #21 0x7f5c73dd0869 FindBestPath(clang::Sema&, (anonymous 
> namespace)::EffectiveContext const&, (anonymous namespace)::AccessTarget&, 
> clang::AccessSpecifier, clang::CXXBasePaths&) 
> /tmp/llvm/clang/lib/Sema/SemaAccess.cpp:956:8
>  #22 0x7f5c73dcf305 IsAccessible(clang::Sema&, (anonymous 
> namespace)::EffectiveContext const&, (anonymous namespace)::AccessTarget&) 
> /tmp/llvm/clang/lib/Sema/SemaAccess.cpp:1402:16
>  #23 0x7f5c73dccdee CheckEffectiveAccess(clang::Sema&, (anonymous 
> namespace)::EffectiveContext const&, clang::SourceLocation, (anonymous 
> namespace)::AccessTarget&) /tmp/llvm/clang/lib/Sema/SemaAccess.cpp:1437:3
>  #24 0x7f5c73dcd379 CheckAccess(clang::Sema&, clang::SourceLocation, 
> (anonymous namespace)::AccessTarget&) 
> /tmp/llvm/clang/lib/Sema/SemaAccess

[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-09 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@glandium, this is the fix for your example. Please, feel free to contact if 
you have any more troubles with this patch 

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


[clang] [clang][NFC] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-06 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc created 
https://github.com/llvm/llvm-project/pull/119024

An assertion failure occurs in Clang when attempting to compile such an example:

```c++
template  struct MozPromise {
  class Private;

private:
  int mMagic4 = 42;
};

template 
struct MozPromise::Private : 
MozPromise {
  void SetTaskPriority() { mMagic4 ; }
};
```

Output:
```
clang: llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) 
llvm::cast(const From&) [with To = clang::RecordType; From = clang::QualType]: 
Assertion `isa(Val) && "cast() argument of incompatible type!"' failed.
```

The reason is in the incorrect way of casting types when searching for names in 
base classes

```c++
return 
Specifier->getType()->castAs()->getDecl()->getCanonicalDecl() == 
BaseRecord;
```

It loses injected types for template class names. 

This patch provides fix for such cases

>From 9c501fc54a9673e9755fdef2a55d040a6fcceea5 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Fri, 6 Dec 2024 23:06:01 +0300
Subject: [PATCH] [clang][NFC] Fix cast for injected types in case name lookup
 for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 10b8d524ff8978..74848696963e99 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -368,8 +368,8 @@ bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier 
*Specifier,
   const CXXRecordDecl *BaseRecord) {
   assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
  "User data for FindBaseClass is not canonical!");
-  return Specifier->getType()->castAs()->getDecl()
-->getCanonicalDecl() == BaseRecord;
+  return (cast(Specifier->getType()->getAsRecordDecl())
+  ->getCanonicalDecl()) == BaseRecord;
 }
 
 bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
@@ -378,8 +378,8 @@ bool CXXRecordDecl::FindVirtualBaseClass(const 
CXXBaseSpecifier *Specifier,
   assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
  "User data for FindBaseClass is not canonical!");
   return Specifier->isVirtual() &&
- Specifier->getType()->castAs()->getDecl()
-->getCanonicalDecl() == BaseRecord;
+ (cast(Specifier->getType()->getAsRecordDecl())
+  ->getCanonicalDecl()) == BaseRecord;
 }
 
 static bool isOrdinaryMember(const NamedDecl *ND) {
@@ -692,7 +692,7 @@ AddIndirectPrimaryBases(const CXXRecordDecl *RD, ASTContext 
&Context,
"Cannot get indirect primary bases for class with dependent 
bases.");
 
 const CXXRecordDecl *BaseDecl =
-  cast(I.getType()->castAs()->getDecl());
+cast(I.getType()->getAsRecordDecl());
 
 // Only bases with virtual bases participate in computing the
 // indirect primary virtual base classes.
@@ -714,7 +714,7 @@ 
CXXRecordDecl::getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const {
"Cannot get indirect primary bases for class with dependent 
bases.");
 
 const CXXRecordDecl *BaseDecl =
-  cast(I.getType()->castAs()->getDecl());
+cast(I.getType()->getAsRecordDecl());
 
 // Only bases with virtual bases participate in computing the
 // indirect primary virtual base classes.

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-12-06 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@glandium, I've provided the fix in this PR 
(https://github.com/llvm/llvm-project/pull/119024). 

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


[clang] [clang][NFC] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-07 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/119024

>From e3fd6b1d8408439e200622f577451d144ef8f720 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Fri, 6 Dec 2024 23:06:01 +0300
Subject: [PATCH] [clang][NFC] Fix cast for injected types in case name lookup
 for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 12 ++--
 clang/test/CXX/drs/cwg5xx.cpp|  9 +
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 10b8d524ff8978..74848696963e99 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -368,8 +368,8 @@ bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier 
*Specifier,
   const CXXRecordDecl *BaseRecord) {
   assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
  "User data for FindBaseClass is not canonical!");
-  return Specifier->getType()->castAs()->getDecl()
-->getCanonicalDecl() == BaseRecord;
+  return (cast(Specifier->getType()->getAsRecordDecl())
+  ->getCanonicalDecl()) == BaseRecord;
 }
 
 bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
@@ -378,8 +378,8 @@ bool CXXRecordDecl::FindVirtualBaseClass(const 
CXXBaseSpecifier *Specifier,
   assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
  "User data for FindBaseClass is not canonical!");
   return Specifier->isVirtual() &&
- Specifier->getType()->castAs()->getDecl()
-->getCanonicalDecl() == BaseRecord;
+ (cast(Specifier->getType()->getAsRecordDecl())
+  ->getCanonicalDecl()) == BaseRecord;
 }
 
 static bool isOrdinaryMember(const NamedDecl *ND) {
@@ -692,7 +692,7 @@ AddIndirectPrimaryBases(const CXXRecordDecl *RD, ASTContext 
&Context,
"Cannot get indirect primary bases for class with dependent 
bases.");
 
 const CXXRecordDecl *BaseDecl =
-  cast(I.getType()->castAs()->getDecl());
+cast(I.getType()->getAsRecordDecl());
 
 // Only bases with virtual bases participate in computing the
 // indirect primary virtual base classes.
@@ -714,7 +714,7 @@ 
CXXRecordDecl::getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const {
"Cannot get indirect primary bases for class with dependent 
bases.");
 
 const CXXRecordDecl *BaseDecl =
-  cast(I.getType()->castAs()->getDecl());
+cast(I.getType()->getAsRecordDecl());
 
 // Only bases with virtual bases participate in computing the
 // indirect primary virtual base classes.
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index 91a76fd2adbb6a..9a5a2f49db66b2 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1209,6 +1209,11 @@ namespace cwg591 { // cwg591: 20
 };
   };
 
+  template  struct M {
+class P;
+int M;
+  };
+
   template struct A::B::C : A {
 M m;
   };
@@ -1224,6 +1229,10 @@ namespace cwg591 { // cwg591: 20
 M m;
   };
 
+  template class M::P : M {
+int foo() { (void) M; }
+  };
+
   template struct A::B::D : A {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}

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


[clang] [clang][NFC] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-07 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

@erichkeane, @cor3ntin, could you, please, take a look at this fix?

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