Skip to content

Commit

Permalink
[C++20] [Modules] [Serialization] Don't record '#pragma once' informa…
Browse files Browse the repository at this point in the history
…tion in named modules

Close #77995

The cause of the issue is that straight forward that we recorded the
'#pragma once' information in named modules, which is an overlook.

I tried to not record the header's information completely within named
modules. But the tests look not happy with some diagnosing problems,
which needs to be looked in details.
  • Loading branch information
ChuanqiXu9 committed Jan 15, 2024
1 parent 9c4cd79 commit 7bc170a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,8 @@ namespace {

unsigned char Flags = (Data.AlreadyIncluded << 6)
| (Data.HFI.isImport << 5)
| (Data.HFI.isPragmaOnce << 4)
| (Writer.isWritingStdCXXNamedModules() ? 0 :
Data.HFI.isPragmaOnce << 4)
| (Data.HFI.DirInfo << 1)
| Data.HFI.IndexHeaderMapHeader;
LE.write<uint8_t>(Flags);
Expand Down
25 changes: 25 additions & 0 deletions clang/test/Modules/pr77995.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -std=c++20 %t/foo.cppm -emit-module-interface -o %t/foo.pcm
// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fmodule-file=foo=%t/foo.pcm -verify -fsyntax-only

//--- a.hpp
#pragma once
#define A 43

//--- foo.cppm
module;
#include "a.hpp"
export module foo;
export constexpr auto B = A;

//--- use.cpp
// expected-no-diagnostics
import foo;
#include "a.hpp"

static_assert(A == 43);
static_assert(B == 43);

0 comments on commit 7bc170a

Please sign in to comment.