llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Oleksandr Tarasiuk (a-tarasyuk)

<details>
<summary>Changes</summary>

Fixes #<!-- -->177943

---

This patch addresses cases where `__underlying_type` is used with enum 
redeclarations. The previously added assertion 
(https://github.com/llvm/llvm-project/pull/155900) treated a missing `int` on 
the referenced `EnumDecl` as an indicator of a _demoted definition_, while this 
condition can also occur for redeclarations.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaType.cpp (-1) 
- (modified) clang/test/SemaCXX/underlying_type.cpp (+9) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d03211a200a29..1f7fc000897a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,7 @@ Bug Fixes in This Version
 - Fixed a failed assertion in the preprocessor when ``__has_embed`` parameters 
are missing parentheses. (#GH175088)
 
 - Fix lifetime extension of temporaries in for-range-initializers in 
templates. (#GH165182)
+- Fixes an assertion failure when evaluating ``__underlying_type`` on enum 
redeclarations. (#GH177943)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 91d36f0502d85..e941da7eeba98 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9891,7 +9891,6 @@ static QualType GetEnumUnderlyingType(Sema &S, QualType 
BaseType,
     // This is an enum without a fixed underlying type which we skipped parsing
     // the body because we saw its definition previously in another module.
     // Use the definition's integer type in that case.
-    assert(ED->isThisDeclarationADemotedDefinition());
     Underlying = ED->getDefinition()->getIntegerType();
     assert(!Underlying.isNull());
   }
diff --git a/clang/test/SemaCXX/underlying_type.cpp 
b/clang/test/SemaCXX/underlying_type.cpp
index 6e7a53661912a..f33843ba687bb 100644
--- a/clang/test/SemaCXX/underlying_type.cpp
+++ b/clang/test/SemaCXX/underlying_type.cpp
@@ -76,3 +76,12 @@ template <typename T>
 __underlying_type(T) ft();
 auto x = &ft<E>;
 }
+
+namespace GH177943 {
+enum E {};
+enum E;
+
+enum {
+  a = (__underlying_type(E)){ },
+};
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/177984
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to