Skip to content

Conversation

@Michael137
Copy link
Member

@Michael137 Michael137 commented Dec 5, 2025

The enum cases for SuppressInlineNamespaceMode leaked into the rest of PrintingPolicy, meaning if we wanted to introduce another enum (which I'm planning on doing in an unrelated PR), then All/None/Redundant are all already taken, which are quite useful names.

This patch turns SuppressInlineNamespaceMode into an enum class, freeing up the names for use by other future enums in PrintingPolicy.

Unfortunately that means we have to cast the values when assigning to PrintingPolicy::SuppressInlineNamespace, because its actual type is unsigned. But if we ever make the bitfields have proper enumeration types (which AFAIU is dependent on an MSVC codegen fix), then we can get rid of those casts.

While doing this I found three instances of assigning booleans to SuppressInlineNamespace. I added a FIXME in LLDB to check what the intended value of the enum should be.

The enum cases for `SuppressInlineNamespaceMode` leaked into the rest of `PrintingPolicy`, meaning if we wanted to introduce another enum (which I'm planning on doing in an unrelated PR), then `All`/`None`/`Redundant` are all already taken, which are quite useful names.

This patch turns `SuppressInlineNamespaceMode` into an `enum class`, freeing up the names for use by other future enums in `PrintingPolicy`.

Unfortunately that means we have to cast the values when assigning to `PrintingPolicy::SuppressInlineNamespace`, because it's actual type is `unsigned`. But if we ever make the bitfields have proper enumeration types (which AFAIU is dependent on an MSVC codegen fix), then we can get rid of those casts.

This caught three instances of assigning booleans to `SuppressInlineNamespace`. I added a FIXME in LLDB to check what the intended value of the enum should be.
@llvmbot llvmbot added lldb clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen IR generation bugs: mangling, exceptions, etc. debuginfo ClangIR Anything related to the ClangIR project labels Dec 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2025

@llvm/pr-subscribers-clangir
@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-debuginfo

Author: Michael Buch (Michael137)

Changes

The enum cases for SuppressInlineNamespaceMode leaked into the rest of PrintingPolicy, meaning if we wanted to introduce another enum (which I'm planning on doing in an unrelated PR), then All/None/Redundant are all already taken, which are quite useful names.

This patch turns SuppressInlineNamespaceMode into an enum class, freeing up the names for use by other future enums in PrintingPolicy.

Unfortunately that means we have to cast the values when assigning to PrintingPolicy::SuppressInlineNamespace, because its actual type is unsigned. But if we ever make the bitfields have proper enumeration types (which AFAIU is dependent on an MSVC codegen fix), then we can get rid of those casts.

This caught three instances of assigning booleans to SuppressInlineNamespace. I added a FIXME in LLDB to check what the intended value of the enum should be.


Full diff: https://github.com/llvm/llvm-project/pull/170802.diff

7 Files Affected:

  • (modified) clang/include/clang/AST/PrettyPrinter.h (+3-2)
  • (modified) clang/lib/AST/Decl.cpp (+4-2)
  • (modified) clang/lib/ASTMatchers/ASTMatchersInternal.cpp (+2-2)
  • (modified) clang/lib/CIR/CodeGen/CIRGenTypes.cpp (+2-1)
  • (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+1-1)
  • (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+1-1)
  • (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+5-2)
diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h
index fd995a653d167..289dff7b23010 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -55,14 +55,15 @@ class PrintingCallbacks {
 /// This type is intended to be small and suitable for passing by value.
 /// It is very frequently copied.
 struct PrintingPolicy {
-  enum SuppressInlineNamespaceMode : uint8_t { None, Redundant, All };
+  enum class SuppressInlineNamespaceMode : uint8_t { None, Redundant, All };
 
   /// Create a default printing policy for the specified language.
   PrintingPolicy(const LangOptions &LO)
       : Indentation(2), SuppressSpecifiers(false),
         SuppressTagKeyword(LO.CPlusPlus), IncludeTagDefinition(false),
         SuppressScope(false), SuppressUnwrittenScope(false),
-        SuppressInlineNamespace(SuppressInlineNamespaceMode::Redundant),
+        SuppressInlineNamespace(
+            llvm::to_underlying(SuppressInlineNamespaceMode::Redundant)),
         SuppressInitializers(false), ConstantArraySizeAsWritten(false),
         AnonymousTagLocations(true), SuppressStrongLifetime(false),
         SuppressLifetimeQualifiers(false),
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 591457b1d66b4..4444b10db8cc0 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1753,9 +1753,11 @@ void NamedDecl::printNestedNameSpecifier(raw_ostream &OS,
     // Suppress inline namespace if it doesn't make the result ambiguous.
     if (Ctx->isInlineNamespace() && NameInScope) {
       if (P.SuppressInlineNamespace ==
-              PrintingPolicy::SuppressInlineNamespaceMode::All ||
+              llvm::to_underlying(
+                  PrintingPolicy::SuppressInlineNamespaceMode::All) ||
           (P.SuppressInlineNamespace ==
-               PrintingPolicy::SuppressInlineNamespaceMode::Redundant &&
+               llvm::to_underlying(
+                   PrintingPolicy::SuppressInlineNamespaceMode::Redundant) &&
            cast<NamespaceDecl>(Ctx)->isRedundantInlineQualifierFor(
                NameInScope))) {
         continue;
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index fbb8b49676045..a556ffca96903 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -654,9 +654,9 @@ bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl &Node) const {
 
     PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy();
     Policy.SuppressUnwrittenScope = SkipUnwritten;
-    Policy.SuppressInlineNamespace =
+    Policy.SuppressInlineNamespace = llvm::to_underlying(
         SkipUnwritten ? PrintingPolicy::SuppressInlineNamespaceMode::All
-                      : PrintingPolicy::SuppressInlineNamespaceMode::None;
+                      : PrintingPolicy::SuppressInlineNamespaceMode::None);
     Node.printQualifiedName(OS, Policy);
 
     const StringRef FullName = OS.str();
diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
index efc2c6c0ba500..24b106b4bcee7 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
@@ -97,7 +97,8 @@ std::string CIRGenTypes::getRecordTypeName(const clang::RecordDecl *recordDecl,
   llvm::raw_svector_ostream outStream(typeName);
 
   PrintingPolicy policy = recordDecl->getASTContext().getPrintingPolicy();
-  policy.SuppressInlineNamespace = false;
+  policy.SuppressInlineNamespace =
+      llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
   policy.AlwaysIncludeTypeForTemplateArgument = true;
   policy.PrintAsCanonical = true;
   policy.SuppressTagKeyword = true;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index c50f372c1f331..5a83c151901f9 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -417,7 +417,7 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
   }
 
   PP.SuppressInlineNamespace =
-      PrintingPolicy::SuppressInlineNamespaceMode::None;
+      llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
   PP.PrintAsCanonical = true;
   PP.UsePreferredNames = false;
   PP.AlwaysIncludeTypeForTemplateArgument = true;
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp
index ea31195b7f92e..be862cf07f177 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -62,7 +62,7 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD,
   // FullyQualifiedNames.
   PrintingPolicy Policy = RD->getASTContext().getPrintingPolicy();
   Policy.SuppressInlineNamespace =
-      PrintingPolicy::SuppressInlineNamespaceMode::None;
+      llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
 
   // Name the codegen type after the typedef name
   // if there is no tag type name available
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index aa8d309fbc730..2cb4a46130c84 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2149,7 +2149,8 @@ PrintingPolicy TypeSystemClang::GetTypePrintingPolicy() {
   printing_policy.SuppressTagKeyword = true;
   // Inline namespaces are important for some type formatters (e.g., libc++
   // and libstdc++ are differentiated by their inline namespaces).
-  printing_policy.SuppressInlineNamespace = false;
+  printing_policy.SuppressInlineNamespace =
+      llvm::to_underlying(PrintingPolicy::SuppressInlineNamespaceMode::None);
   printing_policy.SuppressUnwrittenScope = false;
   // Default arguments are also always important for type formatters. Otherwise
   // we would need to always specify two type names for the setups where we do
@@ -3870,7 +3871,9 @@ TypeSystemClang::GetDisplayTypeName(lldb::opaque_compiler_type_t type) {
   printing_policy.SuppressTagKeyword = true;
   printing_policy.SuppressScope = false;
   printing_policy.SuppressUnwrittenScope = true;
-  printing_policy.SuppressInlineNamespace = true;
+  // FIXME: should we suppress "All" inline namespaces?
+  printing_policy.SuppressInlineNamespace = llvm::to_underlying(
+      PrintingPolicy::SuppressInlineNamespaceMode::Redundant);
   return ConstString(qual_type.getAsString(printing_policy));
 }
 

@Michael137
Copy link
Member Author

Michael137 commented Dec 5, 2025

AArch64 LLDB test failure is unrelated:

2025-12-05T07:21:42.7386549Z ======================================================================
2025-12-05T07:21:42.7387081Z FAIL: test_libcxx_dwarf (TestDataFormatterStdMap.StdMapDataFormatterTestCase.test_libcxx_dwarf)
2025-12-05T07:21:42.7387604Z ----------------------------------------------------------------------
2025-12-05T07:21:42.7387979Z Traceback (most recent call last):
2025-12-05T07:21:42.7388489Z   File "/__w/llvm-project/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1809, in test_method
2025-12-05T07:21:42.7389040Z     return attrvalue(self)
2025-12-05T07:21:42.7389302Z            ^^^^^^^^^^^^^^^
2025-12-05T07:21:42.7389970Z   File "/__w/llvm-project/llvm-project/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/map/TestDataFormatterStdMap.py", line 335, in test_libcxx
2025-12-05T07:21:42.7390688Z     self.do_test()
2025-12-05T07:21:42.7391316Z   File "/__w/llvm-project/llvm-project/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/map/TestDataFormatterStdMap.py", line 31, in do_test
2025-12-05T07:21:42.7391996Z     lldbutil.run_break_set_by_source_regexp(
2025-12-05T07:21:42.7392568Z   File "/__w/llvm-project/llvm-project/lldb/packages/Python/lldbsuite/test/lldbutil.py", line 517, in run_break_set_by_source_regexp
2025-12-05T07:21:42.7393172Z     break_results = run_break_set_command(test, command)
2025-12-05T07:21:42.7393532Z                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-12-05T07:21:42.7394062Z   File "/__w/llvm-project/llvm-project/lldb/packages/Python/lldbsuite/test/lldbutil.py", line 580, in run_break_set_command
2025-12-05T07:21:42.7394612Z     match_object = test.match(command, patterns)
2025-12-05T07:21:42.7394923Z                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-12-05T07:21:42.7395529Z   File "/__w/llvm-project/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2112, in match
2025-12-05T07:21:42.7396128Z     self.runCmd(str, msg=msg, trace=(True if trace else False), check=not error)
2025-12-05T07:21:42.7396777Z   File "/__w/llvm-project/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1006, in runCmd
2025-12-05T07:21:42.7397317Z     self.assertTrue(self.res.Succeeded(), msg + output)
2025-12-05T07:21:42.7397867Z AssertionError: False is not true : Command 'breakpoint add pattern -- Set break point at this line.' did not return successfully
2025-12-05T07:21:42.7398389Z Error output:
2025-12-05T07:21:42.7398722Z error: No selected frame to use to find the default file.
2025-12-05T07:21:42.7399127Z error: No files provided and could not find default file.
2025-12-05T07:21:42.7399406Z 
2025-12-05T07:21:42.7399627Z Config=aarch64-/__w/llvm-project/llvm-project/build/bin/clang
2025-12-05T07:21:42.7400025Z ----------------------------------------------------------------------
2025-12-05T07:21:42.7400391Z Ran 16 tests in 4.979s
2025-12-05T07:21:42.7400582Z 
2025-12-05T07:21:42.7400774Z FAILED (failures=1, skipped=10, expected failures=2)

Happens on other PRs too

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Michael137 Michael137 merged commit 6dac9b4 into llvm:main Dec 5, 2025
9 of 10 checks passed
@Michael137 Michael137 deleted the lldb/pretty-printer-enum-class branch December 5, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" ClangIR Anything related to the ClangIR project debuginfo lldb

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants