Skip to content

Commit 70195e0

Browse files
ChuanqiXu9tstellar
authored andcommitted
[C++20] [Modules] Remove previous workaround for odr hashing enums
Previosly we land 085eae6 to workaround the false positive ODR violations in #76638. However, we decided to not perform ODR checks for decls from GMF in #79240 and we land the corresponding change. So we should be able to remove the workaround now. The original tests get remained.
1 parent a0e1cc0 commit 70195e0

File tree

3 files changed

+52
-51
lines changed

3 files changed

+52
-51
lines changed

clang/docs/ReleaseNotes.rst

-3
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,6 @@ Bug Fixes to C++ Support
10411041
in different visibility.
10421042
Fixes (`#67893 <https://github.com/llvm/llvm-project/issues/67893>`_)
10431043

1044-
- Fix a false-positive ODR violation for different definitions for `std::align_val_t`.
1045-
Fixes (`#76638 <https://github.com/llvm/llvm-project/issues/76638>`_)
1046-
10471044
- Remove recorded `#pragma once` state for headers included in named modules.
10481045
Fixes (`#77995 <https://github.com/llvm/llvm-project/issues/77995>`_)
10491046

clang/lib/AST/ODRHash.cpp

+1-48
Original file line numberDiff line numberDiff line change
@@ -745,55 +745,8 @@ void ODRHash::AddEnumDecl(const EnumDecl *Enum) {
745745
if (Enum->isScoped())
746746
AddBoolean(Enum->isScopedUsingClassTag());
747747

748-
if (Enum->getIntegerTypeSourceInfo()) {
749-
// FIMXE: This allows two enums with different spellings to have the same
750-
// hash.
751-
//
752-
// // mod1.cppm
753-
// module;
754-
// extern "C" {
755-
// typedef unsigned __int64 size_t;
756-
// }
757-
// namespace std {
758-
// using :: size_t;
759-
// }
760-
//
761-
// extern "C++" {
762-
// namespace std {
763-
// enum class align_val_t : std::size_t {};
764-
// }
765-
// }
766-
//
767-
// export module mod1;
768-
// export using std::align_val_t;
769-
//
770-
// // mod2.cppm
771-
// module;
772-
// extern "C" {
773-
// typedef unsigned __int64 size_t;
774-
// }
775-
//
776-
// extern "C++" {
777-
// namespace std {
778-
// enum class align_val_t : size_t {};
779-
// }
780-
// }
781-
//
782-
// export module mod2;
783-
// import mod1;
784-
// export using std::align_val_t;
785-
//
786-
// The above example should be disallowed since it violates
787-
// [basic.def.odr]p14:
788-
//
789-
// Each such definition shall consist of the same sequence of tokens
790-
//
791-
// The definitions of `std::align_val_t` in two module units have different
792-
// spellings but we failed to give an error here.
793-
//
794-
// See https://github.com/llvm/llvm-project/issues/76638 for details.
748+
if (Enum->getIntegerTypeSourceInfo())
795749
AddQualType(Enum->getIntegerType().getCanonicalType());
796-
}
797750

798751
// Filter out sub-Decls which will not be processed in order to get an
799752
// accurate count of Decl's.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/mod1.cppm -emit-module-interface -o %t/mod1.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/mod2.cppm -emit-module-interface -o %t/mod2.pcm
7+
// RUN: %clang_cc1 -std=c++20 %t/test.cpp -fprebuilt-module-path=%t -verify -fsyntax-only
8+
9+
//--- size_t.h
10+
11+
extern "C" {
12+
typedef unsigned int size_t;
13+
}
14+
15+
//--- csize_t
16+
namespace std {
17+
using :: size_t;
18+
}
19+
20+
//--- align.h
21+
namespace std {
22+
enum class align_val_t : size_t {};
23+
}
24+
25+
//--- mod1.cppm
26+
module;
27+
#include "size_t.h"
28+
#include "align.h"
29+
export module mod1;
30+
namespace std {
31+
export using std::align_val_t;
32+
}
33+
34+
//--- mod2.cppm
35+
module;
36+
#include "size_t.h"
37+
#include "csize_t"
38+
#include "align.h"
39+
export module mod2;
40+
namespace std {
41+
export using std::align_val_t;
42+
}
43+
44+
//--- test.cpp
45+
// expected-no-diagnostics
46+
import mod1;
47+
import mod2;
48+
void test() {
49+
std::align_val_t v;
50+
}
51+

0 commit comments

Comments
 (0)