[PATCH] D139428: Handle char{8,16,32} and wchar_t in ASTContext::getIntegerRank()

Hans Wennborg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 6 06:25:49 PST 2022


hans created this revision.
hans added a reviewer: aaron.ballman.
Herald added a project: All.
hans requested review of this revision.
Herald added a project: clang.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139428

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/vector-bool.cpp


Index: clang/test/SemaCXX/vector-bool.cpp
===================================================================
--- clang/test/SemaCXX/vector-bool.cpp
+++ clang/test/SemaCXX/vector-bool.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++17
+// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++20
 // Note that this test depends on the size of long-long to be different from
 // int, so it specifies a triple.
 
@@ -90,3 +90,15 @@
   foo(eight_bools.w);    // expected-error at 90 {{illegal vector component name ''w''}}
   foo(eight_bools.wyx);  // expected-error at 91 {{illegal vector component name ''wyx''}}
 }
+
+// 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);
+}
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -7102,6 +7102,21 @@
   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(CharTy.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());
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139428.480462.patch
Type: text/x-patch
Size: 2033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221206/3e4134d6/attachment.bin>


More information about the cfe-commits mailing list