llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

We can't call getElemDataSize() on e.g. 128-bit integers.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+21-1) 
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+5) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index c9f44807c9080..9530d58e7d6a4 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -50,6 +50,23 @@ namespace interp {
   return false;
 }
 
+static bool isFixedSizeIntegralType(PrimType T) {
+  switch (T) {
+  case PT_Sint8:
+  case PT_Uint8:
+  case PT_Sint16:
+  case PT_Uint16:
+  case PT_Sint32:
+  case PT_Uint32:
+  case PT_Sint64:
+  case PT_Uint64:
+  case PT_Bool:
+    return true;
+  default:
+    return false;
+  }
+}
+
 static void discard(InterpStack &Stk, PrimType T) {
   TYPE_SWITCH(T, { Stk.discard<T>(); });
 }
@@ -435,6 +452,9 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr 
OpPC,
 
   assert(StrPtr.getFieldDesc()->isPrimitiveArray());
   PrimType ElemT = StrPtr.getFieldDesc()->getPrimType();
+  if (!isFixedSizeIntegralType(ElemT))
+    return false;
+
   unsigned ElemSize = StrPtr.getFieldDesc()->getElemDataSize();
   if (ElemSize != 1 && ElemSize != 2 && ElemSize != 4)
     return Invalid(S, OpPC);
@@ -442,7 +462,7 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr 
OpPC,
   if (ID == Builtin::BI__builtin_wcslen || ID == Builtin::BIwcslen) {
     const ASTContext &AC = S.getASTContext();
     unsigned WCharSize = 
AC.getTypeSizeInChars(AC.getWCharType()).getQuantity();
-    if (StrPtr.getFieldDesc()->getElemDataSize() != WCharSize)
+    if (ElemSize != WCharSize)
       return false;
   }
 
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 04e4728da078b..dc6d2274d8293 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -138,6 +138,11 @@ namespace strcmp {
                                         // ref-note {{declared here}}
   static_assert(__builtin_strcmp(missingInit, "bar") == 0, ""); // both-error 
{{not an integral constant expression}} \
                                                                 // ref-note 
{{initializer of 'missingInit' is unknown}}
+#ifdef __SIZEOF_INT128__
+  const unsigned __int128 foo128[] = {};
+  constexpr int bar128 = __builtin_strlen((char *)foo128); // both-error 
{{must be initialized by a constant expression}} \
+                                                           // both-note {{cast 
that performs the conversions of a reinterpret_cast}}
+#endif
 }
 
 namespace WcsCmp {

``````````

</details>


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

Reply via email to