[clang] [clang][Interp] Fix classifying enum types (PR #104582)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 16 04:49:49 PDT 2024


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/104582

We used to always return PT_IntAP(s) for them.

>From b838d2c2c71868ef48b8357c744e5b8d41ba5d14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 16 Aug 2024 13:48:44 +0200
Subject: [PATCH] [clang][Interp] Fix classifying enum types

We used to always return PT_IntAP(s) for them.
---
 clang/lib/AST/Interp/Context.cpp | 3 +++
 clang/test/AST/Interp/enums.cpp  | 5 +++++
 2 files changed, 8 insertions(+)

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



More information about the cfe-commits mailing list