ChuanqiXu created this revision.
ChuanqiXu added reviewers: rsmith, aaron.ballman, urnathan, iains.
ChuanqiXu added a project: clang.
ChuanqiXu requested review of this revision.
Herald added a subscriber: cfe-commits.

See https://github.com/llvm/llvm-project/issues/52713.
This patch is a attempt to fix bug52713.

The key reason for the bug is that `isSameEntity` couldn't recognize `void 
bar(Ty)` in imported module and current module as the same entity. Since the 
compiler thinks the `Ty` type in the argument in imported module and the 
current are different type.

I found the reason is that the `isSameEntity` would judge if two types are the 
same by comparing the addressed of their canonical type. But the `Ty` type in 
this example is `UnresolvedUsingType` and the canonical type of 
`UnresolvedUsingType ` is always null. So that the compare result would be 
different always.

My solution in this patch is to not create a new `UnresolvedUsingType` when 
unserialization if there is already a canonical type in canonical declaration. 
I am not sure if this is proper but it runs well currently.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115792

Files:
  clang/include/clang/AST/TypeProperties.td
  clang/test/Modules/Inputs/odr_using_dependent_name/X.cppm
  clang/test/Modules/Inputs/odr_using_dependent_name/foo.h
  clang/test/Modules/odr_using_dependent_name.cppm


Index: clang/test/Modules/odr_using_dependent_name.cppm
===================================================================
--- /dev/null
+++ clang/test/Modules/odr_using_dependent_name.cppm
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang -std=c++20 %S/Inputs/odr_using_dependent_name/X.cppm 
--precompile -o %t/X.pcm
+// RUN: %clang -std=c++20 -I%S/Inputs/odr_using_dependent_name 
-fprebuilt-module-path=%t %s --precompile -c
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module Y;
+import X;
Index: clang/test/Modules/Inputs/odr_using_dependent_name/foo.h
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/odr_using_dependent_name/foo.h
@@ -0,0 +1,9 @@
+template <class T>
+struct bar {
+  using Ty = int;
+};
+template <class T>
+struct foo : public bar<T> {
+  using typename bar<T>::Ty;
+  void baz(Ty);
+};
Index: clang/test/Modules/Inputs/odr_using_dependent_name/X.cppm
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/odr_using_dependent_name/X.cppm
@@ -0,0 +1,3 @@
+module;
+#include "foo.h"
+export module X;
Index: clang/include/clang/AST/TypeProperties.td
===================================================================
--- clang/include/clang/AST/TypeProperties.td
+++ clang/include/clang/AST/TypeProperties.td
@@ -358,6 +358,9 @@
   }
 
   def : Creator<[{
+    auto *Previous = 
cast<UnresolvedUsingTypenameDecl>(declaration)->getCanonicalDecl();
+    if (Previous && Previous->getTypeForDecl())
+      return Previous->getTypeForDecl()->getCanonicalTypeInternal();
     return ctx.getTypeDeclType(cast<UnresolvedUsingTypenameDecl>(declaration));
   }]>;
 }


Index: clang/test/Modules/odr_using_dependent_name.cppm
===================================================================
--- /dev/null
+++ clang/test/Modules/odr_using_dependent_name.cppm
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang -std=c++20 %S/Inputs/odr_using_dependent_name/X.cppm --precompile -o %t/X.pcm
+// RUN: %clang -std=c++20 -I%S/Inputs/odr_using_dependent_name -fprebuilt-module-path=%t %s --precompile -c
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module Y;
+import X;
Index: clang/test/Modules/Inputs/odr_using_dependent_name/foo.h
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/odr_using_dependent_name/foo.h
@@ -0,0 +1,9 @@
+template <class T>
+struct bar {
+  using Ty = int;
+};
+template <class T>
+struct foo : public bar<T> {
+  using typename bar<T>::Ty;
+  void baz(Ty);
+};
Index: clang/test/Modules/Inputs/odr_using_dependent_name/X.cppm
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/odr_using_dependent_name/X.cppm
@@ -0,0 +1,3 @@
+module;
+#include "foo.h"
+export module X;
Index: clang/include/clang/AST/TypeProperties.td
===================================================================
--- clang/include/clang/AST/TypeProperties.td
+++ clang/include/clang/AST/TypeProperties.td
@@ -358,6 +358,9 @@
   }
 
   def : Creator<[{
+    auto *Previous = cast<UnresolvedUsingTypenameDecl>(declaration)->getCanonicalDecl();
+    if (Previous && Previous->getTypeForDecl())
+      return Previous->getTypeForDecl()->getCanonicalTypeInternal();
     return ctx.getTypeDeclType(cast<UnresolvedUsingTypenameDecl>(declaration));
   }]>;
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to