Author: Chuanqi Xu Date: 2022-07-04T17:38:05+08:00 New Revision: f4dd977537dc0fcd8605a1ce066a4c7fd271a5d7
URL: https://github.com/llvm/llvm-project/commit/f4dd977537dc0fcd8605a1ce066a4c7fd271a5d7 DIFF: https://github.com/llvm/llvm-project/commit/f4dd977537dc0fcd8605a1ce066a4c7fd271a5d7.diff LOG: [AST] Use canonical constraint declaration for ASTContext::getAutoType When we do profiling in ASTContext::getAutoType, it wouldn't think about the canonical declaration for the type constraint. It is bad since it would cause a negative ODR mismatch while we already know the type constraint declaration is a redeclaration for the previous one. Also it shouldn't be bad to use the canonical declaration here. Added: Modified: clang/lib/AST/ASTContext.cpp clang/test/Modules/concept.cppm Removed: ################################################################################ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 682b71a3d6865..e64135cbf3f4e 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -5707,6 +5707,9 @@ QualType ASTContext::getAutoTypeInternal( !TypeConstraintConcept && !IsDependent) return getAutoDeductType(); + if (TypeConstraintConcept) + TypeConstraintConcept = TypeConstraintConcept->getCanonicalDecl(); + // Look in the folding set for an existing type. void *InsertPos = nullptr; llvm::FoldingSetNodeID ID; diff --git a/clang/test/Modules/concept.cppm b/clang/test/Modules/concept.cppm index f171e6d082374..84bc0fef83926 100644 --- a/clang/test/Modules/concept.cppm +++ b/clang/test/Modules/concept.cppm @@ -1,10 +1,54 @@ // RUN: rm -rf %t // RUN: mkdir %t -// RUN: %clang_cc1 -x c++ -std=c++20 %S/Inputs/concept/A.cppm -emit-module-interface -o %t/A.pcm -// RUN: %clang_cc1 -x c++ -std=c++20 -fprebuilt-module-path=%t -I%S/Inputs/concept %s -fsyntax-only -verify -// expected-no-diagnostics +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm +// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/B.cppm -verify + +//--- foo.h +#ifndef FOO_H +#define FOO_H + +template <class T> +concept Range = requires(T &t) { t.begin(); }; + +template<class _Tp> +concept __integer_like = true; + +template <class _Tp> +concept __member_size = requires(_Tp &&t) { t.size(); }; + +struct A { +public: + template <Range T> + using range_type = T; +}; +struct __fn { + template <__member_size _Tp> + constexpr __integer_like auto operator()(_Tp&& __t) const { + return __t.size(); + } +}; +#endif + +//--- A.cppm +module; +#include "foo.h" +export module A; + +//--- B.cppm +// expected-no-diagnostics module; #include "foo.h" export module B; import A; + +void foo() { + A a; + struct S { + int size() { return 0; } + auto operator+(S s) { return 0; } + }; + __fn{}(S()); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits