[clang] cb3ea52 - Handle char{8,16,32} and wchar_t in ASTContext::getIntegerRank()
Hans Wennborg via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 7 07:16:46 PST 2022
Author: Hans Wennborg
Date: 2022-12-07T16:12:38+01:00
New Revision: cb3ea52a5ae5178b8cd257bd61c6e05d9a186b4d
URL: https://github.com/llvm/llvm-project/commit/cb3ea52a5ae5178b8cd257bd61c6e05d9a186b4d
DIFF: https://github.com/llvm/llvm-project/commit/cb3ea52a5ae5178b8cd257bd61c6e05d9a186b4d.diff
LOG: Handle char{8,16,32} and wchar_t in ASTContext::getIntegerRank()
They were previously not handled, causing the llvm_unreachable with
"getIntegerRank(): not a built-in integer" message to be hit.
The test case is derived from how we hit it in Chromium
(crbug.com/1396142). I tried to come up with something more direct, but
this is the best I could find.
Differential revision: https://reviews.llvm.org/D139428
Added:
Modified:
clang/lib/AST/ASTContext.cpp
clang/test/SemaCXX/vector.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 31eae3d7e33b5..e6f360fe79533 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -7102,6 +7102,21 @@ unsigned ASTContext::getIntegerRank(const Type *T) const {
case BuiltinType::Int128:
case BuiltinType::UInt128:
return 7 + (getIntWidth(Int128Ty) << 3);
+
+ // "The ranks of char8_t, char16_t, char32_t, and wchar_t equal the ranks of
+ // their underlying types" [c++20 conv.rank]
+ case BuiltinType::Char8:
+ return getIntegerRank(UnsignedCharTy.getTypePtr());
+ case BuiltinType::Char16:
+ return getIntegerRank(
+ getFromTargetType(Target->getChar16Type()).getTypePtr());
+ case BuiltinType::Char32:
+ return getIntegerRank(
+ getFromTargetType(Target->getChar32Type()).getTypePtr());
+ case BuiltinType::WChar_S:
+ case BuiltinType::WChar_U:
+ return getIntegerRank(
+ getFromTargetType(Target->getWCharType()).getTypePtr());
}
}
diff --git a/clang/test/SemaCXX/vector.cpp b/clang/test/SemaCXX/vector.cpp
index 3882efbbc9556..9c6e2ebedf6ea 100644
--- a/clang/test/SemaCXX/vector.cpp
+++ b/clang/test/SemaCXX/vector.cpp
@@ -1,6 +1,7 @@
// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++20 %s
// RUN: %clang_cc1 -flax-vector-conversions=integer -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT
// RUN: %clang_cc1 -flax-vector-conversions=none -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT -DNO_LAX_INT
@@ -530,3 +531,17 @@ void use() {
S<int, 16> s;
}
} // namespace PR48540
+
+#if __cplusplus >= 202002L // C++20 or later
+// Don't crash due to missing integer ranks.
+char8_t v1 __attribute__((vector_size(16)));
+char16_t v2 __attribute__((vector_size(16)));
+char32_t v3 __attribute__((vector_size(16)));
+wchar_t v4 __attribute__((vector_size(16)));
+void triggerIntegerRankCheck() {
+ auto b1 = (v1 >= 0x12);
+ auto b2 = (v2 >= 0x12);
+ auto b3 = (v3 >= 0x12);
+ auto b4 = (v4 >= 0x12);
+}
+#endif
More information about the cfe-commits
mailing list