Author: Chuanqi Xu Date: 2024-08-30T11:45:01+08:00 New Revision: ca2351dd142bac574021f48f135a9f9383c41128
URL: https://github.com/llvm/llvm-project/commit/ca2351dd142bac574021f48f135a9f9383c41128 DIFF: https://github.com/llvm/llvm-project/commit/ca2351dd142bac574021f48f135a9f9383c41128.diff LOG: [C++20] [Modules] Skip checking ODR for merged context in GMF Solve https://github.com/clangd/clangd/issues/2094 Due clangd will enable PCH automatically, the previous mechanism to skip ODR check in GMF may be invalid. This patch fixes this for a case. Added: clang/test/Modules/skip-func-def-odr-with-pch.cppm Modified: clang/lib/Serialization/ASTReaderDecl.cpp Removed: ################################################################################ diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index d1b77358d0cde4..9272e23c7da3fc 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -3505,7 +3505,8 @@ ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { // same template specialization into the same CXXRecordDecl. auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext()); if (MergedDCIt != Reader.MergedDeclContexts.end() && - !shouldSkipCheckingODR(D) && MergedDCIt->second == D->getDeclContext()) + !shouldSkipCheckingODR(D) && MergedDCIt->second == D->getDeclContext() && + !shouldSkipCheckingODR(cast<Decl>(D->getDeclContext()))) Reader.PendingOdrMergeChecks.push_back(D); return FindExistingResult(Reader, D, /*Existing=*/nullptr, diff --git a/clang/test/Modules/skip-func-def-odr-with-pch.cppm b/clang/test/Modules/skip-func-def-odr-with-pch.cppm new file mode 100644 index 00000000000000..7fb5227d7c61e9 --- /dev/null +++ b/clang/test/Modules/skip-func-def-odr-with-pch.cppm @@ -0,0 +1,44 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: split-file %s %t +// +// Testing the behavior of `-fskip-odr-check-in-gmf` +// RUN: %clang_cc1 -std=c++20 -DDIFFERENT -fskip-odr-check-in-gmf %t/A.cppm -emit-module-interface -o %t/A.pcm +// RUN: %clang_cc1 -std=c++20 -fskip-odr-check-in-gmf -x c++-header %t/foo.h -emit-pch -o %t/foo.pch +// RUN: %clang_cc1 -std=c++20 -fskip-odr-check-in-gmf -include-pch %t/foo.pch %t/B.cppm -emit-module-interface -o %t/B.pcm +// RUN: %clang_cc1 -std=c++20 -fskip-odr-check-in-gmf -fprebuilt-module-path=%t \ +// RUN: %t/C.cpp -verify -fsyntax-only + +//--- foo.h +#ifndef FOO_H +#define FOO_H +class A { +public: +#ifndef DIFFERENT + void func() { + + } +#endif +}; +#endif + +//--- A.cppm +module; +#include "foo.h" +export module A; +export using ::A; + +//--- B.cppm +module; +#include "foo.h" +export module B; +export using ::A; + +//--- C.cpp +import A; +import B; +// expected-no-diagnostics +void C() { + A a; + a.func(); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits