https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/102115
Close https://github.com/llvm/llvm-project/issues/101939 As the issue said, the builtin declarations shouldn't be in any modules. >From 3dabd3815c78697046ba436e62a2ea39cf2361b3 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu <yedeng...@linux.alibaba.com> Date: Tue, 6 Aug 2024 17:07:01 +0800 Subject: [PATCH] [C++20] [Modules] Don't set modules owner ship information for builtin declarations Close https://github.com/llvm/llvm-project/issues/101939 As the issue said, the builtin declarations shouldn't be in any modules. --- clang/lib/Sema/SemaDecl.cpp | 6 ++++++ clang/test/Modules/pr101939.cppm | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 clang/test/Modules/pr101939.cppm diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 1f4bfa247b544..a82c66ced817e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2376,6 +2376,12 @@ NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, FunctionDecl *New = CreateBuiltin(II, R, ID, Loc); RegisterLocallyScopedExternCDecl(New, S); + // Builtin functions shouldn't be owned by any module. + if (New->hasOwningModule()) { + New->setLocalOwningModule(nullptr); + New->setModuleOwnershipKind(Decl::ModuleOwnershipKind::Unowned); + } + // TUScope is the translation-unit scope to insert this function into. // FIXME: This is hideous. We need to teach PushOnScopeChains to // relate Scopes to DeclContexts, and probably eliminate CurContext diff --git a/clang/test/Modules/pr101939.cppm b/clang/test/Modules/pr101939.cppm new file mode 100644 index 0000000000000..35c243ed0f1bf --- /dev/null +++ b/clang/test/Modules/pr101939.cppm @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -std=c++20 %s -ast-dump | FileCheck %s + +export module mod; +export auto a = __builtin_expect(true, true); + +// CHECK-NOT: FunctionDecl{{.*}} in mod {{.*}} __builtin_expect _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits