[clang] 016970d - [Clang] Fix cast to BigIntType in hasUniqueObjectRepresentations
Roy Jacobson via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 10 12:12:03 PDT 2023
Author: Roy Jacobson
Date: 2023-04-10T22:11:57+03:00
New Revision: 016970d079c40b99c28c6973df8f7a98e8b8d536
URL: https://github.com/llvm/llvm-project/commit/016970d079c40b99c28c6973df8f7a98e8b8d536
DIFF: https://github.com/llvm/llvm-project/commit/016970d079c40b99c28c6973df8f7a98e8b8d536.diff
LOG: [Clang] Fix cast to BigIntType in hasUniqueObjectRepresentations
A bad QualType cast caused us not to detect _BigInt types if they were wrapped inside sugar types like SubstTemplateTypeParm.
Fix https://github.com/llvm/llvm-project/issues/62019
Reviewed By: cjdb
Differential Revision: https://reviews.llvm.org/D147904
Added:
Modified:
clang/lib/AST/ASTContext.cpp
clang/test/SemaCXX/type-traits.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 74826da6703f5..6f36b056c7bb9 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2832,7 +2832,7 @@ bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const {
// All integrals and enums are unique.
if (Ty->isIntegralOrEnumerationType()) {
// Except _BitInt types that have padding bits.
- if (const auto *BIT = dyn_cast<BitIntType>(Ty))
+ if (const auto *BIT = Ty->getAs<BitIntType>())
return getTypeSize(BIT) == BIT->getNumBits();
return true;
diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp
index e3fc65713cedf..cc0a83706475d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -2970,6 +2970,12 @@ namespace ErrorType {
bool b = __has_unique_object_representations(T);
};
+static_assert(!has_unique_object_representations<_BitInt(7)>::value, "BitInt:");
+static_assert(has_unique_object_representations<_BitInt(8)>::value, "BitInt:");
+static_assert(!has_unique_object_representations<_BitInt(127)>::value, "BitInt:");
+static_assert(has_unique_object_representations<_BitInt(128)>::value, "BitInt:");
+
+
namespace PR46209 {
// Foo has both a trivial assignment operator and a non-trivial one.
struct Foo {
More information about the cfe-commits
mailing list