[clang] 1cdf1e6 - [clang][Interp] Fix classifying enum types (#104582)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 16 05:37:48 PDT 2024


Author: Timm Baeder
Date: 2024-08-16T14:37:45+02:00
New Revision: 1cdf1e693425ae6830883d2fc0eaaa601a8250d8

URL: https://github.com/llvm/llvm-project/commit/1cdf1e693425ae6830883d2fc0eaaa601a8250d8
DIFF: https://github.com/llvm/llvm-project/commit/1cdf1e693425ae6830883d2fc0eaaa601a8250d8.diff

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

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

Added: 
    

Modified: 
    clang/lib/AST/Interp/Context.cpp
    clang/test/AST/Interp/enums.cpp

Removed: 
    


################################################################################
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