[clang] [clang][Interp] Fix classifying enum types (PR #104582)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 16 04:50:19 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We used to always return PT_IntAP(s) for them.
---
Full diff: https://github.com/llvm/llvm-project/pull/104582.diff
2 Files Affected:
- (modified) clang/lib/AST/Interp/Context.cpp (+3)
- (modified) clang/test/AST/Interp/enums.cpp (+5)
``````````diff
diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index 92ac28137fdb45..e9c1fd1b8dc9f9 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -135,6 +135,9 @@ std::optional<PrimType> Context::classify(QualType T) const {
if (T->isAnyComplexType() || T->isVectorType())
return std::nullopt;
+ if (const auto *ET = T->getAs<EnumType>())
+ return classify(ET->getDecl()->getIntegerType());
+
if (T->isSignedIntegerOrEnumerationType()) {
switch (Ctx.getIntWidth(T)) {
case 64:
diff --git a/clang/test/AST/Interp/enums.cpp b/clang/test/AST/Interp/enums.cpp
index c4db7875451677..459cf3a0c83d54 100644
--- a/clang/test/AST/Interp/enums.cpp
+++ b/clang/test/AST/Interp/enums.cpp
@@ -48,3 +48,8 @@ constexpr EC getB() {
static_assert(getB() == EC::B, "");
+
+namespace B {
+ enum E : bool { Zero, One };
+ static_assert((int)(E)2 == 1, "");
+} // namespace B
``````````
</details>
https://github.com/llvm/llvm-project/pull/104582
More information about the cfe-commits
mailing list